diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-23 21:06:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-23 21:06:27 -0500 |
| commit | 23040fad647634c08697451fc22ee2ca999629c8 (patch) | |
| tree | 72888f88c7728c82f3f6df1f4f70591de15eab36 /src/libDDK/DriverKit | |
| parent | e5cc7351f0577b54c528fb827a7c7e6306c3e843 (diff) | |
| parent | 83d870e58457a1d335a1d9b9966a6a1887cc297b (diff) | |
Merge pull request #81 from nekernel-org/dev
feat! breaking changes on kernel sources.
Diffstat (limited to 'src/libDDK/DriverKit')
| -rw-r--r-- | src/libDDK/DriverKit/ddk.h | 76 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/dev.h | 36 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/dki/contract.h | 34 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/io.h | 18 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/macros.h | 48 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/net.h | 16 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/str.h | 17 |
7 files changed, 245 insertions, 0 deletions
diff --git a/src/libDDK/DriverKit/ddk.h b/src/libDDK/DriverKit/ddk.h new file mode 100644 index 00000000..45f7d356 --- /dev/null +++ b/src/libDDK/DriverKit/ddk.h @@ -0,0 +1,76 @@ +/* ======================================== + + Copyright Amlal El Mahrouss 2025, licensed under the Apache 2.0 license. + + FILE: ddk.h + PURPOSE: DDK Driver model base header. + +======================================== */ + +#pragma once + +#include <DriverKit/macros.h> + +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; + struct DDK_OBJECT_MANIFEST* s_object; +}; + +typedef void* ptr_t; + +/// @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_dispatch(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_set_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 uint32_t kApiVersionHighest; + +/// @brief The lowest API version of the DDK. +DDK_EXTERN uint32_t kApiVersionLowest; + +/// @brief API version in BCD. +DDK_EXTERN uint32_t kApiVersion; diff --git a/src/libDDK/DriverKit/dev.h b/src/libDDK/DriverKit/dev.h new file mode 100644 index 00000000..a88a00dd --- /dev/null +++ b/src/libDDK/DriverKit/dev.h @@ -0,0 +1,36 @@ +/* ======================================== + + Copyright Amlal El Mahrouss. + + File: dev.h + Purpose: DDK device support. + +======================================== */ + +#pragma once + +#include <DriverKit/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. + void (*d_seek)(struct _DDK_DEVICE* dev, size_t off); + size_t (*d_tell)(struct _DDK_DEVICE* dev); +} DDK_DEVICE, *DDK_DEVICE_PTR; + +/// @brief Open a new device from path. +/// @param path the device's path. +DDK_EXTERN DDK_DEVICE_PTR kopen_dev(const char* path); + +/// @brief Close any device. +/// @param device valid device. +DDK_EXTERN BOOL kclose_dev(DDK_DEVICE_PTR device); diff --git a/src/libDDK/DriverKit/dki/contract.h b/src/libDDK/DriverKit/dki/contract.h new file mode 100644 index 00000000..7361d792 --- /dev/null +++ b/src/libDDK/DriverKit/dki/contract.h @@ -0,0 +1,34 @@ +/* ======================================== + + Copyright Amlal El Mahrouss 2025, licensed under the Apache 2.0 license. + + FILE: ddk.h + PURPOSE: Driver Kernel Interface Model base header. + + ======================================== */ + +#pragma once + +#include <CompilerKit/CompilerKit.h> +#include <libDDK/DriverKit/macros.h> + +#define DKI_CONTRACT_IMPL final : public ::Kernel::DKI::DKIContract + +/// @author Amlal El Mahrouss + +namespace Kernel::DKI { +class DKIContract { + public: + explicit DKIContract() = default; + virtual ~DKIContract() = default; + + NE_COPY_DEFAULT(DKIContract); + + using PtrType = VoidPtr; + + virtual BOOL IsCastable() { return NO; } + virtual BOOL IsActive() { return NO; } + virtual VoidPtr Leak() { return nullptr; } + virtual Int32 Type() { return 0; } +}; +} // namespace Kernel::DKI diff --git a/src/libDDK/DriverKit/io.h b/src/libDDK/DriverKit/io.h new file mode 100644 index 00000000..58b625ac --- /dev/null +++ b/src/libDDK/DriverKit/io.h @@ -0,0 +1,18 @@ +/* ======================================== + + Copyright Amlal El Mahrouss. + + Purpose: DDK Text I/O. + +======================================== */ + +#pragma once + +#include <DriverKit/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/src/libDDK/DriverKit/macros.h b/src/libDDK/DriverKit/macros.h new file mode 100644 index 00000000..7fd1403b --- /dev/null +++ b/src/libDDK/DriverKit/macros.h @@ -0,0 +1,48 @@ +/* ======================================== + + Copyright 2025 Amlal El Mahrouss. + + FILE: ddk.h + PURPOSE: DDK Driver model base header. + +======================================== */ + +#pragma once + +#include <stddef.h> +#include <stdint.h> + +#if defined(__cplusplus) +#define BOOL bool +#define YES true +#define NO false +#define DDK_EXTERN extern "C" +#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 +#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" +#else +#define DDK_EXTERN +#endif +#endif + +#define ATTRIBUTE(X) __attribute__((X)) + +#ifndef __NEOSKRNL__ +#error !!! Do not include header in EL0/Ring 3 mode !!! +#endif // __NEOSKRNL__
\ No newline at end of file diff --git a/src/libDDK/DriverKit/net.h b/src/libDDK/DriverKit/net.h new file mode 100644 index 00000000..5dfe6374 --- /dev/null +++ b/src/libDDK/DriverKit/net.h @@ -0,0 +1,16 @@ +/* ======================================== + + Copyright Amlal El Mahrouss. + + FILE: net.h + PURPOSE: Network model base header. + +======================================== */ + +#pragma once + +#include <DriverKit/macros.h> + +struct DDK_NET_MANIFEST; + +/// @brief IFS hooks to plug into the FileMgr. diff --git a/src/libDDK/DriverKit/str.h b/src/libDDK/DriverKit/str.h new file mode 100644 index 00000000..6409b1a7 --- /dev/null +++ b/src/libDDK/DriverKit/str.h @@ -0,0 +1,17 @@ +/* ======================================== + + Copyright Amlal El Mahrouss. + + Purpose: DDK Strings. + +======================================== */ + +#pragma once + +#include <DriverKit/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); |
