arm.inc 4.4 KB

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