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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b1011dae was cfeb368, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

arm32, boot: Remove redundant parameter.

  • Property mode set to 100644
File size: 5.0 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
55
56static inline void invalidate_icache(void)
57{
58 /* ICIALLU Invalidate entire ICache */
59 asm volatile ("mov r0, #0\n" "mcr p15, 0, r0, c7, c5, 0\n" ::: "r0" );
60}
61
62static inline void invalidate_dcache(void *address, size_t size)
63{
64 const uintptr_t addr = (uintptr_t)address;
65 /* DCIMVAC - invalidate by address to the point of coherence */
66 for (uintptr_t a = addr; a < addr + size; a += 4) {
67 asm volatile ("mcr p15, 0, %[a], c7, c6, 1\n" :: [a]"r"(a) : );
68 }
69}
70
71static inline void clean_dcache_poc(void *address, size_t size)
72{
73 const uintptr_t addr = (uintptr_t)address;
74 /* DCCMVAC - clean by address to the point of coherence */
75 for (uintptr_t a = addr; a < addr + size; a += 4) {
76 asm volatile ("mcr p15, 0, %[a], c7, c10, 1\n" :: [a]"r"(a) : );
77 }
78}
79
80static bootinfo_t bootinfo;
81
82void bootstrap(void)
83{
84 /* Make sure we run in memory code when caches are enabled,
85 * make sure we read memory data too. This part is ARMv7 specific as
86 * ARMv7 no longer invalidates caches on restart.
87 * See chapter B2.2.2 of ARM Architecture Reference Manual p. B2-1263*/
88 invalidate_icache();
89 invalidate_dcache(&bdata_start, &bdata_end - &bdata_start);
90
91 /* Enable MMU and caches */
92 mmu_start();
93 version_print();
94
95 printf("Boot data: %p -> %p\n", &bdata_start, &bdata_end);
96 printf("\nMemory statistics\n");
97 printf(" %p|%p: bootstrap stack\n", &boot_stack, &boot_stack);
98 printf(" %p|%p: bootstrap page table\n", &boot_pt, &boot_pt);
99 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
100 printf(" %p|%p: kernel entry point\n",
101 (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
102
103 for (size_t i = 0; i < COMPONENTS; i++) {
104 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
105 components[i].start, components[i].name, components[i].inflated,
106 components[i].size);
107 invalidate_dcache(components[i].start, components[i].size);
108 }
109
110 void *dest[COMPONENTS];
111 size_t top = 0;
112 size_t cnt = 0;
113 bootinfo.cnt = 0;
114 for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
115 top = ALIGN_UP(top, PAGE_SIZE);
116
117 if (i > 0) {
118 bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
119 bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
120
121 str_cpy(bootinfo.tasks[bootinfo.cnt].name,
122 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
123
124 bootinfo.cnt++;
125 }
126
127 dest[i] = TOP2ADDR(top);
128 top += components[i].inflated;
129 cnt++;
130 }
131
132 printf("\nInflating components ... ");
133
134 for (size_t i = cnt; i > 0; i--) {
135 void *tail = components[i - 1].start + components[i - 1].size;
136 if (tail >= dest[i - 1]) {
137 printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
138 components[i].name, tail, dest[i - 1]);
139 halt();
140 }
141
142 printf("%s ", components[i - 1].name);
143
144 int err = inflate(components[i - 1].start, components[i - 1].size,
145 dest[i - 1], components[i - 1].inflated);
146 if (err != EOK) {
147 printf("\n%s: Inflating error %d\n", components[i - 1].name, err);
148 halt();
149 }
150 clean_dcache_poc(dest[i - 1], components[i - 1].inflated);
151 }
152
153 printf(".\n");
154
155 void *kernel_end = (void *) PA2KA(BOOT_OFFSET + components[0].inflated);
156 printf("Booting the kernel...\n");
157 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo);
158}
159
160/** @}
161 */
Note: See TracBrowser for help on using the repository browser.