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