]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/boot/pc98/boot2/asm.S
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / boot / pc98 / boot2 / asm.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:34:13  rpd
27  * $FreeBSD$
28  */
29
30
31 /*
32   Copyright 1988, 1989, 1990, 1991, 1992 
33    by Intel Corporation, Santa Clara, California.
34
35                 All Rights Reserved
36
37 Permission to use, copy, modify, and distribute this software and
38 its documentation for any purpose and without fee is hereby
39 granted, provided that the above copyright notice appears in all
40 copies and that both the copyright notice and this permission notice
41 appear in supporting documentation, and that the name of Intel
42 not be used in advertising or publicity pertaining to distribution
43 of the software without specific, written prior permission.
44
45 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 */
53
54         .file "asm.s"
55
56 #include "asm.h"
57
58
59 CR0_PE_ON       =       0x1
60 CR0_PE_OFF      =       0xfffffffe
61         .code16
62         .text
63
64 /*
65  *
66  * real_to_prot()
67  *      transfer from real mode to protected mode.
68  */
69
70 ENTRY(real_to_prot)
71         /* guarantee that interrupt is disabled when in prot mode */
72         cli
73
74         /* load the gdtr */
75         .code32
76         addr32
77         data32
78         lgdt    EXT(Gdtr)
79         .code16
80
81         /* set the PE bit of CR0 */
82         mov     %cr0, %eax
83
84         or      $CR0_PE_ON, %eax
85         mov     %eax, %cr0 
86
87         /*
88          * make intrasegment jump to flush the processor pipeline and
89          * reload CS register
90          */
91         .code32
92         data32
93         ljmp    $0x18, $xprot
94         .code16
95 xprot:
96
97         /*
98          * we are in USE32 mode now
99          * set up the protected mode segment registers : DS, SS, ES, FS
100          */
101         data32
102         movw    $0x20, %ax      /* data segment */
103         mov     %ax, %ds        /* gas would waste a prefix byte for movw */
104         mov     %ax, %ss
105         mov     %ax, %es
106         data32
107         movw    $0x10, %ax      /* flat segment */
108         mov     %ax, %fs
109
110 #ifdef BDE_DEBUGGER
111         /* load idtr so we can debug */
112         lidt    EXT(Idtr_prot)
113 #endif
114
115         ret
116
117 /*
118  *
119  * prot_to_real()
120  *      transfer from protected mode to real mode
121  * 
122  */
123
124 ENTRY(prot_to_real)
125
126         /* Prepare %ax while we're still in a mode that gas understands. */
127         data32
128         movw    $0x30, %ax
129
130         /* Change to use16 mode. */
131         .code32
132         ljmp    $0x28, $x16
133         .code16
134 x16:
135
136         mov     %ax, %ds
137         mov     %ax, %ss
138         mov     %ax, %es
139         mov     %ax, %fs
140
141         /* clear the PE bit of CR0 */
142         mov     %cr0, %eax
143         and     $CR0_PE_OFF, %eax
144         mov     %eax, %cr0
145
146         /*
147          * make intersegment jmp to flush the processor pipeline
148          * and reload CS register
149          */
150         .code32
151         data32
152         ljmp    $BOOTSEG, $xreal
153         .code16
154 xreal:
155
156         /*
157          * we are in real mode now
158          * set up the real mode segment registers : DS, SS, ES, FS
159          */
160         mov     %cs, %ax
161         mov     %ax, %ds
162         mov     %ax, %ss
163         mov     %ax, %es
164         mov     %ax, %fs
165
166 #ifdef BDE_DEBUGGER
167         /* load idtr so we can debug */
168         addr32
169         data32
170         lidt    EXT(Idtr_real)
171 #endif
172
173         data32
174         ret
175
176 /*
177  * startprog(phyaddr)
178  *      start the program on protected mode where phyaddr is the entry point
179  *
180  * XXX This whole mess should go away and we should run the boot code in
181  * flat 32 bit mode with it linked -T BOOTSEG.  See the netboot code for
182  * how this is done.
183  */
184
185 ENTRY(startprog)
186         .code32
187         push    %ebp
188         mov     %esp, %ebp
189         movl    %esp, %eax              /* Use eax as the old stack pointer */
190
191         /* convert the current stack to a 32 bit flat model */
192         movw    $0x10, %bx
193         data32
194         mov     %bx, %ss
195         addl    $(BOOTSEG<<4),%esp
196         
197         /* copy the arguments from the old stack to the new stack */
198         pushl   0x14(%eax)              /* &bootinfo */
199         pushl   $0                      /* was &nfsdiskless */
200         pushl   $0                      /* was esym */
201         pushl   $0                      /* was cyloffset */
202         pushl   0x10(%eax)              /* bootdev */
203         pushl   0x0C(%eax)              /* howto */
204         movl    $(ourreturn),%ebx
205         addl    $(BOOTSEG<<4),%ebx      /* Fix it up for flat segments */
206         pushl   %ebx                    /* our return address */
207         
208         /* push on our entry address */
209         pushl   $0x08                   /* segment selector */
210         pushl   0x08(%eax)              /* kernel entry address */
211
212         /* convert over the other data segs */
213         movw    $0x10, %bx
214         data32
215         mov     %bx, %ds
216         data32
217         mov     %bx, %es
218
219         /* convert the PC (and code seg) */
220         lret
221 ourreturn:
222         /* For now there is not much we can do, just lock in a loop */
223         jmp     ourreturn
224
225 /*
226  * pcpy(src, dst, cnt)
227  *      where src is a virtual address and dst is a physical address
228  */
229
230 ENTRY(pcpy)
231         .code32
232         push    %ebp
233         mov     %esp, %ebp
234         push    %es
235         push    %esi
236         push    %edi
237         push    %ecx
238
239         cld
240
241         /* set %es to point at the flat segment */
242         movw    $0x10, %ax
243         mov     %ax, %es
244
245         mov     0x8(%ebp), %esi         /* source */
246         mov     0xc(%ebp), %edi         /* destination */
247         mov     0x10(%ebp), %ecx        /* count */
248
249         rep
250         movsb
251
252         pop     %ecx
253         pop     %edi
254         pop     %esi
255         pop     %es
256         pop     %ebp
257
258         ret