forked from fysnet/i440fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i440fx.asm
1612 lines (1395 loc) · 53.1 KB
/
i440fx.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
comment |*******************************************************************
* Copyright (c) 1984-2025 Forever Young Software Benjamin David Lunt *
* *
* i440FX BIOS ROM v1.0 *
* FILE: cmos.asm *
* *
* This code is freeware, not public domain. Please use respectfully. *
* *
* You may: *
* - use this code for learning purposes only. *
* - use this code in your own Operating System development. *
* - distribute any code that you produce pertaining to this code *
* as long as it is for learning purposes only, not for profit, *
* and you give credit where credit is due. *
* *
* You may NOT: *
* - distribute this code for any purpose other than listed above. *
* - distribute this code for profit. *
* *
* You MUST: *
* - include this whole comment block at the top of this file. *
* - include contact information to where the original source is located. *
* https://github.com/fysnet/i440fx *
* *
* DESCRIPTION: *
* main source file *
* *
* BUILT WITH: NewBasic Assembler *
* http://www.fysnet/newbasic.htm *
* NBASM ver 00.27.14 *
* Command line: nbasm i440fx /z<enter> *
* *
* Last Updated: 3 jan 2025 *
* *
****************************************************************************
* Notes: *
* *
* Todo: *
* - at the comment below, where we check the memory, create the E820 *
* list of memory. then at the E820 service call, simply choose the *
* correct entry in the list. *
* - add usb drives to the drive emulation *
* - pci *
* - bochs graphic boot screen *
* - should check for 586+ (but won't be able to print if not)(beep???) *
* - *
* *
* *
***************************************************************************|
.model tiny
include 'i440fx.inc'
outfile 'i440fx.bin'
.code
.if DO_INIT_BIOS32
.586 ; the i440fx is a Pentium+, so 586 would be okay here (required for DO_INIT_BIOS32 == 1)
.else
.386P ; Legacy can be 80x386
.endif
; make sure we are using an assembler that supports the new items included here
.if (_VER < 2714h)
%error 1, 'This source requires NBASM version 00.27.14 or higher'
.end ; if we get this error, be done. No need to continue on.
.endif
.rmode
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; we are loaded to 0xE0000
; this address is E000:0000
org 0x00000
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; POST: Main Post entry point
; this address is E000:0000
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; setup our segments
mov ax,0xE000 ; ds = this segment
mov ds,ax ;
xor ax,ax ; es and ss = 0x0000
mov es,ax ;
mov ss,ax ; top of stack at 0000:FFFF
mov sp,ax ; (0x0FFFF)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Check for 386+ machine.
pushf ; save the interrupt bit
push 0F000h ; if bits 15:14 are still set
popf ; after pushing/poping to/from
pushf ; the flags register then we have
pop ax ; a 386+
and ax,0F000h ;
@@: jz short @b ; it's not a 386+
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; since we have a working conio that uses int 10h
; fairly early in the initialization, we need to
; set INT 10h to simply iret until we initialize
; the video rom.
mov ax,0x10 ; interrtupt 10h
mov bx,offset int10_handler
mov cx,BIOS_BASE
call set_int_vector
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Reset and initialize the DMA controller(s)
xor ax,ax
out PORT_DMA1_MASTER_CLEAR,al
out PORT_DMA2_MASTER_CLEAR,al
mov al,0xC0
out PORT_DMA2_MODE_REG,al
xor al,al
out PORT_DMA2_MASK_REG,al
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Depending on the Shutdown status, we need to
; possibly skip certian items.
; Get the current status, and reset it for next time
mov ah,0x0F
call cmos_get_byte
mov bl,al ; save the shutdown status in BL
mov ax,0x0F00
call cmos_put_byte
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if status was 0x00 or 0x0D and above, do normal post
cmp bl,0x00
je short normal_post
cmp bl,0x0D
jae short normal_post
; if status was 0x05, use the eoi and the jmp 0040:0067
cmp bl,0x05
je short eoi_jmp_post
; if status was 0x0A, use the jmp at 0040:0067
cmp bl,0x0A
je short jmp_post
; if status was 0x0B, use the iret at 0040:0067
cmp bl,0x0B
je short iret_post
; if status was 0x0C, use the retf at 0040:0067
cmp bl,0x0C
je short retf_post
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; else, it is a status we don't know about.
; give an error and halt.
mov ax,BIOS_BASE2
mov ds,ax
xor bh,bh
push bx
mov si,offset unknown_shutdown
call bios_printf
add sp,2
; freeze
call freeze
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; POST: various POST functions
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; do EOI and then jmp from 0040:0067h
eoi_jmp_post:
call init_pic
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; jmp from 0040:0067h
jmp_post: xor ax,ax
mov ds,ax
jmp far [0x0467]
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; iret from 0040:0067h
iret_post: xor ax,ax
mov ds,ax
mov sp,[0x0467]
mov ss,[0x0469]
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; retf from 0040:0067h
retf_post: xor ax,ax
mov ds,ax
mov sp,[0x0467]
mov ss,[0x0469]
retf
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; do a s3 post
s3_post: ;mov sp,0x0FFE
.if DO_INIT_BIOS32
call rombios32_init
; we can now write to 0x000E0000->0x000FFFFF
.endif
call s3_resume
xor bl,bl
and ax,ax
jz short normal_post
mov ax,BIOS_BASE2
mov ds,ax
mov si,offset s3_resume_error
call bios_printf
;add sp,2
call freeze
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; do a normal post bootup
; shutdown status is in BL
; cs = 0xE000
; ds = 0xE000
; es = 0x0000
; ss = 0x0000
; sp = 0x0000 (first push at 0x0000:FFFE)
normal_post:
cli
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; use unreal mode for fs
call unreal_post
; save the shutdown status
mov es:[0x04B0],bl
; if shutdown status == 0xFE, do S2 post
cmp bl,0xFE
je short s3_post
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; clear out the BDA (0x0040:0000 - > 0x0040:00FF)
mov cx,128 ; 128 words
xor ax,ax
mov di,0x0400
cld
rep
stosw
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the IVT
call post_init_ivt
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; base memory size
mov ax,BASE_MEM_IN_K
mov es:[0x0413],ax
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if we wanted to do a manufacturer's test, this
; is where we would do it
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if we wanted to test the memory, this is where
; we would do it
; if [0x0472] == 0x1234, then skip test
; (however, we cleared that memory a few lines above)
call build_mem_table
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the ebda
call post_init_ebda
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; PIT setup
mov ax,08h
mov bx,offset int08_handler
mov cx,BIOS_BASE
call set_int_vector
mov al,00_11_010_0b ; channel 0, lo/hi, rate generator, binary mode
out PORT_PIT_MODE,al
xor al,al
out PORT_PIT_CHANNEL0,al
out PORT_PIT_CHANNEL0,al
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Keyboard setup
mov ax,09h
mov bx,offset int09_handler
mov cx,0xE000
call set_int_vector
mov ax,16h
mov bx,offset int16_handler
mov cx,0xE000
call set_int_vector
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; BIOS Keyboard flags
xor al,al
mov es:[0x417],al ; keyboard shift flags, set 1
mov es:[0x418],al ; keyboard shift flags, set 2
mov es:[0x419],al ; keyboard alt-numpad work area
mov es:[0x471],al ; keyboard ctrl-break flag
mov es:[0x497],al ; keyboard status flags 4
mov al,0x10
mov es:[0x496],al ; keyboard status flags 3
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Keyboard buffer pointers
mov ax,0x001E
mov es:[0x041A],ax ; head pointer
mov es:[0x041C],ax ; tail pointer
mov es:[0x0480],ax ; start pointer
mov ax,0x003E
mov es:[0x0482],ax ; end pointer
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Initialize the keyboard
call init_keyboard
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; move CMOS equipment byte to BDA
mov bx,es:[0x0410]
mov ah,0x14
call cmos_get_byte
mov bl,al
mov es:[0x0410],bx
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the parallel port(s)
call init_parallel
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the serial port(s)
call init_serial
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the RTC
call init_rtc
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; irq9 (irq2 redirect)
mov ax,71h
mov bx,offset int71_handler
mov cx,BIOS_BASE
call set_int_vector
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; ps2 mouse
mov ax,74h
mov bx,offset int74_handler
mov cx,BIOS_BASE
call set_int_vector
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; irq13 (fpu exception)
mov ax,75h
mov bx,offset int75_handler
mov cx,BIOS_BASE
call set_int_vector
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; int 10 dummy
mov ax,10h
mov bx,offset int10_handler
mov cx,BIOS_BASE
call set_int_vector
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Initialize the PIC
call init_pic
.if DO_INIT_BIOS32
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; here is were we initialize the 32-bit stuff
call rombios32_init
; we can now write to 0x000E0000->0x000FFFFF
.else
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Initialize the PCI
; this is done if we are a legacy only....
call init_pci_bases
call init_pci_irqs
.endif
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; was the ESCD read from the flash memory?
call bios_escd_init
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; scan for the video rom
mov cx,0xC000
mov ax,0xC780
call pnp_scan_rom
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Hack fix: SeaVGABIOS does not setup a video mode
mov dx,0x03D4
xor al,al
out dx,al
inc dx
in al,dx
test al,al
jnz short @f
mov ax,0x0003
int 10h
@@:
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; we can finally print our banner
call put_banner
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the boot vectors
call init_boot_vectors
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the floppy drive(s)
call init_floppy
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the harddrive(s)/cdrom(s)
call init_harddrive
call ata_init
call sata_detect
call ata_detect
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the eltorito/USB boot emulation
call cdemu_init
.if DO_INIT_BIOS32
call usb_disk_init
.endif
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the apm
call pnp_initialize
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; scan for the optional rom(s)
mov cx,0xC800
mov ax,0xE000
call pnp_scan_rom
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; check to see if user pressed the F12 key
sti ; enable interrupts
call interactive_bootkey
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; restore the A20 line (off) and gs and fs limits
;call real_post
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; restore the screen mode
;call display_restore_default
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; we are now ready to boot a device, so call our
; int 19 handler
xor ax,ax
int 19h
mov bx,$
mov ax,0xFF19
unsupported:
push cs
pop ds
push bx
push ax
mov si,offset unsupport_str
call bios_printf
add sp,4
call freeze
unsupport_str db 13,10,'Unsupported break: ax=0x%04X bx=0x%04X',13,10,0
;debugout:
; push ds
; push cs
; pop ds
; push ax
; mov si,offset debugout_str
; call bios_printf
; add sp,2
; pop ds
; ret
;debugout_str db 'Debugout string: 0x%04X',13,10,0
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; general interrupt handlers
.even
int00_handler: ; Division by zero
mov bx,$
mov ax,0
call unsupported
iret
.even
int01_handler: ; Single Step
mov bx,$
mov ax,1
call unsupported
iret
.even
int02_handler: ; NonMaskable
mov bx,$
mov ax,2
call unsupported
iret
.even
int03_handler: ; Break Point
mov bx,$
mov ax,3
call unsupported
iret
.even
int04_handler: ; Overflow
mov bx,$
mov ax,4
call unsupported
iret
.even
int05_handler: ; Bound Fault
mov bx,$
mov ax,5
call unsupported
iret
.even
int06_handler: ; Invalid Opcode
mov bx,$
mov ax,6
call unsupported
;xchg cx,cx
;pop ax ; ip
;pop bx ; cs
;pop cx ; flags
;mov dx,1234h
;xchg cx,cx
;iret
.even
int07_handler: ; Processor extension not available
mov bx,$
mov ax,7
call unsupported
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; remember that in real mode, when an exception of 8 through 15 occurs, int08_handler through int15_handler will be called.
; we could move the interrupts from int08... to int16..., but then a guest using this BIOS won't be able to 'hook' the
; correct handler. Therefore, we have no way of knowing if int 0x0D is a General Protection Fault or INT 13h for disk services...
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; System Timer ISR Entry Point
.even
int08_handler:
sti ; allow interrupts again
push eax
push ds
mov ax,0x40
mov ds,ax
; is it time to turn off drive(s)?
mov al,[0x0040]
or al,al
jz short @f
dec al
mov [0x0040],al
jnz short @f
; turn motor(s) off?
push dx
mov dx,0x03F2
in al,dx
and al,0xCF
out dx,al
pop dx
@@: mov eax,[0x006C] ; get ticks dword
inc eax
; compare eax to one day's worth of timer ticks at 18.2 hz
cmp eax,0x001800B0
jb short @f
; there has been a midnight rollover at this point
xor eax,eax ; zero out counter
inc byte [0x0070] ; increment rollover flag
@@: mov [0x006C],eax ; store new ticks dword
; chain to user timer tick INT 1Ch
int 1Ch
cli
call eoi_master_pic
pop ds
pop eax
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Keyboard Hardware Service Entry Point
.even
int09_handler:
cli
push ax
mov al,0xAD ; disable keyboard
out PORT_PS2_STATUS,al
;mov al,0x0B
;out PORT_PIC_MASTER_CMD,al
;in al,PORT_PIC_MASTER_CMD
;and al,0x02
;jz short int09_finish
in al,PORT_PS2_DATA ; read key from keyboard controller
sti
push es
push ds
pushad
mov ah,0x4F ; allow for keyboard intercept
stc
int 15h
push ax ; push dummy value so our stack is same as REG_xx's
push bp
mov bp,sp
mov REG_AL,al ; adjust the pushed al register
pop bp
pop ax
jnc short int09_done
; check for extended key
push 0x0040
pop ds
cmp al,0xE0
jne short @f
mov al,[0x0096] ; mf2_state |= 0x02
or al,0x02
mov [0x0096],al
jmp short int09_done
@@: ; check for pause key
cmp al,0xE1
jne short @f
mov al,[0x0096] ; mf2_state |= 0x01
or al,0x01
mov [0x0096],al
jmp short int09_done
@@: call int09_function
int09_done:
popad
pop ds
pop es
cli
call eoi_master_pic
; Notify keyboard interrupt complete w/ int 15h, function AX=9102
mov ax,0x9102
int 15h
int09_finish:
mov al,0xAE ; enable keyboard
out PORT_PS2_STATUS,al
pop ax
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
.even
int0A_handler:
mov bx,$
mov ax,0x0A
call unsupported
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
.even
int0B_handler:
mov bx,$
mov ax,0x0B
call unsupported
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
.even
int0C_handler:
mov bx,$
mov ax,0x0C
call unsupported
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
.even
int0D_handler:
mov bx,$
mov ax,0x0D
call unsupported
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Floppy Hardware ISR Entry Point
.even
int0E_handler:
push ax
push dx
mov dx,0x03F4
in al,dx
and al,0xC0
cmp al,0xC0
je short int0e_normal
mov dx,0x03F5
mov al,0x08 ; sense interrupt status
out dx,al
@@: mov dx,0x03F4
in al,dx
and al,0xC0
cmp al,0xC0
jne short @b
@@: mov dx,0x03F5
in al,dx
mov dx,0x03f4
in al,dx
and al,0xC0
cmp al,0xC0
je short @b
int0e_normal:
push ds
xor ax,ax
mov ds,ax
call eoi_master_pic
or byte [0x043E],0x80 ; diskette interrupt has occurred
pop ds
; Notify diskette interrupt complete w/ int 15h, function AX=9101
mov ax,0x9101
int 15h
pop dx
pop ax
iret
.even
int0F_handler:
; For IRQ7 and IRQ15, to check if an IRQ is a real IRQ or a spurious IRQ, we
; check the PIC's ISR. If it's a real IRQ, its corresponding bit will be set,
; and if it's a spurious IRQ it won't be.
push ax
mov al,0x0B
out PORT_PIC_MASTER_CMD,al
in al,PORT_PIC_MASTER_CMD
test al,(1<<7)
pop ax
jz short int0F_handler_1
; if called from the APIC, we don't do the above check
int0F_handler_0:
;
; do whatever we are going to do here...
;
push ax
mov al,0x20
out PORT_PIC_MASTER_CMD,al
pop ax
int0F_handler_1:
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Video Support Service Entry Point
; we don't do anything since the Video BIOS should handle this one
.even
int10_handler:
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Equipment List Service Entry Point
.even
int11_handler:
push ds
mov ax,0x0040
mov ds,ax
mov ax,[0x0010]
pop ds
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Memory Size Service Entry Point
.even
int12_handler:
push ds
mov ax,0x0040
mov ds,ax
mov ax,[0x0013]
pop ds
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Hard drive, CD-ROM, and diskette Service Entry Point
.even
int13_handler:
push es
push ds
pushad
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; all but the floppy want a pointer to EBDA_SEG
push ax
call bios_get_ebda
mov es,ax
pop ax
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; check for an eltorito function
cmp ah,0x4A
jb short @f
cmp ah,0x4D
ja short @f
call int13_eltorito_function
jmp short int13_out
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; check if USB disk emulation is active
; (* dx should not be modified before here *)
.if DO_INIT_BIOS32
@@: call usb_disk_emu_active
or ax,ax
jz short @f
call usb_disk_emu_drive
cmp al,dl
jne short @f
call int13_usb_disk_function
jmp short int13_out
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; check if SATA disk emulation is active
; (* dx should not be modified before here *)
@@: call sata_disk_emu_active
or ax,ax
jz short @f
call sata_disk_emu_drive
cmp al,dl
jne short @f
call int13_satadisk_function
jmp short int13_out
.endif
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; check if cdrom emulation is active
; (* dx should not be modified before here *)
@@: call cdrom_emu_active
or ax,ax
jz short @f
call cdrom_emu_drive
cmp al,dl
jne short @f
call cdrom_emu_function
jmp short int13_out
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; the diskette service comes here
@@: cmp dl,0x80
jae short @f
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; is a floppy diskette
mov ax,0x0040
mov ds,ax
call int13_diskette_function
jmp short int13_out
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; is it a cd-rom
@@: cmp dl,0xE0
jb short @f
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; it is a cdrom
call int13_cdrom_function
jmp short int13_out
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; it is a hard drive
@@: call int13_harddisk_function
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; some old software expects the interrupt flag to
; be active on return from (hard)disk services (dl >= 0x80 only?)
int13_out: push bp
mov bp,sp
or word [bp+42],(1<<9) ; 'REG_FLAGS' minus size of the 'return' that is no longer on the stack
pop bp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; we're done, we can return
popad
pop ds
pop es
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Serial Comm Service Entry Point
.even
int14_handler:
push es
push ds
pushad
mov ax,0x0040
mov ds,ax
call int14_function
popad
pop ds
pop es
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; BIOS Services Entry Point
.even
int15_handler:
push es
push ds
pushad
mov bx,0x40
mov ds,bx
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; 32-bit handler (still real-mode code)
cmp ah,0x86
je short int15_handler32
cmp ah,0xE8
jne short @f
int15_handler32:
call int15_function32
jmp short int15_handler_done
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; mouse services
@@: cmp ah,0xC2
jne short @f
call int15_function_mouse
jmp short int15_handler_done
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; all remaining function calls
@@: call int15_function
int15_handler_done:
popad
pop ds
pop es
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Keyboard Service Entry Point
.even
int16_handler:
sti
push es
push ds
pushad
mov ax,0x40
mov ds,ax
call int16_function
popad
pop ds
pop es
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Printer Service Entry Point
.even
int17_handler:
push es
push ds
pushad
mov ax,0x40
mov ds,ax
call int17_function
popad
pop ds
pop es
iret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Boot Fail Service Entry Point
.even
int18_handler:
; Reset SP and SS
xor ax,ax
mov ss,ax
mov sp,ax
; Get the boot sequence number out of the IPL memory
mov ax,EBDA_SEG
mov ds,ax
mov ax,[EBDA_DATA->ipl_sequence] ; bx is now the sequence number
inc ax ; ++
mov [EBDA_DATA->ipl_sequence],ax ; Write it back