OSDev.org
https://forum.osdev.org/

Boot sector
https://forum.osdev.org/viewtopic.php?f=13&t=57042
Page 1 of 1

Author:  Teuton [ Thu Dec 07, 2023 8:54 pm ]
Post subject:  Boot sector

With GPT we have this code as Boot Sector: section .text
Code:
    org 0x7C00
   
    mov bp, 0x7C00
    mov sp, bp
    mov ah, 0x0E

    mov al, 'O'
    int 0x10
   
    mov al, 'p'
    int 0x10

    mov al, 'S'
    int 0x10

    mov al, 'y'
    int 0x10

    mov al, 's'
    int 0x10

    mov al, '1'
    int 0x10
    jmp $

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

Here we create .bin
nasm -f bin boot_sector.asm -o boot_sector.bin

create .img
fsutil file createnew boot_disk.img 1474560

copy
copy /B boot_sector.bin + boot_disk.img /B boot_disk.img
-----------------------------
after Oracle VM Box has decline this format, he recomend to convert

VBoxManage clonehd C:\boot_disk.img C:\boot_disk.vdi --format VDI

How do You think, can this work in principe? I not very trust GPT instruction.

Author:  Octocontrabass [ Thu Dec 07, 2023 9:39 pm ]
Post subject:  Re: Boot sector

Code:
    mov sp, bp

The BIOS does not initialize SS. If you set SP without setting SS, your stack is at an unknown location.

Code:
    mov ah, 0x0E
    int 0x10

This BIOS call may modify AX, BP, SI, and DI. Your code relies on AH remaining unmodified, so your code may not work on some PCs.

Teuton wrote:
fsutil file createnew boot_disk.img 1474560
copy /B boot_sector.bin + boot_disk.img /B boot_disk.img

You create a disk image that's the correct size for a floppy disk, then you make it bigger when you add your boot sector, so the resulting file is the wrong size for a floppy disk.

Teuton wrote:
How do You think, can this work in principe?

Only if you correct the mistakes.

Teuton wrote:
I not very trust GPT instruction.

You shouldn't trust GPT. It doesn't know what it's talking about.

Author:  nullplan [ Thu Dec 07, 2023 10:49 pm ]
Post subject:  Re: Boot sector

Octocontrabass wrote:
Teuton wrote:
I not very trust GPT instruction.

You shouldn't trust GPT. It doesn't know what it's talking about.
I concur. GPT makes texts that look good but are complete nonsense. And especially in the case of source code, remembering where all the pieces go is important. This "bootloader" for example only prints a string (in a really circuitous way; I would have gone for a loop). Nothing is actually loaded. Because that part is quite difficult with lots of tradeoffs.

My advice for bootloaders remains the same: Use an existing one. Don't hobble yourself with implementing a new one and looking into all the different issues you may have. Especially when it comes to legacy (non-UEFI) ones, which are never going to be useful again.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/