prt07.as 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. @---------------------------------------------------------------------------------
  2. .section ".init"
  3. .global _start
  4. @---------------------------------------------------------------------------------
  5. .align 4
  6. .arm
  7. @---------------------------------------------------------------------------------
  8. _start:
  9. @---------------------------------------------------------------------------------
  10. mov r0, #0x04000000 @ IME = 0;
  11. str r0, [r0, #0x208]
  12. mov r0, #0x12 @ Switch to IRQ Mode
  13. msr cpsr, r0
  14. ldr sp, =__sp_irq @ Set IRQ stack
  15. mov r0, #0x13 @ Switch to SVC Mode
  16. msr cpsr, r0
  17. ldr sp, =__sp_svc @ Set SVC stack
  18. mov r0, #0x1F @ Switch to System Mode
  19. msr cpsr, r0
  20. ldr sp, =__sp_usr @ Set user stack
  21. ldr r0, =__bss_start @ Clear BSS section to 0x00
  22. ldr r1, =__bss_end
  23. sub r1, r1, r0
  24. bl ClearMem
  25. mov r0, #0 @ int argc
  26. mov r1, #0 @ char *argv[]
  27. ldr r3, =main
  28. ldr lr,=__libnds_exit
  29. bx r3
  30. @---------------------------------------------------------------------------------
  31. @ Clear memory to 0x00 if length != 0
  32. @ r0 = Start Address
  33. @ r1 = Length
  34. @---------------------------------------------------------------------------------
  35. ClearMem:
  36. @---------------------------------------------------------------------------------
  37. mov r2, #3 @ Round down to nearest word boundary
  38. add r1, r1, r2 @ Shouldn't be needed
  39. bics r1, r1, r2 @ Clear 2 LSB (and set Z)
  40. bxeq lr @ Quit if copy size is 0
  41. mov r2, #0
  42. ClrLoop:
  43. stmia r0!, {r2}
  44. subs r1, r1, #4
  45. bne ClrLoop
  46. bx lr
  47. @---------------------------------------------------------------------------------
  48. @ Copy memory if length != 0
  49. @ r1 = Source Address
  50. @ r2 = Dest Address
  51. @ r4 = Dest Address + Length
  52. @---------------------------------------------------------------------------------
  53. CopyMemCheck:
  54. @---------------------------------------------------------------------------------
  55. sub r3, r4, r2 @ Is there any data to copy?
  56. @---------------------------------------------------------------------------------
  57. @ Copy memory
  58. @ r1 = Source Address
  59. @ r2 = Dest Address
  60. @ r3 = Length
  61. @---------------------------------------------------------------------------------
  62. CopyMem:
  63. @---------------------------------------------------------------------------------
  64. mov r0, #3 @ These commands are used in cases where
  65. add r3, r3, r0 @ the length is not a multiple of 4,
  66. bics r3, r3, r0 @ even though it should be.
  67. bxeq lr @ Length is zero, so exit
  68. CIDLoop:
  69. ldmia r1!, {r0}
  70. stmia r2!, {r0}
  71. subs r3, r3, #4
  72. bne CIDLoop
  73. bx lr
  74. @---------------------------------------------------------------------------------
  75. .align
  76. .pool
  77. .end
  78. @---------------------------------------------------------------------------------