summaryrefslogtreecommitdiffhomepage
path: root/Drivers/Hello
diff options
context:
space:
mode:
Diffstat (limited to 'Drivers/Hello')
-rw-r--r--Drivers/Hello/CheckStack.c18
-rw-r--r--Drivers/Hello/DriverRsrc.rsrc25
-rw-r--r--Drivers/Hello/Hello.c131
-rw-r--r--Drivers/Hello/compile_flags.txt3
-rw-r--r--Drivers/Hello/x86_64.mk52
5 files changed, 229 insertions, 0 deletions
diff --git a/Drivers/Hello/CheckStack.c b/Drivers/Hello/CheckStack.c
new file mode 100644
index 00000000..3ffbe3e2
--- /dev/null
+++ b/Drivers/Hello/CheckStack.c
@@ -0,0 +1,18 @@
+/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#include <DDK/KernelString.h>
+#include <DDK/KernelPrint.h>
+#include <DDK/KernelDev.h>
+
+///! @brief Raised when we get out of bounds. Abort here.
+void ___chkstk_ms(void)
+{
+ kernelPrintStr("Hello: KeStop needs to be raised...\r");
+
+ char* in = "__chkstk_ms on " __FILE__;
+ kernelCall("KeStop", 0, in, kernelStringLength(in));
+}
diff --git a/Drivers/Hello/DriverRsrc.rsrc b/Drivers/Hello/DriverRsrc.rsrc
new file mode 100644
index 00000000..12add0e2
--- /dev/null
+++ b/Drivers/Hello/DriverRsrc.rsrc
@@ -0,0 +1,25 @@
+1 ICON "../../Icons/app-logo.ico"
+
+1 VERSIONINFO
+FILEVERSION 1,0,0,0
+PRODUCTVERSION 1,0,0,0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "080904E4"
+ BEGIN
+ VALUE "CompanyName", "Zeta Electronics Corporation"
+ VALUE "FileDescription", "New OS Zeroconf driver."
+ VALUE "FileVersion", "1.00"
+ VALUE "InternalName", "Bonjour."
+ VALUE "LegalCopyright", "Copyright Zeta Electronics Corporation, 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/Drivers/Hello/Hello.c b/Drivers/Hello/Hello.c
new file mode 100644
index 00000000..ba3d9733
--- /dev/null
+++ b/Drivers/Hello/Hello.c
@@ -0,0 +1,131 @@
+/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#include <DDK/KernelString.h>
+#include <DDK/KernelPrint.h>
+#include <DDK/KernelDev.h>
+
+struct HelloMasterConfigHeader;
+struct HelloMasterConfigHeaderInput;
+
+struct HelloMasterConfigHeaderInput
+{
+ size_t fSizeOfOutput;
+ struct HelloMasterConfigHeader* fOutput;
+};
+
+/// @file Hello.c
+/// @brief Zero configuration protocol, a much more better protocol for zero configuration.
+
+#define cHMCHMaxDataLength (1024)
+
+typedef struct HelloMasterConfigHeader
+{
+ int64_t fMagic;
+ int64_t fVersion;
+ int64_t fSourceAddress;
+ size_t fDataLength;
+ wchar_t fUTF16Data[cHMCHMaxDataLength];
+} __attribute__((packed)) HelloMasterConfigHeader;
+
+#define cHMCHDeviceLen 255
+
+static kernelDeviceRef cDev = nil;
+static char* cDeviceUUID = nil; // 3ed40738-c7d6-4b59-afdf-3c104b05fbf
+static HelloMasterConfigHeader* cHeader = nil;
+
+/// @brief Link to master device to attribute DHCP lease.
+static void __hello_link_device(void* a0)
+{
+ kernelPrintStr("Hello: turning up...\r");
+
+ if (!cDev)
+ {
+ // open raw network device.
+ cDev = kernelOpenDevice("RAWNET:\\");
+ }
+
+ cDev->write("+LINK", kernelStringLength("+LINK"));
+ cDev->wait();
+
+ cDev->write((void*)cDeviceUUID, kernelStringLength(cDeviceUUID));
+ cDev->wait();
+
+ if (cHeader)
+ {
+ kernelFree(cHeader);
+ cHeader = nil;
+ }
+
+ cHeader = cDev->read(nil, sizeof(HelloMasterConfigHeader));
+}
+
+static void __hello_get_hmch(void* a0)
+{
+ if (a0 == nil)
+ return;
+
+ kernelPrintStr("Hello: returning header...\r");
+
+ struct HelloMasterConfigHeaderInput* in = a0;
+ in->fOutput = cHeader;
+ in->fSizeOfOutput = sizeof(in->fOutput);
+}
+
+static void __hello_unlink_device(void* a0)
+{
+ kernelPrintStr("Hello: shutting down...\r");
+
+ if (cDev)
+ {
+ cDev->write("+UNLINK", kernelStringLength("+UNLINK"));
+ cDev->wait();
+
+ /// here is my uuid and my config header. Please disconnect me.
+ cDev->write((void*)cDeviceUUID, kernelStringLength(cDeviceUUID));
+ cDev->write(cHeader, sizeof(cHeader));
+
+ cDev->wait();
+
+ kernelCloseDevice(cDev);
+ cDev = nil;
+ }
+
+ if (cDeviceUUID)
+ {
+ kernelFree((void*)cDeviceUUID);
+ cDeviceUUID = nil;
+ }
+
+ cDev = nil;
+}
+
+int __at_enter(void)
+{
+ kernelPrintStr("Hello: starting up Helloconf...\r");
+
+ cDeviceUUID = kernelAlloc(sizeof(char) * cHMCHDeviceLen);
+
+ kernelAddSyscall(0, __hello_link_device);
+ kernelAddSyscall(1, __hello_unlink_device);
+ kernelAddSyscall(2, __hello_get_hmch);
+
+ return 0;
+}
+
+int __at_exit(void)
+{
+ kernelPrintStr("Hello: starting up Helloconf...\r");
+
+ // first unlink.
+ __hello_unlink_device(nil);
+
+ // then unregister syscalls.
+ kernelAddSyscall(0, nil);
+ kernelAddSyscall(1, nil);
+
+ return 0;
+}
diff --git a/Drivers/Hello/compile_flags.txt b/Drivers/Hello/compile_flags.txt
new file mode 100644
index 00000000..10bdb71e
--- /dev/null
+++ b/Drivers/Hello/compile_flags.txt
@@ -0,0 +1,3 @@
+-I../../
+-I../../Kernel
+-std=c++20
diff --git a/Drivers/Hello/x86_64.mk b/Drivers/Hello/x86_64.mk
new file mode 100644
index 00000000..564fe970
--- /dev/null
+++ b/Drivers/Hello/x86_64.mk
@@ -0,0 +1,52 @@
+##################################################
+# (C) Zeta Electronics Corporation, 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
+
+LD_FLAGS=-e __at_enter --subsystem=17
+
+OBJ=*.o
+
+
+REM=rm
+REM_FLAG=-f
+
+FLAG_ASM=-f win64
+FLAG_GNU=-fshort-wchar -fno-rtti -fno-exceptions -D__DDK_AMD64__ -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 Hello.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 ../../DDK/*.cc) $(wildcard ../../DDK/*.c) $(wildcard ../../DDK/*.S)
+
+.PHONY: clean
+clean:
+ $(REM) $(REM_FLAG) $(OBJ) Hello.exe
+
+.PHONY: help
+help:
+ @echo "=== HELP ==="
+ @echo "clean: Clean driver."
+ @echo "compile-amd64: Build driver."