head.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "sys.h"
  2. #include "picorv32.h"
  3. #define GP_IS_ZERO 1
  4. // The code in this file is sensitive to alignment, so
  5. // don't use compressed instructions (there are very few anyway)
  6. .option norvc
  7. // NULL pointer guard area
  8. // This needs to be an explicitly allocated section or the binary
  9. // memory initialization file ends up broken.
  10. //
  11. // This also contains a pointer to the ROM area associated
  12. // with this image. For a non-primary image it is patched to
  13. // the preferred value.
  14. .section ".null","a"
  15. .globl _NULL
  16. _NULL:
  17. .space 8
  18. .type _NULL, @object
  19. .size _NULL, . - _NULL
  20. .globl __dram_checksum
  21. __dram_checksum:
  22. .long 0 // Filled in post-link
  23. .type __dram_checksum, @object
  24. .size __dram_checksum, . - __dram_checksum
  25. .globl __rom_offset
  26. __rom_offset:
  27. .long ROM_OFFSET
  28. .type __rom_offset, @object
  29. .size __rom_offset, . - __rom_offset
  30. // The linker will always assign this to _PC_RESET
  31. .section ".init.reset","ax"
  32. .globl _reset
  33. _reset:
  34. rdtime s0 // Record timer at reset
  35. li sp,STACK_TOP // Cheaper than using la sp,___stack_top
  36. j __start
  37. .type _reset, @function
  38. .size _reset, . - _reset
  39. .section ".init","ax"
  40. .globl __start
  41. __start:
  42. not t0,zero
  43. maskirq zero,t0,zero
  44. #if !GP_IS_ZERO
  45. .option push
  46. .option norelax // Can't make gp references to set up gp...
  47. la gp, __global_pointer$
  48. .option pop
  49. #else
  50. // Zero gp (linker will usually replace with the zero reg)
  51. li gp,0
  52. #endif
  53. addqxi gp,gp,0 // Set gp for interrupt code too
  54. // Clear dram_io_head.magic as quickly as possible
  55. la a0,__dram_io_start
  56. sw zero,(a0)
  57. // Clear bss
  58. la a0,__BSS_START__
  59. la a1,__BSS_END__
  60. .L_clear_bss_loop:
  61. sw zero,(a0)
  62. sw zero,4(a0)
  63. sw zero,8(a0)
  64. sw zero,12(a0)
  65. sw zero,16(a0)
  66. sw zero,20(a0)
  67. sw zero,24(a0)
  68. sw zero,28(a0)
  69. addi a0,a0,32
  70. bltu a0,a1,.L_clear_bss_loop
  71. sw s0, time_zero, t0
  72. j main
  73. .type __start, @function
  74. .size __start, . - __start
  75. __sbss
  76. .balign 4
  77. .globl time_zero
  78. time_zero:
  79. .space 4
  80. .type time_zero, @object
  81. .size time_zero, . - time_zero
  82. .popsection
  83. // Time stamp definition as patched in by FPGA build
  84. .section ".datestamp","a"
  85. .globl __datestamp
  86. __datestamp:
  87. .space 32
  88. .type __datestamp, @object
  89. .size __datestamp, . - __datestamp
  90. // Stack definition
  91. .section ".stack","aw",@nobits
  92. .balign 4
  93. .globl ___stack_bottom
  94. ___stack:
  95. .space STACK_SIZE
  96. .type ___stack, @object
  97. .size ___stack, STACK_SIZE
  98. .globl ___stack_top
  99. ___stack_top: