From 62975f81b98de577e4ae86a002fa74a62b9bd1b4 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sun, 1 Jan 2023 21:44:10 +0000 Subject: [PATCH] Support boot sectors that i dont want to support anymore --- boot/hello.asm | 8 -- boot/ihex.asm | 219 ----------------------------------- boot/mbr.asm | 41 ------- boot/monitor.asm | 295 ----------------------------------------------- 4 files changed, 563 deletions(-) delete mode 100644 boot/hello.asm delete mode 100644 boot/ihex.asm delete mode 100644 boot/mbr.asm delete mode 100644 boot/monitor.asm diff --git a/boot/hello.asm b/boot/hello.asm deleted file mode 100644 index e163cb9..0000000 --- a/boot/hello.asm +++ /dev/null @@ -1,8 +0,0 @@ - org 0x7C00 - jmp short main - nop - nop -main mov ax, 0x0e37 - int 0x10 -halt hlt - jmp short halt diff --git a/boot/ihex.asm b/boot/ihex.asm deleted file mode 100644 index 6fdb5f9..0000000 --- a/boot/ihex.asm +++ /dev/null @@ -1,219 +0,0 @@ -; ihex - bootsector that reads intel hex from the keyboard - -%define base (0x10000 - 0x400) - - org base - - ; relocate to end of memory -reloc: ; set up src addr - xor ax, ax - mov ds, ax - mov si, 0x7C00 - ; calculate target segment - mov ax, [0x413] - mov cl, 6 - shl ax, cl - sub ax, 0x1000 - mov es, ax - mov di, base - ; set up dst addr - mov ss, ax - mov sp, di - ; relocate - mov cx, 0x100 - rep movsw - ; set DS - mov ds, ax - ; jump relocated - push ds - mov ax, main - push ax - retf - - ; AL -> display -putc: mov ah, 0x0e - xor bx, bx - int 0x10 - ret - - ; read a line -read: mov si, line -.loop: xor ax, ax - int 0x16 - cmp al, 0x08 - je .bs - cmp al, 0x0A - je .cr - cmp al, 0x0D - je .cr - cmp ax, 0x4D00 - je .r - test al, al - jz .loop - cmp al, 0x60 - jc .l01 - sub al, 0x20 -.l01: mov [si], al -.l02: inc si - call putc - jmp .loop -.r: mov al, [si] - jmp .l02 -.bs: dec si - push ax - call putc - mov al, 0x20 - call putc - pop ax - call putc - jmp .loop -.cr: mov cx, line - xchg cx, si - sub cx, si - jmp nl - - ; read 2 hex chars from line into al - ; BX is byte number -getb: add bx, bx - lea si, [line+1+bx] - mov ax, [si] - call .a2b - xchg ah, al - call .a2b - test ax, 0xF0F0 - jnz err - push cx - mov cl, 4 - shl al, cl - shr ax, cl - pop cx -.ret: ret -.err: xor ax, ax - stc - ret -.a2b: sub al, 0x30 - cmp al, 0x10 - jc .ret - sub al, 7 - ret - - ; same like getb, except reads a full word -getw: push bx - call getb - mov dl, al - pop bx - inc bx - call getb - mov ah, dl - ret - -nl: mov al, 0x0A - call putc - mov al, 0x0D - jmp putc - -main: mov sp, base ; reset stack - call read - cmp byte [line], ':' - jmp hexcmd - -err: mov cx, si - sub cx, line - jz .l01 - cmp cx, 80 - jnc .l01 - mov al, ' ' -.l02: call putc - loop .l02 -.l01: mov al, '^' - call putc - mov al, 7 - call putc - call nl - jmp main - -hexcmd: sub cx, 11 - jc err - shr cx, 1 - xor bx, bx - call getb - ; line not long enough for size field - cmp cl, al - jc err - ; calculate checksum - add cl, 5 - xor dx, dx -.loop: push bx - call getb - pop bx - add dl, al - inc bx - add dl, al - loop .loop - jnz err - ; get record type - mov bx, 3 - call getb - cmp al, 0 - je cmd0 - cmp al, 1 - je cmd1 - cmp al, 2 - je cmd2 - cmp al, 3 - je cmd3 - jmp err - - ; ihex command 0: data -cmd0: les di, [addr] - mov bx, 0 - push bx - call getb - pop bx - mov cx, ax - add bx, 4 -.loop: push bx - call getb - pop bx - inc bx - stosb - loop .loop - mov [addr], di - jmp main - - ; ihex command 1: eof / exec -cmd1: push word [exec+2] - push word [exec] - push es - pop ds - retf - - ; ihex command 2: set segment -cmd2: mov bx, 4 - call getw - mov [addr], ax - jmp main - - ; ihex command 3: set start address -cmd3: ; copy CS - mov bx, 4 - call getw - mov [exec+2], ax - ; copy IP - mov bx, 6 - call getw - mov [exec], ax - jmp main - -hlt: hlt - jmp hlt - -addr: dw 0, 0x100 -exec: dw 0, 0x100 - - times 510-($-$$) db 0x00 - db 0x55,0xaa - -section .bss - -line: resb 80 diff --git a/boot/mbr.asm b/boot/mbr.asm deleted file mode 100644 index af44954..0000000 --- a/boot/mbr.asm +++ /dev/null @@ -1,41 +0,0 @@ - cpu 8086 - -%define seg 0 -%define off 0x700 - - org 0x7C00 - (seg << 4) - -init: cli - mov ax, seg - mov ds, ax - mov es, ax - mov ss, ax - xor sp, sp - mov ax, sp - push ax - -.retry: mov ax, 0x0208 - mov cx, 2 - mov dh, 0 - mov bx, off - - int 0x13 - jc .retry - - jmp seg:off - - times (0x1BE - ($-$$)) db 0 - - ; assumes 16 heads, 63 sectors per track - ; image of 1.44 MB floppy starting on 2nd track -part1: db 0x80 - db 1, 1, 0 - db 1 - db 0xFF, 0xFF, 0xFF - dd 63 - dd 0xb40 - - times (0x1FE - ($-$$)) db 0 - - ; Boot signature -sig: dw 0xAA55 diff --git a/boot/monitor.asm b/boot/monitor.asm deleted file mode 100644 index cf465b7..0000000 --- a/boot/monitor.asm +++ /dev/null @@ -1,295 +0,0 @@ -; monitor program that fits in a boot sector -; for debugging disk i/o and bootstrapping - -%define base (0x10000 - 0x200) - - org base - cpu 8086 - - ; relocate to end of memory -init: ; set up src addr - xor ax, ax - mov ds, ax - mov si, 0x7C00 - ; calculate target segment - mov ax, [0x413] - mov cl, 6 - shl ax, cl - sub ax, 0x1000 - ; set up dst addr - mov es, ax - mov di, base - ; set up stack - mov ss, ax - mov sp, di - ; push defptr - push ds - push si - ; relocate - mov cx, 0x100 - rep movsw - ; set up intr vectors - mov bx, 1*4 - call .l02 - ; enter - mov si, 0x7C00-1 - mov byte [si], 0xCC - push cs - push si - sti - retf - - ; call here = run proc tail twice -.l02: call .l01 -.l01: mov word [bx], entry - mov word [bx+2], ss - add bx, 2*4 - ret - -nl: mov ax, 0x0e0A - int 0x10 - mov al, 0x0D - jmp putc - -space: mov al, ' ' -putc: mov ah, 0x0e - int 0x10 - ret - - ; print register set -printr: call nl - xor si, si -.l02: mov ah, 0x0e - mov al, [cs:lbls+si] - int 0x10 - mov al, [cs:lbls+si+1] - int 0x10 - mov al, '=' - int 0x10 - mov dx, [bp+si] - mov ch, ' ' - call prints - add si, 2 - cmp si, 24 - jc .l02 - les bx, [bp+18] - jmp dump - - ; print 16 bytes from ES:BX -dump: mov dx, es - mov ch, ':' - call prints - mov dx, bx - mov ch, ' ' - call prints - push bx - mov cx, 0x10 -.l01: mov dh, [es:bx] - inc bx - push cx - call printb - call space - pop cx - loop .l01 - pop bx - ret - -printw: call printb ; print dx -printb: call .l01 ; print dh -.l01: 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 -printn: ; 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: mov ah, 0x0e - int 0x10 - ret - - ; print dx and char ch -prints: call printw - mov al, ch - int 0x10 - ret - -getc: xor ax, ax - int 0x16 - test al, al - jz getc - ; to uppercase - cmp al, 0x60 - jc .ret - sub al, 0x20 -.ret: ret - -inputw: call inputb -inputb: call inputn -inputn: jc .ret - call getc - cmp al, 0x20 - stc - je .ret - sub al, 0x30 - ; if >9, turn 'A' to A - cmp al, 0x0A - jc .noadj - sub al, 7 -.noadj: ; must be smaller than 'F' - cmp al, 0x10 - jnc inputn - ; append to dx - mov cl, 4 - shl dx, cl - or dl, al - ; print, loop & clear exit - call printn - clc -.ret: ret - - ; edit word at ES:BX - ; space exits with carry -editw: mov dx, [es:bx] - mov ch, '.' - call prints - clc - call inputw - jc .err - mov [es:bx], dx -.err: ret - -cmd_o: mov bx, di - jmp cmd_s.l01 - -cmd_s: lea bx, [di+2] -.l01: call editw - jmp cmd - -cmd_e: les bx, [cs:di] - mov dh, [es:bx] - call printb - mov al, '.' - int 0x10 - mov cx, 2 - clc - call inputb - jc cmd - mov [es:bx], dl - inc word [cs:di] - call space - jmp cmd_e - -entry: push es - push ds - push di - push si - push bp - push bx - push dx - push cx - push ax - mov bp, sp - -cmd_r: call printr -cmd: ; display prompt - call nl - mov al, '-' - call putc -.l01: call getc - cmp al, 0x41 - jc .l01 - ; process input char - call putc - push ax - call space - pop ax - ; set up default for cmds - mov dx, cs - mov ds, dx - mov es, dx - mov di, defptr - ; show and edit mem - cmp al, 'D' - je cmd_d - cmp al, 'E' - je cmd_e - ; show and edit regs - cmp al, 'R' - je cmd_r - cmp al, 'V' - je cmd_v - ; actions - cmp al, 'G' - je cmd_g - cmp al, 'T' - je cmd_t - ; set working ptr - cmp al, 'S' - je cmd_s - cmp al, 'O' - je cmd_o - -err: mov al, '?' - call putc - jmp cmd - -cmd_d: les bx, [di] - mov cx, 8 -.l01: push cx - call nl - call dump - pop cx - add bx, 0x10 - mov [cs:di], bx - loop .l01 - jmp cmd - -cmd_v: call regn - mov ax, dx - mov di, lbls - mov cx, 11 - repne scasw - jne err - sub di, lbls+2 - lea bx, [bp+di] - call space - call editw - jmp cmd - -regn: call .l01 - xchg dh, dl -.l01: call getc - call putc - mov dh, al - ret - -cmd_t: or byte [bp+23], 1 - jmp exit -cmd_g: and byte [bp+23], 0xFE -exit: pop ax - pop cx - pop dx - pop bx - pop bp - pop si - pop di - pop ds - pop es - iret - - ; names for registers -lbls: db "AXCXDXBXBPSIDI" ; gpr - db "DSES" ; seg regs - db "IPCSFL" ; iret frmae - -defptr: equ (base-4) - - times 510-($-$$) db 0x00 - db 0x55,0xaa