head.S 1.4 KB

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