Print this page
de-linting of .s files
m
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/ml/fb_swtch_src.s
+++ new/usr/src/uts/i86pc/ml/fb_swtch_src.s
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 * Copyright 2018 Joyent, Inc.
26 26 */
27 27
28 28
29 -#if defined(__lint)
30 -
31 -int fb_swtch_silence_lint = 0;
32 -
33 -#else
34 -
35 29 #include <sys/asm_linkage.h>
36 30 #include <sys/segments.h>
37 31 #include <sys/controlregs.h>
38 32 #include <sys/machparam.h>
39 33 #include <sys/multiboot.h>
40 34 #include <sys/fastboot.h>
41 35 #include "assym.h"
42 36
43 37 /*
44 38 * This code is to switch from 64-bit or 32-bit to protected mode.
45 39 */
46 40
47 41 /*
48 42 * For debugging with LEDs
49 43 */
50 44 #define FB_OUTB_ASM(val) \
51 45 movb val, %al; \
52 46 outb $0x80;
53 47
54 48
55 49 #define DISABLE_PAGING \
56 50 movl %cr4, %eax ;\
57 51 btrl $17, %eax /* clear PCIDE bit */ ;\
58 52 movl %eax, %cr4 ;\
59 53 movl %cr0, %eax ;\
60 54 btrl $31, %eax /* clear PG bit */ ;\
61 55 movl %eax, %cr0
62 56
63 57 /*
64 58 * This macro contains common code for 64/32-bit versions of copy_sections().
65 59 * On entry:
66 60 * fbf points to the fboot_file_t
67 61 * snum contains the number of sections
68 62 * Registers that would be clobbered:
69 63 * fbs, snum, %eax, %ecx, %edi, %esi.
70 64 * NOTE: fb_dest_pa is supposed to be in the first 1GB,
71 65 * therefore it is safe to use 32-bit register to hold it's value
72 66 * even for 64-bit code.
73 67 */
74 68
75 69 #define COPY_SECT(fbf, fbs, snum) \
76 70 lea FB_SECTIONS(fbf), fbs; \
77 71 xorl %eax, %eax; \
78 72 1: movl FB_DEST_PA(fbf), %esi; \
79 73 addl FB_SEC_OFFSET(fbs), %esi; \
80 74 movl FB_SEC_PADDR(fbs), %edi; \
81 75 movl FB_SEC_SIZE(fbs), %ecx; \
82 76 rep \
83 77 movsb; \
84 78 /* Zero BSS */ \
85 79 movl FB_SEC_BSS_SIZE(fbs), %ecx; \
86 80 rep \
87 81 stosb; \
88 82 add $FB_SECTIONS_INCR, fbs; \
↓ open down ↓ |
44 lines elided |
↑ open up ↑ |
89 83 dec snum; \
90 84 jnz 1b
91 85
92 86
93 87 .globl _start
94 88 _start:
95 89
96 90 /* Disable interrupts */
97 91 cli
98 92
99 -#if defined(__amd64)
100 93 /* Switch to a low memory stack */
101 94 movq $_start, %rsp
102 95 addq $FASTBOOT_STACK_OFFSET, %rsp
103 96
104 97 /*
105 98 * Copy from old stack to new stack
106 99 * If the content before fi_valid gets bigger than 0x200 bytes,
107 100 * the reserved stack size above will need to be changed.
108 101 */
109 102 movq %rdi, %rsi /* source from old stack */
110 103 movq %rsp, %rdi /* destination on the new stack */
111 104 movq $FI_VALID, %rcx /* size to copy */
112 105 rep
113 106 smovb
114 107
115 -#elif defined(__i386)
116 - movl 0x4(%esp), %esi /* address of fastboot info struct */
117 -
118 - /* Switch to a low memory stack */
119 - movl $_start, %esp
120 - addl $FASTBOOT_STACK_OFFSET, %esp
121 -
122 - /* Copy struct to stack */
123 - movl %esp, %edi /* destination on the new stack */
124 - movl $FI_VALID, %ecx /* size to copy */
125 - rep
126 - smovb
127 -
128 -#endif
129 -
130 -#if defined(__amd64)
131 -
132 108 xorl %eax, %eax
133 109 xorl %edx, %edx
134 110
135 111 movl $MSR_AMD_FSBASE, %ecx
136 112 wrmsr
137 113
138 114 movl $MSR_AMD_GSBASE, %ecx
139 115 wrmsr
140 116
141 117 movl $MSR_AMD_KGSBASE, %ecx
142 118 wrmsr
143 119
144 -#endif
145 120 /*
146 121 * zero out all the registers to make sure they're 16 bit clean
147 122 */
148 -#if defined(__amd64)
149 123 xorq %r8, %r8
150 124 xorq %r9, %r9
151 125 xorq %r10, %r10
152 126 xorq %r11, %r11
153 127 xorq %r12, %r12
154 128 xorq %r13, %r13
155 129 xorq %r14, %r14
156 130 xorq %r15, %r15
157 -#endif
158 131 xorl %eax, %eax
159 132 xorl %ebx, %ebx
160 133 xorl %ecx, %ecx
161 134 xorl %edx, %edx
162 135 xorl %ebp, %ebp
163 136
164 -#if defined(__amd64)
165 137 /*
166 138 * Load our own GDT
167 139 */
168 140 lgdt gdt_info
169 -#endif
170 141 /*
171 142 * Load our own IDT
172 143 */
173 144 lidt idt_info
174 145
175 -#if defined(__amd64)
176 146 /*
177 147 * Invalidate all TLB entries.
178 148 * Load temporary pagetables to copy kernel and boot-archive
179 149 */
180 150 movq %cr4, %rax
181 151 andq $_BITNOT(CR4_PGE), %rax
182 152 movq %rax, %cr4
183 153 movq FI_PAGETABLE_PA(%rsp), %rax
184 154 movq %rax, %cr3
185 155
186 156 leaq FI_FILES(%rsp), %rbx /* offset to the files */
187 157
188 158 /* copy unix to final destination */
189 159 movq FI_LAST_TABLE_PA(%rsp), %rsi /* page table PA */
190 160 leaq _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%rbx), %rdi
191 161 call map_copy
192 162
193 163 /* copy boot archive to final destination */
194 164 movq FI_LAST_TABLE_PA(%rsp), %rsi /* page table PA */
195 165 leaq _MUL(FASTBOOT_BOOTARCHIVE, FI_FILES_INCR)(%rbx), %rdi
196 166 call map_copy
197 167
198 168 /* Copy sections if there are any */
199 169 leaq _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%rbx), %rdi
200 170 movl FB_SECTCNT(%rdi), %esi
201 171 cmpl $0, %esi
202 172 je 1f
203 173 call copy_sections
204 174 1:
205 175 /*
206 176 * Shut down 64 bit mode. First get into compatiblity mode.
207 177 */
208 178 movq %rsp, %rax
209 179 pushq $B32DATA_SEL
210 180 pushq %rax
211 181 pushf
212 182 pushq $B32CODE_SEL
213 183 pushq $1f
214 184 iretq
215 185
216 186 .code32
217 187 1:
218 188 movl $B32DATA_SEL, %eax
219 189 movw %ax, %ss
220 190 movw %ax, %ds
221 191 movw %ax, %es
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
222 192 movw %ax, %fs
223 193 movw %ax, %gs
224 194
225 195 /*
226 196 * Disable long mode by:
227 197 * - shutting down paging (bit 31 of cr0). This will flush the
228 198 * TLBs.
229 199 * - turning off PCID in cr4
230 200 * - disabling LME (long mode enable) in EFER (extended feature reg)
231 201 */
232 -#endif
233 202 DISABLE_PAGING /* clobbers %eax */
234 203
235 -#if defined(__amd64)
236 204 ljmp $B32CODE_SEL, $1f
237 205 1:
238 -#endif
239 206
240 207 /*
241 208 * Clear PGE, PAE and PSE flags as dboot expects them to be
242 209 * cleared.
243 210 */
244 211 movl %cr4, %eax
245 212 andl $_BITNOT(CR4_PGE | CR4_PAE | CR4_PSE), %eax
246 213 movl %eax, %cr4
247 214
248 -#if defined(__amd64)
249 215 movl $MSR_AMD_EFER, %ecx /* Extended Feature Enable */
250 216 rdmsr
251 217 btcl $8, %eax /* bit 8 Long Mode Enable bit */
252 218 wrmsr
253 219
254 -#elif defined(__i386)
255 - /*
256 - * If fi_has_pae is set, re-enable paging with PAE.
257 - */
258 - leal FI_FILES(%esp), %ebx /* offset to the files */
259 - movl FI_HAS_PAE(%esp), %edi /* need to enable paging or not */
260 - cmpl $0, %edi
261 - je paging_on /* no need to enable paging */
262 -
263 - movl FI_LAST_TABLE_PA(%esp), %esi /* page table PA */
264 -
265 - /*
266 - * Turn on PAE
267 - */
268 - movl %cr4, %eax
269 - orl $CR4_PAE, %eax
270 - movl %eax, %cr4
271 -
272 - /*
273 - * Load top pagetable base address into cr3
274 - */
275 - movl FI_PAGETABLE_PA(%esp), %eax
276 - movl %eax, %cr3
277 -
278 - movl %cr0, %eax
279 - orl $_CONST(CR0_PG | CR0_WP | CR0_AM), %eax
280 - andl $_BITNOT(CR0_NW | CR0_CD), %eax
281 - movl %eax, %cr0
282 - jmp paging_on
283 -paging_on:
284 -
285 - /* copy unix to final destination */
286 - leal _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%ebx), %edx
287 - call map_copy
288 -
289 - /* copy boot archive to final destination */
290 - leal _MUL(FASTBOOT_BOOTARCHIVE, FI_FILES_INCR)(%ebx), %edx
291 - call map_copy
292 -
293 - /* Disable paging one more time */
294 - DISABLE_PAGING
295 -
296 - /* Copy sections if there are any */
297 - leal _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%ebx), %edx
298 - movl FB_SECTCNT(%edx), %eax
299 - cmpl $0, %eax
300 - je 1f
301 - call copy_sections
302 -1:
303 -
304 - /* Whatever flags we turn on we need to turn off */
305 - movl %cr4, %eax
306 - andl $_BITNOT(CR4_PAE), %eax
307 - movl %eax, %cr4
308 -#endif /* __i386 */
309 -
310 220 dboot_jump:
311 221 /* Jump to dboot */
312 222 movl $DBOOT_ENTRY_ADDRESS, %edi
313 223 movl FI_NEW_MBI_PA(%esp), %ebx
314 224 movl $MB_BOOTLOADER_MAGIC, %eax
315 225 jmp *%edi
316 226
317 -#if defined(__amd64)
318 -
319 227 .code64
320 228 ENTRY_NP(copy_sections)
321 229 /*
322 230 * On entry
323 231 * %rdi points to the fboot_file_t
324 232 * %rsi contains number of sections
325 233 */
326 234 movq %rdi, %rdx
327 235 movq %rsi, %r9
328 236
329 237 COPY_SECT(%rdx, %r8, %r9)
330 238 ret
331 239 SET_SIZE(copy_sections)
332 240
333 241 ENTRY_NP(map_copy)
334 242 /*
335 243 * On entry
336 244 * %rdi points to the fboot_file_t
337 245 * %rsi has FI_LAST_TABLE_PA(%rsp)
338 246 */
339 247
340 248 movq %rdi, %rdx
341 249 movq %rsi, %r8
342 250 movq FB_PTE_LIST_PA(%rdx), %rax /* PA list of the source */
343 251 movq FB_DEST_PA(%rdx), %rdi /* PA of the destination */
344 252
345 253 2:
346 254 movq (%rax), %rcx /* Are we done? */
347 255 cmpl $FASTBOOT_TERMINATE, %ecx
348 256 je 1f
349 257
350 258 movq %rcx, (%r8)
351 259 movq %cr3, %rsi /* Reload cr3 */
352 260 movq %rsi, %cr3
353 261 movq FB_VA(%rdx), %rsi /* Load from VA */
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
354 262 movq $PAGESIZE, %rcx
355 263 shrq $3, %rcx /* 8-byte at a time */
356 264 rep
357 265 smovq
358 266 addq $8, %rax /* Go to next PTE */
359 267 jmp 2b
360 268 1:
361 269 ret
362 270 SET_SIZE(map_copy)
363 271
364 -#elif defined(__i386)
365 -
366 - ENTRY_NP(copy_sections)
367 - /*
368 - * On entry
369 - * %edx points to the fboot_file_t
370 - * %eax contains the number of sections
371 - */
372 - pushl %ebp
373 - pushl %ebx
374 - pushl %esi
375 - pushl %edi
376 -
377 - movl %eax, %ebp
378 -
379 - COPY_SECT(%edx, %ebx, %ebp)
380 -
381 - popl %edi
382 - popl %esi
383 - popl %ebx
384 - popl %ebp
385 - ret
386 - SET_SIZE(copy_sections)
387 -
388 - ENTRY_NP(map_copy)
389 - /*
390 - * On entry
391 - * %edx points to the fboot_file_t
392 - * %edi has FB_HAS_PAE(%esp)
393 - * %esi has FI_LAST_TABLE_PA(%esp)
394 - */
395 - pushl %eax
396 - pushl %ebx
397 - pushl %ecx
398 - pushl %edx
399 - pushl %ebp
400 - pushl %esi
401 - pushl %edi
402 - movl %esi, %ebp /* Save page table PA in %ebp */
403 -
404 - movl FB_PTE_LIST_PA(%edx), %eax /* PA list of the source */
405 - movl FB_DEST_PA(%edx), %ebx /* PA of the destination */
406 -
407 -loop:
408 - movl (%eax), %esi /* Are we done? */
409 - cmpl $FASTBOOT_TERMINATE, %esi
410 - je done
411 -
412 - cmpl $1, (%esp) /* Is paging on? */
413 - jne no_paging /* Nope */
414 -
415 - movl %ebp, %edi /* Page table PA */
416 - movl %esi, (%edi) /* Program low 32-bit */
417 - movl 4(%eax), %esi /* high bits of the table */
418 - movl %esi, 4(%edi) /* Program high 32-bit */
419 - movl %cr3, %esi /* Reload cr3 */
420 - movl %esi, %cr3
421 - movl FB_VA(%edx), %esi /* Load from VA */
422 - jmp do_copy
423 -no_paging:
424 - andl $_BITNOT(MMU_PAGEOFFSET), %esi /* clear lower 12-bit */
425 -do_copy:
426 - movl %ebx, %edi
427 - movl $PAGESIZE, %ecx
428 - shrl $2, %ecx /* 4-byte at a time */
429 - rep
430 - smovl
431 - addl $8, %eax /* We built the PTEs as 8-byte entries */
432 - addl $PAGESIZE, %ebx
433 - jmp loop
434 -done:
435 - popl %edi
436 - popl %esi
437 - popl %ebp
438 - popl %edx
439 - popl %ecx
440 - popl %ebx
441 - popl %eax
442 - ret
443 - SET_SIZE(map_copy)
444 -#endif /* __i386 */
445 -
446 -
447 272 idt_info:
448 273 .value 0x3ff
449 274 .quad 0
450 275
451 276 /*
452 277 * We need to trampoline thru a gdt we have in low memory.
453 278 */
454 279 #include "../boot/boot_gdt.s"
455 -#endif /* __lint */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX