I am writing my own bootloader in NASM x86 on x86_64 architechture, for starters I am just trying to copy the existing bootloader into second sector by using dd, then copy it back and run it from assembly.
file.asm
org 0x7c00
jmp 0:start
start:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x8000
mov ah, 0x02
mov al, 1
mov dl, 0x80
mov ch, 0
mov dh, 0
mov cl, 3
mov bx, 0x7e00
int 0x13
jmp 0x7e00
times 510-($-$$) db 0
dw 0xaa55
times (1024 - ($ - $$)) db 0x00
third_sector:
mov ah, 0x02
mov al, 1
mov dl, 0x80
mov ch, 0
mov dh, 0
mov cl, 2
mov bx, 0x7c00
int 0x13
jmp 0x7c00
The code sets up the stack, then pats itself to 1024 bytes with zeroes to have the last bit of code in third sector of the disk, then it loads the second sector from the disk into the first one and jumps to the first sector.
src.sh
#!/bin/bash
dd bs=1 count=512 if=/dev/c0d0 of=tmp
nasm -f bin file.asm -o file
dd bs=1 count=1200 if=file of=/dev/c0d0
dd bs=1 count=512 seek=512 if=tmp of=/dev/c0d0
What I am doing is copying the original bootloader into temporary file called tmp, then compiling my programme and putting it into old bootloader's place (/dev/c0d0 since I am working on MINIX 3.3.0), then moving old bootloader into second sector.
The result is "Booting from hard disk" string, which is fine, and then I get "NetBSD MBR boot Error P" which corresponds to "no netBSD partition".
Edit: Pasted the wrong asm file. Second edit: Error changed, but still persists.