feat: implemented errno, strtol. Started ustar. Reformatted headers and

code. Added some self-tests. Started prepwork for vfs.
This commit is contained in:
2021-03-14 21:14:22 +01:00
parent 586b8191b4
commit 77c8dca72a
39 changed files with 504 additions and 60 deletions

View File

@@ -0,0 +1,14 @@
//
// Created by rick on 03-02-21.
//
#ifndef NEW_KERNEL_IDE_H
#define NEW_KERNEL_IDE_H
#include <sys/types.h>
uint8_t ide_access(uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numsects, void *target);
void ide_print_devices();
#endif //NEW_KERNEL_IDE_H

View File

@@ -0,0 +1,243 @@
//
// Created by rick on 02-02-21.
//
#ifndef NEW_KERNEL_PCI_H
#define NEW_KERNEL_PCI_H
#include <sys/types.h>
#include <myke/driver.h>
#include <stdbool.h>
#include <myke/attributes.h>
#define PCI_CLASS_MASS_STORAGE 0x01
#define PCI_CLASS_BRIDGE 0x06
// class MASS STORAGE 0x01
#define PCI_SUB_CLASS_IDE 0x01
// class BRIDGE 0x06
#define PCI_SUB_CLASS_PCI_PCI_BRIDGE_4 0x04
#define PCI_SUB_CLASS_PCI_PCI_BRIDGE_9 0x09
#define PCI_REGISTER_OK 0
#define PCI_REGISTER_ERR_FULL (-1)
#define PCI_VALIDATE_OK 0
#define PCI_VALIDATE_FAIL 1
#define PCI_INIT_OK 0
#define PCI_INIT_FAIL 1
#define PCI_USE_OK 0
#define PCI_USE_FAIL 1
#define PCI_HEADER_TYPE_MULTI_FUNC 0x80
#define PCI_HEADER_TYPE_ENDPOINT 0x00
#define PCI_HEADER_TYPE_PCI_PCI_BRIDGE 0x01
#define PCI_HEADER_TYPE_PCI_CARDBUS_BRIDGE 0x02
#define PCI_CONFIG_VENDOR_ID 0x00
#define PCI_CONFIG_DEVICE_ID 0x02
#define PCI_CONFIG_COMMAND 0x04
#define PCI_CONFIG_STATUS 0x06
#define PCI_CONFIG_REVISION_ID 0x08
#define PCI_CONFIG_PROG_IF 0x09
#define PCI_CONFIG_SUBCLASS 0x0A
#define PCI_CONFIG_CLASS_CODE 0x0B
#define PCI_CONFIG_CACHE_LINE_SIZE 0x0C
#define PCI_CONFIG_LATENCY_TIMER 0x0D
#define PCI_CONFIG_HEADER_TYPE 0x0E
#define PCI_CONFIG_BIST 0x0F
#define PCI_CONFIG_BAR0 0x10
#define PCI_CONFIG_BAR1 0x14
#define PCI_CONFIG_BAR2 0x18
#define PCI_CONFIG_BAR3 0x1C
#define PCI_CONFIG_BAR4 0x20
#define PCI_CONFIG_BAR5 0x24
#define PCI_CONFIG_CARDBUS_CIS_P 0x28
#define PCI_CONFIG_SUBSYSTEM_VENDOR_ID 0x2C
#define PCI_CONFIG_SUBSYSTEM_ID 0x2E
#define PCI_CONFIG_EXPANSION_ROM_ADDR 0x30
#define PCI_CONFIG_CAP_POINTER 0x34
#define PCI_CONFIG_INTERRUPT_LINE 0x3C
#define PCI_CONFIG_INTERRUPT_PIN 0x3D
#define PCI_CONFIG_MAX_GRANT 0x3E
#define PCI_CONFIG_MAX_LATENCY 0x3F
// header type 1
#define PCI_CONFIG_PRIMARY_BUS_NUMBER 0x18
#define PCI_CONFIG_SECONDARY_BUS_NUMBER 0x19
#define PCI_CONFIG_SUBORDINATE_BUS_NUMBER 0x1A
#define PCI_CONFIG_SECONDARY_LATENCY_TIMER 0x1B
#define PCI_CONFIG_IO_BASE 0x1C
#define PCI_CONFIG_IO_LIMIT 0x1D
#define PCI_CONFIG_SECONDARY_STATUS 0x1E
#define PCI_CONFIG_MEMORY_BASE 0x20
#define PCI_CONFIG_MEMORY_LIMIT 0x22
#define PCI_CONFIG_MEMORY_BASE_UPPER 0x28
#define PCI_CONFIG_MEMORY_LIMIT_UPPER 0x2C
#define PCI_CONFIG_IO_BASE_UPPER 0x30
#define PCI_CONFIG_IO_LIMIT_UPPER 0x32
#define PCI_CONFIG_EXPANSION_ROM 0x38
#define PCI_CONFIG_BRIDGE_CONTROL 0x3E
#define PCI_INTERRUPT_LINE_DISABLED 0xff
typedef struct pci_device pci_device;
typedef uint8_t (*pci_driver_use)(const pci_device *);
typedef uint8_t (*pci_driver_validate)(const pci_device *);
typedef uint8_t (*pci_driver_initialize)(pci_device *);
struct pci_driver {
const char *name;
const char *description;
struct {
uint8_t class;
uint8_t subclass;
uint8_t interface;
uint16_t vendor;
uint16_t device;
} match;
struct {
bool class: 1;
bool subclass: 1;
bool interface: 1;
bool vendor: 1;
bool device: 1;
} mask;
struct {
bool direct_use: 1;
bool validatable: 1;
bool initialisable: 1;
};
pci_driver_use use;
pci_driver_validate validate;
pci_driver_initialize initialize;
} __attribute__((__aligned__(STRUCT_ALIGNMENT)));
#define PCI_DRIVER(order) GENERIC_DRIVER(pci_driver, order)
typedef struct {
uint32_t address;
uint32_t size;
uint8_t present: 1;
uint8_t is_io_space: 1;
uint8_t type: 2;
uint8_t prefetchable: 1;
} bar_info;
typedef struct pci_device {
uint8_t bus;
uint8_t slot;
uint8_t func;
union {
struct {
uint16_t vendorId;
uint16_t deviceId;
};
uint32_t config_line_0;
};
union {
struct {
uint8_t revisionId;
uint8_t programInterface;
uint8_t subclass;
uint8_t class;
};
uint32_t config_line_2;
};
union {
struct {
uint8_t cacheLineSize;
uint8_t latencyTimer;
uint8_t headerType;
uint8_t bist;
};
uint32_t config_line_3;
};
bar_info bar0;
bar_info bar1;
bar_info bar2;
bar_info bar3;
bar_info bar4;
bar_info bar5;
const struct pci_driver *pci_driver;
struct {
uint8_t present: 1;
} device_state;
struct {
uint8_t initialized: 1;
} driver_state;
} pci_device;
typedef union {
uint16_t value;
struct {
bool io_space: 1;
bool mem_space: 1;
bool bus_master: 1;
bool special_cycles: 1;
bool mem_write_invalidate_enable: 1;
bool vga_palette_snoop: 1;
bool parity_error_response: 1;
uint8_t reserved: 1;
bool serr_enable: 1;
bool fast_b2b_enable: 1;
bool interrupt_disable: 1;
uint8_t reserved2: 5;
} packed command;
} pci_command_register_t;
typedef union {
uint16_t value;
struct {
uint8_t reserved: 3;
bool interrupt_status: 1;
bool capabilities_list: 1;
bool speed_66mhz_capable: 1;
uint8_t reserved2: 1;
bool fast_b2b_capable: 1;
bool master_data_parity_error: 1;
uint8_t devsel_timing: 2;
bool signaled_target_abort: 1;
bool received_target_abort: 1;
bool received_master_abort: 1;
bool signaled_system_error: 1;
bool detected_parity_error: 1;
} packed status;
} pci_status_register_t;
void pci_print_info();
void pci_dump_caps();
#ifdef ENABLE_PCIPP
void pci_pretty_print();
#endif
void pci_init_drivers();
void pci_scan();
uint32_t pci_config_read_double_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
uint8_t pci_config_read_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
void pci_config_write_double_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint32_t value);
void pci_config_write_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t value);
void pci_config_write_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint8_t value);
void pci_init_bar(pci_device *device, uint8_t bar_index);
#endif //NEW_KERNEL_PCI_H

View File

@@ -0,0 +1,296 @@
//
// Created by rick on 06-03-21.
//
#ifndef NEW_KERNEL_PCI_DEVICES_H
#define NEW_KERNEL_PCI_DEVICES_H
#include <sys/types.h>
typedef struct pci_device_info_t {
uint8_t code;
char *name;
struct pci_device_info_t *sub;
} pci_device_info;
// build from https://wiki.osdev.org/PCI#Class_Codes
pci_device_info info_unclassified[] = {
{0x00, "Non VGA Compatible", NULL},
{0x01, "VGA Compatible", NULL},
{0, NULL, NULL},
};
pci_device_info info_mass_storage_ide[] = {
{0x00, "ISA comp only", NULL},
{0x05, "PCI native only", NULL},
{0x0A, "ISA compatibility controller, 2C, PCI native", NULL},
{0x0F, "PCI native controller, 2C, ISA comp", NULL},
{0x80, "ISA comp only, BM", NULL},
{0x85, "PCI native only, BM", NULL},
{0x8A, "ISA Comp only, 2C, BM, PCI native", NULL},
{0x8F, "PCI native, 2C, BM, ISA comp", NULL},
{0, NULL, NULL},
};
pci_device_info info_mass_storage_ata[] = {
{0x20, "Single DMA", NULL},
{0x30, "Chained DMA", NULL},
{0, NULL, NULL},
};
pci_device_info info_mass_storage_sata[] = {
{0x00, "Vendor specific", NULL},
{0x01, "AHCI 1.0", NULL},
{0x02, "Serial Storage Bus", NULL},
{0, NULL, NULL},
};
pci_device_info info_mass_storage_sas[] = {
{0x00, "SAS", NULL},
{0x01, "Serial Storage Bus", NULL},
{0, NULL, NULL},
};
pci_device_info info_mass_storage_nvm[] = {
{0x01, "NVMHCI", NULL},
{0x02, "NVM Express", NULL},
{0, NULL, NULL},
};
pci_device_info info_mass_storage[] = {
{0x00, "SCSI Bus Controller", NULL},
{0x01, "IDE Controller", info_mass_storage_ide},
{0x02, "Floppy Disk Controller", NULL},
{0x03, "IPI Bus Controller", NULL},
{0x04, "RAID Controller", NULL},
{0x05, "ATA Controller", info_mass_storage_ata},
{0x06, "Serial ATA", info_mass_storage_sata},
{0x07, "Serial Attached SCSI", info_mass_storage_sas},
{0x08, "NVM Controller", info_mass_storage_nvm},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_network_controller[] = {
{0x00, "Ethernet", NULL},
{0x01, "Token Ring", NULL},
{0x02, "FDDI", NULL},
{0x03, "ATM", NULL},
{0x04, "ISDN", NULL},
{0x05, "WordFip", NULL},
{0x06, "FICMG 2.14 Multi Computing", NULL},
{0x07, "Infiniband", NULL},
{0x08, "Fabric", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_display_vga_comp[] = {
{0x00, "VGA", NULL},
{0x01, "8514", NULL},
{0, NULL, 0},
};
pci_device_info info_display_controller[] = {
{0x00, "VGA Compatible", info_display_vga_comp},
{0x01, "XGA", NULL},
{0x02, "3D", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_multimedia_controller[] = {
{0x00, "Video", NULL},
{0x01, "Audio", NULL},
{0x02, "Computer Telephony", NULL},
{0x03, "Audio", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_memory_controller[] = {
{0x00, "RAM", NULL},
{0x01, "Flash", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_bridge_pci4[] = {
{0x00, "Normal", NULL},
{0x01, "Subtractive", NULL},
{0, NULL, NULL},
};
pci_device_info info_bridge_raceway[] = {
{0x00, "Transparent", NULL},
{0x01, "Endpoint", NULL},
{0, NULL, NULL},
};
pci_device_info info_bridge_pci9[] = {
{0x40, "Semi-transparent, primary", NULL},
{0x80, "Semi-transparent, secondary", NULL},
{0, NULL, NULL},
};
pci_device_info info_bridge_device[] = {
{0x00, "Host", NULL},
{0x01, "ISA", NULL},
{0x02, "EISA", NULL},
{0x03, "MCA", NULL},
{0x04, "PCI-to-PCI4", info_bridge_pci4},
{0x05, "PMCIA", NULL},
{0x06, "NuBus", NULL},
{0x07, "CardBus", NULL},
{0x08, "RACEway", info_bridge_raceway},
{0x09, "PCI-to-PCI9", info_bridge_pci9},
{0x0A, "Infiniband-to-host", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_simple_comm[] = {
{0x00, "Serial", NULL}, // todo sub
{0x01, "Parallel", NULL}, // todo sub
{0x02, "Multiport serial", NULL},
{0x03, "Modem", NULL}, // todo sub
{0x04, "IEEE 488.1/2 GPIB", NULL},
{0x05, "Smart card", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_base_system_peripheral[] = {
{0x00, "PIC", NULL}, // todo sub
{0x01, "DMA", NULL}, // todo sub
{0x02, "Timer", NULL}, // todo sub
{0x03, "RTC", NULL}, // todo sub
{0x04, "PCI Hot Plug", NULL},
{0x05, "SD", NULL},
{0x06, "IOMMU", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_input_device[] = {
{0x00, "Keyboard", NULL},
{0x01, "Digitizer pen", NULL},
{0x02, "Mouse", NULL},
{0x03, "Scanner", NULL},
{0x04, "Game Port", NULL}, // todo sub
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_docking_station[] = {
{0x00, "Generic", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_processor[] = {
{0x00, "386", NULL},
{0x01, "486", NULL},
{0x02, "Pentium", NULL},
{0x03, "Pentium Pro", NULL},
{0x10, "Alpha", NULL},
{0x20, "PowerPC", NULL},
{0x30, "MIPS", NULL},
{0x40, "Co-Processor", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_serial_bus_usb[] = {
{0x00, "UHCI (1.0)", NULL},
{0x10, "OHCI (1.1)", NULL},
{0x20, "EHCI (2.0)", NULL},
{0x30, "XHCI (3.0)", NULL},
{0x80, "Unspecified", NULL},
{0xFE, "Device", NULL},
{0, NULL, NULL},
};
pci_device_info info_serial_bus[] = {
{0x00, "FireWire", NULL}, // todo sub
{0x01, "ACCESS bus", NULL},
{0x02, "SSA", NULL},
{0x03, "USB", info_serial_bus_usb},
{0x04, "Fibre Channel", NULL},
{0x05, "SMBus", NULL},
{0x06, "InfiniBand", NULL},
{0x07, "IPMI Interface", NULL}, // todo sub
{0x08, "SERCOS", NULL},
{0x09, "CanBus", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_wireless[] = {
{0x00, "IRDA Comp", NULL},
{0x01, "Consumer IR", NULL},
{0x10, "RF", NULL},
{0x11, "Bluetooth", NULL},
{0x12, "Broadband", NULL},
{0x20, "Ethernet 802.1a", NULL},
{0x21, "Ethernet 802.1b", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_intelligent[] = {
{0x00, "I20", NULL},
{0, NULL, NULL},
};
pci_device_info info_satellite[] = {
{0x01, "Satellite TV", NULL},
{0x02, "Satellite Audio", NULL},
{0x03, "Satellite Voice", NULL},
{0x04, "Satellite Data", NULL},
{0, NULL, NULL},
};
pci_device_info info_encryption[] = {
{0x00, "Network and Computing", NULL},
{0x10, "Entertainment", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info info_signal_processing[] = {
{0x00, "DPIO Modules", NULL},
{0x01, "Performance Counters", NULL},
{0x10, "Communication Synchronizer", NULL},
{0x20, "Signal Processing Management", NULL},
{0x80, "Other", NULL},
{0, NULL, NULL},
};
pci_device_info pci_root_info[] = {
{0x00, "Unclassified", info_unclassified},
{0x01, "Mass Storage", info_mass_storage},
{0x02, "Network", info_network_controller},
{0x03, "Display", info_display_controller},
{0x04, "Multimedia", info_multimedia_controller},
{0x05, "Memory", info_memory_controller},
{0x06, "Bridge", info_bridge_device},
{0x07, "Simple Communication", info_simple_comm},
{0x08, "Base System Peripheral", info_base_system_peripheral},
{0x09, "Input Device", info_input_device},
{0x0a, "Docking", info_docking_station},
{0x0b, "Processor", info_processor},
{0x0c, "Serial Bus", info_serial_bus},
{0x0d, "Wireless", info_wireless},
{0x0e, "Intelligent", info_intelligent},
{0x0f, "Satellite Comm", info_satellite},
{0x10, "Encryption", info_encryption},
{0x11, "Signal Processing", info_signal_processing},
{0x12, "Processing Accelerator", NULL},
{0x13, "Non-Essential", NULL},
{0x40, "Co-Processor", NULL},
{0xFF, "Unassigned", NULL},
{0, NULL, NULL},
};
#endif //NEW_KERNEL_PCI_DEVICES_H