[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>
|
---|
[63a045c] | 41 | #include <payload.h>
|
---|
[cfdeedc] | 42 | #include <kernel.h>
|
---|
[4872160] | 43 |
|
---|
| 44 | static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
|
---|
| 45 | static uint32_t *cpumap = (uint32_t *) PA2KA(CPUMAP_OFFSET);
|
---|
| 46 |
|
---|
[dabaa83] | 47 | void bootstrap(int kargc, char **kargv)
|
---|
[4872160] | 48 | {
|
---|
| 49 | version_print();
|
---|
[a35b458] | 50 |
|
---|
[4872160] | 51 | printf("\nMemory statistics\n");
|
---|
[7e752b2] | 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);
|
---|
[a35b458] | 62 |
|
---|
[63a045c] | 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);
|
---|
[a35b458] | 66 |
|
---|
[63a045c] | 67 | // TODO: Make sure that the I-cache, D-cache and memory are coherent.
|
---|
| 68 | // (i.e. provide the clear_cache callback)
|
---|
[a35b458] | 69 |
|
---|
[63a045c] | 70 | extract_payload(&bootinfo->taskmap, kernel_start, ram_end,
|
---|
| 71 | (uintptr_t) kernel_start, NULL);
|
---|
[a35b458] | 72 |
|
---|
[4872160] | 73 | printf("Copying CPU map ... \n");
|
---|
[a35b458] | 74 |
|
---|
[4872160] | 75 | bootinfo->cpumap = 0;
|
---|
[63a045c] | 76 | for (int i = 0; i < CPUMAP_MAX_RECORDS; i++) {
|
---|
[4872160] | 77 | if (cpumap[i] != 0)
|
---|
| 78 | bootinfo->cpumap |= (1 << i);
|
---|
| 79 | }
|
---|
[a35b458] | 80 |
|
---|
[dabaa83] | 81 | str_cpy(bootinfo->bootargs, sizeof(bootinfo->bootargs),
|
---|
| 82 | (kargc > 1) ? kargv[1] : "");
|
---|
| 83 |
|
---|
[cfdeedc] | 84 | uintptr_t entry = check_kernel(kernel_start);
|
---|
| 85 |
|
---|
| 86 | printf("Booting the kernel...\n");
|
---|
| 87 | jump_to_kernel((void *) entry, bootinfo);
|
---|
[4872160] | 88 | }
|
---|