2
0

arm.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. asm
  16. rfs r0
  17. and r0,r0,#0xffe0ffff
  18. orr r0,r0,#0x00020000
  19. wfs r0
  20. end;
  21. end;
  22. {****************************************************************************
  23. stack frame related stuff
  24. ****************************************************************************}
  25. {$define FPC_SYSTEM_HAS_GET_FRAME}
  26. function get_frame:pointer;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
  27. asm
  28. mov r0,r11
  29. end ['R0'];
  30. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  31. function get_caller_addr(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
  32. asm
  33. movs r0,r0
  34. beq .Lg_a_null
  35. ldr r0,[r0,#-4]
  36. .Lg_a_null:
  37. end ['R0'];
  38. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  39. function get_caller_frame(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
  40. asm
  41. movs r0,r0
  42. beq .Lgnf_null
  43. ldr r0,[r0,#-12]
  44. .Lgnf_null:
  45. end ['R0'];
  46. {$define FPC_SYSTEM_HAS_SPTR}
  47. Function Sptr : pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
  48. asm
  49. mov r0,sp
  50. end ['R0'];
  51. {$define FPC_SYSTEM_HAS_FILLCHAR}
  52. Procedure FillChar(var x;count:longint;value:byte);assembler;nostackframe;
  53. asm
  54. // less than 0?
  55. cmp r1,#0
  56. movlt pc,lr
  57. mov r3,r0
  58. cmp r1,#8 // at least 8 bytes to do?
  59. blt .LFillchar2
  60. orr r2,r2,r2,lsl #8
  61. orr r2,r2,r2,lsl #16
  62. .LFillchar0:
  63. tst r3,#3 // aligned yet?
  64. strneb r2,[r3],#1
  65. subne r1,r1,#1
  66. bne .LFillchar0
  67. mov ip,r2
  68. .LFillchar1:
  69. cmp r1,#8 // 8 bytes still to do?
  70. blt .LFillchar2
  71. stmia r3!,{r2,ip}
  72. sub r1,r1,#8
  73. cmp r1,#8 // 8 bytes still to do?
  74. blt .LFillchar2
  75. stmia r3!,{r2,ip}
  76. sub r1,r1,#8
  77. cmp r1,#8 // 8 bytes still to do?
  78. blt .LFillchar2
  79. stmia r3!,{r2,ip}
  80. sub r1,r1,#8
  81. cmp r1,#8 // 8 bytes still to do?
  82. stmgeia r3!,{r2,ip}
  83. subge r1,r1,#8
  84. bge .LFillchar1
  85. .LFillchar2:
  86. movs r1,r1 // anything left?
  87. moveq pc,lr
  88. rsb r1,r1,#7
  89. add pc,pc,r1,lsl #2
  90. mov r0,r0
  91. strb r2,[r3],#1
  92. strb r2,[r3],#1
  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. mov pc,lr
  99. end;
  100. (*
  101. {$define FPC_SYSTEM_HAS_MOVE}
  102. procedure Move(const source;var dest;count:longint);[public, alias: 'FPC_MOVE'];assembler;nostackframe;
  103. asm
  104. // count <=0 ?
  105. cmp r2,#0
  106. movle pc,lr
  107. // overlap?
  108. cmp r2,r1
  109. bls .Lnoverlap
  110. add r3,r0,r2
  111. cmp r3,r2
  112. bls .Lnooverlap
  113. // overlap, copy backward
  114. .Loverlapped
  115. subs r2,r2,#1
  116. ldrb r3,[r0,r2]
  117. strb r3,[r1,r2]
  118. bne .Loverlapped
  119. mov pc,lr
  120. .Lnooverlap:
  121. // less then 16 bytes to copy?
  122. cmp r2,#16
  123. // yes, the forget about the whole optimizations
  124. // and do a bytewise copy
  125. blt .Lbyteloop
  126. // both uneven aligned?
  127. eor r3,r0,r1
  128. tst r3,#1
  129. bne .Ldifferentaligned
  130. // yes, then align
  131. // alignment to 4 byte boundries is enough
  132. ldrb ip,[r0],#1
  133. sub r2,r2,#1
  134. stb ip,[r1],#1
  135. tst r3,#2
  136. bne .Ldifferentaligned
  137. ldrh ip,[r0],#2
  138. sub r2,r2,#2
  139. sth ip,[r1],#2
  140. .Ldifferentaligned
  141. // qword aligned?
  142. orrs r3,r0,r1
  143. tst r3,#7
  144. bne .Ldwordloop
  145. .Lqwordloop:
  146. sub r2,r2,#8
  147. ldmia r0!,{r3,ip}
  148. stmia r1!,{r3,ip}
  149. .Lbyteloop:
  150. ldrb r3,[r0],#1
  151. strb r3,[r1],#1
  152. subs r2,r2,#1
  153. bne .Lbyteloop
  154. mov pc,lr
  155. end;
  156. *)