-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbootos_linux.cpp
673 lines (577 loc) · 18.8 KB
/
bootos_linux.cpp
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
/*
ROM / OS loader, Linux/m68k
ARAnyM (C) 2005-2008 Patrice Mandin
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdeps.h"
#include "cpu_emulation.h"
#include "bootos_linux.h"
#include "aranym_exception.h"
#include "emul_op.h"
#define DEBUG 0
#include "debug.h"
#include "SDL_compat.h"
#ifdef ENABLE_LILO
#ifdef HAVE_LIBZ
#include <zlib.h>
#endif
#include "bootos_elf.h"
/* #include <asm-m68k/bootinfo.h> */
struct bi_record {
uint16 tag; /* tag ID */
uint16 size; /* size of record (in bytes) */
uint32 data[0]; /* data */
};
/*
* Tag Definitions
*
* Machine independent tags start counting from 0x0000
* Machine dependent tags start counting from 0x8000
*/
#define BI_LAST 0x0000 /* last record (sentinel) */
#define BI_MACHTYPE 0x0001 /* machine type (u_long) */
#define BI_CPUTYPE 0x0002 /* cpu type (u_long) */
#define BI_FPUTYPE 0x0003 /* fpu type (u_long) */
#define BI_MMUTYPE 0x0004 /* mmu type (u_long) */
#define BI_MEMCHUNK 0x0005 /* memory chunk address and size */
/* (struct mem_info) */
#define BI_RAMDISK 0x0006 /* ramdisk address and size */
/* (struct mem_info) */
#define BI_COMMAND_LINE 0x0007 /* kernel command line parameters */
/* (string) */
/*
* Atari-specific tags
*/
#define BI_ATARI_MCH_COOKIE 0x8000 /* _MCH cookie from TOS (u_long) */
#define BI_ATARI_MCH_TYPE 0x8001 /* special machine type (u_long) */
/* mch_type values */
#define ATARI_MACH_AB40 3 /* Afterburner040 on Falcon */
/* #include <asm-m68k/setup.h> */
/*
* Linux/m68k Architectures
*/
#define MACH_ATARI 2
/*
* CPU, FPU and MMU types
*
* Note: we may rely on the following equalities:
*
* CPU_68020 == MMU_68851
* CPU_68030 == MMU_68030
* CPU_68040 == FPU_68040 == MMU_68040
* CPU_68060 == FPU_68060 == MMU_68060
*/
#define CPUB_68040 2
#define CPU_68040 (1<<CPUB_68040)
#define FPUB_68040 2 /* Internal FPU */
#define FPU_68040 (1<<FPUB_68040)
#define MMUB_68040 2 /* Internal MMU */
#define MMU_68040 (1<<MMUB_68040)
#ifdef PAGE_SIZE
/* Might have been defined by vm_param.h. already, indirectly included by sysdeps.h */
#undef PAGE_SIZE
#endif
#define PAGE_SIZE 4096
/*--- Defines ---*/
#define MAXREAD_BLOCK_SIZE (1<<20) /* 1 MB */
#define KERNEL_START PAGE_SIZE /* Start address of kernel in Atari RAM */
#define RAMDISK_FS_START 0 /* Offset to start of fs in ramdisk file */
#define MAX_BI_SIZE (4096)
#define GRANULARITY (256*1024) /* min unit for memory */
#define ADD_CHUNK(start,siz) \
{ \
unsigned long _start = (start); \
unsigned long _size = (siz) & ~(GRANULARITY-1); \
\
if (_size > 0) { \
bi.memory[bi.num_memory].addr = SDL_SwapBE32(_start); \
bi.memory[bi.num_memory].size = SDL_SwapBE32(_size); \
bi.num_memory++; \
} \
}
/*--- Structures ---*/
static union {
struct bi_record record;
unsigned char fake[MAX_BI_SIZE];
} bi_union;
#endif
/* Linux/m68k loader class */
LinuxBootOs::LinuxBootOs(void) ARANYM_THROWS(AranymException)
{
/* RESET + Linux/m68k boot */
ROMBaseHost[0x0000] = 0x4e; /* reset */
ROMBaseHost[0x0001] = 0x70;
ROMBaseHost[0x0002] = 0x4e; /* jmp <abs.addr> */
ROMBaseHost[0x0003] = 0xf9;
if (!halt_on_reboot) {
/* set up a minimal OS for successful Linux/m68k reboot */
ROMBaseHost[0x0030] = 0x46; /* move.w #$2700,sr */
ROMBaseHost[0x0031] = 0xfc;
ROMBaseHost[0x0032] = 0x27;
ROMBaseHost[0x0033] = 0x00;
ROMBaseHost[0x0034] = 0x4e; /* reset */
ROMBaseHost[0x0035] = 0x70;
ROMBaseHost[0x0036] = M68K_EMUL_RESET >> 8;
ROMBaseHost[0x0037] = M68K_EMUL_RESET & 0xff;
}
else {
/* code that shuts ARAnyM down when Linux/m68k tries to reboot */
ROMBaseHost[0x0030] = 0x48; /* pea.l NF_SHUTDOWN(pc) */
ROMBaseHost[0x0031] = 0x7a;
ROMBaseHost[0x0032] = 0x00;
ROMBaseHost[0x0033] = 0x0c;
ROMBaseHost[0x0034] = 0x59; /* subq.l #4,sp */
ROMBaseHost[0x0035] = 0x8f;
ROMBaseHost[0x0036] = 0x73; /* NF_ID */
ROMBaseHost[0x0037] = 0x00;
ROMBaseHost[0x0038] = 0x2f; /* move.l d0,-(sp) */
ROMBaseHost[0x0039] = 0x00;
ROMBaseHost[0x003a] = 0x59; /* subq.l #4,sp */
ROMBaseHost[0x003b] = 0x8f;
ROMBaseHost[0x003c] = 0x73; /* NF_CALL */
ROMBaseHost[0x003d] = 0x01;
ROMBaseHost[0x003e] = 'N'; /* "NF_SHUTDOWN" */
ROMBaseHost[0x003f] = 'F';
ROMBaseHost[0x0040] = '_';
ROMBaseHost[0x0041] = 'S';
ROMBaseHost[0x0042] = 'H';
ROMBaseHost[0x0043] = 'U';
ROMBaseHost[0x0044] = 'T';
ROMBaseHost[0x0045] = 'D';
ROMBaseHost[0x0046] = 'O';
ROMBaseHost[0x0047] = 'W';
ROMBaseHost[0x0048] = 'N';
ROMBaseHost[0x0049] = 0;
}
init(true);
}
LinuxBootOs::~LinuxBootOs(void)
{
cleanup();
}
void LinuxBootOs::reset(bool cold) ARANYM_THROWS(AranymException)
{
init(cold);
}
/*--- Private functions ---*/
void LinuxBootOs::cleanup(void)
{
if (kernel!=NULL) {
free(kernel);
kernel=NULL;
}
if (ramdisk!=NULL) {
free(ramdisk);
ramdisk=NULL;
}
}
void LinuxBootOs::init(bool cold)
{
kernel=ramdisk=NULL;
kernel_length=ramdisk_length=0;
bi_size = 0;
bi.ramdisk.addr = 0;
bi.ramdisk.size = 0;
UNUSED(cold);
#ifdef ENABLE_LILO
/* Load the kernel */
kernel=loadFile(bx_options.lilo.kernel, &kernel_length);
if (kernel==NULL) {
throw AranymException("ARAnyM LILO: Error loading kernel '%s'", bx_options.lilo.kernel);
}
/* Load the ramdisk */
if (strlen(bx_options.lilo.ramdisk) > 0) {
ramdisk=loadFile(bx_options.lilo.ramdisk, &ramdisk_length);
if (ramdisk==NULL) {
infoprint("ARAnyM LILO: Error loading ramdisk '%s'", bx_options.lilo.ramdisk);
}
}
memset(RAMBaseHost, 0, RAMSize);
memset(FastRAMBaseHost, 0, FastRAMSize);
/* Check the kernel */
if (checkKernel()<0) {
cleanup();
throw AranymException("ARAnyM LILO: Error setting up kernel");
}
/* Kernel and ramdisk copied in Atari RAM, we can free it */
cleanup();
#else
throw AranymException("ARAnyM LILO: not compiled in");
#endif /* ENABLE_LILO */
}
void *LinuxBootOs::loadFile(const char *filename, unsigned long *length)
{
void *buffer = NULL;
#ifdef ENABLE_LILO
#ifdef HAVE_LIBZ
unsigned long unc_len;
gzFile handle;
#else
int handle;
#endif
if (strlen(filename)==0) {
D(bug("lilo: empty filename"));
return NULL;
}
/* Try to open the file, libz takes care of non-gzipped files */
#ifdef HAVE_LIBZ
handle = gzopen(filename, "rb");
if (handle == NULL)
#else
handle = open(filename, O_RDONLY);
if (handle<0)
#endif
{
D(bug("lilo: unable to open %s", filename));
return NULL;
}
#ifdef HAVE_LIBZ
/* Search the length of the uncompressed stream */
buffer = (char *)malloc(MAXREAD_BLOCK_SIZE);
if (buffer==NULL) {
D(bug("lilo: unable to allocate %d bytes", MAXREAD_BLOCK_SIZE));
gzclose(handle);
return NULL;
}
*length = 0;
unc_len = gzread(handle, buffer, MAXREAD_BLOCK_SIZE);
while (unc_len>0) {
*length += unc_len;
unc_len = gzread(handle, buffer, MAXREAD_BLOCK_SIZE);
}
// Avoid gzseek, it is often broken with LFS which we enable by
// default
gzrewind(handle);
D(bug("lilo: uncompressing '%s'", filename));
D(bug("lilo: uncompressed length: %lu bytes", *length));
free(buffer);
buffer=NULL;
#else
*length = lseek(handle, 0, SEEK_END);
lseek(handle, 0, SEEK_SET);
#endif
buffer = (char *)malloc(*length);
if (buffer==NULL) {
D(bug("lilo: unable to allocate %ld bytes", *length));
#ifdef HAVE_LIBZ
gzclose(handle);
#else
close(handle);
#endif
return NULL;
}
#ifdef HAVE_LIBZ
gzread(handle, buffer, *length);
gzclose(handle);
#else
read(handle, buffer, *length);
close(handle);
#endif
#else
UNUSED(filename);
UNUSED(length);
#endif /* ENABLE_LILO */
return buffer;
}
int LinuxBootOs::checkKernel(void)
{
#ifdef ENABLE_LILO
Elf32_Ehdr *kexec_elf; /* header of kernel executable */
Elf32_Phdr *kernel_phdrs;
Elf32_Addr min_addr=0xffffffff, max_addr=0;
Elf32_Addr kernel_size;
Elf32_Addr mem_ptr;
Elf32_Addr kernel_offset;
int i;
const char *kname, *kernel_name="vmlinux";
bool load_to_fastram = bx_options.lilo.load_to_fastram && FastRAMSize > 0;
kexec_elf = (Elf32_Ehdr *) kernel;
if (memcmp( &kexec_elf->e_ident[EI_MAG0], ELFMAG, SELFMAG ) == 0) {
if ((SDL_SwapBE16(kexec_elf->e_type) != ET_EXEC) || (SDL_SwapBE16(kexec_elf->e_machine) != EM_68K) ||
(SDL_SwapBE32(kexec_elf->e_version) != EV_CURRENT)) {
bug("lilo: Invalid ELF header contents in kernel");
return -1;
}
}
/*--- Copy the kernel at start of RAM ---*/
/* Load the program headers */
kernel_phdrs = (Elf32_Phdr *) (((char *) kexec_elf) + SDL_SwapBE32(kexec_elf->e_phoff));
/* calculate the total required amount of memory */
D(bug("lilo: kexec_elf->e_phnum=0x%08x",SDL_SwapBE16(kexec_elf->e_phnum)));
for (i=0; i<SDL_SwapBE16(kexec_elf->e_phnum); i++) {
D(bug("lilo: kernel_phdrs[%d].p_vaddr=0x%08x",i,SDL_SwapBE32(kernel_phdrs[i].p_vaddr)));
D(bug("lilo: kernel_phdrs[%d].p_offset=0x%08x",i,SDL_SwapBE32(kernel_phdrs[i].p_offset)));
D(bug("lilo: kernel_phdrs[%d].p_filesz=0x%08x",i,SDL_SwapBE32(kernel_phdrs[i].p_filesz)));
D(bug("lilo: kernel_phdrs[%d].p_memsz=0x%08x",i,SDL_SwapBE32(kernel_phdrs[i].p_memsz)));
if (min_addr > SDL_SwapBE32(kernel_phdrs[i].p_vaddr)) {
min_addr = SDL_SwapBE32(kernel_phdrs[i].p_vaddr);
}
if (max_addr < SDL_SwapBE32(kernel_phdrs[i].p_vaddr) + SDL_SwapBE32(kernel_phdrs[i].p_memsz)) {
max_addr = SDL_SwapBE32(kernel_phdrs[i].p_vaddr) + SDL_SwapBE32(kernel_phdrs[i].p_memsz);
}
}
/* This is needed for newer linkers that include the header in
the first segment. */
D(bug("lilo: min_addr=0x%08x",min_addr));
D(bug("lilo: max_addr=0x%08x",max_addr));
if (min_addr == 0) {
D(bug("lilo: new linker"));
D(bug("lilo: kernel_phdrs[0].p_vaddr=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_vaddr)));
D(bug("lilo: kernel_phdrs[0].p_offset=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_offset)));
D(bug("lilo: kernel_phdrs[0].p_filesz=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_filesz)));
D(bug("lilo: kernel_phdrs[0].p_memsz=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_memsz)));
min_addr = PAGE_SIZE;
/*kernel_phdrs[0].p_vaddr += PAGE_SIZE;*/
kernel_phdrs[0].p_vaddr = SDL_SwapBE32(SDL_SwapBE32(kernel_phdrs[0].p_vaddr) + PAGE_SIZE);
/*kernel_phdrs[0].p_offset += PAGE_SIZE;*/
kernel_phdrs[0].p_offset = SDL_SwapBE32(SDL_SwapBE32(kernel_phdrs[0].p_offset) + PAGE_SIZE);
/*kernel_phdrs[0].p_filesz -= PAGE_SIZE;*/
kernel_phdrs[0].p_filesz = SDL_SwapBE32(SDL_SwapBE32(kernel_phdrs[0].p_filesz) - PAGE_SIZE);
/*kernel_phdrs[0].p_memsz -= PAGE_SIZE;*/
kernel_phdrs[0].p_memsz = SDL_SwapBE32(SDL_SwapBE32(kernel_phdrs[0].p_memsz) - PAGE_SIZE);
D(bug("lilo: modified to:"));
D(bug("lilo: kernel_phdrs[0].p_vaddr=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_vaddr)));
D(bug("lilo: kernel_phdrs[0].p_offset=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_offset)));
D(bug("lilo: kernel_phdrs[0].p_filesz=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_filesz)));
D(bug("lilo: kernel_phdrs[0].p_memsz=0x%08x",SDL_SwapBE32(kernel_phdrs[0].p_memsz)));
}
kernel_size = max_addr - min_addr;
D(bug("lilo: kernel_size=%u",kernel_size));
if (load_to_fastram)
{
if (KERNEL_START + kernel_size > FastRAMSize)
{
bug("lilo: kernel of size %x does not fit in TT-RAM of size %x", kernel_size, FastRAMSize);
load_to_fastram = false;
}
}
if (!load_to_fastram)
{
if (KERNEL_START + kernel_size > RAMSize)
{
bug("lilo: kernel of size %x does not fit in RAM of size %x", kernel_size, RAMSize);
return -1;
}
}
if (load_to_fastram)
kernel_offset = FastRAMBase;
else
kernel_offset = 0;
mem_ptr = KERNEL_START;
for (i=0; i<SDL_SwapBE16(kexec_elf->e_phnum); i++) {
Elf32_Word segment_length;
Elf32_Addr segment_ptr;
Elf32_Off segment_offset;
segment_offset = SDL_SwapBE32(kernel_phdrs[i].p_offset);
segment_length = SDL_SwapBE32(kernel_phdrs[i].p_filesz);
if (segment_offset == 0xffffffffUL) {
bug("lilo: Failed to seek to segment %d",i);
return -1;
}
segment_ptr = SDL_SwapBE32(kernel_phdrs[i].p_vaddr) - PAGE_SIZE;
if (load_to_fastram)
memcpy(FastRAMBaseHost + mem_ptr + segment_ptr, (char *) kexec_elf + segment_offset, segment_length);
else
memcpy(RAMBaseHost + mem_ptr + segment_ptr, (char *) kexec_elf + segment_offset, segment_length);
D(bug("lilo: Copied segment %d: 0x%08x,0x%08x at 0x%08x",i,segment_offset,segment_length,kernel_offset+mem_ptr+segment_ptr));
}
/*--- Copy the ramdisk after kernel (and reserved bootinfo) ---*/
if (ramdisk && ramdisk_length) {
Elf32_Addr rd_start;
Elf32_Word rd_len;
Elf32_Off rd_offset;
if (load_to_fastram)
rd_offset = KERNEL_START + kernel_size + MAX_BI_SIZE;
else
rd_offset = 0;
rd_len = ramdisk_length - RAMDISK_FS_START;
if (FastRAMSize > rd_offset + rd_len) {
/* Load in FastRAM */
rd_start = FastRAMBase + FastRAMSize - rd_len;
memcpy(FastRAMBaseHost + rd_start - FastRAMBase, (unsigned char *)ramdisk + RAMDISK_FS_START, rd_len);
} else {
/* Load in ST-RAM */
if (load_to_fastram)
rd_offset = PAGE_SIZE;
else
rd_offset = KERNEL_START + kernel_size + MAX_BI_SIZE;
if (RAMSize < rd_offset + rd_len) {
bug("lilo: not enough memory to load ramdisk of size %u", rd_len);
return -1;
}
rd_start = RAMSize - rd_len;
memcpy(RAMBaseHost+rd_start, ((unsigned char *)ramdisk) + RAMDISK_FS_START, rd_len);
}
bi.ramdisk.addr = SDL_SwapBE32(rd_start);
bi.ramdisk.size = SDL_SwapBE32(rd_len);
D(bug("lilo: Ramdisk at 0x%08x in RAM, length=0x%08x", rd_start, rd_len));
} else {
bi.ramdisk.addr = 0;
bi.ramdisk.size = 0;
D(bug("lilo: No ramdisk"));
}
/*--- Create the bootinfo structure ---*/
/* Command line */
kname = kernel_name;
if (strncmp( kernel_name, "local:", 6 ) == 0) {
kname += 6;
}
if (strlen(bx_options.lilo.args) > CL_SIZE-1) {
bug("lilo: kernel command line too long");
return -1;
}
strcpy(bi.command_line, bx_options.lilo.args);
if (strlen(bi.command_line)+1+strlen(kname)+12 < CL_SIZE-1) {
if (*bi.command_line) {
strcat( bi.command_line, " " );
}
strcat( bi.command_line, "BOOT_IMAGE=" );
strcat( bi.command_line, kname );
} else
{
bug("lilo: kernel command line too long to include kernel name");
}
D(bug("lilo: config_file command line: %s", bx_options.lilo.args ));
D(bug("lilo: kernel command line: %s", bi.command_line ));
/* Machine type, memory banks */
bi.machtype = SDL_SwapBE32(MACH_ATARI);
bi.cputype = SDL_SwapBE32(CPU_68040);
bi.fputype = SDL_SwapBE32(FPU_68040);
bi.mmutype = SDL_SwapBE32(MMU_68040);
bi.mch_cookie = SDL_SwapBE32(0x00030000);
bi.mch_type = SDL_SwapBE32(ATARI_MACH_AB40);
bi.num_memory=0;
/* If loading to FastRAM switch the order of ST and Fast RAM */
if (!load_to_fastram)
ADD_CHUNK(0, RAMSize);
if (FastRAMSize>0) {
ADD_CHUNK(FastRAMBase, FastRAMSize);
}
if (load_to_fastram)
ADD_CHUNK(0, RAMSize);
bi.num_memory=SDL_SwapBE32(bi.num_memory);
if (!create_bootinfo()) {
bug("lilo: Can not create bootinfo structure");
return -1;
}
/*--- Copy boot info in RAM ---*/
if (load_to_fastram)
memcpy(FastRAMBaseHost + KERNEL_START + kernel_size, &bi_union.record, bi_size);
else
memcpy(RAMBaseHost + KERNEL_START + kernel_size, &bi_union.record, bi_size);
D(bug("lilo: bootinfo at 0x%08x", kernel_offset + KERNEL_START + kernel_size));
#if DEBUG
for (i=0; i<16; i++) {
uint32 *tmp;
if (load_to_fastram)
tmp = (uint32 *)((unsigned char *)FastRAMBaseHost + KERNEL_START + kernel_size);
else
tmp = (uint32 *)((unsigned char *)RAMBaseHost + KERNEL_START + kernel_size);
D(bug("lilo: bi_union.record[%d]=0x%08x",i, SDL_SwapBE32(tmp[i])));
}
#endif
/*--- Init SP & PC ---*/
uint32 *tmp = (uint32 *)RAMBaseHost;
tmp[0] = SDL_SwapBE32(kernel_offset + KERNEL_START); /* SP */
tmp[1] = SDL_SwapBE32(0x00e00000); /* PC = ROMBase */
ROMBaseHost[4] = (kernel_offset + KERNEL_START) >> 24;
ROMBaseHost[5] = (kernel_offset + KERNEL_START) >> 16;
ROMBaseHost[6] = (kernel_offset + KERNEL_START) >> 8;
ROMBaseHost[7] = (kernel_offset + KERNEL_START) & 0xff;
D(bug("lilo: ok"));
return 0;
#else
return -1;
#endif /* ENABLE_LILO */
}
/*
* Create the Bootinfo Structure
*/
int LinuxBootOs::create_bootinfo(void)
{
#ifdef ENABLE_LILO
unsigned int i;
struct bi_record *record;
/* Initialization */
bi_size = 0;
/* Generic tags */
if (!add_bi_record(BI_MACHTYPE, sizeof(bi.machtype), &bi.machtype))
return(0);
if (!add_bi_record(BI_CPUTYPE, sizeof(bi.cputype), &bi.cputype))
return(0);
if (!add_bi_record(BI_FPUTYPE, sizeof(bi.fputype), &bi.fputype))
return(0);
if (!add_bi_record(BI_MMUTYPE, sizeof(bi.mmutype), &bi.mmutype))
return(0);
for (i = 0; i < SDL_SwapBE32(bi.num_memory); i++) {
if (!add_bi_record(BI_MEMCHUNK, sizeof(bi.memory[i]), &bi.memory[i]))
return(0);
}
if (SDL_SwapBE32(bi.ramdisk.size)) {
if (!add_bi_record(BI_RAMDISK, sizeof(bi.ramdisk), &bi.ramdisk))
return(0);
}
if (!add_bi_string(BI_COMMAND_LINE, bi.command_line))
return(0);
/* Atari tags */
if (!add_bi_record(BI_ATARI_MCH_COOKIE, sizeof(bi.mch_cookie), &bi.mch_cookie))
return(0);
if (!add_bi_record(BI_ATARI_MCH_TYPE, sizeof(bi.mch_type), &bi.mch_type))
return(0);
/* Trailer */
record = (struct bi_record *)((char *)&bi_union.record+bi_size);
record->tag = SDL_SwapBE16(BI_LAST);
bi_size += sizeof(bi_union.record.tag);
return(1);
#else
return(0);
#endif /* ENABLE_LILO */
}
/*
* Add a Record to the Bootinfo Structure
*/
int LinuxBootOs::add_bi_record( unsigned short tag, unsigned short size, const void *data)
{
#ifdef ENABLE_LILO
struct bi_record *record;
u_short size2;
size2 = (sizeof(struct bi_record)+size+3)&-4;
if (bi_size+size2+sizeof(bi_union.record.tag) > MAX_BI_SIZE) {
bug("Can't add bootinfo record. Ask a wizard to enlarge me.");
return(0);
}
record = (struct bi_record *)((char *)&bi_union.record+bi_size);
record->tag = SDL_SwapBE16(tag);
record->size = SDL_SwapBE16(size2);
memcpy((char *)record + sizeof(struct bi_record), data, size);
bi_size += size2;
#else
UNUSED(tag);
UNUSED(size);
UNUSED(data);
#endif /* ENABLE_LILO */
return(1);
}
/*
* Add a String Record to the Bootinfo Structure
*/
int LinuxBootOs::add_bi_string(unsigned short tag, const char *s)
{
#ifdef ENABLE_LILO
return add_bi_record(tag, strlen(s)+1, (void *)s);
#else
UNUSED(tag);
UNUSED(s);
return 0;
#endif /* ENABLE_LILO */
}