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