aboutsummaryrefslogtreecommitdiff
path: root/include/apos
diff options
context:
space:
mode:
Diffstat (limited to 'include/apos')
-rw-r--r--include/apos/atomic.h83
-rw-r--r--include/apos/attrs.h18
-rw-r--r--include/apos/bits.h10
-rw-r--r--include/apos/debug.h7
-rw-r--r--include/apos/dmem.h6
-rw-r--r--include/apos/elf.h145
-rw-r--r--include/apos/mem.h50
-rw-r--r--include/apos/mem_regions.h18
-rw-r--r--include/apos/sizes.h200
-rw-r--r--include/apos/sp_tree.h22
-rw-r--r--include/apos/string.h38
-rw-r--r--include/apos/types.h284
-rw-r--r--include/apos/utils.h41
-rw-r--r--include/apos/vmem.h12
14 files changed, 470 insertions, 464 deletions
diff --git a/include/apos/atomic.h b/include/apos/atomic.h
index 1b92100..e6dafc8 100644
--- a/include/apos/atomic.h
+++ b/include/apos/atomic.h
@@ -3,8 +3,7 @@
#include <apos/utils.h> /* GLUE */
-typedef enum
-{
+typedef enum {
memory_order_relaxed = __ATOMIC_RELAXED,
memory_order_consume = __ATOMIC_CONSUME,
memory_order_acquire = __ATOMIC_ACQUIRE,
@@ -52,10 +51,9 @@ typedef _Atomic __INTMAX_TYPE__ atomic_intmax_t;
typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
-#define atomic_init(PTR, VAL)\
- atomic_store_explicit(PTR, VAL, __ATOMIC_RELAXED)
+#define atomic_init(PTR, VAL) atomic_store_explicit(PTR, VAL, __ATOMIC_RELAXED)
-#define kill_dependency(y) (y)
+#define kill_dependency(y) (y)
#if defined(__GNUC__)
#define CMPLR_LOCK_FREE(x) GLUE(__GCC_ATOMIC_, x)##_LOCK_FREE
@@ -63,16 +61,16 @@ typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
#define CMPLR_LOCK_FREE(x) GLUE(__CLANG_ATOMIC_, x)##_LOCK_FREE
#endif
-#define ATOMIC_BOOL_LOCK_FREE CMPLR_LOCK_FREE(BOOL)
-#define ATOMIC_CHAR_LOCK_FREE CMPLR_LOCK_FREE(CHAR)
+#define ATOMIC_BOOL_LOCK_FREE CMPLR_LOCK_FREE(BOOL)
+#define ATOMIC_CHAR_LOCK_FREE CMPLR_LOCK_FREE(CHAR)
#define ATOMIC_CHAR16_T_LOCK_FREE CMPLR_LOCK_FREE(CHAR16_T)
#define ATOMIC_CHAR32_T_LOCK_FREE CMPLR_LOCK_FREE(CHAR32_T)
-#define ATOMIC_WCHAR_T_LOCK_FREE CMPLR_LOCK_FREE(WCHAR32_T)
-#define ATOMIC_SHORT_LOCK_FREE CMPLR_LOCK_FREE(SHORT)
-#define ATOMIC_INT_LOCK_FREE CMPLR_LOCK_FREE(INT)
-#define ATOMIC_LONG_LOCK_FREE CMPLR_LOCK_FREE(LONG)
-#define ATOMIC_LLONG_LOCK_FREE CMPLR_LOCK_FREE(LLONG)
-#define ATOMIC_POINTER_LOCK_FREE CMPLR_LOCK_FREE(POINTER)
+#define ATOMIC_WCHAR_T_LOCK_FREE CMPLR_LOCK_FREE(WCHAR32_T)
+#define ATOMIC_SHORT_LOCK_FREE CMPLR_LOCK_FREE(SHORT)
+#define ATOMIC_INT_LOCK_FREE CMPLR_LOCK_FREE(INT)
+#define ATOMIC_LONG_LOCK_FREE CMPLR_LOCK_FREE(LONG)
+#define ATOMIC_LLONG_LOCK_FREE CMPLR_LOCK_FREE(LLONG)
+#define ATOMIC_POINTER_LOCK_FREE CMPLR_LOCK_FREE(POINTER)
#if defined(__GNUC__)
#define C11_ATOMIC(x) GLUE(__atomic_, x)
@@ -102,82 +100,79 @@ typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
#define N_ATOMIC(x) C11_ATOMIC(x)
#endif
-#define atomic_store_explicit(obj, val, mode)\
- N_ATOMIC(store)(obj, val, mode)
+#define atomic_store_explicit(obj, val, mode) N_ATOMIC(store)(obj, val, mode)
-#define atomic_store(obj, val)\
+#define atomic_store(obj, val) \
atomic_store_explicit(obj, val, __ATOMIC_SEQ_CST);
-#define atomic_load_explicit(obj, mode)\
- N_ATOMIC(load)(obj, mode)
+#define atomic_load_explicit(obj, mode) N_ATOMIC(load)(obj, mode)
-#define atomic_load(obj)\
- atomic_load_explicit(obj, ATOMIC_SEQ_CST)
+#define atomic_load(obj) atomic_load_explicit(obj, ATOMIC_SEQ_CST)
-#define atomic_exchange_explicit(obj, val, mode)\
+#define atomic_exchange_explicit(obj, val, mode) \
N_ATOMIC(exchange)(obj, val, mode)
-#define atomic_exchange(obj, val)\
+#define atomic_exchange(obj, val) \
atomic_exchange_explicit(obj, val, __ATOMIC_SEQ_CST)
#if defined(__GNUC__)
-#define atomic_compare_exchange_strong_explicit(obj, val, des, suc, fail)\
+#define atomic_compare_exchange_strong_explicit(obj, val, des, suc, fail) \
N_ATOMIC(compare_exchange)(obj, val, des, 0, suc, fail)
#elif defined(__clang__)
-#define atomic_compare_exchange_strong_explicit(obj, val, des, suc, fail)\
+#define atomic_compare_exchange_strong_explicit(obj, val, des, suc, fail) \
N_ATOMIC(compare_exchange_strong)(obj, val, des, suc, fail)
#endif
-#define atomic_compare_exchange_strong(obj, val, des)\
- atomic_compare_exchange_strong_explicit\
- (obj, val, des, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
+#define atomic_compare_exchange_strong(obj, val, des) \
+ atomic_compare_exchange_strong_explicit( \
+ obj, val, des, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
#if defined(__GNUC__)
-#define atomic_compare_exchange_weak_explicit(obj, val, des, suc, fail)\
+#define atomic_compare_exchange_weak_explicit(obj, val, des, suc, fail) \
N_ATOMIC(compare_exchange)(obj, val, des, 1, suc, fail)
#elif defined(__clang__)
-#define atomic_compare_exchange_weak_explicit(obj, val, des, suc, fail)\
+#define atomic_compare_exchange_weak_explicit(obj, val, des, suc, fail) \
N_ATOMIC(compare_exchange_weak)(obj, val, des, suc, fail)
#endif
-#define atomic_compare_exchange_weak(obj, val, des)\
- atomic_compare_exchange_weak_explicit\
- (obj, val, des, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
+#define atomic_compare_exchange_weak(obj, val, des) \
+ atomic_compare_exchange_weak_explicit(obj, val, des, __ATOMIC_SEQ_CST, \
+ __ATOMIC_SEQ_CST)
-#define atomic_fetch_add_explicit(obj, val, mode)\
+#define atomic_fetch_add_explicit(obj, val, mode) \
C11_ATOMIC(fetch_add)(obj, val, mode)
-#define atomic_fetch_add(obj, val)\
+#define atomic_fetch_add(obj, val) \
atomic_fetch_add_explicit(obj, val, __ATOMIC_SEQ_CST)
-#define atomic_fetch_sub_explicit(obj, val, mode)\
+#define atomic_fetch_sub_explicit(obj, val, mode) \
C11_ATOMIC(fetch_sub)(obj, val, mode)
-#define atomic_fetch_sub(obj, val)\
+#define atomic_fetch_sub(obj, val) \
atomic_fetch_sub_explicit(obj, val, __ATOMIC_SEQ_CST)
-#define atomic_fetch_and_explicit(obj, val, mode)\
+#define atomic_fetch_and_explicit(obj, val, mode) \
C11_ATOMIC(fetch_and)(obj, val, mode)
-#define atomic_fetch_and(obj, val)\
+#define atomic_fetch_and(obj, val) \
atomic_fetch_and_explicit(obj, val, __ATOMIC_SEQ_CST)
-#define atomic_fetch_xor_explicit(obj, val, mode)\
+#define atomic_fetch_xor_explicit(obj, val, mode) \
C11_ATOMIC(fetch_xor)(obj, val, mode)
-#define atomic_fetch_xor(obj, val)\
+#define atomic_fetch_xor(obj, val) \
atomic_fetch_xor_explicit(obj, val, __ATOMIC_SEQ_CST)
-#define atomic_fetch_or_explicit(obj, val, mode)\
+#define atomic_fetch_or_explicit(obj, val, mode) \
C11_ATOMIC(fetch_or)(obj, val, mode)
-#define atomic_fetch_or(obj, val)\
+#define atomic_fetch_or(obj, val) \
atomic_fetch_or_explicit(obj, val, __ATOMIC_SEQ_CST)
-#define atomic_fetch_nand_explicit(obj, val, mode)\
+#define atomic_fetch_nand_explicit(obj, val, mode) \
C11_ATOMIC(fetch_nand)(obj, val, mode)
-#define atomic_fetch_nand(obj, val)\
+#define atomic_fetch_nand(obj, val) \
atomic_fetch_nand_explicit(obj, val, __ATOMIC_SEQ_CST)
/* skip atomic flags, probably not needed */
diff --git a/include/apos/attrs.h b/include/apos/attrs.h
index 0a731cc..094ae54 100644
--- a/include/apos/attrs.h
+++ b/include/apos/attrs.h
@@ -1,14 +1,14 @@
#ifndef APOS_COMPILER_ATTRIBUTES_H
-#define __section(section) __attribute__((__section__(section)))
-#define __fmt(x, y) __attribute__((format (__printf__, x, y)))
-#define __aligned(a) __attribute__((aligned(a)))
-#define __noinline __attribute__((noinline))
-#define __noreturn __attribute__((noreturn))
-#define __packed __attribute__((packed))
-#define __weak __attribute__((weak))
+#define __section(section) __attribute__((__section__(section)))
+#define __fmt(x, y) __attribute__((format(__printf__, x, y)))
+#define __aligned(a) __attribute__((aligned(a)))
+#define __noinline __attribute__((noinline))
+#define __noreturn __attribute__((noreturn))
+#define __packed __attribute__((packed))
+#define __weak __attribute__((weak))
-#define __main __section(".kernel.start") __noinline
-#define __init __section(".init.start") __noinline
+#define __main __section(".kernel.start") __noinline
+#define __init __section(".init.start") __noinline
#endif /* APOS_COMPILER_ATTRIBUTES_H */
diff --git a/include/apos/bits.h b/include/apos/bits.h
index 1e1106a..cc3cd00 100644
--- a/include/apos/bits.h
+++ b/include/apos/bits.h
@@ -4,12 +4,12 @@
#include <apos/types.h>
#include <apos/builtin.h>
-#define __is_set(x, y) ((x) & (y))
-#define __set_bit(x, y) ((x) |= (y))
-#define __clear_bit(x, y) ((x) &= ~(y))
+#define __is_set(x, y) ((x) & (y))
+#define __set_bit(x, y) ((x) |= (y))
+#define __clear_bit(x, y) ((x) &= ~(y))
-#define __is_nset(x, y) (__is_set((x), 1 << (y)))
-#define __set_nbit(x, y) (__set_bit((x), 1 << (y)))
+#define __is_nset(x, y) (__is_set((x), 1 << (y)))
+#define __set_nbit(x, y) (__set_bit((x), 1 << (y)))
#define __clear_nbit(x, y) (__clear_bit((x), 1 << (y)))
uint16_t __bswap16(uint16_t u);
diff --git a/include/apos/debug.h b/include/apos/debug.h
index ec591ef..d9d668c 100644
--- a/include/apos/debug.h
+++ b/include/apos/debug.h
@@ -21,12 +21,13 @@ void setup_dbg(pm_t pt, enum serial_dev dev);
struct dbg_info dbg_from_fdt(const void *fdt);
-#define COMMON_FORMAT "[%s] %s:%d\n\t"
+#define COMMON_FORMAT "[%s] %s:%d\n\t"
#define COMMON_ARGS(s) s, __FILE__, __LINE__
-#define bug(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("BUG"), __VA_ARGS__)
+#define bug(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("BUG"), __VA_ARGS__)
#define warn(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("WARN"), __VA_ARGS__)
#define info(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("INFO"), __VA_ARGS__)
-#define error(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("ERROR"), __VA_ARGS__)
+#define error(fmt, ...) \
+ dbg(COMMON_FORMAT fmt, COMMON_ARGS("ERROR"), __VA_ARGS__)
#else
diff --git a/include/apos/dmem.h b/include/apos/dmem.h
index 811f56d..d337e61 100644
--- a/include/apos/dmem.h
+++ b/include/apos/dmem.h
@@ -13,7 +13,9 @@ stat_t init_devmem(pm_t ram_base, pm_t ram_top);
vm_t alloc_devmem(struct tcb *t, pm_t dev_start, size_t bytes, vmflags_t flags);
stat_t free_devmem(struct tcb *t, vm_t dev_start);
-stat_t dev_free_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, vmflags_t flags, enum mm_order t);
-stat_t dev_alloc_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, vmflags_t flags, enum mm_order t);
+stat_t dev_free_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+ vmflags_t flags, enum mm_order t);
+stat_t dev_alloc_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+ vmflags_t flags, enum mm_order t);
#endif /* APOS_DEV_H */
diff --git a/include/apos/elf.h b/include/apos/elf.h
index c0de62e..7d0004a 100644
--- a/include/apos/elf.h
+++ b/include/apos/elf.h
@@ -5,31 +5,31 @@
#include <apos/types.h>
#include <apos/vmem.h>
-#define EI_MAGIC 0x7f454c46
+#define EI_MAGIC 0x7f454c46
-#define ELFCLASSNONE 0x0
-#define ELFCLASS32 0x1
-#define ELFCLASS64 0x2
+#define ELFCLASSNONE 0x0
+#define ELFCLASS32 0x1
+#define ELFCLASS64 0x2
-#define ELFDATANONE 0x0
-#define ELFDATA2LSB 0x1
-#define ELFDATA2MSB 0x2
+#define ELFDATANONE 0x0
+#define ELFDATA2LSB 0x1
+#define ELFDATA2MSB 0x2
-#define ELFOSABI_NONE 0x0
-#define ELFOSABI_SYSV 0x0
-#define ELFOSABI_NETBSD 0x2
-#define ELFOSABI_LINUX 0x3
-#define ELFOSABI_HURD 0x4
-#define ELFOSABI_FREEBSD 0x9
-#define ELFOSABI_OPENBSD 0xc
+#define ELFOSABI_NONE 0x0
+#define ELFOSABI_SYSV 0x0
+#define ELFOSABI_NETBSD 0x2
+#define ELFOSABI_LINUX 0x3
+#define ELFOSABI_HURD 0x4
+#define ELFOSABI_FREEBSD 0x9
+#define ELFOSABI_OPENBSD 0xc
-#define ET_NONE 0x0
-#define ET_REL 0x1
-#define ET_EXEC 0x2
-#define ET_DYN 0x3
-#define ET_CORE 0x4
+#define ET_NONE 0x0
+#define ET_REL 0x1
+#define ET_EXEC 0x2
+#define ET_DYN 0x3
+#define ET_CORE 0x4
-#define EM_RISCV 0xf3
+#define EM_RISCV 0xf3
struct __packed elf_ident {
uint32_t ei_magic;
@@ -75,22 +75,22 @@ struct __packed elf64_header {
uint16_t e_shstrndx;
};
-#define PT_NULL 0x0
-#define PT_LOAD 0x1
-#define PT_DYNAMIC 0x2
-#define PT_INTERP 0x3
-#define PT_NOTE 0x4
-#define PT_SHLIB 0x5
-#define PT_PHDR 0x6
-#define PT_TLS 0x7
-#define PT_LOOS 0x60000000
-#define PT_HIOS 0x6fffffff
-#define PT_LOPROC 0x70000000
-#define PT_HIPROC 0x7fffffff
+#define PT_NULL 0x0
+#define PT_LOAD 0x1
+#define PT_DYNAMIC 0x2
+#define PT_INTERP 0x3
+#define PT_NOTE 0x4
+#define PT_SHLIB 0x5
+#define PT_PHDR 0x6
+#define PT_TLS 0x7
+#define PT_LOOS 0x60000000
+#define PT_HIOS 0x6fffffff
+#define PT_LOPROC 0x70000000
+#define PT_HIPROC 0x7fffffff
-#define PF_X (1 << 0)
-#define PF_W (1 << 1)
-#define PF_R (1 << 2)
+#define PF_X (1 << 0)
+#define PF_W (1 << 1)
+#define PF_R (1 << 2)
struct __packed program32_header {
uint32_t p_type;
@@ -114,37 +114,37 @@ struct __packed program64_header {
uint64_t p_align;
};
-#define SHT_NULL 0x0
-#define SH_PROGBITS 0x1
-#define SHT_SYMTAB 0x2
-#define SHT_STRTAB 0x3
-#define SHT_RELA 0x4
-#define SHT_HASH 0x5
-#define SHT_DYNAMIC 0x6
-#define SHT_NOTE 0x7
-#define SHT_NOBITS 0x8
-#define SHT_REL 0x9
-#define SHT_SHLIB 0x0a
-#define SHT_DYNSYM 0x0b
-#define SHT_INIT_ARRAY 0x0e
-#define SHT_FINI_ARRAY 0x0f
-#define SHT_PREINIT_ARRAY 0x10
-#define SHT_GROUP 0x11
-#define SHT_SYMTAB_SHNDX 0x12
-#define SHT_NUM 0x13
+#define SHT_NULL 0x0
+#define SH_PROGBITS 0x1
+#define SHT_SYMTAB 0x2
+#define SHT_STRTAB 0x3
+#define SHT_RELA 0x4
+#define SHT_HASH 0x5
+#define SHT_DYNAMIC 0x6
+#define SHT_NOTE 0x7
+#define SHT_NOBITS 0x8
+#define SHT_REL 0x9
+#define SHT_SHLIB 0x0a
+#define SHT_DYNSYM 0x0b
+#define SHT_INIT_ARRAY 0x0e
+#define SHT_FINI_ARRAY 0x0f
+#define SHT_PREINIT_ARRAY 0x10
+#define SHT_GROUP 0x11
+#define SHT_SYMTAB_SHNDX 0x12
+#define SHT_NUM 0x13
-#define SHF_WRITE 0x1
-#define SHF_ALLOC 0x2
-#define SHF_EXECINSTR 0x4
-#define SHF_MERGE 0x10
-#define SHF_STRINGS 0x20
-#define SHF_INFO_LINK 0x40
-#define SHF_LINK_ODER 0x80
-#define SHF_OS_NONCONFORMING 0x100
-#define SHF_GROUP 0x200
-#define SHF_TLS 0x400
-#define SHF_MASKOS 0x0ff00000
-#define SHF_MASKPROC 0xf0000000
+#define SHF_WRITE 0x1
+#define SHF_ALLOC 0x2
+#define SHF_EXECINSTR 0x4
+#define SHF_MERGE 0x10
+#define SHF_STRINGS 0x20
+#define SHF_INFO_LINK 0x40
+#define SHF_LINK_ODER 0x80
+#define SHF_OS_NONCONFORMING 0x100
+#define SHF_GROUP 0x200
+#define SHF_TLS 0x400
+#define SHF_MASKOS 0x0ff00000
+#define SHF_MASKPROC 0xf0000000
struct __packed section32_header {
uint32_t sh_name;
@@ -172,17 +172,20 @@ struct __packed section64_header {
uint64_t s_entsize;
};
-#define elf_indent(e) ((struct elf_ident *)e)
-#define elf64_header(e) ((struct elf64_header *)e)
-#define elf32_header(e) ((struct elf32_header *)e)
+#define elf_indent(e) ((struct elf_ident *)e)
+#define elf64_header(e) ((struct elf64_header *)e)
+#define elf32_header(e) ((struct elf32_header *)e)
#define program64_header(p) ((struct program64_header *)p)
#define program32_header(p) ((struct program32_header *)p)
#define section64_header(s) ((struct section64_header *)s)
#define section32_header(s) ((struct section32_header *)s)
-#define elf_header_prop(c, e, p) (c == ELFCLASS64 ? elf64_header(e)->p : elf32_header(e)->p)
-#define program_header_prop(c, e, p) (c == ELFCLASS64 ? program64_header(e)->p : program32_header(e)->p)
-#define section_header_prop(c, e, p) (c == ELFCLASS64 ? section64_header(e)->p : section32_header(e)->p)
+#define elf_header_prop(c, e, p) \
+ (c == ELFCLASS64 ? elf64_header(e)->p : elf32_header(e)->p)
+#define program_header_prop(c, e, p) \
+ (c == ELFCLASS64 ? program64_header(e)->p : program32_header(e)->p)
+#define section_header_prop(c, e, p) \
+ (c == ELFCLASS64 ? section64_header(e)->p : section32_header(e)->p)
vm_t load_elf(struct tcb *t, vm_t b);
diff --git a/include/apos/mem.h b/include/apos/mem.h
index d995b04..7c0fde1 100644
--- a/include/apos/mem.h
+++ b/include/apos/mem.h
@@ -6,37 +6,39 @@
#define MM_OINFO_WIDTH (sizeof(mm_info_t) * 8)
-#define pnum_to_index(pnum, order) (((pnum) >> __o_offset(order)) & (__o_width(order) - 1))
-#define pm_to_index(paddr, order) (pnum_to_index(pm_to_pnum(paddr), (order)))
-#define pm_to_pnum(paddr) ((paddr) >> __mm_page_shift)
-#define pnum_to_paddr(pnum) ((pnum) << __mm_page_shift)
+#define pnum_to_index(pnum, order) \
+ (((pnum) >> __o_offset(order)) & (__o_width(order) - 1))
+#define pm_to_index(paddr, order) (pnum_to_index(pm_to_pnum(paddr), (order)))
+#define pm_to_pnum(paddr) ((paddr) >> __mm_page_shift)
+#define pnum_to_paddr(pnum) ((pnum) << __mm_page_shift)
-#define move_forward(var, num) (((var) += (num)) - (num))
+#define move_forward(var, num) (((var) += (num)) - (num))
#define move_paddr(paddr, base, offset) ((((pm_t)(paddr)) - (base)) + (offset))
-#define num_elems(num) (((num) + MM_OINFO_WIDTH - 1) / MM_OINFO_WIDTH)
-#define num_indexes(num) ((num) / MM_OINFO_WIDTH)
-#define index_elems(num) ((num) / MM_OINFO_WIDTH)
-#define state_elems(num) (sizeof(mm_info_t) * (num_elems(num)))
-#define next_elems(num) (sizeof(void *) * (num))
-#define max_index(order) (__o_width(order) - 1)
+#define num_elems(num) (((num) + MM_OINFO_WIDTH - 1) / MM_OINFO_WIDTH)
+#define num_indexes(num) ((num) / MM_OINFO_WIDTH)
+#define index_elems(num) ((num) / MM_OINFO_WIDTH)
+#define state_elems(num) (sizeof(mm_info_t) * (num_elems(num)))
+#define next_elems(num) (sizeof(void *) * (num))
+#define max_index(order) (__o_width(order) - 1)
-#define __o_offset(order) (__mm_shifts[order])
-#define __o_width(order) (__mm_widths[order])
-#define __o_size(order) (__mm_sizes[order])
-#define __o_elems(order) (__mm_widths[order] / MM_OINFO_WIDTH)
+#define __o_offset(order) (__mm_shifts[order])
+#define __o_width(order) (__mm_widths[order])
+#define __o_size(order) (__mm_sizes[order])
+#define __o_elems(order) (__mm_widths[order] / MM_OINFO_WIDTH)
-#define __o_container(idx) ((idx) / MM_OINFO_WIDTH)
-#define __o_bit(idx) ((idx) & (MM_OINFO_WIDTH - 1))
+#define __o_container(idx) ((idx) / MM_OINFO_WIDTH)
+#define __o_bit(idx) ((idx) & (MM_OINFO_WIDTH - 1))
-#define __va(x) (((char *)(x)) + VM_DMAP - RAM_BASE)
-#define __pa(x) (((char *)(x)) + RAM_BASE - VM_DMAP)
-#define __page(x) ((x) / BASE_PAGE_SIZE)
-#define __addr(x) ((x) * BASE_PAGE_SIZE)
-#define __pages(x) (aligned((x), BASE_PAGE_SIZE) ? __page((x)) : __page((x) + BASE_PAGE_SIZE))
+#define __va(x) (((char *)(x)) + VM_DMAP - RAM_BASE)
+#define __pa(x) (((char *)(x)) + RAM_BASE - VM_DMAP)
+#define __page(x) ((x) / BASE_PAGE_SIZE)
+#define __addr(x) ((x)*BASE_PAGE_SIZE)
+#define __pages(x) \
+ (aligned((x), BASE_PAGE_SIZE) ? __page((x)) : \
+ __page((x) + BASE_PAGE_SIZE))
#define __bytes(x) (__addr(x))
-
extern size_t __mm_shifts[10];
extern size_t __mm_widths[10];
extern size_t __mm_sizes[10];
@@ -63,6 +65,6 @@ void init_mem(size_t max_order, size_t shifts[10], size_t page_shift);
enum mm_mode get_mmode(void *fdt);
#define BASE_PAGE_SIZE (__o_size(BASE_PAGE))
-#define BASE_PAGE (MM_O0)
+#define BASE_PAGE (MM_O0)
#endif /* APOS_MEM_H */
diff --git a/include/apos/mem_regions.h b/include/apos/mem_regions.h
index a843141..e2ab64b 100644
--- a/include/apos/mem_regions.h
+++ b/include/apos/mem_regions.h
@@ -6,8 +6,7 @@
#include <apos/sp_tree.h>
#include <arch/vmem.h>
-#define mem_container(ptr)\
- container_of(ptr, struct mem_region, sp_n)
+#define mem_container(ptr) container_of(ptr, struct mem_region, sp_n)
struct mem_region_root {
struct sp_root free_regions;
@@ -30,18 +29,21 @@ stat_t init_region(struct mem_region_root *r, vm_t start, size_t arena_size);
void destroy_region(struct mem_region_root *r);
vm_t alloc_region(struct mem_region_root *r, size_t size, size_t *actual_size);
-vm_t alloc_fixed_region(struct mem_region_root *r, vm_t start, size_t size, size_t *actual_size);
+vm_t alloc_fixed_region(struct mem_region_root *r, vm_t start, size_t size,
+ size_t *actual_size);
stat_t free_region(struct mem_region_root *r, vm_t start);
struct mem_region *find_used_region(struct mem_region_root *r, vm_t start);
-struct mem_region *find_closest_used_region(struct mem_region_root *r, vm_t start);
-struct mem_region *find_free_region(struct mem_region_root *r, size_t size, size_t *align);
+struct mem_region *find_closest_used_region(struct mem_region_root *r,
+ vm_t start);
+struct mem_region *find_free_region(struct mem_region_root *r, size_t size,
+ size_t *align);
#define REGION_TRY_AGAIN 1
-typedef stat_t region_callback_t(struct vm_branch *b,
- pm_t *offset, vm_t vaddr, vmflags_t flags, enum mm_order order);
+typedef stat_t region_callback_t(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+ vmflags_t flags, enum mm_order order);
vm_t map_fill_region(struct vm_branch *b, region_callback_t *mem_handler,
- pm_t offset, vm_t start, size_t bytes, vmflags_t flags);
+ pm_t offset, vm_t start, size_t bytes, vmflags_t flags);
#endif /* APOS_MEM_REGIONS_H */
diff --git a/include/apos/sizes.h b/include/apos/sizes.h
index 392e122..1a34d48 100644
--- a/include/apos/sizes.h
+++ b/include/apos/sizes.h
@@ -3,117 +3,117 @@
#if defined(__ASSEMBLER__)
-#define SZ_1 0x000000000001
-#define SZ_2 0x000000000002
-#define SZ_4 0x000000000004
-#define SZ_8 0x000000000008
-#define SZ_16 0x000000000010
-#define SZ_32 0x000000000020
-#define SZ_64 0x000000000040
-#define SZ_128 0x000000000080
-#define SZ_256 0x000000000100
-#define SZ_512 0x000000000200
+#define SZ_1 0x000000000001
+#define SZ_2 0x000000000002
+#define SZ_4 0x000000000004
+#define SZ_8 0x000000000008
+#define SZ_16 0x000000000010
+#define SZ_32 0x000000000020
+#define SZ_64 0x000000000040
+#define SZ_128 0x000000000080
+#define SZ_256 0x000000000100
+#define SZ_512 0x000000000200
-#define SZ_1K 0x000000000400
-#define SZ_2K 0x000000000800
-#define SZ_4K 0x000000001000
-#define SZ_8K 0x000000002000
-#define SZ_16K 0x000000004000
-#define SZ_32K 0x000000008000
-#define SZ_64K 0x000000010000
-#define SZ_128K 0x000000020000
-#define SZ_256K 0x000000040000
-#define SZ_512K 0x000000080000
+#define SZ_1K 0x000000000400
+#define SZ_2K 0x000000000800
+#define SZ_4K 0x000000001000
+#define SZ_8K 0x000000002000
+#define SZ_16K 0x000000004000
+#define SZ_32K 0x000000008000
+#define SZ_64K 0x000000010000
+#define SZ_128K 0x000000020000
+#define SZ_256K 0x000000040000
+#define SZ_512K 0x000000080000
-#define SZ_1M 0x000000100000
-#define SZ_2M 0x000000200000
-#define SZ_4M 0x000000400000
-#define SZ_8M 0x000000800000
-#define SZ_16M 0x000001000000
-#define SZ_32M 0x000002000000
-#define SZ_64M 0x000004000000
-#define SZ_128M 0x000008000000
-#define SZ_256M 0x000010000000
-#define SZ_512M 0x000020000000
+#define SZ_1M 0x000000100000
+#define SZ_2M 0x000000200000
+#define SZ_4M 0x000000400000
+#define SZ_8M 0x000000800000
+#define SZ_16M 0x000001000000
+#define SZ_32M 0x000002000000
+#define SZ_64M 0x000004000000
+#define SZ_128M 0x000008000000
+#define SZ_256M 0x000010000000
+#define SZ_512M 0x000020000000
-#define SZ_1G 0x000040000000
-#define SZ_2G 0x000080000000
-#define SZ_4G 0x000100000000
-#define SZ_8G 0x000200000000
-#define SZ_16G 0x000400000000
-#define SZ_32G 0x000800000000
-#define SZ_64G 0x000400000000
-#define SZ_128G 0x000800000000
-#define SZ_256G 0x001000000000
-#define SZ_512G 0x002000000000
+#define SZ_1G 0x000040000000
+#define SZ_2G 0x000080000000
+#define SZ_4G 0x000100000000
+#define SZ_8G 0x000200000000
+#define SZ_16G 0x000400000000
+#define SZ_32G 0x000800000000
+#define SZ_64G 0x000400000000
+#define SZ_128G 0x000800000000
+#define SZ_256G 0x001000000000
+#define SZ_512G 0x002000000000
-#define SZ_1T 0x004000000000
-#define SZ_2T 0x008000000000
-#define SZ_4T 0x010000000000
-#define SZ_8T 0x020000000000
-#define SZ_16T 0x040000000000
-#define SZ_32T 0x080000000000
-#define SZ_64T 0x100000000000
-#define SZ_128T 0x200000000000
-#define SZ_256T 0x400000000000
-#define SZ_512T 0x800000000000
+#define SZ_1T 0x004000000000
+#define SZ_2T 0x008000000000
+#define SZ_4T 0x010000000000
+#define SZ_8T 0x020000000000
+#define SZ_16T 0x040000000000
+#define SZ_32T 0x080000000000
+#define SZ_64T 0x100000000000
+#define SZ_128T 0x200000000000
+#define SZ_256T 0x400000000000
+#define SZ_512T 0x800000000000
#else
-#define SZ_1 0x000000000001UL
-#define SZ_2 0x000000000002UL
-#define SZ_4 0x000000000004UL
-#define SZ_8 0x000000000008UL
-#define SZ_16 0x000000000010UL
-#define SZ_32 0x000000000020UL
-#define SZ_64 0x000000000040UL
-#define SZ_128 0x000000000080UL
-#define SZ_256 0x000000000100UL
-#define SZ_512 0x000000000200UL
+#define SZ_1 0x000000000001UL
+#define SZ_2 0x000000000002UL
+#define SZ_4 0x000000000004UL
+#define SZ_8 0x000000000008UL
+#define SZ_16 0x000000000010UL
+#define SZ_32 0x000000000020UL
+#define SZ_64 0x000000000040UL
+#define SZ_128 0x000000000080UL
+#define SZ_256 0x000000000100UL
+#define SZ_512 0x000000000200UL
-#define SZ_1K 0x000000000400UL
-#define SZ_2K 0x000000000800UL
-#define SZ_4K 0x000000001000UL
-#define SZ_8K 0x000000002000UL
-#define SZ_16K 0x000000004000UL
-#define SZ_32K 0x000000008000UL
-#define SZ_64K 0x000000010000UL
-#define SZ_128K 0x000000020000UL
-#define SZ_256K 0x000000040000UL
-#define SZ_512K 0x000000080000UL
+#define SZ_1K 0x000000000400UL
+#define SZ_2K 0x000000000800UL
+#define SZ_4K 0x000000001000UL
+#define SZ_8K 0x000000002000UL
+#define SZ_16K 0x000000004000UL
+#define SZ_32K 0x000000008000UL
+#define SZ_64K 0x000000010000UL
+#define SZ_128K 0x000000020000UL
+#define SZ_256K 0x000000040000UL
+#define SZ_512K 0x000000080000UL
-#define SZ_1M 0x000000100000UL
-#define SZ_2M 0x000000200000UL
-#define SZ_4M 0x000000400000UL
-#define SZ_8M 0x000000800000UL
-#define SZ_16M 0x000001000000UL
-#define SZ_32M 0x000002000000UL
-#define SZ_64M 0x000004000000UL
-#define SZ_128M 0x000008000000UL
-#define SZ_256M 0x000010000000UL
-#define SZ_512M 0x000020000000UL
+#define SZ_1M 0x000000100000UL
+#define SZ_2M 0x000000200000UL
+#define SZ_4M 0x000000400000UL
+#define SZ_8M 0x000000800000UL
+#define SZ_16M 0x000001000000UL
+#define SZ_32M 0x000002000000UL
+#define SZ_64M 0x000004000000UL
+#define SZ_128M 0x000008000000UL
+#define SZ_256M 0x000010000000UL
+#define SZ_512M 0x000020000000UL
-#define SZ_1G 0x000040000000UL
-#define SZ_2G 0x000080000000UL
-#define SZ_4G 0x000100000000UL
-#define SZ_8G 0x000200000000UL
-#define SZ_16G 0x000400000000UL
-#define SZ_32G 0x000800000000UL
-#define SZ_64G 0x000400000000UL
-#define SZ_128G 0x000800000000UL
-#define SZ_256G 0x001000000000UL
-#define SZ_512G 0x002000000000UL
+#define SZ_1G 0x000040000000UL
+#define SZ_2G 0x000080000000UL
+#define SZ_4G 0x000100000000UL
+#define SZ_8G 0x000200000000UL
+#define SZ_16G 0x000400000000UL
+#define SZ_32G 0x000800000000UL
+#define SZ_64G 0x000400000000UL
+#define SZ_128G 0x000800000000UL
+#define SZ_256G 0x001000000000UL
+#define SZ_512G 0x002000000000UL
-#define SZ_1T 0x004000000000UL
-#define SZ_2T 0x008000000000UL
-#define SZ_4T 0x010000000000UL
-#define SZ_8T 0x020000000000UL
-#define SZ_16T 0x040000000000UL
-#define SZ_32T 0x080000000000UL
-#define SZ_64T 0x100000000000UL
-#define SZ_128T 0x200000000000UL
-#define SZ_256T 0x400000000000UL
-#define SZ_512T 0x800000000000UL
+#define SZ_1T 0x004000000000UL
+#define SZ_2T 0x008000000000UL
+#define SZ_4T 0x010000000000UL
+#define SZ_8T 0x020000000000UL
+#define SZ_16T 0x040000000000UL
+#define SZ_32T 0x080000000000UL
+#define SZ_64T 0x100000000000UL
+#define SZ_128T 0x200000000000UL
+#define SZ_256T 0x400000000000UL
+#define SZ_512T 0x800000000000UL
#endif
diff --git a/include/apos/sp_tree.h b/include/apos/sp_tree.h
index bbf9f9f..1c1525f 100644
--- a/include/apos/sp_tree.h
+++ b/include/apos/sp_tree.h
@@ -1,13 +1,13 @@
#ifndef SP_TREE_H
#define SP_TREE_H
-#define sp_root(r) (r.sp_r)
-#define sp_left(n) (n->left)
-#define sp_right(n) (n->right)
-#define sp_rparen(n) (sp_right(n)->parent)
-#define sp_lparen(n) (sp_left(n)->parent)
-#define sp_paren(n) (n->parent)
-#define sp_gparen(n) (n->parent->parent)
+#define sp_root(r) (r.sp_r)
+#define sp_left(n) (n->left)
+#define sp_right(n) (n->right)
+#define sp_rparen(n) (sp_right(n)->parent)
+#define sp_lparen(n) (sp_left(n)->parent)
+#define sp_paren(n) (n->parent)
+#define sp_gparen(n) (n->parent->parent)
#define sp_has_gparen(n) (sp_paren(n) && sp_gparen(n))
struct sp_node {
@@ -21,15 +21,13 @@ struct sp_root {
struct sp_node *sp_r;
};
-enum sp_dir {
- LEFT, RIGHT
-};
+enum sp_dir { LEFT, RIGHT };
struct sp_node *sp_first(struct sp_node *n);
struct sp_node *sp_last(struct sp_node *n);
-void sp_insert(struct sp_node **root, struct sp_node *p,
- struct sp_node *n, enum sp_dir d);
+void sp_insert(struct sp_node **root, struct sp_node *p, struct sp_node *n,
+ enum sp_dir d);
void sp_remove(struct sp_node **root, struct sp_node *n);
diff --git a/include/apos/string.h b/include/apos/string.h
index 67cdae8..8a3c737 100644
--- a/include/apos/string.h
+++ b/include/apos/string.h
@@ -53,79 +53,79 @@ int memcmp(const void *ptr1, const void *ptr2, size_t num);
*/
#if __has_builtin(__builtin_memcpy)
-#define memcpy(dst, src, num) __builtin_memcpy(dst, src, num)
+#define memcpy(dst, src, num) __builtin_memcpy(dst, src, num)
#endif
#if __has_builtin(__builtin_memmove)
-#define memmove(dst, src, num) __builtin_memmove(dst, src, num)
+#define memmove(dst, src, num) __builtin_memmove(dst, src, num)
#endif
#if __has_builtin(__builtin_strcpy)
-#define strcpy(dst, src) __builtin_strcpy(dst, src)
+#define strcpy(dst, src) __builtin_strcpy(dst, src)
#endif
#if __has_builtin(__builtin_strncpy)
-#define strncpy(dst, src, num) __builtin_strncpy(dst, src, num)
+#define strncpy(dst, src, num) __builtin_strncpy(dst, src, num)
#endif
#if __has_builtin(__builtin_strcat)
-#define strcat(dst, src) __builtin_strcat(dst, src)
+#define strcat(dst, src) __builtin_strcat(dst, src)
#endif
#if __has_builtin(__builtin_strncat)
-#define strncat(dst, src, num) __builtin_strncat(dst, src, num)
+#define strncat(dst, src, num) __builtin_strncat(dst, src, num)
#endif
#if __has_builtin(__builtin_memcmp)
-#define memcmp(p1, p2, num) __builtin_memcmp(p1, p2, num)
+#define memcmp(p1, p2, num) __builtin_memcmp(p1, p2, num)
#endif
#if __has_builtin(__builtin_strcmp)
-#define strcmp(s1, s2) __builtin_strcmp(s1, s2)
+#define strcmp(s1, s2) __builtin_strcmp(s1, s2)
#endif
#if __has_builtin(__builtin_strncmp)
-#define strncmp(s1, s2, num) __builtin_strncmp(s1, s2, num)
+#define strncmp(s1, s2, num) __builtin_strncmp(s1, s2, num)
#endif
#if __has_builtin(__builtin_strncmp)
-#define memchr(ptr, val, num) __builtin_memchr(ptr, val, num)
+#define memchr(ptr, val, num) __builtin_memchr(ptr, val, num)
#endif
#if __has_builtin(__builtin_strchr)
-#define strchr(str, chr) __builtin_strchr(str, chr)
+#define strchr(str, chr) __builtin_strchr(str, chr)
#endif
#if __has_builtin(__builtin_strcspn)
-#define strcspn(s1, s2) __builtin_strcspn(s1, s2)
+#define strcspn(s1, s2) __builtin_strcspn(s1, s2)
#endif
#if __has_builtin(__builtin_strpbrk)
-#define strpbrk(s1, s2) __builtin_strpbrk(s1, s2)
+#define strpbrk(s1, s2) __builtin_strpbrk(s1, s2)
#endif
#if __has_builtin(__builtin_strchr)
-#define strrchr(s1, s2) __builtin_strrchr(s1, s2)
+#define strrchr(s1, s2) __builtin_strrchr(s1, s2)
#endif
#if __has_builtin(__builtin_strspn)
-#define strspn(s1, s2) __builtin_strspn(s1, s2)
+#define strspn(s1, s2) __builtin_strspn(s1, s2)
#endif
#if __has_builtin(__builtin_strstr)
-#define strstr(s1, s2) __builtin_strstr(s1, s2)
+#define strstr(s1, s2) __builtin_strstr(s1, s2)
#endif
#if __has_builtin(__builtin_strtok)
-#define strtok(s1, s2) __builtin_strtok(s1, s2)
+#define strtok(s1, s2) __builtin_strtok(s1, s2)
#endif
#if __has_builtin(__builtin_memset)
-#define memset(p, v, n) __builtin_memset(p, v, n)
+#define memset(p, v, n) __builtin_memset(p, v, n)
#endif
#if __has_builtin(__builtin_strlen)
-#define strlen(s) __builtin_strlen(s)
+#define strlen(s) __builtin_strlen(s)
#endif
#endif /* APOS_STRING_H */
diff --git a/include/apos/types.h b/include/apos/types.h
index fea71ae..48972da 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -1,179 +1,179 @@
#ifndef APOS_TYPES_H
#define APOS_TYPES_H
-typedef _Bool bool;
-#define true 1
-#define false 0
+typedef _Bool bool;
+#define true 1
+#define false 0
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-typedef __WCHAR_TYPE__ wchar_t;
-typedef __WINT_TYPE__ wint_t;
-typedef __INTMAX_TYPE__ intmax_t;
-typedef __UINTMAX_TYPE__ uintmax_t;
-typedef __INT8_TYPE__ int8_t;
-typedef __INT16_TYPE__ int16_t;
-typedef __INT32_TYPE__ int32_t;
-typedef __INT64_TYPE__ int64_t;
-typedef __UINT8_TYPE__ uint8_t;
-typedef __UINT16_TYPE__ uint16_t;
-typedef __UINT32_TYPE__ uint32_t;
-typedef __UINT64_TYPE__ uint64_t;
-typedef __INT_LEAST8_TYPE__ int_least8_t;
-typedef __INT_LEAST16_TYPE__ int_least16_t;
-typedef __INT_LEAST32_TYPE__ int_least32_t;
-typedef __INT_LEAST64_TYPE__ int_least64_t;
-typedef __UINT_LEAST8_TYPE__ uint_least8_t;
-typedef __UINT_LEAST16_TYPE__ uint_least16_t;
-typedef __UINT_LEAST32_TYPE__ uint_least32_t;
-typedef __UINT_LEAST64_TYPE__ uint_least64_t;
-typedef __INT_FAST8_TYPE__ int_fast8_t;
-typedef __INT_FAST16_TYPE__ int_fast16_t;
-typedef __INT_FAST32_TYPE__ int_fast32_t;
-typedef __INT_FAST64_TYPE__ int_fast64_t;
-typedef __UINT_FAST8_TYPE__ uint_fast8_t;
-typedef __UINT_FAST16_TYPE__ uint_fast16_t;
-typedef __UINT_FAST32_TYPE__ uint_fast32_t;
-typedef __UINT_FAST64_TYPE__ uint_fast64_t;
-typedef __INTPTR_TYPE__ intptr_t;
-typedef __UINTPTR_TYPE__ uintptr_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __WCHAR_TYPE__ wchar_t;
+typedef __WINT_TYPE__ wint_t;
+typedef __INTMAX_TYPE__ intmax_t;
+typedef __UINTMAX_TYPE__ uintmax_t;
+typedef __INT8_TYPE__ int8_t;
+typedef __INT16_TYPE__ int16_t;
+typedef __INT32_TYPE__ int32_t;
+typedef __INT64_TYPE__ int64_t;
+typedef __UINT8_TYPE__ uint8_t;
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+typedef __UINT64_TYPE__ uint64_t;
+typedef __INT_LEAST8_TYPE__ int_least8_t;
+typedef __INT_LEAST16_TYPE__ int_least16_t;
+typedef __INT_LEAST32_TYPE__ int_least32_t;
+typedef __INT_LEAST64_TYPE__ int_least64_t;
+typedef __UINT_LEAST8_TYPE__ uint_least8_t;
+typedef __UINT_LEAST16_TYPE__ uint_least16_t;
+typedef __UINT_LEAST32_TYPE__ uint_least32_t;
+typedef __UINT_LEAST64_TYPE__ uint_least64_t;
+typedef __INT_FAST8_TYPE__ int_fast8_t;
+typedef __INT_FAST16_TYPE__ int_fast16_t;
+typedef __INT_FAST32_TYPE__ int_fast32_t;
+typedef __INT_FAST64_TYPE__ int_fast64_t;
+typedef __UINT_FAST8_TYPE__ uint_fast8_t;
+typedef __UINT_FAST16_TYPE__ uint_fast16_t;
+typedef __UINT_FAST32_TYPE__ uint_fast32_t;
+typedef __UINT_FAST64_TYPE__ uint_fast64_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
/* sort of unconventional, but should be fine */
typedef uintmax_t size_t;
typedef intmax_t ssize_t;
-#define INT8_C __INT8_C
-#define INT16_C __INT16_C
-#define INT32_C __INT32_C
-#define INT64_C __INT64_C
-#define UINT8_C __UINT8_C
-#define UINT16_C __UINT16_C
-#define UINT32_C __UINT32_C
-#define UINT64_C __UINT64_C
-#define INTMAX_C __INTMAX_C
-#define UINTMAX_C __UINTMAX_C
+#define INT8_C __INT8_C
+#define INT16_C __INT16_C
+#define INT32_C __INT32_C
+#define INT64_C __INT64_C
+#define UINT8_C __UINT8_C
+#define UINT16_C __UINT16_C
+#define UINT32_C __UINT32_C
+#define UINT64_C __UINT64_C
+#define INTMAX_C __INTMAX_C
+#define UINTMAX_C __UINTMAX_C
-#define CHAR_BIT __CHAR_BIT__
+#define CHAR_BIT __CHAR_BIT__
-#define SCHAR_MAX __SCHAR_MAX__
-#define SCHAR_MIN (-__SCHAR_MAX - 1)
-#define UCHAR_MAX (2 * __SCHAR_MAX__ - 1)
+#define SCHAR_MAX __SCHAR_MAX__
+#define SCHAR_MIN (-__SCHAR_MAX - 1)
+#define UCHAR_MAX (2 * __SCHAR_MAX__ - 1)
#if defined(__CHAR_UNSIGNED__)
-#define CHAR_MIN 0
-#define CHAR_MAX UCHAR_MAX
+#define CHAR_MIN 0
+#define CHAR_MAX UCHAR_MAX
#else
-#define CHAR_MIN SCHAR_MIN
-#define CHAR_MAX SCHAR_MAX
+#define CHAR_MIN SCHAR_MIN
+#define CHAR_MAX SCHAR_MAX
#endif
/* probably not necessary? */
-#define MB_LEN_MAX 16
+#define MB_LEN_MAX 16
-#define SHRT_MAX __SHRT_MAX__
-#define SHRT_MIN (-__SHRT_MAX - 1)
-#define USHRT_MAX (2 * __SHRT_MAX + 1)
+#define SHRT_MAX __SHRT_MAX__
+#define SHRT_MIN (-__SHRT_MAX - 1)
+#define USHRT_MAX (2 * __SHRT_MAX + 1)
-#define INT_MAX __INT_MAX__
-#define INT_MIN (-__INT_MAX__ - 1)
-#define UINT_MAX (2 * __INT_MAX__ + 1)
+#define INT_MAX __INT_MAX__
+#define INT_MIN (-__INT_MAX__ - 1)
+#define UINT_MAX (2 * __INT_MAX__ + 1)
-#define LONG_MAX __LONG__MAX__
-#define LONG_MIN (-__LONG_MAX__ - 1)
-#define ULONG_MAX (2 * __INT_MAX__ + 1)
+#define LONG_MAX __LONG__MAX__
+#define LONG_MIN (-__LONG_MAX__ - 1)
+#define ULONG_MAX (2 * __INT_MAX__ + 1)
-#define LLONG_MAX __LONG_LONG_MAX__
-#define LLONG_MIN (-__LONG_LONG_MAX__ - 1)
-#define ULLONG_MAX (2 * __LONG_LONG_MAX__ + 1)
+#define LLONG_MAX __LONG_LONG_MAX__
+#define LLONG_MIN (-__LONG_LONG_MAX__ - 1)
+#define ULLONG_MAX (2 * __LONG_LONG_MAX__ + 1)
-#define INT8_MAX __INT8_MAX__
-#define INT8_MIN (-__INT8_MAX__ - 1)
-#define UINT8_MAX __UINT8_MAX__
+#define INT8_MAX __INT8_MAX__
+#define INT8_MIN (-__INT8_MAX__ - 1)
+#define UINT8_MAX __UINT8_MAX__
-#define INT16_MAX __INT16_MAX__
-#define INT16_MIN (-__INT16_MAX__ - 1)
-#define UINT16_MAX __UINT16_MAX__
+#define INT16_MAX __INT16_MAX__
+#define INT16_MIN (-__INT16_MAX__ - 1)
+#define UINT16_MAX __UINT16_MAX__
-#define INT32_MAX __INT32_MAX__
-#define INT32_MIN (-__INT32_MAX__ - 1)
-#define UINT32_MAX __UINT32_MAX__
+#define INT32_MAX __INT32_MAX__
+#define INT32_MIN (-__INT32_MAX__ - 1)
+#define UINT32_MAX __UINT32_MAX__
-#define INT64_MAX __INT64_MAX__
-#define INT64_MIN (-__INT64_MAX__ - 1)
-#define UINT64_MAX __UINT64_MAX__
+#define INT64_MAX __INT64_MAX__
+#define INT64_MIN (-__INT64_MAX__ - 1)
+#define UINT64_MAX __UINT64_MAX__
-#define INT_LEAST8_MAX __INT_LEAST8_MAX__
-#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
-#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
+#define INT_LEAST8_MAX __INT_LEAST8_MAX__
+#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
+#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
-#define INT_LEAST16_MAX __INT_LEAST16_MAX__
-#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
-#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
+#define INT_LEAST16_MAX __INT_LEAST16_MAX__
+#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
+#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
-#define INT_LEAST32_MAX __INT_LEAST32_MAX__
-#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
-#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
+#define INT_LEAST32_MAX __INT_LEAST32_MAX__
+#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
+#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
-#define INT_LEAST64_MAX __INT_LEAST64_MAX__
-#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
-#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
+#define INT_LEAST64_MAX __INT_LEAST64_MAX__
+#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
+#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
-#define INT_FAST8_MAX __INT_FAST8_MAX__
-#define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
-#define UINT_FAST8_MAX __UINT_FAST8_MAX__
+#define INT_FAST8_MAX __INT_FAST8_MAX__
+#define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
+#define UINT_FAST8_MAX __UINT_FAST8_MAX__
-#define INT_FAST16_MAX __INT_FAST16_MAX__
-#define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
-#define UINT_FAST16_MAX __UINT_FAST16_MAX__
+#define INT_FAST16_MAX __INT_FAST16_MAX__
+#define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
+#define UINT_FAST16_MAX __UINT_FAST16_MAX__
-#define INT_FAST32_MAX __INT_FAST32_MAX__
-#define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
-#define UINT_FAST32_MAX __UINT_FAST32_MAX__
+#define INT_FAST32_MAX __INT_FAST32_MAX__
+#define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
+#define UINT_FAST32_MAX __UINT_FAST32_MAX__
-#define INT_FAST64_MAX __INT_FAST64_MAX__
-#define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
-#define UINT_FAST64_MAX __UINT_FAST64_MAX__
+#define INT_FAST64_MAX __INT_FAST64_MAX__
+#define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
+#define UINT_FAST64_MAX __UINT_FAST64_MAX__
-#define INTPTR_MAX __INTPTR_MAX__
-#define INTPTR_MIN (-__INTPTR_MAX__ - 1)
-#define UINTPTR_MAX __UINTPTR_MAX__
+#define INTPTR_MAX __INTPTR_MAX__
+#define INTPTR_MIN (-__INTPTR_MAX__ - 1)
+#define UINTPTR_MAX __UINTPTR_MAX__
-#define INTMAX_MAX __INTMAX_MAX__
-#define INTMAX_MIN (-__INTMAX_MAX__ - 1)
-#define UINTMAX_MAX __UINTMAX_MAX__
+#define INTMAX_MAX __INTMAX_MAX__
+#define INTMAX_MIN (-__INTMAX_MAX__ - 1)
+#define UINTMAX_MAX __UINTMAX_MAX__
-#define INT8_WIDTH 8
-#define INT16_WIDTH 16
-#define INT32_WIDTH 32
-#define INT64_WIDTH 64
-#define UINT8_WIDTH 8
-#define UINT16_WIDTH 16
-#define UINT32_WIDTH 32
-#define UINT64_WIDTH 64
+#define INT8_WIDTH 8
+#define INT16_WIDTH 16
+#define INT32_WIDTH 32
+#define INT64_WIDTH 64
+#define UINT8_WIDTH 8
+#define UINT16_WIDTH 16
+#define UINT32_WIDTH 32
+#define UINT64_WIDTH 64
-#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
-#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
-#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
-#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
-#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
-#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
-#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
-#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
+#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
+#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
+#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
+#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
+#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
+#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
+#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
+#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
-#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
-#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
-#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
-#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
-#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
-#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
-#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
-#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
+#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
+#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
+#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
+#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
+#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
+#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
+#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
+#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
-#define INTPTR_WIDTH __INTPTR_WIDTH__
-#define INTMAX_WIDTH __INTMAX_WIDTH__
-#define UINTPTR_WIDTH __INTPTR_WIDTH__
-#define UINTMAX_WIDTH __INTMAX_WIDTH__
+#define INTPTR_WIDTH __INTPTR_WIDTH__
+#define INTMAX_WIDTH __INTMAX_WIDTH__
+#define UINTPTR_WIDTH __INTPTR_WIDTH__
+#define UINTMAX_WIDTH __INTMAX_WIDTH__
-#define NULL 0
+#define NULL 0
/* some common types used throughout the kernel */
typedef int_fast8_t stat_t;
@@ -184,12 +184,12 @@ typedef uint_fast16_t vmflags_t;
/* negative error codes are reserved for general usage, positive error codes are
* allowed to be function-specific. */
enum {
- ERR_EXT = -5, /* already exists */
- ERR_OOMEM = -4, /* out of memory */
- ERR_ADDR = -3, /* illegal address */
- ERR_ALIGN = -2, /* wrong alignment */
- ERR_NF = -1, /* not found */
- OK = 0, /* OK */
+ ERR_EXT = -5, /* already exists */
+ ERR_OOMEM = -4, /* out of memory */
+ ERR_ADDR = -3, /* illegal address */
+ ERR_ALIGN = -2, /* wrong alignment */
+ ERR_NF = -1, /* not found */
+ OK = 0, /* OK */
};
#include <types.h> /* arch-specific type definitions (pm_t/vm_t etc) */
diff --git a/include/apos/utils.h b/include/apos/utils.h
index c2cff2c..e060c44 100644
--- a/include/apos/utils.h
+++ b/include/apos/utils.h
@@ -1,47 +1,49 @@
#ifndef APOS_UTILS_H
#define APOS_UTILS_H
-#define ABS(a) (a < 0 ? -a : a)
+#define ABS(a) (a < 0 ? -a : a)
-#define MAX(a, b) ((a) >= (b) ? (a) : (b))
+#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MAX3(a, b, c) (MAX(a, b) >= MAX(b, c) ? MAX(a, b) : MAX(b, c))
-#define MAX4(a, b, c, d) (MAX3(a, b, c) >= MAX3(b, c, d) ? MAX3(a, b, c) : MAX3(b, c, d))
+#define MAX4(a, b, c, d) \
+ (MAX3(a, b, c) >= MAX3(b, c, d) ? MAX3(a, b, c) : MAX3(b, c, d))
/* etc... */
-#define MIN(a, b) ((a) <= (b) ? (a) : (b))
+#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define MIN3(a, b, c) (MIN(a, b) <= MIN(b, c) ? MIN(a, b) : MIN(b, c))
-#define MIN4(a, b, c, d) (MIN3(a, b, c) <= MIN3(b, c, d) ? MIN3(a, b, c) : MIN3(b, c, d))
+#define MIN4(a, b, c, d) \
+ (MIN3(a, b, c) <= MIN3(b, c, d) ? MIN3(a, b, c) : MIN3(b, c, d))
/* etc... */
#define GLUE2(x, y) x##y
-#define GLUE(x, y) GLUE2(x, y)
+#define GLUE(x, y) GLUE2(x, y)
-#define QUOTE2(x) #x
-#define QUOTE(x) QUOTE2(x)
+#define QUOTE2(x) #x
+#define QUOTE(x) QUOTE2(x)
-#define UNUSED(x) ((void)(x))
+#define UNUSED(x) ((void)(x))
#include <apos/builtin.h>
#if __has_builtin(__builtin_offsetof)
#define offsetof(type, member) __builtin_offsetof(type, member)
#else
-#define offsetof(type, member) ((size_t)&((type *)0)->member)
+#define offsetof(type, member) ((size_t) & ((type *)0)->member)
#endif
-#define container_of(ptr, type, member) \
- ((type *)((char *)(ptr) - offsetof(type, member)))
+#define container_of(ptr, type, member) \
+ ((type *)((char *)(ptr)-offsetof(type, member)))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define ALIGNED(x, a) ((x) % a == 0)
-#define ptradd(x, y) (((vm_t)(x)) + ((vm_t)(y)))
+#define ptradd(x, y) (((vm_t)(x)) + ((vm_t)(y)))
#include <apos/types.h>
static inline size_t align_up(size_t val, size_t a)
{
- if(!a)
+ if (!a)
return val;
size_t rem = val % a;
@@ -54,7 +56,7 @@ static inline size_t align_up(size_t val, size_t a)
static inline size_t align_down(size_t val, size_t a)
{
- if(!a)
+ if (!a)
return val;
return val - (val % a);
@@ -70,11 +72,11 @@ static inline bool aligned(size_t val, size_t a)
static inline size_t asciinum(char c)
{
- if(c >= '0' && c <= '9')
+ if (c >= '0' && c <= '9')
return c - '0';
- else if(c >= 'A' && c <= 'F')
+ else if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
- else if(c >= 'a' && c <= 'f')
+ else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
else
return 0;
@@ -84,7 +86,7 @@ static inline size_t convnum(const char *c, size_t len, size_t base)
{
size_t multiplier = 1;
size_t sum = 0;
- for(size_t i = 0; i < len; ++i){
+ for (size_t i = 0; i < len; ++i) {
sum += asciinum(c[len - 1 - i]) * multiplier;
multiplier *= base;
}
@@ -92,5 +94,4 @@ static inline size_t convnum(const char *c, size_t len, size_t base)
return sum;
}
-
#endif /* APOS_UTILS_H */
diff --git a/include/apos/vmem.h b/include/apos/vmem.h
index cbdef2e..571b906 100644
--- a/include/apos/vmem.h
+++ b/include/apos/vmem.h
@@ -12,16 +12,18 @@ vm_t alloc_fixed_uvmem(struct tcb *r, vm_t start, size_t size, vmflags_t flags);
stat_t free_uvmem(struct tcb *r, vm_t a);
stat_t init_uvmem(struct tcb *r, vm_t base, vm_t top);
-stat_t alloc_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, vmflags_t flags, enum mm_order order);
-stat_t free_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, vmflags_t flags, enum mm_order order);
+stat_t alloc_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+ vmflags_t flags, enum mm_order order);
+stat_t free_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+ vmflags_t flags, enum mm_order order);
-#define map_allocd_region(b, start, bytes, flags)\
+#define map_allocd_region(b, start, bytes, flags) \
map_fill_region(b, &alloc_uvmem_wrapper, 0, start, bytes, flags)
-#define unmap_freed_region(b, start, bytes)\
+#define unmap_freed_region(b, start, bytes) \
map_fill_region(b, &free_uvmem_wrapper, 0, start, bytes, 0)
#define vm_flags(x) ((x) & ~0xff)
-#define vp_flags(x) ((x) & 0xff)
+#define vp_flags(x) ((x)&0xff)
#endif /* APOS_VMEM_H */