0

I am trying to run a simple bootloader with a dummy kernel in qemu, the bootloader seems to work fine, I get no errors running qemu or commands compiling it, just a warning from qemu that probing guessed raw.

My boot loader is :

[org 0x7c00]
[bits 16]

bt:
    mov ax, 0x0201
    mov bx, 0x1000
    mov cx, 0x0002
    mov dx, 0x0000
    mov es, bx
    int 0x13
    jc  dsk_err
    mov ax, 0x0e24 ;print '$'
    mov bh, 0
    int 0x10
    jmp 0x1000:0x00

dsk_err:
    mov ax, 0x0e21 ;print '!'
    mov bh, 0
    int 0x10
    hlt

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

Then the dummy kernel looks like

[org 0]
[bits 16]

section .text
    global _start

_start:
    mov ax, 0x0e21 ;print '!' to make sure it works
    mov bh, 0
    int 0x10
    hlt

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

and then to separate the two I have a file called zero.bin created by an asm file that looks like times 0x1000-512 db 0

The only output I get in qemu is a single $

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
kwphil
  • 1
  • 1
  • Your `zero.bin` is not needed since you load the second sector. – Jester Jul 30 '23 at 18:30
  • 1
    You're loading to `es:bx` = 1000h:1000h (linear 11000h) but jumping to 1000h:0. – ecm Jul 30 '23 at 18:37
  • Also you should use the `dl` set up by the prior loader, only set `dh`. And you should set up your own stack to avoid the possibility of it clashing with your disk read. Eg `ss:sp` = 0:7C00h. (Make sure to set `ss` first then in the very next instruction set `sp`.) To stop execution once you're at the end of the program a better solution is `haltloop:` \ `sti` \ `hlt` \ `jmp haltloop`, a single `hlt` is not enough and I wouldn't recommend `cli` \ `hlt` either. The `section` and `global` directives are at best useless as is. – ecm Jul 30 '23 at 18:42
  • How would I set the SS register? When I try to set it with MOV, NASM just returns: Invalid combination of opcodes and operands – kwphil Jul 30 '23 at 20:59
  • 1
    To set SS you have to use an intermediate register (or from a memory address) like AX, BX, CX, DX, SI, Di, and BP. So you could do `mov ax, 0` `mov ss, ax` . – Michael Petch Jul 30 '23 at 22:47

0 Answers0