prt07.as 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. bx r3
  29. nop
  30. @ If the user ever returns, return to flash cartridge
  31. mov r0, #0x08000000
  32. bx r0
  33. @---------------------------------------------------------------------------------
  34. @ Clear memory to 0x00 if length != 0
  35. @ r0 = Start Address
  36. @ r1 = Length
  37. @---------------------------------------------------------------------------------
  38. ClearMem:
  39. @---------------------------------------------------------------------------------
  40. mov r2, #3 @ Round down to nearest word boundary
  41. add r1, r1, r2 @ Shouldn't be needed
  42. bics r1, r1, r2 @ Clear 2 LSB (and set Z)
  43. bxeq lr @ Quit if copy size is 0
  44. mov r2, #0
  45. ClrLoop:
  46. stmia r0!, {r2}
  47. subs r1, r1, #4
  48. bne ClrLoop
  49. bx lr
  50. @---------------------------------------------------------------------------------
  51. @ Copy memory if length != 0
  52. @ r1 = Source Address
  53. @ r2 = Dest Address
  54. @ r4 = Dest Address + Length
  55. @---------------------------------------------------------------------------------
  56. CopyMemCheck:
  57. @---------------------------------------------------------------------------------
  58. sub r3, r4, r2 @ Is there any data to copy?
  59. @---------------------------------------------------------------------------------
  60. @ Copy memory
  61. @ r1 = Source Address
  62. @ r2 = Dest Address
  63. @ r3 = Length
  64. @---------------------------------------------------------------------------------
  65. CopyMem:
  66. @---------------------------------------------------------------------------------
  67. mov r0, #3 @ These commands are used in cases where
  68. add r3, r3, r0 @ the length is not a multiple of 4,
  69. bics r3, r3, r0 @ even though it should be.
  70. bxeq lr @ Length is zero, so exit
  71. CIDLoop:
  72. ldmia r1!, {r0}
  73. stmia r2!, {r0}
  74. subs r3, r3, #4
  75. bne CIDLoop
  76. bx lr
  77. @---------------------------------------------------------------------------------
  78. .align
  79. .pool
  80. .end
  81. @---------------------------------------------------------------------------------