summaryrefslogtreecommitdiffhomepage
path: root/dev/ddk/DDKKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-03-29 05:03:14 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-03-29 05:06:15 +0100
commitc4870d08fa4bfb2613bf22a0b7cf306b388f58a4 (patch)
treec8b5023a5ab4fe257f7687573812053c6e5273fb /dev/ddk/DDKKit
parenta8bd5ed975031d63eb448d2ed4f160cf7159c3bc (diff)
ddk: refactor: reorganize kit into a standard kernel kit.
sched: refactor: refactor scheduler file names, for future additions. xcoff: refactor: document and improve XCOFF for NeFS (regarding Ne's FW) codemgr: refactor: make a difference between kernel and user processes. refactor: document project overall. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/ddk/DDKKit')
-rw-r--r--dev/ddk/DDKKit/ddk.h112
-rw-r--r--dev/ddk/DDKKit/dev.h35
-rw-r--r--dev/ddk/DDKKit/io.h18
-rw-r--r--dev/ddk/DDKKit/str.h17
4 files changed, 182 insertions, 0 deletions
diff --git a/dev/ddk/DDKKit/ddk.h b/dev/ddk/DDKKit/ddk.h
new file mode 100644
index 00000000..f6f8d48e
--- /dev/null
+++ b/dev/ddk/DDKKit/ddk.h
@@ -0,0 +1,112 @@
+/* -------------------------------------------
+
+ Copyright Amlal EL Mahrouss.
+
+ FILE: ddk.h
+ PURPOSE: DDK Driver model base header.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <stdint.h>
+#include <stddef.h>
+
+#if defined(__cplusplus)
+#define BOOL bool
+#define YES true
+#define NO false
+#define DDK_EXTERN extern "C" __declspec(dllexport)
+#define nil nullptr
+#undef NULL
+#define NULL 0
+#define DDK_FINAL final
+#else
+#define BOOL char
+#define YES 1
+#define NO 0
+#define DDK_EXTERN extern __declspec(dllexport)
+#define nil ((void*)0)
+#undef NULL
+#define NULL ((void*)0)
+#define DDK_FINAL
+#endif // defined(__cplusplus)
+
+#ifndef __DDK__
+#undef DDK_EXTERN
+#if defined(__cplusplus)
+#define DDK_EXTERN extern "C" __declspec(dllimport)
+#else
+#define DDK_EXTERN __declspec(dllimport)
+#endif
+#endif
+
+#define ATTRIBUTE(X) __attribute__((X))
+
+#ifndef __NEOSKRNL__
+#error !!! Do not include header in EL0/Ring 3 mode !!!
+#endif // __MINOSKRNL__
+
+struct DDK_STATUS_STRUCT;
+struct DDK_OBJECT_MANIFEST;
+
+/// \brief Object handle manifest.
+struct DDK_OBJECT_MANIFEST DDK_FINAL
+{
+ char* p_name;
+ int32_t p_kind;
+ void* p_object;
+};
+
+/// \brief DDK status ping structure.
+struct DDK_STATUS_STRUCT DDK_FINAL
+{
+ int32_t s_action_id;
+ int32_t s_issuer_id;
+ int32_t s_group_id;
+ void* s_object;
+};
+
+/// @brief Call Kernel procedure.
+/// @param name the procedure name.
+/// @param cnt number of elements in **dat**
+/// @param dat data argument pointer.
+/// @param sz sz of whole data argument pointer.
+/// @return result of call
+DDK_EXTERN void* ke_call(const char* name, int32_t cnt, void* dat, size_t sz);
+
+/// @brief add a system call.
+/// @param slot system call slot id.
+/// @param slotFn, syscall slot.
+DDK_EXTERN void ke_add_syscall(const int32_t slot, void (*slotFn)(void* a0));
+
+/// @brief Allocates an heap ptr.
+/// @param sz size of the allocated struct/type.
+/// @return the pointer allocated or **nil**.
+DDK_EXTERN void* kalloc(size_t sz);
+
+/// @brief Frees an heap ptr.
+/// @param pointer kernel pointer to free.
+DDK_EXTERN void kfree(void* the_ptr);
+
+/// @brief Gets a Kernel object.
+/// @param slot object id (can be 0)
+/// @param name the property's name.
+/// @return DDK_OBJECT_MANIFEST.
+DDK_EXTERN struct DDK_OBJECT_MANIFEST* ke_get_obj(const int slot, const char* name);
+
+/// @brief Set a Kernel object.
+/// @param slot object id (can be 0)
+/// @param name the property's name.
+/// @param ddk_pr pointer to a object's DDK_OBJECT_MANIFEST.
+/// @return returned object.
+DDK_EXTERN void* ke_set_obj(const int32_t slot, const struct DDK_OBJECT_MANIFEST* ddk_pr);
+
+/// @brief The highest API version of the DDK.
+DDK_EXTERN int32_t kApiVersionHighest;
+
+/// @brief The lowest API version of the DDK.
+DDK_EXTERN int32_t kApiVersionLowest;
+
+/// @brief API version in BCD.
+DDK_EXTERN int32_t kApiVersion;
diff --git a/dev/ddk/DDKKit/dev.h b/dev/ddk/DDKKit/dev.h
new file mode 100644
index 00000000..929aafa4
--- /dev/null
+++ b/dev/ddk/DDKKit/dev.h
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright Amlal EL Mahrouss.
+
+ File: dev.h
+ Purpose: DDK device support.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <DDKKit/ddk.h>
+
+struct _DDK_DEVICE;
+
+#define DDK_DEVICE_NAME_LEN (255)
+
+/// @brief Kernel Device driver.
+typedef struct _DDK_DEVICE DDK_FINAL
+{
+ char d_name[DDK_DEVICE_NAME_LEN]; // the device name. Could be /./DEVICE_NAME/
+ void* (*d_read)(void* arg, int len); // read from device.
+ void (*d_write)(void* arg, int len);
+ void (*d_wait)(void); // write to device.
+ struct _DDK_DEVICE* (*d_open)(const char* path); // open device.
+ void (*d_close)(struct _DDK_DEVICE* dev); // close device.
+} DDK_DEVICE, *DDK_DEVICE_PTR;
+
+/// @brief Open a new device from path.
+/// @param path the device's path.
+DDK_EXTERN DDK_DEVICE_PTR open(const char* path);
+
+/// @brief Close any device.
+/// @param device valid device.
+DDK_EXTERN BOOL close(DDK_DEVICE_PTR device);
diff --git a/dev/ddk/DDKKit/io.h b/dev/ddk/DDKKit/io.h
new file mode 100644
index 00000000..a5ab93f1
--- /dev/null
+++ b/dev/ddk/DDKKit/io.h
@@ -0,0 +1,18 @@
+/* -------------------------------------------
+
+ Copyright Amlal EL Mahrouss.
+
+ Purpose: DDK Text I/O.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <DDKKit/str.h>
+
+/// @brief print character into UART.
+DDK_EXTERN void kputc(const char ch);
+
+/// @brief print string to UART.
+/// @param message string to transmit to UART.
+DDK_EXTERN void kprint(const char* message);
diff --git a/dev/ddk/DDKKit/str.h b/dev/ddk/DDKKit/str.h
new file mode 100644
index 00000000..49aeb45f
--- /dev/null
+++ b/dev/ddk/DDKKit/str.h
@@ -0,0 +1,17 @@
+/* -------------------------------------------
+
+ Copyright Amlal EL Mahrouss.
+
+ Purpose: DDK Strings.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <DDKKit/ddk.h>
+
+/// @brief DDK equivalent of POSIX's string.h
+/// @file str.h
+
+DDK_EXTERN size_t kstrlen(const char* in);
+DDK_EXTERN int kstrncpy(char* dst, const char* src, size_t len);