From e2d244a919ea926141cee5ae23513df54f018e30 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Tue, 14 Dec 2021 17:46:22 +0000 Subject: [PATCH] remove bios roms --- Makefile | 23 +-- rom/dprintf.asm | 159 ------------------- rom/uartctrl.asm | 394 ----------------------------------------------- 3 files changed, 4 insertions(+), 572 deletions(-) delete mode 100644 rom/dprintf.asm delete mode 100644 rom/uartctrl.asm diff --git a/Makefile b/Makefile index 96f75c8..17780ad 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,11 @@ PROGRAMS = hello.com sys.com KERNEL = @rdos.com DISTFILES = $(KERNEL) $(PROGRAMS) -ROMS = VERSION = $(shell git log -1 --format=%cd --date=format:%Y%m%d) PRODUCT = rdos QEMU = qemu-system-i386 -QEMU_ARGS = $(addprefix --option-rom ,$(ROMS)) QEMU_ARGS += $(shell test -w /dev/kvm && echo --enable-kvm) METRIC = stat -c '%8s %n' @@ -15,17 +13,11 @@ METRIC = stat -c '%8s %n' NASM = nasm NASM_ARGS = -s -Isrc --before "cpu 8086" -DPRODUCT=$(PRODUCT) -DVERSION=$(VERSION) -ifdef DEBUG -ROMS += dprintf.rom -NASM_ARGS += -l $(basename $@).lst -DDEBUG=1 -endif - ifndef DISPLAY QEMU_ARGS += --display curses endif SYS = host/sys.elf -FIXROM = host/fix-rom.elf .PHONY: default clean qemu-floppy5 qemu-floppy3 .PRECIOUS: %.com @@ -57,10 +49,6 @@ fat4.bs: boot/fat.asm fat6.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT16 -DCHS -DLARGE -o $@ $< -# BIOS option roms -%.rom: rom/%.asm $(FIXROM) - $(NASM) $(NASM_ARGS) -o $@ $< && $(FIXROM) $@ - fd%.img: $(DISTFILES) $(SYS) mformat -C -i $@ -f $* -v "$(PRODUCT) $(VERSION)" :: mcopy -i $@ $(DISTFILES) :: @@ -72,21 +60,18 @@ hdd.img: mbr.bs $(KERNEL) fd1440.img dd if=fd1440.img bs=512 seek=63 of=$@ clean: - rm -f *.com *.bs *.0 *.lst *.img *.bin *.rom + rm -f *.com *.bs *.0 *.lst *.img *.bin rm -f host/*.elf -qemu-floppy3: fd1440.img $(ROMS) +qemu-floppy3: fd1440.img $(QEMU) $(QEMU_ARGS) -boot a -fda fd1440.img -qemu-floppy5: fd360.img $(ROMS) +qemu-floppy5: fd360.img $(QEMU) $(QEMU_ARGS) -boot a -fda fd360.img -qemu-hdd: hdd.img $(ROMS) +qemu-hdd: hdd.img $(QEMU) $(QEMU_ARGS) -boot c -hda hdd.img -qemu-uartctrl: uartctrl.rom chartab.bs - $(QEMU) $(QEMU_ARGS) -option-rom uartctrl.rom -serial stdio -hda chartab.bs - dosbox-%: %.com fd1440.img dosbox -c "mount P $(CURDIR)" -c P: -c "IMGMOUNT A: FD1440.IMG -t floppy" -c "$< $(ARGS)" -c pause -c exit diff --git a/rom/dprintf.asm b/rom/dprintf.asm deleted file mode 100644 index b781fbb..0000000 --- a/rom/dprintf.asm +++ /dev/null @@ -1,159 +0,0 @@ - cpu 8086 - org 0x0000 - - db 0x55, 0xAA - db 0x00 - jmp init - nop - - times (0x18 - ($-$$)) db 0 - dw 0 - dw pnp - -pnp: db "$PnP" - db 1 ; version 1 - db 2 ; 2 * 16 length - dw 0 ; offset of next header - db 0 - db 0 ; checksum (filled by fix-rom) - dd 0 ; device identifier - dw 0 ; manufacturer string - dw name ; product name string - db 0,0,0 ; device type string - db 0x20 ; device indicator, bit for "read cacheable" set - dw 0 ; boot connection vector - dw 0 ; boot disconnect vector - dw 0 ; bootstrap entry point - dw 0 ; reserved - dw 0 - -name: db "dprintf" - -init: push ds - push ax - xor ax, ax - mov ds, ax - - mov word [1*4], int3entry - mov word [1*4+2], cs - mov word [3*4], int3entry - mov word [3*4+2], cs - - pop ax - pop ds - retf - -crlf: xor bx, bx - mov ax, 0x0e0a - int 0x10 - mov al, 0x0d - int 0x10 - ret - -printr: mov al, cl - int 0x10 - mov al, ch - int 0x10 - mov al, '=' - int 0x10 - call printd - mov al, ' ' - int 0x10 - ret - -printd: mov cl, 4 - ; this double-call is essentially a 4 times repeating loop - call .c1 -.c1: call .c2 -.c2: ; grab highest nibble from dx - mov al, dh - ; remove highest nibble from dx - shl dx, cl - ; shift away second-highest nibble that we accidentally copied - shr al, cl - ; map 0-9 to ascii codes for '0' to '9' - add al, 0x30 - ; if result is larger than '9', ... - cmp al, 0x3a - jl .noadj - ; ... add 7 so we continue at 'A' - add al, 7 -.noadj: int 0x10 - ret - -int3entry: - push bx - push dx - push cx - push ax - push bp - mov bp, sp - - call crlf - - xor bx, bx - mov ah, 0x0e - mov cx, 'AX' - mov dx, [bp+2] - call printr - - mov cx, 'CX' - mov dx, [bp+4] - call printr - - mov cx, 'DX' - mov dx, [bp+6] - call printr - - mov cx, 'BX' - mov dx, [bp+8] - call printr - - mov cx, 'BP' - mov dx, [bp] - call printr - - mov cx, 'SP' - lea dx, [bp+16] - call printr - - mov cx, 'SI' - mov dx, si - call printr - - mov cx, 'DI' - mov dx, di - call printr - - call crlf - - mov cx, 'ES' - mov dx, es - call printr - - mov cx, 'CS' - mov dx, [bp+12] - call printr - - mov cx, 'SS' - mov dx, ss - call printr - - mov cx, 'DS' - mov dx, ds - call printr - - mov cx, 'IP' - mov dx, [bp+10] - call printr - - call crlf - - pop bp - pop ax - pop cx - pop dx - pop bx - iret - -align 512 diff --git a/rom/uartctrl.asm b/rom/uartctrl.asm deleted file mode 100644 index ae0ced3..0000000 --- a/rom/uartctrl.asm +++ /dev/null @@ -1,394 +0,0 @@ - cpu 8086 - org 0x0000 - - ; configuration for the uart chip for i/o -%define uart 0x3F8 -%define irq 4 -%define clock 115200 -%define baud 9600 - -%ifndef CODEPAGE -%define CODEPAGE 437 -%endif - -data equ (uart + 0) ; data register -ier equ (uart + 1) -fcr equ (uart + 2) -isr equ (uart + 2) -lcr equ (uart + 3) -mcr equ (uart + 4) -lsr equ (uart + 5) ; line status register -msr equ (uart + 6) - -absolute 0xE0 ; data in bios data area -pstate resw 1 ; parser resume offset -parg resb 1 ; accumulator for numerical CSI arguments -curcs resb 1 ; current charset we put remote term in -section .text - - db 0x55, 0xAA - db 0x00 - jmp init - -%defstr uart_s uart -%defstr baud_s baud -banner db "nero uartctrl: port ", uart_s, " irq ", irq + 0x30," baud ", baud_s, 0x0A, 0x0D, 0 - -init push ax - push dx - push bx - push si - push ds - - ; set dlab - mov dx, lcr - in al, dx - or al, 0x80 - out dx, al - ; set divisor - mov cx, (clock / baud) - ; low byte - mov dx, (uart + 0) - mov al, cl - out dx, al - ; high byte - mov dx, (uart + 1) - mov al, ch - out dx, al - ; disable dlab - mov dx, lcr - in al, dx - and al, 0x7F - out dx, al - ; disable fifo - mov dx, fcr - mov al, 0 - out dx, al - ; enable RX interrupt - mov dx, ier - mov al, 1 - out dx, al - ; set line modes (8 bits, no parity, 1 stopbit) - mov dx, lcr - mov al, 3 - out dx, al - ; set modem control lines (unused) - mov dx, mcr - mov al, 8 - out dx, al - - ; DS = interrupt table - xor ax, ax - mov ds, ax - - ; hook video services - ; keep original ptr in intvec 47h for chaining - mov ax, int10 - mov bx, cs - xchg word [4*0x10], ax - xchg word [4*0x10+2], bx - mov word [4*0x47], ax - mov word [4*0x47+2], bx - - ; reset parser state - mov word [0x400+pstate], parse.start - - ; hook uart irq - mov word [4*(0x08+irq)], intu - mov word [4*(0x08+irq)+2], cs - - ; enable IRQ in PIC - mov dx, 0x21 - in al, dx - and al, ~(1 << irq) - out dx, al - - call greet - - pop ds - pop si - pop bx - pop dx - pop ax - retf - -greet mov si, banner - xor bx, bx -.loop mov al, [cs:si] - test al, al - jz .exit - mov ah, 0x0e - int 0x10 - inc si - jmp .loop -.exit ret - -putc mov ah, al - ; check if transmit buffer empty -.l01 mov dx, lsr - in al, dx - test al, 0x20 - jz .l01 - mov al, ah - ; send char to uart - mov dx, data - out dx, al - ret - - ; set charset - ; IN AL '0', 'A' or 'B' -setcs test al, al - jz .fret - push ds - ; set DS - mov dx, 0x40 - mov ds, dx - cmp al, [curcs] - je .ret - mov [curcs], al - mov al, 0x1B - call putc - mov al, '(' - call putc - mov al, [curcs] - call putc -.ret pop ds -.fret ret - -pdx: ; this double-call is essentially a 4 times repeating loop - call .l1 -.l1: call .l2 -.l2: ; set up cl for bit shifts - mov cl, 4 - ; grab highest nibble from dx - mov al, dh - ; remove highest nibble from dx - shl dx, cl - ; shift away second-highest nibble that we accidentally copied - shr al, cl - ; map 0-9 to ascii codes for '0' to '9' - add al, 0x30 - ; if result is larger than '9', ... - cmp al, 0x3a - jl pputc - ; ... add 7 so we continue at 'A' - add al, 7 -pputc mov ah, 0x0e - xor bx, bx - int 0x10 - ret - - ; video services -int10 cmp ah, 0x0e - jne .chain - - push bx - push dx - push ax - ; activate character set for current char - mov bx, csmap - cs xlatb - call setcs - pop ax - push ax - ; look up what we need to write out - mov bx, ecmap - cs xlatb - call putc - - pop ax - pop dx - pop bx - -.chain sub sp, 4 - push bp - mov bp, sp - ; stack: BP IP:CS IP:CS FL - - push ax - push ds - - xor ax, ax - mov ds, ax - ; copy offset - mov ax, [4*0x47] - mov [bp+2], ax - ; copy segment - mov ax, [4*0x47+2] - mov [bp+4], ax - - pop ds - pop ax - - pop bp - retf - - - ; uart controller irq -intu push ax - push dx - ; check if we controller has data ready - mov dx, isr - in al, dx - and al, 0xF - cmp al, 4 - jne ugetc.ret - ; set DS to bios data area - push bx - push ds - mov ax, 0x40 - mov ds, ax - ; receive data - mov dx, data - in al, dx - jmp near [pstate] ; load parser state -ugetc pop word [pstate] ; save parser state - pop ds - pop bx - ; send non-specific EOI signal -.ret mov al, 0x20 - out 0x20, al - pop dx - pop ax - iret - - ; parse loop - ; this is called from inside the uart interrupt - ; only call ugetc when nothing on stack, so no nested funcs -parse call ugetc -.start cmp al, 0x1B - je .esc - cmp al, 0x7F - je .bs -.ascii mov dl, al - mov bx, kmap - cs xlatb - mov dh, al - ; insert key code into buffer in bios data area -.insert mov bx, [0x1C] ; get next empty slot - mov [bx], dx ; store key code - add bx, 2 - cmp bx, 0x3E ; are we beyond last pos? - jc .nowrap - mov bx, 0x1E ; first position -.nowrap cmp bx, [0x1A] ; next to-read slot - je parse - mov [0x1C], bx ; commit if not full - jmp parse -.bs mov dx, 0x0E08 - jmp .insert -.esc call ugetc - cmp al, 0x5B - je .csi - cmp al, 'O' - je .vt_o - jmp parse -.csi mov byte [parg], 0 ; reset argument -.csicon call ugetc ; number parsing - cmp al, 0x30 - jc parse - cmp al, 0x3A - jnc .nonum - sub al, 0x30 - mov dl, al - mov al, 0xA - mul byte [parg] - add al, dl - mov [parg], al - jmp .csicon -.nonum cmp al, '~' ; \e[...$c handling - jne .letter - mov al, [parg] ; \e[$n~ lookup $n - mov bx, fkeysn - jmp .lookup -.vt_o call ugetc ; VT100 \eO... sequences -.letter sub al, 0x40 ; look up special key by letter - mov bx, fkeysc -.lookup cmp al, 0x40 ; special key lookup, bx assumed - jnc parse - cs xlatb - cmp al, 0 - je parse - mov dh, al - mov dl, 0 - jmp .insert - - align 128 - - ; ascii -> XT scancode map -%if CODEPAGE = 437 - ; US Keyboard layout -kmap db 0x00,0x1E,0x30,0x2E, 0x20,0x12,0x21,0x22, 0x23,0x0F,0x24,0x25, 0x26,0x1C,0x31,0x18 - db 0x19,0x10,0x13,0x1F, 0x14,0x16,0x2F,0x11, 0x2D,0x15,0x2C,0x01, 0x2B,0x1B,0x07,0x0C - - db 0x39,0x02,0x03,0x04, 0x05,0x06,0x08,0x28, 0x0A,0x0B,0x09,0x0D, 0x33,0x0C,0x34,0x35 - db 0x0B,0x02,0x03,0x04, 0x05,0x06,0x07,0x08, 0x09,0x0A,0x27,0x27, 0x33,0x0D,0x34,0x35 - - db 0x03,0x1E,0x30,0x2E, 0x20,0x12,0x21,0x22, 0x23,0x17,0x24,0x25, 0x26,0x32,0x31,0x18 - db 0x19,0x10,0x13,0x1F, 0x14,0x16,0x2F,0x11, 0x2D,0x15,0x2C,0x1A, 0x2B,0x1B,0x07,0x0C - - db 0x29,0x1E,0x30,0x2E, 0x20,0x12,0x21,0x22, 0x23,0x17,0x24,0x25, 0x26,0x32,0x31,0x18 - db 0x19,0x10,0x13,0x1F, 0x14,0x16,0x2F,0x11, 0x2D,0x15,0x2C,0x1A, 0x2B,0x1B,0x29,0x70 - - ; character map - ; resolves codepage character to character in charset (see next table) -ecmap db 0x00,0x01,0x02,0x03, 0x60,0x05,0x06,0x07, 0x08,0x09,0x0A,0x0B, 0x0C,0x0D,0x0E,0x0F - db 0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1A,0x1B, 0x1C,0x1D,0x1E,0x1F - db 0x20,0x21,0x22,0x23, 0x24,0x25,0x26,0x27, 0x28,0x29,0x2A,0x2B, 0x2C,0x2D,0x2E,0x2F - db 0x30,0x31,0x32,0x33, 0x34,0x35,0x36,0x37, 0x38,0x39,0x3A,0x3B, 0x3C,0x3D,0x3E,0x3F - - db 0x40,0x41,0x42,0x43, 0x44,0x45,0x46,0x47, 0x48,0x49,0x4A,0x4B, 0x4C,0x4D,0x4E,0x4F - db 0x50,0x51,0x52,0x53, 0x54,0x55,0x56,0x57, 0x58,0x59,0x5A,0x5B, 0x5C,0x5D,0x5E,0x5F - db 0x60,0x61,0x62,0x63, 0x64,0x65,0x66,0x67, 0x68,0x69,0x6A,0x6B, 0x6C,0x6D,0x6E,0x6F - db 0x70,0x71,0x72,0x73, 0x74,0x75,0x76,0x77, 0x78,0x79,0x7A,0x7B, 0x7C,0x7D,0x7E,0x7F - - db 0x47,0x7c,0x69,0x62, 0x64,0x60,0x65,0x67, 0x6A,0x6B,0x68,0x6f, 0x6e,0x6c,0x44,0x45 - db 0x49,0x66,0x46,0x74, 0x76,0x72,0x7b,0x79, 0x7d,0x56,0x5C,0x22, 0x23,0x25,'P' ,'f' - db 0x61,0x6D,0x73,0x7a, 0x71,0x51,0x2A,0x3A, 0x3F,0x2C,0x2C,0x3d, 0x3c,0x21,0x2b,0x3b - db 0x61,0x61,0x61,0x78, 0x75,0x75,0x75,0x6B, 0x6B,0x75,0x78,0x6B, 0x6a,0x6a,0x6a,0x6b - - db 0x6D,0x76,0x77,0x74, 0x71,0x6E,0x74,0x74, 0x6D,0x6C,0x76,0x77, 0x74,0x71,0x6E,0x76 - db 0x76,0x77,0x77,0x6D, 0x6D,0x6C,0x6C,0x6E, 0x6E,0x6A,0x6C,0x61, 0x61,0x61,0x61,0x61 - db 0x61,0x62,0x47,0x70, 0x53,0x73,0x35,0x74, 0x46,0x6A,0x57,0x64, 0x42,0x66,0x65,0x5C - db 0x4F,0x67,0x7A,0x79, 0x24,0x25,0x43,0x49, 0x66,0x7E,0x7E,0x21, 0x32,0x32,0x61,0x5F - - ; character set map - ; resolves codepage character to DEC charset (A,B,0,1,<) -csmap db 0,0,0,0, '0',0,0,0, 0,0,0,0, 0,0,0,0 - db 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 - db 0,'B','B','B', 'B','B','B','B', 'B','B','B','B', 'B','B','B','B' - db 'B','B','B','B', 'B','B','B','B', 'B','B','B','B', 'B','B','B','B' - - db 'B','B','B','B', 'B','B','B','B', 'B','B','B','B', 'B','B','B','B' - db 'B','B','B','B', 'B','B','B','B', 'B','B','B','B', 'B','B','B','B' - db 'B','B','B','B', 'B','B','B','B', 'B','B','B','B', 'B','B','B','B' - db 'B','B','B','B', 'B','B','B','B', 'B','B','B','B', 'B','B','B',0 - - db 'A','A','A','A', 'A','A','A','A', 'A','A','A','A', 'A','A','A','A' - db 'A','A','A','A', 'A','A','A','A', 'A','A','A','A', 'A','A','B','B' - db 'A','A','A','A', 'A','A','A','A', 'A','A','A','A', 'A','A','A','A' - db '0','0','0','0', '0','0','0','0', '0','0','0','0', '0','0','0','0' - - db '0','0','0','0', '0','0','0','0', '0','0','0','0', '0','0','0','0' - db '0','0','0','0', '0','0','0','0', '0','0','0','0', '0','0','0','0' - db '>','>','>','>', '>','>','A','>', '>','>','>','>', '>','>','>','>' - db '>','0','0','0', '>','>','>','>', '0','0','0','>', 'A','A','0','0' -%endif - - ; function keys by character - ; \eO$c, looks up $c to XT scancode - ; table is like ascii, except it starts at 0x40 '@' -fkeysc db 0,0x48,0x50,0x4D, 0x4B,0,0x4F,0, 0x47,0,0,0, 0,0,0,0 - db 0x3B,0x3C,0x3D,0x3E, 0,0,0,0, 0,0,0,0, 0,0,0,0 - db 0,0,0,0, 0,0,0,0, 0,0,0,0, 0x42,0,0,0 - db 0,0,0,0, 0x3F,0x40,0x41,0x43, 0x44,0,0,0, 0,0,0,0 - - ; function keys by numbers - ; 10 entries per line - ; \e[$n~, looks up $n to XT scancode -fkeysn db 0,0x47,0x52,0x53,0, 0x49,0x51,0x47,0x4F,0 ; 0-9 - db 0,0x3B,0x3C,0x3D,0x3E, 0x3F,0,0x40,0x41,0x42 ; 10-19 - db 0x43,0x44,0,0x85,0x86, 0,0,0,0,0 ; 20-29 - db 0,0,0,0,0, 0,0,0,0,0 ; 30-39 - - align 512