Skip to content

Commit

Permalink
Finish the huge build system rework
Browse files Browse the repository at this point in the history
  • Loading branch information
sasdallas committed Aug 7, 2024
1 parent a0c3fb3 commit 559ca70
Show file tree
Hide file tree
Showing 284 changed files with 10,236 additions and 18,900 deletions.
7 changes: 6 additions & 1 deletion cppreduceOS.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
"pmm.h": "c",
"panic.h": "c",
"floppy.h": "c",
"syscall.h": "c"
"syscall.h": "c",
"mem.h": "c",
"list.h": "c",
"hashmap.h": "c",
"liballoc_forwarder.h": "c",
"vmm.h": "c"
}
}
}
Binary file removed obj/assembly/bios.o
Binary file not shown.
Binary file removed obj/assembly/bochs.o
Binary file not shown.
Binary file removed obj/assembly/boot.o
Binary file not shown.
Binary file removed obj/assembly/crtbegin.o
Binary file not shown.
Binary file removed obj/assembly/crtend.o
Binary file not shown.
Binary file removed obj/assembly/crti.o
Binary file not shown.
Binary file removed obj/assembly/crtn.o
Binary file not shown.
Binary file removed obj/assembly/gdt.o
Binary file not shown.
Binary file removed obj/assembly/idt.o
Binary file not shown.
Binary file removed obj/assembly/isr.o
Binary file not shown.
Binary file removed obj/assembly/tss.o
Binary file not shown.
Binary file removed obj/assembly/usermode.o
Binary file not shown.
Binary file removed obj/base/bios32.o
Binary file not shown.
Binary file removed obj/base/gdt.o
Binary file not shown.
Binary file removed obj/base/hal.o
Binary file not shown.
Binary file removed obj/base/idt.o
Binary file not shown.
Binary file removed obj/base/isr.o
Binary file not shown.
Binary file removed obj/base/pic.o
Binary file not shown.
Binary file removed obj/base/processor.o
Binary file not shown.
Binary file removed obj/drivers/acpi.o
Binary file not shown.
Binary file removed obj/drivers/floppy.o
Binary file not shown.
Binary file removed obj/drivers/ide_ata.o
Binary file not shown.
Binary file removed obj/drivers/io_apic.o
Binary file not shown.
Binary file removed obj/drivers/keyboard.o
Binary file not shown.
Binary file removed obj/drivers/local_apic.o
Binary file not shown.
Binary file removed obj/drivers/pci.o
Binary file not shown.
Binary file removed obj/drivers/pit.o
Binary file not shown.
Binary file removed obj/drivers/rtc.o
Binary file not shown.
Binary file removed obj/drivers/serial.o
Binary file not shown.
Binary file removed obj/fonts/font.o
Binary file not shown.
Binary file removed obj/fs/ext2.o
Binary file not shown.
Binary file removed obj/fs/fat.o
Binary file not shown.
Binary file removed obj/fs/initrd.o
Binary file not shown.
Binary file removed obj/fs/vfs.o
Binary file not shown.
Binary file removed obj/gfx/bitmap.o
Binary file not shown.
Binary file removed obj/gfx/font.o
Binary file not shown.
Binary file removed obj/gfx/font_data.o
Binary file not shown.
Binary file removed obj/gfx/gfx.o
Binary file not shown.
Binary file removed obj/gfx/terminal.o
Binary file not shown.
Binary file removed obj/gfx/vesa.o
Binary file not shown.
Binary file removed obj/kernel/cmds.o
Binary file not shown.
Binary file removed obj/kernel/command.o
Binary file not shown.
Binary file removed obj/kernel/kernel.o
Binary file not shown.
Binary file removed obj/kernel/panic.o
Binary file not shown.
Binary file removed obj/kernel/test.o
Binary file not shown.
Binary file removed obj/libc/list.o
Binary file not shown.
Binary file removed obj/libc/ordered_array.o
Binary file not shown.
Binary file removed obj/libc/printf.o
Binary file not shown.
Binary file removed obj/libc/putchar.o
Binary file not shown.
Binary file removed obj/libc/sleep.o
Binary file not shown.
Binary file removed obj/libc/spinlock.o
Binary file not shown.
Binary file removed obj/libc/stdlib.o
Binary file not shown.
Binary file removed obj/libc/string.o
Binary file not shown.
Binary file removed obj/libc/tree.o
Binary file not shown.
Binary file removed obj/mem/dma.o
Binary file not shown.
Binary file removed obj/mem/liballoc/liballoc.o
Binary file not shown.
Binary file removed obj/mem/liballoc/liballoc_forwarder.o
Binary file not shown.
Binary file removed obj/mem/liballoc/liballoc_wrapper.o
Binary file not shown.
Binary file removed obj/mem/pmm.o
Binary file not shown.
Binary file removed obj/mem/vmm.o
Binary file not shown.
Binary file removed obj/mem/vmm_pde.o
Binary file not shown.
Binary file removed obj/mem/vmm_pte.o
Binary file not shown.
Binary file removed obj/misc/hashmap.o
Binary file not shown.
Binary file removed obj/misc/list.o
Binary file not shown.
Binary file removed obj/misc/tree.o
Binary file not shown.
Binary file removed obj/tasks/syscall.o
Binary file not shown.
Binary file removed obj/tasks/tss.o
Binary file not shown.
Binary file removed source/initial_ramdisk/generate_initrd
Binary file not shown.
Binary file removed source/initial_ramdisk/obj/generate_initrd.o
Binary file not shown.
8 changes: 4 additions & 4 deletions source/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OUT_KERNEL = .
ASM_SOURCE_DIR = assembly

# Directories (EDIT ME)
SOURCE_DIRECTORIES = kernel libc drivers base gfx fs mem tasks misc
SOURCE_DIRECTORIES = kernel drivers base gfx fs mem tasks misc
SOURCE_SUBDIRECTORIES = mem/liballoc # We do this because shell find will pick up anything in subdirectories twice
DIRECTORIES = $(addprefix $(OUT_OBJ)/,$(SOURCE_DIRECTORIES)) $(addprefix $(OUT_OBJ)/,$(SOURCE_SUBDIRECTORIES))

Expand Down Expand Up @@ -51,11 +51,11 @@ TARGET_DISABLED:

$(OUT_KERNEL)/kernel_debug.elf: MAKE_OUTPUT_DIRS DELETE_OLD_KERNEL_OBJ BUILDSCRIPTS_DEBUG PRINT_ASM_HEADER $(ASM_OBJS) PRINT_C_HEADER $(C_OBJS)
@echo "-- Linking $(OUT_KERNEL)/kernel.elf for DEBUG target..."
$(LD) $(LDFLAGS) -T linker.ld $(C_OBJS) $(ASM_OBJS) $(OUT_OBJ)/fonts/*.o -o kernel.elf $(LIBS) -lgcc
$(LD) $(LDFLAGS) -T linker.ld $(C_OBJS) $(ASM_OBJS) $(OUT_OBJ)/fonts/*.o -o kernel.elf $(LIBS)

$(OUT_KERNEL)/kernel_release.elf: MAKE_OUTPUT_DIRS DELETE_OLD_KERNEL_OBJ BUILDSCRIPTS_RELEASE PRINT_ASM_HEADER $(ASM_OBJS) PRINT_C_HEADER $(C_OBJS)
@echo "-- Linking $(OUT_KERNEL)/kernel.elf for RELEASE target..."
$(LD) $(LDFLAGS) -T linker.ld $(C_OBJS) $(ASM_OBJS) $(OUT_OBJ)/fonts/*.o -o kernel.elf $(LIBS) -lgcc
$(LD) $(LDFLAGS) -T linker.ld $(C_OBJS) $(ASM_OBJS) $(OUT_OBJ)/fonts/*.o -o kernel.elf $(LIBS)

@echo "-- Stripping debug symbols..."
objcopy --strip-debug kernel.elf
Expand Down Expand Up @@ -106,7 +106,7 @@ $(OUT_OBJ)/%.o: %.c Makefile


$(OUT_ASMOBJ)/crtbegin.o $(OUT_ASMOBJ)/crtend.o:
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
OBJ=`$(CC) $(CFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@

# Installation functions

Expand Down
124 changes: 62 additions & 62 deletions source/kernel/base/bios32.c
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
// ======================================================================
// bios32.c - Handles real-mode interrupt calls in protected mode
// ======================================================================

#include "include/bios32.h" // Main header file

idtPtr_t realModeGDT;
idtPtr_t realModeIDT;

extern gdtEntry_t gdtEntries[8];

void (*bios32_execute)() = (void *)0x7c00;

void bios32_init() {
// Set up the 16-bit code and data segment in GDT.
gdtSetGate(6, 0, 0xFFFFFFFF, 0x9A, 0x0F);
gdtSetGate(7, 0, 0xFFFFFFFF, 0x92, 0x0F);

// Setup the real mode GDT ptr
realModeGDT.base_addr = (uint32_t)gdtEntries;
realModeGDT.limit = sizeof(gdtEntries) - 1;

// Setup the real mode IDT ptr
realModeIDT.base_addr = 0;
realModeIDT.limit = 0x3FF;
}

// bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) - Calls bios32.
void bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) {
serialPrintf("Preparing to call BIOS32 for int 0x%x...\n\tAX = 0x%x BX = 0x%x CX = 0x%x DX = 0x%x\n", interrupt, in->ax, in->bx, in->cx, in->dx);
void *newCodeBase = (void *)0x7c00;

// Copy the GDT entries to the BIOS32 GDT entries.
memcpy(&bios32_gdt_entries, gdtEntries, sizeof(gdtEntries));

// Update the base address of the GDT entries, starting from 0x7C00.
realModeGDT.base_addr = (uint32_t)REBASE_ADDRESS((&bios32_gdt_entries));

// Copy the real mode GDT and IDT to their respective pointers.
memcpy(&bios32_gdt_ptr, &realModeGDT, sizeof(idtPtr_t));
memcpy(&bios32_idt_ptr, &realModeIDT, sizeof(idtPtr_t));

// Copy the in registers to their pointers.
memcpy(&bios32_in_reg16_ptr, in, sizeof(REGISTERS_16));

// Get the in registers' address.
void *in_reg16_address = REBASE_ADDRESS(&bios32_in_reg16_ptr);

// Copy the BIOS interrupt number to its respective pointer.
memcpy(&bios32_int_number_ptr, &interrupt, sizeof(uint8_t));

// Copy the bios32 code to a new address.
uint32_t size = (uint32_t)BIOS32_END - (uint32_t)BIOS32_START;
memcpy(newCodeBase, BIOS32_START, size);

// Start executing the BIOS32 code.
bios32_execute();

// Copy the output registers to the out ptr.
in_reg16_address = REBASE_ADDRESS(&bios32_out_reg16_ptr);
memcpy(out, in_reg16_address, sizeof(REGISTERS_16));
}
// ======================================================================
// bios32.c - Handles real-mode interrupt calls in protected mode
// ======================================================================

#include <kernel/bios32.h> // Main header file

idtPtr_t realModeGDT;
idtPtr_t realModeIDT;

extern gdtEntry_t gdtEntries[8];

void (*bios32_execute)() = (void *)0x7c00;

void bios32_init() {
// Set up the 16-bit code and data segment in GDT.
gdtSetGate(6, 0, 0xFFFFFFFF, 0x9A, 0x0F);
gdtSetGate(7, 0, 0xFFFFFFFF, 0x92, 0x0F);

// Setup the real mode GDT ptr
realModeGDT.base_addr = (uint32_t)gdtEntries;
realModeGDT.limit = sizeof(gdtEntries) - 1;

// Setup the real mode IDT ptr
realModeIDT.base_addr = 0;
realModeIDT.limit = 0x3FF;
}

// bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) - Calls bios32.
void bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) {
serialPrintf("Preparing to call BIOS32 for int 0x%x...\n\tAX = 0x%x BX = 0x%x CX = 0x%x DX = 0x%x\n", interrupt, in->ax, in->bx, in->cx, in->dx);
void *newCodeBase = (void *)0x7c00;

// Copy the GDT entries to the BIOS32 GDT entries.
memcpy(&bios32_gdt_entries, gdtEntries, sizeof(gdtEntries));

// Update the base address of the GDT entries, starting from 0x7C00.
realModeGDT.base_addr = (uint32_t)REBASE_ADDRESS((&bios32_gdt_entries));

// Copy the real mode GDT and IDT to their respective pointers.
memcpy(&bios32_gdt_ptr, &realModeGDT, sizeof(idtPtr_t));
memcpy(&bios32_idt_ptr, &realModeIDT, sizeof(idtPtr_t));

// Copy the in registers to their pointers.
memcpy(&bios32_in_reg16_ptr, in, sizeof(REGISTERS_16));

// Get the in registers' address.
void *in_reg16_address = REBASE_ADDRESS(&bios32_in_reg16_ptr);

// Copy the BIOS interrupt number to its respective pointer.
memcpy(&bios32_int_number_ptr, &interrupt, sizeof(uint8_t));

// Copy the bios32 code to a new address.
uint32_t size = (uint32_t)BIOS32_END - (uint32_t)BIOS32_START;
memcpy(newCodeBase, BIOS32_START, size);

// Start executing the BIOS32 code.
bios32_execute();

// Copy the output registers to the out ptr.
in_reg16_address = REBASE_ADDRESS(&bios32_out_reg16_ptr);
memcpy(out, in_reg16_address, sizeof(REGISTERS_16));
}
112 changes: 56 additions & 56 deletions source/kernel/base/gdt.c
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
// ==================================================
// gdt.c - Global Descriptor Table initializer
// ==================================================
// This file is a part of the reduceOS C kernel. Please credit me if you use this code.

/* Developer note: When reduceOS switched to multiboot, I totally forgot about this file. I'm not sure if this is why paging is failing, but it would be pretty funny if so. */

#include "include/gdt.h" // Main header file

// Variable definitions
gdtEntry_t gdtEntries[MAX_DESCRIPTORS];
gdtPtr_t gdtPtr;

extern void tssFlush();

// Functions

// gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) - Set the value of 1 GDT entry.
void gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
// Sanity check first!
ASSERT(num < MAX_DESCRIPTORS, "gdtSetGate()", "invalid descriptor number");

// Now set the proper values in the gdt entries.
gdtEntries[num].baseLow = (base & 0xFFFF);
gdtEntries[num].baseMiddle = (base >> 16) & 0xFF;
gdtEntries[num].baseHigh = (base >> 24) & 0xFF;

gdtEntries[num].limitLow = (limit & 0xFFFF);
gdtEntries[num].granularity = (limit >> 16) & 0x0F;

gdtEntries[num].granularity |= gran & 0xF0;
gdtEntries[num].access = access;
}


// gdtInit() - Initializes GDT and sets up all the pointers
void gdtInit() {
// Setup the gdtPtr to point to our gdtEntires
gdtPtr.limit = sizeof(gdtEntries)-1;
gdtPtr.base = (uint32_t)&gdtEntries;

// Now setup the GDT entries
gdtSetGate(0, 0, 0, 0, 0); // Null segment
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment
gdtSetGate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment
gdtSetGate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment.
tssWrite(5, 0x10, 0x0); // Task state segment

// Install the GDT.
install_gdt((uint32_t)&gdtPtr);

// Flush TSS.
tssFlush();

}
// ==================================================
// gdt.c - Global Descriptor Table initializer
// ==================================================
// This file is a part of the reduceOS C kernel. Please credit me if you use this code.

/* Developer note: When reduceOS switched to multiboot, I totally forgot about this file. I'm not sure if this is why paging is failing, but it would be pretty funny if so. */

#include <kernel/gdt.h> // Main header file

// Variable definitions
gdtEntry_t gdtEntries[MAX_DESCRIPTORS];
gdtPtr_t gdtPtr;

extern void tssFlush();

// Functions

// gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) - Set the value of 1 GDT entry.
void gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
// Sanity check first!
ASSERT(num < MAX_DESCRIPTORS, "gdtSetGate()", "invalid descriptor number");

// Now set the proper values in the gdt entries.
gdtEntries[num].baseLow = (base & 0xFFFF);
gdtEntries[num].baseMiddle = (base >> 16) & 0xFF;
gdtEntries[num].baseHigh = (base >> 24) & 0xFF;

gdtEntries[num].limitLow = (limit & 0xFFFF);
gdtEntries[num].granularity = (limit >> 16) & 0x0F;

gdtEntries[num].granularity |= gran & 0xF0;
gdtEntries[num].access = access;
}


// gdtInit() - Initializes GDT and sets up all the pointers
void gdtInit() {
// Setup the gdtPtr to point to our gdtEntires
gdtPtr.limit = sizeof(gdtEntries)-1;
gdtPtr.base = (uint32_t)&gdtEntries;

// Now setup the GDT entries
gdtSetGate(0, 0, 0, 0, 0); // Null segment
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment
gdtSetGate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment
gdtSetGate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment.
tssWrite(5, 0x10, 0x0); // Task state segment

// Install the GDT.
install_gdt((uint32_t)&gdtPtr);

// Flush TSS.
tssFlush();

}
Loading

0 comments on commit 559ca70

Please sign in to comment.