Fully synchronize sys/boot from FreeBSD-5.x, but add / to the module path
[dragonfly.git] / sys / boot / pc98 / boot2 / boot2.S
1 /*
2  * Mach Operating System
3  * Copyright (c) 1992, 1991 Carnegie Mellon University
4  * All Rights Reserved.
5  * 
6  * Permission to use, copy, modify and distribute this software and its
7  * documentation is hereby granted, provided that both the copyright
8  * notice and this permission notice appear in all copies of the
9  * software, derivative works or modified versions, and any portions
10  * thereof, and that both notices appear in supporting documentation.
11  * 
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15  * 
16  * Carnegie Mellon requests users of this software to return to
17  * 
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19  *  School of Computer Science
20  *  Carnegie Mellon University
21  *  Pittsburgh PA 15213-3890
22  * 
23  * any improvements or extensions that they make and grant Carnegie Mellon
24  * the rights to redistribute these changes.
25  *
26  *      from: Mach, Revision 2.2  92/04/04  11:35:26  rpd
27  *      boot2.S,v 1.6 1995/01/25 21:37:40 bde Exp
28  * $FreeBSD: src/sys/boot/pc98/boot2/boot2.S,v 1.3 2001/05/24 11:18:32 nyan Exp $
29  * $DragonFly: src/sys/boot/pc98/boot2/Attic/boot2.S,v 1.3 2003/11/10 06:08:38 dillon Exp $
30  */
31 /*
32  * Ported to PC-9801 by Yoshio Kimura
33  */
34
35 #include        "asm.h"
36
37 /* Conventional GDT indexes. */
38 #define BOOT_CS_INDEX           3
39 #define BOOT_CS16_INDEX         5
40 #define BOOT_DS_INDEX           4
41
42 #ifdef BDE_DEBUGGER
43 #define DB_CS_INDEX             14
44 #define DB_CS16_INDEX           15
45 #define DB_DS_INDEX             16
46 #define GDT_INDEX               17
47 #endif
48
49 /* Vector numbers. */
50 #define BREAKPOINT_VECTOR       3
51 #define DEBUG_VECTOR            1
52
53 /*
54  * boot2() -- second stage boot
55  * SP points to default string if found
56  */
57         .code16
58 ENTRY(boot2)
59         subl    %eax, %eax
60         mov     %cs, %ax
61         mov     %ax, %ds
62         mov     %ax, %es
63         shll    $4, %eax
64
65         /* fix up GDT entries for bootstrap */
66 #define FIXUP(gdt_index) \
67         .code32; \
68         addr32; \
69         movl    %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \
70         addr32; \
71         movb    %bl, EXT(Gdt)+(8*gdt_index)+4; \
72         .code16
73
74         shld    $16, %eax, %ebx
75         FIXUP(BOOT_CS_INDEX)
76         FIXUP(BOOT_CS16_INDEX)
77         FIXUP(BOOT_DS_INDEX)
78
79         /* fix up GDT pointer */
80         movl    %eax, %ecx
81         addl    $ EXT(Gdt), %eax
82         .code32
83         addr32
84         data32
85         movl    %eax, EXT(Gdtr)+2
86         .code16
87
88 #ifdef BDE_DEBUGGER
89         /* fix up GDT entry for GDT */
90         data32
91         shld    $16, %eax, %ebx
92         FIXUP(GDT_INDEX)
93
94         /* fix up IDT pointer */
95         data32
96         addl    $ EXT(Idt), %ecx
97         addr32
98         data32
99         movl    %ecx, EXT(Idtr_prot)+2
100
101         /* %es = vector table segment for a while */
102         push    %es
103         data32
104         subl    %eax, %eax
105         mov     %ax, %es
106
107         /* fix up GDT entries for bdb */
108         data32
109         movl    $4*DEBUG_VECTOR, %esi
110         addr32
111         movl    %es: 2(%esi), %eax      /* actually movw to %ax */
112         data32
113         shll    $4, %eax
114         data32
115         shld    $16, %eax, %ebx
116         FIXUP(DB_CS_INDEX)
117         FIXUP(DB_CS16_INDEX)
118         FIXUP(DB_DS_INDEX)
119
120         /* Fetch entry points of bdb's protected mode trap handlers.  These
121          * are stored at 2 before the corresponding entry points for real mode.
122          */
123         data32
124         subl    %ebx, %ebx
125         addr32
126         movl    %es: (%esi), %ebx       /* actually movw to %bx */
127         data32
128         subl    %ecx, %ecx
129         addr32
130         movl    %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx
131                                         /* actually movw to %cx */
132
133         /* %es = bdb segment for a while */
134         data32
135         shrl    $4, %eax
136         mov     %ax, %es
137
138         /* fix up IDT entries for bdb */
139         data32
140         subl    $2, %ebx                /* calculate EA to check it */
141         jb      1f                      /* give up if it would trap */
142         addr32
143         movl    %es: (%ebx), %eax       /* actually movw to %ax */
144         addr32
145         movl    %eax, EXT(Idt)+8*DEBUG_VECTOR   /* actually movw %ax */
146 1:
147         data32
148         subl    $2, %ecx
149         jb      1f
150         addr32
151         movl    %es: (%ecx), %eax       /* actually movw to %ax */
152         addr32
153         movl    %eax, EXT(Idt)+8*BREAKPOINT_VECTOR      /* actually movw %ax */
154 1:
155
156         /* finished with groping in real mode segments */
157         pop     %es
158 #endif /* BDE_DEBUGGER */
159
160         /* change to protected mode */
161         .code32
162         data32
163         call    EXT(real_to_prot)
164
165         /* clear the bss */
166         movl    $ EXT(edata), %edi      /* no EXT(_edata) - krufty ld */
167         movl    $ EXT(end), %ecx        /* or EXT(_end) */
168         subl    %edi, %ecx
169         subb    %al, %al
170         rep
171         stosb
172
173 #ifdef NAMEBLOCK
174         movl    %esp, EXT(dflt_name)
175 #endif
176
177 #ifdef PC98
178         movb    0xA1584 - BOOTSEG * 0x10, %dl
179 #endif
180         movzbl  %dl, %edx       /* discard head (%dh) and random high bits */
181         pushl   %edx
182         call    EXT(boot)
183 oops:
184         hlt
185         jmp     oops