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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 63c1dd5 was 3f7fe9e, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Clean up headers

Depends on <limits.h> and <stdint.h> being provided, which is a step up from
depending on mostly undocumented predefined macros.
In principle, <limits.h> and <stdint.h> mostly describe properties of
the compiler, so even though we depend on certain values for their contents,
actually defining them in the library is kind of reversal of concerns.

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[4872160]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>
[3f7fe9e]32#include <arch/types.h>
[4872160]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>
[4646710]42#include "../../components.h"
[4872160]43
44#define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top))
45
46static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
47static uint32_t *cpumap = (uint32_t *) PA2KA(CPUMAP_OFFSET);
48
49void bootstrap(void)
50{
51 version_print();
[a35b458]52
[4872160]53 printf("\nMemory statistics\n");
[7e752b2]54 printf(" %p|%p: CPU map\n", (void *) PA2KA(CPUMAP_OFFSET),
55 (void *) CPUMAP_OFFSET);
56 printf(" %p|%p: bootstrap stack\n", (void *) PA2KA(STACK_OFFSET),
57 (void *) STACK_OFFSET);
58 printf(" %p|%p: boot info structure\n",
59 (void *) PA2KA(BOOTINFO_OFFSET), (void *) BOOTINFO_OFFSET);
60 printf(" %p|%p: kernel entry point\n", (void *) PA2KA(BOOT_OFFSET),
61 (void *) BOOT_OFFSET);
62 printf(" %p|%p: bootloader entry point\n",
63 (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET);
[a35b458]64
[4872160]65 size_t i;
66 for (i = 0; i < COMPONENTS; i++)
[4646710]67 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
68 (uintptr_t) components[i].addr >= PA2KSEG(0) ?
69 (void *) KSEG2PA(components[i].addr) :
70 (void *) KA2PA(components[i].addr),
[295732b]71 components[i].name, components[i].inflated,
72 components[i].size);
[a35b458]73
[4872160]74 void *dest[COMPONENTS];
75 size_t top = 0;
76 size_t cnt = 0;
77 bootinfo->cnt = 0;
78 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
79 top = ALIGN_UP(top, PAGE_SIZE);
[a35b458]80
[4872160]81 if (i > 0) {
82 bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top);
83 bootinfo->tasks[bootinfo->cnt].size = components[i].inflated;
[a35b458]84
[4872160]85 str_cpy(bootinfo->tasks[bootinfo->cnt].name,
86 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
[a35b458]87
[4872160]88 bootinfo->cnt++;
89 }
[a35b458]90
[4872160]91 dest[i] = TOP2ADDR(top);
92 top += components[i].inflated;
93 cnt++;
94 }
[a35b458]95
[4872160]96 printf("\nInflating components ... ");
[a35b458]97
[4872160]98 for (i = cnt; i > 0; i--) {
[295732b]99#ifdef MACHINE_msim
[4872160]100 void *tail = dest[i - 1] + components[i].inflated;
101 if (tail >= ((void *) PA2KA(LOADER_OFFSET))) {
102 printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
[7e752b2]103 components[i].name, tail, (void *) PA2KA(LOADER_OFFSET));
[4872160]104 halt();
105 }
[295732b]106#endif
[a35b458]107
[4872160]108 printf("%s ", components[i - 1].name);
[a35b458]109
[4646710]110 int err = inflate(components[i - 1].addr, components[i - 1].size,
[4872160]111 dest[i - 1], components[i - 1].inflated);
[a35b458]112
[4872160]113 if (err != EOK) {
114 printf("\n%s: Inflating error %d, halting.\n",
115 components[i - 1].name, err);
116 halt();
117 }
118 }
[a35b458]119
[4872160]120 printf(".\n");
[a35b458]121
[4872160]122 printf("Copying CPU map ... \n");
[a35b458]123
[4872160]124 bootinfo->cpumap = 0;
125 for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
126 if (cpumap[i] != 0)
127 bootinfo->cpumap |= (1 << i);
128 }
[a35b458]129
[4872160]130 printf("Booting the kernel ... \n");
131 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo);
132}
Note: See TracBrowser for help on using the repository browser.