mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2024-11-22 06:06:52 -08:00
Fixed all errors in OS.
This commit is contained in:
parent
07c0c99a48
commit
cd323834ff
266
CMakeLists.txt
266
CMakeLists.txt
@ -1,140 +1,128 @@
|
|||||||
cmake_minimum_required(VERSION 3.13.4)
|
cmake_minimum_required(VERSION 3.13.4)
|
||||||
project(ClassicOS VERSION 0.0.1 LANGUAGES C CXX ASM_NASM)
|
|
||||||
|
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
|
||||||
set(IS_OS_WINDOWS FALSE)
|
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/build)
|
||||||
set(IS_OS_LINUX FALSE)
|
|
||||||
set(IS_OS_MAC FALSE)
|
include(x86-baremetal-toolchain.cmake)
|
||||||
|
|
||||||
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
|
project(ClassicOS VERSION 0.0.1 LANGUAGES C CXX ASM_NASM)
|
||||||
set(IS_OS_WINDOWS TRUE)
|
|
||||||
message("Building on the Windows operating system.")
|
set(IS_OS_WINDOWS FALSE)
|
||||||
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
set(IS_OS_LINUX FALSE)
|
||||||
set(IS_OS_LINUX TRUE)
|
set(IS_OS_MAC FALSE)
|
||||||
message("Building on the Linux operating system.")
|
|
||||||
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
|
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
|
||||||
set(IS_OS_MAC TRUE)
|
set(IS_OS_WINDOWS TRUE)
|
||||||
message("Building on the Mac operating system.")
|
message("Building on the Windows operating system.")
|
||||||
endif ()
|
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
|
set(IS_OS_LINUX TRUE)
|
||||||
# Source files
|
message("Building on the Linux operating system.")
|
||||||
set(BOOT_SOURCE_FILES
|
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
|
||||||
src/boot/boot.asm
|
set(IS_OS_MAC TRUE)
|
||||||
src/boot/linker.ld
|
message("Building on the Mac operating system.")
|
||||||
)
|
endif ()
|
||||||
|
|
||||||
#[[
|
# Source files
|
||||||
set(GRUB_SOURCE_FILES
|
set(BOOT_SOURCE_FILES
|
||||||
src/boot/grub/grub.cfg
|
src/boot/boot.asm
|
||||||
src/boot/grub/menu.lst
|
src/boot/linker.ld
|
||||||
)
|
)
|
||||||
]]
|
|
||||||
|
#[[
|
||||||
set(DRIVERS_SOURCE_FILES
|
set(GRUB_SOURCE_FILES
|
||||||
src/drivers/audio/audio.c
|
src/boot/grub/grub.cfg
|
||||||
src/drivers/audio/audio.h
|
src/boot/grub/menu.lst
|
||||||
src/drivers/bus/eisa.c
|
)
|
||||||
src/drivers/bus/eisa.h
|
]]
|
||||||
src/drivers/bus/isa.c
|
|
||||||
src/drivers/bus/isa.h
|
set(DRIVERS_SOURCE_FILES
|
||||||
src/drivers/bus/mca.c
|
src/drivers/audio/audio.c
|
||||||
src/drivers/bus/mca.h
|
src/drivers/audio/audio.h
|
||||||
#src/drivers/bus/pci.asm
|
src/drivers/bus/eisa.c
|
||||||
src/drivers/bus/pci.c
|
src/drivers/bus/eisa.h
|
||||||
src/drivers/bus/pci.h
|
src/drivers/bus/isa.c
|
||||||
src/drivers/bus/vesa.c
|
src/drivers/bus/isa.h
|
||||||
src/drivers/bus/vesa.h
|
src/drivers/bus/mca.c
|
||||||
src/drivers/display/display.c
|
src/drivers/bus/mca.h
|
||||||
src/drivers/display/display.h
|
#src/drivers/bus/pci.asm
|
||||||
src/drivers/io/io.c
|
src/drivers/bus/pci.c
|
||||||
src/drivers/io/io.asm
|
src/drivers/bus/pci.h
|
||||||
src/drivers/io/io.h
|
src/drivers/bus/vesa.c
|
||||||
src/drivers/keyboard/keyboard.c
|
src/drivers/bus/vesa.h
|
||||||
src/drivers/keyboard/keyboard.h
|
src/drivers/display/display.c
|
||||||
src/drivers/screen/screen.c
|
src/drivers/display/display.h
|
||||||
src/drivers/screen/screen.h
|
src/drivers/io/io.c
|
||||||
src/drivers/tty/tty.c
|
src/drivers/io/io.asm
|
||||||
src/drivers/tty/tty.h
|
src/drivers/io/io.h
|
||||||
)
|
src/drivers/keyboard/keyboard.c
|
||||||
set(KERNEL_SOURCE_FILES
|
src/drivers/keyboard/keyboard.h
|
||||||
src/kernel/arch/x86/include/memory.h
|
src/drivers/screen/screen.c
|
||||||
src/kernel/arch/x86/include/types.h
|
src/drivers/screen/screen.h
|
||||||
src/kernel/arch/x86/include/types.h
|
src/drivers/tty/tty.c
|
||||||
src/kernel/arch/x86/memory/memory.c
|
src/drivers/tty/tty.h
|
||||||
src/kernel/arch/x86/gdt.c
|
)
|
||||||
src/kernel/arch/x86/gdt.c
|
set(KERNEL_SOURCE_FILES
|
||||||
src/kernel/arch/x86/idt.c
|
src/kernel/arch/x86/include/memory.h
|
||||||
src/kernel/arch/x86/idt.asm
|
src/kernel/arch/x86/include/types.h
|
||||||
src/kernel/arch/x86/idt.h
|
src/kernel/arch/x86/include/types.h
|
||||||
src/kernel/arch/x86/isr/isr.c
|
src/kernel/arch/x86/memory/memory.c
|
||||||
src/kernel/arch/x86/isr/isr.h
|
src/kernel/arch/x86/gdt.c
|
||||||
src/kernel/arch/x86/isr/exceptions.c
|
src/kernel/arch/x86/gdt.asm
|
||||||
src/kernel/arch/x86/isr/exceptions.h
|
src/kernel/arch/x86/gdt.h
|
||||||
src/kernel/kernel.c
|
src/kernel/arch/x86/idt.c
|
||||||
src/kernel/kernel.h
|
src/kernel/arch/x86/idt.asm
|
||||||
src/kernel/linker.ld
|
src/kernel/arch/x86/idt.h
|
||||||
src/kernel/print.c
|
src/kernel/arch/x86/isr/isr.c
|
||||||
)
|
src/kernel/arch/x86/isr/isr.h
|
||||||
|
src/kernel/arch/x86/isr/exceptions.c
|
||||||
set(UTIL_SOURCE_FILES
|
src/kernel/arch/x86/isr/exceptions.h
|
||||||
src/EHS.h
|
src/kernel/kernel.c
|
||||||
src/sys/CPU.h src/sys/CPU.cpp src/sys/CPU_GCC_AMD64.asm
|
src/kernel/kernel.h
|
||||||
src/Util.h src/Util.cpp
|
src/kernel/linker.ld
|
||||||
src/Version.h src/Version.cpp
|
src/kernel/print.c
|
||||||
src/Serializer.h
|
src/kernel/stack.c
|
||||||
src/Array.h
|
src/kernel/stack.h
|
||||||
src/Vector.h
|
)
|
||||||
src/SArray.h
|
|
||||||
src/Str.h
|
set(UTIL_SOURCE_FILES
|
||||||
src/PRNG.h
|
src/EHS.h
|
||||||
src/HRNG.h src/HRNG_GCC.s
|
src/sys/CPU.h src/sys/CPU.cpp src/sys/CPU_GCC_AMD64.asm
|
||||||
src/Math.h src/Math.cpp src/Math_GCC_AMD64.s
|
src/Util.h src/Util.cpp
|
||||||
src/Rect.h
|
src/Version.h src/Version.cpp
|
||||||
src/Range.h src/Range.cpp
|
src/Serializer.h
|
||||||
src/Color4.h src/Color4.cpp
|
src/Array.h
|
||||||
src/Color3.h src/Color3.cpp
|
src/Vector.h
|
||||||
src/Quat.h
|
src/SArray.h
|
||||||
src/Vec4.h
|
src/Str.h
|
||||||
src/Vec3.h
|
src/PRNG.h
|
||||||
src/Vec2.h
|
src/HRNG.h src/HRNG_GCC.s
|
||||||
src/Mat4.h
|
src/Math.h src/Math.cpp src/Math_GCC_AMD64.s
|
||||||
src/Mat3.h
|
src/Rect.h
|
||||||
src/Mat2.h
|
src/Range.h src/Range.cpp
|
||||||
)
|
src/Color4.h src/Color4.cpp
|
||||||
|
src/Color3.h src/Color3.cpp
|
||||||
add_executable(ClassicOS
|
src/Quat.h
|
||||||
${GRUB_SOURCE_FILES}
|
src/Vec4.h
|
||||||
${DRIVERS_SOURCE_FILES}
|
src/Vec3.h
|
||||||
${KERNEL_SOURCE_FILES}
|
src/Vec2.h
|
||||||
)
|
src/Mat4.h
|
||||||
|
src/Mat3.h
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
src/Mat2.h
|
||||||
|
)
|
||||||
# Enable testing
|
|
||||||
enable_testing()
|
add_executable(ClassicOS
|
||||||
|
${GRUB_SOURCE_FILES}
|
||||||
target_link_libraries(ClassicOS PRIVATE)
|
${KERNEL_SOURCE_FILES}
|
||||||
|
${DRIVERS_SOURCE_FILES}
|
||||||
|
)
|
||||||
set(CMAKE_SYSTEM_PROCESSOR i386)
|
|
||||||
set(CMAKE_SYSTEM_NAME None)
|
if (IS_OS_LINUX)
|
||||||
set(CMAKE_C_STANDARD 17)
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -f elf")
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_EXE_LINKER_FLAGS "-g -s")
|
||||||
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -e kernel_main")
|
||||||
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
|
||||||
|
#set_target_properties(ClassicOS PROPERTIES LINK_FLAGS "-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
|
||||||
if (IS_OS_LINUX)
|
elseif (IS_OS_WINDOWS)
|
||||||
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -f elf")
|
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -f win32")
|
||||||
set(CMAKE_C_COMPILER gcc)
|
|
||||||
set(CMAKE_LINKER ld)
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-g -s")
|
|
||||||
set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -e kernel_main")
|
|
||||||
set(CMAKE_CXX_FLAGS "-g -Wall")
|
|
||||||
set(CMAKE_C_FLAGS "-g -Wall -m32")
|
|
||||||
set(CMAKE_C_FLAGS_DEBUG "-g")
|
|
||||||
set(CMAKE_GDB_COMMAND gdb)
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
|
||||||
set_target_properties(ClassicOS PROPERTIES LINK_FLAGS "-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
|
|
||||||
elseif (IS_OS_WINDOWS)
|
|
||||||
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -f win32")
|
|
||||||
endif ()
|
endif ()
|
@ -51,8 +51,8 @@ void eisa_detect_devices()
|
|||||||
// This is my device, configure it
|
// This is my device, configure it
|
||||||
uint32_t config1 = eisa_read_config_dword(address, 4);
|
uint32_t config1 = eisa_read_config_dword(address, 4);
|
||||||
uint32_t config2 = eisa_read_config_dword(address, 8);
|
uint32_t config2 = eisa_read_config_dword(address, 8);
|
||||||
printf("Config1: %u\n", config1);
|
//printf("Config1: %u\n", config1);
|
||||||
printf("Config2: %u\n", config2);
|
//printf("Config2: %u\n", config2);
|
||||||
// Do something with the configuration data
|
// Do something with the configuration data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
global inb
|
global inb
|
||||||
global outb
|
global outb
|
||||||
|
|
||||||
|
section .text
|
||||||
inb:
|
inb:
|
||||||
MOV DX, WORD [ESP + 16]
|
MOV DX, WORD [ESP + 16]
|
||||||
IN AL, DX
|
IN AL, DX
|
||||||
|
@ -34,8 +34,8 @@ void KeyboardInterruptHandler()
|
|||||||
void keyboard_init()
|
void keyboard_init()
|
||||||
{
|
{
|
||||||
// Install keyboard interrupt handler
|
// Install keyboard interrupt handler
|
||||||
set_interrupt_vector(KEYBOARD_INTERRUPT_VECTOR, KeyboardInterruptHandler);
|
//set_interrupt_vector(KEYBOARD_INTERRUPT_VECTOR, KeyboardInterruptHandler);
|
||||||
enable_interrupt(KEYBOARD_INTERRUPT_VECTOR);
|
//enable_interrupt(KEYBOARD_INTERRUPT_VECTOR);
|
||||||
|
|
||||||
// Enable keyboard
|
// Enable keyboard
|
||||||
outb(KEYBOARD_COMMAND_PORT, KEYBOARD_ENABLE_COMMAND);
|
outb(KEYBOARD_COMMAND_PORT, KEYBOARD_ENABLE_COMMAND);
|
||||||
|
@ -16,19 +16,19 @@
|
|||||||
// Example function to print a message to the console
|
// Example function to print a message to the console
|
||||||
void tty_print(const char *message)
|
void tty_print(const char *message)
|
||||||
{
|
{
|
||||||
printf("%s", message);
|
//printf("%s", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example function to read input from the console
|
// Example function to read input from the console
|
||||||
void tty_read(char *buffer, size_t size)
|
void tty_read(char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
fgets(buffer, size, stdin);
|
//fgets(buffer, size, stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example function to clear the console
|
// Example function to clear the console
|
||||||
void tty_clear()
|
void tty_clear()
|
||||||
{
|
{
|
||||||
printf("\033[2J\033[H");
|
//printf("\033[2J\033[H");
|
||||||
}
|
}
|
||||||
|
|
||||||
// More function definitions...
|
// More function definitions...
|
||||||
|
6
src/kernel/arch/x86/gdt.asm
Normal file
6
src/kernel/arch/x86/gdt.asm
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
global LoadGDT
|
||||||
|
|
||||||
|
section .text
|
||||||
|
LoadGDT:
|
||||||
|
LGDT [ESP + 32]
|
||||||
|
RET
|
@ -38,6 +38,8 @@ enum GDT_BASE_LIMIT
|
|||||||
GDT_LIMIT_MASK = 0xFFFF
|
GDT_LIMIT_MASK = 0xFFFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern void LoadGDT(struct gdt_ptr* gdt);
|
||||||
|
|
||||||
// Initialize a GDT entry
|
// Initialize a GDT entry
|
||||||
void gdt_set_gate(uint32_t num, uint32_t base, uint32_t limit, uint8_t access,
|
void gdt_set_gate(uint32_t num, uint32_t base, uint32_t limit, uint8_t access,
|
||||||
uint8_t gran, struct gdt_entry *const gdt)
|
uint8_t gran, struct gdt_entry *const gdt)
|
||||||
@ -57,8 +59,8 @@ void gdt_init()
|
|||||||
// Set up GDT pointer
|
// Set up GDT pointer
|
||||||
struct gdt_ptr gp;
|
struct gdt_ptr gp;
|
||||||
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
|
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
|
||||||
gdt = (struct gdt_entry *)malloc(sizeof(struct gdt_entry) * 3);
|
//gdt = (struct gdt_entry *)malloc(sizeof(struct gdt_entry) * 3);
|
||||||
memset(gdt, 0, sizeof(struct gdt_entry) * 3);
|
//memset(gdt, 0, sizeof(struct gdt_entry) * 3);
|
||||||
|
|
||||||
// Initialize GDT entries
|
// Initialize GDT entries
|
||||||
gdt_set_gate(0, 0, 0, 0, 0, gdt); // Null segment
|
gdt_set_gate(0, 0, 0, 0, 0, gdt); // Null segment
|
||||||
@ -69,7 +71,10 @@ void gdt_init()
|
|||||||
struct gdt_ptr gdtp;
|
struct gdt_ptr gdtp;
|
||||||
gdtp.limit = gp.limit;
|
gdtp.limit = gp.limit;
|
||||||
gdtp.base = (uintptr_t)gdt;
|
gdtp.base = (uintptr_t)gdt;
|
||||||
__asm__ volatile("lgdt %0" : : "m"(gdtp));
|
|
||||||
|
LoadGDT(&gdtp);
|
||||||
|
|
||||||
|
/*
|
||||||
__asm__ volatile("mov $0x10, %ax\n\t"
|
__asm__ volatile("mov $0x10, %ax\n\t"
|
||||||
"mov %ax, %ds\n\t"
|
"mov %ax, %ds\n\t"
|
||||||
"mov %ax, %es\n\t"
|
"mov %ax, %es\n\t"
|
||||||
@ -77,6 +82,7 @@ void gdt_init()
|
|||||||
"mov %ax, %gs\n\t"
|
"mov %ax, %gs\n\t"
|
||||||
"ljmp $0x08, $next_label\n\t"
|
"ljmp $0x08, $next_label\n\t"
|
||||||
"next_label:");
|
"next_label:");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exception handlers
|
// Exception handlers
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
global LoadIDT
|
global LoadIDT
|
||||||
|
|
||||||
|
section .text
|
||||||
LoadIDT:
|
LoadIDT:
|
||||||
LIDT [ESP + 32]
|
LIDT [ESP + 32]
|
||||||
RET
|
RET
|
@ -4,20 +4,20 @@
|
|||||||
|
|
||||||
void DivideByZero()
|
void DivideByZero()
|
||||||
{
|
{
|
||||||
printf("Divide By Zero Exception");
|
//printf("Divide By Zero Exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoubleFault()
|
void DoubleFault()
|
||||||
{
|
{
|
||||||
printf("Double Fault Exception");
|
//printf("Double Fault Exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageFault()
|
void PageFault()
|
||||||
{
|
{
|
||||||
printf("Page Fault Exception");
|
//printf("Page Fault Exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralProtectionFault()
|
void GeneralProtectionFault()
|
||||||
{
|
{
|
||||||
printf("General Protection Fault Exception");
|
//printf("General Protection Fault Exception");
|
||||||
}
|
}
|
@ -3,5 +3,5 @@
|
|||||||
|
|
||||||
void print_string(const char *str)
|
void print_string(const char *str)
|
||||||
{
|
{
|
||||||
printf("%s", str);
|
//printf("%s", str);
|
||||||
}
|
}
|
10
src/kernel/stack.c
Normal file
10
src/kernel/stack.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "stack.h"
|
||||||
|
|
||||||
|
void __attribute__((noreturn)) __stack_chk_fail_local(void)
|
||||||
|
{
|
||||||
|
// Your code to handle stack corruption
|
||||||
|
// This could be logging the error, halting the system, etc.
|
||||||
|
while(1) {
|
||||||
|
// Infinite loop to halt execution
|
||||||
|
}
|
||||||
|
}
|
6
src/kernel/stack.h
Normal file
6
src/kernel/stack.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef STACK_H
|
||||||
|
#define STACK_H
|
||||||
|
|
||||||
|
void __attribute__((noreturn)) __stack_chk_fail_local(void);
|
||||||
|
|
||||||
|
#endif
|
15
x86-baremetal-toolchain.cmake
Normal file
15
x86-baremetal-toolchain.cmake
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# x86-baremetal-toolchain.cmake
|
||||||
|
|
||||||
|
# Specify the cross-compiler (If you need one; otherwise, your native GCC should work)
|
||||||
|
set(CMAKE_ASM_COMPILER nasm)
|
||||||
|
set(CMAKE_C_COMPILER gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER g++)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
|
# Add compiler and linker flags for x86 bare metal
|
||||||
|
set(CMAKE_ASM_NASM_FLAGS "-f elf32")
|
||||||
|
set(CMAKE_C_FLAGS "-m32 -ffreestanding -nostdlib")
|
||||||
|
set(CMAKE_CXX_FLAGS "-m32 -ffreestanding -nostdlib")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "-T${CMAKE_CURRENT_LIST_DIR}/linker.ld -m32")
|
Loading…
Reference in New Issue
Block a user