[8b6aa39] | 1 | /*
|
---|
| 2 | * Copyright (c) 2016 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>
|
---|
[ae8d7b0] | 32 | #include <arch/ucb.h>
|
---|
| 33 | #include <arch/mm.h>
|
---|
[3f7fe9e] | 34 | #include <arch/types.h>
|
---|
[8b6aa39] | 35 | #include <version.h>
|
---|
[de1712e] | 36 | #include <stddef.h>
|
---|
[8b6aa39] | 37 | #include <printf.h>
|
---|
| 38 | #include <macros.h>
|
---|
| 39 | #include <errno.h>
|
---|
| 40 | #include <align.h>
|
---|
| 41 | #include <str.h>
|
---|
| 42 | #include <halt.h>
|
---|
[63a045c] | 43 | #include <payload.h>
|
---|
[cfdeedc] | 44 | #include <kernel.h>
|
---|
[8b6aa39] | 45 |
|
---|
| 46 | static bootinfo_t bootinfo;
|
---|
| 47 |
|
---|
| 48 | void bootstrap(void)
|
---|
| 49 | {
|
---|
| 50 | version_print();
|
---|
[a35b458] | 51 |
|
---|
[ae8d7b0] | 52 | bootinfo.htif_frame = ((uintptr_t) &htif_page) >> PAGE_WIDTH;
|
---|
| 53 | bootinfo.pt_frame = ((uintptr_t) &pt_page) >> PAGE_WIDTH;
|
---|
[a35b458] | 54 |
|
---|
[ae8d7b0] | 55 | bootinfo.ucbinfo.tohost =
|
---|
| 56 | (volatile uint64_t *) PA2KA((uintptr_t) &tohost);
|
---|
| 57 | bootinfo.ucbinfo.fromhost =
|
---|
| 58 | (volatile uint64_t *) PA2KA((uintptr_t) &fromhost);
|
---|
[a35b458] | 59 |
|
---|
[8b6aa39] | 60 | // FIXME TODO: read from device tree
|
---|
[ae8d7b0] | 61 | bootinfo.physmem_start = PHYSMEM_START;
|
---|
| 62 | bootinfo.memmap.total = PHYSMEM_SIZE;
|
---|
| 63 | bootinfo.memmap.cnt = 1;
|
---|
| 64 | bootinfo.memmap.zones[0].start = (void *) PHYSMEM_START;
|
---|
| 65 | bootinfo.memmap.zones[0].size = PHYSMEM_SIZE;
|
---|
[a35b458] | 66 |
|
---|
[3f7fe9e] | 67 | printf("\nMemory statistics (total %" PRIu64 " MB, starting at %p)\n\n",
|
---|
[ae8d7b0] | 68 | bootinfo.memmap.total >> 20, (void *) bootinfo.physmem_start);
|
---|
[8b6aa39] | 69 | printf(" %p: boot info structure\n", &bootinfo);
|
---|
[a35b458] | 70 |
|
---|
[63a045c] | 71 | uint8_t *load_addr = (uint8_t *) BOOT_OFFSET;
|
---|
| 72 | uintptr_t kernel_addr = PA2KA(load_addr);
|
---|
[a35b458] | 73 |
|
---|
[63a045c] | 74 | printf(" %p: inflate area\n", load_addr);
|
---|
| 75 | printf(" %p: kernel entry point\n", (void *) kernel_addr);
|
---|
[a35b458] | 76 |
|
---|
[63a045c] | 77 | /* Find the end of the memory zone containing the load address. */
|
---|
| 78 | uint8_t *end = NULL;
|
---|
| 79 | for (size_t i = 0; i < bootinfo.memmap.cnt; i++) {
|
---|
| 80 | memzone_t z = bootinfo.memmap.zones[i];
|
---|
[a35b458] | 81 |
|
---|
[63a045c] | 82 | if (z.start <= (void *) load_addr &&
|
---|
| 83 | z.start + z.size > (void *) load_addr) {
|
---|
| 84 | end = z.start + z.size;
|
---|
[8b6aa39] | 85 | }
|
---|
| 86 | }
|
---|
[a35b458] | 87 |
|
---|
[63a045c] | 88 | // TODO: Cache-coherence callback?
|
---|
| 89 | extract_payload(&bootinfo.taskmap, load_addr, end, kernel_addr, NULL);
|
---|
[a35b458] | 90 |
|
---|
[cfdeedc] | 91 | uintptr_t entry = check_kernel(load_addr);
|
---|
| 92 |
|
---|
[8b6aa39] | 93 | printf("Booting the kernel...\n");
|
---|
[cfdeedc] | 94 | jump_to_kernel(PA2KA(&bootinfo), entry);
|
---|
[8b6aa39] | 95 | }
|
---|