mirror of
https://github.com/Ed94/bare_x86.git
synced 2024-12-26 00:44:45 -08:00
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:
parent
01081ce167
commit
8d1ec63cc1
1
.gitignore
vendored
1
.gitignore
vendored
@ -0,0 +1 @@
|
||||
16bit.loader
|
128
16bit.Scratch.s
128
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"
|
||||
|
61
16bit.boot.S
61
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
|
||||
;=============================================================================================================
|
||||
|
13
16bit.ftable.s
Normal file
13
16bit.ftable.s
Normal 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
13
16bit.symtable.s
Normal 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
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
30
AAL.x86.s
30
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
|
||||
|
||||
|
||||
|
79
Erus.boot.s
79
Erus.boot.s
@ -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
18
Makefile
Normal 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
|
Loading…
Reference in New Issue
Block a user