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
|
/* $NetBSD: bsdbooter.c,v 1.1 1996/01/31 23:18:08 mark Exp $ */
/*
* Copyright (c) 1994,1995 Mark Brinicombe.
* Copyright (c) 1994,1995 Brini.
* All rights reserved.
*
* This code is derived from software written for Brini by Mark Brinicombe
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* RiscBSD kernel project
*
* bsdbooter.c
*
* RiscBSD boot loader
*
* Created : 12/09/94
* Last updated : 08/03/95
*
* Based on kate/boot/boot.c
*
* $Id: bsdbooter.c,v 1.1 1996/04/24 11:08:31 deraadt Exp $
*/
/* Include standard header files */
# include <stdlib.h>
# include <string.h>
# include <stdarg.h>
/* Include local headers */
#include <sys/types.h>
#include <sys/exec.h>
#include <machine/cpu.h>
#include <machine/katelib.h>
#include <machine/bootconfig.h>
#include "swiv.h"
#include "swis.h"
/*
* Declare global variables
*/
# define VERSION "2.10"
# define USE_MODULEAREA
# define KERNAREA 512
# define KERNBASE 0xf0000000
# define TABLEAREA 513
# define LOADAREA 514
# define SCRATCHSIZE 0xc000
# define OS_DynamicArea 0x66
# define OS_Memory 0x68
# define OS_MMUControl 0x6b
# define FASTBOOT_FILENAME "<BtRiscBSD$Dir>.booter.fastboot"
/*
* Declare external variables
*/
extern char *__cli;
/*
* Local vars. Some of these have to be global because they are used after
* the processor has been switches to SVC mode local variables would be
* lost as they would be on the USR mode stack.
*/
typedef struct exec aout_t;
BootConfig bootconfig;
int in[3], out[3];
char kernelname[1024];
unsigned char *buffer;
static aout_t aout;
unsigned int kernelsize;
unsigned int logical;
unsigned int physical;
unsigned int filesize;
unsigned int copysize;
/*
* Local function prototypes
*/
void fatal(struct Error *error);
unsigned char *locate_memory_blocks(void);
void uprintf(char *formattoken, ...);
void _bsdboot(BootConfig *bootconfig, unsigned int address);
int vsprintf(char *buf, const char *fmt, va_list args);
/* Now for the main code */
extern int main (int, char **);
void __exit(int);
void _main(void)
{
uprintf("_main entered\n");
__exit (main (0, (char **)0)); /* ... ignition */
/* not reached */
}
/* The main booter code */
int main(int argc, char *argv[])
{
char *cliptr;
int loop;
int filehandle;
unsigned char *arrangementtable;
uprintf("main entered\n");
/* Analyse the command line */
cliptr = __cli;
uprintf("command line is %s\n", cliptr);
/* Skip the command name */
while (*cliptr != ' ' && *cliptr != 0)
++cliptr;
/* Skip any spaces */
while (*cliptr == ' ')
++cliptr;
/* Check for another parameter */
if (*cliptr != 0)
{
for (loop = 0; *cliptr != ' ' && *cliptr != 0; ++loop,++cliptr)
{
kernelname[loop] = *cliptr;
}
kernelname[loop] = 0;
}
else
strcpy(kernelname, "riscbsd");
strcpy(bootconfig.kernelname, kernelname);
/* Write the command line used to a fastboot file. Execing or Obeying
* this file will boot RiscBSD. This can be used during the RiscOS bootup
* to enable a fast boot.
*/
/*
* Open the autoboot file. Just skip if file cannot be opened.
*/
swi(OS_Find, IN(R0|R1)|OUT(R0), 0x80, FASTBOOT_FILENAME, &filehandle);
if (filehandle != 0)
{
swi(OS_GBPB, IN(R0|R1|R2|R3|R4), 2, filehandle, __cli,
strlen(__cli), 0);
swi(OS_GBPB, IN(R0|R1|R2|R3|R4), 2, filehandle, "\n", 1, 0);
/* Close the file */
swi(OS_Find, IN(R0|R1), 0, filehandle);
swi(OS_File, IN(R0|R1|R2), 18, FASTBOOT_FILENAME, 0xfeb);
}
else
{
uprintf("Warning: Cannot write fastboot file %s\n\r", FASTBOOT_FILENAME);
}
/* Set the screen mode ... */
/* I know this is messy. It is currently just a hack to try things out
* Why didn't Acorn add a SWI call to interpret the mode string and return
* a mode specifer ?
*/
/* Also this is temporary as eventually the console driver will set the VIDC
* up as required.
* It sort of expects the screenmode= options to be at the end of the string.
*/
{
char *modeptr;
int modespec[6];
modeptr = strstr(__cli, "screenmode=");
if (modeptr)
{
modeptr += 11;
modespec[0] = 0x00000001;
modespec[1] = 0x00000000;
modespec[2] = 0x00000000;
modespec[3] = 0x00000003;
modespec[4] = 0x00000000;
modespec[5] = -1;
while (*modeptr)
{
switch (*modeptr)
{
case 'X':
case 'x':
++modeptr;
while (*modeptr >= '0' && *modeptr <= '9')
{
modespec[1] = (modespec[1] * 10) + (*modeptr - '0');
++modeptr;
}
break;
case 'Y':
case 'y':
++modeptr;
while (*modeptr >= '0' && *modeptr <= '9')
{
modespec[2] = (modespec[2] * 10) + (*modeptr - '0');
++modeptr;
}
break;
/*
case 'C':
case 'c':
case 'G':
case 'g':
++modeptr;
while (*modeptr >= '0' && *modeptr <= '9')
{
modespec[3] = (modespec[3] * 10) + (*modeptr - '0');
++modeptr;
}
break;
*/
case 'F':
case 'f':
++modeptr;
while (*modeptr >= '0' && *modeptr <= '9')
{
modespec[4] = (modespec[4] * 10) + (*modeptr - '0');
++modeptr;
}
break;
default:
++modeptr;
break;
}
}
if (modespec[4] == 0) modespec[4] = -1;
/* uprintf("x=%d y=%d c=%d f=%d\n", modespec[1], modespec[2],
modespec[3], modespec[4]);*/
fatal(swix(Wimp_SetMode, IN(R0), &modespec));
bootconfig.framerate = modespec[4];
}
else
bootconfig.framerate = 0;
}
/* Announcement time .. */
/* Used to be above but now moved to after the mode change */
if (strstr(__cli, "verbose") != 0)
uprintf("RiscBSD BootLoader " VERSION " " __DATE__ "\n\r");
/* A bit of info */
if (strstr(__cli, "verbose") != 0)
uprintf("Kernel: %s\n\r", kernelname);
/* Get the machine id */
fatal(swix(OS_ReadSysInfo, IN(R0)|OUT(R3), 2, &bootconfig.machine_id));
/* Get the display variables. Failure on any of these will abort the boot */
in[0] = 149;
in[1] = 150;
in[2] = -1;
fatal(swix(OS_ReadVduVariables, IN(R0|R1), &in, &out));
bootconfig.display_start = out[0];
bootconfig.display_size = out[1];
fatal(swix(OS_ReadModeVariable, IN(R0|R1) | OUT(R2), -1, 9,
&bootconfig.bitsperpixel));
fatal(swix(OS_ReadModeVariable, IN(R0|R1) | OUT(R2), -1, 11,
&bootconfig.width));
fatal(swix(OS_ReadModeVariable, IN(R0|R1) | OUT(R2), -1, 12,
&bootconfig.height));
/* Will the kernel support this mode ? */
if (bootconfig.bitsperpixel > 3)
{
swi(OS_Write0, IN(R0),
"Error: Only 1, 2, 4 or 8 bpp modes are currently supported\n\r");
return(0);
}
/* Get the arrangement table for the memory */
arrangementtable = locate_memory_blocks();
/*
* Ok we will support a.out files as well. This means that we need to
* identify the format.
*/
/* Get the size of the file */
fatal(swix(OS_File, IN(R0|R1)|OUT(R4), 5, kernelname, &filesize));
/*
* Read the start of the file so that we change check for the a.out
* magic number.
*/
swi(OS_Find, IN(R0|R1)|OUT(R0), 0x40, kernelname, &filehandle);
if (filehandle == 0)
{
uprintf("Error: Cannot read kernel file %s\n\r", kernelname);
return(0);
}
aout.a_midmag = 0;
fatal(swix(OS_GBPB, IN(R0|R1|R2|R3|R4), 3, filehandle, &aout,
sizeof(aout_t), 0));
/* Do we have an a.out file ? */
switch(N_GETMAGIC(aout)) {
case NMAGIC:
if (strstr(__cli, "verbose") != 0)
swi(OS_Write0, IN(R0), "Kernel binary is NMAGIC a.out format\n\r");
kernelsize = (unsigned int)(aout.a_text + aout.a_data + aout.a_bss);
copysize = (unsigned int)(aout.a_text + aout.a_data);
break;
case OMAGIC:
if (strstr(__cli, "verbose") != 0)
swi(OS_Write0, IN(R0), "Kernel binary is OMAGIC a.out format\n\r");
kernelsize = (unsigned int)(aout.a_text + aout.a_data + aout.a_bss);
copysize = (unsigned int)(aout.a_text + aout.a_data);
break;
case ZMAGIC:
if (strstr(__cli, "verbose") != 0)
swi(OS_Write0, IN(R0), "Kernel binary is ZMAGIC a.out format\n\r");
kernelsize = (unsigned int)(aout.a_text + aout.a_data + aout.a_bss);
copysize = (unsigned int)(aout.a_text + aout.a_data);
break;
default:
if (strstr(__cli, "verbose") != 0)
swi(OS_Write0, IN(R0), "Kernel binary is AIF format\n\r");
kernelsize = filesize;
copysize = filesize;
break;
}
/* Give ourselves 16K of spare space and round off to a page */
/*
* This is messy. We should read the memory info first, but I have not
* changed things yet. This is part of the hack to support a.out files
* as well
*/
kernelsize = (kernelsize + 0x4000) & ~(bootconfig.pagesize-1);
/* Set the virtual address of the kernel in the bootconfig structure */
bootconfig.kernvirtualbase = KERNBASE;
bootconfig.kernsize = kernelsize;
bootconfig.argvirtualbase = bootconfig.kernvirtualbase
+ bootconfig.kernsize;
bootconfig.argsize = bootconfig.pagesize;
bootconfig.scratchvirtualbase = bootconfig.argvirtualbase
+ bootconfig.argsize;
bootconfig.scratchsize = SCRATCHSIZE;
kernelsize += bootconfig.argsize;
kernelsize += bootconfig.scratchsize;
/* Verbose info to the user. This is mainly debugging */
if (strstr(__cli, "verbose") != 0)
{
uprintf("filesize = %08x\n\r", filesize);
uprintf("bootconfig.kernvirtualbase = %08x\n\r",
bootconfig.kernvirtualbase);
uprintf("bootconfig.kernsize = %08x\n\r", bootconfig.kernsize);
uprintf("bootconfig.argvirtualbase = %08x\n\r",
bootconfig.argvirtualbase);
uprintf("bootconfig.argsize = %08x\n\r", bootconfig.argsize);
uprintf("bootconfig.scratchvirtualbase = %08x\n\r",
bootconfig.scratchvirtualbase);
uprintf("bootconfig.scratchsize = %08x\n\r", bootconfig.scratchsize);
uprintf("kernelsize = %08x\n\r", kernelsize);
uprintf("copysize = %08x\n\r", copysize);
}
# ifdef USE_MODULEAREA
/* Allocate memory in module area to hold the data we are loading */
fatal(swix(OS_Module, IN(R0|R3)|OUT(R2), 6, filesize, &buffer));
# else
/* Allocate memory to hold the data we are loading */
swix(OS_DynamicArea, IN(R0|R1), 1, LOADAREA);
fatal(swix(OS_DynamicArea, IN(R0|R1|R2|R3|R4|R5|R6|R7|R8)|OUT(R3), 0,
LOADAREA, filesize, -1, 0x80, filesize, 0, 0, "Kate Data", &buffer));
# endif
/* Load the appropriate part depending on the file type */
switch (N_GETMAGIC(aout)) {
case OMAGIC:
case NMAGIC:
swi(OS_GBPB, IN(R0|R1|R2|R3|R4), 3, filehandle, buffer,
filesize, sizeof(aout_t));
break;
case ZMAGIC:
default:
swi(OS_GBPB, IN(R0|R1|R2|R3|R4), 3, filehandle, buffer,
filesize, 0);
break;
}
/* Close the file */
fatal(swix(OS_Find, IN(R0|R1), 0, filehandle));
/* This is redundant at the moment */
swix(OS_DynamicArea, IN(R0|R1), 1, KERNAREA);
fatal(swix(OS_DynamicArea, IN(R0|R1|R2|R3|R4|R5|R6|R7|R8), 0,
KERNAREA, 0, KERNBASE, 0x80, 0x1000, 0, 0, "Kate Kernel"));
/* Shutdown RiscOS cleanly ... */
/* Close all open files and shutdown filing systems */
swix(OS_FSControl, IN(R0), 23);
/* Issue a pre-reset service call to reset the podules */
swix(OS_ServiceCall, IN(R1), 0x45);
/* Kill the etherH module to avoid locks up on reboot */
swix(OS_Module, IN(R0|R1), 4, "EtherH");
/* More user information describing the memory found */
if (strstr(__cli, "verbose") != 0)
{
uprintf("DRAM bank 0a = %08x %08x\n\r", bootconfig.dram[0].address,
bootconfig.dram[0].pages * bootconfig.pagesize);
uprintf("DRAM bank 0b = %08x %08x\n\r", bootconfig.dram[1].address,
bootconfig.dram[1].pages * bootconfig.pagesize);
uprintf("DRAM bank 1a = %08x %08x\n\r", bootconfig.dram[2].address,
bootconfig.dram[2].pages * bootconfig.pagesize);
uprintf("DRAM bank 1b = %08x %08x\n\r", bootconfig.dram[3].address,
bootconfig.dram[3].pages * bootconfig.pagesize);
uprintf("VRAM bank 0 = %08x %08x\n\r", bootconfig.vram[0].address,
bootconfig.vram[0].pages * bootconfig.pagesize);
}
/* Hack for 2 Meg VRAM until the new console code is in place */
/* if (strstr(__cli, "vramhack") != 0)
{
bootconfig.display_size /= 1;
bootconfig.vram[0].pages /= 2;
uprintf("VRAM bank 0 = %08x %08x\n\r", bootconfig.vram[0].address,
bootconfig.vram[0].pages * bootconfig.pagesize);
}*/
/* Jump to SVC26 mode - remember we have no local vars now ! */
EnterOS();
/* Find the number of the upper most bank of DRAM available */
loop = 3;
while (bootconfig.dram[loop].address == 0)
--loop;
/* Allocate the physical addresses for the kernel in this bank */
physical = bootconfig.dram[loop].address - kernelsize
+ bootconfig.dram[loop].pages * bootconfig.pagesize;
bootconfig.kernphysicalbase = physical;
bootconfig.argphysicalbase = bootconfig.kernphysicalbase
+ bootconfig.kernsize;
bootconfig.scratchphysicalbase = bootconfig.argphysicalbase
+ bootconfig.argsize;
/* Yet more debugging info */
if (strstr(__cli, "verbose") != 0)
{
uprintf("buffer = %08x\n\r", buffer);
uprintf("physical = %08x\n\r", physical);
uprintf("bootconfig.kernphysicalbase = %08x\n\r",
bootconfig.kernphysicalbase);
uprintf("bootconfig.argphysicalbase = %08x\n\r",
bootconfig.argphysicalbase);
uprintf("bootconfig.scratchphysicalbase = %08x\n\r",
bootconfig.scratchphysicalbase);
}
/*
* Ok just check to see if anything is mapped where we are about to map
* the kernel.
*/
/*
for (logical = KERNBASE; logical < KERNBASE + kernelsize;
logical += bootconfig.pagesize)
{
if (ReadWord(0x02c00000 + (logical >> 10) & 0xfffffffc) != 0)
{
uprintf("Error: Memory required for RiscBSD boot not available\n\r");
return(0);
}
}
*/
/* Get out clause */
if (strstr(__cli, "noboot") != 0)
{
ExitOS();
return(0);
}
/*
* Hook the physical pages to the required virtual address directly by
* writing into RiscOS's page tables. This should be done via a
* dynamic area handler but I cannot get it to work as documented.
*/
for (logical = KERNBASE; logical < KERNBASE + kernelsize;
logical += bootconfig.pagesize)
{
WriteWord(0x02c00000 + (logical >> 10) & 0xfffffffc,
0x00000ffe | (physical & 0xfffff000));
physical += bootconfig.pagesize;
}
/* Map the IO up high so we can get at it */
WriteWord(0x02c0c000 + (0xf6000000 >> 18) & 0xfffffffc,
0x00000412 | (0x03200000 & 0xfffff000));
WriteWord(0x02c0c000 + (0xf6100000 >> 18) & 0xfffffffc,
0x00000412 | (0x03400000 & 0xfffff000));
memset((char *)bootconfig.display_start, 0xcc, 0x4000);
/* Disable IRQ and FIQ interrupts */
SetCPSR(I32_bit | F32_bit, I32_bit | F32_bit);
memset((char *)bootconfig.display_start + 0x4000, 0x55, 0x4000);
memcpy((char *)bootconfig.argvirtualbase, __cli, bootconfig.argsize);
memset((char *)bootconfig.display_start + 0x8000, 0x80, 0x4000);
memset((char *)bootconfig.argvirtualbase, SCRATCHSIZE, 0);
memset((char *)bootconfig.display_start + 0xC000, 0xbb, 0x4000);
memcpy((char *)bootconfig.kernvirtualbase, buffer, copysize);
memset((char *)bootconfig.display_start + 0x10000, 0xaa, 0x4000);
/* Real late debugging get out clause */
if (strstr(__cli, "nearboot") != 0)
{
SetCPSR(I32_bit | F32_bit, 0);
ExitOS();
return(0);
}
/* Punch into SVC32 mode */
SVC32();
/* Point of no return */
switch (N_GETMAGIC(aout)) {
case OMAGIC:
case NMAGIC:
case ZMAGIC:
_bsdboot(&bootconfig, (unsigned int)aout.a_entry);
break;
default:
_bsdboot(&bootconfig, KERNBASE);
break;
}
return(0);
}
/* Report an error */
void fatal(struct Error *error)
{
if (error)
{
swi(OS_GenerateError, IN(R0), error);
}
}
/* Locate all the blocks of memory in the system */
unsigned char *locate_memory_blocks(void)
{
int loop;
int page;
int currentpage;
int currentpages;
int currentaddr;
unsigned char *table;
unsigned int pagesize;
unsigned int tablesize;
int dramblocks = 0;
int vramblocks = 0;
/* Get table size and page size */
fatal(swix(OS_Memory, IN(R0)|OUT(R1|R2), 6, &tablesize, &pagesize));
/* Allocate memory for table */
/*# ifdef USE_MODULEAREA*/
fatal(swix(OS_Module, IN(R0|R3)|OUT(R2), 6, tablesize, &table));
/*# else*/
/* Allocate memory to hold the data we are loading */
/* swix(OS_DynamicArea, IN(R0|R1), 1, TABLEAREA);
fatal(swix(OS_DynamicArea, IN(R0|R1|R2|R3|R4|R5|R6|R7|R8)|OUT(R3), 0,
TABLEAREA, tablesize, -1, 0x80, tablesize, 0, 0, "Kate Table", &table));
# endif*/
/* read the table */
fatal(swix(OS_Memory, IN(R0|R1), 7, table));
/* Loop round locating all the valid blocks of memory */
currentpage = -1;
for (loop = 0; loop < tablesize * 2; ++loop)
{
page = table[loop / 2];
if (loop % 2)
page = page >> 4;
page = page & 0x07;
if (page != currentpage)
{
switch (currentpage)
{
case 1:
bootconfig.dram[dramblocks].address = currentaddr * pagesize;
bootconfig.dram[dramblocks].pages = currentpages;
++dramblocks;
break;
case 2:
bootconfig.vram[vramblocks].address = currentaddr * pagesize;
bootconfig.vram[vramblocks].pages = currentpages;
++vramblocks;
break;
default :
break;
}
currentpage = page;
currentaddr = loop;
currentpages = 0;
}
++currentpages;
}
/* Get the number of dram and vram pages */
fatal(swix(OS_Memory, IN(R0)|OUT(R1), 0x00000108, &bootconfig.drampages));
fatal(swix(OS_Memory, IN(R0)|OUT(R1), 0x00000208, &bootconfig.vrampages));
/* Fill in more bootconfig parameters */
bootconfig.pagesize = pagesize;
bootconfig.dramblocks = dramblocks;
bootconfig.vramblocks = vramblocks;
return(table);
}
/* printf ... */
void uprintf(char *formattoken, ...)
{
va_list ap;
char temp[1024];
temp[0] = '\0';
va_start(ap, formattoken);
vsprintf(temp, formattoken, ap);
va_end(ap);
swi(OS_Write0, IN(R0), temp);
}
/* End of bsdbooter.c */
|