Get rid of pre-tables for interrupts and kprintf
This commit is contained in:
parent
49ae13c73a
commit
0622188353
140
kernel/intr.asm
140
kernel/intr.asm
@ -1,123 +1,23 @@
|
||||
; Data table for interrupts
|
||||
; cs:word for service routine
|
||||
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
|
||||
|
||||
; 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:
|
||||
push ds
|
||||
push es
|
||||
; backup intr 0x0n to 0x4n
|
||||
; Register a interrupt handler
|
||||
; in: sp:bp+0 interrupt number
|
||||
; +2 handler offset
|
||||
; out: sp:bp+4
|
||||
intr_register:
|
||||
; use data stack
|
||||
xchg sp, bp
|
||||
; ES := 0
|
||||
xor ax, ax
|
||||
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
|
||||
mov cx, 0x0020 ; 0x10 vectors, segment:offset each
|
||||
repe movsw
|
||||
; now setup our own handlers (0x0n)
|
||||
mov es, ax
|
||||
; DI := intnum * 4
|
||||
pop di
|
||||
sal di, 1
|
||||
sal di, 1
|
||||
; copy offset from arguments
|
||||
pop ax
|
||||
stosw
|
||||
; copy our segment
|
||||
mov ax, cs
|
||||
mov ds, ax ; read from local segment
|
||||
mov si, intr_table0 ; read from intr_table
|
||||
mov di, 0x0000 ; write to start of IVT table
|
||||
mov cx, 0x0010 ; 0x10 vectors, one offset each
|
||||
.loop0:
|
||||
movsw ; read offset; write offset
|
||||
mov ax,cs
|
||||
stosw ; write segment
|
||||
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
|
||||
pop es
|
||||
pop ds
|
||||
stosw
|
||||
; use code stack
|
||||
xchg sp, bp
|
||||
ret
|
||||
|
||||
irq0:
|
||||
int 0x48
|
||||
or byte [cs:intr_flip], 0x01
|
||||
jmp irqret
|
||||
|
||||
irq1:
|
||||
int 0x49
|
||||
or byte [cs:intr_flip], 0x02
|
||||
jmp irqret
|
||||
|
||||
irq2:
|
||||
int 0x4A
|
||||
or byte [cs:intr_flip], 0x04
|
||||
jmp irqret
|
||||
|
||||
irq3:
|
||||
int 0x4B
|
||||
or byte [cs:intr_flip], 0x08
|
||||
jmp irqret
|
||||
|
||||
irq4:
|
||||
int 0x4C
|
||||
or byte [cs:intr_flip], 0x10
|
||||
jmp irqret
|
||||
|
||||
irq5:
|
||||
int 0x4D
|
||||
or byte [cs:intr_flip], 0x20
|
||||
jmp irqret
|
||||
|
||||
irq6:
|
||||
int 0x4E
|
||||
or byte [cs:intr_flip], 0x40
|
||||
jmp irqret
|
||||
|
||||
irq7:
|
||||
int 0x4F
|
||||
or byte [cs:intr_flip], 0x80
|
||||
jmp irqret
|
||||
|
||||
hwiret:
|
||||
mov al,20h
|
||||
out 20h,al
|
||||
irqret:
|
||||
iret:
|
||||
iret
|
@ -1,140 +0,0 @@
|
||||
; important functions in this file: kprintf
|
||||
|
||||
; write a character to kernel output
|
||||
; in: al
|
||||
kputc:
|
||||
push ax
|
||||
push bx
|
||||
mov bx, 0x0000
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
pop bx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; write a string to kernel output
|
||||
; in: ds:di
|
||||
kputs:
|
||||
push ax
|
||||
.loop:
|
||||
lodsb
|
||||
cmp al,0x00
|
||||
je .end
|
||||
call kputc
|
||||
jmp .loop
|
||||
.end:
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; prints a nibble in hex
|
||||
; in: al
|
||||
kprint4:
|
||||
and al, 0x0F
|
||||
add al, 0x30
|
||||
cmp al, 0x3a
|
||||
jl kputc
|
||||
add al, 0x07
|
||||
jmp kputc
|
||||
|
||||
; print a byte
|
||||
; in: al
|
||||
kprint8:
|
||||
push ax ; avoid destroying ah
|
||||
aam 16 ; high nibble moved into ah
|
||||
xchg ah,al ; high nibble first
|
||||
call kprint4
|
||||
xchg ah,al
|
||||
call kprint4
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; print a word
|
||||
; in: ax
|
||||
kprint16:
|
||||
xchg ah,al
|
||||
call kprint8
|
||||
xchg ah,al
|
||||
call kprint8
|
||||
ret
|
||||
|
||||
; read a word from the stack, using bp as stack pointer
|
||||
; in: bp
|
||||
; out: ax, bp
|
||||
kprintf_lodsw:
|
||||
push ds ; work segment for lodsw
|
||||
push si ; work pointer for lodsw
|
||||
push ss ; data transfer to ds
|
||||
pop ds
|
||||
mov si,bp
|
||||
lodsw
|
||||
mov bp,si ; write back incremented value
|
||||
pop si
|
||||
pop ds
|
||||
ret
|
||||
|
||||
; print data from stack
|
||||
; in: ds:si, ss:sp
|
||||
kprintf:
|
||||
push ax
|
||||
push bp ; state variable for stack lodsw
|
||||
push si ; return original pointer to caller
|
||||
mov ax, sp
|
||||
add ax, 0x08
|
||||
mov bp, ax
|
||||
.loop:
|
||||
lodsb
|
||||
cmp al,0x00
|
||||
je .end
|
||||
cmp al,0x25 ; '%'
|
||||
je .fseq
|
||||
call kputc
|
||||
jmp .loop
|
||||
.end:
|
||||
pop si
|
||||
pop bp
|
||||
mov al,0x0A
|
||||
call kputc
|
||||
mov al,0x0D
|
||||
call kputc
|
||||
pop ax
|
||||
ret
|
||||
.fseq:
|
||||
lodsb
|
||||
cmp al,0x00
|
||||
je .end
|
||||
cmp al,0x25 ; '%'
|
||||
je .fmt_pc
|
||||
cmp al,0x63 ; 'c'
|
||||
je .fmt_c
|
||||
cmp al,0x73 ; 's'
|
||||
je .fmt_s
|
||||
cmp al,0x78 ; 'x'
|
||||
je .fmt_x
|
||||
cmp al,0x58 ; 'X'
|
||||
je .fmt_X
|
||||
mov al,0x3F ; '?'
|
||||
call kputc
|
||||
jmp .loop
|
||||
.fmt_pc:
|
||||
mov al,0x25
|
||||
call kputc
|
||||
jmp .loop
|
||||
.fmt_c:
|
||||
call kprintf_lodsw
|
||||
call kputc
|
||||
jmp .loop
|
||||
.fmt_s:
|
||||
push si
|
||||
call kprintf_lodsw
|
||||
mov si,ax
|
||||
call kputs
|
||||
pop si
|
||||
jmp .loop
|
||||
.fmt_x:
|
||||
call kprintf_lodsw
|
||||
call kprint8
|
||||
jmp .loop
|
||||
.fmt_X:
|
||||
call kprintf_lodsw
|
||||
call kprint16
|
||||
jmp .loop
|
@ -5,13 +5,6 @@ optrom_length:
|
||||
db 0x00
|
||||
jmp optrom_init
|
||||
|
||||
str_vendor:
|
||||
db "Nero", 0
|
||||
|
||||
align 16
|
||||
str_product:
|
||||
db "Nero DOS", 0
|
||||
|
||||
times (0x1A - ($-$$)) db 0
|
||||
dw pnp
|
||||
|
||||
@ -36,13 +29,13 @@ pnp:
|
||||
|
||||
align 16
|
||||
optrom_init:
|
||||
xor ax, ax
|
||||
mov es, ax
|
||||
mov di, 0x0060 ; vector (0x18 * 4 bytes)
|
||||
mov ax, start
|
||||
stosw
|
||||
mov ax, cs
|
||||
stosw
|
||||
; setup data stack below code stack
|
||||
mov bp, sp
|
||||
sub bp, 0x80
|
||||
; intnum and offset to data stack
|
||||
mov word [ss:bp], 0x18
|
||||
mov word [ss:bp+2], start
|
||||
call intr_register
|
||||
retf
|
||||
|
||||
putc:
|
||||
@ -57,6 +50,8 @@ putc:
|
||||
|
||||
announce:
|
||||
push cs
|
||||
mov ax, cs
|
||||
mov ds, ax
|
||||
mov ax, str_product
|
||||
push ax
|
||||
call printf
|
||||
@ -65,42 +60,26 @@ announce:
|
||||
ret
|
||||
|
||||
start:
|
||||
mov ax, cs
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
; setup code + data stack
|
||||
mov ss, ax
|
||||
mov sp, ax
|
||||
mov bp, sp
|
||||
; data stack starts 512 bytes below code stack
|
||||
sub bp, 0x200
|
||||
|
||||
call announce
|
||||
|
||||
; clear memory until 0x01000
|
||||
xor ax, ax
|
||||
mov es, ax
|
||||
mov di, 0x500
|
||||
mov cx, 0xB00
|
||||
rep stosb
|
||||
sub bp, 4
|
||||
mov word [ss:bp], 3
|
||||
mov word [ss:bp+2], isr_debug
|
||||
call intr_register
|
||||
|
||||
call intr_init
|
||||
sti
|
||||
|
||||
sub sp, 0x10
|
||||
mov si, sp
|
||||
mov word [ss:si+0x00], 0
|
||||
mov word [ss:si+0x02], 1
|
||||
mov word [ss:si+0x04], 0
|
||||
mov word [ss:si+0x06], 0x2000
|
||||
mov word [ss:si+0x08], 0x07fc
|
||||
mov word [ss:si+0x0A], 0
|
||||
mov word [ss:si+0x0C], 0
|
||||
mov word [ss:si+0x0E], 0
|
||||
mov ah, 0x42
|
||||
|
||||
push ss
|
||||
pop ds
|
||||
call ramdisk_io
|
||||
push ax
|
||||
call printf
|
||||
db "AX=%X", 0x0A, 0x0D, 0x00
|
||||
pop ax
|
||||
|
||||
add sp, 0x10
|
||||
int 3
|
||||
|
||||
.halt:
|
||||
hlt
|
||||
@ -111,9 +90,5 @@ start:
|
||||
|
||||
%include "intr.asm"
|
||||
%include "debug.asm"
|
||||
%include "kprintf.asm"
|
||||
%include "dosapi.asm"
|
||||
|
||||
_reloc_end:
|
||||
|
||||
align 512
|
Loading…
Reference in New Issue
Block a user