| 1 | /*
|
|---|
| 2 | * Copyright (c) 2005 Martin Decky
|
|---|
| 3 | * Copyright (c) 2006 Jakub Jermar
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | #include <arch/main.h>
|
|---|
| 32 | #include <arch/arch.h>
|
|---|
| 33 | #include <arch/asm.h>
|
|---|
| 34 | #include <arch/_components.h>
|
|---|
| 35 | #include <halt.h>
|
|---|
| 36 | #include <printf.h>
|
|---|
| 37 | #include <memstr.h>
|
|---|
| 38 | #include <version.h>
|
|---|
| 39 | #include <macros.h>
|
|---|
| 40 | #include <align.h>
|
|---|
| 41 | #include <str.h>
|
|---|
| 42 | #include <errno.h>
|
|---|
| 43 | #include <inflate.h>
|
|---|
| 44 |
|
|---|
| 45 | #define DEFAULT_MEMORY_BASE 0x4000000ULL
|
|---|
| 46 | #define DEFAULT_MEMORY_SIZE 0x4000000ULL
|
|---|
| 47 | #define DEFAULT_LEGACY_IO_BASE 0x00000FFFFC000000ULL
|
|---|
| 48 | #define DEFAULT_LEGACY_IO_SIZE 0x4000000ULL
|
|---|
| 49 |
|
|---|
| 50 | #define DEFAULT_FREQ_SCALE 0x0000000100000001ULL /* 1/1 */
|
|---|
| 51 | #define DEFAULT_SYS_FREQ 100000000ULL /* 100MHz */
|
|---|
| 52 |
|
|---|
| 53 | #define EFI_MEMMAP_FREE_MEM 0
|
|---|
| 54 | #define EFI_MEMMAP_IO 1
|
|---|
| 55 | #define EFI_MEMMAP_IO_PORTS 2
|
|---|
| 56 |
|
|---|
| 57 | static bootinfo_t bootinfo;
|
|---|
| 58 |
|
|---|
| 59 | void bootstrap(void)
|
|---|
| 60 | {
|
|---|
| 61 | version_print();
|
|---|
| 62 |
|
|---|
| 63 | printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
|
|---|
| 64 | printf(" %p|%p: kernel entry point\n",
|
|---|
| 65 | (void *) KERNEL_ADDRESS, (void *) KERNEL_ADDRESS);
|
|---|
| 66 | printf(" %p|%p: loader entry point\n",
|
|---|
| 67 | (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS);
|
|---|
| 68 |
|
|---|
| 69 | size_t i;
|
|---|
| 70 | for (i = 0; i < COMPONENTS; i++)
|
|---|
| 71 | printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
|
|---|
| 72 | components[i].start, components[i].name,
|
|---|
| 73 | components[i].inflated, components[i].size);
|
|---|
| 74 |
|
|---|
| 75 | void *dest[COMPONENTS];
|
|---|
| 76 | size_t top = KERNEL_ADDRESS;
|
|---|
| 77 | size_t cnt = 0;
|
|---|
| 78 | bootinfo.taskmap.cnt = 0;
|
|---|
| 79 | for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
|
|---|
| 80 | top = ALIGN_UP(top, PAGE_SIZE);
|
|---|
| 81 |
|
|---|
| 82 | if (i > 0) {
|
|---|
| 83 | bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
|
|---|
| 84 | (void *) top;
|
|---|
| 85 | bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
|
|---|
| 86 | components[i].inflated;
|
|---|
| 87 |
|
|---|
| 88 | str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
|
|---|
| 89 | BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
|
|---|
| 90 |
|
|---|
| 91 | bootinfo.taskmap.cnt++;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | dest[i] = (void *) top;
|
|---|
| 95 | top += components[i].inflated;
|
|---|
| 96 | cnt++;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | printf("\nInflating components ... ");
|
|---|
| 100 |
|
|---|
| 101 | for (i = cnt; i > 0; i--) {
|
|---|
| 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 | if (!bootinfo.hello_configured) { /* XXX */
|
|---|
| 117 | /*
|
|---|
| 118 | * Load configuration defaults for simulators.
|
|---|
| 119 | */
|
|---|
| 120 | bootinfo.memmap_items = 0;
|
|---|
| 121 |
|
|---|
| 122 | bootinfo.memmap[bootinfo.memmap_items].base =
|
|---|
| 123 | DEFAULT_MEMORY_BASE;
|
|---|
| 124 | bootinfo.memmap[bootinfo.memmap_items].size =
|
|---|
| 125 | DEFAULT_MEMORY_SIZE;
|
|---|
| 126 | bootinfo.memmap[bootinfo.memmap_items].type =
|
|---|
| 127 | EFI_MEMMAP_FREE_MEM;
|
|---|
| 128 | bootinfo.memmap_items++;
|
|---|
| 129 |
|
|---|
| 130 | bootinfo.memmap[bootinfo.memmap_items].base =
|
|---|
| 131 | DEFAULT_LEGACY_IO_BASE;
|
|---|
| 132 | bootinfo.memmap[bootinfo.memmap_items].size =
|
|---|
| 133 | DEFAULT_LEGACY_IO_SIZE;
|
|---|
| 134 | bootinfo.memmap[bootinfo.memmap_items].type =
|
|---|
| 135 | EFI_MEMMAP_IO_PORTS;
|
|---|
| 136 | bootinfo.memmap_items++;
|
|---|
| 137 |
|
|---|
| 138 | bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
|
|---|
| 139 | bootinfo.sys_freq = DEFAULT_SYS_FREQ;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 | printf("Booting the kernel ...\n");
|
|---|
| 144 | jump_to_kernel(&bootinfo);
|
|---|
| 145 | }
|
|---|