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

Last change on this file was b169619, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 20 months ago

Deduplicate mem functions

There are a number of functions which are copied between
kernel, libc, and potentially boot too. mem*() functions
are first such offenders. All this duplicate code will
be moved to directory 'common'.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[4872160]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
[c5429fe]29/** @addtogroup boot_arm32
[4872160]30 * @{
31 */
32/** @file
33 * @brief Bootstrap.
34 */
35
36#include <arch/main.h>
[3f7fe9e]37#include <arch/types.h>
[4872160]38#include <arch/asm.h>
39#include <arch/mm.h>
40#include <halt.h>
41#include <printf.h>
[b169619]42#include <mem.h>
[4872160]43#include <version.h>
44#include <macros.h>
45#include <align.h>
[d735e2e]46#include <stdbool.h>
[4872160]47#include <str.h>
48#include <errno.h>
49#include <inflate.h>
[15fbe6a]50#include <arch/cp15.h>
[63a045c]51#include <payload.h>
[cfdeedc]52#include <kernel.h>
[4872160]53
[63a045c]54static void clean_dcache_poc(void *address, size_t size)
[bfb6576]55{
[15fbe6a]56 const uintptr_t addr = (uintptr_t) address;
57
58#if !defined(PROCESSOR_ARCH_armv7_a)
59 bool sep;
60 if (MIDR_read() != CTR_read()) {
61 sep = (CTR_read() & CTR_SEP_FLAG) == CTR_SEP_FLAG;
62 } else {
63 printf("Unknown cache type.\n");
64 halt();
65 }
66#endif
67
68 for (uintptr_t a = ALIGN_DOWN(addr, CP15_C7_MVA_ALIGN); a < addr + size;
69 a += CP15_C7_MVA_ALIGN) {
70#if defined(PROCESSOR_ARCH_armv7_a)
71 DCCMVAC_write(a);
72#else
73 if (sep)
74 DCCMVA_write(a);
75 else
76 CCMVA_write(a);
77#endif
[bfb6576]78 }
79}
80
[4872160]81static bootinfo_t bootinfo;
82
83void bootstrap(void)
84{
[bfb6576]85 /* Enable MMU and caches */
[4872160]86 mmu_start();
87 version_print();
[a35b458]88
[63a045c]89 printf("Boot loader: %p -> %p\n", loader_start, loader_end);
[4872160]90 printf("\nMemory statistics\n");
91 printf(" %p|%p: bootstrap stack\n", &boot_stack, &boot_stack);
92 printf(" %p|%p: bootstrap page table\n", &boot_pt, &boot_pt);
93 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
[7e752b2]94 printf(" %p|%p: kernel entry point\n",
95 (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
[a35b458]96
[63a045c]97 // FIXME: Use the correct value.
98 uint8_t *kernel_dest = (uint8_t *) BOOT_OFFSET;
99 uint8_t *ram_end = kernel_dest + (1 << 24);
[a35b458]100
[63a045c]101 extract_payload(&bootinfo.taskmap, kernel_dest, ram_end,
102 PA2KA(kernel_dest), clean_dcache_poc);
[7cd15b9]103
104 /* Flush PT too. We need this if we disable caches later */
105 clean_dcache_poc(boot_pt, PTL0_ENTRIES * PTL0_ENTRY_SIZE);
[a35b458]106
[cfdeedc]107 uintptr_t entry = check_kernel((void *) PA2KA(BOOT_OFFSET));
108
[83742a4]109 printf("Booting the kernel...\n");
[cfdeedc]110 jump_to_kernel((void *) entry, &bootinfo);
[4872160]111}
112
113/** @}
114 */
Note: See TracBrowser for help on using the repository browser.