From 8d1ec63cc1595a08f7f0840c6581216f00b35072 Mon Sep 17 00:00:00 2001 From: Ed94 Date: Sat, 5 Feb 2022 11:19:40 -0500 Subject: [PATCH] Basic build and runs scripts, began setup of ftable n stuff going the route of watching this series so far. --- .gitignore | 1 + 16bit.Scratch.s | 128 ++++++++++++++++++++++++++++++++++++-- 16bit.boot.S | 61 +++++++++++++----- 16bit.ftable.s | 13 ++++ 16bit.output.tests | Bin 512 -> 0 bytes 16bit.symtable.s | 13 ++++ AAL.x86.routines.macros.s | 26 +++++--- AAL.x86.routines.s | 14 ++--- AAL.x86.s | 30 ++++++++- Erus.boot.s | 79 ----------------------- Makefile | 18 ++++++ run.ps1 | 1 + 12 files changed, 265 insertions(+), 119 deletions(-) create mode 100644 16bit.ftable.s delete mode 100644 16bit.output.tests create mode 100644 16bit.symtable.s delete mode 100644 Erus.boot.s create mode 100644 Makefile create mode 100644 run.ps1 diff --git a/.gitignore b/.gitignore index e69de29..b258aba 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +16bit.loader diff --git a/16bit.Scratch.s b/16bit.Scratch.s index 1918a4a..032fb2e 100644 --- a/16bit.Scratch.s +++ b/16bit.Scratch.s @@ -5,15 +5,115 @@ %include "AAL.x86.routines.macros.S" +%macro DblNewLine_Out 0 + mov AH, Video_TeleType + mov AL, char_LF + int VideoService + mov AL, char_CR + int VideoService + mov AL, char_LF + int VideoService + mov AL, char_CR + int VideoService +%endmacro + +; CmdStr Interface +; Inline +%macro CmdStr_Get 0 + mov SI, CmdStr +%endmacro + +; Inline +%macro CmdStr_Add 0 +; Put input char to CmdStr + mov [SI], AL +; Increment DI, and increment cmdstr length. + inc SI +%endmacro + + ;============================================================================================================= ; Entrypoint ;============================================================================================================= start: -Video_SetTextMode_80x25 -; Video_SetGraphicsMode_320x200 -; Video_SetGraphicsMode_640x200 + mov AH, Video_SetMode + mov AL, VideoMode_Graphics_640_480_VGA + int VideoService -String_Out EntryMsg, [EntryMsg_len] +; Give some times before starting + mov AH, BIOS_Wait + mov CX, 0x10 + int SystemService + + String_Out EntryMsg, [EntryMsg_len] + DblNewLine_Out + +; Give some times before starting + mov AH, BIOS_Wait + mov CX, 0x01 + int SystemService + + String_Out Input_F, [Input_F_len] + + push SI + ; SI will be used as the char index in CmdStr + + + CmdStr_Get +inputLoop: +; Wait for input + mov AH, Keyboard_GetKeyStroke + mov AL, 0x00 + int KeyboardService + + CmdStr_Add + +; Prep to outout character + mov AH, Video_TeleType + mov BH, 0x00 + + cmp AL, KeyL_Enter + je exe_Command + +; Output character if command not recognized + int VideoService + + NewLine_Out + + jmp short inputLoop + +exe_Command: + ; pop SI + mov AL, [CmdStr] + + + cmp AL, KeyL_N + je end_execution + + cmp AL, KeyL_F + jne error_CmdNotFound + String_Out CmdFile, [CmdFile_len] + + CmdStr_Get + jmp short inputLoop + +error_CmdNotFound: + String_Out CmdNotFnd, [CmdNotFnd_len] + + CmdStr_Get + jmp short inputLoop +; End Program + ; cli + ; hlt + +jmp short inputLoop + + +end_execution: + String_Out ExitMsg, [ExitMsg_len] + + cli + hlt hang: jmp short hang @@ -22,8 +122,24 @@ jmp short hang ;============================================================================================================= ; Data ;============================================================================================================= -EntryMsg : db 'Hello World!', char_LF, char_CR -EntryMsg_len : dw 14 +EntryMsg_len : dw 29 +EntryMsg : db 'Bare x86 Mode: 16 bit (Real)', str_endl +; EntryMsg_len : equ $ - EntryMsg + +ExitMsg_len : dw 12 +ExitMsg : db 'Exiting...', str_endl + +Input_F_len : dw 36 +Input_F : db 'F) File/Program Browser & Launcher', str_endl + +CmdFile_len : dw 14 +CmdFile : db 'Command File', str_endl + +CmdNotFnd_len : dw 19 +CmdNotFnd : db 'Command not found', str_endl + +CmdStr_len : dw 0 +CmdStr : db '' %include "AAL.x86.routines.s" diff --git a/16bit.boot.S b/16bit.boot.S index 5704af9..2951aee 100644 --- a/16bit.boot.S +++ b/16bit.boot.S @@ -26,7 +26,7 @@ start: ; Give some times before starting mov AH, BIOS_Wait mov CX, 0x10 -int SystemService + int SystemService xor AX, AX ; Set Data Segment and Extra Segment to 0x0000 @@ -38,12 +38,13 @@ int SystemService mov BX, Mem_BootSector_Start mov SP, BX -String_Out PostMsg, [PostMsg_len] + String_Out PostMsg, [PostMsg_len] mov AH, BIOS_Wait mov CX, 0x05 -int SystemService + int SystemService +; Load : File Table ; Loading the code from disk (storage) mov DH, 0x0 ; Head NUm @@ -57,14 +58,37 @@ int SystemService ; Read Disk (Storage) mov AH, Disk_ReadIntoMemory - mov AL, 0x01 ; Num Sectors -int DiskService + mov AL, 0x02 ; Num Sectors + int DiskService -String_Out SendoffMsg, [SendOffMsg_len] + String_Out FTableMsg, [FTableMsg_len] mov AH, BIOS_Wait mov CX, 0x10 -int SystemService + int SystemService + +; Load : 16bit.Scratch + +; Loading the code from disk (storage) + mov DH, 0x0 ; Head NUm + mov DL, 0x0 ; Drive Num + mov CH, 0x0 ; Track Num + mov CL, 0x03 ; Starting Sector +; Setup ES:BX Memory address/segment + mov BX, 0x2000 ; ES:BX : 0x1000:0x0 + mov ES, BX + mov BX, 0x0 + +; Read Disk (Storage) + mov AH, Disk_ReadIntoMemory + mov AL, 0x02 ; Num Sectors + int DiskService + + String_Out SendoffMsg, [SendOffMsg_len] + + mov AH, BIOS_Wait + mov CX, 0x10 + int SystemService ; Jump if carry flag ; jc error @@ -73,7 +97,7 @@ int SystemService ; jne error ; Reset segment registers for ram - mov AX, 0x1000 + mov AX, 0x2000 mov DS, AX mov DS, AX mov ES, AX @@ -82,7 +106,7 @@ int SystemService mov SS, AX ; Heading to 16bit.scratch - jmp 0x1000:0x0 + jmp 0x2000:0x0 ;============================================================================================================= @@ -107,13 +131,13 @@ out_string: .loop: ; Bounds check cmp SI, [argLen] - je .break + je .break ; Output a character mov BX, CX mov AL, [BX + SI] xor BH, BH ; Clear BH for correct active page -int VideoService + int VideoService add SI, 0x1 jmp .loop @@ -125,21 +149,26 @@ int VideoService ret error: -String_Out ErrorMsg, [ErrorMsg_Len] + String_Out ErrorMsg, [ErrorMsg_Len] hlt ; Halt ;============================================================================================================= ; Data ;============================================================================================================= -ErrorMsg : db 'Failed - DiskService: ReadIntoMemory' ErrorMsg_Len : dw 36 +ErrorMsg : db 'Failed - DiskService: ReadIntoMemory' -PostMsg : db '16bit.boot', char_LF, char_CR -PostMsg_len : dw 13 +PostMsg_len : dw 14 +PostMsg : db '16bit.boot', str_endl + +FTableMsg_len : dw 21 +FTableMsg : db 'Loaded 16bit.ftable', str_endl -SendoffMsg : db 'Sending over to 16bit.scratch...' SendOffMsg_len : dw 32 +SendoffMsg : db 'Sending over to 16bit.scratch...' + + ;============================================================================================================= ; Wrap up ;============================================================================================================= diff --git a/16bit.ftable.s b/16bit.ftable.s new file mode 100644 index 0000000..57438a6 --- /dev/null +++ b/16bit.ftable.s @@ -0,0 +1,13 @@ +; x86 +; 16-bit - Real Mode, V86 Mode +; File Table + + +; 0xF91E7AB1E { filename; sector#; filename; sector#; } +filetable: + dd 0xEF7AB1E + dw 0x0000 + db '{ testfile; 04; testProg; 06; }' + +; Byte pad 512 bytes (zeroed) +times 512-$+filetable db 0 diff --git a/16bit.output.tests b/16bit.output.tests deleted file mode 100644 index ef4cf63cc3bc95510660cdd175a0024aa849f17a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmdnOuz~rkfZ>6@8+`}*F6?Hg>AbVsp?0BfZNLi_#)vI#JDC{HithHWT^I=z`NR;> zEf!t7Grl(P#ZHFEZn49q^WB?f@ z05oa~-v+L;0zi`YtN_rqT?|Ywm>6FF3l1~EG4p?7n&dNvl!S|)-kcLcgL|cA7t_){C2Z diff --git a/16bit.symtable.s b/16bit.symtable.s new file mode 100644 index 0000000..ec49d8c --- /dev/null +++ b/16bit.symtable.s @@ -0,0 +1,13 @@ +; x86 +; 16-bit - Real Mode, V86 Mode +; Symbol Table + + +; 0x5E7AB1E { symbol; hash; symbol; hash; } +symtable: + dd 0x5E7AB1E + dw 0x0000 + db '{ listDir; #; createFile; #; }' + +; Byte pad 512 bytes (zeroed) +times 512-$+symtable db 0 diff --git a/AAL.x86.routines.macros.s b/AAL.x86.routines.macros.s index 84782dd..de208d9 100644 --- a/AAL.x86.routines.macros.s +++ b/AAL.x86.routines.macros.s @@ -9,50 +9,58 @@ %macro Video_SetTextMode_80x25 0 mov AH, Video_SetMode mov AL, VideoMode_Text_80x25 -int VideoService + int VideoService %endmacro %macro Video_SetGraphicsMode_320x200 0 mov AH, Video_SetMode mov AL, VideoMode_Graphics_320x200 -int VideoService + int VideoService %endmacro %macro Video_SetGraphicsMode_640x200 0 mov AH, Video_SetMode mov AL, VideoMode_Graphics_640x200 -int VideoService + int VideoService %endmacro ;============================================================================================================= ; Routines ;============================================================================================================= +%macro Char_Out 1 + mov AH, Video_TeleType + mov AL, %1 + int VideoService +%endmacro + %macro DumpOut 2 mov BX, %1 mov DX, %2 -call out_Dump + call out_Dump %endmacro %macro Hex16_ToString 2 mov DX, %1 mov CX, %2 push CX -call h16_toString + call h16_toString pop CX %endmacro -%macro Char_Out 1 +%macro NewLine_Out 0 mov AH, Video_TeleType - mov AL, %1 -int VideoService + mov AL, char_LF + int VideoService + mov AL, char_CR + int VideoService %endmacro %macro String_Out 2 mov BX, %1 mov AX, %2 push AX -call out_string + call out_string pop AX %endmacro diff --git a/AAL.x86.routines.s b/AAL.x86.routines.s index 596abad..eb9a85a 100644 --- a/AAL.x86.routines.s +++ b/AAL.x86.routines.s @@ -27,8 +27,8 @@ out_Dump: push SI mov AX, StartLocation add AX, SI -Hex16_ToString AX, .HexStr -String_Out .HexStr, 4 + Hex16_ToString AX, .HexStr + String_Out .HexStr, 4 pop SI pop DX pop BX @@ -43,16 +43,16 @@ Char_Out ' ' push BX push DX push SI -Hex16_ToString [.HexNum], .HexStr -String_Out .HexStr, 4 + Hex16_ToString [.HexNum], .HexStr + String_Out .HexStr, 4 pop SI pop DX pop BX -Char_Out ' ' + Char_Out ' ' mov AH, BIOS_Wait mov CX, 0x02 -int SystemService + int SystemService inc SI jmp .loop @@ -145,7 +145,7 @@ out_string: mov BX, CX mov AL, [BX + SI] xor BH, BH ; Clear BH for correct active page -int VideoService + int VideoService add SI, 0x1 jmp .loop diff --git a/AAL.x86.s b/AAL.x86.s index 16f7d6d..288e74f 100644 --- a/AAL.x86.s +++ b/AAL.x86.s @@ -304,6 +304,20 @@ ; Disk Services (Storage) %define DiskService 0x13 +; Input + +%define Keyboard_GetKeyStroke 0x00 + +%define KeyH_Enter 0x1C +%define KeyL_Enter 0x0D + +%define KeyH_F 0x21 +%define KeyL_F 0x66 +%define KeyH_N 0x31 +%define KeyL_N 0x6E + +%define KeyboardService 0x16 + ; Memory ; Real Mode - Conventional Lower Memory @@ -347,6 +361,18 @@ %define VideoMode_Graphics_320x200 0x04 %define VideoMode_Graphics_320x200_cboff 0x05 %define VideoMode_Graphics_640x200 0x06 +%define VideoMode_Text_80x25_Mono 0x07 +%define VideoMode_Graphics_160x200 0x08 +%define VideoMode_Graphics_320x200_PCjr 0x09 +%define VideoMode_Graphics_320x200_PCjr 0x09 +%define VideoMode_Graphics_640x200_PCjr 0x0A +%define VideoMode_Graphics_320x200_VGA 0x0D +%define VideoMode_Graphics_640x200_VGA 0x0E +%define VideoMode_Graphics_640x350_VGA_Mono 0x0F +%define VideoMode_Graphics_640_350_VGA 0x10 +%define VideoMode_Graphics_640_480_VGA_Mono 0x11 +%define VideoMode_Graphics_640_480_VGA 0x12 +%define VideoMode_Graphics_320_200_VGA 0x13 ; Output a character %define Video_TeleType 0xE @@ -360,8 +386,8 @@ %define char_CR 0xD ; Carriage Return %define char_LF 0xA ; Line Feed +%define str_endl char_LF, char_CR + %define AAL_x86_Def %endif - - diff --git a/Erus.boot.s b/Erus.boot.s deleted file mode 100644 index 84656d6..0000000 --- a/Erus.boot.s +++ /dev/null @@ -1,79 +0,0 @@ -; Print HEx - -; x86 -; 16-bit - Real Mode, V86 Mode - -; https://codereview.stackexchange.com/questions/230755/display-hexadecimal-value-stored-at-a-register - - -%include "AAL.x86.s" -%include "AAL.x86.routines.macros.s" - - -; 16-Bit Mode -[BITS 16] -; The ORG directive specifies the starting address of a segment -[ORG Mem_BootSector_Start] - - -start: - mov BX, Mem_BootSector_Start - - mov AH, BIOS_Wait - mov CX, 0x10 -int SystemService - -; Exclusive-OR (xor'ing a value to itself zeros the value) - xor AX, AX -; Set Data Segment and Extra Segment to 0x0000 - mov DS, AX - mov ES, AX -; Set Stack Segment (SS) to to 0x0000 - mov SS, AX -; Set Stack Pointer (SP) to the start of the boot sector. - mov SP, BX - - mov BX, Str_Erus - mov CX, 4 - push CX -call out_string - pop CX - - mov BX, Str_PostMsg - mov CX, 22 - push CX -call out_string - pop CX - - mov AH, BIOS_Wait - mov CX, 0x10 -int SystemService - - mov AH, Video_SetMode - mov AL, VideoMode_Text_80x25 -int VideoService - - mov BX, Str_Erus - mov CX, 4 - push CX -call out_string - pop CX - -; Idle -hang : -jmp short hang - -%include "AAL.x86.routines.s" - -; Data -Str_Erus: db 'Erus' -Str_PostMsg : db '... taking over boot', 0xA, 0xD - -;============================================================================================================= -; Wrap up -;============================================================================================================= -; Byte pad 512 bytes (zeroed) -times 510-$+start db 0 -; Master Boot Record signature -db 0x55 -db 0xAA diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5525db0 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ + +16bit.loader: 16bit.boot 16bit.ftable 16bit.scratch + cat 16bit.boot 16bit.ftable 16bit.scratch > 16bit.loader + make clean + +16bit.boot: + nasm 16bit.boot.s + +16bit.ftable: + nasm 16bit.ftable.s + +16bit.scratch: + nasm 16bit.scratch.s + +clean: + rm 16bit.boot + rm 16bit.ftable + rm 16bit.scratch diff --git a/run.ps1 b/run.ps1 new file mode 100644 index 0000000..25dd479 --- /dev/null +++ b/run.ps1 @@ -0,0 +1 @@ +qemu-system-x86_64 -fda 16bit.loader