From c5bd05fa070d25ae6700660347bdb59ae84390e6 Mon Sep 17 00:00:00 2001 From: Xander Date: Wed, 28 Jun 2023 22:49:01 +0200 Subject: Calling c code --- Makefile | 13 +++++++++++-- arch/x86_64/boot/long_mode_init.asm | 3 +++ kernel/main.c | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 kernel/main.c diff --git a/Makefile b/Makefile index 4178a71..02592c9 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,10 @@ assembly_source_files := $(wildcard arch/$(arch)/boot/*.asm) assembly_object_files := $(patsubst arch/$(arch)/boot/%.asm, \ build/arch/$(arch)/%.o, $(assembly_source_files)) +c_source_files := $(wildcard kernel/*.c) +c_object_files := $(patsubst kernel/%.c, \ + build/kernel/%.o, $(c_source_files)) + .PHONY: all clean run iso all: $(kernel) @@ -27,10 +31,15 @@ $(iso): $(kernel) $(grub_cfg) @grub-mkrescue -o $(iso) build/isofiles 2> /dev/null @rm -r build/isofiles -$(kernel): $(assembly_object_files) $(linker_script) - @ld -n -T $(linker_script) -o $(kernel) $(assembly_object_files) +$(kernel): $(assembly_object_files) $(linker_script) $(c_object_files) + @ld -n -T $(linker_script) -o $(kernel) $(assembly_object_files) $(c_object_files) -nostdlib -z noexecstack # compile assembly files build/arch/$(arch)/%.o: arch/$(arch)/boot/%.asm @mkdir -p $(shell dirname $@) @nasm -felf64 $< -o $@ + +build/kernel/%.o: kernel/%.c + @mkdir -p $(shell dirname $@) + @gcc -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -m64 -c $< -o $@ + diff --git a/arch/x86_64/boot/long_mode_init.asm b/arch/x86_64/boot/long_mode_init.asm index eab3788..c3167f9 100644 --- a/arch/x86_64/boot/long_mode_init.asm +++ b/arch/x86_64/boot/long_mode_init.asm @@ -11,6 +11,9 @@ long_mode_start: mov fs, ax mov gs, ax + extern main + call main + ; print `OKAY` to screen mov rax, 0x2f592f412f4b2f4f mov qword [0xb8000], rax diff --git a/kernel/main.c b/kernel/main.c new file mode 100644 index 0000000..6de1868 --- /dev/null +++ b/kernel/main.c @@ -0,0 +1,4 @@ + +void test(double a) {} +int main() { test(3.0); } + -- cgit v1.2.3