Update drivers

This commit is contained in:
EnderIce2
2024-01-19 06:44:00 +02:00
parent 2ee57b9756
commit da4a6317ea
83 changed files with 9425 additions and 598 deletions

123
include/aip.h Normal file
View File

@ -0,0 +1,123 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_AIP_H__
#define __FENNIX_API_AIP_H__
#include <types.h>
#include <aip/kbd.h>
#include <aip/mouse.h>
#define PIC1_CMD 0x20
#define PIC1_DATA (PIC1_CMD + 1)
#define PIC2_CMD 0xA0
#define PIC2_DATA (PIC2_CMD + 1)
#define _PIC_EOI 0x20
#define PS2_DATA 0x60
#define PS2_STATUS 0x64
#define PS2_CMD PS2_STATUS
#define PS2_ACK 0xFA
#define PS2_TEST_PASSED 0x55
#define PS2_TEST_FAILED 0xFC
#define PS2_CMD_READ_CONFIG 0x20
#define PS2_CMD_READ_CONFIG_N(n) (PS2_CMD_READ_CONFIG + n)
#define PS2_CMD_WRITE_CONFIG 0x60
#define PS2_CMD_WRITE_CONFIG_N(n) (PS2_CMD_WRITE_CONFIG + n)
#define PS2_CMD_DISABLE_PORT_2 0xA7
#define PS2_CMD_ENABLE_PORT_2 0xA8
#define PS2_CMD_TEST_PORT_2 0xA9
#define PS2_CMD_TEST_CONTROLLER 0xAA
#define PS2_CMD_TEST_PORT_1 0xAB
#define PS2_CMD_DIAGNOSTIC_DUMP 0xAC
#define PS2_CMD_DISABLE_PORT_1 0xAD
#define PS2_CMD_ENABLE_PORT_1 0xAE
#define PS2_CMD_READ_INPUT_PORT 0xC0
#define PS2_CMD_COPY_INPUT_0_3_TO_4_7_STATUS 0xC1
#define PS2_CMD_COPY_INPUT_4_7_TO_4_7_STATUS 0xC2
#define PS2_CMD_READ_OUTPUT_PORT 0xD0
#define PS2_CMD_WRITE_NEXT_BYTE_TO_OUTPUT_PORT 0xD1
#define PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_1_OUTPUT 0xD2
#define PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_OUTPUT 0xD3
#define PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT 0xD4
#define PS2_CMD_PULSE_OUTPUT_LINE(n) (0xF0 + n)
typedef union
{
struct
{
uint8_t OutputBufferFull : 1;
uint8_t InputBufferFull : 1;
uint8_t SystemFlag : 1;
uint8_t CommandData : 1;
uint8_t Unknown1 : 1;
uint8_t Unknown2 : 1;
uint8_t TimeoutError : 1;
uint8_t ParityError : 1;
};
uint8_t Raw;
} PS2_STATUSES;
typedef union
{
struct
{
uint8_t Port1Interrupt : 1;
uint8_t Port2Interrupt : 1;
uint8_t SystemFlag : 1;
uint8_t Zero0 : 1;
uint8_t Port1Clock : 1;
uint8_t Port2Clock : 1;
uint8_t Port1Translation : 1;
uint8_t Zero1 : 1;
};
uint8_t Raw;
} PS2_CONFIGURATION;
typedef union
{
struct
{
uint8_t SystemReset : 1;
uint8_t A20Gate : 1;
uint8_t Port2Clock : 1;
uint8_t Port2Data : 1;
uint8_t Port1OutputBufferFull : 1;
uint8_t Port2OutputBufferFull : 1;
uint8_t Port1InputBufferFull : 1;
uint8_t Port2InputBufferFull : 1;
};
uint8_t Raw;
} PS2_OUTPUT_PORT;
void PIC_EOI(uint8_t IRQ);
void IRQ_MASK(uint8_t IRQ);
void IRQ_UNMASK(uint8_t IRQ);
void PS2Wait(const bool Output);
void PS2WriteCommand(uint8_t Command);
void PS2WriteData(uint8_t Data);
uint8_t PS2ReadData();
uint8_t PS2ReadStatus();
uint8_t PS2ReadAfterACK();
void PS2ClearOutputBuffer();
int PS2ACKTimeout();
#define WaitOutput PS2Wait(true)
#define WaitInput PS2Wait(false)
#endif // !__FENNIX_API_AIP_H__

93
include/aip/kbd.h Normal file
View File

@ -0,0 +1,93 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_AIP_KBD_H__
#define __FENNIX_API_AIP_KBD_H__
#include <types.h>
#define PS2_KBD_CMD_SET_LEDS 0xED
#define PS2_KBD_CMD_ECHO 0xEE
#define PS2_KBD_CMD_SCAN_CODE_SET 0xF0
#define PS2_KBD_CMD_IDENTIFY 0xF2
#define PS2_KBD_CMD_TYPEMATIC 0xF3
#define PS2_KBD_CMD_ENABLE_SCANNING 0xF4
#define PS2_KBD_CMD_DISABLE_SCANNING 0xF5
#define PS2_KBD_CMD_DEFAULTS 0xF6
#define PS2_KBD_CMD_ALL_TYPEMATIC 0xF7
#define PS2_KBD_CMD_ALL_MAKE_RELEASE 0xF8
#define PS2_KBD_CMD_ALL_MAKE 0xF9
#define PS2_KBD_CMD_ALL_TYPEMATIC_MAKE_RELEASE 0xFA
#define PS2_KBD_CMD_SPECIFIC_TYPEMATIC 0xFB
#define PS2_KBD_CMD_SPECIFIC_MAKE_RELEASE 0xFC
#define PS2_KBD_CMD_SPECIFIC_MAKE 0xFD
#define PS2_KBD_CMD_RESEND 0xFE
#define PS2_KBD_CMD_RESET 0xFF
#define PS2_KBD_RESP_ACK 0xFA
#define PS2_KBD_RESP_ECHO 0xEE
#define PS2_KBD_RESP_RESEND 0xFE
#define PS2_KBD_RESP_TEST_PASSED 0xAA
#define PS2_KBD_RESP_TEST_FAILED 0xFC
#define PS2_KBD_RESP_TEST_FAILED_2 0xFD
typedef enum
{
PS2_KBD_LED_SCROLL_LOCK = 1,
PS2_KBD_LED_NUM_LOCK = 2,
PS2_KBD_LED_CAPS_LOCK = 4
} PS2_KBD_LEDS;
typedef enum
{
PS2_KBD_SCAN_CODE_GET_CURRENT = 0,
PS2_KBD_SCAN_CODE_SET_1 = 1,
PS2_KBD_SCAN_CODE_SET_2 = 2,
PS2_KBD_SCAN_CODE_SET_3 = 3,
PS2_KBD_SC_SET_1 = 0x43,
PS2_KBD_SC_SET_2 = 0x41,
PS2_KBD_SC_SET_3 = 0x3F
} PS2_KBD_SCAN_CODE_SET;
typedef union
{
struct
{
/**
* 00000b - 30Hz
* 11111b - 2Hz
*/
uint8_t RepeatRate : 5;
/**
* 00b - 250ms
* 01b - 500ms
* 10b - 750ms
* 11b - 1000ms
*/
uint8_t Delay : 2;
/**
* Must be zero
*/
uint8_t Zero : 1;
};
uint8_t Raw;
} PS2_KBD_TYPEMATIC;
#endif // !__FENNIX_API_AIP_KBD_H__

89
include/aip/mouse.h Normal file
View File

@ -0,0 +1,89 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_AIP_MOUSE_H__
#define __FENNIX_API_AIP_MOUSE_H__
#include <types.h>
#define PS2_MOUSE_CMD_SET_SCALING_1_1 0xE6
#define PS2_MOUSE_CMD_SET_SCALING_2_1 0xE7
#define PS2_MOUSE_CMD_SET_RESOLUTION 0xE8
#define PS2_MOUSE_CMD_GET_STATUS 0xE9
#define PS2_MOUSE_CMD_SET_STREAM_MODE 0xEA
#define PS2_MOUSE_CMD_READ_DATA 0xEB
#define PS2_MOUSE_CMD_RESET_WRAP_MODE 0xEC
#define PS2_MOUSE_CMD_SET_WRAP_MODE 0xEE
#define PS2_MOUSE_CMD_SET_REMOTE_MODE 0xF0
#define PS2_MOUSE_CMD_READ_ID 0xF2
/** Values: 10, 20, 40, 60, 80, 100, 200 */
#define PS2_MOUSE_CMD_SET_SAMPLE_RATE 0xF3
#define PS2_MOUSE_CMD_ENABLE_DATA_REPORTING 0xF4
#define PS2_MOUSE_CMD_DISABLE_DATA_REPORTING 0xF5
#define PS2_MOUSE_CMD_SET_DEFAULTS 0xF6
#define PS2_MOUSE_CMD_RESEND 0xFE
#define PS2_MOUSE_CMD_RESET 0xFF
#define PS2_MOUSE_RESP_ACK 0xFA
#define PS2_MOUSE_RESP_RESEND 0xFE
#define PS2_MOUSE_RESP_TEST_PASSED 0xAA
#define PS2_MOUSE_RESP_TEST_FAILED 0xFC
typedef enum
{
PS2_MOUSE_RES_1 = 0,
PS2_MOUSE_RES_2 = 1,
PS2_MOUSE_RES_4 = 2,
PS2_MOUSE_RES_8 = 3
} PS2_MOUSE_RESOLUTION;
typedef struct
{
union
{
struct
{
uint8_t LeftButton : 1;
uint8_t RightButton : 1;
uint8_t MiddleButton : 1;
uint8_t Always1 : 1;
uint8_t XSign : 1;
uint8_t YSign : 1;
uint8_t XOverflow : 1;
uint8_t YOverflow : 1;
} __attribute__((packed));
uint8_t Raw;
} Base;
uint8_t XMovement;
uint8_t YMovement;
union
{
struct
{
uint8_t Z : 4;
uint8_t Button4 : 1;
uint8_t Button5 : 1;
uint8_t Always0 : 1;
uint8_t Always0_2 : 1;
} __attribute__((packed));
uint8_t Raw;
} ZMovement;
} PS2_MOUSE_PACKET;
#endif // !__FENNIX_API_AIP_MOUSE_H__

45
include/audio.h Normal file
View File

@ -0,0 +1,45 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_AUDIO_H__
#define __FENNIX_API_AUDIO_H__
#include <types.h>
#include <driver.h>
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
typedef int (*drvClose_t)(dev_t, dev_t);
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
dev_t RegisterAudioDevice(DeviceDriverType Type,
drvOpen_t Open, drvClose_t Close,
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
int UnregisterAudioDevice(dev_t DeviceID, DeviceDriverType Type);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !__FENNIX_API_AUDIO_H__

277
include/base.h Normal file
View File

@ -0,0 +1,277 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_BASE_H__
#define __FENNIX_API_BASE_H__
#include <driver.h>
#define PAGE_SIZE 0x1000
typedef int CriticalState;
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
/**
* @brief Allocate an amount of memory pages
* @param Pages The amount of pages to allocate
* @return A pointer to the allocated memory, NULL if failed
*/
void *AllocateMemory(size_t Pages);
/**
* @brief Free an amount of memory pages
* @param Pointer The pointer to the memory to free
* @param Pages The amount of pages to free
*
* @note If the pointer is invalid, the error is ignored and the
* function returns
*/
void FreeMemory(void *Pointer, size_t Pages);
/**
* @brief Append a flag to a page
* @param Address The address of the page
* @param Flag The flag to append
*/
void AppendMapFlag(void *Address, PageMapFlags Flag);
/**
* @brief Remove a flag from a page
* @param Address The address of the page
* @param Flag The flag to remove
*/
void RemoveMapFlag(void *Address, PageMapFlags Flag);
/**
* @brief Map pages
* @param PhysicalAddress The physical address to map
* @param VirtualAddress The virtual address to map to
* @param Pages The amount of pages to map
* @param Flags The flags to map the pages with
*/
void MapPages(void *PhysicalAddress, void *VirtualAddress, size_t Pages, uint32_t Flags);
/**
* @brief Unmap pages
* @param VirtualAddress The virtual address to unmap
* @param Pages The amount of pages to unmap
*/
void UnmapPages(void *VirtualAddress, size_t Pages);
/**
* @brief Print to the screen
* @param Format The format string
* @param ... The arguments to the format string
*
* @note The newline character is automatically appended
*/
void KPrint(const char *Format, ...);
/**
* @brief Print to the kernel logger
* @param Format The format string
* @param ... The arguments to the format string
*/
void Log(const char *Format, ...);
/**
* @brief Register an interrupt handler
* @param IRQ The IRQ to register the handler for (IRQ0 != 0x32 but 0)
* @param Handler Function pointer to the handler
* @return 0 on success, errno on failure
*/
int RegisterInterruptHandler(uint8_t IRQ, void *Handler);
/**
* @brief Override an interrupt handler
*
* This function will check all registered handlers (by the drivers)
* for the given IRQ and remove them. Then it will register the new
* handler.
*
* @param IRQ The IRQ to override the handler for (IRQ0 != 0x32 but 0)
* @param Handler Function pointer to the handler
* @return 0 on success, errno on failure
*/
int OverrideInterruptHandler(uint8_t IRQ, void *Handler);
/**
* @brief Unregister an interrupt handler
* @param IRQ The IRQ to unregister the handler for (IRQ0 != 0x32 but 0)
* @param Handler Function pointer to the handler
* @return 0 on success, errno on failure
*/
int UnregisterInterruptHandler(uint8_t IRQ, void *Handler);
/**
* @brief Unregister all interrupt handlers for a given handler
* @param Handler Function pointer to the handler
* @return 0 on success, errno on failure
*/
int UnregisterAllInterruptHandlers(void *Handler);
/**
* @brief Copy memory
* @param Destination The destination
* @param Source The source
* @param Length The length of the memory to copy
* @return The destination
*/
void *MemoryCopy(void *Destination, const void *Source, size_t Length);
/**
* @brief Set memory
* @param Destination The destination
* @param Value The value to set
* @param Length The length of the memory to set
* @return The destination
*/
void *MemorySet(void *Destination, int Value, size_t Length);
/**
* @brief Move memory
* @param Destination The destination
* @param Source The source
* @param Length The length of the memory to move
* @return The destination
*/
void *MemoryMove(void *Destination, const void *Source, size_t Length);
/**
* @brief String length
* @param String The string
* @return The length of the string
*/
size_t StringLength(const char String[]);
char *strstr(const char *Haystack, const char *Needle);
/**
* @brief Create a kernel process
* @param Name The name of the process
* @return The PID of the process, this function never fails
*/
pid_t CreateKernelProcess(const char *Name);
/**
* @brief Create a kernel thread
* @param pId The PID of the process to create the thread in
* @param Name The name of the thread
* @param EntryPoint The entry point of the thread
* @param Argument The argument to pass to the thread (rdi)
* @return The TID of the thread, this function never fails
*/
pid_t CreateKernelThread(pid_t pId, const char *Name, void *EntryPoint,
void *Argument);
/**
* @brief Kill a process
* @param pId The PID of the process to kill
* @param ExitCode The exit code of the process
* @return 0 on success, errno on failure
*/
int KillProcess(pid_t pId, int ExitCode);
/**
* @brief Kill a thread
* @param tId The TID of the thread to kill
* @param ExitCode The exit code of the thread
* @return 0 on success, errno on failure
*/
int KillThread(pid_t tId, int ExitCode);
/**
* @brief Yield the current thread
*
* This function will yield the current thread to the scheduler.
*/
void Yield();
/**
* @brief Sleep for a given amount of milliseconds
* @param Milliseconds The amount of milliseconds to sleep
*/
void Sleep(uint64_t Milliseconds);
/**
* @brief Enter a critical section
* @return The previous interrupt state
*
* This function will disable interrupts and return the previous
* interrupt state.
*/
CriticalState EnterCriticalSection();
/**
* @brief Leave a critical section
* @param PreviousState The previous interrupt state
*
* This function will restore the previous interrupt state.
*/
void LeaveCriticalSection(CriticalState PreviousState);
/** @copydoc EnterCriticalSection */
#define ECS CriticalState __ECS = EnterCriticalSection()
/** @copydoc LeaveCriticalSection */
#define LCS LeaveCriticalSection(__ECS)
#define DriverInfo(Name, Description, Author, Version, License) \
void __IdentifyDriver( \
dev_t ID, \
int (*GetDriverInfo)(dev_t, const char *, const char *, \
const char *, const char *, const char *)) \
{ \
GetDriverInfo(ID, Name, Description, Author, Version, License); \
}
#ifdef DEBUG
#define DebugLog(m, ...) Log(m, ##__VA_ARGS__)
#else
#define DebugLog(m, ...)
#endif // DEBUG
#ifdef __cplusplus
}
#endif // __cplusplus
#ifdef __cplusplus
namespace std
{
typedef decltype(sizeof(0)) size_t;
}
void *operator new(std::size_t Size);
void *operator new[](std::size_t Size);
void operator delete(void *Pointer);
void operator delete[](void *Pointer);
void operator delete(void *Pointer, std::size_t Size);
void operator delete[](void *Pointer, std::size_t Size);
#endif // __cplusplus
#define memcpy(dest, src, len) MemoryCopy(dest, src, len)
#define memset(dest, val, len) MemorySet(dest, val, len)
#define memmove(dest, src, len) MemoryMove(dest, src, len)
#define strlen(str) StringLength(str)
#endif // !__FENNIX_API_BASE_H__

45
include/block.h Normal file
View File

@ -0,0 +1,45 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_BLOCK_H__
#define __FENNIX_API_BLOCK_H__
#include <types.h>
#include <driver.h>
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
typedef int (*drvClose_t)(dev_t, dev_t);
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
dev_t RegisterBlockDevice(DeviceDriverType Type,
drvOpen_t Open, drvClose_t Close,
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
int UnregisterBlockDevice(dev_t DeviceID, DeviceDriverType Type);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !__FENNIX_API_BLOCK_H__

326
include/driver.h Normal file
View File

@ -0,0 +1,326 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_DRIVER_FUNCTIONS_H__
#define __FENNIX_API_DRIVER_FUNCTIONS_H__
#include <types.h>
typedef enum
{
_drf_Entry,
_drf_Final,
_drf_Panic,
_drf_Probe,
} __driverRegFunc;
typedef union
{
struct
{
uint8_t LeftButton : 1;
uint8_t RightButton : 1;
uint8_t MiddleButton : 1;
uint8_t Button4 : 1;
uint8_t Button5 : 1;
uint8_t Button6 : 1;
uint8_t Button7 : 1;
uint8_t Button8 : 1;
};
uint8_t Value;
} __MouseButtons;
typedef struct
{
/* PCIDevice */ void *Device;
/* __PCIArray */ void *Next;
} __PCIArray;
/* ========================================== */
#define PCI_END 0x0000
#define KEY_NULL 0x00
typedef enum
{
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_0,
KEY_Q,
KEY_W,
KEY_E,
KEY_R,
KEY_T,
KEY_Y,
KEY_U,
KEY_I,
KEY_O,
KEY_P,
KEY_A,
KEY_S,
KEY_D,
KEY_F,
KEY_G,
KEY_H,
KEY_J,
KEY_K,
KEY_L,
KEY_Z,
KEY_X,
KEY_C,
KEY_V,
KEY_B,
KEY_N,
KEY_M,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
KEYPAD_7,
KEYPAD_8,
KEYPAD_9,
KEYPAD_MINUS,
KEYPAD_4,
KEYPAD_5,
KEYPAD_6,
KEYPAD_PLUS,
KEYPAD_1,
KEYPAD_2,
KEYPAD_3,
KEYPAD_0,
KEYPAD_PERIOD,
KEYPAD_RETURN,
KEYPAD_ASTERISK,
KEYPAD_SLASH,
KEY_LEFT_CTRL,
KEY_RIGHT_CTRL,
KEY_LEFT_SHIFT,
KEY_RIGHT_SHIFT,
KEY_LEFT_ALT,
KEY_RIGHT_ALT,
KEY_ESCAPE,
KEY_MINUS,
KEY_EQUAL,
KEY_BACKSPACE,
KEY_TAB,
KEY_LEFT_BRACKET,
KEY_RIGHT_BRACKET,
KEY_RETURN,
KEY_SEMICOLON,
KEY_APOSTROPHE,
KEY_BACK_TICK,
KEY_BACKSLASH,
KEY_COMMA,
KEY_PERIOD,
KEY_SLASH,
KEY_SPACE,
KEY_CAPS_LOCK,
KEY_NUM_LOCK,
KEY_SCROLL_LOCK,
KEY_PRINT_SCREEN,
KEY_HOME,
KEY_UP_ARROW,
KEY_LEFT_ARROW,
KEY_RIGHT_ARROW,
KEY_DOWN_ARROW,
KEY_PAGE_UP,
KEY_PAGE_DOWN,
KEY_END,
KEY_INSERT,
KEY_DELETE,
KEY_LEFT_GUI,
KEY_RIGHT_GUI,
KEY_APPS,
KEY_MULTIMEDIA_PREV_TRACK,
KEY_MULTIMEDIA_NEXT_TRACK,
KEY_MULTIMEDIA_MUTE,
KEY_MULTIMEDIA_CALCULATOR,
KEY_MULTIMEDIA_PLAY,
KEY_MULTIMEDIA_STOP,
KEY_MULTIMEDIA_VOL_DOWN,
KEY_MULTIMEDIA_VOL_UP,
KEY_MULTIMEDIA_WWW_HOME,
KEY_MULTIMEDIA_WWW_SEARCH,
KEY_MULTIMEDIA_WWW_FAVORITES,
KEY_MULTIMEDIA_WWW_REFRESH,
KEY_MULTIMEDIA_WWW_STOP,
KEY_MULTIMEDIA_WWW_FORWARD,
KEY_MULTIMEDIA_WWW_BACK,
KEY_MULTIMEDIA_MY_COMPUTER,
KEY_MULTIMEDIA_EMAIL,
KEY_MULTIMEDIA_MEDIA_SELECT,
KEY_ACPI_POWER,
KEY_ACPI_SLEEP,
KEY_ACPI_WAKE,
KEY_PRESSED = 0x80,
} KeyScanCodes;
typedef enum
{
ddt_Keyboard,
ddt_Mouse,
ddt_Joystick,
ddt_Gamepad,
ddt_Touchpad,
ddt_Touchscreen,
ddt_SATA,
ddt_ATA,
ddt_NVMe,
ddt_Audio,
ddt_Network,
} DeviceDriverType;
typedef enum
{
IOCTL_AUDIO_GET_VOLUME,
IOCTL_AUDIO_SET_VOLUME,
IOCTL_AUDIO_GET_MUTE,
IOCTL_AUDIO_SET_MUTE,
IOCTL_AUDIO_GET_SAMPLE_RATE,
IOCTL_AUDIO_SET_SAMPLE_RATE,
IOCTL_AUDIO_GET_CHANNELS,
IOCTL_AUDIO_SET_CHANNELS,
} AudioIoctl;
typedef enum
{
IOCTL_NET_GET_MAC,
} NetIoctl;
typedef enum
{
MAP_PRESENT = 1 << 0,
MAP_WRITE = 1 << 1,
MAP_USER = 1 << 2,
MAP_WRITE_THROUGH = 1 << 3,
MAP_CACHE_DISABLE = 1 << 4,
} PageMapFlags;
typedef struct
{
struct
{
uint8_t Major;
uint8_t Minor;
uint8_t Patch;
} APIVersion;
dev_t MajorID;
uintptr_t Base;
/* Internal */
int (*RegisterFunction)(dev_t MajorID, void *Function, __driverRegFunc Type);
int (*GetDriverInfo)(dev_t MajorID, const char *Name, const char *Description, const char *Author, const char *Version, const char *License);
/* Interrupts */
int (*RegisterInterruptHandler)(dev_t MajorID, uint8_t IRQ, void *Handler);
int (*OverrideInterruptHandler)(dev_t MajorID, uint8_t IRQ, void *Handler);
int (*UnregisterInterruptHandler)(dev_t MajorID, uint8_t IRQ, void *Handler);
int (*UnregisterAllInterruptHandlers)(dev_t MajorID, void *Handler);
/* Input */
dev_t (*RegisterInputDevice)(dev_t MajorID, DeviceDriverType Type);
int (*UnregisterInputDevice)(dev_t MajorID, dev_t MinorID, DeviceDriverType Type);
int (*ReportKeyboardEvent)(dev_t MajorID, dev_t MinorID, uint8_t ScanCode);
int (*ReportRelativeMouseEvent)(dev_t MajorID, dev_t MinorID, __MouseButtons Button, int X, int Y, int8_t Z);
int (*ReportAbsoluteMouseEvent)(dev_t MajorID, dev_t MinorID, __MouseButtons Button, uintptr_t X, uintptr_t Y, int8_t Z);
/* Storage */
dev_t (*RegisterBlockDevice)(dev_t MajorID, DeviceDriverType Type, void *Open, void *Close, void *Read, void *Write, void *Ioctl);
int (*UnregisterBlockDevice)(dev_t MajorID, dev_t MinorID, DeviceDriverType Type);
/* Audio */
dev_t (*RegisterAudioDevice)(dev_t MajorID, DeviceDriverType Type, void *Open, void *Close, void *Read, void *Write, void *Ioctl);
int (*UnregisterAudioDevice)(dev_t MajorID, dev_t MinorID, DeviceDriverType Type);
/* Network */
dev_t (*RegisterNetDevice)(dev_t MajorID, DeviceDriverType Type, void *Open, void *Close, void *Read, void *Write, void *Ioctl);
int (*UnregisterNetDevice)(dev_t MajorID, dev_t MinorID, DeviceDriverType Type);
int (*ReportNetworkPacket)(dev_t MajorID, dev_t MinorID, void *Buffer, size_t Size);
/* Logging */
void (*KPrint)(dev_t MajorID, const char *Format, va_list args);
void (*KernelLog)(dev_t MajorID, const char *Format, va_list args);
/* Memory */
void *(*RequestPages)(dev_t MajorID, size_t Pages);
void (*FreePages)(dev_t MajorID, void *Pointer, size_t Pages);
/* Mapping */
void (*AppendMapFlag)(dev_t MajorID, void *Address, PageMapFlags Flag);
void (*RemoveMapFlag)(dev_t MajorID, void *Address, PageMapFlags Flag);
void (*MapPages)(dev_t MajorID, void *PhysicalAddress, void *VirtualAddress, size_t Pages, uint32_t Flags);
void (*UnmapPages)(dev_t MajorID, void *VirtualAddress, size_t Pages);
/* Scheduling */
pid_t (*CreateKernelProcess)(dev_t MajorID, const char *Name);
pid_t (*CreateKernelThread)(dev_t MajorID, pid_t pId, const char *Name, void *EntryPoint, void *Argument);
int (*KillProcess)(dev_t MajorID, pid_t pId, int ExitCode);
int (*KillThread)(dev_t MajorID, pid_t tId, int ExitCode);
void (*Yield)(dev_t MajorID);
void (*Sleep)(dev_t MajorID, uint64_t Milliseconds);
/* PCI */
__PCIArray *(*GetPCIDevices)(dev_t MajorID, uint16_t Vendors[], uint16_t Devices[]);
void (*InitializePCI)(dev_t MajorID, void *Header);
uint32_t (*GetBAR)(dev_t MajorID, uint8_t Index, void *Header);
/* Kernel std API */
void *(*memcpy)(dev_t MajorID, void *Destination, const void *Source, size_t Length);
void *(*memset)(dev_t MajorID, void *Destination, int Value, size_t Length);
void *(*memmove)(dev_t MajorID, void *Destination, const void *Source, size_t Length);
int (*memcmp)(dev_t MajorID, const void *Left, const void *Right, size_t Length);
size_t (*strlen)(dev_t MajorID, const char *String);
char *(*strcpy)(dev_t MajorID, char *Destination, const char *Source);
char *(*strcat)(dev_t MajorID, char *Destination, const char *Source);
int (*strcmp)(dev_t MajorID, const char *Left, const char *Right);
int (*strncmp)(dev_t MajorID, const char *Left, const char *Right, size_t Length);
char *(*strchr)(dev_t MajorID, const char *String, int Character);
char *(*strrchr)(dev_t MajorID, const char *String, int Character);
char *(*strstr)(dev_t MajorID, const char *Haystack, const char *Needle);
} __driverAPI;
#endif // !__FENNIX_API_DRIVER_FUNCTIONS_H__

408
include/errno.h Normal file
View File

@ -0,0 +1,408 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _ERRNO_H
#define _ERRNO_H
/** Operation not permitted */
#define EPERM 1
/** No such file or directory */
#define ENOENT 2
/** No such process */
#define ESRCH 3
/** Interrupted system call */
#define EINTR 4
/** I/O error */
#define EIO 5
/** No such device or address */
#define ENXIO 6
/** Argument list too long */
#define E2BIG 7
/** Exec format error */
#define ENOEXEC 8
/** Bad file number */
#define EBADF 9
/** No child processes */
#define ECHILD 10
/** Try again */
#define EAGAIN 11
/** Out of memory */
#define ENOMEM 12
/** Permission denied */
#define EACCES 13
/** Bad address */
#define EFAULT 14
/** Block device required */
#define ENOTBLK 15
/** Device or resource busy */
#define EBUSY 16
/** File exists */
#define EEXIST 17
/** Cross-device link */
#define EXDEV 18
/** No such device */
#define ENODEV 19
/** Not a directory */
#define ENOTDIR 20
/** Is a directory */
#define EISDIR 21
/** Invalid argument */
#define EINVAL 22
/** File table overflow */
#define ENFILE 23
/** Too many open files */
#define EMFILE 24
/** Not a typewriter */
#define ENOTTY 25
/** Text file busy */
#define ETXTBSY 26
/** File too large */
#define EFBIG 27
/** No space left on device */
#define ENOSPC 28
/** Illegal seek */
#define ESPIPE 29
/** Read-only file system */
#define EROFS 30
/** Too many links */
#define EMLINK 31
/** Broken pipe */
#define EPIPE 32
/** Math argument out of domain of func */
#define EDOM 33
/** Math result not representable */
#define ERANGE 34
/** Resource deadlock would occur */
#define EDEADLK 35
/** File name too long */
#define ENAMETOOLONG 36
/** No record locks available */
#define ENOLCK 37
/** Function not implemented */
#define ENOSYS 38
/** Directory not empty */
#define ENOTEMPTY 39
/** Too many symbolic links encountered */
#define ELOOP 40
/** No message of desired type */
#define ENOMSG 42
/** Identifier removed */
#define EIDRM 43
/** Channel number out of range */
#define ECHRNG 44
/** Level 2 not synchronized */
#define EL2NSYNC 45
/** Level 3 halted */
#define EL3HLT 46
/** Level 3 reset */
#define EL3RST 47
/** Link number out of range */
#define ELNRNG 48
/** Protocol driver not attached */
#define EUNATCH 49
/** No CSI structure available */
#define ENOCSI 50
/** Level 2 halted */
#define EL2HLT 51
/** Invalid exchange */
#define EBADE 52
/** Invalid request descriptor */
#define EBADR 53
/** Exchange full */
#define EXFULL 54
/** No anode */
#define ENOANO 55
/** Invalid request code */
#define EBADRQC 56
/** Invalid slot */
#define EBADSLT 57
/** Bad font file format */
#define EBFONT 59
/** Device not a stream */
#define ENOSTR 60
/** No data available */
#define ENODATA 61
/** Timer expired */
#define ETIME 62
/** Out of streams resources */
#define ENOSR 63
/** Machine is not on the network */
#define ENONET 64
/** Package not installed */
#define ENOPKG 65
/** Object is remote */
#define EREMOTE 66
/** Link has been severed */
#define ENOLINK 67
/** Advertise error */
#define EADV 68
/** Srmount error */
#define ESRMNT 69
/** Communication error on send */
#define ECOMM 70
/** Protocol error */
#define EPROTO 71
/** Multihop attempted */
#define EMULTIHOP 72
/** RFS specific error */
#define EDOTDOT 73
/** Not a data message */
#define EBADMSG 74
/** Value too large for defined data type */
#define EOVERFLOW 75
/** Name not unique on network */
#define ENOTUNIQ 76
/** File descriptor in bad state */
#define EBADFD 77
/** Remote address changed */
#define EREMCHG 78
/** Can not access a needed shared library */
#define ELIBACC 79
/** Accessing a corrupted shared library */
#define ELIBBAD 80
/** .lib section in a.out corrupted */
#define ELIBSCN 81
/** Attempting to link in too many shared libraries */
#define ELIBMAX 82
/** Cannot exec a shared library directly */
#define ELIBEXEC 83
/** Illegal byte sequence */
#define EILSEQ 84
/** Interrupted system call should be restarted */
#define ERESTART 85
/** Streams pipe error */
#define ESTRPIPE 86
/** Too many users */
#define EUSERS 87
/** Socket operation on non-socket */
#define ENOTSOCK 88
/** Destination address required */
#define EDESTADDRREQ 89
/** Message too long */
#define EMSGSIZE 90
/** Protocol wrong type for socket */
#define EPROTOTYPE 91
/** Protocol not available */
#define ENOPROTOOPT 92
/** Protocol not supported */
#define EPROTONOSUPPORT 93
/** Socket type not supported */
#define ESOCKTNOSUPPORT 94
/** Operation not supported on transport endpoint */
#define EOPNOTSUPP 95
/** Protocol family not supported */
#define EPFNOSUPPORT 96
/** Address family not supported by protocol */
#define EAFNOSUPPORT 97
/** Address already in use */
#define EADDRINUSE 98
/** Cannot assign requested address */
#define EADDRNOTAVAIL 99
/** Network is down */
#define ENETDOWN 100
/** Network is unreachable */
#define ENETUNREACH 101
/** Network dropped connection because of reset */
#define ENETRESET 102
/** Software caused connection abort */
#define ECONNABORTED 103
/** Connection reset by peer */
#define ECONNRESET 104
/** No buffer space available */
#define ENOBUFS 105
/** Transport endpoint is already connected */
#define EISCONN 106
/** Transport endpoint is not connected */
#define ENOTCONN 107
/** Cannot send after transport endpoint shutdown */
#define ESHUTDOWN 108
/** Too many references: cannot splice */
#define ETOOMANYREFS 109
/** Connection timed out */
#define ETIMEDOUT 110
/** Connection refused */
#define ECONNREFUSED 111
/** Host is down */
#define EHOSTDOWN 112
/** No route to host */
#define EHOSTUNREACH 113
/** Operation already in progress */
#define EALREADY 114
/** Operation now in progress */
#define EINPROGRESS 115
/** Stale NFS file handle */
#define ESTALE 116
/** Structure needs cleaning */
#define EUCLEAN 117
/** Not a XENIX named type file */
#define ENOTNAM 118
/** No XENIX semaphores available */
#define ENAVAIL 119
/** Is a named type file */
#define EISNAM 120
/** Remote I/O error */
#define EREMOTEIO 121
/** Quota exceeded */
#define EDQUOT 122
/** No medium found */
#define ENOMEDIUM 123
/** Wrong medium type */
#define EMEDIUMTYPE 124
/** Operation Canceled */
#define ECANCELED 125
/** Required key not available */
#define ENOKEY 126
/** Key has expired */
#define EKEYEXPIRED 127
/** Key has been revoked */
#define EKEYREVOKED 128
/** Key was rejected by service */
#define EKEYREJECTED 129
/** Owner died */
#define EOWNERDEAD 130
/** State not recoverable */
#define ENOTRECOVERABLE 131
#endif // !_ERRNO_H

66
include/input.h Normal file
View File

@ -0,0 +1,66 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_INPUT_H__
#define __FENNIX_API_INPUT_H__
#include <types.h>
#include <driver.h>
typedef struct
{
union
{
struct
{
uint8_t LeftButton : 1;
uint8_t RightButton : 1;
uint8_t MiddleButton : 1;
uint8_t Button4 : 1;
uint8_t Button5 : 1;
};
uint8_t Buttons;
};
/**
* @note Ignored if is absolute
*/
int X;
/**
* @note Ignored if is absolute
*/
int Y;
int8_t Z;
} MouseReport;
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
dev_t RegisterInputDevice(DeviceDriverType Type);
int UnregisterInputDevice(dev_t DeviceID, DeviceDriverType Type);
int ReportKeyboardEvent(dev_t DeviceID, KeyScanCodes ScanCode, uint8_t Pressed);
int ReportRelativeMouseEvent(dev_t DeviceID, MouseReport Report);
int ReportAbsoluteMouseEvent(dev_t DeviceID, MouseReport Report, uintptr_t X, uintptr_t Y);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !__FENNIX_API_INPUT_H__

View File

@ -1,3 +1,20 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_IO_H__
#define __FENNIX_API_IO_H__
@ -9,201 +26,203 @@
extern "C"
{
#endif
static inline uint8_t inportb(uint16_t Port)
{
uint8_t Result;
__asm__("in %%dx, %%al"
: "=a"(Result)
: "d"(Port));
return Result;
}
static inline uint16_t inportw(uint16_t Port)
{
uint16_t Result;
__asm__("in %%dx, %%ax"
: "=a"(Result)
: "d"(Port));
return Result;
}
static inline uint8_t inportb(uint16_t Port)
{
uint8_t Result;
__asm__("in %%dx, %%al"
: "=a"(Result)
: "d"(Port));
return Result;
}
static inline uint32_t inportl(uint16_t Port)
{
uint32_t Result;
__asm__ volatile("inl %1, %0"
: "=a"(Result)
: "dN"(Port));
return Result;
}
static inline uint16_t inportw(uint16_t Port)
{
uint16_t Result;
__asm__("in %%dx, %%ax"
: "=a"(Result)
: "d"(Port));
return Result;
}
static inline void outportb(uint16_t Port, uint8_t Data)
{
__asm__ volatile("out %%al, %%dx"
:
: "a"(Data), "d"(Port));
}
static inline uint32_t inportl(uint16_t Port)
{
uint32_t Result;
__asm__ volatile("inl %1, %0"
: "=a"(Result)
: "dN"(Port));
return Result;
}
static inline void outportw(uint16_t Port, uint16_t Data)
{
__asm__ volatile("out %%ax, %%dx"
:
: "a"(Data), "d"(Port));
}
static inline void outportb(uint16_t Port, uint8_t Data)
{
__asm__ volatile("out %%al, %%dx"
:
: "a"(Data), "d"(Port));
}
static inline void outportl(uint16_t Port, uint32_t Data)
{
__asm__ volatile("outl %1, %0"
:
: "dN"(Port), "a"(Data));
}
static inline void outportw(uint16_t Port, uint16_t Data)
{
__asm__ volatile("out %%ax, %%dx"
:
: "a"(Data), "d"(Port));
}
static inline uint8_t mmioin8(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint8_t Result = *(volatile uint8_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline void outportl(uint16_t Port, uint32_t Data)
{
__asm__ volatile("outl %1, %0"
:
: "dN"(Port), "a"(Data));
}
static inline uint16_t mmioin16(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint16_t Result = *(volatile uint16_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline uint8_t mmioin8(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint8_t Result = *(volatile uint8_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline uint32_t mmioin32(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint32_t Result = *(volatile uint32_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline uint16_t mmioin16(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint16_t Result = *(volatile uint16_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline uint64_t mmioin64(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint64_t Result = *(volatile uint64_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline uint32_t mmioin32(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint32_t Result = *(volatile uint32_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline void mmioout8(uint64_t Address, uint8_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint8_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline uint64_t mmioin64(uint64_t Address)
{
__asm__ volatile("" ::
: "memory");
uint64_t Result = *(volatile uint64_t *)Address;
__asm__ volatile("" ::
: "memory");
return Result;
}
static inline void mmioout16(uint64_t Address, uint16_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint16_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmioout8(uint64_t Address, uint8_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint8_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmioout32(uint64_t Address, uint32_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint32_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmioout16(uint64_t Address, uint16_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint16_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmioout64(uint64_t Address, uint64_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint64_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmioout32(uint64_t Address, uint32_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint32_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmoutb(void *Address, uint8_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint8_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline void mmioout64(uint64_t Address, uint64_t Data)
{
__asm__ volatile("" ::
: "memory");
*(volatile uint64_t *)Address = Data;
__asm__ volatile("" ::
: "memory");
}
static inline void mmoutw(void *Address, uint16_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint16_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline void mmoutb(void *Address, uint8_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint8_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline void mmoutl(void *Address, uint32_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint32_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline void mmoutw(void *Address, uint16_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint16_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline void mmoutq(void *Address, uint64_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint64_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline void mmoutl(void *Address, uint32_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint32_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline uint8_t mminb(void *Address)
{
uint8_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint8_t *)(Address)))
: "memory");
return Result;
}
static inline void mmoutq(void *Address, uint64_t Value)
{
__asm__ volatile("mov %1, %0"
: "=m"((*(uint64_t *)(Address)))
: "r"(Value)
: "memory");
}
static inline uint16_t mminw(void *Address)
{
uint16_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint16_t *)(Address)))
: "memory");
return Result;
}
static inline uint8_t mminb(void *Address)
{
uint8_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint8_t *)(Address)))
: "memory");
return Result;
}
static inline uint32_t mminl(void *Address)
{
uint32_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint32_t *)(Address)))
: "memory");
return Result;
}
static inline uint16_t mminw(void *Address)
{
uint16_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint16_t *)(Address)))
: "memory");
return Result;
}
static inline uint32_t mminl(void *Address)
{
uint32_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint32_t *)(Address)))
: "memory");
return Result;
}
static inline uint64_t mminq(void *Address)
{
uint64_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint64_t *)(Address)))
: "memory");
return Result;
}
static inline uint64_t mminq(void *Address)
{
uint64_t Result;
__asm__ volatile("mov %1, %0"
: "=r"(Result)
: "m"((*(uint64_t *)(Address)))
: "memory");
return Result;
}
#ifdef __cplusplus
}
#endif

47
include/net.h Normal file
View File

@ -0,0 +1,47 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_AUDIO_H__
#define __FENNIX_API_AUDIO_H__
#include <types.h>
#include <driver.h>
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
typedef int (*drvClose_t)(dev_t, dev_t);
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
dev_t RegisterNetDevice(DeviceDriverType Type,
drvOpen_t Open, drvClose_t Close,
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
int UnregisterNetDevice(dev_t DeviceID, DeviceDriverType Type);
int ReportNetworkPacket(dev_t DeviceID, void *Buffer, size_t Size);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !__FENNIX_API_AUDIO_H__

View File

@ -1,3 +1,20 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_NETWORK_UTILS_H__
#define __FENNIX_API_NETWORK_UTILS_H__

View File

@ -1,3 +1,20 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_PCI_H__
#define __FENNIX_API_PCI_H__
@ -6,123 +23,162 @@
/* https://sites.uclouvain.be/SystInfo/usr/include/linux/pci_regs.h.html */
enum PCICommands
{
/** @brief Enable response in I/O space */
PCI_COMMAND_IO = 0x1,
/** @brief Enable response in Memory space */
PCI_COMMAND_MEMORY = 0x2,
/** @brief Enable bus mastering */
PCI_COMMAND_MASTER = 0x4,
/** @brief Enable response to special cycles */
PCI_COMMAND_SPECIAL = 0x8,
/** @brief Use memory write and invalidate */
PCI_COMMAND_INVALIDATE = 0x10,
/** @brief Enable palette snooping */
PCI_COMMAND_VGA_PALETTE = 0x20,
/** @brief Enable parity checking */
PCI_COMMAND_PARITY = 0x40,
/** @brief Enable address/data stepping */
PCI_COMMAND_WAIT = 0x80,
/** @brief Enable SERR */
PCI_COMMAND_SERR = 0x100,
/** @brief Enable back-to-back writes */
PCI_COMMAND_FAST_BACK = 0x200,
/** @brief INTx Emulation Disable */
PCI_COMMAND_INTX_DISABLE = 0x400
/** @brief Enable response in I/O space */
PCI_COMMAND_IO = 0x1,
/** @brief Enable response in Memory space */
PCI_COMMAND_MEMORY = 0x2,
/** @brief Enable bus mastering */
PCI_COMMAND_MASTER = 0x4,
/** @brief Enable response to special cycles */
PCI_COMMAND_SPECIAL = 0x8,
/** @brief Use memory write and invalidate */
PCI_COMMAND_INVALIDATE = 0x10,
/** @brief Enable palette snooping */
PCI_COMMAND_VGA_PALETTE = 0x20,
/** @brief Enable parity checking */
PCI_COMMAND_PARITY = 0x40,
/** @brief Enable address/data stepping */
PCI_COMMAND_WAIT = 0x80,
/** @brief Enable SERR */
PCI_COMMAND_SERR = 0x100,
/** @brief Enable back-to-back writes */
PCI_COMMAND_FAST_BACK = 0x200,
/** @brief INTx Emulation Disable */
PCI_COMMAND_INTX_DISABLE = 0x400
};
struct PCIDeviceHeader
typedef struct
{
uint16_t VendorID;
uint16_t DeviceID;
uint16_t Command;
uint16_t Status;
uint8_t RevisionID;
uint8_t ProgIF;
uint8_t Subclass;
uint8_t Class;
uint8_t CacheLineSize;
uint8_t LatencyTimer;
uint8_t HeaderType;
uint8_t BIST;
};
uint16_t VendorID;
uint16_t DeviceID;
uint16_t Command;
uint16_t Status;
uint8_t RevisionID;
uint8_t ProgIF;
uint8_t Subclass;
uint8_t Class;
uint8_t CacheLineSize;
uint8_t LatencyTimer;
uint8_t HeaderType;
uint8_t BIST;
} __attribute__((packed)) PCIDeviceHeader;
struct PCIHeader0
typedef struct
{
PCIDeviceHeader Header;
uint32_t BAR0;
uint32_t BAR1;
uint32_t BAR2;
uint32_t BAR3;
uint32_t BAR4;
uint32_t BAR5;
uint32_t CardbusCISPointer;
uint16_t SubsystemVendorID;
uint16_t SubsystemID;
uint32_t ExpansionROMBaseAddress;
uint8_t CapabilitiesPointer;
uint8_t Reserved0;
uint16_t Reserved1;
uint32_t Reserved2;
uint8_t InterruptLine;
uint8_t InterruptPin;
uint8_t MinGrant;
uint8_t MaxLatency;
};
PCIDeviceHeader Header;
uint32_t BAR0;
uint32_t BAR1;
uint32_t BAR2;
uint32_t BAR3;
uint32_t BAR4;
uint32_t BAR5;
uint32_t CardbusCISPointer;
uint16_t SubsystemVendorID;
uint16_t SubsystemID;
uint32_t ExpansionROMBaseAddress;
uint8_t CapabilitiesPointer;
uint8_t Reserved0;
uint16_t Reserved1;
uint32_t Reserved2;
uint8_t InterruptLine;
uint8_t InterruptPin;
uint8_t MinGrant;
uint8_t MaxLatency;
} __attribute__((packed)) PCIHeader0;
struct PCIHeader1
typedef struct
{
PCIDeviceHeader Header;
uint32_t BAR0;
uint32_t BAR1;
uint8_t PrimaryBusNumber;
uint8_t SecondaryBusNumber;
uint8_t SubordinateBusNumber;
uint8_t SecondaryLatencyTimer;
uint8_t IOBase;
uint8_t IOLimit;
uint16_t SecondaryStatus;
uint16_t MemoryBase;
uint16_t MemoryLimit;
uint16_t PrefetchableMemoryBase;
uint16_t PrefetchableMemoryLimit;
uint32_t PrefetchableMemoryBaseUpper32;
uint32_t PrefetchableMemoryLimitUpper32;
uint16_t IOBaseUpper16;
uint16_t IOLimitUpper16;
uint8_t CapabilitiesPointer;
uint8_t Reserved0;
uint16_t Reserved1;
uint32_t ExpansionROMBaseAddress;
uint8_t InterruptLine;
uint8_t InterruptPin;
uint16_t BridgeControl;
};
PCIDeviceHeader Header;
uint32_t BAR0;
uint32_t BAR1;
uint8_t PrimaryBusNumber;
uint8_t SecondaryBusNumber;
uint8_t SubordinateBusNumber;
uint8_t SecondaryLatencyTimer;
uint8_t IOBase;
uint8_t IOLimit;
uint16_t SecondaryStatus;
uint16_t MemoryBase;
uint16_t MemoryLimit;
uint16_t PrefetchableMemoryBase;
uint16_t PrefetchableMemoryLimit;
uint32_t PrefetchableMemoryBaseUpper32;
uint32_t PrefetchableMemoryLimitUpper32;
uint16_t IOBaseUpper16;
uint16_t IOLimitUpper16;
uint8_t CapabilitiesPointer;
uint8_t Reserved0;
uint16_t Reserved1;
uint32_t ExpansionROMBaseAddress;
uint8_t InterruptLine;
uint8_t InterruptPin;
uint16_t BridgeControl;
} __attribute__((packed)) PCIHeader1;
struct PCIHeader2
typedef struct
{
PCIDeviceHeader Header;
uint32_t CardbusSocketRegistersBaseAddress;
uint8_t CapabilitiesPointer;
uint8_t Reserved0;
uint16_t SecondaryStatus;
uint8_t PCIbusNumber;
uint8_t CardbusBusNumber;
uint8_t SubordinateBusNumber;
uint8_t CardbusLatencyTimer;
uint32_t MemoryBase0;
uint32_t MemoryLimit0;
uint32_t MemoryBase1;
uint32_t MemoryLimit1;
uint32_t IOBase0;
uint32_t IOLimit0;
uint32_t IOBase1;
uint32_t IOLimit1;
uint8_t InterruptLine;
uint8_t InterruptPin;
uint16_t BridgeControl;
uint16_t SubsystemVendorID;
uint16_t SubsystemID;
uint32_t LegacyBaseAddress;
};
PCIDeviceHeader Header;
uint32_t CardbusSocketRegistersBaseAddress;
uint8_t CapabilitiesPointer;
uint8_t Reserved0;
uint16_t SecondaryStatus;
uint8_t PCIbusNumber;
uint8_t CardbusBusNumber;
uint8_t SubordinateBusNumber;
uint8_t CardbusLatencyTimer;
uint32_t MemoryBase0;
uint32_t MemoryLimit0;
uint32_t MemoryBase1;
uint32_t MemoryLimit1;
uint32_t IOBase0;
uint32_t IOLimit0;
uint32_t IOBase1;
uint32_t IOLimit1;
uint8_t InterruptLine;
uint8_t InterruptPin;
uint16_t BridgeControl;
uint16_t SubsystemVendorID;
uint16_t SubsystemID;
uint32_t LegacyBaseAddress;
} __attribute__((packed)) PCIHeader2;
typedef struct
{
uint64_t BaseAddress;
uint16_t PCISegGroup;
uint8_t StartBus;
uint8_t EndBus;
uint32_t Reserved;
} __attribute__((packed)) DeviceConfig;
typedef struct
{
PCIDeviceHeader *Header;
DeviceConfig *Config;
uint32_t Bus;
uint32_t Device;
uint32_t Function;
} __attribute__((packed)) PCIDevice;
typedef struct
{
PCIDevice *Device;
/* PCIArray */ void *Next;
} __attribute__((packed)) PCIArray;
#ifdef __cplusplus
extern "C"
{
#endif
PCIArray *FindPCIDevices(uint16_t Vendors[], uint16_t Devices[]);
void InitializePCI(PCIDevice *Device);
uint32_t GetBAR(uint8_t Index, PCIDevice *Device);
uint8_t iLine(PCIDevice *Device);
uint8_t iPin(PCIDevice *Device);
#ifdef __cplusplus
}
#endif
#endif // !__FENNIX_API_PCI_H__

100
include/regs.h Normal file
View File

@ -0,0 +1,100 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_REGISTERS_H__
#define __FENNIX_API_REGISTERS_H__
#include <types.h>
#if defined(__amd64__)
typedef struct
{
uint64_t r15; // General purpose
uint64_t r14; // General purpose
uint64_t r13; // General purpose
uint64_t r12; // General purpose
uint64_t r11; // General purpose
uint64_t r10; // General purpose
uint64_t r9; // General purpose
uint64_t r8; // General purpose
uint64_t rbp; // Base Pointer (meant for stack frames)
uint64_t rdi; // Destination index for string operations
uint64_t rsi; // Source index for string operations
uint64_t rdx; // Data (commonly extends the A register)
uint64_t rcx; // Counter
uint64_t rbx; // Base
uint64_t rax; // Accumulator
uint64_t InterruptNumber; // Interrupt Number
uint64_t ErrorCode; // Error code
uint64_t rip; // Instruction Pointer
uint64_t cs; // Code Segment
uint64_t rflags; // Register Flags
uint64_t rsp; // Stack Pointer
uint64_t ss; // Stack Segment
} TrapFrame;
#elif defined(__i386__)
typedef struct TrapFrame
{
uint32_t edi; // Destination index for string operations
uint32_t esi; // Source index for string operations
uint32_t ebp; // Base Pointer (meant for stack frames)
uint32_t esp; // Stack Pointer
uint32_t ebx; // Base
uint32_t edx; // Data (commonly extends the A register)
uint32_t ecx; // Counter
uint32_t eax; // Accumulator
uint32_t InterruptNumber; // Interrupt Number
uint32_t ErrorCode; // Error code
uint32_t eip; // Instruction Pointer
uint32_t cs; // Code Segment
uint32_t eflags; // Register Flags
uint32_t r3_esp; // Stack Pointer
uint32_t r3_ss; // Stack Segment
} TrapFrame;
#elif defined(__aarch64__)
typedef struct TrapFrame
{
uint64_t x19; // General purpose
uint64_t x20; // General purpose
uint64_t x21; // General purpose
uint64_t x22; // General purpose
uint64_t x23; // General purpose
uint64_t x24; // General purpose
uint64_t x25; // General purpose
uint64_t x26; // General purpose
uint64_t x27; // Stack frame pointer
uint64_t x28; // Link register
uint64_t x29; // Frame pointer
uint64_t x30; // Program counter
uint64_t sp_el0; // Stack pointer
uint64_t elr_el1; // Exception Link Register
uint64_t spsr_el1; // Saved Program Status Register
uint64_t ErrorCode /* esr_el1 */; // Exception Syndrome Register
uint64_t InterruptNumber /* iar_el1 */; // Interrupt Acknowledge Register
} TrapFrame;
#endif
#endif // !__FENNIX_API_REGISTERS_H__

231
include/syscall.h Normal file
View File

@ -0,0 +1,231 @@
/*
BSD 3-Clause License
Copyright (c) 2023, EnderIce2
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __FENNIX_KERNEL_SYSCALLS_LIST_H__
#define __FENNIX_KERNEL_SYSCALLS_LIST_H__
/* mmap */
#define sc_PROT_NONE 0
#define sc_PROT_READ 1
#define sc_PROT_WRITE 2
#define sc_PROT_EXEC 4
#define sc_MAP_SHARED 1
#define sc_MAP_PRIVATE 2
#define sc_MAP_FIXED 4
#define sc_MAP_ANONYMOUS 8
/* lseek */
#define sc_SEEK_SET 0
#define sc_SEEK_CUR 1
#define sc_SEEK_END 2
/**
* Enumeration of all the native syscalls
* available in the kernel
*/
typedef enum
{
/**
* This syscall is used to exit the current
* process with the provided exit code.
*
* @fn void exit(int status);
*
* @param Code The exit code
* @return This syscall does not return
*
* @note No permissions are required to call
* this syscall
*/
sc_exit = 0,
/**
* Map pages of memory
*
* @fn void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
*/
sc_mmap,
/**
* Unmap pages of memory
*
* @fn int munmap(void *addr, size_t len);
*/
sc_munmap,
/**
* Change the protection of a page of memory
*
* @fn int mprotect(void *addr, size_t len, int prot);
*/
sc_mprotect,
/**
* Open a file
*
* @fn int open(const char *path, int oflag, ... );
*/
sc_open,
/**
* Close a file descriptor
*
* @fn int close(int fildes);
*/
sc_close,
/**
* Read from a file descriptor
*
* @fn ssize_t read(int fildes, void *buf, size_t nbyte);
*/
sc_read,
/**
* Write to a file descriptor
*
* @fn ssize_t write(int fildes, const void *buf, size_t nbyte);
*/
sc_write,
/**
* Seek to a position in a file descriptor
*
* @fn off_t lseek(int fildes, off_t offset, int whence);
*/
sc_lseek,
/**
* Create a new process
*
* @fn pid_t fork(void);
*/
sc_fork,
/** Not a real syscall */
sc_MaxSyscall
} NativeSyscalls;
#ifndef syscall0
static inline long syscall0(long syscall)
{
long ret;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall)
: "rcx", "r11", "memory");
return ret;
}
#endif
#ifndef syscall1
static inline long syscall1(long syscall, long arg1)
{
long ret;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall), "D"(arg1)
: "rcx", "r11", "memory");
return ret;
}
#endif
#ifndef syscall2
static inline long syscall2(long syscall, long arg1, long arg2)
{
long ret;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall), "D"(arg1), "S"(arg2)
: "rcx", "r11", "memory");
return ret;
}
#endif
#ifndef syscall3
static inline long syscall3(long syscall, long arg1, long arg2, long arg3)
{
long ret;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3)
: "rcx", "r11", "memory");
return ret;
}
#endif
#ifndef syscall4
static inline long syscall4(long syscall, long arg1, long arg2, long arg3, long arg4)
{
long ret;
register long r10 __asm__("r10") = arg4;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10)
: "rcx", "r11", "memory");
return ret;
}
#endif
#ifndef syscall5
static inline long syscall5(long syscall, long arg1, long arg2, long arg3, long arg4, long arg5)
{
long ret;
register long r10 __asm__("r10") = arg4;
register long r8 __asm__("r8") = arg5;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8)
: "rcx", "r11", "memory");
return ret;
}
#endif
#ifndef syscall6
static inline long syscall6(long syscall, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6)
{
long ret;
register long r10 __asm__("r10") = arg4;
register long r8 __asm__("r8") = arg5;
register long r9 __asm__("r9") = arg6;
__asm__ __volatile__("syscall"
: "=a"(ret)
: "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8), "r"(r9)
: "rcx", "r11", "memory");
return ret;
}
#endif
#endif // !__FENNIX_KERNEL_SYSCALLS_LIST_H__

View File

@ -1,3 +1,20 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_TYPES_H__
#define __FENNIX_API_TYPES_H__
@ -37,6 +54,58 @@ typedef __UINTMAX_TYPE__ uintmax_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__ size_t;
typedef __SIZE_TYPE__ dev_t;
typedef __SIZE_TYPE__ off_t;
typedef __INT32_TYPE__ mode_t;
typedef int pid_t;
#define UNUSED(x) (void)(x)
#ifdef __cplusplus
#define EXTERNC extern "C"
#define NULL 0
#else // __cplusplus
#define NULL ((void *)0)
#define bool _Bool
#define EXTERNC
#endif // __cplusplus
#define true 1
#define false 0
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define MAX(a, b) \
({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _a : _b; \
})
#define MIN(a, b) \
({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a < _b ? _a : _b; \
})
#ifndef __va_list__
typedef __builtin_va_list va_list;
#endif
#define asm __asm__
#define asmv __asm__ volatile
#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#define static_assert _Static_assert
#endif
#define va_start(v, l) __builtin_va_start(v, l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v, l) __builtin_va_arg(v, l)
#define TO_PAGES(d) (((d) + PAGE_SIZE - 1) / PAGE_SIZE)
#define FROM_PAGES(d) ((d) * PAGE_SIZE)
#endif // !__FENNIX_API_TYPES_H__

25
include/vm.h Normal file
View File

@ -0,0 +1,25 @@
/*
This file is part of Fennix Drivers.
Fennix Drivers is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Drivers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Drivers. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_API_VM_H__
#define __FENNIX_API_VM_H__
#include <types.h>
bool IsVMwareBackdoorAvailable();
#endif // !__FENNIX_API_VM_H__