]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/ppc/boot/openfirmware/chrpmain.c
Linux-2.6.12-rc2
[mirror_ubuntu-zesty-kernel.git] / arch / ppc / boot / openfirmware / chrpmain.c
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 "nonstdio.h"
11 #include "of1275.h"
12 #include <asm/processor.h>
13 #include <asm/page.h>
14
15 /* Passed from the linker */
16 extern char __image_begin, __image_end;
17 extern char __ramdisk_begin, __ramdisk_end;
18 extern char _start, _end;
19
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);
25
26 char *avail_ram;
27 char *begin_avail, *end_avail;
28 char *avail_high;
29
30 #define RAM_START 0x00000000
31 #define RAM_END (64<<20)
32
33 #define BOOT_START ((unsigned long)_start)
34 #define BOOT_END ((unsigned long)(_end + 0xFFF) & ~0xFFF)
35
36 #define RAM_FREE ((unsigned long)(_end+0x1000)&~0xFFF)
37 #define PROG_START 0x00010000
38 #define PROG_SIZE 0x007f0000 /* 8MB */
39
40 #define SCRATCH_SIZE (128 << 10)
41
42 static char scratch[SCRATCH_SIZE]; /* 1MB of scratch space for gunzip */
43
44 typedef void (*kernel_start_t)(int, int, void *, unsigned int, unsigned int);
45
46 void
47 boot(int a1, int a2, void *prom)
48 {
49 unsigned sa, len;
50 void *dst;
51 unsigned char *im;
52 unsigned int initrd_size, initrd_start;
53
54 printf("chrpboot starting: loaded at 0x%p\n\r", &_start);
55
56 initrd_size = &__ramdisk_end - &__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, &__ramdisk_begin, initrd_size);
64 memcpy((char *)initrd_start, &__ramdisk_begin, initrd_size);
65 } else {
66 initrd_start = 0;
67 initrd_size = 0;
68 a2 = 0xdeadbeef;
69 }
70
71 im = &__image_begin;
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) {
77 avail_ram = scratch;
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);
85 } else {
86 memmove(dst, im, len);
87 }
88
89 flush_cache(dst, len);
90 make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_chrp,
91 (PROG_START + PROG_SIZE));
92
93 sa = PROG_START;
94 printf("start address = 0x%x\n\r", sa);
95
96 (*(kernel_start_t)sa)(a1, a2, prom, initrd_start, initrd_size);
97
98 printf("returned?\n\r");
99
100 pause();
101 }