feat(core): implement Linux-grade architecture (printk with loglevels, list.h, errno.h, procfs, devfs, slab cache, CMOS RTC & 16550A UART serial)
This commit is contained in:
1 parent
2bbeb3f345
commit
1832e7ecff
19 files changed
+805
-6
No files matched your search
@@ -0,0 +1,9 @@
|
||||
#ifndef AIRLYS_DEVFS_H
|
||||
#define AIRLYS_DEVFS_H
|
||||
|
||||
#include <airlys/vfs.h>
|
||||
|
||||
/* Initialize /dev character devices (null, zero, urandom, console) */
|
||||
void devfs_init(void);
|
||||
|
||||
#endif /* AIRLYS_DEVFS_H */
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef AIRLYS_ERRNO_H
|
||||
#define AIRLYS_ERRNO_H
|
||||
|
||||
/* Canonical Linux POSIX Error Numbers (include/uapi/asm-generic/errno-base.h) */
|
||||
#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 /* Argument 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 */
|
||||
|
||||
#endif /* AIRLYS_ERRNO_H */
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef AIRLYS_LIST_H
|
||||
#define AIRLYS_LIST_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
|
||||
/*
|
||||
* Canonical Intrusive Circular Doubly Linked List
|
||||
* Adopted from the Linux Kernel Architecture (include/linux/list.h)
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list) {
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
static inline void __list_add(struct list_head *new_node,
|
||||
struct list_head *prev,
|
||||
struct list_head *next) {
|
||||
next->prev = new_node;
|
||||
new_node->next = next;
|
||||
new_node->prev = prev;
|
||||
prev->next = new_node;
|
||||
}
|
||||
|
||||
static inline void list_add(struct list_head *new_node, struct list_head *head) {
|
||||
__list_add(new_node, head, head->next);
|
||||
}
|
||||
|
||||
static inline void list_add_tail(struct list_head *new_node, struct list_head *head) {
|
||||
__list_add(new_node, head->prev, head);
|
||||
}
|
||||
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next) {
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
static inline void list_del(struct list_head *entry) {
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = NULL;
|
||||
entry->prev = NULL;
|
||||
}
|
||||
|
||||
static inline bool list_empty(const struct list_head *head) {
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
#endif /* AIRLYS_LIST_H */
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef AIRLYS_PRINTK_H
|
||||
#define AIRLYS_PRINTK_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
|
||||
/* Linux Kernel Log Levels (include/linux/kern_levels.h) */
|
||||
#define KERN_SOH "\001"
|
||||
#define KERN_EMERG KERN_SOH "0" /* system is unusable */
|
||||
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
|
||||
#define KERN_CRIT KERN_SOH "2" /* critical conditions */
|
||||
#define KERN_ERR KERN_SOH "3" /* error conditions */
|
||||
#define KERN_WARNING KERN_SOH "4" /* warning conditions */
|
||||
#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
|
||||
#define KERN_INFO KERN_SOH "6" /* informational */
|
||||
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
|
||||
|
||||
#define PRINTK_BUF_SIZE 16384 /* 16 KB Ring Buffer for dmesg */
|
||||
|
||||
/* Standard Linux formatted kernel logger */
|
||||
int printk(const char* fmt, ...);
|
||||
|
||||
/* Access kernel ring-buffer (used by dmesg) */
|
||||
void printk_dump_dmesg(void);
|
||||
|
||||
#endif /* AIRLYS_PRINTK_H */
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef AIRLYS_PROCFS_H
|
||||
#define AIRLYS_PROCFS_H
|
||||
|
||||
#include <airlys/vfs.h>
|
||||
|
||||
/* Mount Linux-style /proc pseudo-filesystem into VFS */
|
||||
void procfs_init(void);
|
||||
|
||||
#endif /* AIRLYS_PROCFS_H */
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef AIRLYS_RTC_H
|
||||
#define AIRLYS_RTC_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
uint16_t year;
|
||||
} rtc_time_t;
|
||||
|
||||
/* Initialize CMOS RTC Driver */
|
||||
void rtc_init(void);
|
||||
|
||||
/* Read current hardware real-time clock from CMOS */
|
||||
rtc_time_t rtc_get_time(void);
|
||||
|
||||
#endif /* AIRLYS_RTC_H */
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef AIRLYS_SERIAL_H
|
||||
#define AIRLYS_SERIAL_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
|
||||
#define COM1_PORT 0x3F8
|
||||
|
||||
/* Initialize 16550A UART Serial Port (COM1) */
|
||||
void serial_init(void);
|
||||
|
||||
/* Write a single character to serial port */
|
||||
void serial_putchar(char c);
|
||||
|
||||
/* Write a string to serial port */
|
||||
void serial_puts(const char* str);
|
||||
|
||||
#endif /* AIRLYS_SERIAL_H */
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef AIRLYS_SLAB_H
|
||||
#define AIRLYS_SLAB_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
|
||||
#define SLAB_NAME_MAX 32
|
||||
|
||||
typedef struct kmem_cache {
|
||||
char name[SLAB_NAME_MAX];
|
||||
size_t obj_size;
|
||||
size_t align;
|
||||
size_t total_alloc;
|
||||
size_t free_count;
|
||||
void* free_list;
|
||||
} kmem_cache_t;
|
||||
|
||||
/* Initialize Slab subsystem */
|
||||
void slab_init(void);
|
||||
|
||||
/* Create named object cache (e.g. "task_cache", "dentry_cache") */
|
||||
kmem_cache_t* kmem_cache_create(const char* name, size_t size, size_t align);
|
||||
|
||||
/* Allocate an object from the cache */
|
||||
void* kmem_cache_alloc(kmem_cache_t* cache);
|
||||
|
||||
/* Free an object back to the cache */
|
||||
void kmem_cache_free(kmem_cache_t* cache, void* obj);
|
||||
|
||||
#endif /* AIRLYS_SLAB_H */
|
||||
@@ -9,5 +9,7 @@ int kstrncmp(const char* s1, const char* s2, size_t n);
|
||||
void kstrncpy(char* dest, const char* src, size_t n);
|
||||
void* kmemcpy(void* dest, const void* src, size_t n);
|
||||
void* kmemset(void* s, int c, size_t n);
|
||||
void* memcpy(void* dest, const void* src, size_t n);
|
||||
void* memset(void* s, int c, size_t n);
|
||||
|
||||
#endif /* AIRLYS_STRING_H */
|
||||
Reference in new issue
Block a user