|
|
1.1 root 1: /*
2: * Ported to boot 386BSD by Julian Elischer ([email protected]) Sept 1992
3: *
4: * Mach Operating System
5: * Copyright (c) 1992, 1991 Carnegie Mellon University
6: * All Rights Reserved.
7: *
8: * Permission to use, copy, modify and distribute this software and its
9: * documentation is hereby granted, provided that both the copyright
10: * notice and this permission notice appear in all copies of the
11: * software, derivative works or modified versions, and any portions
12: * thereof, and that both notices appear in supporting documentation.
13: *
14: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17: *
18: * Carnegie Mellon requests users of this software to return to
19: *
20: * Software Distribution Coordinator or [email protected]
21: * School of Computer Science
22: * Carnegie Mellon University
23: * Pittsburgh PA 15213-3890
24: *
25: * any improvements or extensions that they make and grant Carnegie Mellon
26: * the rights to redistribute these changes.
27: */
28:
29: /*
30: * HISTORY
31: * $Log: asm.S,v $
32: * Revision 1.1 1993/03/21 18:08:21 cgd
33: * after 0.2.2 "stable" patches applied
34: *
35: * Revision 2.2 92/04/04 11:34:13 rpd
36: * Fix Intel Copyright as per B. Davies authorization.
37: * [92/04/03 rvb]
38: * From 2.5 boot: pruned inb(), outb(), and pzero().
39: * [92/03/30 rvb]
40: *
41: * Revision 2.2 91/04/02 14:35:10 mbj
42: * Added _sp() => where is the stack at. [kupfer]
43: * Add Intel copyright
44: * [90/02/09 rvb]
45: *
46: */
47:
48: /*
49: Copyright 1988, 1989, 1990, 1991, 1992
50: by Intel Corporation, Santa Clara, California.
51:
52: All Rights Reserved
53:
54: Permission to use, copy, modify, and distribute this software and
55: its documentation for any purpose and without fee is hereby
56: granted, provided that the above copyright notice appears in all
57: copies and that both the copyright notice and this permission notice
58: appear in supporting documentation, and that the name of Intel
59: not be used in advertising or publicity pertaining to distribution
60: of the software without specific, written prior permission.
61:
62: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
63: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
64: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
65: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
66: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
67: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
68: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
69: */
70:
71: .file "asm.s"
72:
73: #include "asm.h"
74:
75:
76: CR0_PE_ON = 0x1
77: CR0_PE_OFF = 0xfffffffe
78:
79: .globl _ouraddr
80: .text
81:
82: /*
83: #
84: # real_to_prot()
85: # transfer from real mode to protected mode.
86: */
87:
88: ENTRY(real_to_prot)
89: # guarantee that interrupt is disabled when in prot mode
90: cli
91:
92: # load the gdtr
93: addr16
94: data32
95: lgdt EXT(Gdtr)
96:
97: # set the PE bit of CR0
98: mov %cr0, %eax
99:
100: data32
101: or $CR0_PE_ON, %eax
102: mov %eax, %cr0
103:
104: # make intrasegment jump to flush the processor pipeline and
105: # reload CS register
106: data32
107: ljmp $0x18, $xprot
108:
109: xprot:
110: # we are in USE32 mode now
111: # set up the protective mode segment registers : DS, SS, ES
112: mov $0x20, %eax
113: movw %ax, %ds
114: movw %ax, %ss
115: movw %ax, %es
116:
117: ret
118:
119: /*
120: #
121: # prot_to_real()
122: # transfer from protected mode to real mode
123: #
124: */
125:
126: ENTRY(prot_to_real)
127:
128: # set up a dummy stack frame for the second seg change.
129: movl _ouraddr, %eax
130: sarl $4, %eax
131: pushw %ax
132: pushw $xreal
133:
134: # Change to use16 mode.
135: ljmp $0x28, $x16
136:
137: x16:
138: # clear the PE bit of CR0
139: mov %cr0, %eax
140: data32
141: and $CR0_PE_OFF, %eax
142: mov %eax, %cr0
143:
144:
145: # make intersegment jmp to flush the processor pipeline
146: # using the fake stack frame set up earlier
147: # and reload CS register
148: lret
149:
150:
151: xreal:
152: # we are in real mode now
153: # set up the real mode segment registers : DS, SS, ES
154: movw %cs, %ax
155: movw %ax, %ds
156: movw %ax, %ss
157: movw %ax, %es
158:
159: data32
160: ret
161:
162: /*
163: #
164: # startprog(phyaddr)
165: # start the program on protected mode where phyaddr is the entry point
166: #
167: */
168:
169: ENTRY(startprog)
170: push %ebp
171: mov %esp, %ebp
172:
173:
174:
175: # get things we need into registers
176: movl 0x8(%ebp), %ecx # entry offset
177: movl 0x0c(%ebp), %eax # &argv
178:
179: # make a new stack at 0:0xa0000 (big segs)
180: mov $0x10, %ebx
181: movw %bx, %ss
182: movl $0xa0000,%ebx
183: movl %ebx,%esp
184:
185:
186: # push some number of args onto the stack
187: pushl $0 # nominally a cyl offset in the boot.
188: pushl 0x8(%eax) # argv[2] = bootdev
189: pushl 0x4(%eax) # argv[1] = howto
190: pushl $0 # dummy 'return' address
191:
192: # push on our entry address
193: mov $0x08, %ebx # segment
194: pushl %ebx
195: pushl %ecx
196:
197: # convert over the other data segs
198: mov $0x10, %ebx
199: movw %bx, %ds
200: movw %bx, %es
201:
202: # convert the PC (and code seg)
203: lret
204: /*
205: #
206: # pbzero( dst, cnt)
207: # where src is a virtual address and dst is a physical address
208: */
209:
210: ENTRY(pbzero)
211: push %ebp
212: mov %esp, %ebp
213: push %es
214: push %esi
215: push %edi
216: push %ecx
217:
218: cld
219:
220: # set %es to point at the flat segment
221: mov $0x10, %eax
222: movw %ax, %es
223:
224: mov 0x8(%ebp), %edi # destination
225: mov 0xc(%ebp), %ecx # count
226: mov $0x0,%eax # value
227:
228: rep
229: stosb
230:
231: pop %ecx
232: pop %edi
233: pop %esi
234: pop %es
235: pop %ebp
236:
237: ret
238: /*
239: #
240: # pcpy(src, dst, cnt)
241: # where src is a virtual address and dst is a physical address
242: #
243: */
244:
245: ENTRY(pcpy)
246: push %ebp
247: mov %esp, %ebp
248: push %es
249: push %esi
250: push %edi
251: push %ecx
252:
253: cld
254:
255: # set %es to point at the flat segment
256: mov $0x10, %eax
257: movw %ax, %es
258:
259: mov 0x8(%ebp), %esi # source
260: mov 0xc(%ebp), %edi # destination
261: mov 0x10(%ebp), %ecx # count
262:
263: rep
264: movsb
265:
266: pop %ecx
267: pop %edi
268: pop %esi
269: pop %es
270: pop %ebp
271:
272: ret
273:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.