arm.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by the Free Pascal development team.
  4. Processor dependent implementation for the system unit for
  5. ARM
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$asmmode gas}
  13. procedure fpc_cpuinit;
  14. begin
  15. {$IFNDEF WINCE}
  16. asm
  17. rfs r0
  18. and r0,r0,#0xffe0ffff
  19. orr r0,r0,#0x00020000
  20. wfs r0
  21. end;
  22. {$ENDIF}
  23. end;
  24. {****************************************************************************
  25. stack frame related stuff
  26. ****************************************************************************}
  27. {$define FPC_SYSTEM_HAS_GET_FRAME}
  28. function get_frame:pointer;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
  29. asm
  30. mov r0,r11
  31. end ['R0'];
  32. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  33. function get_caller_addr(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
  34. asm
  35. movs r0,r0
  36. beq .Lg_a_null
  37. ldr r0,[r0,#-4]
  38. .Lg_a_null:
  39. end ['R0'];
  40. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  41. function get_caller_frame(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
  42. asm
  43. movs r0,r0
  44. beq .Lgnf_null
  45. ldr r0,[r0,#-12]
  46. .Lgnf_null:
  47. end ['R0'];
  48. {$define FPC_SYSTEM_HAS_SPTR}
  49. Function Sptr : pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
  50. asm
  51. mov r0,sp
  52. end ['R0'];
  53. {$define FPC_SYSTEM_HAS_FILLCHAR}
  54. Procedure FillChar(var x;count:longint;value:byte);assembler;nostackframe;
  55. asm
  56. // less than 0?
  57. cmp r1,#0
  58. movlt pc,lr
  59. mov r3,r0
  60. cmp r1,#8 // at least 8 bytes to do?
  61. blt .LFillchar2
  62. orr r2,r2,r2,lsl #8
  63. orr r2,r2,r2,lsl #16
  64. .LFillchar0:
  65. tst r3,#3 // aligned yet?
  66. strneb r2,[r3],#1
  67. subne r1,r1,#1
  68. bne .LFillchar0
  69. mov ip,r2
  70. .LFillchar1:
  71. cmp r1,#8 // 8 bytes still to do?
  72. blt .LFillchar2
  73. stmia r3!,{r2,ip}
  74. sub r1,r1,#8
  75. cmp r1,#8 // 8 bytes still to do?
  76. blt .LFillchar2
  77. stmia r3!,{r2,ip}
  78. sub r1,r1,#8
  79. cmp r1,#8 // 8 bytes still to do?
  80. blt .LFillchar2
  81. stmia r3!,{r2,ip}
  82. sub r1,r1,#8
  83. cmp r1,#8 // 8 bytes still to do?
  84. stmgeia r3!,{r2,ip}
  85. subge r1,r1,#8
  86. bge .LFillchar1
  87. .LFillchar2:
  88. movs r1,r1 // anything left?
  89. moveq pc,lr
  90. rsb r1,r1,#7
  91. add pc,pc,r1,lsl #2
  92. mov r0,r0
  93. strb r2,[r3],#1
  94. strb r2,[r3],#1
  95. strb r2,[r3],#1
  96. strb r2,[r3],#1
  97. strb r2,[r3],#1
  98. strb r2,[r3],#1
  99. strb r2,[r3],#1
  100. mov pc,lr
  101. end;
  102. (*
  103. {$define FPC_SYSTEM_HAS_MOVE}
  104. procedure Move(const source;var dest;count:longint);[public, alias: 'FPC_MOVE'];assembler;nostackframe;
  105. asm
  106. // count <=0 ?
  107. cmp r2,#0
  108. movle pc,lr
  109. // overlap?
  110. cmp r2,r1
  111. bls .Lnoverlap
  112. add r3,r0,r2
  113. cmp r3,r2
  114. bls .Lnooverlap
  115. // overlap, copy backward
  116. .Loverlapped
  117. subs r2,r2,#1
  118. ldrb r3,[r0,r2]
  119. strb r3,[r1,r2]
  120. bne .Loverlapped
  121. mov pc,lr
  122. .Lnooverlap:
  123. // less then 16 bytes to copy?
  124. cmp r2,#16
  125. // yes, the forget about the whole optimizations
  126. // and do a bytewise copy
  127. blt .Lbyteloop
  128. // both uneven aligned?
  129. eor r3,r0,r1
  130. tst r3,#1
  131. bne .Ldifferentaligned
  132. // yes, then align
  133. // alignment to 4 byte boundries is enough
  134. ldrb ip,[r0],#1
  135. sub r2,r2,#1
  136. stb ip,[r1],#1
  137. tst r3,#2
  138. bne .Ldifferentaligned
  139. ldrh ip,[r0],#2
  140. sub r2,r2,#2
  141. sth ip,[r1],#2
  142. .Ldifferentaligned
  143. // qword aligned?
  144. orrs r3,r0,r1
  145. tst r3,#7
  146. bne .Ldwordloop
  147. .Lqwordloop:
  148. sub r2,r2,#8
  149. ldmia r0!,{r3,ip}
  150. stmia r1!,{r3,ip}
  151. .Lbyteloop:
  152. ldrb r3,[r0],#1
  153. strb r3,[r1],#1
  154. subs r2,r2,#1
  155. bne .Lbyteloop
  156. mov pc,lr
  157. end;
  158. *)