v2 initial commit
This commit is contained in:
parent
2c97dba9f7
commit
d2ef885e8d
118 changed files with 2420 additions and 9320 deletions
|
|
@ -1,345 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _AHCI_H_
|
||||
#define _AHCI_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <dev/pci.h>
|
||||
|
||||
/* Frame information structure (FIS) */
|
||||
#define FIS_REG_H2D 0x27
|
||||
#define FIS_REG_D2H 0x34
|
||||
#define FIS_DMA_ACT 0x39
|
||||
#define FIS_DMA_SETUP 0x41
|
||||
#define FIS_DATA 0x46
|
||||
#define FIS_BIST 0x58
|
||||
#define FIS_PIO_SETUP 0x5F
|
||||
#define FIS_DEV_BITS 0xA1
|
||||
|
||||
#define ATA_DEV_BUSY 0x80
|
||||
#define ATA_DEV_DRQ 0x08
|
||||
|
||||
#define ATA_CMD_READ_DMA_EX 0x25
|
||||
#define ATA_CMD_WRITE_DMA_EX 0x35
|
||||
#define ATA_CMD_IDENT 0xEC
|
||||
|
||||
#define SATA_SIG_ATA 0x00000101
|
||||
#define SATA_SIG_ATAPI 0xEB140101
|
||||
#define SATA_SIG_SEMB 0xC33C0101
|
||||
#define SATA_SIG_PM 0x96690101
|
||||
|
||||
#define AHCI_DEV_NULL 0
|
||||
#define AHCI_DEV_SATA 1
|
||||
#define AHCI_DEV_SEMB 2
|
||||
#define AHCI_DEV_PM 3
|
||||
#define AHCI_DEV_SATAPI 4
|
||||
|
||||
#define AHCI_GHC_IE 0x2
|
||||
#define AHCI_GHC_AE 0x80000000
|
||||
|
||||
#define HBA_PORT_IPM_ACTIVE 0x1
|
||||
#define HBA_PORT_DET_PRESENT 0x3
|
||||
|
||||
#define HBA_PORT_CMD_ST 0x1
|
||||
#define HBA_PORT_CMD_FRE 0x10
|
||||
#define HBA_PORT_CMD_FR 0x4000
|
||||
#define HBA_PORT_CMD_CR 0x8000
|
||||
#define HBA_PORT_IS_TFES 0x40000000
|
||||
|
||||
struct fis_reg_h2d {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 3;
|
||||
uint8_t cmd_mode : 1; /* high: command, low: control */
|
||||
|
||||
uint8_t command;
|
||||
uint8_t feature_low;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t lba0;
|
||||
uint8_t lba1;
|
||||
uint8_t lba2;
|
||||
uint8_t device;
|
||||
|
||||
/* 0x08 */
|
||||
uint8_t lba3;
|
||||
uint8_t lba4;
|
||||
uint8_t lba5;
|
||||
uint8_t feature_high;
|
||||
|
||||
/* 0x0C */
|
||||
uint8_t count_low;
|
||||
uint8_t count_high;
|
||||
uint8_t icc;
|
||||
uint8_t control;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t reserved2;
|
||||
} PACKED;
|
||||
|
||||
struct fis_reg_d2h {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 2;
|
||||
uint8_t intr : 1;
|
||||
uint8_t reserved2 : 1;
|
||||
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t lba0;
|
||||
uint8_t lba1;
|
||||
uint8_t lba2;
|
||||
uint8_t device;
|
||||
|
||||
/* 0x08 */
|
||||
uint8_t lba3;
|
||||
uint8_t lba4;
|
||||
uint8_t lba5;
|
||||
uint8_t feature_high;
|
||||
|
||||
/* 0x0C */
|
||||
uint8_t count_low;
|
||||
uint8_t count_high;
|
||||
uint8_t icc;
|
||||
uint8_t control;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t reserved3;
|
||||
} PACKED;
|
||||
|
||||
struct fis_data {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 4;
|
||||
|
||||
uint8_t reserved2[2];
|
||||
|
||||
/* 0x04 */
|
||||
uint32_t data[1]; /* Variable length */
|
||||
} PACKED;
|
||||
|
||||
struct fis_dma_setup {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 1;
|
||||
uint8_t data_dir : 1;
|
||||
uint8_t intr : 1;
|
||||
uint8_t auto_act : 1;
|
||||
|
||||
uint16_t reserved2;
|
||||
|
||||
/* 0x04 */
|
||||
uint64_t dma_buffer_id;
|
||||
|
||||
/* 0x0C */
|
||||
uint32_t reserved3;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t dma_buffer_offset;
|
||||
|
||||
/* 0x14 */
|
||||
uint32_t transfer_count;
|
||||
|
||||
/* 0x18 */
|
||||
uint32_t reserved4;
|
||||
} PACKED;
|
||||
|
||||
struct fis_pio_setup {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 1;
|
||||
uint8_t data_dir : 1;
|
||||
uint8_t intr : 1;
|
||||
uint8_t reserved2 : 1;
|
||||
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t lba0;
|
||||
uint8_t lba1;
|
||||
uint8_t lba2;
|
||||
uint8_t device;
|
||||
|
||||
/* 0x08 */
|
||||
uint8_t lba3;
|
||||
uint8_t lba4;
|
||||
uint8_t lba5;
|
||||
uint8_t reserved3;
|
||||
|
||||
/* 0x0C */
|
||||
uint8_t count_low;
|
||||
uint8_t count_high;
|
||||
uint8_t reserved4;
|
||||
uint8_t e_status;
|
||||
|
||||
/* 0x10 */
|
||||
uint16_t transfer_count;
|
||||
uint16_t reserved5;
|
||||
} PACKED;
|
||||
|
||||
struct fis_set_device_bits {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 2;
|
||||
uint8_t interrupt : 1;
|
||||
uint8_t n : 1;
|
||||
|
||||
uint8_t statusl : 3;
|
||||
uint8_t reserved2 : 1;
|
||||
uint8_t statush : 3;
|
||||
uint8_t reserved3 : 1;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t errorl : 3;
|
||||
} PACKED;
|
||||
|
||||
struct hba_cmd_header {
|
||||
uint8_t cmd_fis_len : 5;
|
||||
uint8_t atapi : 1;
|
||||
uint8_t write : 1;
|
||||
uint8_t prefetch : 1;
|
||||
|
||||
uint8_t reset : 1;
|
||||
uint8_t bist : 1;
|
||||
uint8_t clear_busy : 1;
|
||||
uint8_t reserved : 1;
|
||||
uint8_t pmp : 4;
|
||||
|
||||
uint16_t prdt_len;
|
||||
|
||||
volatile uint32_t prdb_count;
|
||||
|
||||
paddr_t cmd_table_base;
|
||||
|
||||
uint32_t reserved2[4];
|
||||
} PACKED;
|
||||
|
||||
struct hba_prdt_entry {
|
||||
paddr_t data_base;
|
||||
|
||||
uint32_t reserved;
|
||||
|
||||
uint32_t byte_count : 22;
|
||||
uint32_t reserved2 : 9;
|
||||
uint32_t interrupt : 1;
|
||||
} PACKED;
|
||||
|
||||
struct hba_cmd_tbl {
|
||||
uint8_t cfis[64];
|
||||
|
||||
uint8_t acmd[16];
|
||||
|
||||
uint8_t reserved[48];
|
||||
|
||||
struct hba_prdt_entry prdt_entry[1];
|
||||
} PACKED;
|
||||
|
||||
typedef volatile struct {
|
||||
/* 0x00 */
|
||||
paddr_t clb;
|
||||
|
||||
paddr_t fb;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t is;
|
||||
uint32_t ie;
|
||||
uint32_t cmd;
|
||||
uint32_t reserved;
|
||||
|
||||
/* 0x20 */
|
||||
uint32_t tfd;
|
||||
uint32_t sig;
|
||||
uint32_t ssts;
|
||||
uint32_t sctl;
|
||||
|
||||
/* 0x30 */
|
||||
uint32_t serr;
|
||||
uint32_t sact;
|
||||
uint32_t ci;
|
||||
uint32_t sntf;
|
||||
|
||||
/* 0x40 */
|
||||
uint32_t fbs;
|
||||
|
||||
uint32_t reserved1[11];
|
||||
uint32_t vendor[4];
|
||||
} PACKED hbaport_t;
|
||||
|
||||
typedef volatile struct {
|
||||
/* 0x00 */
|
||||
uint32_t cap;
|
||||
uint32_t ghc;
|
||||
uint32_t is;
|
||||
uint32_t pi;
|
||||
uint32_t vs;
|
||||
|
||||
/* 0x14 */
|
||||
uint32_t ccc_ctl;
|
||||
uint32_t ccc_ports;
|
||||
uint32_t em_loc;
|
||||
uint32_t em_ctl;
|
||||
uint32_t cap2;
|
||||
|
||||
/* 0x28 */
|
||||
uint32_t bohc;
|
||||
|
||||
/* 0x2C */
|
||||
uint8_t reserved[0x74];
|
||||
|
||||
/* 0xA0 */
|
||||
uint8_t vendor[0x60];
|
||||
|
||||
/* 0x100 */
|
||||
hbaport_t ports[32];
|
||||
} PACKED hbamem_t;
|
||||
|
||||
typedef volatile struct {
|
||||
/* 0x00 */
|
||||
struct fis_dma_setup dfis;
|
||||
uint32_t reserved;
|
||||
|
||||
/* 0x20 */
|
||||
struct fis_pio_setup pfis;
|
||||
uint32_t reserved1[3];
|
||||
|
||||
/* 0x40 */
|
||||
struct fis_reg_d2h rfis;
|
||||
uint32_t reserved2;
|
||||
|
||||
struct fis_set_device_bits sdbfis;
|
||||
|
||||
/* 0x60 */
|
||||
uint8_t ufis[64];
|
||||
|
||||
/* 0xA0 */
|
||||
uint8_t reserved3[0x60];
|
||||
|
||||
} PACKED hbafis_t;
|
||||
|
||||
struct sata_device {
|
||||
struct pci_device *controller;
|
||||
uint8_t port;
|
||||
|
||||
size_t sector_size;
|
||||
size_t sector_count;
|
||||
hbamem_t *abar;
|
||||
};
|
||||
|
||||
void ahci_init();
|
||||
bool ahci_access_sectors(struct sata_device *dev, paddr_t lba, uint16_t count, paddr_t buf, bool write);
|
||||
|
||||
#endif /* _AHCI_H_ */
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _APIC_H_
|
||||
#define _APIC_H_
|
||||
|
||||
#define MADT_LAPIC 0
|
||||
#define MADT_IOAPIC 1
|
||||
#define MADT_IOAPIC_OVRD 2
|
||||
#define MADT_IOAPIC_NMI 3
|
||||
#define MADT_LAPIC_NMI 4
|
||||
#define MADT_LAPIC_OVRD 5
|
||||
#define MADT_X2_LAPIC 9
|
||||
|
||||
#define LAPIC_ID 0x20
|
||||
#define LAPIC_VERSION 0x30
|
||||
#define LAPIC_TPR 0x80
|
||||
#define LAPIC_APR 0x90
|
||||
#define LAPIC_PPR 0xA0
|
||||
#define LAPIC_EOI 0xB0
|
||||
#define LAPIC_RRD 0xC0
|
||||
#define LAPIC_LDR 0xD0
|
||||
#define LAPIC_DFR 0xE0
|
||||
#define LAPIC_SIVR 0xF0
|
||||
#define LAPIC_ISR 0x100
|
||||
#define LAPIC_TMR 0x180
|
||||
#define LAPIC_IRR 0x200
|
||||
#define LAPIC_ERR 0x280
|
||||
#define LAPIC_CMCI 0x2F0
|
||||
#define LAPIC_ICR 0x300
|
||||
#define LAPIC_THERMAL 0x330
|
||||
#define LAPIC_LVT_PERF_MON_COUNT 0x340
|
||||
#define LAPIC_LVT_LINT0 0x350
|
||||
#define LAPIC_LVT_LINT1 0x360
|
||||
#define LAPIC_LVT_ERR 0x370
|
||||
#define LAPIC_INIT_COUNT 0x380
|
||||
#define LAPIC_CUR_COUNT 0x390
|
||||
|
||||
#define LAPIC_TIMER 0x320
|
||||
#define LAPIC_TIMER_DIV 0x3E0
|
||||
#define LAPIC_TIMER_INIT_COUNT 0x380
|
||||
|
||||
#define MSR_IA32_APIC_BASE 0x1B
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/acpi.h>
|
||||
|
||||
struct madt {
|
||||
struct acpi_sdt_header h;
|
||||
uint32_t lapic_addr;
|
||||
uint32_t flags;
|
||||
} PACKED;
|
||||
|
||||
struct madt_header {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
} PACKED;
|
||||
|
||||
struct madt_lapic {
|
||||
struct madt_header h;
|
||||
uint8_t acpi_cpu_id;
|
||||
uint8_t apic_id;
|
||||
uint32_t flags;
|
||||
} PACKED;
|
||||
|
||||
struct madt_ioapic {
|
||||
struct madt_header h;
|
||||
uint8_t ioapic_id;
|
||||
uint8_t reserved;
|
||||
uint32_t ioapic_addr;
|
||||
uint32_t intr_base;
|
||||
} PACKED;
|
||||
|
||||
struct madt_ioapic_ovrd {
|
||||
struct madt_header h;
|
||||
uint8_t bus;
|
||||
uint8_t irq;
|
||||
uint32_t intr;
|
||||
uint16_t flags;
|
||||
} PACKED;
|
||||
|
||||
struct madt_ioapic_nmi {
|
||||
struct madt_header h;
|
||||
uint8_t nmi;
|
||||
uint8_t reserved;
|
||||
uint16_t flags;
|
||||
uint32_t intr;
|
||||
} PACKED;
|
||||
|
||||
struct madt_lapic_nmi {
|
||||
struct madt_header h;
|
||||
uint8_t acpi_cpu_id;
|
||||
uint16_t flags;
|
||||
uint8_t lint;
|
||||
} PACKED;
|
||||
|
||||
struct madt_lapic_ovrd {
|
||||
struct madt_header h;
|
||||
uint16_t reserved;
|
||||
uint64_t lapic_addr;
|
||||
} PACKED;
|
||||
|
||||
struct madt_x2_lapic {
|
||||
struct madt_header h;
|
||||
uint16_t reserved;
|
||||
uint32_t lapic_id;
|
||||
uint32_t flags;
|
||||
uint32_t acpi_id;
|
||||
} PACKED;
|
||||
|
||||
struct apic_redirect {
|
||||
union {
|
||||
struct {
|
||||
uint64_t isr : 8;
|
||||
uint64_t delv_mode : 3;
|
||||
uint64_t dest_mode : 1;
|
||||
uint64_t delv_status : 1;
|
||||
uint64_t polarity : 1;
|
||||
uint64_t remote_irr : 1;
|
||||
uint64_t trigger : 1;
|
||||
uint64_t mask : 1;
|
||||
uint64_t reserved : 39;
|
||||
uint64_t dest : 8;
|
||||
} PACKED;
|
||||
struct {
|
||||
uint32_t low;
|
||||
uint32_t high;
|
||||
} PACKED;
|
||||
};
|
||||
} PACKED;
|
||||
|
||||
void apic_init();
|
||||
void lapic_eoi();
|
||||
int madt_parse_next_entry(int offset);
|
||||
void lapic_enable();
|
||||
void apic_enable_timer();
|
||||
uint8_t lapic_idno();
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _APIC_H_ */
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _PCI_H_
|
||||
#define _PCI_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
#define PCIPM_CONFIG_ADDRESS 0xCF8
|
||||
#define PCIPM_CONFIG_DATA 0xCFC
|
||||
|
||||
struct pci_device {
|
||||
uint8_t bus;
|
||||
uint8_t slot;
|
||||
|
||||
uint8_t func;
|
||||
|
||||
uint8_t class;
|
||||
uint8_t subclass;
|
||||
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
|
||||
uint16_t segment_group;
|
||||
|
||||
uint8_t header_type;
|
||||
|
||||
paddr32_t bar0;
|
||||
paddr32_t bar1;
|
||||
paddr32_t bar2;
|
||||
paddr32_t bar3;
|
||||
paddr32_t bar4;
|
||||
paddr32_t bar5;
|
||||
};
|
||||
|
||||
struct pci_header_base {
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
|
||||
uint16_t command;
|
||||
uint16_t status;
|
||||
|
||||
uint8_t revision_id;
|
||||
uint8_t prog_if;
|
||||
uint8_t subclass;
|
||||
uint8_t class;
|
||||
|
||||
uint8_t cache_line_size;
|
||||
uint8_t latency_timer;
|
||||
uint8_t header_type;
|
||||
uint8_t bist;
|
||||
} PACKED;
|
||||
|
||||
struct pci_header_type_0 {
|
||||
struct pci_header_base base;
|
||||
|
||||
paddr32_t bar0;
|
||||
paddr32_t bar1;
|
||||
paddr32_t bar2;
|
||||
paddr32_t bar3;
|
||||
paddr32_t bar4;
|
||||
paddr32_t bar5;
|
||||
|
||||
uint32_t cardbus_cis_pointer;
|
||||
|
||||
uint16_t subsystem_vendor_id;
|
||||
uint16_t subsystem_id;
|
||||
|
||||
uint32_t expansion_rom_base_address;
|
||||
|
||||
uint8_t capabilities_pointer;
|
||||
uint8_t reserved[7];
|
||||
|
||||
uint8_t interrupt_line;
|
||||
uint8_t interrupt_pin;
|
||||
uint8_t min_grant;
|
||||
uint8_t max_latency;
|
||||
} PACKED;
|
||||
|
||||
struct pci_header_type_1 {
|
||||
struct pci_header_base base;
|
||||
|
||||
paddr32_t bar0;
|
||||
paddr32_t bar1;
|
||||
|
||||
uint8_t primary_bus_number;
|
||||
uint8_t secondary_bus_number;
|
||||
uint8_t subordinate_bus_number;
|
||||
uint8_t secondary_latency_timer;
|
||||
|
||||
uint8_t io_base;
|
||||
uint8_t io_limit;
|
||||
uint16_t secondary_status;
|
||||
|
||||
uint16_t memory_base;
|
||||
uint16_t memory_limit;
|
||||
|
||||
uint16_t prefetchable_memory_base;
|
||||
uint16_t prefetchable_memory_limit;
|
||||
|
||||
uint32_t prefetchable_base_upper;
|
||||
uint32_t prefetchable_limit_upper;
|
||||
|
||||
uint16_t io_base_upper;
|
||||
uint16_t io_limit_upper;
|
||||
|
||||
uint8_t capabilities_pointer;
|
||||
uint8_t reserved[3];
|
||||
|
||||
uint32_t expansion_rom_base_address;
|
||||
|
||||
uint8_t interrupt_line;
|
||||
uint8_t interrupt_pin;
|
||||
uint16_t bridge_control;
|
||||
} PACKED;
|
||||
|
||||
void pci_init();
|
||||
uint32_t pci_config_read_long(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
|
||||
void pci_config_write_long(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t data);
|
||||
struct pci_device *pci_find_device(uint8_t class, uint8_t subclass);
|
||||
|
||||
#endif /* _PCI_H_ */
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _PIC_H_
|
||||
#define _PIC_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
#define PIC1_CMD 0x20
|
||||
#define PIC1_DATA 0x21
|
||||
#define PIC2_CMD 0xA0
|
||||
#define PIC2_DATA 0xA1
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
void pic_mask(uint8_t irq, uint8_t i);
|
||||
void pic_eoi(uint8_t irq);
|
||||
void pic_init();
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _PIC_H_ */
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _SERIAL_H_
|
||||
#define _SERIAL_H_
|
||||
|
||||
#define COM1 0x3F8
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
void isr_serial_input();
|
||||
void isr_serial_input_1();
|
||||
ssize_t serial_write(const char *buf, size_t count);
|
||||
void serial_putchar(char c);
|
||||
void serial_trap();
|
||||
int serial_init();
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _SERIAL_H_ */
|
||||
40
include/drivers/tty.h
Normal file
40
include/drivers/tty.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _TTY_H_
|
||||
#define _TTY_H_
|
||||
|
||||
#include <kernel/device.h>
|
||||
|
||||
#define DEV_CLASS_TTY 0x01
|
||||
|
||||
struct tty_serial_ops {
|
||||
void (*serial_putchar)(struct tty *tty, char c);
|
||||
char (*serial_getchar)(struct tty *tty);
|
||||
};
|
||||
|
||||
struct tty {
|
||||
dev_t dev;
|
||||
dev_t serial_device;
|
||||
void *serial_device_private;
|
||||
|
||||
struct tty_serial_ops *serial_ops;
|
||||
};
|
||||
|
||||
void tty_layer_init();
|
||||
|
||||
struct tty *tty_create(const char *name, dev_t serial_device);
|
||||
void tty_putchar(struct tty *tty, char c);
|
||||
char tty_getchar(struct tty *tty);
|
||||
void tty_write(struct tty *tty, const char *s);
|
||||
|
||||
void arch_serial_write(struct tty *tty, char c);
|
||||
char arch_serial_read(struct tty *tty);
|
||||
|
||||
void tty_send_dsr(struct tty *tty);
|
||||
void tty_set_origin_mode(struct tty *tty);
|
||||
void tty_clear_screen(struct tty *tty);
|
||||
void tty_set_cursor_pos(struct tty *tty, int x, int y);
|
||||
void tty_get_cursor_pos(struct tty *tty, int *row, int *col);
|
||||
void tty_get_size(struct tty *tty, int *rows, int *cols);
|
||||
void tty_setlf(struct tty *tty);
|
||||
|
||||
#endif /* _TTY_H_ */
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _DEVFS_H_
|
||||
#define _DEVFS_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct vnode;
|
||||
struct devfs_dev_info {
|
||||
void *dev;
|
||||
ssize_t (*read)(void *dev, void *buf, size_t offset, size_t size);
|
||||
ssize_t (*write)(void *dev, void *buf, size_t offset, size_t size);
|
||||
};
|
||||
|
||||
struct fs *devfs_init();
|
||||
int devfs_insert(struct vnode *dir, const char *name, uint32_t flags, struct devfs_dev_info *ops);
|
||||
|
||||
#endif /* _DEVFS_H_ */
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _EXT2_H_
|
||||
#define _EXT2_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/block.h>
|
||||
#include <kernel/gpt.h>
|
||||
|
||||
#include <fs/vfs.h>
|
||||
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
#define EXT2_ROOT_INO 2
|
||||
#define EXT2_SUPERBLOCK_BLOCKNO 1
|
||||
|
||||
#define EXT2_DE_UNKNOWN 0
|
||||
#define EXT2_DE_FILE 1
|
||||
#define EXT2_DE_DIR 2
|
||||
#define EXT2_DE_CHRDEV 3
|
||||
#define EXT2_DE_BLKDEV 4
|
||||
#define EXT2_DE_FIFO 5
|
||||
#define EXT2_DE_SOCK 6
|
||||
#define EXT2_DE_SYMLINK 7
|
||||
|
||||
#define EXT2_INO_FIFO 0x1000
|
||||
#define EXT2_INO_CHARDEV 0x2000
|
||||
#define EXT2_INO_DIR 0x4000
|
||||
#define EXT2_INO_BLKDEV 0x6000
|
||||
#define EXT2_INO_REG 0x8000
|
||||
#define EXT2_INO_SYMLINK 0xA000
|
||||
#define EXT2_INO_SOCK 0xC000
|
||||
|
||||
#define EXT2_FLAG_LONG_FILESIZE 0x0002
|
||||
|
||||
struct ext2_superblock {
|
||||
uint32_t inodes_count;
|
||||
uint32_t blocks_count;
|
||||
uint32_t u_blocks_count;
|
||||
uint32_t free_blocks_count;
|
||||
uint32_t free_inodes_count;
|
||||
uint32_t first_data_block;
|
||||
|
||||
uint32_t log_block_size;
|
||||
uint32_t log_frag_size;
|
||||
|
||||
uint32_t blocks_per_group;
|
||||
uint32_t frags_per_group;
|
||||
uint32_t inodes_per_group;
|
||||
|
||||
uint32_t mtime;
|
||||
uint32_t wtime;
|
||||
|
||||
uint16_t mnt_count;
|
||||
uint16_t max_mnt_count;
|
||||
uint16_t magic;
|
||||
uint16_t state;
|
||||
uint16_t errors;
|
||||
uint16_t minor_rev_level;
|
||||
|
||||
uint32_t lastcheck;
|
||||
uint32_t checkinterval;
|
||||
uint32_t creator_os;
|
||||
uint32_t rev_level;
|
||||
|
||||
uint16_t def_resuid;
|
||||
uint16_t def_resgid;
|
||||
|
||||
/* extended superblock fields
|
||||
* if rev_level >= 1
|
||||
*/
|
||||
uint32_t first_ino;
|
||||
uint16_t inode_size;
|
||||
uint16_t block_group_nr;
|
||||
uint32_t feature_compat;
|
||||
uint32_t feature_incompat;
|
||||
uint32_t feature_ro_compat;
|
||||
uint8_t uuid[16];
|
||||
char volume_name[16];
|
||||
char last_mounted[64];
|
||||
uint32_t algo_bitmap;
|
||||
|
||||
/* performance hints */
|
||||
uint8_t prealloc_blocks;
|
||||
uint8_t prealloc_dir_blocks;
|
||||
uint16_t padding1;
|
||||
|
||||
/* journaling support */
|
||||
uint8_t journal_uuid[16];
|
||||
uint32_t journal_inum;
|
||||
uint32_t journal_dev;
|
||||
uint32_t last_orphan;
|
||||
} PACKED;
|
||||
|
||||
struct ext2_inode {
|
||||
uint16_t mode;
|
||||
uint16_t uid;
|
||||
uint32_t size;
|
||||
|
||||
uint32_t atime;
|
||||
uint32_t ctime;
|
||||
uint32_t mtime;
|
||||
uint32_t dtime;
|
||||
|
||||
uint16_t gid;
|
||||
uint16_t links_count;
|
||||
uint32_t blocks;
|
||||
uint32_t flags;
|
||||
uint32_t osd1;
|
||||
uint32_t block[15];
|
||||
|
||||
uint32_t generation;
|
||||
uint32_t file_acl;
|
||||
uint32_t dir_acl;
|
||||
uint32_t faddr;
|
||||
|
||||
uint8_t frag_number;
|
||||
uint8_t frag_size;
|
||||
uint16_t padding1;
|
||||
uint16_t user_high;
|
||||
uint16_t group_high;
|
||||
uint32_t padding2;
|
||||
} PACKED;
|
||||
|
||||
struct ext2_group_desc {
|
||||
uint32_t block_bitmap;
|
||||
uint32_t inode_bitmap;
|
||||
uint32_t inode_table;
|
||||
uint16_t free_blocks_count;
|
||||
uint16_t free_inodes_count;
|
||||
uint16_t used_dirs_count;
|
||||
uint16_t padding[7];
|
||||
} PACKED;
|
||||
|
||||
struct ext2_dir_entry {
|
||||
uint32_t inode;
|
||||
uint16_t rec_len;
|
||||
uint8_t name_len;
|
||||
ftype_t file_type;
|
||||
char name[];
|
||||
} PACKED;
|
||||
|
||||
struct ext2fs {
|
||||
struct ext2_superblock sb;
|
||||
struct block_device *bdev;
|
||||
|
||||
uint32_t bgdt_blockno;
|
||||
uint32_t bgdt_num_blocks;
|
||||
struct ext2_group_desc *bgdt;
|
||||
|
||||
spinlock_t lock;
|
||||
|
||||
uint32_t indir_block_size;
|
||||
|
||||
uint32_t block_size;
|
||||
};
|
||||
|
||||
struct fs *ext2_init_fs(struct block_device *bdev);
|
||||
|
||||
#endif /* _EXT2_H_ */
|
||||
162
include/fs/vfs.h
162
include/fs/vfs.h
|
|
@ -1,162 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _VFS_H_
|
||||
#define _VFS_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
#define VFSE_IS_BDEV 0xFFFA
|
||||
|
||||
#define VFS_TYPE_EXT2 0x0001
|
||||
|
||||
/* same as EXT2_INO_* */
|
||||
#define VFS_VNO_FIFO 0x1000
|
||||
#define VFS_VNO_CHARDEV 0x2000
|
||||
#define VFS_VNO_DIR 0x4000
|
||||
#define VFS_VNO_BLKDEV 0x6000
|
||||
#define VFS_VNO_REG 0x8000
|
||||
#define VFS_VNO_SYMLINK 0xA000
|
||||
#define VFS_VNO_SOCK 0xC000
|
||||
#define VFS_VTYPE_MASK 0xF000
|
||||
|
||||
#define FTYPE_CHARDEV VFS_VNO_CHARDEV
|
||||
#define FTYPE_DIR VFS_VNO_DIR
|
||||
#define FTYPE_BLKDEV VFS_VNO_BLKDEV
|
||||
#define FTYPE_REG VFS_VNO_REG
|
||||
#define FTYPE_SYMLINK VFS_VNO_SYMLINK
|
||||
#define FTYPE_SOCK VFS_VNO_SOCK
|
||||
#define FTYPE_FIFO VFS_VNO_FIFO
|
||||
|
||||
#define VFS_DE_UNKNOWN 0
|
||||
#define VFS_DE_FILE 1
|
||||
#define VFS_DE_DIR 2
|
||||
#define VFS_DE_CHRDEV 3
|
||||
#define VFS_DE_BLKDEV 4
|
||||
#define VFS_DE_FIFO 5
|
||||
#define VFS_DE_SOCK 6
|
||||
#define VFS_DE_SYMLINK 7
|
||||
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define O_RDONLY 0x0001
|
||||
#define O_WRONLY 0x0002
|
||||
#define O_RDWR 0x0004
|
||||
#define O_CREAT 0x0008
|
||||
#define O_TRUNC 0x0010
|
||||
#define O_APPEND 0x0020
|
||||
|
||||
#define S_IFIFO 0x1000
|
||||
|
||||
#define FS_TYPE_EXT2 0x0001
|
||||
#define FS_TYPE_PFS 0x0002 /* pseudo fs */
|
||||
|
||||
typedef uint32_t ino_t;
|
||||
typedef uint8_t ftype_t;
|
||||
typedef size_t off_t;
|
||||
|
||||
struct vnode {
|
||||
char name[256];
|
||||
uint32_t flags;
|
||||
uint32_t gid;
|
||||
uint32_t uid;
|
||||
uint32_t size;
|
||||
uint32_t ino_num;
|
||||
|
||||
struct fs *fs;
|
||||
struct vnode *ptr;
|
||||
struct vnode *next;
|
||||
|
||||
struct vnode *parent;
|
||||
|
||||
struct dirent *dirents; /* for directories */
|
||||
size_t num_dirents;
|
||||
|
||||
bool mount_ptr; /* does this node point to a root of a mounted fs? */
|
||||
bool no_free; /* permanently cached vnodes */
|
||||
|
||||
void *priv_data;
|
||||
|
||||
size_t refcount;
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
struct dirent {
|
||||
uint64_t inode; /* fs-specific inode number */
|
||||
uint16_t reclen; /* length of this record */
|
||||
ftype_t type; /* type: file, dir, chrdev, blkdev, etc. */
|
||||
char name[256];
|
||||
|
||||
struct vnode *vnode; /* we don't want duplicate vnodes */
|
||||
};
|
||||
|
||||
struct file {
|
||||
struct vnode *vnode;
|
||||
|
||||
spinlock_t ref_lock;
|
||||
uint64_t refcount;
|
||||
|
||||
ino_t ino_num; /* inode number */
|
||||
uint32_t type; /* type of the file */
|
||||
uint64_t size; /* size of the file */
|
||||
};
|
||||
|
||||
struct file_descriptor {
|
||||
struct file *file;
|
||||
|
||||
int fd;
|
||||
uint64_t pos;
|
||||
uint32_t flags;
|
||||
|
||||
char *buf;
|
||||
size_t buf_len;
|
||||
|
||||
struct fs *fs;
|
||||
};
|
||||
|
||||
struct fs_ops {
|
||||
int (*read)(struct vnode *vnode, void *buf, size_t offset, size_t size);
|
||||
int (*write)(struct vnode *vnode, void *buf, size_t offset, size_t size);
|
||||
int (*unlink)(struct vnode *parent, const char *name);
|
||||
int (*creat)(struct vnode *parent, const char *path, mode_t mode);
|
||||
int (*open_vno)(struct fs *vfs, struct vnode *out, ino_t ino_num);
|
||||
};
|
||||
|
||||
struct fs {
|
||||
struct vnode *root;
|
||||
void *fs;
|
||||
uint32_t type;
|
||||
struct fs_ops *ops;
|
||||
|
||||
char *mount_point;
|
||||
};
|
||||
|
||||
struct statbuf {
|
||||
size_t size;
|
||||
};
|
||||
|
||||
void vfs_init(const char *rootfs);
|
||||
ssize_t vfs_write(struct file *file, void *buf, off_t off, size_t count);
|
||||
ssize_t vfs_read(struct file *file, void *buf, off_t off, size_t count);
|
||||
int vfs_statf(struct file *file, struct statbuf *statbuf);
|
||||
struct file *vfs_open(const char *pathname, int *err);
|
||||
struct vnode *vfs_create_file(struct vnode *parent, const char *path, mode_t mode);
|
||||
struct vnode *vfs_mknod(const char *pathname, mode_t mode);
|
||||
int vfs_close(struct file *file);
|
||||
int unlink(const char *pathname);
|
||||
int statfd(struct file_descriptor *fdesc, struct statbuf *statbuf);
|
||||
|
||||
char *basename(char *path);
|
||||
char *dirname(char *path);
|
||||
|
||||
struct fs *vfs_create();
|
||||
struct vnode *vfs_create_vno();
|
||||
void vfs_dealloc(struct fs *fs);
|
||||
int vfs_mount(struct fs *fs, const char *mount_point);
|
||||
|
||||
uint64_t vfs_file_type(struct file *file);
|
||||
void *vfs_file_dev(struct file *file);
|
||||
|
||||
int stdout_write(struct file_descriptor *fdesc, void *buf, size_t len);
|
||||
|
||||
#endif /* _VFS_H_ */
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _ACPI_H_
|
||||
#define _ACPI_H_
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct rsdp {
|
||||
char signature[8];
|
||||
uint8_t checksum;
|
||||
char oemid[6];
|
||||
uint8_t revision;
|
||||
uint32_t rsdt_addr;
|
||||
} PACKED;
|
||||
|
||||
struct acpi_sdt_header {
|
||||
char signature[4];
|
||||
uint32_t length;
|
||||
uint8_t revision;
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
char oem_table_id[8];
|
||||
uint32_t oem_revision;
|
||||
uint32_t creator_id;
|
||||
uint32_t creator_revision;
|
||||
} PACKED;
|
||||
|
||||
struct rsdt {
|
||||
struct acpi_sdt_header h;
|
||||
uint32_t sdt[];
|
||||
} PACKED;
|
||||
|
||||
struct mcfg {
|
||||
struct acpi_sdt_header h;
|
||||
uint64_t reserved;
|
||||
struct {
|
||||
uint64_t base_addr;
|
||||
uint16_t seg_group;
|
||||
uint8_t start_bus;
|
||||
uint8_t end_bus;
|
||||
uint32_t reserved;
|
||||
} PACKED cfg[];
|
||||
} PACKED;
|
||||
|
||||
void acpi_init();
|
||||
|
||||
extern struct madt *__madt;
|
||||
extern struct mcfg *__mcfg;
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _ACPI_H_ */
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _BLOCK_H_
|
||||
#define _BLOCK_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/gpt.h>
|
||||
|
||||
struct block_device;
|
||||
|
||||
struct block_device_ops {
|
||||
int (*read)(struct block_device *bdev, void *buf, size_t offset, size_t size);
|
||||
int (*write)(struct block_device *bdev, void *buf, size_t offset, size_t size);
|
||||
};
|
||||
|
||||
struct block_device {
|
||||
char *name;
|
||||
struct block_device_ops ops;
|
||||
void *data;
|
||||
size_t size;
|
||||
|
||||
size_t block_count;
|
||||
size_t block_size;
|
||||
size_t lba_start;
|
||||
|
||||
size_t partition_count;
|
||||
|
||||
void *fs;
|
||||
struct block_device *parent;
|
||||
struct block_device *next_part; /* singly linked list */
|
||||
};
|
||||
|
||||
struct block_device *block_register(char *name, struct block_device_ops *ops, void *data, size_t block_count, size_t block_size);
|
||||
struct block_device *block_get_device(const char *name);
|
||||
int block_read(struct block_device *bdev, void *buf, size_t offset, size_t size);
|
||||
int block_write(struct block_device *bdev, void *buf, size_t offset, size_t size);
|
||||
void kerror_print_blkdevs();
|
||||
|
||||
extern struct block_device *block_devices[];
|
||||
extern size_t block_devices_count;
|
||||
|
||||
#endif /* _BLOCK_H_ */
|
||||
11
include/kernel/buddy.h
Normal file
11
include/kernel/buddy.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _BUDDY_H_
|
||||
#define _BUDDY_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
void *buddy_alloc(size_t size);
|
||||
void buddy_free(void *ptr);
|
||||
void buddy_init();
|
||||
|
||||
#endif /* _BUDDY_H_ */
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _CHAR_H_
|
||||
#define _CHAR_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct char_device {
|
||||
char *name;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct char_device *char_device_create(const char *name, void *data);
|
||||
void char_device_destroy(struct char_device *cd);
|
||||
|
||||
#endif /* _CHAR_H_ */
|
||||
|
|
@ -6,43 +6,27 @@
|
|||
|
||||
#include <limine/limine.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <lib/stdio.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/errno.h>
|
||||
#include <lib/math.h>
|
||||
#include <lib/assert.h>
|
||||
#include <kernel/types.h>
|
||||
|
||||
#include <kernel/bitwise.h>
|
||||
#include <lib/stdio.h>
|
||||
|
||||
#define PACKED __attribute__((packed))
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#define ATTEMPT_WRITE(_x, _y) \
|
||||
if (_x) { \
|
||||
*(_x) = _y; \
|
||||
*(_x) = _y; \
|
||||
}
|
||||
|
||||
#define KB (1024ull)
|
||||
#define MB (KB * KB)
|
||||
#define GB (KB * MB)
|
||||
|
||||
#define RFLAGS_IF (1 << 9)
|
||||
|
||||
void yield();
|
||||
void panic();
|
||||
void cli();
|
||||
void sti();
|
||||
void _save_context();
|
||||
void reboot();
|
||||
void load_stack_and_jump(uintptr_t rsp, uintptr_t rbp, void *func, void *arg);
|
||||
#define panic(...) \
|
||||
{ \
|
||||
kprintf(LOG_PANIC __VA_ARGS__); \
|
||||
_panic(); \
|
||||
}
|
||||
|
||||
typedef uintptr_t paddr_t;
|
||||
typedef uint32_t paddr32_t;
|
||||
typedef int64_t ssize_t;
|
||||
typedef int mode_t;
|
||||
typedef long dev_t;
|
||||
void yield();
|
||||
void _panic();
|
||||
|
||||
#endif /* _COMMON_H_ */
|
||||
|
|
|
|||
19
include/kernel/device.h
Normal file
19
include/kernel/device.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _DEVICE_H_
|
||||
#define _DEVICE_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
|
||||
typedef u64 dev_t;
|
||||
typedef u64 dev_class_t;
|
||||
|
||||
|
||||
dev_t device_create(void *private, dev_class_t class, const char *name);
|
||||
void device_destroy(dev_t device);
|
||||
dev_class_t device_class(dev_t dev);
|
||||
void *device_private_info(dev_t dev);
|
||||
|
||||
void device_layer_init();
|
||||
|
||||
#endif /* _DEVICE_H_ */
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _ELF_H_
|
||||
#define _ELF_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/proc.h>
|
||||
|
||||
#define ET_NONE 0
|
||||
#define ET_REL 1
|
||||
#define ET_EXEC 2
|
||||
|
||||
#define EI_CLASS 4
|
||||
#define EI_DATA 5
|
||||
#define EI_VERSION 6
|
||||
#define EI_OSABI 7
|
||||
#define EI_ABIVERSION 8
|
||||
#define EI_PAD 9
|
||||
|
||||
#define EI_CLASS_64 2
|
||||
#define EI_OSABI_SYSV 0
|
||||
|
||||
#define EM_X86_64 62
|
||||
|
||||
#define EI_VERSION_CURRENT 1
|
||||
|
||||
#define ELFCLASS64 2
|
||||
#define ELFDATA2LSB 1 /* Little endian, two's complement */
|
||||
|
||||
#define PT_NULL 0
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
|
||||
#define R_X86_64_NONE 0
|
||||
#define R_X86_64_64 1
|
||||
#define R_X86_64_PC32 2
|
||||
#define R_X86_64_RELATIVE 8
|
||||
|
||||
#define SHT_NULL 0x0
|
||||
#define SHT_PROGBITS 0x1
|
||||
#define SHT_SYMTAB 0x2
|
||||
#define SHT_STRTAB 0x3
|
||||
#define SHT_RELA 0x4
|
||||
#define SHT_HASH 0x5
|
||||
#define SHT_DYNAMIC 0x6
|
||||
#define SHT_NOTE 0x7
|
||||
#define SHT_NOBITS 0x8
|
||||
#define SHT_REL 0x9
|
||||
#define SHT_SHLIB 0x0A
|
||||
#define SHT_DYNSYM 0x0B
|
||||
#define SHT_INIT_ARRAY 0x0E
|
||||
#define SHT_FINI_ARRAY 0x0F
|
||||
#define SHT_PREINIT_ARRAY 0x10
|
||||
|
||||
#define SHF_WRITE 1
|
||||
#define SHF_ALLOC 2
|
||||
#define SHF_EXECINSTR 4
|
||||
|
||||
#define STB_LOCAL 0
|
||||
#define STB_GLOBAL 1
|
||||
#define STB_WEAK 2
|
||||
|
||||
#define STT_NOTYPE 0
|
||||
#define STT_OBJECT 1
|
||||
#define STT_FUNC 2
|
||||
|
||||
#define SHN_UNDEF 0
|
||||
#define SHN_ABS 0xFFF1
|
||||
#define SHN_COMMON 0xFFF2
|
||||
|
||||
#define PF_X 0x1
|
||||
#define PF_W 0x2
|
||||
#define PF_R 0x4
|
||||
|
||||
#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
|
||||
#define ELF64_R_SYM(i) ((i) >> 32)
|
||||
|
||||
#define ELF_RELOC_ERR -1
|
||||
|
||||
typedef uint64_t Elf64_Addr;
|
||||
typedef uint64_t Elf64_Off;
|
||||
typedef uint16_t Elf64_Section;
|
||||
typedef uint16_t Elf64_Versym;
|
||||
typedef unsigned char Elf_Byte;
|
||||
typedef uint16_t Elf64_Half;
|
||||
typedef int32_t Elf64_Sword;
|
||||
typedef uint32_t Elf64_Word;
|
||||
typedef int64_t Elf64_Sxword;
|
||||
typedef uint64_t Elf64_Xword;
|
||||
|
||||
typedef struct {
|
||||
unsigned char e_ident[16];
|
||||
uint16_t e_type;
|
||||
uint16_t e_machine;
|
||||
uint32_t e_version;
|
||||
Elf64_Addr e_entry;
|
||||
Elf64_Off e_phoff;
|
||||
Elf64_Off e_shoff;
|
||||
uint32_t e_flags;
|
||||
uint16_t e_ehsize;
|
||||
uint16_t e_phentsize;
|
||||
uint16_t e_phnum;
|
||||
uint16_t e_shentsize;
|
||||
uint16_t e_shnum;
|
||||
uint16_t e_shstrndx;
|
||||
} PACKED Elf64_Ehdr;
|
||||
|
||||
typedef struct {
|
||||
uint32_t p_type;
|
||||
uint32_t p_flags;
|
||||
Elf64_Off p_offset;
|
||||
Elf64_Addr p_vaddr;
|
||||
Elf64_Addr p_paddr;
|
||||
uint64_t p_filesz;
|
||||
uint64_t p_memsz;
|
||||
uint64_t p_align;
|
||||
} PACKED Elf64_Phdr;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sh_name;
|
||||
uint32_t sh_type;
|
||||
uint64_t sh_flags;
|
||||
Elf64_Addr sh_addr;
|
||||
Elf64_Off sh_offset;
|
||||
uint64_t sh_size;
|
||||
uint32_t sh_link;
|
||||
uint32_t sh_info;
|
||||
uint64_t sh_addralign;
|
||||
uint64_t sh_entsize;
|
||||
} PACKED Elf64_Shdr;
|
||||
|
||||
pid_t elf_load_proc(char *fname);
|
||||
|
||||
#endif /* _ELF_H_ */
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _GDT_H_
|
||||
#define _GDT_H_
|
||||
|
||||
#define GDT_NUMDESC 192
|
||||
#define GDT_SIZE (64 * GDT_NUMDESC)
|
||||
|
||||
#define GDT_ACCESS_DATA_RING0 0b10010010
|
||||
#define GDT_ACCESS_CODE_RING0 0b10011010
|
||||
|
||||
#define GDT_ACCESS_DATA_RING3 0b11110010
|
||||
#define GDT_ACCESS_CODE_RING3 0b11111010
|
||||
|
||||
#define GDT_SEGMENT_CODE_RING0 0x28
|
||||
#define GDT_SEGMENT_DATA_RING0 0x30
|
||||
|
||||
#define GDT_SEGMENT_DATA_RING3 0x38
|
||||
#define GDT_SEGMENT_CODE_RING3 0x40
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct gdt_desc {
|
||||
uint16_t limit;
|
||||
uint16_t base;
|
||||
uint8_t base_2;
|
||||
uint8_t access;
|
||||
uint8_t flags;
|
||||
uint8_t base_3;
|
||||
} PACKED;
|
||||
|
||||
struct gdt_desc_sys {
|
||||
uint16_t limit;
|
||||
uint16_t base;
|
||||
uint8_t base_2;
|
||||
uint8_t access;
|
||||
uint8_t flags;
|
||||
uint8_t base_3;
|
||||
uint32_t base_4;
|
||||
uint32_t reserved;
|
||||
} PACKED;
|
||||
|
||||
struct tss {
|
||||
uint32_t reserved;
|
||||
uint64_t rsp0;
|
||||
uint64_t rsp1;
|
||||
uint64_t rsp2;
|
||||
uint64_t reserved2;
|
||||
uint64_t ist1;
|
||||
uint64_t ist2;
|
||||
uint64_t ist3;
|
||||
uint64_t ist4;
|
||||
uint64_t ist5;
|
||||
uint64_t ist6;
|
||||
uint64_t ist7;
|
||||
uint64_t reserved3;
|
||||
uint16_t reserved4;
|
||||
uint16_t iomap_base;
|
||||
} PACKED;
|
||||
|
||||
struct gdtr {
|
||||
uint16_t size;
|
||||
uint64_t offset;
|
||||
} PACKED;
|
||||
|
||||
extern struct gdtr __gdtr;
|
||||
extern struct gdt_desc __gdt[GDT_NUMDESC];
|
||||
|
||||
void gdt_init();
|
||||
uint16_t gdt_insert_tss(uintptr_t rsp0);
|
||||
void ltr(uint16_t selector);
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _GDT_H_ */
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _GPT_H_
|
||||
#define _GPT_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct block_device;
|
||||
|
||||
/* GPT LBA 0 */
|
||||
struct gpt_mbr_prot {
|
||||
uint8_t boot[1];
|
||||
uint8_t chs_start[3];
|
||||
uint8_t type[1];
|
||||
uint8_t chs_end[3];
|
||||
uint8_t lba_start[4];
|
||||
uint8_t lba_size[4];
|
||||
} PACKED;
|
||||
|
||||
/* GPT LBA 1
|
||||
* checksums use CRC32
|
||||
*/
|
||||
struct gpt_header {
|
||||
uint64_t signature;
|
||||
uint8_t revision[4];
|
||||
uint8_t header_size[4];
|
||||
uint8_t checksum[4];
|
||||
uint8_t reserved[4];
|
||||
uint64_t lba_this;
|
||||
uint64_t lba_alt;
|
||||
uint64_t lba_first;
|
||||
uint64_t lba_last;
|
||||
uint8_t guid[16];
|
||||
uint64_t lba_table;
|
||||
uint32_t entry_count;
|
||||
uint32_t entry_size;
|
||||
uint32_t checksum_table;
|
||||
} PACKED;
|
||||
|
||||
/* GPT LBA 2 */
|
||||
struct gpt_entry {
|
||||
uint64_t type_guid[2];
|
||||
uint64_t unique_guid[2];
|
||||
uint64_t lba_first;
|
||||
uint64_t lba_last;
|
||||
uint64_t flags;
|
||||
uint8_t name[72];
|
||||
} PACKED;
|
||||
|
||||
void block_gpt_init(struct block_device *dev);
|
||||
|
||||
#endif /* _GPT_H_ */
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _IDT_H_
|
||||
#define _IDT_H_
|
||||
|
||||
#define GATE_INTR 0x8E
|
||||
#define GATE_TRAP 0x8F
|
||||
|
||||
#define GATE_INTR_DPL3 0xEE
|
||||
|
||||
#define IDT_GATE_SIZE 16
|
||||
#define IDT_NUM_VECTORS 256
|
||||
#define IDT_SIZE (IDT_GATE_SIZE * IDT_NUM_VECTORS)
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct irqdesc {
|
||||
uint16_t offset_low;
|
||||
uint16_t segment;
|
||||
uint8_t ist;
|
||||
uint8_t attrs;
|
||||
uint16_t offset_mid;
|
||||
uint32_t offset_high;
|
||||
uint32_t reserved;
|
||||
} PACKED;
|
||||
|
||||
struct idtr {
|
||||
uint16_t size;
|
||||
uint64_t offset;
|
||||
} PACKED;
|
||||
|
||||
void idt_init();
|
||||
void cli();
|
||||
void sti();
|
||||
|
||||
extern struct idtr __idtr;
|
||||
extern struct irqdesc __idt[IDT_NUM_VECTORS];
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _IDT_H_ */
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _IRQ_H_
|
||||
#define _IRQ_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
int irq_map(uint8_t irq, void *func);
|
||||
void irq_unmap(uint8_t irq);
|
||||
int irq_highest_free();
|
||||
|
||||
#endif /* _IRQ_H_ */
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _LOCK_H_
|
||||
#define _LOCK_H_
|
||||
|
||||
typedef int spinlock_t;
|
||||
typedef spinlock_t mtx_t;
|
||||
|
||||
int atomic_cmpxchg(volatile int *ptr, int cmpval, int newval);
|
||||
void spinlock_acquire(spinlock_t *lock);
|
||||
void spinlock_release(spinlock_t *lock);
|
||||
|
||||
void mtx_acquire(mtx_t *mtx);
|
||||
void mtx_release(mtx_t *mtx);
|
||||
|
||||
#endif /* _LOCK_H_ */
|
||||
|
|
@ -3,25 +3,12 @@
|
|||
#define _MEM_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/rbtree.h>
|
||||
|
||||
#define BBMAP_FREE 0
|
||||
#define BBMAP_SPLIT 1
|
||||
#define BBMAP_USED 2
|
||||
|
||||
#define PAGE_PRESENT 0x1
|
||||
#define PAGE_RW 0x2
|
||||
#define PAGE_USER 0x4
|
||||
#define PAGE_XD 0x8000000000000000
|
||||
|
||||
#define PAGE_PWT 0x8
|
||||
#define PAGE_PCD 0x10
|
||||
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
|
||||
#ifndef __ASM__
|
||||
#include <kernel/spinlock.h>
|
||||
|
||||
#define ALIGN(_a) __attribute__((aligned(_a)))
|
||||
#define PHYSICAL_PAGE_MASK (~(hhdm_start))
|
||||
#define TO_VIRT(addr) ((addr) | hhdm_start)
|
||||
#define TO_PHYS(addr) ((addr) & PHYSICAL_PAGE_MASK)
|
||||
|
||||
#define genrw(reg) \
|
||||
uint64_t reg##_read(); \
|
||||
|
|
@ -35,90 +22,14 @@ genrw(ds);
|
|||
|
||||
#undef genrw
|
||||
|
||||
struct proc;
|
||||
|
||||
struct page { /* I would rather refer to this as a struct */
|
||||
union {
|
||||
struct {
|
||||
uint64_t present : 1;
|
||||
uint64_t rw : 1;
|
||||
uint64_t usermode : 1;
|
||||
uint64_t pwt : 1;
|
||||
uint64_t pcd : 1;
|
||||
uint64_t accessed : 1;
|
||||
uint64_t ignored : 1;
|
||||
uint64_t zero : 1;
|
||||
uint64_t ignored_2 : 4;
|
||||
uint64_t addr : 36;
|
||||
uint64_t reserved : 4;
|
||||
uint64_t ignored_3 : 11;
|
||||
uint64_t xd : 1;
|
||||
};
|
||||
uint64_t val;
|
||||
};
|
||||
};
|
||||
|
||||
struct cr3 {
|
||||
union {
|
||||
struct {
|
||||
uint64_t ignored : 3;
|
||||
uint64_t pwt : 1;
|
||||
uint64_t pcd : 1;
|
||||
uint64_t ignored_2 : 7;
|
||||
uint64_t pml4_addr : 52;
|
||||
};
|
||||
uint64_t val;
|
||||
};
|
||||
};
|
||||
|
||||
struct mem_region {
|
||||
paddr_t base;
|
||||
struct mem_zone {
|
||||
uintptr_t virt_base;
|
||||
size_t len;
|
||||
bool usable;
|
||||
};
|
||||
|
||||
struct buddy_region_header {
|
||||
paddr_t usable_base;
|
||||
size_t usable_len;
|
||||
size_t max_depth;
|
||||
|
||||
size_t bitmap_len;
|
||||
char bitmap[];
|
||||
};
|
||||
|
||||
extern uintptr_t __data_end;
|
||||
extern uintptr_t __bss_start;
|
||||
extern uintptr_t __bss_end;
|
||||
size_t mem_get_zones(struct mem_zone **ret);
|
||||
void mem_init();
|
||||
|
||||
extern uintptr_t hhdm_start;
|
||||
extern uintptr_t data_end;
|
||||
extern uintptr_t bss_start;
|
||||
extern uintptr_t bss_end;
|
||||
|
||||
extern struct mem_region *regions;
|
||||
extern size_t num_regions;
|
||||
extern size_t max_regions;
|
||||
|
||||
extern struct rbtree *kmap_tree;
|
||||
extern spinlock_t kmap_lock;
|
||||
|
||||
extern struct page *pml4;
|
||||
extern paddr_t kcr3;
|
||||
extern struct page kdefault_attrs;
|
||||
|
||||
void *buddy_alloc(size_t size);
|
||||
void buddy_free(void *paddr_hhdm);
|
||||
uintptr_t mmap_find_unmapped(struct rbtree *tree, spinlock_t *lock, uintptr_t start, size_t len);
|
||||
void kmap(paddr_t paddr, uintptr_t vaddr, size_t len, uint64_t attr);
|
||||
void *proc_mmap(struct proc *proc, paddr_t paddr, uintptr_t vaddr, size_t len, uint64_t attr);
|
||||
void *kmap_device(void *dev_paddr, size_t len);
|
||||
void proc_munmap(struct proc *proc, uintptr_t vaddr);
|
||||
paddr_t proc_clone_mmap(struct proc *in, struct proc *out);
|
||||
paddr_t virt_to_phys(uintptr_t vaddr, paddr_t page_base);
|
||||
void mem_early_init(char *mem, size_t len);
|
||||
uint64_t phys_read(paddr_t paddr);
|
||||
void phys_write(paddr_t paddr, uint64_t data);
|
||||
void *phys_memcpy(void *dest, paddr_t src, size_t num);
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _MEM_H_ */
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _MSR_H_
|
||||
#define _MSR_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
#define MSR_APIC_BASE 0x1B
|
||||
|
||||
#define MSR_IA32_EFER 0xC0000080
|
||||
#define MSR_IA32_STAR 0xC0000081
|
||||
#define MSR_IA32_LSTAR 0xC0000082
|
||||
#define MSR_IA32_FMASK 0xC0000084
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
uint64_t rdmsr(uint32_t msr);
|
||||
void wrmsr(uint32_t msr, uint64_t val);
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _MSR_H_ */
|
||||
25
include/kernel/page.h
Normal file
25
include/kernel/page.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _PAGE_H_
|
||||
#define _PAGE_H_
|
||||
|
||||
#include <kernel/types.h>
|
||||
|
||||
#define PAGE_FLAGS_EMPTY(flags) (!((flags) & PAGE_PRESENT))
|
||||
|
||||
typedef struct {
|
||||
u64 pgd;
|
||||
} pgd_t; /* PML4 entries */
|
||||
typedef struct {
|
||||
u64 pud;
|
||||
} pud_t; /* PDPT entries */
|
||||
typedef struct {
|
||||
u64 pmd;
|
||||
} pmd_t; /* PD entries */
|
||||
typedef struct {
|
||||
u64 pte;
|
||||
} pte_t; /* page table entries */
|
||||
|
||||
void page_init();
|
||||
pgd_t *pgd_get();
|
||||
|
||||
#endif /* _PAGE_H_ */
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _PIO_H_
|
||||
#define _PIO_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define genio(suffix, type) \
|
||||
void out##suffix(uint16_t port, type value); \
|
||||
type in##suffix(uint16_t port);
|
||||
|
||||
genio(b, uint8_t);
|
||||
genio(w, uint16_t);
|
||||
genio(l, uint32_t);
|
||||
|
||||
#undef genio
|
||||
|
||||
void iowait();
|
||||
|
||||
#endif /* _PIO_H_ */
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _PROC_H_
|
||||
#define _PROC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <kernel/lock.h>
|
||||
#include <kernel/rbtree.h>
|
||||
#include <kernel/slab.h>
|
||||
|
||||
#include <lib/sem.h>
|
||||
|
||||
#define PROC_RUNNING 0
|
||||
#define PROC_STOPPED 1
|
||||
#define PROC_ALLOWSCHED 1
|
||||
#define PROC_BLOCKED 2
|
||||
#define PROC_YIELD 3
|
||||
#define PROC_ZOMBIE 4
|
||||
|
||||
#define PT_USER 0
|
||||
#define PT_KERN 1
|
||||
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
#define STDERR_FILENO 2
|
||||
|
||||
#define USER_STACK_BASE 0x0000070000000000
|
||||
#define USER_HEAP_BASE 0x0000000100000000 /* 4GB */
|
||||
|
||||
#define PM_BUD 0
|
||||
#define PM_SLB 1
|
||||
|
||||
typedef int64_t pid_t;
|
||||
|
||||
struct proc_mmap_entry {
|
||||
uintptr_t vaddr;
|
||||
paddr_t paddr;
|
||||
size_t len;
|
||||
uint64_t attr;
|
||||
uint64_t type;
|
||||
};
|
||||
|
||||
struct procregs {
|
||||
uint64_t rax;
|
||||
uint64_t rbx;
|
||||
uint64_t rcx;
|
||||
uint64_t rdx;
|
||||
uint64_t rsi;
|
||||
uint64_t rdi;
|
||||
uint64_t rbp;
|
||||
uint64_t r8;
|
||||
uint64_t r9;
|
||||
uint64_t r10;
|
||||
uint64_t r11;
|
||||
uint64_t r12;
|
||||
uint64_t r13;
|
||||
uint64_t r14;
|
||||
uint64_t r15;
|
||||
|
||||
/* IRETQ stack frame */
|
||||
uint64_t rip;
|
||||
uint64_t cs;
|
||||
uint64_t rflags;
|
||||
uint64_t rsp;
|
||||
uint64_t ss;
|
||||
|
||||
} PACKED;
|
||||
|
||||
struct proc_mapping {
|
||||
uintptr_t vaddr;
|
||||
paddr_t paddr;
|
||||
size_t len;
|
||||
uint64_t attr;
|
||||
uint64_t type;
|
||||
slab_t *slab;
|
||||
struct proc_mapping *next;
|
||||
};
|
||||
|
||||
struct proc_allocation {
|
||||
struct proc_mapping *mappings;
|
||||
struct proc_mapping *last;
|
||||
size_t num_mappings;
|
||||
};
|
||||
|
||||
struct proc {
|
||||
struct procregs regs;
|
||||
uint8_t state;
|
||||
pid_t pid;
|
||||
pid_t ppid;
|
||||
uint64_t cr3;
|
||||
spinlock_t lock;
|
||||
|
||||
bool is_kernel;
|
||||
|
||||
struct rbtree page_map;
|
||||
spinlock_t page_map_lock;
|
||||
|
||||
struct rbtree fd_map;
|
||||
spinlock_t fd_map_lock;
|
||||
|
||||
struct proc *parent;
|
||||
struct rbtree children;
|
||||
|
||||
struct proc *buddy_proc;
|
||||
|
||||
uintptr_t stack_start;
|
||||
uintptr_t stack_size;
|
||||
|
||||
uintptr_t heap_start;
|
||||
|
||||
struct rbtree umalloc_tree;
|
||||
};
|
||||
|
||||
struct procregs *proc_current_regs();
|
||||
struct proc *proc_create();
|
||||
struct proc *proc_createv(int flags);
|
||||
void proc_init_memory(struct proc *proc, uint64_t mem_flags);
|
||||
void proc_init_page_tables(struct proc *proc);
|
||||
struct proc *proc_fork(struct proc *parent);
|
||||
struct proc *proc_get(pid_t pid);
|
||||
pid_t getpid();
|
||||
pid_t getupid();
|
||||
void proc_term(pid_t pid);
|
||||
struct proc *proc_find(pid_t pid);
|
||||
void proc_save_state();
|
||||
void proc_set_current(pid_t pid);
|
||||
void proc_init(unsigned num_cpus);
|
||||
void trap_sched();
|
||||
void schedule();
|
||||
void syscall_block();
|
||||
void proc_set_exec_addr(struct proc *proc, uintptr_t addr);
|
||||
void proc_set_flags(struct proc *proc, uint64_t flags);
|
||||
void proc_set_stack(struct proc *proc, uintptr_t base, size_t size);
|
||||
void proc_set_state(pid_t pid, uint8_t state);
|
||||
|
||||
void sswtch();
|
||||
|
||||
#endif /* _PROC_H_ */
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _RBTREE_H_
|
||||
#define _RBTREE_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/lock.h>
|
||||
|
||||
#define RB_RED 0
|
||||
#define RB_BLACK 1
|
||||
|
||||
struct rbnode {
|
||||
struct rbnode *parent;
|
||||
struct rbnode *left;
|
||||
struct rbnode *right;
|
||||
int color;
|
||||
|
||||
uint64_t key;
|
||||
uint64_t value; /* extra values */
|
||||
uint64_t value2;
|
||||
uint64_t value3;
|
||||
};
|
||||
|
||||
/* we use this rbtree structure because the root node will potentially be
|
||||
* changed when we insert or delete a node
|
||||
*/
|
||||
struct rbtree {
|
||||
struct rbnode *root;
|
||||
spinlock_t lock;
|
||||
size_t num_nodes;
|
||||
};
|
||||
|
||||
struct rbnode *rbt_insert(struct rbtree *tree, uint64_t key);
|
||||
void rbt_delete(struct rbtree *tree, struct rbnode *del);
|
||||
void rbt_destroy(struct rbtree *tree);
|
||||
struct rbnode *rbt_search(struct rbtree *tree, uint64_t key);
|
||||
struct rbnode *rbt_successor(struct rbnode *node);
|
||||
uint64_t rbt_next_key(struct rbtree *tree);
|
||||
struct rbnode *rbt_range_val2(struct rbtree *tree, uint64_t sval, uint64_t len);
|
||||
struct rbnode *rbt_minimum(struct rbnode *node);
|
||||
|
||||
void rbt_slab_init();
|
||||
|
||||
#endif /* _RBTREE_H_ */
|
||||
13
include/kernel/requests.h
Normal file
13
include/kernel/requests.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _REQUESTS_H_
|
||||
#define _REQUESTS_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
extern struct limine_executable_address_response *kern_addr_res;
|
||||
extern struct limine_memmap_response *kern_map_res;
|
||||
extern struct limine_hhdm_response *kern_hhdm_res;
|
||||
|
||||
void requests_init();
|
||||
|
||||
#endif /* _REQUESTS_H_ */
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _RINGBUF_H
|
||||
#define _RINGBUF_H
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
typedef struct _ringbuf {
|
||||
char *buf;
|
||||
size_t size;
|
||||
size_t head;
|
||||
size_t tail;
|
||||
} ringbuf_t;
|
||||
|
||||
ringbuf_t *ringbuf_create(size_t size);
|
||||
void ringbuf_destroy(ringbuf_t *rb);
|
||||
|
||||
size_t ringbuf_write(ringbuf_t *rb, const char *buf, size_t count);
|
||||
size_t ringbuf_read(ringbuf_t *rb, char *buf, size_t count);
|
||||
|
||||
#endif /* _RINGBUF_H */
|
||||
|
|
@ -3,62 +3,23 @@
|
|||
#define _SLAB_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/mem.h>
|
||||
#include <kernel/lock.h>
|
||||
#include <kernel/spinlock.h>
|
||||
|
||||
#define SLAB_PAGE_ALIGN 0x01
|
||||
#define SLAB_DMA_64K 0x02
|
||||
typedef struct _mem_cache_t {
|
||||
size_t item_size;
|
||||
size_t cache_size;
|
||||
size_t offset;
|
||||
size_t alignment; /* must be a power of 2 */
|
||||
size_t num_members;
|
||||
size_t num_free;
|
||||
uintptr_t next_free;
|
||||
spinlock_t lock;
|
||||
struct _mem_cache_t *next;
|
||||
} mem_cache_t;
|
||||
|
||||
#define ALLOC_KERN 0x01
|
||||
#define ALLOC_DMA 0x02
|
||||
|
||||
#define UA_SLAB 0x1
|
||||
#define UA_BUD 0x2
|
||||
|
||||
#define ALLOC_USER 0x0
|
||||
#define ALLOC_USER_STACK 0x1
|
||||
#define ALLOC_USER_RDONLY 0x2
|
||||
#define ALLOC_USER_EXEC 0x4
|
||||
|
||||
#define ATTEMPT_FREE(_x) \
|
||||
if (_x) { \
|
||||
kfree(_x); \
|
||||
_x = NULL; \
|
||||
}
|
||||
|
||||
typedef struct _slab {
|
||||
size_t size; /* size of each object */
|
||||
size_t tsize; /* total size of this slab */
|
||||
size_t num; /* number of objects in this slab */
|
||||
size_t free; /* number of free objects */
|
||||
uint64_t flags;
|
||||
size_t align;
|
||||
uintptr_t *nextfree;
|
||||
struct _slab *next;
|
||||
struct _slab *prev;
|
||||
|
||||
spinlock_t lock;
|
||||
} slab_t;
|
||||
|
||||
struct kmap_entry {
|
||||
uintptr_t *ptr;
|
||||
size_t size;
|
||||
slab_t *slab;
|
||||
struct kmap_entry *next;
|
||||
};
|
||||
|
||||
slab_t *slab_create(size_t size, size_t cache_size, uint64_t flags);
|
||||
void *slab_alloc(slab_t *slab);
|
||||
void slab_free(slab_t *slab, void *ptr);
|
||||
|
||||
void kmalloc_init();
|
||||
void *kmalloc(size_t size, uint64_t flags);
|
||||
void *kzalloc(size_t size, uint64_t flags);
|
||||
void *krealloc(void *ptr, size_t size, uint64_t flags);
|
||||
void kfree(void *ptr);
|
||||
void *umalloc(struct proc *proc, size_t size, uint64_t opts, uintptr_t req_addr);
|
||||
void ufree(struct proc *proc, void *ptr);
|
||||
|
||||
void slabtypes_init();
|
||||
mem_cache_t *slab_create(size_t item_size, size_t cache_size, size_t alignment);
|
||||
void *slab_alloc(mem_cache_t *cache);
|
||||
void slab_free(mem_cache_t *cache, void *ptr);
|
||||
|
||||
#endif /* _SLAB_H_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _SYSCALL_H_
|
||||
#define _SYSCALL_H_
|
||||
|
||||
#define SYS_READ 0
|
||||
#define SYS_WRITE 1
|
||||
#define SYS_OPEN 2
|
||||
#define SYS_MMAP 9
|
||||
#define SYS_MUNMAP 11
|
||||
#define SYS_FORK 57
|
||||
#define SYS_EXIT 60
|
||||
#define SYS_MKDIR 83
|
||||
#define SYS_MKNOD 133
|
||||
#define SYS_LSDIR 254
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/proc.h>
|
||||
|
||||
void sys_set_return(struct proc *proc, uint64_t ret);
|
||||
void sswtch(); /* save and switch */
|
||||
|
||||
#endif /* _SYSCALL_H_ */
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _TRAP_H_
|
||||
#define _TRAP_H_
|
||||
|
||||
void exception(int vector, int error);
|
||||
void exception_init();
|
||||
|
||||
#endif
|
||||
27
include/kernel/types.h
Normal file
27
include/kernel/types.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _TYPES_H_
|
||||
#define _TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define KB (1024ull)
|
||||
#define MB (KB * KB)
|
||||
#define GB (MB * MB)
|
||||
|
||||
typedef uintptr_t paddr_t;
|
||||
typedef uint32_t paddr32_t;
|
||||
typedef int64_t ssize_t;
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int32_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
#endif /* _TYPES_H_ */
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _UMEM_H_
|
||||
#define _UMEM_H_
|
||||
|
||||
#include <kernel/proc.h>
|
||||
|
||||
void copy_to_user(struct proc *proc, void *dst, const void *src, size_t size);
|
||||
|
||||
#endif /* _UMEM_H_ */
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _ASSERT_H_
|
||||
#define _ASSERT_H_
|
||||
|
||||
#ifdef KDEBUG
|
||||
#define assert(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
kprintf(LOG_ERROR "assertion failed: %s, file %s, line %d\n", #expr, __FILE__, __LINE__); \
|
||||
yield(); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define assert(expr) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif /* _ASSERT_H_ */
|
||||
40
include/lib/rbtree.h
Normal file
40
include/lib/rbtree.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _RBTREE_H_
|
||||
#define _RBTREE_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/spinlock.h>
|
||||
|
||||
#define RB_RED 0
|
||||
#define RB_BLACK 1
|
||||
|
||||
typedef struct _rbnode {
|
||||
struct _rbnode *parent;
|
||||
struct _rbnode *left;
|
||||
struct _rbnode *right;
|
||||
int color;
|
||||
|
||||
u64 key;
|
||||
u64 value;
|
||||
} rbnode;
|
||||
|
||||
/* we use this rbtree structure because the root node will potentially be
|
||||
* changed when we insert or delete a node
|
||||
*/
|
||||
typedef struct _rbtree {
|
||||
rbnode *root;
|
||||
spinlock_t lock;
|
||||
size_t num_nodes;
|
||||
} rbtree;
|
||||
|
||||
rbnode *rbt_insert(rbtree *tree, u64 key);
|
||||
void rbt_delete(rbtree *tree, rbnode *del);
|
||||
void rbt_destroy(rbtree *tree);
|
||||
rbnode *rbt_search(rbtree *tree, u64 key);
|
||||
rbnode *rbt_successor(rbnode *node);
|
||||
u64 rbt_next_key(rbtree *tree);
|
||||
rbnode *rbt_minimum(rbnode *node);
|
||||
|
||||
void rbt_slab_init();
|
||||
|
||||
#endif /* _RBTREE_H_ */
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _SEM_H_
|
||||
#define _SEM_H_
|
||||
|
||||
#include <kernel/lock.h>
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
spinlock_t lock;
|
||||
} sem_t;
|
||||
|
||||
sem_t *sem_create(int count);
|
||||
void sem_destroy(sem_t *sem);
|
||||
|
||||
int sem_trywait(sem_t *sem);
|
||||
void sem_post(sem_t *sem);
|
||||
|
||||
#endif /* _SEM_H_ */
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _SORT_H_
|
||||
#define _SORT_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
|
||||
#endif /* _SORT_H_ */
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _STACK_H_
|
||||
#define _STACK_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct stack_node {
|
||||
struct stack_node *next;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct stack {
|
||||
struct stack_node *top;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
void stack_init();
|
||||
struct stack *stack_create();
|
||||
void stack_destroy(struct stack *stack);
|
||||
void stack_push(struct stack *stack, void *data);
|
||||
void *stack_pop(struct stack *stack);
|
||||
void *stack_peek(struct stack *stack);
|
||||
|
||||
#endif /* _STACK_H_ */
|
||||
|
|
@ -2,24 +2,42 @@
|
|||
#ifndef _STDIO_H_
|
||||
#define _STDIO_H_
|
||||
|
||||
#define COL_RED_BLACK "\e[31m"
|
||||
#define COL_YELLOW_BLACK "\e[33m"
|
||||
#define COL_GREEN_BLACK "\e[32m"
|
||||
#define COL_MAGENTA_BLACK "\e[35m"
|
||||
#include <kernel/types.h>
|
||||
|
||||
#define COL_RESET "\e[m"
|
||||
struct tty;
|
||||
|
||||
#define COL_RED_BLACK "\033[31m"
|
||||
#define COL_YELLOW_BLACK "\033[33m"
|
||||
#define COL_GREEN_BLACK "\033[32m"
|
||||
#define COL_MAGENTA_BLACK "\033[35m"
|
||||
#define COL_BLUE_BLACK "\033[34m"
|
||||
#define COL_CYAN_BLACK "\033[36m"
|
||||
#define COL_WHITE_BLACK "\033[37m"
|
||||
|
||||
#define COL_RESET "\033[m"
|
||||
|
||||
#define LOG_ERROR "[" COL_RED_BLACK "ERR" COL_RESET "] "
|
||||
#define LOG_PANIC "[" COL_RED_BLACK "PANIC" COL_RESET "] "
|
||||
#define LOG_WARN "[" COL_YELLOW_BLACK "WRN" COL_RESET "] "
|
||||
#define LOG_DEBUG "[" COL_MAGENTA_BLACK "DBG" COL_RESET "] "
|
||||
#define LOG_SUCCESS "[" COL_GREEN_BLACK "RDY" COL_RESET "] "
|
||||
#define LOG_READY "[" COL_GREEN_BLACK "RDY" COL_RESET "] "
|
||||
#define LOG_INFO "[LOG] "
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#define kprintf(...) (printf_(__VA_ARGS__))
|
||||
#define kinfo(...) (kprintf(LOG_INFO __VA_ARGS__))
|
||||
#define kwarn(...) (kprintf(LOG_WARN __VA_ARGS__))
|
||||
#define kerr(...) (kprintf(LOG_ERROR __VA_ARGS__))
|
||||
#define krdy(...) (kprintf(LOG_READY __VA_ARGS__))
|
||||
#ifdef KDEBUG
|
||||
#define kdebug(...) (kprintf(LOG_DEBUG __VA_ARGS__))
|
||||
#else
|
||||
#define kdebug(...) (void)0;
|
||||
#endif /* KDEBUG */
|
||||
#define snprintf(...) (snprintf_(__VA_ARGS__))
|
||||
|
||||
int kprintf(const char *restrict fmt, ...);
|
||||
int snprintf(char *str, const char *restrict fmt, size_t size, ...);
|
||||
int vsnprintf(char *str, const char *restrict fmt, size_t size, va_list args);
|
||||
int printf_(const char *fmt, ...);
|
||||
int snprintf_(char *buffer, size_t count, const char *format, ...);
|
||||
|
||||
#endif /* _SDTIO_H_ */
|
||||
extern struct tty *tty_printf;
|
||||
|
||||
#endif /* _STDIO_H_ */
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <kernel/lock.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num);
|
||||
int memcmp(const void *aa, const void *bb, size_t num);
|
||||
|
|
@ -23,7 +22,5 @@ char **strsplit(const char *str, char delim, int *num);
|
|||
size_t strlen(const char *c);
|
||||
int atoi(const char *a);
|
||||
|
||||
extern spinlock_t strtok_lock;
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _STRING_H_ */
|
||||
|
|
|
|||
|
|
@ -1,468 +0,0 @@
|
|||
/* BSD Zero Clause License */
|
||||
|
||||
/* Copyright (C) 2022-2023 mintsuki and contributors.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: 0BSD
|
||||
*/
|
||||
|
||||
#ifndef _LIMINE_H
|
||||
#define _LIMINE_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Misc */
|
||||
|
||||
#ifdef LIMINE_NO_POINTERS
|
||||
# define LIMINE_PTR(TYPE) uint64_t
|
||||
#else
|
||||
# define LIMINE_PTR(TYPE) TYPE
|
||||
#endif
|
||||
|
||||
#define LIMINE_COMMON_MAGIC 0xc7b1dd30df4c8b88, 0x0a82e883a194f07b
|
||||
|
||||
struct limine_uuid {
|
||||
uint32_t a;
|
||||
uint16_t b;
|
||||
uint16_t c;
|
||||
uint8_t d[8];
|
||||
};
|
||||
|
||||
#define LIMINE_MEDIA_TYPE_GENERIC 0
|
||||
#define LIMINE_MEDIA_TYPE_OPTICAL 1
|
||||
#define LIMINE_MEDIA_TYPE_TFTP 2
|
||||
|
||||
struct limine_file {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
uint64_t size;
|
||||
LIMINE_PTR(char *) path;
|
||||
LIMINE_PTR(char *) cmdline;
|
||||
uint32_t media_type;
|
||||
uint32_t unused;
|
||||
uint32_t tftp_ip;
|
||||
uint32_t tftp_port;
|
||||
uint32_t partition_index;
|
||||
uint32_t mbr_disk_id;
|
||||
struct limine_uuid gpt_disk_uuid;
|
||||
struct limine_uuid gpt_part_uuid;
|
||||
struct limine_uuid part_uuid;
|
||||
};
|
||||
|
||||
/* Boot info */
|
||||
|
||||
#define LIMINE_BOOTLOADER_INFO_REQUEST { LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
|
||||
|
||||
struct limine_bootloader_info_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(char *) name;
|
||||
LIMINE_PTR(char *) version;
|
||||
};
|
||||
|
||||
struct limine_bootloader_info_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_bootloader_info_response *) response;
|
||||
};
|
||||
|
||||
/* Stack size */
|
||||
|
||||
#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
|
||||
|
||||
struct limine_stack_size_response {
|
||||
uint64_t revision;
|
||||
};
|
||||
|
||||
struct limine_stack_size_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_stack_size_response *) response;
|
||||
uint64_t stack_size;
|
||||
};
|
||||
|
||||
/* HHDM */
|
||||
|
||||
#define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
|
||||
|
||||
struct limine_hhdm_response {
|
||||
uint64_t revision;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
struct limine_hhdm_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_hhdm_response *) response;
|
||||
};
|
||||
|
||||
/* Framebuffer */
|
||||
|
||||
#define LIMINE_FRAMEBUFFER_REQUEST { LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
|
||||
|
||||
#define LIMINE_FRAMEBUFFER_RGB 1
|
||||
|
||||
struct limine_video_mode {
|
||||
uint64_t pitch;
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
uint16_t bpp;
|
||||
uint8_t memory_model;
|
||||
uint8_t red_mask_size;
|
||||
uint8_t red_mask_shift;
|
||||
uint8_t green_mask_size;
|
||||
uint8_t green_mask_shift;
|
||||
uint8_t blue_mask_size;
|
||||
uint8_t blue_mask_shift;
|
||||
};
|
||||
|
||||
struct limine_framebuffer {
|
||||
LIMINE_PTR(void *) address;
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
uint64_t pitch;
|
||||
uint16_t bpp;
|
||||
uint8_t memory_model;
|
||||
uint8_t red_mask_size;
|
||||
uint8_t red_mask_shift;
|
||||
uint8_t green_mask_size;
|
||||
uint8_t green_mask_shift;
|
||||
uint8_t blue_mask_size;
|
||||
uint8_t blue_mask_shift;
|
||||
uint8_t unused[7];
|
||||
uint64_t edid_size;
|
||||
LIMINE_PTR(void *) edid;
|
||||
/* Response revision 1 */
|
||||
uint64_t mode_count;
|
||||
LIMINE_PTR(struct limine_video_mode **) modes;
|
||||
};
|
||||
|
||||
struct limine_framebuffer_response {
|
||||
uint64_t revision;
|
||||
uint64_t framebuffer_count;
|
||||
LIMINE_PTR(struct limine_framebuffer **) framebuffers;
|
||||
};
|
||||
|
||||
struct limine_framebuffer_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_framebuffer_response *) response;
|
||||
};
|
||||
|
||||
/* Terminal */
|
||||
|
||||
#define LIMINE_TERMINAL_REQUEST { LIMINE_COMMON_MAGIC, 0xc8ac59310c2b0844, 0xa68d0c7265d38878 }
|
||||
|
||||
#define LIMINE_TERMINAL_CB_DEC 10
|
||||
#define LIMINE_TERMINAL_CB_BELL 20
|
||||
#define LIMINE_TERMINAL_CB_PRIVATE_ID 30
|
||||
#define LIMINE_TERMINAL_CB_STATUS_REPORT 40
|
||||
#define LIMINE_TERMINAL_CB_POS_REPORT 50
|
||||
#define LIMINE_TERMINAL_CB_KBD_LEDS 60
|
||||
#define LIMINE_TERMINAL_CB_MODE 70
|
||||
#define LIMINE_TERMINAL_CB_LINUX 80
|
||||
|
||||
#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t)(-1))
|
||||
#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t)(-2))
|
||||
#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t)(-3))
|
||||
#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t)(-4))
|
||||
|
||||
/* Response revision 1 */
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t)(-10))
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t)(-11))
|
||||
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OFILL (1 << 2)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OLCUC (1 << 3)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_ONLCR (1 << 4)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_ONLRET (1 << 5)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_ONOCR (1 << 6)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OPOST (1 << 7)
|
||||
|
||||
struct limine_terminal;
|
||||
|
||||
typedef void (*limine_terminal_write)(struct limine_terminal *, const char *, uint64_t);
|
||||
typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
struct limine_terminal {
|
||||
uint64_t columns;
|
||||
uint64_t rows;
|
||||
LIMINE_PTR(struct limine_framebuffer *) framebuffer;
|
||||
};
|
||||
|
||||
struct limine_terminal_response {
|
||||
uint64_t revision;
|
||||
uint64_t terminal_count;
|
||||
LIMINE_PTR(struct limine_terminal **) terminals;
|
||||
LIMINE_PTR(limine_terminal_write) write;
|
||||
};
|
||||
|
||||
struct limine_terminal_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_terminal_response *) response;
|
||||
LIMINE_PTR(limine_terminal_callback) callback;
|
||||
};
|
||||
|
||||
/* 5-level paging */
|
||||
|
||||
#define LIMINE_5_LEVEL_PAGING_REQUEST { LIMINE_COMMON_MAGIC, 0x94469551da9b3192, 0xebe5e86db7382888 }
|
||||
|
||||
struct limine_5_level_paging_response {
|
||||
uint64_t revision;
|
||||
};
|
||||
|
||||
struct limine_5_level_paging_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_5_level_paging_response *) response;
|
||||
};
|
||||
|
||||
/* SMP */
|
||||
|
||||
#define LIMINE_SMP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
|
||||
|
||||
struct limine_smp_info;
|
||||
|
||||
typedef void (*limine_goto_address)(struct limine_smp_info *);
|
||||
|
||||
#if defined (__x86_64__) || defined (__i386__)
|
||||
|
||||
#define LIMINE_SMP_X2APIC (1 << 0)
|
||||
|
||||
struct limine_smp_info {
|
||||
uint32_t processor_id;
|
||||
uint32_t lapic_id;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
struct limine_smp_response {
|
||||
uint64_t revision;
|
||||
uint32_t flags;
|
||||
uint32_t bsp_lapic_id;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct limine_smp_info **) cpus;
|
||||
};
|
||||
|
||||
#elif defined (__aarch64__)
|
||||
|
||||
struct limine_smp_info {
|
||||
uint32_t processor_id;
|
||||
uint32_t gic_iface_no;
|
||||
uint64_t mpidr;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
struct limine_smp_response {
|
||||
uint64_t revision;
|
||||
uint32_t flags;
|
||||
uint64_t bsp_mpidr;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct limine_smp_info **) cpus;
|
||||
};
|
||||
|
||||
#else
|
||||
#error Unknown architecture
|
||||
#endif
|
||||
|
||||
struct limine_smp_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_smp_response *) response;
|
||||
uint64_t flags;
|
||||
};
|
||||
|
||||
/* Memory map */
|
||||
|
||||
#define LIMINE_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
|
||||
|
||||
#define LIMINE_MEMMAP_USABLE 0
|
||||
#define LIMINE_MEMMAP_RESERVED 1
|
||||
#define LIMINE_MEMMAP_ACPI_RECLAIMABLE 2
|
||||
#define LIMINE_MEMMAP_ACPI_NVS 3
|
||||
#define LIMINE_MEMMAP_BAD_MEMORY 4
|
||||
#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE 5
|
||||
#define LIMINE_MEMMAP_KERNEL_AND_MODULES 6
|
||||
#define LIMINE_MEMMAP_FRAMEBUFFER 7
|
||||
|
||||
struct limine_memmap_entry {
|
||||
uint64_t base;
|
||||
uint64_t length;
|
||||
uint64_t type;
|
||||
};
|
||||
|
||||
struct limine_memmap_response {
|
||||
uint64_t revision;
|
||||
uint64_t entry_count;
|
||||
LIMINE_PTR(struct limine_memmap_entry **) entries;
|
||||
};
|
||||
|
||||
struct limine_memmap_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_memmap_response *) response;
|
||||
};
|
||||
|
||||
/* Entry point */
|
||||
|
||||
#define LIMINE_ENTRY_POINT_REQUEST { LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
|
||||
|
||||
typedef void (*limine_entry_point)(void);
|
||||
|
||||
struct limine_entry_point_response {
|
||||
uint64_t revision;
|
||||
};
|
||||
|
||||
struct limine_entry_point_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_entry_point_response *) response;
|
||||
LIMINE_PTR(limine_entry_point) entry;
|
||||
};
|
||||
|
||||
/* Kernel File */
|
||||
|
||||
#define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
|
||||
|
||||
struct limine_kernel_file_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_file *) kernel_file;
|
||||
};
|
||||
|
||||
struct limine_kernel_file_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_kernel_file_response *) response;
|
||||
};
|
||||
|
||||
/* Module */
|
||||
|
||||
#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
|
||||
|
||||
struct limine_module_response {
|
||||
uint64_t revision;
|
||||
uint64_t module_count;
|
||||
LIMINE_PTR(struct limine_file **) modules;
|
||||
};
|
||||
|
||||
struct limine_module_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_module_response *) response;
|
||||
};
|
||||
|
||||
/* RSDP */
|
||||
|
||||
#define LIMINE_RSDP_REQUEST { LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
|
||||
|
||||
struct limine_rsdp_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
};
|
||||
|
||||
struct limine_rsdp_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_rsdp_response *) response;
|
||||
};
|
||||
|
||||
/* SMBIOS */
|
||||
|
||||
#define LIMINE_SMBIOS_REQUEST { LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
|
||||
|
||||
struct limine_smbios_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) entry_32;
|
||||
LIMINE_PTR(void *) entry_64;
|
||||
};
|
||||
|
||||
struct limine_smbios_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_smbios_response *) response;
|
||||
};
|
||||
|
||||
/* EFI system table */
|
||||
|
||||
#define LIMINE_EFI_SYSTEM_TABLE_REQUEST { LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
|
||||
|
||||
struct limine_efi_system_table_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
};
|
||||
|
||||
struct limine_efi_system_table_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_efi_system_table_response *) response;
|
||||
};
|
||||
|
||||
/* Boot time */
|
||||
|
||||
#define LIMINE_BOOT_TIME_REQUEST { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
|
||||
|
||||
struct limine_boot_time_response {
|
||||
uint64_t revision;
|
||||
int64_t boot_time;
|
||||
};
|
||||
|
||||
struct limine_boot_time_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_boot_time_response *) response;
|
||||
};
|
||||
|
||||
/* Kernel address */
|
||||
|
||||
#define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
|
||||
|
||||
struct limine_kernel_address_response {
|
||||
uint64_t revision;
|
||||
uint64_t physical_base;
|
||||
uint64_t virtual_base;
|
||||
};
|
||||
|
||||
struct limine_kernel_address_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_kernel_address_response *) response;
|
||||
};
|
||||
|
||||
/* Device Tree Blob */
|
||||
|
||||
#define LIMINE_DTB_REQUEST { LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
|
||||
|
||||
struct limine_dtb_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) dtb_ptr;
|
||||
};
|
||||
|
||||
struct limine_dtb_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_dtb_response *) response;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue