Print this page
loader: pass args along to unix in C
There's no reason why we can't pass the args gotten from the bootloader to
unix in C.
Note: loader's _start sets the ATAG pointer to 0x100. This change simply
propagates it to unix.
bcm2835: we need a loader on this platform as well
As stated before, the Raspberry Pi loader is terrible. It claims to
supporte ELF file loading, but what it does is crazy. It loads the ELF file
into memory, gets the start address from the header, converts it into file
offset, adds it to the address where the file was loaded and jumps there.
This is very wrong. So, instead of booting the loader as an ELF file, we
objcopy it into a plain ol' binary image. This should be safe because (1)
the loader has no relocations left, (2) whatever benefit we lose from not
having the whole ELF file in memory is only temporary until the loader hands
off control to unix.
Finally, we force the entry point to appear at the beginning of the binary
file by moving _start into its own section (.text.init) and using the
mapfile to put that section before everything else.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/armv6/loader/fakeloader_core.s
+++ new/usr/src/uts/armv6/loader/fakeloader_core.s
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2013 (c) Joyent, Inc. All rights reserved.
14 + * Copyright 2015 (c) Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
14 15 */
15 16
16 17 /*
17 18 * Every story needs a beginning, this is the loader's.
18 19 */
19 20
20 21 #include <sys/asm_linkage.h>
21 22
22 - ENTRY(_start)
23 +/*
24 + * We put _start into the .text.init section so we can more easily shove it
25 + * at the front of the .text.
26 + */
27 + .section .text.init
28 + .align 4
29 + .globl _start
30 + .type _start, %function
31 +_start:
23 32 mov sp, #0x8000
24 33 /*
25 34 * XXX manually fix up the tag start
26 35 */
27 36 mov r2, #0x100
28 37 bl fakeload_init
29 38 SET_SIZE(_start)
30 39
31 40 #if defined(__lint)
32 41
33 42 /* ARGSUSED */
34 43 void
35 44 fakeload_unaligned_enable(void)
36 45 {}
37 46
38 47 #else /* __lint */
39 48
40 49 /*
41 50 * Fix up alignment by turning off A and by turning on U.
42 51 */
43 52 ENTRY(fakeload_unaligned_enable)
44 53 mrc p15, 0, r0, c1, c0, 0
45 54 orr r0, #0x400000
46 55 mcr p15, 0, r0, c1, c0, 0
47 56 bx lr
48 57 SET_SIZE(fakeload_unaligned_enable);
49 58
50 59 #endif /* __lint */
51 60
52 61 #if defined(__lint)
53 62
54 63 fakeload_pt_setup(uintptr_t ptroot)
55 64 {}
56 65
57 66 #else /* __lint */
58 67
59 68 /*
60 69 * We need to set up the world for the first time. We'll do the
61 70 * following in order:
62 71 *
63 72 * o Set the TTBCR to always use TTBR0
64 73 * o Set domain 0 to manager mode
65 74 * o Program the Page table root
66 75 */
67 76 ENTRY(fakeload_pt_setup)
68 77 mov r1, #0
69 78 mcr p15, 0, r1, c2, c0, 2
70 79 mov r1, #3
71 80 mcr p15, 0, r1, c3, c0, 0
72 81 orr r0, r0, #0x1b
73 82 mcr p15, 0, r0, c2, c0, 0
74 83 bx lr
75 84 SET_SIZE(fakeload_pt_setup)
76 85
77 86 #endif /* __lint */
78 87
79 88 #if defined(__lint)
80 89
81 90 /* ARGSUSED */
82 91 void
83 92 fakeload_mmu_enable(void)
84 93 {}
85 94
86 95 #else /* __lint */
87 96
88 97 /*
89 98 * We first make sure that the ARMv6 pages are enabled (bit 23) and then
90 99 * enable the MMU (bit 0).
91 100 */
92 101 ENTRY(fakeload_mmu_enable)
93 102 mrc p15, 0, r0, c1, c0, 0
94 103 orr r0, #0x800000
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
95 104 mcr p15, 0, r0, c1, c0, 0
96 105 mrc p15, 0, r0, c1, c0, 0
97 106 orr r0, #0x1
98 107 mcr p15, 0, r0, c1, c0, 0
99 108 bx lr
100 109 SET_SIZE(fakeload_mmu_enable)
101 110 #endif /* __lint */
102 111
103 112
104 113 ENTRY(fakeload_exec)
105 - mov r4, r0
106 - mov r2, #0x100
107 - blx r4
114 + blx r3
108 115 /* We should never execute this. If we do we'll go back to a panic */
109 116 bx lr
110 117 SET_SIZE(fakeload_exec)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX