Page 1 of 1

Boot sector

Posted: Thu Dec 07, 2023 8:54 pm
by Teuton
With GPT we have this code as Boot Sector: section .text

Code: Select all

    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.

Re: Boot sector

Posted: Thu Dec 07, 2023 9:39 pm
by Octocontrabass

Code: Select all

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

Code: Select all

    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.

Re: Boot sector

Posted: Thu Dec 07, 2023 10:49 pm
by nullplan
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.