1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 2002-2004 by the Free Pascal development team.
Processor dependent implementation for the system unit for
Sparc
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{****************************************************************************
SPARC specific stuff
****************************************************************************}
function get_fsr : dword;assembler;nostackframe;[public, alias: 'FPC_GETFSR'];
var
fsr : dword;
asm
st %fsr,fsr
ld fsr,%o0
end;
procedure set_fsr(fsr : dword);assembler;[public, alias: 'FPC_SETFSR'];
var
_fsr : dword;
asm
// force memory location
st fsr,_fsr
ld _fsr,%fsr
end;
function get_got : pointer;assembler;nostackframe;[public, alias: 'FPC_GETGOT'];
asm
retl
add %o7,%l7,%l7
end;
{$define FPC_SYSTEM_HAS_SYSINITFPU}
Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
{ enable div by 0 and invalid operation fpu exceptions
round towards zero; ieee compliant arithmetics }
set_fsr((get_fsr and $3fbfffff) or $09000000);
end;
{$define FPC_SYSTEM_HAS_SYSRESETFPU}
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
softfloat_exception_flags:=0;
end;
procedure fpc_cpuinit;
begin
SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
end;
{$define FPC_SYSTEM_HAS_GET_FRAME}
function get_frame:pointer;assembler;nostackframe;
asm
mov %fp,%o0
end;
{$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
function get_caller_addr(framebp:pointer):pointer;assembler;nostackframe;
asm
{ framebp = %o0 }
subcc %o0,0,%o0
be .Lframezero
nop
{ flush register windows, so they are stored in the stack }
ta 3
ld [%o0+60],%o0
{ add 8 to skip jmpl and delay slot }
add %o0,8,%o0
.Lframezero:
end;
{$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
function get_caller_frame(framebp:pointer):pointer;assembler;nostackframe;
asm
{ framebp = %o0 }
subcc %o0,0,%o0
be .Lframezero
nop
{ flush register windows, so they are stored in the stack }
ta 3
ld [%o0+56],%o0
.Lframezero:
end;
{$define FPC_SYSTEM_HAS_SPTR}
function Sptr:Pointer;assembler;nostackframe;
asm
mov %sp,%o0
end;
{$ifndef FPC_SYSTEM_HAS_MOVE}
{$define FPC_SYSTEM_HAS_MOVE}
procedure Move(const source;var dest;count:longint);[public, alias: 'FPC_MOVE'];assembler;
{
Registers:
%l0 temp. to do copying
%l1 inc/decrement
%l2/l3/l4/l5 qword move
}
asm
// count < 0 ?
cmp %g0,%i2
bge .Lmoveexit
nop
// possible overlap?
cmp %i0,%i1
bcc .Lnopossibleoverlap
nop
// source < dest ....
add %i0,%i2,%l0
// overlap?
cmp %l0,%i1
// source+count < dest ?
bcs .Lnopossibleoverlap
nop
.Lcopybackward:
// check alignment of source and dest
or %i0,%i1,%l0
// move src and dest to the end of the blocks
// assuming 16 byte block size
sub %i2,1,%l1
add %i0,%l1,%i0
add %i1,%l1,%i1
{
// everything 16 byte aligned ?
andcc %l0,15,%l0
be .Lmovetwordwise
// load direction in delay slot
mov -16,%l1
// adjust according to block size
add %i0,8,%i0
add %i1,8,%i1
andcc %l0,7,%l0
be .Lmoveqwordwise
mov -8,%l1
// adjust according to block size
add %i0,4,%i0
add %i1,4,%i1
andcc %l0,3,%l0
be .Lmovedwordwise
mov -4,%l1
// adjust according to block size
add %i0,2,%i0
add %i1,2,%i1
andcc %l0,1,%l0
be .Lmovewordwise
mov -2,%l1
// adjust according to block size
add %i0,1,%i0
add %i1,1,%i1
}
ba .Lmovebytewise
mov -1,%l1
.Lnopossibleoverlap:
// check alignment of source and dest
or %i0,%i1,%l0
// everything 16 byte aligned ?
andcc %l0,15,%l0
be .Lmovetwordwise
// load direction in delay slot
mov 16,%l1
andcc %l0,7,%l0
be .Lmoveqwordwise
mov 8,%l1
andcc %l0,3,%l0
be .Lmovedwordwise
mov 4,%l1
andcc %l0,1,%l0
be .Lmovewordwise
mov 2,%l1
ba .Lmovebytewise
mov 1,%l1
.Lmovetwordwise:
srl %i2,4,%l6
cmp %g0,%l6
sll %l6,4,%l7
be .Lmoveqwordwise_shift
nop
.Lmovetwordwise_loop:
ld [%i0],%l2
ld [%i0+4],%l3
subcc %l6,1,%l6
ld [%i0+8],%l4
ld [%i0+12],%l5
add %i0,%l1,%i0
st %l2,[%i1]
st %l3,[%i1+4]
st %l4,[%i1+8]
st %l5,[%i1+12]
add %i1,%l1,%i1
bne .Lmovetwordwise_loop
nop
subcc %i2,%l7,%i2
be .Lmoveexit
nop
.Lmoveqwordwise_shift:
sra %l1,1,%l1
.Lmoveqwordwise:
srl %i2,3,%l6
cmp %g0,%l6
sll %l6,3,%l7
be .Lmovedwordwise_shift
nop
.Lmoveqwordwise_loop:
ld [%i0],%l2
ld [%i0+4],%l3
subcc %l6,1,%l6
add %i0,%l1,%i0
st %l2,[%i1]
st %l3,[%i1+4]
add %i1,%l1,%i1
bne .Lmoveqwordwise_loop
nop
subcc %i2,%l7,%i2
be .Lmoveexit
nop
.Lmovedwordwise_shift:
sra %l1,1,%l1
.Lmovedwordwise:
srl %i2,2,%l6
cmp %g0,%l6
sll %l6,2,%l7
be .Lmovewordwise_shift
nop
.Lmovedwordwise_loop:
ld [%i0],%l0
subcc %l6,1,%l6
add %i0,%l1,%i0
st %l0,[%i1]
add %i1,%l1,%i1
bne .Lmovedwordwise_loop
nop
subcc %i2,%l7,%i2
be .Lmoveexit
nop
.Lmovewordwise_shift:
sra %l1,1,%l1
.Lmovewordwise:
srl %i2,1,%l6
cmp %g0,%l6
sll %l6,1,%l7
be .Lmovebytewise_shift
nop
.Lmovewordwise_loop:
lduh [%i0],%l0
subcc %l6,1,%l6
add %i0,%l1,%i0
sth %l0,[%i1]
add %i1,%l1,%i1
bne .Lmovewordwise_loop
nop
subcc %i2,%l7,%i2
be .Lmoveexit
nop
.Lmovebytewise_shift:
sra %l1,1,%l1
.Lmovebytewise:
cmp %g0,%i2
be .Lmoveexit
nop
ldub [%i0],%l0
subcc %i2,1,%i2
add %i0,%l1,%i0
stb %l0,[%i1]
add %i1,%l1,%i1
bne .Lmovebytewise
nop
.Lmoveexit:
end;
{$endif FPC_SYSTEM_HAS_MOVE}
{****************************************************************************
Integer math
****************************************************************************}
{$define FPC_SYSTEM_HAS_ABS_LONGINT}
function abs(l:longint):longint; assembler;{$ifdef SYSTEMINLINE}inline;{$endif}nostackframe;
asm
sra %o0,31,%g1
add %o0,%g1,%o0
xor %o0,%g1,%o0
end;
var
fpc_system_lock : byte;export name 'fpc_system_lock';
{$define FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
function declocked(var l : longint) : boolean;assembler;nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
.Ldeclocked1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .Ldeclocked1
nop
ld [%o0],%g1
sub %g1,1,%g1
st %g1,[%o0]
subcc %g1,1,%g0
addx %g0,%g0,%o0
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
{$define FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
procedure inclocked(var l : longint);assembler;nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
.Linclocked1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .Linclocked1
nop
ld [%o0],%g1
add %g1,1,%g1
st %g1,[%o0]
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
function InterLockedDecrement (var Target: longint) : longint; assembler; nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
.LInterLockedDecrement1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .LInterLockedDecrement1
nop
ld [%o0],%g1
sub %g1,1,%g1
st %g1,[%o0]
mov %g1,%o0
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
function InterLockedIncrement (var Target: longint) : longint; assembler; nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
.LInterLockedIncrement1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .LInterLockedIncrement1
nop
ld [%o0],%g1
add %g1,1,%g1
st %g1,[%o0]
mov %g1,%o0
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
function InterLockedExchange (var Target: longint;Source : longint) : longint; assembler; nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
.LInterLockedExchange1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .LInterLockedExchange1
nop
ld [%o0],%g1
st %o1,[%o0]
mov %g1,%o0
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; assembler; nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
.LInterLockedExchangeAdd1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .LInterLockedExchangeAdd1
nop
ld [%o0],%g1
add %g1,%o1,%o1
st %o1,[%o0]
mov %g1,%o0
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; assembler; nostackframe;
asm
{ usually, we shouldn't lock here so saving the stack frame for these extra intructions is
worse the effort, especially while waiting :)
}
{ input: address of target in o0, newvalue in o1, comparand in o2 }
{ output: value stored in target before entry of the function }
{ side-effect: NewValue stored in target if (target = comparand) }
.LInterlockedCompareExchange1:
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
ldstub [%g1],%g1
cmp %g1,0
bne .LInterlockedCompareExchange1
nop
ld [%o0],%g1
cmp %g1,%o2
bne .LInterlockedCompareExchange2
nop
st %o1,[%o0]
.LInterlockedCompareExchange2:
mov %g1,%o0
{ unlock }
sethi %hi(fpc_system_lock), %g1
or %g1,%lo(fpc_system_lock), %g1
stb %g0,[%g1]
end;
{$ifndef FPC_SYSTEM_HAS_MEM_BARRIER}
{$define FPC_SYSTEM_HAS_MEM_BARRIER}
const
LoadLoad = $01;
StoreLoad = $02;
LoadStore = $04;
StoreStore = $08;
LookAside = $10;
MemIssue = $20;
Sync = $40;
procedure ReadBarrier;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
asm
{$ifdef FPC_HAS_MEMBAR}
ba,pt .L1
membar LoadLoad
.L1:
{$endif}
end;
procedure ReadDependencyBarrier;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{ reads imply barrier on earlier reads depended on }
end;
procedure ReadWriteBarrier;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
asm
{$ifdef FPC_HAS_MEMBAR}
ba,pt .L1
membar LoadLoad + LoadStore + StoreLoad + StoreStore
.L1:
{$endif}
end;
procedure WriteBarrier;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
asm
{$ifdef FPC_HAS_MEMBAR}
ba,pt .L1
stbar
.L1:
{$endif}
end;
{$endif}
|