From 4f7562afaee939467299efdb6b7fac159f6cbd27 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 15 Apr 2025 08:43:30 +0200 Subject: fix, kernel, boot, mod: Fixing issues regarding the boot flow and the kernel. Signed-off-by: Amlal El Mahrouss --- dev/user/user.json | 1 - 1 file changed, 1 deletion(-) (limited to 'dev/user') diff --git a/dev/user/user.json b/dev/user/user.json index 481280f8..9581d4d4 100644 --- a/dev/user/user.json +++ b/dev/user/user.json @@ -5,7 +5,6 @@ "sources_path": ["src/*.cc", "src/*.o"], "output_name": "user.sys", "compiler_flags": [ - "-fPIC", "-ffreestanding", "-shared", "-fno-rtti", -- cgit v1.2.3 From 56a97ff6398c03de22dabd7b93f54b1292f66b97 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 15 Apr 2025 16:54:06 +0200 Subject: dev, user: user.sys refactors. Signed-off-by: Amlal El Mahrouss --- dev/user/SystemCalls.h | 17 ++++++----- dev/user/src/GNUmakefile | 4 +-- dev/user/src/SystemCall+IO.asm | 50 -------------------------------- dev/user/src/SystemCalls+IO.asm | 52 ++++++++++++++++++++++++++++++++++ dev/user/src/SystemCalls.cc | 2 +- public/tools/diutil/src/CommandLine.cc | 7 ++--- 6 files changed, 68 insertions(+), 64 deletions(-) delete mode 100644 dev/user/src/SystemCall+IO.asm create mode 100644 dev/user/src/SystemCalls+IO.asm (limited to 'dev/user') diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index 97a49469..df91bc1e 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -322,14 +322,17 @@ IMPORT_C SInt32 SchedBreakPoint(Void); // @brief Filesystem API. // ------------------------------------------------------------------------------------------ // -IMPORT_C BOOL FsCopy(const char* path, const char* dst); -IMPORT_C BOOL FsMove(const char* path, const char* dst); +IMPORT_C BOOL FsCopy(const Char* path, const Char* dst); -IMPORT_C BOOL FsExists(const char* path); +IMPORT_C BOOL FsMove(const Char* path, const Char* dst); -IMPORT_C BOOL FsCreateDir(const char* path); -IMPORT_C BOOL FsCreateFile(const char* path); -IMPORT_C BOOL FsCreateAlias(const char* path, const char* from); +IMPORT_C BOOL FsExists(const Char* path); + +IMPORT_C BOOL FsCreateDir(const Char* path); + +IMPORT_C BOOL FsCreateFile(const Char* path); + +IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); // ------------------------------------------------------------------------------------------ // // @brief Format API. @@ -337,6 +340,6 @@ IMPORT_C BOOL FsCreateAlias(const char* path, const char* from); IMPORT_C Char* StrFmt(const Char* fmt, ...); -IMPORT_C UInt64 MathToNumber(const Char* in, const Char** endp, const SInt16 base); +IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); #endif // ifndef SCI_SCI_H diff --git a/dev/user/src/GNUmakefile b/dev/user/src/GNUmakefile index c0ddd5b4..09993d16 100644 --- a/dev/user/src/GNUmakefile +++ b/dev/user/src/GNUmakefile @@ -1,6 +1,6 @@ ################################################## # (c) Amlal El Mahrouss, all rights reserved. -# This is the bootloader makefile. +# This file is for user.sys's syscall stubs. ################################################## ASM=nasm @@ -13,4 +13,4 @@ error: .PHONY: sci_asm_io_x64 sci_asm_io_x64: - $(ASM) $(FLAGS) SystemCall+IO.asm -o SystemCall+IO.o + $(ASM) $(FLAGS) SystemCalls+IO.asm -o SystemCalls+IO.asm.o diff --git a/dev/user/src/SystemCall+IO.asm b/dev/user/src/SystemCall+IO.asm deleted file mode 100644 index 8f123ec8..00000000 --- a/dev/user/src/SystemCall+IO.asm +++ /dev/null @@ -1,50 +0,0 @@ -;; /* -;; * ======================================================== -;; * -;; * libsci -;; * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -;; * -;; * ======================================================== -;; */ - -[bits 64] - -section .text - -global sci_syscall_arg_1 -global sci_syscall_arg_2 -global sci_syscall_arg_3 -global sci_syscall_arg_4 - -sci_syscall_arg_1: - mov r8, rcx - syscall - ret - -sci_syscall_arg_2: - mov r8, rcx - mov r9, rdx - syscall - ret - -sci_syscall_arg_3: - mov rbx, r8 - - mov r8, rcx - mov r9, rdx - mov r10, rbx - - syscall - ret - -sci_syscall_arg_4: - mov rbx, r8 - mov rax, r9 - - mov r8, rcx - mov r9, rdx - mov r10, rbx - mov r11, rax - - syscall - ret diff --git a/dev/user/src/SystemCalls+IO.asm b/dev/user/src/SystemCalls+IO.asm new file mode 100644 index 00000000..58ea79e7 --- /dev/null +++ b/dev/user/src/SystemCalls+IO.asm @@ -0,0 +1,52 @@ +;; /* +;; * ======================================================== +;; * +;; * libsci +;; * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +;; * +;; * ======================================================== +;; */ + +[bits 64] + +;; @brief Syscall dispatch, also taking note the Microsoft's calling convention to translate it to NeKernel's ABI. + +section .text + +global sci_syscall_arg_1 +global sci_syscall_arg_2 +global sci_syscall_arg_3 +global sci_syscall_arg_4 + +sci_syscall_arg_1: + mov r8, rcx + syscall + ret + +sci_syscall_arg_2: + mov r8, rcx + mov r9, rdx + syscall + ret + +sci_syscall_arg_3: + mov rbx, r8 + + mov r8, rcx + mov r9, rdx + mov r10, rbx + + syscall + ret + +sci_syscall_arg_4: + mov rbx, r8 + mov rax, r9 + + mov r8, rcx + mov r9, rdx + mov r10, rbx + mov r11, rax + + syscall + ret diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc index 19f1fe42..2dd27dc0 100644 --- a/dev/user/src/SystemCalls.cc +++ b/dev/user/src/SystemCalls.cc @@ -27,7 +27,7 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si return dest; } -/// @brief Fill memory region with **value**. +/// @brief Fill memory region **dest** with **value**. IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { if (!len || diff --git a/public/tools/diutil/src/CommandLine.cc b/public/tools/diutil/src/CommandLine.cc index 61154e7a..9f11e778 100644 --- a/public/tools/diutil/src/CommandLine.cc +++ b/public/tools/diutil/src/CommandLine.cc @@ -11,14 +11,13 @@ static const Char kDiskName[kDIDiskNameLen] = "Disk"; static SInt32 kDiskSectorSz = 512; -static const SInt32 kDiskBlockCnt = 1; static SizeT kDiskSz = gib_cast(4); static const Char kOutDisk[kDIOutNameLen] = "disk.eimg"; /// @brief Filesystem tool entrypoint. int main(int argc, char** argv) { - for (SizeT arg = 0; arg < argc; ++arg) + for (SInt32 arg = 0; arg < argc; ++arg) { const Char* arg_s = argv[arg]; @@ -33,14 +32,14 @@ int main(int argc, char** argv) { if ((arg + 1) < argc) { - kDiskSz = MathToNumber(argv[arg + 1], nullptr, 10); + kDiskSz = StrMathToNumber(argv[arg + 1], nullptr, 10); } } else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-sector-size", MmStrLen("--disk-sector-size") == 0)) { if ((arg + 1) < argc) { - kDiskSectorSz = MathToNumber(argv[arg + 1], nullptr, 10); + kDiskSectorSz = StrMathToNumber(argv[arg + 1], nullptr, 10); } } else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-part-name", MmStrLen("--disk-part-name") == 0)) -- cgit v1.2.3 From 0b0f61ae48bbd8827d6088feab6cf58e7837bf92 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 15 Apr 2025 17:04:45 +0200 Subject: dev, user: drafting a system call map. Signed-off-by: Amlal El Mahrouss --- dev/user/Macros.h | 34 ++++++++++++++- dev/user/src/SystemCalls.cc | 48 +++++++++++++++++++++- .../frameworks/DiskImage.fwrk/headers/DiskImage.h | 1 - public/tools/diutil/diutil.json | 4 +- 4 files changed, 82 insertions(+), 5 deletions(-) (limited to 'dev/user') diff --git a/dev/user/Macros.h b/dev/user/Macros.h index 98beeb0d..556833ea 100644 --- a/dev/user/Macros.h +++ b/dev/user/Macros.h @@ -90,4 +90,36 @@ IMPORT_C void _rtl_assert(Bool expr, const Char* origin); #define ARRAY_SIZE(X) \ (((sizeof(X) / sizeof(*(X))) / \ (static_cast(!(sizeof(X) % sizeof(*(X))))))) -#endif \ No newline at end of file +#endif + +#ifndef KIB +#define KIB(X) (UInt64)((X) / 1024) +#endif + +#ifndef kib_cast +#define kib_cast(X) (UInt64)((X)*1024) +#endif + +#ifndef MIB +#define MIB(X) (UInt64)((UInt64)KIB(X) / 1024) +#endif + +#ifndef mib_cast +#define mib_cast(X) (UInt64)((UInt64)kib_cast(X) * 1024) +#endif + +#ifndef GIB +#define GIB(X) (UInt64)((UInt64)MIB(X) / 1024) +#endif + +#ifndef gib_cast +#define gib_cast(X) (UInt64)((UInt64)mib_cast(X) * 1024) +#endif + +#ifndef TIB +#define TIB(X) (UInt64)((UInt64)GIB(X) / 1024) +#endif + +#ifndef tib_cast +#define tib_cast(X) ((UInt64)gib_cast(X) * 1024) +#endif diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc index 2dd27dc0..7ad0fe6f 100644 --- a/dev/user/src/SystemCalls.cc +++ b/dev/user/src/SystemCalls.cc @@ -6,9 +6,14 @@ #include -/// @file libsci.cc +/// @file SystemCalls.cc /// @brief Source file for the memory functions of the libsci. +IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); +IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); +IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); +IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); + /// @brief Copy memory region. IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { @@ -27,6 +32,21 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si return dest; } +IMPORT_C SInt64 MmStrLen(const Char* in) +{ + if (!in) + return 0; + + SizeT len{0}; + + do + { + ++len; + } while (in[len] != '\0'); + + return len; +} + /// @brief Fill memory region **dest** with **value**. IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { @@ -43,3 +63,29 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt return dest; } + +IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) +{ + return sci_syscall_arg_3(1, reinterpret_cast(const_cast(path)), + reinterpret_cast(const_cast(drv_letter))); +} + +IMPORT_C Void IoCloseFile(_Input Ref desc) +{ + sci_syscall_arg_2(2, desc); +} + +IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) +{ + auto ret = (UInt64*)sci_syscall_arg_3(3, reinterpret_cast(desc), + reinterpret_cast(&off)); + + MUST_PASS((*ret) != ~0UL); + return *ret; +} + +IMPORT_C UInt64 IoTellFile(_Input Ref desc) +{ + auto ret = (UInt64*)sci_syscall_arg_2(4, reinterpret_cast(desc)); + return *ret; +} diff --git a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h index 1dc23c0a..c0566485 100644 --- a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h +++ b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h @@ -10,7 +10,6 @@ #pragma once #include -#include #define kDISectorSz (512) #define kDIMinDiskSz mib_cast(1) diff --git a/public/tools/diutil/diutil.json b/public/tools/diutil/diutil.json index 0805e69f..19b845c5 100644 --- a/public/tools/diutil/diutil.json +++ b/public/tools/diutil/diutil.json @@ -1,8 +1,8 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "../../../dev/kernel", "../../../dev/", "./"], - "sources_path": ["src/CommandLine.cc"], + "headers_path": ["./", "../../../dev/kernel", "../../../public/frameworks/", "../../../dev/", "./"], + "sources_path": ["src/CommandLine.cc", "../../../public/frameworks/DiskImage.fwrk/src/*.cc", "../../../dev/user/src/*.cc"], "output_name": "./dist/diutil", "cpp_macros": [ "kDUTILVersion=0x0100", -- cgit v1.2.3