713e6163af401ff1980ce95af2769bb515d9fea6
[reactos.git] / boot / freeldr / freeldr / arch / powerpc / prep.c
1 #include "freeldr.h"
2 #include "machine.h"
3 #include "ppcmmu/mmu.h"
4 #include "prep.h"
5
6 int prep_serial = 0x800003f8;
7 extern int mem_range_end;
8
9 void sync() { __asm__("eieio\n\tsync"); }
10
11 /* Simple serial */
12
13 void PpcPrepPutChar( int ch ) {
14 if( ch == 0x0a ) {
15 SetPhysByte(prep_serial, 0x0d);
16 sync();
17 }
18 SetPhysByte(prep_serial, ch);
19 sync();
20 }
21
22 BOOLEAN PpcPrepDiskReadLogicalSectors
23 ( ULONG DriveNumber, ULONGLONG SectorNumber,
24 ULONG SectorCount, PVOID Buffer ) {
25 int secct;
26
27 for(secct = 0; secct < SectorCount; secct++)
28 {
29 ide_seek(&ide1_desc, SectorNumber + secct, 0);
30 ide_read(&ide1_desc, ((PCHAR)Buffer) + secct * 512, 512);
31 }
32 /* Never give up! */
33 return TRUE;
34 }
35
36 BOOLEAN PpcPrepConsKbHit()
37 {
38 return 1;
39 //return GetPhysByte(prep_serial+5) & 1;
40 }
41
42 int PpcPrepConsGetCh()
43 {
44 while(!PpcPrepConsKbHit());
45 return GetPhysByte(prep_serial);
46 }
47
48 void PpcPrepVideoClearScreen(UCHAR Attr)
49 {
50 printf("\033c");
51 }
52
53 VIDEODISPLAYMODE PpcPrepVideoSetDisplayMode( char *DisplayMode, BOOLEAN Init )
54 {
55 return VideoTextMode;
56 }
57
58 void PpcPrepVideoGetDisplaySize( PULONG Width, PULONG Height, PULONG Depth )
59 {
60 *Width = 80;
61 *Height = 25;
62 *Depth = 16;
63 }
64
65 VOID PpcInitializeMmu(int max);
66
67 ULONG PpcPrepGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap,
68 ULONG MaxMemoryMapSize )
69 {
70 // Probe memory
71 paddr_t physAddr;
72 register int oldStore = 0, newStore = 0, change = 0, oldmsr;
73
74 __asm__("mfmsr %0\n" : "=r" (oldmsr));
75 change = oldmsr & 0x6fff;
76 __asm__("mtmsr %0\n" : : "r" (change));
77
78 // Find the last ram address in physical space ... this bypasses mapping
79 // but could run into non-ram objects right above ram. Usually systems
80 // aren't designed like that though.
81 for (physAddr = 0x40000, change = newStore;
82 (physAddr < 0x80000000) && (change == newStore);
83 physAddr += 1 << 12)
84 {
85 oldStore = GetPhys(physAddr);
86 newStore = (physAddr & 0x1000) ? 0x55aa55aa : 0xaa55aa55;
87 SetPhys(physAddr, newStore);
88 change = GetPhys(physAddr);
89 SetPhys(physAddr, oldStore);
90 }
91 // Back off by one page
92 physAddr -= 0x1000;
93 BiosMemoryMap[0].BaseAddress = 0x30000; // End of ppcmmu
94 BiosMemoryMap[0].Type = BiosMemoryUsable;
95 BiosMemoryMap[0].Length = physAddr - BiosMemoryMap[0].BaseAddress;
96
97 __asm__("mtmsr %0\n" : : "r" (oldmsr));
98
99 mem_range_end = physAddr;
100
101 printf("Actual RAM: %d Mb\n", physAddr >> 20);
102 return 1;
103 }
104
105 /* Most PReP hardware is in standard locations, based on the corresponding
106 * hardware on PCs. */
107 PCONFIGURATION_COMPONENT_DATA PpcPrepHwDetect() {
108 PCONFIGURATION_COMPONENT_DATA SystemKey;
109
110 /* Create the 'System' key */
111 FldrCreateSystemKey(&SystemKey);
112
113 printf("DetectHardware() Done\n");
114 return SystemKey;
115 }
116
117 VOID
118 PpcPrepHwIdle(VOID)
119 {
120 /* UNIMPLEMENTED */
121 }
122
123 void PpcPrepInit()
124 {
125 MachVtbl.ConsPutChar = PpcPrepPutChar;
126
127 printf("Serial on\n");
128
129 ide_setup( &ide1_desc );
130
131 MachVtbl.DiskReadLogicalSectors = PpcPrepDiskReadLogicalSectors;
132
133 MachVtbl.ConsKbHit = PpcPrepConsKbHit;
134 MachVtbl.ConsGetCh = PpcPrepConsGetCh;
135
136 MachVtbl.VideoClearScreen = PpcPrepVideoClearScreen;
137 MachVtbl.VideoSetDisplayMode = PpcPrepVideoSetDisplayMode;
138 MachVtbl.VideoGetDisplaySize = PpcPrepVideoGetDisplaySize;
139
140 MachVtbl.GetMemoryMap = PpcPrepGetMemoryMap;
141 MachVtbl.HwDetect = PpcPrepHwDetect;
142 MachVtbl.HwIdle = PcPrepHwIdle;
143
144 printf( "FreeLDR version [%s]\n", GetFreeLoaderVersionString() );
145
146 BootMain( "" );
147 }
148