source: mainline/boot/arch/mips64/src/main.c@ fbe89af

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

add initial support for mips64
(it does not do anything useful so far and there are probably severe bugs and ABI violations, but it compiles)

  • Property mode set to 100644
File size: 4.1 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", (void *) PA2KA(CPUMAP_OFFSET),
54 (void *) CPUMAP_OFFSET);
55 printf(" %p|%p: bootstrap stack\n", (void *) PA2KA(STACK_OFFSET),
56 (void *) STACK_OFFSET);
57 printf(" %p|%p: boot info structure\n",
58 (void *) PA2KA(BOOTINFO_OFFSET), (void *) BOOTINFO_OFFSET);
59 printf(" %p|%p: kernel entry point\n", (void *) PA2KA(BOOT_OFFSET),
60 (void *) BOOT_OFFSET);
61 printf(" %p|%p: bootloader entry point\n",
62 (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET);
63
64 size_t i;
65 for (i = 0; i < COMPONENTS; i++)
66 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
67 (void *) KSEG2PA(components[i].start), components[i].name,
68 components[i].inflated, components[i].size);
69
70 void *dest[COMPONENTS];
71 size_t top = 0;
72 size_t cnt = 0;
73 bootinfo->cnt = 0;
74 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
75 top = ALIGN_UP(top, PAGE_SIZE);
76
77 if (i > 0) {
78 bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top);
79 bootinfo->tasks[bootinfo->cnt].size = components[i].inflated;
80
81 str_cpy(bootinfo->tasks[bootinfo->cnt].name,
82 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
83
84 bootinfo->cnt++;
85 }
86
87 dest[i] = TOP2ADDR(top);
88 top += components[i].inflated;
89 cnt++;
90 }
91
92 printf("\nInflating components ... ");
93
94 for (i = cnt; i > 0; i--) {
95 void *tail = dest[i - 1] + components[i].inflated;
96 if (tail >= ((void *) PA2KA(LOADER_OFFSET))) {
97 printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
98 components[i].name, tail, (void *) PA2KA(LOADER_OFFSET));
99 halt();
100 }
101
102 printf("%s ", components[i - 1].name);
103
104 int err = inflate(components[i - 1].start, components[i - 1].size,
105 dest[i - 1], components[i - 1].inflated);
106
107 if (err != EOK) {
108 printf("\n%s: Inflating error %d, halting.\n",
109 components[i - 1].name, err);
110 halt();
111 }
112 }
113
114 printf(".\n");
115
116 printf("Copying CPU map ... \n");
117
118 bootinfo->cpumap = 0;
119 for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
120 if (cpumap[i] != 0)
121 bootinfo->cpumap |= (1 << i);
122 }
123
124 printf("Booting the kernel ... \n");
125 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo);
126}
Note: See TracBrowser for help on using the repository browser.