head.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 esplink_head.magic as quickly as possible
  55. sw zero,esplink_head,a0
  56. // Clear bss
  57. la a0,__BSS_START__
  58. la a1,__BSS_END__
  59. .L_clear_bss_loop:
  60. sw zero,(a0)
  61. sw zero,4(a0)
  62. sw zero,8(a0)
  63. sw zero,12(a0)
  64. sw zero,16(a0)
  65. sw zero,20(a0)
  66. sw zero,24(a0)
  67. sw zero,28(a0)
  68. addi a0,a0,32
  69. bltu a0,a1,.L_clear_bss_loop
  70. sw s0, time_zero, t0
  71. j main
  72. .type __start, @function
  73. .size __start, . - __start
  74. __sbss
  75. .balign 4
  76. .globl time_zero
  77. time_zero:
  78. .space 4
  79. .type time_zero, @object
  80. .size time_zero, . - time_zero
  81. .popsection
  82. // Time stamp definition as patched in by FPGA build
  83. .section ".datestamp","a"
  84. .globl __datestamp
  85. __datestamp:
  86. .space 32
  87. .type __datestamp, @object
  88. .size __datestamp, . - __datestamp
  89. // Stack definition
  90. .section ".stack","aw",@nobits
  91. .balign 4
  92. .globl ___stack_bottom
  93. ___stack:
  94. .space STACK_SIZE
  95. .type ___stack, @object
  96. .size ___stack, STACK_SIZE
  97. .globl ___stack_top
  98. ___stack_top: