VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/orgs.asm@ 60159

Last change on this file since 60159 was 59114, checked in by vboxsync, 9 years ago

BIOS: Merged RMW sequences into single instructions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.3 KB
Line 
1;;
2;; Copyright (C) 2006-2015 Oracle Corporation
3;;
4;; This file is part of VirtualBox Open Source Edition (OSE), as
5;; available from http://www.virtualbox.org. This file is free software;
6;; you can redistribute it and/or modify it under the terms of the GNU
7;; General Public License (GPL) as published by the Free Software
8;; Foundation, in version 2 as it comes in the "COPYING" file of the
9;; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10;; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11;; --------------------------------------------------------------------
12;;
13;; This code is based on:
14;;
15;; ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
16;;
17;; Copyright (C) 2002 MandrakeSoft S.A.
18;;
19;; MandrakeSoft S.A.
20;; 43, rue d'Aboukir
21;; 75002 Paris - France
22;; http://www.linux-mandrake.com/
23;; http://www.mandrakesoft.com/
24;;
25;; This library is free software; you can redistribute it and/or
26;; modify it under the terms of the GNU Lesser General Public
27;; License as published by the Free Software Foundation; either
28;; version 2 of the License, or (at your option) any later version.
29;;
30;; This library is distributed in the hope that it will be useful,
31;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33;; Lesser General Public License for more details.
34;;
35;; You should have received a copy of the GNU Lesser General Public
36;; License along with this library; if not, write to the Free Software
37;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38;;
39;;
40
41
42; Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
43; other than GPL or LGPL is available it will apply instead, Oracle elects to use only
44; the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
45; a choice of LGPL license versions is made available with the language indicating
46; that LGPLv2 or any later version may be used, or where a choice of which version
47; of the LGPL is applied is otherwise unspecified.
48
49EBDA_SEG equ 09FC0h ; starts at 639K
50EBDA_SIZE equ 1 ; 1K
51BASE_MEM_IN_K equ (640 - EBDA_SIZE)
52
53CMOS_ADDR equ 070h
54CMOS_DATA equ 071h
55
56
57PIC_CMD_EOI equ 020h
58PIC_MASTER equ 020h
59PIC_SLAVE equ 0A0h
60
61BIOS_FIX_BASE equ 0E000h
62
63SYS_MODEL_ID equ 0FCh ; PC/AT
64SYS_SUBMODEL_ID equ 0
65BIOS_REVISION equ 1
66
67BIOS_BUILD_DATE equ '06/23/99'
68BIOS_COPYRIGHT equ 'Oracle VM VirtualBox BIOS'
69
70BX_ROMBIOS32 equ 0
71BX_CALL_INT15_4F equ 1
72
73;; Set a fixed BIOS location, with a marker for verification
74BIOSORG macro addr
75 org addr - BIOS_FIX_BASE - 2
76 db 'XM'
77 endm
78
79;; Set an interrupt vector (not very efficient if multiple vectors are
80;; programmed in one go)
81SET_INT_VECTOR macro vec, segm, offs
82 mov ax, offs
83 mov ds:[vec*4], ax
84 mov ax, segm
85 mov ds:[vec*4+2], ax
86endm
87
88; Set up an environment C code expects. DS must point to the BIOS segment
89; and the direction flag must be cleared(!)
90C_SETUP macro
91 push cs
92 pop ds
93 cld
94endm
95
96;; External function in separate modules
97extrn _dummy_isr_function:near
98extrn _log_bios_start:near
99extrn _nmi_handler_msg:near
100extrn _int18_panic_msg:near
101extrn _int09_function:near
102extrn _int13_diskette_function:near
103extrn _int13_eltorito:near
104extrn _int13_cdemu:near
105extrn _int13_cdrom:near
106extrn _cdemu_isactive:near
107extrn _cdemu_emulated_drive:near
108extrn _int13_harddisk:near
109extrn _int13_harddisk_ext:near
110extrn _int14_function:near
111extrn _int15_function:near
112extrn _int15_function_mouse:near
113extrn _int15_function32:near
114extrn _int16_function:near
115extrn _int17_function:near
116extrn _int19_function:near
117extrn _int1a_function:near
118extrn _pci16_function:near
119extrn _int70_function:near
120extrn _int74_function:near
121extrn _apm_function:near
122extrn _ata_init:near
123extrn _ahci_init:near
124extrn _scsi_init:near
125extrn _ata_detect:near
126extrn _cdemu_init:near
127extrn _keyboard_init:near
128extrn _print_bios_banner:near
129extrn _inv_op_handler:near
130extrn rom_scan_:near
131
132
133;; Symbols referenced from C code
134public _diskette_param_table
135public _pmode_IDT
136public _rmode_IDT
137public post
138public eoi_both_pics
139public rtc_post
140
141;; Additional publics for easier disassembly and debugging
142ifndef DEBUG
143 DEBUG equ 1
144endif
145ifdef DEBUG
146
147public int08_handler
148public int0e_handler
149public int11_handler
150public int12_handler
151public int13_handler
152public int13_relocated
153public int15_handler
154public int17_handler
155public int19_handler
156public int19_relocated
157public dummy_iret
158public nmi
159public rom_fdpt
160public cpu_reset
161public normal_post
162public eoi_jmp_post
163public eoi_master_pic
164public ebda_post
165public hard_drive_post
166public int13_legacy
167public int70_handler
168public int75_handler
169public int15_handler32
170public int15_handler_mouse
171public iret_modify_cf
172public init_pic
173public floppy_post
174public int13_out
175public int13_disk
176public int13_notfloppy
177public int13_legacy
178public int13_noeltorito
179public int1c_handler
180public int10_handler
181public int74_handler
182public int76_handler
183public detect_parport
184public detect_serial
185public font8x8
186
187endif
188
189;; NOTE: The last 8K of the ROM BIOS are peppered with fixed locations which
190;; must be retained for compatibility. As a consequence, some of the space is
191;; going to be wasted, but the gaps should be filled with miscellaneous code
192;; and data when possible.
193
194.286p
195
196BIOSSEG segment 'CODE'
197 assume cs:BIOSSEG
198
199;;
200;; Start of fixed code - eoi_jmp_post is kept near here to allow short jumps.
201;;
202 BIOSORG 0E030h
203eoi_both_pics:
204 mov al, PIC_CMD_EOI
205 out PIC_SLAVE, al
206eoi_master_pic:
207 mov al, PIC_CMD_EOI
208 out PIC_MASTER, al
209 ret
210
211 ;; routine to write the pointer in DX:AX to memory starting
212 ;; at DS:BX (repeat CX times)
213 ;; - modifies BX, CX
214set_int_vects proc near
215
216 mov [bx], ax
217 mov [bx+2], dx
218 add bx, 4
219 loop set_int_vects
220 ret
221
222set_int_vects endp
223
224eoi_jmp_post:
225 call eoi_both_pics
226 xor ax, ax
227 mov ds, ax
228 jmp dword ptr ds:[0467h]
229
230;; --------------------------------------------------------
231;; POST entry point
232;; --------------------------------------------------------
233 BIOSORG 0E05Bh
234post:
235 cli
236
237 ;; Check if in protected (V86) mode. If so, the CPU needs
238 ;; to be reset.
239 smsw ax
240 test ax, 1
241 jz in_real_mode
242
243 ;; Reset processor to get out of protected mode. Use system
244 ;; port instead of KBC.
245reset_sys:
246 mov al, 1
247 out 92h, al
248 jmp $ ; not strictly necessary in a VM
249
250
251in_real_mode:
252 ;; read the CMOS shutdown status
253 mov al, 0Fh
254 out CMOS_ADDR, al
255 in al, CMOS_DATA
256
257 ;; save status
258 xchg ah, al
259
260 ;; Check KBC self-test/shutdown flag. If it is set, we need
261 ;; to check for a reboot attempt.
262 in al, 64h
263 test al, 4 ; clear flag indicates cold boot
264 jz cont_post
265
266 ;; Warm boot, check the shutdown byte.
267 mov al, ah
268 or al, al
269 jnz cont_post
270
271 ;; Warm boot but shutdown byte is zero. This is either a warm
272 ;; boot request or an attempt to reset the system via triple
273 ;; faulting the CPU or similar. Check reboot flag.
274 ;; NB: At this point, registers need not be preserved.
275 push 40h
276 pop ds
277 cmp word ptr ds:[72h], 1234h
278 jnz reset_sys ; trigger system reset
279
280cont_post:
281 ;; reset the shutdown status in CMOS
282 mov al, 0Fh
283 out CMOS_ADDR, al
284 mov al, 0
285 out CMOS_DATA, al
286
287 ;; pre-check the shutdown status - shutdown codes 9/A leave
288 ;; the hardware alone
289 mov al, ah
290 cmp al, 09h
291 jz check_shutdown
292 cmp al, 0Ah
293 jz check_shutdown
294
295 xor al, al
296
297 ;; reset the DMA controllers
298 out 00Dh, al
299 out 0DAh, al
300
301 ;; then initialize the DMA controllers
302 mov al, 0C0h
303 out 0D6h, al ; enable channel 4 cascade
304 mov al, 0
305 out 0D4h, al ; unmask channel 4
306
307check_shutdown:
308 ;; examine the shutdown status code
309 mov al, ah
310 cmp al, 0
311 jz normal_post
312
313 cmp al, 0Dh
314 jae normal_post
315 cmp al, 9
316 jne check_next_std
317 jmp return_blkmove
318check_next_std:
319
320 ;; 05h = EOI + jump through 40:67
321 cmp al, 5
322 je eoi_jmp_post
323
324 ;; any other shutdown status values are ignored
325 ;; OpenSolaris sets the status to 0Ah in some cases?
326 jmp normal_post
327
328normal_post:
329 ;; shutdown code 0: normal startup
330
331 ;; Set up the stack top at 0:7800h. The stack should not be
332 ;; located above 0:7C00h; that conflicts with PXE, which
333 ;; considers anything above that address to be fair game.
334 ;; The traditional locations are 30:100 (PC) or 0:400 (PC/AT).
335 mov ax, 7800h
336 mov sp, ax
337 xor ax, ax
338 mov ds, ax
339 mov ss, ax
340
341 ;; clear the bottom of memory except for the word at 40:72
342 ;; TODO: Why not clear all of it? What's the point?
343 mov es, ax
344 xor di, di
345 cld
346 mov cx, 0472h / 2
347 rep stosw
348 inc di
349 inc di
350 mov cx, (1000h - 0472h - 2) / 2
351 rep stosw
352
353 ;; clear the remaining base memory except for the top
354 ;; of the EBDA (the MP table is planted there)
355 xor bx, bx
356memory_zero_loop:
357 add bx, 1000h
358 cmp bx, 9000h
359 jae memory_cleared
360 mov es, bx
361 xor di, di
362 mov cx, 8000h ; 32K words
363 rep stosw
364 jmp memory_zero_loop
365memory_cleared:
366 mov es, bx
367 xor di, di
368 mov cx, 7FF8h ; all but the last 16 bytes
369 rep stosw
370 xor bx, bx
371
372
373 C_SETUP
374 call _log_bios_start
375
376 call pmode_setup
377
378 ;; set all interrupts in 00h-5Fh range to default handler
379 xor bx, bx
380 mov ds, bx
381 mov cx, 60h ; leave the rest as zeros
382 mov ax, dummy_iret
383 mov dx, BIOSSEG
384 call set_int_vects
385
386 ;; also set 68h-77h to default handler; note that the
387 ;; 60h-67h range must contain zeros for certain programs
388 ;; to function correctly
389 mov bx, 68h * 4
390 mov cx, 10h
391 call set_int_vects
392
393 ;; base memory in K to 40:13
394 mov ax, BASE_MEM_IN_K
395 mov ds:[413h], ax
396
397 ;; manufacturing test at 40:12
398 ;; zeroed out above
399
400 ;; set up various service vectors
401 ;; TODO: This should use the table at FEF3h instead
402 SET_INT_VECTOR 06h, BIOSSEG, int06_handler
403 SET_INT_VECTOR 11h, BIOSSEG, int11_handler
404 SET_INT_VECTOR 12h, BIOSSEG, int12_handler
405 SET_INT_VECTOR 15h, BIOSSEG, int15_handler
406 SET_INT_VECTOR 17h, BIOSSEG, int17_handler
407 SET_INT_VECTOR 18h, BIOSSEG, int18_handler
408 SET_INT_VECTOR 19h, BIOSSEG, int19_handler
409 SET_INT_VECTOR 1Ch, BIOSSEG, int1c_handler
410
411 call ebda_post
412
413 ;; Initialize PCI devices. This can and should be done early.
414 call pcibios_init_iomem_bases
415 call pcibios_init_irqs
416 SET_INT_VECTOR 1Ah, BIOSSEG, int1a_handler
417
418 ;; PIT setup
419 SET_INT_VECTOR 08h, BIOSSEG, int08_handler
420 mov al, 34h ; timer 0, binary, 16-bit, mode 2
421 out 43h, al
422 mov al, 0 ; max count -> ~18.2 Hz
423 out 40h, al
424 out 40h, al
425
426 ;; video setup - must be done before POSTing VGA ROM
427 SET_INT_VECTOR 10h, BIOSSEG, int10_handler
428
429 ;; keyboard setup
430 SET_INT_VECTOR 09h, BIOSSEG, int09_handler
431 SET_INT_VECTOR 16h, BIOSSEG, int16_handler
432
433 xor ax, ax
434 mov ds, ax
435 ;; TODO: What's the point? The BDA is zeroed already?!
436 mov ds:[417h], al ; keyboard shift flags, set 1
437 mov ds:[418h], al ; keyboard shift flags, set 2
438 mov ds:[419h], al ; keyboard Alt-numpad work area
439 mov ds:[471h], al ; keyboard Ctrl-Break flag
440 mov ds:[497h], al ; keyboard status flags 4
441 mov al, 10h
442 mov ds:[496h], al ; keyboard status flags 3
443
444 mov bx, 1Eh
445 mov ds:[41Ah], bx ; keyboard buffer head
446 mov ds:[41Ch], bx ; keyboard buffer tail
447 mov ds:[480h], bx ; keyboard buffer start
448 mov bx, 3Eh
449 mov ds:[482h], bx ; keyboard buffer end
450
451 ;; store CMOS equipment byte in BDA
452 mov al, 14h
453 out CMOS_ADDR, al
454 in al, CMOS_DATA
455 mov ds:[410h], al
456
457 push ds
458 C_SETUP
459
460 ;; Scan for video ROMs in the C000-C800 range. This is done
461 ;; early so that errors are displayed on the screen.
462 mov ax, 0C000h
463 mov dx, 0C800h
464 call rom_scan_
465
466 ;; Initialize the keyboard
467 call _keyboard_init
468 pop ds
469
470 ;; parallel setup
471 SET_INT_VECTOR 0Fh, BIOSSEG, dummy_iret
472 xor ax, ax
473 mov ds, ax
474 xor bx, bx
475 mov cl, 14h ; timeout value
476 mov dx, 378h ; parallel port 1
477 call detect_parport
478 mov dx, 278h ; parallel port 2
479 call detect_parport
480 shl bx, 0Eh
481 mov ax, ds:[410h] ; equipment word
482 and ax, 3FFFh
483 or ax, bx ; set number of parallel ports
484 mov ds:[410h], ax ; store in BDA
485
486 ;; Serial setup
487 SET_INT_VECTOR 0Bh, BIOSSEG, dummy_isr
488 SET_INT_VECTOR 0Ch, BIOSSEG, dummy_isr
489 SET_INT_VECTOR 14h, BIOSSEG, int14_handler
490 xor bx, bx
491 mov cl, 0Ah ; timeout value
492 mov dx, 3F8h ; first serial address
493 call detect_serial
494 mov dx, 2F8h ; second serial address
495 call detect_serial
496 mov dx, 3E8h ; third serial address
497 call detect_serial
498 mov dx, 2E8h ; fourth serial address
499 call detect_serial
500 shl bx, 9
501 mov ax, ds:[410h] ; equipment word
502 and ax, 0F1FFh ; bits 9-11 determine serial ports
503 or ax, bx
504 mov ds:[410h], ax
505
506 ;; CMOS RTC
507 SET_INT_VECTOR 4Ah, BIOSSEG, dummy_iret ; TODO: redundant?
508 SET_INT_VECTOR 70h, BIOSSEG, int70_handler
509 ;; BIOS DATA AREA 4CEh ???
510 call rtc_post
511
512 jmp norm_post_cont
513
514
515;; --------------------------------------------------------
516;; NMI handler
517;; --------------------------------------------------------
518 BIOSORG 0E2C3h
519nmi:
520 C_SETUP
521 call _nmi_handler_msg
522 iret
523
524int75_handler:
525 out 0F0h, al ; clear IRQ13
526 call eoi_both_pics
527 int 2 ; emulate legacy NMI
528 iret
529
530
531hard_drive_post proc near
532
533 xor ax, ax
534 mov ds, ax
535 ;; TODO: Didn't we just clear the entire EBDA?
536 mov ds:[474h], al ; last HD operation status
537 mov ds:[477h], al ; HD port offset (XT only???)
538 mov ds:[48Ch], al ; HD status register
539 mov ds:[48Dh], al ; HD error register
540 mov ds:[48Eh], al ; HD task complete flag
541 mov al, 0C0h
542 mov ds:[476h], al ; HD control byte
543 ;; set up hard disk interrupt vectors
544 SET_INT_VECTOR 13h, BIOSSEG, int13_handler
545 SET_INT_VECTOR 76h, BIOSSEG, int76_handler
546 ;; INT 41h/46h: hard disk 0/1 dpt
547 ; TODO: This should be done from the code which
548 ; builds the DPTs?
549 SET_INT_VECTOR 41h, EBDA_SEG, 3Dh
550 SET_INT_VECTOR 46h, EBDA_SEG, 4Dh
551 ret
552
553hard_drive_post endp
554
555
556norm_post_cont:
557 ;; PS/2 mouse setup
558 SET_INT_VECTOR 74h, BIOSSEG, int74_handler
559
560 ;; IRQ 13h (FPU exception) setup
561 SET_INT_VECTOR 75h, BIOSSEG, int75_handler
562
563 call init_pic
564
565 C_SETUP
566 ;; ATA/ATAPI driver setup
567 call _ata_init
568 call _ata_detect
569
570ifdef VBOX_WITH_AHCI
571 ; AHCI driver setup
572 call _ahci_init
573endif
574
575ifdef VBOX_WITH_SCSI
576 ; SCSI driver setup
577 call _scsi_init
578endif
579
580 ;; floppy setup
581 call floppy_post
582
583 ;; hard drive setup
584 call hard_drive_post
585
586 C_SETUP ; in case assembly code changed things
587 ;; Scan for additional ROMs in the C800-EFFF range
588 mov ax, 0C800h
589 mov dx, 0F000h
590 call rom_scan_
591
592 call _print_bios_banner
593
594 ;; El Torito floppy/hard disk emulation
595 call _cdemu_init
596
597 ; TODO: what's the point of enabling interrupts here??
598 sti ; enable interrupts
599 int 19h
600 ;; does not return here
601 sti
602wait_forever:
603 hlt
604 jmp wait_forever
605 cli
606 hlt
607
608
609;;
610;; Return from block move (shutdown code 09h). Care must be taken to disturb
611;; register and memory state as little as possible.
612;;
613return_blkmove:
614 mov ax, 40h
615 mov ds, ax
616 ;; restore user stack
617 mov ss, ds:[69h]
618 mov sp, ds:[67h]
619 ;; reset A20 gate
620 in al, 92h
621 and al, 0FDh
622 out 92h, al
623 ;; ensure proper real mode IDT
624 lidt fword ptr cs:_rmode_IDT
625 ;; restore user segments
626 pop ds
627 pop es
628 ;; set up BP
629 mov bp, sp
630 ;; restore status code
631 in al, 80h
632 mov [bp+15], al
633 ;; set ZF/CF
634 cmp ah,al ; AH is zero here!
635 ;; restore registers and return
636 popa
637 sti
638 retf 2
639
640
641;; --------------------------------------------------------
642;; INT 13h handler - Disk services
643;; --------------------------------------------------------
644 BIOSORG 0E3FEh
645
646int13_handler:
647 jmp int13_relocated
648
649
650;; --------------------------------------------------------
651;; Fixed Disk Parameter Table
652;; --------------------------------------------------------
653;; BIOSORG 0E401h - fixed wrt preceding
654
655rom_fdpt:
656
657;; --------------------------------------------------------
658;; INT 19h handler - Boot load service
659;; --------------------------------------------------------
660 BIOSORG 0E6F2h
661
662int19_handler:
663 jmp int19_relocated
664
665
666
667;; --------------------------------------------------------
668;; System BIOS Configuration Table
669;; --------------------------------------------------------
670;; BIOSORG 0E6F5h - fixed wrt preceding
671; must match BIOS_CONFIG_TABLE
672bios_cfg_table:
673 dw 9 ; table size in bytes
674 db SYS_MODEL_ID
675 db SYS_SUBMODEL_ID
676 db BIOS_REVISION
677 ; Feature byte 1
678 ; b7: 1=DMA channel 3 used by hard disk
679 ; b6: 1=2 interrupt controllers present
680 ; b5: 1=RTC present
681 ; b4: 1=BIOS calls int 15h/4Fh for every key
682 ; b3: 1=wait for extern event supported (Int 15h/41h)
683 ; b2: 1=extended BIOS data area used
684 ; b1: 0=AT or ESDI bus, 1=MicroChannel
685 ; b0: 1=Dual bus (MicroChannel + ISA)
686ifdef BX_CALL_INT15_4F
687 db 74h; or USE_EBDA
688else
689 db 64h; or USE_EBDA
690endif
691 ; Feature byte 2
692 ; b7: 1=32-bit DMA supported
693 ; b6: 1=int16h, function 9 supported
694 ; b5: 1=int15h/C6h (get POS data) supported
695 ; b4: 1=int15h/C7h (get mem map info) supported
696 ; b3: 1=int15h/C8h (en/dis CPU) supported
697 ; b2: 1=non-8042 kb controller
698 ; b1: 1=data streaming supported
699 ; b0: reserved
700 db 40h
701 ; Feature byte 3
702 ; b7: not used
703 ; b6: reserved
704 ; b5: reserved
705 ; b4: POST supports ROM-to-RAM enable/disable
706 ; b3: SCSI on system board
707 ; b2: info panel installed
708 ; b1: Initial Machine Load (IML) system - BIOS on disk
709 ; b0: SCSI supported in IML
710 db 0
711 ; Feature byte 4
712 ; b7: IBM private
713 ; b6: EEPROM present
714 ; b5-3: ABIOS presence (011 = not supported)
715 ; b2: private
716 ; b1: memory split above 16Mb supported
717 ; b0: POSTEXT directly supported by POST
718 db 0
719 ; Feature byte 5 (IBM)
720 ; b1: enhanced mouse
721 ; b0: flash EPROM
722 db 0
723
724
725;; --------------------------------------------------------
726;; Baud Rate Generator Table
727;; --------------------------------------------------------
728 BIOSORG 0E729h
729
730
731;; --------------------------------------------------------
732;; INT 14h handler - Serial Communication Service
733;; --------------------------------------------------------
734 BIOSORG 0E739h
735int14_handler:
736 push ds
737 push es
738 pusha
739 C_SETUP
740 call _int14_function
741 popa
742 pop es
743 pop ds
744 iret
745
746
747
748;;
749;; Handler for unexpected hardware interrupts
750;;
751dummy_isr:
752 push ds
753 push es
754 pusha
755 C_SETUP
756 call _dummy_isr_function
757 popa
758 pop es
759 pop ds
760 iret
761
762
763init_pic proc near
764
765 mov al, 11h ; send init commands
766 out PIC_MASTER, al
767 out PIC_SLAVE, al
768 mov al, 08h ; base 08h
769 out PIC_MASTER+1, al
770 mov al, 70h ; base 70h
771 out PIC_SLAVE+1, al
772 mov al, 04h ; master PIC
773 out PIC_MASTER+1, al
774 mov al, 02h ; slave PIC
775 out PIC_SLAVE+1, al
776 mov al, 01h
777 out PIC_MASTER+1, al
778 out PIC_SLAVE+1, al
779 mov al, 0B8h ; unmask IRQs 0/1/2/6
780 out PIC_MASTER+1, al
781 mov al, 08Fh
782 out PIC_SLAVE+1, al ; unmask IRQs 12/13/14
783 ret
784
785init_pic endp
786
787ebda_post proc near
788
789 SET_INT_VECTOR 0Dh, BIOSSEG, dummy_isr ; IRQ 5
790 SET_INT_VECTOR 0Fh, BIOSSEG, dummy_isr ; IRQ 7
791 SET_INT_VECTOR 72h, BIOSSEG, dummy_isr ; IRQ 11
792 SET_INT_VECTOR 77h, BIOSSEG, dummy_isr ; IRQ 15
793
794 mov ax, EBDA_SEG
795 mov ds, ax
796 mov byte ptr ds:[0], EBDA_SIZE
797 ;; store EBDA seg in 40:0E
798 xor ax, ax
799 mov ds, ax
800 mov word ptr ds:[40Eh], EBDA_SEG
801 ret
802
803ebda_post endp
804
805
806
807;; --------------------------------------------------------
808;; INT 16h handler - Keyboard service
809;; --------------------------------------------------------
810 BIOSORG 0E82Eh
811int16_handler:
812 sti
813 push es
814 push ds
815 pusha
816
817 cmp ah, 0
818 je int16_F00
819
820 cmp ah, 10h
821 je int16_F00
822
823 C_SETUP
824 call _int16_function
825 popa
826 pop ds
827 pop es
828 iret
829
830int16_F00:
831 mov bx, 40h ; TODO: why 40h here and 0 elsewhere?
832 mov ds, bx
833int16_wait_for_key:
834 cli
835 mov bx, ds:[1Ah]
836 cmp bx, ds:[1Ch]
837 jne int16_key_found
838 sti
839 nop
840; TODO: review/enable?
841if 0
842 push ax
843 mov ax, 9002h
844 int 15h
845 pop ax
846endif
847 jmp int16_wait_for_key
848
849int16_key_found:
850 C_SETUP
851 call _int16_function
852 popa
853 pop ds
854 pop es
855; TODO: review/enable? If so, flags should be restored here?
856if 0
857 push ax
858 mov ax, 9202h
859 int 15h
860 pop ax
861endif
862 iret
863
864
865;; Quick and dirty protected mode entry/exit routines
866include pmode.inc
867
868;; Initialization code which needs to run in protected mode (LAPIC etc.)
869include pmsetup.inc
870
871
872KBDC_DISABLE EQU 0ADh
873KBDC_ENABLE EQU 0AEh
874KBC_CMD EQU 64h
875KBC_DATA EQU 60h
876
877;; --------------------------------------------------------
878;; INT 09h handler - Keyboard ISR (IRQ 1)
879;; --------------------------------------------------------
880 BIOSORG 0E987h
881int09_handler:
882 cli ; TODO: why? they're off already!
883 push ax
884 mov al, KBDC_DISABLE
885 out KBC_CMD, al
886
887 mov al, 0Bh
888 out PIC_MASTER, al
889 in al, PIC_MASTER
890 and al, 2
891 jz int09_finish
892
893 in al, KBC_DATA
894 push ds
895 pusha
896 cld ; Before INT 15h (and any C code)
897ifdef BX_CALL_INT15_4F
898 mov ah, 4Fh
899 stc
900 int 15h ; keyboard intercept
901 jnc int09_done
902endif
903 sti ; Only after calling INT 15h
904
905 ;; check for extended key
906 cmp al, 0E0h
907 jne int09_check_pause
908 xor ax, ax
909 mov ds, ax
910 or byte ptr ds:[496h], 2 ; mf2_state |= 0x02
911 jmp int09_done
912
913int09_check_pause:
914 cmp al, 0E1h ; pause key?
915 jne int09_process_key
916 xor ax, ax
917 mov ds, ax
918 or byte ptr ds:[496h], 1 ; mf2_state | 0x01
919 jmp int09_done
920
921int09_process_key:
922 push es
923 C_SETUP
924 call _int09_function
925 pop es
926
927int09_done:
928 popa
929 pop ds
930 cli
931 call eoi_master_pic
932
933int09_finish:
934 mov al, KBDC_ENABLE
935 out KBC_CMD, al
936 pop ax
937 iret
938
939
940;; --------------------------------------------------------
941;; INT 06h handler - Invalid Opcode Exception
942;; --------------------------------------------------------
943
944int06_handler:
945 pusha
946 push es
947 push ds
948 C_SETUP
949 call _inv_op_handler
950 pop ds
951 pop es
952 popa
953 iret
954
955;; --------------------------------------------------------
956;; INT 13h handler - Diskette service
957;; --------------------------------------------------------
958 BIOSORG 0EC59h
959int13_diskette:
960 jmp int13_noeltorito
961
962
963
964;; --------------------------------------------------------
965;; INT 13h handler - Disk service
966;; --------------------------------------------------------
967int13_relocated:
968 ;; check for an El-Torito function
969 cmp ah, 4Ah
970 jb int13_not_eltorito
971
972 cmp ah, 4Dh
973 ja int13_not_eltorito
974
975 pusha
976 push es
977 push ds
978 C_SETUP ; TODO: setup C envrionment only once?
979 push int13_out ; simulate a call
980 jmp _int13_eltorito ; ELDX not used
981
982int13_not_eltorito:
983 push es
984 push ax ; TODO: better register save/restore
985 push bx
986 push cx
987 push dx
988
989 ;; check if emulation is active
990 call _cdemu_isactive
991 cmp al, 0
992 je int13_cdemu_inactive
993
994 ;; check if access to the emulated drive
995 call _cdemu_emulated_drive
996 pop dx ; recover dx (destroyed by C code)
997 push dx
998 cmp al, dl ; INT 13h on emulated drive
999 jne int13_nocdemu
1000
1001 pop dx
1002 pop cx
1003 pop bx
1004 pop ax
1005 pop es
1006
1007 pusha
1008 push es
1009 push ds
1010 C_SETUP ; TODO: setup environment only once?
1011
1012 push int13_out ; simulate a call
1013 jmp _int13_cdemu ; ELDX not used
1014
1015int13_nocdemu:
1016 and dl, 0E0h ; mask to get device class
1017 cmp al, dl
1018 jne int13_cdemu_inactive
1019
1020 pop dx
1021 pop cx
1022 pop bx
1023 pop ax
1024 pop es
1025
1026 push ax
1027 push cx
1028 push dx
1029 push bx
1030
1031 dec dl ; real drive is dl - 1
1032 jmp int13_legacy
1033
1034int13_cdemu_inactive:
1035 pop dx
1036 pop cx
1037 pop bx
1038 pop ax
1039 pop es
1040
1041int13_noeltorito:
1042 push ax
1043 push cx
1044 push dx
1045 push bx
1046int13_legacy:
1047 push dx ; push eltorito dx in place of sp
1048 push bp
1049 push si
1050 push di
1051 push es
1052 push ds
1053 C_SETUP ; TODO: setup environment only once?
1054
1055 ;; now the registers can be restored with
1056 ;; pop ds; pop es; popa; iret
1057 test dl, 80h ; non-removable?
1058 jnz int13_notfloppy
1059
1060 push int13_out ; simulate a near call
1061 jmp _int13_diskette_function
1062
1063int13_notfloppy:
1064 cmp dl, 0E0h
1065 jb int13_notcdrom
1066
1067 ;; ebx may be modified, save here
1068 ;; TODO: check/review 32-bit register use
1069 .386
1070 shr ebx, 16
1071 push bx
1072 call _int13_cdrom
1073 pop bx
1074 shl ebx, 16
1075 .286
1076
1077 jmp int13_out
1078
1079int13_notcdrom:
1080int13_disk:
1081 cmp ah,40h
1082 ja int13x
1083 call _int13_harddisk
1084 jmp int13_out
1085
1086int13x:
1087 call _int13_harddisk_ext
1088
1089int13_out:
1090 pop ds
1091 pop es
1092 popa
1093 iret
1094
1095
1096
1097; parallel port detection: port in dx, index in bx, timeout in cl
1098detect_parport proc near
1099
1100 push dx
1101 inc dx
1102 inc dx
1103 in al, dx
1104 and al, 0DFh ; clear input mode
1105 out dx, al
1106 pop dx
1107 mov al, 0AAh
1108 out dx, al
1109 in al, dx
1110 cmp al, 0AAh
1111 jne no_parport
1112
1113 push bx
1114 shl bx, 1
1115 mov [bx+408h], dx ; parallel I/O address
1116 pop bx
1117 mov [bx+478h], cl ; parallel printer timeout
1118 inc bx
1119no_parport:
1120 ret
1121
1122detect_parport endp
1123
1124; setial port detection: port in dx, index in bx, timeout in cl
1125detect_serial proc near
1126
1127 push dx
1128 inc dx
1129 mov al, 2
1130 out dx, al
1131 in al, dx
1132 cmp al, 2
1133 jne no_serial
1134
1135 inc dx
1136 in al, dx
1137 cmp al, 2
1138 jne no_serial
1139
1140 dec dx
1141 xor al, al
1142 pop dx
1143 push bx
1144 shl bx, 1
1145 mov [bx+400h], dx ; serial I/O address
1146 pop bx
1147 mov [bx+47Ch], cl ; serial timeout
1148 inc bx
1149 ret
1150
1151no_serial:
1152 pop dx
1153 ret
1154
1155detect_serial endp
1156
1157
1158;;
1159;; POST: Floppy drive
1160;;
1161floppy_post proc near
1162
1163 xor ax, ax
1164 mov ds, ax
1165
1166 ;; TODO: This code is really stupid. Zeroing the BDA byte
1167 ;; by byte is dumb, and it's been already zeroed elsewhere!
1168 mov al, 0
1169 mov ds:[43Eh], al ; drive 0/1 uncalibrated, no IRQ
1170 mov ds:[43Fh], al ; motor status
1171 mov ds:[440h], al ; motor timeout counter
1172 mov ds:[441h], al ; controller status return code
1173 mov ds:[442h], al ; hd/floppy ctlr status register
1174 mov ds:[443h], al ; controller status register 1
1175 mov ds:[444h], al ; controller status register 2
1176 mov ds:[445h], al ; cylinder number
1177 mov ds:[446h], al ; head number
1178 mov ds:[447h], al ; sector number
1179 mov ds:[448h], al ; bytes written
1180
1181 mov ds:[48Bh], al ; configuration data
1182
1183 mov al, 10h ; floppy drive type
1184 out CMOS_ADDR, al
1185 in al, CMOS_DATA
1186 mov ah, al ; save drive type byte
1187
1188look_drive0:
1189 ; TODO: pre-init bl to reduce jumps
1190 shr al, 4 ; drive 0 in high nibble
1191 jz f0_missing ; jump if no drive
1192 mov bl, 7 ; drv0 determined, multi-rate, chgline
1193 jmp look_drive1
1194
1195f0_missing:
1196 mov bl, 0 ; no drive 0
1197
1198look_drive1:
1199 mov al, ah ; restore CMOS data
1200 and al, 0Fh ; drive 1 in low nibble
1201 jz f1_missing
1202 or bl, 70h ; drv1 determined, multi-rate, chgline
1203f1_missing:
1204 mov ds:[48Fh], bl ; store in BDA
1205
1206 ;; TODO: See above. Dumb *and* redundant!
1207 mov al, 0
1208 mov ds:[490h], al ; drv0 media state
1209 mov ds:[491h], al ; drv1 media state
1210 mov ds:[492h], al ; drv0 operational state
1211 mov ds:[493h], al ; drv1 operational state
1212 mov ds:[494h], al ; drv0 current cylinder
1213 mov ds:[495h], al ; drv1 current cylinder
1214
1215 mov al, 2
1216 out 0Ah, al ; unmask DMA channel 2
1217
1218 SET_INT_VECTOR 1Eh, BIOSSEG, _diskette_param_table
1219 SET_INT_VECTOR 40h, BIOSSEG, int13_diskette
1220 SET_INT_VECTOR 0Eh, BIOSSEG, int0e_handler ; IRQ 6
1221
1222 ret
1223
1224floppy_post endp
1225
1226
1227bcd_to_bin proc near
1228
1229 ;; in : AL in packed BCD format
1230 ;; out: AL in binary, AH always 0
1231 shl ax, 4
1232 shr al, 4
1233 aad
1234 ret
1235
1236bcd_to_bin endp
1237
1238rtc_post proc near
1239
1240 .386
1241 ;; get RTC seconds
1242 xor eax, eax
1243 mov al, 0
1244 out CMOS_ADDR, al
1245 in al, CMOS_DATA ; RTC seconds, in BCD
1246 call bcd_to_bin ; eax now has seconds in binary
1247 mov edx, 18206507
1248 mul edx
1249 mov ebx, 1000000
1250 xor edx, edx
1251 div ebx
1252 mov ecx, eax ; total ticks in ecx
1253
1254 ;; get RTC minutes
1255 xor eax, eax
1256 mov al, 2
1257 out CMOS_ADDR, al
1258 in al, CMOS_DATA ; RTC minutes, in BCD
1259 call bcd_to_bin ; eax now has minutes in binary
1260 mov edx, 10923904
1261 mul edx
1262 mov ebx, 10000
1263 xor edx, edx
1264 div ebx
1265 add ecx, eax ; add to total ticks
1266
1267 ;; get RTC hours
1268 xor eax, eax
1269 mov al, 4
1270 out CMOS_ADDR, al
1271 in al, CMOS_DATA ; RTC hours, in BCD
1272 call bcd_to_bin ; eax now has hours in binary
1273 mov edx, 65543427
1274 mul edx
1275 mov ebx, 1000
1276 xor edx, edx
1277 div ebx
1278 add ecx, eax ; add to total ticks
1279
1280 mov ds:[46Ch], ecx ; timer tick count
1281 xor al, al ; TODO: redundant?
1282 mov ds:[470h], al ; rollover flag
1283 .286
1284 ret
1285
1286rtc_post endp
1287
1288
1289
1290;; --------------------------------------------------------
1291;; INT 0Eh handler - Diskette IRQ 6 ISR
1292;; --------------------------------------------------------
1293 BIOSORG 0EF57h
1294int0e_handler:
1295 push ax
1296 push dx
1297 mov dx, 3F4h
1298 in al, dx
1299 and al, 0C0h
1300 cmp al, 0C0h
1301 je int0e_normal
1302 mov dx, 3F5h
1303 mov al, 08h ; sense interrupt
1304 out dx, al
1305int0e_loop1:
1306 mov dx, 3F4h ; TODO: move out of the loop?
1307 in al, dx
1308 and al, 0C0h
1309 cmp al, 0C0h
1310 jne int0e_loop1
1311
1312int0e_loop2:
1313 mov dx, 3F5h ; TODO: inc/dec dx instead
1314 in al, dx
1315 mov dx, 3F4h
1316 in al, dx
1317 and al, 0C0h
1318 cmp al, 0C0h
1319 je int0e_loop2
1320
1321int0e_normal:
1322 push ds
1323 xor ax, ax
1324 mov ds, ax
1325 call eoi_master_pic
1326 ; indicate that an interrupt occurred
1327 or byte ptr ds:[43Eh], 80h
1328 pop ds
1329 pop dx
1330 pop ax
1331 iret
1332
1333
1334;; --------------------------------------------------------
1335;; Diskette Parameter Table
1336;; --------------------------------------------------------
1337 BIOSORG 0EFC7h
1338_diskette_param_table:
1339 db 0AFh
1340 db 2 ; HLT=1, DMA mode
1341 db 025h
1342 db 2
1343 db 18 ; SPT (good for 1.44MB media)
1344 db 01Bh
1345 db 0FFh
1346 db 06Ch
1347 db 0F6h ; format filler
1348 db 15
1349 db 8
1350
1351
1352
1353;; --------------------------------------------------------
1354;; INT 17h handler - Printer service
1355;; --------------------------------------------------------
1356;; BIOSORG 0EFD2h - fixed WRT preceding code
1357
1358 jmp int17_handler ; NT floppy boot workaround
1359 ; see @bugref{6481}
1360int17_handler:
1361 push ds
1362 push es
1363 pusha
1364 C_SETUP
1365 call _int17_function
1366 popa
1367 pop es
1368 pop ds
1369 iret
1370
1371
1372
1373;; Protected mode IDT descriptor
1374;;
1375;; The limit is 0 to cause a shutdown if an exception occurs
1376;; in protected mode. TODO: Is that what we really want?
1377;;
1378;; Set base to F0000 to correspond to beginning of BIOS,
1379;; in case an IDT is defined later.
1380
1381_pmode_IDT:
1382 dw 0 ; limit 15:0
1383 dw 0 ; base 15:0
1384 dw 0Fh ; base 23:16
1385
1386
1387;; Real mode IDT descriptor
1388;;
1389;; Set to typical real-mode values.
1390;; base = 000000
1391;; limit = 03ff
1392
1393_rmode_IDT:
1394 dw 3FFh ; limit 15:00
1395 dw 0 ; base 15:00
1396 dw 0 ; base 23:16
1397
1398
1399;;
1400;; INT 1Ch
1401;;
1402;; TODO: Why does this need a special handler?
1403int1c_handler: ;; user timer tick
1404 iret
1405
1406
1407
1408;; --------------------------------------------------------
1409;; INT 10h functions 0-Fh entry point
1410;; --------------------------------------------------------
1411 BIOSORG 0F045h
1412i10f0f_entry:
1413 iret
1414
1415
1416;; --------------------------------------------------------
1417;; INT 10h handler - MDA/CGA video
1418;; --------------------------------------------------------
1419 BIOSORG 0F065h
1420int10_handler:
1421 ;; do nothing - assumes VGA
1422 iret
1423
1424
1425;; --------------------------------------------------------
1426;; MDA/CGA Video Parameter Table (INT 1Dh)
1427;; --------------------------------------------------------
1428 BIOSORG 0F0A4h
1429mdacga_vpt:
1430
1431
1432;;
1433;; INT 18h - boot failure
1434;;
1435int18_handler:
1436 C_SETUP
1437 call _int18_panic_msg
1438 ;; TODO: handle failure better?
1439 hlt
1440 iret
1441
1442;;
1443;; INT 19h - boot service - relocated
1444;;
1445int19_relocated:
1446; If an already booted OS calls int 0x19 to reboot, it is not sufficient
1447; just to try booting from the configured drives. All BIOS variables and
1448; interrupt vectors need to be reset, otherwise strange things may happen.
1449; The approach used is faking a warm reboot (which just skips showing the
1450; logo), which is a bit more than what we need, but hey, it's fast.
1451 mov bp, sp
1452 mov ax, [bp+2] ; TODO: redundant? address via sp?
1453 cmp ax, BIOSSEG ; check caller's segment
1454 jz bios_initiated_boot
1455
1456 xor ax, ax
1457 mov ds, ax
1458 mov ax, 1234h
1459 mov ds:[472], ax
1460 jmp post
1461
1462bios_initiated_boot:
1463 ;; The C worker function returns the boot drive in bl and
1464 ;; the boot segment in ax. In case of failure, the boot
1465 ;; segment will be zero.
1466 C_SETUP ; TODO: Here? Now?
1467 push bp
1468 mov bp, sp
1469
1470 ;; 1st boot device
1471 mov ax, 1
1472 push ax
1473 call _int19_function
1474 inc sp
1475 inc sp
1476 test ax, ax ; if 0, try next device
1477 jnz boot_setup
1478
1479 ;; 2nd boot device
1480 mov ax, 2
1481 push ax
1482 call _int19_function
1483 inc sp
1484 inc sp
1485 test ax, ax ; if 0, try next device
1486 jnz boot_setup
1487
1488 ; 3rd boot device
1489 mov ax, 3
1490 push 3
1491 call _int19_function
1492 inc sp
1493 inc sp
1494 test ax, ax ; if 0, try next device
1495 jnz boot_setup
1496
1497 ; 4th boot device
1498 mov ax, 4
1499 push ax
1500 call _int19_function
1501 inc sp
1502 inc sp
1503 test ax, ax ; if 0, invoke INT 18h
1504 jz int18_handler
1505
1506boot_setup:
1507; TODO: the drive should be in dl already??
1508;; mov dl, bl ; tell guest OS what boot drive is
1509 .386 ; NB: We're getting garbage into high eax bits
1510 shl eax, 4 ; convert seg to ip
1511 mov [bp+2], ax ; set ip
1512
1513 shr eax, 4 ; get cs back
1514 .286
1515 and ax, BIOSSEG ; remove what went in ip
1516 mov [bp+4], ax ; set cs
1517 xor ax, ax
1518 mov ds, ax
1519 mov es, ax
1520 mov [bp], ax ; TODO: what's this?!
1521 mov ax, 0AA55h ; set ok flag ; TODO: and this?
1522
1523 pop bp ; TODO: why'd we just zero it??
1524 iret ; beam me up scotty
1525
1526;; PCI BIOS
1527
1528include pcibios.inc
1529include pirq.inc
1530
1531
1532;; --------------------------------------------------------
1533;; INT 12h handler - Memory size
1534;; --------------------------------------------------------
1535 BIOSORG 0F841h
1536int12_handler:
1537 ;; Don't touch - fixed size!
1538 sti
1539 push ds
1540 mov ax, 40h
1541 mov ds, ax
1542 mov ax, ds:[13h]
1543 pop ds
1544 iret
1545
1546
1547;; --------------------------------------------------------
1548;; INT 11h handler - Equipment list service
1549;; --------------------------------------------------------
1550;; BIOSORG 0F84Dh - fixed wrt preceding code
1551int11_handler:
1552 ;; Don't touch - fixed size!
1553 sti
1554 push ds
1555 mov ax, 40h
1556 mov ds, ax
1557 mov ax, ds:[10h]
1558 pop ds
1559 iret
1560
1561
1562;; --------------------------------------------------------
1563;; INT 15h handler - System services
1564;; --------------------------------------------------------
1565;; BIOSORG 0F859h - fixed wrt preceding code
1566int15_handler:
1567 pushf
1568 push ds
1569 push es
1570 C_SETUP
1571 cmp ah, 86h
1572 je int15_handler32
1573 cmp ah, 0E8h
1574 je int15_handler32
1575 cmp ah, 0d0h
1576 je int15_handler32
1577 pusha
1578 cmp ah, 53h ; APM function?
1579 je apm_call
1580 cmp ah, 0C2h ; PS/2 mouse function?
1581 je int15_handler_mouse
1582
1583 call _int15_function
1584int15_handler_popa_ret:
1585 popa
1586int15_handler32_ret:
1587 pop es
1588 pop ds
1589 popf
1590 jmp iret_modify_cf
1591
1592apm_call:
1593 call _apm_function
1594 jmp int15_handler_popa_ret
1595
1596int15_handler_mouse:
1597 call _int15_function_mouse
1598 jmp int15_handler_popa_ret
1599
1600int15_handler32:
1601 ;; need to save/restore 32-bit registers
1602 .386
1603 pushad
1604 call _int15_function32
1605 popad
1606 .286
1607 jmp int15_handler32_ret
1608
1609;;
1610;; Perform an IRET but retain the current carry flag value
1611;;
1612iret_modify_cf:
1613 jc carry_set
1614 push bp
1615 mov bp, sp
1616 and byte ptr [bp + 6], 0FEh
1617 pop bp
1618 iret
1619carry_set:
1620 push bp
1621 mov bp, sp
1622 or byte ptr [bp + 6], 1
1623 pop bp
1624 iret
1625
1626;;
1627;; INT 74h handler - PS/2 mouse (IRQ 12)
1628;;
1629int74_handler proc
1630
1631 sti
1632 pusha
1633 push es
1634 push ds
1635 push 0 ; placeholder for status
1636 push 0 ; placeholder for X
1637 push 0 ; placeholder for Y
1638 push 0 ; placeholder for Z
1639 push 0 ; placeholder for make_far_call bool
1640 C_SETUP
1641 call _int74_function
1642 pop cx ; pop make_far_call flag
1643 jcxz int74_done
1644
1645 ;; make far call to EBDA:0022
1646 push 0
1647 pop ds
1648 push ds:[40Eh]
1649 pop ds
1650 call far ptr ds:[22h]
1651int74_done:
1652 cli
1653 call eoi_both_pics
1654 add sp, 8 ; remove status, X, Y, Z
1655 pop ds
1656 pop es
1657 popa
1658 iret
1659
1660int74_handler endp
1661
1662int76_handler proc
1663
1664 ;; record completion in BIOS task complete flag
1665 push ax
1666 push ds
1667 mov ax, 40h
1668 mov ds, ax
1669 mov byte ptr ds:[8Eh], 0FFh
1670 call eoi_both_pics
1671 pop ds
1672 pop ax
1673 iret
1674
1675int76_handler endp
1676
1677;; --------------------------------------------------------
1678;; 8x8 font (first 128 characters)
1679;; --------------------------------------------------------
1680 BIOSORG 0FA6Eh
1681include font8x8.inc
1682
1683
1684;; --------------------------------------------------------
1685;; INT 1Ah handler - Time of the day + PCI BIOS
1686;; --------------------------------------------------------
1687;; BIOSORG 0FE6Eh - fixed wrt preceding table
1688int1a_handler:
1689 cmp ah, 0B1h
1690 jne int1a_normal
1691
1692 push es
1693 push ds
1694 C_SETUP
1695 .386
1696 pushad
1697 call _pci16_function
1698 popad
1699 .286
1700 pop ds
1701 pop es
1702 iret
1703
1704int1a_normal:
1705 push es
1706 push ds
1707 pusha
1708 C_SETUP
1709int1a_callfunction:
1710 call _int1a_function
1711 popa
1712 pop ds
1713 pop es
1714 iret
1715
1716
1717;;
1718;; IRQ 8 handler (RTC)
1719;;
1720int70_handler:
1721 push es
1722 push ds
1723 pusha
1724 C_SETUP
1725 call _int70_function
1726 popa
1727 pop ds
1728 pop es
1729 iret
1730
1731
1732;; --------------------------------------------------------
1733;; Timer tick - IRQ 0 handler
1734;; --------------------------------------------------------
1735 BIOSORG 0FEA5h
1736int08_handler:
1737 .386
1738 sti
1739 push eax
1740 push ds
1741 push dx
1742 mov ax, 40h
1743 mov ds, ax
1744
1745 mov eax, ds:[6Ch] ; get ticks dword
1746 inc eax
1747
1748 ;; compare eax to one day's worth of ticks (at 18.2 Hz)
1749 cmp eax, 1800B0h
1750 jb int08_store_ticks
1751 ;; there has been a midnight rollover
1752 xor eax, eax
1753 inc byte ptr ds:[70h] ; increment rollover flag
1754
1755int08_store_ticks:
1756 mov ds:[6Ch], eax
1757
1758 ;; time to turn off floppy drive motor(s)?
1759 mov al, ds:[40h]
1760 or al, al
1761 jz int08_floppy_off
1762 dec al
1763 mov ds:[40h], al
1764 jnz int08_floppy_off
1765 ;; turn motor(s) off
1766 mov dx, 03F2h
1767 in al, dx
1768 and al, 0CFh
1769 out dx, al
1770int08_floppy_off:
1771
1772 int 1Ch ; call the user timer handler
1773
1774 cli
1775 call eoi_master_pic
1776 pop dx
1777 pop ds
1778 pop eax
1779 .286
1780 iret
1781
1782
1783;; --------------------------------------------------------
1784;; Initial interrupt vector offsets for POST
1785;; --------------------------------------------------------
1786 BIOSORG 0FEF3h
1787vector_table:
1788
1789
1790
1791;; --------------------------------------------------------
1792;; BIOS copyright string
1793;; --------------------------------------------------------
1794 BIOSORG 0FF00h
1795bios_string:
1796 db BIOS_COPYRIGHT
1797
1798
1799;; --------------------------------------------------------
1800;; IRET - default interrupt handler
1801;; --------------------------------------------------------
1802 BIOSORG 0FF53h
1803
1804dummy_iret:
1805 iret
1806
1807
1808;; --------------------------------------------------------
1809;; INT 05h - Print Screen service
1810;; --------------------------------------------------------
1811;; BIOSORG 0FF54h - fixed wrt preceding
1812int05_handler:
1813 ;; Not implemented
1814 iret
1815
1816include smidmi.inc
1817
1818;; --------------------------------------------------------
1819;; Processor reset entry point
1820;; --------------------------------------------------------
1821 BIOSORG 0FFF0h
1822cpu_reset:
1823 ;; This is where the CPU starts executing after a reset
1824 jmp far ptr post
1825
1826 ;; BIOS build date
1827 db BIOS_BUILD_DATE
1828 db 0 ; padding
1829 ;; System model ID
1830 db SYS_MODEL_ID
1831 ;; Checksum byte
1832 db 0FFh
1833
1834
1835BIOSSEG ends
1836
1837 end
1838
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette