arm.inc 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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. {$ifndef FPC_SYSTEM_HAS_MOVE}
  13. {$define FPC_SYSTEM_FPC_MOVE}
  14. {$endif FPC_SYSTEM_HAS_MOVE}
  15. {$ifdef FPC_SYSTEM_FPC_MOVE}
  16. const
  17. cpu_has_edsp : boolean = false;
  18. in_edsp_test : boolean = false;
  19. {$endif FPC_SYSTEM_FPC_MOVE}
  20. {$if not(defined(wince)) and not(defined(gba)) and not(defined(nds)) and not(defined(FPUSOFT)) and not(defined(FPULIBGCC))}
  21. {$define FPC_SYSTEM_HAS_SYSINITFPU}
  22. {$if not defined(darwin) and not defined(FPUVFPV2) and not defined(FPUVFPV3) and not defined(FPUVFPV3_D16)}
  23. Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  24. begin
  25. { Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL }
  26. asm
  27. rfs r0
  28. and r0,r0,#0xffe0ffff
  29. orr r0,r0,#0x00070000
  30. wfs r0
  31. end;
  32. end;
  33. {$else}
  34. Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  35. begin
  36. { Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL }
  37. asm
  38. fmrx r0,fpscr
  39. // set "round to nearest" mode
  40. and r0,r0,#0xff3fffff
  41. // mask "exception happened" and overflow flags
  42. and r0,r0,#0xffffff20
  43. // mask exception flags
  44. and r0,r0,#0xffff40ff
  45. {$ifndef darwin}
  46. // Floating point exceptions cause kernel panics on iPhoneOS 2.2.1...
  47. // disable flush-to-zero mode (IEEE math compliant)
  48. and r0,r0,#0xfeffffff
  49. // enable invalid operation, div-by-zero and overflow exceptions
  50. orr r0,r0,#0x00000700
  51. {$endif}
  52. fmxr fpscr,r0
  53. end;
  54. end;
  55. {$endif}
  56. {$endif}
  57. procedure fpc_cpuinit;
  58. begin
  59. { don't let libraries influence the FPU cw set by the host program }
  60. if not IsLibrary then
  61. SysInitFPU;
  62. end;
  63. {$ifdef wince}
  64. function _controlfp(new: DWORD; mask: DWORD): DWORD; cdecl; external 'coredll';
  65. {$define FPC_SYSTEM_HAS_SYSRESETFPU}
  66. Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  67. begin
  68. end;
  69. {$define FPC_SYSTEM_HAS_SYSINITFPU}
  70. Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  71. begin
  72. { Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL }
  73. { FPU precision 64 bit, rounding to nearest, affine infinity }
  74. _controlfp($000C0003, $030F031F);
  75. end;
  76. {$endif wince}
  77. {****************************************************************************
  78. stack frame related stuff
  79. ****************************************************************************}
  80. {$IFNDEF INTERNAL_BACKTRACE}
  81. {$define FPC_SYSTEM_HAS_GET_FRAME}
  82. function get_frame:pointer;assembler;nostackframe;
  83. asm
  84. {$ifndef darwin}
  85. mov r0,r11
  86. {$else}
  87. mov r0,r7
  88. {$endif}
  89. end;
  90. {$ENDIF not INTERNAL_BACKTRACE}
  91. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  92. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;assembler;nostackframe;
  93. asm
  94. cmp r0,#0
  95. {$ifndef darwin}
  96. ldrne r0,[r0,#-4]
  97. {$else}
  98. ldrne r0,[r0,#4]
  99. {$endif}
  100. end;
  101. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  102. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;assembler;nostackframe;
  103. asm
  104. cmp r0,#0
  105. {$ifndef darwin}
  106. ldrne r0,[r0,#-12]
  107. {$else}
  108. ldrne r0,[r0]
  109. {$endif}
  110. end;
  111. {$define FPC_SYSTEM_HAS_SPTR}
  112. Function Sptr : pointer;assembler;nostackframe;
  113. asm
  114. mov r0,sp
  115. end;
  116. {$ifndef FPC_SYSTEM_HAS_FILLCHAR}
  117. {$define FPC_SYSTEM_HAS_FILLCHAR}
  118. Procedure FillChar(var x;count:longint;value:byte);assembler;nostackframe;
  119. asm
  120. // less than 0?
  121. cmp r1,#0
  122. {$ifdef CPUARM_HAS_BX}
  123. bxle lr
  124. {$else}
  125. movle pc,lr
  126. {$endif}
  127. mov r3,r0
  128. orr r2,r2,r2,lsl #8
  129. orr r2,r2,r2,lsl #16
  130. tst r3, #3 // Aligned?
  131. bne .LFillchar_do_align
  132. .LFillchar_is_aligned:
  133. subs r1,r1,#8
  134. bmi .LFillchar_less_than_8bytes
  135. mov ip,r2
  136. .LFillchar_at_least_8bytes:
  137. // Do 16 bytes per loop
  138. // More unrolling is uncessary, as we'll just stall on the write buffers
  139. stmia r3!,{r2,ip}
  140. subs r1,r1,#8
  141. stmplia r3!,{r2,ip}
  142. subpls r1,r1,#8
  143. bpl .LFillchar_at_least_8bytes
  144. .LFillchar_less_than_8bytes:
  145. // Do the rest
  146. adds r1, r1, #8
  147. {$ifdef CPUARM_HAS_BX}
  148. bxeq lr
  149. {$else}
  150. moveq pc,lr
  151. {$endif}
  152. tst r1, #4
  153. strne r2,[r3],#4
  154. tst r1, #2
  155. strneh r2,[r3],#2
  156. tst r1, #1
  157. strneb r2,[r3],#1
  158. {$ifdef CPUARM_HAS_BX}
  159. bx lr
  160. {$else}
  161. mov pc,lr
  162. {$endif}
  163. // Special case for unaligned start
  164. // We make a maximum of 3 loops here
  165. .LFillchar_do_align:
  166. strb r2,[r3],#1
  167. subs r1, r1, #1
  168. {$ifdef CPUARM_HAS_BX}
  169. bxeq lr
  170. {$else}
  171. moveq pc,lr
  172. {$endif}
  173. tst r3,#3
  174. bne .LFillchar_do_align
  175. b .LFillchar_is_aligned
  176. end;
  177. {$endif FPC_SYSTEM_HAS_FILLCHAR}
  178. {$ifndef FPC_SYSTEM_HAS_MOVE}
  179. {$define FPC_SYSTEM_HAS_MOVE}
  180. {$ifdef CPUARM_HAS_EDSP}
  181. procedure Move(const source;var dest;count:longint);[public, alias: 'FPC_MOVE'];assembler;nostackframe;
  182. {$else CPUARM_HAS_EDSP}
  183. procedure Move_pld(const source;var dest;count:longint);assembler;nostackframe;
  184. {$endif CPUARM_HAS_EDSP}
  185. asm
  186. pld [r0]
  187. // count <=0 ?
  188. cmp r2,#0
  189. {$ifdef CPUARM_HAS_BX}
  190. bxle lr
  191. {$else}
  192. movle pc,lr
  193. {$endif}
  194. // overlap?
  195. subs r3, r1, r0 // if (dest > source) and
  196. cmphi r2, r3 // (count > dest - src) then
  197. bhi .Loverlapped // DoReverseByteCopy;
  198. cmp r2,#8 // if (count < 8) then
  199. blt .Lbyteloop // DoForwardByteCopy;
  200. // Any way to avoid the above jump and fuse the next two instructions?
  201. tst r0, #3 // if (source and 3) <> 0 or
  202. tsteq r1, #3 // (dest and 3) <> 0 then
  203. bne .Lbyteloop // DoForwardByteCopy;
  204. pld [r0,#32]
  205. .Ldwordloop:
  206. ldmia r0!, {r3, ip}
  207. // preload
  208. pld [r0,#64]
  209. sub r2,r2,#8
  210. cmp r2, #8
  211. stmia r1!, {r3, ip}
  212. bge .Ldwordloop
  213. cmp r2,#0
  214. {$ifdef CPUARM_HAS_BX}
  215. bxeq lr
  216. {$else}
  217. moveq pc,lr
  218. {$endif}
  219. .Lbyteloop:
  220. subs r2,r2,#1
  221. ldrb r3,[r0],#1
  222. strb r3,[r1],#1
  223. bne .Lbyteloop
  224. {$ifdef CPUARM_HAS_BX}
  225. bx lr
  226. {$else}
  227. mov pc,lr
  228. {$endif}
  229. .Loverlapped:
  230. subs r2,r2,#1
  231. ldrb r3,[r0,r2]
  232. strb r3,[r1,r2]
  233. bne .Loverlapped
  234. end;
  235. {$ifndef CPUARM_HAS_EDSP}
  236. procedure Move_blended(const source;var dest;count:longint);assembler;nostackframe;
  237. asm
  238. // count <=0 ?
  239. cmp r2,#0
  240. {$ifdef CPUARM_HAS_BX}
  241. bxle lr
  242. {$else}
  243. movle pc,lr
  244. {$endif}
  245. // overlap?
  246. subs r3, r1, r0 // if (dest > source) and
  247. cmphi r2, r3 // (count > dest - src) then
  248. bhi .Loverlapped // DoReverseByteCopy;
  249. cmp r2,#8 // if (count < 8) then
  250. blt .Lbyteloop // DoForwardByteCopy;
  251. // Any way to avoid the above jump and fuse the next two instructions?
  252. tst r0, #3 // if (source and 3) <> 0 or
  253. tsteq r1, #3 // (dest and 3) <> 0 then
  254. bne .Lbyteloop // DoForwardByteCopy;
  255. .Ldwordloop:
  256. ldmia r0!, {r3, ip}
  257. sub r2,r2,#8
  258. cmp r2, #8
  259. stmia r1!, {r3, ip}
  260. bge .Ldwordloop
  261. cmp r2,#0
  262. {$ifdef CPUARM_HAS_BX}
  263. bxeq lr
  264. {$else}
  265. moveq pc,lr
  266. {$endif}
  267. .Lbyteloop:
  268. subs r2,r2,#1
  269. ldrb r3,[r0],#1
  270. strb r3,[r1],#1
  271. bne .Lbyteloop
  272. {$ifdef CPUARM_HAS_BX}
  273. bx lr
  274. {$else}
  275. mov pc,lr
  276. {$endif}
  277. .Loverlapped:
  278. subs r2,r2,#1
  279. ldrb r3,[r0,r2]
  280. strb r3,[r1,r2]
  281. bne .Loverlapped
  282. end;
  283. const
  284. moveproc : procedure(const source;var dest;count:longint) = @move_blended;
  285. procedure Move(const source;var dest;count:longint);[public, alias: 'FPC_MOVE']; {$ifndef FPC_PIC} assembler;nostackframe; {$endif FPC_PIC}
  286. {$ifdef FPC_PIC}
  287. begin
  288. moveproc(source,dest,count);
  289. end;
  290. {$else FPC_PIC}
  291. asm
  292. ldr ip,.Lmoveproc
  293. ldr pc,[ip]
  294. .Lmoveproc:
  295. .long moveproc
  296. end;
  297. {$endif FPC_PIC}
  298. {$endif CPUARM_HAS_EDSP}
  299. {$endif FPC_SYSTEM_HAS_MOVE}
  300. {****************************************************************************
  301. String
  302. ****************************************************************************}
  303. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
  304. {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
  305. procedure fpc_shortstr_to_shortstr(out res:shortstring;const sstr:shortstring);assembler;nostackframe;[public,alias: 'FPC_SHORTSTR_TO_SHORTSTR'];compilerproc;
  306. {r0: __RESULT
  307. r1: len
  308. r2: sstr}
  309. asm
  310. ldrb r12,[r2],#1
  311. cmp r12,r1
  312. movgt r12,r1
  313. strb r12,[r0],#1
  314. cmp r12,#6 (* 6 seems to be the break even point. *)
  315. blt .LStartTailCopy
  316. (* Align destination on 32bits. This is the only place where unrolling
  317. really seems to help, since in the common case, sstr is aligned on
  318. 32 bits, therefore in the common case we need to copy 3 bytes to
  319. align, i.e. in the case of a loop, you wouldn't branch out early.*)
  320. rsb r3,r0,#0
  321. ands r3,r3,#3
  322. sub r12,r12,r3
  323. ldrneb r1,[r2],#1
  324. strneb r1,[r0],#1
  325. subnes r3,r3,#1
  326. ldrneb r1,[r2],#1
  327. strneb r1,[r0],#1
  328. subnes r3,r3,#1
  329. ldrneb r1,[r2],#1
  330. strneb r1,[r0],#1
  331. subnes r3,r3,#1
  332. .LDoneAlign:
  333. (* Destination should be aligned now, but source might not be aligned,
  334. if this is the case, do a byte-per-byte copy. *)
  335. tst r2,#3
  336. bne .LStartTailCopy
  337. (* Start the main copy, 32 bit at a time. *)
  338. movs r3,r12,lsr #2
  339. and r12,r12,#3
  340. beq .LStartTailCopy
  341. .LNext4bytes:
  342. (* Unrolling this loop would save a little bit of time for long strings
  343. (>20 chars), but alas, it hurts for short strings and they are the
  344. common case.*)
  345. ldrne r1,[r2],#4
  346. strne r1,[r0],#4
  347. subnes r3,r3,#1
  348. bne .LNext4bytes
  349. .LStartTailCopy:
  350. (* Do remaining bytes. *)
  351. cmp r12,#0
  352. beq .LDoneTail
  353. .LNextChar3:
  354. ldrb r1,[r2],#1
  355. strb r1,[r0],#1
  356. subs r12,r12,#1
  357. bne .LNextChar3
  358. .LDoneTail:
  359. end;
  360. procedure fpc_shortstr_assign(len:longint;sstr,dstr:pointer);assembler;nostackframe;[public,alias:'FPC_SHORTSTR_ASSIGN'];compilerproc;
  361. {r0: len
  362. r1: sstr
  363. r2: dstr}
  364. asm
  365. ldrb r12,[r1],#1
  366. cmp r12,r0
  367. movgt r12,r0
  368. strb r12,[r2],#1
  369. cmp r12,#6 (* 6 seems to be the break even point. *)
  370. blt .LStartTailCopy
  371. (* Align destination on 32bits. This is the only place where unrolling
  372. really seems to help, since in the common case, sstr is aligned on
  373. 32 bits, therefore in the common case we need to copy 3 bytes to
  374. align, i.e. in the case of a loop, you wouldn't branch out early.*)
  375. rsb r3,r2,#0
  376. ands r3,r3,#3
  377. sub r12,r12,r3
  378. ldrneb r0,[r1],#1
  379. strneb r0,[r2],#1
  380. subnes r3,r3,#1
  381. ldrneb r0,[r1],#1
  382. strneb r0,[r2],#1
  383. subnes r3,r3,#1
  384. ldrneb r0,[r1],#1
  385. strneb r0,[r2],#1
  386. subnes r3,r3,#1
  387. .LDoneAlign:
  388. (* Destination should be aligned now, but source might not be aligned,
  389. if this is the case, do a byte-per-byte copy. *)
  390. tst r1,#3
  391. bne .LStartTailCopy
  392. (* Start the main copy, 32 bit at a time. *)
  393. movs r3,r12,lsr #2
  394. and r12,r12,#3
  395. beq .LStartTailCopy
  396. .LNext4bytes:
  397. (* Unrolling this loop would save a little bit of time for long strings
  398. (>20 chars), but alas, it hurts for short strings and they are the
  399. common case.*)
  400. ldrne r0,[r1],#4
  401. strne r0,[r2],#4
  402. subnes r3,r3,#1
  403. bne .LNext4bytes
  404. .LStartTailCopy:
  405. (* Do remaining bytes. *)
  406. cmp r12,#0
  407. beq .LDoneTail
  408. .LNextChar3:
  409. ldrb r0,[r1],#1
  410. strb r0,[r2],#1
  411. subs r12,r12,#1
  412. bne .LNextChar3
  413. .LDoneTail:
  414. end;
  415. {$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
  416. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  417. {$define FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  418. function fpc_Pchar_length(p:Pchar):sizeint;assembler;nostackframe;[public,alias:'FPC_PCHAR_LENGTH'];compilerproc;
  419. asm
  420. cmp r0,#0
  421. mov r1,r0
  422. beq .Ldone
  423. .Lnextchar:
  424. (*Are we aligned?*)
  425. tst r1,#3
  426. bne .Ltest_unaligned (*No, do byte per byte.*)
  427. ldr r3,.L01010101
  428. .Ltest_aligned:
  429. (*Aligned, load 4 bytes at a time.*)
  430. ldr r12,[r1],#4
  431. (*Check wether r12 contains a 0 byte.*)
  432. sub r2,r12,r3
  433. mvn r12,r12
  434. and r2,r2,r12
  435. ands r2,r2,r3,lsl #7 (*r3 lsl 7 = $80808080*)
  436. beq .Ltest_aligned (*No 0 byte, repeat.*)
  437. sub r1,r1,#4
  438. .Ltest_unaligned:
  439. ldrb r12,[r1],#1
  440. cmp r12,#1 (*r12<1 same as r12=0, but result in carry flag*)
  441. bcs .Lnextchar
  442. (*Dirty trick: we need to subtract 1 extra because we have counted the
  443. terminating 0, due to the known carry flag sbc can do this.*)
  444. sbc r0,r1,r0
  445. .Ldone:
  446. {$ifdef CPUARM_HAS_BX}
  447. bx lr
  448. {$else}
  449. mov pc,lr
  450. {$endif}
  451. .L01010101:
  452. .long 0x01010101
  453. end;
  454. {$endif}
  455. {$ifndef darwin}
  456. {$define FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
  457. Procedure fpc_ansistr_decr_ref (Var S : Pointer); [Public,Alias:'FPC_ANSISTR_DECR_REF'];assembler;nostackframe; compilerproc;
  458. asm
  459. ldr r1, [r0]
  460. // On return the pointer will always be set to zero, so utilize the delay slots
  461. mov r2, #0
  462. str r2, [r0]
  463. // Check for a zero string
  464. cmp r1, #0
  465. // Load reference counter
  466. ldrne r2, [r1, #-8]
  467. {$ifdef CPUARM_HAS_BX}
  468. bxeq lr
  469. {$else}
  470. moveq pc,lr
  471. {$endif}
  472. // Check for a constant string
  473. cmp r2, #0
  474. {$ifdef CPUARM_HAS_BX}
  475. bxlt lr
  476. {$else}
  477. movlt pc,lr
  478. {$endif}
  479. stmfd sp!, {r1, lr}
  480. sub r0, r1, #8
  481. {$ifdef CPUARM_HAS_BLX}
  482. blx InterLockedDecrement
  483. {$else}
  484. bl InterLockedDecrement
  485. {$endif}
  486. // InterLockedDecrement is a nice guy and sets the z flag for us
  487. // if the reference count dropped to 0
  488. ldmnefd sp!, {r1, pc}
  489. ldmfd sp!, {r0, lr}
  490. // We currently can not use constant symbols in ARM-Assembly
  491. // but we need to stay backward compatible with 2.6
  492. sub r0, r0, #12
  493. // Jump without a link, so freemem directly returns to our caller
  494. b FPC_FREEMEM
  495. end;
  496. {$define FPC_SYSTEM_HAS_ANSISTR_INCR_REF}
  497. Procedure fpc_ansistr_incr_ref (S : Pointer); [Public,Alias:'FPC_ANSISTR_INCR_REF'];assembler;nostackframe; compilerproc;
  498. asm
  499. // Null string?
  500. cmp r0, #0
  501. // Load reference counter
  502. ldrne r1, [r0, #-8]
  503. // pointer to counter, calculate here for delay slot utilization
  504. subne r0, r0, #8
  505. {$ifdef CPUARM_HAS_BX}
  506. bxeq lr
  507. {$else}
  508. moveq pc,lr
  509. {$endif}
  510. // Check for a constant string
  511. cmp r1, #0
  512. // Tailcall
  513. // Hopefully the linker will place InterLockedIncrement as layed out here
  514. bge InterLockedIncrement
  515. // Freepascal will generate a proper return here, save some cachespace
  516. end;
  517. {$endif not darwin}
  518. // --- InterLocked functions begin
  519. {$if not defined(CPUARM_HAS_LDREX) and not defined(SYSTEM_HAS_KUSER_CMPXCHG) }
  520. // Use generic interlock implementation
  521. var
  522. fpc_system_lock: longint;
  523. {$ifdef FPC_PIC}
  524. // Use generic interlock implementation with PIC
  525. // A helper function to get a pointer to fpc_system_lock in the PIC compatible way.
  526. function get_fpc_system_lock_ptr: pointer;
  527. begin
  528. get_fpc_system_lock_ptr:=@fpc_system_lock;
  529. end;
  530. {$endif FPC_PIC}
  531. {$endif}
  532. function InterLockedDecrement (var Target: longint) : longint; assembler; nostackframe;
  533. asm
  534. {$ifdef CPUARM_HAS_LDREX}
  535. .Lloop:
  536. ldrex r1, [r0]
  537. sub r1, r1, #1
  538. strex r2, r1, [r0]
  539. cmp r2, #0
  540. bne .Lloop
  541. movs r0, r1
  542. bx lr
  543. {$else}
  544. {$ifdef SYSTEM_HAS_KUSER_CMPXCHG}
  545. stmfd r13!, {lr}
  546. mov r2, r0 // kuser_cmpxchg does not clobber r2 by definition
  547. .Latomic_dec_loop:
  548. ldr r0, [r2] // Load the current value
  549. // We expect this to work without looping most of the time
  550. // R3 gets clobbered in kuser_cmpxchg so in the unlikely case that we have to
  551. // loop here again, we have to reload the value. Normaly this just fills the
  552. // load stall-cycles from the above ldr so in reality we'll not get any additional
  553. // delays because of this
  554. // Don't use ldr to load r3 to avoid cacheline trashing
  555. // Load 0xffff0fff into r3 and substract to 0xffff0fc0,
  556. // the kuser_cmpxchg entry point
  557. mvn r3, #0x0000f000
  558. sub r3, r3, #0x3F
  559. sub r1, r0, #1 // Decrement value
  560. {$ifdef CPUARM_HAS_BLX}
  561. blx r3 // Call kuser_cmpxchg, sets C-Flag on success
  562. {$else}
  563. mov lr, pc
  564. {$ifdef CPUARM_HAS_BX}
  565. bx r3
  566. {$else}
  567. mov pc, r3
  568. {$endif}
  569. {$endif}
  570. // MOVS sets the Z flag when the result reaches zero, this can be used later on
  571. // The C-Flag will not be modified by this because we're not doing any shifting
  572. movcss r0, r1 // We expect that to work most of the time so keep it pipeline friendly
  573. ldmcsfd r13!, {pc}
  574. b .Latomic_dec_loop // kuser_cmpxchg sets C flag on error
  575. {$else}
  576. // lock
  577. {$ifdef FPC_PIC}
  578. push {r0,lr}
  579. {$ifdef CPUARM_HAS_BLX}
  580. blx get_fpc_system_lock_ptr
  581. {$else}
  582. bl get_fpc_system_lock_ptr
  583. {$endif CPUARM_HAS_BLX}
  584. mov r3,r0
  585. pop {r0,lr}
  586. {$else FPC_PIC}
  587. ldr r3, .Lfpc_system_lock
  588. {$endif FPC_PIC}
  589. mov r1, #1
  590. .Lloop:
  591. swp r2, r1, [r3]
  592. cmp r2, #0
  593. bne .Lloop
  594. // do the job
  595. ldr r1, [r0]
  596. sub r1, r1, #1
  597. str r1, [r0]
  598. movs r0, r1
  599. // unlock and return
  600. str r2, [r3]
  601. {$ifdef CPUARM_HAS_BX}
  602. bx lr
  603. {$else}
  604. mov pc,lr
  605. {$endif}
  606. {$ifndef FPC_PIC}
  607. .Lfpc_system_lock:
  608. .long fpc_system_lock
  609. {$endif FPC_PIC}
  610. {$endif}
  611. {$endif}
  612. end;
  613. function InterLockedIncrement (var Target: longint) : longint; assembler; nostackframe;
  614. asm
  615. {$ifdef CPUARM_HAS_LDREX}
  616. .Lloop:
  617. ldrex r1, [r0]
  618. add r1, r1, #1
  619. strex r2, r1, [r0]
  620. cmp r2, #0
  621. bne .Lloop
  622. mov r0, r1
  623. bx lr
  624. {$else}
  625. {$ifdef SYSTEM_HAS_KUSER_CMPXCHG}
  626. stmfd r13!, {lr}
  627. mov r2, r0 // kuser_cmpxchg does not clobber r2 by definition
  628. .Latomic_inc_loop:
  629. ldr r0, [r2] // Load the current value
  630. // We expect this to work without looping most of the time
  631. // R3 gets clobbered in kuser_cmpxchg so in the unlikely case that we have to
  632. // loop here again, we have to reload the value. Normaly this just fills the
  633. // load stall-cycles from the above ldr so in reality we'll not get any additional
  634. // delays because of this
  635. // Don't use ldr to load r3 to avoid cacheline trashing
  636. // Load 0xffff0fff into r3 and substract to 0xffff0fc0,
  637. // the kuser_cmpxchg entry point
  638. mvn r3, #0x0000f000
  639. sub r3, r3, #0x3F
  640. add r1, r0, #1 // Increment value
  641. {$ifdef CPUARM_HAS_BLX}
  642. blx r3 // Call kuser_cmpxchg, sets C-Flag on success
  643. {$else}
  644. mov lr, pc
  645. {$ifdef CPUARM_HAS_BX}
  646. bx r3
  647. {$else}
  648. mov pc, r3
  649. {$endif}
  650. {$endif}
  651. movcs r0, r1 // We expect that to work most of the time so keep it pipeline friendly
  652. ldmcsfd r13!, {pc}
  653. b .Latomic_inc_loop // kuser_cmpxchg sets C flag on error
  654. {$else}
  655. // lock
  656. {$ifdef FPC_PIC}
  657. push {r0,lr}
  658. {$ifdef CPUARM_HAS_BLX}
  659. blx get_fpc_system_lock_ptr
  660. {$else}
  661. bl get_fpc_system_lock_ptr
  662. {$endif CPUARM_HAS_BLX}
  663. mov r3,r0
  664. pop {r0,lr}
  665. {$else FPC_PIC}
  666. ldr r3, .Lfpc_system_lock
  667. {$endif FPC_PIC}
  668. mov r1, #1
  669. .Lloop:
  670. swp r2, r1, [r3]
  671. cmp r2, #0
  672. bne .Lloop
  673. // do the job
  674. ldr r1, [r0]
  675. add r1, r1, #1
  676. str r1, [r0]
  677. mov r0, r1
  678. // unlock and return
  679. str r2, [r3]
  680. {$ifdef CPUARM_HAS_BX}
  681. bx lr
  682. {$else}
  683. mov pc,lr
  684. {$endif}
  685. {$ifndef FPC_PIC}
  686. .Lfpc_system_lock:
  687. .long fpc_system_lock
  688. {$endif FPC_PIC}
  689. {$endif}
  690. {$endif}
  691. end;
  692. function InterLockedExchange (var Target: longint;Source : longint) : longint; assembler; nostackframe;
  693. asm
  694. {$ifdef CPUARM_HAS_LDREX}
  695. // swp is deprecated on ARMv6 and above
  696. .Lloop:
  697. ldrex r2, [r0]
  698. strex r3, r1, [r0]
  699. cmp r3, #0
  700. bne .Lloop
  701. mov r0, r2
  702. bx lr
  703. {$else}
  704. {$ifdef SYSTEM_HAS_KUSER_CMPXCHG}
  705. stmfd r13!, {r4, lr}
  706. mov r2, r0 // kuser_cmpxchg does not clobber r2 (and r1) by definition
  707. .Latomic_add_loop:
  708. ldr r0, [r2] // Load the current value
  709. // We expect this to work without looping most of the time
  710. // R3 gets clobbered in kuser_cmpxchg so in the unlikely case that we have to
  711. // loop here again, we have to reload the value. Normaly this just fills the
  712. // load stall-cycles from the above ldr so in reality we'll not get any additional
  713. // delays because of this
  714. // Don't use ldr to load r3 to avoid cacheline trashing
  715. // Load 0xffff0fff into r3 and substract to 0xffff0fc0,
  716. // the kuser_cmpxchg entry point
  717. mvn r3, #0x0000f000
  718. sub r3, r3, #0x3F
  719. mov r4, r0 // save the current value because kuser_cmpxchg clobbers r0
  720. {$ifdef CPUARM_HAS_BLX}
  721. blx r3 // Call kuser_cmpxchg, sets C-Flag on success
  722. {$else}
  723. mov lr, pc
  724. {$ifdef CPUARM_HAS_BX}
  725. bx r3
  726. {$else}
  727. mov pc, r3
  728. {$endif}
  729. {$endif}
  730. // restore the original value if needed
  731. movcs r0, r4
  732. ldmcsfd r13!, {r4, pc}
  733. b .Latomic_add_loop // kuser_cmpxchg failed, loop back
  734. {$else}
  735. // lock
  736. {$ifdef FPC_PIC}
  737. push {r0,r1,lr}
  738. {$ifdef CPUARM_HAS_BLX}
  739. blx get_fpc_system_lock_ptr
  740. {$else}
  741. bl get_fpc_system_lock_ptr
  742. {$endif CPUARM_HAS_BLX}
  743. mov r3,r0
  744. pop {r0,r1,lr}
  745. {$else FPC_PIC}
  746. ldr r3, .Lfpc_system_lock
  747. {$endif FPC_PIC}
  748. mov r2, #1
  749. .Lloop:
  750. swp r2, r2, [r3]
  751. cmp r2, #0
  752. bne .Lloop
  753. // do the job
  754. ldr r2, [r0]
  755. str r1, [r0]
  756. mov r0, r2
  757. // unlock and return
  758. mov r2, #0
  759. str r2, [r3]
  760. {$ifdef CPUARM_HAS_BX}
  761. bx lr
  762. {$else}
  763. mov pc,lr
  764. {$endif}
  765. {$ifndef FPC_PIC}
  766. .Lfpc_system_lock:
  767. .long fpc_system_lock
  768. {$endif FPC_PIC}
  769. {$endif}
  770. {$endif}
  771. end;
  772. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; assembler; nostackframe;
  773. asm
  774. {$ifdef CPUARM_HAS_LDREX}
  775. .Lloop:
  776. ldrex r2, [r0]
  777. add r12, r1, r2
  778. strex r3, r12, [r0]
  779. cmp r3, #0
  780. bne .Lloop
  781. mov r0, r2
  782. bx lr
  783. {$else}
  784. {$ifdef SYSTEM_HAS_KUSER_CMPXCHG}
  785. stmfd r13!, {r4, lr}
  786. mov r2, r0 // kuser_cmpxchg does not clobber r2 by definition
  787. mov r4, r1 // Save addend
  788. .Latomic_add_loop:
  789. ldr r0, [r2] // Load the current value
  790. // We expect this to work without looping most of the time
  791. // R3 gets clobbered in kuser_cmpxchg so in the unlikely case that we have to
  792. // loop here again, we have to reload the value. Normaly this just fills the
  793. // load stall-cycles from the above ldr so in reality we'll not get any additional
  794. // delays because of this
  795. // Don't use ldr to load r3 to avoid cacheline trashing
  796. // Load 0xffff0fff into r3 and substract to 0xffff0fc0,
  797. // the kuser_cmpxchg entry point
  798. mvn r3, #0x0000f000
  799. sub r3, r3, #0x3F
  800. add r1, r0, r4 // Add to value
  801. {$ifdef CPUARM_HAS_BLX}
  802. blx r3 // Call kuser_cmpxchg, sets C-Flag on success
  803. {$else}
  804. mov lr, pc
  805. {$ifdef CPUARM_HAS_BX}
  806. bx r3
  807. {$else}
  808. mov pc, r3
  809. {$endif}
  810. {$endif}
  811. // r1 does not get clobbered, so just get back the original value
  812. // Otherwise we would have to allocate one more register and store the
  813. // temporary value
  814. subcs r0, r1, r4
  815. ldmcsfd r13!, {r4, pc}
  816. b .Latomic_add_loop // kuser_cmpxchg failed, loop back
  817. {$else}
  818. // lock
  819. {$ifdef FPC_PIC}
  820. push {r0,r1,lr}
  821. {$ifdef CPUARM_HAS_BLX}
  822. blx get_fpc_system_lock_ptr
  823. {$else}
  824. bl get_fpc_system_lock_ptr
  825. {$endif CPUARM_HAS_BLX}
  826. mov r3,r0
  827. pop {r0,r1,lr}
  828. {$else FPC_PIC}
  829. ldr r3, .Lfpc_system_lock
  830. {$endif FPC_PIC}
  831. mov r2, #1
  832. .Lloop:
  833. swp r2, r2, [r3]
  834. cmp r2, #0
  835. bne .Lloop
  836. // do the job
  837. ldr r2, [r0]
  838. add r1, r1, r2
  839. str r1, [r0]
  840. mov r0, r2
  841. // unlock and return
  842. mov r2, #0
  843. str r2, [r3]
  844. {$ifdef CPUARM_HAS_BX}
  845. bx lr
  846. {$else}
  847. mov pc,lr
  848. {$endif}
  849. {$ifndef FPC_PIC}
  850. .Lfpc_system_lock:
  851. .long fpc_system_lock
  852. {$endif FPC_PIC}
  853. {$endif}
  854. {$endif}
  855. end;
  856. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; assembler; nostackframe;
  857. asm
  858. {$ifdef CPUARM_HAS_LDREX}
  859. .Lloop:
  860. ldrex r3, [r0]
  861. mov r12, #0
  862. cmp r3, r2
  863. strexeq r12, r1, [r0]
  864. cmp r12, #0
  865. bne .Lloop
  866. mov r0, r3
  867. bx lr
  868. {$else}
  869. {$ifdef SYSTEM_HAS_KUSER_CMPXCHG}
  870. stmfd r13!, {r4, lr}
  871. mov r4, r2 // Swap parameters around
  872. mov r2, r0
  873. mov r0, r4 // Use r4 because we'll need the new value for later
  874. // r1 and r2 will not be clobbered by kuser_cmpxchg
  875. // If we have to loop, r0 will be set to the original Comperand
  876. // kuser_cmpxchg is documented to destroy r3, therefore setting
  877. // r3 must be in the loop
  878. .Linterlocked_compare_exchange_loop:
  879. mvn r3, #0x0000f000
  880. sub r3, r3, #0x3F
  881. {$ifdef CPUARM_HAS_BLX}
  882. blx r3 // Call kuser_cmpxchg, sets C-Flag on success
  883. {$else}
  884. mov lr, pc
  885. {$ifdef CPUARM_HAS_BX}
  886. bx r3
  887. {$else}
  888. mov pc, r3
  889. {$endif}
  890. {$endif}
  891. movcs r0, r4 // Return the previous value on success
  892. ldmcsfd r13!, {r4, pc}
  893. // The error case is a bit tricky, kuser_cmpxchg does not return the current value
  894. // So we may need to loop to avoid race conditions
  895. // The loop case is HIGHLY unlikely, it would require that we got rescheduled between
  896. // calling kuser_cmpxchg and the ldr. While beeing rescheduled another process/thread
  897. // would have the set the value to our comperand
  898. ldr r0, [r2] // Load the currently set value
  899. cmp r0, r4 // Return if Comperand != current value, otherwise loop again
  900. ldmnefd r13!, {r4, pc}
  901. // If we need to loop here, we have to
  902. b .Linterlocked_compare_exchange_loop
  903. {$else}
  904. // lock
  905. {$ifdef FPC_PIC}
  906. push {r0,r1,r2,lr}
  907. {$ifdef CPUARM_HAS_BLX}
  908. blx get_fpc_system_lock_ptr
  909. {$else}
  910. bl get_fpc_system_lock_ptr
  911. {$endif CPUARM_HAS_BLX}
  912. mov r12,r0
  913. pop {r0,r1,r2,lr}
  914. {$else FPC_PIC}
  915. ldr r12, .Lfpc_system_lock
  916. {$endif FPC_PIC}
  917. mov r3, #1
  918. .Lloop:
  919. swp r3, r3, [r12]
  920. cmp r3, #0
  921. bne .Lloop
  922. // do the job
  923. ldr r3, [r0]
  924. cmp r3, r2
  925. streq r1, [r0]
  926. mov r0, r3
  927. // unlock and return
  928. mov r3, #0
  929. str r3, [r12]
  930. {$ifdef CPUARM_HAS_BX}
  931. bx lr
  932. {$else}
  933. mov pc,lr
  934. {$endif}
  935. {$ifndef FPC_PIC}
  936. .Lfpc_system_lock:
  937. .long fpc_system_lock
  938. {$endif FPC_PIC}
  939. {$endif}
  940. {$endif}
  941. end;
  942. {$define FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
  943. function declocked(var l: longint) : boolean; inline;
  944. begin
  945. Result:=InterLockedDecrement(l) = 0;
  946. end;
  947. {$define FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
  948. procedure inclocked(var l: longint); inline;
  949. begin
  950. InterLockedIncrement(l);
  951. end;
  952. // --- InterLocked functions end
  953. procedure fpc_cpucodeinit;
  954. begin
  955. {$ifdef FPC_SYSTEM_FPC_MOVE}
  956. {$ifndef CPUARM_HAS_EDSP}
  957. cpu_has_edsp:=true;
  958. in_edsp_test:=true;
  959. asm
  960. bic r0,sp,#7
  961. ldrd r0,r1,[r0]
  962. end;
  963. in_edsp_test:=false;
  964. if cpu_has_edsp then
  965. moveproc:=@move_pld
  966. else
  967. moveproc:=@move_blended;
  968. {$else CPUARM_HAS_EDSP}
  969. cpu_has_edsp:=true;
  970. {$endif CPUARM_HAS_EDSP}
  971. {$endif FPC_SYSTEM_FPC_MOVE}
  972. end;
  973. {$define FPC_SYSTEM_HAS_SWAPENDIAN}
  974. { SwapEndian(<16 Bit>) being inlined is faster than using assembler }
  975. function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  976. begin
  977. { the extra Word type cast is necessary because the "AValue shr 8" }
  978. { is turned into "longint(AValue) shr 8", so if AValue < 0 then }
  979. { the sign bits from the upper 16 bits are shifted in rather than }
  980. { zeroes. }
  981. Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8));
  982. end;
  983. function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  984. begin
  985. Result := Word((AValue shr 8) or (AValue shl 8));
  986. end;
  987. (*
  988. This is kept for reference. Thats what the compiler COULD generate in these cases.
  989. But FPC currently does not support inlining of asm-functions, so the whole call-overhead
  990. is bigger than the gain of the optimized function.
  991. function AsmSwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif};assembler;nostackframe;
  992. asm
  993. // We're starting with 4321
  994. {$if defined(CPUARM_HAS_REV)}
  995. rev r0, r0 // Reverse byteorder r0 = 1234
  996. mov r0, r0, shr #16 // Shift down to 16bits r0 = 0012
  997. {$else}
  998. mov r0, r0, shl #16 // Shift to make that 2100
  999. mov r0, r0, ror #24 // Rotate to 1002
  1000. orr r0, r0, r0 shr #16 // Shift and combine into 0012
  1001. {$endif}
  1002. end;
  1003. *)
  1004. {
  1005. These used to be an assembler-function, but with newer improvements to the compiler this
  1006. generates a perfect 4 cycle code sequence and can be inlined.
  1007. }
  1008. function SwapEndian(const AValue: LongWord): LongWord;{$ifdef SYSTEMINLINE}inline;{$endif}
  1009. begin
  1010. Result:= AValue xor rordword(AValue,16);
  1011. Result:= Result and $FF00FFFF;
  1012. Result:= (Result shr 8) xor rordword(AValue,8);
  1013. end;
  1014. function SwapEndian(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  1015. begin
  1016. Result:=LongInt(SwapEndian(DWord(AValue)));
  1017. end;
  1018. {
  1019. Currently freepascal will not generate a good assembler sequence for
  1020. Result:=(SwapEndian(longword(lo(AValue))) shl 32) or
  1021. (SwapEndian(longword(hi(AValue))));
  1022. So we keep an assembly version for now
  1023. }
  1024. function SwapEndian(const AValue: Int64): Int64; assembler; nostackframe;
  1025. asm
  1026. // fpc >2.6.0 adds the "rev" instruction in the internal assembler
  1027. {$if defined(CPUARM_HAS_REV)}
  1028. rev r2, r0
  1029. rev r0, r1
  1030. mov r1, r2
  1031. {$else}
  1032. mov ip, r1
  1033. // We're starting with r0 = $87654321
  1034. eor r1, r0, r0, ror #16 // r1 = $C444C444
  1035. bic r1, r1, #16711680 // r1 = r1 and $ff00ffff = $C400C444
  1036. mov r0, r0, ror #8 // r0 = $21876543
  1037. eor r1, r0, r1, lsr #8 // r1 = $21436587
  1038. eor r0, ip, ip, ror #16
  1039. bic r0, r0, #16711680
  1040. mov ip, ip, ror #8
  1041. eor r0, ip, r0, lsr #8
  1042. {$endif}
  1043. end;
  1044. function SwapEndian(const AValue: QWord): QWord; {$ifdef SYSTEMINLINE}inline;{$endif}
  1045. begin
  1046. Result:=QWord(SwapEndian(Int64(AValue)));
  1047. end;
  1048. {$ifndef FPC_SYSTEM_HAS_MEM_BARRIER}
  1049. {$define FPC_SYSTEM_HAS_MEM_BARRIER}
  1050. { Generic read/readwrite barrier code. }
  1051. procedure barrier; assembler; nostackframe;
  1052. asm
  1053. // manually encode the instructions to avoid bootstrap and -march external
  1054. // assembler settings
  1055. {$ifdef CPUARM_HAS_DMB}
  1056. .long 0xf57ff05f // dmb sy
  1057. {$else CPUARM_HAS_DMB}
  1058. {$ifdef CPUARMV6}
  1059. mov r0, #0
  1060. .long 0xee070fba // mcr 15, 0, r0, cr7, cr10, {5}
  1061. {$else CPUARMV6}
  1062. {$ifdef SYSTEM_HAS_KUSER_MEMORY_BARRIER}
  1063. stmfd r13!, {lr}
  1064. mvn r0, #0x0000f000
  1065. sub r0, r0, #0x5F
  1066. {$ifdef CPUARM_HAS_BLX}
  1067. blx r0 // Call kuser_memory_barrier at address 0xffff0fa0
  1068. {$else CPUARM_HAS_BLX}
  1069. mov lr, pc
  1070. {$ifdef CPUARM_HAS_BX}
  1071. bx r0
  1072. {$else CPUARM_HAS_BX}
  1073. mov pc, r0
  1074. {$endif CPUARM_HAS_BX}
  1075. {$endif CPUARM_HAS_BLX}
  1076. ldmfd r13!, {pc}
  1077. {$endif SYSTEM_HAS_KUSER_MEMORY_BARRIER}
  1078. {$endif CPUARMV6}
  1079. {$endif CPUARM_HAS_DMB}
  1080. end;
  1081. procedure ReadBarrier;{$ifdef SYSTEMINLINE}inline;{$endif}
  1082. begin
  1083. barrier;
  1084. end;
  1085. procedure ReadDependencyBarrier;{$ifdef SYSTEMINLINE}inline;{$endif}
  1086. begin
  1087. { reads imply barrier on earlier reads depended on; not required on ARM }
  1088. end;
  1089. procedure ReadWriteBarrier;{$ifdef SYSTEMINLINE}inline;{$endif}
  1090. begin
  1091. barrier;
  1092. end;
  1093. procedure WriteBarrier; assembler; nostackframe;
  1094. asm
  1095. // specialize the write barrier because according to ARM, implementations for
  1096. // "dmb st" may be more optimal than the more generic "dmb sy"
  1097. {$ifdef CPUARM_HAS_DMB}
  1098. .long 0xf57ff05e // dmb st
  1099. {$else CPUARM_HAS_DMB}
  1100. {$ifdef CPUARMV6}
  1101. mov r0, #0
  1102. .long 0xee070fba // mcr 15, 0, r0, cr7, cr10, {5}
  1103. {$else CPUARMV6}
  1104. {$ifdef SYSTEM_HAS_KUSER_MEMORY_BARRIER}
  1105. stmfd r13!, {lr}
  1106. mvn r0, #0x0000f000
  1107. sub r0, r0, #0x5F
  1108. {$ifdef CPUARM_HAS_BLX}
  1109. blx r0 // Call kuser_memory_barrier at address 0xffff0fa0
  1110. {$else CPUARM_HAS_BLX}
  1111. mov lr, pc
  1112. {$ifdef CPUARM_HAS_BX}
  1113. bx r0
  1114. {$else CPUARM_HAS_BX}
  1115. mov pc, r0
  1116. {$endif CPUARM_HAS_BX}
  1117. {$endif CPUARM_HAS_BLX}
  1118. ldmfd r13!, {pc}
  1119. {$endif SYSTEM_HAS_KUSER_MEMORY_BARRIER}
  1120. {$endif CPUARMV6}
  1121. {$endif CPUARM_HAS_DMB}
  1122. end;
  1123. {$endif}
  1124. {include hand-optimized assembler division code}
  1125. {$i divide.inc}