head.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // Unblock fatal exceptions - only
  66. li a0,~6
  67. maskirq zero,a0,zero
  68. // Clear esplink_head.magic as quickly as possible
  69. sw zero,esplink_head,a0
  70. // Clear bss
  71. la a0,__BSS_START__
  72. la a1,__BSS_END__
  73. .L_clear_bss_loop:
  74. sw zero,(a0)
  75. sw zero,4(a0)
  76. sw zero,8(a0)
  77. sw zero,12(a0)
  78. sw zero,16(a0)
  79. sw zero,20(a0)
  80. sw zero,24(a0)
  81. sw zero,28(a0)
  82. addi a0,a0,32
  83. bltu a0,a1,.L_clear_bss_loop
  84. sw s0, time_zero, t0
  85. j main
  86. .type __start, @function
  87. .size __start, . - __start
  88. __sbss
  89. .balign 4
  90. .globl time_zero
  91. time_zero:
  92. .space 4
  93. .type time_zero, @object
  94. .size time_zero, . - time_zero
  95. .popsection
  96. // Time stamp definition as patched in by FPGA build
  97. .section ".datestamp","a"
  98. .globl __datestamp
  99. __datestamp:
  100. .space 32
  101. .type __datestamp, @object
  102. .size __datestamp, . - __datestamp
  103. // Stack definition
  104. .section ".stack","aw",@nobits
  105. .balign 4
  106. .globl __irqstack_bottom
  107. ___irqstack:
  108. .space IRQSTACK_SIZE
  109. .type ___irqstack, @object
  110. .size ___irqstack, IRQSTACK_SIZE
  111. .globl ___irqstack_top
  112. ___irqstack_top:
  113. .balign 4
  114. .globl ___stack
  115. ___stack:
  116. .space STACK_SIZE
  117. .type ___stack, @object
  118. .size ___stack, STACK_SIZE
  119. .globl ___stack_top
  120. ___stack_top: