This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / sys / i386 / boot / asm.S
CommitLineData
a27f4645 1/*
a27f4645
RM
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.
a27f4645 25 *
e4270b63
RG
26 * from: Mach, Revision 2.2 92/04/04 11:34:13 rpd
27 * $Id$
a27f4645
RM
28 */
29
e4270b63 30
a27f4645
RM
31/*
32 Copyright 1988, 1989, 1990, 1991, 1992
33 by Intel Corporation, Santa Clara, California.
34
35 All Rights Reserved
36
37Permission to use, copy, modify, and distribute this software and
38its documentation for any purpose and without fee is hereby
39granted, provided that the above copyright notice appears in all
40copies and that both the copyright notice and this permission notice
41appear in supporting documentation, and that the name of Intel
42not be used in advertising or publicity pertaining to distribution
43of the software without specific, written prior permission.
44
45INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52*/
53
54 .file "asm.s"
55
56#include "asm.h"
57
58
59CR0_PE_ON = 0x1
60CR0_PE_OFF = 0xfffffffe
61
62.globl _ouraddr
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 addr32
77 data32
78 lgdt EXT(Gdtr)
79
80 # set the PE bit of CR0
81 mov %cr0, %eax
82
83 data32
84 or $CR0_PE_ON, %eax
85 mov %eax, %cr0
86
87 # make intrasegment jump to flush the processor pipeline and
88 # reload CS register
89 data32
90 ljmp $0x18, $xprot
91
92xprot:
93 # we are in USE32 mode now
94 # set up the protected mode segment registers : DS, SS, ES
95 mov $0x20, %eax
96 movw %ax, %ds
97 movw %ax, %ss
98 movw %ax, %es
99
100 # load idtr so we can debug
101 lidt EXT(Idtr_prot)
102
103 ret
104
105/*
106#
107# prot_to_real()
108# transfer from protected mode to real mode
109#
110*/
111
112ENTRY(prot_to_real)
113
114 # set up a dummy stack frame for the second seg change.
115 movl _ouraddr, %eax
116 sarl $4, %eax
117 pushw %ax
118 movw $xreal, %ax # gas botches pushw $xreal - extra bytes 0, 0
119 pushw %ax # decode to add %al, (%eax) (%al usually 0)
120
121 # Change to use16 mode.
122 ljmp $0x28, $x16
123
124x16:
125 # clear the PE bit of CR0
126 mov %cr0, %eax
127 data32
128 and $CR0_PE_OFF, %eax
129 mov %eax, %cr0
130
131 # make intersegment jmp to flush the processor pipeline
132 # using the fake stack frame set up earlier
133 # and reload CS register
134 lret
135
136xreal:
137 # we are in real mode now
138 # set up the real mode segment registers : DS, SS, ES
139 movw %cs, %ax
140 movw %ax, %ds
141 movw %ax, %ss
142 movw %ax, %es
143
144 # load idtr so we can debug
145 addr32
146 data32
147 lidt EXT(Idtr_real)
148
149 data32
150 ret
151
152/*
153#
154# startprog(phyaddr)
155# start the program on protected mode where phyaddr is the entry point
156#
157*/
158
159ENTRY(startprog)
160 push %ebp
161 mov %esp, %ebp
162
163 # get things we need into registers
164 movl 0x8(%ebp), %ecx # entry offset
165 movl 0x0c(%ebp), %eax # &argv
166
167 # make a new stack at 0:0xa0000 (big segs)
168 mov $0x10, %ebx
169 movw %bx, %ss
170 movl $0xa0000, %ebx
171 movl %ebx, %esp
172
173 # push some number of args onto the stack
174 pushl $0 # nominally a cyl offset in the boot.
175 pushl 0x8(%eax) # argv[2] = bootdev
176 pushl 0x4(%eax) # argv[1] = howto
177 pushl $0 # dummy 'return' address
178
179 # push on our entry address
180 mov $0x08, %ebx # segment
181 pushl %ebx
182 pushl %ecx
183
184 # convert over the other data segs
185 mov $0x10, %ebx
186 movw %bx, %ds
187 movw %bx, %es
188
189 # convert the PC (and code seg)
190 lret
191/*
192#
193# pbzero( dst, cnt)
194# where src is a virtual address and dst is a physical address
195*/
196
197ENTRY(pbzero)
198 push %ebp
199 mov %esp, %ebp
200 push %es
201 push %esi
202 push %edi
203 push %ecx
204
205 cld
206
207 # set %es to point at the flat segment
208 mov $0x10, %eax
209 movw %ax, %es
210
211 mov 0x8(%ebp), %edi # destination
212 mov 0xc(%ebp), %ecx # count
213 mov $0x0, %eax # value
214
215 rep
216 stosb
217
218 pop %ecx
219 pop %edi
220 pop %esi
221 pop %es
222 pop %ebp
223
224 ret
225/*
226#
227# pcpy(src, dst, cnt)
228# where src is a virtual address and dst is a physical address
229#
230*/
231
232ENTRY(pcpy)
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 mov $0x10, %eax
244 movw %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
260