use new toolchain for kernel too

This commit is contained in:
2024-03-29 21:30:55 +01:00
parent 95e015c92a
commit 425fd39788
8 changed files with 31 additions and 101 deletions

4
.idea/cmake.xml generated
View File

@@ -2,9 +2,9 @@
<project version="4">
<component name="CMakeSharedSettings">
<configurations>
<configuration PROFILE_NAME="RelWithDebInfo" ENABLED="true" CONFIG_NAME="RelWithDebInfo" GENERATION_OPTIONS="-DOS2_ROOT=$CMakeProjectDir$ -DCMAKE_TOOLCHAIN_FILE=CMake-x86_64-elf-toolchain.cmake" />
<configuration PROFILE_NAME="RelWithDebInfo" ENABLED="true" CONFIG_NAME="RelWithDebInfo" GENERATION_OPTIONS="-DOS2_ROOT=$CMakeProjectDir$ -DCMAKE_TOOLCHAIN_FILE=CMake-x86_64-os3-toolchain.cmake" />
<configuration PROFILE_NAME="Test" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DTEST_MODE=NATIVE" />
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DOS2_ROOT=$CMakeProjectDir$ -DCMAKE_TOOLCHAIN_FILE=CMake-x86_64-elf-toolchain.cmake" />
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DOS2_ROOT=$CMakeProjectDir$ -DCMAKE_TOOLCHAIN_FILE=CMake-x86_64-os3-toolchain.cmake" />
</configurations>
</component>
</project>

View File

@@ -1,26 +0,0 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(triple x86_64-elf)
set(tools ${OS2_ROOT}/toolchain)
set(CMAKE_C_COMPILER ${tools}/gcc-x86_64-elf-prefix/bin/x86_64-elf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/gcc-x86_64-elf-prefix/bin/x86_64-elf-g++)
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS asm)
set(cxxflags -ffreestanding -nostdlib -mno-red-zone -mcmodel=large -fno-exceptions -fno-rtti)
set(cflags -ffreestanding -nostdlib -mno-red-zone -mcmodel=large)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${cxxflags}>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${cflags}>")
add_link_options(-ffreestanding -nostdlib -mno-red-zone -mcmodel=large -fno-exceptions -fno-rtti)
include_directories(${tools}/limine/prefix/include)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)

View File

@@ -0,0 +1,16 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(triple x86_64-os3)
set(tools ${OS2_ROOT}/toolchain)
set(CMAKE_C_COMPILER ${tools}/gcc-x86_64-os3-prefix/bin/x86_64-os3-gcc)
set(CMAKE_CXX_COMPILER ${tools}/gcc-x86_64-os3-prefix/bin/x86_64-os3-g++)
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS asm)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)

View File

@@ -1,8 +1,11 @@
add_executable(kernel.elf)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all -Wno-pointer-arith -fsanitize=undefined>)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all -Wno-pointer-arith -fsanitize=undefined>)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all -Wno-pointer-arith -fsanitize=undefined -ffreestanding -nostdlib -mno-red-zone -mcmodel=large -fno-exceptions -fno-rtti>)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all -Wno-pointer-arith -fsanitize=undefined -ffreestanding -nostdlib -mno-red-zone -mcmodel=large>)
target_link_options(kernel.elf PUBLIC -ffreestanding -nostdlib -mno-red-zone -mcmodel=large -fno-exceptions -fno-rtti)
target_include_directories(kernel.elf PRIVATE ${tools}/limine/prefix/include)
add_subdirectory(./arch/)
add_subdirectory(./kernel/)

View File

@@ -1,18 +1,14 @@
add_executable(init init.c)
target_compile_options(init PRIVATE -fno-exceptions -fno-rtti)
target_link_libraries(init syscalls_interface)
target_include_directories(init PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_options(init PRIVATE "SHELL:-T${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
set_target_properties(init PROPERTIES LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
add_executable(hello2 hello2.c)
target_compile_options(hello2 PRIVATE -fno-exceptions -fno-rtti)
target_link_libraries(hello2 syscalls_interface)
target_include_directories(hello2 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_options(hello2 PRIVATE "SHELL:-T${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
set_target_properties(hello2 PROPERTIES LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")

View File

@@ -1,17 +1,16 @@
#include "syscalls_interface.h"
volatile char asdfasdf[323];
volatile int x = 3;
volatile int w = 0;
volatile char asdfasdf[323];
volatile int x = 3;
volatile int w = 0;
volatile const char *hello = "hello xd";
volatile const char *hello = "hello xd";
__attribute__((unused)) void _start() {
int main() {
if (x == 3) putchar('x');
if (w == 2) putchar('w');
if (asdfasdf[0] == '\0') putchar('a');
putchar('h');
putchar('i');
putchar('\n');
exit();
}

View File

@@ -1,7 +1,7 @@
#include "syscalls_interface.h"
__attribute__((unused)) void _start() {
int main() {
// putchar('h');
// putchar('i');
// putchar('\n');

View File

@@ -1,58 +0,0 @@
OUTPUT_FORMAT("elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
PHDRS
{
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; /* Dynamic PHDR for relocations */
}
SECTIONS
{
. = 0x00020000;
.text : {
*(.text .text.*)
} :text
/* Move to the next memory page for .rodata */
. += CONSTANT(MAXPAGESIZE);
.rodata : {
ctors_begin = .;
*(.ctors)
*(.init_array)
ctors_end = .;
*(.rodata .rodata.*)
} :rodata
/* Move to the next memory page for .data */
. += CONSTANT(MAXPAGESIZE);
.data : {
*(.data .data.*)
} :data
/* Dynamic section for relocations, both in its own PHDR and inside data PHDR */
.dynamic : {
*(.dynamic)
} :data :dynamic
/* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
/* unnecessary zeros will be written to the binary. */
/* If you need, for example, .init_array and .fini_array, those should be placed */
/* above this. */
.bss : {
*(.bss .bss.*)
*(COMMON)
} :data
/* Discard .note.* and .eh_frame since they may cause issues on some hosts. */
/DISCARD/ : {
*(.eh_frame)
*(.note .note.*)
}}