简体   繁体   中英

Register setup for bare metal

I am trying to code bios level applications for fun. I tested my program on a vm and it worked but on bare metal it's very glitchy. I have heard that you need to setup segments and registers before coding at bare medal, but I can't find any resources on what setup I need to do. If it will help here is the code:

; I know this is not the proper way to print a string, but its just for testing

start:
    mov ah, 0x0e
    mov al, 'H'
    int 0x10
    mov al, 'e'
    int 0x10
    mov al, 'l'
    int 0x10
    mov al, 'l'
    int 0x10
    mov al, 'o'
    int 0x10
    mov al, ' '
    int 0x10
    mov al, 'W'
    int 0x10
    mov al, 'o'
    int 0x10
    mov al, 'r'
    int 0x10
    mov al, 'l'
    int 0x10
    mov al, 'd'
    int 0x10
    mov al, '!'
    int 0x10
    jmp $
    times 510-($-$$) db 0
    db 0x55, 0xaa

And here is the output

Hello Wld!

I have tried printing other things and they are very inconsistent and glitchy.

Boot sector with your program should look like this:

00000000: B4 0E B0 48 CD 10 B0 65  CD 10 B0 6C CD 10 B0 6C    H   e   l   l
00000010: CD 10 B0 6F CD 10 B0 20  CD 10 B0 57 CD 10 B0 6F    o       W   o
00000020: CD 10 B0 72 CD 10 B0 6C  CD 10 B0 64 CD 10 B0 21    r   l   d   !
00000030: CD 10 EB FE 00 00 00 00  00 00 00 00 00 00 00 00      
00000040: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
        25 x ---- " ----
000001E0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
000001F0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 AA 

When this file is loaded by boot firmware at the address 0x07C00, BIOS will overwrite the memory at 0x07C1E by a 11 bytes long structure called Disk Base Table . This will damage the part of your code responsible for displaying few letters of the expected message.

As @fuz recommended, boot code is not a sane environment for beginners to start with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM