structing project folders

This commit is contained in:
brenozd
2024-10-29 10:28:58 -03:00
parent 2e60c4560b
commit 7fb003ad0b
12 changed files with 83 additions and 22 deletions

View File

@@ -61,14 +61,14 @@ target_compile_options(
file(GLOB C_FILES CONFIGURE_DEPENDS *.c)
file(GLOB H_FILES CONFIGURE_DEPENDS *.h)
target_sources(${PROJECT_NAME}-kernel PRIVATE ${C_FILES} PUBLIC ${H_FILES})
target_include_directories(${PROJECT_NAME}-kernel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(${PROJECT_NAME}-obj PRIVATE ${C_FILES} PUBLIC ${H_FILES})
target_include_directories(${PROJECT_NAME}-obj PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# Add complementary files
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/boot")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/crt")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/arch")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/include")
# Make sure to build boot and CRT before the kernel itself
# https://wiki.osdev.org/Calling_Global_Constructors#GNU_Compiler_Collection_-_System_V_ABI
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}-crti ${PROJECT_NAME}-crtbegin ${PROJECT_NAME}-boot
${PROJECT_NAME}-kernel ${PROJECT_NAME}-crtend ${PROJECT_NAME}-crtn)
${PROJECT_NAME}-obj ${PROJECT_NAME}-crtend ${PROJECT_NAME}-crtn)

View File

@@ -1,3 +1,10 @@
# Build files for architecture
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i386)|(i686)|(x86)|(X86)|(amd64)|(AMD64)")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/i386/")
else()
message(FATAL_ERROR "Unsupported system processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
# Gather crtbegin.o and crtend.o from toolchain
execute_process(
COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o
@@ -17,12 +24,3 @@ message(STATUS "Using crtend.o as ${CRTEND_O}")
add_library(${PROJECT_NAME}-crtend OBJECT IMPORTED GLOBAL)
set_property(TARGET ${PROJECT_NAME}-crtend PROPERTY IMPORTED_OBJECTS ${CRTEND_O})
# Build own crt
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i686)|(x86)|(X86)|(amd64)|(AMD64)")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/x86")
add_library(${PROJECT_NAME}-crti ALIAS ${PROJECT_NAME}-crti-x86)
add_library(${PROJECT_NAME}-crtn ALIAS ${PROJECT_NAME}-crtn-x86)
else()
message(FATAL_ERROR "Unsupported CRT for ${CMAKE_SYSTEM_PROCESSOR}")
endif()

View File

@@ -0,0 +1,8 @@
# Create aliases to we have a single link with multiple archs
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/boot")
add_library(${PROJECT_NAME}-boot ALIAS ${PROJECT_NAME}-boot-i386)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/crt/")
add_library(${PROJECT_NAME}-crti ALIAS ${PROJECT_NAME}-crti-i386)
add_library(${PROJECT_NAME}-crtn ALIAS ${PROJECT_NAME}-crtn-i386)

View File

@@ -0,0 +1,6 @@
add_library(${PROJECT_NAME}-boot-i386 OBJECT)
file(GLOB ASM_FILES CONFIGURE_DEPENDS *.s)
target_sources(${PROJECT_NAME}-boot-i386 PRIVATE ${ASM_FILES})
target_include_directories(${PROJECT_NAME}-boot-i386 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -0,0 +1,2 @@
add_library(${PROJECT_NAME}-crti-i386 OBJECT crti.s)
add_library(${PROJECT_NAME}-crtn-i386 OBJECT crtn.s)

View File

@@ -1,6 +0,0 @@
add_library(${PROJECT_NAME}-boot OBJECT)
file(GLOB ASM_FILES CONFIGURE_DEPENDS *.s)
target_sources(${PROJECT_NAME}-boot PRIVATE ${ASM_FILES})
target_include_directories(${PROJECT_NAME}-boot PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -1,2 +0,0 @@
add_library(${PROJECT_NAME}-crti-x86 OBJECT crti.s)
add_library(${PROJECT_NAME}-crtn-x86 OBJECT crtn.s)

View File

55
src/kernel/include/tty.h Normal file
View File

@@ -0,0 +1,55 @@
#ifndef INCLUDE_INCLUDE_TTY_H_
#define INCLUDE_INCLUDE_TTY_H_
#include <stddef.h>
/**
* @brief Initializes the terminal interface.
*
* This function sets up the initial state of the terminal, including its
* dimensions, color settings, and initializes all buffer entries to a default
* character with black foreground and white background colors. The
* initialization process involves iterating over every cell in the terminal's
* grid and setting each entry to the default VGA entry.
*/
void tty_initialize(void);
/**
* @brief Outputs a character to the terminal.
*
* This function writes a single character to the terminal at its current cursor
* position. The cursor is moved one cell right after each write; if it reaches
* the end of the row (VGA_WIDTH), it resets to the beginning of the next line
* (row) and increments the row counter (terminal_row).
*
* @param c The character to be displayed on the terminal
*/
void tty_putchar(char c);
/**
* @brief Writes a string to the terminal.
*
* This function iterates over each character in the provided string and calls
* 'terminal_putchar' for each. The string is assumed to be null-terminated,
* meaning that 'strlen' can be used to determine its length before writing it
* out.
*
* @param data A pointer to a null-terminated string containing characters to
* display on the terminal
*/
void tty_write(const char *data, size_t size);
/**
* @brief Writes a string to the terminal.
*
* This function is an alias for 'terminal_write', providing a simpler interface
* for printing strings by directly passing in a string literal. The length of
* the string is determined automatically using 'strlen'.
*
* @param data A pointer to a null-terminated string containing characters to
* display on the terminal
*/
void tty_write_str(const char *data);
#endif // INCLUDE_INCLUDE_TTY_H_