最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

assembly - Issue when running Makefile on boot.asm, "init :: non dos media" - Stack Overflow

programmeradmin2浏览0评论

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:

 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

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:

 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
Share Improve this question edited Mar 19 at 6:23 Michael Petch 47.8k9 gold badges119 silver badges215 bronze badges asked Mar 19 at 4:18 Joshua AlexanderJoshua Alexander 314 bronze badges 3
  • 2 Debugging questions need a self-contained minimal reproducible example. A link to your code on github is good, but can't be the only way you include your code. Since this is probably a pretty early-boot problem, the minimal reproducible example can presumably be pretty simple, like just a jmp $ or hlt loop for code in a boot sector. – Peter Cordes Commented Mar 19 at 5:47
  • 3 You should just add the code and Makefile right to your question (they aren't very big). Anyway I think the problem is that you have bdb_reserved_sectors: db 1 when it should be bdb_reserved_sectors: dw 1 (note the change from db to dw). Because of this error mcopy doesn't see the floppy image as valid so can't write to it. – Michael Petch Commented Mar 19 at 6:16
  • 1 Thank you @MichaelPetch ! After trying your recommendation it worked without issue! – Joshua Alexander Commented Mar 20 at 20:51
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论