i am currently following an OS dev tutorial (https://www.youtube.com/watch?v=pXzortxPZR8&list=PLxN4E629pPnKKqYsNVXpmCza8l0Jb6l8-)
i reached episode 4 and i decided to test my os on real hardware, so i copied the binary contents of the "boot.bin" file and i put it on a USB flash drive using HxD Hex Editor. i also made sure to put the bytes into the correct sectors, but when i tried to boot from it all i got was a smiley face emoji at the bottom of the screen (the os is made to read 4 sectors from the disk and say "disk read successfully" if it successfully did so, it also is 32 bit and i made a Global Descriptor Table from the tutorial) the usb i used was a 4gb MBR formattet USB with the FAT file system, i also tried FAT32 but it didnt help, also the computer i used to boot from is an old PC that i decided to make an os for (it has a dead hdd so i cant install windows on it and i decided i could learn something new by doing this). can anyone help me? i would really like to get this working.
EDIT: i forgot to mention this, but as the title says, it works perfectly fine on emulators
Bootloader:
[org 0x7c00]
mov [BOOT_DISK], dl
mov bp, 0x7c00
mov sp, bp
call ReadDisk
jmp PROGRAM_SPACE
%include "print.asm"
%include "DskRead.asm"
times 510-($-$$) db 0
dw 0xaa55
Read Disk Program:
PROGRAM_SPACE equ 0x7e00
ReadDisk:
mov ah, 0x02
mov bx, PROGRAM_SPACE
mov al, 4
mov dl, [BOOT_DISK]
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
int 0x13
jc DiskReadFailed
ret
BOOT_DISK:
db 0
DiskReadErrorStr:
db 'Failed To Read Disk',0
DiskReadFailed:
mov bx, DiskReadErrorStr
call printstr
jmp $
Extended Program (the code written on secotr 2 or higher):
[org 0x7e00]
jmp EnterProtectedMode
%include "gdt.asm"
%include "print.asm"
EnterProtectedMode:
call EnableA20
cli
lgdt [gdt_descriptor]
mov eax, cr0
mov eax, 1
mov cr0, eax
jmp codeseg:StartProtectedMode
EnableA20:
in al, 0x92
or al, 2
out 0x92, al
ret
[bits 32]
StartProtectedMode:
mov ax, dataseg
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov [0xb8000], byte 'H'
jmp $
times 2048-($-$$) db 0
print function code:
printstr:
mov ah, 0x0e
.Loop:
cmp [bx], byte 0
je .Exit
mov al, [bx]
int 0x10
inc bx
jmp .Loop
.Exit:
ret
GDT:
gdt_nulldesc:
dd 0
dd 0
gdt_codedesc:
dw 0xFFFF
dw 0x0000
db 0x00
db 10011010b
db 11001111b
db 0x00
gdt_datadesc:
dw 0xFFFF
dw 0x0000
db 0x00
db 10010010b
db 11001111b
db 0x00
gdt_end:
gdt_descriptor:
gdt_size:
dw gdt_end - gdt_nulldesc - 1
dd gdt_nulldesc
codeseg equ gdt_codedesc - gdt_nulldesc
dataseg equ gdt_datadesc - gdt_nulldesc
Run Bat script (QEMU):
qemu-system-x86_64 boot.bin
Compile Bat Script (NASM):
nasm -f bin boot.asm -o boot.bin
nasm -f bin ExtPrg.asm -o ExtPrg.bin
copy /b boot.bin+ExtPrg.bin boot.bin