-
Notifications
You must be signed in to change notification settings - Fork 3
/
ppcgen.e
5167 lines (4720 loc) · 138 KB
/
ppcgen.e
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-> ECX/ppcgen.e
/* ECX by Leif Salomonsson [ecx tele2 se] is Copyright (c) 2002-2008 */
/* Released under the ECX COMPILER LICENSE, See ECXCOMPILERLICENSE.TXT */
OPT MODULE
OPT PREPROCESS
OPT LARGE
-> May 2008, ppcgen.e created, extracted from codegen.e.
->#define DBG_PPCGEN
MODULE '*codegen'
MODULE '*compiler'
MODULE '*support'
MODULE '*common'
MODULE '*assembler'
MODULE '*opcodes68'
MODULE '*opcodesppc'
MODULE '*binary'
MODULE '*inlineppc'
MODULE '*runtime'
MODULE 'exec/lists'
#define PPCEQ 12,2
#define PPCNE 4,2
#define PPCLT 12,0
#define PPCGT 12,1
#define PPCLE 4,1
#define PPCGE 4,0
#define DOSICBICOPTI
#define USEMULDIVSHIFT
EXPORT DEF g_codeptr:PTR TO LONG,
g_codebuf,
g_currentproc:PTR TO proc,
g_rwreflist:PTR TO rwref,
g_globalsize,
g_databuf:PTR TO LONG, -> for rw init
g_databufsize,
g_numregalloc,
g_numfregalloc,
g_stacksize,
g_gvarlist:PTR TO gvar,
g_regusetab:PTR TO oreg,
g_modulelist:PTR TO mlh, -> for glob/rw init
link_globaldatasize -> for glob init
EXPORT DEF g_od:PTR TO LONG, g_punct -> shared with inline.e
EXPORT DEF g_lastx:PTR TO lastx
DEF g_exceptlab:PTR TO codelab
DEF g_endexceptlab:PTR TO codelab
DEF g_procendlab:PTR TO codelab
DEF g_localstackoffset:PTR TO LONG -> ppc only
DEF g_localstackstart -> ppc only
-> v2.3
DEF g_d64bottom, g_lastd64
EXPORT DEF g_optroundnear, g_optmodule,g_optosid
EXPORT DEF
g_dreg, -> RX/DRX
g_areg, -> RX/ARX
g_freg, -> FPX
g_vreg, -> VX
g_d64reg, -> D64 v55
g_ireg0, -> R3/D0 (non obtainable)
g_ireg1, -> R4/D1
g_freg0, -> FP1, F1
g_stackreg, -> R1/A7 (non obtainable, dedicated)
g_selfreg, -> R12/A0
g_globreg, -> R13/A4 (non obtainable, dedicated)
g_framereg, -> R1/A5 (non obtainable, dedicated)
g_atemp, -> R11/A6 (non obtainable)
g_dtemp, -> R12/D3 (non obtain)
g_ftemp, -> FP0/F0 (non obtain)
g_d64temp -> v55
EXPORT DEF g_sizeofptr
EXPORT DEF g_multireturn:PTR TO multireturn
EXPORT OBJECT ppc OF codegen
lasttempREG
lasttempFREG
lasttempVREG
tempvecstackofs -> v48 for vectors starting at localstack-bottom.. not used yet
p_esoffset -> exceptstruct offset on stack
lif_private_i2f:PTR TO lif -> v51 points to I_2_F lif
-> 1.10.0
lif_private_d642f:PTR TO lif
lif_private_f2d64:PTR TO lif
lif_private_shl64:PTR TO lif
lif_private_shr64:PTR TO lif
lif_private_asr64:PTR TO lif
lif_private_div64:PTR TO lif
ENDOBJECT
EXPORT OBJECT ppcsysv OF ppc
ENDOBJECT
PROC init() OF ppcsysv
DREG := RX
AREG := RX
FREG := FPX
VREG := VX
D64REG := D64
IREG0 := 3 -> r3
IREG1 := 4 -> r4
FREG0 := 1
STACKREG := 1 -> stack
SELFREG := 12 -> self arg
GLOBREG := 13 -> global reg
FRAMEREG := 1 -> frameptr (same as stack)
ATEMP := 11 -> non obtainable ptr scratch
DTEMP := 12 -> v50, same as selfreg
FTEMP := 0 -> v50
D64TEMP := 0 -> is set by self.doprochead()
self.lasttempREG := 3
self.lasttempFREG := 1
self.lasttempVREG := 2
ENDPROC
PROC putInit(globalsize, ivarsize) OF ppc
#ifdef DBG_PPCGEN
DEBUGF('putPPCInit()\n')
#endif
ppcmfspr(12,8) -> mflr r12
putRWInit()
ppcaddi(3,3,ivarsize)
ppcor(3,GLOBREG,3,0) -> R13 is set up!
ppcaddi(3,3,globalsize)
self.putGlobInit()
putModulesInit()
ppcmtspr(12,8) -> mtlr r12
ppcbclr(20,0,0) -> blr, returns endofglobdata in r3
ENDPROC
PROC putModulesInit()
DEF mod:PTR TO moduleheader, info:PTR TO modinfo, t
mod := g_modulelist.head
WHILE mod.succ
info := IF mod.headsize < 160 THEN NIL ELSE mod.globinitinfo
IF info
IF mod.cpu <> CPU_PPC THEN reportErr('init code cpu mismatch for module', mod.mname)
info := info + mod
t := Div(info.misc - currentOffset(), 4)
ppcb(t, 0, 1) -> bl
ENDIF
mod := mod.succ
ENDWHILE
ENDPROC
PROC putRWInit()
DEF mod:PTR TO moduleheader
DEF offset:PTR TO LONG
DEF info:PTR TO modinfo
DEF a
DEF t
DEF lptr:PTR TO LONG
-> init rw-data !
ppcaddi(4,0,-1)
ppcaddi(5,0,1)
ppcaddi(6,0,2)
ppcaddi(7,0,3)
ppcaddi(8,0,4)
ppcaddi(9,0,8)
offset := 0
mod := g_modulelist.head
WHILE mod.succ
info := mod.datainfo
IF info
info := info + mod
lptr := info + SIZEOF modinfo
a := info.count+1
WHILE a--
t := lptr[]++
SELECT t
CASE 0 ; offset++
CASE -1 ; ppcstw(4,3,offset++)
CASE 1 ; ppcstw(5,3,offset++)
CASE 2 ; ppcstw(6,3,offset++)
CASE 3 ; ppcstw(7,3,offset++)
CASE 4 ; ppcstw(8,3,offset++)
CASE 8 ; ppcstw(9,3,offset++)
DEFAULT
IF t AND $FFFF = NIL
ppcaddis(10,0,Shr(t,16) AND $FFFF)
ELSE
ppcliw(10,t)
ENDIF
ppcstw(10,3,offset++)
ENDSELECT
IF offset = $7FFC
ppcaddi(3,3,$7FFC)
offset := 0
ENDIF
ENDWHILE
ENDIF
mod := mod.succ
ENDWHILE
lptr := g_databuf
a := Shr(g_databufsize, 2) + 1
WHILE a--
t := lptr[]++
SELECT t
CASE 0 ; offset++
CASE -1 ; ppcstw(4,3,offset++)
CASE 1 ; ppcstw(5,3,offset++)
CASE 2 ; ppcstw(6,3,offset++)
CASE 3 ; ppcstw(7,3,offset++)
CASE 4 ; ppcstw(8,3,offset++)
CASE 8 ; ppcstw(9,3,offset++)
DEFAULT
IF t AND $FFFF = NIL
ppcaddis(10,0,Shr(t,16) AND $FFFF)
ELSE
ppcliw(10,t)
ENDIF
ppcstw(10,3,offset++)
ENDSELECT
IF offset = $7FFC
ppcaddi(3,3,$7FFC)
offset := 0
ENDIF
ENDWHILE
ppcaddi(3,3,offset)
ENDPROC
-> 2.2 now called directly from main if in module mode
PROC putGlobInit() OF ppc
DEF gvar:PTR TO gvar
-> initialise user globals
gvar := g_gvarlist
WHILE gvar
link_globaldatasize := link_globaldatasize + initGvar(gvar)
gvar := gvar.next
ENDWHILE
IF g_optmodule THEN ppcbclr(20,0,0) -> blr
ENDPROC
#define ToGlobal(r) IF gvar.link THEN ppcstwlab(r,GLOBREG,gvar) ELSE ppcstw(r,GLOBREG,gvar.offset)
#define ToGlobalD(r) IF gvar.link THEN ppcstfdlab(r,GLOBREG,gvar) ELSE ppcstfd(r,GLOBREG,gvar.offset)
PROC initGvar(gvar:PTR TO gvar)
DEF t, t2, globaldatasize=0
IF gvar.type.numes
SELECT 256 OF gvar.type.esize
CASE 1
IF gvar.cmplx -> STRING
globaldatasize := 4 + (t := gvar.type.numes + 1 + 3 AND $FFFFFC)
ppcaddis(0,0,gvar.type.numes)
ppcstw(0,3,0)
ppcaddi(3,3,4)
ToGlobal(3)
-> memory is cleared already ->ppcstb(0,3,4) -> nilterm
ppcaddi(3,3,t)
ELSE -> ARRAY OF CHAR
globaldatasize := (t := gvar.type.numes + 3 AND $FFFFFC)
ToGlobal(3)
ppcaddiw(3,3,t)
ENDIF
CASE 2 -> ARRAY OF INT
globaldatasize := (t := gvar.type.numes * 2 + 3 AND $FFFFFC)
ToGlobal(3)
ppcaddiw(3,3,t)
CASE 4
IF gvar.cmplx -> LIST
globaldatasize := 4 + (t := gvar.type.numes * 4)
ppcaddis(0,0,gvar.type.numes)
ppcstw(0,3,0)
ppcaddi(3,3,4)
ToGlobal(3)
ppcaddiw(3,3,t)
ELSE -> ARRAY OF LONG
globaldatasize := (t := gvar.type.numes * 4)
ToGlobal(3)
ppcaddiw(3,3,t)
ENDIF
CASE 8
globaldatasize := (t := gvar.type.numes * 8)
ToGlobal(3)
ppcaddiw(3,3,t)
CASE 255 -> (ARRAY OF) OBJECT
IF gvar.type.object.nrofmethods THEN addWarning('methods will not be installed for global')
globaldatasize := (t := gvar.type.numes *
gvar.type.object.sizeof + 3 AND $FFFFFC)
ToGlobal(3)
ppcaddiw(3,3,t)
ENDSELECT
ELSEIF gvar.defo
IF gvar.type.size = 4
ppcliw(10,gvar.defd)
ToGlobal(10)
ELSEIF gvar.type.flags AND MEMBF_FLOAT -> double
ppcliw(10,gvar.defd)
ppcstw(10,1,-4)
ppclfs(0,1,-4)
ToGlobalD(0)
ELSE -> 2.2: forgotten WIDE
ppcliw(10,gvar.defd)
ppcstw(10, 1, -4)
ppcsrawi(10, 10, 31, 0)
ppcstw(10, 1, -8)
ppclfd(0, 1, -8)
ToGlobalD(0)
ENDIF
ENDIF
ENDPROC globaldatasize
PROC abiArgs(array:PTR TO LONG, numargs, flags) OF ppcsysv
DEF va:PTR TO arg, a, rnum=3, fnum=1, sofs=8:PTR TO LONG, vnum=2
FOR a := 0 TO numargs-1
va := array[a]
IF va.type.size = 4
IF rnum < 11
va.rtype := PPCARGRTYPE_RX
va.rnum := rnum++
ELSE
va.rtype := PPCARGRTYPE_STACKRX
va.rnum := sofs++
ENDIF
ELSEIF va.type.size = 8
IF va.type.flags AND MEMBF_FLOAT
IF fnum < 9
va.rtype := PPCARGRTYPE_FX
va.rnum := fnum++
ELSE
reportErr('too many REAL arguments for procedure (bug author)')
ENDIF
ELSE -> 1.10.0
IF rnum > 9
va.rtype := PPCARGRTYPE_STACKRX2
va.rnum := sofs++
sofs++
ELSE
va.rtype := PPCARGRTYPE_RX2
va.rnum := rnum
rnum := rnum + 2
ENDIF
ENDIF
ELSEIF va.type.size = 16
IF vnum < 13
va.rtype := PPCARGRTYPE_VX
va.rnum := vnum++
ELSE
reportErr('too many VECTOR arguments for procedure (bug author)')
ENDIF
ENDIF
ENDFOR
ENDPROC
PROC abiReturns(mret:PTR TO multireturn) OF ppcsysv
DEF reg=3, freg=1, vreg=2, t
t := mret.ros[0]
SELECT t
CASE DREG ; mret.rds[0] := reg++
CASE FREG ; mret.rds[0] := freg++
CASE VREG ; mret.rds[0] := vreg++
CASE X2R ; mret.rds[0] := reg++ ; reg++ -> 1.10.0
DEFAULT ; reportIErr('ppcsysv.abiReturns 0 t=?')
ENDSELECT
t := mret.ros[1]
SELECT t
CASE DREG ; mret.rds[1] := reg++
CASE FREG ; mret.rds[1] := freg++
CASE VREG ; mret.rds[1] := vreg++
CASE X2R ; mret.rds[1] := reg++ ; reg++ -> 1.10.0
DEFAULT ; reportIErr('ppcsysv.abiReturns 1 t=?')
ENDSELECT
t := mret.ros[2]
SELECT t
CASE DREG ; mret.rds[2] := reg++
CASE FREG ; mret.rds[2] := freg++
CASE VREG ; mret.rds[2] := vreg++
CASE X2R ; mret.rds[2] := reg++ ; reg++ -> 1.10.0
DEFAULT ; reportIErr('ppcsysv.abiReturns 2 t=?')
ENDSELECT
t := mret.ros[3]
SELECT t
CASE DREG ; mret.rds[3] := reg++
CASE FREG ; mret.rds[3] := freg++
CASE VREG ; mret.rds[3] := vreg++
CASE X2R ; mret.rds[3] := reg++ ; reg++ -> 1.10.0
DEFAULT ; reportIErr('ppcsysv.abiReturns 3 t=?')
ENDSELECT
ENDPROC
-> v50, now uses new parameterpassing
-> v55, wide args
PROC doProcfunc(buf:PTR TO item, meth=NIL:PTR TO proc) OF ppc
DEF n:PTR TO item, hln:PTR TO hln, proc:PTR TO proc
DEF regusecopy[REGUSETABSIZE]:ARRAY OF oreg -> v44, 49
DEF a, as, as2, param:PTR TO var
DEF stub:PTR TO codelab, endstub:PTR TO codelab
DEF nrofparams, t:PTR TO LONG
DEF o,d, var:PTR TO var, float
DEF argtype
DEF it_funccall:PTR TO it_funccall
DEF ro, rd
DEF ha:hintargs, noraise
ha.hregisvar := FALSE
it_funccall := buf.info
hln := it_funccall.data ->n.info
nrofparams := it_funccall.numpars ->buf.num
n := it_funccall + SIZEOF it_funccall ->n++ -> skip label
#ifdef DBG_PPCGEN
DEBUGF('dofunction() \s \n', hln.name)
#endif
IF meth = NIL
self.saveObtained(regusecopy)
proc := hln.ident
IF proc = NIL THEN reportErr('unknown function', hln.name)
proc.referenced := 1
ELSE
proc := meth
ENDIF
IF nrofparams > proc.nrofargs THEN reportErr('too many parameters for procedure', proc.name)
IF (nrofparams+proc.nrofdefaults) < proc.nrofargs THEN reportErr('too few parameters for procedure', proc.name)
/* evaluate expressions and put on stack or in register */
FOR a := 0 TO nrofparams-1
param := proc.argarray[a]
IF param.rtype = PPCARGRTYPE_STACKRX -> put in parameter store area ?
n, o, d := self.doExpression(n)
inst_copy(o,d, DREG,DTEMP)
inst_copy(DREG,DTEMP, ARXPO,AxSizeOfs(1,PTRSIZE,param.rnum))
ELSEIF param.rtype = PPCARGRTYPE_RX
ha.hregop := DREG
ha.hregnum := param.rnum
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, RX,param.rnum)
self.copyObtainToDREG(RX,param.rnum) -> put obtain on register
ELSEIF param.rtype = PPCARGRTYPE_FX
ha.hregop := FREG
ha.hregnum := param.rnum
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, FPX,param.rnum)
self.copyObtainToFREG(FPX,param.rnum) -> put obtain on register
ELSEIF param.rtype = PPCARGRTYPE_RX2 -> 2.0.0 WIDE/X2R
n, o, d := self.doExpression(n)
->inst_copy(o,d, D64,D64TEMP)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP), RX, param.rnum)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP+4), RX, param.rnum+1)
self.tox2r(o,d,param.rnum)
self.copyObtainToDREG(RX,param.rnum) -> put obtain on register
self.copyObtainToDREG(RX,param.rnum+1) -> put obtain on register
ELSEIF param.rtype = PPCARGRTYPE_STACKRX2
n, o, d := self.doExpression(n)
inst_copy(o,d, D64,param.rnum) -> clever eh !
ENDIF
ENDFOR
-> should we put some defaults ?
IF proc.nrofargs > nrofparams
a := nrofparams
WHILE a < proc.nrofargs
param := proc.argarray[a]
IF param.rtype = PPCARGRTYPE_RX
inst_copy(DV,param.defd, RX,param.rnum)
self.copyObtainToDREG(RX,param.rnum) -> put an obtain on register
ELSEIF param.rtype = PPCARGRTYPE_FX
inst_copy(DV,param.defd, FPX,param.rnum)
self.copyObtainToFREG(FPX,param.rnum) -> put an obtain on register
ELSEIF param.rtype = PPCARGRTYPE_STACKRX
inst_copy(DV,param.defd, RX,DTEMP)
inst_copy(RX,DTEMP, ARXPO,AxSizeOfs(1,PTRSIZE,param.rnum))
ELSEIF param.rtype = PPCARGRTYPE_RX2
->inst_copy(DV,param.defd, D64, D64TEMP)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP), RX, param.rnum)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP+4), RX, param.rnum+1)
self.tox2r(DV,param.defd,param.rnum)
self.copyObtainToDREG(RX,param.rnum) -> put obtain on register
self.copyObtainToDREG(RX,param.rnum+1) -> put obtain on register
ELSEIF param.rtype = PPCARGRTYPE_STACKRX2
inst_copy(DV,param.defd, RX,DTEMP)
inst_copy(RX,DTEMP, D64,param.rnum) -> clever eh !
ENDIF
a++
ENDWHILE
ENDIF
FOR a := nrofparams-1 TO 0 STEP -1
param := proc.argarray[a]
IF param.rtype = PPCARGRTYPE_RX
self.releaseDREG(param.rnum,0)
ELSEIF param.rtype = PPCARGRTYPE_FX
self.releaseFREG(param.rnum,0)
ELSEIF param.rtype = PPCARGRTYPE_RX2
self.releaseDREG(param.rnum,0)
self.releaseDREG(param.rnum+1,0)
ENDIF
ENDFOR
IF meth = NIL
IF proc.cpu = CPU_PPC
inst_goslab(proc)
ELSE -> ppc calling 68k ! (max 8 params)
IF g_optosid <> OSID_MORPHOS
reportErr('automagic ppc->68k calling not implemented for target', proc.name)
ENDIF
-> 68k passing out exception currently a problem
-> copy into emulhandle regs
FOR a := 0 TO proc.nrofargs-1
param := proc.argarray[a]
ppcstw(param.rnum,2,a*4)
ENDFOR
-> copy r13 into emulhandle.a4
ppcstw(13,2,48)
-> do the twist
endstub := newLabel()
ppcblab(endstub,0,1) -> skip 68k stubcode
-> stub: from 68k regs to stack as params for procedure
FOR a := 0 TO proc.nrofargs-1 DO IF a > 7 THEN moveaxaxpd(SIZE_L,a-8,7) ELSE movedxaxpd(SIZE_L,a,7)
bsrlab(proc)
leaaxpofsax(7,proc.nrofargs*4,7)
rts_()
putAlign(4) -> align 4
putLabel(endstub)
ppcmfspr(3,8) -> to r3
ppclwz(0,2,104) -> emulcalldirect68k to r0
ppcmtspr(0,8) -> lr
ppcbclr(20,0,1)
ENDIF
ro := proc.mret.ros[0]
rd := proc.mret.rds[0]
ro, rd := self.secureReturn(ro, rd, regusecopy) -> v50
self.loadObtained(regusecopy)
clearRegs()
#ifdef DBG_PPCGEN
DEBUGF('dofunction() \s DONE ro=\d rd=\h\n', hln.name, ro, rd)
#endif
ELSE
#ifdef DBG_PPCGEN
DEBUGF('dofunction() (method) \s DONE\n', hln.name)
#endif
ENDIF
n := buf[1]
-> 2.2
IF proc.raise
noraise := newLabel()
inst_bic(DV,proc.raise.trigval,proc.raise.condition, ro,rd,noraise)
inst_copy(DV,proc.raise.excval, DREG,IREG0)
ppcblab(self.raise_lif,0,0)
def_label(noraise)
ENDIF
g_multireturn := proc.mret
ENDPROC n, ro, rd
-> 1.9.0, added support for new style varfunc
PROC doVarfunc(n:PTR TO item) OF ppc
DEF v:PTR TO var, r, count=0
DEF regusecopy[REGUSETABSIZE]:ARRAY OF oreg
DEF o, d, t
DEF it_funccall:PTR TO it_funccall
DEF ro, rd
DEF ha:hintargs
DEF arg:PTR TO arg, a
ha.hregisvar := FALSE
r := n[1]
it_funccall := n.info
v := it_funccall.data
n := it_funccall + SIZEOF it_funccall
#ifdef DBG_PPCGEN
DEBUGF('dovfunction() \s \n', v.hln.name)
#endif
ro := RX
rd := IREG0
self.saveObtained(regusecopy)
IF v.argsarray = FALSE
/* evaluate expressions and put in regs or on stack */
WHILE (t := n.data)
IF count > 7 -> put in parameter store area ?
n, o, d := self.doExpression(n)
inst_copy(o,d, ARXPO,AxSizeOfs(1,PTRSIZE,count-8*4+8))
ELSE
ha.hregop := RX
ha.hregnum := count+3
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, RX,count+3)
self.copyObtainToDREG(RX,count+3) -> put an obtain on register
ENDIF
count++
ENDWHILE
WHILE count
count--
IF count <= 7 THEN self.releaseDREG(count+3, 0)-> release regs
ENDWHILE
ELSE -> 1.9.0
/* evaluate expressions and put on stack or in register */
FOR a := 0 TO it_funccall.numpars-1
arg := v.argsarray[a]
IF arg.rtype = PPCARGRTYPE_STACKRX -> put in parameter store area ?
n, o, d := self.doExpression(n)
inst_copy(o,d, DREG,DTEMP)
inst_copy(DREG,DTEMP, ARXPO,AxSizeOfs(1,PTRSIZE,arg.rnum))
ELSEIF arg.rtype = PPCARGRTYPE_RX
ha.hregop := DREG
ha.hregnum := arg.rnum
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, RX,arg.rnum)
self.copyObtainToDREG(RX,arg.rnum) -> put obtain on register
ELSEIF arg.rtype = PPCARGRTYPE_FX
ha.hregop := FREG
ha.hregnum := arg.rnum
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, FPX,arg.rnum)
self.copyObtainToFREG(FPX,arg.rnum) -> put obtain on register
ELSEIF arg.rtype = PPCARGRTYPE_RX2
ha.hregop := NIL
ha.hregnum := -1
n, o, d := self.doExpression(n, ha)
->inst_copy(o,d, D64, D64TEMP)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP), RX, arg.rnum)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP+4), RX, arg.rnum+1)
self.tox2r(o,d,arg.rnum)
self.copyObtainToDREG(RX,arg.rnum) -> put obtain on register
self.copyObtainToDREG(RX,arg.rnum+1) -> put obtain on register
ELSEIF arg.rtype = PPCARGRTYPE_STACKRX2
n, o, d := self.doExpression(n)
inst_copy(o,d, D64, arg.rnum) -> ohyeah
ENDIF
ENDFOR
FOR a := it_funccall.numpars-1 TO 0 STEP -1
arg := v.argsarray[a]
IF arg.rtype = PPCARGRTYPE_RX
self.releaseDREG(arg.rnum,0)
ELSEIF arg.rtype = PPCARGRTYPE_FX
self.releaseFREG(arg.rnum,0)
ELSEIF arg.rtype = PPCARGRTYPE_RX2
self.releaseDREG(arg.rnum,0)
self.releaseDREG(arg.rnum+1,0)
ENDIF
ENDFOR
ENDIF
inst_copy(v.o,v.d, RX,ATEMP)
inst_gosarx(ATEMP)
ro, rd := self.secureReturn(ro, rd, regusecopy) -> v50
self.loadObtained(regusecopy)
clearRegs()
g_multireturn := IF v.multiret THEN v.multiret ELSE [DREG,DREG,DREG,DREG,3,4,5,6]:LONG
#ifdef DBG_PPCGEN
DEBUGF('dovfunction() \s DONE\n', v.hln.name)
#endif
ENDPROC r, ro, rd
-> v50 new parameterpassing
-> v55 64bit varargs support
PROC doIntfunc(n:PTR TO item) OF ppc
DEF buf:PTR TO item, r:PTR TO raise, o, d, a, t
DEF numparams, defs:PTR TO LONG
DEF ifunc:PTR TO lif, regusecopy[REGUSETABSIZE]:ARRAY OF oreg
DEF hln:PTR TO hln, numvarargs=0, var:PTR TO var
DEF noraise:PTR TO genlab
DEF return=FALSE, o2,d2
DEF ifNumArgs
DEF it_funccall:PTR TO it_funccall
DEF ro, rd, ro2, rd2
DEF ha:hintargs
DEF rx=3, fx=1
ha.hregisvar := FALSE
buf := n
it_funccall := n.info
numparams := it_funccall.numpars
ifunc := it_funccall.data
n := it_funccall + SIZEOF it_funccall
ifNumArgs := ListLen(ifunc.params)
#ifdef DBG_PPCGEN
DEBUGF('doifunction() \s \n', ifunc.name)
#endif
-> suckass solution for now 2.0.0
return := ListItem(ifunc.returns, 0)
SELECT return
CASE 0
ro := DREG
rd := IREG0
CASE 1
ro := FREG
rd := FREG0
CASE 2
ro := X2R
rd := IREG0
DEFAULT
ro := NIL
ENDSELECT
return := IF ListLen(ifunc.returns) = 2 THEN ListItem(ifunc.returns, 1) ELSE -1
SELECT return
CASE 0
ro2 := DREG
rd2 := IF ro = FREG THEN IREG0 ELSE IREG1
CASE 1
ro2 := FREG
rd2 := FREG0
CASE 2
ro2 := X2R
rd2 := 5 ->IREG2
DEFAULT
ro2 := NIL
ENDSELECT
self.saveObtained(regusecopy)
defs := ifunc.defaults
IF ifunc.flags <> 2 -> ppc non varargs ?
/* evaluate expressions and put on stack or registers */
FOR a := 0 TO numparams-1
IF a > 7 -> put in parameter store area ?
n, o, d := self.doExpression(n)
inst_copy(o,d, DREG,DTEMP)
inst_copy(DREG,DTEMP, ARXPO,AxSizeOfs(1,4,a-8*4+8))
ELSE
t := ListItem(ifunc.params,a)
IF t = 1
o2 := FPX
d2 := fx++
ELSEIF t = 0
o2 := RX
d2 := rx++
ELSEIF t = 2 -> 2.0.0 X2R WIDE
o2 := D64
d2 := D64TEMP
ENDIF
ha.hregop := o2
ha.hregnum := d2
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, o2,d2)
IF o2 = FPX
self.copyObtainToFREG(FPX,d2) -> put an pbtain on register
ELSEIF o2 = RX
self.copyObtainToDREG(RX,d2) -> put an pbtain on register
ELSEIF o2 = D64
self.copyObtainToDREG(RX, rx)
self.copyObtainToDREG(RX, rx+1)
inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP), RX,rx)
inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP+4), RX,rx+1)
rx++ ; rx++
ENDIF
ENDIF
ENDFOR
IF n.data THEN reportIErr(' doifunction, not completed')
-> should we put some defaults ?
IF ifNumArgs > numparams
FOR a := numparams TO ifNumArgs-1
IF a < 8
t := ListItem(ifunc.params,a)
IF t = 1
o2 := FPX
d2 := fx++
ELSEIF t = 0
o2 := RX
d2 := rx++
ENDIF
inst_copy(DV,defs[]++, o2,d2)
IF o2 = FPX
self.copyObtainToFREG(FPX,d2) -> put an pbtain on register
ELSEIF o2 = RX
self.copyObtainToDREG(RX,d2) -> put an pbtain on register
ENDIF
ELSE
inst_copy(DV,defs[]++, RX,DTEMP)
inst_copy(RX,DTEMP, ARXPO,AxSizeOfs(1,4,a-8*4+8))
ENDIF
ENDFOR
ENDIF
-> release registers
FOR a := ifNumArgs-1 TO 0 STEP -1
IF a < 8
t := ListItem(ifunc.params,a)
IF t = 1
o2 := FPX
d2 := fx--
ELSEIF t = 0
o2 := RX
d2 := rx--
ELSEIF t = 2 -> 2.0.0
o2 := D64
d2 := D64TEMP
ENDIF
IF o2 = FPX
self.releaseFREG(d2,0) -> release register
ELSEIF o2 = RX
self.releaseDREG(d2,0) -> release register
ELSEIF o2 = D64
rx-- ; rx--
self.releaseDREG(rx+1,0) -> release register
self.releaseDREG(rx,0) -> release register
ENDIF
ENDIF
ENDFOR
IF ifunc.flags = 1 -> inline ?
CopyMemQuick(ifunc.code, g_codeptr, ifunc.codelen)
g_codeptr := g_codeptr + ifunc.codelen
ELSE
inst_goslab(ifunc)
ENDIF
ELSEIF ifunc.flags = 2 -> ppc varargs ?
-> put ALL parameters on stack
t := g_localstackoffset
WHILE n.data
n, o, d := self.doExpression(n)
SELECT o -> 1.10.0 support 8byte values
CASE D64 ; inst_push(8, o, d)
CASE VAR64 ; inst_push(8, o, d)
CASE X2R ; inst_push(8, o, d)
CASE FPX ; inst_push(8, o, d)
DEFAULT ; inst_push(4, o, d)
ENDSELECT
ENDWHILE
-> put fixed params in regs
FOR a := 0 TO ifNumArgs-1
inst_copy(ARXPO,AxSizeOfs(1,4,t+(a*4)), RX,a+3)
ENDFOR
-> now always creates varargs array regardless to
-> avoid problem with OS4 DebugF() *TEMP FIX*
->IF numparams > ifNumArgs
-> get address of varargs in next reg
inst_copy(ARXPO,AxSizeOfs(1,0,t+(a*4)), RX,a+3)
->ENDIF
-> call function
inst_goslab(ifunc)
g_localstackoffset := t
ENDIF
ro, rd := self.secureReturn(ro, rd, regusecopy)
self.loadObtained(regusecopy)
-> 2.0.0 crap but hey
IF ro2 = X2R
-> copy regs into a non obtained WIDE "register"
inst_copy(RX,rd2, ARXPO,AxSizeOfs(1,4,g_localstackoffset))
inst_copy(RX,rd2+1, ARXPO,AxSizeOfs(1,4,g_localstackoffset+4))
ro2 := D64
rd2 := g_localstackoffset
ENDIF
clearRegs()
IF ifunc.raise
noraise := newLabel()
inst_bic(DV,ifunc.raise.trigval,ifunc.raise.condition, ro,rd,noraise)
t := ifunc.raise.excval
inst_copy(DV,t, DREG,IREG0)
ppcblab(self.raise_lif,0,0)->g_internalfuncsppc[6],0,0) -> Raise
def_label(noraise)
ENDIF
g_multireturn := [ro,
ro2,
NIL,
NIL,
rd,
rd2,
NIL,
NIL]:LONG
#ifdef DBG_PPCGEN
DEBUGF('doiunction() \s DONE\n', ifunc.name)
#endif
ENDPROC buf[1], ro, rd
-> v50: new parameterpassing for sysv ....
PROC doLibfunc(n:PTR TO item) OF ppcsysv
DEF buf:PTR TO item, a, o, d, libbase:PTR TO var, r:PTR TO raise
DEF regusecopy[REGUSETABSIZE]:ARRAY OF oreg, lfunc:PTR TO lfunc, hln:PTR TO hln
DEF numparams, t, var:PTR TO var
DEF o2, d2, t2, noraise:PTR TO genlab
DEF it_funccall:PTR TO it_funccall
DEF ro, rd, saved2
DEF ha:hintargs->, regusecopy2[REGUSETABSIZE]:ARRAY OF oreg
ha.hregisvar := FALSE
buf := n
it_funccall := n.info
numparams := it_funccall.numpars
lfunc := it_funccall.data
libbase := it_funccall.info
n := it_funccall + SIZEOF it_funccall
IF numparams <> lfunc.nrofargs THEN reportErr('wrong nr of parameters for function', lfunc.name)
#ifdef DBG_PPCGEN
DEBUGF('dolfunction(/\d) buf.num=\d \a\s\a buf.info=$\h\n', lfunc.nrofargs, buf.num, lfunc.name, buf.info)
#endif
-> 2.2.1. float and wide wasnt implemented
t := lfunc.return
SELECT t
CASE 0
ro := RX
rd := 3
CASE 1
ro := FPX
rd := 1
CASE 3
ro := X2R
rd := 3
ENDSELECT
self.saveObtained(regusecopy)
IF lfunc.type = 1 -> sysv ?
FOR a := 0 TO numparams-1
IF lfunc.regs[a].rtype = PPCARGRTYPE_STACKRX -> put in parameter store area ?
n, o, d := self.doExpression(n)
inst_copy(o,d, ARXPO,AxSizeOfs(1,4,lfunc.regs[a].rnum))
ELSEIF lfunc.regs[a].rtype = PPCARGRTYPE_RX
ha.hregop := RX
ha.hregnum := lfunc.regs[a].rnum
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, RX,lfunc.regs[a].rnum)
self.copyObtainToDREG(RX,lfunc.regs[a].rnum)
ELSEIF lfunc.regs[a].rtype = PPCARGRTYPE_FX
ha.hregop := FREG
ha.hregnum := lfunc.regs[a].rnum
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, FPX,lfunc.regs[a].rnum)
self.copyObtainToFREG(FPX,lfunc.regs[a].rnum)
ELSEIF lfunc.regs[a].rtype = PPCARGRTYPE_RX2 -> 2.0.0 WIDE/X2R
n, o, d := self.doExpression(n)
->inst_copy(o,d, D64,D64TEMP)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP), RX, lfunc.regs[a].rnum)
->inst_copy(ARXPO,AxSizeOfs(1,4,D64TEMP+4), RX, lfunc.regs[a].rnum+1)
self.tox2r(o,d,lfunc.regs[a].rnum)
self.copyObtainToDREG(RX,lfunc.regs[a].rnum) -> put obtain on register
self.copyObtainToDREG(RX,lfunc.regs[a].rnum+1) -> put obtain on register
ELSEIF lfunc.regs[a].rtype = PPCARGRTYPE_STACKRX2