]> git.saurik.com Git - apple/boot.git/blame - i386/libsaio/old/bios_old.s
boot-83.2.tar.gz
[apple/boot.git] / i386 / libsaio / old / bios_old.s
CommitLineData
14c7c974
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Mach Operating System
26 * Copyright (c) 1990 Carnegie-Mellon University
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * All rights reserved. The CMU software License Agreement specifies
29 * the terms and conditions for use and redistribution.
30 */
31
32// INTEL CORPORATION PROPRIETARY INFORMATION
33//
34// This software is supplied under the terms of a license agreement or
35// nondisclosure agreement with Intel Corporation and may not be copied
36// nor disclosed except in accordance with the terms of that agreement.
37//
38// Copyright 1988 Intel Corporation
39// Copyright 1988, 1989 by Intel Corporation
40//
41
42 .file "bios.s"
43
44#include <machdep/i386/asm.h>
45#include "memory.h"
46
47 .text
48
49#if 0
50// biosread(dev, cyl, head, sec, num)
51// Read num sectors from disk into the internal buffer "intbuf" which
52// is the first 4K bytes of the boot loader.
53// BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
54// Call with %ah = 0x2
55// %al = number of sectors
56// %ch = cylinder
57// %cl = sector
58// %dh = head
59// %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
60// %es:%bx = segment:offset of buffer
61// Return:
62// %al = 0x0 on success; err code on failure
63
64ENTRY(_biosread)
65 push %ebp
66 mov %esp, %ebp
67
68 push %ebx
69 push %ecx
70 push %edx
71 push %esi
72 push %edi
73 push %ds
74 push %es
75// push %fs
76// push %gs
77
78 movb 0x10(%ebp), %dh // head
79
80 movw 0x0c(%ebp), %cx
81 xchgb %ch, %cl // cylinder; %cl=the high 2 bits of cyl
82 rorb $2, %cl
83 movb 0x14(%ebp), %al
84 orb %al, %cl
85 incb %cl // sector; sec starts from 1, not 0
86
87 movb 0x8(%ebp), %dl // device
88 movb 0x18(%ebp),%bl // number of sectors
89 movb $2,%bh // bios read function
90
91 call EXT(_prot_to_real) // enter real mode, set %es to BOOTSEG
92
93 data16
94 mov $5,%edi // retry up to 5 times
95
96retry_disc:
97 mov %ebx,%eax // get function and amount
98// xor %ebx, %ebx // offset = 0
99 data16
100 mov $(ptov(BIOS_ADDR)), %ebx
101
102 push %eax // save amount
103 push %ecx
104 push %edx
105 push %edi
106 int $0x13
107 pop %edi
108 pop %edx
109 pop %ecx
110 pop %ebx // pop amount into bx (safe place)
111
112// test $0, %ah
113 data16
114 jnb read_succes
115
116 // woops, bios failed to read sector
117 push %eax // save error
118 xor %eax,%eax
119 int $0x13 // reset disk
120 pop %eax // restore error code
121 dec %edi
122 data16
123 jne retry_disc
124
125read_succes:
126 mov %eax, %ebx // save return value
127
128 data16
129 call EXT(_real_to_prot) // back to protected mode
130
131 xor %ax, %ax
132 movb %bh, %al // return value in %ax
133
134// pop %gs
135// pop %fs
136 pop %es
137 pop %ds
138 pop %edi
139 pop %esi
140 pop %edx
141 pop %ecx
142 pop %ebx
143
144 pop %ebp
145
146 ret
147
148// putc(ch)
149// BIOS call "INT 10H Function 0Eh" to write character to console
150// Call with %ah = 0x0e
151// %al = character
152// %bh = page
153// %bl = foreground color ( graphics modes)
154
155
156ENTRY(_putc)
157 push %ebp
158 mov %esp, %ebp
159
160 push %ebx
161 push %ecx
162 push %edx
163 push %esi
164 push %edi
165 push %ds
166 push %es
167
168 movb 0x8(%ebp), %cl
169
170 call EXT(_prot_to_real)
171
172// data16
173// mov $0x13, %ebx // colors in 2 bit palette, grey and white
174// mov $0x1, %ebx // %bh=0, %bl=1 (blue)
175//
176// movb $1,%bh // background gray
177 movb $0,%bh // background gray
178 movb $3,%bl // foreground white in 2 bit palette
179
180 movb $0xe, %ah
181 movb %cl, %al
182
183 int $0x10 // display a byte
184
185 data16
186 call EXT(_real_to_prot)
187
188 pop %es
189 pop %ds
190 pop %edi
191 pop %esi
192 pop %edx
193 pop %ecx
194 pop %ebx
195
196 pop %ebp
197 ret
198
199ENTRY(cputc)
200 push %ebp
201 mov %esp, %ebp
202
203 push %ebx
204 push %ecx
205 push %edx
206 push %esi
207 push %edi
208 push %ds
209 push %es
210
211 movb 0x8(%ebp), %cl
212 movb 0x12(%ebp), %bl
213
214 call EXT(_prot_to_real)
215
216 movb $0,%bh // page 0
217
218 movb %cl, %al
219 movb $0x9, %ah
220 movb $1, %cx
221
222 int $0x10 // display a byte
223
224 data16
225 call EXT(_real_to_prot)
226
227 pop %es
228 pop %ds
229 pop %edi
230 pop %esi
231 pop %edx
232 pop %ecx
233 pop %ebx
234
235 pop %ebp
236 ret
237
238// bgetc()
239// BIOS call "INT 16H Function 00H" to read character from keyboard
240// Call with %ah = 0x0
241// Return: %ah = keyboard scan code
242// %al = ASCII character
243
244ENTRY(bgetc)
245 push %ebp
246 mov %esp, %ebp
247
248 push %ebx
249 push %ecx
250 push %edx
251 push %esi
252 push %edi
253 push %ds
254 push %es
255
256 call EXT(_prot_to_real)
257
258 movb $0, %ah
259
260 int $0x16
261
262 mov %eax, %ebx // _real_to_prot uses %eax
263
264 data16
265 call EXT(_real_to_prot)
266
267 xor %eax, %eax
268 mov %bx, %ax
269
270 pop %es
271 pop %ds
272 pop %edi
273 pop %esi
274 pop %edx
275 pop %ecx
276 pop %ebx
277
278 pop %ebp
279 ret
280
281// readKeyboardStatus()
282// if there is a character pending, return it; otherwise return 0
283// BIOS call "INT 16H Function 01H" to check whether a character is pending
284// Call with %ah = 0x1
285// Return:
286// If key waiting to be input:
287// %ah = keyboard scan code
288// %al = ASCII character
289// Zero flag = clear
290// else
291// Zero flag = set
292
293ENTRY(_readKeyboardStatus)
294 push %ebp
295 mov %esp, %ebp
296
297 push %ebx
298 push %ecx
299 push %edx
300 push %esi
301 push %edi
302 push %ds
303 push %es
304
305 call EXT(_prot_to_real) // enter real mode
306
307 xor %ebx, %ebx
308 movb $0x1, %ah
309 int $0x16
310
311 data16
312 jz nochar
313
314 movw %ax, %bx
315
316nochar:
317 data16
318 call EXT(_real_to_prot)
319
320 xor %eax, %eax
321 movw %bx, %ax
322
323 pop %es
324 pop %ds
325 pop %edi
326 pop %esi
327 pop %edx
328 pop %ecx
329 pop %ebx
330
331 pop %ebp
332 ret
333
334
335// time in 18ths of a second
336ENTRY(_time18)
337 push %ebp
338 mov %esp, %ebp
339
340 push %ebx
341 push %ecx
342 push %edx
343 push %esi
344 push %edi
345 push %ds
346 push %es
347
348 call EXT(_prot_to_real) // enter real mode
349
350 xor %bx, %bx
351 xor %eax, %eax
352 int $0x1a
353
354 mov %edx,%ebx
355 shl $16,%cx // shifts ecx
356 or %cx,%bx // %ebx has 32 bit time
357
358 data16
359 call EXT(_real_to_prot)
360
361 mov %ebx,%eax
362
363 pop %es
364 pop %ds
365 pop %edi
366 pop %esi
367 pop %edx
368 pop %ecx
369 pop %ebx
370
371 pop %ebp
372 ret
373
374//
375// get_diskinfo(): return a word that represents the
376// max number of sectors and heads and drives for this device
377//
378
379ENTRY(_get_diskinfo)
380 push %ebp
381 mov %esp, %ebp
382
383 push %ebx
384 push %ecx
385 push %edx
386 push %esi
387 push %edi
388 push %ds
389 push %es
390
391 movb 0x8(%ebp), %dl // diskinfo(drive #)
392 call EXT(_prot_to_real) // enter real mode
393
394 movb $0x8, %ah // ask for disk info
395 int $0x13
396
397 data16
398 call EXT(_real_to_prot) // back to protected mode
399
400// form a longword representing all this gunk
401 mov %ecx, %eax
402 shrb $6, %al
403 andb $0x03, %al
404 xchgb %ah, %al // ax has max cyl
405 shl $16, %eax
406
407 movb %dh, %ah // # heads
408 andb $0x3f, %cl // mask of cylinder gunk
409 movb %cl, %al // # sectors
410
411 pop %es
412 pop %ds
413 pop %edi
414 pop %esi
415 pop %edx
416 pop %ecx
417 pop %ebx
418
419 pop %ebp
420 ret
421#endif
422#if 0
423//
424// getEisaInfo(<slot>): return an int that represents the
425// vendor id for the specified slot (0 < slot < 64)
426// returns 0 for any error
427// returns bytes in the order [0 1 2 3] in %eax;
428
429ENTRY(getEisaInfo)
430 push %ebp
431 mov %esp, %ebp
432
433 push %ebx
434 push %ecx
435 push %edx
436 push %esi
437 push %edi
438 push %ds
439 push %es
440
441 movb 0x8(%ebp), %cl // slot #
442 call EXT(_prot_to_real) // enter real mode
443
444 movb $0,%al
445 movb $0xd8, %ah // eisa slot info
446 int $0x15
447
448 data16
449 call EXT(_real_to_prot) // back to protected mode
450
451 movb %ah,%bl
452 xor %eax,%eax
453
454 test $0,%bl
455 jne eisaerr
456
457// form a longword representing all this gunk
458 mov %esi, %eax
459 shl $16, %eax
460 mov %di,%ax
461 bswap %eax
462
463eisaerr:
464 pop %es
465 pop %ds
466 pop %edi
467 pop %esi
468 pop %edx
469 pop %ecx
470 pop %ebx
471
472 pop %ebp
473 ret
474#endif
475
476#if 0
477//
478// memsize(i) : return the memory size in KB. i == 0 for conventional memory,
479// i == 1 for extended memory
480// BIOS call "INT 12H" to get conventional memory size
481// BIOS call "INT 15H, AH=88H" to get extended memory size
482// Both have the return value in AX.
483//
484
485ENTRY(_memsize)
486 push %ebp
487 mov %esp, %ebp
488
489 push %ebx
490 push %ecx
491 push %edx
492 push %esi
493 push %edi
494 push %ds
495 push %es
496
497 mov 8(%ebp), %ebx
498 call EXT(_prot_to_real) // enter real mode
499 cmpb $0x1, %bl
500 data16
501 je xext
502 int $0x12
503 data16
504 jmp xdone
505xext:
506 movb $0x88, %ah
507 int $0x15
508xdone:
509 mov %eax, %ebx
510 data16
511 call EXT(_real_to_prot)
512 xor %eax, %eax
513 mov %ebx, %eax
514
515 pop %es
516 pop %ds
517 pop %edi
518 pop %esi
519 pop %edx
520 pop %ecx
521 pop %ebx
522
523 pop %ebp
524 ret
525
526
527// video_mode(mode)
528// BIOS call "INT 10H Function 0h" to set vga graphics mode
529
530
531ENTRY(_video_mode)
532 push %ebp
533 mov %esp, %ebp
534
535 push %ebx
536 push %ecx
537 push %edx
538 push %esi
539 push %edi
540 push %ds
541 push %es
542
543 movb 0x8(%ebp), %cl
544
545 call EXT(_prot_to_real)
546
547 movb $0, %ah
548 movb %cl, %al
549
550 int $0x10 // display a byte
551
552 data16
553 call EXT(_real_to_prot)
554
555 pop %es
556 pop %ds
557 pop %edi
558 pop %esi
559 pop %edx
560 pop %ecx
561 pop %ebx
562
563 pop %ebp
564 ret
565
566
567
568// setCursorPosition(x,y)
569// BIOS call "INT 10H Function 2" to set cursor position
570
571
572ENTRY(_setCursorPosition)
573 push %ebp
574 mov %esp, %ebp
575
576 push %ebx
577 push %ecx
578 push %edx
579 push %esi
580 push %edi
581 push %ds
582 push %es
583
584 movb 0x8(%ebp), %cl
585 movb 0xc(%ebp), %ch
586
587 call EXT(_prot_to_real)
588
589 movb $2, %ah // setcursor function
590 movb $0, %bh // page num 0 for graphics
591 movb %cl, %dl // column, x
592 movb %ch, %dh // row, y
593
594 int $0x10 // set cursor
595
596 data16
597 call EXT(_real_to_prot)
598
599 pop %es
600 pop %ds
601 pop %edi
602 pop %esi
603 pop %edx
604 pop %ecx
605 pop %ebx
606
607 pop %ebp
608 ret
609#endif
610