summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-20 23:13:11 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-20 23:13:11 +0200
commit155971914073bedfa585a0be4d14a40bd23e3b8f (patch)
treef39af19dc2f1b7f33cac33eff07001b2e791f7db
parent7013c094668be2204b1245496236f0cf6afa07c2 (diff)
MHR-9: Driver toolkit, initial commit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/DriverKit/KernelDev.c31
-rw-r--r--Private/DriverKit/KernelDev.h28
-rw-r--r--Private/DriverKit/KernelDispatchCall.s13
-rw-r--r--Private/DriverKit/KernelPrint.c23
-rw-r--r--Private/DriverKit/KernelPrint.h33
-rw-r--r--Private/DriverKit/KernelStd.c24
-rw-r--r--Private/DriverKit/KernelStd.h22
-rw-r--r--Private/DriverKit/KernelString.c19
-rw-r--r--Private/DriverKit/KernelString.h13
-rw-r--r--Private/Drivers/Bonjour/DriverRsrc.rsrc25
-rw-r--r--Private/Drivers/Bonjour/SampleDriver.c18
-rw-r--r--Private/Drivers/Bonjour/makefile62
-rw-r--r--Private/Drivers/SampleDriver/SampleDriver.c5
-rw-r--r--Private/Drivers/SampleDriver/makefile2
-rw-r--r--Private/NewKit/Application.hxx10
-rw-r--r--Private/Root/Boot/Icons/bonjour-logo.icobin0 -> 87830 bytes
-rw-r--r--Private/Root/Boot/Icons/boot-logo.icobin3638 -> 87830 bytes
-rw-r--r--Private/Root/Boot/Icons/driver-logo.icobin3638 -> 87830 bytes
-rw-r--r--Private/Root/Boot/Icons/kernel-logo.icobin3638 -> 87830 bytes
-rw-r--r--Private/Root/Users/Shared/.gitkeep0
-rw-r--r--Private/Root/Users/User.script3
-rw-r--r--Public/Developer/SystemLib/Sources/App.c4
22 files changed, 285 insertions, 50 deletions
diff --git a/Private/DriverKit/KernelDev.c b/Private/DriverKit/KernelDev.c
new file mode 100644
index 00000000..e8c041af
--- /dev/null
+++ b/Private/DriverKit/KernelDev.c
@@ -0,0 +1,31 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Text I/O.
+
+------------------------------------------- */
+
+#include <DriverKit/KernelDev.h>
+
+/// @brief Open a new binary device from path.
+DK_EXTERN kernelDeviceRef kernelOpenBinaryDevice(const char* devicePath) {
+ if (!devicePath) return NIL;
+
+ return kernelCall("OpenBinaryDevice", 1, devicePath);
+}
+
+/// @brief Open a new character device from path.
+DK_EXTERN kernelDeviceRef kernelOpenCharDevice(const char* devicePath) {
+ if (!devicePath) return NIL;
+
+ return kernelCall("OpenCharDevice", 1, devicePath);
+}
+
+/// @brief Close any device.
+/// @param device valid device.
+DK_EXTERN void kernelCloseDevice(kernelDeviceRef device) {
+ if (!device) return;
+
+ kernelCall("CloseDevice", 1, device);
+}
diff --git a/Private/DriverKit/KernelDev.h b/Private/DriverKit/KernelDev.h
new file mode 100644
index 00000000..daa60a7c
--- /dev/null
+++ b/Private/DriverKit/KernelDev.h
@@ -0,0 +1,28 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Devices.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <DriverKit/KernelStd.h>
+
+typedef struct _kernelDevice {
+ int32_t(*read)(); // read from device.
+ int32_t(*write)(); // write to device.
+ struct _kernelDevice* (*open)(const char* path); // open device.
+ void (*close)(struct _kernelDevice* dev); // close device.
+} kernelDevice,* kernelDeviceRef;
+
+/// @brief Open a new binary device from path.
+DK_EXTERN kernelDeviceRef kernelOpenBinaryDevice(const char* devicePath);
+
+/// @brief Open a new character device from path.
+DK_EXTERN kernelDeviceRef kernelOpenCharDevice(const char* devicePath);
+
+/// @brief Close any device.
+/// @param device valid device.
+DK_EXTERN void kernelCloseDevice(kernelDeviceRef device);
diff --git a/Private/DriverKit/KernelDispatchCall.s b/Private/DriverKit/KernelDispatchCall.s
new file mode 100644
index 00000000..2919f6ec
--- /dev/null
+++ b/Private/DriverKit/KernelDispatchCall.s
@@ -0,0 +1,13 @@
+.globl __kernelDispatchCall
+
+.section .text
+
+#ifdef __x86_64__
+
+/* Really simple function, takes our va-list,
+ and brings it to the trap handler in the kernel. */
+__kernelDispatchCall:
+ int $0x33
+ ret
+
+#endif
diff --git a/Private/DriverKit/KernelPrint.c b/Private/DriverKit/KernelPrint.c
index 32e20f4f..5ca09ccf 100644
--- a/Private/DriverKit/KernelPrint.c
+++ b/Private/DriverKit/KernelPrint.c
@@ -6,14 +6,23 @@
------------------------------------------- */
-#include "DriverKit/KernelPrint.h"
+#include <DriverKit/KernelPrint.h>
-#ifdef __x86_64__
-static void kernelPrintCharAMD64(const char ch) {
- __asm__ volatile("outb %%al, %1" : : "a"(ch), "Nd"(0x3F8) : "memory");
+DK_EXTERN void kernelPrintChar(const char ch) {
+ kernelCall("WriteCharacter", 1, ch);
}
-#endif // if __x86_64__
-DK_EXTERN void kernelPrintChar(const char ch) {
- kernelPrintChar(ch);
+/// @brief print string to UART.
+/// @param message UART to transmit.
+DK_EXTERN void kernelPrintStr(const char* message) {
+ if (!message) return;
+ if (*message == 0) return;
+
+ size_t index = 0;
+ size_t len = kernelStringLength(message);
+
+ while (index < len) {
+ kernelPrintChar(message[index]);
+ ++index;
+ }
}
diff --git a/Private/DriverKit/KernelPrint.h b/Private/DriverKit/KernelPrint.h
index 7e25e304..36e55442 100644
--- a/Private/DriverKit/KernelPrint.h
+++ b/Private/DriverKit/KernelPrint.h
@@ -8,38 +8,11 @@
#pragma once
-#if defined(__cplusplus)
-#define DK_EXTERN extern "C"
-#else
-#define DK_EXTERN extern
-#endif // defined(__cplusplus)
-
-#include <stdint.h>
-#include <stddef.h>
+#include <DriverKit/KernelString.h>
/// @brief print character into UART.
DK_EXTERN void kernelPrintChar(const char ch);
-static inline size_t kernelStringLength(const char* str) {
- size_t index = 0;
-
- while (str[index] != 0) {
- ++index;
- }
-
- return index;
-}
-
/// @brief print string to UART.
-static inline void kernelPrintStr(const char* message) {
- if (!message) return;
- if (*message == 0) return;
-
- size_t index = 0;
- size_t len = kernelStringLength(message);
-
- while (index < len) {
- kernelPrintChar(message[index]);
- ++index;
- }
-}
+/// @param message UART to transmit.
+DK_EXTERN void kernelPrintStr(const char* message);
diff --git a/Private/DriverKit/KernelStd.c b/Private/DriverKit/KernelStd.c
new file mode 100644
index 00000000..494ac0bc
--- /dev/null
+++ b/Private/DriverKit/KernelStd.c
@@ -0,0 +1,24 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Definitions.
+
+------------------------------------------- */
+
+#include <DriverKit/KernelStd.h>
+#include <stdarg.h>
+
+DK_EXTERN __attribute__((naked)) void __kernelDispatchCall(int32_t cnt, ...);
+
+DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, ...) {
+ if (!kernelRpcName || cnt == 0) return NIL;
+
+ va_list arg;
+ va_start(arg, cnt);
+
+ __kernelDispatchCall(cnt, arg);
+
+ va_end(arg);
+
+}
diff --git a/Private/DriverKit/KernelStd.h b/Private/DriverKit/KernelStd.h
new file mode 100644
index 00000000..3344630e
--- /dev/null
+++ b/Private/DriverKit/KernelStd.h
@@ -0,0 +1,22 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Definitions.
+
+------------------------------------------- */
+
+#pragma once
+
+#if defined(__cplusplus)
+#define DK_EXTERN extern "C"
+#define NIL nullptr
+#else
+#define DK_EXTERN extern
+#define NIL NULL
+#endif // defined(__cplusplus)
+
+#include <stdint.h>
+#include <stddef.h>
+
+DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, ...);
diff --git a/Private/DriverKit/KernelString.c b/Private/DriverKit/KernelString.c
new file mode 100644
index 00000000..7c129dd4
--- /dev/null
+++ b/Private/DriverKit/KernelString.c
@@ -0,0 +1,19 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Strings.
+
+------------------------------------------- */
+
+#include <DriverKit/KernelString.h>
+
+DK_EXTERN size_t kernelStringLength(const char* str) {
+ size_t index = 0;
+
+ while (str[index] != 0) {
+ ++index;
+ }
+
+ return index;
+}
diff --git a/Private/DriverKit/KernelString.h b/Private/DriverKit/KernelString.h
new file mode 100644
index 00000000..d1b8ac93
--- /dev/null
+++ b/Private/DriverKit/KernelString.h
@@ -0,0 +1,13 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Strings.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <DriverKit/KernelStd.h>
+
+DK_EXTERN size_t kernelStringLength(const char* str);
diff --git a/Private/Drivers/Bonjour/DriverRsrc.rsrc b/Private/Drivers/Bonjour/DriverRsrc.rsrc
new file mode 100644
index 00000000..62347b80
--- /dev/null
+++ b/Private/Drivers/Bonjour/DriverRsrc.rsrc
@@ -0,0 +1,25 @@
+1 ICON "../../Root/Boot/Icons/bonjour-logo.ico"
+
+1 VERSIONINFO
+FILEVERSION 1,0,0,0
+PRODUCTVERSION 1,0,0,0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "080904E4"
+ BEGIN
+ VALUE "CompanyName", "Mahrouss-Logic"
+ VALUE "FileDescription", "NewOS Bonjour driver."
+ VALUE "FileVersion", "1.00"
+ VALUE "InternalName", "Bonjour."
+ VALUE "LegalCopyright", "Copyright Mahrouss-Logic, all rights reserved."
+ VALUE "OriginalFilename", "Bonjour.exe"
+ VALUE "ProductName", "Bonjour."
+ VALUE "ProductVersion", "1.00"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x809, 1252
+ END
+END
diff --git a/Private/Drivers/Bonjour/SampleDriver.c b/Private/Drivers/Bonjour/SampleDriver.c
new file mode 100644
index 00000000..8289fcbc
--- /dev/null
+++ b/Private/Drivers/Bonjour/SampleDriver.c
@@ -0,0 +1,18 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <DriverKit/KernelString.h>
+#include <DriverKit/KernelPrint.h>
+
+int __ImageStart(void) {
+ kernelPrintStr("SampleDriver: Starting up...\r\n");
+ return 0;
+}
+
+int __ImageEnd(void) {
+ kernelPrintStr("SampleDriver: Shutting down...\r\n");
+ return 0;
+}
diff --git a/Private/Drivers/Bonjour/makefile b/Private/Drivers/Bonjour/makefile
new file mode 100644
index 00000000..e1cdba67
--- /dev/null
+++ b/Private/Drivers/Bonjour/makefile
@@ -0,0 +1,62 @@
+##################################################
+# (C) Mahrouss Logic, all rights reserved.
+# This is the sample driver makefile.
+##################################################
+
+CC_GNU=x86_64-w64-mingw32-gcc
+LD_GNU=x86_64-w64-mingw32-ld
+
+WINDRES=x86_64-w64-mingw32-windres
+
+ADD_FILE=touch
+COPY=cp
+HTTP_GET=wget
+
+ifeq ($(shell uname), Windows_NT)
+EMU=qemu-system-x86_64w
+else
+EMU=qemu-system-x86_64
+endif
+
+IMG=epm.img
+IMG_2=epm-slave.img
+EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int -hdd epm-slave.img
+
+LD_FLAGS=-e __ImageStart --subsystem=17
+
+OBJ=$(wildcard *.o) $(wildcard HEL/AMD64/*.obj)
+
+
+REM=rm
+REM_FLAG=-f
+
+FLAG_ASM=-f win64
+FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -std=c17 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./
+
+.PHONY: invalid-recipe
+invalid-recipe:
+ @echo "invalid-recipe: Use make all instead."
+
+.PHONY: all
+all: compile-amd64
+ $(LD_GNU) $(OBJ) $(LD_FLAGS) -o Bonjour.exe
+ cp Bonjour.exe ../../Root/Boot/Bonjour.exe
+
+ifneq ($(DEBUG_SUPPORT), )
+DEBUG = -D__DEBUG__
+endif
+
+.PHONY: compile-amd64
+compile-amd64:
+ $(WINDRES) DriverRsrc.rsrc -O coff -o DriverRsrc.o
+ $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard *.c) $(wildcard ../../DriverKit/*.c) $(wildcard ../../DriverKit/*.s)
+
+.PHONY: clean
+clean:
+ $(REM) $(REM_FLAG) $(OBJ) Bonjour.exe
+
+.PHONY: help
+help:
+ @echo "=== HELP ==="
+ @echo "clean: Clean driver."
+ @echo "compile-amd64: Build driver."
diff --git a/Private/Drivers/SampleDriver/SampleDriver.c b/Private/Drivers/SampleDriver/SampleDriver.c
index 04d40516..8289fcbc 100644
--- a/Private/Drivers/SampleDriver/SampleDriver.c
+++ b/Private/Drivers/SampleDriver/SampleDriver.c
@@ -4,14 +4,15 @@
------------------------------------------- */
+#include <DriverKit/KernelString.h>
#include <DriverKit/KernelPrint.h>
int __ImageStart(void) {
- kernelPrintStr("SampleDriver: Starting up.\n");
+ kernelPrintStr("SampleDriver: Starting up...\r\n");
return 0;
}
int __ImageEnd(void) {
- kernelPrintStr("SampleDriver: Shutting down.\n");
+ kernelPrintStr("SampleDriver: Shutting down...\r\n");
return 0;
}
diff --git a/Private/Drivers/SampleDriver/makefile b/Private/Drivers/SampleDriver/makefile
index 19e88f8f..637be18d 100644
--- a/Private/Drivers/SampleDriver/makefile
+++ b/Private/Drivers/SampleDriver/makefile
@@ -49,7 +49,7 @@ endif
.PHONY: compile-amd64
compile-amd64:
$(WINDRES) DriverRsrc.rsrc -O coff -o DriverRsrc.o
- $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard *.c) $(wildcard ../../DriverKit/*.c)
+ $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard *.c) $(wildcard ../../DriverKit/*.c) $(wildcard ../../DriverKit/*.s)
.PHONY: clean
clean:
diff --git a/Private/NewKit/Application.hxx b/Private/NewKit/Application.hxx
index f19dbd97..15ffd073 100644
--- a/Private/NewKit/Application.hxx
+++ b/Private/NewKit/Application.hxx
@@ -7,7 +7,7 @@
#pragma once
///
-/// @brief Main application object, given by the OS to interact with the OS.
+/// @brief Application object, given by the OS to the process. interact with the OS.
/// @file Application.hxx
/// @author Amlal EL Mahrouss
///
@@ -17,14 +17,14 @@
/// \brief Application Interface.
/// \author Amlal El Mahrouss
-typedef struct Application final {
+typedef struct _Application final {
/// @brief Releases the object exit the process on main object.
- NewOS::Void(*Release)(struct Application* Self, NewOS::Int32 ExitCode);
+ NewOS::Void(*Release)(struct _Application* Self, NewOS::Int32 ExitCode);
/// @brief Invoke a function from the application object.
- NewOS::IntPtr(*Invoke)(struct Application* Self, NewOS::Int32 Sel, ...);
+ NewOS::IntPtr(*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...);
/// @brief Query a new application object from a GUID.
/// @note this doesn't query a process, it query a registered object withtin that app.
- NewOS::Void(*Query)(struct Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf);
+ NewOS::Void(*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf);
} Application, *ApplicationRef;
#define app_cast reinterpret_cast<ApplicationRef>
diff --git a/Private/Root/Boot/Icons/bonjour-logo.ico b/Private/Root/Boot/Icons/bonjour-logo.ico
new file mode 100644
index 00000000..5424b46f
--- /dev/null
+++ b/Private/Root/Boot/Icons/bonjour-logo.ico
Binary files differ
diff --git a/Private/Root/Boot/Icons/boot-logo.ico b/Private/Root/Boot/Icons/boot-logo.ico
index 9be8328f..3a0258b8 100644
--- a/Private/Root/Boot/Icons/boot-logo.ico
+++ b/Private/Root/Boot/Icons/boot-logo.ico
Binary files differ
diff --git a/Private/Root/Boot/Icons/driver-logo.ico b/Private/Root/Boot/Icons/driver-logo.ico
index 9394ab64..5cf8e397 100644
--- a/Private/Root/Boot/Icons/driver-logo.ico
+++ b/Private/Root/Boot/Icons/driver-logo.ico
Binary files differ
diff --git a/Private/Root/Boot/Icons/kernel-logo.ico b/Private/Root/Boot/Icons/kernel-logo.ico
index 0512b65e..0866aa2d 100644
--- a/Private/Root/Boot/Icons/kernel-logo.ico
+++ b/Private/Root/Boot/Icons/kernel-logo.ico
Binary files differ
diff --git a/Private/Root/Users/Shared/.gitkeep b/Private/Root/Users/Shared/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/Private/Root/Users/Shared/.gitkeep
diff --git a/Private/Root/Users/User.script b/Private/Root/Users/User.script
deleted file mode 100644
index 09cecb8b..00000000
--- a/Private/Root/Users/User.script
+++ /dev/null
@@ -1,3 +0,0 @@
-# User script
-
-Guest: true;
diff --git a/Public/Developer/SystemLib/Sources/App.c b/Public/Developer/SystemLib/Sources/App.c
index 9d390795..36e53c7e 100644
--- a/Public/Developer/SystemLib/Sources/App.c
+++ b/Public/Developer/SystemLib/Sources/App.c
@@ -11,7 +11,7 @@ ApplicationRef kSharedApplication = NullPtr;
/// @brief Gets the app arguments count.
/// @param void no arguments.
-/// @return
+/// @return The number of arguments given to the application.
CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) {
CA_MUST_PASS(kSharedApplication);
@@ -23,7 +23,7 @@ CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) {
/// @return
CA_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) {
CA_MUST_PASS(kSharedApplication);
-
+
return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication,
kCallGetArgsPtr);
}