source: mainline/boot/arch/mips32/src/main.c@ b278b4e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b278b4e was 4872160, checked in by Martin Decky <martin@…>, 16 years ago

new boot infrastructure

  • more code and metadata unification
  • import of up-to-date implementations from the kernel
  • the boot loaders should behave more similarly on all platforms
  • support for deflate compressed (LZ77) boot components
    • this again allows feasible boot images to be created on mips32
  • IA64 is still not booting
    • the broken forked GNU EFI library has been removed, a replacement of the functionality is on its way
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <arch/main.h>
30#include <arch/arch.h>
31#include <arch/asm.h>
32#include <arch/_components.h>
33#include <halt.h>
34#include <printf.h>
35#include <memstr.h>
36#include <version.h>
37#include <macros.h>
38#include <align.h>
39#include <str.h>
40#include <errno.h>
41#include <inflate.h>
42
43#define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top))
44
45static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
46static uint32_t *cpumap = (uint32_t *) PA2KA(CPUMAP_OFFSET);
47
48void bootstrap(void)
49{
50 version_print();
51
52 printf("\nMemory statistics\n");
53 printf(" %p|%p: CPU map\n", PA2KA(CPUMAP_OFFSET), CPUMAP_OFFSET);
54 printf(" %p|%p: bootstrap stack\n", PA2KA(STACK_OFFSET), STACK_OFFSET);
55 printf(" %p|%p: boot info structure\n", PA2KA(BOOTINFO_OFFSET), BOOTINFO_OFFSET);
56 printf(" %p|%p: kernel entry point\n", PA2KA(BOOT_OFFSET), BOOT_OFFSET);
57 printf(" %p|%p: bootloader entry point\n", PA2KA(LOADER_OFFSET), LOADER_OFFSET);
58
59 size_t i;
60 for (i = 0; i < COMPONENTS; i++)
61 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
62 KSEG2PA(components[i].start), components[i].name,
63 components[i].inflated, components[i].size);
64
65 void *dest[COMPONENTS];
66 size_t top = 0;
67 size_t cnt = 0;
68 bootinfo->cnt = 0;
69 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
70 top = ALIGN_UP(top, PAGE_SIZE);
71
72 if (i > 0) {
73 bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top);
74 bootinfo->tasks[bootinfo->cnt].size = components[i].inflated;
75
76 str_cpy(bootinfo->tasks[bootinfo->cnt].name,
77 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
78
79 bootinfo->cnt++;
80 }
81
82 dest[i] = TOP2ADDR(top);
83 top += components[i].inflated;
84 cnt++;
85 }
86
87 printf("\nInflating components ... ");
88
89 for (i = cnt; i > 0; i--) {
90 void *tail = dest[i - 1] + components[i].inflated;
91 if (tail >= ((void *) PA2KA(LOADER_OFFSET))) {
92 printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
93 components[i].name, tail, PA2KA(LOADER_OFFSET));
94 halt();
95 }
96
97 printf("%s ", components[i - 1].name);
98
99 int err = inflate(components[i - 1].start, components[i - 1].size,
100 dest[i - 1], components[i - 1].inflated);
101
102 if (err != EOK) {
103 printf("\n%s: Inflating error %d, halting.\n",
104 components[i - 1].name, err);
105 halt();
106 }
107 }
108
109 printf(".\n");
110
111 printf("Copying CPU map ... \n");
112
113 bootinfo->cpumap = 0;
114 for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
115 if (cpumap[i] != 0)
116 bootinfo->cpumap |= (1 << i);
117 }
118
119 printf("Booting the kernel ... \n");
120 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo);
121}
Note: See TracBrowser for help on using the repository browser.