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

Last change on this file was b169619, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 20 months ago

Deduplicate mem functions

There are a number of functions which are copied between
kernel, libc, and potentially boot too. mem*() functions
are first such offenders. All this duplicate code will
be moved to directory 'common'.

  • Property mode set to 100644
File size: 3.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/types.h>
33#include <halt.h>
34#include <printf.h>
35#include <mem.h>
36#include <version.h>
37#include <macros.h>
38#include <align.h>
39#include <str.h>
40#include <errno.h>
41#include <payload.h>
42#include <kernel.h>
43
44static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
45static uint32_t *cpumap = (uint32_t *) PA2KA(CPUMAP_OFFSET);
46
47void bootstrap(int kargc, char **kargv)
48{
49 version_print();
50
51 printf("\nMemory statistics\n");
52 printf(" %p|%p: CPU map\n", (void *) PA2KA(CPUMAP_OFFSET),
53 (void *) CPUMAP_OFFSET);
54 printf(" %p|%p: bootstrap stack\n", (void *) PA2KA(STACK_OFFSET),
55 (void *) STACK_OFFSET);
56 printf(" %p|%p: boot info structure\n",
57 (void *) PA2KA(BOOTINFO_OFFSET), (void *) BOOTINFO_OFFSET);
58 printf(" %p|%p: kernel entry point\n", (void *) PA2KA(BOOT_OFFSET),
59 (void *) BOOT_OFFSET);
60 printf(" %p|%p: bootloader entry point\n",
61 (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET);
62
63 uint8_t *kernel_start = (uint8_t *) PA2KA(BOOT_OFFSET);
64 // FIXME: Use the correct value.
65 uint8_t *ram_end = kernel_start + (1 << 24);
66
67 // TODO: Make sure that the I-cache, D-cache and memory are coherent.
68 // (i.e. provide the clear_cache callback)
69
70 extract_payload(&bootinfo->taskmap, kernel_start, ram_end,
71 (uintptr_t) kernel_start, NULL);
72
73 printf("Copying CPU map ... \n");
74
75 bootinfo->cpumap = 0;
76 for (int i = 0; i < CPUMAP_MAX_RECORDS; i++) {
77 if (cpumap[i] != 0)
78 bootinfo->cpumap |= (1 << i);
79 }
80
81 str_cpy(bootinfo->bootargs, sizeof(bootinfo->bootargs),
82 (kargc > 1) ? kargv[1] : "");
83
84 uintptr_t entry = check_kernel(kernel_start);
85
86 printf("Booting the kernel...\n");
87 jump_to_kernel((void *) entry, bootinfo);
88}
Note: See TracBrowser for help on using the repository browser.