Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,76 @@ ARCH=i686
KERNEL=build/elsos-$(ARCH).bin
ISO=build/elsos-$(ARCH).iso
TARGET=$(ARCH)-elsos
RUST_OS=target/$(TARGET)/$(DEBUG_RELEASE)/libelsos.a
RUST_KERNEL=target/$(TARGET)/$(DEBUG_RELEASE)/libelsos.a

LD=$(ARCH)-elf-ld
CC=$(ARCH)-elf-gcc
AR=$(ARCH)-elf-ar

CFLAGS=-m32 -std=gnu99 -ffreestanding -Wall -Wextra -c
ARFLAGS=rcs

export CFLAGS
export CC

LD_SCRIPT=src/arch/$(ARCH)/linker.ld
LD_SCRIPT=linkers/$(ARCH).ld
GRUB_CFG=grub/grub.cfg

ASM_SRC=$(wildcard src/arch/$(ARCH)/*.asm)
ASM_OBJ=$(subst src/, build/, ${ASM_SRC:.asm=.o})

.PHONY: all clean run iso kernel
LIBC_SRC=$(wildcard src/libc/*.c)
LIBC_OBJ=$(subst src/, build/, ${LIBC_SRC:.c=.o})
LIBC_A=build/libc/libc.a

.PHONY: all clean run iso kernel libc

all: $(KERNEL)

run: $(ISO)
@qemu-system-i386 -drive format=raw,file=$(ISO) -serial stdio
qemu-system-i386 -drive format=raw,file=$(ISO) -serial stdio

rund: $(ISO)
@qemu-system-i386 -drive format=raw,file=$(ISO) -serial stdio -d int
qemu-system-i386 -drive format=raw,file=$(ISO) -serial stdio -d int

rundd: $(ISO)
@qemu-system-i386 -drive format=raw,file=$(ISO) -serial stdio -d int -s -S
qemu-system-i386 -drive format=raw,file=$(ISO) -serial stdio -d int -s -S

iso: $(ISO)

$(ISO): $(KERNEL) $(GRUB_CFG)
@mkdir -p build/iso/boot/grub
@cp $(KERNEL) build/iso/boot/elsos.bin
@cp $(GRUB_CFG) build/iso/boot/grub
@grub-mkrescue -o $(ISO) build/iso 2> /dev/null
@rm -r build/iso
mkdir -p build/iso/boot/grub
cp $(KERNEL) build/iso/boot/elsos.bin
cp $(GRUB_CFG) build/iso/boot/grub
grub-mkrescue -o $(ISO) build/iso 2> /dev/null
rm -r build/iso

libc: libc.a
libc: $(LIBC_A)

libc.a:
@make -C src/libc
@cp src/libc/libc.a .
$(LIBC_A): $(LIBC_OBJ)
$(AR) $(ARFLAGS) $@ $(LIBC_OBJ)

$(KERNEL): kernel $(RUST_OS) $(ASM_OBJ) $(LD_SCRIPT)
$(LD) -n --gc-sections -T $(LD_SCRIPT) -o $(KERNEL) $(ASM_OBJ) $(RUST_OS)
$(KERNEL): $(ASM_OBJ) $(RUST_KERNEL) $(LD_SCRIPT)
$(LD) -n --gc-sections -T $(LD_SCRIPT) -o $(KERNEL) $(ASM_OBJ) $(RUST_KERNEL)

kernel: libc
$(RUST_KERNEL): libc
cargo +nightly build --target $(TARGET).json

kernel: $(RUST_KERNEL)

clippy: libc
cargo +nightly clippy --target $(TARGET).json

# compile assembly files
build/arch/$(ARCH)/%.o: src/arch/$(ARCH)/%.asm
@mkdir -p $(shell dirname $@)
@nasm -f elf32 $< -o $@
nasm -f elf32 $< -o $@

build/libc/%.o: src/libc/%.c
@mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -o $@ $<

clean:
@rm -rf build
@rm -f libc.a
make -C src/libc clean
rm -rf build

mrproper: clean
cargo clean
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main()
{
println!("cargo:rustc-link-search=native=./");
println!("cargo:rustc-link-search=native=./build/libc");
println!("cargo:rustc-link-lib=static=c");
println!("cargo:rerun-if-changed=libc.a");
println!("cargo:rerun-if-changed=build/libc");
}
24 changes: 11 additions & 13 deletions src/arch/i686/linker.ld → linkers/i686.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,44 @@ ENTRY(_start)

SECTIONS
{
.boot BLOCK(4K) : ALIGN(4K)
. = 0x100000;
_kernel_start = .;
.boot ALIGN(4K) :
{
/* ensure that the multiboot header is at the beginning */
KEEP(*(.multiboot_header))
}
. = 0x00100000;
.text BLOCK(4K) : ALIGN(4K)
.text ALIGN(4K) :
{
_kernel_start = .;
*(.text)
}
/* Read-only data. */
.rodata BLOCK(4K) : ALIGN(4K)
.rodata ALIGN(4K) :
{
*(.rodata)
}

/* Read-write data (initialized) */
.data BLOCK(4K) : ALIGN(4K)
.data ALIGN(4K) :
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
.bss ALIGN(4K) :
{
*(COMMON)
*(.bss)
}
.stab BLOCK(4K) : ALIGN(4K)
.stab ALIGN(4K) :
{
*(.stab)
}
.stabstr BLOCK(4K) : ALIGN(4K)
.stabstr ALIGN(4K) :
{
*(.stabstr)
}
.note BLOCK(4K) : ALIGN(4K)
.note ALIGN(4K) :
{
*(.note)
}
.comment BLOCK(4K) : ALIGN(4K)
.comment ALIGN(4K) :
{
*(.comment)
}
Expand Down
17 changes: 0 additions & 17 deletions src/libc/Makefile

This file was deleted.