Commit | Line | Data |
---|---|---|
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:26 rpd |
27 | * $Id$ | |
a27f4645 RM |
28 | */ |
29 | ||
a27f4645 RM |
30 | /* |
31 | Copyright 1988, 1989, 1990, 1991, 1992 | |
32 | by Intel Corporation, Santa Clara, California. | |
33 | ||
34 | All Rights Reserved | |
35 | ||
36 | Permission to use, copy, modify, and distribute this software and | |
37 | its documentation for any purpose and without fee is hereby | |
38 | granted, provided that the above copyright notice appears in all | |
39 | copies and that both the copyright notice and this permission notice | |
40 | appear in supporting documentation, and that the name of Intel | |
41 | not be used in advertising or publicity pertaining to distribution | |
42 | of the software without specific, written prior permission. | |
43 | ||
44 | INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE | |
45 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, | |
46 | IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR | |
47 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
48 | LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, | |
49 | NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | |
50 | WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
51 | */ | |
52 | ||
53 | .file "bios.s" | |
54 | ||
55 | #include "asm.h" | |
56 | .text | |
57 | ||
58 | /* | |
59 | # biosread(dev, cyl, head, sec, nsec, offset) | |
60 | # Read "nsec" sectors from disk to offset "offset" in boot segment | |
61 | # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory | |
62 | # Call with %ah = 0x2 | |
63 | # %al = number of sectors | |
64 | # %ch = cylinder | |
65 | # %cl = sector | |
66 | # %dh = head | |
67 | # %dl = drive (0x80 for hard disk, 0x0 for floppy disk) | |
68 | # %es:%bx = segment:offset of buffer | |
69 | # Return: | |
70 | # %al = 0x0 on success; err code on failure | |
71 | */ | |
72 | ||
73 | ENTRY(biosread) | |
74 | push %ebp | |
75 | mov %esp, %ebp | |
76 | ||
77 | push %ebx | |
78 | push %ecx | |
79 | push %edx | |
80 | push %es | |
81 | ||
82 | movb 0x10(%ebp), %dh | |
83 | movw 0x0c(%ebp), %cx | |
84 | xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl | |
85 | rorb $2, %cl | |
86 | movb 0x14(%ebp), %al | |
87 | orb %al, %cl | |
88 | incb %cl # sector; sec starts from 1, not 0 | |
89 | movb 0x8(%ebp), %dl # device | |
90 | movl 0x1c(%ebp), %ebx # offset | |
91 | # prot_to_real will set %es to BOOTSEG | |
92 | ||
93 | call EXT(prot_to_real) # enter real mode | |
94 | movb $0x2, %ah # subfunction | |
95 | addr32 | |
96 | movb 0x18(%ebp), %al # number of sectors | |
97 | ||
98 | sti | |
99 | int $0x13 | |
100 | cli | |
101 | ||
102 | mov %eax, %ebx # save return value (actually movw %ax, %bx) | |
103 | ||
104 | data32 | |
105 | call EXT(real_to_prot) # back to protected mode | |
106 | ||
107 | xor %eax, %eax | |
108 | movb %bh, %al # return value in %ax | |
109 | ||
110 | pop %es | |
111 | pop %edx | |
112 | pop %ecx | |
113 | pop %ebx | |
114 | pop %ebp | |
115 | ||
116 | ret | |
117 | ||
118 | ||
119 | /* | |
120 | # putc(ch) | |
121 | # BIOS call "INT 10H Function 0Eh" to write character to console | |
122 | # Call with %ah = 0x0e | |
123 | # %al = character | |
124 | # %bh = page | |
125 | # %bl = foreground color ( graphics modes) | |
126 | */ | |
127 | ||
128 | ||
129 | ENTRY(putc) | |
130 | push %ebp | |
131 | mov %esp, %ebp | |
132 | push %ebx | |
133 | push %ecx | |
134 | ||
135 | movb 0x8(%ebp), %cl | |
136 | ||
137 | call EXT(prot_to_real) | |
138 | ||
139 | data32 | |
140 | mov $0x1, %ebx # %bh=0, %bl=1 (blue) | |
141 | movb $0xe, %ah | |
142 | movb %cl, %al | |
143 | sti | |
144 | int $0x10 # display a byte | |
145 | cli | |
146 | ||
147 | data32 | |
148 | call EXT(real_to_prot) | |
149 | ||
150 | pop %ecx | |
151 | pop %ebx | |
152 | pop %ebp | |
153 | ret | |
154 | ||
155 | ||
156 | /* | |
157 | # getc() | |
158 | # BIOS call "INT 16H Function 00H" to read character from keyboard | |
159 | # Call with %ah = 0x0 | |
160 | # Return: %ah = keyboard scan code | |
161 | # %al = ASCII character | |
162 | */ | |
163 | ||
164 | ENTRY(getc) | |
165 | push %ebp | |
166 | mov %esp, %ebp | |
167 | push %ebx # save %ebx | |
168 | ||
169 | call EXT(prot_to_real) | |
170 | ||
171 | movb $0x0, %ah | |
172 | sti | |
173 | int $0x16 | |
174 | cli | |
175 | ||
176 | movb %al, %bl # real_to_prot uses %eax | |
177 | ||
178 | data32 | |
179 | call EXT(real_to_prot) | |
180 | ||
181 | xor %eax, %eax | |
182 | movb %bl, %al | |
183 | ||
184 | pop %ebx | |
185 | pop %ebp | |
186 | ret | |
187 | /* | |
188 | # ischar() | |
189 | # if there is a character pending, return it; otherwise return 0 | |
190 | # BIOS call "INT 16H Function 01H" to check whether a character is pending | |
191 | # Call with %ah = 0x1 | |
192 | # Return: | |
193 | # If key waiting to be input: | |
194 | # %ah = keyboard scan code | |
195 | # %al = ASCII character | |
196 | # Zero flag = clear | |
197 | # else | |
198 | # Zero flag = set | |
199 | */ | |
200 | ENTRY(ischar) | |
201 | push %ebp | |
202 | mov %esp, %ebp | |
203 | push %ebx | |
204 | ||
205 | call EXT(prot_to_real) # enter real mode | |
206 | ||
207 | xor %ebx, %ebx | |
208 | movb $0x1, %ah | |
209 | sti | |
210 | int $0x16 | |
211 | cli | |
212 | data32 | |
213 | jz nochar | |
214 | movb %al, %bl | |
215 | ||
216 | nochar: | |
217 | data32 | |
218 | call EXT(real_to_prot) | |
219 | ||
220 | xor %eax, %eax | |
221 | movb %bl, %al | |
222 | ||
223 | pop %ebx | |
224 | pop %ebp | |
225 | ret | |
226 | ||
227 | /* | |
228 | # | |
229 | # get_diskinfo(): return a word that represents the | |
230 | # max number of sectors and heads and drives for this device | |
231 | # | |
232 | */ | |
233 | ||
234 | ENTRY(get_diskinfo) | |
235 | push %ebp | |
236 | mov %esp, %ebp | |
237 | push %es | |
238 | push %ebx | |
239 | push %ecx | |
240 | push %edx | |
241 | ||
242 | movb 0x8(%ebp), %dl # diskinfo(drive #) | |
243 | call EXT(prot_to_real) # enter real mode | |
244 | ||
245 | movb $0x8, %ah # ask for disk info | |
246 | ||
247 | sti | |
248 | int $0x13 | |
249 | cli | |
250 | ||
251 | jnc ok | |
252 | /* | |
253 | * Urk. Call failed. It is not supported for floppies by old BIOS's. | |
254 | * Guess it's a 15-sector floppy. Initialize all the registers for | |
255 | * documentation, although we only need head and sector counts. | |
256 | */ | |
257 | subb %ah, %ah # %ax = 0 | |
258 | movb %al, %al | |
259 | movb %ah, %bh # %bh = 0 | |
260 | movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M | |
261 | movb $79, %ch # max track | |
262 | movb $15, %cl # max sector | |
263 | movb $1, %dh # max head | |
264 | movb $1, %dl # # floppy drives installed | |
265 | # es:di = parameter table | |
266 | # carry = 0 | |
267 | ok: | |
268 | ||
269 | data32 | |
270 | call EXT(real_to_prot) # back to protected mode | |
271 | ||
272 | xor %eax, %eax | |
273 | ||
274 | /*form a longword representing all this gunk*/ | |
275 | movb %dh, %ah # max head | |
276 | andb $0x3f, %cl # mask of cylinder gunk | |
277 | movb %cl, %al # max sector (and # sectors) | |
278 | ||
279 | pop %edx | |
280 | pop %ecx | |
281 | pop %ebx | |
282 | pop %es | |
283 | pop %ebp | |
284 | ret | |
285 | ||
286 | /* | |
287 | # | |
288 | # memsize(i) : return the memory size in KB. i == 0 for conventional memory, | |
289 | # i == 1 for extended memory | |
290 | # BIOS call "INT 12H" to get conventional memory size | |
291 | # BIOS call "INT 15H, AH=88H" to get extended memory size | |
292 | # Both have the return value in AX. | |
293 | # | |
294 | */ | |
295 | ||
296 | ENTRY(memsize) | |
297 | push %ebp | |
298 | mov %esp, %ebp | |
299 | push %ebx | |
300 | ||
301 | mov 8(%ebp), %ebx | |
302 | ||
303 | call EXT(prot_to_real) # enter real mode | |
304 | ||
305 | cmpb $0x1, %bl | |
306 | data32 | |
307 | je xext | |
308 | ||
309 | sti | |
310 | int $0x12 | |
311 | cli | |
312 | data32 | |
313 | jmp xdone | |
314 | ||
315 | xext: movb $0x88, %ah | |
316 | sti | |
317 | int $0x15 | |
318 | cli | |
319 | ||
320 | xdone: | |
321 | mov %eax, %ebx | |
322 | ||
323 | data32 | |
324 | call EXT(real_to_prot) | |
325 | ||
326 | mov %ebx, %eax | |
327 | pop %ebx | |
328 | pop %ebp | |
329 | ret |