diff --git a/CMakeLists.txt b/CMakeLists.txt index 39c29bc..2abb58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(LIMINE_DIR ${CMAKE_BINARY_DIR}/limine) file(GLOB_RECURSE KERNEL_SOURCES CONFIGURE_DEPENDS kernel/*.cpp + include/*.h + include/*.hpp ) find_program(LLD_LINKER NAMES ld.lld REQUIRED) @@ -52,7 +54,9 @@ add_custom_command( -T ${CMAKE_SOURCE_DIR}/linker.ld -o ${KERNEL_ELF} $ - DEPENDS avery_objects ${CMAKE_SOURCE_DIR}/linker.ld + DEPENDS + $ + ${CMAKE_SOURCE_DIR}/linker.ld COMMAND_EXPAND_LISTS VERBATIM ) diff --git a/include/io/io.h b/include/io/io.h new file mode 100644 index 0000000..a9dbbd7 --- /dev/null +++ b/include/io/io.h @@ -0,0 +1,36 @@ +/* +* io.h +* As part of the Avery project +* Created by Max Van den Eynde in 2026 +* -------------------------------------- +* Description: I/O Mapping and writing functions +* Copyright (c) 2026 Max Van den Eynde +*/ + +#ifndef AVERY_IO_H +#define AVERY_IO_H +#include "../types.h" + +namespace io { + inline void outb(u16 port, u8 value) { + asm volatile( + "outb %0, %1" + : + : "a"(value), "Nd"(port) + ); + } + + inline u8 inb(u16 port) { + u8 val; + + asm volatile( + "inb %1, %0" + : "=a"(val) + : "Nd"(port) + ); + + return val; + } +} + +#endif //AVERY_IO_H diff --git a/include/io/serial.h b/include/io/serial.h new file mode 100644 index 0000000..ce891ab --- /dev/null +++ b/include/io/serial.h @@ -0,0 +1,19 @@ +/* +* serial.h +* As part of the Avery project +* Created by Max Van den Eynde in 2026 +* -------------------------------------- +* Description: The serial output for Avery +* Copyright (c) 2026 Max Van den Eynde +*/ + +#ifndef AVERY_SERIAL_H +#define AVERY_SERIAL_H +#include "../types.h" + +namespace io { + void serialWriteChar(char c); + void serialWrite(string input); +} + +#endif //AVERY_SERIAL_H diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..ff4585c --- /dev/null +++ b/include/types.h @@ -0,0 +1,27 @@ +/* +* types.h +* As part of the Avery project +* Created by Max Van den Eynde in 2026 +* -------------------------------------- +* Description: Type definition for the Avery Kernel +* Copyright (c) 2026 Max Van den Eynde +*/ + +#ifndef AVERY_TYPES_H +#define AVERY_TYPES_H + +using u8 = unsigned char; +using u16 = unsigned short; +using u32 = unsigned int; +using u64 = unsigned long long; +using usize = decltype(sizeof(0)); + +using i8 = char; +using i16 = short; +using i32 = int; +using i64 = long long; + +using string = const char*; + + +#endif //AVERY_TYPES_H diff --git a/kernel/io/serial.cpp b/kernel/io/serial.cpp new file mode 100644 index 0000000..950e072 --- /dev/null +++ b/kernel/io/serial.cpp @@ -0,0 +1,23 @@ +/* +* serial.cpp +* As part of the Avery project +* Created by Max Van den Eynde in 2026 +* -------------------------------------- +* Description: Serial implementation +* Copyright (c) 2026 Max Van den Eynde +*/ + +#include "types.h" +#include "io/serial.h" +#include "io/io.h" + +void io::serialWriteChar(char c) { + outb(0xE9, static_cast(c)); +} + +void io::serialWrite(string input) { + while (*input) { + serialWriteChar(*input); + input++; + } +} diff --git a/kernel/main.cpp b/kernel/main.cpp index 4a7c2a0..d09e5ce 100644 --- a/kernel/main.cpp +++ b/kernel/main.cpp @@ -1,5 +1,7 @@ #include +#include "io/serial.h" + __attribute__((used, section(".limine_requests"))) static volatile uint64_t limine_base_revision[] = LIMINE_BASE_REVISION(6); @@ -17,6 +19,8 @@ __attribute__((used, section(".limine_requests_end"))) static volatile uint64_t limine_requests_end_marker[] = LIMINE_REQUESTS_END_MARKER; extern "C" [[noreturn]] void _start() { + io::serialWrite("Hello, World!"); + if (LIMINE_BASE_REVISION_SUPPORTED(limine_base_revision) == false) { while (true) { asm("hlt");