Squash commits for public release

This commit is contained in:
2025-02-12 09:54:05 -05:00
commit 7118adc514
1108 changed files with 80873 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#ifndef _KERNEL_ALGO_BITMAP_H
#define _KERNEL_ALGO_BITMAP_H
#include <libkern/types.h>
struct bitmap {
uint8_t* data;
size_t len;
};
typedef struct bitmap bitmap_t;
bitmap_t bitmap_wrap(uint8_t* data, size_t len);
bitmap_t bitmap_allocate(size_t len);
int bitmap_find_space(bitmap_t bitmap, int req);
int bitmap_find_space_aligned(bitmap_t bitmap, int req, int alignment);
int bitmap_set(bitmap_t bitmap, int where);
int bitmap_unset(bitmap_t bitmap, int where);
int bitmap_set_range(bitmap_t bitmap, int start, int len);
int bitmap_unset_range(bitmap_t bitmap, int start, int len);
#endif //_KERNEL_ALGO_BITMAP_H

View File

@@ -0,0 +1,34 @@
#ifndef _KERNEL_ALGO_DYNAMIC_ARRAY_H
#define _KERNEL_ALGO_DYNAMIC_ARRAY_H
#include <libkern/types.h>
// TODO: Speed up bucket search using binary jumps.
struct dynamic_array_bucket {
void* data;
struct dynamic_array_bucket* next;
size_t capacity;
size_t size;
};
typedef struct dynamic_array_bucket dynamic_array_bucket_t;
struct dynamic_array {
dynamic_array_bucket_t* head;
dynamic_array_bucket_t* tail;
size_t size; /* number of elements in vector */
size_t element_size; /* size of elements in bytes */
};
typedef struct dynamic_array dynamic_array_t;
#define dynarr_init(type, v) dynarr_init_of_size_impl(v, sizeof(type), 8)
#define dynarr_init_of_size(type, v, cap) dynarr_init_of_size_impl(v, sizeof(type), cap)
int dynarr_init_of_size_impl(dynamic_array_t* v, size_t element_size, size_t capacity);
int dynarr_free(dynamic_array_t* v);
void* dynarr_get(dynamic_array_t* v, int index);
void* dynarr_push(dynamic_array_t* v, void* element);
int dynarr_pop(dynamic_array_t* v);
int dynarr_clear(dynamic_array_t* v);
#endif // _KERNEL_ALGO_DYNAMIC_ARRAY_H

View File

@@ -0,0 +1,11 @@
#ifndef _KERNEL_ALGO_HASH_H
#define _KERNEL_ALGO_HASH_H
#include <libkern/types.h>
#define hashint(hfunc, val) (hfunc((uint8_t*)&val, sizeof(val)))
uint32_t hash_crc32(uint8_t* data, size_t len);
uint32_t hashstr_crc32(char* data);
#endif // _KERNEL_ALGO_HASH_H

View File

@@ -0,0 +1,39 @@
#ifndef _KERNEL_ALGO_RINGBUFFER_H
#define _KERNEL_ALGO_RINGBUFFER_H
#include <libkern/libkern.h>
#include <libkern/lock.h>
#include <mem/kmemzone.h>
#define RINGBUFFER_STD_SIZE (16 * KB)
struct __ringbuffer {
kmemzone_t zone;
size_t start;
size_t end;
};
typedef struct __ringbuffer ringbuffer_t;
ringbuffer_t ringbuffer_create(size_t size);
static ALWAYS_INLINE ringbuffer_t ringbuffer_create_std() { return ringbuffer_create(RINGBUFFER_STD_SIZE); }
void ringbuffer_free(ringbuffer_t* rbuf);
ssize_t ringbuffer_space_to_read_from(ringbuffer_t* rbuf, size_t start);
ssize_t ringbuffer_space_to_read(ringbuffer_t* rbuf);
ssize_t ringbuffer_space_to_write(ringbuffer_t* rbuf);
size_t ringbuffer_read_from(ringbuffer_t* rbuf, size_t ustart, uint8_t __user* buf, size_t siz);
size_t ringbuffer_read_user_from(ringbuffer_t* rbuf, size_t ustart, uint8_t __user* buf, size_t siz);
size_t ringbuffer_read(ringbuffer_t* rbuf, uint8_t*, size_t);
size_t ringbuffer_read_user(ringbuffer_t* rbuf, uint8_t __user* buf, size_t siz);
size_t ringbuffer_write(ringbuffer_t* rbuf, const uint8_t*, size_t);
size_t ringbuffer_write_user(ringbuffer_t* rbuf, const uint8_t __user* buf, size_t siz);
size_t ringbuffer_write_ignore_bounds(ringbuffer_t* rbuf, const uint8_t* buf, size_t siz);
size_t ringbuffer_write_user_ignore_bounds(ringbuffer_t* rbuf, const uint8_t* __user buf, size_t siz);
size_t ringbuffer_read_one(ringbuffer_t* rbuf, uint8_t* data);
size_t ringbuffer_write_one(ringbuffer_t* rbuf, uint8_t data);
void ringbuffer_clear(ringbuffer_t* rbuf);
#endif //_KERNEL_ALGO_RINGBUFFER_H

View File

@@ -0,0 +1,131 @@
#ifndef _KERNEL_ALGO_SYNC_RINGBUFFER_H
#define _KERNEL_ALGO_SYNC_RINGBUFFER_H
#include <algo/ringbuffer.h>
#include <libkern/libkern.h>
#include <libkern/lock.h>
#include <mem/kmemzone.h>
struct __sync_ringbuffer {
ringbuffer_t ringbuffer;
spinlock_t lock;
};
typedef struct __sync_ringbuffer sync_ringbuffer_t;
static ALWAYS_INLINE sync_ringbuffer_t sync_ringbuffer_create(size_t size)
{
sync_ringbuffer_t res;
res.ringbuffer = ringbuffer_create(size);
spinlock_init(&res.lock);
return res;
}
#define sync_ringbuffer_create_std() sync_ringbuffer_create(RINGBUFFER_STD_SIZE)
static ALWAYS_INLINE void sync_ringbuffer_free(sync_ringbuffer_t* buf)
{
spinlock_acquire(&buf->lock);
ringbuffer_free(&buf->ringbuffer);
spinlock_release(&buf->lock);
}
static ALWAYS_INLINE ssize_t sync_ringbuffer_space_to_read(sync_ringbuffer_t* buf)
{
spinlock_acquire(&buf->lock);
ssize_t res = ringbuffer_space_to_read(&buf->ringbuffer);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE ssize_t sync_ringbuffer_space_to_read_from(sync_ringbuffer_t* buf, size_t start)
{
spinlock_acquire(&buf->lock);
ssize_t res = ringbuffer_space_to_read_from(&buf->ringbuffer, start);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE ssize_t sync_ringbuffer_space_to_write(sync_ringbuffer_t* buf)
{
spinlock_acquire(&buf->lock);
ssize_t res = ringbuffer_space_to_write(&buf->ringbuffer);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_read_from(sync_ringbuffer_t* buf, size_t start, uint8_t* holder, size_t siz)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_read_from(&buf->ringbuffer, start, holder, siz);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_read_user_from(sync_ringbuffer_t* buf, size_t start, uint8_t __user* holder, size_t siz)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_read_user_from(&buf->ringbuffer, start, holder, siz);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_read(sync_ringbuffer_t* buf, uint8_t* v, size_t a)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_read(&buf->ringbuffer, v, a);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_read_user(sync_ringbuffer_t* buf, uint8_t __user* v, size_t a)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_read_user(&buf->ringbuffer, v, a);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_write(sync_ringbuffer_t* buf, const uint8_t* v, size_t a)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_write(&buf->ringbuffer, v, a);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_write_user(sync_ringbuffer_t* buf, const uint8_t __user* v, size_t a)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_write_user(&buf->ringbuffer, v, a);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_write_ignore_bounds(sync_ringbuffer_t* buf, const uint8_t* holder, size_t siz)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_write_ignore_bounds(&buf->ringbuffer, holder, siz);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_write_user_ignore_bounds(sync_ringbuffer_t* buf, const uint8_t __user* holder, size_t siz)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_write_user_ignore_bounds(&buf->ringbuffer, holder, siz);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_read_one(sync_ringbuffer_t* buf, uint8_t* data)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_read_one(&buf->ringbuffer, data);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE size_t sync_ringbuffer_write_one(sync_ringbuffer_t* buf, uint8_t data)
{
spinlock_acquire(&buf->lock);
size_t res = ringbuffer_write_one(&buf->ringbuffer, data);
spinlock_release(&buf->lock);
return res;
}
static ALWAYS_INLINE void sync_ringbuffer_clear(sync_ringbuffer_t* buf)
{
spinlock_acquire(&buf->lock);
ringbuffer_clear(&buf->ringbuffer);
spinlock_release(&buf->lock);
}
#endif //_KERNEL_ALGO_SYNC_RINGBUFFER_H

View File

@@ -0,0 +1,68 @@
#ifndef _KERNEL_DRIVERS_BITS_DEVICE_H
#define _KERNEL_DRIVERS_BITS_DEVICE_H
#include <libkern/lock.h>
#include <libkern/types.h>
enum DEVICES_TYPE {
DEVICE_STORAGE = (1 << 0),
DEVICE_SOUND = (1 << 1),
DEVICE_INPUT_SYSTEMS = (1 << 2),
DEVICE_NETWORK = (1 << 3),
DEVICE_DISPLAY = (1 << 4),
DEVICE_BUS_CONTROLLER = (1 << 5),
DEVICE_BRIDGE = (1 << 6),
DEVICE_CHAR = (1 << 7),
DEVICE_RTC = (1 << 8),
DEVICE_UNKNOWN = (1 << 9),
};
enum DEVICE_DESC_TYPE {
DEVICE_DESC_PCI,
DEVICE_DESC_DEVTREE,
};
struct device_desc_pci {
uint8_t bus;
uint8_t device;
uint8_t function;
uint16_t vendor_id;
uint16_t device_id;
uint8_t class_id;
uint8_t subclass_id;
uint8_t interface_id;
uint8_t revision_id;
uint32_t interrupt;
uint32_t port_base;
};
typedef struct device_desc_pci device_desc_pci_t;
struct devtree_entry;
struct device_desc_devtree {
struct devtree_entry* entry;
};
typedef struct device_desc_devtree device_desc_devtree_t;
struct device_desc {
int type;
union {
device_desc_pci_t pci;
device_desc_devtree_t devtree;
};
uint32_t args[4];
};
typedef struct device_desc device_desc_t;
#define DRIVER_ID_EMPTY (0xff)
struct device {
int id;
int type;
bool is_virtual;
int driver_id;
spinlock_t lock;
device_desc_t device_desc;
};
typedef struct device device_t;
#endif // _KERNEL_DRIVERS_BITS_DEVICE_H

View File

@@ -0,0 +1,123 @@
#ifndef _KERNEL_DRIVERS_BITS_DRIVER_H
#define _KERNEL_DRIVERS_BITS_DRIVER_H
#include <libkern/types.h>
#define MAX_DRIVER_FUNCTION_COUNT 32
// Supported driver's types
enum DRIVERS_TYPE {
DRIVER_STORAGE_DEVICE = (1 << 0),
DRIVER_VIDEO_DEVICE = (1 << 1),
DRIVER_SOUND_DEVICE = (1 << 2),
DRIVER_INPUT_SYSTEMS_DEVICE = (1 << 3),
DRIVER_NETWORK_DEVICE = (1 << 4),
DRIVER_BUS_CONTROLLER = (1 << 5),
DRIVER_CHAR_DEVICE = (1 << 6),
DRIVER_VIRTUAL_FILE_SYSTEM = (1 << 7),
DRIVER_FILE_SYSTEM = (1 << 8),
DRIVER_TIMER = (1 << 9),
DRIVER_RTC = (1 << 10),
DRIVER_TIME_MANAGER = (1 << 11),
DRIVER_VIRTUAL = (1 << 12),
};
// Api function of DRIVER_STORAGE type
enum DRIVER_VIDEO_OPERTAION {
DRIVER_VIDEO_INIT = 0x1, // function called when a device is found
DRIVER_VIDEO_SET_RESOLUTION,
};
// Api function of DRIVER_STORAGE type
enum DRIVER_STORAGE_OPERTAION {
DRIVER_STORAGE_ADD_DEVICE = 0x1, // function called when a device is found
DRIVER_STORAGE_READ,
DRIVER_STORAGE_WRITE,
DRIVER_STORAGE_FLUSH,
DRIVER_STORAGE_CAPACITY,
};
// Api function of DRIVER_INPUT_SYSTEMS type
enum DRIVER_INPUT_SYSTEMS_OPERTAION {
DRIVER_INPUT_SYSTEMS_ADD_DEVICE = 0x1, // function called when a device is found
DRIVER_INPUT_SYSTEMS_GET_LAST_KEY,
DRIVER_INPUT_SYSTEMS_DISCARD_LAST_KEY
};
// Api function of DRIVER_CONTROLLER type
enum DRIVER_BUS_CONTROLLER_OPERTAION {
DRIVER_BUS_CONTROLLER_FIND_DEVICE = 0x1, // function called when a device is found
};
// Api function of DRIVER_VIRTUAL_FILE_SYSTEM type
enum DRIVER_VIRTUAL_FILE_SYSTEM_OPERTAION {
DRIVER_VIRTUAL_FILE_SYSTEM_ADD_DRIVER = 0x1,
DRIVER_VIRTUAL_FILE_SYSTEM_ADD_DEVICE,
DRIVER_VIRTUAL_FILE_SYSTEM_EJECT_DEVICE,
};
// Api function of DRIVER_FILE_SYSTEM type
enum DRIVER_FILE_SYSTEM_OPERTAION {
DRIVER_FILE_SYSTEM_RECOGNIZE = 0x1,
DRIVER_FILE_SYSTEM_PREPARE_FS,
DRIVER_FILE_SYSTEM_EJECT_DEVICE,
DRIVER_FILE_SYSTEM_OPEN,
DRIVER_FILE_SYSTEM_CAN_READ,
DRIVER_FILE_SYSTEM_CAN_WRITE,
DRIVER_FILE_SYSTEM_READ,
DRIVER_FILE_SYSTEM_WRITE,
DRIVER_FILE_SYSTEM_TRUNCATE,
DRIVER_FILE_SYSTEM_MKDIR,
DRIVER_FILE_SYSTEM_RMDIR,
DRIVER_FILE_SYSTEM_READ_INODE,
DRIVER_FILE_SYSTEM_WRITE_INODE,
DRIVER_FILE_SYSTEM_FREE_INODE,
DRIVER_FILE_SYSTEM_LOOKUP,
DRIVER_FILE_SYSTEM_GETDENTS,
DRIVER_FILE_SYSTEM_CREATE,
DRIVER_FILE_SYSTEM_UNLINK,
DRIVER_FILE_SYSTEM_FSTAT,
DRIVER_FILE_SYSTEM_FCHMOD,
DRIVER_FILE_SYSTEM_IOCTL,
DRIVER_FILE_SYSTEM_MMAP,
};
enum DRIVER_RTC_OPERTAION {
DRIVER_RTC_GET_TIME,
};
struct driver;
struct device;
typedef struct {
void (*recieve_notification)(uintptr_t key, uintptr_t val);
int (*on_start)();
int (*on_stop)();
int (*init_with_dev)(struct device* device);
} driver_system_funcs_t;
enum DRIVER_DESC_FLAGS {
DRIVER_DESC_FLAG_START = (1 << 0),
};
struct driver_desc {
int type;
uint32_t flags;
uint32_t listened_device_mask;
uint32_t listened_driver_mask;
void* functions[MAX_DRIVER_FUNCTION_COUNT];
driver_system_funcs_t system_funcs;
};
typedef struct driver_desc driver_desc_t;
struct driver {
int id;
int status;
driver_desc_t desc;
const char* name;
};
typedef struct driver driver_t;
#endif // _KERNEL_DRIVERS_BITS_DRIVER_H

View File

@@ -0,0 +1,10 @@
#ifndef _KERNEL_DRIVERS_BUS_X86_IDE_H
#define _KERNEL_DRIVERS_BUS_X86_IDE_H
#include <drivers/driver_manager.h>
#include <libkern/types.h>
void ide_install();
int ide_init_with_dev(device_t* dev);
#endif // _KERNEL_DRIVERS_BUS_X86_IDE_H

View File

@@ -0,0 +1,46 @@
#ifndef _KERNEL_DRIVERS_BUS_X86_PCI_H
#define _KERNEL_DRIVERS_BUS_X86_PCI_H
#include <drivers/driver_manager.h>
#include <libkern/c_attrs.h>
#include <libkern/types.h>
#include <platform/x86/port.h>
struct PACKED pcidd {
uint8_t bus;
uint8_t device;
uint8_t function;
uint16_t vendor_id;
uint16_t device_id;
uint8_t class_id;
uint8_t subclass_id;
uint8_t interface_id;
uint8_t revision_id;
uint32_t interrupt;
uint32_t port_base;
};
typedef struct pcidd pcidd_t;
enum bar_type {
MEMORY_MAPPED = 0,
INPUT_OUTPUT = 1
};
typedef struct {
char prefetchable;
uint32_t address;
uint8_t type;
} bar_t;
void pci_install();
uint32_t pci_read(uint16_t bus, uint16_t device, uint16_t function, uint32_t offset);
void pci_write(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t data);
char pci_has_device_functions(uint8_t bus, uint8_t device);
int pci_find_devices();
device_desc_t pci_get_device_desriptor(uint8_t bus, uint8_t device, uint8_t function);
uint32_t pci_read_bar(device_t* dev, int bar_id);
#endif /* _KERNEL_DRIVERS_BUS_X86_PCI_H */

View File

@@ -0,0 +1,21 @@
#ifndef _KERNEL_DRIVERS_CLOCK_ARM_PL031_H
#define _KERNEL_DRIVERS_CLOCK_ARM_PL031_H
#include <drivers/driver_manager.h>
#include <libkern/mask.h>
#include <libkern/types.h>
#include <platform/arm32/interrupts.h>
#include <platform/arm32/target/cortex-a15/device_settings.h>
struct pl031_registers {
uint32_t data;
uint32_t match;
uint32_t load;
uint32_t control;
// TO BE CONTINUED
};
typedef struct pl031_registers pl031_registers_t;
uint32_t pl031_read_rtc();
#endif // _KERNEL_DRIVERS_CLOCK_ARM_PL031_H

View File

@@ -0,0 +1,8 @@
#ifndef _KERNEL_DRIVERS_CLOCK_X86_RTC_H
#define _KERNEL_DRIVERS_CLOCK_X86_RTC_H
#include <libkern/types.h>
uint32_t rtc_load_time();
#endif /* _KERNEL_DRIVERS_CLOCK_X86_RTC_H */

View File

@@ -0,0 +1,10 @@
#ifndef _KERNEL_DRIVERS_DEBUG_SCREEN_H
#define _KERNEL_DRIVERS_DEBUG_SCREEN_H
#include <libkern/types.h>
struct boot_args;
int screen_setup(struct boot_args* boot_args);
int screen_put_char(char c);
#endif //_KERNEL_DRIVERS_DEBUG_SCREEN_H

View File

@@ -0,0 +1,51 @@
#ifndef _KERNEL_DRIVERS_DEVTREE_H
#define _KERNEL_DRIVERS_DEVTREE_H
#include <libkern/c_attrs.h>
#include <libkern/types.h>
#include <mem/boot.h>
#define DEVTREE_HEADER_SIGNATURE ("odtr3")
#define DEVTREE_HEADER_SIGNATURE_LEN (sizeof(DEVTREE_HEADER_SIGNATURE) - 1)
struct PACKED devtree_header {
char signature[8];
uint32_t revision;
uint32_t flags;
uint32_t entries_count;
uint32_t name_list_offset;
};
typedef struct devtree_header devtree_header_t;
#define DEVTREE_ENTRY_FLAGS_MMIO = (1 << 0)
#define DEVTREE_ENTRY_TYPE_IO (0)
#define DEVTREE_ENTRY_TYPE_FB (1)
#define DEVTREE_ENTRY_TYPE_UART (2)
#define DEVTREE_ENTRY_TYPE_RAM (3)
#define DEVTREE_ENTRY_TYPE_STORAGE (4)
#define DEVTREE_ENTRY_TYPE_BUS_CONTROLLER (5)
#define DEVTREE_ENTRY_TYPE_RTC (6)
struct PACKED devtree_entry {
uint32_t type;
uint32_t flags;
uint64_t region_base;
uint64_t region_size;
uint32_t irq_lane;
uint32_t irq_flags;
uint32_t irq_priority;
uint32_t rel_name_offset;
uint64_t aux1;
uint64_t aux2;
uint64_t aux3;
uint64_t aux4;
};
typedef struct devtree_entry devtree_entry_t;
int devtree_init(boot_args_t* boot_args);
devtree_entry_t* devtree_find_device(const char* name);
const char* devtree_name_of_entry(devtree_entry_t* en);
devtree_entry_t* devtree_new_entry(const devtree_entry_t* from);
uint32_t devtree_new_entry_name(const char* ptr);
#endif // _KERNEL_DRIVERS_DEVTREE_H

View File

@@ -0,0 +1,57 @@
#ifndef _KERNEL_DRIVERS_DRIVER_MANAGER_H
#define _KERNEL_DRIVERS_DRIVER_MANAGER_H
#include <drivers/bits/device.h>
#include <drivers/bits/driver.h>
#include <drivers/devtree.h>
#include <libkern/types.h>
#define MAX_DRIVERS_COUNT 256
#define MAX_DEVICES_COUNT 64
#define DEVMAN_FUNC_NOTIFY 0x0
#define DEVMAN_FUNC_DEVICE_START 0x1
#define DEVMAN_FUNC_DRIVER_START 0x1
#define DEVMAN_FUNC_DRIVER_EMIT_DRIVER 0x1
#define DEVMAN_FUNC_DRIVER_EMIT_DEVICE 0x2
#define DEFAULT_DRIVER_PRIV (100)
typedef void (*driver_installation_func_t)();
#define devman_register_driver_installation_order(func, N) \
static driver_installation_func_t registered_driver_##func \
__attribute__((used)) __attribute__((section(".driver_init_sections." #N))) \
= func
#define devman_register_driver_installation(func) devman_register_driver_installation_order(func, DEFAULT_DRIVER_PRIV)
enum DEVMAN_NOTIFICATIONS {
DEVMAN_NOTIFICATION_DEVFS_READY = 0,
DEVMAN_NOTIFICATION_NEW_DRIVER = 1,
DEVMAN_NOTIFICATION_NEW_DEVICE = 2,
DEVMAN_NOTIFICATION_STOP,
};
extern driver_t drivers[MAX_DRIVERS_COUNT];
extern device_t devices[MAX_DEVICES_COUNT];
int devman_init();
int devman_install_drivers();
void devman_run();
int devman_register_driver(driver_desc_t driver_info, const char* name);
int devman_register_device(device_desc_t device_info, int type);
device_t* new_virtual_device(int type);
int devman_get_driver_id_by_name(const char* name);
void devman_send_notification(uintptr_t msg, uintptr_t param);
static inline void* devman_driver_function(int driver_id, int function_id)
{
return drivers[driver_id].desc.functions[function_id];
}
static inline void* devman_function_handler(device_t* dev, int function_id)
{
return devman_driver_function(dev->driver_id, function_id);
}
#endif // _KERNEL_DRIVERS_DRIVER_MANAGER_H

View File

@@ -0,0 +1,49 @@
#ifndef _KERNEL_DRIVERS_GRAPHICS_ARM_PL111_H
#define _KERNEL_DRIVERS_GRAPHICS_ARM_PL111_H
#include <drivers/driver_manager.h>
#include <libkern/mask.h>
#include <libkern/types.h>
enum PL111RegisterMasks {
MASKDEFINE(PIXELS_PER_LINE, 2, 6),
MASKDEFINE(LINES_PER_PANEL, 0, 10),
MASKDEFINE(LCD_POWER, 11, 1),
MASKDEFINE(LCD_ENDIAN, 9, 2),
MASKDEFINE(LCD_BGR, 8, 1),
MASKDEFINE(LCD_DUAL, 7, 1),
MASKDEFINE(LCD_TFT, 5, 1),
MASKDEFINE(LCD_BW, 4, 1),
MASKDEFINE(LCD_BPP, 1, 3),
MASKDEFINE(LCD_EN, 0, 1),
};
enum PL111Consts {
NUM_TIMINGS = 4,
NUM_PALETTE_WORDS = 0x378,
LCD_16_BPP = 4, // Register constant for 16 bits per pixel
LCD_24_BPP = 5, // Register constant for 24 bits per pixel
};
struct pl111_registers {
uint32_t lcd_timing_0;
uint32_t lcd_timing_1;
uint32_t lcd_timing_2;
uint32_t lcd_timing_3;
uint32_t lcd_upbase;
uint32_t lcd_lpbase;
uint32_t lcd_control;
uint32_t lcd_imsc;
uint32_t lcd_ris;
uint32_t lcd_mis;
uint32_t lcd_icr;
uint32_t lcd_upcurr;
uint32_t lcd_lpcurr;
// TO BE CONTINUED
};
typedef struct pl111_registers pl111_registers_t;
void pl111_install();
#endif //_KERNEL_DRIVERS_GRAPHICS_ARM_PL111_H

View File

@@ -0,0 +1,182 @@
#ifndef _KERNEL_DRIVERS_GRAPHICS_VIRTIO_GPU_H
#define _KERNEL_DRIVERS_GRAPHICS_VIRTIO_GPU_H
#include <drivers/driver_manager.h>
#include <drivers/virtio/virtio.h>
#include <libkern/types.h>
#include <mem/kmalloc.h>
enum CtrlType {
// 2d commands
CmdGetDisplayInfo = 0x0100,
CmdResourceCreate2d,
CmdResourceUref,
CmdSetScanout,
CmdResourceFlush,
CmdTransferToHost2d,
CmdResourceAttachBacking,
CmdResourceDetachBacking,
CmdGetCapsetInfo,
CmdGetCapset,
CmdGetEdid,
// cursor commands
CmdUpdateCursor = 0x0300,
CmdMoveCursor,
// success responses
RespOkNoData = 0x1100,
RespOkDisplayInfo,
RespOkCapsetInfo,
RespOkCapset,
RespOkEdid,
// error responses
RespErrUnspec = 0x1200,
RespErrOutOfMemory,
RespErrInvalidScanoutId,
RespErrInvalidResourceId,
RespErrInvalidContextId,
RespErrInvalidParameter,
};
struct gpu_dev {
virtio_queue_desc_t queue_desc;
volatile virtio_mmio_registers_t* registers;
uint32_t idx;
uint32_t ack_used_idx;
virtio_buffer_desc_t fb_desc;
size_t width;
size_t height;
int current_fb;
};
typedef struct gpu_dev gpu_dev_t;
struct gpu_ctrl_header {
uint32_t ctrl_type;
uint32_t flags;
uint64_t fence_id;
uint32_t ctx_id;
uint32_t padding;
};
typedef struct gpu_ctrl_header gpu_ctrl_header_t;
struct gpu_rect {
uint32_t x;
uint32_t y;
uint32_t width;
uint32_t height;
};
typedef struct gpu_rect gpu_rect_t;
struct gpu_display_one {
gpu_rect_t r;
uint32_t enabled;
uint32_t flags;
};
typedef struct gpu_display_one gpu_display_one_t;
#define MAX_SCANOUTS (16)
typedef struct gpu_resp_display_info {
gpu_ctrl_header_t hdr;
gpu_display_one_t pmodes[MAX_SCANOUTS];
} gpu_resp_display_info_t;
typedef struct gpu_get_edid {
gpu_ctrl_header_t hdr;
uint32_t scanout;
uint32_t padding;
} gpu_get_edid_t;
typedef struct gpu_resp_edid {
gpu_ctrl_header_t hdr;
uint32_t size;
uint32_t padding;
uint8_t edid[1024];
} gpu_resp_edid_t;
typedef enum gpu_formats {
GPU_FORMAT_B8G8R8A8Unorm = 1,
GPU_FORMAT_B8G8R8X8Unorm = 2,
GPU_FORMAT_A8R8G8B8Unorm = 3,
GPU_FORMAT_X8R8G8B8Unorm = 4,
GPU_FORMAT_R8G8B8A8Unorm = 67,
GPU_FORMAT_X8B8G8R8Unorm = 68,
GPU_FORMAT_A8B8G8R8Unorm = 121,
GPU_FORMAT_R8G8B8X8Unorm = 134,
} gpu_formats_t;
typedef struct gpu_resource_create_2d {
gpu_ctrl_header_t hdr;
uint32_t resource_id;
gpu_formats_t format;
uint32_t width;
uint32_t height;
} gpu_resource_create_2d_t;
typedef struct gpu_resource_unref {
gpu_ctrl_header_t hdr;
uint32_t resource_id;
uint32_t padding;
} gpu_resource_unref_t;
typedef struct gpu_set_scanout {
gpu_ctrl_header_t hdr;
gpu_rect_t r;
uint32_t scanout_id;
uint32_t resource_id;
} gpu_set_scanout_t;
typedef struct gpu_resource_flush {
gpu_ctrl_header_t hdr;
gpu_rect_t r;
uint32_t resource_id;
uint32_t padding;
} gpu_resource_flush_t;
typedef struct gpu_transfer_to_host_2d {
gpu_ctrl_header_t hdr;
gpu_rect_t r;
uint64_t offset;
uint32_t resource_id;
uint32_t padding;
} gpu_transfer_to_host_2d_t;
typedef struct gpu_attach_backing {
gpu_ctrl_header_t hdr;
uint32_t resource_id;
uint32_t nr_entries;
} gpu_attach_backing_t;
typedef struct gpu_mem_entry {
uint64_t addr;
uint32_t length;
uint32_t padding;
} gpu_mem_entry_t;
typedef struct gpu_detach_backing {
gpu_ctrl_header_t hdr;
uint32_t resource_id;
uint32_t padding;
} gpu_detach_backing_t;
typedef struct gpu_cursor_pos {
uint32_t scanout_id;
uint32_t x;
uint32_t y;
uint32_t padding;
} gpu_cursor_pos_t;
typedef struct gpu_update_cursor {
gpu_ctrl_header_t hdr;
gpu_cursor_pos_t pos;
uint32_t resource_id;
uint32_t hot_x;
uint32_t hot_y;
uint32_t padding;
} gpu_update_cursor_t;
typedef struct gpu_request {
void* request;
void* response;
void* alloc_start;
} gpu_request_t;
#endif //_KERNEL_DRIVERS_GRAPHICS_VIRTIO_GPU_H

View File

@@ -0,0 +1,12 @@
#ifndef _KERNEL_DRIVERS_GRAPHICS_X86_BGA_H
#define _KERNEL_DRIVERS_GRAPHICS_X86_BGA_H
#include <drivers/driver_manager.h>
#include <libkern/types.h>
#include <mem/kmalloc.h>
#include <platform/x86/port.h>
void bga_install();
int bga_init_with_dev(device_t* dev);
#endif //_KERNEL_DRIVERS_GRAPHICS_X86_BGA_H

View File

@@ -0,0 +1,20 @@
#ifndef _KERNEL_DRIVERS_IO_ARM_PL050_H
#define _KERNEL_DRIVERS_IO_ARM_PL050_H
#include <drivers/driver_manager.h>
#include <libkern/mask.h>
#include <libkern/types.h>
struct pl050_registers {
uint32_t cr; // control register (rw)
uint32_t stat; // status register (r)
uint32_t data; // data register (rw)
uint32_t clk; // clock divisor register (rw)
uint32_t ir;
};
typedef struct pl050_registers pl050_registers_t;
void pl050_keyboard_install();
void pl050_mouse_install();
#endif //_KERNEL_DRIVERS_IO_ARM_PL050_H

View File

@@ -0,0 +1,186 @@
#ifndef _KERNEL_DRIVERS_IO_KEYBOARD_H
#define _KERNEL_DRIVERS_IO_KEYBOARD_H
#include <libkern/types.h>
enum KEYCODE {
// Alphanumeric keys ////////////////
KEY_CTRLC = '\003',
KEY_SPACE = ' ',
KEY_0 = '0',
KEY_1 = '1',
KEY_2 = '2',
KEY_3 = '3',
KEY_4 = '4',
KEY_5 = '5',
KEY_6 = '6',
KEY_7 = '7',
KEY_8 = '8',
KEY_9 = '9',
KEY_A = 'a',
KEY_B = 'b',
KEY_C = 'c',
KEY_D = 'd',
KEY_E = 'e',
KEY_F = 'f',
KEY_G = 'g',
KEY_H = 'h',
KEY_I = 'i',
KEY_J = 'j',
KEY_K = 'k',
KEY_L = 'l',
KEY_M = 'm',
KEY_N = 'n',
KEY_O = 'o',
KEY_P = 'p',
KEY_Q = 'q',
KEY_R = 'r',
KEY_S = 's',
KEY_T = 't',
KEY_U = 'u',
KEY_V = 'v',
KEY_W = 'w',
KEY_X = 'x',
KEY_Y = 'y',
KEY_Z = 'z',
KEY_RETURN = '\r',
KEY_ESCAPE = 0x1001,
KEY_BACKSPACE = '\b',
// Arrow keys ////////////////////////
KEY_UP = 0x1100,
KEY_DOWN = 0x1101,
KEY_LEFT = 0x1102,
KEY_RIGHT = 0x1103,
// Function keys /////////////////////
KEY_F1 = 0x1201,
KEY_F2 = 0x1202,
KEY_F3 = 0x1203,
KEY_F4 = 0x1204,
KEY_F5 = 0x1205,
KEY_F6 = 0x1206,
KEY_F7 = 0x1207,
KEY_F8 = 0x1208,
KEY_F9 = 0x1209,
KEY_F10 = 0x120a,
KEY_F11 = 0x120b,
KEY_F12 = 0x120b,
KEY_F13 = 0x120c,
KEY_F14 = 0x120d,
KEY_F15 = 0x120e,
KEY_DOT = '.',
KEY_COMMA = ',',
KEY_COLON = ':',
KEY_SEMICOLON = ';',
KEY_SLASH = '/',
KEY_BACKSLASH = '\\',
KEY_PLUS = '+',
KEY_MINUS = '-',
KEY_ASTERISK = '*',
KEY_EXCLAMATION = '!',
KEY_QUESTION = '?',
KEY_QUOTEDOUBLE = '\"',
KEY_QUOTE = '\'',
KEY_EQUAL = '=',
KEY_HASH = '#',
KEY_PERCENT = '%',
KEY_AMPERSAND = '&',
KEY_UNDERSCORE = '_',
KEY_LEFTPARENTHESIS = '(',
KEY_RIGHTPARENTHESIS = ')',
KEY_LEFTBRACKET = '[',
KEY_RIGHTBRACKET = ']',
KEY_LEFTCURL = '{',
KEY_RIGHTCURL = '}',
KEY_DOLLAR = '$',
KEY_POUND = 0,
KEY_EURO = '$',
KEY_LESS = '<',
KEY_GREATER = '>',
KEY_BAR = '|',
KEY_GRAVE = '`',
KEY_TILDE = '~',
KEY_AT = '@',
KEY_CARRET = '^',
// Numeric keypad //////////////////////
KEY_KP_0 = '0',
KEY_KP_1 = '1',
KEY_KP_2 = '2',
KEY_KP_3 = '3',
KEY_KP_4 = '4',
KEY_KP_5 = '5',
KEY_KP_6 = '6',
KEY_KP_7 = '7',
KEY_KP_8 = '8',
KEY_KP_9 = '9',
KEY_KP_PLUS = '+',
KEY_KP_MINUS = '-',
KEY_KP_DECIMAL = '.',
KEY_KP_DIVIDE = '/',
KEY_KP_ASTERISK = '*',
KEY_KP_NUMLOCK = 0x300f,
KEY_KP_ENTER = 0x3010,
KEY_TAB = 0x4000,
KEY_CAPSLOCK = 0x4001,
// Modify keys ////////////////////////////
KEY_LSHIFT = 0x4002,
KEY_LCTRL = 0x4003,
KEY_LALT = 0x4004,
KEY_LWIN = 0x4005,
KEY_RSHIFT = 0x4006,
KEY_RCTRL = 0x4007,
KEY_RALT = 0x4008,
KEY_RWIN = 0x4009,
KEY_INSERT = 0x400a,
KEY_DELETE = 0x400b,
KEY_HOME = 0x400c,
KEY_END = 0x400d,
KEY_PAGEUP = 0x400e,
KEY_PAGEDOWN = 0x400f,
KEY_SCROLLLOCK = 0x4010,
KEY_PAUSE = 0x4011,
// Multimedia keys ////////////////////////
KEY_PREV_TRACK = 0x5001,
KEY_NEXT_TRACK = 0x5002,
KEY_MUTE = 0x5003,
KEY_CALC = 0x5004,
KEY_PLAY = 0x5005,
KEY_STOP = 0x5006,
KEY_VOL_DOWN = 0x5007,
KEY_VOL_UP = 0x5008,
KEY_WWW_HOME = 0x500a,
KEY_UNKNOWN,
KEY_NUMKEYCODES
};
typedef uint32_t key_t;
/* The keyboard packet should be aligned to 4 bytes */
struct kbd_packet {
key_t key;
};
typedef struct kbd_packet kbd_packet_t;
int generic_keyboard_create_devfs();
void generic_keyboard_init();
void generic_emit_key_set1(uint32_t scancode);
#endif //_KERNEL_DRIVERS_IO_KEYBOARD_H

View File

@@ -0,0 +1,180 @@
#include <drivers/io/keyboard.h>
static key_t _scancode_set1[] = {
KEY_UNKNOWN, // 0
KEY_ESCAPE, // 1
KEY_1, // 2
KEY_2, // 3
KEY_3, // 4
KEY_4, // 5
KEY_5, // 6
KEY_6, // 7
KEY_7, // 8
KEY_8, // 9
KEY_9, // 0xa
KEY_0, // 0xb
KEY_MINUS, // 0xc
KEY_EQUAL, // 0xd
KEY_BACKSPACE, // 0xe
KEY_TAB, // 0xf
KEY_Q, // 0x10
KEY_W, // 0x11
KEY_E, // 0x12
KEY_R, // 0x13
KEY_T, // 0x14
KEY_Y, // 0x15
KEY_U, // 0x16
KEY_I, // 0x17
KEY_O, // 0x18
KEY_P, // 0x19
KEY_LEFTBRACKET, // 0x1a
KEY_RIGHTBRACKET, // 0x1b
KEY_RETURN, // 0x1c
KEY_LCTRL, // 0x1d
KEY_A, // 0x1e
KEY_S, // 0x1f
KEY_D, // 0x20
KEY_F, // 0x21
KEY_G, // 0x22
KEY_H, // 0x23
KEY_J, // 0x24
KEY_K, // 0x25
KEY_L, // 0x26
KEY_SEMICOLON, // 0x27
KEY_QUOTE, // 0x28
KEY_GRAVE, // 0x29
KEY_LSHIFT, // 0x2a
KEY_BACKSLASH, // 0x2b
KEY_Z, // 0x2c
KEY_X, // 0x2d
KEY_C, // 0x2e
KEY_V, // 0x2f
KEY_B, // 0x30
KEY_N, // 0x31
KEY_M, // 0x32
KEY_COMMA, // 0x33
KEY_DOT, // 0x34
KEY_SLASH, // 0x35
KEY_RSHIFT, // 0x36
KEY_KP_ASTERISK, // 0x37
KEY_RALT, // 0x38
KEY_SPACE, // 0x39
KEY_CAPSLOCK, // 0x3a
KEY_F1, // 0x3b
KEY_F2, // 0x3c
KEY_F3, // 0x3d
KEY_F4, // 0x3e
KEY_F5, // 0x3f
KEY_F6, // 0x40
KEY_F7, // 0x41
KEY_F8, // 0x42
KEY_F9, // 0x43
KEY_F10, // 0x44
KEY_KP_NUMLOCK, // 0x45
KEY_SCROLLLOCK, // 0x46
KEY_HOME, // 0x47
KEY_KP_8, // 0x48 //keypad up arrow
KEY_PAGEUP, // 0x49
KEY_KP_2, // 0x50 //keypad down arrow
KEY_KP_3, // 0x51 //keypad page down
KEY_KP_0, // 0x52 //keypad insert key
KEY_KP_DECIMAL, // 0x53 //keypad delete key
KEY_UNKNOWN, // 0x54
KEY_UNKNOWN, // 0x55
KEY_UNKNOWN, // 0x56
KEY_F11, // 0x57
KEY_F12 // 0x58
};
static key_t _scancode_set1_upper[] = {
KEY_UNKNOWN, // 0
KEY_UNKNOWN, // 1
KEY_UNKNOWN, // 2
KEY_UNKNOWN, // 3
KEY_UNKNOWN, // 4
KEY_UNKNOWN, // 5
KEY_UNKNOWN, // 6
KEY_UNKNOWN, // 7
KEY_UNKNOWN, // 8
KEY_UNKNOWN, // 9
KEY_UNKNOWN, // 0xa
KEY_UNKNOWN, // 0xb
KEY_UNKNOWN, // 0xc
KEY_UNKNOWN, // 0xd
KEY_UNKNOWN, // 0xe
KEY_UNKNOWN, // 0xf
KEY_PREV_TRACK, // 0x10
KEY_UNKNOWN, // 0x11
KEY_UNKNOWN, // 0x12
KEY_UNKNOWN, // 0x13
KEY_UNKNOWN, // 0x14
KEY_UNKNOWN, // 0x15
KEY_UNKNOWN, // 0x16
KEY_UNKNOWN, // 0x17
KEY_UNKNOWN, // 0x18
KEY_NEXT_TRACK, // 0x19
KEY_UNKNOWN, // 0x1a
KEY_UNKNOWN, // 0x1b
KEY_KP_ENTER, // 0x1c
KEY_RCTRL, // 0x1d
KEY_UNKNOWN, // 0x1e
KEY_UNKNOWN, // 0x1f
KEY_MUTE, // 0x20
KEY_CALC, // 0x21
KEY_PLAY, // 0x22
KEY_UNKNOWN, // 0x23
KEY_STOP, // 0x24
KEY_UNKNOWN, // 0x25
KEY_UNKNOWN, // 0x26
KEY_UNKNOWN, // 0x27
KEY_UNKNOWN, // 0x28
KEY_UNKNOWN, // 0x29
KEY_UNKNOWN, // 0x2a
KEY_UNKNOWN, // 0x2b
KEY_UNKNOWN, // 0x2c
KEY_UNKNOWN, // 0x2d
KEY_VOL_DOWN, // 0x2e
KEY_UNKNOWN, // 0x2f
KEY_VOL_UP, // 0x30
KEY_UNKNOWN, // 0x31
KEY_WWW_HOME, // 0x32
KEY_UNKNOWN, // 0x33
KEY_UNKNOWN, // 0x34
KEY_NUMKEYCODES, // 0x35
KEY_UNKNOWN, // 0x36
KEY_UNKNOWN, // 0x37
KEY_RALT, // 0x38
KEY_UNKNOWN, // 0x39
KEY_UNKNOWN, // 0x3a
KEY_UNKNOWN, // 0x3b
KEY_UNKNOWN, // 0x3c
KEY_UNKNOWN, // 0x3d
KEY_UNKNOWN, // 0x3e
KEY_UNKNOWN, // 0x3f
KEY_UNKNOWN, // 0x40
KEY_UNKNOWN, // 0x41
KEY_UNKNOWN, // 0x42
KEY_UNKNOWN, // 0x43
KEY_UNKNOWN, // 0x44
KEY_UNKNOWN, // 0x45
KEY_UNKNOWN, // 0x46
KEY_HOME, // 0x47
KEY_UP, // 0x48
KEY_PAGEUP, // 0x49
KEY_UNKNOWN, // 0x4a
KEY_LEFT, // 0x4b
KEY_UNKNOWN, // 0x4c
KEY_RIGHT, // 0x4d
KEY_UNKNOWN, // 0x4e
KEY_END, // 0x4f
KEY_DOWN, // 0x50
KEY_PAGEDOWN, // 0x51
KEY_INSERT, // 0x52
KEY_DELETE // 0x53
};
static inline key_t generic_keyboard_get_keycode_set1(uint32_t scancode)
{
key_t* lookup_table[] = { _scancode_set1, _scancode_set1_upper };
return lookup_table[(scancode >> 8) & 1][scancode & ~((uint32_t)0x100)];
}

View File

@@ -0,0 +1,19 @@
#ifndef _KERNEL_DRIVERS_IO_MOUSE_H
#define _KERNEL_DRIVERS_IO_MOUSE_H
#include <libkern/types.h>
/* The mouse packet should be aligned to 4 bytes */
struct mouse_packet {
int16_t x_offset;
int16_t y_offset;
uint16_t button_states;
int16_t wheel_data;
};
typedef struct mouse_packet mouse_packet_t;
int generic_mouse_create_devfs();
void generic_mouse_init();
void generic_mouse_send_packet(mouse_packet_t* packet);
#endif //_KERNEL_DRIVERS_IO_MOUSE_H

View File

@@ -0,0 +1,28 @@
#ifndef _KERNEL_DRIVERS_STORAGE_VIRTIO_INPUT_H
#define _KERNEL_DRIVERS_STORAGE_VIRTIO_INPUT_H
#include <drivers/driver_manager.h>
#include <drivers/irq/irq_api.h>
#include <drivers/virtio/virtio.h>
#include <libkern/types.h>
#include <mem/kmalloc.h>
struct virtio_input_event {
int16_t event_type;
int16_t code;
int32_t value;
};
typedef struct virtio_input_event virtio_input_event_t;
struct virtio_input_dev {
virtio_queue_desc_t event_queue_desc;
virtio_queue_desc_t status_queue_desc;
uint32_t status_ack_used_idx;
uint32_t event_idx;
uint32_t event_ack_used_idx;
virtio_buffer_desc_t event_buffer_desc;
irq_line_t irq_line;
};
typedef struct virtio_input_dev virtio_input_dev_t;
#endif //_KERNEL_DRIVERS_STORAGE_VIRTIO_INPUT_H

View File

@@ -0,0 +1,13 @@
#ifndef _KERNEL_DRIVERS_IO_X86_KEYBOARD_H
#define _KERNEL_DRIVERS_IO_X86_KEYBOARD_H
#include <drivers/io/keyboard.h>
#include <libkern/types.h>
void kbdriver_install();
int kbdriver_run();
uint32_t kbdriver_get_last_key();
void kbdriver_discard_last_key();
#endif

View File

@@ -0,0 +1,9 @@
#ifndef _KERNEL_DRIVERS_IO_X86_MOUSE_H
#define _KERNEL_DRIVERS_IO_X86_MOUSE_H
#include <drivers/io/mouse.h>
#include <libkern/types.h>
void mouse_install();
#endif // _KERNEL_DRIVERS_IO_X86_MOUSE_H

View File

@@ -0,0 +1,69 @@
#ifndef _KERNEL_DRIVERS_IRQ_ARM_GICV2_H
#define _KERNEL_DRIVERS_IRQ_ARM_GICV2_H
#include <drivers/driver_manager.h>
#include <drivers/irq/irq_api.h>
#include <libkern/mask.h>
#include <libkern/types.h>
enum GICDControlMasks {
MASKDEFINE(GICD_ENABLE, 0, 1),
};
enum GICCControlMasks {
MASKDEFINE(GICC_ENABLE_GR1, 0, 1),
MASKDEFINE(GICC_FIQ_BYP_DIS_GR1, 5, 1),
MASKDEFINE(GICC_IRQ_BYP_DIS_GR1, 6, 1),
MASKDEFINE(GICC_EO_IMODE_NS, 9, 1),
};
struct gicv2_distributor_registers {
uint32_t control;
uint32_t typer;
uint32_t iidr;
SKIP(0x008 + 0x4, 0x080);
uint32_t igroup[8];
SKIP(0x09C + 0x4, 0x100);
uint32_t isenabler[8];
SKIP(0x11C + 0x4, 0x180);
uint32_t icenabler[8];
SKIP(0x19C + 0x4, 0x200);
uint32_t ispendr[8];
SKIP(0x21C + 0x4, 0x280);
uint32_t icpendr[8];
SKIP(0x29C + 0x4, 0x300);
uint32_t isactiver[8];
SKIP(0x31C + 0x4, 0x380);
uint32_t icactiver[8];
SKIP(0x39C + 0x4, 0x400);
uint32_t ipriorityr[64];
SKIP(0x4FC + 0x4, 0x800);
uint32_t itargetsr[64];
SKIP(0x8FC + 0x4, 0xC00);
uint32_t icfgr[16];
// TO BE CONTINUED
};
typedef struct gicv2_distributor_registers gicv2_distributor_registers_t;
struct gicv2_cpu_interface_registers {
uint32_t control;
uint32_t pmr;
uint32_t bpr;
uint32_t iar;
uint32_t eoir;
uint32_t hppir;
uint32_t abpr;
uint32_t aiar;
uint32_t aeoir;
uint32_t ahppir;
// TO BE CONTINUED
};
typedef struct gicv2_cpu_interface_registers gicv2_cpu_interface_registers_t;
void gicv2_enable_irq(irq_line_t id, irq_priority_t prior, irq_flags_t flags, int cpu_mask);
void gicv2_install();
void gicv2_install_secondary_cpu();
uint32_t gicv2_interrupt_descriptor();
void gicv2_end(uint32_t int_disc);
#endif //_KERNEL_DRIVERS_IRQ_ARM_GICV2_H

View File

@@ -0,0 +1,35 @@
#ifndef _KERNEL_DRIVERS_IRQ_IRQ_API_H
#define _KERNEL_DRIVERS_IRQ_IRQ_API_H
#include <libkern/types.h>
// This value shows the maximum number of irqs OS supports. It is irqdev independent,
// thus irqdev implementations should double check the irqlines.
#define IRQ_HANDLERS_MAX 256
#define ALL_CPU_MASK 0xff
#define BOOT_CPU_MASK 0x01
typedef int irq_flags_t;
typedef int irq_line_t;
typedef uint8_t irq_priority_t;
typedef void (*irq_handler_t)(irq_line_t line);
// Currently flags maps to devtree irq_flags.
// Later we might need to enhance irq_flags_from_devtree() to use as translator.
#define IRQ_FLAG_EDGE_TRIGGERED (1 << 0)
struct irqdev_descritptor {
uint32_t (*interrupt_descriptor)();
void (*end_interrupt)(uint32_t int_desc);
void (*enable_irq)(irq_line_t line, irq_priority_t prior, irq_flags_t type, int cpu_mask);
};
typedef struct irqdev_descritptor irqdev_descritptor_t;
static inline irq_flags_t irq_flags_from_devtree(uint32_t devtree_irq_flags) { return (irq_flags_t)devtree_irq_flags; }
void irq_register_handler(irq_line_t line, irq_priority_t prior, irq_flags_t flags, irq_handler_t func, int cpu_mask);
void irq_set_dev(irqdev_descritptor_t irqdev_desc);
irq_line_t irqline_from_id(int id);
#endif

View File

@@ -0,0 +1,12 @@
#ifndef _KERNEL_DRIVERS_IRQ_RISCV_PLIC_H
#define _KERNEL_DRIVERS_IRQ_RISCV_PLIC_H
#include <drivers/driver_manager.h>
#include <drivers/irq/irq_api.h>
void plic_install();
void plic_enable_irq(irq_line_t id, irq_priority_t prior, irq_flags_t flags, int cpu_mask);
uint32_t plic_interrupt_descriptor();
void plic_end(uint32_t id);
#endif //_KERNEL_DRIVERS_IRQ_RISCV_PLIC_H

View File

@@ -0,0 +1,14 @@
#ifndef _KERNEL_DRIVERS_IRQ_X86_PIC_H
#define _KERNEL_DRIVERS_IRQ_X86_PIC_H
#include <platform/x86/port.h>
#define MASTER_PIC_CMD 0x0020
#define MASTER_PIC_DATA 0x0021
#define SLAVE_PIC_CMD 0x00A0
#define SLAVE_PIC_DATA 0x00A1
#define ICW4_8086 0x01
void pic_remap(unsigned int offset1, unsigned int offset2);
#endif

View File

@@ -0,0 +1,9 @@
#ifndef _KERNEL_DRIVERS_SERIAL_ARM_UART_H
#define _KERNEL_DRIVERS_SERIAL_ARM_UART_H
#include <drivers/serial/uart_api.h>
#include <libkern/types.h>
void uart_remap();
#endif /* _KERNEL_DRIVERS_SERIAL_ARM_UART_H */

View File

@@ -0,0 +1,9 @@
#ifndef _KERNEL_DRIVERS_SERIAL_RISCV_UART_H
#define _KERNEL_DRIVERS_SERIAL_RISCV_UART_H
#include <drivers/serial/uart_api.h>
#include <libkern/types.h>
void uart_remap();
#endif /* _KERNEL_DRIVERS_SERIAL_RISCV_UART_H */

View File

@@ -0,0 +1,11 @@
#ifndef _KERNEL_DRIVERS_SERIAL_UART_API_H
#define _KERNEL_DRIVERS_SERIAL_UART_API_H
#include <libkern/types.h>
struct boot_args;
void uart_setup(struct boot_args* boot_args);
int uart_write(uint8_t data);
int uart_read(uint8_t* data);
#endif //_KERNEL_DRIVERS_SERIAL_UART_API_H

View File

@@ -0,0 +1,12 @@
#ifndef _KERNEL_DRIVERS_SERIAL_X86_UART_H
#define _KERNEL_DRIVERS_SERIAL_X86_UART_H
#include <drivers/serial/uart_api.h>
#include <libkern/types.h>
#define COM1 0x3F8
#define COM2 0x2F8
#define COM3 0x3E8
#define COM4 0x2E8
#endif //_KERNEL_DRIVERS_SERIAL_X86_UART_H

View File

@@ -0,0 +1,74 @@
#ifndef _KERNEL_DRIVERS_STORAGE_ARM_PL181_H
#define _KERNEL_DRIVERS_STORAGE_ARM_PL181_H
#include <drivers/driver_manager.h>
#include <libkern/mask.h>
#include <libkern/types.h>
#define PL181_SECTOR_SIZE 512
enum PL181CommandMasks {
MASKDEFINE(MMC_CMD_IDX, 0, 6),
MASKDEFINE(MMC_CMD_RESP, 6, 1),
MASKDEFINE(MMC_CMD_LONG_RESP, 7, 1),
MASKDEFINE(MMC_CMD_INTERRUPT, 8, 1),
MASKDEFINE(MMC_CMD_PENDING, 9, 1),
MASKDEFINE(MMC_CMD_ENABLE, 10, 1),
};
enum PL181StatusMasks {
MASKDEFINE(MMC_STAT_CRC_FAIL, 0, 1),
MASKDEFINE(MMC_STAT_CMD_TIMEOUT, 2, 1),
MASKDEFINE(MMC_STAT_CMD_RESP_END, 6, 1),
MASKDEFINE(MMC_STAT_CMD_SENT, 7, 1),
MASKDEFINE(MMC_STAT_CMD_ACTIVE, 11, 1),
MASKDEFINE(MMC_STAT_TRANSMIT_FIFO_EMPTY, 18, 1),
MASKDEFINE(MMC_STAT_FIFO_DATA_AVAIL_TO_READ, 21, 1),
};
enum PL181Commands {
CMD_GO_IDLE_STATE = 0,
CMD_ALL_SEND_CID = 2,
CMD_SET_RELATIVE_ADDR = 3,
CMD_SELECT = 7,
CMD_SEND_CSD = 9,
CMD_SEND_CID = 10,
CMD_SET_SECTOR_SIZE = 16,
CMD_READ_SINGLE_BLOCK = 17,
CMD_WRITE_SINGLE_BLOCK = 24,
CMD_SD_SEND_OP_COND = 41,
CMD_APP_CMD = 55,
};
struct pl181_registers {
uint32_t power;
uint32_t clock;
uint32_t arg;
uint32_t cmd;
uint32_t resp_cmd;
uint32_t response[4];
uint32_t data_timer;
uint32_t data_length;
uint32_t data_control;
uint32_t data_count;
uint32_t status;
uint32_t clear;
uint32_t interrupt_mask[2];
uint32_t interrupt_select;
uint32_t fifo_count;
char res[0x34];
uint32_t fifo_data[16];
// TO BE CONTINUED
};
typedef struct pl181_registers pl181_registers_t;
struct sd_card {
uint32_t rca;
uint32_t ishc;
uint32_t capacity;
};
typedef struct sd_card sd_card_t;
void pl181_install();
#endif //_KERNEL_DRIVERS_STORAGE_ARM_PL181_H

View File

@@ -0,0 +1,9 @@
#ifndef _KERNEL_DRIVERS_STORAGE_RAMDISK_H
#define _KERNEL_DRIVERS_STORAGE_RAMDISK_H
#include <drivers/driver_manager.h>
#include <libkern/types.h>
void ramdisk_install();
#endif //_KERNEL_DRIVERS_STORAGE_RAMDISK_H

View File

@@ -0,0 +1,58 @@
#ifndef _KERNEL_DRIVERS_STORAGE_VIRTIO_BLOCK_H
#define _KERNEL_DRIVERS_STORAGE_VIRTIO_BLOCK_H
#include <drivers/driver_manager.h>
#include <drivers/virtio/virtio.h>
#include <libkern/types.h>
#include <mem/kmalloc.h>
#define VIRTIO_BLK_T_IN (0)
#define VIRTIO_BLK_T_OUT (1)
#define VIRTIO_BLK_T_FLUSH (4)
#define VIRTIO_BLK_T_DISCARD (11)
#define VIRTIO_BLK_T_WRITE_ZEROES (13)
// Status values
#define VIRTIO_BLK_S_OK (0)
#define VIRTIO_BLK_S_IOERR (1)
#define VIRTIO_BLK_S_UNSUPP (2)
// Feature bits
#define VIRTIO_BLK_F_SIZE_MAX (1)
#define VIRTIO_BLK_F_SEG_MAX (2)
#define VIRTIO_BLK_F_GEOMETRY (4)
#define VIRTIO_BLK_F_RO (5)
#define VIRTIO_BLK_F_BLK_SIZE (6)
#define VIRTIO_BLK_F_FLUSH (9)
#define VIRTIO_BLK_F_TOPOLOGY (10)
#define VIRTIO_BLK_F_CONFIG_WCE (11)
#define VIRTIO_BLK_F_DISCARD (13)
#define VIRTIO_BLK_F_WRITE_ZEROES (14)
struct block_dev {
virtio_queue_desc_t queue_desc;
void* ptr;
uint32_t idx;
uint32_t ack_used_idx;
virtio_buffer_desc_t buffer_desc;
};
typedef struct block_dev block_dev_t;
typedef struct {
uint32_t blktype;
uint32_t reserved;
uint64_t sector;
} block_header_t;
typedef struct {
uint8_t status;
} block_status_t;
typedef struct {
block_header_t header;
block_status_t status;
uint16_t head;
uint16_t watcher;
} block_request_t;
#endif //_KERNEL_DRIVERS_STORAGE_VIRTIO_BLOCK_H

View File

@@ -0,0 +1,40 @@
#ifndef _KERNEL_DRIVERS_STORAGE_X86_ATA_H
#define _KERNEL_DRIVERS_STORAGE_X86_ATA_H
#include <drivers/driver_manager.h>
#include <libkern/types.h>
#include <mem/kmalloc.h>
#include <platform/x86/port.h>
typedef struct { // LBA28 | LBA48
uint32_t data; // 16bit | 16 bits
uint32_t error; // 8 bit | 16 bits
uint32_t sector_count; // 8 bit | 16 bits
uint32_t lba_lo; // 8 bit | 16 bits
uint32_t lba_mid; // 8 bit | 16 bits
uint32_t lba_hi; // 8 bit | 16 bits
uint32_t device; // 8 bit
uint32_t command; // 8 bit
uint32_t control;
} ata_ports_t;
typedef struct {
ata_ports_t port;
bool is_master;
uint16_t cylindres;
uint16_t heads;
uint16_t sectors;
bool dma;
bool lba;
uint32_t capacity; // in sectors
} ata_t;
extern ata_t _ata_drives[MAX_DEVICES_COUNT];
int ata_init_with_dev(device_t* dev);
void ata_install();
void ata_init(ata_t* ata, uint32_t port, bool is_master);
bool ata_indentify(ata_t* ata);
#endif //_KERNEL_DRIVERS_STORAGE_X86_ATA_H

View File

@@ -0,0 +1,10 @@
#ifndef _KERNEL_DRIVERS_TIMER_ARM_ARM64_TIMER_H
#define _KERNEL_DRIVERS_TIMER_ARM_ARM64_TIMER_H
#include <libkern/types.h>
#include <time/time_manager.h>
void arm64_timer_rearm();
void arm64_timer_install();
#endif // _KERNEL_DRIVERS_TIMER_ARM_ARM64_TIMER_H

View File

@@ -0,0 +1,34 @@
#ifndef _KERNEL_DRIVERS_TIMER_ARM_SP804_H
#define _KERNEL_DRIVERS_TIMER_ARM_SP804_H
#include <drivers/driver_manager.h>
#include <libkern/mask.h>
#include <libkern/types.h>
#include <time/time_manager.h>
#define SP804_CLK_HZ 1000000
// https://developer.arm.com/documentation/ddi0271/d/programmer-s-model/register-descriptions/control-register--timerxcontrol?lang=en
enum SP804ControlMasks {
MASKDEFINE(SP804_ONE_SHOT, 0, 1),
MASKDEFINE(SP804_32_BIT, 1, 1),
MASKDEFINE(SP804_PRESCALE, 2, 2),
MASKDEFINE(SP804_INTS_ENABLED, 5, 1),
MASKDEFINE(SP804_PERIODIC, 6, 1),
MASKDEFINE(SP804_ENABLE, 7, 1),
};
struct sp804_registers {
uint32_t load;
uint32_t value;
uint32_t control;
uint32_t intclr;
uint32_t ris;
uint32_t mis;
uint32_t bg_load;
};
typedef struct sp804_registers sp804_registers_t;
void sp804_install();
#endif //_KERNEL_DRIVERS_TIMER_ARM_SP804_H

View File

@@ -0,0 +1,11 @@
#ifndef _KERNEL_DRIVERS_TIMER_X86_PIT_H
#define _KERNEL_DRIVERS_TIMER_X86_PIT_H
#include <libkern/types.h>
#include <time/time_manager.h>
#define PIT_BASE_FREQ 1193180
void pit_setup();
#endif /* _KERNEL_DRIVERS_TIMER_X86_PIT_H */

View File

@@ -0,0 +1,186 @@
#ifndef _KERNEL_DRIVERS_VIRTIO_VIRTIO_H
#define _KERNEL_DRIVERS_VIRTIO_VIRTIO_H
#include <drivers/driver_manager.h>
#include <libkern/mask.h>
#include <libkern/types.h>
#include <platform/generic/vmm/consts.h>
#include <time/time_manager.h>
#define VIRTIO_DESC_F_NEXT (1)
#define VIRTIO_DESC_F_WRITE (2)
#define VIRTIO_DESC_F_INDIRECT (4)
#define VIRTIO_F_EVENT_IDX (1 << 29)
#define VIRTIO_RING_SIZE (1 << 7)
enum VIRTIO_DEVTYPE {
VIRTIO_DEVTYPE_NETWORK = 1,
VIRTIO_DEVTYPE_BLOCK = 2,
VIRTIO_DEVTYPE_GPU = 16,
VIRTIO_DEVTYPE_IO = 18,
};
enum VIRTIO_STATUS {
VIRTIO_STATUS_ACK = 1,
VIRTIO_STATUS_DRIVER = 2,
VIRTIO_STATUS_DRIVER_OK = 4,
VIRTIO_STATUS_FEATS_OK = 8,
VIRTIO_STATUS_DEV_NEEDS_RESET = 64,
VIRTIO_STATUS_FAILED = 128,
};
struct virtio_mmio_registers {
uint32_t magic_value;
uint32_t version;
uint32_t device_id;
uint32_t vendor_id;
uint32_t host_features;
uint32_t host_features_sel;
uint8_t reserved1[8];
uint32_t guest_features;
uint32_t guest_features_sel;
uint32_t guest_page_size;
uint8_t reserved2[4];
uint32_t queue_sel;
uint32_t queue_num_max;
uint32_t queue_num;
uint32_t queue_align;
uint64_t queue_pfn;
uint8_t reserved3[8];
uint32_t queue_notify;
uint8_t reserved4[12];
uint32_t interrupt_status;
uint32_t interrupt_ack;
uint8_t reserved5[8];
uint32_t status;
uint8_t reserved6[140];
uint32_t config[1];
};
typedef struct virtio_mmio_registers virtio_mmio_registers_t;
struct virtio_desc {
uint64_t addr;
uint32_t len;
uint16_t flags;
uint16_t next;
};
typedef struct virtio_desc virtio_desc_t;
struct virtio_avail {
uint16_t flags;
uint16_t idx;
uint16_t ring[VIRTIO_RING_SIZE];
uint16_t event;
};
typedef struct virtio_avail virtio_avail_t;
struct virtio_used_elem {
uint32_t id;
uint32_t len;
};
typedef struct virtio_used_elem virtio_used_elem_t;
struct virtio_used {
uint16_t flags;
uint16_t idx;
virtio_used_elem_t ring[VIRTIO_RING_SIZE];
uint16_t event;
};
typedef struct virtio_used virtio_used_t;
struct virtio_desc_array {
virtio_desc_t entities[VIRTIO_RING_SIZE];
};
typedef struct virtio_desc_array virtio_desc_array_t;
struct virtio_queue {
virtio_desc_t desc[VIRTIO_RING_SIZE];
virtio_avail_t avail;
uint8_t padding0[4096 - sizeof(virtio_desc_t) * VIRTIO_RING_SIZE - sizeof(virtio_avail_t)];
virtio_used_t used;
};
typedef struct virtio_queue virtio_queue_t;
struct virtio_alloc_result {
void* req_vaddr;
void* req_paddr;
void* mem_vaddr;
void* mem_paddr;
void* resp_vaddr;
void* resp_paddr;
};
typedef struct virtio_alloc_result virtio_alloc_result_t;
struct virtio_buffer_desc {
union {
uintptr_t vaddr;
void* ptr;
};
uintptr_t paddr;
kmemzone_t kzone;
};
typedef struct virtio_buffer_desc virtio_buffer_desc_t;
struct virtio_queue_desc {
// These are vaddrs.
virtio_desc_array_t* descs;
virtio_avail_t* avail;
virtio_used_t* used;
// Start of the queue.
uintptr_t paddr;
};
typedef struct virtio_queue_desc virtio_queue_desc_t;
int virtio_alloc_buffer(size_t size, virtio_buffer_desc_t* result);
int virtio_alloc_queue(virtio_queue_desc_t* result);
int virtio_alloc_init();
int virtio_alloc(size_t size, virtio_alloc_result_t* result);
void virtio_free_paddr(void* paddr_ptr);
#define virtio_alloc_raw(req_ptr, result) do_virtio_alloc_raw(req_ptr, sizeof(*req_ptr), result)
static int do_virtio_alloc_raw(void* req_ptr, size_t req_size, virtio_alloc_result_t* result)
{
int err = virtio_alloc(req_size, result);
if (err) {
return err;
}
memcpy(result->req_vaddr, req_ptr, req_size);
return err;
}
#define virtio_alloc_request(req_ptr, resp_ptr, result) do_virtio_alloc_request(req_ptr, sizeof(*req_ptr), resp_ptr, sizeof(*resp_ptr), result)
static int do_virtio_alloc_request(void* req_ptr, size_t req_size, void* resp_ptr, size_t resp_size, virtio_alloc_result_t* result)
{
int err = virtio_alloc(req_size + resp_size, result);
if (err) {
return err;
}
result->resp_vaddr = (void*)((uintptr_t)result->req_vaddr + req_size);
result->resp_paddr = (void*)((uintptr_t)result->req_paddr + req_size);
memcpy(result->req_vaddr, req_ptr, req_size);
memcpy(result->resp_vaddr, resp_ptr, resp_size);
return err;
}
#define virtio_alloc_mem_request(req_ptr, mem_ptr, resp_ptr, result) do_alloc_mem_request(req_ptr, sizeof(*req_ptr), mem_ptr, sizeof(*mem_ptr), resp_ptr, sizeof(*resp_ptr), result)
static int do_alloc_mem_request(void* req_ptr, size_t req_size, void* mem_ptr, size_t mem_size, void* resp_ptr, size_t resp_size, virtio_alloc_result_t* result)
{
int err = virtio_alloc(req_size + mem_size + resp_size, result);
if (err) {
return err;
}
result->mem_vaddr = (void*)((uintptr_t)result->req_vaddr + req_size);
result->mem_paddr = (void*)((uintptr_t)result->req_paddr + req_size);
result->resp_vaddr = (void*)((uintptr_t)result->mem_vaddr + mem_size);
result->resp_paddr = (void*)((uintptr_t)result->mem_paddr + mem_size);
memcpy(result->req_vaddr, req_ptr, req_size);
memcpy(result->mem_vaddr, mem_ptr, mem_size);
memcpy(result->resp_vaddr, resp_ptr, resp_size);
return err;
}
#endif //_KERNEL_DRIVERS_VIRTIO_VIRTIO_H

View File

@@ -0,0 +1,61 @@
#ifndef _KERNEL_FS_DEVFS_DEVFS_H
#define _KERNEL_FS_DEVFS_DEVFS_H
#include <fs/vfs.h>
#include <libkern/c_attrs.h>
#include <libkern/kassert.h>
#include <libkern/types.h>
#define DEVFS_INODE_LEN (sizeof(struct devfs_inode))
struct PACKED devfs_inode {
mode_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;
/* NOTE: Instead of blocks here, we store devfs required things */
uint32_t index;
uint32_t dev_id;
struct file_ops* handlers;
struct devfs_inode* parent;
struct devfs_inode* prev;
struct devfs_inode* next;
struct devfs_inode* first;
struct devfs_inode* last;
#ifdef BITS32
char* name;
uint8_t padding[24];
#else // BITS64
uint8_t padding[4];
#endif
/* Block hack ends here */
uint32_t generation;
uint32_t file_acl;
uint32_t dir_acl;
uint32_t faddr;
#ifdef BITS32
uint32_t osd2[3];
#else // BITS64
char* name;
uint32_t osd2[1];
#endif
};
typedef struct devfs_inode devfs_inode_t;
STATIC_ASSERT(DEVFS_INODE_LEN == INODE_LEN, devfs_inode);
void devfs_install();
int devfs_mount();
devfs_inode_t* devfs_mkdir(const path_t* vfspath, const char* name, size_t len);
devfs_inode_t* devfs_register(const path_t* vfspath, dev_t devid, const char* name, size_t len, mode_t mode, const file_ops_t* handlers);
#endif /* _KERNEL_FS_DEVFS_DEVFS_H */

View File

@@ -0,0 +1,139 @@
#ifndef _KERNEL_FS_EXT2_EXT2_H
#define _KERNEL_FS_EXT2_EXT2_H
#include <libkern/c_attrs.h>
#include <libkern/types.h>
#define SUPERBLOCK_START 1024
#define SUPERBLOCK_LEN (sizeof(superblock_t))
struct PACKED superblock {
uint32_t inodes_count;
uint32_t blocks_count;
uint32_t r_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;
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];
uint8_t volume_name[16];
uint8_t last_mounted[64];
uint32_t algo_bitmap;
uint8_t prealloc_blocks;
uint8_t prealloc_dir_blocks;
// current jurnalling is unsupported
uint8_t unused[1024 - 206];
};
typedef struct superblock superblock_t;
#define GROUP_LEN (sizeof(group_desc_t))
struct PACKED 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 pad;
uint8_t reserved[12];
};
typedef struct group_desc group_desc_t;
struct ext2_groups_info {
uint32_t count;
group_desc_t* table;
};
typedef struct ext2_groups_info ext2_groups_info_t;
struct ext2_fsdata {
superblock_t* sb;
ext2_groups_info_t* gt;
size_t blksize;
};
typedef struct ext2_fsdata ext2_fsdata_t;
#define S_IFSOCK 0xC000
#define S_IFLNK 0xA000
#define S_IFREG 0x8000
#define S_IFBLK 0x6000
#define S_IFDIR 0x4000
#define S_IFCHR 0x2000
#define S_IFIFO 0x1000
#define S_ISUID 0x0800
#define S_ISGID 0x0400
#define S_ISVTX 0x0200
#define S_IRUSR 0x0100
#define S_IWUSR 0x0080
#define S_IXUSR 0x0040
#define S_IRGRP 0x0020
#define S_IWGRP 0x0010
#define S_IXGRP 0x0008
#define S_IROTH 0x0004
#define S_IWOTH 0x0002
#define S_IXOTH 0x0001
#define INODE_LEN (sizeof(inode_t))
#define INODES_RESERVED 11
struct PACKED inode {
mode_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;
uint32_t osd2[3];
};
typedef struct inode inode_t;
#define DIR_ENTRY_LEN (sizeof(dir_entry_t))
struct PACKED dir_entry {
uint32_t inode;
uint16_t rec_len;
uint8_t name_len;
uint8_t file_type;
char* name;
};
typedef struct dir_entry dir_entry_t;
void ext2_install();
#endif // _KERNEL_FS_EXT2_EXT2_H

View File

@@ -0,0 +1,73 @@
#ifndef _KERNEL_FS_PROCFS_PROCFS_H
#define _KERNEL_FS_PROCFS_PROCFS_H
#include <fs/vfs.h>
#include <libkern/c_attrs.h>
#include <libkern/types.h>
struct procfs_files {
char* name;
void* data;
mode_t mode;
const file_ops_t* ops;
ino_t (*inode_index)(int);
void* extra1;
void* extra2;
};
typedef struct procfs_files procfs_files_t;
#define PROCFS_INODE_LEN (sizeof(struct procfs_inode))
struct PACKED procfs_inode {
mode_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;
/* NOTE: Instead of blocks here, we store procfs required data */
uint32_t index;
const struct file_ops* ops;
#ifdef BITS32
uint8_t padding[52];
#else // BITS64
uint8_t padding[48];
#endif
/* Block hack ends here */
uint32_t generation;
uint32_t file_acl;
uint32_t dir_acl;
uint32_t faddr;
uint32_t osd2[3];
};
typedef struct procfs_inode procfs_inode_t;
STATIC_ASSERT(PROCFS_INODE_LEN == INODE_LEN, procfs_inode);
void procfs_install();
int procfs_mount();
pid_t procfs_root_get_pid_from_inode_index(ino_t inode_index);
static inline ino_t procfs_inode_get_index(uint32_t level, uint32_t main)
{
return (level << 28) | (main & 0x0fffffff);
}
static inline uint32_t procfs_inode_get_level(ino_t inode_indx)
{
return (inode_indx >> 28);
}
static inline uint32_t procfs_inode_get_body(ino_t inode_indx)
{
return (inode_indx & 0x0fffffff);
}
#endif // _KERNEL_FS_PROCFS_PROCFS_H

285
kernel/include/fs/vfs.h Normal file
View File

@@ -0,0 +1,285 @@
#ifndef _KERNEL_FS_VFS_H
#define _KERNEL_FS_VFS_H
#include <algo/sync_ringbuffer.h>
#include <drivers/driver_manager.h>
#include <fs/ext2/ext2.h>
#include <libkern/lock.h>
#include <libkern/syscall_structs.h>
#define DENTRY_WAS_IN_CACHE 0
#define DENTRY_NEWLY_ALLOCATED 1
#define VFS_MAX_FS_COUNT 5
#define VFS_MAX_DEV_COUNT 5
#define VFS_MAX_FILENAME 16
#define VFS_MAX_FILENAME_EXT 4
#define VFS_ATTR_NOTFILE 0xff
// The flag could be used as return when custom mmap function could not handle file.
// In this case the standard implementation will be used if possible.
#define VFS_USE_STD_MMAP 0xffffffff
// VFS Device is a wrapper for each of logical storage device.
// The wrapper is created only for those.
struct fs_desc;
typedef struct {
int fsid;
void* fsdata; // Holds data which is needed for FS, like pointers to superblocks and e.g.
struct fs_desc* fsdesc;
spinlock_t fslock;
device_t* dev;
} vfs_device_t;
struct dirent {
ino_t inode;
uint16_t rec_len;
uint8_t name_len;
uint8_t file_type;
char* name;
};
typedef struct dirent dirent_t;
#define DENTRY_DIRTY 0x1
#define DENTRY_MOUNTPOINT 0x2
#define DENTRY_MOUNTED 0x4
#define DENTRY_INODE_TO_BE_DELETED 0x8
#define DENTRY_PRIVATE 0x10 // This dentry can't be opened so can't be copied.
#define DENTRY_CUSTOM 0x20 // Such dentries won't be process in dentry.c file.
typedef uint32_t dentry_flag_t;
struct dentry {
size_t d_count;
dentry_flag_t flags;
ino_t inode_indx;
inode_t* inode;
// Lock controls all dentry fields, (including inode, since it could be hold only by one dentry).
spinlock_t lock;
struct fs_ops* ops;
dev_t dev_indx;
vfs_device_t* vfsdev;
char* filename;
struct dentry* parent;
struct dentry* mountpoint;
struct dentry* mounted_dentry;
struct socket* sock;
};
typedef struct dentry dentry_t;
struct path {
dentry_t* dentry;
};
typedef struct path path_t;
struct file;
struct file_descriptor;
struct file_ops {
bool (*can_read)(struct file* file, size_t start);
bool (*can_write)(struct file* file, size_t start);
int (*read)(struct file* file, void __user* buf, size_t start, size_t len);
int (*write)(struct file* file, void __user* buf, size_t start, size_t len);
int (*truncate)(struct file* file, size_t len);
int (*open)(const path_t* path, struct file_descriptor* fd, uint32_t flags);
int (*create)(const path_t* path, const char* name, size_t len, mode_t mode, uid_t uid, gid_t gid);
int (*unlink)(const path_t* path);
int (*getdents)(dentry_t* dir, void __user* buf, off_t* offset, size_t len);
int (*lookup)(const path_t* path, const char* name, size_t len, path_t* result_path);
int (*mkdir)(const path_t* path, const char* name, size_t len, mode_t mode, uid_t uid, gid_t gid);
int (*rmdir)(const path_t* path);
int (*ioctl)(struct file* file, uintptr_t cmd, uintptr_t arg);
int (*fstat)(struct file* file, stat_t* stat);
int (*fchmod)(struct file* file, mode_t mode);
struct memzone* (*mmap)(struct file* file, mmap_params_t* params);
};
typedef struct file_ops file_ops_t;
struct dentry_ops {
int (*read_inode)(dentry_t* dentry);
int (*write_inode)(dentry_t* dentry);
int (*free_inode)(dentry_t* dentry);
};
typedef struct dentry_ops dentry_ops_t;
struct fs_ops {
int (*recognize)(vfs_device_t* dev);
int (*prepare_fs)(vfs_device_t* dev);
int (*eject_device)(vfs_device_t* dev);
file_ops_t file;
dentry_ops_t dentry;
};
typedef struct fs_ops fs_ops_t;
struct fs_desc {
driver_t* driver;
fs_ops_t* ops;
};
typedef struct fs_desc fs_desc_t;
typedef uint32_t file_type_t;
enum FTYPES {
FTYPE_FILE,
FTYPE_SOCKET,
};
struct file {
size_t count;
file_type_t type;
union {
dentry_t* dentry; // type == FTYPE_FILE
struct socket* socket; // type == FTYPE_SOCKET
};
uint32_t flags;
path_t path;
file_ops_t* ops;
// Used by socket to keep data.
void* auxdata;
// Protects flags.
spinlock_t lock;
};
typedef struct file file_t;
struct file_descriptor {
file_t* file;
off_t offset;
int flags;
};
typedef struct file_descriptor file_descriptor_t;
struct socket {
size_t d_count;
int domain;
int type;
int protocol;
mode_t mode;
sync_ringbuffer_t buffer;
file_t* bind_file;
spinlock_t lock;
};
typedef struct socket socket_t;
/**
* DENTRIES
*/
void kdentryflusherd();
void dentry_set_parent(dentry_t* to, dentry_t* parent);
void dentry_set_filename(dentry_t* to, char* filename);
dentry_t* dentry_get(dev_t dev_indx, ino_t inode_indx);
dentry_t* dentry_get_no_inode(dev_t dev_indx, ino_t inode_indx, int* newly_allocated);
dentry_t* dentry_get_parent(dentry_t* dentry);
dentry_t* dentry_duplicate(dentry_t* dentry);
void dentry_put(dentry_t* dentry);
void dentry_force_put(dentry_t* dentry);
void dentry_put_all_dentries_of_dev(dev_t dev_indx);
int dentry_flush(dentry_t* dentry);
void dentry_set_inode(dentry_t* dentry, inode_t* inode);
void dentry_set_flag(dentry_t* dentry, dentry_flag_t flag);
bool dentry_test_flag(dentry_t* dentry, dentry_flag_t flag);
void dentry_rem_flag(dentry_t* dentry, dentry_flag_t flag);
void dentry_inode_set_flag(dentry_t* dentry, mode_t mode);
bool dentry_test_mode(dentry_t* dentry, mode_t mode);
void dentry_inode_rem_flag(dentry_t* dentry, mode_t mode);
void dentry_put_locked(dentry_t* dentry);
void dentry_set_flag_locked(dentry_t* dentry, dentry_flag_t flag);
bool dentry_test_flag_locked(dentry_t* dentry, dentry_flag_t flag);
void dentry_rem_flag_locked(dentry_t* dentry, dentry_flag_t flag);
bool dentry_test_mode_locked(dentry_t* dentry, mode_t mode);
size_t dentry_stat_cached_count();
/**
* VFS HELPERS
*/
ssize_t vfs_helper_write_dirent(dirent_t __user* buf, size_t buf_len, ino_t inode_index, const char* name);
char* vfs_helper_split_path_with_name(char* name, size_t len);
void vfs_helper_restore_full_path_after_split(char* path, char* name);
/**
* FILE HELPERS
*/
static inline dentry_t* file_dentry(file_t* file) { return file->type == FTYPE_FILE ? file->dentry : NULL; }
static inline socket_t* file_socket(file_t* file) { return file->type == FTYPE_SOCKET ? file->socket : NULL; }
static inline dentry_t* file_dentry_assert(file_t* file)
{
ASSERT(file->type == FTYPE_FILE);
return file->dentry;
}
static inline socket_t* file_socket_assert(file_t* file)
{
ASSERT(file->type == FTYPE_SOCKET);
return file->socket;
}
file_t* file_init_pseudo_dentry(dentry_t* pseudo_dentry);
file_t* file_init_socket(socket_t* socket, file_ops_t* ops);
file_t* file_init_path(const path_t* path);
file_t* file_duplicate(file_t* file);
file_t* file_duplicate_locked(file_t* file);
void file_put(file_t* file);
static inline bool path_is_valid(const path_t* path) { return path && path->dentry; }
path_t path_duplicate(const path_t* path);
void path_put(path_t* path);
inline path_t vfs_empty_path()
{
path_t a = { .dentry = NULL };
return a;
}
/**
* VFS APIS
*/
void vfs_install();
int vfs_add_dev(device_t* dev);
int vfs_add_dev_with_fs(device_t* dev, int fs_id);
int vfs_add_fs(driver_t* fs);
int vfs_get_fs_id(const char* name);
void vfs_eject_device(device_t* t_new_dev);
int vfs_resolve_path(const char* path, path_t* result);
int vfs_resolve_path_start_from(const path_t* vfspath, const char* path, path_t* result);
int vfs_create(const path_t* path, const char* name, size_t len, mode_t mode, uid_t uid, gid_t gid);
int vfs_unlink(const path_t* path);
int vfs_lookup(const path_t* path, const char* name, size_t len, path_t* result);
int vfs_open(const path_t* path, file_descriptor_t* fd, int flags);
int vfs_close(file_descriptor_t* fd);
bool vfs_can_read(file_descriptor_t* fd);
bool vfs_can_write(file_descriptor_t* fd);
int vfs_read(file_descriptor_t* fd, void __user* buf, size_t len);
int vfs_write(file_descriptor_t* fd, void __user* buf, size_t len);
int vfs_mkdir(const path_t* path, const char* name, size_t len, mode_t mode, uid_t uid, gid_t gid);
int vfs_rmdir(const path_t* path);
int vfs_getdents(file_descriptor_t* dir_fd, void __user* buf, size_t len);
int vfs_fstat(file_descriptor_t* fd, stat_t* stat);
int vfs_chmod(const path_t* path, mode_t mode);
int vfs_fchmod(file_descriptor_t* fd, mode_t mode);
int vfs_get_absolute_path(const path_t* path, char* buf, int len);
int vfs_mount(path_t* mount_path, device_t* dev, uint32_t fs_indx);
int vfs_umount(dentry_t* mountpoint);
struct proc;
struct memzone* vfs_mmap(file_descriptor_t* fd, mmap_params_t* params);
int vfs_munmap(struct proc* p, struct memzone*);
struct thread;
int vfs_check_open_perms(const path_t* path, int flags);
int vfs_perm_to_read(dentry_t* dentry, struct thread* t);
int vfs_perm_to_write(dentry_t* dentry, struct thread* t);
int vfs_perm_to_execute(dentry_t* dentry, struct thread* t);
#endif // _KERNEL_FS_VFS_H

View File

@@ -0,0 +1,11 @@
#ifndef _KERNEL_IO_SHARED_BUFFER_SHARED_BUFFER_H
#define _KERNEL_IO_SHARED_BUFFER_SHARED_BUFFER_H
#include <libkern/types.h>
int shared_buffer_init();
int shared_buffer_create(uintptr_t __user* buffer, size_t size);
int shared_buffer_get(int id, uintptr_t __user* buffer);
int shared_buffer_free(int id);
#endif /* _KERNEL_IO_SHARED_BUFFER_SHARED_BUFFER_H */

View File

@@ -0,0 +1,16 @@
#ifndef _KERNEL_IO_SOCKETS_LOCAL_SOCKET_H
#define _KERNEL_IO_SOCKETS_LOCAL_SOCKET_H
#include <io/sockets/socket.h>
int local_socket_create(int type, int protocol, file_descriptor_t* fd);
bool local_socket_can_read(file_t* file, size_t start);
int local_socket_read(file_t* file, void __user* buf, size_t start, size_t len);
bool local_socket_can_write(file_t* file, size_t start);
int local_socket_write(file_t* file, void __user* buf, size_t start, size_t len);
int local_socket_fchmod(file_t* file, mode_t mode);
int local_socket_bind(file_descriptor_t* sock, char* name, size_t len);
int local_socket_connect(file_descriptor_t* sock, char* name, size_t len);
#endif /* _KERNEL_IO_SOCKETS_LOCAL_SOCKET_H */

View File

@@ -0,0 +1,14 @@
#ifndef _KERNEL_IO_SOCKETS_SOCKET_H
#define _KERNEL_IO_SOCKETS_SOCKET_H
#include <fs/vfs.h>
#include <libkern/syscall_structs.h>
#include <libkern/types.h>
#define MAX_SOCKET_COUNT 32
int socket_create(int domain, int type, int protocol, file_descriptor_t* fd, file_ops_t* ops);
socket_t* socket_duplicate(socket_t* sock);
int socket_put(socket_t* sock);
#endif /* _KERNEL_IO_SOCKETS_SOCKET_H */

View File

@@ -0,0 +1,6 @@
#ifndef _KERNEL_IO_TTY_PTMX_H
#define _KERNEL_IO_TTY_PTMX_H
int ptmx_install();
#endif

View File

@@ -0,0 +1,23 @@
#ifndef _KERNEL_IO_TTY_PTY_MASTER_H
#define _KERNEL_IO_TTY_PTY_MASTER_H
#include <algo/sync_ringbuffer.h>
#include <fs/vfs.h>
#ifndef PTYS_COUNT
#define PTYS_COUNT 16
#endif
struct pty_slave_entry;
struct pty_master_entry {
sync_ringbuffer_t buffer;
struct pty_slave_entry* pts;
dentry_t dentry;
};
typedef struct pty_master_entry pty_master_entry_t;
extern pty_master_entry_t pty_masters[PTYS_COUNT];
int pty_master_alloc(file_descriptor_t* fd);
#endif

View File

@@ -0,0 +1,24 @@
#ifndef _KERNEL_IO_TTY_PTY_SLAVE_H
#define _KERNEL_IO_TTY_PTY_SLAVE_H
#include <algo/sync_ringbuffer.h>
#include <io/tty/tty.h>
#ifndef PTYS_COUNT
#define PTYS_COUNT 4
#endif
struct pty_master_entry;
struct pty_slave_entry {
int inode_indx;
struct pty_master_entry* ptm;
tty_entry_t tty;
};
typedef struct pty_slave_entry pty_slave_entry_t;
extern pty_slave_entry_t pty_slaves[PTYS_COUNT];
int pty_slave_create(int id, struct pty_master_entry* ptm);
#endif

View File

@@ -0,0 +1,88 @@
#ifndef _KERNEL_IO_TTY_TTY_H
#define _KERNEL_IO_TTY_TTY_H
#include <algo/sync_ringbuffer.h>
#include <fs/vfs.h>
#include <libkern/types.h>
#define TTY_MAX_COUNT 8
#define TTY_BUFFER_SIZE 1024
typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
#define NCCS 32
struct termios {
tcflag_t c_iflag; // input mode flags
tcflag_t c_oflag; // output mode flags
tcflag_t c_cflag; // control mode flags
tcflag_t c_lflag; // local mode flags
cc_t c_cc[NCCS]; // control characters
};
typedef struct termios termios_t;
/* c_cc characters */
#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_lflag bits */
#define ISIG 0000001
#define ICANON 0000002
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#define IEXTEN 0100000
/* tcflow() and TCXONC use these */
#define TCOOFF 0
#define TCOON 1
#define TCIOFF 2
#define TCION 3
/* tcflush() and TCFLSH use these */
#define TCIFLUSH 0
#define TCOFLUSH 1
#define TCIOFLUSH 2
/* tcsetattr uses these */
#define TCSANOW 0
#define TCSADRAIN 1
#define TCSAFLUSH 2
struct tty_entry {
sync_ringbuffer_t buffer;
int line_count;
gid_t pgid;
termios_t termios;
};
typedef struct tty_entry tty_entry_t;
int tty_init(tty_entry_t* tty);
int tty_clear(tty_entry_t* tty);
bool tty_can_read(tty_entry_t* tty, file_t* file, size_t start);
int tty_read(tty_entry_t* tty, file_t* file, void __user* buf, size_t start, size_t len);
bool tty_can_write(tty_entry_t* tty, file_t* file, size_t start);
int tty_write(tty_entry_t* tty, file_t* file, void __user* buf, size_t start, size_t len);
int tty_ioctl(tty_entry_t* tty, file_t* file, uintptr_t cmd, uintptr_t arg);
#endif // _KERNEL_IO_TTY_TTY_H

View File

@@ -0,0 +1,23 @@
#ifndef _KERNEL_IO_TTY_VCONSOLE_H
#define _KERNEL_IO_TTY_VCONSOLE_H
#include <algo/sync_ringbuffer.h>
#include <io/tty/tty.h>
#include <libkern/types.h>
#define VCONSOLE_MAX_COUNT 8
#define VCONSOLE_BUFFER_SIZE 1024
struct vconsole_entry {
int id;
int inode_indx;
tty_entry_t tty;
};
typedef struct vconsole_entry vconsole_entry_t;
extern vconsole_entry_t vconsoles[VCONSOLE_MAX_COUNT];
vconsole_entry_t* vconsole_new();
void vconsole_eat_key(int key);
#endif // _KERNEL_IO_TTY_TTY_H

View File

@@ -0,0 +1,6 @@
#ifndef _KERNEL_LIBKERN__TYPES__VA_LIST_H
#define _KERNEL_LIBKERN__TYPES__VA_LIST_H
typedef __builtin_va_list va_list;
#endif // _KERNEL_LIBKERN__TYPES__VA_LIST_H

View File

@@ -0,0 +1,12 @@
#ifndef _KERNEL_LIBKERN_ATOMIC_H
#define _KERNEL_LIBKERN_ATOMIC_H
#include <libkern/c_attrs.h>
#include <libkern/kassert.h>
#include <libkern/types.h>
#define atomic_add(x, val) (__atomic_add_fetch(x, val, __ATOMIC_SEQ_CST))
#define atomic_store(x, val) (__atomic_store_n(x, val, __ATOMIC_SEQ_CST))
#define atomic_load(x) (__atomic_load_n(x, __ATOMIC_SEQ_CST))
#endif // _KERNEL_LIBKERN_LOCK_H

View File

@@ -0,0 +1,135 @@
#ifndef _KERNEL_LIBKERN_BITS_ERRNO_H
#define _KERNEL_LIBKERN_BITS_ERRNO_H
// clang-format off
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define EBADARCH 125 /* Bad arch */
// clang-format on
#endif // _KERNEL_LIBKERN_BITS_ERRNO_H

View File

@@ -0,0 +1,19 @@
#ifndef _KERNEL_LIBKERN_BITS_FCNTL_H
#define _KERNEL_LIBKERN_BITS_FCNTL_H
#define SEEK_SET 0x1
#define SEEK_CUR 0x2
#define SEEK_END 0x3
/* OPEN */
#define O_RDONLY 0x1
#define O_WRONLY 0x2
#define O_RDWR (O_RDONLY | O_WRONLY)
#define O_DIRECTORY 0x4
#define O_CREAT 0x8
#define O_TRUNC 0x10
#define O_APPEND 0x20
#define O_EXCL 0x40
#define O_EXEC 0x80
#endif // _KERNEL_LIBKERN_BITS_FCNTL_H

View File

@@ -0,0 +1,44 @@
#ifndef _KERNEL_LIBKERN_BITS_SIGNAL_H
#define _KERNEL_LIBKERN_BITS_SIGNAL_H
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPOLL SIGIO
#define SIGPWR 30
#define SIGSYS 31
typedef void (*sighandler_t)(int);
#define SIG_DFL ((sighandler_t)0)
#define SIG_ERR ((sighandler_t)-1)
#define SIG_IGN ((sighandler_t)1)
#endif // _KERNEL_LIBKERN_BITS_SIGNAL_H

View File

@@ -0,0 +1,18 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_IOCTLS_H
#define _KERNEL_LIBKERN_BITS_SYS_IOCTLS_H
/* TTY */
#define TIOCGPGRP 0x0101
#define TIOCSPGRP 0x0102
#define TCGETS 0x0103
#define TCSETS 0x0104
#define TCSETSW 0x0105
#define TCSETSF 0x0106
/* BGA */
#define BGA_SWAP_BUFFERS 0x0101
#define BGA_GET_HEIGHT 0x0102
#define BGA_GET_WIDTH 0x0103
#define BGA_GET_SCALE 0x0104
#endif // _KERNEL_LIBKERN_BITS_SYS_IOCTLS_H

View File

@@ -0,0 +1,27 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_MMAN_H
#define _KERNEL_LIBKERN_BITS_SYS_MMAN_H
#include <libkern/types.h>
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
#define MAP_STACK 0x40
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define PROT_NONE 0x0
struct mmap_params {
void* addr;
size_t size;
int prot;
int flags;
int fd;
off_t offset;
};
typedef struct mmap_params mmap_params_t;
#endif // _KERNEL_LIBKERN_BITS_SYS_MMAN_H

View File

@@ -0,0 +1,12 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_PTRACE_H
#define _KERNEL_LIBKERN_BITS_SYS_PTRACE_H
#include <libkern/types.h>
typedef int ptrace_request_t;
#define PTRACE_TRACEME (0x1)
#define PTRACE_CONT (0x2)
#define PTRACE_PEEKTEXT (0x3)
#define PTRACE_PEEKDATA (0x4)
#endif // _KERNEL_LIBKERN_BITS_SYS_PTRACE_H

View File

@@ -0,0 +1,18 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_SELECT_H
#define _KERNEL_LIBKERN_BITS_SYS_SELECT_H
#include <libkern/types.h>
#define FD_SETSIZE 32
struct fd_set {
uint8_t fds[FD_SETSIZE / 8];
};
typedef struct fd_set fd_set_t;
#define FD_SET(fd, fd_set_ptr) ((fd_set_ptr)->fds[fd / 8] |= (1 << (fd % 8)))
#define FD_CLR(fd, fd_set_ptr) ((fd_set_ptr)->fds[fd / 8] &= ~(1 << (fd % 8)))
#define FD_ZERO(fd_set_ptr) (memset((uint8_t*)(fd_set_ptr), 0, sizeof(fd_set_t)))
#define FD_ISSET(fd, fd_set_ptr) ((fd_set_ptr)->fds[fd / 8] & (1 << (fd % 8)))
#endif // _KERNEL_LIBKERN_BITS_SYS_SELECT_H

View File

@@ -0,0 +1,26 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_SOCKET_H
#define _KERNEL_LIBKERN_BITS_SYS_SOCKET_H
enum SOCK_DOMAINS {
PF_LOCAL,
PF_INET,
PF_INET6,
PF_IPX,
PF_NETLINK,
PF_X25,
PF_AX25,
PF_ATMPVC,
PF_APPLETALK,
PF_PACKET,
};
enum SOCK_TYPES {
SOCK_STREAM,
SOCK_DGRAM,
SOCK_SEQPACKET,
SOCK_RAW,
SOCK_RDM,
SOCK_PACKET,
};
#endif // _KERNEL_LIBKERN_BITS_SYS_SOCKET_H

View File

@@ -0,0 +1,64 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_STAT_H
#define _KERNEL_LIBKERN_BITS_SYS_STAT_H
#include <libkern/bits/time.h>
#include <libkern/types.h>
#define S_IFMT 0xF000
/* MODES */
#define S_IFSOCK 0xC000 /* [XSI] socket */
#define S_IFLNK 0xA000 /* [XSI] symbolic link */
#define S_IFREG 0x8000 /* [XSI] regular */
#define S_IFBLK 0x6000 /* [XSI] block special */
#define S_IFDIR 0x4000 /* [XSI] directory */
#define S_IFCHR 0x2000 /* [XSI] character special */
#define S_IFIFO 0x1000 /* [XSI] named pipe (fifo) */
#define S_ISUID 0x0800
#define S_ISGID 0x0400
#define S_ISVTX 0x0200
/* Read, write, execute/search by owner */
#define S_IRWXU 0x01c0
#define S_IRUSR 0x0100
#define S_IWUSR 0x0080
#define S_IXUSR 0x0040
/* Read, write, execute/search by group */
#define S_IRWXG 0x0038
#define S_IRGRP 0x0020
#define S_IWGRP 0x0010
#define S_IXGRP 0x0008
/* Read, write, execute/search by others */
#define S_IRWXO 0x0007
#define S_IROTH 0x0004
#define S_IWOTH 0x0002
#define S_IXOTH 0x0001
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO)
#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK)
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* Inode number */
mode_t st_mode; /* File type and mode */
nlink_t st_nlink; /* Number of hard links */
uid_t st_uid; /* User ID of owner */
gid_t st_gid; /* Group ID of owner */
dev_t st_rdev; /* Device ID (if special file) */
off_t st_size; /* Total size, in bytes */
uint32_t st_blksize; /* Block size for filesystem I/O */
uint32_t st_blocks; /* Number of 512B blocks allocated */
struct timespec st_atim; /* Time of last access */
struct timespec st_mtim; /* Time of last modification */
struct timespec st_ctim; /* Time of last status change */
};
typedef struct stat stat_t;
#endif // _KERNEL_LIBKERN_BITS_SYS_STAT_H

View File

@@ -0,0 +1,15 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_UTSNAME_H
#define _KERNEL_LIBKERN_BITS_SYS_UTSNAME_H
#define UTSNAME_ENTRY_LEN 65
struct utsname {
char sysname[UTSNAME_ENTRY_LEN];
char nodename[UTSNAME_ENTRY_LEN];
char release[UTSNAME_ENTRY_LEN];
char version[UTSNAME_ENTRY_LEN];
char machine[UTSNAME_ENTRY_LEN];
};
typedef struct utsname utsname_t;
#endif // _KERNEL_LIBKERN_BITS_SYS_UTSNAME_H

View File

@@ -0,0 +1,7 @@
#ifndef _KERNEL_LIBKERN_BITS_SYS_WAIT_H
#define _KERNEL_LIBKERN_BITS_SYS_WAIT_H
#define WNOHANG 0x1
#define WUNTRACED 0x2
#endif // _KERNEL_LIBKERN_BITS_SYS_WAIT_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
#ifndef _KERNEL_LIBKERN_BITS_THREAD_H
#define _KERNEL_LIBKERN_BITS_THREAD_H
#include <libkern/types.h>
struct thread_create_params {
uint32_t entry_point;
uint32_t stack_start;
uint32_t stack_size;
};
typedef struct thread_create_params thread_create_params_t;
#endif // _KERNEL_LIBKERN_BITS_THREAD_H

View File

@@ -0,0 +1,51 @@
#ifndef _KERNEL_LIBKERN_BITS_TIME_H
#define _KERNEL_LIBKERN_BITS_TIME_H
#include <libkern/types.h>
struct timeval {
time_t tv_sec;
uint32_t tv_usec;
};
typedef struct timeval timeval_t;
#define DST_NONE 0 /* not on dst */
#define DST_USA 1 /* USA style dst */
#define DST_AUST 2 /* Australian style dst */
#define DST_WET 3 /* Western European dst */
#define DST_MET 4 /* Middle European dst */
#define DST_EET 5 /* Eastern European dst */
#define DST_CAN 6 /* Canada */
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
typedef struct timezone timezone_t;
struct timespec {
time_t tv_sec;
uint32_t tv_nsec;
};
typedef struct timespec timespec_t;
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
typedef struct tm tm_t;
typedef enum {
CLOCK_REALTIME,
CLOCK_MONOTONIC,
CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID,
} clockid_t;
#endif // _KERNEL_LIBKERN_BITS_TIME_H

View File

@@ -0,0 +1,31 @@
#ifndef _KERNEL_LIBKERN_BITS_TYPES_H
#define _KERNEL_LIBKERN_BITS_TYPES_H
typedef char __int8_t;
typedef short __int16_t;
typedef int __int32_t;
typedef long long __int64_t;
typedef unsigned char __uint8_t;
typedef unsigned short __uint16_t;
typedef unsigned int __uint32_t;
typedef unsigned long long __uint64_t;
typedef __uint32_t __dev_t; /* Type of device numbers. */
typedef __uint32_t __uid_t; /* Type of user identifications. */
typedef __uint32_t __gid_t; /* Type of group identifications. */
typedef __uint32_t __ino_t; /* Type of file serial numbers. */
typedef __uint64_t __ino64_t; /* Type of file serial numbers (LFS).*/
typedef __uint16_t __mode_t; /* Type of file attribute bitmasks. */
typedef __uint32_t __nlink_t; /* Type of file link counts. */
typedef __int64_t __off64_t; /* Type of file sizes and offsets (LFS). */
typedef __uint32_t __pid_t; /* Type of process identifications. */
typedef __uint32_t __fsid_t; /* Type of file system IDs. */
typedef __uint32_t __time_t; /* Seconds since the Epoch. */
#if defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64))
typedef __int64_t __off_t; /* Type of file sizes and offsets. */
#else
typedef __int32_t __off_t; /* Type of file sizes and offsets. */
#endif
#endif // _KERNEL_LIBKERN_BITS_TYPES_H

View File

@@ -0,0 +1,24 @@
#ifndef _KERNEL_LIBKERN_C_ATTRS_H
#define _KERNEL_LIBKERN_C_ATTRS_H
#ifndef PACKED
#define PACKED __attribute__((packed))
#endif // PACKED
#ifndef MAYBE_UNUSED
#define MAYBE_UNUSED __attribute__((__unused__))
#endif // MAYBE_UNUSED
#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#endif // ALWAYS_INLINE
#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif // NORETURN
#ifndef WARN_UNUSED_RESULT
#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#endif // WARN_UNUSED_RESULT
#endif // _KERNEL_LIBKERN_C_ATTRS_H

View File

@@ -0,0 +1,31 @@
#ifndef _KERNEL_LIBKERN_CTYPE_H
#define _KERNEL_LIBKERN_CTYPE_H
#include <libkern/types.h>
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
extern const char __kern_ctypes[256];
static inline int isalnum(int c) { return __kern_ctypes[(unsigned char)(c)] & (_U | _L | _N); }
static inline int isalpha(int c) { return __kern_ctypes[(unsigned char)(c)] & (_U | _L); }
static inline int iscntrl(int c) { return __kern_ctypes[(unsigned char)(c)] & (_C); }
static inline int isdigit(int c) { return __kern_ctypes[(unsigned char)(c)] & (_N); }
static inline int isxdigit(int c) { return __kern_ctypes[(unsigned char)(c)] & (_N | _X); }
static inline int isspace(int c) { return __kern_ctypes[(unsigned char)(c)] & (_S); }
static inline int ispunct(int c) { return __kern_ctypes[(unsigned char)(c)] & (_P); }
static inline int isprint(int c) { return __kern_ctypes[(unsigned char)(c)] & (_P | _U | _L | _N | _B); }
static inline int isgraph(int c) { return __kern_ctypes[(unsigned char)(c)] & (_P | _U | _L | _N); }
static inline int islower(int c) { return (__kern_ctypes[(unsigned char)(c)] & (_U | _L)) == _L; }
static inline int isupper(int c) { return (__kern_ctypes[(unsigned char)(c)] & (_U | _L)) == _U; }
static inline int tolower(int c) { return isupper(c) ? (c) - 'a' + 'A' : c; }
static inline int toupper(int c) { return islower(c) ? (c) - 'A' + 'a' : c; }
#endif /* _KERNEL_LIBKERN_CTYPE_H */

View File

@@ -0,0 +1,152 @@
/**
* 8x8 monochrome bitmap fonts for rendering
* Author: Daniel Hepper <daniel@hepper.net>
*
* License: Public Domain
*
* Based on:
* // Summary: font8x8.h
* // 8x8 monochrome bitmap fonts for rendering
* //
* // Author:
* // Marcel Sondaar
* // International Business Machines (public domain VGA fonts)
* //
* // License:
* // Public Domain
*
* Fetched from: http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm
**/
// Constant: font8x8_basic
// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin)
static char font8x8_basic[128][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0000 (nul)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0001
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0002
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0003
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0004
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0005
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0006
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0007
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0008
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0009
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000A
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000B
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000C
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000D
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000E
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000F
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0010
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0011
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0012
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0013
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0014
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0015
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0016
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0017
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0018
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0019
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001A
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001B
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001C
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001D
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001E
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001F
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0020 (space)
{ 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00 }, // U+0021 (!)
{ 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0022 (")
{ 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00 }, // U+0023 (#)
{ 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00 }, // U+0024 ($)
{ 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00 }, // U+0025 (%)
{ 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00 }, // U+0026 (&)
{ 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0027 (')
{ 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00 }, // U+0028 (()
{ 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00 }, // U+0029 ())
{ 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00 }, // U+002A (*)
{ 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00 }, // U+002B (+)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06 }, // U+002C (,)
{ 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00 }, // U+002D (-)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // U+002E (.)
{ 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00 }, // U+002F (/)
{ 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00 }, // U+0030 (0)
{ 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00 }, // U+0031 (1)
{ 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00 }, // U+0032 (2)
{ 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00 }, // U+0033 (3)
{ 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00 }, // U+0034 (4)
{ 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00 }, // U+0035 (5)
{ 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00 }, // U+0036 (6)
{ 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00 }, // U+0037 (7)
{ 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00 }, // U+0038 (8)
{ 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00 }, // U+0039 (9)
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // U+003A (:)
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06 }, // U+003B (;)
{ 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00 }, // U+003C (<)
{ 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00 }, // U+003D (=)
{ 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00 }, // U+003E (>)
{ 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00 }, // U+003F (?)
{ 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00 }, // U+0040 (@)
{ 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00 }, // U+0041 (A)
{ 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00 }, // U+0042 (B)
{ 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00 }, // U+0043 (C)
{ 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00 }, // U+0044 (D)
{ 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00 }, // U+0045 (E)
{ 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00 }, // U+0046 (F)
{ 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00 }, // U+0047 (G)
{ 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00 }, // U+0048 (H)
{ 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0049 (I)
{ 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00 }, // U+004A (J)
{ 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00 }, // U+004B (K)
{ 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00 }, // U+004C (L)
{ 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00 }, // U+004D (M)
{ 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00 }, // U+004E (N)
{ 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00 }, // U+004F (O)
{ 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00 }, // U+0050 (P)
{ 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00 }, // U+0051 (Q)
{ 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00 }, // U+0052 (R)
{ 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00 }, // U+0053 (S)
{ 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0054 (T)
{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00 }, // U+0055 (U)
{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00 }, // U+0056 (V)
{ 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00 }, // U+0057 (W)
{ 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00 }, // U+0058 (X)
{ 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0059 (Y)
{ 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00 }, // U+005A (Z)
{ 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00 }, // U+005B ([)
{ 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00 }, // U+005C (\)
{ 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00 }, // U+005D (])
{ 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00 }, // U+005E (^)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, // U+005F (_)
{ 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0060 (`)
{ 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00 }, // U+0061 (a)
{ 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00 }, // U+0062 (b)
{ 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00 }, // U+0063 (c)
{ 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00 }, // U+0064 (d)
{ 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00 }, // U+0065 (e)
{ 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00 }, // U+0066 (f)
{ 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F }, // U+0067 (g)
{ 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00 }, // U+0068 (h)
{ 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0069 (i)
{ 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E }, // U+006A (j)
{ 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00 }, // U+006B (k)
{ 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+006C (l)
{ 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00 }, // U+006D (m)
{ 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00 }, // U+006E (n)
{ 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00 }, // U+006F (o)
{ 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F }, // U+0070 (p)
{ 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78 }, // U+0071 (q)
{ 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00 }, // U+0072 (r)
{ 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00 }, // U+0073 (s)
{ 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00 }, // U+0074 (t)
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00 }, // U+0075 (u)
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00 }, // U+0076 (v)
{ 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00 }, // U+0077 (w)
{ 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00 }, // U+0078 (x)
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F }, // U+0079 (y)
{ 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00 }, // U+007A (z)
{ 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00 }, // U+007B ({)
{ 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00 }, // U+007C (|)
{ 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00 }, // U+007D (})
{ 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+007E (~)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } // U+007F
};

View File

@@ -0,0 +1,26 @@
#ifndef _KERNEL_LIBKERN_KASAN_H
#define _KERNEL_LIBKERN_KASAN_H
#ifdef KASAN_ENABLED
#include <libkern/c_attrs.h>
#include <libkern/log.h>
#include <libkern/types.h>
#define KASAN_FREED_OBJECT (0xfb)
#define KASAN_KMALLOC_REDZONE (0xfe)
#define KASAN_FREED_PAGE (0xff)
void kasan_init(uintptr_t shadow_base, size_t shadow_size);
bool kasan_is_enabled();
void kasan_enable();
void kasan_disable();
uintptr_t kasan_mem_to_shadow(uintptr_t addr);
int kasan_poison(uintptr_t addr, size_t size, int value);
int kasan_unpoison(uintptr_t addr, size_t size, int value);
int kasan_poison_kmalloc(uintptr_t addr, size_t size);
#endif
#endif // _KERNEL_LIBKERN_KASAN_H

View File

@@ -0,0 +1,35 @@
#ifndef _KERNEL_LIBKERN_KASSERT_H
#define _KERNEL_LIBKERN_KASSERT_H
#include <libkern/c_attrs.h>
#include <libkern/log.h>
#include <libkern/types.h>
#include <platform/generic/system.h>
#include <platform/generic/tasking/trapframe.h>
void assert_handler(const char* cond, const char* func, const char* file, int line) NORETURN;
#define ASSERT(x) \
if (unlikely(!(x))) { \
assert_handler(#x, __func__, __FILE__, __LINE__); \
}
#ifdef DEBUG_KERNEL
#define DEBUG_ASSERT(x) \
if (unlikely(!(x))) { \
assert_handler(#x, __func__, __FILE__, __LINE__); \
}
#else
#undef DEBUG_ASSERT
#define DEBUG_ASSERT(x)
#endif
#define __IMPL_SASSERT_PASTE(a, b) a##b
#define __IMPL_SASSERT_LINE(predicate, line, file) \
typedef char __IMPL_SASSERT_PASTE(assertion_failed_##file##_, line)[2 * !!(predicate)-1]
#define STATIC_ASSERT(predicate, file) __IMPL_SASSERT_LINE(predicate, __LINE__, file)
void kpanic(const char* msg) NORETURN;
void kpanic_tf(const char* err_msg, trapframe_t* tf) NORETURN;
#endif // _KERNEL_LIBKERN_KASSERT_H

View File

@@ -0,0 +1,9 @@
#ifndef _KERNEL_LIBKERN_KERNEL_SELF_TEST_H
#define _KERNEL_LIBKERN_KERNEL_SELF_TEST_H
#include <libkern/types.h>
void kpanic_at_test(char* t_err_msg, uint16_t test_no);
bool kernel_self_test(bool throw_kernel_panic);
#endif // _KERNEL_LIBKERN_KERNEL_SELF_TEST_H

View File

@@ -0,0 +1,45 @@
#ifndef _KERNEL_LIBKERN_LIBKERN_H
#define _KERNEL_LIBKERN_LIBKERN_H
#include <libkern/kassert.h>
#include <libkern/mem.h>
#include <libkern/types.h>
#include <libkern/umem.h>
#define KB (1024)
#define MB (1024 * 1024)
/**
* SHORTCUTS
*/
#define TEST_FLAG(val, flag) (((val) & (flag)) == (flag))
#define TEST_BIT(val, bitnum) (((val) & (1 << bitnum)) == (1 << bitnum))
int stoi(void* str, int len);
void htos(uintptr_t hex, char str[]);
void dtos(uintptr_t dec, char str[]);
void reverse(char s[]);
size_t strlen(const char* s);
int strcmp(const char* a, const char* b);
int strncmp(const char* a, const char* b, size_t num);
size_t ptrarray_len(const void** s);
#ifndef max
#define max(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#endif /* max */
#ifndef min
#define min(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#endif /* min */
#define ROUND_CEIL(a, b) (((a) + ((b)-1)) & ~((b)-1))
#define ROUND_FLOOR(a, b) ((a) & ~((b)-1))
#endif // _KERNEL_LIBKERN_LIBKERN_H

View File

@@ -0,0 +1,69 @@
#ifndef _KERNEL_LIBKERN_LOCK_H
#define _KERNEL_LIBKERN_LOCK_H
#include <libkern/c_attrs.h>
#include <libkern/kassert.h>
#include <libkern/log.h>
#include <libkern/types.h>
// #define DEBUG_SPINLOCK
struct spinlock {
int status;
#ifdef DEBUG_SPINLOCK
#endif // DEBUG_SPINLOCK
};
typedef struct spinlock spinlock_t;
static ALWAYS_INLINE void spinlock_init(spinlock_t* lock)
{
__atomic_store_n(&lock->status, 0, __ATOMIC_RELAXED);
}
static ALWAYS_INLINE void spinlock_acquire(spinlock_t* lock)
{
int counter = 16;
while (__atomic_exchange_n(&lock->status, 1, __ATOMIC_ACQUIRE) == 1) {
extern bool system_can_preempt_kernel();
if (system_can_preempt_kernel()) {
if (!(--counter)) {
extern void resched();
resched();
}
}
}
}
static ALWAYS_INLINE void spinlock_release(spinlock_t* lock)
{
ASSERT(lock->status == 1);
__atomic_store_n(&lock->status, 0, __ATOMIC_RELEASE);
}
static ALWAYS_INLINE bool spinlock_try_acquire(spinlock_t* lock)
{
return !__atomic_exchange_n(&lock->status, 1, __ATOMIC_ACQUIRE);
}
#ifdef DEBUG_SPINLOCK
#define spinlock_acquire(x) \
system_disable_interrupts(); \
extern int vmm_init_setup_finished; \
if (vmm_init_setup_finished) { \
log("acquire lock[%d] %s %s:%d", system_cpu_id(), #x, __FILE__, __LINE__); \
} \
system_enable_interrupts(); \
spinlock_acquire(x);
#define spinlock_release(x) \
system_disable_interrupts(); \
extern int vmm_init_setup_finished; \
if (vmm_init_setup_finished) { \
log("release lock[%d] %s %s:%d ", system_cpu_id(), #x, __FILE__, __LINE__); \
} \
system_enable_interrupts(); \
spinlock_release(x);
#endif
#endif // _KERNEL_LIBKERN_LOCK_H

View File

@@ -0,0 +1,15 @@
#ifndef _KERNEL_LIBKERN_LOG_H
#define _KERNEL_LIBKERN_LOG_H
#include <libkern/printf.h>
#include <libkern/types.h>
struct boot_args;
void logger_setup(struct boot_args* boot_args);
int log(const char* format, ...);
int log_warn(const char* format, ...);
int log_error(const char* format, ...);
int log_not_formatted(const char* format, ...);
#endif // _KERNEL_LIBKERN_LOG_H

View File

@@ -0,0 +1,13 @@
#ifndef _KERNEL_LIBKERN_MASK_H
#define _KERNEL_LIBKERN_MASK_H
#define MASKDEFINE(N, P, S) \
N##_POS = (P), \
N##_SIZE = (S), \
N##_MASK = ((~(~0 << (S))) << (P))
#define TOKEN_PASTE_IMPL(x, y) x##y
#define TOKEN_PASTE(x, y) TOKEN_PASTE_IMPL(x, y)
#define SKIP(x, y) char TOKEN_PASTE(prefix, __LINE__)[y - x - 8]
#endif // _KERNEL_LIBKERN_MASK_H

View File

@@ -0,0 +1,15 @@
#ifndef _KERNEL_LIBKERN_MEM_H
#define _KERNEL_LIBKERN_MEM_H
#include <libkern/types.h>
void* memset(void* dest, uint8_t fll, size_t nbytes);
void* memcpy(void* dest, const void* src, size_t nbytes);
void* memccpy(void* dest, const void* src, uint8_t stop, size_t nbytes);
void* memmove(void* dest, const void* src, size_t nbytes);
int memcmp(const void* src1, const void* src2, size_t nbytes);
char* kmem_bring_to_kernel(const char* data, size_t size);
char** kmem_bring_to_kernel_ptrarr(const char** data, size_t size);
#endif // _KERNEL_LIBKERN_MEM_H

View File

@@ -0,0 +1,11 @@
#ifndef _KERNEL_LIBKERN_PLATFORM_H
#define _KERNEL_LIBKERN_PLATFORM_H
#include <libkern/c_attrs.h>
ALWAYS_INLINE int ctz32(unsigned int val)
{
return __builtin_ctz(val);
}
#endif // _KERNEL_LIBKERN_PLATFORM_H

View File

@@ -0,0 +1,15 @@
#ifndef _KERNEL_LIBKERN_PRINTF_H
#define _KERNEL_LIBKERN_PRINTF_H
#include <libkern/types.h>
typedef int (*printf_putch_callback)(char ch, char* buf_base, size_t* written, void* callback_params);
int vsnprintf(char* s, size_t n, const char* format, va_list arg);
int vsprintf(char* s, const char* format, va_list arg);
int snprintf(char* s, size_t n, const char* format, ...);
int sprintf(char* s, const char* format, ...);
int printf_engine(char* buf, const char* format, printf_putch_callback callback, void* callback_params, va_list arg);
#endif // _KERNEL_LIBKERN_PRINTF_H

View File

@@ -0,0 +1,74 @@
#ifndef _KERNEL_LIBKERN_RWLOCK_H
#define _KERNEL_LIBKERN_RWLOCK_H
#include <libkern/atomic.h>
#include <libkern/c_attrs.h>
#include <libkern/kassert.h>
#include <libkern/lock.h>
#include <libkern/log.h>
#include <libkern/types.h>
struct rwlock {
int readers;
spinlock_t lock;
#ifdef DEBUG_SPINLOCK
#endif // DEBUG_SPINLOCK
};
typedef struct rwlock rwspinlock_t;
static ALWAYS_INLINE void rwspinlock_init(rwspinlock_t* rwlock)
{
}
static ALWAYS_INLINE void rwlock_r_acquire(rwspinlock_t* rwlock)
{
spinlock_acquire(&rwlock->lock);
rwlock->readers++;
spinlock_release(&rwlock->lock);
}
static ALWAYS_INLINE void rwlock_r_release(rwspinlock_t* rwlock)
{
spinlock_acquire(&rwlock->lock);
ASSERT(rwlock->readers >= 0);
rwlock->readers--;
spinlock_release(&rwlock->lock);
}
static ALWAYS_INLINE void rwlock_w_acquire(rwspinlock_t* rwlock)
{
for (;;) {
spinlock_acquire(&rwlock->lock);
if (!rwlock->readers) {
return;
}
spinlock_release(&rwlock->lock);
}
}
static ALWAYS_INLINE void rwlock_w_release(rwspinlock_t* rwlock)
{
spinlock_release(&rwlock->lock);
}
// #define DEBUG_SPINLOCK
#ifdef DEBUG_SPINLOCK
#define rwlock_r_acquire(x) \
log("acquire r rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_r_acquire(x);
#define rwlock_r_release(x) \
log("release r rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_r_release(x);
#define rwlock_w_acquire(x) \
log("acquire w rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_w_acquire(x);
#define rwlock_w_release(x) \
log("release w rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
rwlock_w_release(x);
#endif
#endif // _KERNEL_LIBKERN_RWLOCK_H

View File

@@ -0,0 +1,17 @@
#ifndef _KERNEL_LIBKERN_SCANF_H
#define _KERNEL_LIBKERN_SCANF_H
#include <libkern/types.h>
#define EOF (-1)
typedef int (*scanf_lookupch_callback)(void* callback_params);
typedef int (*scanf_getch_callback)(void* callback_params);
typedef int (*scanf_putch_callback)(char ch, char* buf_base, size_t* written, void* callback_params);
int vsscanf(const char* buf, const char* fmt, va_list arg);
int sscanf(const char* buf, const char* fmt, ...);
int scanf_engine(const char* format, scanf_lookupch_callback lookupch, scanf_getch_callback getch, void* callback_params, va_list arg);
#endif // _KERNEL_LIBKERN_SCANF_H

View File

@@ -0,0 +1,8 @@
#ifndef _KERNEL_LIBKERN_STDARG_H
#define _KERNEL_LIBKERN_STDARG_H
#define va_start(v, l) __builtin_va_start(v, l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v, l) __builtin_va_arg(v, l)
#endif // _KERNEL_LIBKERN_STDARG_H

View File

@@ -0,0 +1,14 @@
#ifndef _KERNEL_LIBKERN_SYSCALL_STRUCTS_H
#define _KERNEL_LIBKERN_SYSCALL_STRUCTS_H
#include <libkern/bits/fcntl.h>
#include <libkern/bits/sys/ioctls.h>
#include <libkern/bits/sys/mman.h>
#include <libkern/bits/sys/select.h>
#include <libkern/bits/sys/socket.h>
#include <libkern/bits/sys/stat.h>
#include <libkern/bits/sys/utsname.h>
#include <libkern/bits/syscalls.h>
#include <libkern/bits/thread.h>
#endif /* _KERNEL_LIBKERN_SYSCALL_STRUCTS_H */

View File

@@ -0,0 +1,65 @@
#ifndef _KERNEL_LIBKERN_TIME_H
#define _KERNEL_LIBKERN_TIME_H
#include <libkern/bits/time.h>
#include <libkern/kassert.h>
#include <libkern/types.h>
static inline void timespec_add_nsec(timespec_t* time, int nsec)
{
ASSERT(-1000000000 < nsec && nsec < 1000000000);
time->tv_nsec += nsec;
if (time->tv_nsec >= 1000000000) {
time->tv_nsec -= 1000000000;
time->tv_sec++;
}
if (time->tv_nsec < 0) {
time->tv_nsec += 1000000000;
time->tv_sec--;
}
}
static inline void timespec_add_usec(timespec_t* time, int usec)
{
int sec = usec / 1000000;
int nsec = (usec % 1000000) * 1000;
timespec_add_nsec(time, nsec);
time->tv_sec += sec;
}
static inline void timespec_add_sec(timespec_t* time, int sec)
{
time->tv_sec += sec;
}
static inline void timespec_add_timespec(timespec_t* lhs, const timespec_t* rhs)
{
timespec_add_nsec(lhs, rhs->tv_nsec);
lhs->tv_sec += rhs->tv_sec;
}
static inline void timespec_add_timeval(timespec_t* lhs, const timeval_t* rhs)
{
timespec_add_usec(lhs, rhs->tv_usec);
lhs->tv_sec += rhs->tv_sec;
}
static inline int timespec_cmp(const timespec_t* a, const timespec_t* b)
{
if (a->tv_sec == b->tv_sec) {
if (a->tv_nsec == b->tv_nsec) {
return 0;
}
if (a->tv_nsec < b->tv_nsec) {
return -1;
}
return 1;
}
if (a->tv_sec < b->tv_sec) {
return -2;
}
return 2;
}
#endif // _KERNEL_LIBKERN_TIME_H

View File

@@ -0,0 +1,139 @@
#ifndef _KERNEL_LIBKERN_TYPES_H
#define _KERNEL_LIBKERN_TYPES_H
#include <libkern/_types/_va_list.h>
#include <libkern/bits/types.h>
#ifndef __stdints_defined
#define __stdints_defined
typedef __int8_t int8_t;
typedef __int16_t int16_t;
typedef __int32_t int32_t;
typedef __int64_t int64_t;
typedef __uint8_t uint8_t;
typedef __uint16_t uint16_t;
typedef __uint32_t uint32_t;
typedef __uint64_t uint64_t;
#endif // __stdints_defined
#ifndef __dev_t_defined
#define __dev_t_defined
typedef __dev_t dev_t;
#endif // __dev_t_defined
#ifndef __uid_t_defined
#define __uid_t_defined
typedef __uid_t uid_t;
#endif // __uid_t_defined
#ifndef __gid_t_defined
#define __gid_t_defined
typedef __gid_t gid_t;
#endif // __gid_t_defined
#ifndef __ino_t_defined
#define __ino_t_defined
typedef __ino_t ino_t;
#endif // __ino_t_defined
#ifndef __ino64_t_defined
#define __ino64_t_defined
typedef __ino64_t ino64_t;
#endif // __ino64_t_defined
#ifndef __mode_t_defined
#define __mode_t_defined
typedef __mode_t mode_t;
#endif // __mode_t_defined
#ifndef __nlink_t_defined
#define __nlink_t_defined
typedef __nlink_t nlink_t;
#endif // __nlink_t_defined
#ifndef __off_t_defined
#define __off_t_defined
typedef __off_t off_t;
#endif // __off_t_defined
#ifndef __off64_t_defined
#define __off64_t_defined
typedef __off64_t off64_t;
#endif // __off64_t_defined
#ifndef __pid_t_defined
#define __pid_t_defined
typedef __pid_t pid_t;
#endif // __pid_t_defined
#ifndef __fsid_t_defined
#define __fsid_t_defined
typedef __fsid_t fsid_t;
#endif // __fsid_t_defined
#ifndef __time_t_defined
#define __time_t_defined
typedef __time_t time_t;
#endif // __time_t_defined
#ifdef __i386__
typedef int32_t intptr_t;
typedef uint32_t uintptr_t;
typedef off_t off_t;
#if defined(__clang__)
typedef unsigned int size_t;
typedef int ssize_t;
#elif defined(__GNUC__) || defined(__GNUG__)
typedef unsigned long size_t;
typedef long ssize_t;
#endif
#define BITS32
#elif __x86_64__
typedef uint64_t size_t;
typedef int64_t ssize_t;
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
typedef off64_t off_t;
#define BITS64
#elif __arm__
typedef unsigned int size_t;
typedef int ssize_t;
typedef int32_t intptr_t;
typedef uint32_t uintptr_t;
typedef off_t off_t;
#define BITS32
#elif __aarch64__
typedef uint64_t size_t;
typedef int64_t ssize_t;
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
typedef off64_t off_t;
#define BITS64
#elif defined(__riscv) && (__riscv_xlen == 64)
typedef uint64_t size_t;
typedef int64_t ssize_t;
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
typedef off64_t off_t;
#define BITS64
#endif
#define __user
#define bool _Bool
#define true (1)
#define false (0)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define NULL ((void*)0)
#define MINORBITS 20
#define MINORMASK ((1U << MINORBITS) - 1)
#define MAJOR(dev) ((unsigned int)((dev) >> MINORBITS))
#define MINOR(dev) ((unsigned int)((dev)&MINORMASK))
#define MKDEV(ma, mi) (((ma) << MINORBITS) | (mi))
#endif // _KERNEL_LIBKERN_TYPES_H

View File

@@ -0,0 +1,77 @@
#ifndef _KERNEL_LIBKERN_UMEM_H
#define _KERNEL_LIBKERN_UMEM_H
#include <libkern/c_attrs.h>
#include <libkern/types.h>
#define USER_STR_MAXLEN (128)
#define USER_PTRARRAY_MAXLEN (128)
#define USER_STRARRAY_MAXLEN (128)
bool umem_validate_str(const char __user* us, size_t maxlen);
bool umem_validate_ptrarray(const void __user** uptrarr, size_t maxlen);
static ALWAYS_INLINE bool umem_validate_strarray(const char __user** s, size_t maxlen) { return umem_validate_ptrarray((const void __user**)s, maxlen); }
void* umem_bring_to_kernel(const void __user* data, size_t size);
char* umem_bring_to_kernel_str(const char __user* data, size_t maxlen);
char* umem_bring_to_kernel_str_with_len(const char __user* data, size_t size);
char** umem_bring_to_kernel_strarray(const char __user** udata, size_t maxlen);
void umem_copy_to_user(void __user* dest, const void* src, size_t length);
void umem_copy_from_user(void* dest, const void __user* src, size_t length);
static ALWAYS_INLINE void umem_get_user_1(uint8_t* ptr, uint8_t* uptr) { *ptr = *uptr; }
static ALWAYS_INLINE void umem_get_user_2(uint16_t* ptr, uint16_t* uptr) { *ptr = *uptr; }
static ALWAYS_INLINE void umem_get_user_4(uint32_t* ptr, uint32_t* uptr) { *ptr = *uptr; }
static ALWAYS_INLINE void umem_get_user_8(uint64_t* ptr, uint64_t* uptr) { *ptr = *uptr; }
static ALWAYS_INLINE void umem_put_user_1(uint8_t* val, uint8_t* uptr) { *uptr = *val; }
static ALWAYS_INLINE void umem_put_user_2(uint16_t* val, uint16_t* uptr) { *uptr = *val; }
static ALWAYS_INLINE void umem_put_user_4(uint32_t* val, uint32_t* uptr) { *uptr = *val; }
static ALWAYS_INLINE void umem_put_user_8(uint64_t* val, uint64_t* uptr) { *uptr = *val; }
#define __umem_put_user_impl_size(size, x, ptr) umem_put_user_##size(x, ptr)
#define umem_put_user(x, ptr) \
({ \
__typeof__(*(ptr)) __user_val; \
__user_val = x; \
switch (sizeof(*(ptr))) { \
case 1: \
__umem_put_user_impl_size(1, (uint8_t*)&__user_val, (uint8_t*)ptr); \
break; \
case 2: \
__umem_put_user_impl_size(2, (uint16_t*)&__user_val, (uint16_t*)ptr); \
break; \
case 4: \
__umem_put_user_impl_size(4, (uint32_t*)&__user_val, (uint32_t*)ptr); \
break; \
case 8: \
__umem_put_user_impl_size(8, (uint64_t*)&__user_val, (uint64_t*)ptr); \
break; \
default: \
umem_copy_to_user(ptr, &__user_val, sizeof(*(ptr))); \
break; \
} \
})
#define __umem_get_user_impl_size(size, x, ptr) umem_get_user_##size(x, ptr)
#define umem_get_user(ptr, uptr) \
({ \
switch (sizeof(*(ptr))) { \
case 1: \
__umem_get_user_impl_size(1, (uint8_t*)ptr, (uint8_t*)uptr); \
break; \
case 2: \
__umem_get_user_impl_size(2, (uint16_t*)ptr, (uint16_t*)uptr); \
break; \
case 4: \
__umem_get_user_impl_size(4, (uint32_t*)ptr, (uint32_t*)uptr); \
break; \
case 8: \
__umem_get_user_impl_size(8, (uint64_t*)ptr, (uint64_t*)uptr); \
break; \
default: \
umem_copy_from_user(ptr, uptr, sizeof(*(ptr))); \
break; \
} \
})
#endif // _KERNEL_LIBKERN_UMEM_H

View File

@@ -0,0 +1,23 @@
#ifndef _KERNEL_LIBKERN_VERSION_H
#define _KERNEL_LIBKERN_VERSION_H
#define OSTYPE "xOS"
#define OSRELEASE "1.0.0-dev"
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_REVISION 0
#define VERSION_VARIANT "0"
#ifdef __i386__
#define MACHINE "x86"
#elif __x86_64__
#define MACHINE "x86-64"
#elif __arm__
#define MACHINE "arm"
#elif __aarch64__
#define MACHINE "arm64"
#elif defined(__riscv) && (__riscv_xlen == 64)
#define MACHINE "riscv64"
#endif
#endif // _KERNEL_LIBKERN_VERSION_H

View File

@@ -0,0 +1,42 @@
#ifndef _KERNEL_MEM_BITS_MMU_H
#define _KERNEL_MEM_BITS_MMU_H
#include <libkern/types.h>
enum MMU_FLAGS {
MMU_FLAG_PERM_WRITE = (1 << 0),
MMU_FLAG_PERM_READ = (1 << 1),
MMU_FLAG_PERM_EXEC = (1 << 2),
MMU_FLAG_UNCACHED = (1 << 3),
MMU_FLAG_NONPRIV = (1 << 4),
MMU_FLAG_INVALID = (1 << 5),
MMU_FLAG_COW = (1 << 6), // TODO: Remove this flag.
MMU_FLAG_HUGE_PAGE = (1 << 7),
MMU_FLAG_DEVICE = MMU_FLAG_PERM_READ | MMU_FLAG_PERM_WRITE | MMU_FLAG_UNCACHED,
};
typedef uint32_t mmu_flags_t;
enum MMU_PF_INFO_FLAGS {
MMU_PF_INFO_ON_NOT_PRESENT = (1 << 0),
MMU_PF_INFO_ON_WRITE = (1 << 1),
MMU_PF_INFO_ON_NONPRIV_ACCESS = (1 << 2),
MMU_PF_INFO_SECURITY_VIOLATION = (1 << 3),
};
typedef uint32_t mmu_pf_info_flags_t;
enum PTABLE_LEVELS {
PTABLE_LV0 = 0,
PTABLE_LV1 = 1,
PTABLE_LV2 = 2,
PTABLE_LV3 = 3,
};
typedef enum PTABLE_LEVELS ptable_lv_t;
enum PTABLE_ENTITY_STATES {
PTABLE_ENTITY_PRESENT,
PTABLE_ENTITY_INVALID,
PTABLE_ENTITY_ALLOC, // For arm32 pspace, other targets never return this state.
};
typedef uint32_t ptable_state_t;
#endif // _KERNEL_MEM_BITS_MMU_H

View File

@@ -0,0 +1,10 @@
#ifndef _KERNEL_MEM_BITS_SWAP_H
#define _KERNEL_MEM_BITS_SWAP_H
enum SWAP_TYPE {
SWAP_TO_DEV,
SWAP_DROP,
SWAP_NOT_ALLOWED,
};
#endif // _KERNEL_MEM_BITS_SWAP_H

View File

@@ -0,0 +1,68 @@
#ifndef _KERNEL_MEM_BITS_VM_H
#define _KERNEL_MEM_BITS_VM_H
#include <libkern/types.h>
#include <mem/bits/mmu.h>
#include <platform/generic/vmm/consts.h>
#include <platform/generic/vmm/mmu.h>
#ifndef VMM_LV2_ENTITY_COUNT
#define VMM_LV2_ENTITY_COUNT (1)
#endif
#ifndef VMM_LV3_ENTITY_COUNT
#define VMM_LV3_ENTITY_COUNT (1)
#endif
#ifndef PTABLE_LV2_VADDR_OFFSET
#define PTABLE_LV2_VADDR_OFFSET (32)
#endif
#ifndef PTABLE_LV3_VADDR_OFFSET
#define PTABLE_LV3_VADDR_OFFSET (32)
#endif
#define PTABLE_ENTITY_COUNT(lv) (ptable_entity_count_at_level[lv])
#define PTABLE_SIZE(lv) (ptable_size_at_level[lv])
#define IS_INDIVIDUAL_PER_DIR(index) (index < PTABLE_TOP_KERNEL_OFFSET || (index == VMM_OFFSET_IN_DIRECTORY(pspace_zone.start)))
typedef struct {
ptable_entity_t entities[1];
} ptable_t;
static const size_t ptable_entity_count_at_level[] = {
[PTABLE_LV0] = VMM_LV0_ENTITY_COUNT,
[PTABLE_LV1] = VMM_LV1_ENTITY_COUNT,
[PTABLE_LV2] = VMM_LV2_ENTITY_COUNT,
[PTABLE_LV3] = VMM_LV3_ENTITY_COUNT,
};
static const size_t ptable_size_at_level[] = {
[PTABLE_LV0] = VMM_LV0_ENTITY_COUNT * sizeof(ptable_entity_t),
[PTABLE_LV1] = VMM_LV1_ENTITY_COUNT * sizeof(ptable_entity_t),
[PTABLE_LV2] = VMM_LV2_ENTITY_COUNT * sizeof(ptable_entity_t),
[PTABLE_LV3] = VMM_LV3_ENTITY_COUNT * sizeof(ptable_entity_t),
};
static const size_t ptable_entity_vaddr_offset_at_level[] = {
[PTABLE_LV0] = PTABLE_LV0_VADDR_OFFSET,
[PTABLE_LV1] = PTABLE_LV1_VADDR_OFFSET,
[PTABLE_LV2] = PTABLE_LV2_VADDR_OFFSET,
[PTABLE_LV3] = PTABLE_LV3_VADDR_OFFSET,
};
#define VM_VADDR_OFFSET_AT_LEVEL(vaddr, lv) ((vaddr >> ptable_entity_vaddr_offset_at_level[lv]) % ptable_entity_count_at_level[lv])
static inline ptable_lv_t lower_level(ptable_lv_t lv)
{
ASSERT(lv != PTABLE_LV0);
return lv - 1;
}
static inline ptable_lv_t upper_level(ptable_lv_t lv)
{
ASSERT(lv != PTABLE_LV_TOP);
return lv + 1;
}
#endif // _KERNEL_MEM_BITS_VM_H

View File

@@ -0,0 +1,18 @@
#ifndef _KERNEL_MEM_BITS_ZONE_H
#define _KERNEL_MEM_BITS_ZONE_H
#include <mem/bits/mmu.h>
enum ZONE_TYPES {
ZONE_TYPE_NULL = 0x0,
ZONE_TYPE_CODE = 0x1,
ZONE_TYPE_DATA = 0x2,
ZONE_TYPE_STACK = 0x4,
ZONE_TYPE_BSS = 0x8,
ZONE_TYPE_DEVICE = 0x10,
ZONE_TYPE_MAPPED = 0x20,
ZONE_TYPE_MAPPED_FILE_PRIVATLY = 0x40,
ZONE_TYPE_MAPPED_FILE_SHAREDLY = 0x80,
};
#endif // _KERNEL_MEM_BITS_ZONE_H

45
kernel/include/mem/boot.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef _KERNEL_MEM_BOOT_H
#define _KERNEL_MEM_BOOT_H
#include <libkern/types.h>
enum MEMORY_LAYOUT_FLAGS {
MEMORY_LAYOUT_FLAG_TERMINATE = (1 << 0),
};
struct memory_layout {
uint64_t base;
uint64_t size;
uint32_t flags;
};
typedef struct memory_layout memory_layout_t;
struct memory_boot_desc {
uint64_t ram_base;
uint64_t ram_size;
memory_layout_t* reserved_areas;
};
typedef struct memory_boot_desc memory_boot_desc_t;
struct fb_boot_desc {
uintptr_t vaddr;
uintptr_t paddr;
size_t width;
size_t height;
size_t pixels_per_row;
};
typedef struct fb_boot_desc fb_boot_desc_t;
struct boot_args {
size_t paddr;
size_t vaddr;
size_t kernel_data_size;
memory_boot_desc_t mem_boot_desc;
fb_boot_desc_t fb_boot_desc;
void* devtree;
char cmd_args[32];
char init_process[32];
};
typedef struct boot_args boot_args_t;
#endif // _KERNEL_MEM_BOOT_H

View File

@@ -0,0 +1,18 @@
#ifndef _KERNEL_MEM_KMALLOC_H
#define _KERNEL_MEM_KMALLOC_H
#include <libkern/types.h>
#include <mem/vmm.h>
#define KMALLOC_SPACE_SIZE (4 * MB)
#define KMALLOC_BLOCK_SIZE 32
void kmalloc_init();
void* kmalloc(size_t size);
void* kmalloc_aligned(size_t size, size_t alignment);
void* kmalloc_page_aligned();
void kfree(void* ptr);
void kfree_aligned(void* ptr);
void* krealloc(void* ptr, size_t size);
#endif // _KERNEL_MEM_KMALLOC_H

View File

@@ -0,0 +1,35 @@
#ifndef _KERNEL_MEM_KMEMZONE_H
#define _KERNEL_MEM_KMEMZONE_H
#include <libkern/types.h>
#include <mem/bits/zone.h>
extern char __text_start[];
extern char __text_end[];
extern char __rodata_start[];
extern char __rodata_end[];
extern char __data_start[];
extern char __data_end[];
extern char __bss_start[];
extern char __bss_end[];
extern char __stack_start[];
extern char __stack_end[];
extern char __end[];
struct __kmemzone {
union {
uintptr_t start;
uint8_t* ptr;
};
size_t len;
};
typedef struct __kmemzone kmemzone_t;
void kmemzone_init();
void kmemzone_init_stage2();
kmemzone_t kmemzone_new(size_t size);
kmemzone_t kmemzone_new_aligned(size_t size, size_t alignment);
int kmemzone_free(kmemzone_t zone);
#endif // _KERNEL_MEM_KMEMZONE_H

View File

@@ -0,0 +1,6 @@
#ifndef _KERNEL_MEM_KSWAPD_H
#define _KERNEL_MEM_KSWAPD_H
void kswapd();
#endif // _KERNEL_MEM_KSWAPD_H

View File

@@ -0,0 +1,34 @@
#ifndef _KERNEL_MEM_MEMZONE_H
#define _KERNEL_MEM_MEMZONE_H
#include <algo/dynamic_array.h>
#include <fs/vfs.h>
#include <libkern/types.h>
#include <mem/bits/zone.h>
struct vm_ops;
struct memzone {
uintptr_t vaddr;
size_t len;
mmu_flags_t mmu_flags;
uint32_t type;
file_t* file;
off_t file_offset;
size_t file_size;
struct vm_ops* ops;
};
typedef struct memzone memzone_t;
struct vm_address_space;
memzone_t* memzone_new(struct vm_address_space* vm_aspace, size_t start, size_t len);
memzone_t* memzone_new_random(struct vm_address_space* vm_aspace, size_t len);
memzone_t* memzone_new_random_backward(struct vm_address_space* vm_aspace, size_t len);
memzone_t* memzone_find(struct vm_address_space* vm_aspace, size_t addr);
memzone_t* memzone_find_no_proc(dynamic_array_t* zones, size_t addr);
memzone_t* memzone_split(struct vm_address_space* vm_aspace, memzone_t* zone, uintptr_t addr);
int memzone_free_no_proc(dynamic_array_t*, memzone_t*);
int memzone_free(struct vm_address_space* vm_aspace, memzone_t*);
int memzone_copy(struct vm_address_space* to_vm_aspace, struct vm_address_space* from_vm_aspace);
#endif // _KERNEL_MEM_MEMZONE_H

40
kernel/include/mem/pmm.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef _KERNEL_MEM_PMM_H
#define _KERNEL_MEM_PMM_H
#include <algo/bitmap.h>
#include <libkern/types.h>
#include <mem/boot.h>
#include <platform/generic/pmm/settings.h>
struct pmm_state {
size_t kernel_va_base;
size_t kernel_data_size; // Kernel + MAT size.
bitmap_t mat;
boot_args_t* boot_args;
size_t ram_size;
size_t ram_offset;
size_t max_blocks;
size_t used_blocks;
};
typedef struct pmm_state pmm_state_t;
void pmm_setup(boot_args_t* boot_args);
void* pmm_alloc(size_t size);
void* pmm_alloc_aligned(size_t size, size_t alignment);
int pmm_free(void* ptr, size_t size);
size_t pmm_get_ram_size();
size_t pmm_get_max_blocks();
size_t pmm_get_used_blocks();
size_t pmm_get_free_blocks();
size_t pmm_get_block_size();
size_t pmm_get_ram_in_kb();
size_t pmm_get_free_space_in_kb();
const pmm_state_t* pmm_get_state();
const boot_args_t* boot_args();
#endif // _KERNEL_MEM_PMM_H

Some files were not shown because too many files have changed in this diff Show More