init.s 966 B

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