From b07b4f0d38b40e709fe457c0a1a1e4aab6aeaf06 Mon Sep 17 00:00:00 2001 From: Nigel Date: Sun, 19 Feb 2023 23:38:32 +0100 Subject: [PATCH] Moving certain aspects into their own static library Problem: As our kernel grows we need more complex datastructures and functions these would come from the standard C/C++ library with normal programs. The kernel is a freestanding programme and has no access to standard libraries. Solution: We build a mini version of the standard C/C++ library which will contain the datastructures and functions we want. This library can then be statically linked into our kernel binary. Making it a statically linked library also gives more structure to the project. Keeping these random functions and datastructures in the kernel just clutters the kernel source code with less relevant source code. --- Makefile | 16 +--- source/CoreLib/Makefile | 33 +++++++ source/CoreLib/Memory.cpp | 58 ++++++++++++ source/CoreLib/Memory.h | 12 +++ source/CoreLib/Path.cpp | 24 +++++ source/CoreLib/Path.h | 22 +++++ source/CoreLib/Stack.cpp | 3 + .../{lib/include/stack.h => CoreLib/Stack.h} | 2 +- source/CoreLib/String.cpp | 39 ++++++++ source/CoreLib/String.h | 18 ++++ source/CoreLib/StringView.cpp | 14 +++ source/CoreLib/StringView.h | 14 +++ source/CoreLib/bin/memory.o | Bin 0 -> 4712 bytes source/CoreLib/bin/path.o | Bin 0 -> 4988 bytes source/CoreLib/bin/stack.o | Bin 0 -> 788 bytes source/CoreLib/bin/string.o | Bin 0 -> 4400 bytes source/CoreLib/bin/stringview.o | Bin 0 -> 3772 bytes source/kernel/drivers/acpi/rsdp.h | 3 +- source/kernel/drivers/ata/ataDevice.cpp | 1 - source/kernel/kernel.cpp | 4 - source/kernel/memory/PhysicalMemoryManager.h | 3 +- source/kernel/memory/TaskStateSegment.h | 2 +- source/kernel/memory/memory.h | 3 +- .../supervisorterminal/superVisorTerminal.h | 4 +- source/kernel/terminal/kterm.h | 5 +- source/kernel/vfs/Path.cpp | 83 ------------------ source/kernel/vfs/Path.h | 46 ---------- source/kernel/vfs/VFS.cpp | 7 +- source/kernel/vfs/VFS.h | 2 +- source/lib/include/mem.h | 31 ------- source/lib/include/string.c | 26 ------ source/lib/include/string.h | 4 - 32 files changed, 255 insertions(+), 224 deletions(-) create mode 100644 source/CoreLib/Makefile create mode 100644 source/CoreLib/Memory.cpp create mode 100644 source/CoreLib/Memory.h create mode 100644 source/CoreLib/Path.cpp create mode 100644 source/CoreLib/Path.h create mode 100644 source/CoreLib/Stack.cpp rename source/{lib/include/stack.h => CoreLib/Stack.h} (96%) create mode 100644 source/CoreLib/String.cpp create mode 100644 source/CoreLib/String.h create mode 100644 source/CoreLib/StringView.cpp create mode 100644 source/CoreLib/StringView.h create mode 100644 source/CoreLib/bin/memory.o create mode 100644 source/CoreLib/bin/path.o create mode 100644 source/CoreLib/bin/stack.o create mode 100644 source/CoreLib/bin/string.o create mode 100644 source/CoreLib/bin/stringview.o delete mode 100644 source/kernel/vfs/Path.cpp delete mode 100644 source/kernel/vfs/Path.h delete mode 100644 source/lib/include/mem.h delete mode 100644 source/lib/include/string.c delete mode 100644 source/lib/include/string.h diff --git a/Makefile b/Makefile index faad734..b4eb068 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ - EMULATOR = qemu-system-i386 AS = ${HOME}/opt/cross/bin/i686-elf-as CC = ${HOME}/opt/cross/bin/i686-elf-gcc CPP = ${HOME}/opt/cross/bin/i686-elf-g++ -CFLAGS = -ffreestanding -Og -ggdb -Wall -Wextra +CFLAGS = -ffreestanding -Og -ggdb -Wall -Wextra -I source/CoreLib/build/include -OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/Path.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/paging.o $(BUILD_DIR)/VFS.o $(BUILD_DIR)/pit.o $(BUILD_DIR)/time.o $(BUILD_DIR)/keyboard.o $(BUILD_DIR)/io.o $(BUILD_DIR)/processor.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/KHeap.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pcidevice.o $(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/ataDevice.o $(BUILD_DIR)/rsdp.o $(BUILD_DIR)/acpi.o +OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/paging.o $(BUILD_DIR)/VFS.o $(BUILD_DIR)/pit.o $(BUILD_DIR)/time.o $(BUILD_DIR)/keyboard.o $(BUILD_DIR)/io.o $(BUILD_DIR)/processor.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/KHeap.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pcidevice.o $(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/ataDevice.o $(BUILD_DIR)/rsdp.o $(BUILD_DIR)/acpi.o SRC_DIR = source BUILD_DIR = build @@ -53,8 +52,7 @@ test_disk: all build_kernel: $(OBJ_LINK_LIST) - $(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \ - -ffreestanding -ggdb -Og -nostdlib $(OBJ_LINK_LIST) -lgcc + $(CPP) -T $(SRC_DIR)/kernel/linker.ld -o $(BUILD_DIR)/myos.bin -ffreestanding -ggdb -Og -nostdlib $(OBJ_LINK_LIST) -lgcc -L source/CoreLib/build -lCoreLib build_x86_64: $(AS) $(SRC_DIR)/cgc/x86_64/crti.s -o $(BUILD_DIR)/crti_64.o @@ -71,7 +69,7 @@ $(BUILD_DIR)/kterm.o: $(CPP) -c $(SRC_DIR)/kernel/terminal/kterm.cpp -o $(BUILD_DIR)/kterm.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/io.o: - $(CPP) -c $(SRC_DIR)/kernel/drivers/io/io.cpp -o $(BUILD_DIR)/io.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/io/io.cpp -o $(BUILD_DIR)/io.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/idt.o: $(CPP) -c $(SRC_DIR)/kernel/interrupts/idt.cpp -o $(BUILD_DIR)/idt.o $(CFLAGS) -fno-exceptions -fno-rtti @@ -82,9 +80,6 @@ $(BUILD_DIR)/gdtc.o: $(BUILD_DIR)/pic.o: $(CPP) -c $(SRC_DIR)/kernel/drivers/pic/pic.cpp -o $(BUILD_DIR)/pic.o $(CFLAGS) -fno-exceptions -fno-rtti -$(BUILD_DIR)/string.o: - $(CC) -c $(SRC_DIR)/lib/include/string.c -o $(BUILD_DIR)/string.o $(CFLAGS) -std=gnu99 - $(BUILD_DIR)/PhysicalMemoryManager.o: $(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti @@ -136,9 +131,6 @@ $(BUILD_DIR)/prekernel.o: $(BUILD_DIR)/processor.o: $(CPP) -c $(SRC_DIR)/kernel/i386/processor.cpp -o $(BUILD_DIR)/processor.o $(CFLAGS) -fno-exceptions -fno-rtti -$(BUILD_DIR)/Path.o: - $(CPP) -c $(SRC_DIR)/kernel/vfs/Path.cpp -o $(BUILD_DIR)/Path.o $(CFLAGS) -fno-exceptions -fno-rtti - # Assembly -> Object files $(BUILD_DIR)/boot.o: $(AS) $(SRC_DIR)/kernel/boot/boot.s -o $(BUILD_DIR)/boot.o diff --git a/source/CoreLib/Makefile b/source/CoreLib/Makefile new file mode 100644 index 0000000..b5a0cbb --- /dev/null +++ b/source/CoreLib/Makefile @@ -0,0 +1,33 @@ +CPP = ${HOME}/opt/cross/bin/i686-elf-g++ +CFLAGS = -ffreestanding -Og -ggdb -Wall -Wextra + +SRC_DIR = . +BUILD_DIR = build +OBJ_FOLDER = bin +OUTPUTFILE = $(BUILD_DIR)/libCoreLib.a + +OFILES = $(OBJ_FOLDER)/memory.o $(OBJ_FOLDER)/path.o $(OBJ_FOLDER)/stack.o $(OBJ_FOLDER)/string.o $(OBJ_FOLDER)/stringview.o + + +.phony: all +all: $(OUTPUTFILE) + cp *.h build/include/ + +$(OUTPUTFILE): $(OFILES) + ar -rc $(OUTPUTFILE) $(OFILES) + +$(OBJ_FOLDER)/memory.o: Memory.cpp + $(CPP) -c Memory.cpp -o $(OBJ_FOLDER)/memory.o $(CFLAGS) + +$(OBJ_FOLDER)/path.o: Path.cpp + $(CPP) -c Path.cpp -o $(OBJ_FOLDER)/path.o $(CFLAGS) + +$(OBJ_FOLDER)/stack.o: Stack.cpp + $(CPP) -c Stack.cpp -o $(OBJ_FOLDER)/stack.o $(CFLAGS) + +$(OBJ_FOLDER)/string.o: String.cpp + $(CPP) -c String.cpp -o $(OBJ_FOLDER)/string.o $(CFLAGS) + +$(OBJ_FOLDER)/stringview.o: StringView.cpp + $(CPP) -c StringView.cpp -o $(OBJ_FOLDER)/stringview.o $(CFLAGS) + diff --git a/source/CoreLib/Memory.cpp b/source/CoreLib/Memory.cpp new file mode 100644 index 0000000..fce2e66 --- /dev/null +++ b/source/CoreLib/Memory.cpp @@ -0,0 +1,58 @@ +// +// Created by nigel on 19/02/23. +// +#include "Memory.h" + +void* memset (void* ptr, int value, size_t num) +{ + for( int i = 0; i < num; i++ ) + { + unsigned char* data = (unsigned char*)ptr+ i; + *data = (unsigned char)value; + } + return ptr; +} + + +int memcmp( const void* ptr1, const void* ptr2, size_t num) +{ + const unsigned char * cs = (const unsigned char*) ptr1; + const unsigned char * ct = (const unsigned char*) ptr2; + + + for (int i = 0 ; i < num ; i++, cs++, ct++ ){ + if( *cs < *ct){ + return -1; + } else if( *cs > *ct){ + return 1; + } + } + + return 0; + +} + +size_t strlen(const char* str) { + size_t len = 0; + while(str[len]){ + len++; + } + return len; +} + +int strncmp ( const char* str1, const char* str2, size_t num ){ + for( int i = 0; i < num ; i++){ + + if( str1[i] < str2[i]){ + return -1; + } + + if( str1[i] > str2[i] ){ + return 1; + } + + + } + + return 0; +} \ No newline at end of file diff --git a/source/CoreLib/Memory.h b/source/CoreLib/Memory.h new file mode 100644 index 0000000..e31a5dc --- /dev/null +++ b/source/CoreLib/Memory.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +void* memset (void* ptr, int value, size_t num); + +int memcmp( const void* ptr1, const void* ptr2, size_t num); + +size_t strlen(const char* str); + +int strncmp ( const char* str1, const char* str2, size_t num ); \ No newline at end of file diff --git a/source/CoreLib/Path.cpp b/source/CoreLib/Path.cpp new file mode 100644 index 0000000..d23b226 --- /dev/null +++ b/source/CoreLib/Path.cpp @@ -0,0 +1,24 @@ +// +// Created by nigel on 19/02/23. +// +#include "Path.h" + +Path::Path(String path) +: path(path) +{ + +} + +StringView Path::getbasename() +{ + unsigned int path_length = path.length(); + int i = path_length; + while (path[i] != '/') + i--; + + return {path,static_cast(i +1), path_length}; +} + +char* Path::str() { + return path.str(); +} \ No newline at end of file diff --git a/source/CoreLib/Path.h b/source/CoreLib/Path.h new file mode 100644 index 0000000..ec4d955 --- /dev/null +++ b/source/CoreLib/Path.h @@ -0,0 +1,22 @@ +// +// Created by nigel on 19/02/23. +// +#pragma once +#include +#include "StringView.h" + + +class Path{ +public: + explicit Path(String path); + + StringView getbasename(); + + char* str(); + +private: + String path; + +}; + + diff --git a/source/CoreLib/Stack.cpp b/source/CoreLib/Stack.cpp new file mode 100644 index 0000000..af9520e --- /dev/null +++ b/source/CoreLib/Stack.cpp @@ -0,0 +1,3 @@ +// +// Created by nigel on 19/02/23. +// diff --git a/source/lib/include/stack.h b/source/CoreLib/Stack.h similarity index 96% rename from source/lib/include/stack.h rename to source/CoreLib/Stack.h index 0128bf6..b363fed 100644 --- a/source/lib/include/stack.h +++ b/source/CoreLib/Stack.h @@ -1,5 +1,5 @@ #pragma once -#include "../../kernel/memory/KernelHeap.h" +#include "../kernel/memory/KernelHeap.h" #include template diff --git a/source/CoreLib/String.cpp b/source/CoreLib/String.cpp new file mode 100644 index 0000000..1aaf064 --- /dev/null +++ b/source/CoreLib/String.cpp @@ -0,0 +1,39 @@ +#include "String.h" +#include +#include + + +String::String(char* characters) +: chars(characters) + { + + } + +char* String::str(){ + return chars; +} + +unsigned int String::length () +{ + int i = 0; + + while ( chars[i] != '\0'){ + i++; + } + + return i; +} + +// Returns a null character if size exceeds limits +char String::operator[] (size_t idx) +{ + if( idx > this->length()) + return '\0'; + + return chars[idx]; +} + +const char String::operator[](size_t idx) const { +return (const char) chars[idx]; +} + diff --git a/source/CoreLib/String.h b/source/CoreLib/String.h new file mode 100644 index 0000000..8ff3f05 --- /dev/null +++ b/source/CoreLib/String.h @@ -0,0 +1,18 @@ +#pragma once +#include + +class String { +public: + String(char* characters); + String(String&) = default; + unsigned int length(); + + char* str (); + char operator[](size_t index) ; + const char operator[](size_t idx) const; + +protected: + char* chars; + + +}; \ No newline at end of file diff --git a/source/CoreLib/StringView.cpp b/source/CoreLib/StringView.cpp new file mode 100644 index 0000000..5392c87 --- /dev/null +++ b/source/CoreLib/StringView.cpp @@ -0,0 +1,14 @@ +// +// Created by nigel on 19/02/23. +// +#include "StringView.h" + +StringView::StringView(String string, unsigned int start, unsigned int end) + : String(string), begin(start), end(end) +{ + +} + +char* StringView::str(){ + //TODO: Not implemented +} \ No newline at end of file diff --git a/source/CoreLib/StringView.h b/source/CoreLib/StringView.h new file mode 100644 index 0000000..725284b --- /dev/null +++ b/source/CoreLib/StringView.h @@ -0,0 +1,14 @@ +// +// Created by nigel on 19/02/23. +// +#pragma once +#include "String.h" + +class StringView : String { +public: + StringView(String string, unsigned int start, unsigned int end ); + char* str (); +private: + unsigned int begin; + unsigned int end; +}; diff --git a/source/CoreLib/bin/memory.o b/source/CoreLib/bin/memory.o new file mode 100644 index 0000000000000000000000000000000000000000..7b6893fc65737d96e5c0f55bb73064c293c0145a GIT binary patch literal 4712 zcmb_fYiv}<6`r~G&h^^6ek{9y!2}k93CMWYCKT3S5{#23yh#iM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pQ}#stKtl56(=TZc!wbH|FQ6=9JY_(oU-uutM_4s=}=`Q z+A!*{;)Hk`=QIIYok1Xur8=MY0O=3QqY8hddJAu(bRA99oQ=ni^lkfMqS`UnYKTpwBRE=|=e>=Gn&adnS@ z_r}-W=Imd_N4YzH4bW~Mkm61FdzpkTuI^*tz5WvLw-++{;}^;G_XKG6;ry^XtM3Pg zb9B@{gX*=r4(ES#jkJ#XYm4lj!^aK3gPMgltS@SGr}kU0d$MWe#7FjPsNOt^$bOAynca(-Jsu0hLI!-4@EH0sh^9`I=ipAV6kVRg zICEd9NvG~3&T*FIDGhSlfk^nY*LRDo6cM_9Ca{}?03F|dV0GH*TCZcCvdO#eslv~4 z=T>lv&r}8>WhvHqVk(Ir5}Z*W18~Bkpc2C}9?lYurY6*ssy$r!C`;AGo9p)$7euHX z4>h^|*W1s`{+F7o?BTBH{D`!VyV3LXIQZ}0d(Aa9sJK`2kv>y9`nopUf_$4~LNQ8x zoelRz{+wjOa4H{|CgpDuBOQ}eze+mQ-n^A8{E}*_(4pq2I3w+HOY#GCpu=!~^A=-L literal 0 HcmV?d00001 diff --git a/source/CoreLib/bin/string.o b/source/CoreLib/bin/string.o new file mode 100644 index 0000000000000000000000000000000000000000..482fce0ad4b555babe51f8a5a91c4429992ea669 GIT binary patch literal 4400 zcmb_fU2Ggj9iQ3T-8=iv=d;hBv0I<3#MlJi#m2aaW4Cr(CoyT#5-TB1xY+lx_d(Bh z*S)=vgpU-tpIjoyLmw)cf`mY=D53=k5LAG015~I8Bp%8O5)y?<i+4>XdYtv`p(zV+_y+qbt~ zjU0Nz?r4~u-_ZwdSpU3mF}dTq|4qe>G*&{;YRR1+YK$3->lD8Iml#Hg3ete~2^XL@ zidcXU`+nVj2x6}LuM-4}321mow+SNp%Mga*7&_jELD%%a-B5&y(M-b+;Ge?qB=Pgm z_>N*=okH(7$d>ajLh^jm;G<+dTh3sfmI>my?X9zUol;8qapyrzYIf8)yCWKLxy6iB6GTa+_8DkF0 zE;87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xQ**Tw$*7OUSW#Cv6>r}n>hyQm`8(Y4E;(vn)RQ+K(!u^}p*e$TD= zUfbw_z5vK}-=k`{2e{1oZt#1ncKp-D~>x>bxok=2;`!uo^i6`a}BDQ~o2*0vM_M7su z#%DBsTH|$%{5?ZIoVh|@h_ymZxHVCt_O9$?e0=_J>NA;kk7DG*Oc7s_xLJBN!?CuJ*f9w z6#YNa9Q@FF!Tyo>Tix6P%4mV25@!0L#fsRcIMGIW41?eHfAdr4!3CNa@AD=ZcoUEJ zbOhrJ25AYx6&NSL^OfLWK6M{}hTcc4@0lP_8dlvC;{+TcfO*@fHh!Op@zmdgUy+O^ ztkJ}zR!U-Yru*h!q6q7$=G_3J>+`&v7hA4Hw9KafFIAu5aW>8r?}srk@x$`5>3YM E-;p%>LI3~& literal 0 HcmV?d00001 diff --git a/source/kernel/drivers/acpi/rsdp.h b/source/kernel/drivers/acpi/rsdp.h index eb5a87a..7d7aecb 100644 --- a/source/kernel/drivers/acpi/rsdp.h +++ b/source/kernel/drivers/acpi/rsdp.h @@ -1,7 +1,8 @@ #pragma once #include #include "./../../terminal/kterm.h" -#include "../../../lib/include/mem.h" +#include + struct RSDPTR { char signature[8]; uint8_t Checksum ; diff --git a/source/kernel/drivers/ata/ataDevice.cpp b/source/kernel/drivers/ata/ataDevice.cpp index 873aa0e..bde914a 100644 --- a/source/kernel/drivers/ata/ataDevice.cpp +++ b/source/kernel/drivers/ata/ataDevice.cpp @@ -12,7 +12,6 @@ void ATA_DEVICE::Soft_Reset(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive){ } - void ATA_DEVICE::Identify(uint16_t DEVICE_CHANNEL,DEVICE_DRIVE drive ){ // lets ignore which port we actually want to check for now ! diff --git a/source/kernel/kernel.cpp b/source/kernel/kernel.cpp index 7bd0ca1..9440716 100644 --- a/source/kernel/kernel.cpp +++ b/source/kernel/kernel.cpp @@ -1,10 +1,6 @@ /* Copyright © Nigel Barink 2023 */ -extern "C"{ -#include "../lib/include/string.h" -} - #include "memory/memory.h" #include "memory/KernelHeap.h" #include "memory/gdt/gdtc.h" diff --git a/source/kernel/memory/PhysicalMemoryManager.h b/source/kernel/memory/PhysicalMemoryManager.h index 9aa9c15..f83fff1 100644 --- a/source/kernel/memory/PhysicalMemoryManager.h +++ b/source/kernel/memory/PhysicalMemoryManager.h @@ -1,8 +1,9 @@ #pragma once #include +#include + #include "../prekernel/bootstructure.h" #include "../terminal/kterm.h" -#include "../../lib/include/mem.h" #include "../bitmap.h" #define BLOCK_SIZE 4092 diff --git a/source/kernel/memory/TaskStateSegment.h b/source/kernel/memory/TaskStateSegment.h index b41a4fb..f26b3ec 100644 --- a/source/kernel/memory/TaskStateSegment.h +++ b/source/kernel/memory/TaskStateSegment.h @@ -1,6 +1,6 @@ #pragma once #include "gdt/gdtc.h" -#include "../../lib/include/string.h" +#include struct TaskStateSegment { uint32_t prev_tss; diff --git a/source/kernel/memory/memory.h b/source/kernel/memory/memory.h index ea609ac..1f2df61 100644 --- a/source/kernel/memory/memory.h +++ b/source/kernel/memory/memory.h @@ -5,7 +5,8 @@ #include "memoryinfo.h" #include "../prekernel/multiboot.h" #include "../terminal/kterm.h" -#include "../../lib/include/mem.h" +#include + #include "../bitmap.h" #define BLOCK_SIZE 4092 diff --git a/source/kernel/supervisorterminal/superVisorTerminal.h b/source/kernel/supervisorterminal/superVisorTerminal.h index ad3c39b..f68456c 100644 --- a/source/kernel/supervisorterminal/superVisorTerminal.h +++ b/source/kernel/supervisorterminal/superVisorTerminal.h @@ -4,8 +4,6 @@ #include "../drivers/pit/pit.h" #include "../drivers/ps-2/keyboard.h" #include "../memory/PhysicalMemoryManager.h" -extern "C" { - #include "../../lib/include/string.h" -} +#include extern "C" void startSuperVisorTerminal(); \ No newline at end of file diff --git a/source/kernel/terminal/kterm.h b/source/kernel/terminal/kterm.h index 7ac6d27..8cce182 100644 --- a/source/kernel/terminal/kterm.h +++ b/source/kernel/terminal/kterm.h @@ -5,10 +5,7 @@ #include "../drivers/vga/colors.h" #include "../drivers/io/io.h" -extern "C" { -#include "../../lib/include/string.h" -} - +#include "CoreLib/Memory.h" void kterm_init(); diff --git a/source/kernel/vfs/Path.cpp b/source/kernel/vfs/Path.cpp deleted file mode 100644 index 3489836..0000000 --- a/source/kernel/vfs/Path.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// -// Created by nigel on 19/02/23. -// -#include "Path.h" -#include "../memory/KernelHeap.h" -String::String(char* characters) -: chars(characters) -{ - -} - -char* String::str(){ - return chars; -} - -unsigned int String::length () -{ - int i = 0; - - while ( chars[i] != '\0'){ - i++; - } - - return i; -} - -// Returns a null character if size exceeds limits -char String::operator[] (size_t idx) -{ - if( idx > this->length()) - return '\0'; - - return chars[idx]; -} - -const char String::operator[](size_t idx) const { - return (const char) chars[idx]; -} - -StringView::StringView(String &string, unsigned int start, unsigned int end) -: String(string), begin(start), end(end) -{ - -} - -char* StringView::str(){ - char* str = (char*) malloc((this->length() * sizeof(char))+1); - - int index = 0; - for ( int i = begin; i < end ; i++){ - str[index] = chars[i]; - index++; - } - chars[index+1] ='\0'; - return str; -} - - -Path::Path(char *path) -: path(String(path)) -{ - -} - -Path::Path(String &path) -: path(path) -{ - -} - -StringView Path::getbasename() -{ - unsigned int path_length = path.length(); - int i = path_length; - while (path[i] != '/') - i--; - - return StringView(path,i +1, path_length); -} - -char* Path::str() { - return path.str(); -} \ No newline at end of file diff --git a/source/kernel/vfs/Path.h b/source/kernel/vfs/Path.h deleted file mode 100644 index 2d6de27..0000000 --- a/source/kernel/vfs/Path.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// Created by nigel on 19/02/23. -// -#pragma once -#include - -class String { -public: - String(char* characters); - String(String&) = default; - unsigned int length(); - - char* str (); - char operator[](size_t index) ; - const char operator[](size_t idx) const; - -protected: - char* chars; - - -}; - -class StringView : String { -public: - StringView(String& string, unsigned int start, unsigned int end ); - char* str (); -private: - unsigned int begin; - unsigned int end; -}; - -class Path{ -public: - Path(String& path); - Path(char* path); - - StringView getbasename(); - - char* str(); - -private: - String path; - -}; - - diff --git a/source/kernel/vfs/VFS.cpp b/source/kernel/vfs/VFS.cpp index 3f59fc2..9fe8d3f 100644 --- a/source/kernel/vfs/VFS.cpp +++ b/source/kernel/vfs/VFS.cpp @@ -4,7 +4,7 @@ #include "../drivers/ata/ataDevice.h" #include "../partitiontable/mbr/MasterBootRecord.h" #include "../memory/KernelHeap.h" -#include "Path.h" +#include "../../CoreLib/Memory.h" #include "../filesystem/FAT/DirectoryEntry.h" MOUNT_INFO mountInfo; @@ -389,6 +389,8 @@ char* FindNextEntryName (char* path ) void FileSystem::ResolvePath(Path &path) { + // See reference material (1) https://man7.org/linux/man-pages/man7/path_resolution.7.html + char* string_path = path.str(); void* cpy = string_path; @@ -410,9 +412,6 @@ void FileSystem::ResolvePath(Path &path) skip = strlen(entry_name); free(entry_name); - - - free(cpy); } \ No newline at end of file diff --git a/source/kernel/vfs/VFS.h b/source/kernel/vfs/VFS.h index 17b92c0..b294244 100644 --- a/source/kernel/vfs/VFS.h +++ b/source/kernel/vfs/VFS.h @@ -1,6 +1,6 @@ #pragma once #include -#include "Path.h" +#include "../../CoreLib/Path.h" #define FS_FILE 0 #define FS_DIRECTORY 1 diff --git a/source/lib/include/mem.h b/source/lib/include/mem.h deleted file mode 100644 index e5ff1dd..0000000 --- a/source/lib/include/mem.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -// NOTE: These should not be inline -inline void* memset (void* ptr, int value, size_t num) -{ - for( int i = 0; i < num; i++ ) - { - unsigned char* data = (unsigned char*)ptr+ i; - *data = (unsigned char)value; - } - return ptr; -} - - - -inline int memcmp( const void* ptr1, const void* ptr2, size_t num) -{ - const unsigned char * cs = (const unsigned char*) ptr1; - const unsigned char * ct = (const unsigned char*) ptr2; - - - for (int i = 0 ; i < num ; i++, cs++, ct++ ){ - if( *cs < *ct){ - return -1; - } else if( *cs > *ct){ - return 1; - } - } - - return 0; - -} \ No newline at end of file diff --git a/source/lib/include/string.c b/source/lib/include/string.c deleted file mode 100644 index 672d1a8..0000000 --- a/source/lib/include/string.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "string.h" - -size_t strlen(const char* str) { - size_t len = 0; - while(str[len]){ - len++; - } - return len; -} - -int strncmp ( const char* str1, const char* str2, size_t num ){ - for( int i = 0; i < num ; i++){ - - if( str1[i] < str2[i]){ - return -1; - } - - if( str1[i] > str2[i] ){ - return 1; - } - - - } - - return 0; -} diff --git a/source/lib/include/string.h b/source/lib/include/string.h deleted file mode 100644 index 7009681..0000000 --- a/source/lib/include/string.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include -size_t strlen(const char* str); -int strncmp ( const char* str1, const char* str2, size_t num ); \ No newline at end of file