Red Bear OS — microkernel OS in Rust, based on Redox

Derivative of Redox OS (https://www.redox-os.org) adding:
- AMD GPU driver (amdgpu) via LinuxKPI compat layer
- ext4 filesystem support (ext4d scheme daemon)
- ACPI fixes for AMD bare metal (x2APIC, DMAR, IVRS, MCFG)
- Custom branding (hostname, os-release, boot identity)

Build system is full upstream Redox with RBOS overlay in local/.
Patches for kernel, base, and relibc are symlinked from local/patches/
and protected from make clean/distclean. Custom recipes live in
local/recipes/ with symlinks into the recipes/ search path.

Build:  make all CONFIG_NAME=redbear-full
Sync:   ./local/scripts/sync-upstream.sh
This commit is contained in:
2026-04-12 19:05:00 +01:00
commit 50b731f1b7
3392 changed files with 98327 additions and 0 deletions
@@ -0,0 +1,77 @@
#ifndef _ASM_IO_H
#define _ASM_IO_H
#include <linux/types.h>
#include <linux/compiler.h>
static inline unsigned char inb(unsigned short port)
{
unsigned char val;
__asm__ __volatile__("inb %1, %0" : "=a"(val) : "Nd"(port));
return val;
}
static inline unsigned short inw(unsigned short port)
{
unsigned short val;
__asm__ __volatile__("inw %1, %0" : "=a"(val) : "Nd"(port));
return val;
}
static inline unsigned int inl(unsigned short port)
{
unsigned int val;
__asm__ __volatile__("inl %1, %0" : "=a"(val) : "Nd"(port));
return val;
}
static inline void outb(unsigned char val, unsigned short port)
{
__asm__ __volatile__("outb %0, %1" : : "a"(val), "Nd"(port));
}
static inline void outw(unsigned short val, unsigned short port)
{
__asm__ __volatile__("outw %0, %1" : : "a"(val), "Nd"(port));
}
static inline void outl(unsigned int val, unsigned short port)
{
__asm__ __volatile__("outl %0, %1" : : "a"(val), "Nd"(port));
}
static inline void insb(unsigned short port, void *buf, unsigned long count)
{
__asm__ __volatile__("rep insb" : "+D"(buf), "+c"(count) : "d"(port) : "memory");
}
static inline void insw(unsigned short port, void *buf, unsigned long count)
{
__asm__ __volatile__("rep insw" : "+D"(buf), "+c"(count) : "d"(port) : "memory");
}
static inline void insl(unsigned short port, void *buf, unsigned long count)
{
__asm__ __volatile__("rep insl" : "+D"(buf), "+c"(count) : "d"(port) : "memory");
}
static inline void outsb(unsigned short port, const void *buf, unsigned long count)
{
__asm__ __volatile__("rep outsb" : "+S"(buf), "+c"(count) : "d"(port) : "memory");
}
static inline void outsw(unsigned short port, const void *buf, unsigned long count)
{
__asm__ __volatile__("rep outsw" : "+S"(buf), "+c"(count) : "d"(port) : "memory");
}
static inline void outsl(unsigned short port, const void *buf, unsigned long count)
{
__asm__ __volatile__("rep outsl" : "+S"(buf), "+c"(count) : "d"(port) : "memory");
}
#define mb() __asm__ __volatile__("mfence" : : : "memory")
#define rmb() __asm__ __volatile__("lfence" : : : "memory")
#define wmb() __asm__ __volatile__("sfence" : : : "memory")
#endif
@@ -0,0 +1,38 @@
#ifndef _DRM_DRM_H
#define _DRM_DRM_H
#include <linux/types.h>
#include <stddef.h>
#define DRM_NAME "drm"
#define DRM_MINORS 256
#define DRM_IOCTL_BASE 'd'
#define DRM_IO(nr) _IO(DRM_IOCTL_BASE, nr)
#define DRM_IOR(nr,type) _IOR(DRM_IOCTL_BASE, nr, type)
#define DRM_IOW(nr,type) _IOW(DRM_IOCTL_BASE, nr, type)
#define DRM_IOWR(nr,type) _IOWR(DRM_IOCTL_BASE, nr, type)
struct drm_version {
int version_major;
int version_minor;
int version_patchlevel;
size_t name_len;
char *name;
size_t date_len;
char *date;
size_t desc_len;
char *desc;
};
struct drm_unique {
size_t unique_len;
char *unique;
};
#define _IO(type, nr) ((type) << 8 | (nr))
#define _IOR(type, nr, t) ((type) << 8 | (nr))
#define _IOW(type, nr, t) ((type) << 8 | (nr))
#define _IOWR(type, nr, t) ((type) << 8 | (nr))
#endif
@@ -0,0 +1,75 @@
#ifndef _DRM_DRM_CRTC_H
#define _DRM_DRM_CRTC_H
#include <linux/types.h>
#include <stddef.h>
struct drm_crtc {
void *dev;
void *primary;
void *cursor;
u32 index;
char name[32];
bool enabled;
int x;
int y;
u32 width;
u32 height;
};
struct drm_connector {
void *dev;
u32 connector_type;
u32 connector_type_id;
int status;
char name[32];
};
struct drm_encoder {
void *dev;
u32 encoder_type;
u32 possible_crtcs;
u32 possible_clones;
};
struct drm_display_mode {
u32 clock;
u16 hdisplay;
u16 hsync_start;
u16 hsync_end;
u16 htotal;
u16 hskew;
u16 vdisplay;
u16 vsync_start;
u16 vsync_end;
u16 vtotal;
u16 vscan;
u32 flags;
u32 type;
char name[32];
};
struct drm_mode_fb_cmd {
u32 fb_id;
u32 width;
u32 height;
u32 pitch;
u32 bpp;
u32 depth;
u32 handle;
};
#define DRM_MODE_TYPE_BUILTIN (1 << 0)
#define DRM_MODE_TYPE_CLOCK_C ((1 << 1) | (1 << 2))
#define DRM_MODE_TYPE_CRTC_C ((1 << 3) | (1 << 4))
#define DRM_MODE_FLAG_PHSYNC (1 << 0)
#define DRM_MODE_FLAG_NHSYNC (1 << 1)
#define DRM_MODE_FLAG_PVSYNC (1 << 2)
#define DRM_MODE_FLAG_NVSYNC (1 << 3)
#define DRM_CONNECTOR_STATUS_UNKNOWN 0
#define DRM_CONNECTOR_STATUS_CONNECTED 1
#define DRM_CONNECTOR_STATUS_DISCONNECTED 2
#endif
@@ -0,0 +1,39 @@
#ifndef _DRM_DRM_GEM_H
#define _DRM_DRM_GEM_H
#include <linux/types.h>
#include <stddef.h>
struct drm_device;
struct drm_file;
struct drm_gem_object {
void *dev;
u32 handle_count;
size_t size;
void *driver_private;
};
struct drm_gem_object_ops {
void (*free)(struct drm_gem_object *obj);
int (*open)(struct drm_gem_object *obj, struct drm_file *file);
void (*close)(struct drm_gem_object *obj, struct drm_file *file);
int (*pin)(struct drm_gem_object *obj);
void (*unpin)(struct drm_gem_object *obj);
int (*get_sg_table)(struct drm_gem_object *obj);
void *(*vmap)(struct drm_gem_object *obj);
void (*vunmap)(struct drm_gem_object *obj, void *vaddr);
};
extern int drm_gem_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size);
extern void drm_gem_object_release(struct drm_gem_object *obj);
extern int drm_gem_handle_create(struct drm_file *file,
struct drm_gem_object *obj,
u32 *handlep);
extern void drm_gem_handle_delete(struct drm_file *file, u32 handle);
extern struct drm_gem_object *drm_gem_object_lookup(struct drm_file *file,
u32 handle);
extern void drm_gem_object_put(struct drm_gem_object *obj);
#endif
@@ -0,0 +1,55 @@
#ifndef _DRM_DRM_IOCTL_H
#define _DRM_DRM_IOCTL_H
#include <linux/types.h>
struct drm_file {
u32 pid;
u32 uid;
int authenticated;
int master;
void *driver_priv;
};
struct drm_device {
const char *name;
const char *desc;
u32 driver_features;
void *dev_private;
void *pdev;
u32 irq;
void *mode_config;
void *primary;
void *render;
int unplugged;
};
#define DRIVER_USE_AGP 0x1U
#define DRIVER_REQUIRE_AGP 0x2U
#define DRIVER_GEM 0x8U
#define DRIVER_MODESET 0x10U
#define DRIVER_PRIME 0x20U
#define DRIVER_RENDER 0x40U
#define DRIVER_ATOMIC 0x80U
#define DRIVER_SYNCOBJ 0x100U
struct drm_driver {
const char *name;
const char *desc;
u32 driver_features;
int (*load)(struct drm_device *dev, unsigned long flags);
void (*unload)(struct drm_device *dev);
int (*open)(struct drm_device *dev, struct drm_file *file);
void (*preclose)(struct drm_device *dev, struct drm_file *file);
void (*postclose)(struct drm_device *dev, struct drm_file *file);
void (*lastclose)(struct drm_device *dev);
int (*dma_ioctl)(struct drm_device *dev, void *data, struct drm_file *file);
void (*irq_handler)(int irq, void *arg);
};
extern int drm_dev_register(struct drm_device *dev, unsigned long flags);
extern void drm_dev_unregister(struct drm_device *dev);
extern int drm_ioctl(struct drm_device *dev, unsigned int cmd, void *data,
struct drm_file *file);
#endif
@@ -0,0 +1,84 @@
#ifndef _LINUX_ATOMIC_H
#define _LINUX_ATOMIC_H
#include <linux/types.h>
typedef struct {
volatile int counter;
} atomic_t;
typedef struct {
volatile long counter;
} atomic_long_t;
static inline int atomic_read(const atomic_t *v)
{
return __sync_fetch_and_add((volatile int *)&v->counter, 0) + v->counter;
}
static inline void atomic_set(atomic_t *v, int i)
{
v->counter = i;
__sync_synchronize();
}
static inline void atomic_inc(atomic_t *v)
{
__sync_fetch_and_add(&v->counter, 1);
}
static inline void atomic_dec(atomic_t *v)
{
__sync_fetch_and_sub(&v->counter, 1);
}
static inline void atomic_add(int i, atomic_t *v)
{
__sync_fetch_and_add(&v->counter, i);
}
static inline void atomic_sub(int i, atomic_t *v)
{
__sync_fetch_and_sub(&v->counter, i);
}
static inline int atomic_inc_return(atomic_t *v)
{
return __sync_add_and_fetch(&v->counter, 1);
}
static inline int atomic_dec_return(atomic_t *v)
{
return __sync_sub_and_fetch(&v->counter, 1);
}
static inline int atomic_xchg(atomic_t *v, int new_val)
{
return __sync_lock_test_and_set(&v->counter, new_val);
}
static inline int atomic_cmpxchg(atomic_t *v, int old_val, int new_val)
{
return __sync_val_compare_and_swap(&v->counter, old_val, new_val);
}
static inline int atomic_add_unless(atomic_t *v, int a, int u)
{
int c = v->counter;
while (c != u && !__sync_bool_compare_and_swap(&v->counter, c, c + a))
c = v->counter;
return c != u;
}
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
static inline int atomic_dec_and_test(atomic_t *v)
{
return __sync_sub_and_fetch(&v->counter, 1) == 0;
}
#define smp_mb() __sync_synchronize()
#define smp_rmb() __sync_synchronize()
#define smp_wmb() __sync_synchronize()
#endif
@@ -0,0 +1,33 @@
#ifndef _LINUX_BUG_H
#define _LINUX_BUG_H
#include <stdio.h>
#include <stdlib.h>
#define BUG() \
do { fprintf(stderr, "BUG: %s:%d\n", __FILE__, __LINE__); } while(0)
#define BUG_ON(condition) \
do { if (unlikely(condition)) { BUG(); } } while(0)
#define WARN(condition, fmt, ...) \
({ \
int __ret = !!(condition); \
if (__ret) { fprintf(stderr, "WARN: %s:%d: " fmt "\n", \
__FILE__, __LINE__, ##__VA_ARGS__); } \
__ret; \
})
#define WARN_ON(condition) \
({ \
int __ret = !!(condition); \
if (__ret) { fprintf(stderr, "WARN: %s:%d\n", __FILE__, __LINE__); } \
__ret; \
})
#define WARN_ON_ONCE(condition) WARN_ON(condition)
#define BUILD_BUG_ON(condition) \
extern char __build_bug_on[(condition) ? -1 : 1] __attribute__((unused))
#endif
@@ -0,0 +1,35 @@
#ifndef _LINUX_COMPILER_H
#define _LINUX_COMPILER_H
#define __init
#define __exit
#define __devinit
#define __devexit
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define __read_mostly
#define __aligned(x) __attribute__((aligned(x)))
#define __packed __attribute__((packed))
#define __cold __attribute__((cold))
#define __hot __attribute__((hot))
#define barrier() __asm__ __volatile__("" : : : "memory")
#define WRITE_ONCE(var, val) \
(*((volatile typeof(var) *)&(var)) = (val))
#define READ_ONCE(var) \
(*((volatile typeof(var) *)&(var)))
#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
#define container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
#endif
@@ -0,0 +1,37 @@
#ifndef _LINUX_DEVICE_H
#define _LINUX_DEVICE_H
#include <linux/types.h>
#include <stddef.h>
struct device_driver {
const char *name;
void *owner;
};
struct device {
struct device_driver *driver;
void *driver_data;
void *platform_data;
void *of_node;
u64 dma_mask;
};
static inline void *dev_get_drvdata(const struct device *dev)
{
return dev->driver_data;
}
static inline void dev_set_drvdata(struct device *dev, void *data)
{
dev->driver_data = data;
}
struct class {
const char *name;
};
extern struct device *devm_kzalloc(struct device *dev, size_t size, gfp_t flags);
extern void devm_kfree(struct device *dev, void *ptr);
#endif
@@ -0,0 +1,35 @@
#ifndef _LINUX_DMA_MAPPING_H
#define _LINUX_DMA_MAPPING_H
#include <linux/types.h>
enum dma_data_direction {
DMA_BIDIRECTIONAL = 0,
DMA_TO_DEVICE = 1,
DMA_FROM_DEVICE = 2,
DMA_NONE = 3,
};
#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL << (n)) - 1))
extern void *dma_alloc_coherent(void *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flags);
extern void dma_free_coherent(void *dev, size_t size,
void *vaddr, dma_addr_t dma_handle);
extern dma_addr_t dma_map_single(void *dev, void *ptr, size_t size,
enum dma_data_direction dir);
extern void dma_unmap_single(void *dev, dma_addr_t addr, size_t size,
enum dma_data_direction dir);
static inline int dma_mapping_error(void *dev, dma_addr_t addr)
{
(void)dev;
(void)addr;
return 0;
}
extern int dma_set_mask(void *dev, u64 mask);
extern int dma_set_coherent_mask(void *dev, u64 mask);
#endif
@@ -0,0 +1,34 @@
#ifndef _LINUX_ERRNO_H
#define _LINUX_ERRNO_H
#define EPERM 1
#define ENOENT 2
#define ESRCH 3
#define EINTR 4
#define EIO 5
#define ENXIO 6
#define E2BIG 7
#define ENOEXEC 8
#define EBADF 9
#define ECHILD 10
#define EAGAIN 11
#define ENOMEM 12
#define EACCES 13
#define EFAULT 14
#define EBUSY 16
#define EEXIST 17
#define ENODEV 19
#define EINVAL 22
#define ENFILE 23
#define EMFILE 24
#define ENOTTY 25
#define EPIPE 32
#define ERANGE 34
#define ENOSYS 38
#define ENODATA 61
#define ENOTSUP 95
#define ETIMEDOUT 110
#define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-4096)
#endif
@@ -0,0 +1,26 @@
#ifndef _LINUX_FIRMWARE_H
#define _LINUX_FIRMWARE_H
#include <linux/types.h>
struct firmware {
size_t size;
const u8 *data;
void *priv;
};
struct device;
extern int request_firmware(const struct firmware **fw, const char *name,
struct device *dev);
extern void release_firmware(const struct firmware *fw);
extern int request_firmware_nowait(
struct device *dev, int uevent,
const char *name, void *context,
void (*cont)(const struct firmware *fw, void *context));
extern int request_firmware_direct(const struct firmware **fw,
const char *name, struct device *dev);
#endif
@@ -0,0 +1,46 @@
#ifndef _LINUX_IDR_H
#define _LINUX_IDR_H
#include <linux/types.h>
struct idr {
unsigned char __opaque[256];
};
static inline void idr_init(struct idr *idr)
{
(void)idr;
}
static inline int idr_alloc(struct idr *idr, void *ptr, int start, int end, u32 flags)
{
(void)idr;
(void)ptr;
(void)start;
(void)end;
(void)flags;
return 0;
}
static inline void idr_remove(struct idr *idr, int id)
{
(void)idr;
(void)id;
}
static inline void *idr_find(struct idr *idr, int id)
{
(void)idr;
(void)id;
return (void *)0;
}
static inline void idr_destroy(struct idr *idr)
{
(void)idr;
}
#define idr_for_each_entry(idr, entry, id) \
for ((id) = 0, (entry) = (void *)0; (entry); (id)++)
#endif
@@ -0,0 +1,38 @@
#ifndef _LINUX_INTERRUPT_H
#define _LINUX_INTERRUPT_H
#include <linux/types.h>
#include <linux/irq.h>
static inline int in_interrupt(void)
{
return 0;
}
static inline int in_irq(void)
{
return 0;
}
static inline void local_irq_save(unsigned long *flags)
{
(void)flags;
}
static inline void local_irq_restore(unsigned long flags)
{
(void)flags;
}
static inline void local_irq_disable(void) {}
static inline void local_irq_enable(void) {}
#define disable_irq_nosync(irq) ((void)(irq))
#define enable_irq(irq) ((void)(irq))
#define IRQF_NO_SUSPEND 0x0000U
#define IRQF_FORCE_RESUME 0x0000U
#define IRQF_NO_THREAD 0x0000U
#define IRQF_EARLY_RESUME 0x0000U
#endif
@@ -0,0 +1,41 @@
#ifndef _LINUX_IO_H
#define _LINUX_IO_H
#include <linux/types.h>
#include <stddef.h>
extern void *ioremap(phys_addr_t phys_addr, size_t size);
extern void iounmap(void *addr, size_t size);
extern u32 readl(const void *addr);
extern void writel(u32 val, void *addr);
extern u64 readq(const void *addr);
extern void writeq(u64 val, void *addr);
extern u8 readb(const void *addr);
extern void writeb(u8 val, void *addr);
extern u16 readw(const void *addr);
extern void writew(u16 val, void *addr);
static inline void memcpy_toio(void *dst, const void *src, size_t count)
{
__builtin_memcpy(dst, src, count);
}
static inline void memcpy_fromio(void *dst, const void *src, size_t count)
{
__builtin_memcpy(dst, src, count);
}
static inline void memset_io(void *dst, int c, size_t count)
{
__builtin_memset(dst, c, count);
}
#define ioread8(addr) readb(addr)
#define ioread16(addr) readw(addr)
#define ioread32(addr) readl(addr)
#define iowrite8(v, a) writeb(v, a)
#define iowrite16(v, a) writew(v, a)
#define iowrite32(v, a) writel(v, a)
#endif
@@ -0,0 +1,24 @@
#ifndef _LINUX_IRQ_H
#define _LINUX_IRQ_H
#include <linux/types.h>
typedef unsigned int irqreturn_t;
#define IRQ_NONE 0
#define IRQ_HANDLED 1
#define IRQ_WAKE_THREAD 2
#define IRQF_SHARED 0x0001U
#define IRQF_TRIGGER_RISING 0x0010U
#define IRQF_TRIGGER_FALLING 0x0020U
#define IRQF_TRIGGER_HIGH 0x0040U
#define IRQF_TRIGGER_LOW 0x0080U
typedef irqreturn_t (*irq_handler_t)(int irq, void *dev_id);
extern int request_irq(unsigned int irq, irq_handler_t handler,
unsigned long flags, const char *name, void *dev_id);
extern void free_irq(unsigned int irq, void *dev_id);
#endif
@@ -0,0 +1,24 @@
#ifndef _LINUX_JIFFIES_H
#define _LINUX_JIFFIES_H
#include <linux/types.h>
#include <time.h>
static inline u64 redox_get_jiffies(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (u64)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}
#define jiffies redox_get_jiffies()
#define msecs_to_jiffies(msec) ((unsigned long)(msec))
#define usecs_to_jiffies(usec) ((unsigned long)((usec) / 1000))
#define time_after(a, b) ((long)((b) - (a)) < 0)
#define time_before(a, b) time_after(b, a)
#define MAX_JIFFY_OFFSET ((unsigned long)(~0UL >> 1))
#endif
@@ -0,0 +1,62 @@
#ifndef _LINUX_KERNEL_H
#define _LINUX_KERNEL_H
#include <linux/compiler.h>
#include <linux/types.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#define min(a, b) \
({ typeof(a) _a = (a); typeof(b) _b = (b); _a < _b ? _a : _b; })
#define max(a, b) \
({ typeof(a) _a = (a); typeof(b) _b = (b); _a > _b ? _a : _b; })
#define clamp(val, lo, hi) min(max(val, lo), hi)
#define min_t(type, a, b) \
((type)(a) < (type)(b) ? (type)(a) : (type)(b))
#define max_t(type, a, b) \
((type)(a) > (type)(b) ? (type)(a) : (type)(b))
#define min3(a, b, c) min((a), min((b), (c)))
#define max3(a, b, c) max((a), max((b), (c)))
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define DIV_ROUND_DOWN(n, d) ((n) / (d))
#define DIV_ROUND_CLOSEST(n, d) (((n) + (d) / 2) / (d))
#define round_up(x, y) ((((x) + (y) - 1) / (y)) * (y))
#define round_down(x, y) (((x) / (y)) * (y))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
#define IS_ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
#define swap(a, b) \
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
static inline void msleep(unsigned int msecs)
{
usleep(msecs * 1000);
}
static inline void udelay(unsigned long usecs)
{
usleep(usecs);
}
static inline void mdelay(unsigned long msecs)
{
usleep(msecs * 1000);
}
#define lower_32_bits(n) ((u32)(n))
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
#define roundup(x, y) ((((x) + (y) - 1) / (y)) * (y))
#endif
@@ -0,0 +1,90 @@
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
#include <stddef.h>
struct list_head {
struct list_head *prev;
struct list_head *next;
};
#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->prev = list;
list->next = 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->prev = (struct list_head *)0;
entry->next = (struct list_head *)0;
}
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
static inline int list_is_last(const struct list_head *list,
const struct list_head *head)
{
return list->next == head;
}
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(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)
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
#endif
@@ -0,0 +1,36 @@
#ifndef _LINUX_MM_H
#define _LINUX_MM_H
#include <linux/types.h>
#include <linux/slab.h>
#include <stddef.h>
struct page {
unsigned char __opaque[64];
};
#define __get_free_pages(flags, order) \
((unsigned long)kmalloc(4096 << (order), (flags)))
#define free_pages(addr, order) \
kfree((const void *)(addr))
static inline void *vmalloc(unsigned long size)
{
return kmalloc(size, 0);
}
static inline void vfree(const void *addr)
{
kfree(addr);
}
static inline unsigned long get_zeroed_page(unsigned int flags)
{
void *p = kzalloc(4096, flags);
return (unsigned long)p;
}
#define PageReserved(page) (0)
#endif
@@ -0,0 +1,29 @@
#ifndef _LINUX_MODULE_H
#define _LINUX_MODULE_H
#define MODULE_LICENSE(x)
#define MODULE_AUTHOR(x)
#define MODULE_DESCRIPTION(x)
#define MODULE_VERSION(x)
#define MODULE_ALIAS(x)
#define MODULE_DEVICE_TABLE(type, name)
#define module_init(x)
#define module_exit(x)
#define THIS_MODULE ((void *)0)
#define EXPORT_SYMBOL(x)
#define EXPORT_SYMBOL_GPL(x)
#define EXPORT_SYMBOL_NS(x, ns)
#define MODULE_PARM_DESC(name, desc)
#define module_param(name, type, perm)
#define MODULE_INFO(tag, info)
typedef struct {
int unused;
} module_t;
#endif
@@ -0,0 +1,23 @@
#ifndef _LINUX_MUTEX_H
#define _LINUX_MUTEX_H
#include <linux/types.h>
struct mutex {
unsigned char __opaque[64];
};
extern void mutex_init(struct mutex *lock);
extern void mutex_lock(struct mutex *lock);
extern void mutex_unlock(struct mutex *lock);
extern int mutex_is_locked(struct mutex *lock);
static inline int mutex_trylock(struct mutex *lock)
{
(void)lock;
return 1;
}
#define DEFINE_MUTEX(name) struct mutex name = { .__opaque = {0} }
#endif
@@ -0,0 +1,71 @@
#ifndef _LINUX_PCI_H
#define _LINUX_PCI_H
#include <linux/types.h>
#include <linux/device.h>
#include <linux/io.h>
#include <stddef.h>
#define PCI_VENDOR_ID_AMD 0x1002U
#define PCI_VENDOR_ID_INTEL 0x8086U
#define PCI_VENDOR_ID_NVIDIA 0x10DEU
#define PCI_ANY_ID (~0U)
struct pci_device_id {
u32 vendor;
u32 device;
u32 subvendor;
u32 subdevice;
u32 class;
u32 class_mask;
unsigned long driver_data;
};
struct pci_dev {
u16 vendor;
u16 device;
u8 bus_number;
u8 dev_number;
u8 func_number;
u8 revision;
u32 irq;
u64 resource_start[6];
u64 resource_len[6];
void *driver_data;
struct device device;
};
struct pci_driver {
const char *name;
const struct pci_device_id *id_table;
int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
void (*remove)(struct pci_dev *dev);
int (*suspend)(struct pci_dev *dev, u32 state);
int (*resume)(struct pci_dev *dev);
void (*shutdown)(struct pci_dev *dev);
};
extern int pci_enable_device(struct pci_dev *dev);
extern void pci_disable_device(struct pci_dev *dev);
extern void pci_set_master(struct pci_dev *dev);
extern void *pci_iomap(struct pci_dev *dev, unsigned int bar, size_t max_len);
extern void pci_iounmap(struct pci_dev *dev, void *addr, size_t size);
extern int pci_read_config_dword(struct pci_dev *dev, unsigned int offset, u32 *val);
extern int pci_write_config_dword(struct pci_dev *dev, unsigned int offset, u32 val);
extern u64 pci_resource_start(struct pci_dev *dev, unsigned int bar);
extern u64 pci_resource_len(struct pci_dev *dev, unsigned int bar);
extern int pci_register_driver(struct pci_driver *drv);
extern void pci_unregister_driver(struct pci_driver *drv);
#define MODULE_DEVICE_TABLE(type, name)
#define PCI_DEVICE(vend, dev) \
.vendor = (vend), .device = (dev), \
.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
#endif
@@ -0,0 +1,56 @@
#ifndef _LINUX_PRINTK_H
#define _LINUX_PRINTK_H
#include <stdio.h>
#define KERN_SOH "\001"
#define KERN_EMERG KERN_SOH "0"
#define KERN_ALERT KERN_SOH "1"
#define KERN_CRIT KERN_SOH "2"
#define KERN_ERR KERN_SOH "3"
#define KERN_WARNING KERN_SOH "4"
#define KERN_NOTICE KERN_SOH "5"
#define KERN_INFO KERN_SOH "6"
#define KERN_DEBUG KERN_SOH "7"
#define KERN_DEFAULT KERN_SOH "d"
#define pr_info(fmt, ...) \
fprintf(stdout, "[INFO] " fmt "\n", ##__VA_ARGS__)
#define pr_warn(fmt, ...) \
fprintf(stderr, "[WARN] " fmt "\n", ##__VA_ARGS__)
#define pr_err(fmt, ...) \
fprintf(stderr, "[ERR] " fmt "\n", ##__VA_ARGS__)
#define pr_debug(fmt, ...) \
((void)0)
#define pr_emerg(fmt, ...) \
fprintf(stderr, "[EMERG] " fmt "\n", ##__VA_ARGS__)
#define pr_alert(fmt, ...) \
fprintf(stderr, "[ALERT] " fmt "\n", ##__VA_ARGS__)
#define pr_crit(fmt, ...) \
fprintf(stderr, "[CRIT] " fmt "\n", ##__VA_ARGS__)
#define pr_notice(fmt, ...) \
fprintf(stdout, "[NOTE] " fmt "\n", ##__VA_ARGS__)
#define printk(fmt, ...) \
fprintf(stdout, fmt, ##__VA_ARGS__)
#define dev_info(dev, fmt, ...) \
pr_info(fmt, ##__VA_ARGS__)
#define dev_warn(dev, fmt, ...) \
pr_warn(fmt, ##__VA_ARGS__)
#define dev_err(dev, fmt, ...) \
pr_err(fmt, ##__VA_ARGS__)
#define dev_dbg(dev, fmt, ...) \
pr_debug(fmt, ##__VA_ARGS__)
#endif
@@ -0,0 +1,33 @@
#ifndef _LINUX_SLAB_H
#define _LINUX_SLAB_H
#include <linux/types.h>
#include <stddef.h>
#define GFP_KERNEL 0U
#define GFP_ATOMIC 1U
#define GFP_DMA32 2U
#define GFP_HIGHUSER 3U
#define GFP_NOWAIT 4U
#define GFP_DMA 5U
#define __GFP_NOWARN 0U
#define __GFP_ZERO 0U
extern void *kmalloc(size_t size, gfp_t flags);
extern void *kzalloc(size_t size, gfp_t flags);
extern void kfree(const void *ptr);
#define kmalloc_array(n, size, flags) \
kmalloc((n) * (size), flags)
#define kcalloc(n, size, flags) \
kzalloc((n) * (size), flags)
#define kmemdup(src, len, flags) ({ \
void *__p = kmalloc(len, flags); \
if (__p) __builtin_memcpy(__p, src, len); \
__p; \
})
#endif
@@ -0,0 +1,28 @@
#ifndef _LINUX_SPINLOCK_H
#define _LINUX_SPINLOCK_H
#include <linux/types.h>
typedef struct spinlock {
volatile unsigned char __locked;
} spinlock_t;
extern void spin_lock_init(spinlock_t *lock);
extern void spin_lock(spinlock_t *lock);
extern void spin_unlock(spinlock_t *lock);
extern unsigned long spin_lock_irqsave(spinlock_t *lock, unsigned long *flags);
extern void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags);
static inline void spin_lock_irq(spinlock_t *lock)
{
spin_lock(lock);
}
static inline void spin_unlock_irq(spinlock_t *lock)
{
spin_unlock(lock);
}
#define DEFINE_SPINLOCK(name) spinlock_t name = { .__locked = 0 }
#endif
@@ -0,0 +1,51 @@
#ifndef _LINUX_TIMER_H
#define _LINUX_TIMER_H
#include <linux/types.h>
#include <linux/compiler.h>
struct timer_list {
void (*function)(unsigned long data);
unsigned long data;
unsigned long expires;
unsigned char __opaque[64];
};
static inline void setup_timer(struct timer_list *timer,
void (*function)(unsigned long),
unsigned long data)
{
timer->function = function;
timer->data = data;
timer->expires = 0;
}
static inline int mod_timer(struct timer_list *timer, unsigned long expires)
{
(void)timer;
(void)expires;
return 0;
}
static inline int del_timer(struct timer_list *timer)
{
(void)timer;
return 0;
}
static inline int del_timer_sync(struct timer_list *timer)
{
(void)timer;
return 0;
}
static inline int timer_pending(const struct timer_list *timer)
{
(void)timer;
return 0;
}
#define DEFINE_TIMER(_name, _function, _flags, _data) \
struct timer_list _name = { .function = (_function), .data = (_data) }
#endif
@@ -0,0 +1,29 @@
#ifndef _LINUX_TYPES_H
#define _LINUX_TYPES_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <sys/types.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef u64 phys_addr_t;
typedef u64 dma_addr_t;
#define __iomem
#define __user
#define __force
#define __must_check
typedef unsigned int gfp_t;
#endif
@@ -0,0 +1,47 @@
#ifndef _LINUX_WAIT_H
#define _LINUX_WAIT_H
#include <linux/types.h>
#include <linux/compiler.h>
struct wait_queue_head {
unsigned char __opaque[128];
};
static inline void init_waitqueue_head(struct wait_queue_head *wq)
{
(void)wq;
}
#define wait_event(wq, condition) \
do { while (!(condition)) { __asm__ volatile("pause"); } } while(0)
#define wait_event_timeout(wq, condition, timeout) \
({ (void)(wq); (condition) ? 1 : 0; })
#define wait_event_interruptible(wq, condition) \
({ (void)(wq); (condition) ? 0 : -512; })
#define wait_event_interruptible_timeout(wq, condition, timeout) \
({ (void)(wq); (condition) ? 1 : 0; })
static inline void wake_up(struct wait_queue_head *wq)
{
(void)wq;
}
static inline void wake_up_interruptible(struct wait_queue_head *wq)
{
(void)wq;
}
#define DEFINE_WAIT(name) \
int name = 0
#define finish_wait(wq, wait) \
do { (void)(wq); (void)(wait); } while(0)
#define prepare_to_wait(wq, wait, state) \
do { (void)(wq); (void)(wait); (void)(state); } while(0)
#endif
@@ -0,0 +1,42 @@
#ifndef _LINUX_WORKQUEUE_H
#define _LINUX_WORKQUEUE_H
#include <linux/types.h>
struct work_struct {
void (*func)(struct work_struct *work);
unsigned char __opaque[64];
};
struct delayed_work {
struct work_struct work;
unsigned char __timer_opaque[64];
};
struct workqueue_struct {
unsigned char __opaque[128];
};
typedef void (*work_func_t)(struct work_struct *work);
extern struct workqueue_struct *alloc_workqueue(const char *name,
unsigned int flags,
int max_active);
extern void destroy_workqueue(struct workqueue_struct *wq);
extern int queue_work(struct workqueue_struct *wq, struct work_struct *work);
extern void flush_workqueue(struct workqueue_struct *wq);
#define INIT_WORK(_work, _func) \
do { (_work)->func = (_func); } while(0)
#define INIT_DELAYED_WORK(_work, _func) \
do { (_work)->work.func = (_func); } while(0)
extern int schedule_work(struct work_struct *work);
extern int schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);
extern void flush_scheduled_work(void);
#define create_singlethread_workqueue(name) alloc_workqueue(name, 0, 1)
#define create_workqueue(name) alloc_workqueue(name, 0, 0)
#endif