From 341c95f5357c451e2420fb81e64ec6b42c40e124 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 1 Feb 2024 14:43:11 -0500 Subject: [PATCH] update makefile --- Makefile | 22 ++++++++++------- arch/amd64/linker.ld | 52 ++++++++++++++++++++--------------------- src/arch/amd64/paging.c | 8 +++++++ src/kmain.c | 2 +- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 2a8c565..cb3a85b 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ ISO_NAME=os_image.iso CC=cc LD=ld +AS=nasm CFLAGS+=-std=c2x -ffreestanding -fno-stack-protector -g -Wall -Wextra -pedantic -lgcc -isystem $(INCLUDE_DIR) CFLAGS+=-DPAGE_SIZE=4096 @@ -27,29 +28,34 @@ A_OBJ=$(patsubst %.S,$(BUILD_DIR)/%.S.o,$(A_SRC)) all: $(BUILD_DIR)/$(ISO_NAME) clean: - rm -rf $(BUILD_DIR)/* + @printf "\033[31m RM \033[0m%s\n" $(BUILD_DIR) + @rm -rf $(BUILD_DIR)/* $(A_OBJ): $(BUILD_DIR)/%.S.o : %.S @mkdir -p $(@D) - nasm $< -f elf64 -o $@ + @printf "\033[33m AS \033[0m%s\n" $< + @nasm $< -f elf64 -o $@ $(C_OBJ): $(BUILD_DIR)/%.o : %.c @mkdir -p $(@D) - $(CC) -c $(CFLAGS) -o $@ $< + @printf "\033[34m CC \033[0m%s\n" $< + @$(CC) -c $(CFLAGS) -o $@ $< $(BUILD_DIR)/$(K_BIN_NAME): arch/amd64/linker.ld $(A_OBJ) $(C_OBJ) $(H_SRC) $(H_INCLUDE) @mkdir -p $(@D) - $(LD) $(LDFLAGS) -T arch/amd64/linker.ld -o $(BUILD_DIR)/$(K_BIN_NAME) $(A_OBJ) $(C_OBJ) + @printf "\033[32m LD \033[0m%s\n" $@ + @$(LD) $(LDFLAGS) --no-warn-rwx-segments -T arch/amd64/linker.ld -o $(BUILD_DIR)/$(K_BIN_NAME) $(A_OBJ) $(C_OBJ) $(BUILD_DIR)/$(ISO_NAME): $(BUILD_DIR)/$(K_BIN_NAME) grub.cfg @mkdir -p $(@D) @mkdir -p $(BUILD_DIR)/iso/boot/grub - cp grub.cfg $(BUILD_DIR)/iso/boot/grub - cp $(BUILD_DIR)/$(K_BIN_NAME) $(BUILD_DIR)/iso/boot - grub-mkrescue -o $(BUILD_DIR)/$(ISO_NAME) $(BUILD_DIR)/iso + @cp grub.cfg $(BUILD_DIR)/iso/boot/grub + @cp $(BUILD_DIR)/$(K_BIN_NAME) $(BUILD_DIR)/iso/boot + @printf "\033[35m ISO \033[0m%s\n" $(BUILD_DIR)/$(ISO_NAME) + @grub-mkrescue -o $(BUILD_DIR)/$(ISO_NAME) $(BUILD_DIR)/iso 2> /dev/null run: all - qemu-system-x86_64 \ + @qemu-system-x86_64 \ -cdrom $(BUILD_DIR)/$(ISO_NAME) \ -serial stdio \ -display gtk,show-menubar=off,zoom-to-fit=on \ diff --git a/arch/amd64/linker.ld b/arch/amd64/linker.ld index e097f56..7a34a9e 100644 --- a/arch/amd64/linker.ld +++ b/arch/amd64/linker.ld @@ -1,38 +1,38 @@ ENTRY(start) SECTIONS { - . = 1M; - - kernel_start = .; + . = 1M; - .boot BLOCK(4K) : ALIGN(4K) - { - *(.multiboot) - } + kernel_start = .; - .rodata BLOCK(4K) : ALIGN(4K) - { - *(.rodata) - } + .boot BLOCK(4K) : ALIGN(4K) + { + *(.multiboot) + } - .data BLOCK(4K) : ALIGN(4K) - { - *(.data) - } + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } - text_start = .; + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } - .text BLOCK(4K) : ALIGN(4K) - { - *(.text) - } + text_start = .; - text_end = .; + .text BLOCK(4K) : ALIGN(4K) + { + *(.text) + } - .bss BLOCK(4K) : ALIGN(4K) - { - *(.bss) - } + text_end = .; - kernel_end = .; + .bss BLOCK(4K) : ALIGN(4K) + { + *(.bss) + } + + kernel_end = .; } diff --git a/src/arch/amd64/paging.c b/src/arch/amd64/paging.c index 3ea79f1..18eb079 100644 --- a/src/arch/amd64/paging.c +++ b/src/arch/amd64/paging.c @@ -88,6 +88,8 @@ load_pml4( void *phys ) { static struct pte *pt = &paging_pt[0]; + if ((uint64_t)phys >> 12 == pt->address) + return; pt->address = (uint64_t)phys >> 12; pt->flags = F_PRESENT | F_WRITEABLE; invlpg(pml4_mapped); @@ -98,6 +100,8 @@ load_pdpt( void *phys ) { static struct pte *pt = &paging_pt[1]; + if ((uint64_t)phys >> 12 == pt->address) + return; pt->address = (uint64_t)phys >> 12; pt->flags = F_PRESENT | F_WRITEABLE; invlpg(pdpt_mapped); @@ -108,6 +112,8 @@ load_pd( void *phys ) { static struct pte *pt = &paging_pt[2]; + if ((uint64_t)phys >> 12 == pt->address) + return; pt->address = (uint64_t)phys >> 12; pt->flags = F_PRESENT | F_WRITEABLE; invlpg(pdpt_mapped); @@ -118,6 +124,8 @@ load_pt( void *phys ) { static struct pte *pt = &paging_pt[3]; + if ((uint64_t)phys >> 12 == pt->address) + return; pt->address = (uint64_t)phys >> 12; pt->flags = F_PRESENT | F_WRITEABLE; invlpg(pt_mapped); diff --git a/src/kmain.c b/src/kmain.c index 057620d..85a051a 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -16,7 +16,7 @@ void kmain(struct boot_info *info) { *(char*)(0xB8000 + 0x146) = 'i'; while (1) { - //kprintf("ret: 0x%p\n", kalloc(2)); + //kprintf("ret: 0x%p\n", kalloc(1024)); // loop so we dont halt // this allows interrupts to fire }