2
0

head.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 12
  18. .type _NULL, @object
  19. .size _NULL, . - _NULL
  20. .globl __rom_offset
  21. __rom_offset:
  22. .long ROM_OFFSET
  23. .type __rom_offset, @object
  24. .size __rom_offset, . - __rom_offset
  25. // The linker will always assign this to _PC_RESET
  26. .section ".init.reset","ax"
  27. .globl _reset
  28. _reset:
  29. rdtime s0 // Record timer at reset
  30. li sp,STACK_TOP // Cheaper than using la sp,___stack_top
  31. j __start
  32. .type _reset, @function
  33. .size _reset, . - _reset
  34. .section ".init","ax"
  35. .globl __start
  36. __start:
  37. not t0,zero
  38. maskirq zero,t0,zero
  39. #if !GP_IS_ZERO
  40. .option push
  41. .option norelax // Can't make gp references to set up gp...
  42. la gp, __global_pointer$
  43. .option pop
  44. #else
  45. // Zero gp (linker will usually replace with the zero reg)
  46. li gp,0
  47. #endif
  48. addqxi gp,gp,0 // Set gp for interrupt code too
  49. // Clear bss
  50. la a0,__BSS_START__
  51. la a1,__BSS_END__
  52. .L_clear_bss_loop:
  53. sw zero,(a0)
  54. sw zero,4(a0)
  55. sw zero,8(a0)
  56. sw zero,12(a0)
  57. sw zero,16(a0)
  58. sw zero,20(a0)
  59. sw zero,24(a0)
  60. sw zero,28(a0)
  61. addi a0,a0,32
  62. bltu a0,a1,.L_clear_bss_loop
  63. sw s0, time_zero, t0
  64. j main
  65. .type __start, @function
  66. .size __start, . - __start
  67. __sbss
  68. .balign 4
  69. .globl time_zero
  70. time_zero:
  71. .space 4
  72. .type time_zero, @object
  73. .size time_zero, . - time_zero
  74. .popsection
  75. .section ".stack","aw",@nobits
  76. .balign 4
  77. .globl ___stack_bottom
  78. ___stack:
  79. .space STACK_SIZE
  80. .type ___stack, @object
  81. .size ___stack, STACK_SIZE
  82. .globl ___stack_top
  83. ___stack_top: