mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-02 10:59:15 +00:00
Merge remote-tracking branch 'Drivers/master'
This commit is contained in:
259
Drivers/include/aip.h
Normal file
259
Drivers/include/aip.h
Normal file
@ -0,0 +1,259 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
#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(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__
|
93
Drivers/include/aip/kbd.h
Normal file
93
Drivers/include/aip/kbd.h
Normal 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
Drivers/include/aip/mouse.h
Normal file
89
Drivers/include/aip/mouse.h
Normal 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__
|
29
Drivers/include/audio.h
Normal file
29
Drivers/include/audio.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
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_AUDIO_H__
|
||||
#define __FENNIX_API_AUDIO_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#if __has_include(<interface/device.h>)
|
||||
#include <interface/device.h>
|
||||
#else
|
||||
#include <device.h>
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_API_AUDIO_H__
|
287
Drivers/include/base.h
Normal file
287
Drivers/include/base.h
Normal file
@ -0,0 +1,287 @@
|
||||
/*
|
||||
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 kernel terminal
|
||||
* @param Format The format string
|
||||
* @param ... The arguments to the format string
|
||||
*
|
||||
* @note The newline character is automatically appended
|
||||
*/
|
||||
void KernelPrint(const char *Format, ...);
|
||||
|
||||
/**
|
||||
* @brief Print to the kernel logger
|
||||
* @param Format The format string
|
||||
* @param ... The arguments to the format string
|
||||
*/
|
||||
void KernelLog(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 Get the PID of the current process
|
||||
* @return The PID of the current process
|
||||
*/
|
||||
pid_t GetCurrentProcess();
|
||||
|
||||
/**
|
||||
* @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 pId The PID of the process the thread is in
|
||||
* @param ExitCode The exit code of the thread
|
||||
* @return 0 on success, errno on failure
|
||||
*/
|
||||
int KillThread(pid_t tId, pid_t pId, 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, _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, ...) KernelLog(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__
|
75
Drivers/include/device.h
Normal file
75
Drivers/include/device.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
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,
|
||||
NETWORK_TYPE_UART = DEVICE_TYPE_NETWORK + 16,
|
||||
|
||||
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__
|
76
Drivers/include/driver.h
Normal file
76
Drivers/include/driver.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
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 struct
|
||||
{
|
||||
/* PCIDevice */ void *Device;
|
||||
/* __PCIArray */ void *Next;
|
||||
} __PCIArray;
|
||||
|
||||
/* ========================================== */
|
||||
|
||||
#define PCI_END 0x0000
|
||||
#define KEY_NULL 0x00
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IOCTL_AUDIO_GET_VOLUME = 0,
|
||||
IOCTL_AUDIO_SET_VOLUME = 1,
|
||||
|
||||
IOCTL_AUDIO_GET_MUTE = 2,
|
||||
IOCTL_AUDIO_SET_MUTE = 3,
|
||||
|
||||
IOCTL_AUDIO_GET_SAMPLE_RATE = 4,
|
||||
IOCTL_AUDIO_SET_SAMPLE_RATE = 5,
|
||||
|
||||
IOCTL_AUDIO_GET_CHANNELS = 6,
|
||||
IOCTL_AUDIO_SET_CHANNELS = 7,
|
||||
} AudioIoctl;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IOCTL_NET_GET_MAC = 0,
|
||||
} 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;
|
||||
|
||||
struct __DriverInfo
|
||||
{
|
||||
const char *Name;
|
||||
const char *Description;
|
||||
const char *Author;
|
||||
struct __DriverVersion
|
||||
{
|
||||
int APIVersion;
|
||||
int Major, Minor, Patch;
|
||||
} Version;
|
||||
const char *License;
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_API_DRIVER_FUNCTIONS_H__
|
604
Drivers/include/errno.h
Normal file
604
Drivers/include/errno.h
Normal file
@ -0,0 +1,604 @@
|
||||
/*
|
||||
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_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__
|
382
Drivers/include/fs.h
Normal file
382
Drivers/include/fs.h
Normal file
@ -0,0 +1,382 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
uintptr_t KernelData;
|
||||
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;
|
||||
KernelData = 0x0;
|
||||
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__
|
244
Drivers/include/input.h
Normal file
244
Drivers/include/input.h
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
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_INPUT_H__
|
||||
#define __FENNIX_API_INPUT_H__
|
||||
|
||||
#include <types.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
|
||||
{
|
||||
KeyScanCodes Key;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
char IsScanCode : 1;
|
||||
};
|
||||
char Value;
|
||||
};
|
||||
unsigned char Character;
|
||||
} KeyboardReport;
|
||||
|
||||
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;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
} JoystickReport;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t X, Y;
|
||||
uint8_t Pressure;
|
||||
} TouchScreenReport;
|
||||
|
||||
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__
|
239
Drivers/include/io.h
Normal file
239
Drivers/include/io.h
Normal file
@ -0,0 +1,239 @@
|
||||
/*
|
||||
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__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
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 uint32_t inportl(uint16_t Port)
|
||||
{
|
||||
uint32_t Result;
|
||||
__asm__ volatile("inl %1, %0"
|
||||
: "=a"(Result)
|
||||
: "dN"(Port));
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline void outportb(uint16_t Port, uint8_t Data)
|
||||
{
|
||||
__asm__ volatile("out %%al, %%dx"
|
||||
:
|
||||
: "a"(Data), "d"(Port));
|
||||
}
|
||||
|
||||
static inline void outportw(uint16_t Port, uint16_t Data)
|
||||
{
|
||||
__asm__ volatile("out %%ax, %%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 uint8_t mmioin8(uint64_t Address)
|
||||
{
|
||||
__asm__ volatile("" ::
|
||||
: "memory");
|
||||
uint8_t Result = *(volatile uint8_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 uint32_t mmioin32(uint64_t Address)
|
||||
{
|
||||
__asm__ volatile("" ::
|
||||
: "memory");
|
||||
uint32_t Result = *(volatile uint32_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 void mmioout8(uint64_t Address, uint8_t Data)
|
||||
{
|
||||
__asm__ volatile("" ::
|
||||
: "memory");
|
||||
*(volatile uint8_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 mmioout32(uint64_t Address, uint32_t Data)
|
||||
{
|
||||
__asm__ volatile("" ::
|
||||
: "memory");
|
||||
*(volatile uint32_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 mmoutb(void *Address, uint8_t Value)
|
||||
{
|
||||
__asm__ volatile("mov %1, %0"
|
||||
: "=m"((*(uint8_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 mmoutl(void *Address, uint32_t Value)
|
||||
{
|
||||
__asm__ volatile("mov %1, %0"
|
||||
: "=m"((*(uint32_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 uint8_t mminb(void *Address)
|
||||
{
|
||||
uint8_t Result;
|
||||
__asm__ volatile("mov %1, %0"
|
||||
: "=r"(Result)
|
||||
: "m"((*(uint8_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;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define inb(Port) inportb(Port)
|
||||
#define inw(Port) inportw(Port)
|
||||
#define inl(Port) inportl(Port)
|
||||
#define outb(Port, Data) outportb(Port, Data)
|
||||
#define outw(Port, Data) outportw(Port, Data)
|
||||
#define outl(Port, Data) outportl(Port, Data)
|
||||
|
||||
#endif // defined(__amd64__) || defined(__i386__)
|
||||
|
||||
#endif // !__FENNIX_API_IO_H__
|
145
Drivers/include/netools.h
Normal file
145
Drivers/include/netools.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
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__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
typedef __UINT64_TYPE__ uint48_t;
|
||||
|
||||
struct MediaAccessControl
|
||||
{
|
||||
uint8_t Address[6];
|
||||
|
||||
inline bool operator==(const MediaAccessControl &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3] &&
|
||||
lhs.Address[4] == this->Address[4] &&
|
||||
lhs.Address[5] == this->Address[5];
|
||||
}
|
||||
|
||||
inline bool operator==(const uint48_t &lhs) const
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
MAC.Address[0] = (uint8_t)((lhs >> 40) & 0xFF);
|
||||
MAC.Address[1] = (uint8_t)((lhs >> 32) & 0xFF);
|
||||
MAC.Address[2] = (uint8_t)((lhs >> 24) & 0xFF);
|
||||
MAC.Address[3] = (uint8_t)((lhs >> 16) & 0xFF);
|
||||
MAC.Address[4] = (uint8_t)((lhs >> 8) & 0xFF);
|
||||
MAC.Address[5] = (uint8_t)(lhs & 0xFF);
|
||||
return MAC.Address[0] == this->Address[0] &&
|
||||
MAC.Address[1] == this->Address[1] &&
|
||||
MAC.Address[2] == this->Address[2] &&
|
||||
MAC.Address[3] == this->Address[3] &&
|
||||
MAC.Address[4] == this->Address[4] &&
|
||||
MAC.Address[5] == this->Address[5];
|
||||
}
|
||||
|
||||
inline bool operator!=(const MediaAccessControl &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint48_t &lhs) const { return !(*this == lhs); }
|
||||
|
||||
inline uint48_t ToHex()
|
||||
{
|
||||
return ((uint48_t)this->Address[0] << 40) |
|
||||
((uint48_t)this->Address[1] << 32) |
|
||||
((uint48_t)this->Address[2] << 24) |
|
||||
((uint48_t)this->Address[3] << 16) |
|
||||
((uint48_t)this->Address[4] << 8) |
|
||||
((uint48_t)this->Address[5]);
|
||||
}
|
||||
|
||||
inline MediaAccessControl FromHex(uint48_t Hex)
|
||||
{
|
||||
this->Address[0] = (uint8_t)((Hex >> 40) & 0xFF);
|
||||
this->Address[1] = (uint8_t)((Hex >> 32) & 0xFF);
|
||||
this->Address[2] = (uint8_t)((Hex >> 24) & 0xFF);
|
||||
this->Address[3] = (uint8_t)((Hex >> 16) & 0xFF);
|
||||
this->Address[4] = (uint8_t)((Hex >> 8) & 0xFF);
|
||||
this->Address[5] = (uint8_t)(Hex & 0xFF);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool Valid()
|
||||
{
|
||||
// TODO: More complex MAC validation
|
||||
return (this->Address[0] != 0 ||
|
||||
this->Address[1] != 0 ||
|
||||
this->Address[2] != 0 ||
|
||||
this->Address[3] != 0 ||
|
||||
this->Address[4] != 0 ||
|
||||
this->Address[5] != 0) &&
|
||||
(this->Address[0] != 0xFF ||
|
||||
this->Address[1] != 0xFF ||
|
||||
this->Address[2] != 0xFF ||
|
||||
this->Address[3] != 0xFF ||
|
||||
this->Address[4] != 0xFF ||
|
||||
this->Address[5] != 0xFF);
|
||||
}
|
||||
};
|
||||
|
||||
struct InternetProtocol4
|
||||
{
|
||||
uint8_t Address[4];
|
||||
|
||||
inline bool operator==(const InternetProtocol4 &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3];
|
||||
}
|
||||
|
||||
inline bool operator==(const uint32_t &lhs) const
|
||||
{
|
||||
InternetProtocol4 IP;
|
||||
IP.Address[0] = (uint8_t)((lhs >> 24) & 0xFF);
|
||||
IP.Address[1] = (uint8_t)((lhs >> 16) & 0xFF);
|
||||
IP.Address[2] = (uint8_t)((lhs >> 8) & 0xFF);
|
||||
IP.Address[3] = (uint8_t)(lhs & 0xFF);
|
||||
|
||||
return IP.Address[0] == this->Address[0] &&
|
||||
IP.Address[1] == this->Address[1] &&
|
||||
IP.Address[2] == this->Address[2] &&
|
||||
IP.Address[3] == this->Address[3];
|
||||
}
|
||||
|
||||
inline bool operator!=(const InternetProtocol4 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint32_t &lhs) const { return !(*this == lhs); }
|
||||
|
||||
inline uint32_t ToHex()
|
||||
{
|
||||
return ((uint64_t)this->Address[0] << 24) |
|
||||
((uint64_t)this->Address[1] << 16) |
|
||||
((uint64_t)this->Address[2] << 8) |
|
||||
((uint64_t)this->Address[3]);
|
||||
}
|
||||
|
||||
inline InternetProtocol4 FromHex(uint32_t Hex)
|
||||
{
|
||||
this->Address[0] = (uint8_t)((Hex >> 24) & 0xFF);
|
||||
this->Address[1] = (uint8_t)((Hex >> 16) & 0xFF);
|
||||
this->Address[2] = (uint8_t)((Hex >> 8) & 0xFF);
|
||||
this->Address[3] = (uint8_t)(Hex & 0xFF);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_API_NETWORK_UTILS_H__
|
29
Drivers/include/network.h
Normal file
29
Drivers/include/network.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
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_NETWORK_H__
|
||||
#define __FENNIX_API_NETWORK_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#if __has_include(<interface/device.h>)
|
||||
#include <interface/device.h>
|
||||
#else
|
||||
#include <device.h>
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_API_NETWORK_H__
|
184
Drivers/include/pci.h
Normal file
184
Drivers/include/pci.h
Normal file
@ -0,0 +1,184 @@
|
||||
/*
|
||||
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__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
/* https://sites.uclouvain.be/SystInfo/usr/include/linux/pci_regs.h.html */
|
||||
typedef enum
|
||||
{
|
||||
/** @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
|
||||
} PCI_COMMANDS;
|
||||
|
||||
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;
|
||||
} __attribute__((packed)) PCIDeviceHeader;
|
||||
|
||||
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;
|
||||
} __attribute__((packed)) PCIHeader0;
|
||||
|
||||
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;
|
||||
} __attribute__((packed)) PCIHeader1;
|
||||
|
||||
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;
|
||||
} __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 *GetPCIDevices(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__
|
106
Drivers/include/regs.h
Normal file
106
Drivers/include/regs.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
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__
|
111
Drivers/include/syscalls.h
Normal file
111
Drivers/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__
|
186
Drivers/include/types.h
Normal file
186
Drivers/include/types.h
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
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__
|
||||
|
||||
typedef __INT8_TYPE__ int8_t;
|
||||
typedef __INT16_TYPE__ int16_t;
|
||||
typedef __INT32_TYPE__ int32_t;
|
||||
typedef __INT64_TYPE__ int64_t;
|
||||
typedef __UINT8_TYPE__ uint8_t;
|
||||
typedef __UINT16_TYPE__ uint16_t;
|
||||
typedef __UINT32_TYPE__ uint32_t;
|
||||
typedef __UINT64_TYPE__ uint64_t;
|
||||
|
||||
typedef __INT_LEAST8_TYPE__ int_least8_t;
|
||||
typedef __INT_LEAST16_TYPE__ int_least16_t;
|
||||
typedef __INT_LEAST32_TYPE__ int_least32_t;
|
||||
typedef __INT_LEAST64_TYPE__ int_least64_t;
|
||||
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
|
||||
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
|
||||
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
|
||||
typedef __UINT_LEAST64_TYPE__ uint_least64_t;
|
||||
|
||||
typedef __INT_FAST8_TYPE__ int_fast8_t;
|
||||
typedef __INT_FAST16_TYPE__ int_fast16_t;
|
||||
typedef __INT_FAST32_TYPE__ int_fast32_t;
|
||||
typedef __INT_FAST64_TYPE__ int_fast64_t;
|
||||
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
|
||||
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
|
||||
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
|
||||
typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||
|
||||
typedef __INTPTR_TYPE__ intptr_t;
|
||||
typedef __UINTPTR_TYPE__ uintptr_t;
|
||||
|
||||
typedef __INTMAX_TYPE__ intmax_t;
|
||||
typedef __UINTMAX_TYPE__ uintmax_t;
|
||||
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
typedef intptr_t ssize_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)
|
||||
|
||||
#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)
|
||||
|
||||
#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