Get rid of pre-tables for interrupts and kprintf

This commit is contained in:
Nero 2019-05-02 20:14:31 +00:00
parent 49ae13c73a
commit 0622188353
3 changed files with 43 additions and 308 deletions

View File

@ -1,123 +1,23 @@
; Data table for interrupts ; Register a interrupt handler
; cs:word for service routine ; in: sp:bp+0 interrupt number
intr_table0: ; +2 handler offset
dw iret ; 00 Divide by Zero ; out: sp:bp+4
dw iret ; 01 Single Step intr_register:
dw iret ; 02 Parity error routine (NMI) ; use data stack
dw debug_reg_ir ; 03 Break xchg sp, bp
dw iret ; 04 Overflow ; ES := 0
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
xor ax, ax xor ax, ax
mov ds, ax ; read from IVT mov es, ax
mov es, ax ; write to IVT ; DI := intnum * 4
mov si, ax ; read from start of IVT table pop di
mov di, 0x0100 ; write to offset of int 0x40 address sal di, 1
mov cx, 0x0020 ; 0x10 vectors, segment:offset each sal di, 1
repe movsw ; copy offset from arguments
; now setup our own handlers (0x0n) pop ax
stosw
; copy our segment
mov ax, cs mov ax, cs
mov ds, ax ; read from local segment stosw
mov si, intr_table0 ; read from intr_table ; use code stack
mov di, 0x0000 ; write to start of IVT table xchg sp, bp
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
ret 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

View File

@ -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

View File

@ -5,13 +5,6 @@ optrom_length:
db 0x00 db 0x00
jmp optrom_init jmp optrom_init
str_vendor:
db "Nero", 0
align 16
str_product:
db "Nero DOS", 0
times (0x1A - ($-$$)) db 0 times (0x1A - ($-$$)) db 0
dw pnp dw pnp
@ -36,13 +29,13 @@ pnp:
align 16 align 16
optrom_init: optrom_init:
xor ax, ax ; setup data stack below code stack
mov es, ax mov bp, sp
mov di, 0x0060 ; vector (0x18 * 4 bytes) sub bp, 0x80
mov ax, start ; intnum and offset to data stack
stosw mov word [ss:bp], 0x18
mov ax, cs mov word [ss:bp+2], start
stosw call intr_register
retf retf
putc: putc:
@ -57,6 +50,8 @@ putc:
announce: announce:
push cs push cs
mov ax, cs
mov ds, ax
mov ax, str_product mov ax, str_product
push ax push ax
call printf call printf
@ -65,42 +60,26 @@ announce:
ret ret
start: start:
mov ax, cs xor ax, ax
mov ds, 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 call announce
; clear memory until 0x01000 sub bp, 4
xor ax, ax mov word [ss:bp], 3
mov es, ax mov word [ss:bp+2], isr_debug
mov di, 0x500 call intr_register
mov cx, 0xB00
rep stosb
call intr_init
sti sti
sub sp, 0x10 int 3
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
.halt: .halt:
hlt hlt
@ -111,9 +90,5 @@ start:
%include "intr.asm" %include "intr.asm"
%include "debug.asm" %include "debug.asm"
%include "kprintf.asm"
%include "dosapi.asm"
_reloc_end:
align 512 align 512