]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (C) Paul Mackerras 1997. | |
3 | * | |
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. | |
8 | */ | |
9 | #include <linux/string.h> | |
10 | #include <asm/processor.h> | |
11 | #include <asm/page.h> | |
12 | ||
13 | #include "nonstdio.h" | |
14 | #include "of1275.h" | |
15 | ||
16 | /* Passed from the linker */ | |
17 | extern char __image_begin, __image_end; | |
18 | extern char __ramdisk_begin[], __ramdisk_end; | |
19 | extern char _start, _end; | |
20 | ||
21 | extern char image_data[], initrd_data[]; | |
22 | extern int initrd_len, image_len; | |
23 | extern unsigned int heap_max; | |
24 | extern void flush_cache(void *start, unsigned int len); | |
25 | extern void gunzip(void *, int, unsigned char *, int *); | |
26 | extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach, | |
27 | unsigned int progend); | |
28 | extern void setup_bats(unsigned long start); | |
29 | ||
30 | char *avail_ram; | |
31 | char *begin_avail, *end_avail; | |
32 | char *avail_high; | |
33 | ||
34 | #define SCRATCH_SIZE (128 << 10) | |
35 | ||
36 | static char heap[SCRATCH_SIZE]; | |
37 | ||
38 | static unsigned long ram_start = 0; | |
39 | static unsigned long ram_end = 0x1000000; | |
40 | ||
41 | static unsigned long prog_start = 0x900000; | |
42 | static unsigned long prog_size = 0x700000; | |
43 | ||
44 | typedef void (*kernel_start_t)(int, int, void *); | |
45 | ||
46 | void boot(int a1, int a2, void *prom) | |
47 | { | |
48 | unsigned sa, len; | |
49 | void *dst; | |
50 | unsigned char *im; | |
51 | unsigned initrd_start, initrd_size; | |
52 | ||
53 | printf("coffboot starting: loaded at 0x%p\n", &_start); | |
54 | setup_bats(ram_start); | |
55 | ||
56 | initrd_size = (char *)(&__ramdisk_end) - (char *)(&__ramdisk_begin); | |
57 | if (initrd_size) { | |
58 | initrd_start = (ram_end - initrd_size) & ~0xFFF; | |
59 | a1 = initrd_start; | |
60 | a2 = initrd_size; | |
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, (char *)(&__ramdisk_begin), initrd_size); | |
64 | memcpy((char *)initrd_start, (char *)(&__ramdisk_begin), initrd_size); | |
65 | prog_size = initrd_start - prog_start; | |
66 | } else | |
67 | a2 = 0xdeadbeef; | |
68 | ||
69 | im = (char *)(&__image_begin); | |
70 | len = (char *)(&__image_end) - (char *)(&__image_begin); | |
71 | /* claim 4MB starting at PROG_START */ | |
72 | claim(prog_start, prog_size, 0); | |
73 | map(prog_start, prog_start, prog_size); | |
74 | dst = (void *) prog_start; | |
75 | if (im[0] == 0x1f && im[1] == 0x8b) { | |
76 | /* set up scratch space */ | |
77 | begin_avail = avail_high = avail_ram = heap; | |
78 | end_avail = heap + sizeof(heap); | |
79 | printf("heap at 0x%p\n", avail_ram); | |
80 | printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len); | |
81 | gunzip(dst, prog_size, im, &len); | |
82 | printf("done %u bytes\n", len); | |
83 | printf("%u bytes of heap consumed, max in use %u\n", | |
84 | avail_high - begin_avail, heap_max); | |
85 | } else { | |
86 | memmove(dst, im, len); | |
87 | } | |
88 | ||
89 | flush_cache(dst, len); | |
90 | make_bi_recs(((unsigned long) dst + len), "coffboot", _MACH_Pmac, | |
91 | (prog_start + prog_size)); | |
92 | ||
93 | sa = (unsigned long)prog_start; | |
94 | printf("start address = 0x%x\n", sa); | |
95 | ||
96 | (*(kernel_start_t)sa)(a1, a2, prom); | |
97 | ||
98 | printf("returned?\n"); | |
99 | ||
100 | pause(); | |
101 | } |