From 609698e032f4d110004908d4eefcc77c43553258 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 12 May 2025 17:19:50 +0200 Subject: feat: sched, tooling: improving and laying foundations for the future milestones and objectives, such as: driver loading (ifs.sys, ddk.sys, user.sys), and better tooling for application development. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 15 +++++- dev/kernel/KernelKit/KernelTaskScheduler.h | 15 +++++- dev/kernel/KernelKit/UserProcessScheduler.h | 10 ---- dev/kernel/src/Network/IPCMsg.cc | 1 - tooling/fsck.hefs.cc | 2 - tooling/mk_app.py | 80 +++++++++++++++++++++++++++++ tooling/mk_fwrk.py | 31 ++++++----- 7 files changed, 124 insertions(+), 30 deletions(-) create mode 100755 tooling/mk_app.py diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index b3bc3e65..643c5479 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -9,9 +9,19 @@ #include #include +#define kSchedMinMicroTime (AffinityKind::kStandard) +#define kSchedInvalidPID (-1) +#define kSchedProcessLimitPerTeam (32U) +#define kSchedTeamCount (256U) + +#define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ +#define kSchedMaxStackSz mib_cast(8) /* maximum stack size */ + +#define kSchedNameLen (128U) + namespace Kernel { class USER_PROCESS; -class KERNEL_PROCESS; +class KERNEL_TASK; class UserProcessTeam; /***********************************************************************************/ @@ -117,7 +127,8 @@ struct PROCESS_IMAGE final { private: friend USER_PROCESS; - friend KERNEL_PROCESS; + friend KERNEL_TASK; + friend class UserProcessScheduler; ImagePtr fCode; diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index ca10003f..ed33ceba 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -12,4 +12,17 @@ #include #include -#include \ No newline at end of file +#include + +namespace Kernel { +struct KERNEL_TASK; + +struct KERNEL_TASK final { + Char Name[kSchedNameLen] = {"KERNEL_TASK"}; + ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemInvalid}; + HAL::StackFramePtr StackFrame{nullptr}; + UInt8* StackReserve{nullptr}; + SizeT StackSize{kSchedMaxStackSz}; + PROCESS_IMAGE Image{}; +}; +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 3ed3cbfe..42855e11 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -17,16 +17,6 @@ #include #include -#define kSchedMinMicroTime (AffinityKind::kStandard) -#define kSchedInvalidPID (-1) -#define kSchedProcessLimitPerTeam (32U) -#define kSchedTeamCount (256U) - -#define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ -#define kSchedMaxStackSz mib_cast(8) /* maximum stack size */ - -#define kSchedNameLen (128U) - //////////////////////////////////////////////////// // Last revision date is: Fri Mar 28 2025 // //////////////////////////////////////////////////// diff --git a/dev/kernel/src/Network/IPCMsg.cc b/dev/kernel/src/Network/IPCMsg.cc index e89e7c1b..cff19cfa 100644 --- a/dev/kernel/src/Network/IPCMsg.cc +++ b/dev/kernel/src/Network/IPCMsg.cc @@ -101,7 +101,6 @@ Bool ipc_construct_packet(_Output IPC_MSG** pckt_in) { Bool IPC_MSG::Pass(IPC_MSG* src, IPC_MSG* target) noexcept { if (src && target && (target != src)) { if (src->IpcMsgSz > target->IpcMsgSz) return No; - if (target->IpcMsgSz > src->IpcMsgSz) return No; rt_copy_memory(src->IpcData, target->IpcData, src->IpcMsgSz); diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc index 96cd36b6..ce586b13 100644 --- a/tooling/fsck.hefs.cc +++ b/tooling/fsck.hefs.cc @@ -15,7 +15,5 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - (void) argv; - return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tooling/mk_app.py b/tooling/mk_app.py new file mode 100755 index 00000000..ef2b64c9 --- /dev/null +++ b/tooling/mk_app.py @@ -0,0 +1,80 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import json +import sys + +def create_directory_structure(base_path, project_name): + # Define the directory structure + structure = { + project_name: { + "dist": { + ".keep": None + }, + "src": { + ".keep": None, + "CommandLine.cc": None, + }, + "vendor": { + ".keep": None + }, + ".keep": None, + f"{project_name}.json": {} + } + } + + def create_structure(path, structure): + for name, content in structure.items(): + current_path = os.path.join(path, name) + # Create directories or files based on the content type + if isinstance(content, dict) and current_path.endswith(".json") == False: + os.makedirs(current_path, exist_ok=True) + create_structure(current_path, content) + elif content is None: + # Create an empty file + with open(current_path, 'w') as f: + pass + + # Create the base directory + os.makedirs(base_path, exist_ok=True) + create_structure(base_path, structure) + + # Create the JSON file + proj_json_path = os.path.join(base_path, project_name, f"{project_name}.json") + + manifest = { + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": ["./", "../../../dev/kernel", "../../../public/frameworks/", "../../../dev/", "./"], + "sources_path": [ + + ], + "output_name": f"./dist/{project_name}", + "cpp_macros": [ + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", + "__NE_SDK__" + ] + } + + with open(proj_json_path, 'w') as json_file: + json.dump(manifest, json_file, indent=4) + + proj_cpp_path = os.path.join(base_path, project_name, f"src/CommandLine.cc") + + cpp_file = "#include \n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + + with open(proj_cpp_path, 'w') as cpp_file_io: + cpp_file_io.write(cpp_file) + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: mk_app.py ") + sys.exit(os.EX_CONFIG) + + base_path = os.getcwd() # Use the current working directory as the base path + create_directory_structure(base_path, sys.argv[1]) + + print("NeKernel Application created successfully.") diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py index 9bc132e6..89857347 100755 --- a/tooling/mk_fwrk.py +++ b/tooling/mk_fwrk.py @@ -5,7 +5,10 @@ import os import json import sys -def create_directory_structure(base_path, project_name): +""" + Create directory structure for the framework. +""" +def create_directory_structure(base_path_fwrk, project_file_name, project_name): # Define the directory structure structure = { project_name: { @@ -20,12 +23,12 @@ def create_directory_structure(base_path, project_name): ".keep": None }, ".keep": None, - f"{project_name}.json": {} + f"{project_file_name}.json": {} } } - def create_structure(path, structure): - for name, content in structure.items(): + def create_structure(path, structure_in): + for name, content in structure_in.items(): current_path = os.path.join(path, name) # Create directories or files based on the content type if isinstance(content, dict) and current_path.endswith(".json") == False: @@ -37,18 +40,18 @@ def create_directory_structure(base_path, project_name): pass # Create the base directory - os.makedirs(base_path, exist_ok=True) - create_structure(base_path, structure) + os.makedirs(base_path_fwrk, exist_ok=True) + create_structure(base_path_fwrk, structure) # Create the JSON file - proj_json_path = os.path.join(base_path, project_name, f"{project_name}.json") + proj_json_path = os.path.join(base_path_fwrk, project_name, f"{project_file_name}.json") manifest = { "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["./", "../../../dev/kernel", "../../../public/frameworks/", "../../../dev/", "./"], "sources_path": [ - + ], "output_name": f"./dist/{project_name}", "cpp_macros": [ @@ -58,13 +61,13 @@ def create_directory_structure(base_path, project_name): "__NE_SDK__" ] } - + with open(proj_json_path, 'w') as json_file: json.dump(manifest, json_file, indent=4) - proj_cpp_path = os.path.join(base_path, project_name, f"src/CommandLine.cc") + proj_cpp_path = os.path.join(base_path_fwrk, project_name, f"src/CommandLine.cc") - cpp_file = "#include \n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include \n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" with open(proj_cpp_path, 'w') as cpp_file_io: cpp_file_io.write(cpp_file) @@ -75,6 +78,6 @@ if __name__ == "__main__": sys.exit(os.EX_CONFIG) base_path = os.getcwd() # Use the current working directory as the base path - create_directory_structure(base_path, sys.argv[1]) - - print("NeKernel framework created successfully.") + create_directory_structure(base_path, sys.argv[1], sys.argv[1] + '.fwrk') + + print("NeKernel Framework created successfully.") -- cgit v1.2.3