OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Apr 29, 2024 2:50 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: OS development help - unable to load on real computer
PostPosted: Sun Oct 22, 2023 8:58 am 
Offline

Joined: Sun Oct 22, 2023 8:31 am
Posts: 1
I have been using a couple of tutorials and using QEMU and VirtualBox to learn OS development. I have recently made three bootloaders which are a basic bootloader prints letter A using 0x10 interrupt, a bootloader that uses 0x13 to access disc and jumps to it, a bootloader that calls external C code.

I compile the code to .bin format using nasm and gcc -ffreestanding and then combine them using cat (in case of c kernel). The images work on qemu and if I turn them into floppy images they work on virtualbox too. When booting on a real computer the invalid partition table error is thrown so I followed the first part of this tutorial (https://wiki.osdev.org/Bootable_Disk#Creating_a_File_System_on_the_First_Partition) and used fdisk to just create partition table using option 'o' (DOS/MBR) then the last part adding the BIOS bootloader. This did not work. I have tested it on three computers, the first one says invalid partition table but does print letter B using the second bootloader if enter key is pressed, the second and third one does nothing except a blinking cursor. I have used legacy mode on all three computers. The third bootloader with external C code does not work or print anything on the real computer at all. Code for the first two bootloaders is below but I can post the bootloader with externel C code too if needed, it is just longer which is why I have not posted it.

Code:

; Basic bootloader to print letter A
[org 0x7c00]

mov ah, 0x0e ; tell bios we want to print character
mov al, 'A'
int 0x10

times 510 - ($ - $$) db 0
dw 0xAA55



Code:

; Basic bootloader to print letter A
[org 0x7c00]

xor ax, ax
mov ds, ax
cld

mov ah, 0x02 ;Read
mov al, 0x02 ;Read second sector
mov ch, 0x00 ;Cylinder 0
mov cl, 0x02 ;Sector
mov dh, 0x00
xor bx, bx
mov es, bx
mov bx, 0x8001 ;where to jump after reading sector
int 0x13

jmp 0x8001 ;Now load the second sector

times 510 - ($ - $$) db 0
dw 0xAA55

mov ah, 0x0e
mov al, 'B'
int 0x10

jmp $ ;loop here



Any guidance on what I am doing wrong? Thank you.


Top
 Profile  
 
 Post subject: Re: OS development help - unable to load on real computer
PostPosted: Tue Oct 24, 2023 8:12 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
hunter21 wrote:
I have been using a couple of tutorials

Bootloader tutorials are usually not very good. Also, writing your own bootloader takes time away from writing your OS. If you want to write an OS, you should use an existing bootloader like GRUB or Limine.

hunter21 wrote:
I compile the code to .bin format using nasm and gcc -ffreestanding and then combine them using cat (in case of c kernel).

That doesn't sound like the correct way to use GCC...

hunter21 wrote:
When booting on a real computer the invalid partition table error is thrown so I followed the first part of this tutorial

Huh. That tutorial has terrible advice, you don't need GPT or an ESP system partition to boot from USB.

hunter21 wrote:
and used fdisk to just create partition table using option 'o' (DOS/MBR) then the last part adding the BIOS bootloader. This did not work.

If you want to partition your USB drive for boot, your MBR must include exactly one active primary partition. Some BIOSes are picky about the geometry, too.

hunter21 wrote:
Code for the first two bootloaders is below but I can post the bootloader with externel C code too if needed, it is just longer which is why I have not posted it.

There are several websites (including GitHub and Gitlab) that can host all of your source code plus version history. You can use one of those to share your code. (You should use version control even if you don't want to use one of those websites.)

Code:
mov al, 0x02 ;Read second sector

The comment is incorrect. That value determines how many sectors to read, not which sector to read.

Code:
mov bx, 0x8001 ;where to jump after reading sector

You should use an aligned address. Also, you have no idea where the BIOS might have put its stack, so you might be overwriting the stack when you load data.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], SemrushBot [Bot] and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group