]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/boot/pc98/boot2/boot2.S
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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$
29  */
30 /*
31  * Ported to PC-9801 by Yoshio Kimura
32  */
33
34 #include        "asm.h"
35
36 /* Conventional GDT indexes. */
37 #define BOOT_CS_INDEX           3
38 #define BOOT_CS16_INDEX         5
39 #define BOOT_DS_INDEX           4
40
41 #ifdef BDE_DEBUGGER
42 #define DB_CS_INDEX             14
43 #define DB_CS16_INDEX           15
44 #define DB_DS_INDEX             16
45 #define GDT_INDEX               17
46 #endif
47
48 /* Vector numbers. */
49 #define BREAKPOINT_VECTOR       3
50 #define DEBUG_VECTOR            1
51
52 /*
53  * boot2() -- second stage boot
54  * SP points to default string if found
55  */
56         .code16
57 ENTRY(boot2)
58         subl    %eax, %eax
59         mov     %cs, %ax
60         mov     %ax, %ds
61         mov     %ax, %es
62         shll    $4, %eax
63
64         /* fix up GDT entries for bootstrap */
65 #define FIXUP(gdt_index) \
66         .code32; \
67         addr32; \
68         movl    %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \
69         addr32; \
70         movb    %bl, EXT(Gdt)+(8*gdt_index)+4; \
71         .code16
72
73         shld    $16, %eax, %ebx
74         FIXUP(BOOT_CS_INDEX)
75         FIXUP(BOOT_CS16_INDEX)
76         FIXUP(BOOT_DS_INDEX)
77
78         /* fix up GDT pointer */
79         movl    %eax, %ecx
80         addl    $ EXT(Gdt), %eax
81         .code32
82         addr32
83         data32
84         movl    %eax, EXT(Gdtr)+2
85         .code16
86
87 #ifdef BDE_DEBUGGER
88         /* fix up GDT entry for GDT */
89         data32
90         shld    $16, %eax, %ebx
91         FIXUP(GDT_INDEX)
92
93         /* fix up IDT pointer */
94         data32
95         addl    $ EXT(Idt), %ecx
96         addr32
97         data32
98         movl    %ecx, EXT(Idtr_prot)+2
99
100         /* %es = vector table segment for a while */
101         push    %es
102         data32
103         subl    %eax, %eax
104         mov     %ax, %es
105
106         /* fix up GDT entries for bdb */
107         data32
108         movl    $4*DEBUG_VECTOR, %esi
109         addr32
110         movl    %es: 2(%esi), %eax      /* actually movw to %ax */
111         data32
112         shll    $4, %eax
113         data32
114         shld    $16, %eax, %ebx
115         FIXUP(DB_CS_INDEX)
116         FIXUP(DB_CS16_INDEX)
117         FIXUP(DB_DS_INDEX)
118
119         /* Fetch entry points of bdb's protected mode trap handlers.  These
120          * are stored at 2 before the corresponding entry points for real mode.
121          */
122         data32
123         subl    %ebx, %ebx
124         addr32
125         movl    %es: (%esi), %ebx       /* actually movw to %bx */
126         data32
127         subl    %ecx, %ecx
128         addr32
129         movl    %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx
130                                         /* actually movw to %cx */
131
132         /* %es = bdb segment for a while */
133         data32
134         shrl    $4, %eax
135         mov     %ax, %es
136
137         /* fix up IDT entries for bdb */
138         data32
139         subl    $2, %ebx                /* calculate EA to check it */
140         jb      1f                      /* give up if it would trap */
141         addr32
142         movl    %es: (%ebx), %eax       /* actually movw to %ax */
143         addr32
144         movl    %eax, EXT(Idt)+8*DEBUG_VECTOR   /* actually movw %ax */
145 1:
146         data32
147         subl    $2, %ecx
148         jb      1f
149         addr32
150         movl    %es: (%ecx), %eax       /* actually movw to %ax */
151         addr32
152         movl    %eax, EXT(Idt)+8*BREAKPOINT_VECTOR      /* actually movw %ax */
153 1:
154
155         /* finished with groping in real mode segments */
156         pop     %es
157 #endif /* BDE_DEBUGGER */
158
159         /* change to protected mode */
160         .code32
161         data32
162         call    EXT(real_to_prot)
163
164         /* clear the bss */
165         movl    $ EXT(edata), %edi      /* no EXT(_edata) - krufty ld */
166         movl    $ EXT(end), %ecx        /* or EXT(_end) */
167         subl    %edi, %ecx
168         subb    %al, %al
169         rep
170         stosb
171
172 #ifdef NAMEBLOCK
173         movl    %esp, EXT(dflt_name)
174 #endif
175
176         movb    0xA1584 - BOOTSEG * 0x10, %dl
177         movzbl  %dl, %edx       /* discard head (%dh) and random high bits */
178         pushl   %edx
179         call    EXT(boot)
180 oops:
181         hlt
182         jmp     oops