head.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. .option push
  36. .option norvc
  37. .option norelax
  38. rdtime s0 // Record timer at reset
  39. lui sp,%hi(___stack_top)
  40. addi sp,sp,%lo(___stack_top)
  41. j __start
  42. .option pop
  43. .type _reset, @function
  44. .size _reset, . - _reset
  45. .section ".text.hot","ax"
  46. .globl __start
  47. .balign 4
  48. __start:
  49. .option push
  50. .option norvc // Weird things happen?
  51. .option norelax // Can't make gp references to set up gp...
  52. not t0,zero
  53. maskirq zero,t0,zero
  54. // Interrupt stack
  55. lui t0,%hi(___irqstack_top)
  56. addqxi sp,t0,%lo(___irqstack_top)
  57. // Global pointer register (not actually used...)
  58. #if GP_IS_ZERO
  59. li gp, 0
  60. #else
  61. la gp, __global_pointer$
  62. #endif
  63. .option pop
  64. addqxi gp,gp,0 // Set gp for interrupt code too
  65. // Clear esplink_head.magic as quickly as possible
  66. sw zero,esplink_head,a0
  67. // Clear bss
  68. la a0,__BSS_START__
  69. la a1,__BSS_END__
  70. .L_clear_bss_loop:
  71. sw zero,(a0)
  72. sw zero,4(a0)
  73. sw zero,8(a0)
  74. sw zero,12(a0)
  75. sw zero,16(a0)
  76. sw zero,20(a0)
  77. sw zero,24(a0)
  78. sw zero,28(a0)
  79. addi a0,a0,32
  80. bltu a0,a1,.L_clear_bss_loop
  81. sw s0, time_zero, t0
  82. j main
  83. .type __start, @function
  84. .size __start, . - __start
  85. __sbss
  86. .balign 4
  87. .globl time_zero
  88. time_zero:
  89. .space 4
  90. .type time_zero, @object
  91. .size time_zero, . - time_zero
  92. .popsection
  93. // Time stamp definition as patched in by FPGA build
  94. .section ".datestamp","a"
  95. .globl __datestamp
  96. __datestamp:
  97. .space 32
  98. .type __datestamp, @object
  99. .size __datestamp, . - __datestamp
  100. // Stack definition
  101. .section ".stack","aw",@nobits
  102. .balign 4
  103. .globl __irqstack_bottom
  104. ___irqstack:
  105. .space IRQSTACK_SIZE
  106. .type ___irqstack, @object
  107. .size ___irqstack, IRQSTACK_SIZE
  108. .globl ___irqstack_top
  109. ___irqstack_top:
  110. .balign 4
  111. .globl ___stack
  112. ___stack:
  113. .space STACK_SIZE
  114. .type ___stack, @object
  115. .size ___stack, STACK_SIZE
  116. .globl ___stack_top
  117. ___stack_top: