2 * Copyright (C) Paul Mackerras 1997.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 #include <linux/string.h>
12 #include <asm/processor.h>
15 /* Passed from the linker */
16 extern char __image_begin
, __image_end
;
17 extern char __ramdisk_begin
[], __ramdisk_end
;
18 extern char _start
, _end
;
20 extern unsigned int heap_max
;
21 extern void flush_cache(void *start
, unsigned int len
);
22 extern void gunzip(void *, int, unsigned char *, int *);
23 extern void make_bi_recs(unsigned long addr
, char *name
, unsigned int mach
,
24 unsigned int progend
);
27 char *begin_avail
, *end_avail
;
31 #define RAM_END (16 << 20)
33 #define PROG_START 0x00010000
34 #define PROG_SIZE 0x007f0000
36 #define SCRATCH_SIZE (128 << 10)
38 typedef void (*kernel_start_t
)(int, int, void *);
40 void boot(int a1
, int a2
, void *prom
)
45 unsigned initrd_start
, initrd_size
;
47 printf("chrpboot starting: loaded at 0x%p\n", &_start
);
49 initrd_size
= (char *)(&__ramdisk_end
) - (char *)(&__ramdisk_begin
);
51 initrd_start
= (RAM_END
- initrd_size
) & ~0xFFF;
54 claim(initrd_start
, RAM_END
- initrd_start
, 0);
55 printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
56 initrd_start
, (char *)(&__ramdisk_begin
), initrd_size
);
57 memcpy((char *)initrd_start
, (char *)(&__ramdisk_begin
), initrd_size
);
61 im
= (char *)(&__image_begin
);
62 len
= (char *)(&__image_end
) - (char *)(&__image_begin
);
63 /* claim 3MB starting at PROG_START */
64 claim(PROG_START
, PROG_SIZE
, 0);
65 dst
= (void *) PROG_START
;
66 if (im
[0] == 0x1f && im
[1] == 0x8b) {
67 /* claim some memory for scratch space */
68 avail_ram
= (char *) claim(0, SCRATCH_SIZE
, 0x10);
69 begin_avail
= avail_high
= avail_ram
;
70 end_avail
= avail_ram
+ SCRATCH_SIZE
;
71 printf("heap at 0x%p\n", avail_ram
);
72 printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst
, im
, im
+len
);
73 gunzip(dst
, PROG_SIZE
, im
, &len
);
74 printf("done %u bytes\n", len
);
75 printf("%u bytes of heap consumed, max in use %u\n",
76 avail_high
- begin_avail
, heap_max
);
77 release(begin_avail
, SCRATCH_SIZE
);
79 memmove(dst
, im
, len
);
82 flush_cache(dst
, len
);
83 make_bi_recs(((unsigned long) dst
+ len
), "chrpboot", _MACH_Pmac
,
84 (PROG_START
+ PROG_SIZE
));
86 sa
= (unsigned long)PROG_START
;
87 printf("start address = 0x%x\n", sa
);
89 (*(kernel_start_t
)sa
)(a1
, a2
, prom
);
91 printf("returned?\n");