Debian Codegraph @

grub-core/boot/sparc64/ieee1275/boot.S

raw
1 /* -*-Asm-*- */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
5 *
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <grub/machine/boot.h>
21
22 .text
23 .align 4
24 /*
25 * We're writing the a.out header ourselves as newer
26 * upstream versions of binutils no longer support
27 * the a.out format on sparc64.
28 *
29 * The boot loader fits into 512 bytes with 32 bytes
30 * used for the a.out header, hence the text segment
31 * size is 512 - 32. There is no data segment and no
32 * code relocation, thus those fields remain zero.
33 */
34 .word 0x1030107 /* Magic number. */
35 .word 512 - GRUB_BOOT_AOUT_HEADER_SIZE /* Size of text segment. */
36 .word 0 /* Size of initialized data. */
37 .word 0 /* Size of uninitialized data. */
38 .word 0 /* Size of symbol table || checksum. */
39 .word _start /* Entry point. */
40 .word 0 /* Size of text relocation. */
41 .word 0 /* Size of data relocation. */
42 .globl _start
43 _start:
44 /* OF CIF entry point arrives in %o4 */
45 pic_base:
46 call boot_continue
47 mov %o4, CIF_REG
48
49 #ifndef CDBOOT
50 /* The offsets to these locations are defined by the
51 * GRUB_BOOT_MACHINE_foo macros in include/grub/sparc64/ieee1275/boot.h,
52 * and grub-setup uses this to patch these next three values as needed.
53 *
54 * The boot_path will be the OF device path of the partition where the
55 * rest of the GRUB kernel image resides. kernel_sector will be set to
56 * the location of the first block of the GRUB kernel, and
57 * kernel_address is the location where we should load that first block.
58 *
59 * After loading in that block we will execute it by jumping to the
60 * load address plus the size of the prepended A.OUT header (32 bytes).
61 *
62 * Since this assembly code includes the 32 bytes long a.out header,
63 * we need to move the actual code entry point forward by the size
64 * of the a.out header, i.e. += GRUB_BOOT_AOUT_HEADER_SIZE.
65 */
66 .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE
67 boot_path:
68 .org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE
69 boot_path_end:
70 kernel_byte: .xword (2 << 9)
71 kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR
72 #else
73 #define boot_path (_start + 512 + SCRATCH_PAD_BOOT_SIZE)
74 #define boot_path_end (_start + 1024)
75 #include <grub/offsets.h>
76
77 .org 8 + GRUB_BOOT_AOUT_HEADER_SIZE
78 kernel_byte: .xword (2 << 9)
79 kernel_size: .word 512
80 kernel_address: .word GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS
81 #endif
82
83 prom_finddev_name: .asciz "finddevice"
84 prom_chosen_path: .asciz "/chosen"
85 prom_getprop_name: .asciz "getprop"
86 prom_stdout_name: .asciz "stdout"
87 prom_write_name: .asciz "write"
88 prom_bootpath_name: .asciz "bootpath"
89 prom_open_name: .asciz "open"
90 prom_seek_name: .asciz "seek"
91 prom_read_name: .asciz "read"
92 prom_exit_name: .asciz "exit"
93 grub_name: .asciz "GRUB "
94 #ifdef CDBOOT
95 prom_close_name: .asciz "close"
96 #endif
97
98 #define GRUB_NAME_LEN 5
99
100 .align 4
101
102 prom_open_error:
103 GET_ABS(prom_open_name, %o2)
104 call console_write
105 mov 4, %o3
106 /* fallthru */
107
108 prom_error:
109 GET_ABS(prom_exit_name, %o0)
110 /* fallthru */
111
112 /* %o0: OF call name
113 * %o1: input arg 1
114 */
115 prom_call_1_1_o2:
116 clr %o2
117 ba prom_call_x_1
118 mov 1, %g1
119
120 prom_call_getprop:
121 mov 4, %g1
122 stx %g1, [%l1 + 256]
123 mov CHOSEN_NODE_REG, %o1
124 ba prom_call_x_1
125 GET_ABS(prom_getprop_name, %o0)
126
127 prom_call_3_1_o1:
128 ba prom_call_3_1
129 mov BOOTDEV_REG, %o1
130
131
132 /* %o2: message string
133 * %o3: message length
134 */
135 console_write:
136 GET_ABS(prom_write_name, %o0)
137 mov STDOUT_NODE_REG, %o1
138 /* fallthru */
139
140 /* %o0: OF call name
141 * %o1: input arg 1
142 * %o2: input arg 2
143 * %o3: input arg 3
144 */
145 prom_call_3_1:
146 mov 3, %g1
147 prom_call_x_1:
148 mov 1, %o5
149 /* fallthru */
150
151 /* %o0: OF call name
152 * %g1: num inputs
153 * %o5: num outputs
154 * %o1-%o4: inputs
155 */
156 prom_call:
157 stx %o0, [%l1 + 0x00]
158 stx %g1, [%l1 + 0x08]
159 stx %o5, [%l1 + 0x10]
160 stx %o1, [%l1 + 0x18]
161 stx %o2, [%l1 + 0x20]
162 stx %o3, [%l1 + 0x28]
163 stx %o4, [%l1 + 0x30]
164 jmpl CIF_REG, %g0
165 mov %l1, %o0
166
167 boot_continue:
168 mov %o7, PIC_REG /* PIC base */
169 #ifndef CDBOOT
170 sethi %hi(SCRATCH_PAD_BOOT), %l1 /* OF argument slots */
171 #else
172 GET_ABS(_start + 512, %l1) /* OF argument slots */
173 #endif
174
175 /* Find the /chosen node so we can fetch the stdout handle,
176 * and thus perform console output.
177 *
178 * chosen_node = prom_finddevice("/chosen")
179 */
180 GET_ABS(prom_finddev_name, %o0)
181 call prom_call_1_1_o2
182 GET_ABS(prom_chosen_path, %o1)
183
184 ldx [%l1 + 0x20], CHOSEN_NODE_REG
185 brz CHOSEN_NODE_REG, prom_error
186
187 /* getprop(chosen_node, "stdout", &buffer, buffer_size) */
188 GET_ABS(prom_stdout_name, %o2)
189 add %l1, 256, %o3
190 call prom_call_getprop
191 mov 1024, %o4
192
193 lduw [%l1 + 256], STDOUT_NODE_REG
194 brz,pn STDOUT_NODE_REG, prom_error
195
196 /* write(stdout_node, "GRUB ", strlen("GRUB ")) */
197 GET_ABS(grub_name, %o2)
198 call console_write
199 mov GRUB_NAME_LEN, %o3
200
201 GET_ABS(boot_path, %o3)
202 #ifndef CDBOOT
203 ldub [%o3], %o1
204 brnz,pn %o1, bootpath_known
205 #endif
206
207 /* getprop(chosen_node, "bootpath", &buffer, buffer_size) */
208 GET_ABS(prom_bootpath_name, %o2)
209 call prom_call_getprop
210 mov (boot_path_end - boot_path), %o4
211
212 bootpath_known:
213
214 /* Open up the boot_path, and use that handle to read the
215 * first block of the GRUB kernel image.
216 *
217 * bootdev_handle = open(boot_path)
218 */
219 GET_ABS(prom_open_name, %o0)
220 call prom_call_1_1_o2
221 GET_ABS(boot_path, %o1)
222
223 ldx [%l1 + 0x20], BOOTDEV_REG
224 brz,pn BOOTDEV_REG, prom_open_error
225
226 /* Since we have 64-bit cells, the high cell of the seek offset
227 * is zero and the low cell is the entire value.
228 *
229 * seek(bootdev, 0, *kernel_byte)
230 */
231 GET_ABS(prom_seek_name, %o0)
232 clr %o2
233 call prom_call_3_1_o1
234 LDX_ABS(kernel_byte, 0x00, %o3)
235
236 /* read(bootdev, *kernel_address, 512) */
237 GET_ABS(prom_read_name, %o0)
238 LDUW_ABS(kernel_address, 0x00, %o2)
239 call prom_call_3_1_o1
240 #ifdef CDBOOT
241 LDUW_ABS(kernel_size, 0x00, %o3)
242
243 GET_ABS(prom_close_name, %o0)
244 mov 1, %g1
245 mov 0, %o5
246 call prom_call
247 mov BOOTDEV_REG, %o1
248 #else
249 mov 512, %o3
250 #endif
251
252 LDUW_ABS(kernel_address, 0x00, %o2)
253 jmpl %o2, %o7
254 #ifdef CDBOOT
255 mov CIF_REG, %o4
256 #else
257 nop
258 #endif
259 .org GRUB_BOOT_MACHINE_CODE_END
260
261 /* the last 4 bytes in the sector 0 contain the signature */
262 .word GRUB_BOOT_MACHINE_SIGNATURE