mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
568
include/acpi.hpp
568
include/acpi.hpp
@ -20,6 +20,7 @@
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <boot/binfo.h>
|
||||
#include <ints.hpp>
|
||||
#include <cpu.hpp>
|
||||
@ -27,272 +28,359 @@
|
||||
|
||||
namespace ACPI
|
||||
{
|
||||
class ACPI
|
||||
{
|
||||
public:
|
||||
struct ACPIHeader
|
||||
{
|
||||
unsigned char Signature[4];
|
||||
uint32_t Length;
|
||||
uint8_t Revision;
|
||||
uint8_t Checksum;
|
||||
uint8_t OEMID[6];
|
||||
uint8_t OEMTableID[8];
|
||||
uint32_t OEMRevision;
|
||||
uint32_t CreatorID;
|
||||
uint32_t CreatorRevision;
|
||||
} __packed;
|
||||
class ACPI
|
||||
{
|
||||
public:
|
||||
struct ACPIHeader
|
||||
{
|
||||
unsigned char Signature[4];
|
||||
uint32_t Length;
|
||||
uint8_t Revision;
|
||||
uint8_t Checksum;
|
||||
uint8_t OEMID[6];
|
||||
uint8_t OEMTableID[8];
|
||||
uint32_t OEMRevision;
|
||||
uint32_t CreatorID;
|
||||
uint32_t CreatorRevision;
|
||||
} __packed;
|
||||
|
||||
struct GenericAddressStructure
|
||||
{
|
||||
uint8_t AddressSpace;
|
||||
uint8_t BitWidth;
|
||||
uint8_t BitOffset;
|
||||
uint8_t AccessSize;
|
||||
uint64_t Address;
|
||||
} __packed;
|
||||
struct GenericAddressStructure
|
||||
{
|
||||
uint8_t AddressSpace;
|
||||
uint8_t BitWidth;
|
||||
uint8_t BitOffset;
|
||||
uint8_t AccessSize;
|
||||
uint64_t Address;
|
||||
} __packed;
|
||||
|
||||
struct MCFGHeader
|
||||
{
|
||||
struct ACPIHeader Header;
|
||||
uint64_t Reserved;
|
||||
} __packed;
|
||||
enum DBG2PortType
|
||||
{
|
||||
TYPE_SERIAL = 0x8000,
|
||||
TYPE_1394 = 0x8001,
|
||||
TYPE_USB = 0x8002,
|
||||
TYPE_NET = 0x8003
|
||||
};
|
||||
|
||||
struct HPETHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint8_t HardwareRevID;
|
||||
uint8_t ComparatorCount : 5;
|
||||
uint8_t CounterSize : 1;
|
||||
uint8_t Reserved : 1;
|
||||
uint8_t LegacyReplacement : 1;
|
||||
uint16_t PCIVendorID;
|
||||
struct GenericAddressStructure Address;
|
||||
uint8_t HPETNumber;
|
||||
uint16_t MinimumTick;
|
||||
uint8_t PageProtection;
|
||||
} __packed;
|
||||
enum DBG2PortSubtype
|
||||
{
|
||||
SUBTYPE_SERIAL_16550_COMPATIBLE = 0x0000,
|
||||
SUBTYPE_SERIAL_16550_SUBSET = 0x0001,
|
||||
SUBTYPE_SERIAL_MAX311xE_SPI_UART = 0x0002,
|
||||
SUBTYPE_SERIAL_Arm_PL011_UART = 0x0003,
|
||||
SUBTYPE_SERIAL_MSM8x60 = 0x0004,
|
||||
SUBTYPE_SERIAL_Nvidia_16550 = 0x0005,
|
||||
SUBTYPE_SERIAL_TI_OMAP = 0x0006,
|
||||
SUBTYPE_SERIAL_APM88xxxx = 0x0008,
|
||||
SUBTYPE_SERIAL_MSM8974 = 0x0009,
|
||||
SUBTYPE_SERIAL_SAM5250 = 0x000A,
|
||||
SUBTYPE_SERIAL_Intel_USIF = 0x000B,
|
||||
SUBTYPE_SERIAL_iMX6 = 0x000C,
|
||||
SUBTYPE_SERIAL_Arm_SBSA_UART = 0x000D,
|
||||
SUBTYPE_SERIAL_Arm_SBSA_Generic_UART = 0x000E,
|
||||
SUBTYPE_SERIAL_Arm_DCC = 0x000F,
|
||||
SUBTYPE_SERIAL_BCM2835 = 0x0010,
|
||||
SUBTYPE_SERIAL_SDM845_At_1_8432MHz = 0x0011,
|
||||
SUBTYPE_SERIAL_16550_With_Generic_Address_Structure = 0x0012,
|
||||
SUBTYPE_SERIAL_SDM845_At_7_372MHz = 0x0013,
|
||||
SUBTYPE_SERIAL_Intel_LPSS = 0x0014,
|
||||
SUBTYPE_SERIAL_RISC_V_SBI_Console = 0x0015,
|
||||
|
||||
struct FADTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t FirmwareCtrl;
|
||||
uint32_t Dsdt;
|
||||
uint8_t Reserved;
|
||||
uint8_t PreferredPowerManagementProfile;
|
||||
uint16_t SCI_Interrupt;
|
||||
uint32_t SMI_CommandPort;
|
||||
uint8_t AcpiEnable;
|
||||
uint8_t AcpiDisable;
|
||||
uint8_t S4BIOS_REQ;
|
||||
uint8_t PSTATE_Control;
|
||||
uint32_t PM1aEventBlock;
|
||||
uint32_t PM1bEventBlock;
|
||||
uint32_t PM1aControlBlock;
|
||||
uint32_t PM1bControlBlock;
|
||||
uint32_t PM2ControlBlock;
|
||||
uint32_t PMTimerBlock;
|
||||
uint32_t GPE0Block;
|
||||
uint32_t GPE1Block;
|
||||
uint8_t PM1EventLength;
|
||||
uint8_t PM1ControlLength;
|
||||
uint8_t PM2ControlLength;
|
||||
uint8_t PMTimerLength;
|
||||
uint8_t GPE0Length;
|
||||
uint8_t GPE1Length;
|
||||
uint8_t GPE1Base;
|
||||
uint8_t CStateControl;
|
||||
uint16_t WorstC2Latency;
|
||||
uint16_t WorstC3Latency;
|
||||
uint16_t FlushSize;
|
||||
uint16_t FlushStride;
|
||||
uint8_t DutyOffset;
|
||||
uint8_t DutyWidth;
|
||||
uint8_t DayAlarm;
|
||||
uint8_t MonthAlarm;
|
||||
uint8_t Century;
|
||||
uint16_t BootArchitectureFlags;
|
||||
uint8_t Reserved2;
|
||||
uint32_t Flags;
|
||||
struct GenericAddressStructure ResetReg;
|
||||
uint8_t ResetValue;
|
||||
uint8_t Reserved3[3];
|
||||
uint64_t X_FirmwareControl;
|
||||
uint64_t X_Dsdt;
|
||||
struct GenericAddressStructure X_PM1aEventBlock;
|
||||
struct GenericAddressStructure X_PM1bEventBlock;
|
||||
struct GenericAddressStructure X_PM1aControlBlock;
|
||||
struct GenericAddressStructure X_PM1bControlBlock;
|
||||
struct GenericAddressStructure X_PM2ControlBlock;
|
||||
struct GenericAddressStructure X_PMTimerBlock;
|
||||
struct GenericAddressStructure X_GPE0Block;
|
||||
struct GenericAddressStructure X_GPE1Block;
|
||||
} __packed;
|
||||
SUBTYPE_1394_IEEE1394_HCI = 0x0000,
|
||||
|
||||
SUBTYPE_USB_XHCI = 0x0000,
|
||||
SUBTYPE_USB_EHCI = 0x0001,
|
||||
|
||||
struct BGRTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint16_t Version;
|
||||
uint8_t Status;
|
||||
uint8_t ImageType;
|
||||
uint64_t ImageAddress;
|
||||
uint32_t ImageOffsetX;
|
||||
uint32_t ImageOffsetY;
|
||||
};
|
||||
SUBTYPE_NET_NNNN = 0x0000,
|
||||
};
|
||||
|
||||
struct SRATHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t TableRevision; // Must be value 1
|
||||
uint64_t Reserved; // Reserved, must be zero
|
||||
};
|
||||
struct DBG2Device
|
||||
{
|
||||
uint8_t Revision;
|
||||
uint16_t Length;
|
||||
uint8_t NumberofGenericAddressRegisters;
|
||||
uint16_t NamespaceStringLength;
|
||||
uint16_t NamespaceStringOffset;
|
||||
uint16_t OemDataLength;
|
||||
uint16_t OemDataOffset;
|
||||
uint16_t PortType;
|
||||
uint16_t PortSubtype;
|
||||
uint16_t Reserved;
|
||||
uint16_t BaseAddressRegisterOffset;
|
||||
uint16_t AddressSizeOffset;
|
||||
/* BaseAddressRegister[NumberofGenericAddressRegisters * 12] at offset BaseAddressRegisterOffset */
|
||||
/* AddressSize[NumberofGenericAddressRegisters * 4] at offset AddressSizeOffset */
|
||||
/* NamespaceString[NamespaceStringLength] at offset NamespaceStringOffset */
|
||||
/* OemData[OemDataLength] at offset OemDataOffset */
|
||||
} __packed;
|
||||
|
||||
struct TPM2Header
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t Flags;
|
||||
uint64_t ControlAddress;
|
||||
uint32_t StartMethod;
|
||||
};
|
||||
struct MCFGHeader
|
||||
{
|
||||
struct ACPIHeader Header;
|
||||
uint64_t Reserved;
|
||||
} __packed;
|
||||
|
||||
struct TCPAHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint16_t Reserved;
|
||||
uint32_t MaxLogLength;
|
||||
uint64_t LogAddress;
|
||||
};
|
||||
struct HPETHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint8_t HardwareRevID;
|
||||
uint8_t ComparatorCount : 5;
|
||||
uint8_t CounterSize : 1;
|
||||
uint8_t Reserved : 1;
|
||||
uint8_t LegacyReplacement : 1;
|
||||
uint16_t PCIVendorID;
|
||||
struct GenericAddressStructure Address;
|
||||
uint8_t HPETNumber;
|
||||
uint16_t MinimumTick;
|
||||
uint8_t PageProtection;
|
||||
} __packed;
|
||||
|
||||
struct WAETHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t Flags;
|
||||
};
|
||||
struct FADTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t FirmwareCtrl;
|
||||
uint32_t Dsdt;
|
||||
uint8_t Reserved;
|
||||
uint8_t PreferredPowerManagementProfile;
|
||||
uint16_t SCI_Interrupt;
|
||||
uint32_t SMI_CommandPort;
|
||||
uint8_t AcpiEnable;
|
||||
uint8_t AcpiDisable;
|
||||
uint8_t S4BIOS_REQ;
|
||||
uint8_t PSTATE_Control;
|
||||
uint32_t PM1aEventBlock;
|
||||
uint32_t PM1bEventBlock;
|
||||
uint32_t PM1aControlBlock;
|
||||
uint32_t PM1bControlBlock;
|
||||
uint32_t PM2ControlBlock;
|
||||
uint32_t PMTimerBlock;
|
||||
uint32_t GPE0Block;
|
||||
uint32_t GPE1Block;
|
||||
uint8_t PM1EventLength;
|
||||
uint8_t PM1ControlLength;
|
||||
uint8_t PM2ControlLength;
|
||||
uint8_t PMTimerLength;
|
||||
uint8_t GPE0Length;
|
||||
uint8_t GPE1Length;
|
||||
uint8_t GPE1Base;
|
||||
uint8_t CStateControl;
|
||||
uint16_t WorstC2Latency;
|
||||
uint16_t WorstC3Latency;
|
||||
uint16_t FlushSize;
|
||||
uint16_t FlushStride;
|
||||
uint8_t DutyOffset;
|
||||
uint8_t DutyWidth;
|
||||
uint8_t DayAlarm;
|
||||
uint8_t MonthAlarm;
|
||||
uint8_t Century;
|
||||
uint16_t BootArchitectureFlags;
|
||||
uint8_t Reserved2;
|
||||
uint32_t Flags;
|
||||
struct GenericAddressStructure ResetReg;
|
||||
uint8_t ResetValue;
|
||||
uint8_t Reserved3[3];
|
||||
uint64_t X_FirmwareControl;
|
||||
uint64_t X_Dsdt;
|
||||
struct GenericAddressStructure X_PM1aEventBlock;
|
||||
struct GenericAddressStructure X_PM1bEventBlock;
|
||||
struct GenericAddressStructure X_PM1aControlBlock;
|
||||
struct GenericAddressStructure X_PM1bControlBlock;
|
||||
struct GenericAddressStructure X_PM2ControlBlock;
|
||||
struct GenericAddressStructure X_PMTimerBlock;
|
||||
struct GenericAddressStructure X_GPE0Block;
|
||||
struct GenericAddressStructure X_GPE1Block;
|
||||
} __packed;
|
||||
|
||||
struct HESTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t ErrorSourceCount;
|
||||
};
|
||||
struct BGRTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint16_t Version;
|
||||
uint8_t Status;
|
||||
uint8_t ImageType;
|
||||
uint64_t ImageAddress;
|
||||
uint32_t ImageOffsetX;
|
||||
uint32_t ImageOffsetY;
|
||||
} __packed;
|
||||
|
||||
struct MADTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t LocalControllerAddress;
|
||||
uint32_t Flags;
|
||||
char Entries[];
|
||||
} __packed;
|
||||
struct SRATHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t TableRevision; // Must be value 1
|
||||
uint64_t Reserved; // Reserved, must be zero
|
||||
} __packed;
|
||||
|
||||
ACPIHeader *XSDT = nullptr;
|
||||
MCFGHeader *MCFG = nullptr;
|
||||
HPETHeader *HPET = nullptr;
|
||||
FADTHeader *FADT = nullptr;
|
||||
BGRTHeader *BGRT = nullptr;
|
||||
SRATHeader *SRAT = nullptr;
|
||||
TPM2Header *TPM2 = nullptr;
|
||||
TCPAHeader *TCPA = nullptr;
|
||||
WAETHeader *WAET = nullptr;
|
||||
MADTHeader *MADT = nullptr;
|
||||
HESTHeader *HEST = nullptr;
|
||||
bool XSDTSupported = false;
|
||||
struct TPM2Header
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t Flags;
|
||||
uint64_t ControlAddress;
|
||||
uint32_t StartMethod;
|
||||
} __packed;
|
||||
|
||||
void *FindTable(ACPIHeader *ACPIHeader, char *Signature);
|
||||
void SearchTables(ACPIHeader *Header);
|
||||
ACPI();
|
||||
~ACPI();
|
||||
};
|
||||
struct TCPAHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint16_t Reserved;
|
||||
uint32_t MaxLogLength;
|
||||
uint64_t LogAddress;
|
||||
} __packed;
|
||||
|
||||
class MADT
|
||||
{
|
||||
public:
|
||||
struct APICHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Length;
|
||||
} __packed;
|
||||
struct WAETHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t Flags;
|
||||
} __packed;
|
||||
|
||||
struct MADTIOApic
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t APICID;
|
||||
uint8_t reserved;
|
||||
uint32_t Address;
|
||||
uint32_t GSIBase;
|
||||
} __packed;
|
||||
struct HESTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t ErrorSourceCount;
|
||||
} __packed;
|
||||
|
||||
struct MADTIso
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t BuSSource;
|
||||
uint8_t IRQSource;
|
||||
uint32_t GSI;
|
||||
uint16_t Flags;
|
||||
} __packed;
|
||||
struct MADTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t LocalControllerAddress;
|
||||
uint32_t Flags;
|
||||
char Entries[];
|
||||
} __packed;
|
||||
|
||||
struct MADTNmi
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t processor;
|
||||
uint16_t flags;
|
||||
uint8_t lint;
|
||||
} __packed;
|
||||
struct SSDTHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
char DefinitionBlock[];
|
||||
} __packed;
|
||||
|
||||
struct LocalAPIC
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t ACPIProcessorId;
|
||||
uint8_t APICId;
|
||||
uint32_t Flags;
|
||||
} __packed;
|
||||
struct DBGPHeader
|
||||
{
|
||||
ACPIHeader Header;
|
||||
/**
|
||||
* 0 - 16550 compatible
|
||||
* 1 - Subset of 16550
|
||||
*/
|
||||
uint8_t InterfaceType;
|
||||
uint8_t Reserved[3];
|
||||
GenericAddressStructure BaseAddress;
|
||||
} __packed;
|
||||
|
||||
struct LAPIC
|
||||
{
|
||||
uint8_t id;
|
||||
uintptr_t PhysicalAddress;
|
||||
void *VirtualAddress;
|
||||
};
|
||||
struct DBG2Header
|
||||
{
|
||||
ACPIHeader Header;
|
||||
uint32_t OffsetDbgDeviceInfo;
|
||||
uint32_t NumberDbgDeviceInfo;
|
||||
/* DBG2Device[NumberDbgDeviceInfo] at offset OffsetDbgDeviceInfo */
|
||||
} __packed;
|
||||
|
||||
std::vector<MADTIOApic *> ioapic;
|
||||
std::vector<MADTIso *> iso;
|
||||
std::vector<MADTNmi *> nmi;
|
||||
std::vector<LocalAPIC *> lapic;
|
||||
struct LAPIC *LAPICAddress;
|
||||
uint16_t CPUCores;
|
||||
ACPIHeader *XSDT = nullptr;
|
||||
MCFGHeader *MCFG = nullptr;
|
||||
HPETHeader *HPET = nullptr;
|
||||
FADTHeader *FADT = nullptr;
|
||||
BGRTHeader *BGRT = nullptr;
|
||||
SRATHeader *SRAT = nullptr;
|
||||
TPM2Header *TPM2 = nullptr;
|
||||
TCPAHeader *TCPA = nullptr;
|
||||
WAETHeader *WAET = nullptr;
|
||||
MADTHeader *MADT = nullptr;
|
||||
HESTHeader *HEST = nullptr;
|
||||
SSDTHeader *SSDT = nullptr;
|
||||
DBGPHeader *DBGP = nullptr;
|
||||
DBG2Header *DBG2 = nullptr;
|
||||
bool XSDTSupported = false;
|
||||
|
||||
MADT(ACPI::MADTHeader *madt);
|
||||
~MADT();
|
||||
};
|
||||
std::unordered_map<const char *, ACPIHeader *> Tables;
|
||||
|
||||
class DSDT : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
uint32_t SMI_CMD = 0;
|
||||
uint8_t ACPI_ENABLE = 0;
|
||||
uint8_t ACPI_DISABLE = 0;
|
||||
uint32_t PM1a_CNT = 0;
|
||||
uint32_t PM1b_CNT = 0;
|
||||
uint16_t SLP_TYPa = 0;
|
||||
uint16_t SLP_TYPb = 0;
|
||||
uint16_t SLP_EN = 0;
|
||||
uint16_t SCI_EN = 0;
|
||||
uint8_t PM1_CNT_LEN = 0;
|
||||
void *FindTable(ACPIHeader *ACPIHeader, char *Signature);
|
||||
void SearchTables(ACPIHeader *Header);
|
||||
ACPI();
|
||||
~ACPI();
|
||||
};
|
||||
|
||||
ACPI *acpi;
|
||||
#if defined(a64)
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
#elif defined(a32)
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
#endif
|
||||
class MADT
|
||||
{
|
||||
public:
|
||||
struct APICHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Length;
|
||||
} __packed;
|
||||
|
||||
public:
|
||||
bool ACPIShutdownSupported = false;
|
||||
struct MADTIOApic
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t APICID;
|
||||
uint8_t reserved;
|
||||
uint32_t Address;
|
||||
uint32_t GSIBase;
|
||||
} __packed;
|
||||
|
||||
void Reboot();
|
||||
void Shutdown();
|
||||
struct MADTIso
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t BuSSource;
|
||||
uint8_t IRQSource;
|
||||
uint32_t GSI;
|
||||
uint16_t Flags;
|
||||
} __packed;
|
||||
|
||||
DSDT(ACPI *acpi);
|
||||
~DSDT();
|
||||
};
|
||||
struct MADTNmi
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t processor;
|
||||
uint16_t flags;
|
||||
uint8_t lint;
|
||||
} __packed;
|
||||
|
||||
struct LocalAPIC
|
||||
{
|
||||
struct APICHeader Header;
|
||||
uint8_t ACPIProcessorId;
|
||||
uint8_t APICId;
|
||||
uint32_t Flags;
|
||||
} __packed;
|
||||
|
||||
struct LAPIC
|
||||
{
|
||||
uint8_t id;
|
||||
uintptr_t PhysicalAddress;
|
||||
void *VirtualAddress;
|
||||
};
|
||||
|
||||
std::vector<MADTIOApic *> ioapic;
|
||||
std::vector<MADTIso *> iso;
|
||||
std::vector<MADTNmi *> nmi;
|
||||
std::vector<LocalAPIC *> lapic;
|
||||
struct LAPIC *LAPICAddress;
|
||||
uint16_t CPUCores;
|
||||
|
||||
MADT(ACPI::MADTHeader *madt);
|
||||
~MADT();
|
||||
};
|
||||
|
||||
class DSDT : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
uint32_t SMI_CMD = 0;
|
||||
uint8_t ACPI_ENABLE = 0;
|
||||
uint8_t ACPI_DISABLE = 0;
|
||||
uint32_t PM1a_CNT = 0;
|
||||
uint32_t PM1b_CNT = 0;
|
||||
uint16_t SLP_TYPa = 0;
|
||||
uint16_t SLP_TYPb = 0;
|
||||
uint16_t SLP_EN = 0;
|
||||
uint16_t SCI_EN = 0;
|
||||
uint8_t PM1_CNT_LEN = 0;
|
||||
|
||||
ACPI *acpi;
|
||||
void OnInterruptReceived(CPU::TrapFrame *Frame);
|
||||
|
||||
public:
|
||||
bool ACPIShutdownSupported = false;
|
||||
|
||||
void Reboot();
|
||||
void Shutdown();
|
||||
|
||||
DSDT(ACPI *acpi);
|
||||
~DSDT();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ACPI_H__
|
||||
|
@ -38,7 +38,7 @@
|
||||
/* Alignment of the multiboot info structure. */
|
||||
#define MULTIBOOT_INFO_ALIGN 0x00000004
|
||||
|
||||
/* Flags set in the ’flags’ member of the multiboot header. */
|
||||
/* Flags set in the 'flags' member of the multiboot header. */
|
||||
|
||||
/* Align all boot modules on i386 page (4KB) boundaries. */
|
||||
#define MULTIBOOT_PAGE_ALIGN 0x00000001
|
||||
@ -52,7 +52,7 @@
|
||||
/* This flag indicates the use of the address fields in the header. */
|
||||
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
|
||||
|
||||
/* Flags to be set in the ’flags’ member of the multiboot info structure. */
|
||||
/* Flags to be set in the 'flags' member of the multiboot info structure. */
|
||||
|
||||
/* is there basic lower/upper memory information? */
|
||||
#define MULTIBOOT_INFO_MEMORY 0x00000001
|
||||
@ -243,7 +243,7 @@ typedef struct multiboot_mmap_entry multiboot_memory_map_t;
|
||||
|
||||
struct multiboot_mod_list
|
||||
{
|
||||
/* the memory used goes from bytes ’mod_start’ to ’mod_end-1’ inclusive */
|
||||
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
|
||||
multiboot_uint32_t mod_start;
|
||||
multiboot_uint32_t mod_end;
|
||||
|
||||
|
208
include/cargs.h
208
include/cargs.h
@ -63,122 +63,122 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* An option is used to describe a flag/argument option submitted when the
|
||||
* program is run.
|
||||
*/
|
||||
typedef struct cag_option
|
||||
{
|
||||
const char identifier;
|
||||
const char *access_letters;
|
||||
const char *access_name;
|
||||
const char *value_name;
|
||||
const char *description;
|
||||
} cag_option;
|
||||
/**
|
||||
* An option is used to describe a flag/argument option submitted when the
|
||||
* program is run.
|
||||
*/
|
||||
typedef struct cag_option
|
||||
{
|
||||
const char identifier;
|
||||
const char *access_letters;
|
||||
const char *access_name;
|
||||
const char *value_name;
|
||||
const char *description;
|
||||
} cag_option;
|
||||
|
||||
/**
|
||||
* A context is used to iterate over all options provided. It stores the parsing
|
||||
* state.
|
||||
*/
|
||||
typedef struct cag_option_context
|
||||
{
|
||||
const struct cag_option *options;
|
||||
size_t option_count;
|
||||
int argc;
|
||||
char **argv;
|
||||
int index;
|
||||
int inner_index;
|
||||
bool forced_end;
|
||||
char identifier;
|
||||
char *value;
|
||||
} cag_option_context;
|
||||
/**
|
||||
* A context is used to iterate over all options provided. It stores the parsing
|
||||
* state.
|
||||
*/
|
||||
typedef struct cag_option_context
|
||||
{
|
||||
const struct cag_option *options;
|
||||
size_t option_count;
|
||||
int argc;
|
||||
char **argv;
|
||||
int index;
|
||||
int inner_index;
|
||||
bool forced_end;
|
||||
char identifier;
|
||||
char *value;
|
||||
} cag_option_context;
|
||||
|
||||
/**
|
||||
* This is just a small macro which calculates the size of an array.
|
||||
*/
|
||||
#define CAG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/**
|
||||
* @brief Prints all options to the terminal.
|
||||
*
|
||||
* This function prints all options to the terminal. This can be used to
|
||||
* generate the output for a "--help" option.
|
||||
*
|
||||
* @param options The options which will be printed.
|
||||
* @param option_count The option count which will be printed.
|
||||
* @param destination The destination where the output will be printed.
|
||||
*/
|
||||
CAG_PUBLIC void cag_option_print(const cag_option *options, size_t option_count,
|
||||
FILE *destination);
|
||||
/**
|
||||
* @brief Prints all options to the terminal.
|
||||
*
|
||||
* This function prints all options to the terminal. This can be used to
|
||||
* generate the output for a "--help" option.
|
||||
*
|
||||
* @param options The options which will be printed.
|
||||
* @param option_count The option count which will be printed.
|
||||
* @param destination The destination where the output will be printed.
|
||||
*/
|
||||
CAG_PUBLIC void cag_option_print(const cag_option *options, size_t option_count,
|
||||
FILE *destination);
|
||||
|
||||
/**
|
||||
* @brief Prepare argument options context for parsing.
|
||||
*
|
||||
* This function prepares the context for iteration and initializes the context
|
||||
* with the supplied options and arguments. After the context has been prepared,
|
||||
* it can be used to fetch arguments from it.
|
||||
*
|
||||
* @param context The context which will be initialized.
|
||||
* @param options The registered options which are available for the program.
|
||||
* @param option_count The amount of options which are available for the
|
||||
* program.
|
||||
* @param argc The amount of arguments the user supplied in the main function.
|
||||
* @param argv A pointer to the arguments of the main function.
|
||||
*/
|
||||
CAG_PUBLIC void cag_option_prepare(cag_option_context *context,
|
||||
const cag_option *options, size_t option_count, int argc, char **argv);
|
||||
/**
|
||||
* @brief Prepare argument options context for parsing.
|
||||
*
|
||||
* This function prepares the context for iteration and initializes the context
|
||||
* with the supplied options and arguments. After the context has been prepared,
|
||||
* it can be used to fetch arguments from it.
|
||||
*
|
||||
* @param context The context which will be initialized.
|
||||
* @param options The registered options which are available for the program.
|
||||
* @param option_count The amount of options which are available for the
|
||||
* program.
|
||||
* @param argc The amount of arguments the user supplied in the main function.
|
||||
* @param argv A pointer to the arguments of the main function.
|
||||
*/
|
||||
CAG_PUBLIC void cag_option_prepare(cag_option_context *context,
|
||||
const cag_option *options, size_t option_count, int argc, char **argv);
|
||||
|
||||
/**
|
||||
* @brief Fetches an option from the argument list.
|
||||
*
|
||||
* This function fetches a single option from the argument list. The context
|
||||
* will be moved to that item. Information can be extracted from the context
|
||||
* after the item has been fetched.
|
||||
* The arguments will be re-ordered, which means that non-option arguments will
|
||||
* be moved to the end of the argument list. After all options have been
|
||||
* fetched, all non-option arguments will be positioned after the index of
|
||||
* the context.
|
||||
*
|
||||
* @param context The context from which we will fetch the option.
|
||||
* @return Returns true if there was another option or false if the end is
|
||||
* reached.
|
||||
*/
|
||||
CAG_PUBLIC bool cag_option_fetch(cag_option_context *context);
|
||||
/**
|
||||
* @brief Fetches an option from the argument list.
|
||||
*
|
||||
* This function fetches a single option from the argument list. The context
|
||||
* will be moved to that item. Information can be extracted from the context
|
||||
* after the item has been fetched.
|
||||
* The arguments will be re-ordered, which means that non-option arguments will
|
||||
* be moved to the end of the argument list. After all options have been
|
||||
* fetched, all non-option arguments will be positioned after the index of
|
||||
* the context.
|
||||
*
|
||||
* @param context The context from which we will fetch the option.
|
||||
* @return Returns true if there was another option or false if the end is
|
||||
* reached.
|
||||
*/
|
||||
CAG_PUBLIC bool cag_option_fetch(cag_option_context *context);
|
||||
|
||||
/**
|
||||
* @brief Gets the identifier of the option.
|
||||
*
|
||||
* This function gets the identifier of the option, which should be unique to
|
||||
* this option and can be used to determine what kind of option this is.
|
||||
*
|
||||
* @param context The context from which the option was fetched.
|
||||
* @return Returns the identifier of the option.
|
||||
*/
|
||||
CAG_PUBLIC char cag_option_get(const cag_option_context *context);
|
||||
/**
|
||||
* @brief Gets the identifier of the option.
|
||||
*
|
||||
* This function gets the identifier of the option, which should be unique to
|
||||
* this option and can be used to determine what kind of option this is.
|
||||
*
|
||||
* @param context The context from which the option was fetched.
|
||||
* @return Returns the identifier of the option.
|
||||
*/
|
||||
CAG_PUBLIC char cag_option_get(const cag_option_context *context);
|
||||
|
||||
/**
|
||||
* @brief Gets the value from the option.
|
||||
*
|
||||
* This function gets the value from the option, if any. If the option does not
|
||||
* contain a value, this function will return NULL.
|
||||
*
|
||||
* @param context The context from which the option was fetched.
|
||||
* @return Returns a pointer to the value or NULL if there is no value.
|
||||
*/
|
||||
CAG_PUBLIC const char *cag_option_get_value(const cag_option_context *context);
|
||||
/**
|
||||
* @brief Gets the value from the option.
|
||||
*
|
||||
* This function gets the value from the option, if any. If the option does not
|
||||
* contain a value, this function will return NULL.
|
||||
*
|
||||
* @param context The context from which the option was fetched.
|
||||
* @return Returns a pointer to the value or NULL if there is no value.
|
||||
*/
|
||||
CAG_PUBLIC const char *cag_option_get_value(const cag_option_context *context);
|
||||
|
||||
/**
|
||||
* @brief Gets the current index of the context.
|
||||
*
|
||||
* This function gets the index within the argv arguments of the context. The
|
||||
* context always points to the next item which it will inspect. This is
|
||||
* particularly useful to inspect the original argument array, or to get
|
||||
* non-option arguments after option fetching has finished.
|
||||
*
|
||||
* @param context The context from which the option was fetched.
|
||||
* @return Returns the current index of the context.
|
||||
*/
|
||||
CAG_PUBLIC int cag_option_get_index(const cag_option_context *context);
|
||||
/**
|
||||
* @brief Gets the current index of the context.
|
||||
*
|
||||
* This function gets the index within the argv arguments of the context. The
|
||||
* context always points to the next item which it will inspect. This is
|
||||
* particularly useful to inspect the original argument array, or to get
|
||||
* non-option arguments after option fetching has finished.
|
||||
*
|
||||
* @param context The context from which the option was fetched.
|
||||
* @return Returns the current index of the context.
|
||||
*/
|
||||
CAG_PUBLIC int cag_option_get_index(const cag_option_context *context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
@ -23,90 +23,99 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct mbstate_t
|
||||
{
|
||||
int count;
|
||||
unsigned int value;
|
||||
} mbstate_t;
|
||||
typedef struct mbstate_t
|
||||
{
|
||||
int count;
|
||||
unsigned int value;
|
||||
} mbstate_t;
|
||||
|
||||
#define NAN (__builtin_nanf(""))
|
||||
|
||||
int isdigit(int c);
|
||||
int isspace(int c);
|
||||
int isempty(char *str);
|
||||
int isalpha(int c);
|
||||
int isupper(int c);
|
||||
unsigned int isdelim(char c, const char *delim);
|
||||
long abs(long i);
|
||||
void swap(char *x, char *y);
|
||||
char *reverse(char *Buffer, int i, int j);
|
||||
int isdigit(int c);
|
||||
int isspace(int c);
|
||||
int isempty(char *str);
|
||||
int isalpha(int c);
|
||||
int isupper(int c);
|
||||
unsigned int isdelim(char c, const char *delim);
|
||||
long abs(long i);
|
||||
void swap(char *x, char *y);
|
||||
char *reverse(char *Buffer, int i, int j);
|
||||
|
||||
float sqrtf(float x);
|
||||
double clamp(double x, double low, double high);
|
||||
float sqrtf(float x);
|
||||
double clamp(double x, double low, double high);
|
||||
|
||||
float lerp(float a, float b, float t);
|
||||
float smoothstep(float a, float b, float t);
|
||||
float cubicInterpolate(float a, float b, float t);
|
||||
float lerp(float a, float b, float t);
|
||||
float smoothstep(float a, float b, float t);
|
||||
float cubicInterpolate(float a, float b, float t);
|
||||
|
||||
void backspace(char s[]);
|
||||
void append(char s[], char n);
|
||||
void backspace(char s[]);
|
||||
void append(char s[], char n);
|
||||
|
||||
int atoi(const char *String);
|
||||
double atof(const char *String);
|
||||
char *itoa(int Value, char *Buffer, int Base);
|
||||
char *ltoa(long Value, char *Buffer, int Base);
|
||||
char *ultoa(unsigned long Value, char *Buffer, int Base);
|
||||
unsigned long int strtoul(const char *str, char **endptr, int base);
|
||||
int atoi(const char *String);
|
||||
double atof(const char *String);
|
||||
char *itoa(int Value, char *Buffer, int Base);
|
||||
char *ltoa(long Value, char *Buffer, int Base);
|
||||
char *ultoa(unsigned long Value, char *Buffer, int Base);
|
||||
unsigned long int strtoul(const char *str, char **endptr, int base);
|
||||
|
||||
void *memcpy_unsafe(void *dest, const void *src, size_t n);
|
||||
void *memset_unsafe(void *dest, int c, size_t n);
|
||||
void *memmove_unsafe(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *vl, const void *vr, size_t n);
|
||||
void *memcpy_unsafe(void *dest, const void *src, size_t n);
|
||||
void *memset_unsafe(void *dest, int c, size_t n);
|
||||
void *memmove_unsafe(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *vl, const void *vr, size_t n);
|
||||
|
||||
void *memcpy_sse(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse2(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse3(void *dest, const void *src, size_t n);
|
||||
void *memcpy_ssse3(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse4_1(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse4_2(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse2(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse3(void *dest, const void *src, size_t n);
|
||||
void *memcpy_ssse3(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse4_1(void *dest, const void *src, size_t n);
|
||||
void *memcpy_sse4_2(void *dest, const void *src, size_t n);
|
||||
|
||||
void *memset_sse(void *dest, int c, size_t n);
|
||||
void *memset_sse2(void *dest, int c, size_t n);
|
||||
void *memset_sse3(void *dest, int c, size_t n);
|
||||
void *memset_ssse3(void *dest, int c, size_t n);
|
||||
void *memset_sse4_1(void *dest, int c, size_t n);
|
||||
void *memset_sse4_2(void *dest, int c, size_t n);
|
||||
void *memset_sse(void *dest, int c, size_t n);
|
||||
void *memset_sse2(void *dest, int c, size_t n);
|
||||
void *memset_sse3(void *dest, int c, size_t n);
|
||||
void *memset_ssse3(void *dest, int c, size_t n);
|
||||
void *memset_sse4_1(void *dest, int c, size_t n);
|
||||
void *memset_sse4_2(void *dest, int c, size_t n);
|
||||
|
||||
void *memmove_sse(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse2(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse3(void *dest, const void *src, size_t n);
|
||||
void *memmove_ssse3(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse4_1(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse4_2(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse2(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse3(void *dest, const void *src, size_t n);
|
||||
void *memmove_ssse3(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse4_1(void *dest, const void *src, size_t n);
|
||||
void *memmove_sse4_2(void *dest, const void *src, size_t n);
|
||||
|
||||
long unsigned strlen(const char s[]);
|
||||
int strncmp(const char *s1, const char *s2, unsigned long n);
|
||||
char *strcat_unsafe(char *destination, const char *source);
|
||||
char *strcpy_unsafe(char *destination, const char *source);
|
||||
char *strncpy(char *destination, const char *source, unsigned long num);
|
||||
int strcmp(const char *l, const char *r);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
char *strdup(const char *String);
|
||||
char *strchr(const char *String, int Char);
|
||||
char *strrchr(const char *String, int Char);
|
||||
int strncasecmp(const char *lhs, const char *rhs, long unsigned int Count);
|
||||
int strcasecmp(const char *s1, const char *s2);
|
||||
char *strtok(char *src, const char *delim);
|
||||
long int strtol(const char *str, char **endptr, int base);
|
||||
size_t wcslen(const wchar_t *s);
|
||||
size_t wcsrtombs(char *dst, const wchar_t **src, size_t len, mbstate_t *ps);
|
||||
int log2(unsigned int n);
|
||||
long unsigned __strlen(const char s[]);
|
||||
|
||||
void *__memcpy_chk(void *dest, const void *src, size_t len, size_t slen);
|
||||
void *__memset_chk(void *dest, int val, size_t len, size_t slen);
|
||||
void *__memmove_chk(void *dest, const void *src, size_t len, size_t slen);
|
||||
char *__strcat_chk(char *dest, const char *src, size_t slen);
|
||||
char *__strcpy_chk(char *dest, const char *src, size_t slen);
|
||||
long unsigned strlen_sse(const char s[]);
|
||||
long unsigned strlen_sse2(const char s[]);
|
||||
long unsigned strlen_sse3(const char s[]);
|
||||
long unsigned strlen_ssse3(const char s[]);
|
||||
long unsigned strlen_sse4_1(const char s[]);
|
||||
long unsigned strlen_sse4_2(const char s[]);
|
||||
|
||||
long unsigned strlen(const char s[]);
|
||||
int strncmp(const char *s1, const char *s2, unsigned long n);
|
||||
char *strcat_unsafe(char *destination, const char *source);
|
||||
char *strcpy_unsafe(char *destination, const char *source);
|
||||
char *strncpy(char *destination, const char *source, unsigned long num);
|
||||
int strcmp(const char *l, const char *r);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
char *strdup(const char *String);
|
||||
char *strchr(const char *String, int Char);
|
||||
char *strrchr(const char *String, int Char);
|
||||
int strncasecmp(const char *string1, const char *string2, size_t count);
|
||||
int strcasecmp(const char *s1, const char *s2);
|
||||
char *strtok(char *src, const char *delim);
|
||||
long int strtol(const char *str, char **endptr, int base);
|
||||
size_t wcslen(const wchar_t *s);
|
||||
size_t wcsrtombs(char *dst, const wchar_t **src, size_t len, mbstate_t *ps);
|
||||
int log2(unsigned int n);
|
||||
|
||||
void *__memcpy_chk(void *dest, const void *src, size_t len, size_t slen);
|
||||
void *__memset_chk(void *dest, int val, size_t len, size_t slen);
|
||||
void *__memmove_chk(void *dest, const void *src, size_t len, size_t slen);
|
||||
char *__strcat_chk(char *dest, const char *src, size_t slen);
|
||||
char *__strcpy_chk(char *dest, const char *src, size_t slen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -114,20 +123,20 @@ extern "C"
|
||||
|
||||
#undef memcpy
|
||||
#define memcpy(dest, src, n) \
|
||||
__memcpy_chk(dest, src, n, __builtin_object_size(dest, 0))
|
||||
__memcpy_chk(dest, src, n, __builtin_object_size(dest, 0))
|
||||
|
||||
#undef memset
|
||||
#define memset(dest, c, n) \
|
||||
__memset_chk(dest, c, n, __builtin_object_size(dest, 0))
|
||||
__memset_chk(dest, c, n, __builtin_object_size(dest, 0))
|
||||
|
||||
#undef memmove
|
||||
#define memmove(dest, src, n) \
|
||||
__memmove_chk(dest, src, n, __builtin_object_size(dest, 0))
|
||||
__memmove_chk(dest, src, n, __builtin_object_size(dest, 0))
|
||||
|
||||
#undef strcat
|
||||
#define strcat(dest, src) \
|
||||
__strcat_chk(dest, src, __builtin_object_size(dest, 0))
|
||||
__strcat_chk(dest, src, __builtin_object_size(dest, 0))
|
||||
|
||||
#undef strcpy
|
||||
#define strcpy(dest, src) \
|
||||
__strcpy_chk(dest, src, __builtin_object_size(dest, 0))
|
||||
__strcpy_chk(dest, src, __builtin_object_size(dest, 0))
|
||||
|
@ -161,7 +161,7 @@ namespace CPU
|
||||
"cli\n"
|
||||
"hlt\n"
|
||||
"jmp CPUStopLoop");
|
||||
#elif defined(aa64) // annoying warning: "‘noreturn’ function does return" and "‘naked’ attribute directive ignored"
|
||||
#elif defined(aa64) // annoying warning: "'noreturn' function does return" and "'naked' attribute directive ignored"
|
||||
SafeFunction __used inline void Stop()
|
||||
{
|
||||
asmv("CPUStopLoop:\n"
|
||||
@ -198,10 +198,13 @@ namespace CPU
|
||||
* @brief Get/Set the CPU's page table
|
||||
*
|
||||
* @param PT The new page table, if empty, the current page table will be returned
|
||||
* @return void* The current page table
|
||||
* @return Get: The current page table
|
||||
* @return Set: The old page table
|
||||
*/
|
||||
void *PageTable(void *PT = nullptr);
|
||||
|
||||
#define thisPageTable (Memory::PageTable *)CPU::PageTable()
|
||||
|
||||
/** @brief To be used only once. */
|
||||
void InitializeFeatures(int Core);
|
||||
|
||||
@ -826,7 +829,7 @@ namespace CPU
|
||||
uint8_t st[8][16];
|
||||
/** @brief XMM registers */
|
||||
uint8_t xmm[16][16];
|
||||
} __packed;
|
||||
} __packed __aligned(16);
|
||||
|
||||
SafeFunction static inline void lgdt(void *gdt)
|
||||
{
|
||||
@ -950,6 +953,29 @@ namespace CPU
|
||||
uint64_t InterruptNumber /* iar_el1 */; // Interrupt Acknowledge Register
|
||||
} TrapFrame;
|
||||
}
|
||||
|
||||
#if defined(a64)
|
||||
/**
|
||||
* CPU trap frame for the current architecture
|
||||
*
|
||||
* @note This is for x86_64
|
||||
*/
|
||||
typedef x64::TrapFrame TrapFrame;
|
||||
#elif defined(a32)
|
||||
/**
|
||||
* CPU trap frame for the current architecture
|
||||
*
|
||||
* @note This is for x86_32
|
||||
*/
|
||||
typedef x32::TrapFrame TrapFrame;
|
||||
#elif defined(aa64)
|
||||
/**
|
||||
* CPU trap frame for the current architecture
|
||||
*
|
||||
* @note This is for aarch64
|
||||
*/
|
||||
typedef aarch64::TrapFrame TrapFrame;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_CPU_H__
|
||||
|
@ -1,18 +1,18 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
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 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.
|
||||
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/>.
|
||||
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_CPU_x86_INTERRUPTS_H__
|
||||
@ -82,7 +82,7 @@ namespace CPU
|
||||
|
||||
/* Reserved by OS */
|
||||
|
||||
IRQ16 = 0x30, // Reserved for multitasking
|
||||
IRQ16 = 0x30, /* Reserved for multitasking */
|
||||
IRQ17 = 0x31,
|
||||
IRQ18 = 0x32,
|
||||
IRQ19 = 0x33,
|
||||
@ -95,12 +95,11 @@ namespace CPU
|
||||
IRQ26 = 0x3a,
|
||||
IRQ27 = 0x3b,
|
||||
IRQ28 = 0x3c,
|
||||
IRQ29 = 0x3d, // Reserved for icr stop core
|
||||
IRQ29 = 0x3d,
|
||||
IRQ30 = 0x3e,
|
||||
IRQ31 = 0x3f, /* Halt core interrupt */
|
||||
|
||||
/* Free */
|
||||
|
||||
IRQ30 = 0x3e,
|
||||
IRQ31 = 0x3f,
|
||||
IRQ32 = 0x40,
|
||||
IRQ33 = 0x41,
|
||||
IRQ34 = 0x42,
|
||||
|
@ -117,4 +117,6 @@ void SysDbgLockedWriteLine(enum DebugLevel Level, const char *File, int Line, co
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
EXTERNC void uart_wrapper(char c, void *unused);
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DEBUGGER_H__
|
||||
|
208
include/driver.hpp
Normal file
208
include/driver.hpp
Normal file
@ -0,0 +1,208 @@
|
||||
/*
|
||||
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_DRIVER_H__
|
||||
#define __FENNIX_KERNEL_DRIVER_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <unordered_map>
|
||||
#include <memory.hpp>
|
||||
#include <ints.hpp>
|
||||
#include <lock.hpp>
|
||||
#include <task.hpp>
|
||||
#include <debug.h>
|
||||
#include <cpu.hpp>
|
||||
#include <pci.hpp>
|
||||
#include <vector>
|
||||
#include <io.h>
|
||||
#include <list>
|
||||
|
||||
namespace Driver
|
||||
{
|
||||
char GetScanCode(uint8_t ScanCode, bool Upper);
|
||||
bool IsValidChar(uint8_t ScanCode);
|
||||
|
||||
class SlaveDeviceFile : public vfs::Node
|
||||
{
|
||||
private:
|
||||
int /* DeviceDriverType */ DeviceType;
|
||||
|
||||
std::list<uint8_t> KeyQueue;
|
||||
|
||||
public:
|
||||
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
|
||||
typedef int (*drvClose_t)(dev_t, dev_t);
|
||||
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
|
||||
|
||||
drvOpen_t Open;
|
||||
drvClose_t Close;
|
||||
drvRead_t Read;
|
||||
drvWrite_t Write;
|
||||
drvIoctl_t Ioctl;
|
||||
|
||||
int open(int Flags, mode_t Mode) final;
|
||||
int close() final;
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
void ClearBuffers();
|
||||
|
||||
int ReportKeyEvent(uint8_t ScanCode);
|
||||
|
||||
SlaveDeviceFile(const char *Name, vfs::Node *Parent, int Type, vfs::NodeType NType);
|
||||
~SlaveDeviceFile();
|
||||
};
|
||||
|
||||
class MasterDeviceFile : private vfs::Node
|
||||
{
|
||||
private:
|
||||
typedef dev_t maj_t;
|
||||
typedef dev_t min_t;
|
||||
char SlaveName[16];
|
||||
vfs::Node *SlaveParent;
|
||||
int /* DeviceDriverType */ DeviceType;
|
||||
min_t SlaveIDCounter = 0;
|
||||
|
||||
typedef std::unordered_map<min_t, SlaveDeviceFile *> *Slaves;
|
||||
std::unordered_map<maj_t, Slaves> SlavesMap;
|
||||
|
||||
std::list<uint8_t> RawKeyQueue;
|
||||
std::list<uint8_t> KeyQueue;
|
||||
bool UpperCase = false;
|
||||
bool CapsLock = false;
|
||||
|
||||
public:
|
||||
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
|
||||
typedef int (*drvClose_t)(dev_t, dev_t);
|
||||
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
|
||||
|
||||
int open(int Flags, mode_t Mode) final;
|
||||
int close() final;
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
void ClearBuffers();
|
||||
|
||||
int ReportKeyEvent(maj_t ID, min_t MinorID, uint8_t ScanCode);
|
||||
int ReportMouseEvent(maj_t ID, min_t MinorID,
|
||||
bool LeftButton, bool RightButton, bool MiddleButton,
|
||||
bool Button4, bool Button5, bool Button6,
|
||||
bool Button7, bool Button8,
|
||||
uintptr_t X, uintptr_t Y, int8_t Z, bool Relative);
|
||||
|
||||
int ReportNetworkPacket(maj_t ID, min_t MinorID, void *Buffer, size_t Size);
|
||||
|
||||
int NewBlock(maj_t ID, min_t MinorID, drvOpen_t Open, drvClose_t Close,
|
||||
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
|
||||
|
||||
int NewAudio(maj_t ID, min_t MinorID, drvOpen_t Open, drvClose_t Close,
|
||||
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
|
||||
|
||||
int NewNet(maj_t ID, min_t MinorID, drvOpen_t Open, drvClose_t Close,
|
||||
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
|
||||
|
||||
dev_t Register(maj_t ID);
|
||||
int Unregister(maj_t ID, min_t MinorID);
|
||||
|
||||
MasterDeviceFile(const char *MasterName,
|
||||
const char *SlaveName,
|
||||
vfs::Node *Parent,
|
||||
int Type);
|
||||
~MasterDeviceFile();
|
||||
};
|
||||
|
||||
struct DriverObject
|
||||
{
|
||||
uintptr_t BaseAddress = 0;
|
||||
uintptr_t EntryPoint = 0;
|
||||
Memory::VirtualMemoryArea *vma = nullptr;
|
||||
|
||||
/* Path has the same pointer as in the Node */
|
||||
const char *Path = nullptr;
|
||||
std::unordered_map<uint8_t, void *> *InterruptHandlers;
|
||||
|
||||
char Name[32] = {'\0'};
|
||||
char Description[64] = {'\0'};
|
||||
char Author[32] = {'\0'};
|
||||
char Version[16] = {'\0'};
|
||||
char License[32] = {'\0'};
|
||||
bool Initialized = false;
|
||||
int ErrorCode = 0;
|
||||
|
||||
int (*Entry)() = nullptr;
|
||||
int (*Final)() = nullptr;
|
||||
int (*Panic)() = nullptr;
|
||||
int (*Probe)() = nullptr;
|
||||
};
|
||||
|
||||
class Manager
|
||||
{
|
||||
private:
|
||||
NewLock(ModuleInitLock);
|
||||
std::unordered_map<dev_t, DriverObject> Drivers;
|
||||
dev_t MajorIDCounter = 0;
|
||||
|
||||
int LoadDriverFile(uintptr_t &EntryPoint,
|
||||
uintptr_t &BaseAddress,
|
||||
Memory::VirtualMemoryArea *dVma,
|
||||
vfs::RefNode *rDrv);
|
||||
|
||||
public:
|
||||
MasterDeviceFile *InputMouseDev = nullptr;
|
||||
MasterDeviceFile *InputKeyboardDev = nullptr;
|
||||
|
||||
MasterDeviceFile *BlockSATADev = nullptr;
|
||||
MasterDeviceFile *BlockHDDev = nullptr;
|
||||
MasterDeviceFile *BlockNVMeDev = nullptr;
|
||||
|
||||
MasterDeviceFile *AudioDev = nullptr;
|
||||
|
||||
MasterDeviceFile *NetDev = nullptr;
|
||||
|
||||
std::unordered_map<dev_t, DriverObject> &
|
||||
GetDrivers() { return Drivers; }
|
||||
|
||||
void LoadAllDrivers();
|
||||
void UnloadAllDrivers();
|
||||
void Panic();
|
||||
|
||||
Manager();
|
||||
~Manager();
|
||||
};
|
||||
|
||||
void PopulateDriverAPI(void *API);
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DRIVER_H__
|
209
include/elf.h
209
include/elf.h
@ -26,6 +26,7 @@ typedef uint16_t Elf32_Half;
|
||||
typedef uint32_t Elf32_Off;
|
||||
typedef int32_t Elf32_Sword;
|
||||
typedef uint32_t Elf32_Word;
|
||||
typedef Elf32_Sword Elf32_pid_t;
|
||||
|
||||
/* 64-bit ELF base types. */
|
||||
typedef uint64_t Elf64_Addr;
|
||||
@ -36,6 +37,11 @@ typedef int32_t Elf64_Sword;
|
||||
typedef uint32_t Elf64_Word;
|
||||
typedef uint64_t Elf64_Xword;
|
||||
typedef int64_t Elf64_Sxword;
|
||||
typedef Elf64_Sword Elf64_pid_t;
|
||||
|
||||
#define ELF_NGREG 23
|
||||
typedef Elf32_Word Elf32_greg_t[ELF_NGREG];
|
||||
typedef Elf64_Xword Elf64_greg_t[ELF_NGREG];
|
||||
|
||||
enum IdentificationIndex
|
||||
{
|
||||
@ -227,8 +233,6 @@ enum SegmentTypes
|
||||
PT_TLS = 7,
|
||||
PT_LOPROC = 0x70000000,
|
||||
PT_HIPROC = 0x7fffffff,
|
||||
PT_GNU_EH_FRAME = 0x6474e550,
|
||||
PT_GNU_STACK = 0x6474e551,
|
||||
};
|
||||
|
||||
enum DynamicArrayTags
|
||||
@ -305,15 +309,15 @@ enum DynamicArrayTags
|
||||
|
||||
/* Used for Elf64_Sym st_info */
|
||||
#define ELF32_ST_BIND(info) ((info) >> 4)
|
||||
#define ELF32_ST_TYPE(info) ((info)&0xf)
|
||||
#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
|
||||
#define ELF32_ST_TYPE(info) ((info) & 0xf)
|
||||
#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
|
||||
#define ELF64_ST_BIND(info) ((info) >> 4)
|
||||
#define ELF64_ST_TYPE(info) ((info)&0xf)
|
||||
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
|
||||
#define ELF64_ST_TYPE(info) ((info) & 0xf)
|
||||
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
|
||||
|
||||
/* Used for Elf64_Sym st_other */
|
||||
#define ELF32_ST_VISIBILITY(o) ((o)&0x3)
|
||||
#define ELF64_ST_VISIBILITY(o) ((o)&0x3)
|
||||
#define ELF32_ST_VISIBILITY(o) ((o) & 0x3)
|
||||
#define ELF64_ST_VISIBILITY(o) ((o) & 0x3)
|
||||
|
||||
#define DO_386_32(S, A) ((S) + (A))
|
||||
#define DO_386_PC32(S, A, P) ((S) + (A) - (P))
|
||||
@ -326,8 +330,8 @@ enum DynamicArrayTags
|
||||
#define ELF32_R_INFO(s, t) (((s) << 8) + (unsigned char)(t))
|
||||
|
||||
#define ELF64_R_SYM(i) ((i) >> 32)
|
||||
#define ELF64_R_TYPE(i) ((i)&0xffffffffL)
|
||||
#define ELF64_R_INFO(s, t) (((s) << 32) + ((t)&0xffffffffL))
|
||||
#define ELF64_R_TYPE(i) ((i) & 0xffffffffL)
|
||||
#define ELF64_R_INFO(s, t) (((s) << 32) + ((t) & 0xffffffffL))
|
||||
|
||||
#define SHN_UNDEF 0
|
||||
#define SHN_ABS 0xfff1
|
||||
@ -576,6 +580,80 @@ enum SpecialSections
|
||||
SHT_HIUSER = 0x8fffffff
|
||||
};
|
||||
|
||||
#define NT_PRSTATUS 1
|
||||
#define NT_PRFPREG 2
|
||||
#define NT_FPREGSET 2
|
||||
#define NT_PRPSINFO 3
|
||||
#define NT_PRXREG 4
|
||||
#define NT_TASKSTRUCT 4
|
||||
#define NT_PLATFORM 5
|
||||
#define NT_AUXV 6
|
||||
#define NT_GWINDOWS 7
|
||||
#define NT_ASRS 8
|
||||
#define NT_PSTATUS 10
|
||||
#define NT_PSINFO 13
|
||||
#define NT_PRCRED 14
|
||||
#define NT_UTSNAME 15
|
||||
#define NT_LWPSTATUS 16
|
||||
#define NT_LWPSINFO 17
|
||||
#define NT_PRFPXREG 20
|
||||
#define NT_SIGINFO 0x53494749
|
||||
#define NT_FILE 0x46494c45
|
||||
#define NT_PRXFPREG 0x46e62b7f
|
||||
#define NT_PPC_VMX 0x100
|
||||
#define NT_PPC_SPE 0x101
|
||||
#define NT_PPC_VSX 0x102
|
||||
#define NT_PPC_TAR 0x103
|
||||
#define NT_PPC_PPR 0x104
|
||||
#define NT_PPC_DSCR 0x105
|
||||
#define NT_PPC_EBB 0x106
|
||||
#define NT_PPC_PMU 0x107
|
||||
#define NT_PPC_TM_CGPR 0x108
|
||||
#define NT_PPC_TM_CFPR 0x109
|
||||
#define NT_PPC_TM_CVMX 0x10a
|
||||
#define NT_PPC_TM_CVSX 0x10b
|
||||
#define NT_PPC_TM_SPR 0x10c
|
||||
#define NT_PPC_TM_CTAR 0x10d
|
||||
#define NT_PPC_TM_CPPR 0x10e
|
||||
#define NT_PPC_TM_CDSCR 0x10f
|
||||
#define NT_386_TLS 0x200
|
||||
#define NT_386_IOPERM 0x201
|
||||
#define NT_X86_XSTATE 0x202
|
||||
#define NT_S390_HIGH_GPRS 0x300
|
||||
#define NT_S390_TIMER 0x301
|
||||
#define NT_S390_TODCMP 0x302
|
||||
#define NT_S390_TODPREG 0x303
|
||||
#define NT_S390_CTRS 0x304
|
||||
#define NT_S390_PREFIX 0x305
|
||||
#define NT_S390_LAST_BREAK 0x306
|
||||
#define NT_S390_SYSTEM_CALL 0x307
|
||||
#define NT_S390_TDB 0x308
|
||||
#define NT_S390_VXRS_LOW 0x309
|
||||
#define NT_S390_VXRS_HIGH 0x30a
|
||||
#define NT_S390_GS_CB 0x30b
|
||||
#define NT_S390_GS_BC 0x30c
|
||||
#define NT_S390_RI_CB 0x30d
|
||||
#define NT_ARM_VFP 0x400
|
||||
#define NT_ARM_TLS 0x401
|
||||
#define NT_ARM_HW_BREAK 0x402
|
||||
#define NT_ARM_HW_WATCH 0x403
|
||||
#define NT_ARM_SYSTEM_CALL 0x404
|
||||
#define NT_ARM_SVE 0x405
|
||||
#define NT_ARM_PAC_MASK 0x406
|
||||
#define NT_ARM_PACA_KEYS 0x407
|
||||
#define NT_ARM_PACG_KEYS 0x408
|
||||
#define NT_ARM_TAGGED_ADDR_CTRL 0x409
|
||||
#define NT_ARM_PAC_ENABLED_KEYS 0x40a
|
||||
#define NT_METAG_CBUF 0x500
|
||||
#define NT_METAG_RPIPE 0x501
|
||||
#define NT_METAG_TLS 0x502
|
||||
#define NT_ARC_V2 0x600
|
||||
#define NT_VMCOREDD 0x700
|
||||
#define NT_MIPS_DSP 0x800
|
||||
#define NT_MIPS_FP_MODE 0x801
|
||||
#define NT_MIPS_MSA 0x802
|
||||
#define NT_VERSION 1
|
||||
|
||||
typedef struct elf32_hdr
|
||||
{
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
@ -730,6 +808,117 @@ typedef struct
|
||||
Elf64_Sxword r_addend;
|
||||
} Elf64_Rela;
|
||||
|
||||
struct Elf32_Nhdr
|
||||
{
|
||||
Elf32_Word n_namesz;
|
||||
Elf32_Word n_descsz;
|
||||
Elf32_Word n_type;
|
||||
};
|
||||
|
||||
struct Elf64_Nhdr
|
||||
{
|
||||
Elf64_Word n_namesz;
|
||||
Elf64_Word n_descsz;
|
||||
Elf64_Word n_type;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword si_signo;
|
||||
Elf32_Sword si_code;
|
||||
Elf32_Sword si_errno;
|
||||
} Elf32_Siginfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Sword si_signo;
|
||||
Elf64_Sword si_code;
|
||||
Elf64_Sword si_errno;
|
||||
} Elf64_Siginfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword tv_sec;
|
||||
Elf32_Sword tv_usec;
|
||||
} Elf32_Prtimeval;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Sxword tv_sec;
|
||||
Elf64_Sxword tv_usec;
|
||||
} Elf64_Prtimeval;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Siginfo pr_info;
|
||||
Elf32_Half pr_cursig;
|
||||
Elf32_Word pr_sigpend;
|
||||
Elf32_Word pr_sighold;
|
||||
Elf32_pid_t pr_pid;
|
||||
Elf32_pid_t pr_ppid;
|
||||
Elf32_pid_t pr_pgrp;
|
||||
Elf32_pid_t pr_sid;
|
||||
Elf32_Prtimeval pr_utime;
|
||||
Elf32_Prtimeval pr_stime;
|
||||
Elf32_Prtimeval pr_cutime;
|
||||
Elf32_Prtimeval pr_cstime;
|
||||
Elf32_greg_t pr_reg;
|
||||
Elf32_Word pr_fpvalid;
|
||||
} Elf32_Prstatus;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Siginfo pr_info;
|
||||
Elf64_Half pr_cursig;
|
||||
Elf64_Word pr_sigpend;
|
||||
Elf64_Word pr_sighold;
|
||||
Elf64_pid_t pr_pid;
|
||||
Elf64_pid_t pr_ppid;
|
||||
Elf64_pid_t pr_pgrp;
|
||||
Elf64_pid_t pr_sid;
|
||||
Elf64_Prtimeval pr_utime;
|
||||
Elf64_Prtimeval pr_stime;
|
||||
Elf64_Prtimeval pr_cutime;
|
||||
Elf64_Prtimeval pr_cstime;
|
||||
Elf64_greg_t pr_reg;
|
||||
Elf64_Word pr_fpvalid;
|
||||
} Elf64_Prstatus;
|
||||
|
||||
#define ELF_PRARGSZ 80
|
||||
typedef struct
|
||||
{
|
||||
char pr_state;
|
||||
char pr_sname;
|
||||
char pr_zomb;
|
||||
char pr_nice;
|
||||
Elf32_Word pr_flag;
|
||||
Elf32_Half pr_uid;
|
||||
Elf32_Half pr_gid;
|
||||
Elf32_pid_t pr_pid;
|
||||
Elf32_pid_t pr_ppid;
|
||||
Elf32_pid_t pr_pgrp;
|
||||
Elf32_pid_t pr_sid;
|
||||
char pr_fname[16];
|
||||
char pr_psargs[ELF_PRARGSZ];
|
||||
} Elf32_Prpsinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char pr_state;
|
||||
char pr_sname;
|
||||
char pr_zomb;
|
||||
char pr_nice;
|
||||
Elf64_Xword pr_flag;
|
||||
Elf64_Half pr_uid;
|
||||
Elf64_Half pr_gid;
|
||||
Elf64_pid_t pr_pid;
|
||||
Elf64_pid_t pr_ppid;
|
||||
Elf64_pid_t pr_pgrp;
|
||||
Elf64_pid_t pr_sid;
|
||||
char pr_fname[16];
|
||||
char pr_psargs[ELF_PRARGSZ];
|
||||
} Elf64_Prpsinfo;
|
||||
|
||||
#if defined(a64) || defined(aa64)
|
||||
typedef Elf64_Addr Elf_Addr;
|
||||
typedef Elf64_Half Elf_Half;
|
||||
|
@ -32,7 +32,6 @@ namespace Execute
|
||||
enum BinaryType : int
|
||||
{
|
||||
BinTypeInvalid,
|
||||
BinTypeFex,
|
||||
BinTypeELF,
|
||||
BinTypePE,
|
||||
BinTypeNE,
|
||||
@ -122,7 +121,7 @@ namespace Execute
|
||||
BinaryType GetBinaryType(const char *Path);
|
||||
|
||||
int Spawn(char *Path, const char **argv, const char **envp,
|
||||
Tasking::PCB *Parent = nullptr,
|
||||
Tasking::PCB *Parent = nullptr, bool Fork = false,
|
||||
Tasking::TaskCompatibility Compatibility = Tasking::TaskCompatibility::Native,
|
||||
bool Critical = false);
|
||||
|
||||
|
@ -84,40 +84,81 @@
|
||||
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
|
||||
|
||||
/**
|
||||
* @struct stat
|
||||
* @brief Structure holding information about a file, as returned by the stat function.
|
||||
*
|
||||
* The 'stat' structure provides information about a file, including its size, ownership, permissions,
|
||||
* and other attributes. It is used with the stat function to query file status.
|
||||
*/
|
||||
struct stat
|
||||
{
|
||||
/** Device ID of the file. */
|
||||
dev_t st_dev;
|
||||
/** Inode number. */
|
||||
ino_t st_ino;
|
||||
/** File type and mode. */
|
||||
mode_t st_mode;
|
||||
/** Number of hard links. */
|
||||
nlink_t st_nlink;
|
||||
|
||||
/** User ID of the file's owner. */
|
||||
uid_t st_uid;
|
||||
/** Group ID of the file's owner. */
|
||||
gid_t st_gid;
|
||||
/** Device ID for special files. */
|
||||
dev_t st_rdev;
|
||||
/** Size of the file in bytes. */
|
||||
off_t st_size;
|
||||
/** Time of last access. */
|
||||
time_t st_atime;
|
||||
/** Time of last modification. */
|
||||
time_t st_mtime;
|
||||
/** Time of last status change. */
|
||||
time_t st_ctime;
|
||||
/** Optimal I/O block size. */
|
||||
blksize_t st_blksize;
|
||||
/** Number of blocks allocated. */
|
||||
blkcnt_t st_blocks;
|
||||
/** Additional file attributes. */
|
||||
mode_t st_attr;
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct stat64
|
||||
* @brief Extended structure for large file support, holding information about a file.
|
||||
*
|
||||
* The 'stat64' structure is similar to 'struct stat' but is extended to support large files on 32-bit systems.
|
||||
* It is used with the stat64 function for large file support.
|
||||
*/
|
||||
struct stat64
|
||||
{
|
||||
/** Device ID of the file. */
|
||||
dev_t st_dev;
|
||||
/** Inode number. */
|
||||
ino64_t st_ino;
|
||||
/** File type and mode. */
|
||||
mode_t st_mode;
|
||||
/** Number of hard links. */
|
||||
nlink_t st_nlink;
|
||||
/** User ID of the file's owner. */
|
||||
uid_t st_uid;
|
||||
/** Group ID of the file's owner. */
|
||||
gid_t st_gid;
|
||||
/** Device ID for special files. */
|
||||
dev_t st_rdev;
|
||||
/** Size of the file in bytes. */
|
||||
off64_t st_size;
|
||||
/** Time of last access. */
|
||||
time_t st_atime;
|
||||
/** Time of last modification. */
|
||||
time_t st_mtime;
|
||||
/** Time of last status change. */
|
||||
time_t st_ctime;
|
||||
/** Optimal I/O block size. */
|
||||
blksize_t st_blksize;
|
||||
/** Number of blocks allocated. */
|
||||
blkcnt64_t st_blocks;
|
||||
/** Additional file attributes. */
|
||||
mode_t st_attr;
|
||||
};
|
||||
|
||||
@ -165,6 +206,12 @@ namespace vfs
|
||||
};
|
||||
|
||||
class RefNode;
|
||||
|
||||
/**
|
||||
* Virtual filesystem node
|
||||
*
|
||||
* @note https://isocpp.org/wiki/faq/freestore-mgmt#delete-this
|
||||
*/
|
||||
class Node
|
||||
{
|
||||
private:
|
||||
@ -173,15 +220,35 @@ namespace vfs
|
||||
public:
|
||||
virtual int open(int Flags, mode_t Mode);
|
||||
virtual int close();
|
||||
virtual size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual int ioctl(unsigned long Request,
|
||||
void *Argp);
|
||||
virtual ~Node();
|
||||
virtual size_t read(uint8_t *Buffer, size_t Size, off_t Offset);
|
||||
virtual size_t write(uint8_t *Buffer, size_t Size, off_t Offset);
|
||||
virtual int ioctl(unsigned long Request, void *Argp);
|
||||
// virtual int stat(struct stat *Stat);
|
||||
// virtual int lstat(struct stat *Stat);
|
||||
// virtual int fstat(struct stat *Stat);
|
||||
// virtual int unlink();
|
||||
// virtual int mkdir(mode_t Mode);
|
||||
// virtual int rmdir();
|
||||
// virtual int rename(const char *NewName);
|
||||
// virtual int chmod(mode_t Mode);
|
||||
// virtual int chown(uid_t User, gid_t Group);
|
||||
// virtual int truncate(off_t Size);
|
||||
// virtual int symlink(const char *Target);
|
||||
// virtual int readlink(char *Buffer, size_t Size);
|
||||
// virtual int mount(Node *Target);
|
||||
// virtual int umount();
|
||||
|
||||
typedef int (*open_t)(int, mode_t);
|
||||
typedef int (*close_t)();
|
||||
typedef size_t (*read_t)(uint8_t *, size_t, off_t);
|
||||
typedef size_t (*write_t)(uint8_t *, size_t, off_t);
|
||||
typedef int (*ioctl_t)(unsigned long, void *);
|
||||
|
||||
open_t open_ptr = nullptr;
|
||||
close_t close_ptr = nullptr;
|
||||
read_t read_ptr = nullptr;
|
||||
write_t write_ptr = nullptr;
|
||||
ioctl_t ioctl_ptr = nullptr;
|
||||
|
||||
class Virtual *vFS = nullptr;
|
||||
Node *Parent = nullptr;
|
||||
@ -211,21 +278,13 @@ namespace vfs
|
||||
RefNode *CreateReference();
|
||||
void RemoveReference(RefNode *Reference);
|
||||
|
||||
/**
|
||||
* Delete all children of this node
|
||||
*
|
||||
* @note The function will self-delete
|
||||
* if there are no errors.
|
||||
*/
|
||||
int Delete(bool Recursive = false);
|
||||
|
||||
/**
|
||||
* Create a new node
|
||||
*
|
||||
* @param Parent The parent node
|
||||
* @param Name The name of the node
|
||||
* @param Type The type of the node
|
||||
* @param NoParent If true, the @param Parent will
|
||||
* @param NoParent If true, the Parent will
|
||||
* be used as a hint for the parent node, but it
|
||||
* won't be set as the parent node.
|
||||
* @param fs The virtual filesystem (only if
|
||||
@ -239,6 +298,8 @@ namespace vfs
|
||||
bool NoParent = false,
|
||||
Virtual *fs = nullptr,
|
||||
int *Err = nullptr);
|
||||
|
||||
virtual ~Node();
|
||||
};
|
||||
|
||||
class RefNode
|
||||
@ -250,6 +311,8 @@ namespace vfs
|
||||
RefNode *SymlinkTo;
|
||||
|
||||
public:
|
||||
void *SpecialData;
|
||||
|
||||
decltype(FileSize) &Size = FileSize;
|
||||
decltype(n) &node = n;
|
||||
|
||||
@ -287,6 +350,7 @@ namespace vfs
|
||||
bool PathExists(const char *Path, Node *Parent = nullptr);
|
||||
|
||||
Node *Create(const char *Path, NodeType Type, Node *Parent = nullptr);
|
||||
Node *CreateLink(const char *Path, const char *Target, Node *Parent);
|
||||
|
||||
int Delete(const char *Path, bool Recursive = false, Node *Parent = nullptr);
|
||||
int Delete(Node *Path, bool Recursive = false, Node *Parent = nullptr);
|
||||
@ -299,6 +363,8 @@ namespace vfs
|
||||
*/
|
||||
RefNode *Open(const char *Path, Node *Parent = nullptr);
|
||||
|
||||
Node *CreateIfNotExists(const char *Path, NodeType Type, Node *Parent);
|
||||
|
||||
Virtual();
|
||||
~Virtual();
|
||||
|
||||
@ -310,27 +376,32 @@ namespace vfs
|
||||
public:
|
||||
struct Fildes
|
||||
{
|
||||
RefNode *Handle{};
|
||||
RefNode *Handle = nullptr;
|
||||
mode_t Mode = 0;
|
||||
int Flags = 0;
|
||||
int Descriptor = -1;
|
||||
};
|
||||
|
||||
struct DupFildes
|
||||
{
|
||||
RefNode *Handle{};
|
||||
mode_t Mode = 0;
|
||||
int Flags = 0;
|
||||
int Descriptor = -1;
|
||||
};
|
||||
int operator==(const Fildes &other)
|
||||
{
|
||||
return this->Handle == other.Handle &&
|
||||
this->Mode == other.Mode &&
|
||||
this->Flags == other.Flags &&
|
||||
this->Descriptor == other.Descriptor;
|
||||
}
|
||||
|
||||
int operator!=(const Fildes &other)
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
} __attribute__((packed)) nullfd;
|
||||
|
||||
private:
|
||||
std::vector<Fildes> FileDescriptors;
|
||||
std::vector<DupFildes> FildesDuplicates;
|
||||
std::vector<Fildes> FildesDuplicates;
|
||||
vfs::Node *fdDir = nullptr;
|
||||
|
||||
Fildes GetFileDescriptor(int FileDescriptor);
|
||||
FileDescriptorTable::DupFildes GetDupFildes(int FileDescriptor);
|
||||
Fildes &GetFileDescriptor(int FileDescriptor);
|
||||
FileDescriptorTable::Fildes &GetDupFildes(int FileDescriptor);
|
||||
|
||||
int ProbeMode(mode_t Mode, int Flags);
|
||||
int AddFileDescriptor(const char *AbsolutePath, mode_t Mode, int Flags);
|
||||
@ -338,8 +409,14 @@ namespace vfs
|
||||
int GetFreeFileDescriptor();
|
||||
|
||||
public:
|
||||
Fildes &GetDescriptor(int FileDescriptor);
|
||||
const char *GetAbsolutePath(int FileDescriptor);
|
||||
std::vector<Fildes> &GetFileDescriptors() { return FileDescriptors; }
|
||||
std::vector<Fildes> &GetFileDescriptorsDuplicates() { return FildesDuplicates; }
|
||||
RefNode *GetRefNode(int FileDescriptor);
|
||||
int GetFlags(int FileDescriptor);
|
||||
int SetFlags(int FileDescriptor, int Flags);
|
||||
void Fork(FileDescriptorTable *Parent);
|
||||
|
||||
int _open(const char *pathname, int flags, mode_t mode);
|
||||
int _creat(const char *pathname, mode_t mode);
|
||||
|
@ -24,68 +24,68 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class EXT2
|
||||
{
|
||||
public:
|
||||
struct SuperBlock
|
||||
{
|
||||
uint32_t Inodes;
|
||||
uint32_t Blocks;
|
||||
uint32_t ReservedBlocks;
|
||||
uint32_t FreeBlock;
|
||||
uint32_t FreeInodes;
|
||||
uint32_t FirstDataBlock;
|
||||
uint32_t LogBlockSize;
|
||||
uint32_t LogFragSize;
|
||||
uint32_t BlocksPerGroup;
|
||||
uint32_t FragsPerGroup;
|
||||
uint32_t InodesPerGroup;
|
||||
uint32_t LastMountTime;
|
||||
uint32_t LastWrittenTime;
|
||||
uint16_t MountedTimes;
|
||||
uint16_t MaximumMountedTimes;
|
||||
uint16_t Magic;
|
||||
uint16_t State;
|
||||
uint16_t Errors;
|
||||
uint16_t MinorRevLevel;
|
||||
uint32_t LastCheck;
|
||||
uint32_t CheckInternval;
|
||||
uint32_t SystemID;
|
||||
uint32_t RevLevel;
|
||||
uint16_t ReservedBlocksUserID;
|
||||
uint16_t ReservedBlocksGroupID;
|
||||
class EXT2
|
||||
{
|
||||
public:
|
||||
struct SuperBlock
|
||||
{
|
||||
uint32_t Inodes;
|
||||
uint32_t Blocks;
|
||||
uint32_t ReservedBlocks;
|
||||
uint32_t FreeBlock;
|
||||
uint32_t FreeInodes;
|
||||
uint32_t FirstDataBlock;
|
||||
uint32_t LogBlockSize;
|
||||
uint32_t LogFragSize;
|
||||
uint32_t BlocksPerGroup;
|
||||
uint32_t FragsPerGroup;
|
||||
uint32_t InodesPerGroup;
|
||||
uint32_t LastMountTime;
|
||||
uint32_t LastWrittenTime;
|
||||
uint16_t MountedTimes;
|
||||
uint16_t MaximumMountedTimes;
|
||||
uint16_t Magic;
|
||||
uint16_t State;
|
||||
uint16_t Errors;
|
||||
uint16_t MinorRevLevel;
|
||||
uint32_t LastCheck;
|
||||
uint32_t CheckInternval;
|
||||
uint32_t SystemID;
|
||||
uint32_t RevLevel;
|
||||
uint16_t ReservedBlocksUserID;
|
||||
uint16_t ReservedBlocksGroupID;
|
||||
|
||||
uint32_t FirstInode;
|
||||
uint16_t InodeSize;
|
||||
uint16_t BlockGroups;
|
||||
uint32_t FeatureCompatibility;
|
||||
uint32_t FeatureIncompatibility;
|
||||
uint32_t FeatureRoCompatibility;
|
||||
uint8_t UUID[16];
|
||||
char VolumeName[16];
|
||||
char LastMounted[64];
|
||||
uint32_t BitmapAlogrithm;
|
||||
uint32_t FirstInode;
|
||||
uint16_t InodeSize;
|
||||
uint16_t BlockGroups;
|
||||
uint32_t FeatureCompatibility;
|
||||
uint32_t FeatureIncompatibility;
|
||||
uint32_t FeatureRoCompatibility;
|
||||
uint8_t UUID[16];
|
||||
char VolumeName[16];
|
||||
char LastMounted[64];
|
||||
uint32_t BitmapAlogrithm;
|
||||
|
||||
uint8_t PreallocatedBlocks;
|
||||
uint8_t PreallocatedDirectoryBlocks;
|
||||
uint8_t PreallocatedBlocks;
|
||||
uint8_t PreallocatedDirectoryBlocks;
|
||||
|
||||
uint16_t Padding;
|
||||
uint8_t JournalUUID[16];
|
||||
uint32_t JournalInum;
|
||||
uint32_t JournalDev;
|
||||
uint32_t LastOrphan;
|
||||
uint32_t HashSeed[4];
|
||||
uint8_t DefHashVersion;
|
||||
uint8_t ReservedCharPad;
|
||||
uint16_t ReservedWordPad;
|
||||
uint32_t DefaultMountOptions;
|
||||
uint32_t FirstMetaBg;
|
||||
uint32_t Reserved[190];
|
||||
};
|
||||
uint16_t Padding;
|
||||
uint8_t JournalUUID[16];
|
||||
uint32_t JournalInum;
|
||||
uint32_t JournalDev;
|
||||
uint32_t LastOrphan;
|
||||
uint32_t HashSeed[4];
|
||||
uint8_t DefHashVersion;
|
||||
uint8_t ReservedCharPad;
|
||||
uint16_t ReservedWordPad;
|
||||
uint32_t DefaultMountOptions;
|
||||
uint32_t FirstMetaBg;
|
||||
uint32_t Reserved[190];
|
||||
};
|
||||
|
||||
EXT2(void *partition);
|
||||
~EXT2();
|
||||
};
|
||||
EXT2(void *partition);
|
||||
~EXT2();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_EXT2_H__
|
||||
|
@ -24,54 +24,54 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class FAT
|
||||
{
|
||||
public:
|
||||
enum FatType
|
||||
{
|
||||
Unknown,
|
||||
FAT12,
|
||||
FAT16,
|
||||
FAT32
|
||||
};
|
||||
class FAT
|
||||
{
|
||||
public:
|
||||
enum FatType
|
||||
{
|
||||
Unknown,
|
||||
FAT12,
|
||||
FAT16,
|
||||
FAT32
|
||||
};
|
||||
|
||||
/* https://wiki.osdev.org/FAT */
|
||||
struct BIOSParameterBlock
|
||||
{
|
||||
/** @brief The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP. (The 3C value may be different.) The reason for this is to jump over the disk format information (the BPB and EBPB). Since the first sector of the disk is loaded into ram at location 0x0000:0x7c00 and executed, without this jump, the processor would attempt to execute data that isn't code. Even for non-bootable volumes, code matching this pattern (or using the E9 jump opcode) is required to be present by both Windows and OS X. To fulfil this requirement, an infinite loop can be placed here with the bytes EB FE 90. */
|
||||
uint8_t JumpBoot[3];
|
||||
/** @brief OEM identifier. The first 8 Bytes (3 - 10) is the version of DOS being used. The next eight Bytes 29 3A 63 7E 2D 49 48 and 43 read out the name of the version. The official FAT Specification from Microsoft says that this field is really meaningless and is ignored by MS FAT Modules, however it does recommend the value "MSWIN4.1" as some 3rd party drivers supposedly check it and expect it to have that value. Older versions of dos also report MSDOS5.1, linux-formatted floppy will likely to carry "mkdosfs" here, and FreeDOS formatted disks have been observed to have "FRDOS5.1" here. If the string is less than 8 bytes, it is padded with spaces. */
|
||||
uint8_t OEM[8];
|
||||
/** @brief The number of Bytes per sector (remember, all numbers are in the little-endian format). */
|
||||
uint16_t BytesPerSector;
|
||||
/** @brief Number of sectors per cluster. */
|
||||
uint8_t SectorsPerCluster;
|
||||
/** @brief Number of reserved sectors. The boot record sectors are included in this value. */
|
||||
uint16_t ReservedSectors;
|
||||
/** @brief Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2. */
|
||||
uint8_t NumberOfFATs;
|
||||
/** @brief Number of root directory entries (must be set so that the root directory occupies entire sectors). */
|
||||
uint16_t RootDirectoryEntries;
|
||||
/** @brief The total sectors in the logical volume. If this value is 0, it means there are more than 65535 sectors in the volume, and the actual count is stored in the Large Sector Count entry at 0x20. */
|
||||
uint16_t Sectors16;
|
||||
/** @brief This Byte indicates the media descriptor type. */
|
||||
uint8_t Media;
|
||||
/** @brief Number of sectors per FAT. FAT12/FAT16 only. */
|
||||
uint16_t SectorsPerFAT;
|
||||
/** @brief Number of sectors per track. */
|
||||
uint16_t SectorsPerTrack;
|
||||
/** @brief Number of heads or sides on the storage media. */
|
||||
uint16_t NumberOfHeads;
|
||||
/** @brief Number of hidden sectors. (i.e. the LBA of the beginning of the partition). */
|
||||
uint32_t HiddenSectors;
|
||||
/** @brief Large sector count. This field is set if there are more than 65535 sectors in the volume, resulting in a value which does not fit in the Number of Sectors entry at 0x13. */
|
||||
uint32_t Sectors32;
|
||||
} __packed;
|
||||
/* https://wiki.osdev.org/FAT */
|
||||
struct BIOSParameterBlock
|
||||
{
|
||||
/** @brief The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP. (The 3C value may be different.) The reason for this is to jump over the disk format information (the BPB and EBPB). Since the first sector of the disk is loaded into ram at location 0x0000:0x7c00 and executed, without this jump, the processor would attempt to execute data that isn't code. Even for non-bootable volumes, code matching this pattern (or using the E9 jump opcode) is required to be present by both Windows and OS X. To fulfil this requirement, an infinite loop can be placed here with the bytes EB FE 90. */
|
||||
uint8_t JumpBoot[3];
|
||||
/** @brief OEM identifier. The first 8 Bytes (3 - 10) is the version of DOS being used. The next eight Bytes 29 3A 63 7E 2D 49 48 and 43 read out the name of the version. The official FAT Specification from Microsoft says that this field is really meaningless and is ignored by MS FAT Modules, however it does recommend the value "MSWIN4.1" as some 3rd party drivers supposedly check it and expect it to have that value. Older versions of dos also report MSDOS5.1, linux-formatted floppy will likely to carry "mkdosfs" here, and FreeDOS formatted disks have been observed to have "FRDOS5.1" here. If the string is less than 8 bytes, it is padded with spaces. */
|
||||
uint8_t OEM[8];
|
||||
/** @brief The number of Bytes per sector (remember, all numbers are in the little-endian format). */
|
||||
uint16_t BytesPerSector;
|
||||
/** @brief Number of sectors per cluster. */
|
||||
uint8_t SectorsPerCluster;
|
||||
/** @brief Number of reserved sectors. The boot record sectors are included in this value. */
|
||||
uint16_t ReservedSectors;
|
||||
/** @brief Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2. */
|
||||
uint8_t NumberOfFATs;
|
||||
/** @brief Number of root directory entries (must be set so that the root directory occupies entire sectors). */
|
||||
uint16_t RootDirectoryEntries;
|
||||
/** @brief The total sectors in the logical volume. If this value is 0, it means there are more than 65535 sectors in the volume, and the actual count is stored in the Large Sector Count entry at 0x20. */
|
||||
uint16_t Sectors16;
|
||||
/** @brief This Byte indicates the media descriptor type. */
|
||||
uint8_t Media;
|
||||
/** @brief Number of sectors per FAT. FAT12/FAT16 only. */
|
||||
uint16_t SectorsPerFAT;
|
||||
/** @brief Number of sectors per track. */
|
||||
uint16_t SectorsPerTrack;
|
||||
/** @brief Number of heads or sides on the storage media. */
|
||||
uint16_t NumberOfHeads;
|
||||
/** @brief Number of hidden sectors. (i.e. the LBA of the beginning of the partition). */
|
||||
uint32_t HiddenSectors;
|
||||
/** @brief Large sector count. This field is set if there are more than 65535 sectors in the volume, resulting in a value which does not fit in the Number of Sectors entry at 0x13. */
|
||||
uint32_t Sectors32;
|
||||
} __packed;
|
||||
|
||||
FatType GetFATType(BIOSParameterBlock *bpb);
|
||||
FAT(void *partition);
|
||||
~FAT();
|
||||
};
|
||||
FatType GetFATType(BIOSParameterBlock *bpb);
|
||||
FAT(void *partition);
|
||||
~FAT();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_FAT_H__
|
||||
|
@ -24,25 +24,25 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class Initrd
|
||||
{
|
||||
public:
|
||||
struct InitrdHeader
|
||||
{
|
||||
uint32_t nfiles;
|
||||
};
|
||||
class Initrd
|
||||
{
|
||||
public:
|
||||
struct InitrdHeader
|
||||
{
|
||||
uint32_t nfiles;
|
||||
};
|
||||
|
||||
struct InitrdFileHeader
|
||||
{
|
||||
uint8_t magic;
|
||||
char name[64];
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
struct InitrdFileHeader
|
||||
{
|
||||
uint8_t magic;
|
||||
char name[64];
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
Initrd(uintptr_t Address);
|
||||
~Initrd();
|
||||
};
|
||||
Initrd(uintptr_t Address);
|
||||
~Initrd();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_INITRD_H__
|
||||
|
@ -20,13 +20,58 @@
|
||||
|
||||
#include <types.h>
|
||||
#include <stropts.h>
|
||||
#include <filesystem/termios.hpp>
|
||||
|
||||
struct winsize
|
||||
{
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
unsigned short ws_xpixel;
|
||||
unsigned short ws_ypixel;
|
||||
};
|
||||
#define _IOC_NRBITS 8
|
||||
#define _IOC_TYPEBITS 8
|
||||
#define _IOC_SIZEBITS 14
|
||||
#define _IOC_DIRBITS 2
|
||||
|
||||
#define _IOC_NRMASK \
|
||||
((1 << _IOC_NRBITS) - 1)
|
||||
#define _IOC_TYPEMASK \
|
||||
((1 << _IOC_TYPEBITS) - 1)
|
||||
#define _IOC_SIZEMASK \
|
||||
((1 << _IOC_SIZEBITS) - 1)
|
||||
#define _IOC_DIRMASK \
|
||||
((1 << _IOC_DIRBITS) - 1)
|
||||
|
||||
#define _IOC_NRSHIFT 0
|
||||
#define _IOC_TYPESHIFT \
|
||||
(_IOC_NRSHIFT + _IOC_NRBITS)
|
||||
#define _IOC_SIZESHIFT \
|
||||
(_IOC_TYPESHIFT + _IOC_TYPEBITS)
|
||||
#define _IOC_DIRSHIFT \
|
||||
(_IOC_SIZESHIFT + _IOC_SIZEBITS)
|
||||
|
||||
#define _IOC(dir, type, nr, size) \
|
||||
(((dir) << _IOC_DIRSHIFT) | \
|
||||
((type) << _IOC_TYPESHIFT) | \
|
||||
((nr) << _IOC_NRSHIFT) | \
|
||||
((size) << _IOC_SIZESHIFT))
|
||||
|
||||
#define _IOC_NONE 0U
|
||||
#define _IOC_WRITE 1U
|
||||
#define _IOC_READ 2U
|
||||
|
||||
#define _IOC_TYPECHECK(t) (sizeof(t))
|
||||
|
||||
#define _IO(type, nr) \
|
||||
_IOC(_IOC_NONE, (type), (nr), 0)
|
||||
#define _IOR(type, nr, size) \
|
||||
_IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(size)))
|
||||
#define _IOW(type, nr, size) \
|
||||
_IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
|
||||
#define _IOWR(type, nr, size) \
|
||||
_IOC(_IOC_READ | _IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
|
||||
#define _IOR_BAD(type, nr, size) \
|
||||
_IOC(_IOC_READ, (type), (nr), sizeof(size))
|
||||
#define _IOW_BAD(type, nr, size) \
|
||||
_IOC(_IOC_WRITE, (type), (nr), sizeof(size))
|
||||
#define _IOWR_BAD(type, nr, size) \
|
||||
_IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(size))
|
||||
|
||||
#define TIOCGPTN _IOR('T', 0x30, unsigned int)
|
||||
#define TIOCSPTLCK _IOW('T', 0x31, int)
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_IOCTL_H__
|
||||
|
@ -20,7 +20,12 @@
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <filesystem/termios.hpp>
|
||||
#include <filesystem.hpp>
|
||||
#include <bitmap.hpp>
|
||||
#include <task.hpp>
|
||||
#include <lock.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
@ -34,12 +39,12 @@ namespace vfs
|
||||
class NullDevice : public Node
|
||||
{
|
||||
public:
|
||||
virtual size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
|
||||
NullDevice();
|
||||
~NullDevice();
|
||||
@ -48,12 +53,12 @@ namespace vfs
|
||||
class RandomDevice : public Node
|
||||
{
|
||||
public:
|
||||
virtual size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
|
||||
RandomDevice();
|
||||
~RandomDevice();
|
||||
@ -62,42 +67,137 @@ namespace vfs
|
||||
class ZeroDevice : public Node
|
||||
{
|
||||
public:
|
||||
virtual size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
|
||||
ZeroDevice();
|
||||
~ZeroDevice();
|
||||
};
|
||||
|
||||
class KConDevice : public Node
|
||||
{
|
||||
public:
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
termios term{};
|
||||
winsize termSize{};
|
||||
|
||||
KConDevice();
|
||||
~KConDevice();
|
||||
};
|
||||
|
||||
class TTYDevice : public Node
|
||||
{
|
||||
public:
|
||||
virtual size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual int ioctl(unsigned long Request,
|
||||
void *Argp);
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
TTYDevice();
|
||||
~TTYDevice();
|
||||
};
|
||||
|
||||
class MasterPTY
|
||||
{
|
||||
NewLock(PTYLock);
|
||||
|
||||
public:
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
|
||||
MasterPTY();
|
||||
~MasterPTY();
|
||||
};
|
||||
|
||||
class SlavePTY
|
||||
{
|
||||
NewLock(PTYLock);
|
||||
|
||||
public:
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
|
||||
SlavePTY();
|
||||
~SlavePTY();
|
||||
};
|
||||
|
||||
class PTYDevice : public Node
|
||||
{
|
||||
private:
|
||||
Node *pts;
|
||||
int id;
|
||||
int fildes;
|
||||
bool isMaster;
|
||||
termios term{};
|
||||
winsize termSize{};
|
||||
|
||||
MasterPTY *MasterDev;
|
||||
SlavePTY *SlaveDev;
|
||||
|
||||
public:
|
||||
decltype(id) &ptyId = id;
|
||||
decltype(fildes) &fd = fildes;
|
||||
|
||||
int open(int Flags, mode_t Mode) final;
|
||||
int close() final;
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
int OpenMaster(int Flags, mode_t Mode);
|
||||
|
||||
PTYDevice(Node *pts, int id);
|
||||
~PTYDevice();
|
||||
};
|
||||
|
||||
class PTMXDevice : public Node
|
||||
{
|
||||
private:
|
||||
Node *pts = nullptr;
|
||||
NewLock(PTMXLock);
|
||||
Node *pts;
|
||||
Bitmap ptysId;
|
||||
std::vector<PTYDevice *> ptysList;
|
||||
|
||||
public:
|
||||
virtual size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
virtual size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset);
|
||||
int open(int Flags, mode_t Mode) final;
|
||||
|
||||
/**
|
||||
* Remove a PTY from the list
|
||||
*
|
||||
* @param fd The file descriptor of the PTY
|
||||
* @param pcb The process that owns the PTY
|
||||
*
|
||||
* @note if pcb is nullptr, the current process
|
||||
* will be used.
|
||||
*
|
||||
*/
|
||||
void RemovePTY(int fd, Tasking::PCB *pcb = nullptr);
|
||||
|
||||
PTMXDevice();
|
||||
~PTMXDevice();
|
||||
|
160
include/filesystem/termios-bits.hpp
Normal file
160
include/filesystem/termios-bits.hpp
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
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_TERMIOS_BITS_H__
|
||||
#define __FENNIX_KERNEL_TERMIOS_BITS_H__
|
||||
|
||||
/* c_cc */
|
||||
#define VINTR 0
|
||||
#define VQUIT 1
|
||||
#define VERASE 2
|
||||
#define VKILL 3
|
||||
#define VEOF 4
|
||||
#define VTIME 5
|
||||
#define VMIN 6
|
||||
#define VSWTC 7
|
||||
#define VSTART 8
|
||||
#define VSTOP 9
|
||||
#define VSUSP 10
|
||||
#define VEOL 11
|
||||
#define VREPRINT 12
|
||||
#define VDISCARD 13
|
||||
#define VWERASE 14
|
||||
#define VLNEXT 15
|
||||
#define VEOL2 16
|
||||
|
||||
/* c_iflag */
|
||||
#define IGNBRK 0000001
|
||||
#define BRKINT 0000002
|
||||
#define IGNPAR 0000004
|
||||
#define PARMRK 0000010
|
||||
#define INPCK 0000020
|
||||
#define ISTRIP 0000040
|
||||
#define INLCR 0000100
|
||||
#define IGNCR 0000200
|
||||
#define ICRNL 0000400
|
||||
#define IUCLC 0001000
|
||||
#define IXON 0002000
|
||||
#define IXANY 0004000
|
||||
#define IXOFF 0010000
|
||||
#define IMAXBEL 0020000
|
||||
#define IUTF8 0040000
|
||||
|
||||
/* c_lflag */
|
||||
#define ISIG 0000001
|
||||
#define ICANON 0000002
|
||||
#define XCASE 0000004
|
||||
#define ECHO 0000010
|
||||
#define ECHOE 0000020
|
||||
#define ECHOK 0000040
|
||||
#define ECHONL 0000100
|
||||
#define NOFLSH 0000200
|
||||
#define TOSTOP 0000400
|
||||
#define ECHOCTL 0001000
|
||||
#define ECHOPRT 0002000
|
||||
#define ECHOKE 0004000
|
||||
#define FLUSHO 0010000
|
||||
#define PENDIN 0040000
|
||||
#define IEXTEN 0100000
|
||||
#define EXTPROC 0200000
|
||||
|
||||
/* c_oflag */
|
||||
#define OPOST 0000001
|
||||
#define OLCUC 0000002
|
||||
#define ONLCR 0000004
|
||||
#define OCRNL 0000010
|
||||
#define ONOCR 0000020
|
||||
#define ONLRET 0000040
|
||||
#define OFILL 0000100
|
||||
#define OFDEL 0000200
|
||||
#define NLDLY 0000400
|
||||
#define NL0 0000000
|
||||
#define NL1 0000400
|
||||
#define CRDLY 0003000
|
||||
#define _CR0 0000000
|
||||
#define _CR1 0001000
|
||||
#define _CR2 0002000
|
||||
#define _CR3 0003000
|
||||
#define TABDLY 0014000
|
||||
#define TAB0 0000000
|
||||
#define TAB1 0004000
|
||||
#define TAB2 0010000
|
||||
#define TAB3 0014000
|
||||
#define XTABS 0014000
|
||||
#define BSDLY 0020000
|
||||
#define BS0 0000000
|
||||
#define BS1 0020000
|
||||
#define VTDLY 0040000
|
||||
#define VT0 0000000
|
||||
#define VT1 0040000
|
||||
#define FFDLY 0100000
|
||||
#define FF0 0000000
|
||||
#define FF1 0100000
|
||||
|
||||
/* c_cflag */
|
||||
#define CBAUD 0010017
|
||||
#define _B0 0000000
|
||||
#define B50 0000001
|
||||
#define B75 0000002
|
||||
#define B110 0000003
|
||||
#define B134 0000004
|
||||
#define B150 0000005
|
||||
#define B200 0000006
|
||||
#define B300 0000007
|
||||
#define B600 0000010
|
||||
#define B1200 0000011
|
||||
#define B1800 0000012
|
||||
#define B2400 0000013
|
||||
#define B4800 0000014
|
||||
#define B9600 0000015
|
||||
#define B19200 0000016
|
||||
#define B38400 0000017
|
||||
#define EXTA B19200
|
||||
#define EXTB B38400
|
||||
#define CSIZE 0000060
|
||||
#define CS5 0000000
|
||||
#define CS6 0000020
|
||||
#define CS7 0000040
|
||||
#define CS8 0000060
|
||||
#define CSTOPB 0000100
|
||||
#define CREAD 0000200
|
||||
#define PARENB 0000400
|
||||
#define PARODD 0001000
|
||||
#define HUPCL 0002000
|
||||
#define CLOCAL 0004000
|
||||
#define CBAUDEX 0010000
|
||||
#define BOTHER 0010000
|
||||
#define B57600 0010001
|
||||
#define B115200 0010002
|
||||
#define B230400 0010003
|
||||
#define B460800 0010004
|
||||
#define B500000 0010005
|
||||
#define B576000 0010006
|
||||
#define B921600 0010007
|
||||
#define B1000000 0010010
|
||||
#define B1152000 0010011
|
||||
#define B1500000 0010012
|
||||
#define B2000000 0010013
|
||||
#define B2500000 0010014
|
||||
#define B3000000 0010015
|
||||
#define B3500000 0010016
|
||||
#define B4000000 0010017
|
||||
#define CIBAUD 002003600000
|
||||
#define CMSPAR 010000000000
|
||||
#define CRTSCTS 020000000000
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TERMIOS_BITS_H__
|
@ -15,9 +15,35 @@
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_EMMINTRIN_H__
|
||||
#define __FENNIX_KERNEL_EMMINTRIN_H__
|
||||
#ifndef __FENNIX_KERNEL_TERMIOS_H__
|
||||
#define __FENNIX_KERNEL_TERMIOS_H__
|
||||
|
||||
/* stub header */
|
||||
#include <types.h>
|
||||
#include <filesystem/termios-bits.hpp>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_EMMINTRIN_H__
|
||||
typedef unsigned char cc_t;
|
||||
typedef unsigned int speed_t;
|
||||
typedef unsigned int tcflag_t;
|
||||
|
||||
#define NCCS 32
|
||||
struct termios
|
||||
{
|
||||
tcflag_t c_iflag;
|
||||
tcflag_t c_oflag;
|
||||
tcflag_t c_cflag;
|
||||
tcflag_t c_lflag;
|
||||
cc_t c_line;
|
||||
cc_t c_cc[NCCS];
|
||||
speed_t c_ispeed;
|
||||
speed_t c_ospeed;
|
||||
};
|
||||
|
||||
struct winsize
|
||||
{
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
unsigned short ws_xpixel;
|
||||
unsigned short ws_ypixel;
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TERMIOS_H__
|
1067
include/ini.h
Normal file
1067
include/ini.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,7 @@
|
||||
|
||||
#include <types.h>
|
||||
#include <cpu.hpp>
|
||||
#include <pci.hpp>
|
||||
|
||||
namespace Interrupts
|
||||
{
|
||||
@ -30,49 +31,55 @@ namespace Interrupts
|
||||
#endif
|
||||
|
||||
#if defined(a64)
|
||||
/* APIC::APIC */ extern void *apic[256]; // MAX_CPU
|
||||
/* APIC::Timer */ extern void *apicTimer[256]; // MAX_CPU
|
||||
/* APIC::APIC */ extern void *apic[255]; // MAX_CPU
|
||||
/* APIC::Timer */ extern void *apicTimer[255]; // MAX_CPU
|
||||
#elif defined(a32)
|
||||
/* APIC::APIC */ extern void *apic[256]; // MAX_CPU
|
||||
/* APIC::Timer */ extern void *apicTimer[256]; // MAX_CPU
|
||||
/* APIC::APIC */ extern void *apic[255]; // MAX_CPU
|
||||
/* APIC::Timer */ extern void *apicTimer[255]; // MAX_CPU
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
extern void *InterruptFrames[INT_FRAMES_MAX];
|
||||
extern void *InterruptFrames[INT_FRAMES_MAX];
|
||||
|
||||
void Initialize(int Core);
|
||||
void Enable(int Core);
|
||||
void InitializeTimer(int Core);
|
||||
void RemoveAll();
|
||||
void Initialize(int Core);
|
||||
void Enable(int Core);
|
||||
void InitializeTimer(int Core);
|
||||
void RemoveAll();
|
||||
|
||||
class Handler
|
||||
{
|
||||
private:
|
||||
int InterruptNumber;
|
||||
void AddHandler(void (*Callback)(CPU::TrapFrame *),
|
||||
int InterruptNumber, void *ctx = nullptr,
|
||||
bool Critical = false);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Set a new interrupt number.
|
||||
* @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32)
|
||||
*/
|
||||
void SetInterruptNumber(int InterruptNumber) { this->InterruptNumber = InterruptNumber; }
|
||||
int GetInterruptNumber() { return this->InterruptNumber; }
|
||||
void RemoveHandler(void (*Callback)(CPU::TrapFrame *),
|
||||
int InterruptNumber);
|
||||
|
||||
/**
|
||||
* @brief Create a new interrupt handler.
|
||||
* @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32)
|
||||
*/
|
||||
Handler(int InterruptNumber);
|
||||
~Handler();
|
||||
void RemoveHandler(void (*Callback)(CPU::TrapFrame *));
|
||||
void RemoveHandler(int InterruptNumber);
|
||||
|
||||
public:
|
||||
#if defined(a64)
|
||||
virtual void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
#elif defined(a32)
|
||||
virtual void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
#elif defined(aa64)
|
||||
virtual void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
#endif
|
||||
};
|
||||
class Handler
|
||||
{
|
||||
private:
|
||||
int InterruptNumber;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Set a new interrupt number.
|
||||
* @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32)
|
||||
*/
|
||||
void SetInterruptNumber(int InterruptNumber) { this->InterruptNumber = InterruptNumber; }
|
||||
int GetInterruptNumber() { return this->InterruptNumber; }
|
||||
|
||||
/**
|
||||
* @brief Create a new interrupt handler.
|
||||
* @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32)
|
||||
*/
|
||||
Handler(int InterruptNumber, bool Critical = false);
|
||||
Handler(PCI::PCIDevice Device, bool Critical = false);
|
||||
Handler();
|
||||
~Handler();
|
||||
|
||||
public:
|
||||
virtual void OnInterruptReceived(CPU::TrapFrame *Frame);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_INTERRUPTS_H__
|
||||
|
97
include/io.h
97
include/io.h
@ -26,7 +26,7 @@
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
static inline uint8_t inportb(uint16_t Port)
|
||||
static inline uint8_t inb(uint16_t Port)
|
||||
{
|
||||
uint8_t Result;
|
||||
asm("in %%dx, %%al"
|
||||
@ -35,7 +35,7 @@ extern "C"
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline uint16_t inportw(uint16_t Port)
|
||||
static inline uint16_t inw(uint16_t Port)
|
||||
{
|
||||
uint16_t Result;
|
||||
asm("in %%dx, %%ax"
|
||||
@ -44,7 +44,7 @@ extern "C"
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline uint32_t inportl(uint16_t Port)
|
||||
static inline uint32_t inl(uint16_t Port)
|
||||
{
|
||||
uint32_t Result;
|
||||
asmv("inl %1, %0"
|
||||
@ -53,103 +53,27 @@ extern "C"
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline void outportb(uint16_t Port, uint8_t Data)
|
||||
static inline void outb(uint16_t Port, uint8_t Data)
|
||||
{
|
||||
asmv("out %%al, %%dx"
|
||||
:
|
||||
: "a"(Data), "d"(Port));
|
||||
}
|
||||
|
||||
static inline void outportw(uint16_t Port, uint16_t Data)
|
||||
static inline void outw(uint16_t Port, uint16_t Data)
|
||||
{
|
||||
asmv("out %%ax, %%dx"
|
||||
:
|
||||
: "a"(Data), "d"(Port));
|
||||
}
|
||||
|
||||
static inline void outportl(uint16_t Port, uint32_t Data)
|
||||
static inline void outl(uint16_t Port, uint32_t Data)
|
||||
{
|
||||
asmv("outl %1, %0"
|
||||
:
|
||||
: "dN"(Port), "a"(Data));
|
||||
}
|
||||
|
||||
static inline uint8_t mmioin8(uint64_t Address)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
uint8_t Result = *(volatile uint8_t *)(uintptr_t)Address;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline uint16_t mmioin16(uint64_t Address)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
uint16_t Result = *(volatile uint16_t *)(uintptr_t)Address;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline uint32_t mmioin32(uint64_t Address)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
uint32_t Result = *(volatile uint32_t *)(uintptr_t)Address;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline uint64_t mmioin64(uint64_t Address)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
uint64_t Result = *(volatile uint64_t *)(uintptr_t)Address;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
return Result;
|
||||
}
|
||||
|
||||
static inline void mmioout8(uint64_t Address, uint8_t Data)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
*(volatile uint8_t *)Address = Data;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void mmioout16(uint64_t Address, uint16_t Data)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
*(volatile uint16_t *)Address = Data;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void mmioout32(uint64_t Address, uint32_t Data)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
*(volatile uint32_t *)Address = Data;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void mmioout64(uint64_t Address, uint64_t Data)
|
||||
{
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
*(volatile uint64_t *)Address = Data;
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void mmoutb(void *Address, uint8_t Value)
|
||||
{
|
||||
asmv("mov %1, %0"
|
||||
@ -225,17 +149,10 @@ extern "C"
|
||||
return Result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#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(a86)
|
||||
|
||||
#endif // !__FENNIX_KERNEL_IO_H__
|
||||
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
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_IPC_H__
|
||||
#define __FENNIX_KERNEL_IPC_H__
|
||||
|
||||
#include <types.h>
|
||||
#include <filesystem.hpp>
|
||||
#include <memory.hpp>
|
||||
#include <lock.hpp>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
namespace InterProcessCommunication
|
||||
{
|
||||
typedef int IPCID;
|
||||
|
||||
enum IPCType
|
||||
{
|
||||
IPCNone,
|
||||
IPCMessagePassing,
|
||||
IPCPort,
|
||||
IPCSharedMemory,
|
||||
IPCPipe,
|
||||
IPCSocket
|
||||
};
|
||||
|
||||
enum IPCErrorCode
|
||||
{
|
||||
IPCError = -1,
|
||||
IPCSuccess,
|
||||
IPCNotListening,
|
||||
IPCTimeout,
|
||||
IPCInvalidCommand,
|
||||
IPCAlreadyAllocated,
|
||||
IPCNotAllocated,
|
||||
IPCIDInUse,
|
||||
IPCIDNotRegistered,
|
||||
IPCIDNotFound
|
||||
};
|
||||
|
||||
struct IPCHandle
|
||||
{
|
||||
IPCID ID;
|
||||
vfs::Node *Node;
|
||||
void *Buffer;
|
||||
long Length;
|
||||
std::atomic_bool Listening;
|
||||
};
|
||||
|
||||
class IPC
|
||||
{
|
||||
private:
|
||||
NewLock(IPCLock);
|
||||
IPCID NextID = 0;
|
||||
std::vector<IPCHandle *> Handles;
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
vfs::Node *IPCNode;
|
||||
void *Process;
|
||||
|
||||
public:
|
||||
std::vector<IPCHandle *> GetHandles() { return Handles; }
|
||||
void Fork(IPC *Parent);
|
||||
IPCHandle *Create(IPCType Type, char UniqueToken[16]);
|
||||
IPCErrorCode Destroy(IPCID ID);
|
||||
IPCErrorCode Allocate(IPCID ID, long Size);
|
||||
IPCErrorCode Deallocate(IPCID ID);
|
||||
IPCErrorCode Read(IPCID ID, void *Buffer, long Size);
|
||||
IPCErrorCode Write(IPCID ID, void *Buffer, long Size);
|
||||
IPCErrorCode Listen(IPCID ID, bool Listen);
|
||||
IPCErrorCode Wait(IPCID ID);
|
||||
IPCHandle *SearchByToken(char UniqueToken[16]);
|
||||
int HandleSyscall(long Command, long Type, int ID, int Flags, void *Buffer, size_t Size);
|
||||
|
||||
IPC(void *Process);
|
||||
~IPC();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_IPC_H__
|
@ -23,23 +23,23 @@
|
||||
|
||||
enum KCSchedType
|
||||
{
|
||||
Mono = 0,
|
||||
Multi = 1,
|
||||
Mono = 0,
|
||||
Multi = 1,
|
||||
};
|
||||
|
||||
struct KernelConfig
|
||||
{
|
||||
Memory::MemoryAllocatorType AllocatorType;
|
||||
bool SchedulerType;
|
||||
char ModuleDirectory[256];
|
||||
char InitPath[256];
|
||||
bool UseLinuxSyscalls;
|
||||
bool InterruptsOnCrash;
|
||||
int Cores;
|
||||
int IOAPICInterruptCore;
|
||||
bool UnlockDeadLock;
|
||||
bool SIMD;
|
||||
bool BootAnimation;
|
||||
Memory::MemoryAllocatorType AllocatorType;
|
||||
bool SchedulerType;
|
||||
char DriverDirectory[256];
|
||||
char InitPath[256];
|
||||
bool UseLinuxSyscalls;
|
||||
bool InterruptsOnCrash;
|
||||
int Cores;
|
||||
int IOAPICInterruptCore;
|
||||
bool UnlockDeadLock;
|
||||
bool SIMD;
|
||||
bool Quiet;
|
||||
};
|
||||
|
||||
void ParseConfig(char *ConfigString, KernelConfig *ModConfig);
|
||||
|
@ -60,6 +60,7 @@ private:
|
||||
void Yield();
|
||||
|
||||
public:
|
||||
bool Locked() { return IsLocked.load(); }
|
||||
SpinLockData *GetLockData() { return &LockData; }
|
||||
int Lock(const char *FunctionName);
|
||||
int Unlock();
|
||||
@ -74,6 +75,11 @@ private:
|
||||
LockClass *LockPointer = nullptr;
|
||||
|
||||
public:
|
||||
bool Locked()
|
||||
{
|
||||
return this->LockPointer->Locked();
|
||||
}
|
||||
|
||||
SmartLockClass(LockClass &Lock, const char *FunctionName)
|
||||
{
|
||||
this->LockPointer = &Lock;
|
||||
@ -88,6 +94,11 @@ private:
|
||||
LockClass *LockPointer = nullptr;
|
||||
|
||||
public:
|
||||
bool Locked()
|
||||
{
|
||||
return this->LockPointer->Locked();
|
||||
}
|
||||
|
||||
SmartTimeoutLockClass(LockClass &Lock,
|
||||
const char *FunctionName,
|
||||
uint64_t Timeout)
|
||||
|
@ -28,10 +28,10 @@ START_EXTERNC
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t size; // Size of input in bytes
|
||||
uint32_t buffer[4]; // Current accumulation of hash
|
||||
uint8_t input[64]; // Input to be used in the next step
|
||||
uint8_t digest[16]; // Result of algorithm
|
||||
size_t size; // Size of input in bytes
|
||||
uint32_t buffer[4]; // Current accumulation of hash
|
||||
uint8_t input[64]; // Input to be used in the next step
|
||||
uint8_t digest[16]; // Result of algorithm
|
||||
} MD5Context;
|
||||
|
||||
void md5Init(MD5Context *ctx);
|
||||
|
@ -43,10 +43,20 @@ namespace Memory
|
||||
enum MemoryAllocatorType
|
||||
{
|
||||
None,
|
||||
|
||||
/** Allocate memory by pages. */
|
||||
Pages,
|
||||
|
||||
XallocV1,
|
||||
XallocV2,
|
||||
liballoc11
|
||||
liballoc11,
|
||||
|
||||
/**
|
||||
* @warning Not working as expected.
|
||||
*
|
||||
* FIXME: This allocator is not working as expected.
|
||||
*/
|
||||
rpmalloc_,
|
||||
};
|
||||
}
|
||||
|
||||
@ -61,6 +71,7 @@ namespace Memory
|
||||
#include <memory/brk.hpp>
|
||||
|
||||
void InitializeMemoryManagement();
|
||||
void CreatePageTable(Memory::PageTable *pt);
|
||||
|
||||
void *operator new(std::size_t Size);
|
||||
void *operator new[](std::size_t Size);
|
||||
|
@ -36,6 +36,9 @@ namespace Memory
|
||||
uintptr_t Break = 0x0;
|
||||
|
||||
public:
|
||||
/* fork() */
|
||||
void SetTable(PageTable *Table) { this->Table = Table; }
|
||||
|
||||
/* Directly to syscall */
|
||||
void *brk(void *Address);
|
||||
|
||||
|
@ -148,7 +148,7 @@ namespace Memory
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
};
|
||||
uintptr_t raw;
|
||||
uintptr_t raw = 0;
|
||||
|
||||
/** @brief Set Address */
|
||||
void SetAddress(uintptr_t _Address)
|
||||
@ -273,7 +273,7 @@ namespace Memory
|
||||
} FourMiB;
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
uintptr_t raw;
|
||||
uintptr_t raw = 0;
|
||||
|
||||
/** @brief Set PageTableEntryPtr address */
|
||||
void SetAddress(uintptr_t _Address)
|
||||
@ -359,7 +359,7 @@ namespace Memory
|
||||
} OneGiB;
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
uintptr_t raw;
|
||||
uintptr_t raw = 0;
|
||||
|
||||
/** @brief Set PageDirectoryEntryPtr address */
|
||||
void SetAddress(uintptr_t _Address)
|
||||
@ -413,7 +413,7 @@ namespace Memory
|
||||
};
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
uintptr_t raw;
|
||||
uintptr_t raw = 0;
|
||||
|
||||
/** @brief Set PageDirectoryPointerTableEntryPtr address */
|
||||
void SetAddress(uintptr_t _Address)
|
||||
@ -467,7 +467,7 @@ namespace Memory
|
||||
};
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
uintptr_t raw;
|
||||
uintptr_t raw = 0;
|
||||
|
||||
/** @brief Set PageMapLevel4Ptr address */
|
||||
void SetAddress(uintptr_t _Address)
|
||||
@ -516,10 +516,34 @@ namespace Memory
|
||||
*
|
||||
* @return A new PageTable with the same content
|
||||
*/
|
||||
PageTable Fork();
|
||||
PageTable *Fork();
|
||||
|
||||
void *__getPhysical(void *Address);
|
||||
|
||||
/**
|
||||
* @brief Get the Physical Address of a virtual address
|
||||
*
|
||||
* This function will return the physical address
|
||||
* of a virtual address and not the virtual address
|
||||
* of the current page table. This is intentional because
|
||||
* the kernel page table has 1:1 mapping for the free
|
||||
* memory.
|
||||
*
|
||||
* @tparam T
|
||||
* @param Address The virtual address
|
||||
* @return The physical address
|
||||
*/
|
||||
template <typename T>
|
||||
T Get(T Address);
|
||||
T Get(T Address)
|
||||
{
|
||||
void *PhysAddr = __getPhysical((void *)Address);
|
||||
if (PhysAddr == nullptr)
|
||||
return {};
|
||||
uintptr_t Diff = uintptr_t(Address);
|
||||
Diff &= 0xFFF;
|
||||
Diff = uintptr_t(PhysAddr) + Diff;
|
||||
return (T)Diff;
|
||||
}
|
||||
} __aligned(0x1000);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace Memory
|
||||
{
|
||||
private:
|
||||
NewLock(MemoryLock);
|
||||
PageTable *Table = nullptr;
|
||||
PageTable *pTable = nullptr;
|
||||
|
||||
public:
|
||||
enum MapType
|
||||
@ -60,8 +60,7 @@ namespace Memory
|
||||
* @param VirtualAddress Virtual address of the page
|
||||
* @param Flag Flag to check
|
||||
* @param Type Type of the page. Check MapType enum.
|
||||
* @return true if page has the specified flag.
|
||||
* @return false if page is has the specified flag.
|
||||
* @return true if page has the specified flag, false otherwise.
|
||||
*/
|
||||
bool Check(void *VirtualAddress,
|
||||
PTFlag Flag = PTFlag::P,
|
||||
|
@ -56,6 +56,7 @@ namespace Memory
|
||||
|
||||
public:
|
||||
PageTable *GetTable() { return Table; }
|
||||
void SetTable(PageTable *Table) { this->Table = Table; }
|
||||
|
||||
std::vector<AllocatedPages> GetAllocatedPagesList()
|
||||
{
|
||||
@ -94,6 +95,10 @@ namespace Memory
|
||||
|
||||
bool HandleCoW(uintptr_t PFA);
|
||||
|
||||
void FreeAllPages();
|
||||
|
||||
void Fork(VirtualMemoryArea *Parent);
|
||||
|
||||
VirtualMemoryArea(PageTable *Table = nullptr);
|
||||
~VirtualMemoryArea();
|
||||
};
|
||||
|
@ -1,235 +0,0 @@
|
||||
/*
|
||||
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_MODULE_H__
|
||||
#define __FENNIX_KERNEL_MODULE_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <ints.hpp>
|
||||
#include <lock.hpp>
|
||||
#include <debug.h>
|
||||
#include <cpu.hpp>
|
||||
#include <pci.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Module
|
||||
{
|
||||
enum ModuleCode
|
||||
{
|
||||
/* This must be the same as in mapi.hpp ModuleReturnCode */
|
||||
ERROR,
|
||||
OK,
|
||||
NOT_IMPLEMENTED,
|
||||
NOT_FOUND,
|
||||
NOT_READY,
|
||||
NOT_AVAILABLE,
|
||||
NOT_AUTHORIZED,
|
||||
NOT_VALID,
|
||||
NOT_ACCEPTED,
|
||||
INVALID_PCI_BAR,
|
||||
INVALID_KERNEL_API,
|
||||
INVALID_MEMORY_ALLOCATION,
|
||||
INVALID_DATA,
|
||||
DEVICE_NOT_SUPPORTED,
|
||||
SYSTEM_NOT_SUPPORTED,
|
||||
KERNEL_API_VERSION_NOT_SUPPORTED,
|
||||
|
||||
/* End of module-only errors */
|
||||
|
||||
INVALID_FEX_HEADER,
|
||||
INVALID_MODULE_DATA,
|
||||
NOT_MODULE,
|
||||
MODULE_RETURNED_ERROR,
|
||||
UNKNOWN_MODULE_TYPE,
|
||||
UNKNOWN_MODULE_BIND_TYPE,
|
||||
PCI_DEVICE_NOT_FOUND,
|
||||
MODULE_CONFLICT
|
||||
};
|
||||
|
||||
class ModuleInterruptHook;
|
||||
struct ModuleFile
|
||||
{
|
||||
bool Enabled = false;
|
||||
bool BuiltIn = false;
|
||||
unsigned int modUniqueID = 0;
|
||||
void *Address = nullptr;
|
||||
void *ExtendedHeaderAddress = nullptr;
|
||||
void *InterruptCallback = nullptr;
|
||||
Memory::VirtualMemoryArea *vma = nullptr;
|
||||
ModuleInterruptHook *InterruptHook[16]{};
|
||||
|
||||
bool operator==(const ModuleFile &Other) const
|
||||
{
|
||||
return modUniqueID == Other.modUniqueID;
|
||||
}
|
||||
};
|
||||
|
||||
struct BuiltInModuleInfo
|
||||
{
|
||||
int (*EntryPoint)(void *);
|
||||
void *ExtendedHeader;
|
||||
};
|
||||
|
||||
class ModuleInterruptHook : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
NewLock(DriverInterruptLock);
|
||||
|
||||
ModuleFile Handle;
|
||||
bool Enabled = true;
|
||||
|
||||
#if defined(a64)
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
#elif defined(a32)
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
#elif defined(aa64)
|
||||
void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
#endif
|
||||
|
||||
public:
|
||||
void Enable() { Enabled = true; }
|
||||
void Disable() { Enabled = false; }
|
||||
bool IsEnabled() { return Enabled; }
|
||||
ModuleInterruptHook(int Interrupt, ModuleFile Handle);
|
||||
virtual ~ModuleInterruptHook() = default;
|
||||
};
|
||||
|
||||
class Module
|
||||
{
|
||||
private:
|
||||
NewLock(ModuleInitLock);
|
||||
|
||||
std::vector<ModuleFile> Modules;
|
||||
unsigned int modUIDs = 0;
|
||||
/* If BuiltIn is true, the "fex" is the entry point. */
|
||||
ModuleCode CallModuleEntryPoint(void *fex, bool BuiltIn = false);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Load and bind a module to a PCI device.
|
||||
*
|
||||
* This function will search for a PCI device with the given VendorID and DeviceID.
|
||||
* If the device is found, the module will be loaded and bound to the device.
|
||||
*
|
||||
* @param ModuleAddress The address of the module. The file will be copied to a new location.
|
||||
* @param Size The size of the module.
|
||||
* @param IsBuiltIn If the module is built-in, the @param ModuleAddress will be @see BuiltInModuleInfo and the @param Size will be ignored.
|
||||
* @return ModuleCode The result of the operation.
|
||||
*/
|
||||
ModuleCode ModuleLoadBindPCI(uintptr_t ModuleAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
/**
|
||||
* @brief Load and bind a module to an interrupt.
|
||||
*
|
||||
* This function will search for an interrupt with the given IRQ.
|
||||
* If the interrupt is found, the module will be loaded and bound to the interrupt.
|
||||
*
|
||||
* @param ModuleAddress The address of the module. The file will be copied to a new location.
|
||||
* @param Size The size of the module.
|
||||
* @param IsBuiltIn If the module is built-in, the @param ModuleAddress will be @see BuiltInModuleInfo and the @param Size will be ignored.
|
||||
* @return ModuleCode The result of the operation.
|
||||
*/
|
||||
ModuleCode ModuleLoadBindInterrupt(uintptr_t ModuleAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
/**
|
||||
* @brief Load and bind a module to an input device.
|
||||
*
|
||||
* This function will attach the module to the input device.
|
||||
*
|
||||
* @param ModuleAddress The address of the module. The file will be copied to a new location.
|
||||
* @param Size The size of the module.
|
||||
* @param IsBuiltIn If the module is built-in, the @param ModuleAddress will be @see BuiltInModuleInfo and the @param Size will be ignored.
|
||||
* @return ModuleCode The result of the operation.
|
||||
*/
|
||||
ModuleCode ModuleLoadBindInput(uintptr_t ModuleAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
/**
|
||||
* @brief Load and bind a module to a process.
|
||||
*
|
||||
* This function will attach the module to the process.
|
||||
*
|
||||
* @param ModuleAddress The address of the module. The file will be copied to a new location.
|
||||
* @param Size The size of the module.
|
||||
* @param IsBuiltIn If the module is built-in, the @param ModuleAddress will be @see BuiltInModuleInfo and the @param Size will be ignored.
|
||||
* @return ModuleCode The result of the operation.
|
||||
*/
|
||||
ModuleCode ModuleLoadBindProcess(uintptr_t ModuleAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
/**
|
||||
* @brief Get the currently loaded drivers.
|
||||
*
|
||||
* This function returns a clone of the drivers vector.
|
||||
* This means that the vector can be modified without affecting the drivers.
|
||||
*
|
||||
* @return std::vector<ModuleFile> A clone of the drivers vector.
|
||||
*/
|
||||
std::vector<ModuleFile> GetModules() { return Modules; }
|
||||
|
||||
/* Reserved by the kernel */
|
||||
void Panic();
|
||||
|
||||
/**
|
||||
* @brief Unload all drivers.
|
||||
*
|
||||
* This function will unload all drivers.
|
||||
*/
|
||||
void UnloadAllModules();
|
||||
|
||||
/**
|
||||
* @brief Unload a module.
|
||||
*
|
||||
* This function will unload a module with the given module unique ID.
|
||||
* It will free the memory and remove the module from the drivers vector.
|
||||
*
|
||||
* @param id The module unique ID.
|
||||
* @return true If the module was found and unloaded successfully, false otherwise.
|
||||
*/
|
||||
bool UnloadModule(unsigned long id);
|
||||
|
||||
/**
|
||||
* @brief Send a callback to a module.
|
||||
*
|
||||
* This function will send a callback to a module with the given module unique ID.
|
||||
* This is used to communicate with drivers.
|
||||
*
|
||||
* @param id The module unique ID.
|
||||
* @param KCB The @see KernelCallback structure.
|
||||
* @return int The result of the operation.
|
||||
*/
|
||||
int IOCB(unsigned long id, /* KernelCallback */ void *KCB);
|
||||
|
||||
/**
|
||||
* @brief Load a module.
|
||||
* @param fildes The file descriptor of the module file.
|
||||
* @return ModuleCode The result of the operation.
|
||||
*/
|
||||
ModuleCode LoadModule(vfs::Node *fildes);
|
||||
|
||||
/* Reserved by the kernel */
|
||||
void LoadModules();
|
||||
|
||||
/* Reserved by the kernel */
|
||||
Module();
|
||||
|
||||
/* Reserved by the kernel */
|
||||
~Module();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_MODULE_H__
|
212
include/msexec.h
212
include/msexec.h
@ -112,137 +112,137 @@ typedef double DOUBLE;
|
||||
|
||||
typedef struct _IMAGE_DOS_HEADER /* DOS .EXE header */
|
||||
{
|
||||
USHORT e_magic; /* Magic number */
|
||||
USHORT e_cblp; /* Bytes on last page of file */
|
||||
USHORT e_cp; /* Pages in file */
|
||||
USHORT e_crlc; /* Relocations */
|
||||
USHORT e_cparhdr; /* Size of header in paragraphs */
|
||||
USHORT e_minalloc; /* Minimum extra paragraphs needed */
|
||||
USHORT e_maxalloc; /* Maximum extra paragraphs needed */
|
||||
USHORT e_ss; /* Initial (relative) SS value */
|
||||
USHORT e_sp; /* Initial SP value */
|
||||
USHORT e_csum; /* Checksum */
|
||||
USHORT e_ip; /* Initial IP value */
|
||||
USHORT e_cs; /* Initial (relative) CS value */
|
||||
USHORT e_lfarlc; /* File address of relocation table */
|
||||
USHORT e_ovno; /* Overlay number */
|
||||
USHORT e_res[4]; /* Reserved words */
|
||||
USHORT e_oemid; /* OEM identifier (for e_oeminfo) */
|
||||
USHORT e_oeminfo; /* OEM information; e_oemid specific */
|
||||
USHORT e_res2[10]; /* Reserved words */
|
||||
USHORT e_lfanew; /* File address of new exe header */
|
||||
USHORT e_magic; /* Magic number */
|
||||
USHORT e_cblp; /* Bytes on last page of file */
|
||||
USHORT e_cp; /* Pages in file */
|
||||
USHORT e_crlc; /* Relocations */
|
||||
USHORT e_cparhdr; /* Size of header in paragraphs */
|
||||
USHORT e_minalloc; /* Minimum extra paragraphs needed */
|
||||
USHORT e_maxalloc; /* Maximum extra paragraphs needed */
|
||||
USHORT e_ss; /* Initial (relative) SS value */
|
||||
USHORT e_sp; /* Initial SP value */
|
||||
USHORT e_csum; /* Checksum */
|
||||
USHORT e_ip; /* Initial IP value */
|
||||
USHORT e_cs; /* Initial (relative) CS value */
|
||||
USHORT e_lfarlc; /* File address of relocation table */
|
||||
USHORT e_ovno; /* Overlay number */
|
||||
USHORT e_res[4]; /* Reserved words */
|
||||
USHORT e_oemid; /* OEM identifier (for e_oeminfo) */
|
||||
USHORT e_oeminfo; /* OEM information; e_oemid specific */
|
||||
USHORT e_res2[10]; /* Reserved words */
|
||||
USHORT e_lfanew; /* File address of new exe header */
|
||||
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
|
||||
|
||||
typedef struct _IMAGE_OS2_HEADER /* OS/2 .EXE header */
|
||||
{
|
||||
USHORT ne_magic; /* Magic number */
|
||||
UCHAR ne_ver; /* Version number */
|
||||
UCHAR ne_rev; /* Revision number */
|
||||
USHORT ne_enttab; /* Offset of Entry Table */
|
||||
USHORT ne_cbenttab; /* Number of bytes in Entry Table */
|
||||
UINT ne_crc; /* Checksum of whole file */
|
||||
USHORT ne_flags; /* Flag word */
|
||||
USHORT ne_autodata; /* Automatic data segment number */
|
||||
USHORT ne_heap; /* Initial heap allocation */
|
||||
USHORT ne_stack; /* Initial stack allocation */
|
||||
UINT ne_csip; /* Initial CS:IP setting */
|
||||
UINT ne_sssp; /* Initial SS:SP setting */
|
||||
USHORT ne_cseg; /* Count of file segments */
|
||||
USHORT ne_cmod; /* Entries in Module Reference Table */
|
||||
USHORT ne_cbnrestab; /* Size of non-resident name table */
|
||||
USHORT ne_segtab; /* Offset of Segment Table */
|
||||
USHORT ne_rsrctab; /* Offset of Resource Table */
|
||||
USHORT ne_restab; /* Offset of resident name table */
|
||||
USHORT ne_modtab; /* Offset of Module Reference Table */
|
||||
USHORT ne_imptab; /* Offset of Imported Names Table */
|
||||
UINT ne_nrestab; /* Offset of Non-resident Names Table */
|
||||
USHORT ne_cmovent; /* Count of movable entries */
|
||||
USHORT ne_align; /* Segment alignment shift count */
|
||||
USHORT ne_cres; /* Count of resource segments */
|
||||
UCHAR ne_exetyp; /* Target Operating system */
|
||||
UCHAR ne_flagsothers; /* Other .EXE flags */
|
||||
USHORT ne_pretthunks; /* offset to return thunks */
|
||||
USHORT ne_psegrefbytes; /* offset to segment ref. bytes */
|
||||
USHORT ne_swaparea; /* Minimum code swap area size */
|
||||
USHORT ne_expver; /* Expected Windows version number */
|
||||
USHORT ne_magic; /* Magic number */
|
||||
UCHAR ne_ver; /* Version number */
|
||||
UCHAR ne_rev; /* Revision number */
|
||||
USHORT ne_enttab; /* Offset of Entry Table */
|
||||
USHORT ne_cbenttab; /* Number of bytes in Entry Table */
|
||||
UINT ne_crc; /* Checksum of whole file */
|
||||
USHORT ne_flags; /* Flag word */
|
||||
USHORT ne_autodata; /* Automatic data segment number */
|
||||
USHORT ne_heap; /* Initial heap allocation */
|
||||
USHORT ne_stack; /* Initial stack allocation */
|
||||
UINT ne_csip; /* Initial CS:IP setting */
|
||||
UINT ne_sssp; /* Initial SS:SP setting */
|
||||
USHORT ne_cseg; /* Count of file segments */
|
||||
USHORT ne_cmod; /* Entries in Module Reference Table */
|
||||
USHORT ne_cbnrestab; /* Size of non-resident name table */
|
||||
USHORT ne_segtab; /* Offset of Segment Table */
|
||||
USHORT ne_rsrctab; /* Offset of Resource Table */
|
||||
USHORT ne_restab; /* Offset of resident name table */
|
||||
USHORT ne_modtab; /* Offset of Module Reference Table */
|
||||
USHORT ne_imptab; /* Offset of Imported Names Table */
|
||||
UINT ne_nrestab; /* Offset of Non-resident Names Table */
|
||||
USHORT ne_cmovent; /* Count of movable entries */
|
||||
USHORT ne_align; /* Segment alignment shift count */
|
||||
USHORT ne_cres; /* Count of resource segments */
|
||||
UCHAR ne_exetyp; /* Target Operating system */
|
||||
UCHAR ne_flagsothers; /* Other .EXE flags */
|
||||
USHORT ne_pretthunks; /* offset to return thunks */
|
||||
USHORT ne_psegrefbytes; /* offset to segment ref. bytes */
|
||||
USHORT ne_swaparea; /* Minimum code swap area size */
|
||||
USHORT ne_expver; /* Expected Windows version number */
|
||||
} IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
|
||||
|
||||
typedef struct _IMAGE_SECTION_HEADER
|
||||
{
|
||||
#define IMAGE_SIZEOF_SHORT_NAME 8
|
||||
uint8_t Name[IMAGE_SIZEOF_SHORT_NAME];
|
||||
union
|
||||
{
|
||||
uint32_t PhysicalAddress;
|
||||
uint32_t VirtualSize;
|
||||
} Misc;
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t SizeOfRawData;
|
||||
uint32_t PointerToRawData;
|
||||
uint32_t PointerToRelocations;
|
||||
uint32_t PointerToLinenumbers;
|
||||
uint16_t NumberOfRelocations;
|
||||
uint16_t NumberOfLinenumbers;
|
||||
uint32_t Characteristics;
|
||||
uint8_t Name[IMAGE_SIZEOF_SHORT_NAME];
|
||||
union
|
||||
{
|
||||
uint32_t PhysicalAddress;
|
||||
uint32_t VirtualSize;
|
||||
} Misc;
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t SizeOfRawData;
|
||||
uint32_t PointerToRawData;
|
||||
uint32_t PointerToRelocations;
|
||||
uint32_t PointerToLinenumbers;
|
||||
uint16_t NumberOfRelocations;
|
||||
uint16_t NumberOfLinenumbers;
|
||||
uint32_t Characteristics;
|
||||
} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
|
||||
|
||||
typedef struct _IMAGE_FILE_HEADER
|
||||
{
|
||||
uint16_t Machine;
|
||||
uint16_t NumberOfSections;
|
||||
uint32_t TimeDateStamp;
|
||||
uint32_t PointerToSymbolTable;
|
||||
uint32_t NumberOfSymbols;
|
||||
uint16_t SizeOfOptionalHeader;
|
||||
uint16_t Characteristics;
|
||||
uint16_t Machine;
|
||||
uint16_t NumberOfSections;
|
||||
uint32_t TimeDateStamp;
|
||||
uint32_t PointerToSymbolTable;
|
||||
uint32_t NumberOfSymbols;
|
||||
uint16_t SizeOfOptionalHeader;
|
||||
uint16_t Characteristics;
|
||||
} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
|
||||
|
||||
typedef struct _IMAGE_DATA_DIRECTORY
|
||||
{
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t Size;
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t Size;
|
||||
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
|
||||
|
||||
typedef struct _IMAGE_OPTIONAL_HEADER
|
||||
{
|
||||
uint16_t Magic;
|
||||
uint8_t MajorLinkerVersion;
|
||||
uint8_t MinorLinkerVersion;
|
||||
uint32_t SizeOfCode;
|
||||
uint32_t SizeOfInitializedData;
|
||||
uint32_t SizeOfUninitializedData;
|
||||
uint32_t AddressOfEntryPoint;
|
||||
uint32_t BaseOfCode;
|
||||
uint32_t BaseOfData;
|
||||
uint32_t ImageBase;
|
||||
uint32_t SectionAlignment;
|
||||
uint32_t FileAlignment;
|
||||
uint16_t MajorOperatingSystemVersion;
|
||||
uint16_t MinorOperatingSystemVersion;
|
||||
uint16_t MajorImageVersion;
|
||||
uint16_t MinorImageVersion;
|
||||
uint16_t MajorSubsystemVersion;
|
||||
uint16_t MinorSubsystemVersion;
|
||||
uint32_t Win32VersionValue;
|
||||
uint32_t SizeOfImage;
|
||||
uint32_t SizeOfHeaders;
|
||||
uint32_t CheckSum;
|
||||
uint16_t Subsystem;
|
||||
uint16_t DllCharacteristics;
|
||||
uint32_t SizeOfStackReserve;
|
||||
uint32_t SizeOfStackCommit;
|
||||
uint32_t SizeOfHeapReserve;
|
||||
uint32_t SizeOfHeapCommit;
|
||||
uint32_t LoaderFlags;
|
||||
uint32_t NumberOfRvaAndSizes;
|
||||
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
|
||||
uint16_t Magic;
|
||||
uint8_t MajorLinkerVersion;
|
||||
uint8_t MinorLinkerVersion;
|
||||
uint32_t SizeOfCode;
|
||||
uint32_t SizeOfInitializedData;
|
||||
uint32_t SizeOfUninitializedData;
|
||||
uint32_t AddressOfEntryPoint;
|
||||
uint32_t BaseOfCode;
|
||||
uint32_t BaseOfData;
|
||||
uint32_t ImageBase;
|
||||
uint32_t SectionAlignment;
|
||||
uint32_t FileAlignment;
|
||||
uint16_t MajorOperatingSystemVersion;
|
||||
uint16_t MinorOperatingSystemVersion;
|
||||
uint16_t MajorImageVersion;
|
||||
uint16_t MinorImageVersion;
|
||||
uint16_t MajorSubsystemVersion;
|
||||
uint16_t MinorSubsystemVersion;
|
||||
uint32_t Win32VersionValue;
|
||||
uint32_t SizeOfImage;
|
||||
uint32_t SizeOfHeaders;
|
||||
uint32_t CheckSum;
|
||||
uint16_t Subsystem;
|
||||
uint16_t DllCharacteristics;
|
||||
uint32_t SizeOfStackReserve;
|
||||
uint32_t SizeOfStackCommit;
|
||||
uint32_t SizeOfHeapReserve;
|
||||
uint32_t SizeOfHeapCommit;
|
||||
uint32_t LoaderFlags;
|
||||
uint32_t NumberOfRvaAndSizes;
|
||||
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
|
||||
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
|
||||
|
||||
typedef struct _IMAGE_NT_HEADERS
|
||||
{
|
||||
uint32_t Signature;
|
||||
IMAGE_FILE_HEADER FileHeader;
|
||||
IMAGE_OPTIONAL_HEADER OptionalHeader;
|
||||
uint32_t Signature;
|
||||
IMAGE_FILE_HEADER FileHeader;
|
||||
IMAGE_OPTIONAL_HEADER OptionalHeader;
|
||||
} IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
|
||||
|
||||
#endif // !__FENNIX_KERNEL_MSEXEC_H__
|
||||
|
@ -25,82 +25,82 @@
|
||||
|
||||
namespace NetworkARP
|
||||
{
|
||||
enum ARPOperation
|
||||
{
|
||||
REQUEST = 0x1,
|
||||
REPLY = 0x2
|
||||
};
|
||||
enum ARPOperation
|
||||
{
|
||||
REQUEST = 0x1,
|
||||
REPLY = 0x2
|
||||
};
|
||||
|
||||
enum ARPHardwareType
|
||||
{
|
||||
HTYPE_ETHERNET = 1,
|
||||
HTYPE_802_3 = 6,
|
||||
HTYPE_ARCNET = 7,
|
||||
HTYPE_FRAME_RELAY = 15,
|
||||
HTYPE_ATM = 16,
|
||||
HTYPE_HDLC = 17,
|
||||
HTYPE_FIBRE_CHANNEL = 18,
|
||||
HTYPE_ATM_2 = 19,
|
||||
HTYPE_SERIAL_LINE = 20
|
||||
};
|
||||
enum ARPHardwareType
|
||||
{
|
||||
HTYPE_ETHERNET = 1,
|
||||
HTYPE_802_3 = 6,
|
||||
HTYPE_ARCNET = 7,
|
||||
HTYPE_FRAME_RELAY = 15,
|
||||
HTYPE_ATM = 16,
|
||||
HTYPE_HDLC = 17,
|
||||
HTYPE_FIBRE_CHANNEL = 18,
|
||||
HTYPE_ATM_2 = 19,
|
||||
HTYPE_SERIAL_LINE = 20
|
||||
};
|
||||
|
||||
struct ARPHeader
|
||||
{
|
||||
uint16_t HardwareType;
|
||||
uint16_t ProtocolType;
|
||||
uint8_t HardwareSize;
|
||||
uint8_t ProtocolSize;
|
||||
uint16_t Operation;
|
||||
uint48_t SenderMAC : 48;
|
||||
uint32_t SenderIP;
|
||||
uint48_t TargetMAC : 48;
|
||||
uint32_t TargetIP;
|
||||
} __packed;
|
||||
struct ARPHeader
|
||||
{
|
||||
uint16_t HardwareType;
|
||||
uint16_t ProtocolType;
|
||||
uint8_t HardwareSize;
|
||||
uint8_t ProtocolSize;
|
||||
uint16_t Operation;
|
||||
uint48_t SenderMAC : 48;
|
||||
uint32_t SenderIP;
|
||||
uint48_t TargetMAC : 48;
|
||||
uint32_t TargetIP;
|
||||
} __packed;
|
||||
|
||||
struct DiscoveredAddress
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
InternetProtocol IP;
|
||||
};
|
||||
struct DiscoveredAddress
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
InternetProtocol IP;
|
||||
};
|
||||
|
||||
class ARP : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
class ARP : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
|
||||
enum DAType
|
||||
{
|
||||
DA_ADD = 1,
|
||||
DA_DEL = 2,
|
||||
DA_SEARCH = 3,
|
||||
DA_UPDATE = 4
|
||||
};
|
||||
enum DAType
|
||||
{
|
||||
DA_ADD = 1,
|
||||
DA_DEL = 2,
|
||||
DA_SEARCH = 3,
|
||||
DA_UPDATE = 4
|
||||
};
|
||||
|
||||
std::vector<NetworkARP::DiscoveredAddress *> DiscoveredAddresses;
|
||||
DiscoveredAddress *ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC);
|
||||
DiscoveredAddress *Search(InternetProtocol TargetIP);
|
||||
DiscoveredAddress *Update(InternetProtocol TargetIP, MediaAccessControl TargetMAC);
|
||||
bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
std::vector<NetworkARP::DiscoveredAddress *> DiscoveredAddresses;
|
||||
DiscoveredAddress *ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC);
|
||||
DiscoveredAddress *Search(InternetProtocol TargetIP);
|
||||
DiscoveredAddress *Update(InternetProtocol TargetIP, MediaAccessControl TargetMAC);
|
||||
bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
ARP(NetworkEthernet::Ethernet *Ethernet);
|
||||
~ARP();
|
||||
public:
|
||||
ARP(NetworkEthernet::Ethernet *Ethernet);
|
||||
~ARP();
|
||||
|
||||
/**
|
||||
* @brief Resolve an IP address to a MAC address.
|
||||
*
|
||||
* @param IP The IP address to resolve. (Little-endian)
|
||||
* @return uint48_t The MAC address of the IP address.
|
||||
*/
|
||||
uint48_t Resolve(InternetProtocol IP);
|
||||
/**
|
||||
* @brief Resolve an IP address to a MAC address.
|
||||
*
|
||||
* @param IP The IP address to resolve. (Little-endian)
|
||||
* @return uint48_t The MAC address of the IP address.
|
||||
*/
|
||||
uint48_t Resolve(InternetProtocol IP);
|
||||
|
||||
/**
|
||||
* @brief Broadcast an ARP packet.
|
||||
*
|
||||
* @param IP The IP address to broadcast.
|
||||
*/
|
||||
void Broadcast(InternetProtocol IP);
|
||||
};
|
||||
/**
|
||||
* @brief Broadcast an ARP packet.
|
||||
*
|
||||
* @param IP The IP address to broadcast.
|
||||
*/
|
||||
void Broadcast(InternetProtocol IP);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NETWORK_ARP_H__
|
||||
|
@ -25,158 +25,158 @@
|
||||
|
||||
namespace NetworkDHCP
|
||||
{
|
||||
struct DHCPHeader
|
||||
{
|
||||
uint8_t Opcode;
|
||||
uint8_t HardwareType;
|
||||
uint8_t HardwareAddressLength;
|
||||
uint8_t Hops;
|
||||
uint32_t TransactionID;
|
||||
uint16_t Seconds;
|
||||
uint16_t Flags;
|
||||
uint32_t ClientIP;
|
||||
uint32_t YourIP;
|
||||
uint32_t ServerIP;
|
||||
uint32_t GatewayIP;
|
||||
uint8_t ClientHardwareAddress[16];
|
||||
uint8_t ServerHostName[64];
|
||||
uint8_t BootFileName[128];
|
||||
uint8_t Options[64];
|
||||
} __packed;
|
||||
struct DHCPHeader
|
||||
{
|
||||
uint8_t Opcode;
|
||||
uint8_t HardwareType;
|
||||
uint8_t HardwareAddressLength;
|
||||
uint8_t Hops;
|
||||
uint32_t TransactionID;
|
||||
uint16_t Seconds;
|
||||
uint16_t Flags;
|
||||
uint32_t ClientIP;
|
||||
uint32_t YourIP;
|
||||
uint32_t ServerIP;
|
||||
uint32_t GatewayIP;
|
||||
uint8_t ClientHardwareAddress[16];
|
||||
uint8_t ServerHostName[64];
|
||||
uint8_t BootFileName[128];
|
||||
uint8_t Options[64];
|
||||
} __packed;
|
||||
|
||||
enum DHCPOperation
|
||||
{
|
||||
DHCP_OP_BOOTREQUEST = 1,
|
||||
DHCP_OP_BOOTREPLY = 2
|
||||
};
|
||||
enum DHCPOperation
|
||||
{
|
||||
DHCP_OP_BOOTREQUEST = 1,
|
||||
DHCP_OP_BOOTREPLY = 2
|
||||
};
|
||||
|
||||
/* TODO: Complete list from https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol#Options */
|
||||
enum DHCPOption
|
||||
{
|
||||
DHCP_OPTION_PAD = 0,
|
||||
DHCP_OPTION_SUBNETMASK = 1,
|
||||
DHCP_OPTION_TIME_OFFSET = 2,
|
||||
DHCP_OPTION_ROUTER = 3,
|
||||
DHCP_OPTION_TIME_SERVER = 4,
|
||||
DHCP_OPTION_NAME_SERVER = 5,
|
||||
DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
|
||||
DHCP_OPTION_LOG_SERVER = 7,
|
||||
DHCP_OPTION_COOKIE_SERVER = 8,
|
||||
DHCP_OPTION_LPR_SERVER = 9,
|
||||
DHCP_OPTION_IMPRESS_SERVER = 10,
|
||||
DHCP_OPTION_RESOURCE_LOCATION_SERVER = 11,
|
||||
DHCP_OPTION_HOST_NAME = 12,
|
||||
DHCP_OPTION_BOOT_FILE_SIZE = 13,
|
||||
DHCP_OPTION_MERIT_DUMP_FILE = 14,
|
||||
DHCP_OPTION_DOMAIN_NAME = 15,
|
||||
DHCP_OPTION_SWAP_SERVER = 16,
|
||||
DHCP_OPTION_ROOT_PATH = 17,
|
||||
DHCP_OPTION_EXTENSION_PATH = 18,
|
||||
/* TODO: Complete list from https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol#Options */
|
||||
enum DHCPOption
|
||||
{
|
||||
DHCP_OPTION_PAD = 0,
|
||||
DHCP_OPTION_SUBNETMASK = 1,
|
||||
DHCP_OPTION_TIME_OFFSET = 2,
|
||||
DHCP_OPTION_ROUTER = 3,
|
||||
DHCP_OPTION_TIME_SERVER = 4,
|
||||
DHCP_OPTION_NAME_SERVER = 5,
|
||||
DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
|
||||
DHCP_OPTION_LOG_SERVER = 7,
|
||||
DHCP_OPTION_COOKIE_SERVER = 8,
|
||||
DHCP_OPTION_LPR_SERVER = 9,
|
||||
DHCP_OPTION_IMPRESS_SERVER = 10,
|
||||
DHCP_OPTION_RESOURCE_LOCATION_SERVER = 11,
|
||||
DHCP_OPTION_HOST_NAME = 12,
|
||||
DHCP_OPTION_BOOT_FILE_SIZE = 13,
|
||||
DHCP_OPTION_MERIT_DUMP_FILE = 14,
|
||||
DHCP_OPTION_DOMAIN_NAME = 15,
|
||||
DHCP_OPTION_SWAP_SERVER = 16,
|
||||
DHCP_OPTION_ROOT_PATH = 17,
|
||||
DHCP_OPTION_EXTENSION_PATH = 18,
|
||||
|
||||
DHCP_OPTION_IP_FORWARDING = 19,
|
||||
DHCP_OPTION_NON_LOCAL_SOURCE_ROUTING = 20,
|
||||
DHCP_OPTION_POLICY_FILTER = 21,
|
||||
DHCP_OPTION_MAX_DATAGRAM_REASSEMBLY_SIZE = 22,
|
||||
DHCP_OPTION_DEFAULT_IP_TTL = 23,
|
||||
DHCP_OPTION_PATH_MTU_AGING_TIMEOUT = 24,
|
||||
DHCP_OPTION_PATH_MTU_PLATEAU_TABLE = 25,
|
||||
DHCP_OPTION_IP_FORWARDING = 19,
|
||||
DHCP_OPTION_NON_LOCAL_SOURCE_ROUTING = 20,
|
||||
DHCP_OPTION_POLICY_FILTER = 21,
|
||||
DHCP_OPTION_MAX_DATAGRAM_REASSEMBLY_SIZE = 22,
|
||||
DHCP_OPTION_DEFAULT_IP_TTL = 23,
|
||||
DHCP_OPTION_PATH_MTU_AGING_TIMEOUT = 24,
|
||||
DHCP_OPTION_PATH_MTU_PLATEAU_TABLE = 25,
|
||||
|
||||
DHCP_OPTION_INTERFACE_MTU = 26,
|
||||
DHCP_OPTION_ALL_SUBNETS_ARE_LOCAL = 27,
|
||||
DHCP_OPTION_BROADCAST_ADDRESS = 28,
|
||||
DHCP_OPTION_PERFORM_MASK_DISCOVERY = 29,
|
||||
DHCP_OPTION_MASK_SUPPLIER = 30,
|
||||
DHCP_OPTION_ROUTER_DISCOVERY = 31,
|
||||
DHCP_OPTION_ROUTER_SOLICITATION_ADDRESS = 32,
|
||||
DHCP_OPTION_STATIC_ROUTE = 33,
|
||||
DHCP_OPTION_INTERFACE_MTU = 26,
|
||||
DHCP_OPTION_ALL_SUBNETS_ARE_LOCAL = 27,
|
||||
DHCP_OPTION_BROADCAST_ADDRESS = 28,
|
||||
DHCP_OPTION_PERFORM_MASK_DISCOVERY = 29,
|
||||
DHCP_OPTION_MASK_SUPPLIER = 30,
|
||||
DHCP_OPTION_ROUTER_DISCOVERY = 31,
|
||||
DHCP_OPTION_ROUTER_SOLICITATION_ADDRESS = 32,
|
||||
DHCP_OPTION_STATIC_ROUTE = 33,
|
||||
|
||||
DHCP_OPTION_TRAILER_ENCAPSULATION = 34,
|
||||
DHCP_OPTION_ARP_CACHE_TIMEOUT = 35,
|
||||
DHCP_OPTION_ETHERNET_ENCAPSULATION = 36,
|
||||
DHCP_OPTION_TRAILER_ENCAPSULATION = 34,
|
||||
DHCP_OPTION_ARP_CACHE_TIMEOUT = 35,
|
||||
DHCP_OPTION_ETHERNET_ENCAPSULATION = 36,
|
||||
|
||||
DHCP_OPTION_DEFAULT_TCP_TTL = 37,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_INTERVAL = 38,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_GARBAGE = 39,
|
||||
DHCP_OPTION_DEFAULT_TCP_TTL = 37,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_INTERVAL = 38,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_GARBAGE = 39,
|
||||
|
||||
DHCP_OPTION_NIS_DOMAIN = 40,
|
||||
DHCP_OPTION_NIS_SERVERS = 41,
|
||||
DHCP_OPTION_NTP_SERVERS = 42,
|
||||
DHCP_OPTION_VENDOR_SPECIFIC = 43,
|
||||
DHCP_OPTION_NETBIOS_NAME_SERVERS = 44,
|
||||
DHCP_OPTION_NETBIOS_DD_SERVER = 45,
|
||||
DHCP_OPTION_NETBIOS_NODE_TYPE = 46,
|
||||
DHCP_OPTION_NETBIOS_SCOPE = 47,
|
||||
DHCP_OPTION_X_FONT_SERVERS = 48,
|
||||
DHCP_OPTION_X_DISPLAY_MANAGER = 49,
|
||||
DHCP_OPTION_NIS_DOMAIN = 40,
|
||||
DHCP_OPTION_NIS_SERVERS = 41,
|
||||
DHCP_OPTION_NTP_SERVERS = 42,
|
||||
DHCP_OPTION_VENDOR_SPECIFIC = 43,
|
||||
DHCP_OPTION_NETBIOS_NAME_SERVERS = 44,
|
||||
DHCP_OPTION_NETBIOS_DD_SERVER = 45,
|
||||
DHCP_OPTION_NETBIOS_NODE_TYPE = 46,
|
||||
DHCP_OPTION_NETBIOS_SCOPE = 47,
|
||||
DHCP_OPTION_X_FONT_SERVERS = 48,
|
||||
DHCP_OPTION_X_DISPLAY_MANAGER = 49,
|
||||
|
||||
DHCP_OPTION_REQUESTED_IP = 50,
|
||||
DHCP_OPTION_IP_LEASE_TIME = 51,
|
||||
DHCP_OPTION_OPTION_OVERLOAD = 52,
|
||||
DHCP_OPTION_MESSAGE_TYPE = 53,
|
||||
DHCP_OPTION_SERVER_IDENTIFIER = 54,
|
||||
DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
|
||||
DHCP_OPTION_MESSAGE = 56,
|
||||
DHCP_OPTION_MAX_MESSAGE_SIZE = 57,
|
||||
DHCP_OPTION_T1_TIMEOUT = 58,
|
||||
DHCP_OPTION_T2_TIMEOUT = 59,
|
||||
DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
|
||||
DHCP_OPTION_CLIENT_IDENTIFIER = 61,
|
||||
DHCP_OPTION_REQUESTED_IP = 50,
|
||||
DHCP_OPTION_IP_LEASE_TIME = 51,
|
||||
DHCP_OPTION_OPTION_OVERLOAD = 52,
|
||||
DHCP_OPTION_MESSAGE_TYPE = 53,
|
||||
DHCP_OPTION_SERVER_IDENTIFIER = 54,
|
||||
DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
|
||||
DHCP_OPTION_MESSAGE = 56,
|
||||
DHCP_OPTION_MAX_MESSAGE_SIZE = 57,
|
||||
DHCP_OPTION_T1_TIMEOUT = 58,
|
||||
DHCP_OPTION_T2_TIMEOUT = 59,
|
||||
DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
|
||||
DHCP_OPTION_CLIENT_IDENTIFIER = 61,
|
||||
|
||||
DHCP_OPTION_NETWORK_TIME_SERVER = 62,
|
||||
DHCP_OPTION_NETWORK_TIME_SERVER = 62,
|
||||
|
||||
DHCP_OPTION_END = 255
|
||||
};
|
||||
DHCP_OPTION_END = 255
|
||||
};
|
||||
|
||||
enum DHCPMessageType
|
||||
{
|
||||
DHCP_MESSAGE_TYPE_DISCOVER = 1,
|
||||
DHCP_MESSAGE_TYPE_OFFER = 2,
|
||||
DHCP_MESSAGE_TYPE_REQUEST = 3,
|
||||
DHCP_MESSAGE_TYPE_DECLINE = 4,
|
||||
DHCP_MESSAGE_TYPE_ACK = 5,
|
||||
DHCP_MESSAGE_TYPE_NAK = 6,
|
||||
DHCP_MESSAGE_TYPE_RELEASE = 7,
|
||||
DHCP_MESSAGE_TYPE_INFORM = 8,
|
||||
DHCP_MESSAGE_TYPE_FORCERENEW = 9,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERY = 10,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNASSIGNED = 11,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNKNOWN = 12,
|
||||
DHCP_MESSAGE_TYPE_LEASEACTIVE = 13,
|
||||
DHCP_MESSAGE_TYPE_BULKLEASEQUERY = 14,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYDONE = 15,
|
||||
DHCP_MESSAGE_TYPE_ACTIVELEASEQUERY = 16,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYSTATUS = 17,
|
||||
DHCP_MESSAGE_TYPE_DHCPTLS = 18
|
||||
};
|
||||
enum DHCPMessageType
|
||||
{
|
||||
DHCP_MESSAGE_TYPE_DISCOVER = 1,
|
||||
DHCP_MESSAGE_TYPE_OFFER = 2,
|
||||
DHCP_MESSAGE_TYPE_REQUEST = 3,
|
||||
DHCP_MESSAGE_TYPE_DECLINE = 4,
|
||||
DHCP_MESSAGE_TYPE_ACK = 5,
|
||||
DHCP_MESSAGE_TYPE_NAK = 6,
|
||||
DHCP_MESSAGE_TYPE_RELEASE = 7,
|
||||
DHCP_MESSAGE_TYPE_INFORM = 8,
|
||||
DHCP_MESSAGE_TYPE_FORCERENEW = 9,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERY = 10,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNASSIGNED = 11,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNKNOWN = 12,
|
||||
DHCP_MESSAGE_TYPE_LEASEACTIVE = 13,
|
||||
DHCP_MESSAGE_TYPE_BULKLEASEQUERY = 14,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYDONE = 15,
|
||||
DHCP_MESSAGE_TYPE_ACTIVELEASEQUERY = 16,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYSTATUS = 17,
|
||||
DHCP_MESSAGE_TYPE_DHCPTLS = 18
|
||||
};
|
||||
|
||||
#define DHCP_TRANSACTION_ID 0xFE2EC005
|
||||
|
||||
class DHCP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
bool Received = false;
|
||||
class DHCP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
bool Received = false;
|
||||
|
||||
void CreatePacket(DHCPHeader *Packet, uint8_t MessageType, uint32_t RequestIP);
|
||||
void *GetOption(DHCPHeader *Packet, uint8_t Type);
|
||||
void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
void CreatePacket(DHCPHeader *Packet, uint8_t MessageType, uint32_t RequestIP);
|
||||
void *GetOption(DHCPHeader *Packet, uint8_t Type);
|
||||
void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
/** @brief IP address (Little-endian) */
|
||||
InternetProtocol IP = {};
|
||||
/** @brief Gateway address (Little-endian) */
|
||||
InternetProtocol Gateway = {};
|
||||
/** @brief Subnet mask (Little-endian) */
|
||||
InternetProtocol SubNetworkMask = {};
|
||||
/** @brief DNS server address (Little-endian) */
|
||||
InternetProtocol DomainNameSystem = {};
|
||||
public:
|
||||
/** @brief IP address (Little-endian) */
|
||||
InternetProtocol IP = {};
|
||||
/** @brief Gateway address (Little-endian) */
|
||||
InternetProtocol Gateway = {};
|
||||
/** @brief Subnet mask (Little-endian) */
|
||||
InternetProtocol SubNetworkMask = {};
|
||||
/** @brief DNS server address (Little-endian) */
|
||||
InternetProtocol DomainNameSystem = {};
|
||||
|
||||
DHCP(NetworkUDP::Socket *Socket, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~DHCP();
|
||||
void Request();
|
||||
void Request(InternetProtocol IP);
|
||||
};
|
||||
DHCP(NetworkUDP::Socket *Socket, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~DHCP();
|
||||
void Request();
|
||||
void Request(InternetProtocol IP);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DHCP_H__
|
||||
|
@ -23,15 +23,15 @@
|
||||
|
||||
namespace NetworkDNS
|
||||
{
|
||||
class DNS : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
class DNS : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
|
||||
public:
|
||||
DNS(NetworkUDP::Socket *Socket);
|
||||
~DNS();
|
||||
};
|
||||
public:
|
||||
DNS(NetworkUDP::Socket *Socket);
|
||||
~DNS();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DNS_H__
|
||||
|
@ -23,86 +23,86 @@
|
||||
|
||||
namespace NetworkEthernet
|
||||
{
|
||||
enum FrameType
|
||||
{
|
||||
TYPE_IPV4 = 0x0800,
|
||||
TYPE_ARP = 0x0806,
|
||||
TYPE_RARP = 0x8035,
|
||||
TYPE_IPV6 = 0x86DD
|
||||
};
|
||||
enum FrameType
|
||||
{
|
||||
TYPE_IPV4 = 0x0800,
|
||||
TYPE_ARP = 0x0806,
|
||||
TYPE_RARP = 0x8035,
|
||||
TYPE_IPV6 = 0x86DD
|
||||
};
|
||||
|
||||
struct EthernetHeader
|
||||
{
|
||||
uint48_t DestinationMAC : 48;
|
||||
uint48_t SourceMAC : 48;
|
||||
uint16_t Type;
|
||||
} __packed;
|
||||
struct EthernetHeader
|
||||
{
|
||||
uint48_t DestinationMAC : 48;
|
||||
uint48_t SourceMAC : 48;
|
||||
uint16_t Type;
|
||||
} __packed;
|
||||
|
||||
struct EthernetPacket
|
||||
{
|
||||
EthernetHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct EthernetPacket
|
||||
{
|
||||
EthernetHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class EthernetEvents
|
||||
{
|
||||
private:
|
||||
FrameType FType;
|
||||
class EthernetEvents
|
||||
{
|
||||
private:
|
||||
FrameType FType;
|
||||
|
||||
protected:
|
||||
EthernetEvents(FrameType Type);
|
||||
~EthernetEvents();
|
||||
protected:
|
||||
EthernetEvents(FrameType Type);
|
||||
~EthernetEvents();
|
||||
|
||||
public:
|
||||
FrameType GetFrameType() { return FType; }
|
||||
virtual void OnEthernetPacketSent(EthernetPacket *Packet)
|
||||
{
|
||||
UNUSED(Packet);
|
||||
netdbg("Event not handled. [%p]", Packet);
|
||||
}
|
||||
public:
|
||||
FrameType GetFrameType() { return FType; }
|
||||
virtual void OnEthernetPacketSent(EthernetPacket *Packet)
|
||||
{
|
||||
UNUSED(Packet);
|
||||
netdbg("Event not handled. [%p]", Packet);
|
||||
}
|
||||
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event not handled. [%p, %d]", Data, Length);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event not handled. [%p, %d]", Data, Length);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Ethernet : public NetworkInterfaceManager::Events
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
void Receive(uint8_t *Data, size_t Length);
|
||||
void OnInterfaceReceived(NetworkInterfaceManager::DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
class Ethernet : public NetworkInterfaceManager::Events
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
void Receive(uint8_t *Data, size_t Length);
|
||||
void OnInterfaceReceived(NetworkInterfaceManager::DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
/** @brief Get driver interface
|
||||
* @return Module interface
|
||||
*/
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface()
|
||||
{
|
||||
netdbg("Interface: %#lx (MAC: %s; IPv4: %s; IPv6: %s)", this->Interface,
|
||||
this->Interface->MAC.ToString(),
|
||||
this->Interface->IP.v4.ToStringLittleEndian(),
|
||||
this->Interface->IP.v6.ToStringLittleEndian());
|
||||
return this->Interface;
|
||||
}
|
||||
public:
|
||||
/** @brief Get driver interface
|
||||
* @return Driver interface
|
||||
*/
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface()
|
||||
{
|
||||
netdbg("Interface: %#lx (MAC: %s; IPv4: %s; IPv6: %s)", this->Interface,
|
||||
this->Interface->MAC.ToString(),
|
||||
this->Interface->IP.v4.ToStringLittleEndian(),
|
||||
this->Interface->IP.v6.ToStringLittleEndian());
|
||||
return this->Interface;
|
||||
}
|
||||
|
||||
Ethernet(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~Ethernet();
|
||||
Ethernet(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~Ethernet();
|
||||
|
||||
/**
|
||||
* @brief Send an Ethernet packet.
|
||||
*
|
||||
* @param MAC The MAC address of the destination. (Big-endian)
|
||||
* @param Type The type of the packet.
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
*/
|
||||
void Send(MediaAccessControl MAC, FrameType Type, uint8_t *Data, size_t Length);
|
||||
};
|
||||
/**
|
||||
* @brief Send an Ethernet packet.
|
||||
*
|
||||
* @param MAC The MAC address of the destination. (Big-endian)
|
||||
* @param Type The type of the packet.
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
*/
|
||||
void Send(MediaAccessControl MAC, FrameType Type, uint8_t *Data, size_t Length);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NETWORK_ETHERNET_H__
|
||||
|
@ -23,49 +23,49 @@
|
||||
|
||||
namespace NetworkICMPv4
|
||||
{
|
||||
enum ICMPv4Type
|
||||
{
|
||||
TYPE_ECHO_REPLY = 0,
|
||||
TYPE_DESTINATION_UNREACHABLE = 3,
|
||||
TYPE_SOURCE_QUENCH = 4,
|
||||
TYPE_REDIRECT = 5,
|
||||
TYPE_ECHO = 8,
|
||||
TYPE_ROUTER_ADVERTISEMENT = 9,
|
||||
TYPE_ROUTER_SELECTION = 10,
|
||||
TYPE_TIME_EXCEEDED = 11,
|
||||
TYPE_PARAMETER_PROBLEM = 12,
|
||||
TYPE_TIMESTAMP = 13,
|
||||
TYPE_TIMESTAMP_REPLY = 14
|
||||
};
|
||||
enum ICMPv4Type
|
||||
{
|
||||
TYPE_ECHO_REPLY = 0,
|
||||
TYPE_DESTINATION_UNREACHABLE = 3,
|
||||
TYPE_SOURCE_QUENCH = 4,
|
||||
TYPE_REDIRECT = 5,
|
||||
TYPE_ECHO = 8,
|
||||
TYPE_ROUTER_ADVERTISEMENT = 9,
|
||||
TYPE_ROUTER_SELECTION = 10,
|
||||
TYPE_TIME_EXCEEDED = 11,
|
||||
TYPE_PARAMETER_PROBLEM = 12,
|
||||
TYPE_TIMESTAMP = 13,
|
||||
TYPE_TIMESTAMP_REPLY = 14
|
||||
};
|
||||
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class ICMPv4
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
class ICMPv4
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
|
||||
ICMPv4(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv4();
|
||||
void Send(/* ???? */);
|
||||
void Receive(ICMPPacket *Packet);
|
||||
};
|
||||
ICMPv4(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv4();
|
||||
void Send(/* ???? */);
|
||||
void Receive(ICMPPacket *Packet);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ICMPv4_H__
|
||||
|
@ -23,34 +23,34 @@
|
||||
|
||||
namespace NetworkICMPv6
|
||||
{
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class ICMPv6
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
class ICMPv6
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
|
||||
ICMPv6(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv6();
|
||||
void Send(uint8_t *Data, size_t Length);
|
||||
void Receive(uint8_t *Data);
|
||||
};
|
||||
ICMPv6(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv6();
|
||||
void Send(uint8_t *Data, size_t Length);
|
||||
void Receive(uint8_t *Data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ICMPv6_H__
|
||||
|
@ -25,113 +25,113 @@
|
||||
|
||||
namespace NetworkIPv4
|
||||
{
|
||||
struct IPv4Header
|
||||
{
|
||||
uint8_t IHL : 4;
|
||||
uint8_t Version : 4;
|
||||
uint8_t TypeOfService;
|
||||
uint16_t TotalLength;
|
||||
uint16_t Identification;
|
||||
uint8_t Flags;
|
||||
uint8_t FragmentOffset;
|
||||
uint8_t TimeToLive;
|
||||
uint8_t Protocol;
|
||||
uint16_t HeaderChecksum;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
struct IPv4Header
|
||||
{
|
||||
uint8_t IHL : 4;
|
||||
uint8_t Version : 4;
|
||||
uint8_t TypeOfService;
|
||||
uint16_t TotalLength;
|
||||
uint16_t Identification;
|
||||
uint8_t Flags;
|
||||
uint8_t FragmentOffset;
|
||||
uint8_t TimeToLive;
|
||||
uint8_t Protocol;
|
||||
uint16_t HeaderChecksum;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
|
||||
/* On wikipedia page we have this: https://en.wikipedia.org/wiki/File:IPv4_Packet-en.svg
|
||||
but only the code above works... */
|
||||
// uint8_t Version : 4;
|
||||
// uint8_t IHL : 4;
|
||||
// uint16_t TypeOfService : 8;
|
||||
// uint16_t TotalLength : 12;
|
||||
// uint16_t Identification : 16;
|
||||
// uint16_t Flags : 3;
|
||||
// uint16_t FragmentOffset : 13;
|
||||
// uint8_t TimeToLive : 8;
|
||||
// uint8_t Protocol : 8;
|
||||
// uint16_t HeaderChecksum;
|
||||
// uint32_t SourceIP;
|
||||
// uint32_t DestinationIP;
|
||||
};
|
||||
/* On wikipedia page we have this: https://en.wikipedia.org/wiki/File:IPv4_Packet-en.svg
|
||||
but only the code above works... */
|
||||
// uint8_t Version : 4;
|
||||
// uint8_t IHL : 4;
|
||||
// uint16_t TypeOfService : 8;
|
||||
// uint16_t TotalLength : 12;
|
||||
// uint16_t Identification : 16;
|
||||
// uint16_t Flags : 3;
|
||||
// uint16_t FragmentOffset : 13;
|
||||
// uint8_t TimeToLive : 8;
|
||||
// uint8_t Protocol : 8;
|
||||
// uint16_t HeaderChecksum;
|
||||
// uint32_t SourceIP;
|
||||
// uint32_t DestinationIP;
|
||||
};
|
||||
|
||||
struct IPv4Packet
|
||||
{
|
||||
IPv4Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct IPv4Packet
|
||||
{
|
||||
IPv4Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
enum IPv4Protocols
|
||||
{
|
||||
PROTOCOL_ICMP = 1,
|
||||
PROTOCOL_IGMP = 2,
|
||||
PROTOCOL_TCP = 6,
|
||||
PROTOCOL_UDP = 17,
|
||||
PROTOCOL_IPV6 = 41,
|
||||
PROTOCOL_ROUTING = 43,
|
||||
PROTOCOL_FRAGMENT = 44,
|
||||
PROTOCOL_ESP = 50,
|
||||
PROTOCOL_AH = 51,
|
||||
PROTOCOL_ICMPV6 = 58,
|
||||
PROTOCOL_NONE = 59,
|
||||
PROTOCOL_DSTOPTS = 60,
|
||||
PROTOCOL_ND = 77,
|
||||
PROTOCOL_ICLFXBM = 78,
|
||||
PROTOCOL_PIM = 103,
|
||||
PROTOCOL_COMP = 108,
|
||||
PROTOCOL_SCTP = 132,
|
||||
PROTOCOL_UDPLITE = 136,
|
||||
PROTOCOL_RAW = 255
|
||||
};
|
||||
enum IPv4Protocols
|
||||
{
|
||||
PROTOCOL_ICMP = 1,
|
||||
PROTOCOL_IGMP = 2,
|
||||
PROTOCOL_TCP = 6,
|
||||
PROTOCOL_UDP = 17,
|
||||
PROTOCOL_IPV6 = 41,
|
||||
PROTOCOL_ROUTING = 43,
|
||||
PROTOCOL_FRAGMENT = 44,
|
||||
PROTOCOL_ESP = 50,
|
||||
PROTOCOL_AH = 51,
|
||||
PROTOCOL_ICMPV6 = 58,
|
||||
PROTOCOL_NONE = 59,
|
||||
PROTOCOL_DSTOPTS = 60,
|
||||
PROTOCOL_ND = 77,
|
||||
PROTOCOL_ICLFXBM = 78,
|
||||
PROTOCOL_PIM = 103,
|
||||
PROTOCOL_COMP = 108,
|
||||
PROTOCOL_SCTP = 132,
|
||||
PROTOCOL_UDPLITE = 136,
|
||||
PROTOCOL_RAW = 255
|
||||
};
|
||||
|
||||
class IPv4 : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkARP::ARP *ARP;
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
class IPv4 : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkARP::ARP *ARP;
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
InternetProtocol GatewayIP;
|
||||
InternetProtocol SubNetworkMaskIP;
|
||||
IPv4(NetworkARP::ARP *ARP, NetworkEthernet::Ethernet *Ethernet);
|
||||
~IPv4();
|
||||
public:
|
||||
InternetProtocol GatewayIP;
|
||||
InternetProtocol SubNetworkMaskIP;
|
||||
IPv4(NetworkARP::ARP *ARP, NetworkEthernet::Ethernet *Ethernet);
|
||||
~IPv4();
|
||||
|
||||
/**
|
||||
* @brief Send an IPv4 packet.
|
||||
*
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
* @param Protocol The protocol of the packet.
|
||||
* @param DestinationIP The IP address of the destination. (Big-endian)
|
||||
*/
|
||||
void Send(uint8_t *Data, size_t Length, uint8_t Protocol, InternetProtocol DestinationIP);
|
||||
};
|
||||
/**
|
||||
* @brief Send an IPv4 packet.
|
||||
*
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
* @param Protocol The protocol of the packet.
|
||||
* @param DestinationIP The IP address of the destination. (Big-endian)
|
||||
*/
|
||||
void Send(uint8_t *Data, size_t Length, uint8_t Protocol, InternetProtocol DestinationIP);
|
||||
};
|
||||
|
||||
class IPv4Events
|
||||
{
|
||||
private:
|
||||
uint8_t Protocol;
|
||||
class IPv4Events
|
||||
{
|
||||
private:
|
||||
uint8_t Protocol;
|
||||
|
||||
protected:
|
||||
IPv4Events(IPv4Protocols Protocol);
|
||||
~IPv4Events();
|
||||
protected:
|
||||
IPv4Events(IPv4Protocols Protocol);
|
||||
~IPv4Events();
|
||||
|
||||
public:
|
||||
uint8_t GetProtocol() { return Protocol; }
|
||||
public:
|
||||
uint8_t GetProtocol() { return Protocol; }
|
||||
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(SourceIP);
|
||||
UNUSED(DestinationIP);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(SourceIP);
|
||||
UNUSED(DestinationIP);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_IPv4_H__
|
||||
|
@ -22,23 +22,23 @@
|
||||
|
||||
namespace NetworkIPv6
|
||||
{
|
||||
struct IPv6Header
|
||||
{
|
||||
uint32_t Version;
|
||||
uint8_t TrafficClass;
|
||||
uint16_t FlowLabel;
|
||||
uint16_t PayloadLength;
|
||||
uint8_t NextHeader;
|
||||
uint8_t HopLimit;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
};
|
||||
struct IPv6Header
|
||||
{
|
||||
uint32_t Version;
|
||||
uint8_t TrafficClass;
|
||||
uint16_t FlowLabel;
|
||||
uint16_t PayloadLength;
|
||||
uint8_t NextHeader;
|
||||
uint8_t HopLimit;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
};
|
||||
|
||||
struct IPv6Packet
|
||||
{
|
||||
IPv6Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct IPv6Packet
|
||||
{
|
||||
IPv6Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_IPv6_H__
|
||||
|
@ -27,90 +27,90 @@
|
||||
|
||||
namespace NetworkInterfaceManager
|
||||
{
|
||||
struct DeviceInterface
|
||||
{
|
||||
/** @brief Device interface name */
|
||||
char Name[128];
|
||||
struct DeviceInterface
|
||||
{
|
||||
/** @brief Device interface name */
|
||||
char Name[128];
|
||||
|
||||
/** @brief Device interface index */
|
||||
uint64_t ID;
|
||||
/** @brief Device interface index */
|
||||
uint64_t ID;
|
||||
|
||||
/** @brief Device interface MAC address (Big-endian) */
|
||||
MediaAccessControl MAC;
|
||||
/** @brief Device interface MAC address (Big-endian) */
|
||||
MediaAccessControl MAC;
|
||||
|
||||
/** @brief Device interface IP address (Big-endian) */
|
||||
InternetProtocol IP;
|
||||
/** @brief Device interface IP address (Big-endian) */
|
||||
InternetProtocol IP;
|
||||
|
||||
/** @brief Reserved */
|
||||
unsigned long DriverID;
|
||||
};
|
||||
/** @brief Reserved */
|
||||
unsigned long DriverID;
|
||||
};
|
||||
|
||||
class Events
|
||||
{
|
||||
protected:
|
||||
Events(DeviceInterface *Interface);
|
||||
~Events();
|
||||
class Events
|
||||
{
|
||||
protected:
|
||||
Events(DeviceInterface *Interface);
|
||||
~Events();
|
||||
|
||||
public:
|
||||
virtual void OnInterfaceAdded(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
public:
|
||||
virtual void OnInterfaceAdded(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceRemoved(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
virtual void OnInterfaceRemoved(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceChanged(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
virtual void OnInterfaceChanged(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceReceived(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
virtual void OnInterfaceReceived(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceSent(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
};
|
||||
virtual void OnInterfaceSent(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
};
|
||||
|
||||
class NetworkInterface
|
||||
{
|
||||
private:
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
int CardIDs = 0;
|
||||
std::vector<DeviceInterface *> Interfaces;
|
||||
class NetworkInterface
|
||||
{
|
||||
private:
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
int CardIDs = 0;
|
||||
std::vector<DeviceInterface *> Interfaces;
|
||||
|
||||
Tasking::TCB *NetSvcThread;
|
||||
void StopNetworkStack();
|
||||
void FetchNetworkCards(unsigned long modUniqueID);
|
||||
Tasking::TCB *NetSvcThread;
|
||||
void StopNetworkStack();
|
||||
void FetchNetworkCards(unsigned long modUniqueID);
|
||||
|
||||
public:
|
||||
NetworkInterface();
|
||||
~NetworkInterface();
|
||||
public:
|
||||
NetworkInterface();
|
||||
~NetworkInterface();
|
||||
|
||||
void StartService();
|
||||
void StartService();
|
||||
|
||||
void Send(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
void Receive(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
void Send(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
void Receive(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
|
||||
void DrvSend(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void DrvReceive(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void StartNetworkStack();
|
||||
};
|
||||
void DrvSend(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void DrvReceive(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void StartNetworkStack();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NETWORK_CONTROLLER_H__
|
||||
|
@ -32,199 +32,199 @@ void DbgDumpData(const char *Description, void *Address, unsigned long Length);
|
||||
static inline void DbgNetwork() { return; }
|
||||
static inline void DbgDumpData(const char *Description, void *Address, unsigned long Length)
|
||||
{
|
||||
UNUSED(Description);
|
||||
UNUSED(Address);
|
||||
UNUSED(Length);
|
||||
return;
|
||||
UNUSED(Description);
|
||||
UNUSED(Address);
|
||||
UNUSED(Length);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum Endianness
|
||||
{
|
||||
LITTLE_ENDIAN,
|
||||
BIG_ENDIAN
|
||||
LITTLE_ENDIAN,
|
||||
BIG_ENDIAN
|
||||
};
|
||||
|
||||
struct MediaAccessControl
|
||||
{
|
||||
uint8_t Address[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
uint8_t Address[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
|
||||
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 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 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 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 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 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
char *ToString()
|
||||
{
|
||||
static char Buffer[18];
|
||||
sprintf(Buffer, "%02X:%02X:%02X:%02X:%02X:%02X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5]);
|
||||
return Buffer;
|
||||
}
|
||||
char *ToString()
|
||||
{
|
||||
static char Buffer[18];
|
||||
sprintf(Buffer, "%02X:%02X:%02X:%02X:%02X:%02X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5]);
|
||||
return Buffer;
|
||||
}
|
||||
};
|
||||
|
||||
/* There's a confusion between LSB and MSB. Not sure if "ToStringLittleEndian" and "ToStringBigEndian" are implemented correctly.
|
||||
Because x86 is a LSB architecture, I'm assuming that the "ToStringLittleEndian" is correct? */
|
||||
struct InternetProtocol
|
||||
{
|
||||
struct Version4
|
||||
{
|
||||
uint8_t Address[4] = {255, 255, 255, 255};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
struct Version4
|
||||
{
|
||||
uint8_t Address[4] = {255, 255, 255, 255};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
|
||||
inline bool operator==(const InternetProtocol::Version4 &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 InternetProtocol::Version4 &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
|
||||
{
|
||||
InternetProtocol::Version4 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);
|
||||
inline bool operator==(const uint32_t &lhs) const
|
||||
{
|
||||
InternetProtocol::Version4 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];
|
||||
}
|
||||
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 InternetProtocol::Version4 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint32_t &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const InternetProtocol::Version4 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint32_t &lhs) const { return !(*this == lhs); }
|
||||
|
||||
inline uint32_t ToHex()
|
||||
{
|
||||
return ((uint32_t)this->Address[0] << 24) |
|
||||
((uint32_t)this->Address[1] << 16) |
|
||||
((uint32_t)this->Address[2] << 8) |
|
||||
((uint32_t)this->Address[3]);
|
||||
}
|
||||
inline uint32_t ToHex()
|
||||
{
|
||||
return ((uint32_t)this->Address[0] << 24) |
|
||||
((uint32_t)this->Address[1] << 16) |
|
||||
((uint32_t)this->Address[2] << 8) |
|
||||
((uint32_t)this->Address[3]);
|
||||
}
|
||||
|
||||
inline InternetProtocol::Version4 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;
|
||||
}
|
||||
inline InternetProtocol::Version4 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;
|
||||
}
|
||||
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[0], this->Address[1], this->Address[2], this->Address[3]);
|
||||
return Buffer;
|
||||
}
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[0], this->Address[1], this->Address[2], this->Address[3]);
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v4;
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v4;
|
||||
|
||||
struct Version6
|
||||
{
|
||||
uint16_t Address[8] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
struct Version6
|
||||
{
|
||||
uint16_t Address[8] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
|
||||
inline bool operator==(const InternetProtocol::Version6 &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] &&
|
||||
lhs.Address[6] == this->Address[6] &&
|
||||
lhs.Address[7] == this->Address[7];
|
||||
}
|
||||
inline bool operator==(const InternetProtocol::Version6 &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] &&
|
||||
lhs.Address[6] == this->Address[6] &&
|
||||
lhs.Address[7] == this->Address[7];
|
||||
}
|
||||
|
||||
inline bool operator!=(const InternetProtocol::Version6 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const InternetProtocol::Version6 &lhs) const { return !(*this == lhs); }
|
||||
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5], this->Address[6], this->Address[7]);
|
||||
return Buffer;
|
||||
}
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5], this->Address[6], this->Address[7]);
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[7], this->Address[6], this->Address[5], this->Address[4], this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v6;
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[7], this->Address[6], this->Address[5], this->Address[4], this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v6;
|
||||
};
|
||||
|
||||
uint16_t CalculateChecksum(uint16_t *Data, size_t Length);
|
||||
|
@ -23,144 +23,144 @@
|
||||
|
||||
namespace NetworkNTP
|
||||
{
|
||||
struct NTPHeader
|
||||
{
|
||||
/** @brief Leap indicator
|
||||
* 00 - no warning
|
||||
* 01 - last minute has 61 seconds
|
||||
* 10 - last minute has 59 seconds
|
||||
* 11 - alarm condition (clock not synchronized)
|
||||
*/
|
||||
uint8_t LeapIndicator : 2;
|
||||
/** @brief Version number of the protocol
|
||||
* 3 - IPv4 only
|
||||
* 4 - IPv4, IPv6 and OSI
|
||||
* 5 - IPv4, IPv6 and OSI
|
||||
* 6 - IPv4, IPv6 and OSI
|
||||
* 7 - IPv4, IPv6 and OSI
|
||||
*/
|
||||
uint8_t VersionNumber : 3;
|
||||
/** @brief Mode
|
||||
* 0 - reserved
|
||||
* 1 - symmetric active
|
||||
* 2 - symmetric passive
|
||||
* 3 - client
|
||||
* 4 - server
|
||||
* 5 - broadcast
|
||||
* 6 - reserved for NTP control message
|
||||
* 7 - reserved for private use
|
||||
*/
|
||||
uint8_t Mode : 3;
|
||||
/** @brief Stratum
|
||||
* 0 - unspecified or unavailable
|
||||
* 1 - primary reference (e.g. radio clock)
|
||||
* 2-15 - secondary reference (via NTP or SNTP)
|
||||
* 16 - unsynchronized
|
||||
* 17-255 - reserved
|
||||
*/
|
||||
uint8_t Stratum;
|
||||
/** @brief Polling interval
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
* 8 - 256 seconds
|
||||
* 9 - 512 seconds
|
||||
* 10 - 1024 seconds
|
||||
* 11 - 2048 seconds
|
||||
* 12 - 4096 seconds
|
||||
* 13 - 8192 seconds
|
||||
* 14 - 16384 seconds
|
||||
* 15 - 32768 seconds
|
||||
*/
|
||||
uint8_t Poll;
|
||||
/** @brief Precision
|
||||
* -6 - 0.015625 seconds
|
||||
* -5 - 0.03125 seconds
|
||||
* -4 - 0.0625 seconds
|
||||
* -3 - 0.125 seconds
|
||||
* -2 - 0.25 seconds
|
||||
* -1 - 0.5 seconds
|
||||
* 0 - 1 second
|
||||
* 1 - 2 seconds
|
||||
* 2 - 4 seconds
|
||||
* 3 - 8 seconds
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
*/
|
||||
uint8_t Precision;
|
||||
/** @brief Root delay
|
||||
* Total round trip delay to the primary reference source
|
||||
*/
|
||||
uint32_t RootDelay;
|
||||
/** @brief Root dispersion
|
||||
* Nominal error relative to the primary reference source
|
||||
*/
|
||||
uint32_t RootDispersion;
|
||||
/** @brief Reference identifier
|
||||
* 0x00000000 - unspecified
|
||||
* 0x00000001 - radio clock
|
||||
* 0x00000002 - atomic clock
|
||||
* 0x00000003 - GPS receiver
|
||||
* 0x00000004 - local oscillator
|
||||
* 0x00000005 - LORAN-C receiver
|
||||
* 0x00000006 - microprocessor
|
||||
* 0x00000007 - internet
|
||||
* 0x00000008 - FLL
|
||||
* 0x00000009 - other
|
||||
* 0x0000000A - WWV
|
||||
* 0x0000000B - WWVB
|
||||
* 0x0000000C - WWVH
|
||||
* 0x0000000D - NIST dialup
|
||||
* 0x0000000E - telephone
|
||||
* 0x0000000F - reserved
|
||||
*/
|
||||
uint32_t ReferenceIdentifier;
|
||||
/** @brief Reference timestamp
|
||||
* The time at which the clock was last set or corrected
|
||||
*/
|
||||
uint32_t ReferenceTimestamp[2];
|
||||
/** @brief Originate timestamp
|
||||
* The time at which the request departed the client for the server
|
||||
*/
|
||||
uint32_t OriginateTimestamp[2];
|
||||
/** @brief Receive timestamp
|
||||
* The time at which the request arrived at the server
|
||||
*/
|
||||
uint32_t ReceiveTimestamp[2];
|
||||
/** @brief Transmit timestamp
|
||||
* The time at which the reply departed the server for the client
|
||||
*/
|
||||
uint32_t TransmitTimestamp[2];
|
||||
/** @brief Message authentication code
|
||||
* Key identifier
|
||||
* @note Only when the NTP authentication scheme is used
|
||||
*/
|
||||
// uint32_t MessageAuthenticationCode;
|
||||
} __packed;
|
||||
struct NTPHeader
|
||||
{
|
||||
/** @brief Leap indicator
|
||||
* 00 - no warning
|
||||
* 01 - last minute has 61 seconds
|
||||
* 10 - last minute has 59 seconds
|
||||
* 11 - alarm condition (clock not synchronized)
|
||||
*/
|
||||
uint8_t LeapIndicator : 2;
|
||||
/** @brief Version number of the protocol
|
||||
* 3 - IPv4 only
|
||||
* 4 - IPv4, IPv6 and OSI
|
||||
* 5 - IPv4, IPv6 and OSI
|
||||
* 6 - IPv4, IPv6 and OSI
|
||||
* 7 - IPv4, IPv6 and OSI
|
||||
*/
|
||||
uint8_t VersionNumber : 3;
|
||||
/** @brief Mode
|
||||
* 0 - reserved
|
||||
* 1 - symmetric active
|
||||
* 2 - symmetric passive
|
||||
* 3 - client
|
||||
* 4 - server
|
||||
* 5 - broadcast
|
||||
* 6 - reserved for NTP control message
|
||||
* 7 - reserved for private use
|
||||
*/
|
||||
uint8_t Mode : 3;
|
||||
/** @brief Stratum
|
||||
* 0 - unspecified or unavailable
|
||||
* 1 - primary reference (e.g. radio clock)
|
||||
* 2-15 - secondary reference (via NTP or SNTP)
|
||||
* 16 - unsynchronized
|
||||
* 17-255 - reserved
|
||||
*/
|
||||
uint8_t Stratum;
|
||||
/** @brief Polling interval
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
* 8 - 256 seconds
|
||||
* 9 - 512 seconds
|
||||
* 10 - 1024 seconds
|
||||
* 11 - 2048 seconds
|
||||
* 12 - 4096 seconds
|
||||
* 13 - 8192 seconds
|
||||
* 14 - 16384 seconds
|
||||
* 15 - 32768 seconds
|
||||
*/
|
||||
uint8_t Poll;
|
||||
/** @brief Precision
|
||||
* -6 - 0.015625 seconds
|
||||
* -5 - 0.03125 seconds
|
||||
* -4 - 0.0625 seconds
|
||||
* -3 - 0.125 seconds
|
||||
* -2 - 0.25 seconds
|
||||
* -1 - 0.5 seconds
|
||||
* 0 - 1 second
|
||||
* 1 - 2 seconds
|
||||
* 2 - 4 seconds
|
||||
* 3 - 8 seconds
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
*/
|
||||
uint8_t Precision;
|
||||
/** @brief Root delay
|
||||
* Total round trip delay to the primary reference source
|
||||
*/
|
||||
uint32_t RootDelay;
|
||||
/** @brief Root dispersion
|
||||
* Nominal error relative to the primary reference source
|
||||
*/
|
||||
uint32_t RootDispersion;
|
||||
/** @brief Reference identifier
|
||||
* 0x00000000 - unspecified
|
||||
* 0x00000001 - radio clock
|
||||
* 0x00000002 - atomic clock
|
||||
* 0x00000003 - GPS receiver
|
||||
* 0x00000004 - local oscillator
|
||||
* 0x00000005 - LORAN-C receiver
|
||||
* 0x00000006 - microprocessor
|
||||
* 0x00000007 - internet
|
||||
* 0x00000008 - FLL
|
||||
* 0x00000009 - other
|
||||
* 0x0000000A - WWV
|
||||
* 0x0000000B - WWVB
|
||||
* 0x0000000C - WWVH
|
||||
* 0x0000000D - NIST dialup
|
||||
* 0x0000000E - telephone
|
||||
* 0x0000000F - reserved
|
||||
*/
|
||||
uint32_t ReferenceIdentifier;
|
||||
/** @brief Reference timestamp
|
||||
* The time at which the clock was last set or corrected
|
||||
*/
|
||||
uint32_t ReferenceTimestamp[2];
|
||||
/** @brief Originate timestamp
|
||||
* The time at which the request departed the client for the server
|
||||
*/
|
||||
uint32_t OriginateTimestamp[2];
|
||||
/** @brief Receive timestamp
|
||||
* The time at which the request arrived at the server
|
||||
*/
|
||||
uint32_t ReceiveTimestamp[2];
|
||||
/** @brief Transmit timestamp
|
||||
* The time at which the reply departed the server for the client
|
||||
*/
|
||||
uint32_t TransmitTimestamp[2];
|
||||
/** @brief Message authentication code
|
||||
* Key identifier
|
||||
* @note Only when the NTP authentication scheme is used
|
||||
*/
|
||||
// uint32_t MessageAuthenticationCode;
|
||||
} __packed;
|
||||
|
||||
class NTP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
bool TimeReceived = false;
|
||||
NTPHeader NTPPacket;
|
||||
class NTP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
bool TimeReceived = false;
|
||||
NTPHeader NTPPacket;
|
||||
|
||||
virtual void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
virtual void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
NTP(NetworkUDP::Socket *Socket);
|
||||
~NTP();
|
||||
public:
|
||||
NTP(NetworkUDP::Socket *Socket);
|
||||
~NTP();
|
||||
|
||||
/**
|
||||
* @brief Get the time from the NTP server
|
||||
*
|
||||
* @return Unix Timestamp
|
||||
*/
|
||||
int ReadTime();
|
||||
};
|
||||
/**
|
||||
* @brief Get the time from the NTP server
|
||||
*
|
||||
* @return Unix Timestamp
|
||||
*/
|
||||
int ReadTime();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NTP_H__
|
||||
|
@ -25,73 +25,73 @@
|
||||
|
||||
namespace NetworkUDP
|
||||
{
|
||||
struct UDPHeader
|
||||
{
|
||||
uint16_t SourcePort;
|
||||
uint16_t DestinationPort;
|
||||
uint16_t Length;
|
||||
uint16_t Checksum;
|
||||
} __packed;
|
||||
struct UDPHeader
|
||||
{
|
||||
uint16_t SourcePort;
|
||||
uint16_t DestinationPort;
|
||||
uint16_t Length;
|
||||
uint16_t Checksum;
|
||||
} __packed;
|
||||
|
||||
struct UDPPacket
|
||||
{
|
||||
UDPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct UDPPacket
|
||||
{
|
||||
UDPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class Socket;
|
||||
class Socket;
|
||||
|
||||
class UDPEvents
|
||||
{
|
||||
protected:
|
||||
UDPEvents();
|
||||
~UDPEvents();
|
||||
class UDPEvents
|
||||
{
|
||||
protected:
|
||||
UDPEvents();
|
||||
~UDPEvents();
|
||||
|
||||
public:
|
||||
virtual void OnUDPPacketReceived(Socket *Socket, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Socket);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
}
|
||||
};
|
||||
public:
|
||||
virtual void OnUDPPacketReceived(Socket *Socket, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Socket);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
}
|
||||
};
|
||||
|
||||
class UDP : public NetworkIPv4::IPv4Events
|
||||
{
|
||||
private:
|
||||
NetworkIPv4::IPv4 *ipv4;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
class UDP : public NetworkIPv4::IPv4Events
|
||||
{
|
||||
private:
|
||||
NetworkIPv4::IPv4 *ipv4;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
|
||||
UDP(NetworkIPv4::IPv4 *ipv4, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~UDP();
|
||||
UDP(NetworkIPv4::IPv4 *ipv4, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~UDP();
|
||||
|
||||
virtual Socket *Connect(InternetProtocol IP, uint16_t Port);
|
||||
virtual Socket *Listen(uint16_t Port);
|
||||
virtual void Disconnect(Socket *Socket);
|
||||
virtual void Send(Socket *Socket, uint8_t *Data, size_t Length);
|
||||
virtual void Bind(Socket *Socket, UDPEvents *EventHandler);
|
||||
virtual Socket *Connect(InternetProtocol IP, uint16_t Port);
|
||||
virtual Socket *Listen(uint16_t Port);
|
||||
virtual void Disconnect(Socket *Socket);
|
||||
virtual void Send(Socket *Socket, uint8_t *Data, size_t Length);
|
||||
virtual void Bind(Socket *Socket, UDPEvents *EventHandler);
|
||||
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length);
|
||||
};
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length);
|
||||
};
|
||||
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
InternetProtocol LocalIP;
|
||||
uint16_t LocalPort = 0;
|
||||
InternetProtocol RemoteIP;
|
||||
uint16_t RemotePort = 0;
|
||||
bool Listening = false;
|
||||
UDPEvents *EventHandler = nullptr;
|
||||
UDP *SocketUDP = nullptr;
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
InternetProtocol LocalIP;
|
||||
uint16_t LocalPort = 0;
|
||||
InternetProtocol RemoteIP;
|
||||
uint16_t RemotePort = 0;
|
||||
bool Listening = false;
|
||||
UDPEvents *EventHandler = nullptr;
|
||||
UDP *SocketUDP = nullptr;
|
||||
|
||||
Socket(UDP *_UDP);
|
||||
~Socket();
|
||||
};
|
||||
Socket(UDP *_UDP);
|
||||
~Socket();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_UDP_H__
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <debug.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace PCI
|
||||
{
|
||||
@ -30,6 +30,8 @@ namespace PCI
|
||||
{
|
||||
enum PCIVendors
|
||||
{
|
||||
Apple = 0x106B,
|
||||
BusLogic = 0x104B,
|
||||
SymbiosLogic = 0x1000,
|
||||
RedHat = 0x1AF4,
|
||||
REDHat2 = 0x1B36,
|
||||
@ -120,12 +122,9 @@ namespace PCI
|
||||
uint8_t LatencyTimer;
|
||||
uint8_t HeaderType;
|
||||
uint8_t BIST;
|
||||
};
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* @brief PCI Header Type 0
|
||||
*
|
||||
*/
|
||||
/** PCI Header Type 0 */
|
||||
struct PCIHeader0
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
@ -147,11 +146,9 @@ namespace PCI
|
||||
uint8_t InterruptPin;
|
||||
uint8_t MinGrant;
|
||||
uint8_t MaxLatency;
|
||||
};
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* @brief PCI Header Type 1 (PCI-to-PCI Bridge)
|
||||
*/
|
||||
/** PCI Header Type 1 (PCI-to-PCI Bridge) */
|
||||
struct PCIHeader1
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
@ -179,11 +176,9 @@ namespace PCI
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint16_t BridgeControl;
|
||||
};
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* @brief PCI Header Type 2 (PCI-to-CardBus Bridge)
|
||||
*/
|
||||
/** PCI Header Type 2 (PCI-to-CardBus Bridge) */
|
||||
struct PCIHeader2
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
@ -209,7 +204,7 @@ namespace PCI
|
||||
uint16_t SubsystemVendorID;
|
||||
uint16_t SubsystemID;
|
||||
uint32_t LegacyBaseAddress;
|
||||
};
|
||||
} __packed;
|
||||
|
||||
struct DeviceConfig
|
||||
{
|
||||
@ -227,24 +222,25 @@ namespace PCI
|
||||
uint32_t Bus;
|
||||
uint32_t Device;
|
||||
uint32_t Function;
|
||||
};
|
||||
} __packed;
|
||||
|
||||
class PCI
|
||||
class Manager
|
||||
{
|
||||
private:
|
||||
std::vector<PCIDevice> Devices;
|
||||
std::list<PCIDevice> Devices;
|
||||
|
||||
public:
|
||||
std::vector<PCIDevice> &GetDevices() { return Devices; }
|
||||
void MapPCIAddresses(PCIDevice Device, Memory::PageTable *Table = nullptr);
|
||||
std::list<PCIDevice> GetDevices() { return Devices; }
|
||||
void MapPCIAddresses(PCIDevice Device, Memory::PageTable *Table);
|
||||
void EnumerateFunction(uint64_t DeviceAddress, uint32_t Function, PCIDevice dev);
|
||||
void EnumerateDevice(uint64_t BusAddress, uint32_t Device, PCIDevice dev);
|
||||
void EnumerateBus(uint64_t BaseAddress, uint32_t Bus, PCIDevice dev);
|
||||
std::vector<PCIDevice> FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF);
|
||||
std::vector<PCIDevice> FindPCIDevice(int VendorID, int DeviceID);
|
||||
std::list<PCIDevice> FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF);
|
||||
std::list<PCIDevice> FindPCIDevice(uint16_t VendorID, uint16_t DeviceID);
|
||||
std::list<PCIDevice> FindPCIDevice(std::list<uint16_t> VendorIDs, std::list<uint16_t> DeviceIDs);
|
||||
|
||||
PCI();
|
||||
~PCI();
|
||||
Manager();
|
||||
~Manager();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -22,48 +22,48 @@
|
||||
|
||||
namespace Power
|
||||
{
|
||||
class Power
|
||||
{
|
||||
private:
|
||||
void *acpi = nullptr;
|
||||
void *dsdt = nullptr;
|
||||
void *madt = nullptr;
|
||||
class Power
|
||||
{
|
||||
private:
|
||||
void *acpi = nullptr;
|
||||
void *dsdt = nullptr;
|
||||
void *madt = nullptr;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Get Advanced Configuration and Power Interface. (Available only on x32 and x64)
|
||||
*
|
||||
* @return void* (ACPI::ACPI *)
|
||||
*/
|
||||
void *GetACPI() { return this->acpi; }
|
||||
public:
|
||||
/**
|
||||
* @brief Get Advanced Configuration and Power Interface. (Available only on x32 and x64)
|
||||
*
|
||||
* @return void* (ACPI::ACPI *)
|
||||
*/
|
||||
void *GetACPI() { return this->acpi; }
|
||||
|
||||
/**
|
||||
* @brief Get Differentiated System Description Table. (Available only on x32 and x64)
|
||||
*
|
||||
* @return void* (ACPI::DSDT *)
|
||||
*/
|
||||
void *GetDSDT() { return this->dsdt; }
|
||||
/**
|
||||
* @brief Get Differentiated System Description Table. (Available only on x32 and x64)
|
||||
*
|
||||
* @return void* (ACPI::DSDT *)
|
||||
*/
|
||||
void *GetDSDT() { return this->dsdt; }
|
||||
|
||||
/**
|
||||
* @brief Get Multiple APIC Description Table. (Available only on x32 and x64)
|
||||
*
|
||||
* @return void* (ACPI::MADT *)
|
||||
*/
|
||||
void *GetMADT() { return this->madt; }
|
||||
/**
|
||||
* @brief Get Multiple APIC Description Table. (Available only on x32 and x64)
|
||||
*
|
||||
* @return void* (ACPI::MADT *)
|
||||
*/
|
||||
void *GetMADT() { return this->madt; }
|
||||
|
||||
/**
|
||||
* @brief Reboot the system.
|
||||
*/
|
||||
void Reboot();
|
||||
/**
|
||||
* @brief Reboot the system.
|
||||
*/
|
||||
void Reboot();
|
||||
|
||||
/**
|
||||
* @brief Shutdown the system.
|
||||
*/
|
||||
void Shutdown();
|
||||
/**
|
||||
* @brief Shutdown the system.
|
||||
*/
|
||||
void Shutdown();
|
||||
|
||||
void InitDSDT();
|
||||
Power();
|
||||
};
|
||||
void InitDSDT();
|
||||
Power();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_POWER_H__
|
||||
|
194
include/signal.h
194
include/signal.h
@ -1,194 +0,0 @@
|
||||
/*
|
||||
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_SIGNAL_H__
|
||||
#define __FENNIX_KERNEL_SIGNAL_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
enum Signals
|
||||
{
|
||||
/**
|
||||
* Process abort signal.
|
||||
*/
|
||||
SIGABRT,
|
||||
|
||||
/**
|
||||
* Alarm clock.
|
||||
*/
|
||||
SIGALRM,
|
||||
|
||||
/**
|
||||
* Access to an undefined portion of a memory object.
|
||||
*/
|
||||
SIGBUS,
|
||||
|
||||
/**
|
||||
* Child process terminated, stopped,
|
||||
*/
|
||||
SIGCHLD,
|
||||
|
||||
/**
|
||||
* Continue executing, if stopped.
|
||||
*/
|
||||
SIGCONT,
|
||||
|
||||
/**
|
||||
* Erroneous arithmetic operation.
|
||||
*/
|
||||
SIGFPE,
|
||||
|
||||
/**
|
||||
* Hangup.
|
||||
*/
|
||||
SIGHUP,
|
||||
|
||||
/**
|
||||
* Illegal instruction.
|
||||
*/
|
||||
SIGILL,
|
||||
|
||||
/**
|
||||
* Terminal interrupt signal.
|
||||
*/
|
||||
SIGINT,
|
||||
|
||||
/**
|
||||
* Kill (cannot be caught or ignored).
|
||||
*/
|
||||
SIGKILL,
|
||||
|
||||
/**
|
||||
* Write on a pipe with no one to read it.
|
||||
*/
|
||||
SIGPIPE,
|
||||
|
||||
/**
|
||||
* Terminal quit signal.
|
||||
*/
|
||||
SIGQUIT,
|
||||
|
||||
/**
|
||||
* Invalid memory reference.
|
||||
*/
|
||||
SIGSEGV,
|
||||
|
||||
/**
|
||||
* Stop executing (cannot be caught or ignored).
|
||||
*/
|
||||
SIGSTOP,
|
||||
|
||||
/**
|
||||
* Termination signal.
|
||||
*/
|
||||
SIGTERM,
|
||||
|
||||
/**
|
||||
* Terminal stop signal.
|
||||
*/
|
||||
SIGTSTP,
|
||||
|
||||
/**
|
||||
* Background process attempting read.
|
||||
*/
|
||||
SIGTTIN,
|
||||
|
||||
/**
|
||||
* Background process attempting write.
|
||||
*/
|
||||
SIGTTOU,
|
||||
|
||||
/**
|
||||
* User-defined signal 1.
|
||||
*/
|
||||
SIGUSR1,
|
||||
|
||||
/**
|
||||
* User-defined signal 2.
|
||||
*/
|
||||
SIGUSR2,
|
||||
|
||||
/**
|
||||
* Pollable event.
|
||||
*/
|
||||
SIGPOLL,
|
||||
|
||||
/**
|
||||
* Profiling timer expired.
|
||||
*/
|
||||
SIGPROF,
|
||||
|
||||
/**
|
||||
* Bad system call.
|
||||
*/
|
||||
SIGSYS,
|
||||
|
||||
/**
|
||||
* Trace/breakpoint trap.
|
||||
*/
|
||||
SIGTRAP,
|
||||
|
||||
/**
|
||||
* High bandwidth data is available at a socket.
|
||||
*/
|
||||
SIGURG,
|
||||
|
||||
/**
|
||||
* Virtual timer expired.
|
||||
*/
|
||||
SIGVTALRM,
|
||||
|
||||
/**
|
||||
* CPU time limit exceeded.
|
||||
*/
|
||||
SIGXCPU,
|
||||
|
||||
/**
|
||||
* File size limit exceeded.
|
||||
*/
|
||||
SIGXFSZ,
|
||||
};
|
||||
|
||||
union sigval
|
||||
{
|
||||
int sival_int;
|
||||
void *sival_ptr;
|
||||
};
|
||||
|
||||
struct sched_param
|
||||
{
|
||||
int sched_priority;
|
||||
};
|
||||
|
||||
struct pthread_attr_t
|
||||
{
|
||||
uint64_t sig;
|
||||
size_t guard_sz;
|
||||
bool detach;
|
||||
sched_param sched;
|
||||
};
|
||||
|
||||
struct sigevent
|
||||
{
|
||||
int sigev_notify;
|
||||
int sigev_signo;
|
||||
union sigval sigev_value;
|
||||
void (*sigev_notify_function)(union sigval);
|
||||
pthread_attr_t *sigev_notify_attributes;
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_KERNEL_SIGNAL_H__
|
534
include/signal.hpp
Normal file
534
include/signal.hpp
Normal file
@ -0,0 +1,534 @@
|
||||
/*
|
||||
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_SIGNAL_H__
|
||||
#define __FENNIX_KERNEL_SIGNAL_H__
|
||||
|
||||
#include <syscalls.hpp>
|
||||
#include <lock.hpp>
|
||||
#include <types.h>
|
||||
#include <vector>
|
||||
#include <syscall/linux/signals.hpp>
|
||||
|
||||
enum Signals : int
|
||||
{
|
||||
SIG_NULL = 0,
|
||||
|
||||
/**
|
||||
* Process abort signal.
|
||||
*/
|
||||
SIGABRT,
|
||||
|
||||
/**
|
||||
* Alarm clock.
|
||||
*/
|
||||
SIGALRM,
|
||||
|
||||
/**
|
||||
* Access to an undefined portion of a memory object.
|
||||
*/
|
||||
SIGBUS,
|
||||
|
||||
/**
|
||||
* Child process terminated, stopped, or continued.
|
||||
*/
|
||||
SIGCHLD,
|
||||
|
||||
/**
|
||||
* Continue executing, if stopped.
|
||||
*/
|
||||
SIGCONT,
|
||||
|
||||
/**
|
||||
* Erroneous arithmetic operation.
|
||||
*/
|
||||
SIGFPE,
|
||||
|
||||
/**
|
||||
* Hangup.
|
||||
*/
|
||||
SIGHUP,
|
||||
|
||||
/**
|
||||
* Illegal instruction.
|
||||
*/
|
||||
SIGILL,
|
||||
|
||||
/**
|
||||
* Terminal interrupt signal.
|
||||
*/
|
||||
SIGINT,
|
||||
|
||||
/**
|
||||
* Kill (cannot be caught or ignored).
|
||||
*/
|
||||
SIGKILL,
|
||||
|
||||
/**
|
||||
* Write on a pipe with no one to read it.
|
||||
*/
|
||||
SIGPIPE,
|
||||
|
||||
/**
|
||||
* Terminal quit signal.
|
||||
*/
|
||||
SIGQUIT,
|
||||
|
||||
/**
|
||||
* Invalid memory reference.
|
||||
*/
|
||||
SIGSEGV,
|
||||
|
||||
/**
|
||||
* Stop executing (cannot be caught or ignored).
|
||||
*/
|
||||
SIGSTOP,
|
||||
|
||||
/**
|
||||
* Termination signal.
|
||||
*/
|
||||
SIGTERM,
|
||||
|
||||
/**
|
||||
* Terminal stop signal.
|
||||
*/
|
||||
SIGTSTP,
|
||||
|
||||
/**
|
||||
* Background process attempting read.
|
||||
*/
|
||||
SIGTTIN,
|
||||
|
||||
/**
|
||||
* Background process attempting write.
|
||||
*/
|
||||
SIGTTOU,
|
||||
|
||||
/**
|
||||
* User-defined signal 1.
|
||||
*/
|
||||
SIGUSR1,
|
||||
|
||||
/**
|
||||
* User-defined signal 2.
|
||||
*/
|
||||
SIGUSR2,
|
||||
|
||||
/**
|
||||
* Pollable event.
|
||||
*/
|
||||
SIGPOLL,
|
||||
|
||||
/**
|
||||
* Profiling timer expired.
|
||||
*/
|
||||
SIGPROF,
|
||||
|
||||
/**
|
||||
* Bad system call.
|
||||
*/
|
||||
SIGSYS,
|
||||
|
||||
/**
|
||||
* Trace/breakpoint trap.
|
||||
*/
|
||||
SIGTRAP,
|
||||
|
||||
/**
|
||||
* High bandwidth data is available at a socket.
|
||||
*/
|
||||
SIGURG,
|
||||
|
||||
/**
|
||||
* Virtual timer expired.
|
||||
*/
|
||||
SIGVTALRM,
|
||||
|
||||
/**
|
||||
* CPU time limit exceeded.
|
||||
*/
|
||||
SIGXCPU,
|
||||
|
||||
/**
|
||||
* File size limit exceeded.
|
||||
*/
|
||||
SIGXFSZ,
|
||||
|
||||
/**
|
||||
* Reserved
|
||||
*
|
||||
* These are just to match Linux's signal numbers.
|
||||
*/
|
||||
SIGRSV1,
|
||||
SIGRSV2,
|
||||
|
||||
/**
|
||||
* Maximum signal number.
|
||||
*/
|
||||
SIGNAL_MAX
|
||||
};
|
||||
|
||||
enum SignalDisposition
|
||||
{
|
||||
/**
|
||||
* Terminate the process.
|
||||
*/
|
||||
SIG_TERM,
|
||||
|
||||
/**
|
||||
* Ignore the signal.
|
||||
*/
|
||||
SIG_IGN,
|
||||
|
||||
/**
|
||||
* Dump core.
|
||||
*/
|
||||
SIG_CORE,
|
||||
|
||||
/**
|
||||
* Stop the process.
|
||||
*/
|
||||
SIG_STOP,
|
||||
|
||||
/**
|
||||
* Continue the process.
|
||||
*/
|
||||
SIG_CONT
|
||||
};
|
||||
|
||||
enum SignalAction
|
||||
{
|
||||
SIG_BLOCK,
|
||||
SIG_UNBLOCK,
|
||||
SIG_SETMASK
|
||||
};
|
||||
|
||||
#define SA_NOCLDSTOP 1
|
||||
#define SA_NOCLDWAIT 2
|
||||
#define SA_SIGINFO 4
|
||||
#define SA_ONSTACK 0x08000000
|
||||
#define SA_RESTART 0x10000000
|
||||
#define SA_NODEFER 0x40000000
|
||||
#define SA_RESETHAND 0x80000000
|
||||
#define SA_RESTORER 0x04000000
|
||||
|
||||
#define __SI_PAD_SIZE \
|
||||
(128 - 2 * sizeof(int) - sizeof(long))
|
||||
|
||||
typedef unsigned long sigset_t;
|
||||
|
||||
union sigval
|
||||
{
|
||||
int sival_int;
|
||||
void *sival_ptr;
|
||||
};
|
||||
|
||||
struct sched_param
|
||||
{
|
||||
int sched_priority;
|
||||
};
|
||||
|
||||
struct pthread_attr_t
|
||||
{
|
||||
uint64_t sig;
|
||||
size_t guard_sz;
|
||||
bool detach;
|
||||
sched_param sched;
|
||||
};
|
||||
|
||||
struct sigevent
|
||||
{
|
||||
int sigev_notify;
|
||||
int sigev_signo;
|
||||
union sigval sigev_value;
|
||||
void (*sigev_notify_function)(union sigval);
|
||||
pthread_attr_t *sigev_notify_attributes;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int si_signo;
|
||||
int si_errno;
|
||||
int si_code;
|
||||
union
|
||||
{
|
||||
char __pad[__SI_PAD_SIZE];
|
||||
struct
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
pid_t si_pid;
|
||||
uid_t si_uid;
|
||||
} __piduid;
|
||||
struct
|
||||
{
|
||||
int si_timerid;
|
||||
int si_overrun;
|
||||
} __timer;
|
||||
} __first;
|
||||
union
|
||||
{
|
||||
union sigval si_value;
|
||||
struct
|
||||
{
|
||||
int si_status;
|
||||
clock_t si_utime, si_stime;
|
||||
} __sigchld;
|
||||
} __second;
|
||||
} __si_common;
|
||||
|
||||
struct
|
||||
{
|
||||
void *si_addr;
|
||||
short si_addr_lsb;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
void *si_lower;
|
||||
void *si_upper;
|
||||
} __addr_bnd;
|
||||
unsigned si_pkey;
|
||||
} __first;
|
||||
} __sigfault;
|
||||
|
||||
struct
|
||||
{
|
||||
long si_band;
|
||||
int si_fd;
|
||||
} __sigpoll;
|
||||
|
||||
struct
|
||||
{
|
||||
void *si_call_addr;
|
||||
int si_syscall;
|
||||
unsigned si_arch;
|
||||
} __sigsys;
|
||||
} __si_fields;
|
||||
} siginfo_t;
|
||||
|
||||
struct sigaction
|
||||
{
|
||||
union
|
||||
{
|
||||
void (*sa_handler)(int);
|
||||
void (*sa_sigaction)(int, siginfo_t *, void *);
|
||||
} __sa_handler;
|
||||
sigset_t sa_mask;
|
||||
int sa_flags;
|
||||
void (*sa_restorer)(void);
|
||||
};
|
||||
|
||||
namespace Tasking
|
||||
{
|
||||
__no_sanitize("shift") inline __always_inline
|
||||
sigset_t
|
||||
ToFlag(sigset_t sig)
|
||||
{
|
||||
return 1 << (sig - 1);
|
||||
}
|
||||
|
||||
inline __always_inline
|
||||
sigset_t
|
||||
ToSig(sigset_t flag)
|
||||
{
|
||||
return __builtin_ctzl(flag) + 1;
|
||||
}
|
||||
|
||||
class Signal
|
||||
{
|
||||
private:
|
||||
struct SignalInfo
|
||||
{
|
||||
int sig;
|
||||
union sigval val;
|
||||
};
|
||||
|
||||
struct StackInfo
|
||||
{
|
||||
#ifdef a64
|
||||
CPU::x64::FXState fx;
|
||||
CPU::x64::TrapFrame tf;
|
||||
uintptr_t GSBase, FSBase, ShadowGSBase;
|
||||
#else
|
||||
CPU::x32::FXState fx;
|
||||
CPU::x32::TrapFrame tf;
|
||||
uintptr_t GSBase, FSBase;
|
||||
#endif
|
||||
sigset_t SignalMask;
|
||||
int Compatibility;
|
||||
|
||||
#ifdef DEBUG
|
||||
// For debugging purposes
|
||||
char dbg[6] = {'S', 'I', 'G', 'N', 'A', 'L'};
|
||||
#endif
|
||||
} __aligned(16) __packed;
|
||||
|
||||
NewLock(SignalLock);
|
||||
void *ctx;
|
||||
Signals LastSignal = SIG_NULL;
|
||||
|
||||
// Signal trampoline
|
||||
void *TrampAddr = nullptr;
|
||||
size_t TrampSz = 0;
|
||||
|
||||
std::vector<SignalInfo> SignalQueue;
|
||||
std::atomic<sigset_t> SignalMask = 0;
|
||||
sigaction SignalAction[SIGNAL_MAX]{};
|
||||
SignalDisposition sigDisp[SIGNAL_MAX];
|
||||
std::vector<SignalInfo> Watchers;
|
||||
|
||||
bool LinuxSig();
|
||||
|
||||
int ConvertToLinuxIfNecessary(int sig);
|
||||
int ConvertToNativeIfNecessary(int sig);
|
||||
|
||||
sigset_t ConvertSigsetToLinuxIfNecessary(sigset_t sig);
|
||||
sigset_t ConvertSigsetToNativeIfNecessary(sigset_t sig);
|
||||
|
||||
int MakeExitCode(int sig);
|
||||
|
||||
const sigset_t nMasks = ToFlag(SIGKILL) |
|
||||
ToFlag(SIGSTOP) |
|
||||
ToFlag(SIGCONT) |
|
||||
ToFlag(SIGSEGV) |
|
||||
ToFlag(SIGBUS) |
|
||||
ToFlag(SIGILL) |
|
||||
ToFlag(SIGFPE);
|
||||
|
||||
const sigset_t lMasks = ToFlag(linux_SIGKILL) |
|
||||
ToFlag(linux_SIGSTOP) |
|
||||
ToFlag(linux_SIGCONT) |
|
||||
ToFlag(linux_SIGSEGV) |
|
||||
ToFlag(linux_SIGBUS) |
|
||||
ToFlag(linux_SIGILL) |
|
||||
ToFlag(linux_SIGFPE);
|
||||
|
||||
void RemoveUnmaskable(sigset_t *sig)
|
||||
{
|
||||
if (LinuxSig())
|
||||
*sig &= ~lMasks;
|
||||
else
|
||||
*sig &= ~nMasks;
|
||||
}
|
||||
|
||||
bool CanHaveHandler(sigset_t sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case SIGKILL:
|
||||
case SIGSTOP:
|
||||
case SIGCONT:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void *GetContext() { return ctx; }
|
||||
Signals GetLastSignal() { return LastSignal; }
|
||||
|
||||
int AddWatcher(Signal *who, int sig);
|
||||
int RemoveWatcher(Signal *who, int sig);
|
||||
|
||||
int AddSignal(int sig, union sigval val);
|
||||
int RemoveSignal(int sig);
|
||||
|
||||
/**
|
||||
* For scheduler use only
|
||||
* @return True if there is a signal to handle
|
||||
*/
|
||||
bool HandleSignal(CPU::TrapFrame *tf);
|
||||
void RestoreHandleSignal(SyscallsFrame *tf);
|
||||
|
||||
/**
|
||||
* Mask a signal
|
||||
*
|
||||
* @param sig The signal to set
|
||||
*
|
||||
* @return Old mask
|
||||
*/
|
||||
sigset_t Block(sigset_t sig);
|
||||
|
||||
/**
|
||||
* Unmask a signal
|
||||
*
|
||||
* @param sig The signal to set
|
||||
*
|
||||
* @return Old mask
|
||||
*/
|
||||
sigset_t Unblock(sigset_t sig);
|
||||
|
||||
/**
|
||||
* Set the signal mask
|
||||
*
|
||||
* @param sig The signal to set
|
||||
*
|
||||
* @return Old mask
|
||||
*/
|
||||
sigset_t SetMask(sigset_t sig);
|
||||
|
||||
sigset_t GetMask() { return SignalMask.load(); }
|
||||
|
||||
int SetAction(int sig, const sigaction act);
|
||||
int GetAction(int sig, sigaction *act);
|
||||
|
||||
/**
|
||||
* Send a signal to the process
|
||||
*
|
||||
* @param sig The signal to send
|
||||
* (compatibility specific)
|
||||
* @param val The value to send
|
||||
*
|
||||
* @return 0 on success, -errno on error
|
||||
*/
|
||||
int SendSignal(int sig, union sigval val = {0});
|
||||
|
||||
int WaitAnySignal();
|
||||
|
||||
/**
|
||||
* Wait for a signal
|
||||
*
|
||||
* @param sig The signal to wait for
|
||||
* (compatibility specific)
|
||||
* @param val The value to wait for
|
||||
*
|
||||
* @return 0 on success, -errno on error
|
||||
*/
|
||||
int WaitSignal(int sig, union sigval *val);
|
||||
|
||||
/**
|
||||
* Wait for a signal with a timeout
|
||||
*
|
||||
* @param sig The signal to wait for
|
||||
* (compatibility specific)
|
||||
* @param val The value to wait for
|
||||
* @param timeout The timeout to wait for
|
||||
*
|
||||
* @return 0 on success, -errno on error
|
||||
*/
|
||||
int WaitSignalTimeout(int sig, union sigval *val, uint64_t timeout);
|
||||
|
||||
Signal(void *ctx);
|
||||
~Signal();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_SIGNAL_H__
|
@ -24,7 +24,7 @@
|
||||
#include <atomic>
|
||||
|
||||
/** @brief Maximum supported number of CPU cores by the kernel */
|
||||
#define MAX_CPU 256
|
||||
#define MAX_CPU 255
|
||||
#define CPU_DATA_CHECKSUM 0xC0FFEE
|
||||
|
||||
struct CPUArchData
|
||||
|
@ -31,17 +31,20 @@ namespace SymbolResolver
|
||||
};
|
||||
|
||||
std::vector<SymbolTable> SymTable;
|
||||
void *Image;
|
||||
void *Image = nullptr;
|
||||
bool SymbolTableExists = false;
|
||||
|
||||
public:
|
||||
decltype(SymbolTableExists) &SymTableExists = this->SymbolTableExists;
|
||||
std::vector<SymbolTable> &GetSymTable() { return this->SymTable; }
|
||||
void *GetImage() { return this->Image; }
|
||||
const char *GetSymbolFromAddress(uintptr_t Address);
|
||||
const char *GetSymbol(uintptr_t Address);
|
||||
uintptr_t GetSymbol(const char *Name);
|
||||
void AddSymbol(uintptr_t Address, const char *Name);
|
||||
void AddSymbolInfoFromGRUB(uint64_t Num, uint64_t EntSize, uint64_t Shndx, uintptr_t Sections);
|
||||
void AppendSymbols(uintptr_t ImageAddress, uintptr_t BaseAddress = 0);
|
||||
Symbols(uintptr_t ImageAddress);
|
||||
Symbols() {}
|
||||
~Symbols();
|
||||
};
|
||||
}
|
||||
|
233
include/syscall/linux/defs.hpp
Normal file
233
include/syscall/linux/defs.hpp
Normal file
@ -0,0 +1,233 @@
|
||||
/*
|
||||
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_LINUX_DEFS_H__
|
||||
#define __FENNIX_KERNEL_LINUX_DEFS_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define ARCH_SET_GS 0x1001
|
||||
#define ARCH_SET_FS 0x1002
|
||||
#define ARCH_GET_FS 0x1003
|
||||
#define ARCH_GET_GS 0x1004
|
||||
|
||||
#define ARCH_GET_CPUID 0x1011
|
||||
#define ARCH_SET_CPUID 0x1012
|
||||
|
||||
#define ARCH_GET_XCOMP_SUPP 0x1021
|
||||
#define ARCH_GET_XCOMP_PERM 0x1022
|
||||
#define ARCH_REQ_XCOMP_PERM 0x1023
|
||||
#define ARCH_GET_XCOMP_GUEST_PERM 0x1024
|
||||
#define ARCH_REQ_XCOMP_GUEST_PERM 0x1025
|
||||
|
||||
#define ARCH_XCOMP_TILECFG 17
|
||||
#define ARCH_XCOMP_TILEDATA 18
|
||||
|
||||
#define ARCH_MAP_VDSO_X32 0x2001
|
||||
#define ARCH_MAP_VDSO_32 0x2002
|
||||
#define ARCH_MAP_VDSO_64 0x2003
|
||||
|
||||
#define ARCH_GET_UNTAG_MASK 0x4001
|
||||
#define ARCH_ENABLE_TAGGED_ADDR 0x4002
|
||||
#define ARCH_GET_MAX_TAG_BITS 0x4003
|
||||
#define ARCH_FORCE_TAGGED_SVA 0x4004
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_EXEC 4
|
||||
#define PROT_GROWSDOWN 0x01000000
|
||||
#define PROT_GROWSUP 0x02000000
|
||||
|
||||
#define MAP_TYPE 0x0f
|
||||
|
||||
#define MAP_FILE 0
|
||||
#define MAP_SHARED 0x01
|
||||
#define MAP_PRIVATE 0x02
|
||||
#define MAP_SHARED_VALIDATE 0x03
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_NORESERVE 0x4000
|
||||
#define MAP_GROWSDOWN 0x0100
|
||||
#define MAP_DENYWRITE 0x0800
|
||||
#define MAP_EXECUTABLE 0x1000
|
||||
#define MAP_LOCKED 0x2000
|
||||
#define MAP_POPULATE 0x8000
|
||||
#define MAP_NONBLOCK 0x10000
|
||||
#define MAP_STACK 0x20000
|
||||
#define MAP_HUGETLB 0x40000
|
||||
#define MAP_SYNC 0x80000
|
||||
#define MAP_FIXED_NOREPLACE 0x100000
|
||||
|
||||
#define CLOCK_REALTIME 0
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#define CLOCK_PROCESS_CPUTIME_ID 2
|
||||
#define CLOCK_THREAD_CPUTIME_ID 3
|
||||
#define CLOCK_MONOTONIC_RAW 4
|
||||
#define CLOCK_REALTIME_COARSE 5
|
||||
#define CLOCK_MONOTONIC_COARSE 6
|
||||
#define CLOCK_BOOTTIME 7
|
||||
#define CLOCK_REALTIME_ALARM 8
|
||||
#define CLOCK_BOOTTIME_ALARM 9
|
||||
#define CLOCK_SGI_CYCLE 10
|
||||
#define CLOCK_TAI 11
|
||||
|
||||
#define GRND_NONBLOCK 0x1
|
||||
#define GRND_RANDOM 0x2
|
||||
#define GRND_INSECURE 0x4
|
||||
|
||||
#define RLIMIT_CPU 0
|
||||
#define RLIMIT_FSIZE 1
|
||||
#define RLIMIT_DATA 2
|
||||
#define RLIMIT_STACK 3
|
||||
#define RLIMIT_CORE 4
|
||||
#define RLIMIT_RSS 5
|
||||
#define RLIMIT_NPROC 6
|
||||
#define RLIMIT_NOFILE 7
|
||||
#define RLIMIT_MEMLOCK 8
|
||||
#define RLIMIT_AS 9
|
||||
#define RLIMIT_LOCKS 10
|
||||
#define RLIMIT_SIGPENDING 11
|
||||
#define RLIMIT_MSGQUEUE 12
|
||||
#define RLIMIT_NICE 13
|
||||
#define RLIMIT_RTPRIO 14
|
||||
#define RLIMIT_RTTIME 15
|
||||
#define RLIMIT_NLIMITS 16
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define F_SETOWN 8
|
||||
#define F_GETOWN 9
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#if __LONG_MAX == 0x7fffffffL
|
||||
#define F_GETLK 12
|
||||
#define F_SETLK 13
|
||||
#define F_SETLKW 14
|
||||
#else
|
||||
#define F_GETLK 5
|
||||
#define F_SETLK 6
|
||||
#define F_SETLKW 7
|
||||
#endif
|
||||
|
||||
#define F_SETOWN_EX 15
|
||||
#define F_GETOWN_EX 16
|
||||
|
||||
#define DT_UNKNOWN 0
|
||||
#define DT_FIFO 1
|
||||
#define DT_CHR 2
|
||||
#define DT_DIR 4
|
||||
#define DT_BLK 6
|
||||
#define DT_REG 8
|
||||
#define DT_LNK 10
|
||||
#define DT_SOCK 12
|
||||
#define DT_WHT 14
|
||||
|
||||
#define AT_FDCWD (-100)
|
||||
#define AT_SYMLINK_NOFOLLOW 0x100
|
||||
#define AT_REMOVEDIR 0x200
|
||||
#define AT_SYMLINK_FOLLOW 0x400
|
||||
#define AT_EACCESS 0x200
|
||||
#define AT_NO_AUTOMOUNT 0x800
|
||||
#define AT_EMPTY_PATH 0x1000
|
||||
#define AT_STATX_SYNC_TYPE 0x6000
|
||||
#define AT_STATX_SYNC_AS_STAT 0x0000
|
||||
#define AT_STATX_FORCE_SYNC 0x2000
|
||||
#define AT_STATX_DONT_SYNC 0x4000
|
||||
#define AT_RECURSIVE 0x8000
|
||||
|
||||
#define LINUX_REBOOT_MAGIC1 0xfee1dead
|
||||
#define LINUX_REBOOT_MAGIC2 0x28121969
|
||||
#define LINUX_REBOOT_MAGIC2A 0x05121996
|
||||
#define LINUX_REBOOT_MAGIC2B 0x16041998
|
||||
#define LINUX_REBOOT_MAGIC2C 0x20112000
|
||||
|
||||
#define LINUX_REBOOT_CMD_RESTART 0x01234567
|
||||
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
|
||||
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
|
||||
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
|
||||
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
|
||||
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
|
||||
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
|
||||
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
|
||||
|
||||
typedef long __kernel_old_time_t;
|
||||
typedef long __kernel_suseconds_t;
|
||||
typedef int clockid_t;
|
||||
|
||||
struct iovec
|
||||
{
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
struct timeval
|
||||
{
|
||||
__kernel_old_time_t tv_sec;
|
||||
__kernel_suseconds_t tv_usec;
|
||||
};
|
||||
|
||||
struct rusage
|
||||
{
|
||||
struct timeval ru_utime;
|
||||
struct timeval ru_stime;
|
||||
long ru_maxrss;
|
||||
long ru_ixrss;
|
||||
long ru_idrss;
|
||||
long ru_isrss;
|
||||
long ru_minflt;
|
||||
long ru_majflt;
|
||||
long ru_nswap;
|
||||
long ru_inblock;
|
||||
long ru_oublock;
|
||||
long ru_msgsnd;
|
||||
long ru_msgrcv;
|
||||
long ru_nsignals;
|
||||
long ru_nvcsw;
|
||||
long ru_nivcsw;
|
||||
};
|
||||
|
||||
typedef unsigned long rlim_t;
|
||||
struct rlimit
|
||||
{
|
||||
rlim_t rlim_cur; /* Soft limit */
|
||||
rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */
|
||||
};
|
||||
|
||||
struct linux_dirent
|
||||
{
|
||||
unsigned long d_ino; /* Inode number */
|
||||
unsigned long d_off; /* Offset to next linux_dirent */
|
||||
unsigned short d_reclen; /* Length of this linux_dirent */
|
||||
char d_name[]; /* Filename (null-terminated) */
|
||||
};
|
||||
|
||||
struct linux_dirent64
|
||||
{
|
||||
ino64_t d_ino; /* 64-bit inode number */
|
||||
off64_t d_off; /* 64-bit offset to next structure */
|
||||
unsigned short d_reclen; /* Size of this dirent */
|
||||
unsigned char d_type; /* File type */
|
||||
char d_name[]; /* Filename (null-terminated) */
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_KERNEL_LINUX_DEFS_H__
|
56
include/syscall/linux/signals.hpp
Normal file
56
include/syscall/linux/signals.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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_LINUX_SIGNALS_H__
|
||||
#define __FENNIX_KERNEL_LINUX_SIGNALS_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define linux_SIGHUP 1
|
||||
#define linux_SIGINT 2
|
||||
#define linux_SIGQUIT 3
|
||||
#define linux_SIGILL 4
|
||||
#define linux_SIGTRAP 5
|
||||
#define linux_SIGABRT 6
|
||||
#define linux_SIGBUS 7
|
||||
#define linux_SIGFPE 8
|
||||
#define linux_SIGKILL 9
|
||||
#define linux_SIGUSR1 10
|
||||
#define linux_SIGSEGV 11
|
||||
#define linux_SIGUSR2 12
|
||||
#define linux_SIGPIPE 13
|
||||
#define linux_SIGALRM 14
|
||||
#define linux_SIGTERM 15
|
||||
#define linux_SIGSTKFLT 16
|
||||
#define linux_SIGCHLD 17
|
||||
#define linux_SIGCONT 18
|
||||
#define linux_SIGSTOP 19
|
||||
#define linux_SIGTSTP 20
|
||||
#define linux_SIGTTIN 21
|
||||
#define linux_SIGTTOU 22
|
||||
#define linux_SIGURG 23
|
||||
#define linux_SIGXCPU 24
|
||||
#define linux_SIGXFSZ 25
|
||||
#define linux_SIGVTALRM 26
|
||||
#define linux_SIGPROF 27
|
||||
#define linux_SIGWINCH 28
|
||||
#define linux_SIGPOLL 29
|
||||
#define linux_SIGPWR 30
|
||||
#define linux_SIGSYS 31
|
||||
#define linux_SIGUNUSED linux_SIGSYS
|
||||
|
||||
#endif // !__FENNIX_KERNEL_LINUX_SIGNALS_H__
|
381
include/syscall/linux/syscalls_amd64.hpp
Normal file
381
include/syscall/linux/syscalls_amd64.hpp
Normal file
@ -0,0 +1,381 @@
|
||||
/*
|
||||
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_LINUX_SYSCALLS_x64_H__
|
||||
#define __FENNIX_KERNEL_LINUX_SYSCALLS_x64_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define __NR_amd64_read 0
|
||||
#define __NR_amd64_write 1
|
||||
#define __NR_amd64_open 2
|
||||
#define __NR_amd64_close 3
|
||||
#define __NR_amd64_stat 4
|
||||
#define __NR_amd64_fstat 5
|
||||
#define __NR_amd64_lstat 6
|
||||
#define __NR_amd64_poll 7
|
||||
#define __NR_amd64_lseek 8
|
||||
#define __NR_amd64_mmap 9
|
||||
#define __NR_amd64_mprotect 10
|
||||
#define __NR_amd64_munmap 11
|
||||
#define __NR_amd64_brk 12
|
||||
#define __NR_amd64_rt_sigaction 13
|
||||
#define __NR_amd64_rt_sigprocmask 14
|
||||
#define __NR_amd64_rt_sigreturn 15
|
||||
#define __NR_amd64_ioctl 16
|
||||
#define __NR_amd64_pread64 17
|
||||
#define __NR_amd64_pwrite64 18
|
||||
#define __NR_amd64_readv 19
|
||||
#define __NR_amd64_writev 20
|
||||
#define __NR_amd64_access 21
|
||||
#define __NR_amd64_pipe 22
|
||||
#define __NR_amd64_select 23
|
||||
#define __NR_amd64_sched_yield 24
|
||||
#define __NR_amd64_mremap 25
|
||||
#define __NR_amd64_msync 26
|
||||
#define __NR_amd64_mincore 27
|
||||
#define __NR_amd64_madvise 28
|
||||
#define __NR_amd64_shmget 29
|
||||
#define __NR_amd64_shmat 30
|
||||
#define __NR_amd64_shmctl 31
|
||||
#define __NR_amd64_dup 32
|
||||
#define __NR_amd64_dup2 33
|
||||
#define __NR_amd64_pause 34
|
||||
#define __NR_amd64_nanosleep 35
|
||||
#define __NR_amd64_getitimer 36
|
||||
#define __NR_amd64_alarm 37
|
||||
#define __NR_amd64_setitimer 38
|
||||
#define __NR_amd64_getpid 39
|
||||
#define __NR_amd64_sendfile 40
|
||||
#define __NR_amd64_socket 41
|
||||
#define __NR_amd64_connect 42
|
||||
#define __NR_amd64_accept 43
|
||||
#define __NR_amd64_sendto 44
|
||||
#define __NR_amd64_recvfrom 45
|
||||
#define __NR_amd64_sendmsg 46
|
||||
#define __NR_amd64_recvmsg 47
|
||||
#define __NR_amd64_shutdown 48
|
||||
#define __NR_amd64_bind 49
|
||||
#define __NR_amd64_listen 50
|
||||
#define __NR_amd64_getsockname 51
|
||||
#define __NR_amd64_getpeername 52
|
||||
#define __NR_amd64_socketpair 53
|
||||
#define __NR_amd64_setsockopt 54
|
||||
#define __NR_amd64_getsockopt 55
|
||||
#define __NR_amd64_clone 56
|
||||
#define __NR_amd64_fork 57
|
||||
#define __NR_amd64_vfork 58
|
||||
#define __NR_amd64_execve 59
|
||||
#define __NR_amd64_exit 60
|
||||
#define __NR_amd64_wait4 61
|
||||
#define __NR_amd64_kill 62
|
||||
#define __NR_amd64_uname 63
|
||||
#define __NR_amd64_semget 64
|
||||
#define __NR_amd64_semop 65
|
||||
#define __NR_amd64_semctl 66
|
||||
#define __NR_amd64_shmdt 67
|
||||
#define __NR_amd64_msgget 68
|
||||
#define __NR_amd64_msgsnd 69
|
||||
#define __NR_amd64_msgrcv 70
|
||||
#define __NR_amd64_msgctl 71
|
||||
#define __NR_amd64_fcntl 72
|
||||
#define __NR_amd64_flock 73
|
||||
#define __NR_amd64_fsync 74
|
||||
#define __NR_amd64_fdatasync 75
|
||||
#define __NR_amd64_truncate 76
|
||||
#define __NR_amd64_ftruncate 77
|
||||
#define __NR_amd64_getdents 78
|
||||
#define __NR_amd64_getcwd 79
|
||||
#define __NR_amd64_chdir 80
|
||||
#define __NR_amd64_fchdir 81
|
||||
#define __NR_amd64_rename 82
|
||||
#define __NR_amd64_mkdir 83
|
||||
#define __NR_amd64_rmdir 84
|
||||
#define __NR_amd64_creat 85
|
||||
#define __NR_amd64_link 86
|
||||
#define __NR_amd64_unlink 87
|
||||
#define __NR_amd64_symlink 88
|
||||
#define __NR_amd64_readlink 89
|
||||
#define __NR_amd64_chmod 90
|
||||
#define __NR_amd64_fchmod 91
|
||||
#define __NR_amd64_chown 92
|
||||
#define __NR_amd64_fchown 93
|
||||
#define __NR_amd64_lchown 94
|
||||
#define __NR_amd64_umask 95
|
||||
#define __NR_amd64_gettimeofday 96
|
||||
#define __NR_amd64_getrlimit 97
|
||||
#define __NR_amd64_getrusage 98
|
||||
#define __NR_amd64_sysinfo 99
|
||||
#define __NR_amd64_times 100
|
||||
#define __NR_amd64_ptrace 101
|
||||
#define __NR_amd64_getuid 102
|
||||
#define __NR_amd64_syslog 103
|
||||
#define __NR_amd64_getgid 104
|
||||
#define __NR_amd64_setuid 105
|
||||
#define __NR_amd64_setgid 106
|
||||
#define __NR_amd64_geteuid 107
|
||||
#define __NR_amd64_getegid 108
|
||||
#define __NR_amd64_setpgid 109
|
||||
#define __NR_amd64_getppid 110
|
||||
#define __NR_amd64_getpgrp 111
|
||||
#define __NR_amd64_setsid 112
|
||||
#define __NR_amd64_setreuid 113
|
||||
#define __NR_amd64_setregid 114
|
||||
#define __NR_amd64_getgroups 115
|
||||
#define __NR_amd64_setgroups 116
|
||||
#define __NR_amd64_setresuid 117
|
||||
#define __NR_amd64_getresuid 118
|
||||
#define __NR_amd64_setresgid 119
|
||||
#define __NR_amd64_getresgid 120
|
||||
#define __NR_amd64_getpgid 121
|
||||
#define __NR_amd64_setfsuid 122
|
||||
#define __NR_amd64_setfsgid 123
|
||||
#define __NR_amd64_getsid 124
|
||||
#define __NR_amd64_capget 125
|
||||
#define __NR_amd64_capset 126
|
||||
#define __NR_amd64_rt_sigpending 127
|
||||
#define __NR_amd64_rt_sigtimedwait 128
|
||||
#define __NR_amd64_rt_sigqueueinfo 129
|
||||
#define __NR_amd64_rt_sigsuspend 130
|
||||
#define __NR_amd64_sigaltstack 131
|
||||
#define __NR_amd64_utime 132
|
||||
#define __NR_amd64_mknod 133
|
||||
#define __NR_amd64_uselib 134
|
||||
#define __NR_amd64_personality 135
|
||||
#define __NR_amd64_ustat 136
|
||||
#define __NR_amd64_statfs 137
|
||||
#define __NR_amd64_fstatfs 138
|
||||
#define __NR_amd64_sysfs 139
|
||||
#define __NR_amd64_getpriority 140
|
||||
#define __NR_amd64_setpriority 141
|
||||
#define __NR_amd64_sched_setparam 142
|
||||
#define __NR_amd64_sched_getparam 143
|
||||
#define __NR_amd64_sched_setscheduler 144
|
||||
#define __NR_amd64_sched_getscheduler 145
|
||||
#define __NR_amd64_sched_get_priority_max 146
|
||||
#define __NR_amd64_sched_get_priority_min 147
|
||||
#define __NR_amd64_sched_rr_get_interval 148
|
||||
#define __NR_amd64_mlock 149
|
||||
#define __NR_amd64_munlock 150
|
||||
#define __NR_amd64_mlockall 151
|
||||
#define __NR_amd64_munlockall 152
|
||||
#define __NR_amd64_vhangup 153
|
||||
#define __NR_amd64_modify_ldt 154
|
||||
#define __NR_amd64_pivot_root 155
|
||||
#define __NR_amd64__sysctl 156
|
||||
#define __NR_amd64_prctl 157
|
||||
#define __NR_amd64_arch_prctl 158
|
||||
#define __NR_amd64_adjtimex 159
|
||||
#define __NR_amd64_setrlimit 160
|
||||
#define __NR_amd64_chroot 161
|
||||
#define __NR_amd64_sync 162
|
||||
#define __NR_amd64_acct 163
|
||||
#define __NR_amd64_settimeofday 164
|
||||
#define __NR_amd64_mount 165
|
||||
#define __NR_amd64_umount2 166
|
||||
#define __NR_amd64_swapon 167
|
||||
#define __NR_amd64_swapoff 168
|
||||
#define __NR_amd64_reboot 169
|
||||
#define __NR_amd64_sethostname 170
|
||||
#define __NR_amd64_setdomainname 171
|
||||
#define __NR_amd64_iopl 172
|
||||
#define __NR_amd64_ioperm 173
|
||||
#define __NR_amd64_create_module 174
|
||||
#define __NR_amd64_init_module 175
|
||||
#define __NR_amd64_delete_module 176
|
||||
#define __NR_amd64_get_kernel_syms 177
|
||||
#define __NR_amd64_query_module 178
|
||||
#define __NR_amd64_quotactl 179
|
||||
#define __NR_amd64_nfsservctl 180
|
||||
#define __NR_amd64_getpmsg 181
|
||||
#define __NR_amd64_putpmsg 182
|
||||
#define __NR_amd64_afs_syscall 183
|
||||
#define __NR_amd64_tuxcall 184
|
||||
#define __NR_amd64_security 185
|
||||
#define __NR_amd64_gettid 186
|
||||
#define __NR_amd64_readahead 187
|
||||
#define __NR_amd64_setxattr 188
|
||||
#define __NR_amd64_lsetxattr 189
|
||||
#define __NR_amd64_fsetxattr 190
|
||||
#define __NR_amd64_getxattr 191
|
||||
#define __NR_amd64_lgetxattr 192
|
||||
#define __NR_amd64_fgetxattr 193
|
||||
#define __NR_amd64_listxattr 194
|
||||
#define __NR_amd64_llistxattr 195
|
||||
#define __NR_amd64_flistxattr 196
|
||||
#define __NR_amd64_removexattr 197
|
||||
#define __NR_amd64_lremovexattr 198
|
||||
#define __NR_amd64_fremovexattr 199
|
||||
#define __NR_amd64_tkill 200
|
||||
#define __NR_amd64_time 201
|
||||
#define __NR_amd64_futex 202
|
||||
#define __NR_amd64_sched_setaffinity 203
|
||||
#define __NR_amd64_sched_getaffinity 204
|
||||
#define __NR_amd64_set_thread_area 205
|
||||
#define __NR_amd64_io_setup 206
|
||||
#define __NR_amd64_io_destroy 207
|
||||
#define __NR_amd64_io_getevents 208
|
||||
#define __NR_amd64_io_submit 209
|
||||
#define __NR_amd64_io_cancel 210
|
||||
#define __NR_amd64_get_thread_area 211
|
||||
#define __NR_amd64_lookup_dcookie 212
|
||||
#define __NR_amd64_epoll_create 213
|
||||
#define __NR_amd64_epoll_ctl_old 214
|
||||
#define __NR_amd64_epoll_wait_old 215
|
||||
#define __NR_amd64_remap_file_pages 216
|
||||
#define __NR_amd64_getdents64 217
|
||||
#define __NR_amd64_set_tid_address 218
|
||||
#define __NR_amd64_restart_syscall 219
|
||||
#define __NR_amd64_semtimedop 220
|
||||
#define __NR_amd64_fadvise64 221
|
||||
#define __NR_amd64_timer_create 222
|
||||
#define __NR_amd64_timer_settime 223
|
||||
#define __NR_amd64_timer_gettime 224
|
||||
#define __NR_amd64_timer_getoverrun 225
|
||||
#define __NR_amd64_timer_delete 226
|
||||
#define __NR_amd64_clock_settime 227
|
||||
#define __NR_amd64_clock_gettime 228
|
||||
#define __NR_amd64_clock_getres 229
|
||||
#define __NR_amd64_clock_nanosleep 230
|
||||
#define __NR_amd64_exit_group 231
|
||||
#define __NR_amd64_epoll_wait 232
|
||||
#define __NR_amd64_epoll_ctl 233
|
||||
#define __NR_amd64_tgkill 234
|
||||
#define __NR_amd64_utimes 235
|
||||
#define __NR_amd64_vserver 236
|
||||
#define __NR_amd64_mbind 237
|
||||
#define __NR_amd64_set_mempolicy 238
|
||||
#define __NR_amd64_get_mempolicy 239
|
||||
#define __NR_amd64_mq_open 240
|
||||
#define __NR_amd64_mq_unlink 241
|
||||
#define __NR_amd64_mq_timedsend 242
|
||||
#define __NR_amd64_mq_timedreceive 243
|
||||
#define __NR_amd64_mq_notify 244
|
||||
#define __NR_amd64_mq_getsetattr 245
|
||||
#define __NR_amd64_kexec_load 246
|
||||
#define __NR_amd64_waitid 247
|
||||
#define __NR_amd64_add_key 248
|
||||
#define __NR_amd64_request_key 249
|
||||
#define __NR_amd64_keyctl 250
|
||||
#define __NR_amd64_ioprio_set 251
|
||||
#define __NR_amd64_ioprio_get 252
|
||||
#define __NR_amd64_inotify_init 253
|
||||
#define __NR_amd64_inotify_add_watch 254
|
||||
#define __NR_amd64_inotify_rm_watch 255
|
||||
#define __NR_amd64_migrate_pages 256
|
||||
#define __NR_amd64_openat 257
|
||||
#define __NR_amd64_mkdirat 258
|
||||
#define __NR_amd64_mknodat 259
|
||||
#define __NR_amd64_fchownat 260
|
||||
#define __NR_amd64_futimesat 261
|
||||
#define __NR_amd64_newfstatat 262
|
||||
#define __NR_amd64_unlinkat 263
|
||||
#define __NR_amd64_renameat 264
|
||||
#define __NR_amd64_linkat 265
|
||||
#define __NR_amd64_symlinkat 266
|
||||
#define __NR_amd64_readlinkat 267
|
||||
#define __NR_amd64_fchmodat 268
|
||||
#define __NR_amd64_faccessat 269
|
||||
#define __NR_amd64_pselect6 270
|
||||
#define __NR_amd64_ppoll 271
|
||||
#define __NR_amd64_unshare 272
|
||||
#define __NR_amd64_set_robust_list 273
|
||||
#define __NR_amd64_get_robust_list 274
|
||||
#define __NR_amd64_splice 275
|
||||
#define __NR_amd64_tee 276
|
||||
#define __NR_amd64_sync_file_range 277
|
||||
#define __NR_amd64_vmsplice 278
|
||||
#define __NR_amd64_move_pages 279
|
||||
#define __NR_amd64_utimensat 280
|
||||
#define __NR_amd64_epoll_pwait 281
|
||||
#define __NR_amd64_signalfd 282
|
||||
#define __NR_amd64_timerfd_create 283
|
||||
#define __NR_amd64_eventfd 284
|
||||
#define __NR_amd64_fallocate 285
|
||||
#define __NR_amd64_timerfd_settime 286
|
||||
#define __NR_amd64_timerfd_gettime 287
|
||||
#define __NR_amd64_accept4 288
|
||||
#define __NR_amd64_signalfd4 289
|
||||
#define __NR_amd64_eventfd2 290
|
||||
#define __NR_amd64_epoll_create1 291
|
||||
#define __NR_amd64_dup3 292
|
||||
#define __NR_amd64_pipe2 293
|
||||
#define __NR_amd64_inotify_init1 294
|
||||
#define __NR_amd64_preadv 295
|
||||
#define __NR_amd64_pwritev 296
|
||||
#define __NR_amd64_rt_tgsigqueueinfo 297
|
||||
#define __NR_amd64_perf_event_open 298
|
||||
#define __NR_amd64_recvmmsg 299
|
||||
#define __NR_amd64_fanotify_init 300
|
||||
#define __NR_amd64_fanotify_mark 301
|
||||
#define __NR_amd64_prlimit64 302
|
||||
#define __NR_amd64_name_to_handle_at 303
|
||||
#define __NR_amd64_open_by_handle_at 304
|
||||
#define __NR_amd64_clock_adjtime 305
|
||||
#define __NR_amd64_syncfs 306
|
||||
#define __NR_amd64_sendmmsg 307
|
||||
#define __NR_amd64_setns 308
|
||||
#define __NR_amd64_getcpu 309
|
||||
#define __NR_amd64_process_vm_readv 310
|
||||
#define __NR_amd64_process_vm_writev 311
|
||||
#define __NR_amd64_kcmp 312
|
||||
#define __NR_amd64_finit_module 313
|
||||
#define __NR_amd64_sched_setattr 314
|
||||
#define __NR_amd64_sched_getattr 315
|
||||
#define __NR_amd64_renameat2 316
|
||||
#define __NR_amd64_seccomp 317
|
||||
#define __NR_amd64_getrandom 318
|
||||
#define __NR_amd64_memfd_create 319
|
||||
#define __NR_amd64_kexec_file_load 320
|
||||
#define __NR_amd64_bpf 321
|
||||
#define __NR_amd64_execveat 322
|
||||
#define __NR_amd64_userfaultfd 323
|
||||
#define __NR_amd64_membarrier 324
|
||||
#define __NR_amd64_mlock2 325
|
||||
#define __NR_amd64_copy_file_range 326
|
||||
#define __NR_amd64_preadv2 327
|
||||
#define __NR_amd64_pwritev2 328
|
||||
#define __NR_amd64_pkey_mprotect 329
|
||||
#define __NR_amd64_pkey_alloc 330
|
||||
#define __NR_amd64_pkey_free 331
|
||||
#define __NR_amd64_statx 332
|
||||
#define __NR_amd64_io_pgetevents 333
|
||||
#define __NR_amd64_rseq 334
|
||||
#define __NR_amd64_pidfd_send_signal 424
|
||||
#define __NR_amd64_io_uring_setup 425
|
||||
#define __NR_amd64_io_uring_enter 426
|
||||
#define __NR_amd64_io_uring_register 427
|
||||
#define __NR_amd64_open_tree 428
|
||||
#define __NR_amd64_move_mount 429
|
||||
#define __NR_amd64_fsopen 430
|
||||
#define __NR_amd64_fsconfig 431
|
||||
#define __NR_amd64_fsmount 432
|
||||
#define __NR_amd64_fspick 433
|
||||
#define __NR_amd64_pidfd_open 434
|
||||
#define __NR_amd64_clone3 435
|
||||
#define __NR_amd64_close_range 436
|
||||
#define __NR_amd64_openat2 437
|
||||
#define __NR_amd64_pidfd_getfd 438
|
||||
#define __NR_amd64_faccessat2 439
|
||||
#define __NR_amd64_process_madvise 440
|
||||
#define __NR_amd64_epoll_pwait2 441
|
||||
#define __NR_amd64_mount_setattr 442
|
||||
#define __NR_amd64_landlock_create_ruleset 444
|
||||
#define __NR_amd64_landlock_add_rule 445
|
||||
#define __NR_amd64_landlock_restrict_self 446
|
||||
|
||||
#endif // !__FENNIX_KERNEL_LINUX_SYSCALLS_x64_H__
|
459
include/syscall/linux/syscalls_i386.hpp
Normal file
459
include/syscall/linux/syscalls_i386.hpp
Normal file
@ -0,0 +1,459 @@
|
||||
/*
|
||||
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_LINUX_SYSCALLS_I386_H__
|
||||
#define __FENNIX_KERNEL_LINUX_SYSCALLS_I386_H__
|
||||
|
||||
#define __NR_i386_restart_syscall 0
|
||||
#define __NR_i386_exit 1
|
||||
#define __NR_i386_fork 2
|
||||
#define __NR_i386_read 3
|
||||
#define __NR_i386_write 4
|
||||
#define __NR_i386_open 5
|
||||
#define __NR_i386_close 6
|
||||
#define __NR_i386_waitpid 7
|
||||
#define __NR_i386_creat 8
|
||||
#define __NR_i386_link 9
|
||||
#define __NR_i386_unlink 10
|
||||
#define __NR_i386_execve 11
|
||||
#define __NR_i386_chdir 12
|
||||
#define __NR_i386_time 13
|
||||
#define __NR_i386_mknod 14
|
||||
#define __NR_i386_chmod 15
|
||||
#define __NR_i386_lchown 16
|
||||
#define __NR_i386_break 17
|
||||
#define __NR_i386_oldstat 18
|
||||
#define __NR_i386_lseek 19
|
||||
#define __NR_i386_getpid 20
|
||||
#define __NR_i386_mount 21
|
||||
#define __NR_i386_umount 22
|
||||
#define __NR_i386_setuid 23
|
||||
#define __NR_i386_getuid 24
|
||||
#define __NR_i386_stime 25
|
||||
#define __NR_i386_ptrace 26
|
||||
#define __NR_i386_alarm 27
|
||||
#define __NR_i386_oldfstat 28
|
||||
#define __NR_i386_pause 29
|
||||
#define __NR_i386_utime 30
|
||||
#define __NR_i386_stty 31
|
||||
#define __NR_i386_gtty 32
|
||||
#define __NR_i386_access 33
|
||||
#define __NR_i386_nice 34
|
||||
#define __NR_i386_ftime 35
|
||||
#define __NR_i386_sync 36
|
||||
#define __NR_i386_kill 37
|
||||
#define __NR_i386_rename 38
|
||||
#define __NR_i386_mkdir 39
|
||||
#define __NR_i386_rmdir 40
|
||||
#define __NR_i386_dup 41
|
||||
#define __NR_i386_pipe 42
|
||||
#define __NR_i386_times 43
|
||||
#define __NR_i386_prof 44
|
||||
#define __NR_i386_brk 45
|
||||
#define __NR_i386_setgid 46
|
||||
#define __NR_i386_getgid 47
|
||||
#define __NR_i386_signal 48
|
||||
#define __NR_i386_geteuid 49
|
||||
#define __NR_i386_getegid 50
|
||||
#define __NR_i386_acct 51
|
||||
#define __NR_i386_umount2 52
|
||||
#define __NR_i386_lock 53
|
||||
#define __NR_i386_ioctl 54
|
||||
#define __NR_i386_fcntl 55
|
||||
#define __NR_i386_mpx 56
|
||||
#define __NR_i386_setpgid 57
|
||||
#define __NR_i386_ulimit 58
|
||||
#define __NR_i386_oldolduname 59
|
||||
#define __NR_i386_umask 60
|
||||
#define __NR_i386_chroot 61
|
||||
#define __NR_i386_ustat 62
|
||||
#define __NR_i386_dup2 63
|
||||
#define __NR_i386_getppid 64
|
||||
#define __NR_i386_getpgrp 65
|
||||
#define __NR_i386_setsid 66
|
||||
#define __NR_i386_sigaction 67
|
||||
#define __NR_i386_sgetmask 68
|
||||
#define __NR_i386_ssetmask 69
|
||||
#define __NR_i386_setreuid 70
|
||||
#define __NR_i386_setregid 71
|
||||
#define __NR_i386_sigsuspend 72
|
||||
#define __NR_i386_sigpending 73
|
||||
#define __NR_i386_sethostname 74
|
||||
#define __NR_i386_setrlimit 75
|
||||
#define __NR_i386_getrlimit 76
|
||||
#define __NR_i386_getrusage 77
|
||||
#define __NR_i386_gettimeofday_time32 78
|
||||
#define __NR_i386_settimeofday_time32 79
|
||||
#define __NR_i386_getgroups 80
|
||||
#define __NR_i386_setgroups 81
|
||||
#define __NR_i386_select 82
|
||||
#define __NR_i386_symlink 83
|
||||
#define __NR_i386_oldlstat 84
|
||||
#define __NR_i386_readlink 85
|
||||
#define __NR_i386_uselib 86
|
||||
#define __NR_i386_swapon 87
|
||||
#define __NR_i386_reboot 88
|
||||
#define __NR_i386_readdir 89
|
||||
#define __NR_i386_mmap 90
|
||||
#define __NR_i386_munmap 91
|
||||
#define __NR_i386_truncate 92
|
||||
#define __NR_i386_ftruncate 93
|
||||
#define __NR_i386_fchmod 94
|
||||
#define __NR_i386_fchown 95
|
||||
#define __NR_i386_getpriority 96
|
||||
#define __NR_i386_setpriority 97
|
||||
#define __NR_i386_profil 98
|
||||
#define __NR_i386_statfs 99
|
||||
#define __NR_i386_fstatfs 100
|
||||
#define __NR_i386_ioperm 101
|
||||
#define __NR_i386_socketcall 102
|
||||
#define __NR_i386_syslog 103
|
||||
#define __NR_i386_setitimer 104
|
||||
#define __NR_i386_getitimer 105
|
||||
#define __NR_i386_stat 106
|
||||
#define __NR_i386_lstat 107
|
||||
#define __NR_i386_fstat 108
|
||||
#define __NR_i386_olduname 109
|
||||
#define __NR_i386_iopl 110
|
||||
#define __NR_i386_vhangup 111
|
||||
#define __NR_i386_idle 112
|
||||
#define __NR_i386_vm86old 113
|
||||
#define __NR_i386_wait4 114
|
||||
#define __NR_i386_swapoff 115
|
||||
#define __NR_i386_sysinfo 116
|
||||
#define __NR_i386_ipc 117
|
||||
#define __NR_i386_fsync 118
|
||||
#define __NR_i386_sigreturn 119
|
||||
#define __NR_i386_clone 120
|
||||
#define __NR_i386_setdomainname 121
|
||||
#define __NR_i386_uname 122
|
||||
#define __NR_i386_modify_ldt 123
|
||||
#define __NR_i386_adjtimex 124
|
||||
#define __NR_i386_mprotect 125
|
||||
#define __NR_i386_sigprocmask 126
|
||||
#define __NR_i386_create_module 127
|
||||
#define __NR_i386_init_module 128
|
||||
#define __NR_i386_delete_module 129
|
||||
#define __NR_i386_get_kernel_syms 130
|
||||
#define __NR_i386_quotactl 131
|
||||
#define __NR_i386_getpgid 132
|
||||
#define __NR_i386_fchdir 133
|
||||
#define __NR_i386_bdflush 134
|
||||
#define __NR_i386_sysfs 135
|
||||
#define __NR_i386_personality 136
|
||||
#define __NR_i386_afs_syscall 137
|
||||
#define __NR_i386_setfsuid 138
|
||||
#define __NR_i386_setfsgid 139
|
||||
#define __NR_i386__llseek 140
|
||||
#define __NR_i386_getdents 141
|
||||
#define __NR_i386__newselect 142
|
||||
#define __NR_i386_flock 143
|
||||
#define __NR_i386_msync 144
|
||||
#define __NR_i386_readv 145
|
||||
#define __NR_i386_writev 146
|
||||
#define __NR_i386_getsid 147
|
||||
#define __NR_i386_fdatasync 148
|
||||
#define __NR_i386__sysctl 149
|
||||
#define __NR_i386_mlock 150
|
||||
#define __NR_i386_munlock 151
|
||||
#define __NR_i386_mlockall 152
|
||||
#define __NR_i386_munlockall 153
|
||||
#define __NR_i386_sched_setparam 154
|
||||
#define __NR_i386_sched_getparam 155
|
||||
#define __NR_i386_sched_setscheduler 156
|
||||
#define __NR_i386_sched_getscheduler 157
|
||||
#define __NR_i386_sched_yield 158
|
||||
#define __NR_i386_sched_get_priority_max 159
|
||||
#define __NR_i386_sched_get_priority_min 160
|
||||
#define __NR_i386_sched_rr_get_interval 161
|
||||
#define __NR_i386_nanosleep 162
|
||||
#define __NR_i386_mremap 163
|
||||
#define __NR_i386_setresuid 164
|
||||
#define __NR_i386_getresuid 165
|
||||
#define __NR_i386_vm86 166
|
||||
#define __NR_i386_query_module 167
|
||||
#define __NR_i386_poll 168
|
||||
#define __NR_i386_nfsservctl 169
|
||||
#define __NR_i386_setresgid 170
|
||||
#define __NR_i386_getresgid 171
|
||||
#define __NR_i386_prctl 172
|
||||
#define __NR_i386_rt_sigreturn 173
|
||||
#define __NR_i386_rt_sigaction 174
|
||||
#define __NR_i386_rt_sigprocmask 175
|
||||
#define __NR_i386_rt_sigpending 176
|
||||
#define __NR_i386_rt_sigtimedwait 177
|
||||
#define __NR_i386_rt_sigqueueinfo 178
|
||||
#define __NR_i386_rt_sigsuspend 179
|
||||
#define __NR_i386_pread64 180
|
||||
#define __NR_i386_pwrite64 181
|
||||
#define __NR_i386_chown 182
|
||||
#define __NR_i386_getcwd 183
|
||||
#define __NR_i386_capget 184
|
||||
#define __NR_i386_capset 185
|
||||
#define __NR_i386_sigaltstack 186
|
||||
#define __NR_i386_sendfile 187
|
||||
#define __NR_i386_getpmsg 188
|
||||
#define __NR_i386_putpmsg 189
|
||||
#define __NR_i386_vfork 190
|
||||
#define __NR_i386_ugetrlimit 191
|
||||
#define __NR_i386_mmap2 192
|
||||
#define __NR_i386_truncate64 193
|
||||
#define __NR_i386_ftruncate64 194
|
||||
#define __NR_i386_stat64 195
|
||||
#define __NR_i386_lstat64 196
|
||||
#define __NR_i386_fstat64 197
|
||||
#define __NR_i386_lchown32 198
|
||||
#define __NR_i386_getuid32 199
|
||||
#define __NR_i386_getgid32 200
|
||||
#define __NR_i386_geteuid32 201
|
||||
#define __NR_i386_getegid32 202
|
||||
#define __NR_i386_setreuid32 203
|
||||
#define __NR_i386_setregid32 204
|
||||
#define __NR_i386_getgroups32 205
|
||||
#define __NR_i386_setgroups32 206
|
||||
#define __NR_i386_fchown32 207
|
||||
#define __NR_i386_setresuid32 208
|
||||
#define __NR_i386_getresuid32 209
|
||||
#define __NR_i386_setresgid32 210
|
||||
#define __NR_i386_getresgid32 211
|
||||
#define __NR_i386_chown32 212
|
||||
#define __NR_i386_setuid32 213
|
||||
#define __NR_i386_setgid32 214
|
||||
#define __NR_i386_setfsuid32 215
|
||||
#define __NR_i386_setfsgid32 216
|
||||
#define __NR_i386_pivot_root 217
|
||||
#define __NR_i386_mincore 218
|
||||
#define __NR_i386_madvise 219
|
||||
#define __NR_i386_getdents64 220
|
||||
#define __NR_i386_fcntl64 221
|
||||
#define __NR_i386_gettid 224
|
||||
#define __NR_i386_readahead 225
|
||||
#define __NR_i386_setxattr 226
|
||||
#define __NR_i386_lsetxattr 227
|
||||
#define __NR_i386_fsetxattr 228
|
||||
#define __NR_i386_getxattr 229
|
||||
#define __NR_i386_lgetxattr 230
|
||||
#define __NR_i386_fgetxattr 231
|
||||
#define __NR_i386_listxattr 232
|
||||
#define __NR_i386_llistxattr 233
|
||||
#define __NR_i386_flistxattr 234
|
||||
#define __NR_i386_removexattr 235
|
||||
#define __NR_i386_lremovexattr 236
|
||||
#define __NR_i386_fremovexattr 237
|
||||
#define __NR_i386_tkill 238
|
||||
#define __NR_i386_sendfile64 239
|
||||
#define __NR_i386_futex 240
|
||||
#define __NR_i386_sched_setaffinity 241
|
||||
#define __NR_i386_sched_getaffinity 242
|
||||
#define __NR_i386_set_thread_area 243
|
||||
#define __NR_i386_get_thread_area 244
|
||||
#define __NR_i386_io_setup 245
|
||||
#define __NR_i386_io_destroy 246
|
||||
#define __NR_i386_io_getevents 247
|
||||
#define __NR_i386_io_submit 248
|
||||
#define __NR_i386_io_cancel 249
|
||||
#define __NR_i386_fadvise64 250
|
||||
#define __NR_i386_set_zone_reclaim 251 /* removed in 2.6.16 */
|
||||
#define __NR_i386_exit_group 252
|
||||
#define __NR_i386_lookup_dcookie 253
|
||||
#define __NR_i386_epoll_create 254
|
||||
#define __NR_i386_epoll_ctl 255
|
||||
#define __NR_i386_epoll_wait 256
|
||||
#define __NR_i386_remap_file_pages 257
|
||||
#define __NR_i386_set_tid_address 258
|
||||
#define __NR_i386_timer_create 259
|
||||
#define __NR_i386_timer_settime32 260
|
||||
#define __NR_i386_timer_gettime32 261
|
||||
#define __NR_i386_timer_getoverrun 262
|
||||
#define __NR_i386_timer_delete 263
|
||||
#define __NR_i386_clock_settime32 264
|
||||
#define __NR_i386_clock_gettime32 265
|
||||
#define __NR_i386_clock_getres_time32 266
|
||||
#define __NR_i386_clock_nanosleep_time32 267
|
||||
#define __NR_i386_statfs64 268
|
||||
#define __NR_i386_fstatfs64 269
|
||||
#define __NR_i386_tgkill 270
|
||||
#define __NR_i386_utimes 271
|
||||
#define __NR_i386_fadvise64_64 272
|
||||
#define __NR_i386_vserver 273
|
||||
#define __NR_i386_mbind 274
|
||||
#define __NR_i386_get_mempolicy 275
|
||||
#define __NR_i386_set_mempolicy 276
|
||||
#define __NR_i386_mq_open 277
|
||||
#define __NR_i386_mq_unlink 278
|
||||
#define __NR_i386_mq_timedsend 279
|
||||
#define __NR_i386_mq_timedreceive 280
|
||||
#define __NR_i386_mq_notify 281
|
||||
#define __NR_i386_mq_getsetattr 282
|
||||
#define __NR_i386_kexec_load 283
|
||||
#define __NR_i386_waitid 284
|
||||
#define __NR_i386_sys_setaltroot 285
|
||||
#define __NR_i386_add_key 286
|
||||
#define __NR_i386_request_key 287
|
||||
#define __NR_i386_keyctl 288
|
||||
#define __NR_i386_ioprio_set 289
|
||||
#define __NR_i386_ioprio_get 290
|
||||
#define __NR_i386_inotify_init 291
|
||||
#define __NR_i386_inotify_add_watch 292
|
||||
#define __NR_i386_inotify_rm_watch 293
|
||||
#define __NR_i386_migrate_pages 294
|
||||
#define __NR_i386_openat 295
|
||||
#define __NR_i386_mkdirat 296
|
||||
#define __NR_i386_mknodat 297
|
||||
#define __NR_i386_fchownat 298
|
||||
#define __NR_i386_futimesat 299
|
||||
#define __NR_i386_fstatat64 300
|
||||
#define __NR_i386_unlinkat 301
|
||||
#define __NR_i386_renameat 302
|
||||
#define __NR_i386_linkat 303
|
||||
#define __NR_i386_symlinkat 304
|
||||
#define __NR_i386_readlinkat 305
|
||||
#define __NR_i386_fchmodat 306
|
||||
#define __NR_i386_faccessat 307
|
||||
#define __NR_i386_pselect6 308
|
||||
#define __NR_i386_ppoll 309
|
||||
#define __NR_i386_unshare 310
|
||||
#define __NR_i386_set_robust_list 311
|
||||
#define __NR_i386_get_robust_list 312
|
||||
#define __NR_i386_splice 313
|
||||
#define __NR_i386_sync_file_range 314
|
||||
#define __NR_i386_tee 315
|
||||
#define __NR_i386_vmsplice 316
|
||||
#define __NR_i386_move_pages 317
|
||||
#define __NR_i386_getcpu 318
|
||||
#define __NR_i386_epoll_pwait 319
|
||||
#define __NR_i386_utimensat 320
|
||||
#define __NR_i386_signalfd 321
|
||||
#define __NR_i386_timerfd_create 322
|
||||
#define __NR_i386_eventfd 323
|
||||
#define __NR_i386_fallocate 324
|
||||
#define __NR_i386_timerfd_settime32 325
|
||||
#define __NR_i386_timerfd_gettime32 326
|
||||
#define __NR_i386_signalfd4 327
|
||||
#define __NR_i386_eventfd2 328
|
||||
#define __NR_i386_epoll_create1 329
|
||||
#define __NR_i386_dup3 330
|
||||
#define __NR_i386_pipe2 331
|
||||
#define __NR_i386_inotify_init1 332
|
||||
#define __NR_i386_preadv 333
|
||||
#define __NR_i386_pwritev 334
|
||||
#define __NR_i386_rt_tgsigqueueinfo 335
|
||||
#define __NR_i386_perf_event_open 336
|
||||
#define __NR_i386_recvmmsg 337
|
||||
#define __NR_i386_fanotify_init 338
|
||||
#define __NR_i386_fanotify_mark 339
|
||||
#define __NR_i386_prlimit64 340
|
||||
#define __NR_i386_name_to_handle_at 341
|
||||
#define __NR_i386_open_by_handle_at 342
|
||||
#define __NR_i386_clock_adjtime 343
|
||||
#define __NR_i386_syncfs 344
|
||||
#define __NR_i386_sendmmsg 345
|
||||
#define __NR_i386_setns 346
|
||||
#define __NR_i386_process_vm_readv 347
|
||||
#define __NR_i386_process_vm_writev 348
|
||||
#define __NR_i386_kcmp 349
|
||||
#define __NR_i386_finit_module 350
|
||||
#define __NR_i386_sched_setattr 351
|
||||
#define __NR_i386_sched_getattr 352
|
||||
#define __NR_i386_renameat2 353
|
||||
#define __NR_i386_seccomp 354
|
||||
#define __NR_i386_getrandom 355
|
||||
#define __NR_i386_memfd_create 356
|
||||
#define __NR_i386_bpf 357
|
||||
#define __NR_i386_execveat 358
|
||||
#define __NR_i386_socket 359
|
||||
#define __NR_i386_socketpair 360
|
||||
#define __NR_i386_bind 361
|
||||
#define __NR_i386_connect 362
|
||||
#define __NR_i386_listen 363
|
||||
#define __NR_i386_accept4 364
|
||||
#define __NR_i386_getsockopt 365
|
||||
#define __NR_i386_setsockopt 366
|
||||
#define __NR_i386_getsockname 367
|
||||
#define __NR_i386_getpeername 368
|
||||
#define __NR_i386_sendto 369
|
||||
#define __NR_i386_sendmsg 370
|
||||
#define __NR_i386_recvfrom 371
|
||||
#define __NR_i386_recvmsg 372
|
||||
#define __NR_i386_shutdown 373
|
||||
#define __NR_i386_userfaultfd 374
|
||||
#define __NR_i386_membarrier 375
|
||||
#define __NR_i386_mlock2 376
|
||||
#define __NR_i386_copy_file_range 377
|
||||
#define __NR_i386_preadv2 378
|
||||
#define __NR_i386_pwritev2 379
|
||||
#define __NR_i386_pkey_mprotect 380
|
||||
#define __NR_i386_pkey_alloc 381
|
||||
#define __NR_i386_pkey_free 382
|
||||
#define __NR_i386_statx 383
|
||||
#define __NR_i386_arch_prctl 384
|
||||
#define __NR_i386_io_pgetevents 385
|
||||
#define __NR_i386_rseq 386
|
||||
#define __NR_i386_semget 393
|
||||
#define __NR_i386_semctl 394
|
||||
#define __NR_i386_shmget 395
|
||||
#define __NR_i386_shmctl 396
|
||||
#define __NR_i386_shmat 397
|
||||
#define __NR_i386_shmdt 398
|
||||
#define __NR_i386_msgget 399
|
||||
#define __NR_i386_msgsnd 400
|
||||
#define __NR_i386_msgrcv 401
|
||||
#define __NR_i386_msgctl 402
|
||||
#define __NR_i386_clock_gettime64 403
|
||||
#define __NR_i386_clock_settime64 404
|
||||
#define __NR_i386_clock_adjtime64 405
|
||||
#define __NR_i386_clock_getres_time64 406
|
||||
#define __NR_i386_clock_nanosleep_time64 407
|
||||
#define __NR_i386_timer_gettime64 408
|
||||
#define __NR_i386_timer_settime64 409
|
||||
#define __NR_i386_timerfd_gettime64 410
|
||||
#define __NR_i386_timerfd_settime64 411
|
||||
#define __NR_i386_utimensat_time64 412
|
||||
#define __NR_i386_pselect6_time64 413
|
||||
#define __NR_i386_ppoll_time64 414
|
||||
#define __NR_i386_io_pgetevents_time64 416
|
||||
#define __NR_i386_recvmmsg_time64 417
|
||||
#define __NR_i386_mq_timedsend_time64 418
|
||||
#define __NR_i386_mq_timedreceive_time64 419
|
||||
#define __NR_i386_semtimedop_time64 420
|
||||
#define __NR_i386_rt_sigtimedwait_time64 421
|
||||
#define __NR_i386_futex_time64 422
|
||||
#define __NR_i386_sched_rr_get_interval_time64 423
|
||||
#define __NR_i386_pidfd_send_signal 424
|
||||
#define __NR_i386_io_uring_setup 425
|
||||
#define __NR_i386_io_uring_enter 426
|
||||
#define __NR_i386_io_uring_register 427
|
||||
#define __NR_i386_open_tree 428
|
||||
#define __NR_i386_move_mount 429
|
||||
#define __NR_i386_fsopen 430
|
||||
#define __NR_i386_fsconfig 431
|
||||
#define __NR_i386_fsmount 432
|
||||
#define __NR_i386_fspick 433
|
||||
#define __NR_i386_pidfd_open 434
|
||||
#define __NR_i386_clone3 435
|
||||
#define __NR_i386_close_range 436
|
||||
#define __NR_i386_openat2 437
|
||||
#define __NR_i386_pidfd_getfd 438
|
||||
#define __NR_i386_faccessat2 439
|
||||
#define __NR_i386_process_madvise 440
|
||||
#define __NR_i386_epoll_pwait2 441
|
||||
#define __NR_i386_mount_setattr 442
|
||||
#define __NR_i386_landlock_create_ruleset 444
|
||||
#define __NR_i386_landlock_add_rule 445
|
||||
#define __NR_i386_landlock_restrict_self 446
|
||||
|
||||
#endif // !__FENNIX_KERNEL_LINUX_SYSCALLS_I386_H__
|
@ -23,46 +23,47 @@
|
||||
typedef struct SyscallsFrame
|
||||
{
|
||||
#if defined(a64)
|
||||
uint64_t r15;
|
||||
uint64_t r14;
|
||||
uint64_t r13;
|
||||
uint64_t r12;
|
||||
uint64_t r11;
|
||||
uint64_t r10;
|
||||
uint64_t r9;
|
||||
uint64_t r8;
|
||||
uint64_t rbp;
|
||||
uint64_t rdi;
|
||||
uint64_t rsi;
|
||||
uint64_t rdx;
|
||||
uint64_t rcx;
|
||||
uint64_t rbx;
|
||||
uint64_t rax;
|
||||
uint64_t r15;
|
||||
uint64_t r14;
|
||||
uint64_t r13;
|
||||
uint64_t r12;
|
||||
uint64_t r11;
|
||||
uint64_t r10;
|
||||
uint64_t r9;
|
||||
uint64_t r8;
|
||||
uint64_t rbp;
|
||||
uint64_t rdi;
|
||||
uint64_t rsi;
|
||||
uint64_t rdx;
|
||||
uint64_t rcx;
|
||||
uint64_t rbx;
|
||||
uint64_t rax;
|
||||
|
||||
uint64_t ReturnAddress;
|
||||
uint64_t CodeSegment;
|
||||
uint64_t Flags;
|
||||
uint64_t StackPointer;
|
||||
uint64_t StackSegment;
|
||||
uint64_t ReturnAddress;
|
||||
uint64_t CodeSegment;
|
||||
uint64_t Flags;
|
||||
uint64_t StackPointer;
|
||||
uint64_t StackSegment;
|
||||
#elif defined(a32)
|
||||
uint32_t ebp;
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t edx;
|
||||
uint32_t ecx;
|
||||
uint32_t ebx;
|
||||
uint32_t eax;
|
||||
uint32_t ebp;
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t edx;
|
||||
uint32_t ecx;
|
||||
uint32_t ebx;
|
||||
uint32_t eax;
|
||||
|
||||
uint32_t ReturnAddress;
|
||||
uint32_t CodeSegment;
|
||||
uint32_t Flags;
|
||||
uint32_t StackPointer;
|
||||
uint32_t StackSegment;
|
||||
uint32_t ReturnAddress;
|
||||
uint32_t CodeSegment;
|
||||
uint32_t Flags;
|
||||
uint32_t StackPointer;
|
||||
uint32_t StackSegment;
|
||||
#elif defined(aa64)
|
||||
uint32_t ReturnAddress;
|
||||
uint32_t StackPointer;
|
||||
uint32_t ReturnAddress;
|
||||
uint32_t StackPointer;
|
||||
#endif
|
||||
} SyscallsFrame;
|
||||
#define SysFrm SyscallsFrame
|
||||
|
||||
uintptr_t HandleNativeSyscalls(SyscallsFrame *Frame);
|
||||
uintptr_t HandleLinuxSyscalls(SyscallsFrame *Frame);
|
||||
|
@ -23,7 +23,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void targp_parse(const char *cmd, char **argv, int *argc);
|
||||
void targp_parse(const char *cmd, char **argv, int *argc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
189
include/task.hpp
189
include/task.hpp
@ -23,13 +23,14 @@
|
||||
#include <filesystem.hpp>
|
||||
#include <symbols.hpp>
|
||||
#include <memory.hpp>
|
||||
#include <signal.hpp>
|
||||
#include <ints.hpp>
|
||||
#include <ipc.hpp>
|
||||
#include <debug.h>
|
||||
#include <cwalk.h>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <abi.h>
|
||||
#include <list>
|
||||
|
||||
namespace Tasking
|
||||
{
|
||||
@ -39,9 +40,9 @@ namespace Tasking
|
||||
/** Instruction Pointer */
|
||||
typedef __UINTPTR_TYPE__ IP;
|
||||
/** Process ID */
|
||||
typedef int PID;
|
||||
typedef pid_t PID;
|
||||
/** Thread ID */
|
||||
typedef int TID;
|
||||
typedef pid_t TID;
|
||||
|
||||
enum TaskArchitecture
|
||||
{
|
||||
@ -77,48 +78,54 @@ namespace Tasking
|
||||
_ExecuteModeMax = User
|
||||
};
|
||||
|
||||
enum TaskState : int
|
||||
enum TaskState : short
|
||||
{
|
||||
UnknownStatus,
|
||||
|
||||
/**
|
||||
* Task ready to be scheduled
|
||||
* Ready
|
||||
*
|
||||
* Used when the task is ready
|
||||
* to be scheduled
|
||||
*/
|
||||
Ready,
|
||||
|
||||
/**
|
||||
* Task is the current running task
|
||||
* Running
|
||||
*
|
||||
* Used when the task is running
|
||||
* on the CPU
|
||||
*/
|
||||
Running,
|
||||
|
||||
/**
|
||||
* Task is sleeping
|
||||
*
|
||||
* Used when the task is waiting for
|
||||
* a specific amount of time to pass
|
||||
* Sleeping
|
||||
*
|
||||
* Used when the task is sleeping
|
||||
* for a given amount of time
|
||||
*/
|
||||
Sleeping,
|
||||
|
||||
/**
|
||||
* Task is blocked
|
||||
*
|
||||
* Used when the task is waiting for
|
||||
* another task to finish or for an
|
||||
* event to occur
|
||||
* Blocked
|
||||
*
|
||||
* Used when the task is blocked
|
||||
* by another task or until an
|
||||
* event occurs
|
||||
*/
|
||||
Blocked,
|
||||
|
||||
/**
|
||||
* Task is stopped
|
||||
*
|
||||
* Stopped
|
||||
*
|
||||
* Used when the task is stopped
|
||||
* by the debugger or by the user
|
||||
* by the user
|
||||
*/
|
||||
Stopped,
|
||||
|
||||
/**
|
||||
* Task is waiting
|
||||
*
|
||||
* Waiting
|
||||
*
|
||||
* Used when the task is not ready
|
||||
* to be scheduled by implementation
|
||||
* e.g. Creating a separate page table
|
||||
@ -127,8 +134,8 @@ namespace Tasking
|
||||
Waiting,
|
||||
|
||||
/**
|
||||
* Task is a zombie
|
||||
*
|
||||
* Zombie
|
||||
*
|
||||
* Used when the task is waiting
|
||||
* for the parent to read the exit
|
||||
* code
|
||||
@ -136,8 +143,17 @@ namespace Tasking
|
||||
Zombie,
|
||||
|
||||
/**
|
||||
* Task is terminated
|
||||
*
|
||||
* Core Dump
|
||||
*
|
||||
* Used when the task is waiting
|
||||
* for the parent to read the core
|
||||
* dump
|
||||
*/
|
||||
CoreDump,
|
||||
|
||||
/**
|
||||
* Terminated
|
||||
*
|
||||
* Used when the task is terminated
|
||||
* and is waiting to be cleaned up
|
||||
* by the scheduler
|
||||
@ -161,7 +177,7 @@ namespace Tasking
|
||||
_PriorityMax = Critical
|
||||
};
|
||||
|
||||
enum KillErrorCodes : int
|
||||
enum KillCode : int
|
||||
{
|
||||
KILL_SCHEDULER_DESTRUCTION = -0xFFFF,
|
||||
KILL_CXXABI_EXCEPTION = -0xECE97,
|
||||
@ -188,6 +204,36 @@ namespace Tasking
|
||||
cwk_path_style PathStyle = CWK_STYLE_UNIX;
|
||||
};
|
||||
|
||||
struct ThreadLocalStorage
|
||||
{
|
||||
/**
|
||||
* Physical base address of the
|
||||
* TLS segment with the data
|
||||
*/
|
||||
uintptr_t pBase;
|
||||
|
||||
/**
|
||||
* Virtual base where the TLS
|
||||
* segment should be mapped
|
||||
*/
|
||||
uintptr_t vBase;
|
||||
|
||||
/**
|
||||
* Alignment of the TLS segment
|
||||
*/
|
||||
uintptr_t Align;
|
||||
|
||||
/**
|
||||
* Size of the TLS segment
|
||||
*/
|
||||
uintptr_t Size;
|
||||
|
||||
/**
|
||||
* File size of the TLS segment
|
||||
*/
|
||||
uintptr_t fSize;
|
||||
};
|
||||
|
||||
/**
|
||||
* TCB struct for gs register
|
||||
*/
|
||||
@ -246,6 +292,12 @@ namespace Tasking
|
||||
const char **envp,
|
||||
const std::vector<AuxiliaryVector> &auxv);
|
||||
|
||||
/**
|
||||
* This function should be called after
|
||||
* GS and FS are set up
|
||||
*/
|
||||
void SetupThreadLocalStorage();
|
||||
|
||||
public:
|
||||
class Task *GetContext() { return ctx; }
|
||||
|
||||
@ -258,8 +310,6 @@ namespace Tasking
|
||||
/* Statuses */
|
||||
std::atomic_int ExitCode;
|
||||
std::atomic<TaskState> State = TaskState::Waiting;
|
||||
std::atomic_bool KeepInMemory = false;
|
||||
std::atomic_size_t KeepTime = 0;
|
||||
int ErrorNumber;
|
||||
|
||||
/* Memory */
|
||||
@ -271,12 +321,11 @@ namespace Tasking
|
||||
CPU::x64::TrapFrame Registers{};
|
||||
uintptr_t ShadowGSBase, GSBase, FSBase;
|
||||
#elif defined(a32)
|
||||
CPU::x32::TrapFrame Registers; // TODO
|
||||
CPU::x32::TrapFrame Registers{};
|
||||
uintptr_t ShadowGSBase, GSBase, FSBase;
|
||||
#elif defined(aa64)
|
||||
uintptr_t Registers; // TODO
|
||||
#endif
|
||||
uintptr_t IPHistory[128];
|
||||
__aligned(16) CPU::x64::FXState FPU;
|
||||
|
||||
/* Info & Security info */
|
||||
@ -288,6 +337,7 @@ namespace Tasking
|
||||
bool IsKernelDebugEnabled = false;
|
||||
} Security{};
|
||||
TaskInfo Info{};
|
||||
ThreadLocalStorage TLS{};
|
||||
|
||||
/* Compatibility structures */
|
||||
struct
|
||||
@ -296,6 +346,9 @@ namespace Tasking
|
||||
int *clear_child_tid{};
|
||||
} Linux{};
|
||||
|
||||
int SendSignal(int sig);
|
||||
void SetState(TaskState state);
|
||||
void SetExitCode(int code);
|
||||
void Rename(const char *name);
|
||||
void SetPriority(TaskPriority priority);
|
||||
int GetExitCode() { return ExitCode.load(); }
|
||||
@ -303,7 +356,6 @@ namespace Tasking
|
||||
void SetDebugMode(bool Enable);
|
||||
void SetKernelDebugMode(bool Enable);
|
||||
size_t GetSize();
|
||||
|
||||
void Block() { State.store(TaskState::Blocked); }
|
||||
void Unblock() { State.store(TaskState::Ready); }
|
||||
|
||||
@ -328,7 +380,7 @@ namespace Tasking
|
||||
~TCB();
|
||||
};
|
||||
|
||||
class PCB
|
||||
class PCB : public vfs::Node
|
||||
{
|
||||
private:
|
||||
class Task *ctx = nullptr;
|
||||
@ -355,8 +407,6 @@ namespace Tasking
|
||||
/* Statuses */
|
||||
std::atomic_int ExitCode;
|
||||
std::atomic<TaskState> State = Waiting;
|
||||
std::atomic_bool KeepInMemory = false;
|
||||
std::atomic_size_t KeepTime = 0;
|
||||
|
||||
/* Info & Security info */
|
||||
struct
|
||||
@ -372,30 +422,40 @@ namespace Tasking
|
||||
} Real, Effective;
|
||||
} Security{};
|
||||
TaskInfo Info{};
|
||||
ThreadLocalStorage TLS{};
|
||||
|
||||
/* Filesystem */
|
||||
Node *CurrentWorkingDirectory;
|
||||
Node *ProcessDirectory;
|
||||
Node *Executable;
|
||||
FileDescriptorTable *FileDescriptors;
|
||||
|
||||
/* stdio */
|
||||
Node *stdin;
|
||||
Node *stdout;
|
||||
Node *stderr;
|
||||
|
||||
/* Memory */
|
||||
Memory::PageTable *PageTable;
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
Memory::ProgramBreak *ProgramBreak;
|
||||
|
||||
/* Other */
|
||||
InterProcessCommunication::IPC *IPC;
|
||||
Signal *Signals;
|
||||
SymbolResolver::Symbols *ELFSymbolTable;
|
||||
|
||||
/* Threads & Children */
|
||||
std::vector<TCB *> Threads;
|
||||
std::vector<PCB *> Children;
|
||||
std::list<TCB *> Threads;
|
||||
std::list<PCB *> Children;
|
||||
|
||||
public:
|
||||
class Task *GetContext() { return ctx; }
|
||||
|
||||
int SendSignal(int sig);
|
||||
void SetState(TaskState state);
|
||||
void SetExitCode(int code);
|
||||
void Rename(const char *name);
|
||||
void SetWorkingDirectory(Node *node);
|
||||
void SetExe(const char *path);
|
||||
size_t GetSize();
|
||||
|
||||
PCB(class Task *ctx,
|
||||
@ -403,7 +463,7 @@ namespace Tasking
|
||||
const char *Name,
|
||||
TaskExecutionMode ExecutionMode,
|
||||
void *Image = nullptr,
|
||||
bool DoNotCreatePageTable = false,
|
||||
bool UseKernelPageTable = false,
|
||||
uint16_t UserID = -1,
|
||||
uint16_t GroupID = -1);
|
||||
|
||||
@ -419,10 +479,10 @@ namespace Tasking
|
||||
PID NextPID = 0;
|
||||
TID NextTID = 0;
|
||||
|
||||
std::vector<PCB *> ProcessList;
|
||||
std::list<PCB *> ProcessList;
|
||||
PCB *KernelProcess = nullptr;
|
||||
PCB *IdleProcess = nullptr;
|
||||
TCB *IdleThread = nullptr;
|
||||
TCB *CleanupThread = nullptr;
|
||||
std::atomic_size_t SchedulerTicks = 0;
|
||||
std::atomic_size_t LastTaskTicks = 0;
|
||||
std::atomic_int LastCore = 0;
|
||||
@ -481,36 +541,24 @@ namespace Tasking
|
||||
*/
|
||||
void WakeUpThreads();
|
||||
|
||||
#if defined(a64)
|
||||
/**
|
||||
* @note This function is NOT thread safe
|
||||
*/
|
||||
void Schedule(CPU::x64::TrapFrame *Frame);
|
||||
void CleanupTerminated();
|
||||
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
#elif defined(a32)
|
||||
/**
|
||||
* @note This function is NOT thread safe
|
||||
*/
|
||||
void Schedule(CPU::x32::TrapFrame *Frame);
|
||||
void Schedule(CPU::TrapFrame *Frame);
|
||||
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
#elif defined(aa64)
|
||||
/**
|
||||
* @note This function is NOT thread safe
|
||||
*/
|
||||
void Schedule(CPU::aarch64::TrapFrame *Frame);
|
||||
|
||||
void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
#endif
|
||||
void OnInterruptReceived(CPU::TrapFrame *Frame) final;
|
||||
|
||||
public:
|
||||
void SetCleanupThread(TCB *Thread) { CleanupThread = Thread; }
|
||||
PCB *GetKernelProcess() { return KernelProcess; }
|
||||
size_t GetSchedulerTicks() { return SchedulerTicks.load(); }
|
||||
size_t GetLastTaskTicks() { return LastTaskTicks.load(); }
|
||||
int GetLastCore() { return LastCore.load(); }
|
||||
std::vector<PCB *> GetProcessList() { return ProcessList; }
|
||||
void CleanupProcessesThread();
|
||||
std::list<PCB *> GetProcessList() { return ProcessList; }
|
||||
void Panic() { StopScheduler = true; }
|
||||
bool IsPanic() { return StopScheduler; }
|
||||
|
||||
@ -542,18 +590,18 @@ namespace Tasking
|
||||
|
||||
void SignalShutdown();
|
||||
|
||||
void KillThread(TCB *tcb, enum KillErrorCodes Code)
|
||||
void KillThread(TCB *tcb, enum KillCode Code)
|
||||
{
|
||||
tcb->State = TaskState::Terminated;
|
||||
tcb->ExitCode = (int)Code;
|
||||
tcb->SetState(TaskState::Terminated);
|
||||
tcb->SetExitCode(Code);
|
||||
debug("Killing thread %s(%d) with exit code %d",
|
||||
tcb->Name, tcb->ID, Code);
|
||||
}
|
||||
|
||||
void KillProcess(PCB *pcb, enum KillErrorCodes Code)
|
||||
void KillProcess(PCB *pcb, enum KillCode Code)
|
||||
{
|
||||
pcb->State = TaskState::Terminated;
|
||||
pcb->ExitCode = (int)Code;
|
||||
pcb->SetState(TaskState::Terminated);
|
||||
pcb->SetExitCode(Code);
|
||||
debug("Killing process %s(%d) with exit code %d",
|
||||
pcb->Name, pcb->ID, Code);
|
||||
}
|
||||
@ -594,7 +642,7 @@ namespace Tasking
|
||||
const char *Name,
|
||||
TaskExecutionMode TrustLevel,
|
||||
void *Image = nullptr,
|
||||
bool DoNotCreatePageTable = false,
|
||||
bool UseKernelPageTable = false,
|
||||
uint16_t UserID = UINT16_MAX,
|
||||
uint16_t GroupID = UINT16_MAX);
|
||||
|
||||
@ -607,6 +655,7 @@ namespace Tasking
|
||||
TaskCompatibility Compatibility = TaskCompatibility::Native,
|
||||
bool ThreadNotReady = false);
|
||||
|
||||
void StartScheduler();
|
||||
Task(const IP EntryPoint);
|
||||
~Task();
|
||||
|
||||
@ -615,11 +664,15 @@ namespace Tasking
|
||||
};
|
||||
}
|
||||
|
||||
#define thisProcess TaskManager->GetCurrentProcess()
|
||||
#define thisThread TaskManager->GetCurrentThread()
|
||||
/*
|
||||
If these macros are used,
|
||||
you have to add:
|
||||
"#include <smp.hpp>" too
|
||||
if necessary.
|
||||
*/
|
||||
|
||||
#define PEXIT(Code) thisProcess->ExitCode = Code
|
||||
#define TEXIT(Code) thisThread->ExitCode = Code
|
||||
#define thisProcess GetCurrentCPU()->CurrentProcess.load()
|
||||
#define thisThread GetCurrentCPU()->CurrentThread.load()
|
||||
|
||||
extern "C" void TaskingScheduler_OneShot(int TimeSlice);
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <types.h>
|
||||
#include <debug.h>
|
||||
#include <cassert>
|
||||
|
||||
namespace Time
|
||||
{
|
||||
@ -47,6 +48,38 @@ namespace Time
|
||||
Years
|
||||
};
|
||||
|
||||
/** @deprecated this shouldn't be used */
|
||||
inline uint64_t ConvertUnit(const Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
assert(!"Invalid time unit");
|
||||
}
|
||||
}
|
||||
|
||||
class HighPrecisionEventTimer
|
||||
{
|
||||
private:
|
||||
@ -67,38 +100,6 @@ namespace Time
|
||||
HPET *hpet = nullptr;
|
||||
uint64_t ClassCreationTime = 0;
|
||||
|
||||
inline uint64_t ConvertUnit(Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
error("Invalid time unit %d", Unit);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool Sleep(size_t Duration, Units Unit);
|
||||
uint64_t GetCounter();
|
||||
@ -115,38 +116,6 @@ namespace Time
|
||||
uint64_t clk = 0;
|
||||
uint64_t ClassCreationTime = 0;
|
||||
|
||||
inline uint64_t ConvertUnit(Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
error("Invalid time unit %d", Unit);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool Sleep(size_t Duration, Units Unit);
|
||||
uint64_t GetCounter();
|
||||
@ -198,5 +167,5 @@ namespace Time
|
||||
~time();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TIME_H__
|
||||
|
@ -212,6 +212,8 @@ typedef int64_t blkcnt64_t;
|
||||
typedef int64_t time_t;
|
||||
typedef unsigned uid_t;
|
||||
typedef unsigned gid_t;
|
||||
typedef long clock_t;
|
||||
typedef int pid_t;
|
||||
#elif defined(a32)
|
||||
typedef int32_t off_t;
|
||||
typedef long long off64_t;
|
||||
@ -226,6 +228,8 @@ 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 INT8_MAX __INT8_MAX__
|
||||
@ -323,15 +327,15 @@ typedef uint48_t uint_fast48_t;
|
||||
#endif // __INT48_TYPE__
|
||||
|
||||
#define b4(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4)
|
||||
#define b8(x) ((x)&0xFF)
|
||||
#define b8(x) ((x) & 0xFF)
|
||||
#define b16(x) __builtin_bswap16(x)
|
||||
#define b32(x) __builtin_bswap32(x)
|
||||
#define b48(x) (((((x)&0x0000000000ff) << 40) | \
|
||||
(((x)&0x00000000ff00) << 24) | \
|
||||
(((x)&0x000000ff0000) << 8) | \
|
||||
(((x)&0x0000ff000000) >> 8) | \
|
||||
(((x)&0x00ff00000000) >> 24) | \
|
||||
(((x)&0xff0000000000) >> 40)))
|
||||
#define b48(x) (((((x) & 0x0000000000ff) << 40) | \
|
||||
(((x) & 0x00000000ff00) << 24) | \
|
||||
(((x) & 0x000000ff0000) << 8) | \
|
||||
(((x) & 0x0000ff000000) >> 8) | \
|
||||
(((x) & 0x00ff00000000) >> 24) | \
|
||||
(((x) & 0xff0000000000) >> 40)))
|
||||
#define b64(x) __builtin_bswap64(x)
|
||||
|
||||
/* https://gcc.gnu.org/onlinedocs/gcc-9.5.0/gnat_ugn/Optimization-Levels.html */
|
||||
@ -401,6 +405,8 @@ typedef uint48_t uint_fast48_t;
|
||||
#define __synchronize __sync_synchronize()
|
||||
#define __sync __synchronize
|
||||
|
||||
#define __unreachable __builtin_unreachable()
|
||||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
@ -417,4 +423,10 @@ typedef uint48_t uint_fast48_t;
|
||||
: \
|
||||
: "memory")
|
||||
|
||||
#define StackPush(stack, type, value) \
|
||||
*((type *)--stack) = value;
|
||||
|
||||
#define StackPop(stack, type) \
|
||||
*((type *)stack++)
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TYPES_H__
|
||||
|
108
include/uart.hpp
108
include/uart.hpp
@ -22,67 +22,67 @@
|
||||
|
||||
namespace UniversalAsynchronousReceiverTransmitter
|
||||
{
|
||||
/**
|
||||
* @brief Serial ports. (if available)
|
||||
*/
|
||||
enum SerialPorts
|
||||
{
|
||||
COMNULL = 0,
|
||||
COM1 = 0x3F8,
|
||||
COM2 = 0x2F8,
|
||||
COM3 = 0x3E8,
|
||||
COM4 = 0x2E8,
|
||||
COM5 = 0x5F8,
|
||||
COM6 = 0x4F8,
|
||||
COM7 = 0x5E8,
|
||||
COM8 = 0x4E8
|
||||
};
|
||||
/**
|
||||
* @brief Serial ports. (if available)
|
||||
*/
|
||||
enum SerialPorts
|
||||
{
|
||||
COMNULL = 0,
|
||||
COM1 = 0x3F8,
|
||||
COM2 = 0x2F8,
|
||||
COM3 = 0x3E8,
|
||||
COM4 = 0x2E8,
|
||||
COM5 = 0x5F8,
|
||||
COM6 = 0x4F8,
|
||||
COM7 = 0x5E8,
|
||||
COM8 = 0x4E8
|
||||
};
|
||||
|
||||
class UART
|
||||
{
|
||||
private:
|
||||
SerialPorts Port;
|
||||
bool IsAvailable;
|
||||
class UART
|
||||
{
|
||||
private:
|
||||
SerialPorts Port;
|
||||
bool IsAvailable;
|
||||
|
||||
public:
|
||||
UART(SerialPorts Port = COMNULL);
|
||||
~UART();
|
||||
void Write(uint8_t Char);
|
||||
uint8_t Read();
|
||||
};
|
||||
public:
|
||||
UART(SerialPorts Port = COMNULL);
|
||||
~UART();
|
||||
void Write(uint8_t Char);
|
||||
uint8_t Read();
|
||||
};
|
||||
|
||||
class Events
|
||||
{
|
||||
private:
|
||||
SerialPorts Port;
|
||||
class Events
|
||||
{
|
||||
private:
|
||||
SerialPorts Port;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief UART events.
|
||||
* @param Port if none, all ports are registered for events.
|
||||
*/
|
||||
Events(SerialPorts Port = COMNULL);
|
||||
~Events();
|
||||
protected:
|
||||
/**
|
||||
* @brief UART events.
|
||||
* @param Port if none, all ports are registered for events.
|
||||
*/
|
||||
Events(SerialPorts Port = COMNULL);
|
||||
~Events();
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Get the Registered Port object
|
||||
* @return SerialPorts
|
||||
*/
|
||||
SafeFunction NIF SerialPorts GetRegisteredPort() { return this->Port; }
|
||||
public:
|
||||
/**
|
||||
* @brief Get the Registered Port object
|
||||
* @return SerialPorts
|
||||
*/
|
||||
SafeFunction NIF SerialPorts GetRegisteredPort() { return this->Port; }
|
||||
|
||||
/**
|
||||
* @brief Called when a character is sent.
|
||||
* @param Char the sent character.
|
||||
*/
|
||||
/**
|
||||
* @brief Called when a character is sent.
|
||||
* @param Char the sent character.
|
||||
*/
|
||||
|
||||
virtual void OnSent(uint8_t Char) { UNUSED(Char); }
|
||||
/**
|
||||
* @brief Called when a character is received.
|
||||
* @param Char the received character.
|
||||
*/
|
||||
virtual void OnReceived(uint8_t Char) { UNUSED(Char); }
|
||||
};
|
||||
virtual void OnSent(uint8_t Char) { UNUSED(Char); }
|
||||
/**
|
||||
* @brief Called when a character is received.
|
||||
* @param Char the received character.
|
||||
*/
|
||||
virtual void OnReceived(uint8_t Char) { UNUSED(Char); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user