Basic build and runs scripts, began setup of ftable n stuff

going the route of watching this series so far.
This commit is contained in:
Edward R. Gonzalez 2022-02-05 11:19:40 -05:00
parent 01081ce167
commit 8d1ec63cc1
12 changed files with 265 additions and 119 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
16bit.loader

View File

@ -5,15 +5,115 @@
%include "AAL.x86.routines.macros.S" %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 ; Entrypoint
;============================================================================================================= ;=============================================================================================================
start: start:
Video_SetTextMode_80x25 mov AH, Video_SetMode
; Video_SetGraphicsMode_320x200 mov AL, VideoMode_Graphics_640_480_VGA
; Video_SetGraphicsMode_640x200 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: hang:
jmp short hang jmp short hang
@ -22,8 +122,24 @@ jmp short hang
;============================================================================================================= ;=============================================================================================================
; Data ; Data
;============================================================================================================= ;=============================================================================================================
EntryMsg : db 'Hello World!', char_LF, char_CR EntryMsg_len : dw 29
EntryMsg_len : dw 14 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" %include "AAL.x86.routines.s"

View File

@ -26,7 +26,7 @@ start:
; Give some times before starting ; Give some times before starting
mov AH, BIOS_Wait mov AH, BIOS_Wait
mov CX, 0x10 mov CX, 0x10
int SystemService int SystemService
xor AX, AX xor AX, AX
; Set Data Segment and Extra Segment to 0x0000 ; Set Data Segment and Extra Segment to 0x0000
@ -38,12 +38,13 @@ int SystemService
mov BX, Mem_BootSector_Start mov BX, Mem_BootSector_Start
mov SP, BX mov SP, BX
String_Out PostMsg, [PostMsg_len] String_Out PostMsg, [PostMsg_len]
mov AH, BIOS_Wait mov AH, BIOS_Wait
mov CX, 0x05 mov CX, 0x05
int SystemService int SystemService
; Load : File Table
; Loading the code from disk (storage) ; Loading the code from disk (storage)
mov DH, 0x0 ; Head NUm mov DH, 0x0 ; Head NUm
@ -57,14 +58,37 @@ int SystemService
; Read Disk (Storage) ; Read Disk (Storage)
mov AH, Disk_ReadIntoMemory mov AH, Disk_ReadIntoMemory
mov AL, 0x01 ; Num Sectors mov AL, 0x02 ; Num Sectors
int DiskService int DiskService
String_Out SendoffMsg, [SendOffMsg_len] String_Out FTableMsg, [FTableMsg_len]
mov AH, BIOS_Wait mov AH, BIOS_Wait
mov CX, 0x10 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 ; Jump if carry flag
; jc error ; jc error
@ -73,7 +97,7 @@ int SystemService
; jne error ; jne error
; Reset segment registers for ram ; Reset segment registers for ram
mov AX, 0x1000 mov AX, 0x2000
mov DS, AX mov DS, AX
mov DS, AX mov DS, AX
mov ES, AX mov ES, AX
@ -82,7 +106,7 @@ int SystemService
mov SS, AX mov SS, AX
; Heading to 16bit.scratch ; Heading to 16bit.scratch
jmp 0x1000:0x0 jmp 0x2000:0x0
;============================================================================================================= ;=============================================================================================================
@ -113,7 +137,7 @@ out_string:
mov BX, CX mov BX, CX
mov AL, [BX + SI] mov AL, [BX + SI]
xor BH, BH ; Clear BH for correct active page xor BH, BH ; Clear BH for correct active page
int VideoService int VideoService
add SI, 0x1 add SI, 0x1
jmp .loop jmp .loop
@ -125,21 +149,26 @@ int VideoService
ret ret
error: error:
String_Out ErrorMsg, [ErrorMsg_Len] String_Out ErrorMsg, [ErrorMsg_Len]
hlt ; Halt hlt ; Halt
;============================================================================================================= ;=============================================================================================================
; Data ; Data
;============================================================================================================= ;=============================================================================================================
ErrorMsg : db 'Failed - DiskService: ReadIntoMemory'
ErrorMsg_Len : dw 36 ErrorMsg_Len : dw 36
ErrorMsg : db 'Failed - DiskService: ReadIntoMemory'
PostMsg : db '16bit.boot', char_LF, char_CR PostMsg_len : dw 14
PostMsg_len : dw 13 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_len : dw 32
SendoffMsg : db 'Sending over to 16bit.scratch...'
;============================================================================================================= ;=============================================================================================================
; Wrap up ; Wrap up
;============================================================================================================= ;=============================================================================================================

13
16bit.ftable.s Normal file
View File

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

Binary file not shown.

13
16bit.symtable.s Normal file
View File

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

View File

@ -9,50 +9,58 @@
%macro Video_SetTextMode_80x25 0 %macro Video_SetTextMode_80x25 0
mov AH, Video_SetMode mov AH, Video_SetMode
mov AL, VideoMode_Text_80x25 mov AL, VideoMode_Text_80x25
int VideoService int VideoService
%endmacro %endmacro
%macro Video_SetGraphicsMode_320x200 0 %macro Video_SetGraphicsMode_320x200 0
mov AH, Video_SetMode mov AH, Video_SetMode
mov AL, VideoMode_Graphics_320x200 mov AL, VideoMode_Graphics_320x200
int VideoService int VideoService
%endmacro %endmacro
%macro Video_SetGraphicsMode_640x200 0 %macro Video_SetGraphicsMode_640x200 0
mov AH, Video_SetMode mov AH, Video_SetMode
mov AL, VideoMode_Graphics_640x200 mov AL, VideoMode_Graphics_640x200
int VideoService int VideoService
%endmacro %endmacro
;============================================================================================================= ;=============================================================================================================
; Routines ; Routines
;============================================================================================================= ;=============================================================================================================
%macro Char_Out 1
mov AH, Video_TeleType
mov AL, %1
int VideoService
%endmacro
%macro DumpOut 2 %macro DumpOut 2
mov BX, %1 mov BX, %1
mov DX, %2 mov DX, %2
call out_Dump call out_Dump
%endmacro %endmacro
%macro Hex16_ToString 2 %macro Hex16_ToString 2
mov DX, %1 mov DX, %1
mov CX, %2 mov CX, %2
push CX push CX
call h16_toString call h16_toString
pop CX pop CX
%endmacro %endmacro
%macro Char_Out 1 %macro NewLine_Out 0
mov AH, Video_TeleType mov AH, Video_TeleType
mov AL, %1 mov AL, char_LF
int VideoService int VideoService
mov AL, char_CR
int VideoService
%endmacro %endmacro
%macro String_Out 2 %macro String_Out 2
mov BX, %1 mov BX, %1
mov AX, %2 mov AX, %2
push AX push AX
call out_string call out_string
pop AX pop AX
%endmacro %endmacro

View File

@ -27,8 +27,8 @@ out_Dump:
push SI push SI
mov AX, StartLocation mov AX, StartLocation
add AX, SI add AX, SI
Hex16_ToString AX, .HexStr Hex16_ToString AX, .HexStr
String_Out .HexStr, 4 String_Out .HexStr, 4
pop SI pop SI
pop DX pop DX
pop BX pop BX
@ -43,16 +43,16 @@ Char_Out ' '
push BX push BX
push DX push DX
push SI push SI
Hex16_ToString [.HexNum], .HexStr Hex16_ToString [.HexNum], .HexStr
String_Out .HexStr, 4 String_Out .HexStr, 4
pop SI pop SI
pop DX pop DX
pop BX pop BX
Char_Out ' ' Char_Out ' '
mov AH, BIOS_Wait mov AH, BIOS_Wait
mov CX, 0x02 mov CX, 0x02
int SystemService int SystemService
inc SI inc SI
jmp .loop jmp .loop
@ -145,7 +145,7 @@ out_string:
mov BX, CX mov BX, CX
mov AL, [BX + SI] mov AL, [BX + SI]
xor BH, BH ; Clear BH for correct active page xor BH, BH ; Clear BH for correct active page
int VideoService int VideoService
add SI, 0x1 add SI, 0x1
jmp .loop jmp .loop

View File

@ -304,6 +304,20 @@
; Disk Services (Storage) ; Disk Services (Storage)
%define DiskService 0x13 %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 ; Memory
; Real Mode - Conventional Lower Memory ; Real Mode - Conventional Lower Memory
@ -347,6 +361,18 @@
%define VideoMode_Graphics_320x200 0x04 %define VideoMode_Graphics_320x200 0x04
%define VideoMode_Graphics_320x200_cboff 0x05 %define VideoMode_Graphics_320x200_cboff 0x05
%define VideoMode_Graphics_640x200 0x06 %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 ; Output a character
%define Video_TeleType 0xE %define Video_TeleType 0xE
@ -360,8 +386,8 @@
%define char_CR 0xD ; Carriage Return %define char_CR 0xD ; Carriage Return
%define char_LF 0xA ; Line Feed %define char_LF 0xA ; Line Feed
%define str_endl char_LF, char_CR
%define AAL_x86_Def %define AAL_x86_Def
%endif %endif

View File

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

18
Makefile Normal file
View File

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

1
run.ps1 Normal file
View File

@ -0,0 +1 @@
qemu-system-x86_64 -fda 16bit.loader