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 *, unsigned long);
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
;
30 #define RAM_START 0x00000000
31 #define RAM_END (64<<20)
33 #define BOOT_START ((unsigned long)_start)
34 #define BOOT_END ((unsigned long)(_end + 0xFFF) & ~0xFFF)
36 #define RAM_FREE ((unsigned long)(_end+0x1000)&~0xFFF)
37 #define PROG_START 0x00010000
38 #define PROG_SIZE 0x007f0000 /* 8MB */
40 #define SCRATCH_SIZE (128 << 10)
42 static char scratch
[SCRATCH_SIZE
]; /* 1MB of scratch space for gunzip */
44 typedef void (*kernel_start_t
)(int, int, void *, unsigned int, unsigned int);
47 boot(int a1
, int a2
, void *prom
)
52 unsigned int initrd_size
, initrd_start
;
54 printf("chrpboot starting: loaded at 0x%p\n\r", &_start
);
56 initrd_size
= &__ramdisk_end
- &__ramdisk_begin
;
58 initrd_start
= (RAM_END
- initrd_size
) & ~0xFFF;
61 claim(initrd_start
, RAM_END
- initrd_start
, 0);
62 printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
63 initrd_start
, &__ramdisk_begin
, initrd_size
);
64 memcpy((char *)initrd_start
, &__ramdisk_begin
, initrd_size
);
72 len
= &__image_end
- &__image_begin
;
73 /* claim 4MB starting at PROG_START */
74 claim(PROG_START
, PROG_SIZE
- PROG_START
, 0);
75 dst
= (void *) PROG_START
;
76 if (im
[0] == 0x1f && im
[1] == 0x8b) {
78 begin_avail
= avail_high
= avail_ram
;
79 end_avail
= scratch
+ sizeof(scratch
);
80 printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst
, im
, im
+len
);
81 gunzip(dst
, 0x400000, im
, &len
);
82 printf("done %u bytes\n\r", len
);
83 printf("%u bytes of heap consumed, max in use %u\n\r",
84 avail_high
- begin_avail
, heap_max
);
86 memmove(dst
, im
, len
);
89 flush_cache(dst
, len
);
90 make_bi_recs(((unsigned long) dst
+ len
), "chrpboot", _MACH_chrp
,
91 (PROG_START
+ PROG_SIZE
));
94 printf("start address = 0x%x\n\r", sa
);
96 (*(kernel_start_t
)sa
)(a1
, a2
, prom
, initrd_start
, initrd_size
);
98 printf("returned?\n\r");