mirror of
https://github.com/Ed94/bare_x86.git
synced 2024-12-26 17:04:44 -08:00
Got disk loading to work.
COPY /b 16bit.boot 16bit.scratch 16bit.loader qemu-system-x86_64 -fda 16bit.loader
This commit is contained in:
parent
fb3b3aa33d
commit
01081ce167
@ -1,60 +0,0 @@
|
||||
; Hello world.
|
||||
|
||||
; x86
|
||||
; 16-bit - Real Mode, V86 Mode
|
||||
|
||||
%include "AAL.x86.S"
|
||||
|
||||
|
||||
; 16-Bit Mode
|
||||
[BITS 16]
|
||||
; The ORG directive specifies the starting address of a segment
|
||||
[ORG Mem_BootSector_Start]
|
||||
|
||||
|
||||
start :
|
||||
|
||||
textmode_ClearScreen:
|
||||
; Params
|
||||
mov AH, Video_SetMode
|
||||
mov AL, VideoMode_Text_40x25
|
||||
; Call Interrupt
|
||||
int VideoService
|
||||
|
||||
teletype_HelloWorld :
|
||||
mov BH, 0x0 ; Make sure the Active page is the first
|
||||
mov AH, Video_TeleType
|
||||
mov AL, 'H'
|
||||
int VideoService
|
||||
mov AL, 'e'
|
||||
int VideoService
|
||||
mov AL, 'l'
|
||||
int VideoService
|
||||
mov AL, 'l'
|
||||
int VideoService
|
||||
mov AL, 'l'
|
||||
int VideoService
|
||||
mov AL, 'o'
|
||||
int VideoService
|
||||
mov AL, ' '
|
||||
int VideoService
|
||||
mov AL, 'W'
|
||||
int VideoService
|
||||
mov AL, 'o'
|
||||
int VideoService
|
||||
mov AL, 'r'
|
||||
int VideoService
|
||||
mov AL, 'l'
|
||||
int VideoService
|
||||
mov AL, 'd'
|
||||
int VideoService
|
||||
|
||||
hang :
|
||||
jmp short hang
|
||||
|
||||
|
||||
; Byte pad 512 bytes (zeroed)
|
||||
times 510-$+start db 0
|
||||
; Master Boot Record signature
|
||||
db 0x55
|
||||
db 0xAA
|
Binary file not shown.
93
16bit.Output.Tests.s
Normal file
93
16bit.Output.Tests.s
Normal file
@ -0,0 +1,93 @@
|
||||
; 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]
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Boot Sector Code
|
||||
;=============================================================================================================
|
||||
start:
|
||||
Video_SetTextMode_80x25
|
||||
; Video_SetGraphicsMode_320x200
|
||||
; Video_SetGraphicsMode_640x200
|
||||
|
||||
; 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 BX, Mem_BootSector_Start
|
||||
mov SP, BX
|
||||
|
||||
; String testing
|
||||
String_Out TestStr, [TestStr_len]
|
||||
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x02
|
||||
int SystemService
|
||||
|
||||
; Hex Testing
|
||||
String_Out HexTest, [HexTest_len]
|
||||
Hex16_ToString [HexNumA], HexStringA
|
||||
Hex16_ToString [HexNumB], HexStringB
|
||||
String_Out ResultStr, [ResultStr_len]
|
||||
String_Out HexStringA, 4
|
||||
String_Out HexStringB, 4
|
||||
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x10
|
||||
int SystemService
|
||||
|
||||
Char_Out char_LF
|
||||
Char_Out char_CR
|
||||
|
||||
DumpOut 0x7C00, 512
|
||||
|
||||
; Idle
|
||||
hang :
|
||||
jmp short hang
|
||||
|
||||
|
||||
%include "AAL.x86.routines.s"
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Data
|
||||
;=============================================================================================================
|
||||
TestStr : db 'String Test', char_LF, char_CR
|
||||
TestStr_len : dw 13
|
||||
|
||||
HexTest : db 'Hex Test', char_LF, char_CR
|
||||
HexTest_len : dw 10
|
||||
|
||||
HexNumA : dw 0x1994
|
||||
HexNumB : dw 0x2022
|
||||
HexStringA : db '0000'
|
||||
HexStringB : db '0000'
|
||||
|
||||
ResultStr : db 'Result: '
|
||||
ResultStr_len : db 8
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Wrap up
|
||||
;=============================================================================================================
|
||||
; Byte pad 512 bytes (zeroed)
|
||||
times 510-$+start db 0
|
||||
; Master Boot Record signature
|
||||
db 0x55
|
||||
db 0xAA
|
@ -1,94 +1,36 @@
|
||||
; 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]
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Boot Sector Code
|
||||
; Entrypoint
|
||||
;=============================================================================================================
|
||||
start:
|
||||
Video_SetTextMode_80x25
|
||||
; Video_SetGraphicsMode_320x200
|
||||
; Video_SetGraphicsMode_640x200
|
||||
|
||||
; 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 BX, Mem_BootSector_Start
|
||||
mov SP, BX
|
||||
String_Out EntryMsg, [EntryMsg_len]
|
||||
|
||||
; String testing
|
||||
String_Out TestStr, [TestStr_len]
|
||||
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x02
|
||||
int SystemService
|
||||
|
||||
; Hex Testing
|
||||
String_Out HexTest, [HexTest_len]
|
||||
Hex16_ToString [HexNumA], HexStringA
|
||||
Hex16_ToString [HexNumB], HexStringB
|
||||
String_Out ResultStr, [ResultStr_len]
|
||||
String_Out HexStringA, 4
|
||||
String_Out HexStringB, 4
|
||||
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x10
|
||||
int SystemService
|
||||
|
||||
Char_Out char_LF
|
||||
Char_Out char_CR
|
||||
|
||||
DumpOut 0x7C00, 512
|
||||
|
||||
; Idle
|
||||
hang:
|
||||
jmp short hang
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Data
|
||||
;=============================================================================================================
|
||||
EntryMsg : db 'Hello World!', char_LF, char_CR
|
||||
EntryMsg_len : dw 14
|
||||
|
||||
|
||||
%include "AAL.x86.routines.s"
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Data
|
||||
;=============================================================================================================
|
||||
TestStr : db 'String Test', char_LF, char_CR
|
||||
TestStr_len : dw 13
|
||||
|
||||
HexTest : db 'Hex Test', char_LF, char_CR
|
||||
HexTest_len : dw 10
|
||||
|
||||
HexNumA : dw 0x1994
|
||||
HexNumB : dw 0x2022
|
||||
HexStringA : db '0000'
|
||||
HexStringB : db '0000'
|
||||
|
||||
ResultStr : db 'Result: '
|
||||
ResultStr_len : db 8
|
||||
|
||||
;=============================================================================================================
|
||||
; Wrap up
|
||||
;=============================================================================================================
|
||||
; Byte pad 512 bytes (zeroed)
|
||||
times 510-$+start db 0
|
||||
; Master Boot Record signature
|
||||
db 0x55
|
||||
db 0xAA
|
||||
times 512-$+start db 0
|
||||
|
150
16bit.boot.S
Normal file
150
16bit.boot.S
Normal file
@ -0,0 +1,150 @@
|
||||
; x86
|
||||
; 16-bit - Real Mode, V86 Mode
|
||||
|
||||
%include "AAL.x86.s"
|
||||
|
||||
|
||||
%macro String_Out 2
|
||||
mov BX, %1
|
||||
mov AX, %2
|
||||
push AX
|
||||
call out_string
|
||||
pop AX
|
||||
%endmacro
|
||||
|
||||
|
||||
; 16-Bit Mode
|
||||
[BITS 16]
|
||||
; The ORG directive specifies the starting address of a segment
|
||||
[ORG Mem_BootSector_Start]
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Boot Sector Code
|
||||
;=============================================================================================================
|
||||
start:
|
||||
; Give some times before starting
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x10
|
||||
int SystemService
|
||||
|
||||
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 BX, Mem_BootSector_Start
|
||||
mov SP, BX
|
||||
|
||||
String_Out PostMsg, [PostMsg_len]
|
||||
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x05
|
||||
int SystemService
|
||||
|
||||
|
||||
; Loading the code from disk (storage)
|
||||
mov DH, 0x0 ; Head NUm
|
||||
mov DL, 0x0 ; Drive Num
|
||||
mov CH, 0x0 ; Track Num
|
||||
mov CL, 0x02 ; Starting Sector
|
||||
; Setup ES:BX Memory address/segment
|
||||
mov BX, 0x1000 ; ES:BX : 0x1000:0x0
|
||||
mov ES, BX
|
||||
mov BX, 0x0
|
||||
|
||||
; Read Disk (Storage)
|
||||
mov AH, Disk_ReadIntoMemory
|
||||
mov AL, 0x01 ; Num Sectors
|
||||
int DiskService
|
||||
|
||||
String_Out SendoffMsg, [SendOffMsg_len]
|
||||
|
||||
mov AH, BIOS_Wait
|
||||
mov CX, 0x10
|
||||
int SystemService
|
||||
|
||||
; Jump if carry flag
|
||||
; jc error
|
||||
|
||||
; cmp DH, AL
|
||||
; jne error
|
||||
|
||||
; Reset segment registers for ram
|
||||
mov AX, 0x1000
|
||||
mov DS, AX
|
||||
mov DS, AX
|
||||
mov ES, AX
|
||||
mov FS, AX
|
||||
mov GS, AX
|
||||
mov SS, AX
|
||||
|
||||
; Heading to 16bit.scratch
|
||||
jmp 0x1000:0x0
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Routines
|
||||
;=============================================================================================================
|
||||
; Print out an ascii string of speicifed length
|
||||
out_string:
|
||||
; Arg - BX: String
|
||||
%define argLen BP + 4 ; String Length
|
||||
; Store previous state of BP and set it to SP
|
||||
; pusha ; 14 bytes
|
||||
push BP ; 4 bytes
|
||||
mov BP, SP
|
||||
; Using the source index
|
||||
push SI ; 0 bytes...
|
||||
xor SI, SI
|
||||
|
||||
; Backup BX for later
|
||||
mov CX, BX
|
||||
mov AH, Video_TeleType
|
||||
|
||||
.loop:
|
||||
; Bounds check
|
||||
cmp SI, [argLen]
|
||||
je .break
|
||||
|
||||
; Output a character
|
||||
mov BX, CX
|
||||
mov AL, [BX + SI]
|
||||
xor BH, BH ; Clear BH for correct active page
|
||||
int VideoService
|
||||
|
||||
add SI, 0x1
|
||||
jmp .loop
|
||||
|
||||
.break:
|
||||
pop SI
|
||||
pop BP
|
||||
%undef argLen
|
||||
ret
|
||||
|
||||
error:
|
||||
String_Out ErrorMsg, [ErrorMsg_Len]
|
||||
hlt ; Halt
|
||||
|
||||
|
||||
;=============================================================================================================
|
||||
; Data
|
||||
;=============================================================================================================
|
||||
ErrorMsg : db 'Failed - DiskService: ReadIntoMemory'
|
||||
ErrorMsg_Len : dw 36
|
||||
|
||||
PostMsg : db '16bit.boot', char_LF, char_CR
|
||||
PostMsg_len : dw 13
|
||||
|
||||
SendoffMsg : db 'Sending over to 16bit.scratch...'
|
||||
SendOffMsg_len : dw 32
|
||||
;=============================================================================================================
|
||||
; Wrap up
|
||||
;=============================================================================================================
|
||||
; Byte pad 512 bytes (zeroed)
|
||||
times 510-$+start db 0
|
||||
; Master Boot Record signature
|
||||
db 0x55
|
||||
db 0xAA
|
Loading…
Reference in New Issue
Block a user