head.S 1.7 KB

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