mirror of
https://github.com/Fennix-Project/Drivers.git
synced 2025-07-10 22:59:25 +00:00
Fix driver implementation
This commit is contained in:
144
include/aip.h
144
include/aip.h
@ -19,8 +19,6 @@
|
||||
#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)
|
||||
@ -117,7 +115,145 @@ uint8_t PS2ReadAfterACK();
|
||||
void PS2ClearOutputBuffer();
|
||||
int PS2ACKTimeout();
|
||||
|
||||
#define WaitOutput PS2Wait(true)
|
||||
#define WaitInput PS2Wait(false)
|
||||
#define WaitOutput PS2Wait(DriverID, true)
|
||||
#define WaitInput PS2Wait(DriverID, false)
|
||||
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
#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_H__
|
||||
|
@ -1,45 +1,29 @@
|
||||
/*
|
||||
This file is part of Fennix Drivers.
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Drivers is free software: you can redistribute it and/or
|
||||
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 Drivers is distributed in the hope that it will be useful,
|
||||
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 Drivers. If not, see <https://www.gnu.org/licenses/>.
|
||||
along with Fennix Kernel. 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
|
||||
#if __has_include(<interface/device.h>)
|
||||
#include <interface/device.h>
|
||||
#else
|
||||
#include <device.h>
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_API_AUDIO_H__
|
||||
|
@ -77,20 +77,20 @@ extern "C"
|
||||
void UnmapPages(void *VirtualAddress, size_t Pages);
|
||||
|
||||
/**
|
||||
* @brief Print to the screen
|
||||
* @brief Print to the kernel terminal
|
||||
* @param Format The format string
|
||||
* @param ... The arguments to the format string
|
||||
*
|
||||
* @note The newline character is automatically appended
|
||||
*/
|
||||
void KPrint(const char *Format, ...);
|
||||
void KernelPrint(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, ...);
|
||||
void KernelLog(const char *Format, ...);
|
||||
|
||||
/**
|
||||
* @brief Register an interrupt handler
|
||||
@ -241,17 +241,20 @@ extern "C"
|
||||
/** @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); \
|
||||
}
|
||||
#define DriverInfo(_Name, _Description, _Author, _MajorVersion, \
|
||||
_MinorVersion, _PathVersion, _License) \
|
||||
__attribute__((section(".driver.info"))) struct __DriverInfo \
|
||||
__di = {.Name = _Name, \
|
||||
.Description = _Description, \
|
||||
.Author = _Author, \
|
||||
.Version = {.APIVersion = 0, \
|
||||
.Major = _MajorVersion, \
|
||||
.Minor = _MinorVersion, \
|
||||
.Patch = _PathVersion}, \
|
||||
.License = _License}
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DebugLog(m, ...) Log(m, ##__VA_ARGS__)
|
||||
#define DebugLog(m, ...) KernelLog(m, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DebugLog(m, ...)
|
||||
#endif // DEBUG
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
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__
|
74
include/device.h
Normal file
74
include/device.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
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_DEVICE_H__
|
||||
#define __FENNIX_API_DEVICE_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#ifndef __FENNIX_API_FILESYSTEM_H__
|
||||
#if __has_include(<interface/fs.h>)
|
||||
#include <interface/fs.h>
|
||||
#else
|
||||
#include <fs.h>
|
||||
#endif
|
||||
#endif // !__FENNIX_API_FILESYSTEM_H__
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DEVICE_TYPE_MASK = 0b1111111100000000000000000000000000000000,
|
||||
DEVICE_TYPE_NONE = 0b0000000000000000000000000000000000000000,
|
||||
DEVICE_TYPE_INPUT = 0b0000000100000000000000000000000000000000,
|
||||
DEVICE_TYPE_AUDIO = 0b0000001000000000000000000000000000000000,
|
||||
DEVICE_TYPE_NETWORK = 0b0000010000000000000000000000000000000000,
|
||||
DEVICE_TYPE_BLOCK = 0b0000100000000000000000000000000000000000,
|
||||
|
||||
INPUT_TYPE_NONE = DEVICE_TYPE_INPUT + 0,
|
||||
INPUT_TYPE_KEYBOARD = DEVICE_TYPE_INPUT + 2,
|
||||
INPUT_TYPE_MOUSE = DEVICE_TYPE_INPUT + 4,
|
||||
INPUT_TYPE_JOYSTICK = DEVICE_TYPE_INPUT + 8,
|
||||
INPUT_TYPE_TOUCHSCREEN = DEVICE_TYPE_INPUT + 16,
|
||||
INPUT_TYPE_GAMEPAD = DEVICE_TYPE_INPUT + 32,
|
||||
INPUT_TYPE_ACCELEROMETER = DEVICE_TYPE_INPUT + 64,
|
||||
INPUT_TYPE_GYROSCOPE = DEVICE_TYPE_INPUT + 128,
|
||||
INPUT_TYPE_MAGNETOMETER = DEVICE_TYPE_INPUT + 256,
|
||||
|
||||
AUDIO_TYPE_NONE = DEVICE_TYPE_AUDIO + 0,
|
||||
AUDIO_TYPE_PWM = DEVICE_TYPE_AUDIO + 2,
|
||||
AUDIO_TYPE_DSP = DEVICE_TYPE_AUDIO + 4,
|
||||
AUDIO_TYPE_PCM = DEVICE_TYPE_AUDIO + 8,
|
||||
AUDIO_TYPE_MIDI = DEVICE_TYPE_AUDIO + 16,
|
||||
|
||||
NETWORK_TYPE_NONE = DEVICE_TYPE_NETWORK + 0,
|
||||
NETWORK_TYPE_ETHERNET = DEVICE_TYPE_NETWORK + 2,
|
||||
NETWORK_TYPE_WIFI = DEVICE_TYPE_NETWORK + 4,
|
||||
NETWORK_TYPE_BLUETOOTH = DEVICE_TYPE_NETWORK + 8,
|
||||
|
||||
BLOCK_TYPE_NONE = DEVICE_TYPE_BLOCK + 0,
|
||||
BLOCK_TYPE_SDCARD = DEVICE_TYPE_BLOCK + 2,
|
||||
BLOCK_TYPE_HDD = DEVICE_TYPE_BLOCK + 4,
|
||||
BLOCK_TYPE_SSD = DEVICE_TYPE_BLOCK + 8,
|
||||
BLOCK_TYPE_USB = DEVICE_TYPE_BLOCK + 16,
|
||||
BLOCK_TYPE_NVME = DEVICE_TYPE_BLOCK + 32,
|
||||
BLOCK_TYPE_CDROM = DEVICE_TYPE_BLOCK + 64,
|
||||
BLOCK_TYPE_FLOPPY = DEVICE_TYPE_BLOCK + 128,
|
||||
} DeviceType;
|
||||
|
||||
EXTERNC dev_t RegisterDevice(DeviceType Type, const struct InodeOperations *Operations);
|
||||
EXTERNC int UnregisterDevice(dev_t Device);
|
||||
|
||||
#endif // !__FENNIX_API_DEVICE_H__
|
289
include/driver.h
289
include/driver.h
@ -20,30 +20,6 @@
|
||||
|
||||
#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;
|
||||
@ -57,177 +33,22 @@ typedef struct
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_1,
|
||||
KEY_2,
|
||||
KEY_3,
|
||||
KEY_4,
|
||||
KEY_5,
|
||||
KEY_6,
|
||||
KEY_7,
|
||||
KEY_8,
|
||||
KEY_9,
|
||||
KEY_0,
|
||||
IOCTL_AUDIO_GET_VOLUME = 0,
|
||||
IOCTL_AUDIO_SET_VOLUME = 1,
|
||||
|
||||
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,
|
||||
IOCTL_AUDIO_GET_MUTE = 2,
|
||||
IOCTL_AUDIO_SET_MUTE = 3,
|
||||
|
||||
KEY_F1,
|
||||
KEY_F2,
|
||||
KEY_F3,
|
||||
KEY_F4,
|
||||
KEY_F5,
|
||||
KEY_F6,
|
||||
KEY_F7,
|
||||
KEY_F8,
|
||||
KEY_F9,
|
||||
KEY_F10,
|
||||
KEY_F11,
|
||||
KEY_F12,
|
||||
IOCTL_AUDIO_GET_SAMPLE_RATE = 4,
|
||||
IOCTL_AUDIO_SET_SAMPLE_RATE = 5,
|
||||
|
||||
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,
|
||||
IOCTL_AUDIO_GET_CHANNELS = 6,
|
||||
IOCTL_AUDIO_SET_CHANNELS = 7,
|
||||
} AudioIoctl;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IOCTL_NET_GET_MAC,
|
||||
IOCTL_NET_GET_MAC = 0,
|
||||
} NetIoctl;
|
||||
|
||||
typedef enum
|
||||
@ -239,89 +60,17 @@ typedef enum
|
||||
MAP_CACHE_DISABLE = 1 << 4,
|
||||
} PageMapFlags;
|
||||
|
||||
typedef struct
|
||||
struct __DriverInfo
|
||||
{
|
||||
struct
|
||||
const char *Name;
|
||||
const char *Description;
|
||||
const char *Author;
|
||||
struct __DriverVersion
|
||||
{
|
||||
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);
|
||||
pid_t (*GetCurrentProcess)(dev_t MajorID);
|
||||
int (*KillProcess)(dev_t MajorID, pid_t pId, int ExitCode);
|
||||
int (*KillThread)(dev_t MajorID, pid_t tId, pid_t pId, 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;
|
||||
int APIVersion;
|
||||
int Major, Minor, Patch;
|
||||
} Version;
|
||||
const char *License;
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_API_DRIVER_FUNCTIONS_H__
|
||||
|
986
include/errno.h
986
include/errno.h
@ -1,408 +1,604 @@
|
||||
/*
|
||||
This file is part of Fennix Drivers.
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Drivers is free software: you can redistribute it and/or
|
||||
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 Drivers is distributed in the hope that it will be useful,
|
||||
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 Drivers. If not, see <https://www.gnu.org/licenses/>.
|
||||
along with Fennix Kernel. 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
|
||||
#ifndef __FENNIX_KERNEL_ERRNO_H__
|
||||
#define __FENNIX_KERNEL_ERRNO_H__
|
||||
|
||||
/**
|
||||
* The documentation for these error codes are from:
|
||||
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html
|
||||
*
|
||||
* Full list:
|
||||
* https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/basedefs/errno.h.html
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/**
|
||||
* No Error
|
||||
*/
|
||||
EOK = 0,
|
||||
|
||||
/**
|
||||
* Argument list too long. The sum of the number of bytes used by the
|
||||
* new process image's argument list and environment list is greater
|
||||
* than the system-imposed limit of {ARG_MAX} bytes.
|
||||
* or:
|
||||
* Lack of space in an output buffer.
|
||||
* or:
|
||||
* Argument is greater than the system-imposed maximum.
|
||||
*/
|
||||
E2BIG = 1,
|
||||
|
||||
/**
|
||||
* Permission denied. An attempt was made to access a file in a way
|
||||
* forbidden by its file access permissions.
|
||||
*/
|
||||
EACCES = 2,
|
||||
|
||||
/**
|
||||
* Address in use. The specified address is in use.
|
||||
*/
|
||||
EADDRINUSE = 3,
|
||||
|
||||
/**
|
||||
* Address not available. The specified address is not available from
|
||||
* the local system.
|
||||
*/
|
||||
EADDRNOTAVAIL = 4,
|
||||
|
||||
/**
|
||||
* Address family not supported. The implementation does not support
|
||||
* the specified address family, or the specified address is not a
|
||||
* valid address for the address family of the specified socket.
|
||||
*/
|
||||
EAFNOSUPPORT = 5,
|
||||
|
||||
/**
|
||||
* Resource temporarily unavailable. This is a temporary condition
|
||||
* and later calls to the same routine may complete normally.
|
||||
*/
|
||||
EAGAIN = 6,
|
||||
|
||||
/**
|
||||
* Connection already in progress. A connection request is already in
|
||||
* progress for the specified socket.
|
||||
*/
|
||||
EALREADY = 7,
|
||||
|
||||
/**
|
||||
* Bad file descriptor. A file descriptor argument is out of range,
|
||||
* refers to no open file, or a read (write) request is made to a
|
||||
* file that is only open for writing (reading).
|
||||
*/
|
||||
EBADF = 8,
|
||||
|
||||
/**
|
||||
* Bad message. During a read(), getmsg(), getpmsg(), or ioctl()
|
||||
* I_RECVFD request to a STREAMS device, a message arrived at the
|
||||
* head of the STREAM that is inappropriate for the function
|
||||
* receiving the message.
|
||||
* read()
|
||||
* Message waiting to be read on a STREAM is not a data message.
|
||||
* getmsg() or getpmsg()
|
||||
* A file descriptor was received instead of a control message.
|
||||
* ioctl()
|
||||
* Control or data information was received instead of a file
|
||||
* descriptor when I_RECVFD was specified.
|
||||
*/
|
||||
EBADMSG = 9,
|
||||
|
||||
/**
|
||||
* Resource busy. An attempt was made to make use of a system
|
||||
* resource that is not currently available, as it is being
|
||||
* used by another process in a manner that would have
|
||||
* conflicted with the request being made by this process.
|
||||
*/
|
||||
EBUSY = 10,
|
||||
|
||||
/**
|
||||
* Operation canceled. The associated asynchronous operation was
|
||||
* canceled before completion.
|
||||
*/
|
||||
ECANCELED = 11,
|
||||
|
||||
/**
|
||||
* No child process. A wait(), waitid(), or waitpid() function was
|
||||
* executed by a process that had no existing or unwaited-for
|
||||
* child process.
|
||||
*/
|
||||
ECHILD = 12,
|
||||
|
||||
/**
|
||||
* Connection aborted. The connection has been aborted.
|
||||
*/
|
||||
ECONNABORTED = 13,
|
||||
|
||||
/**
|
||||
* Connection refused. An attempt to connect to a socket was refused
|
||||
* because there was no process listening or because the queue of
|
||||
* connection requests was full and the underlying protocol does not
|
||||
* support retransmissions.
|
||||
*/
|
||||
ECONNREFUSED = 14,
|
||||
|
||||
/**
|
||||
* Connection reset. The connection was forcibly closed by the peer.
|
||||
*/
|
||||
ECONNRESET = 15,
|
||||
|
||||
/**
|
||||
* Resource deadlock would occur. An attempt was made to lock a system
|
||||
* resource that would have resulted in a deadlock situation.
|
||||
*/
|
||||
EDEADLK = 16,
|
||||
|
||||
/**
|
||||
* Destination address required. No bind address was established.
|
||||
*/
|
||||
EDESTADDRREQ = 17,
|
||||
|
||||
/**
|
||||
* Domain error. An input argument is outside the defined domain of the
|
||||
* mathematical function (defined in the ISO C standard).
|
||||
*/
|
||||
EDOM = 18,
|
||||
|
||||
/**
|
||||
* Reserved.
|
||||
*/
|
||||
EDQUOT = 19,
|
||||
|
||||
/**
|
||||
* File exists. An existing file was mentioned in an inappropriate
|
||||
* context; for example, as a new link name in the link() function.
|
||||
*/
|
||||
EEXIST = 20,
|
||||
|
||||
/**
|
||||
* Bad address. The system detected an invalid address in attempting
|
||||
* to use an argument of a call. The reliable detection of this error
|
||||
* cannot be guaranteed, and when not detected may result in the
|
||||
* generation of a signal, indicating an address violation, which is
|
||||
* sent to the process.
|
||||
*/
|
||||
EFAULT = 21,
|
||||
|
||||
/**
|
||||
* File too large. The size of a file would exceed the maximum file
|
||||
* size of an implementation or offset maximum established in the
|
||||
* corresponding file description.
|
||||
*/
|
||||
EFBIG = 22,
|
||||
|
||||
/**
|
||||
* Host is unreachable. The destination host cannot be reached
|
||||
* (probably because the host is down or a remote router cannot
|
||||
* reach it).
|
||||
*/
|
||||
EHOSTUNREACH = 23,
|
||||
|
||||
/**
|
||||
* Identifier removed. Returned during XSI interprocess communication
|
||||
* if an identifier has been removed from the system.
|
||||
*/
|
||||
EIDRM = 24,
|
||||
|
||||
/**
|
||||
* Illegal byte sequence. A wide-character code has been detected that
|
||||
* does not correspond to a valid character, or a byte sequence does
|
||||
* not form a valid wide-character code (defined in the ISO C standard).
|
||||
*/
|
||||
EILSEQ = 25,
|
||||
|
||||
/**
|
||||
* Operation in progress. This code is used to indicate that an
|
||||
* asynchronous operation has not yet completed.
|
||||
* or:
|
||||
* O_NONBLOCK is set for the socket file descriptor and the connection
|
||||
* cannot be immediately established.
|
||||
*/
|
||||
EINPROGRESS = 26,
|
||||
|
||||
/**
|
||||
* Interrupted function call. An asynchronous signal was caught by the
|
||||
* process during the execution of an interruptible function. If the
|
||||
* signal handler performs a normal return, the interrupted function
|
||||
* call may return this condition (see the Base Definitions volume
|
||||
* of POSIX.1-2017, <signal.h>).
|
||||
*/
|
||||
EINTR = 27,
|
||||
|
||||
/**
|
||||
* Invalid argument. Some invalid argument was supplied; for example,
|
||||
* specifying an undefined signal in a signal() function or a
|
||||
* kill() function.
|
||||
*/
|
||||
EINVAL = 28,
|
||||
|
||||
/**
|
||||
* Input/output error. Some physical input or output error has occurred.
|
||||
* This error may be reported on a subsequent operation on the same
|
||||
* file descriptor. Any other error-causing operation on the same file
|
||||
* descriptor may cause the [EIO] error indication to be lost.
|
||||
*/
|
||||
EIO = 29,
|
||||
|
||||
/**
|
||||
* Socket is connected. The specified socket is already connected.
|
||||
*/
|
||||
EISCONN = 30,
|
||||
|
||||
/**
|
||||
* Is a directory. An attempt was made to open a directory with write
|
||||
* mode specified.
|
||||
*/
|
||||
EISDIR = 31,
|
||||
|
||||
/**
|
||||
* Symbolic link loop. A loop exists in symbolic links encountered
|
||||
* during pathname resolution. This error may also be returned if
|
||||
* more than {SYMLOOP_MAX} symbolic links are encountered during
|
||||
* pathname resolution.
|
||||
*/
|
||||
ELOOP = 32,
|
||||
|
||||
/**
|
||||
* File descriptor value too large or too many open streams. An
|
||||
* attempt was made to open a file descriptor with a value greater
|
||||
* than or equal to {OPEN_MAX}, or an attempt was made to open more
|
||||
* than the maximum number of streams allowed in the process.
|
||||
*/
|
||||
EMFILE = 33,
|
||||
|
||||
/**
|
||||
* Too many links. An attempt was made to have the link count of a
|
||||
* single file exceed {LINK_MAX}.
|
||||
*/
|
||||
EMLINK = 34,
|
||||
|
||||
/**
|
||||
* Message too large. A message sent on a transport provider was
|
||||
* larger than an internal message buffer or some other network limit.
|
||||
* or:
|
||||
* Inappropriate message buffer length.
|
||||
*/
|
||||
EMSGSIZE = 35,
|
||||
|
||||
/**
|
||||
* Reserved.
|
||||
*/
|
||||
EMULTIHOP = 36,
|
||||
|
||||
/**
|
||||
* Filename too long. The length of a pathname exceeds {PATH_MAX} and
|
||||
* the implementation considers this to be an error, or a pathname
|
||||
* component is longer than {NAME_MAX}. This error may also occur
|
||||
* when pathname substitution, as a result of encountering a
|
||||
* symbolic link during pathname resolution, results in a pathname
|
||||
* string the size of which exceeds {PATH_MAX}.
|
||||
*/
|
||||
ENAMETOOLONG = 37,
|
||||
|
||||
/**
|
||||
* Network is down. The local network interface used to reach the
|
||||
* destination is down.
|
||||
*/
|
||||
ENETDOWN = 38,
|
||||
|
||||
/**
|
||||
* The connection was aborted by the network.
|
||||
*/
|
||||
ENETRESET = 39,
|
||||
|
||||
/**
|
||||
* Network unreachable. No route to the network is present.
|
||||
*/
|
||||
ENETUNREACH = 40,
|
||||
|
||||
/**
|
||||
* Too many files open in system. Too many files are currently open
|
||||
* in the system. The system has reached its predefined limit for
|
||||
* simultaneously open files and temporarily cannot accept requests
|
||||
* to open another one.
|
||||
*/
|
||||
ENFILE = 41,
|
||||
|
||||
/**
|
||||
* No buffer space available. Insufficient buffer resources were
|
||||
* available in the system to perform the socket operation.
|
||||
*/
|
||||
ENOBUFS = 42,
|
||||
|
||||
/**
|
||||
* No message available. No message is available on the STREAM head
|
||||
* read queue.
|
||||
*/
|
||||
ENODATA = 43,
|
||||
|
||||
/**
|
||||
* No such device. An attempt was made to apply an inappropriate
|
||||
* function to a device; for example, trying to read a write-only
|
||||
* device such as a printer.
|
||||
*/
|
||||
ENODEV = 44,
|
||||
|
||||
/**
|
||||
* No such file or directory. A component of a specified pathname
|
||||
* does not exist, or the pathname is an empty string.
|
||||
*/
|
||||
ENOENT = 45,
|
||||
|
||||
/**
|
||||
* Executable file format error. A request is made to execute a file
|
||||
* that, although it has appropriate privileges, is not in the
|
||||
* format required by the implementation for executable files.
|
||||
*/
|
||||
ENOEXEC = 46,
|
||||
|
||||
/**
|
||||
* No locks available. A system-imposed limit on the number of
|
||||
* simultaneous file and record locks has been reached and no more
|
||||
* are currently available.
|
||||
*/
|
||||
ENOLCK = 47,
|
||||
|
||||
/**
|
||||
* Reserved.
|
||||
*/
|
||||
ENOLINK = 48,
|
||||
|
||||
/**
|
||||
* Not enough space. The new process image requires more memory than
|
||||
* is allowed by the hardware or system-imposed memory management
|
||||
* constraints.
|
||||
*/
|
||||
ENOMEM = 49,
|
||||
|
||||
/**
|
||||
* No message of the desired type. The message queue does not contain
|
||||
* a message of the required type during XSI interprocess communication.
|
||||
*/
|
||||
ENOMSG = 50,
|
||||
|
||||
/**
|
||||
* Protocol not available. The protocol option specified to
|
||||
* setsockopt() is not supported by the implementation.
|
||||
*/
|
||||
ENOPROTOOPT = 51,
|
||||
|
||||
/**
|
||||
* No space left on a device. During the write() function on a
|
||||
* regular file or when extending a directory, there is no free
|
||||
* space left on the device.
|
||||
*/
|
||||
ENOSPC = 52,
|
||||
|
||||
/**
|
||||
* No STREAM resources. Insufficient STREAMS memory resources are
|
||||
* available to perform a STREAMS-related function. This is a
|
||||
* temporary condition; it may be recovered from if other
|
||||
* processes release resources.
|
||||
*/
|
||||
ENOSR = 53,
|
||||
|
||||
/**
|
||||
* Not a STREAM. A STREAM function was attempted on a file descriptor
|
||||
* that was not associated with a STREAMS device.
|
||||
*/
|
||||
ENOSTR = 54,
|
||||
|
||||
/**
|
||||
* Functionality not supported. An attempt was made to use optional
|
||||
* functionality that is not supported in this implementation.
|
||||
*/
|
||||
ENOSYS = 55,
|
||||
|
||||
/**
|
||||
* Socket not connected. The socket is not connected.
|
||||
*/
|
||||
ENOTCONN = 56,
|
||||
|
||||
/**
|
||||
* Not a directory. A component of the specified pathname exists, but
|
||||
* it is not a directory, when a directory was expected; or an
|
||||
* attempt was made to create a non-directory file, and the specified
|
||||
* pathname contains at least one non- <slash> character and ends
|
||||
* with one or more trailing <slash> characters.
|
||||
*/
|
||||
ENOTDIR = 57,
|
||||
|
||||
/**
|
||||
* Directory not empty. A directory other than an empty directory
|
||||
* was supplied when an empty directory was expected.
|
||||
*/
|
||||
ENOTEMPTY = 58,
|
||||
|
||||
/**
|
||||
* State not recoverable. The state protected by a robust mutex
|
||||
* is not recoverable.
|
||||
*/
|
||||
ENOTRECOVERABLE = 59,
|
||||
|
||||
/**
|
||||
* Not a socket. The file descriptor does not refer to a socket.
|
||||
*/
|
||||
ENOTSOCK = 60,
|
||||
|
||||
/**
|
||||
* Not supported. The implementation does not support the requested
|
||||
* feature or value.
|
||||
*/
|
||||
ENOTSUP = 61,
|
||||
|
||||
/**
|
||||
* Inappropriate I/O control operation. A control function has been
|
||||
* attempted for a file or special file for which the operation
|
||||
* is inappropriate.
|
||||
*/
|
||||
ENOTTY = 62,
|
||||
|
||||
/**
|
||||
* No such device or address. Input or output on a special file
|
||||
* refers to a device that does not exist, or makes a request
|
||||
* beyond the capabilities of the device. It may also occur when,
|
||||
* for example, a tape drive is not on-line.
|
||||
*/
|
||||
ENXIO = 63,
|
||||
|
||||
/**
|
||||
* Operation not supported on socket. The type of socket (address
|
||||
* family or protocol) does not support the requested operation.
|
||||
*/
|
||||
EOPNOTSUPP = 64,
|
||||
|
||||
/**
|
||||
* Value too large to be stored in data type. An operation was
|
||||
* attempted which would generate a value that is outside the
|
||||
* range of values that can be represented in the relevant data
|
||||
* type or that are allowed for a given data item.
|
||||
*/
|
||||
EOVERFLOW = 65,
|
||||
|
||||
/**
|
||||
* Previous owner died. The owner of a robust mutex terminated
|
||||
* while holding the mutex lock.
|
||||
*/
|
||||
EOWNERDEAD = 66,
|
||||
|
||||
/**
|
||||
* Operation not permitted. An attempt was made to perform an
|
||||
* operation limited to processes with appropriate privileges or
|
||||
* to the owner of a file or other resource.
|
||||
*/
|
||||
EPERM = 67,
|
||||
|
||||
/**
|
||||
* Broken pipe. A write was attempted on a socket, pipe, or FIFO
|
||||
* for which there is no process to read the data.
|
||||
*/
|
||||
EPIPE = 68,
|
||||
|
||||
/**
|
||||
* Protocol error. Some protocol error occurred. This error is
|
||||
* device-specific, but is generally not related to a
|
||||
* hardware failure.
|
||||
*/
|
||||
EPROTO = 69,
|
||||
|
||||
/**
|
||||
* Protocol not supported. The protocol is not supported by the
|
||||
* address family, or the protocol is not supported by
|
||||
* the implementation.
|
||||
*/
|
||||
EPROTONOSUPPORT = 70,
|
||||
|
||||
/**
|
||||
* Protocol wrong type for socket. The socket type is not
|
||||
* supported by the protocol.
|
||||
*/
|
||||
EPROTOTYPE = 71,
|
||||
|
||||
/**
|
||||
* Result too large or too small. The result of the function
|
||||
* is too large (overflow) or too small (underflow) to be
|
||||
* represented in the available space.
|
||||
*/
|
||||
ERANGE = 72,
|
||||
|
||||
/**
|
||||
* Read-only file system. An attempt was made to modify a file
|
||||
* or directory on a file system that is read-only.
|
||||
*/
|
||||
EROFS = 73,
|
||||
|
||||
/**
|
||||
* Invalid seek. An attempt was made to access the file offset
|
||||
* associated with a pipe or FIFO.
|
||||
*/
|
||||
ESPIPE = 74,
|
||||
|
||||
/**
|
||||
* No such process. No process can be found corresponding to that
|
||||
* specified by the given process ID.
|
||||
*/
|
||||
ESRCH = 75,
|
||||
|
||||
/**
|
||||
* Reserved.
|
||||
*/
|
||||
ESTALE = 76,
|
||||
|
||||
/**
|
||||
* STREAM ioctl() timeout. The timer set for a STREAMS ioctl() call
|
||||
* has expired. The cause of this error is device-specific and could
|
||||
* indicate either a hardware or software failure, or a timeout
|
||||
* value that is too short for the specific operation. The status
|
||||
* of the ioctl() operation is unspecified.
|
||||
*/
|
||||
ETIME = 77,
|
||||
|
||||
/**
|
||||
* Connection timed out. The connection to a remote machine has
|
||||
* timed out.
|
||||
* If the connection timed out during execution of the function that
|
||||
* reported this error (as opposed to timing out prior to the
|
||||
* function being called), it is unspecified whether the function
|
||||
* has completed some or all of the documented behavior associated
|
||||
* with a successful completion of the function.
|
||||
* or:
|
||||
* Operation timed out. The time limit associated with the operation
|
||||
* was exceeded before the operation completed.
|
||||
*/
|
||||
ETIMEDOUT = 78,
|
||||
|
||||
/**
|
||||
* Text file busy. An attempt was made to execute a pure-procedure
|
||||
* program that is currently open for writing, or an attempt has
|
||||
* been made to open for writing a pure-procedure program that
|
||||
* is being executed.
|
||||
*/
|
||||
ETXTBSY = 79,
|
||||
|
||||
/**
|
||||
* Operation would block. An operation on a socket marked as
|
||||
* non-blocking has encountered a situation such as no data available
|
||||
* that otherwise would have caused the function to suspend execution.
|
||||
*/
|
||||
EWOULDBLOCK = 80,
|
||||
|
||||
/**
|
||||
* Improper link. A link to a file on another file system was attempted.
|
||||
*/
|
||||
EXDEV = 81,
|
||||
|
||||
__ERRNO_MAX
|
||||
} KernelErrors;
|
||||
|
||||
#include <types.h>
|
||||
EXTERNC int *__errno_location(void) __attribute__((const));
|
||||
#define errno (*__errno_location())
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
char *strerror(int errnum);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ERRNO_H__
|
||||
|
380
include/fs.h
Normal file
380
include/fs.h
Normal file
@ -0,0 +1,380 @@
|
||||
/*
|
||||
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_FILESYSTEM_H__
|
||||
#define __FENNIX_API_FILESYSTEM_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
/**
|
||||
* File type mask for the upper 32 bits of mode_t.
|
||||
*
|
||||
* @note Maybe it will be used in the future.
|
||||
*/
|
||||
#define S_IFMT32 037777600000
|
||||
|
||||
/**
|
||||
* File type mask.
|
||||
*
|
||||
* This mask is used to extract the file type
|
||||
* from the mode field of a stat structure.
|
||||
*
|
||||
* Doing bitwise AND with this mask will return
|
||||
* the file type.
|
||||
* Example: st_mode & S_IFMT
|
||||
*
|
||||
* Doing bitwise negation and AND with this mask
|
||||
* will return the permissions.
|
||||
* Example: st_mode & ~S_IFMT
|
||||
*/
|
||||
#define S_IFMT 0170000
|
||||
|
||||
/* Whiteout */
|
||||
#define S_IFWHT 0160000
|
||||
/* Socket */
|
||||
#define S_IFSOCK 0140000
|
||||
/* Symbolic link */
|
||||
#define S_IFLNK 0120000
|
||||
/* Regular file */
|
||||
#define S_IFREG 0100000
|
||||
/* Block device */
|
||||
#define S_IFBLK 0060000
|
||||
/* Directory */
|
||||
#define S_IFDIR 0040000
|
||||
/* Character device */
|
||||
#define S_IFCHR 0020000
|
||||
/* FIFO */
|
||||
#define S_IFIFO 0010000
|
||||
|
||||
#define S_ISUID 04000
|
||||
#define S_ISGID 02000
|
||||
#define S_ISVTX 01000
|
||||
|
||||
/** Owner: RWX */
|
||||
#define S_IRWXU 0700
|
||||
/** Owner: R */
|
||||
#define S_IRUSR 0400
|
||||
/** Owner: W */
|
||||
#define S_IWUSR 0200
|
||||
/** Owner: X */
|
||||
#define S_IXUSR 0100
|
||||
|
||||
/** Group: RWX */
|
||||
#define S_IRWXG 0070
|
||||
/** Group: R */
|
||||
#define S_IRGRP 0040
|
||||
/** Group: W */
|
||||
#define S_IWGRP 0020
|
||||
/** Group: X */
|
||||
#define S_IXGRP 0010
|
||||
|
||||
/** Other: RWX */
|
||||
#define S_IRWXO 0007
|
||||
/** Other: R */
|
||||
#define S_IROTH 0004
|
||||
/** Other: W */
|
||||
#define S_IWOTH 0002
|
||||
/** Other: X */
|
||||
#define S_IXOTH 0001
|
||||
|
||||
#define O_RDONLY 00
|
||||
#define O_WRONLY 01
|
||||
#define O_RDWR 02
|
||||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NOFOLLOW 0400000
|
||||
#define O_CLOEXEC 02000000
|
||||
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
|
||||
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
||||
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
|
||||
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
|
||||
|
||||
#define DT_UNKNOWN 0x0
|
||||
#define DT_FIFO 0x1
|
||||
#define DT_CHR 0x2
|
||||
#define DT_DIR 0x4
|
||||
#define DT_BLK 0x6
|
||||
#define DT_REG 0x8
|
||||
#define DT_LNK 0xA
|
||||
#define DT_SOCK 0xC
|
||||
#define DT_WHT 0xE
|
||||
|
||||
#define IFTODT(x) ((x) >> 12 & 0xF)
|
||||
#define DTTOIF(x) ((x) << 12)
|
||||
|
||||
#define SYMLOOP_MAX 40
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#ifdef __LP64__
|
||||
static_assert(sizeof(dev_t) == 8, "dev_t must be 64 bits");
|
||||
static_assert(sizeof(ino_t) == 8, "ino_t must be 64 bits");
|
||||
static_assert(sizeof(mode_t) == 4, "mode_t must be 32 bits");
|
||||
static_assert(sizeof(nlink_t) == 4, "nlink_t must be 32 bits");
|
||||
static_assert(sizeof(uid_t) == 4, "uid_t must be 32 bits");
|
||||
static_assert(sizeof(gid_t) == 4, "gid_t must be 32 bits");
|
||||
static_assert(sizeof(off_t) == 8, "off_t must be 64 bits");
|
||||
static_assert(sizeof(time_t) == 8, "time_t must be 64 bits");
|
||||
static_assert(sizeof(blksize_t) == 8, "blksize_t must be 64 bits");
|
||||
static_assert(sizeof(blkcnt_t) == 8, "blkcnt_t must be 64 bits");
|
||||
#else
|
||||
static_assert(sizeof(dev_t) == 4, "dev_t must be 32 bits");
|
||||
static_assert(sizeof(ino_t) == 4, "ino_t must be 32 bits");
|
||||
static_assert(sizeof(mode_t) == 2, "mode_t must be 16 bits");
|
||||
static_assert(sizeof(nlink_t) == 2, "nlink_t must be 16 bits");
|
||||
static_assert(sizeof(uid_t) == 2, "uid_t must be 16 bits");
|
||||
static_assert(sizeof(gid_t) == 2, "gid_t must be 16 bits");
|
||||
static_assert(sizeof(off_t) == 4, "off_t must be 32 bits");
|
||||
static_assert(sizeof(time_t) == 4, "time_t must be 32 bits");
|
||||
static_assert(sizeof(blksize_t) == 4, "blksize_t must be 32 bits");
|
||||
static_assert(sizeof(blkcnt_t) == 4, "blkcnt_t must be 32 bits");
|
||||
#endif
|
||||
|
||||
#undef static_assert
|
||||
|
||||
struct kstat
|
||||
{
|
||||
/** Device ID of the file. */
|
||||
dev_t Device;
|
||||
|
||||
/** Inode number. */
|
||||
ino_t Index;
|
||||
|
||||
/** File type and mode. */
|
||||
mode_t Mode;
|
||||
|
||||
/** Number of hard links. */
|
||||
nlink_t HardLinks;
|
||||
|
||||
/** User ID of the file's owner. */
|
||||
uid_t UserID;
|
||||
|
||||
/** Group ID of the file's owner. */
|
||||
gid_t GroupID;
|
||||
|
||||
/** Device ID for special files. */
|
||||
dev_t RawDevice;
|
||||
|
||||
/** Size of the file in bytes. */
|
||||
off_t Size;
|
||||
|
||||
/** Time of last access. */
|
||||
time_t AccessTime;
|
||||
|
||||
/** Time of last modification. */
|
||||
time_t ModifyTime;
|
||||
|
||||
/** Time of last status change. */
|
||||
time_t ChangeTime;
|
||||
|
||||
/** Optimal I/O block size. */
|
||||
blksize_t BlockSize;
|
||||
|
||||
/** Number of blocks allocated. */
|
||||
blkcnt_t Blocks;
|
||||
|
||||
/** Additional file attributes. */
|
||||
mode_t Attribute;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
dev_t MakeDevice(int Major, int Minor)
|
||||
{
|
||||
return ((Major & 0xFFF) << 8) |
|
||||
(Minor & 0xFF);
|
||||
}
|
||||
|
||||
int GetMajor()
|
||||
{
|
||||
return ((unsigned int)(Device) >> 8) & 0xFFF;
|
||||
}
|
||||
|
||||
int GetMinor()
|
||||
{
|
||||
return Device & 0xFF;
|
||||
}
|
||||
|
||||
void SetFileType(mode_t Type)
|
||||
{
|
||||
Mode = (Mode & ~S_IFMT) |
|
||||
(Type & S_IFMT);
|
||||
}
|
||||
|
||||
mode_t GetFileType() { return Mode & S_IFMT; }
|
||||
void ClearFileType() { Mode = Mode & ~S_IFMT; }
|
||||
bool IsType(mode_t Type) { return (Mode & S_IFMT) == Type; }
|
||||
|
||||
void SetPermissions(mode_t Permissions)
|
||||
{
|
||||
Mode = (Mode & S_IFMT) |
|
||||
(Permissions & ~S_IFMT);
|
||||
}
|
||||
|
||||
mode_t GetPermissions() { return Mode & ~S_IFMT; }
|
||||
void ClearPermissions() { Mode = Mode & S_IFMT; }
|
||||
|
||||
#endif // __cplusplus
|
||||
};
|
||||
|
||||
struct kdirent
|
||||
{
|
||||
ino_t d_ino;
|
||||
off_t d_off;
|
||||
unsigned short d_reclen;
|
||||
unsigned char d_type;
|
||||
char d_name[];
|
||||
};
|
||||
|
||||
struct Inode
|
||||
{
|
||||
dev_t Device, RawDevice;
|
||||
ino_t Index;
|
||||
mode_t Mode;
|
||||
uint32_t Flags;
|
||||
off_t Offset;
|
||||
|
||||
void *PrivateData;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/* ... */
|
||||
|
||||
void SetDevice(int Major, int Minor)
|
||||
{
|
||||
this->RawDevice = ((Major & 0xFFF) << 8) |
|
||||
(Minor & 0xFF);
|
||||
}
|
||||
|
||||
int GetMajor()
|
||||
{
|
||||
return ((unsigned int)(this->RawDevice) >> 8) & 0xFFF;
|
||||
}
|
||||
|
||||
int GetMinor()
|
||||
{
|
||||
return this->RawDevice & 0xFF;
|
||||
}
|
||||
|
||||
Inode()
|
||||
{
|
||||
Device = 0;
|
||||
RawDevice = 0;
|
||||
Index = 0;
|
||||
Mode = 0;
|
||||
Flags = 0;
|
||||
Offset = 0;
|
||||
PrivateData = nullptr;
|
||||
}
|
||||
|
||||
~Inode() = default;
|
||||
|
||||
#else // __cplusplus
|
||||
|
||||
#define INODE_MAKEDEV(major, minor) \
|
||||
((dev_t)(((major & 0xFFF) << 8) | \
|
||||
(minor & 0xFF)))
|
||||
|
||||
#define INODE_MAJOR(rdev) \
|
||||
((int)(((rdev) >> 8) & 0xFFF))
|
||||
|
||||
#define INODE_MINOR(rdev) \
|
||||
((int)((rdev) & 0xFF))
|
||||
|
||||
#endif // __cplusplus
|
||||
};
|
||||
|
||||
struct InodeOperations
|
||||
{
|
||||
int (*Lookup)(struct Inode *Parent, const char *Name, struct Inode **Result);
|
||||
int (*Create)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result);
|
||||
int (*Remove)(struct Inode *Parent, const char *Name);
|
||||
int (*Rename)(struct Inode *Parent, const char *OldName, const char *NewName);
|
||||
ssize_t (*Read)(struct Inode *Node, void *Buffer, size_t Size, off_t Offset);
|
||||
ssize_t (*Write)(struct Inode *Node, const void *Buffer, size_t Size, off_t Offset);
|
||||
int (*Truncate)(struct Inode *Node, off_t Size);
|
||||
int (*Open)(struct Inode *Node, int Flags, mode_t Mode);
|
||||
int (*Close)(struct Inode *Node);
|
||||
int (*Ioctl)(struct Inode *Node, unsigned long Request, void *Argp);
|
||||
ssize_t (*ReadDir)(struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries);
|
||||
int (*MkDir)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result);
|
||||
int (*RmDir)(struct Inode *Parent, const char *Name);
|
||||
int (*SymLink)(struct Inode *Parent, const char *Name, const char *Target, struct Inode **Result);
|
||||
ssize_t (*ReadLink)(struct Inode *Node, char *Buffer, size_t Size);
|
||||
off_t (*Seek)(struct Inode *Node, off_t Offset);
|
||||
int (*Stat)(struct Inode *Node, struct kstat *Stat);
|
||||
} __attribute__((packed));
|
||||
|
||||
#define I_FLAG_ROOT 0x1
|
||||
#define I_FLAG_MOUNTPOINT 0x2
|
||||
#define I_FLAG_CACHE_KEEP 0x4
|
||||
|
||||
struct FileSystemInfo;
|
||||
struct SuperBlockOperations
|
||||
{
|
||||
int (*AllocateInode)(struct FileSystemInfo *Info, struct Inode **Result);
|
||||
int (*DeleteInode)(struct FileSystemInfo *Info, struct Inode *Node);
|
||||
|
||||
/**
|
||||
* Synchronize the filesystem.
|
||||
*
|
||||
* Write all pending changes to the disk.
|
||||
*
|
||||
* @param Info Inode to synchronize. If NULL, synchronize all inodes.
|
||||
*
|
||||
* @return Zero on success, otherwise an error code.
|
||||
*/
|
||||
int (*Synchronize)(struct FileSystemInfo *Info, struct Inode *Node);
|
||||
|
||||
/**
|
||||
* Destroy the filesystem.
|
||||
*
|
||||
* Unregister the filesystem and free all resources.
|
||||
*
|
||||
* @param Info Filesystem to destroy.
|
||||
*
|
||||
* @return Zero on success, otherwise an error code.
|
||||
*/
|
||||
int (*Destroy)(struct FileSystemInfo *Info);
|
||||
} __attribute__((packed));
|
||||
|
||||
struct FileSystemInfo
|
||||
{
|
||||
const char *Name;
|
||||
const char *RootName;
|
||||
int Flags;
|
||||
struct SuperBlockOperations SuperOps;
|
||||
struct InodeOperations Ops;
|
||||
|
||||
void *PrivateData;
|
||||
} __attribute__((packed));
|
||||
|
||||
dev_t RegisterFileSystem(struct FileSystemInfo *Info, struct Inode *Root);
|
||||
int UnregisterFileSystem(dev_t Device);
|
||||
|
||||
#endif // !__FENNIX_API_FILESYSTEM_H__
|
242
include/input.h
242
include/input.h
@ -1,66 +1,234 @@
|
||||
/*
|
||||
This file is part of Fennix Drivers.
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Drivers is free software: you can redistribute it and/or
|
||||
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 Drivers is distributed in the hope that it will be useful,
|
||||
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 Drivers. If not, see <https://www.gnu.org/licenses/>.
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_API_INPUT_H__
|
||||
#define __FENNIX_API_INPUT_H__
|
||||
|
||||
#include <types.h>
|
||||
#include <driver.h>
|
||||
|
||||
#if __has_include(<interface/device.h>)
|
||||
#include <interface/device.h>
|
||||
#else
|
||||
#include <device.h>
|
||||
#endif
|
||||
|
||||
struct InodeOperations;
|
||||
|
||||
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 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;
|
||||
};
|
||||
KeyScanCodes Key;
|
||||
} KeyboardReport;
|
||||
|
||||
/**
|
||||
* @note Ignored if is absolute
|
||||
*/
|
||||
int X;
|
||||
|
||||
/**
|
||||
* @note Ignored if is absolute
|
||||
*/
|
||||
int Y;
|
||||
typedef struct
|
||||
{
|
||||
long X, Y;
|
||||
int8_t Z;
|
||||
uint8_t Absolute : 1;
|
||||
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;
|
||||
} MouseReport;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
typedef struct
|
||||
{
|
||||
#endif // __cplusplus
|
||||
} JoystickReport;
|
||||
|
||||
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);
|
||||
typedef struct
|
||||
{
|
||||
uint16_t X, Y;
|
||||
uint8_t Pressure;
|
||||
} TouchScreenReport;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
typedef struct
|
||||
{
|
||||
} GamepadReport;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
} AccelerometerReport;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
} GyroscopeReport;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
} MagnetometerReport;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DeviceType Type;
|
||||
dev_t Device;
|
||||
union
|
||||
{
|
||||
KeyboardReport Keyboard;
|
||||
MouseReport Mouse;
|
||||
JoystickReport Joystick;
|
||||
TouchScreenReport TouchScreen;
|
||||
GamepadReport Gamepad;
|
||||
AccelerometerReport Accelerometer;
|
||||
GyroscopeReport Gyroscope;
|
||||
MagnetometerReport Magnetometer;
|
||||
/* ... */
|
||||
};
|
||||
} InputReport;
|
||||
|
||||
EXTERNC int ReportInputEvent(InputReport *Report);
|
||||
|
||||
#endif // !__FENNIX_API_INPUT_H__
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
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__
|
@ -1,25 +1,29 @@
|
||||
/*
|
||||
This file is part of Fennix Drivers.
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Drivers is free software: you can redistribute it and/or
|
||||
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 Drivers is distributed in the hope that it will be useful,
|
||||
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 Drivers. If not, see <https://www.gnu.org/licenses/>.
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_API_VM_H__
|
||||
#define __FENNIX_API_VM_H__
|
||||
#ifndef __FENNIX_API_NETWORK_H__
|
||||
#define __FENNIX_API_NETWORK_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
bool IsVMwareBackdoorAvailable();
|
||||
#if __has_include(<interface/device.h>)
|
||||
#include <interface/device.h>
|
||||
#else
|
||||
#include <device.h>
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_API_VM_H__
|
||||
#endif // !__FENNIX_API_NETWORK_H__
|
@ -21,7 +21,7 @@
|
||||
#include <types.h>
|
||||
|
||||
/* https://sites.uclouvain.be/SystInfo/usr/include/linux/pci_regs.h.html */
|
||||
enum PCICommands
|
||||
typedef enum
|
||||
{
|
||||
/** @brief Enable response in I/O space */
|
||||
PCI_COMMAND_IO = 0x1,
|
||||
@ -45,7 +45,7 @@ enum PCICommands
|
||||
PCI_COMMAND_FAST_BACK = 0x200,
|
||||
/** @brief INTx Emulation Disable */
|
||||
PCI_COMMAND_INTX_DISABLE = 0x400
|
||||
};
|
||||
} PCI_COMMANDS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -171,7 +171,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
PCIArray *FindPCIDevices(uint16_t Vendors[], uint16_t Devices[]);
|
||||
PCIArray *GetPCIDevices(uint16_t Vendors[], uint16_t Devices[]);
|
||||
void InitializePCI(PCIDevice *Device);
|
||||
uint32_t GetBAR(uint8_t Index, PCIDevice *Device);
|
||||
uint8_t iLine(PCIDevice *Device);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <types.h>
|
||||
|
||||
#if defined(__amd64__)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t r15; // General purpose
|
||||
@ -49,8 +50,10 @@ typedef struct
|
||||
uint64_t rsp; // Stack Pointer
|
||||
uint64_t ss; // Stack Segment
|
||||
} TrapFrame;
|
||||
|
||||
#elif defined(__i386__)
|
||||
typedef struct TrapFrame
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t edi; // Destination index for string operations
|
||||
uint32_t esi; // Source index for string operations
|
||||
@ -71,8 +74,10 @@ typedef struct TrapFrame
|
||||
uint32_t r3_esp; // Stack Pointer
|
||||
uint32_t r3_ss; // Stack Segment
|
||||
} TrapFrame;
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
typedef struct TrapFrame
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t x19; // General purpose
|
||||
uint64_t x20; // General purpose
|
||||
@ -95,6 +100,7 @@ typedef struct TrapFrame
|
||||
|
||||
uint64_t InterruptNumber /* iar_el1 */; // Interrupt Acknowledge Register
|
||||
} TrapFrame;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_API_REGISTERS_H__
|
||||
|
@ -1,231 +0,0 @@
|
||||
/*
|
||||
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__
|
111
include/syscalls.h
Normal file
111
include/syscalls.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
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_SYSCALLS_LIST_H__
|
||||
#define __FENNIX_API_SYSCALLS_LIST_H__
|
||||
|
||||
#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_API_SYSCALLS_LIST_H__
|
@ -53,11 +53,41 @@ typedef __UINTMAX_TYPE__ uintmax_t;
|
||||
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
typedef intptr_t ssize_t;
|
||||
|
||||
typedef __SIZE_TYPE__ dev_t;
|
||||
typedef __SIZE_TYPE__ off_t;
|
||||
#if defined(__LP64__)
|
||||
typedef int64_t off_t;
|
||||
typedef int64_t off64_t;
|
||||
typedef uint32_t mode_t;
|
||||
typedef uint64_t dev_t;
|
||||
typedef uint64_t ino64_t;
|
||||
typedef uint64_t ino_t;
|
||||
typedef uint32_t nlink_t;
|
||||
typedef int64_t blksize_t;
|
||||
typedef int64_t blkcnt_t;
|
||||
typedef int64_t blkcnt64_t;
|
||||
typedef int64_t time_t;
|
||||
typedef uint32_t uid_t;
|
||||
typedef uint32_t gid_t;
|
||||
typedef int64_t clock_t;
|
||||
typedef int32_t pid_t;
|
||||
#elif defined(__LP32__)
|
||||
typedef int32_t off_t;
|
||||
typedef long long off64_t;
|
||||
typedef __INT32_TYPE__ mode_t;
|
||||
typedef int32_t dev_t;
|
||||
typedef int32_t ino64_t;
|
||||
typedef int32_t ino_t;
|
||||
typedef unsigned int nlink_t;
|
||||
typedef int blksize_t;
|
||||
typedef int32_t blkcnt_t;
|
||||
typedef int32_t blkcnt64_t;
|
||||
typedef int32_t time_t;
|
||||
typedef unsigned uid_t;
|
||||
typedef unsigned gid_t;
|
||||
typedef long clock_t;
|
||||
typedef int pid_t;
|
||||
#endif
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
@ -108,4 +138,49 @@ typedef __builtin_va_list va_list;
|
||||
#define TO_PAGES(d) (((d) + PAGE_SIZE - 1) / PAGE_SIZE)
|
||||
#define FROM_PAGES(d) ((d) * PAGE_SIZE)
|
||||
|
||||
#define __unused __attribute__((unused))
|
||||
#define __packed __attribute__((packed))
|
||||
#define __naked __attribute__((naked))
|
||||
#define __aligned(x) __attribute__((aligned(x)))
|
||||
#define __section(x) __attribute__((section(x)))
|
||||
#define __noreturn __attribute__((noreturn))
|
||||
#define __weak __attribute__((weak))
|
||||
#define __alias(x) __attribute__((alias(x)))
|
||||
#define __always_inline __attribute__((always_inline))
|
||||
#define __noinline __attribute__((noinline))
|
||||
#define __pure __attribute__((pure))
|
||||
#define __const __attribute__((const))
|
||||
#define __malloc __attribute__((malloc))
|
||||
#define __returns_twice __attribute__((returns_twice))
|
||||
#define __used __attribute__((used))
|
||||
#define __deprecated __attribute__((deprecated))
|
||||
#define __deprecated_msg(x) __attribute__((deprecated(x)))
|
||||
#define __weakref(x) __attribute__((weakref(x)))
|
||||
#define __weakrefalias(x) __attribute__((weakref(#x)))
|
||||
#define __visibility(x) __attribute__((visibility(x)))
|
||||
#define __constructor __attribute__((constructor))
|
||||
#define __destructor __attribute__((destructor))
|
||||
#define __cleanup(x) __attribute__((cleanup(x)))
|
||||
#define __fallthrough __attribute__((fallthrough))
|
||||
#define __nonnull(x) __attribute__((nonnull x))
|
||||
#define __nonnull_all __attribute__((nonnull))
|
||||
#define __returns_nonnull __attribute__((returns_nonnull))
|
||||
#define __sentinel __attribute__((sentinel))
|
||||
#define __sentinel_all __attribute__((sentinel(0)))
|
||||
#define __format(x, y, z) __attribute__((format(x, y, z)))
|
||||
#define __format_arg(x) __attribute__((format_arg(x)))
|
||||
#define __nonnull_params(x) __attribute__((nonnull x))
|
||||
#define __nonnull_all __attribute__((nonnull))
|
||||
#define __warn_unused_result __attribute__((warn_unused_result))
|
||||
#define __no_stack_protector __attribute__((no_stack_protector))
|
||||
#define __no_instrument_function __attribute__((no_instrument_function))
|
||||
#define __no_debug __attribute__((no_debug))
|
||||
#define __target(x) __attribute__((target(x)))
|
||||
#define __min_vector_width(x) __attribute__((min_vector_width(x)))
|
||||
|
||||
#define __sync __sync_synchronize()
|
||||
#define __unreachable __builtin_unreachable()
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
#endif // !__FENNIX_API_TYPES_H__
|
||||
|
Reference in New Issue
Block a user