init.s 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ; init.s
  2. ;
  3. ; to be included by the crt*.s files
  4. ;
  5. ; initialize stacks
  6. ;
  7. ; set the hardware stack to ram_end, and the software stack some
  8. ; bytes below that
  9. ldi R28,<ram_end
  10. ldi R29,>ram_end
  11. out $3D,R28
  12. out $3E,R29
  13. subi R28,<hwstk_size
  14. sbci R29,>hwstk_size
  15. ldi R16,0xAA ; sentenial
  16. std Y+0,R16 ; put sentenial at bottom of HW stack
  17. clr R0
  18. ldi R30,<__bss_start
  19. ldi R31,>__bss_start
  20. ldi R17,>__bss_end
  21. ; this loop zeros out all the data in the bss area
  22. ;
  23. init_loop:
  24. cpi R30,<__bss_end
  25. cpc R31,R17
  26. breq init_done
  27. st Z+,R0
  28. rjmp init_loop
  29. init_done:
  30. std Z+0,R16 ; put sentenial at bottom of SW stack
  31. ; copy data from idata to data
  32. ; idata contains the initialized values of the global variables
  33. ldi R30,<__idata_start
  34. ldi R31,>__idata_start
  35. ldi R26,<__data_start
  36. ldi R27,>__data_start
  37. ldi R17,>__idata_end
  38. .if USE_ELPM
  39. ; set RAMPZ to 1
  40. ldi R16,1
  41. out 0x3B,R16
  42. .endif
  43. copy_loop:
  44. cpi R30,<__idata_end
  45. cpc R31,R17
  46. breq copy_done
  47. .if USE_ELPM
  48. elpm ; load (RAMPZ:Z)
  49. .else
  50. lpm ; load (Z) byte into R0
  51. .endif
  52. adiw R30,1
  53. st X+,R0
  54. rjmp copy_loop
  55. copy_done: