biosboot.S revision 1.1.2.4 1 /* $NetBSD: biosboot.S,v 1.1.2.4 2004/09/21 13:17:10 skrll Exp $ */
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <machine/asm.h>
40 #include <sys/bootblock.h>
41
42 /*
43 * Code linked to 0x1000:0 and (usually) read from /boot by bootxx code
44 *
45 * On entry:
46 * %dl BIOS drive number
47 * %ebx Sector number of netbsd partition
48 * %ds:%esi Boot parameter block (patched by installboot)
49 * %cs 0x1000
50 * %ds, %es, %ss All zero
51 * %sp near 0xfffc
52 */
53
54 .text
55 .code16
56 ENTRY(boot_start)
57 jmp boot_start_1
58 .balign 4
59 ENTRY(boot_magic)
60 .long X86_BOOT_MAGIC_2 /* checked for by bootxx code */
61 ENTRY(boot_params)
62 .long boot_start_1 - boot_params
63 #include <boot_params.S>
64 . = boot_start + 0x80 /* space for patchable variables */
65 boot_start_1:
66
67 #if 0
68 /* Allow for boot_start not being %cs:0 */
69 call 2f
70 2: pop %cx
71 sub $2b, %cx /* %ax is offset */
72 test $0xf, %cx /* check code seg aligned */
73 jz 3f
74 lret /* not playing if not */
75 3: mov %cs, %ax
76 shr $4, %cx
77 add %cx, %ax /* segment staring at boot_start */
78 push %ax
79 push $4f
80 lret
81 4:
82 #endif
83
84 mov %cs, %ax
85 mov %ax, %es
86
87 /* Grab boot_params patched into bootxx by installboot */
88 cmpl $X86_BOOT_MAGIC_1,-4(%si) /* sanity check ptr */
89 jne 2f
90 mov $boot_params, %di
91 movl (%si),%ecx
92 cmp $boot_start_1 - boot_params, %cx
93 jbe 1f
94 mov $boot_start_1 - boot_params, %cx
95 1: cld
96 rep
97 movsb
98 2:
99
100 mov %ax, %ds
101 movl $_end, %eax /* top of bss */
102 shr $4, %eax /* as a segment */
103 add $0x1001, %ax /* and + 64k */
104 mov %ax, %ss /* for stack */
105 mov $0xfffc, %sp /* %sp at top of it */
106
107 call gdt_fixup
108
109 calll real_to_prot
110 .code32
111
112 movl $_end, %ecx /* zero bss */
113 movl $__bss_start, %edi
114 subl %edi, %ecx
115 shr $2, %ecx /* _end and __bss_start are aligned */
116 xor %eax, %eax
117 rep
118 stosl
119
120 and $0xff, %edx
121 push %ebx /* first sector of bios partition */
122 push %edx /* bios disk */
123 call _C_LABEL(boot2) /* C bootstrap code */
124 add $8, %esp
125 call prot_to_real
126 .code16
127
128 boot_fail:
129 push %ax
130 movw $1f, %si
131 call message
132 pop %si
133 call message
134 jmp loopstop
135 1: .asciz "Boot2 failed: "
136
137 ENTRY(_rtt)
138 .code32
139 call prot_to_real
140 .code16
141 loopstop:
142 movb 0x86, %ah /* delay for about a second */
143 movw $16, %cx
144 int $0x15
145 int $0x18 /* might be a boot fail entry */
146 1: sti
147 hlt
148 jmp 1b
149