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.