2
0

head.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "sys.h"
  2. #include "sections.h"
  3. #include "picorv32.h"
  4. #define GP_IS_ZERO 1
  5. // The code in this file is sensitive to alignment, so
  6. // don't use compressed instructions (there are very few anyway)
  7. .option norvc
  8. // NULL pointer guard area
  9. // This needs to be an explicitly allocated section or the binary
  10. // memory initialization file ends up broken.
  11. //
  12. // This also contains a pointer to the ROM area associated
  13. // with this image. For a non-primary image it is patched to
  14. // the preferred value.
  15. .section ".null","a"
  16. .globl _NULL
  17. _NULL:
  18. .space 8
  19. .type _NULL, @object
  20. .size _NULL, . - _NULL
  21. .globl __dram_checksum
  22. __dram_checksum:
  23. .long 0 // Filled in post-link
  24. .type __dram_checksum, @object
  25. .size __dram_checksum, . - __dram_checksum
  26. .globl __rom_offset
  27. __rom_offset:
  28. .long ROM_OFFSET
  29. .type __rom_offset, @object
  30. .size __rom_offset, . - __rom_offset
  31. // The linker will always assign this to _PC_RESET
  32. .section ".init.reset","ax"
  33. .globl _reset
  34. _reset:
  35. rdtime s0 // Record timer at reset
  36. li sp,STACK_TOP // Cheaper than using la sp,___stack_top
  37. j __start
  38. .type _reset, @function
  39. .size _reset, . - _reset
  40. .section ".init","ax"
  41. .globl __start
  42. __start:
  43. not t0,zero
  44. maskirq zero,t0,zero
  45. #if !GP_IS_ZERO
  46. .option push
  47. .option norelax // Can't make gp references to set up gp...
  48. la gp, __global_pointer$
  49. .option pop
  50. #else
  51. // Zero gp (linker will usually replace with the zero reg)
  52. li gp,0
  53. #endif
  54. addqxi gp,gp,0 // Set gp for interrupt code too
  55. // Clear esplink_head.magic as quickly as possible
  56. sw zero,esplink_head,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: