kernel: add c++ support
This commit is contained in:
11
Makefile
11
Makefile
@@ -22,7 +22,8 @@ include arch/$(SOCKS_ARCH)/config.mk
|
||||
|
||||
KERNEL_SRC_DIRS := init kernel vm ds util obj sched test
|
||||
KERNEL_C_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(wildcard $(dir)/*.c))
|
||||
KERNEL_OBJ := $(addprefix $(BUILD_DIR)/,$(KERNEL_C_FILES:.c=.o))
|
||||
KERNEL_CXX_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(wildcard $(dir)/*.cpp))
|
||||
KERNEL_OBJ := $(addprefix $(BUILD_DIR)/,$(KERNEL_C_FILES:.c=.o) $(KERNEL_CXX_FILES:.cpp=.o))
|
||||
|
||||
####################################
|
||||
# Kernel libc source files
|
||||
@@ -34,9 +35,10 @@ LIBC_OBJ := $(addprefix $(BUILD_DIR)/,$(LIBC_C_FILES:.c=.o))
|
||||
|
||||
BUILD_ID := $(shell tools/generate_build_id.py --arch $(SOCKS_ARCH))
|
||||
|
||||
CFLAGS := $(CFLAGS) -DBUILD_ID=\"$(BUILD_ID)\" -g -Wall -Werror -pedantic \
|
||||
CFLAGS := $(CFLAGS) -DBUILD_ID=\"$(BUILD_ID)\" -g -Wall -Werror -pedantic -fPIC \
|
||||
-Iinclude -Iarch/$(SOCKS_ARCH)/include -Ilibc/include -Wno-language-extension-token
|
||||
|
||||
CXXFLAGS := $(CFLAGS) $(CXXFLAGS)
|
||||
ASMFLAGS := $(ASMFLAGS) -DBUILD_ID=\"$(BUILD_ID)\"
|
||||
LDFLAGS := $(LDFLAGS) -g -lgcc
|
||||
|
||||
@@ -64,6 +66,11 @@ $(BUILD_DIR)/%.o: %.c
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) $< -o $@ -c $(CFLAGS) $(ARCH_CFLAGS) -MMD
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp
|
||||
@printf " \033[1;32mCXX\033[0m \033[35m$(KERNEL_EXEC)\033[0m/$<\n"
|
||||
@mkdir -p $(@D)
|
||||
@$(CXX) $< -o $@ -c $(CXXFLAGS) $(ARCH_CXXFLAGS) -MMD
|
||||
|
||||
clean:
|
||||
@printf " \033[1;93mRM\033[0m Deleting build files.\n"
|
||||
@rm -rf $(BUILD_DIR)
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
#ifndef ARCH_STDCON_H_
|
||||
#define ARCH_STDCON_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void stdcon_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef SOCKS_USER_CPU_H_
|
||||
#define SOCKS_USER_CPU_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ml_cpu_block {
|
||||
int cpu_reserved;
|
||||
} ml_cpu_block;
|
||||
@@ -12,4 +16,8 @@ extern int ml_cpu_block_use(ml_cpu_block *p);
|
||||
|
||||
extern void ml_halt_cpu(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#define ML_HWLOCK_INIT (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int ml_hwlock_t;
|
||||
|
||||
extern void ml_hwlock_lock(ml_hwlock_t *lck);
|
||||
@@ -11,4 +15,8 @@ extern void ml_hwlock_unlock(ml_hwlock_t *lck);
|
||||
extern void ml_hwlock_lock_irqsave(ml_hwlock_t *lck, unsigned long *flags);
|
||||
extern void ml_hwlock_unlock_irqrestore(ml_hwlock_t *lck, unsigned long flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define __X2(x) #x
|
||||
#define __X(x) __X2(x)
|
||||
|
||||
@@ -18,4 +22,8 @@
|
||||
|
||||
extern int ml_init(uintptr_t arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uintptr_t __pagemap_base(void);
|
||||
extern uintptr_t __pagemap_limit(void);
|
||||
|
||||
@@ -23,4 +27,8 @@ extern uintptr_t __pagemap_limit(void);
|
||||
#define VM_PAGE_MIN_ORDER VM_PAGE_4K
|
||||
#define VM_PAGE_MAX_ORDER VM_PAGE_8M
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
|
||||
static uint32_t *lapic_base;
|
||||
|
||||
extern int check_apic(void);
|
||||
extern "C" {
|
||||
/* defined in apic_ctrl.S */
|
||||
extern int check_apic(void);
|
||||
}
|
||||
|
||||
static uintptr_t apic_get_base(void)
|
||||
{
|
||||
@@ -78,7 +81,7 @@ kern_status_t local_apic_enable(void)
|
||||
}
|
||||
|
||||
apic_set_base(apic_get_base());
|
||||
lapic_base = find_lapic(madt);
|
||||
lapic_base = (uint32_t *)find_lapic(madt);
|
||||
|
||||
local_apic_write(0xF0, local_apic_read(0xF0) | 0x100);
|
||||
|
||||
@@ -104,11 +107,11 @@ static void init_all_ioapic(void)
|
||||
|
||||
kern_status_t apic_init(void)
|
||||
{
|
||||
static int bsp_id = -1;
|
||||
static unsigned int bsp_id = (unsigned int)-1;
|
||||
|
||||
/* the bootstrap processor will be the first one ro call apic_init().
|
||||
it is responsible for initialising the I/O APICs */
|
||||
if (bsp_id == -1) {
|
||||
if (bsp_id == (unsigned int)-1) {
|
||||
bsp_id = this_cpu();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include <socks/status.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ACPI_MADT_LAPIC 0x00
|
||||
#define ACPI_MADT_IOAPIC 0x01
|
||||
#define ACPI_MADT_LAPIC_OVERRIDE 0x05
|
||||
@@ -56,12 +60,12 @@ struct acpi_sdt {
|
||||
|
||||
struct acpi_rsdt {
|
||||
struct acpi_sdt r_header;
|
||||
uint32_t r_tables[];
|
||||
uint32_t r_tables[1];
|
||||
} __packed;
|
||||
|
||||
struct acpi_xsdt {
|
||||
struct acpi_sdt x_header;
|
||||
uint64_t x_tables[];
|
||||
uint64_t x_tables[1];
|
||||
} __packed;
|
||||
|
||||
struct acpi_madt {
|
||||
@@ -95,4 +99,8 @@ extern kern_status_t smp_init(void);
|
||||
|
||||
extern struct acpi_sdt *acpi_find_sdt(uint32_t sig);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
#include <stddef.h>
|
||||
#include <arch/multiboot.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void e820_scan(multiboot_memory_map_t *mmap, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NR_GDT_ENTRIES 5
|
||||
|
||||
#define GDT_A_PRESENT (1 << 7)
|
||||
@@ -39,4 +43,8 @@ struct gdt_ptr {
|
||||
extern int gdt_init(struct gdt *gdt, struct gdt_ptr *gdtp);
|
||||
extern int gdt_load(struct gdt_ptr *gdtp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include <socks/queue.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NR_IDT_ENTRIES 48
|
||||
|
||||
typedef enum irq_vector {
|
||||
@@ -68,4 +72,8 @@ extern int idt_load(struct idt_ptr *idtp);
|
||||
extern void hook_irq(irq_vector_t vec, irq_hook_t *hook);
|
||||
extern void unhook_irq(irq_vector_t vec, irq_hook_t *hook);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,8 +5,16 @@
|
||||
|
||||
#define MSR_GS_BASE 0xC0000101
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* defined in cpu_ctrl.S */
|
||||
extern uint64_t rdmsr(uint32_t id);
|
||||
extern void wrmsr(uint32_t id, uint64_t val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/types.h>
|
||||
#include <socks/compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PTE_PRESENT 0x01ULL
|
||||
#define PTE_RW 0x02ULL
|
||||
#define PTE_USR 0x04ULL
|
||||
@@ -52,4 +56,8 @@ typedef enum page_size {
|
||||
extern int gigabyte_pages(void);
|
||||
extern int enable_nx(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
#ifndef ARCH_PIT_H_
|
||||
#define ARCH_PIT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void pit_start(unsigned int hz);
|
||||
extern void pit_stop(void);
|
||||
extern void pit_wait(unsigned int ticks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint8_t inportb(uint16_t port);
|
||||
extern uint16_t inportw(uint16_t port);
|
||||
extern uint32_t inportl(uint16_t port);
|
||||
@@ -12,4 +16,8 @@ extern void outportl(uint16_t port, uint32_t data);
|
||||
extern void outportsw(uint16_t port, void *data, uint32_t size);
|
||||
extern void inportsw(uint16_t port, unsigned char *data, unsigned long size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef ARCH_SERIAL_H_
|
||||
#define ARCH_SERIAL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SERIAL_PORT_A 0x3F8
|
||||
#define SERIAL_PORT_B 0x2F8
|
||||
#define SERIAL_PORT_C 0x3E8
|
||||
@@ -14,4 +18,8 @@ extern char serial_recv_byte(int device);
|
||||
|
||||
extern int serial_rcvd(int device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
#ifndef ARCH_VGACON_H_
|
||||
#define ARCH_VGACON_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void vgacon_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <arch/gdt.h>
|
||||
#include <arch/irq.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ml_cpu_block_get_id(p) ((p)->c_cpu_id)
|
||||
|
||||
typedef struct ml_cpu_block {
|
||||
@@ -28,4 +32,8 @@ extern int ml_cpu_block_use(ml_cpu_block *p);
|
||||
extern void ml_halt_cpu(void);
|
||||
extern ml_cpu_block *ml_this_cpu(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#define ML_HWLOCK_INIT (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int ml_hwlock_t;
|
||||
|
||||
extern void ml_hwlock_lock(ml_hwlock_t *lck);
|
||||
@@ -11,4 +15,8 @@ extern void ml_hwlock_unlock(ml_hwlock_t *lck);
|
||||
extern void ml_hwlock_lock_irqsave(ml_hwlock_t *lck, unsigned long *flags);
|
||||
extern void ml_hwlock_unlock_irqrestore(ml_hwlock_t *lck, unsigned long flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define __X2(x) #x
|
||||
#define __X(x) __X2(x)
|
||||
|
||||
@@ -12,4 +16,8 @@
|
||||
|
||||
extern int ml_init(uintptr_t arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BITS_PER_WORD (8 * sizeof(unsigned long))
|
||||
#define __DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
|
||||
#define BITMAP_WORDS(nbits) __DIV_ROUND_UP(nbits, BITS_PER_WORD)
|
||||
@@ -23,4 +27,8 @@ extern unsigned int bitmap_highest_clear(unsigned long *map, unsigned long nbits
|
||||
extern unsigned int bitmap_lowest_set(unsigned long *map, unsigned long nbits);
|
||||
extern unsigned int bitmap_lowest_clear(unsigned long *map, unsigned long nbits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
|
||||
- Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
@@ -25,6 +25,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* if your custom structure contains a btree_node_t (i.e. it can be part of a btree),
|
||||
you can use this macro to convert a btree_node_t* to a your_type*
|
||||
|
||||
@@ -94,8 +98,8 @@
|
||||
} \
|
||||
\
|
||||
btree_insert_fixup(tree, &node->container_node_member); \
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* defines a node insertion function.
|
||||
this function should be used for trees with complex node keys that cannot be directly compared.
|
||||
a comparator for your keys must be supplied.
|
||||
@@ -114,9 +118,9 @@
|
||||
|
||||
Which implements the following:
|
||||
|
||||
return -1 if a < b
|
||||
return 0 if a == b
|
||||
return 1 if a > b
|
||||
return -1 if a < b
|
||||
return 0 if a == b
|
||||
return 1 if a > b
|
||||
|
||||
You would use the following call to generate an insert function for a tree with this node type:
|
||||
|
||||
@@ -370,4 +374,8 @@ static inline unsigned short btree_height(btree_node_t *node)
|
||||
return node->b_height;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include <socks/locks.h>
|
||||
#include <socks/status.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum console_flags {
|
||||
/* console is only used during the boot process. the console
|
||||
will be automatically de-registered when the first
|
||||
@@ -42,4 +46,8 @@ extern kern_status_t console_unregister(console_t *con);
|
||||
extern void console_write(console_t *con, const char *s, unsigned int len);
|
||||
extern int console_read(console_t *con, char *s, unsigned int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/machine/cpu.h>
|
||||
#include <socks/sched.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum cpu_flags {
|
||||
CPU_ONLINE = 0x01u,
|
||||
} cpu_flags_t;
|
||||
@@ -30,4 +34,8 @@ extern void cpu_set_online(unsigned int cpu_id);
|
||||
|
||||
extern unsigned int cpu_get_highest_available(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/compiler.h>
|
||||
#include <socks/machine/init.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int (*initcall_t)(void);
|
||||
|
||||
#define INITLEVEL_EARLY 0
|
||||
@@ -30,4 +34,8 @@ extern void print_kernel_banner(void);
|
||||
extern int do_initcalls(void);
|
||||
extern int start_initlevel(int level);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/compiler.h>
|
||||
#include <socks/machine/hwlock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef __aligned(8) ml_hwlock_t spin_lock_t;
|
||||
|
||||
#define SPIN_LOCK_INIT ML_HWLOCK_INIT
|
||||
@@ -11,4 +15,8 @@ typedef __aligned(8) ml_hwlock_t spin_lock_t;
|
||||
#define spin_lock_irqsave(lck, flags) ml_hwlock_lock_irqsave(lck, flags);
|
||||
#define spin_unlock_irqrestore(lck, flags) ml_hwlock_unlock_irqrestore(lck, flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
|
||||
- Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
@@ -26,6 +26,10 @@
|
||||
#include <limits.h>
|
||||
#include <socks/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MEMBLOCK_INIT_MEMORY_REGION_COUNT 128
|
||||
#define MEMBLOCK_INIT_RESERVED_REGION_COUNT 128
|
||||
|
||||
@@ -50,7 +54,7 @@
|
||||
if you don't want to use an upper bound, pass UINTPTR_MAX.
|
||||
|
||||
EXAMPLE: to iterate through all memory regions (with no bounds):
|
||||
|
||||
|
||||
memblock_iter_t it;
|
||||
for_each_mem_region (&it, 0x0, UINTPTR_MAX) { ... }
|
||||
|
||||
@@ -80,7 +84,7 @@
|
||||
if you don't want to use an upper bound, pass UINTPTR_MAX.
|
||||
|
||||
EXAMPLE: to iterate through all reserved memory regions (with no bounds):
|
||||
|
||||
|
||||
memblock_iter_t it;
|
||||
for_each_reserved_mem_region (&it, 0x0, UINTPTR_MAX) { ... }
|
||||
|
||||
@@ -319,4 +323,8 @@ extern void __next_memory_region(memblock_iter_t *it, \
|
||||
memblock_type_t *type_a, memblock_type_t *type_b,
|
||||
phys_addr_t start, phys_addr_t end);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include <socks/vm.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define OBJECT_MAGIC 0xBADDCAFE
|
||||
#define OBJECT_NAME_MAX 64
|
||||
|
||||
@@ -19,7 +23,7 @@ typedef enum object_type_flags {
|
||||
typedef struct object_ops {
|
||||
kern_status_t(*open)(struct object *obj);
|
||||
kern_status_t(*close)(struct object *obj);
|
||||
kern_status_t(*delete)(struct object *obj);
|
||||
kern_status_t(*destroy)(struct object *obj);
|
||||
kern_status_t(*query_name)(struct object *obj, char out[OBJECT_NAME_MAX]);
|
||||
kern_status_t(*parse)(struct object *obj, const char *path, struct object **out);
|
||||
kern_status_t(*get_named)(struct object *obj, const char *name, struct object **out);
|
||||
@@ -89,4 +93,8 @@ extern bool object_is_set(object_t *obj);
|
||||
extern void init_set_objects(void);
|
||||
extern void init_global_namespace(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/status.h>
|
||||
#include <socks/compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DEFINE_PERCPU_VAR(type, name) \
|
||||
__section(".data.percpu") type name
|
||||
|
||||
@@ -14,4 +18,8 @@
|
||||
extern kern_status_t init_per_cpu_areas(void);
|
||||
extern void *__percpu_get(void *var);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
|
||||
#define PFN(x) ((x) >> VM_PAGE_SHIFT)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef ml_pmap_t pmap_t;
|
||||
typedef ml_pfn_t pfn_t;
|
||||
|
||||
@@ -30,4 +34,8 @@ extern kern_status_t pmap_add_block(pmap_t pmap, void *p, pfn_t pfn, size_t len,
|
||||
extern kern_status_t pmap_remove(pmap_t pmap, void *p);
|
||||
extern kern_status_t pmap_remove_range(pmap_t pmap, void *p, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,15 @@
|
||||
|
||||
#include <socks/console.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void early_printk_init(console_t *con);
|
||||
extern int printk(const char *format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <socks/libc/string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define QUEUE_CONTAINER(t, m, v) ((void *)((v) ? (uintptr_t)(v) - (offsetof(t, m)) : 0))
|
||||
|
||||
#define QUEUE_INIT ((queue_t){ .q_first = NULL, .q_last = NULL })
|
||||
@@ -51,4 +55,8 @@ extern queue_entry_t *queue_pop_back(queue_t *q);
|
||||
extern void queue_delete(queue_t *q, queue_entry_t *entry);
|
||||
extern void queue_delete_all(queue_t *q);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#define TASK_NAME_MAX 64
|
||||
#define PRIO_MAX 32
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum task_state {
|
||||
TASK_RUNNING,
|
||||
TASK_STOPPED,
|
||||
@@ -73,7 +77,7 @@ extern kern_status_t sched_init(void);
|
||||
extern void runqueue_init(runqueue_t *rq);
|
||||
|
||||
extern task_t *task_alloc(void);
|
||||
static inline task_t *task_ref(task_t *task) { return object_data(object_ref(object_header(task))); }
|
||||
static inline task_t *task_ref(task_t *task) { return (task_t *)object_data(object_ref(object_header(task))); }
|
||||
static inline void task_deref(task_t *task) { object_deref(object_header(task)); }
|
||||
extern task_t *task_from_pid(unsigned int pid);
|
||||
extern task_t *kernel_task(void);
|
||||
@@ -90,4 +94,8 @@ static inline void task_unlock_irqrestore(task_t *task, unsigned long flags)
|
||||
|
||||
extern thread_t *thread_alloc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
#ifndef SOCKS_TEST_H_
|
||||
#define SOCKS_TEST_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int run_all_tests(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
device, a serial port, etc.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* opaque context pointer for use by the tty driver */
|
||||
typedef void *tty_driver_ctx_t;
|
||||
|
||||
@@ -84,4 +88,8 @@ extern void tty_destroy(tty_t *tty);
|
||||
extern int tty_read(tty_t *tty, char *s, unsigned long len);
|
||||
extern int tty_write(tty_t *tty, const char *s, unsigned long len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void data_size_to_string(size_t value, char *out, size_t outsz);
|
||||
static inline bool power_of_2(size_t x) { return (x > 0 && (x & (x - 1)) == 0); }
|
||||
static inline unsigned long long div64_pow2(unsigned long long x, unsigned long long y)
|
||||
@@ -17,4 +21,8 @@ static inline unsigned long long absdiff64(unsigned long long x, unsigned long l
|
||||
return x > y ? y - x : x - y;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#include <socks/locks.h>
|
||||
#include <socks/machine/vm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* maximum number of NUMA nodes */
|
||||
#define VM_MAX_NODES 64
|
||||
/* maximum number of memory zones per node */
|
||||
@@ -185,8 +189,9 @@ typedef struct vm_slab {
|
||||
when freeing:
|
||||
- s_free should be set to the index of the object being freed.
|
||||
- s_freelist[s_free] should be set to the previous value of s_free.
|
||||
this is commented as it as flexible arrays are not supported in c++.
|
||||
*/
|
||||
unsigned int s_freelist[];
|
||||
//unsigned int s_freelist[];
|
||||
} vm_slab_t;
|
||||
|
||||
typedef struct vm_page {
|
||||
@@ -212,9 +217,7 @@ typedef struct vm_page {
|
||||
|
||||
/* owner-specific data */
|
||||
union {
|
||||
struct {
|
||||
vm_slab_t *p_slab;
|
||||
};
|
||||
vm_slab_t *p_slab;
|
||||
};
|
||||
|
||||
} __attribute__((aligned(2 * sizeof(unsigned long)))) vm_page_t;
|
||||
@@ -287,4 +290,8 @@ extern void vm_sparse_init(void);
|
||||
extern vm_page_t *vm_page_get_sparse(phys_addr_t addr);
|
||||
extern size_t vm_page_get_pfn_sparse(vm_page_t *pg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
18
obj/object.c
18
obj/object.c
@@ -24,10 +24,10 @@ kern_status_t object_type_register(object_type_t *p)
|
||||
p->ob_cache.c_name = p->ob_name;
|
||||
p->ob_cache.c_obj_size = sizeof(object_t) + p->ob_size;
|
||||
p->ob_cache.c_page_order = VM_PAGE_16K;
|
||||
|
||||
|
||||
vm_cache_init(&p->ob_cache);
|
||||
p->ob_flags |= OBJTYPE_INIT;
|
||||
|
||||
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ object_t *object_create(object_type_t *type)
|
||||
if (!(type->ob_flags & OBJTYPE_INIT)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
vm_cache_t *cache = &type->ob_cache;
|
||||
object_t *obj = vm_cache_alloc(cache, 0);
|
||||
if (!obj) {
|
||||
@@ -58,7 +58,7 @@ object_t *object_create(object_type_t *type)
|
||||
obj->ob_magic = OBJECT_MAGIC;
|
||||
obj->ob_refcount = 1;
|
||||
obj->ob_handles = 0;
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void object_deref(object_t *obj)
|
||||
{
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&obj->ob_lock, &flags);
|
||||
|
||||
|
||||
if (obj->ob_refcount == 0) {
|
||||
spin_unlock_irqrestore(&obj->ob_lock, flags);
|
||||
return;
|
||||
@@ -85,8 +85,8 @@ void object_deref(object_t *obj)
|
||||
return;
|
||||
}
|
||||
|
||||
if (HAS_OP(obj, delete)) {
|
||||
obj->ob_type->ob_ops.delete(obj);
|
||||
if (HAS_OP(obj, destroy)) {
|
||||
obj->ob_type->ob_ops.destroy(obj);
|
||||
}
|
||||
|
||||
vm_cache_free(&obj->ob_type->ob_cache, obj);
|
||||
@@ -120,7 +120,7 @@ object_t *object_header(void *p)
|
||||
kern_status_t object_get_child_named(object_t *obj, const char *name, object_t **out)
|
||||
{
|
||||
kern_status_t status = KERN_UNSUPPORTED;
|
||||
|
||||
|
||||
if (HAS_OP(obj, get_named)) {
|
||||
status = obj->ob_type->ob_ops.get_named(obj, name, out);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ kern_status_t object_get_child_named(object_t *obj, const char *name, object_t *
|
||||
kern_status_t object_get_child_at(object_t *obj, size_t at, object_t **out)
|
||||
{
|
||||
kern_status_t status = KERN_UNSUPPORTED;
|
||||
|
||||
|
||||
if (HAS_OP(obj, get_at)) {
|
||||
status = obj->ob_type->ob_ops.get_at(obj, at, out);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
LD := gcc
|
||||
CC := gcc
|
||||
CXX := g++
|
||||
ASM := gcc
|
||||
|
||||
CFLAGS := -Wall -Werror -pedantic
|
||||
CXXFLAGS := $(CFLAGS)
|
||||
ASMFLAGS := $(CFLAGS)
|
||||
LDFLAGS := -O2
|
||||
|
||||
@@ -5,7 +5,7 @@ import os
|
||||
|
||||
|
||||
def is_source_file(filepath):
|
||||
return filepath.endswith('.c') or filepath.endswith('.h') or filepath.endswith('.S')
|
||||
return filepath.endswith('.c') or filepath.endswith('.cpp') or filepath.endswith('.h') or filepath.endswith('.S')
|
||||
|
||||
dir_stack = []
|
||||
rootdir = os.getcwd()
|
||||
@@ -30,7 +30,7 @@ for line in make_output_lines:
|
||||
dir_stack.pop()
|
||||
continue;
|
||||
|
||||
if 'gcc' not in line_parts[0]:
|
||||
if 'gcc' not in line_parts[0] and 'g++' not in line_parts[0]:
|
||||
continue
|
||||
|
||||
src_file = ''
|
||||
|
||||
12
vm/cache.c
12
vm/cache.c
@@ -106,11 +106,12 @@ static vm_slab_t *alloc_slab(vm_cache_t *cache, vm_flags_t flags)
|
||||
slab_hdr->s_obj_allocated = 0;
|
||||
slab_hdr->s_free = 0;
|
||||
|
||||
unsigned int *freelist = (unsigned int *)(slab_hdr + 1);
|
||||
for (unsigned int i = 0; i < cache->c_obj_count; i++) {
|
||||
slab_hdr->s_freelist[i] = i + 1;
|
||||
freelist[i] = i + 1;
|
||||
}
|
||||
|
||||
slab_hdr->s_freelist[cache->c_obj_count - 1] = FREELIST_END;
|
||||
freelist[cache->c_obj_count - 1] = FREELIST_END;
|
||||
|
||||
vm_page_foreach (slab_page, i) {
|
||||
i->p_slab = slab_hdr;
|
||||
@@ -131,7 +132,8 @@ static unsigned int slab_allocate_slot(vm_slab_t *slab)
|
||||
}
|
||||
|
||||
unsigned int slot = slab->s_free;
|
||||
slab->s_free = slab->s_freelist[slab->s_free];
|
||||
unsigned int *freelist = (unsigned int *)(slab + 1);
|
||||
slab->s_free = freelist[slab->s_free];
|
||||
slab->s_obj_allocated++;
|
||||
|
||||
return slot;
|
||||
@@ -140,8 +142,10 @@ static unsigned int slab_allocate_slot(vm_slab_t *slab)
|
||||
static void slab_free_slot(vm_slab_t *slab, unsigned int slot)
|
||||
{
|
||||
unsigned int next = slab->s_free;
|
||||
unsigned int *freelist = (unsigned int *)(slab + 1);
|
||||
|
||||
slab->s_free = slot;
|
||||
slab->s_freelist[slot] = next;
|
||||
freelist[slot] = next;
|
||||
slab->s_obj_allocated--;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user