Annotation of src/sys/arch/i386/stand/boot/biosboot.S, Revision 1.5.74.1
1.5.74.1! mjf 1: /* $NetBSD$ */
1.1 dsl 2:
3: /*-
4: * Copyright (c) 2003 The NetBSD Foundation, Inc.
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
8: * by David Laight.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29: * POSSIBILITY OF SUCH DAMAGE.
30: */
31:
32: #include <machine/asm.h>
1.2 lukem 33: #include <sys/bootblock.h>
1.1 dsl 34:
35: /*
36: * Code linked to 0x1000:0 and (usually) read from /boot by bootxx code
37: *
38: * On entry:
39: * %dl BIOS drive number
40: * %ebx Sector number of netbsd partition
41: * %ds:%esi Boot parameter block (patched by installboot)
42: * %cs 0x1000
43: * %ds, %es, %ss All zero
44: * %sp near 0xfffc
45: */
46:
47: .text
48: .code16
49: ENTRY(boot_start)
50: jmp boot_start_1
1.3 dsl 51: .balign 4
1.1 dsl 52: ENTRY(boot_magic)
53: .long X86_BOOT_MAGIC_2 /* checked for by bootxx code */
54: ENTRY(boot_params)
55: .long boot_start_1 - boot_params
1.3 dsl 56: #include <boot_params.S>
1.1 dsl 57: . = boot_start + 0x80 /* space for patchable variables */
58: boot_start_1:
59:
60: #if 0
61: /* Allow for boot_start not being %cs:0 */
62: call 2f
63: 2: pop %cx
64: sub $2b, %cx /* %ax is offset */
65: test $0xf, %cx /* check code seg aligned */
66: jz 3f
67: lret /* not playing if not */
68: 3: mov %cs, %ax
69: shr $4, %cx
70: add %cx, %ax /* segment staring at boot_start */
71: push %ax
72: push $4f
73: lret
74: 4:
75: #endif
76:
77: mov %cs, %ax
78: mov %ax, %es
79:
1.4 junyoung 80: /* Grab boot_params patched into bootxx by installboot */
1.1 dsl 81: cmpl $X86_BOOT_MAGIC_1,-4(%si) /* sanity check ptr */
82: jne 2f
83: mov $boot_params, %di
84: movl (%si),%ecx
85: cmp $boot_start_1 - boot_params, %cx
86: jbe 1f
87: mov $boot_start_1 - boot_params, %cx
88: 1: cld
89: rep
90: movsb
91: 2:
92:
93: mov %ax, %ds
94: movl $_end, %eax /* top of bss */
95: shr $4, %eax /* as a segment */
96: add $0x1001, %ax /* and + 64k */
97: mov %ax, %ss /* for stack */
98: mov $0xfffc, %sp /* %sp at top of it */
99:
100: call gdt_fixup
101:
102: calll real_to_prot
103: .code32
104:
105: movl $_end, %ecx /* zero bss */
106: movl $__bss_start, %edi
107: subl %edi, %ecx
108: shr $2, %ecx /* _end and __bss_start are aligned */
109: xor %eax, %eax
110: rep
111: stosl
112:
113: and $0xff, %edx
114: push %ebx /* first sector of bios partition */
115: push %edx /* bios disk */
116: call _C_LABEL(boot2) /* C bootstrap code */
117: add $8, %esp
118: call prot_to_real
119: .code16
120:
121: boot_fail:
122: push %ax
123: movw $1f, %si
124: call message
125: pop %si
126: call message
127: jmp loopstop
128: 1: .asciz "Boot2 failed: "
129:
130: ENTRY(_rtt)
131: .code32
132: call prot_to_real
133: .code16
134: loopstop:
135: movb 0x86, %ah /* delay for about a second */
136: movw $16, %cx
137: int $0x15
138: int $0x18 /* might be a boot fail entry */
139: 1: sti
140: hlt
141: jmp 1b
CVSweb <webmaster@jp.NetBSD.org>