-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibinit.c
2176 lines (1838 loc) · 67.2 KB
/
libinit.c
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
// Copyright (c) 2019-2021 Dennis van der Boon
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <stdarg.h>
#include <libraries/mediatorpci.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <proto/mediatorpci.h>
#include <proto/expansion.h>
#include <proto/prometheus.h>
#include <exec/resident.h>
#include <exec/libraries.h>
#include <exec/execbase.h>
#include <hardware/intbits.h>
#include <exec/interrupts.h>
#include <dos/var.h>
#include <dos/dosextens.h>
#include <utility/tagitem.h>
#include <dos/dostags.h>
#include <powerpc/powerpc.h>
#include <powerpc/tasksPPC.h>
#include <intuition/intuition.h>
#include "librev.h"
#include "constants.h"
#include "libstructs.h"
#include "Internalsppc.h"
#include "Internals68k.h"
APTR OldLoadSeg, OldNewLoadSeg, OldAllocMem, OldAddTask, OldRemTask;
struct PPCBase* myPPCBase;
struct ExecBase* mySysBase;
/********************************************************************************************
*
* Standard dummy entry of a device/library
*
*********************************************************************************************/
int main (void)
{
return -1;
}
/********************************************************************************************
*
* Our Resident struct.
*
*********************************************************************************************/
static const struct Resident RomTag =
{
RTC_MATCHWORD,
(struct Resident *) &RomTag,
(struct Resident *) &RomTag+1,
RTW_NEVER,
VERSION,
NT_LIBRARY,
LIB_PRIORITY,
LIBNAME,
VSTRING,
(APTR)&LibInit
};
/********************************************************************************************
*
* Supported ATI cards and PPC chipsets
*
*********************************************************************************************/
static const ULONG cardList[] =
{
DEVICE_MPC107<<16|VENDOR_MOTOROLA,
DEVICE_HARRIER<<16|VENDOR_MOTOROLA,
DEVICE_MPC8343E<<16|VENDOR_FREESCALE,
DEVICE_MPC8314E<<16|VENDOR_FREESCALE,
0
};
static const ULONG atiList[] =
{
DEVICE_RV280PRO,
DEVICE_RV280,
DEVICE_RV280_2,
DEVICE_RV280MOB,
DEVICE_RV280SE,
0
};
/********************************************************************************************
*
* Debug routines. Use as D(("format",value1, ...));
*
*********************************************************************************************/
#ifdef DEBUG
APTR __DRawPutChar(__reg("a6") void *, __reg("d0") UBYTE MyChar)="\tjsr\t-516(a6)";
#define DRawPutChar(MyChar) __DRawPutChar(SysBase, (MyChar))
void DPutChProc(__reg("d0") UBYTE mychar, __reg("a3") APTR PutChData)
{
struct ExecBase* SysBase = (struct ExecBase*)PutChData;
DRawPutChar(mychar);
return;
}
void kprintf(STRPTR format, ...)
{
if (format)
{
struct ExecBase* SysBase = mySysBase;
va_list args;
va_start(args, format);
RawDoFmt(format, (APTR)args, &DPutChProc, (APTR)SysBase);
va_end(args);
}
return;
}
#define D(x) do { kprintf x; } while (0)
#else
#define D(x) do { } while (0)
#endif
/********************************************************************************************
*
* Exiting and clean-up
*
*********************************************************************************************/
static void CleanUp(struct InternalConsts *myConsts)
{
struct PciBase *MediatorPCIBase;
struct DosLibrary *DOSBase;
struct ExpansionBase *ExpansionBase;
struct ExecBase *SysBase = myConsts->ic_SysBase;
#if 0
if (nameSpace)
{
FreeVec(nameSpace);
}
#endif
if (MediatorPCIBase = myConsts->ic_PciBase)
{
CloseLibrary((struct Library*)MediatorPCIBase);
}
if (DOSBase = myConsts->ic_DOSBase)
{
CloseLibrary((struct Library*)DOSBase);
}
if (ExpansionBase = myConsts->ic_ExpansionBase)
{
CloseLibrary((struct Library*)ExpansionBase);
}
return;
}
/********************************************************************************************
*
* Setting up our library
*
*********************************************************************************************/
struct PPCBase *mymakeLibrary(struct InternalConsts *myConsts, ULONG funPointer)
{
ULONG funSize, funOffset;
UBYTE *baseMem;
APTR funMem, funAddr;
struct PPCBase *PowerPCBase = NULL;
struct ExecBase *SysBase = myConsts->ic_SysBase;
funSize = *((ULONG*)(funPointer - 4));
if (!(funMem = myAllocVec32(NULL, funSize, MEMF_PUBLIC|MEMF_PPC|MEMF_REVERSE|MEMF_CLEAR)))
{
return NULL;
}
funOffset = (ULONG)funMem - (funPointer + 4);
CopyMem((APTR)(funPointer+4), funMem, funSize);
if (!(baseMem = (char *)AllocVec((sizeof(struct PrivatePPCBase)) + (NEGSIZEALIGN), MEMF_PUBLIC|MEMF_PPC|MEMF_REVERSE|MEMF_CLEAR)))
{
return NULL;
}
PowerPCBase = (struct PPCBase*)(baseMem + (NEGSIZEALIGN));
PowerPCBase->PPC_LibNode.lib_PosSize = sizeof(struct PrivatePPCBase);
PowerPCBase->PPC_LibNode.lib_NegSize = NEGSIZEALIGN;
baseMem = (UBYTE*)PowerPCBase;
for (int n=0; n<(TOTAL_FUNCS); n++)
{
funAddr = LibVectors[n];
if (n > (NUM_OF_68K_FUNCS-1))
{
funAddr = (UBYTE*)funAddr + funOffset;
}
*((ULONG*)(baseMem - 4)) = (ULONG)funAddr;
*((UWORD*)(baseMem - 6)) = 0x4ef9;
baseMem -= 6;
}
CacheClearU();
InitStruct(&LibInitData[0], PowerPCBase, 0);
PowerPCBase->PPC_LibNode.lib_Node.ln_Name = LIBNAME; //Initializer of ln_Name does not seem to work with vbcc
PowerPCBase->PPC_LibNode.lib_IdString = VSTRING;
AddLibrary((struct Library*)PowerPCBase);
PowerPCBase->PPC_SysLib = SysBase;
return PowerPCBase;
}
/********************************************************************************************
*
* the libinit routine. Called when the library is opened.
*
*********************************************************************************************/
__entry struct PPCBase *LibInit(__reg("d0") struct PPCBase *ppcbase,
__reg("a0") BPTR seglist, __reg("a6") struct ExecBase* __sys)
{
struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
struct UtilityBase *UtilityBase;
struct PciBase *MediatorPCIBase;
struct Library *PrometheusBase;
struct ExpansionBase *ExpansionBase;
struct PPCBase *PowerPCBase;
struct Process *myProc;
ULONG deviceID = 0;
struct ConfigDev *cd = NULL;
struct PciDevice *ppcdevice = NULL;
struct PciDevice *gfxdevice = NULL;
struct PCIBoard *pppcdevice = NULL;
struct PCIBoard *pgfxdevice = NULL;
struct MemHeader *pcimemDMAnode;
ULONG cardNumber = 0;
BYTE memPrio;
ULONG card, devfuncnum, res, i, n, testLen, offset;
ULONG testSize, bytesFree, initPointer, kernelPointer, funPointer;
volatile ULONG status;
struct PPCZeroPage *myZeroPage;
struct MemHeader *myPPCMemHeader;
struct InitData *cardData;
APTR nameSpace = NULL;
struct InternalConsts consts;
struct InternalConsts *myConsts = &consts;
SysBase = __sys;
mySysBase = __sys;
myConsts->ic_SysBase = __sys;
myConsts->ic_SegList = seglist;
D(("Started Library Init routine\n"));
D(("Version: %s\n", VSTRING));
if (!(SysBase->AttnFlags & (AFF_68040|AFF_68060)))
{
PrintCrtErr(myConsts, "This library requires a 68LC040 or better");
return NULL;
}
#if 1
if ((FindName(&SysBase->MemList,"ppc memory")) || (FindName(&SysBase->LibList,LIBNAME)))
{
PrintCrtErr(myConsts, "Other PPC library already active (WarpOS/Sonnet");
return NULL;
}
#endif
if (!(DOSBase = (struct DosLibrary*)OpenLibrary("dos.library",37L)))
{
PrintCrtErr(myConsts, "Could not open dos.library V37+");
return NULL;
}
myConsts->ic_DOSBase = DOSBase;
UtilityBase = (struct UtilityBase*)OpenLibrary("utility.library",0L);
if (!(ExpansionBase = (struct ExpansionBase*)OpenLibrary("expansion.library",37L)))
{
PrintCrtErr(myConsts, "Could not open expansion.library V37+");;
return NULL;
}
myConsts->ic_ExpansionBase = ExpansionBase;
if ((FindConfigDev(NULL, VENDOR_ELBOX, MEDIATOR_MKII)) || (FindConfigDev(NULL, VENDOR_ELBOX, MEDIATOR_MKIII)))
{
if (!(cd = FindConfigDev(NULL, VENDOR_ELBOX, MEDIATOR_LOGIC)))
{
if (!(cd = FindConfigDev(NULL, VENDOR_ELBOX, MEDIATOR_LOGICIII)))
{
PrintCrtErr(myConsts, "Could not find a supported Mediator board");
return NULL;
}
}
D(("Detected supported Elbox Mediator PCI bridge\n"));
myConsts->ic_pciType = VENDOR_ELBOX;
if (!(MediatorPCIBase = (struct PciBase*)OpenLibrary("pci.library",VERPCI)))
{
PrintCrtErr(myConsts, "Could not open pci.library V13.8+");
return NULL;
}
myConsts->ic_PciBase = MediatorPCIBase;
offset = 0;
#if 1
if ((MediatorPCIBase->pb_LibNode.lib_Version == VERPCI) && (MediatorPCIBase->pb_LibNode.lib_Revision < REVPCI))
{
PrintCrtErr(myConsts, "Could not open pci.library V13.8+");
return NULL;
}
#endif
if (cd)
{
if (!(cd->cd_BoardSize == 0x20000000))
{
PrintCrtErr(myConsts, "Mediator WindowSize jumper incorrectly configured");
return NULL;
}
}
}
else if (cd = FindConfigDev(NULL, VENDOR_E3B, PROMETHEUS_FIRESTORM))
{
myConsts->ic_pciType = VENDOR_E3B;
D(("Detected Firestorm/Firebird PCI bridge\n"));
if (!(PrometheusBase = OpenLibrary("prometheus.library",VERPCIP)))
{
PrintCrtErr(myConsts, "Could not open prometheus.library V4+");
return NULL;
}
myConsts->ic_PciBase = (struct PciBase*)PrometheusBase;
offset = (ULONG)cd->cd_BoardAddr;
#if 0
if ((PrometheusBase->lib_Version == VERPCIP) && (PrometheusBase->lib_Revision < REVPCIP))
{
PrintCrtErr(myConsts, "Could not open prometheus.library V4.0+");
return NULL;
}
#endif
}
else
{
PrintCrtErr(myConsts, "Could not find a supported PCI bridge");
return NULL;
}
D(("Opening of support libraries completed\n"));
myConsts->ic_startBAT = 0;
myConsts->ic_sizeBAT = 0;
if (myConsts->ic_pciType == VENDOR_ELBOX)
{
for (i=0; i<MAX_PCI_SLOTS; i++)
{
devfuncnum = i << DEVICENUMBER_SHIFT;
res = ReadConfigurationLong((UWORD)devfuncnum, PCI_OFFSET_ID);
while (card = cardList[cardNumber])
{
if (card == res)
{
break;
}
cardNumber += 1;
}
if (card == res)
{
break;
}
cardNumber = 0;
}
if (!(card))
{
PrintCrtErr(myConsts, "No supported PPC PCI bridge detected");
return NULL;
}
ppcdevice = FindPciDevFunc(devfuncnum);
deviceID = ppcdevice->pd_DeviceID;
myConsts->ic_deviceID = deviceID;
cardNumber = 0;
myConsts->ic_gfxSubType = DEVICE_VOODOO45;
if (!(gfxdevice = FindPciDevice(VENDOR_3DFX, DEVICE_VOODOO45, 0)))
{
myConsts->ic_gfxSubType = DEVICE_VOODOO3;
if (!(gfxdevice = FindPciDevice(VENDOR_3DFX, DEVICE_VOODOO3, 0)))
{
gfxdevice = FindPciDevice(VENDOR_3DFX, DEVICE_VBANSHEE, 0);
}
}
if (gfxdevice)
{
myConsts->ic_gfxMem = gfxdevice->pd_ABaseAddress1;
myConsts->ic_gfxSize = -((gfxdevice->pd_Size1)&-16L);
myConsts->ic_gfxConfig = gfxdevice->pd_ABaseAddress0;
myConsts->ic_gfxType = VENDOR_3DFX;
D(("3DFX card detected, Gfx address at %08lx, config address at %08lx\n", myConsts->ic_gfxMem, myConsts->ic_gfxConfig));
}
else
{
while (atiList[cardNumber])
{
if (gfxdevice = FindPciDevice(VENDOR_ATI, atiList[cardNumber], 0))
{
myConsts->ic_gfxMem = gfxdevice->pd_ABaseAddress0;
myConsts->ic_gfxSize = -((gfxdevice->pd_Size0)&-16L);
myConsts->ic_gfxConfig = gfxdevice->pd_ABaseAddress2;
myConsts->ic_gfxType = VENDOR_ATI;
myConsts->ic_gfxSubType = 0;
D(("ATI card detected. Gfx address at %08lx, config address at %08lx\n", myConsts->ic_gfxMem, myConsts->ic_gfxConfig));
break;
}
cardNumber++;
}
}
if (!gfxdevice)
{
PrintCrtErr(myConsts, "No supported VGA card detected");
return NULL;
}
D(("Size of Gfx card in PCI memory is %08lx\n", myConsts->ic_gfxSize));
//Add ATI Radeon memory as extra memory for K1/M1
//Need to have Voodoo as primary VGA output
//As the list has twice the memory name, we search it twice
//Findname only returns first in the list
//Also moved pcidma memory to bottom of memory list
for (i=0; i<2; i++)
{
if (!(pcimemDMAnode = (struct MemHeader *)FindName(&SysBase->MemList, "pcidma memory")))
{
break;
}
if (!(pcimemDMAnode->mh_Node.ln_Succ))
{
break;
}
if (pcimemDMAnode->mh_Node.ln_Pri == -20)
{
break;
}
memPrio = -20;
if ((!(myConsts->ic_gfxType == VENDOR_ATI)) && (deviceID == DEVICE_MPC8343E))
{
testSize = 0x2000000;
testLen = ((ULONG)pcimemDMAnode->mh_Upper)-((ULONG)pcimemDMAnode->mh_Lower);
for (n=0; n<4; n++)
{
if (testSize > testLen)
{
break;
}
testSize = (testSize<<1);
}
if ((n > 0) && (n < 4))
{
memPrio = -15;
myConsts->ic_startBAT = (((ULONG)pcimemDMAnode->mh_Lower) & (-(testSize)));
myConsts->ic_sizeBAT = testSize;
D(("Detected usable pcidma memory at %08lx of size %08lx\n", myConsts->ic_startBAT, myConsts->ic_sizeBAT));
}
}
Disable();
Remove((struct Node *)pcimemDMAnode);
pcimemDMAnode->mh_Node.ln_Pri = memPrio;
Enqueue(&SysBase->MemList, (struct Node *)pcimemDMAnode);
Enable();
}
#if 0
if (myConsts->ic_gfxMem >>31)
{
PrintCrtErr(myConsts, "PPCPCI environment not set in ENVARC:Mediator");
}
#endif
}
else
{
while (card = cardList[cardNumber])
{
deviceID = card >> 16;
if (pppcdevice = Prm_FindBoardTags(NULL,
PRM_Vendor, card & 0xffff,
PRM_Device, deviceID,
TAG_DONE))
{
break;
}
cardNumber++;
}
if (!(pppcdevice))
{
PrintCrtErr(myConsts, "No supported PPC PCI bridge detected");
return NULL;
}
myConsts->ic_deviceID = deviceID;
myConsts->ic_gfxSubType = DEVICE_VOODOO45;
if (!(pgfxdevice = Prm_FindBoardTags(NULL,
PRM_Vendor, VENDOR_3DFX,
PRM_Device, DEVICE_VOODOO45,
TAG_DONE)))
{
pgfxdevice = Prm_FindBoardTags(NULL,
PRM_Vendor, VENDOR_3DFX,
PRM_Device, DEVICE_VOODOO3,
TAG_DONE);
myConsts->ic_gfxSubType = DEVICE_VOODOO3;
}
if (pgfxdevice)
{
Prm_GetBoardAttrsTags(pgfxdevice, PRM_MemoryAddr0, (ULONG)&myConsts->ic_gfxConfig,
PRM_MemoryAddr1, (ULONG)&myConsts->ic_gfxMem,
PRM_MemorySize1, (ULONG)&myConsts->ic_gfxSize,
TAG_DONE);
myConsts->ic_gfxType = VENDOR_3DFX;
D(("3DFX card detected, Gfx address at %08lx, config address at %08lx\n", myConsts->ic_gfxMem, myConsts->ic_gfxConfig));
}
else
{
cardNumber = 0;
while (atiList[cardNumber])
{
if (pgfxdevice = Prm_FindBoardTags(NULL,
PRM_Vendor, VENDOR_ATI,
PRM_Device, atiList[cardNumber],
TAG_DONE))
{
Prm_GetBoardAttrsTags(pgfxdevice,
PRM_MemoryAddr0, (ULONG)&myConsts->ic_gfxMem,
PRM_MemorySize0, (ULONG)&myConsts->ic_gfxSize,
PRM_MemoryAddr2, (ULONG)&myConsts->ic_gfxConfig,
TAG_DONE);
myConsts->ic_gfxType = VENDOR_ATI;
myConsts->ic_gfxSubType = 0;
D(("ATI card detected. Gfx address at %08lx, config address at %08lx\n", myConsts->ic_gfxMem, myConsts->ic_gfxConfig));
break;
}
cardNumber++;
}
}
if (!pgfxdevice)
{
if (pgfxdevice = Prm_FindBoardTags(NULL,
PRM_Vendor, VENDOR_TI,
PRM_Device, DEVICE_PERMEDIA2,
TAG_DONE))
{
Prm_GetBoardAttrsTags(pgfxdevice,
PRM_MemoryAddr1, (ULONG)&myConsts->ic_gfxMem,
PRM_MemorySize1, (ULONG)&myConsts->ic_gfxSize,
PRM_MemoryAddr0, (ULONG)&myConsts->ic_gfxConfig,
TAG_DONE);
myConsts->ic_gfxType = VENDOR_TI;
myConsts->ic_gfxSubType = 0;
D(("Permedia2 card detected. Gfx address at %08lx, config address at %08lx\n", myConsts->ic_gfxMem, myConsts->ic_gfxConfig));
}
else
{
PrintCrtErr(myConsts, "No supported VGA card detected");
return NULL;
}
}
D(("Size of Gfx card in PCI memory is %08lx\n", myConsts->ic_gfxSize));
devfuncnum = 0;
pcimemDMAnode = 0;
}
getENVs(myConsts);
initPointer = (*((ULONG*)(seglist << 2)) << 2); //setup
kernelPointer = (*((ULONG*)(initPointer)) << 2); //kernel
funPointer = (*((ULONG*)(kernelPointer)) << 2); //functions
switch (deviceID)
{
case DEVICE_HARRIER:
{
cardData = SetupHarrier(myConsts, devfuncnum, ppcdevice, pppcdevice, initPointer);
break;
}
case DEVICE_MPC8343E:
case DEVICE_MPC8314E:
{
cardData = SetupKiller(myConsts, devfuncnum, ppcdevice, pppcdevice, initPointer);
break;
}
case DEVICE_MPC107:
{
cardData = SetupMPC107(myConsts, devfuncnum, ppcdevice, pppcdevice, initPointer, (ULONG)pcimemDMAnode);
break;
}
default:
{
D(("Error in device ID. Detected %08lx which is not supported\n", deviceID));
PrintCrtErr(myConsts, "Error setting up PPC card");
return NULL;
}
}
if (!(cardData))
{
return NULL;
}
D(("Waiting on PPC card to respond\n"));
for (i=0; i<0xEC0000; i++)
{
status = cardData->id_Status;
switch (status)
{
case ERR_PPCOK:
{
break;
}
case ERR_PPCMMU:
{
PrintCrtErr(myConsts, "Error during MMU setup of PPC");
return NULL;
}
case ERR_PPCMEM:
{
PrintCrtErr(myConsts, "No memory detected on the PPC card");
return NULL;
}
case ERR_PPCCORRUPT:
{
PrintCrtErr(myConsts, "Memory corruption detected during setup");
return NULL;
}
case ERR_PPCSETUP:
{
PrintCrtErr(myConsts, "General PPC setup error");
return NULL;
}
}
if (status == ERR_PPCOK)
{
break;
}
}
if (i == 0xEC0000)
{
switch (status)
{
case STATUS_INIT:
case ERR_PPCOK:
{
PrintCrtErr(myConsts, "PowerPC CPU possibly crashed during setup");
return NULL;
}
#if 0
case 0xabcdabcd:
{
PrintCrtErr(myConsts, "PowerPC CPU not responding");
return NULL;
}
#endif
default:
{
PrintCrtErr(myConsts, "PowerPC CPU not responding");
return NULL;
}
}
}
ULONG memAddress = cardData->id_MemBase + 0x80;
APTR sysStack = SuperState();
writememL(memAddress, 0, SUPERKEY);
cinv(memAddress);
ULONG checkV = readmemL(memAddress, 0);
UserState(sysStack);
if (!(checkV == SUPERKEY))
{
PrintCrtErr(myConsts, "PPC memory not set as being cache inhibited");
return NULL;
}
writememL(memAddress, 0, 0);
myZeroPage = (struct PPCZeroPage*)cardData->id_MemBase;
myConsts->ic_MemBase = (ULONG)myZeroPage;
nameSpace = AllocVec(16L, MEMF_PUBLIC|MEMF_CLEAR|MEMF_REVERSE);
if (!(nameSpace))
{
PrintCrtErr(myConsts, "General memory allocation error");
return NULL;
}
CopyMemQuick("ppc memory", nameSpace, 16L);
myPPCMemHeader = (struct MemHeader*)((ULONG)myZeroPage + MEM_GAP);
D(("Accessible PPC memory set up with header at %08lx\n", myPPCMemHeader));
if ((deviceID == DEVICE_MPC8343E) || (deviceID == DEVICE_MPC8314E))
{
myPPCMemHeader->mh_Upper = (APTR)((ULONG)myZeroPage + (cardData->id_MemSize));
bytesFree = (cardData->id_MemSize - MEM_GAP - sizeof(struct MemHeader));
}
else
{
myPPCMemHeader->mh_Upper = (APTR)((ULONG)myZeroPage + (cardData->id_MemSize) - (myZeroPage->zp_PageTableSize));
bytesFree = (cardData->id_MemSize - myZeroPage->zp_PageTableSize - MEM_GAP - sizeof(struct MemHeader));
}
myPPCMemHeader->mh_Node.ln_Type = NT_MEMORY;
myPPCMemHeader->mh_Node.ln_Pri = 1;
myPPCMemHeader->mh_Node.ln_Name = nameSpace;
myPPCMemHeader->mh_First = (struct MemChunk*)((ULONG)myPPCMemHeader + sizeof(struct MemHeader));
myPPCMemHeader->mh_First->mc_Next = NULL;
myPPCMemHeader->mh_First->mc_Bytes = bytesFree;
myPPCMemHeader->mh_Free = bytesFree;
myPPCMemHeader->mh_Lower = (APTR)((ULONG)myPPCMemHeader + sizeof(struct MemHeader));
myPPCMemHeader->mh_Attributes = MEMF_PUBLIC|MEMF_FAST|MEMF_PPC;
Disable();
Enqueue(&SysBase->MemList, (struct Node*)myPPCMemHeader);
PowerPCBase = mymakeLibrary(myConsts, funPointer);
Enable();
D(("Inserted PPC memory into Exec memory list\n"));
if (!(PowerPCBase))
{
PrintCrtErr(myConsts, "Error during library function setup");
return NULL;
}
D(("Library base set up at %08lx\n", PowerPCBase));
PowerPCBase->PPC_DosLib = (APTR)DOSBase;
PowerPCBase->PPC_SegList = (APTR)seglist;
PowerPCBase->PPC_Flags = (UBYTE)((myConsts->ic_env3 >> 22) | (myConsts->ic_env3 >> 15) | (myConsts->ic_env3 >> 8));
myPPCBase = PowerPCBase;
struct PrivatePPCBase* myBase = (struct PrivatePPCBase*)PowerPCBase;
switch (deviceID)
{
case DEVICE_HARRIER:
{
myBase->pp_BridgeConfig = cardData->id_ConfigBase;
myBase->pp_BridgeMsgs = cardData->id_MsgsBase;
myBase->pp_BridgeMPIC = cardData->id_MPICBase;
break;
}
case DEVICE_MPC8343E:
case DEVICE_MPC8314E:
{
myBase->pp_BridgeConfig = cardData->id_ConfigBase;
break;
}
case DEVICE_MPC107:
{
myBase->pp_BridgeMsgs = cardData->id_MsgsBase;
break;
}
}
myBase->pp_DeviceID = deviceID;
myBase->pp_MirrorList.mlh_Head = (struct MinNode*)&myBase->pp_MirrorList.mlh_Tail;
myBase->pp_MirrorList.mlh_TailPred = (struct MinNode*)&myBase->pp_MirrorList.mlh_Head;
myBase->pp_UtilityBase = UtilityBase;
myBase->pp_PPCMemBase = (ULONG)myZeroPage;
myZeroPage->zp_SysBase = SysBase;
myZeroPage->zp_PPCMemHeader = myPPCMemHeader;
myZeroPage->zp_PowerPCBase = PowerPCBase;
myZeroPage->zp_PPCMemBase = (ULONG)myZeroPage;
struct Library* WarpBase = MakeLibrary(&WarpVectors[0], &WarpInitData[0], 0 ,124, 0);
if (!(WarpBase))
{
PrintCrtErr(myConsts, "Could not set up dummy warp.library");
return NULL;
}
WarpBase->lib_Node.ln_Name = "warp.library"; //Initializer of ln_Name does not seem to work with vbcc
WarpBase->lib_IdString = "$VER: warp.library 5.1 (22.3.17)\r\n";
AddLibrary(WarpBase);
CopyMem((APTR)(kernelPointer + 4), (APTR)(cardData->id_MemBase + OFFSET_KERNEL), *((ULONG*)(kernelPointer - 4)));
CacheClearU();
D(("Copied PPC kernel code into place\n"));
struct Interrupt* myInt = AllocVec(sizeof(struct Interrupt), MEMF_PUBLIC | MEMF_CLEAR);
myInt->is_Code = (APTR)&GortInt;
myInt->is_Data = NULL;
myInt->is_Node.ln_Pri = 110;
myInt->is_Node.ln_Name = "Gort\0";
myInt->is_Node.ln_Type = NT_INTERRUPT;
if (myConsts->ic_pciType == VENDOR_ELBOX)
{
AddInterrupt(ppcdevice, myInt);
SetInterrupt(ppcdevice);
}
else
{
Prm_AddIntServer(pppcdevice, myInt);
Prm_SetBoardAttrsTags(pppcdevice, PRM_BoardOwner,
(ULONG)PowerPCBase, TAG_END);
}
D(("Gort 68K interrupt now running at %08lx\n", myInt));
if(!(myProc = CreateNewProcTags(
NP_Entry, (ULONG)&MasterControl,
NP_Name, "MasterControl",
NP_Priority, 1,
NP_StackSize, 0x20000,
TAG_DONE)))
{
PrintCrtErr(myConsts, "Error setting up 68K MasterControl process");
return NULL;
}
D(("MasterControl now running at %08lx\n", myProc));
myProc->pr_Task.tc_UserData = (APTR)myConsts;
Signal((struct Task*)myProc, SIGBREAKF_CTRL_F);
for (i=0; i<0xEC0000; i++)
{
if (myZeroPage->zp_Status == STATUS_READY)
{
break;
}
}
if (i == 0xEC0000)
{
PrintCrtErr(myConsts, "PowerPC CPU possibly crashed during setup");
return NULL;
}
Disable();
if (!(ChangeStackRamLib(0x4000, SysBase)))
{
PrintCrtErr(myConsts, "Failure to increase ramlib stack size");
return NULL;
}
OldLoadSeg = SetFunction((struct Library*)DOSBase, _LVOLoadSeg, (ULONG (*)())patchLoadSeg);
OldNewLoadSeg = SetFunction((struct Library*)DOSBase, _LVONewLoadSeg, (ULONG (*)())patchNewLoadSeg);
OldAddTask = SetFunction((struct Library*)SysBase, _LVOAddTask, (ULONG (*)())patchAddTask);
OldRemTask = SetFunction((struct Library*)SysBase, _LVORemTask, (ULONG (*)())patchRemTask);
OldAllocMem = SetFunction((struct Library*)SysBase, _LVOAllocMem, (ULONG (*)())patchAllocMem);
Enable();
D(("Completed adding various patches to Exec library\n"));
switch (myBase->pp_DeviceID)
{
case DEVICE_MPC8343E:
case DEVICE_MPC8314E:
{
struct Interrupt* myInt2 = AllocVec(sizeof(struct Interrupt), MEMF_PUBLIC | MEMF_CLEAR);
myInt2->is_Code = (APTR)&ZenInt;
myInt2->is_Data = NULL;
myInt2->is_Node.ln_Pri = -50;
myInt2->is_Node.ln_Name = "Zen\0";
myInt2->is_Node.ln_Type = NT_INTERRUPT;
AddIntServer(INTB_VERTB, myInt2);
D(("Zen support interrupt now running at %08lx\n", myInt2));
break;
}
case DEVICE_MPC107:
{
while (!(myZeroPage->zp_DECCounter));
ULONG otwrValue = (swap32(((ULONG)(cd->cd_BoardAddr) - offset) | MPC107_TWR_512MB)) & -2;
writememL(myBase->pp_BridgeMsgs, MPC107_OTWR, otwrValue);
writememL(myBase->pp_BridgeMsgs, MPC107_OMBAR, otwrValue + ((OFFSET_PCIMEM + offset) >> 24));
break;
}
}
struct TagItem myTags[] =
{
TASKATTR_CODE, *((ULONG*)(((ULONG)PowerPCBase + _LVOSystemStart + 2))),
TASKATTR_NAME, (ULONG)"Kryten",
TASKATTR_R3, (ULONG)PowerPCBase,
TASKATTR_SYSTEM, TRUE,
TAG_DONE
};
if (!(myCreatePPCTask((struct PrivatePPCBase*)PowerPCBase, (struct TagItem*)&myTags)))
{
PrintError(SysBase, "Error setting up Kryten PPC process");
return NULL;
}
D(("Started Kryten PPC cleanup task\n"));
struct Library* ppcemu;