[b6b02c0] | 1 | /*
|
---|
| 2 | * Copyright (c) 2013 Jakub Klama
|
---|
| 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 | /** @addtogroup sparc32boot
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief Bootstrap.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <arch/asm.h>
|
---|
| 37 | #include <arch/common.h>
|
---|
| 38 | #include <arch/arch.h>
|
---|
| 39 | #include <arch/ambapp.h>
|
---|
| 40 | #include <arch/mm.h>
|
---|
| 41 | #include <arch/main.h>
|
---|
| 42 | #include <arch/_components.h>
|
---|
| 43 | #include <halt.h>
|
---|
| 44 | #include <printf.h>
|
---|
| 45 | #include <memstr.h>
|
---|
| 46 | #include <version.h>
|
---|
| 47 | #include <macros.h>
|
---|
| 48 | #include <align.h>
|
---|
| 49 | #include <str.h>
|
---|
| 50 | #include <errno.h>
|
---|
| 51 | #include <inflate.h>
|
---|
| 52 |
|
---|
| 53 | #define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top))
|
---|
[f6f22cdb] | 54 |
|
---|
[b6b02c0] | 55 | static bootinfo_t bootinfo;
|
---|
| 56 |
|
---|
| 57 | void bootstrap(void)
|
---|
| 58 | {
|
---|
| 59 | /* Initialize AMBA P&P device list */
|
---|
| 60 | ambapp_scan();
|
---|
[f6f22cdb] | 61 |
|
---|
| 62 | /* Look for UART */
|
---|
[b6b02c0] | 63 | amba_device_t *uart = ambapp_lookup_first(GAISLER, GAISLER_APBUART);
|
---|
| 64 | amba_uart_base = uart->bars[0].start;
|
---|
[a73ebf0] | 65 | bootinfo.uart_base = amba_uart_base;
|
---|
| 66 | bootinfo.uart_irq = uart->irq;
|
---|
[f6f22cdb] | 67 |
|
---|
| 68 | /* Look for IRQMP */
|
---|
[a73ebf0] | 69 | amba_device_t *irqmp = ambapp_lookup_first(GAISLER, GAISLER_IRQMP);
|
---|
| 70 | bootinfo.intc_base = irqmp->bars[0].start;
|
---|
[f6f22cdb] | 71 |
|
---|
| 72 | /* Look for timer */
|
---|
[a73ebf0] | 73 | amba_device_t *timer = ambapp_lookup_first(GAISLER, GAISLER_GPTIMER);
|
---|
| 74 | bootinfo.timer_base = timer->bars[0].start;
|
---|
| 75 | bootinfo.timer_irq = timer->irq;
|
---|
| 76 |
|
---|
[f6f22cdb] | 77 | /* Look for memory controller and obtain memory size */
|
---|
| 78 | if (!ambapp_fake()) {
|
---|
[a73ebf0] | 79 | amba_device_t *mctrl = ambapp_lookup_first(ESA, ESA_MCTRL);
|
---|
[f6f22cdb] | 80 | volatile mctrl_mcfg2_t *mcfg2 = (volatile mctrl_mcfg2_t *)
|
---|
| 81 | (mctrl->bars[0].start + 0x4);
|
---|
[a73ebf0] | 82 | bootinfo.memsize = (1 << (13 + mcfg2->bank_size));
|
---|
[f6f22cdb] | 83 | } else
|
---|
| 84 | bootinfo.memsize = 64 * 1024 * 1024;
|
---|
[a73ebf0] | 85 |
|
---|
[b6b02c0] | 86 | /* Standard output is now initialized */
|
---|
| 87 | version_print();
|
---|
[f6f22cdb] | 88 |
|
---|
[b6b02c0] | 89 | for (size_t i = 0; i < COMPONENTS; i++) {
|
---|
| 90 | printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
|
---|
| 91 | components[i].start, components[i].name, components[i].inflated,
|
---|
| 92 | components[i].size);
|
---|
| 93 | }
|
---|
[f6f22cdb] | 94 |
|
---|
[b6b02c0] | 95 | ambapp_print_devices();
|
---|
[f6f22cdb] | 96 |
|
---|
| 97 | printf("Memory size: %u MB\n", bootinfo.memsize >> 20);
|
---|
| 98 |
|
---|
[b6b02c0] | 99 | mmu_init();
|
---|
[f6f22cdb] | 100 |
|
---|
[b6b02c0] | 101 | void *dest[COMPONENTS];
|
---|
| 102 | size_t top = 0;
|
---|
| 103 | size_t cnt = 0;
|
---|
| 104 | bootinfo.cnt = 0;
|
---|
| 105 | for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
|
---|
| 106 | top = ALIGN_UP(top, PAGE_SIZE);
|
---|
| 107 |
|
---|
| 108 | if (i > 0) {
|
---|
| 109 | bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
|
---|
| 110 | bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
|
---|
| 111 |
|
---|
| 112 | str_cpy(bootinfo.tasks[bootinfo.cnt].name,
|
---|
| 113 | BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
|
---|
| 114 |
|
---|
| 115 | bootinfo.cnt++;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | dest[i] = TOP2ADDR(top);
|
---|
[f6f22cdb] | 119 |
|
---|
[b6b02c0] | 120 | top += components[i].inflated;
|
---|
| 121 | cnt++;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | printf("\nInflating components ... ");
|
---|
| 125 |
|
---|
| 126 | for (size_t i = cnt; i > 0; i--) {
|
---|
| 127 | void *tail = components[i - 1].start + components[i - 1].size;
|
---|
| 128 | if (tail >= dest[i - 1]) {
|
---|
| 129 | printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
|
---|
| 130 | components[i].name, tail, dest[i - 1]);
|
---|
[f6f22cdb] | 131 | halt();
|
---|
[b6b02c0] | 132 | }
|
---|
| 133 |
|
---|
| 134 | printf("%s ", components[i - 1].name);
|
---|
| 135 |
|
---|
| 136 | int err = inflate(components[i - 1].start, components[i - 1].size,
|
---|
| 137 | dest[i - 1], components[i - 1].inflated);
|
---|
| 138 | if (err != EOK) {
|
---|
| 139 | printf("\n%s: Inflating error %d\n", components[i - 1].name, err);
|
---|
[f6f22cdb] | 140 | halt();
|
---|
[b6b02c0] | 141 | }
|
---|
| 142 | }
|
---|
[f6f22cdb] | 143 |
|
---|
[b6b02c0] | 144 | printf("Booting the kernel ... \n");
|
---|
[ef9a2a8] | 145 | jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo);
|
---|
[b6b02c0] | 146 | }
|
---|
| 147 |
|
---|
| 148 | /** @}
|
---|
| 149 | */
|
---|