2019-04-10 00:38:20 +02:00
|
|
|
; Data table for interrupts
|
|
|
|
; cs:word for service routine
|
2019-04-14 21:35:55 +02:00
|
|
|
intr_table0:
|
|
|
|
dw iret ; 00 Divide by Zero
|
|
|
|
dw iret ; 01 Single Step
|
|
|
|
dw iret ; 02 Parity error routine (NMI)
|
|
|
|
dw debug_reg_ir ; 03 Break
|
|
|
|
dw iret ; 04 Overflow
|
|
|
|
dw iret ; 05 Print Screen
|
|
|
|
dw iret ; 06 Mouse button control
|
|
|
|
dw isr_dosmain ; 07 Reserved
|
|
|
|
dw irq0 ; 08 System Clock interrupt
|
|
|
|
dw irq1 ; 09 Keyboard interrupt
|
|
|
|
dw irq2 ; 0a RTC interrupt
|
|
|
|
dw irq3 ; 0b COMMS
|
|
|
|
dw irq4 ; 0c COMMS
|
|
|
|
dw irq5 ; 0d Hard Disk
|
|
|
|
dw irq6 ; 0e Floppy Disk interrupt routine
|
|
|
|
dw irq7 ; 0f Printer interrupt
|
|
|
|
intr_table2:
|
|
|
|
dw iret ; 20
|
|
|
|
dw isr_dosmain ; 21
|
|
|
|
dw iret ; 22
|
|
|
|
dw iret ; 23
|
|
|
|
dw iret ; 24
|
|
|
|
dw iret ; 25
|
|
|
|
dw iret ; 26
|
|
|
|
dw iret ; 27
|
|
|
|
dw iret ; 28
|
|
|
|
dw iret ; 29
|
|
|
|
dw iret ; 2a
|
|
|
|
dw iret ; 2b
|
|
|
|
dw iret ; 2c
|
|
|
|
dw iret ; 2d
|
|
|
|
dw iret ; 2e
|
|
|
|
dw iret ; 2f
|
2019-04-10 00:38:20 +02:00
|
|
|
|
|
|
|
; LSB is IRQ0, MSB is IRQ16
|
|
|
|
; A IRQ will set their bit to 1, so userspace may poll it via wait_irq
|
|
|
|
intr_flip:
|
|
|
|
dw 0
|
|
|
|
|
|
|
|
intr_init:
|
2019-03-24 18:59:03 +01:00
|
|
|
push ds
|
2019-03-31 22:54:51 +02:00
|
|
|
push es
|
2019-04-10 00:38:20 +02:00
|
|
|
; backup intr 0x0n to 0x4n
|
2019-03-31 22:54:51 +02:00
|
|
|
xor ax, ax
|
2019-04-10 00:38:20 +02:00
|
|
|
mov ds, ax ; read from IVT
|
|
|
|
mov es, ax ; write to IVT
|
|
|
|
mov si, ax ; read from start of IVT table
|
|
|
|
mov di, 0x0100 ; write to offset of int 0x40 address
|
2019-04-14 17:30:29 +02:00
|
|
|
mov cx, 0x0020 ; 0x10 vectors, segment:offset each
|
2019-03-31 22:54:51 +02:00
|
|
|
repe movsw
|
2019-04-14 21:35:55 +02:00
|
|
|
; now setup our own handlers (0x0n)
|
2019-04-10 00:38:20 +02:00
|
|
|
mov ax, cs
|
|
|
|
mov ds, ax ; read from local segment
|
2019-04-14 21:35:55 +02:00
|
|
|
mov si, intr_table0 ; read from intr_table
|
2019-04-10 00:38:20 +02:00
|
|
|
mov di, 0x0000 ; write to start of IVT table
|
2019-04-14 17:30:29 +02:00
|
|
|
mov cx, 0x0010 ; 0x10 vectors, one offset each
|
2019-04-14 21:35:55 +02:00
|
|
|
.loop0:
|
|
|
|
movsw ; read offset; write offset
|
2019-04-10 00:38:20 +02:00
|
|
|
mov ax,cs
|
|
|
|
stosw ; write segment
|
2019-04-14 21:35:55 +02:00
|
|
|
loop .loop0
|
|
|
|
; second vector block (0x2n)
|
|
|
|
mov si, intr_table2 ; read from intr_table
|
|
|
|
mov di, 0x0080 ; write to int 20h vector and above
|
|
|
|
mov cx, 0x0010 ; 0x10 vectors, one offset each
|
|
|
|
.loop2:
|
|
|
|
movsw ; read offset; write offset
|
|
|
|
mov ax,cs
|
|
|
|
stosw ; write segment
|
|
|
|
loop .loop2
|
2019-03-31 22:54:51 +02:00
|
|
|
pop es
|
2019-03-24 18:59:03 +01:00
|
|
|
pop ds
|
|
|
|
ret
|
|
|
|
|
2019-04-10 00:38:20 +02:00
|
|
|
irq0:
|
|
|
|
int 0x48
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x01
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
|
|
|
|
|
|
|
irq1:
|
|
|
|
int 0x49
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x02
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
2019-03-14 17:17:02 +01:00
|
|
|
|
2019-04-10 00:38:20 +02:00
|
|
|
irq2:
|
|
|
|
int 0x4A
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x04
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
2019-03-14 17:17:02 +01:00
|
|
|
|
2019-04-10 00:38:20 +02:00
|
|
|
irq3:
|
|
|
|
int 0x4B
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x08
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
2019-03-14 17:17:02 +01:00
|
|
|
|
2019-04-10 00:38:20 +02:00
|
|
|
irq4:
|
|
|
|
int 0x4C
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x10
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
2019-03-14 17:17:02 +01:00
|
|
|
|
2019-04-10 00:38:20 +02:00
|
|
|
irq5:
|
|
|
|
int 0x4D
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x20
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
|
|
|
|
|
|
|
irq6:
|
|
|
|
int 0x4E
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x40
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
|
|
|
|
|
|
|
irq7:
|
|
|
|
int 0x4F
|
2019-04-16 09:23:22 +02:00
|
|
|
or byte [cs:intr_flip], 0x80
|
2019-04-10 00:38:20 +02:00
|
|
|
jmp irqret
|
|
|
|
|
|
|
|
hwiret:
|
|
|
|
mov al,20h
|
|
|
|
out 20h,al
|
|
|
|
irqret:
|
|
|
|
iret:
|
|
|
|
iret
|