Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Refactor filesystem & stl code
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderIce2 committed May 18, 2024
1 parent 77a291d commit 6801475
Show file tree
Hide file tree
Showing 186 changed files with 15,427 additions and 9,389 deletions.
141 changes: 0 additions & 141 deletions .vscode/c_boilerplates.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@
],
"description": "Create kernel documentation brief."
},
"For Iteration": {
"prefix": [
"foritr",
],
"body": [
"forItr(${1:itr}, ${2:container})",
"{",
"\t$0",
"}"
],
"description": "Create for loop with iterator."
},
"License": {
"prefix": [
"license",
Expand All @@ -77,134 +65,5 @@
"*/"
],
"description": "Create kernel license."
},
"Driver Code": {
"prefix": [
"driver",
],
"body": [
"/*",
"\tThis file is part of Fennix Kernel.",
"",
"\tFennix Kernel is free software: you can redistribute it and/or",
"\tmodify it under the terms of the GNU General Public License as",
"\tpublished by the Free Software Foundation, either version 3 of",
"\tthe License, or (at your option) any later version.",
"",
"\tFennix Kernel is distributed in the hope that it will be useful,",
"\tbut WITHOUT ANY WARRANTY; without even the implied warranty of",
"\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
"\tGNU General Public License for more details.",
"",
"\tYou should have received a copy of the GNU General Public License",
"\talong with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.",
"*/",
"",
"#include \"${1:driver}.hpp\"",
"",
"#include <debug.h>",
"",
"#include \"../../../kernel.h\"",
"",
"namespace Driver",
"{",
"\tint ${2:driver}::drvOpen(int Flags, mode_t Mode) { return 0; }",
"",
"\tint ${2:driver}::drvClose() { return 0; }",
"",
"\tsize_t ${2:driver}::drvRead(uint8_t *Buffer, size_t Size, off_t Offset) { return 0; }",
"",
"\tsize_t ${2:driver}::drvWrite(uint8_t *Buffer, size_t Size, off_t Offset) { return 0; }",
"",
"\tint ${2:driver}::drvIoctl(unsigned long Request, void *Argp) { return 0; }",
"",
"\tvoid ${2:driver}::OnInterruptReceived(CPU::TrapFrame *) {}",
"",
"\tvoid ${2:driver}::Panic() {}",
"",
"\t${2:driver}::${2:driver}(PCI::PCIDevice dev)",
"\t\t: Object(dev),",
"\t\t Interrupts::Handler(dev)",
"\t{",
"\t}",
"",
"\t${2:driver}::${2:driver}(int irq)",
"\t\t: Object(irq),",
"\t\t Interrupts::Handler(irq)",
"\t{",
"\t}",
"",
"\t${2:driver}::${2:driver}()",
"\t{",
"\t}",
"",
"\t${2:driver}::~${2:driver}()",
"\t{",
"\t\tif (GetError() != 0)",
"\t\t\treturn;",
"\t}",
"}",
"",

],
"description": "Kernel driver code template."
},
"Driver Header": {
"prefix": [
"driver",
],
"body": [
"/*",
"\tThis file is part of Fennix Kernel.",
"",
"\tFennix Kernel is free software: you can redistribute it and/or",
"\tmodify it under the terms of the GNU General Public License as",
"\tpublished by the Free Software Foundation, either version 3 of",
"\tthe License, or (at your option) any later version.",
"",
"\tFennix Kernel is distributed in the hope that it will be useful,",
"\tbut WITHOUT ANY WARRANTY; without even the implied warranty of",
"\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
"\tGNU General Public License for more details.",
"",
"\tYou should have received a copy of the GNU General Public License",
"\talong with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.",
"*/",
"",
"#pragma once",
"#include <driver.hpp>",
"",
"namespace Driver",
"{",
"\tclass ${1:driver} : public Object, public Interrupts::Handler",
"\t{",
"\tprivate:",
"\t\tvoid OnInterruptReceived(CPU::TrapFrame *Frame) final;",
"\t\tvoid Panic(Driver::DriverContext *ctx) final;",
"",
"\tpublic:",
"\t\tint drvOpen(int Flags, mode_t Mode);",
"\t\tint drvClose();",
"\t\tsize_t drvRead(uint8_t *Buffer, size_t Size, off_t Offset);",
"\t\tsize_t drvWrite(uint8_t *Buffer, size_t Size, off_t Offset);",
"\t\tint drvIoctl(unsigned long Request, void *Argp);",
"",
"\t\tconst char *drvName() final { return \"${2:MyDriver}\"; }",
"\t\tconst char *drvDescription() final { return \"${3:MyDescription}\"; }",
"\t\tconst char *drvVersion() final { return \"${4:0.0.0}\"; }",
"\t\tconst char *drvAuthor() final { return \"${5:Author}\"; }",
"\t\tconst char *drvLicense() final { return \"${6:License}\"; }",
"\t\tDriverType drvType() final { return DriverType_${7:Generic}; }",
"",
"\t\t${1:driver}(PCI::PCIDevice dev);",
"\t\t${1:driver}(int irq);",
"\t\t${1:driver}();",
"\t\t~${1:driver}();",
"\t};",
"}",
"",

],
"description": "Kernel driver header template."
}
}
33 changes: 12 additions & 21 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
"${workspaceFolder}/include",
"${workspaceFolder}/include/**",
"${workspaceFolder}/include_std",
"${workspaceFolder}/include_std/**"
"${workspaceFolder}/include_std/**",
"${workspaceFolder}/arch/amd64/include"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_ARCH=\"amd64\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"a64",
"a86",
"DEBUG=\"1\""
Expand Down Expand Up @@ -79,15 +74,13 @@
"${workspaceFolder}/include",
"${workspaceFolder}/include/**",
"${workspaceFolder}/include_std",
"${workspaceFolder}/include_std/**"
"${workspaceFolder}/include_std/**",
"${workspaceFolder}/arch/i386/include"
],
"forcedInclude": [
"${workspaceFolder}/.vscode/preinclude.h"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_ARCH=\"i386\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"a32",
"a86",
"DEBUG=\"1\""
Expand Down Expand Up @@ -152,15 +145,13 @@
"${workspaceFolder}/include",
"${workspaceFolder}/include/**",
"${workspaceFolder}/include_std",
"${workspaceFolder}/include_std/**"
"${workspaceFolder}/include_std/**",
"${workspaceFolder}/arch/aarch64/include"
],
"forcedInclude": [
"${workspaceFolder}/.vscode/preinclude.h"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_ARCH=\"aarch64\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"aa64",
"DEBUG=\"1\""
],
Expand Down
7 changes: 7 additions & 0 deletions .vscode/preinclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
#undef _WIN64
#undef __APPLE__
#undef __clang__
#define __vscode__ 1
#define __kernel__ 1
#define KERNEL_NAME "Fennix"
#define KERNEL_ARCH "amd64"
#define KERNEL_VERSION "1.0"
#define GIT_COMMIT "0000000000000000000000000000000000000000"
#define GIT_COMMIT_SHORT "0000000"
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"C_Cpp.errorSquiggles": "Enabled",
"C_Cpp.errorSquiggles": "enabled",
"C_Cpp.autocompleteAddParentheses": true,
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
"C_Cpp.clang_format_style": "Visual Studio",
Expand All @@ -14,6 +14,10 @@
"clang-diagnostic-unknown-warning-option",
"clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling",
"clang-diagnostic-implicit-exception-spec-mismatch",
"clang-diagnostic-unknown-attributes"
"clang-diagnostic-unknown-attributes",
"clang-diagnostic-user-defined-literals",
"clang-diagnostic-non-pod-varargs",
"clang-diagnostic-non-pod-varargs",
"clang-diagnostic-non-pod-varargs"
]
}
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,57 @@ RUST_TARGET_PATH = arch/$(OSARCH)/rust-target.json
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)

HEADERS = $(sort $(dir $(wildcard ./include/*))) $(sort $(dir $(wildcard ./include_std/*)))
INCLUDE_DIR = -I./include -I./include_std

BMP_SOURCES = $(shell find ./ -type f -name '*.bmp')
PSF_SOURCES = $(shell find ./ -type f -name '*.psf')
ifeq ($(OSARCH), amd64)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
s_SOURCES = $(shell find ./ -type f -name '*.s' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
HEADERS += $(sort $(dir $(wildcard ./arch/amd64/include/*)))
INCLUDE_DIR += -I./arch/amd64/include
else ifeq ($(OSARCH), i386)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
s_SOURCES = $(shell find ./ -type f -name '*.s' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
HEADERS += $(sort $(dir $(wildcard ./arch/i386/include/*)))
INCLUDE_DIR += -I./arch/i386/include
else ifeq ($(OSARCH), aarch64)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
s_SOURCES = $(shell find ./ -type f -name '*.s' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
HEADERS += $(sort $(dir $(wildcard ./arch/aarch64/include/*)))
INCLUDE_DIR += -I./arch/aarch64/include
endif
HEADERS = $(sort $(dir $(wildcard ./include/*))) $(sort $(dir $(wildcard ./include_std/*)))
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(s_SOURCES:.s=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
STACK_USAGE_OBJ = $(C_SOURCES:.c=.su) $(CPP_SOURCES:.cpp=.su)
GCNO_OBJ = $(C_SOURCES:.c=.gcno) $(CPP_SOURCES:.cpp=.gcno)
INCLUDE_DIR = -I./include -I./include_std

LDFLAGS := -Wl,-Map kernel.map -static -nostdlib -nodefaultlibs -nolibc

# Disable all warnings by adding "-w" in WARNCFLAG and if you want to treat the warnings as errors, add "-Werror"
# -Wconversion this may be re-added later
WARNCFLAG = -Wall -Wextra \
-Wfloat-equal -Wpointer-arith -Wcast-align \
-Wredundant-decls -Winit-self -Wswitch-default \
-Wstrict-overflow=5 -Wconversion -Wno-error=cpp -Werror \
-Wstrict-overflow=5 -Wno-error=cpp -Werror \
-Wno-unused-parameter

# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
CFLAGS := \
$(INCLUDE_DIR) \
-D__kernel__='1' \
-DKERNEL_NAME='"$(OSNAME)"' \
-DKERNEL_ARCH='"$(OSARCH)"' \
-DKERNEL_VERSION='"$(KERNEL_VERSION)"' \
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'

SIMD_FLAGS := -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mavx512f

ifeq ($(OSARCH), amd64)

CFLAGS += -fno-pic -fno-pie -mno-red-zone -march=core2 \
Expand Down Expand Up @@ -131,6 +138,7 @@ endif
$(KERNEL_FILENAME): $(OBJ)
$(info Linking $@)
$(CC) $(LDFLAGS) $(OBJ) -o $@
# $(CC) $(LDFLAGS) $(OBJ) -mno-red-zone -lgcc -o $@

%.o: %.c $(HEADERS)
$(info Compiling $<)
Expand All @@ -139,7 +147,7 @@ $(KERNEL_FILENAME): $(OBJ)
# https://gcc.gnu.org/projects/cxx-status.html
%.o: %.cpp $(HEADERS)
$(info Compiling $<)
$(CPP) $(CFLAGS) $(CFLAG_STACK_PROTECTOR) $(WARNCFLAG) -std=c++20 -c $< -o $@ -fno-exceptions -fno-rtti
$(CPP) $(CFLAGS) $(CFLAG_STACK_PROTECTOR) $(WARNCFLAG) -std=c++20 -c $< -o $@ -fno-rtti

%.o: %.S
$(info Compiling $<)
Expand Down
Empty file added arch/aarch64/include/.gitkeep
Empty file.
Empty file added arch/amd64/include/.gitkeep
Empty file.
25 changes: 25 additions & 0 deletions arch/amd64/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ SECTIONS
{
*(.data .data.*)
} :data

.eh_frame : AT(ADDR(.eh_frame) - KERNEL_VMA) ONLY_IF_RW
{
KEEP (*(.eh_frame .eh_frame.*))
} :data

.gcc_except_table : AT(ADDR(.gcc_except_table) - KERNEL_VMA) ONLY_IF_RW
{
KEEP (*(.gcc_except_table .gcc_except_table.*))
} :data
_kernel_data_end = ALIGN(CONSTANT(MAXPAGESIZE));

_kernel_rodata_start = ALIGN(CONSTANT(MAXPAGESIZE));
Expand All @@ -85,6 +95,21 @@ SECTIONS
KEEP(*(.fini_array .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} :rodata

.eh_frame_hdr : AT(ADDR(.eh_frame_hdr) - KERNEL_VMA)
{
*(.eh_frame_hdr .eh_frame_hdr.*)
} :rodata

.eh_frame : AT(ADDR(.eh_frame) - KERNEL_VMA) ONLY_IF_RO
{
KEEP (*(.eh_frame .eh_frame.*))
} :rodata

.gcc_except_table : AT(ADDR(.gcc_except_table) - KERNEL_VMA) ONLY_IF_RO
{
KEEP (*(.gcc_except_table .gcc_except_table.*))
} :rodata
_kernel_rodata_end = ALIGN(CONSTANT(MAXPAGESIZE));

_kernel_bss_start = ALIGN(CONSTANT(MAXPAGESIZE));
Expand Down
Loading

0 comments on commit 6801475

Please sign in to comment.