From 2d48606692cb702881e0ec8934603bac250b5fbc Mon Sep 17 00:00:00 2001 From: d0p1 Date: Fri, 5 Jul 2024 08:16:40 +0200 Subject: [PATCH] docs: minor change --- boot/common/bootinfo.inc | 7 + boot/common/fat12.inc | 24 ++- boot/common/macro.inc | 3 + boot/loader/a20.inc | 348 ++++++++++++++++++----------------- boot/loader/loader.asm | 2 + boot/loader/video.inc | 1 + releasetools/cdimage.sh | 5 + releasetools/floppyimage.sh | 12 +- releasetools/hdimage.sh | 11 ++ releasetools/image.defaults | 3 +- releasetools/image.functions | 22 ++- 11 files changed, 256 insertions(+), 182 deletions(-) diff --git a/boot/common/bootinfo.inc b/boot/common/bootinfo.inc index e889bbf..8500061 100644 --- a/boot/common/bootinfo.inc +++ b/boot/common/bootinfo.inc @@ -1,16 +1,23 @@ ;; File: bootinfo.inc + ;; Struct: BootInfoRange struc BootInfoRange { .base dd ? .legth dd ? } + ;; Struct: BootInfo + ;; + ;; StupidOS boot protocol structure struc BootInfo { .mmap dd 4*2*40 dup(0) .kernel_start dd ? .kernel_size dd ? } + ;; Section: Globals + + ;; Constant: BOOTINFO_MEMORY_LIMIT BOOTINFO_MEMORY_LIMIT = 0xFFFFF000 diff --git a/boot/common/fat12.inc b/boot/common/fat12.inc index 9b0d148..c42dab8 100644 --- a/boot/common/fat12.inc +++ b/boot/common/fat12.inc @@ -1,12 +1,6 @@ ;; File: fat12.inc - ATTR_READ_ONLY = 0x01 - ATTR_HIDDEN = 0x02 - ATTR_SYSTEM = 0x04 - ATTR_VOLUME_ID = 0x08 - ATTR_DIRECTORY = 0x10 - ATTR_ARCHIVE = 0x20 - + ;; Struct: fat_entry struc fat_entry { .name db 8 dup ? @@ -24,6 +18,22 @@ struc fat_entry } defn fat_entry + ;; Constants: Attributes + ;; ATTR_READ_ONLY - Read-only + ;; ATTR_HIDDEN - Hidden + ;; ATTR_SYSTEM - System + ;; ATTR_VOLUME_ID - Volume label + ;; ATTR_DIRECTORY - Subdirectory + ;; ATTR_ARCHIVE - Archive + ATTR_READ_ONLY = 0x01 + ATTR_HIDDEN = 0x02 + ATTR_SYSTEM = 0x04 + ATTR_VOLUME_ID = 0x08 + ATTR_DIRECTORY = 0x10 + ATTR_ARCHIVE = 0x20 + + ;; Section: Globals + ;; Function: fat_load_root fat_load_root: mov ax, DISK_BUFFER/0x10 diff --git a/boot/common/macro.inc b/boot/common/macro.inc index 610e5b6..1218de9 100644 --- a/boot/common/macro.inc +++ b/boot/common/macro.inc @@ -1,3 +1,6 @@ + ;; File: macro.inc + + ;; Macro: defn name macro defn name { virtual at 0 diff --git a/boot/loader/a20.inc b/boot/loader/a20.inc index 0c62cb4..a8007d8 100644 --- a/boot/loader/a20.inc +++ b/boot/loader/a20.inc @@ -1,171 +1,177 @@ - ; copy/pasted from https://wiki.osdev.org/A20_Line - ; .... sorry I was lazy :x - -a20_get_state: - pushf - push si - push di - push ds - push es - - cli - - xor ax, ax - mov ds, ax - mov si, 0x500 - - not ax - mov es, ax - mov di, 0x0510 - - mov al, [ds:si] ; save old values - mov byte [.BufferBelowMB], al - mov al, [es:di] - mov byte [.BufferOverMB], al - - mov ah, 1 ; check byte [0x00100500] == byte [0x0500] - mov byte [ds:si], 0 - mov byte [es:di], 1 - mov al, [ds:si] - cmp al, [es:di] - jne .exit - dec ah -.exit: - mov al, [.BufferBelowMB] - mov [ds:si], al - mov al, [.BufferOverMB] - mov [es:di], al - shr ax, 8 - sti - pop es - pop ds - pop di - pop si - popf - ret - -.BufferBelowMB: db 0 -.BufferOverMB db 0 - - -a20_query_support: - push bx - clc - - mov ax, 0x2403 - int 0x15 - jc .error - - test ah, ah - jnz .error - - mov ax, bx - pop bx - ret -.error: - stc - pop bx - ret - -a20_enable_keyboard_controller: - cli - - call .wait_io1 - mov al, 0xad - out 0x64, al - - call .wait_io1 - mov al, 0xd0 - out 0x64, al - - call .wait_io2 - in al, 0x60 - push eax - - call .wait_io1 - mov al, 0xd1 - out 0x64, al - - call .wait_io1 - pop eax - or al, 2 - out 0x60, al - - call .wait_io1 - mov al, 0xae - out 0x64, al - - call .wait_io1 - sti - ret -.wait_io1: - in al, 0x64 - test al, 2 - jnz .wait_io1 - ret -.wait_io2: - in al, 0x64 - test al, 1 - jz .wait_io2 - ret - -; out: -; cf - set on error -a20_enable: - clc ; clear cf - pusha - mov bh, 0 ; clear bh - - call a20_get_state - jc .fast_gate - - test ax, ax - jnz .done - - call a20_query_support - mov bl, al - test bl, 1 ; enable A20 using keyboard controller - jnz .keybord_controller - - test bl, 2 ; enable A20 using fast A20 gate - jnz .fast_gate -.bios_int: - mov ax, 0x2401 - int 0x15 - jc .fast_gate - test ah, ah - jnz .failed - call a20_get_state - test ax, ax - jnz .done -.fast_gate: - in al, 0x92 - test al, 2 - jnz .done - - or al, 2 - and al, 0xfe - out 0x92, al - - call a20_get_state - test ax, ax - jnz .done - - test bh, bh ; test if there was an attempt using the keyboard controller - jnz .failed -.keybord_controller: - call a20_enable_keyboard_controller - call a20_get_state - test ax, ax - jnz .done - - mov bh, 1 ; flag enable attempt with keyboard controller - - test bl, 2 - jnz .fast_gate - jmp .failed -.failed: - stc -.done: - popa - ret \ No newline at end of file + ;; File: a20.inc + ;; copy/pasted from https://wiki.osdev.org/A20_Line + ;; .... sorry I was lazy :x + + ;; Function: a20_get_state +a20_get_state: + pushf + push si + push di + push ds + push es + + cli + + xor ax, ax + mov ds, ax + mov si, 0x500 + + not ax + mov es, ax + mov di, 0x0510 + + mov al, [ds:si] ; save old values + mov byte [.BufferBelowMB], al + mov al, [es:di] + mov byte [.BufferOverMB], al + + mov ah, 1 ; check byte [0x00100500] == byte [0x0500] + mov byte [ds:si], 0 + mov byte [es:di], 1 + mov al, [ds:si] + cmp al, [es:di] + jne .exit + dec ah +.exit: + mov al, [.BufferBelowMB] + mov [ds:si], al + mov al, [.BufferOverMB] + mov [es:di], al + shr ax, 8 + sti + pop es + pop ds + pop di + pop si + popf + ret + +.BufferBelowMB: db 0 +.BufferOverMB db 0 + + ;; Function: a20_query_support +a20_query_support: + push bx + clc + + mov ax, 0x2403 + int 0x15 + jc .error + + test ah, ah + jnz .error + + mov ax, bx + pop bx + ret +.error: + stc + pop bx + ret + + ;; Function: a20_enable_keyboard_controller +a20_enable_keyboard_controller: + cli + + call .wait_io1 + mov al, 0xad + out 0x64, al + + call .wait_io1 + mov al, 0xd0 + out 0x64, al + + call .wait_io2 + in al, 0x60 + push eax + + call .wait_io1 + mov al, 0xd1 + out 0x64, al + + call .wait_io1 + pop eax + or al, 2 + out 0x60, al + + call .wait_io1 + mov al, 0xae + out 0x64, al + + call .wait_io1 + sti + ret +.wait_io1: + in al, 0x64 + test al, 2 + jnz .wait_io1 + ret +.wait_io2: + in al, 0x64 + test al, 1 + jz .wait_io2 + ret + + ;; Function: a20_enable + ;; + ;; Out: + ;; CF - set on error + ;; +a20_enable: + clc ; clear cf + pusha + mov bh, 0 ; clear bh + + call a20_get_state + jc .fast_gate + + test ax, ax + jnz .done + + call a20_query_support + mov bl, al + test bl, 1 ; enable A20 using keyboard controller + jnz .keybord_controller + + test bl, 2 ; enable A20 using fast A20 gate + jnz .fast_gate +.bios_int: + mov ax, 0x2401 + int 0x15 + jc .fast_gate + test ah, ah + jnz .failed + call a20_get_state + test ax, ax + jnz .done +.fast_gate: + in al, 0x92 + test al, 2 + jnz .done + + or al, 2 + and al, 0xfe + out 0x92, al + + call a20_get_state + test ax, ax + jnz .done + + test bh, bh ; test if there was an attempt using the keyboard controller + jnz .failed +.keybord_controller: + call a20_enable_keyboard_controller + call a20_get_state + test ax, ax + jnz .done + + mov bh, 1 ; flag enable attempt with keyboard controller + + test bl, 2 + jnz .fast_gate + jmp .failed +.failed: + stc +.done: + popa + ret diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index d833f70..8c5ee92 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -14,6 +14,8 @@ multiboot_header: mb_header MultibootHeader multiboot_header + ;; Function: _start + ;; Loader entry point. _start: cmp eax, MULTIBOOT_MAGIC je multiboot diff --git a/boot/loader/video.inc b/boot/loader/video.inc index c4f4b54..71be57b 100644 --- a/boot/loader/video.inc +++ b/boot/loader/video.inc @@ -56,6 +56,7 @@ struc VesaModeInfo .Reserved2 db 206 dup(?) } + ;; Function: video_setup video_setup: mov si, szMsgDetectVideo call bios_log diff --git a/releasetools/cdimage.sh b/releasetools/cdimage.sh index 85677d3..0966b9d 100755 --- a/releasetools/cdimage.sh +++ b/releasetools/cdimage.sh @@ -11,4 +11,9 @@ fi DESTDIR=${BUILDDIR}/iso +mkdir -p "${OBJ}" + +(cd "${OBJ}"; get_grub) + + make diff --git a/releasetools/floppyimage.sh b/releasetools/floppyimage.sh index 9507f3a..fb7f4c3 100755 --- a/releasetools/floppyimage.sh +++ b/releasetools/floppyimage.sh @@ -10,5 +10,15 @@ fi . ./releasetools/image.functions DESTDIR=${BUILDDIR}/floppy - export DESTDIR + +mkdir -p "${BUILDDIR}" "${OBJ}" + +mkdir -p "${DESTDIR}/boot" + +create_stpdboot_ini "${DESTDIR}/boot" + +make + +echo "" +echo "floppy image at $(pwd)/${IMG}" diff --git a/releasetools/hdimage.sh b/releasetools/hdimage.sh index 8763de7..7bc0178 100755 --- a/releasetools/hdimage.sh +++ b/releasetools/hdimage.sh @@ -11,10 +11,21 @@ fi . ./releasetools/image.defaults . ./releasetools/image.functions +DESTDIR=${BUILDDIR}/hd +export DESTDIR + if [ -f "${IMG}" ] then rm -f "${IMG}" fi +mkdir -p "${BUILDDIR}" "${OBJ}" + +mkdir -p "${DESTDIR}/boot" + +create_stpdboot_ini "${DESTDIR}/boot" + +make + echo "" echo "Disk image at $(pwd)/${IMG}" diff --git a/releasetools/image.defaults b/releasetools/image.defaults index 4aadb83..f9911ca 100644 --- a/releasetools/image.defaults +++ b/releasetools/image.defaults @@ -1,5 +1,6 @@ #!/usr/bin/env bash -: "${BUILDDIR=.build}" +: "${BUILDDIR=$(pwd)/.build}" : "${OBJ=${BUILDDIR}/obj}" : "${DESTDIR=${BUILDDIR}/dist}" +: "${TOOLSDIR=$(pwd)/.tools}" diff --git a/releasetools/image.functions b/releasetools/image.functions index 660514d..07a84af 100644 --- a/releasetools/image.functions +++ b/releasetools/image.functions @@ -19,12 +19,18 @@ menuentry "StupidOS" { EOF )" - echo "$grub_cfg" > "$target" + echo "$grub_cfg" > "${target}/grub.cfg" } get_grub() { - echo + local version="2.12" + local url="https://ftp.gnu.org/gnu/grub/grub-${version}.tar.gz" + + wget "${url}" + tar -xvf "grub-${version}.tar.gz" + + (cd "grub-${version}"; ./configure --prefix="${TOOLSDIR}" && make install) } create_efi_image() @@ -32,3 +38,15 @@ create_efi_image() echo } +create_stpdboot_ini() +{ + local target="$1" + local stupid_ini="$(cat < "${target}/stupid.ini" +}