source: mainline/boot/arch/arm32/src/main.c@ 7cd15b9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7cd15b9 was 7cd15b9, checked in by Jakub Jermar <jakub@…>, 11 years ago

Flush cachelines holding the initial arm32 boot page table.
(Thx Jano Vesely)

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (c) 2007 Michal Kebrt
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 arm32boot
30 * @{
31 */
32/** @file
33 * @brief Bootstrap.
34 */
35
36#include <arch/main.h>
37#include <arch/asm.h>
38#include <arch/mm.h>
39#include <arch/_components.h>
40#include <halt.h>
41#include <printf.h>
42#include <memstr.h>
43#include <version.h>
44#include <macros.h>
45#include <align.h>
46#include <str.h>
47#include <errno.h>
48#include <inflate.h>
49
50#define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top))
51
52extern void *bdata_start;
53extern void *bdata_end;
54
55static inline void clean_dcache_poc(void *address, size_t size)
56{
57 const uintptr_t addr = (uintptr_t)address;
58 for (uintptr_t a = addr; a < addr + size; a += 4) {
59 /* DCCMVAC - clean by address to the point of coherence */
60 asm volatile ("mcr p15, 0, %[a], c7, c10, 1\n" :: [a]"r"(a) : );
61 }
62}
63
64static bootinfo_t bootinfo;
65
66void bootstrap(void)
67{
68 /* Enable MMU and caches */
69 mmu_start();
70 version_print();
71
72 printf("Boot data: %p -> %p\n", &bdata_start, &bdata_end);
73 printf("\nMemory statistics\n");
74 printf(" %p|%p: bootstrap stack\n", &boot_stack, &boot_stack);
75 printf(" %p|%p: bootstrap page table\n", &boot_pt, &boot_pt);
76 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
77 printf(" %p|%p: kernel entry point\n",
78 (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
79
80 for (size_t i = 0; i < COMPONENTS; i++) {
81 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
82 components[i].start, components[i].name, components[i].inflated,
83 components[i].size);
84 }
85
86 void *dest[COMPONENTS];
87 size_t top = 0;
88 size_t cnt = 0;
89 bootinfo.cnt = 0;
90 for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
91 top = ALIGN_UP(top, PAGE_SIZE);
92
93 if (i > 0) {
94 bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
95 bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
96
97 str_cpy(bootinfo.tasks[bootinfo.cnt].name,
98 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
99
100 bootinfo.cnt++;
101 }
102
103 dest[i] = TOP2ADDR(top);
104 top += components[i].inflated;
105 cnt++;
106 }
107
108 printf("\nInflating components ... ");
109
110 for (size_t i = cnt; i > 0; i--) {
111 void *tail = components[i - 1].start + components[i - 1].size;
112 if (tail >= dest[i - 1]) {
113 printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
114 components[i].name, tail, dest[i - 1]);
115 halt();
116 }
117
118 printf("%s ", components[i - 1].name);
119
120 int err = inflate(components[i - 1].start, components[i - 1].size,
121 dest[i - 1], components[i - 1].inflated);
122 if (err != EOK) {
123 printf("\n%s: Inflating error %d\n", components[i - 1].name, err);
124 halt();
125 }
126 /* Make sure data are in the memory, ICache will need them */
127 clean_dcache_poc(dest[i - 1], components[i - 1].inflated);
128 }
129
130 printf(".\n");
131
132 /* Flush PT too. We need this if we disable caches later */
133 clean_dcache_poc(boot_pt, PTL0_ENTRIES * PTL0_ENTRY_SIZE);
134
135 printf("Booting the kernel...\n");
136 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo);
137}
138
139/** @}
140 */
Note: See TracBrowser for help on using the repository browser.