assemblymakefilex86-16bootloaderosdev

Issue when running Makefile on boot.asm, "init :: non dos media"


I've been trying to build a custom OS following the steps in this guide. However, I continue to get the following error from my Makefile,

init :: non DOS media
Cannot initialize '::' ::kernel.bin: Success
make: *** [Makefile:20: build/main_floppy.img] Error 1```

Makefile:

ASM=nasm
CC=gcc
SRC_DIR=src
TOOLS_DIR=tools
BUILD_DIR=build

.PHONY: all floppy_image kernel bootloader clean always tools_fat

#ALL
all: floppy_image tools_fat


#FLOPPY IMAGE
floppy_image: $(BUILD_DIR)/main_floppy.img

$(BUILD_DIR)/main_floppy.img: bootloader kernel
    dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880
    mkfs.fat -F12 -n "MOOM_OS" $(BUILD_DIR)/main_floppy.img
    dd if=$(BUILD_DIR)/bootloader.bin of=$(BUILD_DIR)/main_floppy.img conv=notrunc
    mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin"

#BOOTLOADER
bootloader: $(BUILD_DIR)/bootloader.bin

$(BUILD_DIR)/bootloader.bin: always
    $(ASM) $(SRC_DIR)/bootloader/boot.asm -f bin -o $(BUILD_DIR)/bootloader.bin

#KERNEL
kernel: $(BUILD_DIR)/kernel.bin

$(BUILD_DIR)/kernel.bin: always
    $(ASM) $(SRC_DIR)/kernel/main.asm -f bin -o $(BUILD_DIR)/kernel.bin

#TOOLS
tools_fat: $(BUILD_DIR)/tools/fat

$(BUILD_DIR)/tools/fat: always $(TOOLS_DIR)/fat/fat.c
    mkdir -p $(BUILD_DIR)/tools
    $(CC) -g -o2 $(BUILD_DIR)/tools/fat $(TOOLS_DIR)/fat/fat.c

#ALWAYS
always:
    mkdir -p $(BUILD_DIR)

#CLEAN
clean:
    rm -rf $(BUILD_DIR)/*

boot.asm:

org 0x7C00
bits 16

%define ENDL 0x0D, 0x0A

jmp strict short start
nop

bdb_oem:                    db "MSWIN4.1"
bdb_bytes_per_sector:       dw 512
bdb_sectors_by_cluster:     db 1
bdb_reserved_sectors:       db 1
bdb_fat_count:              db 2
bdb_dir_entries_count:      dw 0E0H
bdb_total_secotrs:          dw 2880
bdb_media_descriptor_type:  db 0F0H
bdb_sectors_per_fat:        dw 9
bdb_sectors_per_track:      dw 18
bdb_heads:                  dw 2
bdb_hidden_sectors:         dd 0
bdb_large_sector_count:     dd 0

ebr_drive_number:           db 0
                            db 0
ebr_signature:              db 29H
ebr_volume_id:              db 12H, 34H, 56H, 78H
ebr_volume_label:           db "MOOM     OS"
ebr_system_id:              db "FAT12   "

start:
    jmp main

puts:
    push si
    push ax

.loop:
    lodsb
    or al, al
    jz .done

    mov ah, 0x0e
    mov bh, 0
    int 0x10

    jmp .loop

.done:
    pop ax
    pop si
    ret

main:
    xor ax, ax
    mov ds, ax
    mov es, ax
    
    mov ss, ax
    mov sp, 0x7C00

    hlt

.halt:
        jmp .halt


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

Solution

  • After trying the recommendation from Michael, to change bdb_reserved_sectors: db 1 to bdb_reserved_sectors: dw 1, the issue was resolved! Thank you for fixing my oversight, hopefully this won't happen again.