cprt07.as 2.8 KB

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