2 * FreeLoader PowerPC Part
3 * Copyright (C) 2005 Art Yerkes
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 extern void BootMain( char * );
24 extern char *GetFreeLoaderVersionString();
25 ULONG BootPartition
= 0;
29 void *PageDirectoryStart
, *PageDirectoryEnd
;
30 static int chosen_package
, stdin_handle
;
31 BOOLEAN AcpiPresent
= FALSE
;
34 void le_swap( const void *start_addr_v
,
35 const void *end_addr_v
,
36 const void *target_addr_v
) {
37 long *start_addr
= (long *)ROUND_DOWN((long)start_addr_v
,8),
38 *end_addr
= (long *)ROUND_UP((long)end_addr_v
,8),
39 *target_addr
= (long *)ROUND_DOWN((long)target_addr_v
,8);
41 while( start_addr
<= end_addr
) {
43 target_addr
[0] = REV(start_addr
[1]);
44 target_addr
[1] = REV(tmp
);
50 int ofw_finddevice( const char *name
) {
54 le_swap( name
, name
+ len
, name
);
55 ret
= ofproxy( 0, (char *)name
, NULL
, NULL
, NULL
);
56 le_swap( name
, name
+ len
, name
);
60 int ofw_getprop( int package
, const char *name
, void *buffer
, int buflen
) {
61 int ret
, len
= strlen(name
);
62 le_swap( name
, name
+ len
, name
);
63 le_swap( buffer
, buffer
+ buflen
, buffer
);
65 ( 4, (void *)package
, (char *)name
, buffer
, (void *)buflen
);
66 le_swap( buffer
, buffer
+ buflen
, buffer
);
67 le_swap( name
, name
+ len
, name
);
71 int ofw_write( int handle
, const char *data
, int len
) {
73 le_swap( data
, data
+ len
, data
);
75 ( 8, (void *)handle
, (char *)data
, (void *)len
, NULL
);
76 le_swap( data
, data
+ len
, data
);
80 int ofw_read( int handle
, const char *data
, int len
) {
82 le_swap( data
, data
+ len
, data
);
84 ( 12, (void *)handle
, (char *)data
, (void *)len
, NULL
);
85 le_swap( data
, data
+ len
, data
);
90 ofproxy( 16, NULL
, NULL
, NULL
, NULL
);
94 ofproxy( 20, NULL
, NULL
, NULL
, NULL
);
97 void ofw_print_string( const char *str
) {
98 int len
= strlen(str
);
99 le_swap( (char *)str
, str
+ len
, (char *)str
);
100 ofproxy( 24, (void *)str
, NULL
, NULL
, NULL
);
101 le_swap( (char *)str
, str
+ len
, (char *)str
);
104 void ofw_print_number( int num
) {
105 ofproxy( 28, (void *)num
, NULL
, NULL
, NULL
);
108 void PpcPutChar( int ch
) {
110 if( ch
== 0x0a ) { buf
[0] = 0x0d; buf
[1] = 0x0a; }
111 else { buf
[0] = ch
; buf
[1] = 0; }
113 ofw_print_string( buf
);
116 BOOL
PpcConsKbHit() {
122 ofw_read( stdin_handle
, &buf
, 1 );
126 void PpcVideoClearScreen( UCHAR Attr
) {
127 ofw_print_string("ClearScreen\n");
130 VIDEODISPLAYMODE
PpcVideoSetDisplayMode( char *DisplayMode
, BOOL Init
) {
131 printf( "DisplayMode: %s %s\n", DisplayMode
, Init
? "true" : "false" );
132 return VideoGraphicsMode
;
136 VOID
PpcVideoGetDisplaySize( PULONG Width
, PULONG Height
, PULONG Depth
) {
137 ofw_print_string("GetDisplaySize\n");
143 ULONG
PpcVideoGetBufferSize() {
144 ULONG Width
, Height
, Depth
;
145 ofw_print_string("PpcVideoGetBufferSize\n");
146 PpcVideoGetDisplaySize( &Width
, &Height
, &Depth
);
147 return Width
* Height
* Depth
/ 8;
150 VOID
PpcVideoSetTextCursorPosition( ULONG X
, ULONG Y
) {
151 printf("SetTextCursorPosition(%d,%d)\n", X
,Y
);
154 VOID
PpcVideoHideShowTextCursor( BOOL Show
) {
155 printf("HideShowTextCursor(%s)\n", Show
? "true" : "false");
158 VOID
PpcVideoPutChar( int Ch
, UCHAR Attr
, unsigned X
, unsigned Y
) {
159 printf( "\033[%d;%dH%c", Y
, X
, Ch
);
162 VOID
PpcVideoCopyOffScreenBufferToVRAM( PVOID Buffer
) {
163 printf( "CopyOffScreenBufferToVRAM(%x)\n", Buffer
);
166 BOOL
PpcVideoIsPaletteFixed() {
170 VOID
PpcVideoSetPaletteColor( UCHAR Color
,
171 UCHAR Red
, UCHAR Green
, UCHAR Blue
) {
172 printf( "SetPaletteColor(%x,%x,%x,%x)\n", Color
, Red
, Green
, Blue
);
175 VOID
PpcVideoGetPaletteColor( UCHAR Color
,
176 UCHAR
*Red
, UCHAR
*Green
, UCHAR
*Blue
) {
177 printf( "GetPaletteColor(%x)\n", Color
);
180 VOID
PpcVideoSync() {
184 VOID
PpcVideoPrepareForReactOS() {
185 printf( "PrepareForReactOS\n");
188 * According to the linux people (this is backed up by my own experience),
189 * the memory object in older ofw does not do getprop right.
191 * The "right" way is to probe the pci bridge. *sigh*
193 ULONG
PpcGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap
,
194 ULONG MaxMemoryMapSize
) {
195 printf("GetMemoryMap(chosen=%x)\n", chosen_package
);
197 BiosMemoryMap
[0].Type
= MEMTYPE_USABLE
;
198 BiosMemoryMap
[0].BaseAddress
= 0;
199 BiosMemoryMap
[0].Length
= 32 * 1024 * 1024; /* Assume 32 meg for now */
201 printf( "Returning memory map (%dk total)\n",
202 (int)BiosMemoryMap
[0].Length
/ 1024 );
207 BOOL
PpcDiskReadLogicalSectors( ULONG DriveNumber
, ULONGLONG SectorNumber
,
208 ULONG SectorCount
, PVOID Buffer
) {
209 printf("DiskReadLogicalSectors\n");
213 BOOL
PpcDiskGetPartitionEntry( ULONG DriveNumber
, ULONG PartitionNumber
,
214 PPARTITION_TABLE_ENTRY PartitionTableEntry
) {
215 printf("GetPartitionEntry(%d,%d)\n", DriveNumber
, PartitionNumber
);
219 BOOL
PpcDiskGetDriveGeometry( ULONG DriveNumber
, PGEOMETRY DriveGeometry
) {
220 printf("GetGeometry(%d)\n", DriveNumber
);
224 ULONG
PpcDiskGetCacheableBlockCount( ULONG DriveNumber
) {
225 printf("GetCacheableBlockCount\n");
229 VOID
PpcRTCGetCurrentDateTime( PULONG Hear
, PULONG Month
, PULONG Day
,
230 PULONG Hour
, PULONG Minute
, PULONG Second
) {
231 printf("RTCGeturrentDateTime\n");
237 void PpcInit( of_proxy the_ofproxy
) {
238 ofproxy
= the_ofproxy
;
239 chosen_package
= ofw_finddevice( "/chosen" );
241 ofw_getprop( chosen_package
, "stdin",
242 &stdin_handle
, sizeof(stdin_handle
) );
244 stdin_handle
= REV(stdin_handle
);
246 MachVtbl
.ConsPutChar
= PpcPutChar
;
247 MachVtbl
.ConsKbHit
= PpcConsKbHit
;
248 MachVtbl
.ConsGetCh
= PpcConsGetCh
;
250 printf("chosen_package = %x\n", chosen_package
);
252 MachVtbl
.VideoClearScreen
= PpcVideoClearScreen
;
253 MachVtbl
.VideoSetDisplayMode
= PpcVideoSetDisplayMode
;
254 MachVtbl
.VideoGetDisplaySize
= PpcVideoGetDisplaySize
;
255 MachVtbl
.VideoGetBufferSize
= PpcVideoGetBufferSize
;
256 MachVtbl
.VideoSetTextCursorPosition
= PpcVideoSetTextCursorPosition
;
257 MachVtbl
.VideoHideShowTextCursor
= PpcVideoHideShowTextCursor
;
258 MachVtbl
.VideoPutChar
= PpcVideoPutChar
;
259 MachVtbl
.VideoCopyOffScreenBufferToVRAM
=
260 PpcVideoCopyOffScreenBufferToVRAM
;
261 MachVtbl
.VideoIsPaletteFixed
= PpcVideoIsPaletteFixed
;
262 MachVtbl
.VideoSetPaletteColor
= PpcVideoSetPaletteColor
;
263 MachVtbl
.VideoGetPaletteColor
= PpcVideoGetPaletteColor
;
264 MachVtbl
.VideoSync
= PpcVideoSync
;
265 MachVtbl
.VideoPrepareForReactOS
= PpcVideoPrepareForReactOS
;
267 MachVtbl
.GetMemoryMap
= PpcGetMemoryMap
;
269 MachVtbl
.DiskReadLogicalSectors
= PpcDiskReadLogicalSectors
;
270 MachVtbl
.DiskGetPartitionEntry
= PpcDiskGetPartitionEntry
;
271 MachVtbl
.DiskGetDriveGeometry
= PpcDiskGetDriveGeometry
;
272 MachVtbl
.DiskGetCacheableBlockCount
= PpcDiskGetCacheableBlockCount
;
274 MachVtbl
.RTCGetCurrentDateTime
= PpcRTCGetCurrentDateTime
;
276 MachVtbl
.HwDetect
= PpcHwDetect
;
278 printf( "FreeLDR version [%s]\n", GetFreeLoaderVersionString() );
279 BootMain("freeldr-ppc");
282 void MachInit(char *CmdLine
) {
284 printf( "Determining boot device:\n" );
285 len
= ofw_getprop(chosen_package
, "bootpath",
286 BootPath
, sizeof(BootPath
));
287 printf( "Got %d bytes of path\n", len
);
289 printf( "Boot Path: %s\n", BootPath
);
291 printf( "FreeLDR starting\n" );
294 void FrLdrSetupPageDirectory() {
300 UCHAR STDCALL
READ_PORT_UCHAR(PUCHAR Address
) {
304 void WRITE_PORT_UCHAR(PUCHAR Address
, UCHAR Value
) {