Boot sector

Programming, for all ages and all languages.
Post Reply
Teuton
Posts: 3
Joined: Thu Feb 02, 2023 5:13 pm

Boot sector

Post 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.
Octocontrabass
Member
Member
Posts: 5549
Joined: Mon Mar 25, 2013 7:01 pm

Re: Boot sector

Post 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.
nullplan
Member
Member
Posts: 1780
Joined: Wed Aug 30, 2017 8:24 am

Re: Boot sector

Post 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.
Carpe diem!
Post Reply