Search code examples
makefileoperating-systemkernelbootbin

Unable to use type command to concatenate files, says syntax is not correct


I am building my own kernel and have 2 .bin files boot.bin and kernel.bin in my project, and I want to concatenate both of them into a single .img file called os.img. I am performing this action with the use of a makefile.

I have included the code for my makefile below:

all: bootloader
 
bootloader:
    mkdir boot\bin
    nasm boot/boot.asm -f bin -o boot/bin/boot.bin
    nasm boot/kernel_entry.asm -f elf -o boot/bin/kernel_entry.bin

    gcc -m32 -ffreestanding -c boot/main.c -o boot/bin/kernel.o
    ld -m i386pe -o boot/bin/kernel.img -Ttext 0x1000 boot/bin/kernel_entry.bin boot/bin/kernel.o

    objcopy -O binary -j .text boot/bin/kernel.img boot/bin/kernel.bin
    type boot/bin/boot.bin boot/bin/kernel.bin > os.img

clear:
    rm -f boot/boot.img
 
run:
    qemu-system-x86_64.exe -drive format=raw,file=os.img

However, when I run this script using the make command, it says that the syntax of the type command is incorrect. This may be a simple problem, but as far as I checked many resources on the internet, the syntax should be fine.

I got the below-mentioned error on running the make command:

type boot/bin/boot.bin,boot/bin/kernel.bin > os.img
The syntax of the command is incorrect.

I have tested my .asm and .c files and they work perfectly fine.

Below is the code for my .asm and .c files if they may be needed:

boot.asm

[org 0x7c00]
[bits 16]

section code

.switch:
    mov bx, 0x1000 ; location of the code being loaded from the hard disk
    mov ah, 0x02
    mov al, 30 ; number of sectors to read from the hard disk
    mov ch, 0x00
    mov dh, 0x00
    mov cl, 0x02
    int 0x13

    cli ; turn off interrupts
    lgdt [gdt_descriptor] ; load GDT table

    mov eax, cr0
    or eax, 0x1
    mov cr0, eax ; make the switch

    jmp code_seg:protected_start

startupmsg: db 'Welcome to Wyvern!', 0

[bits 32]
protected_start:
    mov ax, data_seg
    mov ds, ax
    mov ss, ax
    mov es, ax
    mov fs, ax
    mov gs, ax

    ; update stack pointer
    mov ebp, 0x90000
    mov esp, ebp

    call 0x1000
    jmp $

gdt_begin:
gdt_null_descriptor:
    dd 0x00
    dd 0x00
gdt_code_seg:
    dw 0xffff
    dw 0x00
    db 0x00
    db 10011010b
    db 11001111b
    db 0x00
gdt_data_seg:
    dw 0xffff
    dw 0x00
    db 0x00
    db 10010010b
    db 11001111b
    db 0x00
gdt_end:
gdt_descriptor:
    dw gdt_end - gdt_begin - 1
    dd gdt_begin
code_seg equ gdt_code_seg - gdt_begin
data_seg equ gdt_data_seg - gdt_begin

times 510 - ($ - $$) db 0x00 ; pads the file with 0s, making it the right size

db 0x55
db 0xaa

kernel.asm

[bits 32]
START:
[extern _start]
    call _start
    jmp $

main.c

char* video_memory;

int start() {
    video_memory = (char*) 0xb8000;

    for (int i = 0; i < 2 * 25 * 80; i += 2) {
        *(video_memory + i) = 0;
        *(video_memory + i + 1) = 0x0A;
    }
}

I have also attached the directory structure for my project below:

Directory structure

If anything else needs to be modified, please feel free to add to it.


Solution

  • I managed to figure out that type gives this error as the args are not formatted properly. So I made the following changes to my makefile:

    1. In the type command, replace all the forward-slashes with a backslash.
    2. Surround each file name with quotes

    This helped me solve the problem.