update makefile

This commit is contained in:
Freya Murphy 2024-02-01 14:43:11 -05:00
parent 192a4ccd6b
commit 341c95f535
Signed by: freya
GPG key ID: 744AB800E383AE52
4 changed files with 49 additions and 35 deletions

View file

@ -7,6 +7,7 @@ ISO_NAME=os_image.iso
CC=cc CC=cc
LD=ld LD=ld
AS=nasm
CFLAGS+=-std=c2x -ffreestanding -fno-stack-protector -g -Wall -Wextra -pedantic -lgcc -isystem $(INCLUDE_DIR) CFLAGS+=-std=c2x -ffreestanding -fno-stack-protector -g -Wall -Wextra -pedantic -lgcc -isystem $(INCLUDE_DIR)
CFLAGS+=-DPAGE_SIZE=4096 CFLAGS+=-DPAGE_SIZE=4096
@ -27,29 +28,34 @@ A_OBJ=$(patsubst %.S,$(BUILD_DIR)/%.S.o,$(A_SRC))
all: $(BUILD_DIR)/$(ISO_NAME) all: $(BUILD_DIR)/$(ISO_NAME)
clean: 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 $(A_OBJ): $(BUILD_DIR)/%.S.o : %.S
@mkdir -p $(@D) @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 $(C_OBJ): $(BUILD_DIR)/%.o : %.c
@mkdir -p $(@D) @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) $(BUILD_DIR)/$(K_BIN_NAME): arch/amd64/linker.ld $(A_OBJ) $(C_OBJ) $(H_SRC) $(H_INCLUDE)
@mkdir -p $(@D) @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 $(BUILD_DIR)/$(ISO_NAME): $(BUILD_DIR)/$(K_BIN_NAME) grub.cfg
@mkdir -p $(@D) @mkdir -p $(@D)
@mkdir -p $(BUILD_DIR)/iso/boot/grub @mkdir -p $(BUILD_DIR)/iso/boot/grub
cp grub.cfg $(BUILD_DIR)/iso/boot/grub @cp grub.cfg $(BUILD_DIR)/iso/boot/grub
cp $(BUILD_DIR)/$(K_BIN_NAME) $(BUILD_DIR)/iso/boot @cp $(BUILD_DIR)/$(K_BIN_NAME) $(BUILD_DIR)/iso/boot
grub-mkrescue -o $(BUILD_DIR)/$(ISO_NAME) $(BUILD_DIR)/iso @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 run: all
qemu-system-x86_64 \ @qemu-system-x86_64 \
-cdrom $(BUILD_DIR)/$(ISO_NAME) \ -cdrom $(BUILD_DIR)/$(ISO_NAME) \
-serial stdio \ -serial stdio \
-display gtk,show-menubar=off,zoom-to-fit=on \ -display gtk,show-menubar=off,zoom-to-fit=on \

View file

@ -88,6 +88,8 @@ load_pml4(
void *phys void *phys
) { ) {
static struct pte *pt = &paging_pt[0]; static struct pte *pt = &paging_pt[0];
if ((uint64_t)phys >> 12 == pt->address)
return;
pt->address = (uint64_t)phys >> 12; pt->address = (uint64_t)phys >> 12;
pt->flags = F_PRESENT | F_WRITEABLE; pt->flags = F_PRESENT | F_WRITEABLE;
invlpg(pml4_mapped); invlpg(pml4_mapped);
@ -98,6 +100,8 @@ load_pdpt(
void *phys void *phys
) { ) {
static struct pte *pt = &paging_pt[1]; static struct pte *pt = &paging_pt[1];
if ((uint64_t)phys >> 12 == pt->address)
return;
pt->address = (uint64_t)phys >> 12; pt->address = (uint64_t)phys >> 12;
pt->flags = F_PRESENT | F_WRITEABLE; pt->flags = F_PRESENT | F_WRITEABLE;
invlpg(pdpt_mapped); invlpg(pdpt_mapped);
@ -108,6 +112,8 @@ load_pd(
void *phys void *phys
) { ) {
static struct pte *pt = &paging_pt[2]; static struct pte *pt = &paging_pt[2];
if ((uint64_t)phys >> 12 == pt->address)
return;
pt->address = (uint64_t)phys >> 12; pt->address = (uint64_t)phys >> 12;
pt->flags = F_PRESENT | F_WRITEABLE; pt->flags = F_PRESENT | F_WRITEABLE;
invlpg(pdpt_mapped); invlpg(pdpt_mapped);
@ -118,6 +124,8 @@ load_pt(
void *phys void *phys
) { ) {
static struct pte *pt = &paging_pt[3]; static struct pte *pt = &paging_pt[3];
if ((uint64_t)phys >> 12 == pt->address)
return;
pt->address = (uint64_t)phys >> 12; pt->address = (uint64_t)phys >> 12;
pt->flags = F_PRESENT | F_WRITEABLE; pt->flags = F_PRESENT | F_WRITEABLE;
invlpg(pt_mapped); invlpg(pt_mapped);

View file

@ -16,7 +16,7 @@ void kmain(struct boot_info *info) {
*(char*)(0xB8000 + 0x146) = 'i'; *(char*)(0xB8000 + 0x146) = 'i';
while (1) { while (1) {
//kprintf("ret: 0x%p\n", kalloc(2)); //kprintf("ret: 0x%p\n", kalloc(1024));
// loop so we dont halt // loop so we dont halt
// this allows interrupts to fire // this allows interrupts to fire
} }