mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-26 17:12:35 +00:00
feat: Massive OS expansion with IPC, Sound & TTS, Block layer, FAT32/ext2/sysfs, Signals, Syscalls, Modules, Drivers & 50+ LazyBox applets
This commit is contained in:
1 parent
5662be29f5
commit
d680335f05
64 files changed
+2370
-166
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#ifndef _BLOCK_BLOCK_H
|
||||
#define _BLOCK_BLOCK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define BLOCK_SECTOR_SIZE 512
|
||||
#define MAX_BLOCK_DEVS 8
|
||||
|
||||
typedef enum {
|
||||
REQ_READ = 0,
|
||||
REQ_WRITE = 1,
|
||||
REQ_FLUSH = 2
|
||||
} block_req_type_t;
|
||||
|
||||
typedef struct block_request {
|
||||
block_req_type_t type;
|
||||
uint64_t sector;
|
||||
uint32_t sector_count;
|
||||
void* buffer;
|
||||
bool completed;
|
||||
int status;
|
||||
struct block_request* next;
|
||||
} block_request_t;
|
||||
|
||||
typedef struct block_device {
|
||||
char name[32];
|
||||
uint32_t device_id;
|
||||
uint64_t total_sectors;
|
||||
uint32_t sector_size;
|
||||
bool read_only;
|
||||
int (*read_sectors)(struct block_device* dev, uint64_t sector, uint32_t count, void* buffer);
|
||||
int (*write_sectors)(struct block_device* dev, uint64_t sector, uint32_t count, const void* buffer);
|
||||
int (*flush)(struct block_device* dev);
|
||||
block_request_t* queue_head;
|
||||
block_request_t* queue_tail;
|
||||
} block_device_t;
|
||||
|
||||
void block_init(void);
|
||||
int block_register_device(block_device_t* dev);
|
||||
block_device_t* block_get_device(const char* name);
|
||||
int block_submit_bio(const char* dev_name, block_req_type_t type, uint64_t sector, uint32_t count, void* buffer);
|
||||
size_t block_get_device_count(void);
|
||||
block_device_t* block_get_device_by_index(size_t index);
|
||||
|
||||
#endif // _BLOCK_BLOCK_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef _BLOCK_ELEVATOR_H
|
||||
#define _BLOCK_ELEVATOR_H
|
||||
|
||||
#include <block/block.h>
|
||||
|
||||
typedef enum {
|
||||
ELEVATOR_NOOP = 0,
|
||||
ELEVATOR_DEADLINE,
|
||||
ELEVATOR_CFQ
|
||||
} elevator_type_t;
|
||||
|
||||
typedef struct elevator {
|
||||
elevator_type_t type;
|
||||
const char* name;
|
||||
void (*queue_request)(block_device_t* dev, block_request_t* req);
|
||||
block_request_t* (*dispatch_request)(block_device_t* dev);
|
||||
} elevator_t;
|
||||
|
||||
void elevator_init(void);
|
||||
elevator_t* elevator_get_active(void);
|
||||
void elevator_set_scheduler(elevator_type_t type);
|
||||
|
||||
#endif // _BLOCK_ELEVATOR_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef _DRIVERS_ACPI_H
|
||||
#define _DRIVERS_ACPI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void acpi_init(void);
|
||||
void acpi_poweroff(void);
|
||||
void acpi_reboot(void);
|
||||
|
||||
#endif // _DRIVERS_ACPI_H
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef _DRIVERS_FB_H
|
||||
#define _DRIVERS_FB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t* address;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t pitch;
|
||||
uint8_t bpp;
|
||||
bool active;
|
||||
} fb_info_t;
|
||||
|
||||
void fb_init(void);
|
||||
const fb_info_t* fb_get_info(void);
|
||||
void fb_put_pixel(uint32_t x, uint32_t y, uint32_t color);
|
||||
void fb_draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color);
|
||||
void fb_clear(uint32_t color);
|
||||
void fb_draw_char(uint32_t x, uint32_t y, char c, uint32_t fg, uint32_t bg);
|
||||
void fb_draw_string(uint32_t x, uint32_t y, const char* str, uint32_t fg, uint32_t bg);
|
||||
|
||||
#endif // _DRIVERS_FB_H
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef _DRIVERS_MOUSE_H
|
||||
#define _DRIVERS_MOUSE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
bool left_btn;
|
||||
bool right_btn;
|
||||
bool middle_btn;
|
||||
} mouse_state_t;
|
||||
|
||||
void mouse_init(void);
|
||||
const mouse_state_t* mouse_get_state(void);
|
||||
void mouse_set_bounds(int max_x, int max_y);
|
||||
|
||||
#endif // _DRIVERS_MOUSE_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef _DRIVERS_RTC_H
|
||||
#define _DRIVERS_RTC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
uint32_t year;
|
||||
} rtc_time_t;
|
||||
|
||||
void rtc_init(void);
|
||||
void rtc_get_time(rtc_time_t* time);
|
||||
void rtc_format_string(char* buf, size_t max_len);
|
||||
|
||||
#endif // _DRIVERS_RTC_H
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef _DRIVERS_USB_H
|
||||
#define _DRIVERS_USB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define USB_MAX_DEVICES 8
|
||||
|
||||
typedef enum {
|
||||
USB_SPEED_LOW = 0,
|
||||
USB_SPEED_FULL = 1,
|
||||
USB_SPEED_HIGH = 2
|
||||
} usb_speed_t;
|
||||
|
||||
typedef struct usb_device {
|
||||
uint8_t address;
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint8_t class_code;
|
||||
char product_name[32];
|
||||
usb_speed_t speed;
|
||||
bool connected;
|
||||
} usb_device_t;
|
||||
|
||||
void usb_init(void);
|
||||
size_t usb_get_device_count(void);
|
||||
const usb_device_t* usb_get_device(size_t index);
|
||||
|
||||
#endif // _DRIVERS_USB_H
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef _FS_EXT2_H
|
||||
#define _FS_EXT2_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <fs/vfs.h>
|
||||
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
|
||||
/* ext2 Superblock Definition */
|
||||
typedef struct {
|
||||
uint32_t s_inodes_count;
|
||||
uint32_t s_blocks_count;
|
||||
uint32_t s_r_blocks_count;
|
||||
uint32_t s_free_blocks_count;
|
||||
uint32_t s_free_inodes_count;
|
||||
uint32_t s_first_data_block;
|
||||
uint32_t s_log_block_size;
|
||||
uint32_t s_log_frag_size;
|
||||
uint32_t s_blocks_per_group;
|
||||
uint32_t s_frags_per_group;
|
||||
uint32_t s_inodes_per_group;
|
||||
uint32_t s_mtime;
|
||||
uint32_t s_wtime;
|
||||
uint16_t s_mnt_count;
|
||||
uint16_t s_max_mnt_count;
|
||||
uint16_t s_magic;
|
||||
uint16_t s_state;
|
||||
uint16_t s_errors;
|
||||
uint16_t s_minor_rev_level;
|
||||
uint32_t s_lastcheck;
|
||||
uint32_t s_checkinterval;
|
||||
uint32_t s_creator_os;
|
||||
uint32_t s_rev_level;
|
||||
uint16_t s_def_resuid;
|
||||
uint16_t s_def_resgid;
|
||||
} __attribute__((packed)) ext2_superblock_t;
|
||||
|
||||
/* ext2 Inode Structure */
|
||||
typedef struct {
|
||||
uint16_t i_mode;
|
||||
uint16_t i_uid;
|
||||
uint32_t i_size;
|
||||
uint32_t i_atime;
|
||||
uint32_t i_ctime;
|
||||
uint32_t i_mtime;
|
||||
uint32_t i_dtime;
|
||||
uint16_t i_gid;
|
||||
uint16_t i_links_count;
|
||||
uint32_t i_blocks;
|
||||
uint32_t i_flags;
|
||||
uint32_t i_osd1;
|
||||
uint32_t i_block[15];
|
||||
uint32_t i_generation;
|
||||
uint32_t i_file_acl;
|
||||
uint32_t i_dir_acl;
|
||||
uint32_t i_faddr;
|
||||
uint8_t i_osd2[12];
|
||||
} __attribute__((packed)) ext2_inode_t;
|
||||
|
||||
void ext2_init(void);
|
||||
vfs_node_t* ext2_mount(const char* block_device_name);
|
||||
|
||||
#endif // _FS_EXT2_H
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef _FS_FAT32_H
|
||||
#define _FS_FAT32_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <fs/vfs.h>
|
||||
|
||||
/* FAT32 Extended BIOS Parameter Block */
|
||||
typedef struct {
|
||||
uint8_t jmp[3];
|
||||
char oem[8];
|
||||
uint16_t bytes_per_sector;
|
||||
uint8_t sectors_per_cluster;
|
||||
uint16_t reserved_sectors;
|
||||
uint8_t fat_count;
|
||||
uint16_t root_entries;
|
||||
uint16_t total_sectors_short;
|
||||
uint8_t media_type;
|
||||
uint16_t table_size_16;
|
||||
uint16_t sectors_per_track;
|
||||
uint16_t head_side_count;
|
||||
uint32_t hidden_sectors;
|
||||
uint32_t total_sectors_32;
|
||||
|
||||
// FAT32 Extended
|
||||
uint32_t table_size_32;
|
||||
uint16_t extended_flags;
|
||||
uint16_t fat_version;
|
||||
uint32_t root_cluster;
|
||||
uint16_t fat_info;
|
||||
uint16_t backup_boot_sector;
|
||||
uint8_t reserved[12];
|
||||
uint8_t drive_number;
|
||||
uint8_t reserved1;
|
||||
uint8_t boot_signature;
|
||||
uint32_t volume_id;
|
||||
char volume_label[11];
|
||||
char fat_type_label[8];
|
||||
} __attribute__((packed)) fat32_bpb_t;
|
||||
|
||||
typedef struct {
|
||||
char name[11];
|
||||
uint8_t attr;
|
||||
uint8_t nt_reserved;
|
||||
uint8_t creation_time_tenth;
|
||||
uint16_t creation_time;
|
||||
uint16_t creation_date;
|
||||
uint16_t last_access_date;
|
||||
uint16_t cluster_high;
|
||||
uint16_t write_time;
|
||||
uint16_t write_date;
|
||||
uint16_t cluster_low;
|
||||
uint32_t file_size;
|
||||
} __attribute__((packed)) fat32_dirent_t;
|
||||
|
||||
void fat32_init(void);
|
||||
vfs_node_t* fat32_mount(const char* block_device_name);
|
||||
|
||||
#endif // _FS_FAT32_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef _FS_SYSFS_H
|
||||
#define _FS_SYSFS_H
|
||||
|
||||
#include <fs/vfs.h>
|
||||
|
||||
void sysfs_init(void);
|
||||
vfs_node_t* sysfs_create_entry(const char* path, const char* value);
|
||||
|
||||
#endif // _FS_SYSFS_H
|
||||
@@ -72,6 +72,7 @@ typedef struct {
|
||||
void vfs_init(void);
|
||||
vfs_node_t* vfs_namei(const char* path);
|
||||
int vfs_open(const char* path, uint32_t flags);
|
||||
int vfs_open_node(vfs_node_t* node, uint32_t flags);
|
||||
ssize_t vfs_read(int fd, void* buffer, size_t size);
|
||||
ssize_t vfs_write(int fd, const void* buffer, size_t size);
|
||||
off_t vfs_lseek(int fd, off_t offset, int whence);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef _IPC_IPC_H
|
||||
#define _IPC_IPC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define IPC_CREAT 01000
|
||||
#define IPC_EXCL 02000
|
||||
#define IPC_NOWAIT 04000
|
||||
#define IPC_RMID 0
|
||||
#define IPC_SET 1
|
||||
#define IPC_STAT 2
|
||||
|
||||
typedef int32_t key_t;
|
||||
|
||||
void ipc_init(void);
|
||||
|
||||
#endif // _IPC_IPC_H
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef _IPC_MSG_H
|
||||
#define _IPC_MSG_H
|
||||
|
||||
#include <ipc/ipc.h>
|
||||
#include <kernel/types.h>
|
||||
|
||||
#define MAX_MSG_QUEUES 16
|
||||
#define MAX_MSG_PAYLOAD 256
|
||||
#define MAX_MSGS_PER_QUEUE 16
|
||||
|
||||
typedef struct msgbuf {
|
||||
long mtype;
|
||||
char mtext[MAX_MSG_PAYLOAD];
|
||||
} msgbuf_t;
|
||||
|
||||
typedef struct msg_entry {
|
||||
long mtype;
|
||||
size_t size;
|
||||
uint8_t data[MAX_MSG_PAYLOAD];
|
||||
struct msg_entry* next;
|
||||
} msg_entry_t;
|
||||
|
||||
typedef struct msqid_ds {
|
||||
int msqid;
|
||||
key_t key;
|
||||
uint32_t msg_qnum;
|
||||
uint32_t msg_qbytes;
|
||||
msg_entry_t* head;
|
||||
msg_entry_t* tail;
|
||||
bool in_use;
|
||||
} msqid_ds_t;
|
||||
|
||||
int msgget(key_t key, int msgflg);
|
||||
int msgsnd(int msqid, const void* msgp, size_t msgsz, int msgflg);
|
||||
ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg);
|
||||
int msgctl(int msqid, int cmd, struct msqid_ds* buf);
|
||||
|
||||
#endif // _IPC_MSG_H
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _IPC_PIPE_H
|
||||
#define _IPC_PIPE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <fs/vfs.h>
|
||||
|
||||
#define PIPE_BUF_SIZE 4096
|
||||
|
||||
typedef struct pipe {
|
||||
uint8_t buffer[PIPE_BUF_SIZE];
|
||||
uint32_t head;
|
||||
uint32_t tail;
|
||||
uint32_t count;
|
||||
bool read_open;
|
||||
bool write_open;
|
||||
vfs_node_t* read_node;
|
||||
vfs_node_t* write_node;
|
||||
} pipe_t;
|
||||
|
||||
int pipe_create(int pipefd[2]);
|
||||
ssize_t pipe_read(pipe_t* p, void* buf, size_t count);
|
||||
ssize_t pipe_write(pipe_t* p, const void* buf, size_t count);
|
||||
void pipe_close_read(pipe_t* p);
|
||||
void pipe_close_write(pipe_t* p);
|
||||
|
||||
#endif // _IPC_PIPE_H
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef _IPC_SEM_H
|
||||
#define _IPC_SEM_H
|
||||
|
||||
#include <ipc/ipc.h>
|
||||
|
||||
#define MAX_SEM_SETS 16
|
||||
#define MAX_SEMS_PER_SET 16
|
||||
|
||||
struct sembuf {
|
||||
unsigned short sem_num;
|
||||
short sem_op;
|
||||
short sem_flg;
|
||||
};
|
||||
|
||||
typedef struct semid_ds {
|
||||
int semid;
|
||||
key_t key;
|
||||
uint32_t nsems;
|
||||
int values[MAX_SEMS_PER_SET];
|
||||
bool in_use;
|
||||
} semid_ds_t;
|
||||
|
||||
int semget(key_t key, int nsems, int semflg);
|
||||
int semop(int semid, struct sembuf* sops, size_t nsops);
|
||||
int semctl(int semid, int semnum, int cmd, ...);
|
||||
|
||||
#endif // _IPC_SEM_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef _IPC_SHM_H
|
||||
#define _IPC_SHM_H
|
||||
|
||||
#include <ipc/ipc.h>
|
||||
|
||||
#define MAX_SHM_SEGS 16
|
||||
#define SHM_MAX_SIZE 65536
|
||||
|
||||
typedef struct shmid_ds {
|
||||
int shmid;
|
||||
key_t key;
|
||||
size_t size;
|
||||
void* addr;
|
||||
uint32_t nattch;
|
||||
bool in_use;
|
||||
} shmid_ds_t;
|
||||
|
||||
int shmget(key_t key, size_t size, int shmflg);
|
||||
void* shmat(int shmid, const void* shmaddr, int shmflg);
|
||||
int shmdt(const void* shmaddr);
|
||||
int shmctl(int shmid, int cmd, struct shmid_ds* buf);
|
||||
|
||||
#endif // _IPC_SHM_H
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _KERNEL_MODULE_H
|
||||
#define _KERNEL_MODULE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MODULE_NAME_LEN 32
|
||||
#define MAX_MODULES 16
|
||||
|
||||
typedef struct kernel_module {
|
||||
char name[MODULE_NAME_LEN];
|
||||
char description[64];
|
||||
char author[32];
|
||||
char version[16];
|
||||
size_t size;
|
||||
int (*init)(void);
|
||||
void (*cleanup)(void);
|
||||
bool loaded;
|
||||
} kernel_module_t;
|
||||
|
||||
void module_init_subsystem(void);
|
||||
int module_load(const char* name, int (*init_fn)(void), void (*cleanup_fn)(void), size_t size);
|
||||
int module_unload(const char* name);
|
||||
size_t module_get_count(void);
|
||||
const kernel_module_t* module_get(size_t index);
|
||||
|
||||
#endif // _KERNEL_MODULE_H
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef _KERNEL_SIGNAL_H
|
||||
#define _KERNEL_SIGNAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGABRT 6
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGSEGV 11
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGCHLD 17
|
||||
#define SIGCONT 18
|
||||
#define SIGSTOP 19
|
||||
#define SIGTSTP 20
|
||||
#define SIGUSR1 10
|
||||
#define SIGUSR2 12
|
||||
|
||||
#define NSIG 32
|
||||
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
#define SIG_DFL ((sighandler_t)0)
|
||||
#define SIG_IGN ((sighandler_t)1)
|
||||
#define SIG_ERR ((sighandler_t)-1)
|
||||
|
||||
typedef uint32_t sigset_t;
|
||||
|
||||
struct sigaction {
|
||||
sighandler_t sa_handler;
|
||||
sigset_t sa_mask;
|
||||
int sa_flags;
|
||||
};
|
||||
|
||||
void signal_init(void);
|
||||
sighandler_t signal_set_handler(int signum, sighandler_t handler);
|
||||
int signal_send(uint32_t pid, int signum);
|
||||
void signal_deliver_pending(void);
|
||||
|
||||
#endif // _KERNEL_SIGNAL_H
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef _KERNEL_SYSCALL_H
|
||||
#define _KERNEL_SYSCALL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* Linux x86_64 Standard Syscall Numbers */
|
||||
#define SYS_read 0
|
||||
#define SYS_write 1
|
||||
#define SYS_open 2
|
||||
#define SYS_close 3
|
||||
#define SYS_stat 4
|
||||
#define SYS_fstat 5
|
||||
#define SYS_lseek 8
|
||||
#define SYS_mmap 9
|
||||
#define SYS_munmap 11
|
||||
#define SYS_brk 12
|
||||
#define SYS_rt_sigaction 13
|
||||
#define SYS_pipe 22
|
||||
#define SYS_getpid 39
|
||||
#define SYS_fork 57
|
||||
#define SYS_execve 59
|
||||
#define SYS_exit 60
|
||||
#define SYS_kill 62
|
||||
#define SYS_mkdir 83
|
||||
#define SYS_rmdir 84
|
||||
#define SYS_unlink 87
|
||||
#define SYS_time 201
|
||||
#define SYS_reboot 169
|
||||
|
||||
typedef int64_t (*syscall_fn_t)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
void syscall_init(void);
|
||||
int64_t syscall_handler(uint64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6);
|
||||
|
||||
#endif // _KERNEL_SYSCALL_H
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef _KERNEL_TIMER_H
|
||||
#define _KERNEL_TIMER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*timer_callback_t)(uint64_t data);
|
||||
|
||||
typedef struct timer_list {
|
||||
uint64_t expires;
|
||||
timer_callback_t function;
|
||||
uint64_t data;
|
||||
bool active;
|
||||
struct timer_list* next;
|
||||
} timer_list_t;
|
||||
|
||||
void timer_wheel_init(void);
|
||||
void timer_add(timer_list_t* timer);
|
||||
void timer_mod(timer_list_t* timer, uint64_t expires);
|
||||
void timer_del(timer_list_t* timer);
|
||||
void timer_tick(void);
|
||||
|
||||
#endif // _KERNEL_TIMER_H
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef _KERNEL_WORKQUEUE_H
|
||||
#define _KERNEL_WORKQUEUE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*work_func_t)(void* data);
|
||||
|
||||
typedef struct work_struct {
|
||||
work_func_t func;
|
||||
void* data;
|
||||
bool pending;
|
||||
struct work_struct* next;
|
||||
} work_struct_t;
|
||||
|
||||
void workqueue_init(void);
|
||||
int schedule_work(work_struct_t* work);
|
||||
void workqueue_run_pending(void);
|
||||
|
||||
#endif // _KERNEL_WORKQUEUE_H
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _NET_DHCP_H
|
||||
#define _NET_DHCP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void dhcp_init(void);
|
||||
int dhcp_request_lease(void);
|
||||
|
||||
#endif // _NET_DHCP_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef _NET_DNS_H
|
||||
#define _NET_DNS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void dns_init(void);
|
||||
uint32_t dns_resolve(const char* hostname);
|
||||
|
||||
#endif // _NET_DNS_H
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef _NET_SOCKET_H
|
||||
#define _NET_SOCKET_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel/types.h>
|
||||
|
||||
#define AF_INET 2
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
#define SOCK_RAW 3
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_ICMP 1
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
typedef struct sockaddr_in {
|
||||
uint16_t sin_family;
|
||||
uint16_t sin_port;
|
||||
uint32_t sin_addr;
|
||||
char sin_zero[8];
|
||||
} sockaddr_in_t;
|
||||
|
||||
typedef struct socket {
|
||||
int domain;
|
||||
int type;
|
||||
int protocol;
|
||||
uint32_t local_ip;
|
||||
uint16_t local_port;
|
||||
uint32_t remote_ip;
|
||||
uint16_t remote_port;
|
||||
int state;
|
||||
bool in_use;
|
||||
} socket_t;
|
||||
|
||||
void socket_subsystem_init(void);
|
||||
int sys_socket(int domain, int type, int protocol);
|
||||
int sys_bind(int sockfd, const struct sockaddr_in* addr, size_t addrlen);
|
||||
int sys_connect(int sockfd, const struct sockaddr_in* addr, size_t addrlen);
|
||||
ssize_t sys_send(int sockfd, const void* buf, size_t len, int flags);
|
||||
ssize_t sys_recv(int sockfd, void* buf, size_t len, int flags);
|
||||
int sys_close_socket(int sockfd);
|
||||
|
||||
#endif // _NET_SOCKET_H
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef _NET_TCP_H
|
||||
#define _NET_TCP_H
|
||||
|
||||
#include <net/net.h>
|
||||
|
||||
#define TCP_STATE_CLOSED 0
|
||||
#define TCP_STATE_LISTEN 1
|
||||
#define TCP_STATE_SYN_SENT 2
|
||||
#define TCP_STATE_SYN_RCVD 3
|
||||
#define TCP_STATE_ESTABLISHED 4
|
||||
#define TCP_STATE_FIN_WAIT1 5
|
||||
#define TCP_STATE_FIN_WAIT2 6
|
||||
#define TCP_STATE_CLOSE_WAIT 7
|
||||
#define TCP_STATE_CLOSING 8
|
||||
#define TCP_STATE_LAST_ACK 9
|
||||
#define TCP_STATE_TIME_WAIT 10
|
||||
|
||||
typedef struct {
|
||||
uint16_t src_port;
|
||||
uint16_t dst_port;
|
||||
uint32_t seq_num;
|
||||
uint32_t ack_num;
|
||||
uint8_t data_offset_reserved;
|
||||
uint8_t flags;
|
||||
uint16_t window_size;
|
||||
uint16_t checksum;
|
||||
uint16_t urgent_pointer;
|
||||
} __attribute__((packed)) tcp_header_t;
|
||||
|
||||
void tcp_init(void);
|
||||
void tcp_receive(const uint8_t* packet, uint16_t length, uint32_t src_ip);
|
||||
|
||||
#endif // _NET_TCP_H
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _NET_UDP_H
|
||||
#define _NET_UDP_H
|
||||
|
||||
#include <net/net.h>
|
||||
|
||||
void udp_init(void);
|
||||
void udp_receive(const uint8_t* packet, uint16_t length, uint32_t src_ip);
|
||||
void udp_send(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port, const void* data, uint16_t len);
|
||||
|
||||
#endif // _NET_UDP_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef _SOUND_AC97_H
|
||||
#define _SOUND_AC97_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define AC97_PCI_VENDOR 0x8086
|
||||
#define AC97_PCI_DEVICE 0x2415 // Intel 82801AA AC'97 Audio
|
||||
|
||||
bool ac97_init(void);
|
||||
void ac97_set_master_volume(uint8_t left, uint8_t right);
|
||||
int ac97_play_pcm(const void* samples, size_t length);
|
||||
|
||||
#endif // _SOUND_AC97_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef _SOUND_PCM_H
|
||||
#define _SOUND_PCM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define PCM_BUFFER_SIZE 8192
|
||||
|
||||
typedef struct {
|
||||
uint32_t sample_rate;
|
||||
uint8_t channels;
|
||||
uint8_t bits;
|
||||
uint8_t buffer[PCM_BUFFER_SIZE];
|
||||
size_t length;
|
||||
} pcm_stream_t;
|
||||
|
||||
void pcm_init(void);
|
||||
int pcm_write(const void* data, size_t len);
|
||||
|
||||
#endif // _SOUND_PCM_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef _SOUND_SOUND_H
|
||||
#define _SOUND_SOUND_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct sound_device {
|
||||
char name[32];
|
||||
uint32_t sample_rate;
|
||||
uint8_t channels;
|
||||
uint8_t bits_per_sample;
|
||||
int volume;
|
||||
int (*play_sample)(const void* buffer, size_t length);
|
||||
int (*set_volume)(int volume);
|
||||
bool active;
|
||||
} sound_device_t;
|
||||
|
||||
void sound_init(void);
|
||||
int sound_register_device(sound_device_t* dev);
|
||||
sound_device_t* sound_get_default_device(void);
|
||||
|
||||
#endif // _SOUND_SOUND_H
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef _SOUND_TTS_H
|
||||
#define _SOUND_TTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
char phoneme[4];
|
||||
uint32_t freq_f1;
|
||||
uint32_t freq_f2;
|
||||
uint32_t duration_ms;
|
||||
} tts_phoneme_t;
|
||||
|
||||
void tts_init(void);
|
||||
void tts_speak(const char* text);
|
||||
void tts_speak_letter(char c);
|
||||
|
||||
#endif // _SOUND_TTS_H
|
||||
Reference in new issue
Block a user