Hello, I compile my OS project using this cmake code:
Code:
cmake_minimum_required(VERSION 3.7.2)
# Set the active output directories:
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build/x86_64/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/x86_64/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/x86_64/bin)
project(kernel)
enable_language(ASM_NASM)
set(KERNEL_BIN "kernel.bin")
set(KERNEL_ISO "kernel.iso")
set(KERNEL_LIB "kernel")
set(LINKER_SCRIPT targets/x86_64/linker.ld)
set(GRUB_CFG targets/x86_64/iso/boot/grub/grub.cfg)
set(CMAKE_C_FLAGS "-c -ffreestanding")
set(CMAKE_ASM_FLAGS "{CMAKE_ASM_FLAGS} -f elf64")
set(CMAKE_C_COMPILER "x86_64-elf-gcc")
set(CMAKE_LINKER "x86_64-elf-ld")
file(GLOB BOOT_ASM_MODULES src/impl/x86_64/boot/*.asm)
file(GLOB KERNEL_C_MODULES src/impl/kernel/*.c)
file(GLOB X86_64_C_MODULES src/impl/x86_64/*.c)
add_library(
${KERNEL_LIB}
STATIC
${BOOT_ASM_MODULES}
${KERNEL_C_MODULES}
${X86_64_C_MODULES}
)
include_directories(src/intf)
target_include_directories(${KERNEL_LIB} PUBLIC src/intf)
add_custom_command(TARGET ${KERNEL_LIB} POST_BUILD
COMMAND mkdir -p dist/x86_64
COMMAND x86_64-elf-ld -n -o dist/x86_64/${KERNEL_BIN} -T ${LINKER_SCRIPT} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${KERNEL_LIB}.a
COMMAND cp dist/x86_64/${KERNEL_BIN} targets/x86_64/iso/boot/${KERNEL_BIN}
COMMAND grub-mkrescue /usr/lib/grub/i386-pc -o dist/x86_64/${KERNEL_ISO} targets/x86_64/iso
)
When I run the .iso file that was built, I get these errors:
Quote:
error: no multiheader found.
error: you need to load the kernel first.
What could cause those problems?
Here is the grub.cfg file:
Code:
# Nobody knows what these lines do:
set timeout=0
set default=0
# Set the name of the OS in the boot menu:
menuentry "LearnOS" {
multiboot2 /boot/kernel.bin # Set the binary in this location.
boot
}
And here is the headers asm file:
Code:
; Constants:
MAGIC_NUMBER equ 0xe85250d6
CHECKSUM_INITIALIZER equ 0x100000000
HEADER_LENGTH equ (header_end - header_start)
; Name the Section:
section .multiboot_header
; Header Start:
header_start:
; Magic Number:
dd MAGIC_NUMBER ; Multiboot2
; Architecture:
dd 0 ; Protected mode i386
; Header Length:
dd HEADER_LENGTH
; Checksum:
dd CHECKSUM_INITIALIZER - (MAGIC_NUMBER + 0 + HEADER_LENGTH)
; End Tag:
dw 0
dw 0
dd 8
header_end:
And here is the linker code:
Code:
/* Specify where the entry point is (start): */
ENTRY(start)
/* Define t(he sections of our binary: */
SECTIONS
{
. = 1M; /* All OS data start 1M in. */
/* Set the boot section: */
.boot :
{
KEEP(*(.multiboot_header)) /* Include the multiboot header. */
}
/* Set the text section: */
.text :
{
*(.text) /* Include the text section (CPU instructions). */
}
}