Compare commits

..

10 Commits

149 changed files with 693 additions and 2271 deletions

53
CMakeLists.txt Normal file
View File

@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.13)
project(mango C ASM)
if (NOT BUILD_TOOLS_DIR)
message(FATAL_ERROR "No build tools directory specified. Please run build.sh")
endif ()
set(CMAKE_C_STANDARD 17)
set(kernel_arch x86_64)
set(kernel_name "Mango")
set(kernel_exe_name "mango_kernel")
set(generic_src_dirs ds init kernel libc sched util vm)
set(kernel_sources "")
set(kernel_headers "")
foreach (dir ${generic_src_dirs})
message(STATUS ${dir})
file(GLOB_RECURSE dir_sources ${dir}/*.c)
file(GLOB_RECURSE dir_headers ${dir}/*.h)
set(kernel_sources ${kernel_sources} ${dir_sources})
set(kernel_headers ${kernel_headers} ${dir_headers})
endforeach (dir)
file(GLOB_RECURSE arch_sources_c arch/${kernel_arch}/*.c)
file(GLOB_RECURSE arch_sources_asm arch/${kernel_arch}/*.S)
file(GLOB_RECURSE arch_headers arch/${kernel_arch}/*.h)
set_property(SOURCE ${arch_sources_asm} PROPERTY LANGUAGE C)
add_executable(${kernel_exe_name}
${kernel_sources}
${kernel_headers}
${arch_sources_c}
${arch_sources_asm}
${arch_headers})
target_include_directories(${kernel_exe_name} PRIVATE
include
libc/include
arch/${kernel_arch}/include)
target_compile_options(${kernel_exe_name} PRIVATE
-nostdlib -ffreestanding
-Wall -Werror -pedantic -Wno-language-extension-token -Wno-unused-function -Wno-gnu-statement-expression
-O2 -g -fPIC -Iinclude -Iarch/${kernel_arch}/include -Ilibc/include)
target_link_libraries(${kernel_exe_name} -nostdlib -ffreestanding -lgcc)
target_compile_definitions(${kernel_exe_name} PRIVATE BUILD_ID="0")
include(arch/${kernel_arch}/config.cmake)
include(arch/${kernel_arch}/targets.cmake)

114
Makefile
View File

@@ -1,114 +0,0 @@
KERNEL_EXEC := socks_kernel
SOCKS_ARCH ?= x86_64
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
ROOT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
include tools/make/gcc-cross-compile.mk
BUILD_DIR := build
CONFIG_DIR := .config
####################################
# If the user has selected some kernel extensions to include
# in the kernel image, include the file that describes the
# extension source files to build
####################################
-include $(CONFIG_DIR)/extensions.mk
####################################
# Architecture-specific source files
####################################
include arch/$(SOCKS_ARCH)/config.mk
####################################
# Platform-independent kernel source files
####################################
KERNEL_SRC_DIRS := init kernel vm ds util obj sched test
KERNEL_C_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(shell find $(dir) -type f -name *.c))
KERNEL_CXX_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(shell find $(dir) -type f -name *.cpp))
KERNEL_OBJ := $(addprefix $(BUILD_DIR)/,$(KERNEL_C_FILES:.c=.o) $(KERNEL_CXX_FILES:.cpp=.o))
####################################
# Kernel libc source files
####################################
LIBC_SRC_DIRS := stdio string ctype
LIBC_C_FILES := $(foreach dir,$(LIBC_SRC_DIRS),$(shell find libc/$(dir) -type f -name *.c))
LIBC_OBJ := $(addprefix $(BUILD_DIR)/,$(LIBC_C_FILES:.c=.o))
BUILD_ID := $(shell tools/socks.buildid --arch $(SOCKS_ARCH))
CWARNINGS := -Wall -Werror -pedantic -Wno-language-extension-token -Wno-unused-function -Wno-gnu-statement-expression
OPTIMISATION_LEVEL := -O2
CFLAGS := $(CFLAGS) -DBUILD_ID=\"$(BUILD_ID)\" $(OPTIMISATION_LEVEL) -g -fPIC -std=gnu17 \
-Iinclude -Iarch/$(SOCKS_ARCH)/include -Ilibc/include $(CWARNINGS)
KERNEL_DEFINES := -DSOCKS_INTERNAL=1
CXXFLAGS := $(CXXFLAGS) -DBUILD_ID=\"$(BUILD_ID)\" $(OPTIMISATION_LEVEL) -g -fPIC -std=gnu++17 \
-Iinclude -Iarch/$(SOCKS_ARCH)/include -Ilibc/include -Wno-language-extension-token $(CWARNINGS)
ASMFLAGS := $(ASMFLAGS) -DBUILD_ID=\"$(BUILD_ID)\"
LDFLAGS := $(LDFLAGS) -g -lgcc $(OPTIMISATION_LEVEL)
ALL_KERNEL_OBJECT_FILES := $(KERNEL_OBJ) $(ARCH_OBJ) $(LIBC_OBJ)
ALL_KERNEL_DEPS := $(ALL_KERNEL_OBJECT_FILES:.o=.d)
all: $(BUILD_DIR)/$(KERNEL_EXEC) tools
-include $(ALL_KERNEL_DEPS)
$(BUILD_DIR)/$(KERNEL_EXEC): $(ALL_KERNEL_OBJECT_FILES)
@printf " \033[1;36mLD\033[0m \033[1mbuild/\033[35m$(KERNEL_EXEC)\033[0m\n"
@mkdir -p $(@D)
@$(LD) $^ -o $@ $(LDFLAGS) $(ARCH_LDFLAGS)
@cp $@ $@.dbg
@$(STRIP) $@
$(BUILD_DIR)/%.o: %.S
@printf " \033[1;32mAS\033[0m \033[35m$(KERNEL_EXEC)\033[0m/$<\n"
@mkdir -p $(@D)
@$(ASM) $< -o $@ -c $(ASMFLAGS) $(ARCH_ASMFLAGS) -MMD
$(BUILD_DIR)/%.o: %.c
@printf " \033[1;32mCC\033[0m \033[35m$(KERNEL_EXEC)\033[0m/$<\n"
@mkdir -p $(@D)
@$(CC) $< -o $@ -c $(CFLAGS) $(ARCH_CFLAGS) -MMD $(KERNEL_DEFINES)
$(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_CFLAGS) -MMD $(KERNEL_DEFINES)
clean:
@printf " \033[1;93mRM\033[0m Deleting build files.\n"
@rm -rf $(BUILD_DIR)
$(BUILD_DIR)/compile_commands.json:
@printf " \033[1;93mGEN\033[0m Generating compiler database.\n"
@./tools/socks.compiledb
cd: $(BUILD_DIR)/socks-kernel.iso
install-cd: $(BUILD_DIR)/socks-kernel.iso
@./tools/socks.install-cd
compile-db: $(BUILD_DIR)/compile_commands.json
tools:
@$(MAKE) -C tools
include arch/$(SOCKS_ARCH)/extra.mk
.PHONY: all tools compile-db $(BUILD_DIR)/compile_commands.json
.INTERMEDIATE: $(ARCH_TEMP_FILES)

2
README
View File

@@ -1,4 +1,4 @@
Socks
Mango
=====
It's a kernel!

View File

@@ -1,18 +0,0 @@
LD := gcc
CC := gcc
ASM := gcc
OBJCOPY := objcopy
STRIP := strip
CFLAGS :=
ASMFLAGS := $(CFLAGS)
LDFLAGS :=
ARCH_CFLAGS := -D_64BIT
ARCH_LDFLAGS :=
ARCH_DIR := arch/$(SOCKS_ARCH)
ARCH_C_FILES := $(wildcard $(ARCH_DIR)/*.c) $(wildcard $(ARCH_DIR)/acpi/*.c)
ARCH_ASM_FILES := $(wildcard $(ARCH_DIR)/*.S) $(wildcard $(ARCH_DIR)/acpi/*.S)
ARCH_OBJ := $(addprefix $(BUILD_DIR)/,$(ARCH_C_FILES:.c=.o) $(ARCH_ASM_FILES:.S=.o))

View File

@@ -1,5 +1,5 @@
#include <unistd.h>
#include <socks/machine/cpu.h>
#include <mango/machine/cpu.h>
int ml_init_bootcpu(void)
{

View File

@@ -1,13 +0,0 @@
run: $(BUILD_DIR)/$(KERNEL_EXEC)
@printf " \033[1;93mEXEC\033[0m $<\n"
@$(BUILD_DIR)/$(KERNEL_EXEC)
debug: $(BUILD_DIR)/$(KERNEL_EXEC) $(BUILD_DIR)/$(KERNEL_EXEC).dbg
@if command -v gdb &> /dev/null; then \
gdb -tui $(BUILD_DIR)/$(KERNEL_EXEC).dbg; \
elif command -v lldb &> /dev/null; then \
lldb -- $(BUILD_DIR)/$(KERNEL_EXEC).dbg; \
else \
printf "No debuggers available.\n"; \
fi

View File

@@ -1,5 +1,5 @@
#include <socks/machine/hwlock.h>
#include <socks/compiler.h>
#include <mango/machine/hwlock.h>
#include <mango/compiler.h>
void ml_hwlock_lock(ml_hwlock_t *lck)
{

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_USER_CPU_H_
#define SOCKS_USER_CPU_H_
#ifndef MANGO_USER_CPU_H_
#define MANGO_USER_CPU_H_
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_USER_HWLOCK_H_
#define SOCKS_USER_HWLOCK_H_
#ifndef MANGO_USER_HWLOCK_H_
#define MANGO_USER_HWLOCK_H_
#define ML_HWLOCK_INIT (0)

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_INIT_H_
#define SOCKS_X86_64_INIT_H_
#ifndef MANGO_X86_64_INIT_H_
#define MANGO_X86_64_INIT_H_
#include <stdint.h>

View File

@@ -0,0 +1,5 @@
#ifndef MANGO_X86_64_IRQ_H_
#define MANGO_X86_64_IRQ_H_
#endif

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_USER_PMAP_H_
#define SOCKS_USER_PMAP_H_
#ifndef MANGO_USER_PMAP_H_
#define MANGO_USER_PMAP_H_
typedef uintptr_t ml_pmap_t;
typedef uint64_t ml_pfn_t;

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_USER_VM_H_
#define SOCKS_USER_VM_H_
#ifndef MANGO_USER_VM_H_
#define MANGO_USER_VM_H_
#include <stdint.h>

View File

@@ -1,5 +0,0 @@
#ifndef SOCKS_X86_64_IRQ_H_
#define SOCKS_X86_64_IRQ_H_
#endif

View File

@@ -1,11 +1,11 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <socks/init.h>
#include <socks/memblock.h>
#include <socks/vm.h>
#include <socks/object.h>
#include <socks/printk.h>
#include <mango/init.h>
#include <mango/memblock.h>
#include <mango/vm.h>
#include <mango/object.h>
#include <mango/printk.h>
#include <arch/stdcon.h>
#include <sys/mman.h>

View File

@@ -1,4 +1,4 @@
#include <socks/init.h>
#include <mango/init.h>
#ifdef __APPLE__
extern char __start_initcall0[] __asm("section$start$__DATA$__initcall0.init");

View File

@@ -1,10 +1,10 @@
#include <socks/libc/string.h>
#include <socks/libc/ctype.h>
#include <mango/libc/string.h>
#include <mango/libc/ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <socks/console.h>
#include <socks/vm.h>
#include <socks/printk.h>
#include <mango/console.h>
#include <mango/vm.h>
#include <mango/printk.h>
static void stdcon_write(struct console *con, const char *s, unsigned int len)
{

View File

@@ -1,5 +1,5 @@
#include <socks/sched.h>
#include <socks/compiler.h>
#include <mango/sched.h>
#include <mango/compiler.h>
//size_t THREAD_sp = offsetof(struct thread, tr_sp);

10
arch/x86_64/config.cmake Normal file
View File

@@ -0,0 +1,10 @@
target_compile_options(${kernel_exe_name} PRIVATE
-z max-page-size=0x1000 -m64 -mcmodel=large -mno-red-zone -mno-mmx
-mno-sse -mno-sse2 -D_64BIT -DBYTE_ORDER=1234)
target_link_libraries(${kernel_exe_name} "-z max-page-size=0x1000" "-T ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86_64/layout.ld")
add_custom_command(TARGET ${kernel_exe_name} POST_BUILD
COMMAND ${BUILD_TOOLS_DIR}/e64patch $<TARGET_FILE:${kernel_exe_name}>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Patching kernel elf64 image"
)

View File

@@ -1,21 +0,0 @@
LD := $(SOCKS_ARCH)-elf-gcc
CC := $(SOCKS_ARCH)-elf-gcc
CXX := $(SOCKS_ARCH)-elf-g++
ASM := $(SOCKS_ARCH)-elf-gcc
OBJCOPY := $(SOCKS_ARCH)-elf-objcopy
STRIP := $(SOCKS_ARCH)-elf-strip
CFLAGS := -ffreestanding -nostdlib
CXXFLAGS := $(CFLAGS)
ASMFLAGS := $(CFLAGS)
LDFLAGS := -nostdlib
ARCH_CFLAGS := -z max-page-size=0x1000 -m64 -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -D_64BIT -DBYTE_ORDER=1234
ARCH_LDFLAGS := -z max-page-size=0x1000 -T arch/x86_64/layout.ld
ARCH_DIR := arch/$(SOCKS_ARCH)
ARCH_C_FILES := $(wildcard $(ARCH_DIR)/*.c) $(wildcard $(ARCH_DIR)/acpi/*.c)
ARCH_CXX_FILES := $(wildcard $(ARCH_DIR)/*.cpp) $(wildcard $(ARCH_DIR)/acpi/*.cpp)
ARCH_ASM_FILES := $(wildcard $(ARCH_DIR)/*.S) $(wildcard $(ARCH_DIR)/acpi/*.S)
ARCH_OBJ := $(addprefix $(BUILD_DIR)/,$(ARCH_C_FILES:.c=.o) $(ARCH_CXX_FILES:.cpp=.o) $(ARCH_ASM_FILES:.S=.o))

View File

@@ -1,4 +1,4 @@
#include <socks/machine/cpu.h>
#include <mango/machine/cpu.h>
#include <arch/msr.h>
int ml_cpu_block_init(ml_cpu_block *p)

View File

@@ -1,7 +1,7 @@
#include "socks/types.h"
#include <socks/memblock.h>
#include <socks/printk.h>
#include <socks/util.h>
#include "mango/types.h"
#include <mango/memblock.h>
#include <mango/printk.h>
#include <mango/util.h>
#include <arch/e820.h>
void e820_scan(multiboot_memory_map_t *mmap, size_t len)

View File

@@ -1,64 +0,0 @@
QEMU := qemu-system-x86_64
#QEMU_MONITOR_FLAGS := -serial file:$(BUILD_DIR)socks.log -monitor stdio
QEMU_MONITOR_FLAGS := -serial stdio
QEMU_FLAGS := \
-m 10M \
-display sdl \
-smp 4 -cpu qemu64,pdpe1gb
ARCH_TEMP_FILES := $(BUILD_DIR)/$(KERNEL_EXEC).elf32
# qemu refuses to boot ELF64 binaries. this creates a patched version of the kernel
# binary to trick qemu into thinking its an ELF32.
# this has no effect on the kernel itself; the x86_64 kernel's
# entry point is 32-bit machine code.
$(BUILD_DIR)/$(KERNEL_EXEC).elf32: $(BUILD_DIR)/$(KERNEL_EXEC)
@cp $(BUILD_DIR)/$(KERNEL_EXEC) $(BUILD_DIR)/$(KERNEL_EXEC).elf32
$(BUILD_DIR)/tools/e64patch/e64patch $(BUILD_DIR)/$(KERNEL_EXEC).elf32
$(BUILD_DIR)/socks-kernel.iso: $(BUILD_DIR)/$(KERNEL_EXEC)
@$(BUILD_DIR)/../tools/socks.mkrescue
run: $(BUILD_DIR)/$(KERNEL_EXEC) $(BUILD_DIR)/$(KERNEL_EXEC).elf32
@printf " \033[1;93mQEMU\033[0m $<\n"
@$(QEMU) -kernel $(BUILD_DIR)/$(KERNEL_EXEC).elf32 $(QEMU_FLAGS) $(QEMU_MONITOR_FLAGS)
run-curses: $(BUILD_DIR)/$(KERNEL_EXEC) $(BUILD_DIR)/$(KERNEL_EXEC).elf32
@printf " \033[1;93mQEMU\033[0m $<\n"
@$(QEMU) -kernel $(BUILD_DIR)/$(KERNEL_EXEC).elf32 $(QEMU_FLAGS) $(QEMU_MONITOR_FLAGS)
run-cd-curses: $(BUILD_DIR)/socks-kernel.iso
@printf " \033[1;93mQEMU\033[0m $<\n"
@$(QEMU) -cdrom $(BUILD_DIR)/socks-kernel.iso $(QEMU_FLAGS) -display curses -serial file:$(BUILD_DIR)/socks.log
debug: $(BUILD_DIR)/$(KERNEL_EXEC) $(BUILD_DIR)/$(KERNEL_EXEC).elf32
@./tools/kernel-debug/debug_session.sh \
tools/kernel-debug/gdb_session_init \
tools/kernel-debug/lldb_session_init \
$(QEMU) \
-kernel $(BUILD_DIR)/$(KERNEL_EXEC).elf32 -S -s \
-monitor stdio -serial file:$(BUILD_DIR)/socks.log $(QEMU_FLAGS)
debug-curses: $(BUILD_DIR)/$(KERNEL_EXEC) $(BUILD_DIR)/$(KERNEL_EXEC).elf32
@./tools/kernel-debug/debug_session.sh \
tools/kernel-debug/gdb_session_init \
tools/kernel-debug/lldb_session_init \
$(QEMU) \
-kernel $(BUILD_DIR)/$(KERNEL_EXEC).elf32 -S -s \
-display curses -serial file:$(BUILD_DIR)/socks.log $(QEMU_FLAGS) > build/qemu.log
debug-cd-curses: $(BUILD_DIR)/socks-kernel.iso
@./tools/kernel-debug/debug_session.sh \
tools/kernel-debug/gdb_session_init \
tools/kernel-debug/lldb_session_init \
$(QEMU) \
-cdrom $(BUILD_DIR)/socks-kernel.iso -S -s \
-display curses -serial file:$(BUILD_DIR)/socks.log $(QEMU_FLAGS) > build/qemu.log
run-bochs: $(BUILD_DIR)/socks-kernel.iso
@printf " \033[1;93mBOCHS\033[0m $<\n"
@bochs -f $(BUILD_DIR)/../tools/bochsrc.bxrc

View File

@@ -1,4 +1,4 @@
#include <socks/libc/string.h>
#include <mango/libc/string.h>
#include <arch/gdt.h>
static void init_entry(struct gdt_entry *entry, int access, int flags)

View File

@@ -1,7 +1,7 @@
#ifndef ARCH_GDT_H_
#define ARCH_GDT_H_
#include <socks/compiler.h>
#include <mango/compiler.h>
#include <stdint.h>
#ifdef __cplusplus

View File

@@ -1,8 +1,8 @@
#ifndef ARCH_IRQ_H_
#define ARCH_IRQ_H_
#include <socks/compiler.h>
#include <socks/queue.h>
#include <mango/compiler.h>
#include <mango/queue.h>
#include <stdint.h>
#ifdef __cplusplus

View File

@@ -1,8 +1,8 @@
#ifndef ARCH_PAGING_H_
#define ARCH_PAGING_H_
#include <socks/types.h>
#include <socks/compiler.h>
#include <mango/types.h>
#include <mango/compiler.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_CPU_H_
#define SOCKS_X86_64_CPU_H_
#ifndef MANGO_X86_64_CPU_H_
#define MANGO_X86_64_CPU_H_
#include <arch/gdt.h>
#include <arch/irq.h>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_HWLOCK_H_
#define SOCKS_X86_64_HWLOCK_H_
#ifndef MANGO_X86_64_HWLOCK_H_
#define MANGO_X86_64_HWLOCK_H_
#define ML_HWLOCK_INIT (0)

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_INIT_H_
#define SOCKS_X86_64_INIT_H_
#ifndef MANGO_X86_64_INIT_H_
#define MANGO_X86_64_INIT_H_
#include <stdint.h>

View File

@@ -0,0 +1,5 @@
#ifndef MANGO_X86_64_IRQ_H_
#define MANGO_X86_64_IRQ_H_
#endif

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_PANIC_H_
#define SOCKS_X86_64_PANIC_H_
#ifndef MANGO_X86_64_PANIC_H_
#define MANGO_X86_64_PANIC_H_
#include <stdint.h>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_PMAP_H_
#define SOCKS_X86_64_PMAP_H_
#ifndef MANGO_X86_64_PMAP_H_
#define MANGO_X86_64_PMAP_H_
#include <arch/paging.h>

View File

@@ -1,7 +1,7 @@
#ifndef SOCKS_X86_64_THREAD_H_
#define SOCKS_X86_64_THREAD_H_
#ifndef MANGO_X86_64_THREAD_H_
#define MANGO_X86_64_THREAD_H_
#include <socks/sched.h>
#include <mango/sched.h>
extern void switch_to(struct thread *from, struct thread *to);
extern void prepare_stack(uintptr_t ip, uintptr_t *sp);

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_X86_64_VM_H_
#define SOCKS_X86_64_VM_H_
#ifndef MANGO_X86_64_VM_H_
#define MANGO_X86_64_VM_H_
/* kernel higher-half base virtual address. */
#define VM_KERNEL_VOFFSET 0xFFFFFFFF80000000

View File

@@ -1,5 +0,0 @@
#ifndef SOCKS_X86_64_IRQ_H_
#define SOCKS_X86_64_IRQ_H_
#endif

View File

@@ -2,20 +2,20 @@
#include <arch/e820.h>
#include <arch/pit.h>
#include <socks/arg.h>
#include <socks/clock.h>
#include <socks/console.h>
#include <socks/cpu.h>
#include <socks/init.h>
#include <socks/libc/stdio.h>
#include <socks/machine/cpu.h>
#include <socks/memblock.h>
#include <socks/object.h>
#include <socks/percpu.h>
#include <socks/pmap.h>
#include <socks/printk.h>
#include <socks/types.h>
#include <socks/vm.h>
#include <mango/arg.h>
#include <mango/clock.h>
#include <mango/console.h>
#include <mango/cpu.h>
#include <mango/init.h>
#include <mango/libc/stdio.h>
#include <mango/machine/cpu.h>
#include <mango/memblock.h>
#include <mango/object.h>
#include <mango/percpu.h>
#include <mango/pmap.h>
#include <mango/printk.h>
#include <mango/types.h>
#include <mango/vm.h>
#define PTR32(x) ((void *)((uintptr_t)(x)))

View File

@@ -1,4 +1,4 @@
#include <socks/init.h>
#include <mango/init.h>
extern char __initcall0_start[];
extern char __initcall1_start[];

View File

@@ -1,11 +1,11 @@
#include <arch/irq.h>
#include <arch/ports.h>
#include <socks/cpu.h>
#include <socks/libc/string.h>
#include <socks/machine/cpu.h>
#include <socks/machine/irq.h>
#include <socks/panic.h>
#include <socks/sched.h>
#include <mango/cpu.h>
#include <mango/libc/string.h>
#include <mango/machine/cpu.h>
#include <mango/machine/irq.h>
#include <mango/panic.h>
#include <mango/sched.h>
#include <stddef.h>
#define MAX_ISR_HANDLERS 16

View File

@@ -1,7 +1,7 @@
#include "socks/machine/panic.h"
#include "socks/vm.h"
#include <socks/printk.h>
#include <socks/libc/stdio.h>
#include "mango/machine/panic.h"
#include "mango/vm.h"
#include <mango/printk.h>
#include <mango/libc/stdio.h>
#include <arch/irq.h>
#define R_CF 0

View File

@@ -1,8 +1,8 @@
#include <arch/irq.h>
#include <arch/ports.h>
#include <socks/clock.h>
#include <socks/cpu.h>
#include <socks/printk.h>
#include <mango/clock.h>
#include <mango/cpu.h>
#include <mango/printk.h>
#define PIT_COUNTER0 0x40
#define PIT_CMD 0x43

View File

@@ -1,10 +1,10 @@
#include <socks/types.h>
#include <socks/memblock.h>
#include <socks/vm.h>
#include <socks/printk.h>
#include <socks/status.h>
#include <socks/compiler.h>
#include <socks/pmap.h>
#include <mango/types.h>
#include <mango/memblock.h>
#include <mango/vm.h>
#include <mango/printk.h>
#include <mango/status.h>
#include <mango/compiler.h>
#include <mango/pmap.h>
/* some helpful datasize constants */
#define C_1GiB 0x40000000ULL

View File

@@ -1,11 +1,8 @@
#include <arch/irq.h>
#include <arch/ports.h>
#include <arch/serial.h>
#include <socks/device.h>
#include <socks/kext.h>
#include <socks/libc/stdio.h>
#include <socks/printk.h>
#include <socks/tty.h>
#include <mango/libc/stdio.h>
#include <mango/printk.h>
#define COM1 0x3F8
#define COM2 0x2F8

View File

@@ -0,0 +1,7 @@
find_program(QEMU qemu-system-x86_64)
add_custom_target(run
USES_TERMINAL
COMMAND ${QEMU}
-kernel $<TARGET_FILE:${kernel_exe_name}>
-serial stdio)

View File

@@ -1,4 +1,4 @@
#include <socks/machine/thread.h>
#include <mango/machine/thread.h>
struct thread_ctx {
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;

View File

@@ -0,0 +1,18 @@
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Mango)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER x86_64-elf-gcc)
set(CMAKE_ASM_COMPILER x86_64-elf-gcc)
set(CMAKE_CXX_COMPILER x86_64-elf-g++)
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

39
build.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
arch=$1
tools_src_dir="$(pwd)/tools"
kernel_src_dir="$(pwd)"
tools_build_dir="$(pwd)/build/tools"
kernel_build_dir="$(pwd)/build"
bin_dir="$kernel_build_dir/bin"
lib_dir="$kernel_build_dir/lib"
if [[ -z "$arch" ]]; then
echo "No architecture specified."
exit -1
fi
rm -rf $kernel_build_dir
mkdir -p $tools_build_dir
mkdir -p $kernel_build_dir
pushd $tools_build_dir
cmake \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY="$bin_dir" \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="$lib_dir" \
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="$lib_dir" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
$tools_src_dir
ninja
popd
pushd $kernel_build_dir
cmake \
-DBUILD_TOOLS_DIR="$bin_dir" \
-DCMAKE_TOOLCHAIN_FILE="$kernel_src_dir/arch/$arch/toolchain.cmake" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
$kernel_src_dir
ninja
popd

59
doc/kernel-interface.txt Executable file
View File

@@ -0,0 +1,59 @@
=== KERNEL TYPES ====
kern_handle_t
kern_status_t
kern_txnid_t
kern_clock_t
kern_msg_t
=== KERNEL ENUMS ====
kern_status_t:
KERN_SUCCESS
KERN_BAD_HANDLE
clockid_t:
CLOCK_REALTIME
CLOCK_MONOTONIC
=== KERNEL STRUCTS ====
kern_msg_t {
void *buf;
size_t len;
kern_handle_t *handles;
size_t nhandles
}
=== KERNEL OBJECTS ====
port
timer
address_space
page_buf
task
thread
event
=== KERNEL SYSTEM CALLS ====
handle_close
port_create
port_publish
port_connect
msg_send
msg_recv
msg_read
msg_write
timer_create
timer_arm
clock_gettime
task_get
task_move_handle

View File

@@ -1,109 +0,0 @@
=================
THE OBJECT SYSTEM
=================
Objects are the primary means of managing and controlling access to
user-facing resources a uniform way. This document provides an
overview of the object system in the Socks kernel, including:
1. Object Layout and Definition.
2. The Object Lifecycle.
3. Object Operations and Conventions.
4. References and Handles.
5. Attributes.
Object Layout and Definition
============================
An object is made up of two distinct halves: the **header** and the
**data**. The header contains bookkeeping data used by the object
system, while the data is the programmer-defined part of the object,
and can be used however the object-creator wants.
Object behaviour is defined by a `struct object_type` instance.
A `struct object_type` provides the object system with all the information
it needs to instantiate and interact with your objects.
The Object Header
-----------------
The object header is defined in `include/socks/object.h` as `struct object`.
It contains information that is used by the object system, and typically
should not be directly accessed outside of the object system.
The contents of the object header include:
* `ob_magic`: A magic value used to identify active objects.
Functions that retrieve an object's header from its data (and vice versa)
do not have type checking (i.e. they convert between `struct object *` and `void *`
using simple pointer arithmetic), so checking for this magic number helps
protect against non-objects being passed to functions expecting objects.
* `ob_type`: A pointer to the `struct object_type` that was used to create the
object. Outside of the object system, this can be used as a read-only
way to query type information about an object.
* `ob_lock`: A general-purpose per-object lock. This lock is *not* reserved
for the object system to use, and can be used by the programmer. You
can lock and unlock an object by using `object_lock()` and `object_unlock()`
respectively.
* `ob_refcount` and `ob_handles`: The number of kernel references and open
handles to an object. See :ref:`References and Handles` for more details.
* `ob_attrib`: A list of attributes that are accessible for this object.
See :ref:`Attributes` for more details.
* `ob_list`: A general-purpose queue entry for adding the object to a linked
list. Note that some internal object types (such as `set`) make use of this
queue entry.
When defining a C structure for use when creating objects, you should
define a member of type `struct object` somewhere within the structure.
It does not have to be the first member in the struct. The object system
provides a number of macros to simplify converting a `struct object *`
to a pointer of your structure.
The Object Type
---------------
The object type defines the name, size, and behaviour of an object.
It is defined using the `struct object_type` C structure.
Some notable parts of `struct object_type` include:
* `ob_name`: Human-readable name of the object type. For example:
"namespace", "set", "task", etc.
* `ob_size`: The length of the data section of the object in bytes.
* `ob_cache`: An instance of `struct vm_cache` from which objects of this
type are allocated. This cache is initialised and managed by the
object system on behalf of the programmer, so this can be ignored
outside of the object system.
* `ob_list`: A queue entry used internally by the object system.
* `ob_attrib`: A list of object attributes defined for objects of
this type.
* `ob_ops`: A set of function pointers that are used by the object
system to interact with the object. See
:ref:`Object Operations and Conventions` for more details.
The Object Lifecycle
====================
TODO
Object Operations and Conventions
=================================
TODO
References and Handles
======================
TODO
Attributes
==========
TODO

View File

@@ -1,5 +1,5 @@
#include <socks/libc/string.h>
#include <socks/bitmap.h>
#include <mango/libc/string.h>
#include <mango/bitmap.h>
void bitmap_zero(unsigned long *map, unsigned long nbits)
{

View File

@@ -57,7 +57,7 @@
provide a comparator function.
*/
#include <socks/btree.h>
#include <mango/btree.h>
#include <stddef.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))

View File

@@ -1,4 +1,4 @@
#include <socks/queue.h>
#include <mango/queue.h>
size_t queue_length(struct queue *q)
{

View File

@@ -1,5 +1,5 @@
#include <socks/ringbuffer.h>
#include <socks/sched.h>
#include <mango/ringbuffer.h>
#include <mango/sched.h>
size_t ringbuffer_unread(struct ringbuffer *ring_buffer)
{
@@ -45,7 +45,7 @@ static inline void increment_write(struct ringbuffer *ring_buffer)
}
}
size_t ringbuffer_read(struct ringbuffer *ring_buffer, size_t size, void *p, socks_flags_t flags)
size_t ringbuffer_read(struct ringbuffer *ring_buffer, size_t size, void *p, mango_flags_t flags)
{
if (!ring_buffer) {
return 0;
@@ -86,7 +86,7 @@ size_t ringbuffer_read(struct ringbuffer *ring_buffer, size_t size, void *p, soc
return collected;
}
size_t ringbuffer_write(struct ringbuffer *ring_buffer, size_t size, const void *p, socks_flags_t flags)
size_t ringbuffer_write(struct ringbuffer *ring_buffer, size_t size, const void *p, mango_flags_t flags)
{
if (!ring_buffer || !size) {
return 0;

View File

@@ -1,8 +1,8 @@
#ifndef SOCKS_ARG_H_
#define SOCKS_ARG_H_
#ifndef MANGO_ARG_H_
#define MANGO_ARG_H_
#include <stdbool.h>
#include <socks/status.h>
#include <mango/status.h>
#define CMDLINE_MAX 4096

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_BITMAP_H_
#define SOCKS_BITMAP_H_
#ifndef MANGO_BITMAP_H_
#define MANGO_BITMAP_H_
#include <stdbool.h>

View File

@@ -20,8 +20,8 @@
software without specific prior written permission.
*/
#ifndef SOCKS_BTREE_H_
#define SOCKS_BTREE_H_
#ifndef MANGO_BTREE_H_
#define MANGO_BTREE_H_
#include <stdint.h>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_CLOCK_H_
#define SOCKS_CLOCK_H_
#ifndef MANGO_CLOCK_H_
#define MANGO_CLOCK_H_
#include <stdint.h>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_COMPILER_H_
#define SOCKS_COMPILER_H_
#ifndef MANGO_COMPILER_H_
#define MANGO_COMPILER_H_
#ifdef __cplusplus
template <typename T>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_CONSOLE_H_
#define SOCKS_CONSOLE_H_
#ifndef MANGO_CONSOLE_H_
#define MANGO_CONSOLE_H_
/* The console system
@@ -14,9 +14,9 @@
representing a serial port may allow both sending AND receiving over the
port.
*/
#include <socks/queue.h>
#include <socks/locks.h>
#include <socks/status.h>
#include <mango/queue.h>
#include <mango/locks.h>
#include <mango/status.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,10 +1,10 @@
#ifndef SOCKS_CPU_H_
#define SOCKS_CPU_H_
#ifndef MANGO_CPU_H_
#define MANGO_CPU_H_
#include <socks/types.h>
#include <socks/machine/cpu.h>
#include <mango/types.h>
#include <mango/machine/cpu.h>
#include <stdint.h>
#include <socks/sched.h>
#include <mango/sched.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_FB_H_
#define SOCKS_FB_H_
#ifndef MANGO_FB_H_
#define MANGO_FB_H_
#include <stdint.h>

View File

@@ -1,11 +1,11 @@
#ifndef SOCKS_FLAGS_H_
#define SOCKS_FLAGS_H_
#ifndef MANGO_FLAGS_H_
#define MANGO_FLAGS_H_
#include <stdint.h>
typedef enum {
S_NORMAL = 0x00u,
S_NOBLOCK = 0x01u,
} socks_flags_t;
} mango_flags_t;
#endif

View File

@@ -1,8 +1,8 @@
#ifndef SOCKS_INIT_H_
#define SOCKS_INIT_H_
#ifndef MANGO_INIT_H_
#define MANGO_INIT_H_
#include <socks/compiler.h>
#include <socks/machine/init.h>
#include <mango/compiler.h>
#include <mango/machine/init.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,9 +1,9 @@
#ifndef SOCKS_INPUT_H_
#define SOCKS_INPUT_H_
#ifndef MANGO_INPUT_H_
#define MANGO_INPUT_H_
#include <stdint.h>
#include <socks/queue.h>
#include <socks/status.h>
#include <mango/queue.h>
#include <mango/status.h>
enum input_event_hook_flags {
INPUT_HOOK_SQUASH_EVENT = 0x01u,

View File

@@ -1,8 +1,8 @@
#ifndef SOCKS_LOCKS_H_
#define SOCKS_LOCKS_H_
#ifndef MANGO_LOCKS_H_
#define MANGO_LOCKS_H_
#include <socks/compiler.h>
#include <socks/machine/hwlock.h>
#include <mango/compiler.h>
#include <mango/machine/hwlock.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -19,12 +19,12 @@
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
*/
#ifndef SOCKS_MEMBLOCK_H_
#define SOCKS_MEMBLOCK_H_
#ifndef MANGO_MEMBLOCK_H_
#define MANGO_MEMBLOCK_H_
#include <stddef.h>
#include <limits.h>
#include <socks/types.h>
#include <mango/types.h>
#ifdef __cplusplus
extern "C" {

71
include/mango/object.h Normal file
View File

@@ -0,0 +1,71 @@
#ifndef MANGO_OBJECT_H_
#define MANGO_OBJECT_H_
#include <mango/flags.h>
#include <mango/locks.h>
#include <mango/status.h>
#include <mango/vm.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OBJECT_MAGIC 0xBADDCAFE
#define OBJECT_NAME_MAX 64
#define OBJECT_PATH_MAX 256
#define OBJECT_CAST(to_type, to_type_member, p) \
((to_type *)((uintptr_t)p) - offsetof(to_type, to_type_member))
#define OBJECT_C_CAST(c_type, c_type_member, obj_type, objp) \
OBJECT_IS_TYPE(objp, obj_type) \
? OBJECT_CAST(c_type, c_type_member, (objp)) : NULL
#define OBJECT_IS_TYPE(obj, type_ptr) ((obj)->ob_type == (type_ptr))
struct object;
struct object_attrib;
enum object_type_flags {
OBJTYPE_INIT = 0x01u,
};
struct object_ops {
kern_status_t (*destroy)(struct object *obj);
};
struct object_type {
enum object_type_flags ob_flags;
char ob_name[32];
unsigned int ob_size;
unsigned int ob_header_offset;
struct vm_cache ob_cache;
struct queue_entry ob_list;
struct object_ops ob_ops;
};
struct object {
uint32_t ob_magic;
struct object_type *ob_type;
spin_lock_t ob_lock;
unsigned int ob_refcount;
unsigned int ob_handles;
struct queue_entry ob_list;
} __aligned(sizeof(long));
extern kern_status_t object_bootstrap(void);
extern kern_status_t object_type_register(struct object_type *p);
extern kern_status_t object_type_unregister(struct object_type *p);
extern struct object *object_create(struct object_type *type);
extern struct object *object_ref(struct object *obj);
extern void object_deref(struct object *obj);
extern void object_lock(struct object *obj);
extern void object_unlock(struct object *obj);
extern void object_lock_irqsave(struct object *obj, unsigned long *flags);
extern void object_unlock_irqrestore(struct object *obj, unsigned long flags);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,7 +1,7 @@
#ifndef SOCKS_PANIC_H_
#define SOCKS_PANIC_H_
#ifndef MANGO_PANIC_H_
#define MANGO_PANIC_H_
#include <socks/compiler.h>
#include <mango/compiler.h>
struct cpu_context;

View File

@@ -1,9 +1,9 @@
#ifndef SOCKS_PERCPU_H_
#define SOCKS_PERCPU_H_
#ifndef MANGO_PERCPU_H_
#define MANGO_PERCPU_H_
#include <socks/status.h>
#include <socks/compiler.h>
#include <socks/sched.h>
#include <mango/status.h>
#include <mango/compiler.h>
#include <mango/sched.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,11 +1,11 @@
#ifndef SOCKS_PMAP_H_
#define SOCKS_PMAP_H_
#ifndef MANGO_PMAP_H_
#define MANGO_PMAP_H_
/* all the functions declared in this file are defined in arch/xyz/pmap.c */
#include <socks/vm.h>
#include <socks/status.h>
#include <socks/machine/pmap.h>
#include <mango/vm.h>
#include <mango/status.h>
#include <mango/machine/pmap.h>
#include <stddef.h>
#define PFN(x) ((x) >> VM_PAGE_SHIFT)

View File

@@ -1,7 +1,7 @@
#ifndef SOCKS_PRINTK_H_
#define SOCKS_PRINTK_H_
#ifndef MANGO_PRINTK_H_
#define MANGO_PRINTK_H_
#include <socks/console.h>
#include <mango/console.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,7 +1,7 @@
#ifndef SOCKS_QUEUE_H_
#define SOCKS_QUEUE_H_
#ifndef MANGO_QUEUE_H_
#define MANGO_QUEUE_H_
#include <socks/libc/string.h>
#include <mango/libc/string.h>
#include <stdbool.h>
#ifdef __cplusplus

View File

@@ -1,8 +1,8 @@
#ifndef SOCKS_RINGBUFFER_H_
#define SOCKS_RINGBUFFER_H_
#ifndef MANGO_RINGBUFFER_H_
#define MANGO_RINGBUFFER_H_
#include <socks/locks.h>
#include <socks/sched.h>
#include <mango/locks.h>
#include <mango/sched.h>
struct ringbuffer {
unsigned char *r_buffer;
@@ -22,8 +22,8 @@ extern kern_status_t ringbuffer_deinit(struct ringbuffer *buf);
extern size_t ringbuffer_unread(struct ringbuffer *buf);
extern size_t ringbuffer_avail(struct ringbuffer *buf);
extern size_t ringbuffer_read(struct ringbuffer *buf, size_t size, void *buffer, socks_flags_t flags);
extern size_t ringbuffer_write(struct ringbuffer *buf, size_t size, const void *buffer, socks_flags_t flags);
extern size_t ringbuffer_read(struct ringbuffer *buf, size_t size, void *buffer, mango_flags_t flags);
extern size_t ringbuffer_write(struct ringbuffer *buf, size_t size, const void *buffer, mango_flags_t flags);
/* TODO */
//extern size_t ringbuffer_peek(struct ringbuffer *buf, size_t at, size_t size, void *buffer);

View File

@@ -1,30 +1,31 @@
#ifndef SOCKS_SCHED_H_
#define SOCKS_SCHED_H_
#ifndef MANGO_SCHED_H_
#define MANGO_SCHED_H_
#include <socks/pmap.h>
#include <socks/locks.h>
#include <socks/queue.h>
#include <socks/object.h>
#include <socks/btree.h>
#include <socks/status.h>
#include <mango/btree.h>
#include <mango/locks.h>
#include <mango/object.h>
#include <mango/pmap.h>
#include <mango/queue.h>
#include <mango/status.h>
#define TASK_NAME_MAX 64
#define PRIO_MAX 32
#define TASK_NAME_MAX 64
#define PRIO_MAX 32
#define THREAD_KSTACK_ORDER VM_PAGE_4K
#define THREAD_MAX 65536
#define wait_event(wq, cond) \
({ \
struct thread *self = current_thread(); \
struct wait_item waiter; \
wait_item_init(&waiter, self); \
for (;;) { \
thread_wait_begin(&waiter, wq); \
if (cond) { \
break; \
} \
schedule(SCHED_NORMAL); \
} \
thread_wait_end(&waiter, wq); \
#define wait_event(wq, cond) \
({ \
struct thread *self = current_thread(); \
struct wait_item waiter; \
wait_item_init(&waiter, self); \
for (;;) { \
thread_wait_begin(&waiter, wq); \
if (cond) { \
break; \
} \
schedule(SCHED_NORMAL); \
} \
thread_wait_end(&waiter, wq); \
})
#ifdef __cplusplus
@@ -40,34 +41,34 @@ enum task_state {
};
enum thread_state {
THREAD_READY = 1,
THREAD_READY = 1,
THREAD_SLEEPING = 2,
THREAD_STOPPED = 3,
THREAD_STOPPED = 3,
};
enum thread_flags {
THREAD_F_NEED_RESCHED = 0x01u,
THREAD_F_NO_PREEMPT = 0x02u,
THREAD_F_NO_PREEMPT = 0x02u,
};
enum sched_priority {
PRIO_IDLE = 4,
PRIO_SUBNORMAL = 6,
PRIO_NORMAL = 10,
PRIO_IDLE = 4,
PRIO_SUBNORMAL = 6,
PRIO_NORMAL = 10,
PRIO_SUPERNORMAL = 14,
PRIO_HIGH = 18,
PRIO_REALTIME = 24,
PRIO_HIGH = 18,
PRIO_REALTIME = 24,
};
enum sched_mode {
/* used when calling from non-interrupt context.
threads that aren't in state THREAD_READY are
removed from the runqueue. */
SCHED_NORMAL = 0,
SCHED_NORMAL = 0,
/* used when calling from interrupt context.
threads that aren't in state THREAD_READY are
still added to the runqueue. */
SCHED_IRQ = 1,
SCHED_IRQ = 1,
};
struct task {
@@ -123,7 +124,7 @@ struct timer {
struct cpu_data *t_cpu;
struct thread *t_owner;
unsigned long t_expiry;
void(*t_callback)(struct timer *);
void (*t_callback)(struct timer *);
};
struct wait_item {
@@ -136,7 +137,7 @@ struct waitqueue {
spin_lock_t wq_lock;
};
typedef void(*work_func_t)(struct work_item *);
typedef void (*work_func_t)(struct work_item *);
struct work_item {
void *w_data;
@@ -174,8 +175,14 @@ extern void rq_remove_thread(struct runqueue *rq, struct thread *thr);
extern struct runqueue *cpu_rq(unsigned int cpu);
extern struct task *task_alloc(void);
static inline struct task *task_ref(struct task *task) { return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base)); }
static inline void task_deref(struct task *task) { object_deref(&task->t_base); }
static inline struct task *task_ref(struct task *task)
{
return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base));
}
static inline void task_deref(struct task *task)
{
object_deref(&task->t_base);
}
extern struct task *task_from_pid(unsigned int pid);
extern struct task *kernel_task(void);
extern struct task *idle_task(void);
@@ -196,7 +203,9 @@ static inline void task_lock_irqsave(struct task *task, unsigned long *flags)
object_lock_irqsave(&task->t_base, flags);
}
static inline void task_unlock_irqrestore(struct task *task, unsigned long flags)
static inline void task_unlock_irqrestore(
struct task *task,
unsigned long flags)
{
object_unlock_irqrestore(&task->t_base, flags);
}
@@ -205,7 +214,7 @@ extern struct thread *thread_alloc(void);
extern kern_status_t thread_init(struct thread *thr, uintptr_t ip);
extern int thread_priority(struct thread *thr);
extern void idle(void);
extern struct thread *create_kernel_thread(void(*fn)(void));
extern struct thread *create_kernel_thread(void (*fn)(void));
extern struct thread *create_idle_thread(void);
extern void add_timer(struct timer *timer);

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_STATUS_H_
#define SOCKS_STATUS_H_
#ifndef MANGO_STATUS_H_
#define MANGO_STATUS_H_
typedef unsigned int kern_status_t;

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_TEST_H_
#define SOCKS_TEST_H_
#ifndef MANGO_TEST_H_
#define MANGO_TEST_H_
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_TYPES_H_
#define SOCKS_TYPES_H_
#ifndef MANGO_TYPES_H_
#define MANGO_TYPES_H_
#include <stdint.h>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_UTIL_H_
#define SOCKS_UTIL_H_
#ifndef MANGO_UTIL_H_
#define MANGO_UTIL_H_
#include <stddef.h>
#include <stdint.h>

View File

@@ -1,14 +1,14 @@
#ifndef SOCKS_VM_H_
#define SOCKS_VM_H_
#ifndef MANGO_VM_H_
#define MANGO_VM_H_
#include <stddef.h>
#include <socks/types.h>
#include <socks/status.h>
#include <socks/queue.h>
#include <socks/btree.h>
#include <socks/bitmap.h>
#include <socks/locks.h>
#include <socks/machine/vm.h>
#include <mango/types.h>
#include <mango/status.h>
#include <mango/queue.h>
#include <mango/btree.h>
#include <mango/bitmap.h>
#include <mango/locks.h>
#include <mango/machine/vm.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,36 +0,0 @@
#ifndef SOCKS_BLOCK_H_
#define SOCKS_BLOCK_H_
#include <socks/types.h>
#include <socks/btree.h>
#include <socks/locks.h>
#include <socks/status.h>
#include <stdbool.h>
enum block_device_flags {
BLOCK_DEVICE_NO_BCACHE = 0x01u,
};
struct bcache {
unsigned int b_sector_size;
unsigned int b_sectors_per_page;
struct btree b_pagetree;
};
struct bcache_sector {
struct vm_page *sect_page;
unsigned int sect_index;
void *sect_buf;
bool sect_present;
};
extern struct bcache *bcache_create(unsigned int block_size);
extern void bcache_destroy(struct bcache *cache);
extern kern_status_t bcache_init(struct bcache *cache, unsigned int block_size);
extern void bcache_deinit(struct bcache *cache);
extern kern_status_t bcache_get(struct bcache *cache, sectors_t at, bool create, struct bcache_sector *out);
extern void bcache_mark_present(struct bcache_sector *sect);
#endif

View File

@@ -1,336 +0,0 @@
#ifndef SOCKS_DEVICE_H_
#define SOCKS_DEVICE_H_
#include <socks/queue.h>
#include <socks/btree.h>
#include <socks/status.h>
#include <socks/bitmap.h>
#include <socks/object.h>
#include <socks/block.h>
#include <socks/fb.h>
#include <socks/ringbuffer.h>
struct device;
struct input_event;
struct input_event_hook;
struct tty_device;
#define DEV_NAME_MAX OBJECT_NAME_MAX
#define DEV_MODEL_NAME_MAX 64
#define DEV_MAJOR_MAX 1024
#define DEV_MINOR_MAX 1024
#define DEV_MAJOR_INVALID ((unsigned int)0)
#define DEV_MINOR_INVALID ((unsigned int)0)
#define INPUT_DEVICE_EVENT_QUEUE_SIZE 128
#define INPUT_DEVICE_MAX 4096
#define BLOCK_DEVICE_MAX 4096
#define FRAMEBUFFER_DEVICE_MAX 4096
#define BLOCK_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_BLOCK ? &(dev)->blk : NULL)
#define CHAR_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_CHAR ? &(dev)->chr : NULL)
#define NET_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_NET ? &(dev)->net : NULL)
#define INPUT_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_INPUT ? &(dev)->input : NULL)
#define BUS_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_BUS ? &(dev)->bus : NULL)
#define FRAMEBUFFER_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_FRAMEBUFFER ? &(dev)->fb : NULL)
enum device_type {
DEV_TYPE_UNKNOWN = 0,
DEV_TYPE_BLOCK,
DEV_TYPE_CHAR,
DEV_TYPE_NET,
DEV_TYPE_INPUT,
DEV_TYPE_BUS,
DEV_TYPE_FRAMEBUFFER,
};
struct iovec {
void *io_buf;
size_t io_len;
};
struct device_type_ops {
kern_status_t(*read)(struct device *, void *, size_t, size_t, size_t *, socks_flags_t);
kern_status_t(*write)(struct device *, const void *, size_t, size_t, size_t *, socks_flags_t);
kern_status_t(*register_device)(struct device *);
};
struct block_device_ops {
kern_status_t(*read_blocks)(struct device *, sectors_t, size_t *, struct iovec *, size_t, socks_flags_t);
kern_status_t(*write_blocks)(struct device *, sectors_t, size_t *, struct iovec *, size_t, socks_flags_t);
kern_status_t(*ioctl)(struct device *, unsigned int, void *);
};
struct net_device_ops {
kern_status_t(*online)(struct device *);
kern_status_t(*offline)(struct device *);
kern_status_t(*transmit)(struct device *, const void *, size_t);
kern_status_t(*ioctl)(struct device *, unsigned int, void *);
};
struct char_device_ops {
kern_status_t(*read)(struct device *, void *, size_t, size_t, size_t *, socks_flags_t);
kern_status_t(*write)(struct device *, const void *, size_t, size_t, size_t *, socks_flags_t);
};
struct input_device_ops {
kern_status_t(*ioctl)(struct device *, unsigned int, void *);
};
struct bus_device_ops {
kern_status_t(*scan)(struct device *);
};
struct framebuffer_device_ops {
kern_status_t(*set_varinfo)(struct device *, const struct framebuffer_varinfo *);
};
struct block_device {
struct block_device_ops *b_ops;
struct bcache b_cache;
enum block_device_flags b_flags;
unsigned int b_id;
unsigned int b_sector_size;
sectors_t b_capacity;
};
struct char_device {
struct char_device_ops *c_ops;
/* only valid for TTY devices */
struct tty_device *c_tty;
};
struct net_device {
struct net_device_ops *n_ops;
};
struct input_device {
struct input_device_ops *i_ops;
unsigned int i_id;
struct ringbuffer i_events;
struct queue i_hooks;
};
struct bus_device {
struct queue_entry b_buslist;
struct bus_device_ops *b_ops;
};
struct framebuffer_device {
unsigned int fb_id;
struct framebuffer_device_ops *fb_ops;
struct framebuffer_varinfo fb_varinfo;
struct framebuffer_fixedinfo fb_fixedinfo;
};
struct device {
struct object dev_base;
unsigned int dev_minor;
enum device_type dev_type;
struct device *dev_parent;
struct driver *dev_owner;
struct queue dev_children;
struct queue_entry dev_childent;
struct btree_node dev_driverent;
char dev_name[DEV_NAME_MAX];
char dev_model_name[DEV_MODEL_NAME_MAX];
void *dev_bus_priv;
void *dev_priv;
union {
struct block_device blk;
struct char_device chr;
struct net_device net;
struct input_device input;
struct bus_device bus;
struct framebuffer_device fb;
};
};
struct driver;
struct driver_ops {
/* called when a bus driver finds a device for this driver to manage. */
kern_status_t(*bind)(struct driver *, struct device *, struct device *);
/* called when driver is registered. */
kern_status_t(*install)(struct driver *);
/* called when driver is unregistered. */
kern_status_t(*uninstall)(struct driver *);
};
struct driver {
struct kext *drv_owner;
unsigned int drv_major;
DECLARE_BITMAP(drv_minors, DEV_MINOR_MAX);
char drv_name[DEV_NAME_MAX];
struct btree drv_children;
struct btree_node drv_ent;
spin_lock_t drv_lock;
void *drv_priv;
struct driver_ops *drv_ops;
};
extern kern_status_t device_init(void);
extern struct device *root_device(void);
extern struct device *misc_device(void);
extern struct device *device_alloc(void);
static inline void device_lock(struct device *dev)
{
object_lock(&dev->dev_base);
}
static inline void device_unlock(struct device *dev)
{
object_unlock(&dev->dev_base);
}
static inline void device_lock_irqsave(struct device *dev, unsigned long *flags)
{
object_lock_irqsave(&dev->dev_base, flags);
}
static inline void device_unlock_irqrestore(struct device *dev, unsigned long flags)
{
object_unlock_irqrestore(&dev->dev_base, flags);
}
extern kern_status_t device_read(struct device *dev, void *buf, size_t offset, size_t size, size_t *bytes_read, socks_flags_t flags);
extern kern_status_t device_write(struct device *dev, const void *buf, size_t offset, size_t size, size_t *bytes_written, socks_flags_t flags);
extern struct device *cast_to_device(struct object *obj);
extern struct device *generic_device_create(void);
extern struct char_device *char_device_create(void);
extern struct block_device *block_device_create(void);
extern struct net_device *net_device_create(void);
extern struct input_device *input_device_create(void);
extern struct bus_device *bus_device_create(void);
extern struct framebuffer_device *framebuffer_device_create(void);
extern struct char_device *char_device_from_generic(struct device *dev);
extern struct block_device *block_device_from_generic(struct device *dev);
extern struct net_device *net_device_from_generic(struct device *dev);
extern struct input_device *input_device_from_generic(struct device *dev);
extern struct bus_device *bus_device_from_generic(struct device *dev);
extern struct framebuffer_device *framebuffer_device_from_generic(struct device *dev);
static inline struct device *char_device_base(struct char_device *dev)
{
return (struct device *)((char *)dev - offsetof(struct device, chr));
}
static inline struct device *block_device_base(struct block_device *dev)
{
return (struct device *)((char *)dev - offsetof(struct device, blk));
}
static inline struct device *net_device_base(struct net_device *dev)
{
return (struct device *)((char *)dev - offsetof(struct device, net));
}
static inline struct device *input_device_base(struct input_device *dev)
{
return (struct device *)((char *)dev - offsetof(struct device, input));
}
static inline struct device *bus_device_base(struct bus_device *dev)
{
return (struct device *)((char *)dev - offsetof(struct device, bus));
}
static inline struct device *framebuffer_device_base(struct framebuffer_device *dev)
{
return (struct device *)((char *)dev - offsetof(struct device, fb));
}
static inline struct object *char_device_object(struct char_device *dev)
{
return &char_device_base(dev)->dev_base;
}
static inline struct object *block_device_object(struct block_device *dev)
{
return &block_device_base(dev)->dev_base;
}
static inline struct object *net_device_object(struct net_device *dev)
{
return &net_device_base(dev)->dev_base;
}
static inline struct object *input_device_object(struct input_device *dev)
{
return &input_device_base(dev)->dev_base;
}
static inline struct object *bus_device_object(struct bus_device *dev)
{
return &bus_device_base(dev)->dev_base;
}
static inline struct object *framebuffer_device_object(struct framebuffer_device *dev)
{
return &framebuffer_device_base(dev)->dev_base;
}
extern kern_status_t device_register(struct device *dev, struct driver *owner, struct device *parent);
static inline struct device *device_ref(struct device *dev)
{
return cast_to_device(object_ref(&dev->dev_base));
}
static inline void device_deref(struct device *dev)
{
object_deref(&dev->dev_base);
}
extern kern_status_t input_device_report_event(struct input_device *dev, const struct input_event *ev, bool noblock);
extern kern_status_t input_device_read(struct device *dev, void *buf, size_t offset,
size_t size, size_t *bytes_read, socks_flags_t flags);
extern kern_status_t input_device_add_hook(struct device *dev, struct input_event_hook *hook);
extern kern_status_t input_device_remove_hook(struct device *dev, struct input_event_hook *hook);
extern struct driver *driver_create(struct kext *self, const char *name);
extern kern_status_t driver_destroy(struct driver *driver);
extern kern_status_t driver_init(struct driver *driver, struct kext *self, const char *name);
extern kern_status_t driver_deinit(struct driver *driver);
extern kern_status_t driver_register(struct driver *driver);
extern kern_status_t driver_unregister(struct driver *driver);
extern unsigned int driver_alloc_minor(struct driver *driver);
extern void driver_free_minor(struct driver *driver, unsigned int minor);
extern struct device *driver_get_device(struct driver *driver, unsigned int minor);
extern kern_status_t driver_add_device(struct driver *driver, struct device *dev);
extern kern_status_t driver_remove_device(struct driver *driver, struct device *dev);
extern struct driver *system_driver(void);
extern kern_status_t framebuffer_get_fixedinfo(struct device *dev, struct framebuffer_fixedinfo *out);
extern kern_status_t framebuffer_get_varinfo(struct device *dev, struct framebuffer_varinfo *out);
extern kern_status_t framebuffer_set_varinfo(struct device *dev, const struct framebuffer_varinfo *varinfo);
static inline void driver_lock(struct driver *driver)
{
spin_lock(&driver->drv_lock);
}
static inline void driver_unlock(struct driver *driver)
{
spin_unlock(&driver->drv_lock);
}
static inline void driver_lock_irqsave(struct driver *driver, unsigned long *flags)
{
spin_lock_irqsave(&driver->drv_lock, flags);
}
static inline void driver_unlock_irqrestore(struct driver *driver, unsigned long flags)
{
spin_unlock_irqrestore(&driver->drv_lock, flags);
}
extern kern_status_t scan_all_buses(void);
#endif

View File

@@ -1,99 +0,0 @@
#ifndef SOCKS_KEXT_H_
#define SOCKS_KEXT_H_
#include <socks/status.h>
#include <socks/object.h>
#include <socks/compiler.h>
#include <socks/btree.h>
#define KERNEL_KEXT_ID "net.doorstuck.socks-kernel"
#define KEXT_IDENT_MAX 80
#define KEXT_NO_DEPENDENCIES NULL
#define __KEXT_INFO_VARNAME_2(a, b) a ## b
#define __KEXT_INFO_VARNAME_1(a, b) __KEXT_INFO_VARNAME_2(a, b)
#ifdef SOCKS_INTERNAL
#define __KEXT_INFO_LINKAGE static
#define __KEXT_INFO_VARNAME() __KEXT_INFO_VARNAME_1(__kext_info, __LINE__)
#define __KEXT_INFO_DEPNAME() __KEXT_INFO_VARNAME_1(__kext_deps, __LINE__)
#define __KEXT_INFO_FLAGS KEXT_INTERNAL
#define __KEXT_INFO_ALIGNMENT 0x80
#else
#define __KEXT_INFO_LINKAGE
#define __KEXT_INFO_VARNAME() __kext_info
#define __KEXT_INFO_DEPNAME() __kext_deps
#define __KEXT_INFO_FLAGS KEXT_NONE
#define __KEXT_INFO_ALIGNMENT 0x80
#endif
#ifdef __cplusplus
#define DEFINE_KEXT(ident, online, offline, ...) \
static const char *__KEXT_INFO_DEPNAME()[] = { \
__VA_ARGS__, NULL \
}; \
static struct kext_info __section(".kextinfo") __aligned(__KEXT_INFO_ALIGNMENT) __used __KEXT_INFO_VARNAME() = { \
__KEXT_INFO_FLAGS, \
ident, \
online, \
offline, \
__KEXT_INFO_DEPNAME(), \
}
#else
#define DEFINE_KEXT(ident, online, offline, ...) \
static const char *__KEXT_INFO_DEPNAME()[] = { \
__VA_ARGS__, NULL \
}; \
static struct kext_info __section(".kextinfo") __aligned(__KEXT_INFO_ALIGNMENT) __used __KEXT_INFO_VARNAME() = { \
.k_flags = __KEXT_INFO_FLAGS, \
.k_ident = ident, \
.k_online = online, \
.k_offline = offline, \
.k_dependencies = __KEXT_INFO_DEPNAME(), \
}
#endif
struct kext;
enum kext_flags {
KEXT_NONE = 0x00u,
KEXT_INTERNAL = 0x01u,
KEXT_ONLINE = 0x02u,
};
struct kext_info {
enum kext_flags k_flags;
char k_ident[KEXT_IDENT_MAX];
kern_status_t(*k_online)(struct kext *);
kern_status_t(*k_offline)(struct kext *);
const char **k_dependencies;
};
struct kext {
struct object k_base;
enum kext_flags k_flags;
char k_ident[KEXT_IDENT_MAX];
uint64_t k_ident_hash;
struct btree_node k_node;
kern_status_t(*k_online)(struct kext *);
kern_status_t(*k_offline)(struct kext *);
unsigned int k_nr_dependencies;
struct kext **k_dependencies;
};
extern kern_status_t scan_internal_kexts(void);
extern kern_status_t bring_internal_kexts_online(void);
extern kern_status_t init_kernel_kext(void);
extern struct kext *kernel_kext(void);
extern kern_status_t kext_cache_init(void);
extern struct kext *kext_alloc(void);
extern void kext_release(struct kext *kext);
extern kern_status_t kext_register(struct kext *kext);
extern struct kext *kext_get_by_id(const char *ident);
extern kern_status_t kext_bring_online(struct kext *kext);
#endif

View File

@@ -1,118 +0,0 @@
#ifndef SOCKS_OBJECT_H_
#define SOCKS_OBJECT_H_
#include <socks/locks.h>
#include <socks/status.h>
#include <socks/flags.h>
#include <socks/vm.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OBJECT_MAGIC 0xBADDCAFE
#define OBJECT_NAME_MAX 64
#define OBJECT_PATH_MAX 256
#define OBJECT_CAST(to_type, to_type_member, p) \
((to_type *)((uintptr_t)p) - offsetof(to_type, to_type_member))
#define OBJECT_C_CAST(c_type, c_type_member, obj_type, objp) \
OBJECT_IS_TYPE(objp, obj_type) ? OBJECT_CAST(c_type, c_type_member, (objp)) : NULL
#define OBJECT_IS_TYPE(obj, type_ptr) \
((obj)->ob_type == (type_ptr))
struct object;
struct object_attrib;
enum object_type_flags {
OBJTYPE_INIT = 0x01u,
};
struct object_ops {
kern_status_t(*open)(struct object *obj);
kern_status_t(*close)(struct object *obj);
kern_status_t(*read)(struct object *obj, void *p, size_t off, size_t *r, socks_flags_t flags);
kern_status_t(*write)(struct object *obj, const void *p, size_t off, size_t *w, socks_flags_t flags);
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);
kern_status_t(*get_at)(struct object *obj, size_t at, struct object **out);
kern_status_t(*read_attrib)(struct object *obj, struct object_attrib *attrib, char *out, size_t max, size_t *r);
kern_status_t(*write_attrib)(struct object *obj, struct object_attrib *attrib, const char *s, size_t len, size_t *r);
};
struct object_attrib {
char *a_name;
struct queue_entry a_list;
};
struct object_type {
enum object_type_flags ob_flags;
char ob_name[32];
unsigned int ob_size;
unsigned int ob_header_offset;
struct vm_cache ob_cache;
struct queue_entry ob_list;
struct queue ob_attrib;
struct object_ops ob_ops;
};
struct object {
uint32_t ob_magic;
struct object_type *ob_type;
spin_lock_t ob_lock;
unsigned int ob_refcount;
unsigned int ob_handles;
struct queue ob_attrib;
struct queue_entry ob_list;
} __aligned(sizeof(long));
extern kern_status_t object_bootstrap(void);
extern kern_status_t object_type_register(struct object_type *p);
extern kern_status_t object_type_unregister(struct object_type *p);
extern struct object_namespace *global_namespace(void);
extern struct object_namespace *object_namespace_create(void);
extern struct object *ns_header(struct object_namespace *ns);
extern kern_status_t object_namespace_get_object(struct object_namespace *ns, const char *path, struct object **out);
extern kern_status_t object_namespace_create_link(struct object_namespace *ns, const char *linkpath, struct object *dest);
extern kern_status_t object_publish(struct object_namespace *ns, const char *path, struct object *obj);
extern kern_status_t object_unpublish(struct object_namespace *ns, struct object *obj);
extern struct object *object_create(struct object_type *type);
extern struct object *object_ref(struct object *obj);
extern void object_deref(struct object *obj);
extern void object_lock(struct object *obj);
extern void object_unlock(struct object *obj);
extern void object_lock_irqsave(struct object *obj, unsigned long *flags);
extern void object_unlock_irqrestore(struct object *obj, unsigned long flags);
static inline kern_status_t object_get(const char *path, struct object **out)
{
return object_namespace_get_object(global_namespace(), path, out);
}
extern kern_status_t object_read(struct object *obj, void *p, size_t offset, size_t max, size_t *nr_read, socks_flags_t flags);
extern kern_status_t object_write(struct object *obj, const void *p, size_t offset, size_t max, size_t *nr_written, socks_flags_t flags);
extern kern_status_t object_get_child_named(struct object *obj, const char *name, struct object **out);
extern kern_status_t object_get_child_at(struct object *obj, size_t at, struct object **out);
extern kern_status_t object_query_name(struct object *obj, char name[OBJECT_NAME_MAX]);
extern struct object *set_create(const char *name);
extern kern_status_t set_add_object(struct object *set, struct object *obj);
extern kern_status_t set_remove_object(struct object *set, struct object *obj);
extern bool object_is_set(struct object *obj);
extern struct object *link_create(const char *name, struct object *dest);
extern struct object *link_read_ptr(struct object *link);
extern bool object_is_link(struct object *obj);
extern void init_set_objects(void);
extern void init_link_objects(void);
extern void init_global_namespace(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,113 +0,0 @@
#ifndef SOCKS_TERMIOS_H_
#define SOCKS_TERMIOS_H_
#include <stdint.h>
#define NCCS 32
#define BRKINT 00000001
#define ICRNL 00000002
#define IGNBRK 00000004
#define IGNCR 00000010
#define IGNPAR 00000020
#define INLCR 00000040
#define INPCK 00000100
#define ISTRIP 00000200
#define IUCLC 00000400
#define IXANY 00001000
#define IXOFF 00002000
#define IXON 00004000
#define PARMRK 00010000
#define OPOST 00000001
#define OLCUC 00000002
#define ONLCR 00000004
#define OCRNL 00000010
#define ONOCR 00000020
#define ONLRET 00000040
#define NLDLY 00000100
#define NL0 00000000
#define NL1 00000100
#define OFILL 00000200
#define CRDLY 00003400
#define CR0 00000000
#define CR1 00000400
#define CR2 00001000
#define CR3 00002000
#define TABDLY 00034000
#define TAB0 00000000
#define TAB1 00004000
#define TAB2 00010000
#define TAB3 00020000
#define BSDLY 00040000
#define BS0 00000000
#define BS1 00040000
#define VTDLY 00100000
#define VT0 00000000
#define VT1 00100000
#define FFDLY 00200000
#define FF0 00000000
#define FF1 00200000
#define B0 0
#define B50 50
#define B75 75
#define B110 110
#define B134 134
#define B150 150
#define B200 200
#define B300 300
#define B600 600
#define B1200 1200
#define B1800 1800
#define B2400 2400
#define B4800 4800
#define B9600 9600
#define B19200 19200
#define B38400 38400
#define CSIZE 00000007
#define CS5 00000000
#define CS6 00000001
#define CS7 00000002
#define CS8 00000004
#define CSTOPB 00000010
#define CREAD 00000020
#define PARENB 00000040
#define PARODD 00000100
#define HUPCL 00000200
#define CLOCAL 00000400
#define ECHO 00000001
#define ECHOE 00000002
#define ECHOK 00000004
#define ECHONL 00000010
#define ICANON 00000020
#define IEXTEN 00000040
#define ISIG 00000100
#define NOFLSH 00000200
#define TOSTOP 00000400
#define XCASE 00001000
#define TCSANOW 1
#define TCSADRAIN 2
#define TCSAFLUSH 3
#define TCIFLUSH 1
#define TCOFLUSH 2
#define TCIOFLUSH (TCIFLUSH | TCOFLUSH)
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
typedef unsigned char cc_t;
struct termios {
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_line;
cc_t c_cc[NCCS];
};
#endif

View File

@@ -1,145 +0,0 @@
#ifndef SOCKS_TTY_H_
#define SOCKS_TTY_H_
#include <socks/status.h>
#include <socks/device.h>
#include <socks/queue.h>
#include <socks/object.h>
#include <socks/termios.h>
#include <stdint.h>
#define TTY_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_CHAR ? (dev)->chr.c_tty : NULL)
#define TTY_DRIVER(drv) ((struct tty_driver *)((char *)drv - offsetof(struct tty_driver, tty_base)))
#define TTY_INPUT_QUEUE_SIZE 256
#define TTY_LINE_MAX 4096
struct kext;
/* The TTY system.
TTYs are an enhanced version of the console object. Rather than a simple output
device for log messages, TTYs are intended to support fully-featured interactive
user sessions, including advanced display manipulation (if applicable) and
buffered user input.
A TTY object is split into 2 parts:
- struct tty: This represents the terminal session, and tracks things like the cursor
position, input buffer, flags, etc.
- struct tty_driver: This is a set of function callbacks that the TTY can use to
manipulate the output device. This could represent a char-based framebuffer
device, a serial port, etc.
*/
#ifdef __cplusplus
extern "C" {
#endif
enum tty_driver_type {
/* For TTYs operating on simple IO devices like serial ports.
Allows writing characters, receiving characters, and not much else. */
TTY_DRIVER_SIMPLE,
/* For TTYs operating on more capable display interfaces.
Allows putting characters at arbitrary locations, scrolling, etc */
TTY_DRIVER_FULL,
};
/* TTY cursor status. The extra cursor styles are just for completeness,
the important one to support (if possible), is TTY_CURSOR_NONE.
The others can be interpreted as "just turn on a cursor of any style". */
enum tty_cursor {
TTY_CURSOR_ULINE,
TTY_CURSOR_BLOCK,
TTY_CURSOR_NONE,
};
/* direction to use for scrolling. The important one to support is
TTY_SCROLL_DOWN for when output overflows the display */
enum tty_scroll_dir {
TTY_SCROLL_DOWN,
TTY_SCROLL_UP,
};
enum tty_modifier_key {
TTY_KEY_OTHER = 0x00u,
TTY_KEY_CTRL = 0x01u,
TTY_KEY_ALT = 0x02u,
TTY_KEY_SHIFT = 0x04u,
};
/* character attribute. this could be as simple as VGA's 16-colour palette
plus an extra bit for bright, or a full 24-bit RGB value with bold and underline
support, depending on what the driver supports. */
typedef uint64_t tty_attrib_t;
struct tty_driver_ops {
void (*tty_init)(struct device *dev);
void (*tty_deinit)(struct device *dev);
void (*tty_clear)(struct device *dev, int x, int y, int width, int height);
void (*tty_putc)(struct device *dev, int c, int xpos, int ypos, tty_attrib_t attrib);
void (*tty_set_cursor)(struct device *dev, enum tty_cursor cur);
void (*tty_move_cursor)(struct device *dev, int x, int y);
void (*tty_scroll)(struct device *dev, enum tty_scroll_dir dir, int lines);
};
struct tty_driver {
struct driver tty_base;
char tty_name[16];
enum tty_driver_type tty_type;
struct queue_entry tty_head;
struct tty_driver_ops *tty_ops;
};
struct tty_ldisc {
char name[OBJECT_NAME_MAX];
kern_status_t(*read)(struct device *, void *, size_t, size_t *, socks_flags_t);
void(*write)(struct device *, const struct input_event *);
};
struct tty_device {
unsigned int tty_xcells, tty_ycells;
unsigned int tty_xcur, tty_ycur;
struct termios tty_config;
tty_attrib_t tty_curattrib;
enum tty_modifier_key tty_modstate;
struct tty_ldisc *tty_ldisc;
/* input characters processed from tty_events, returned by tty_read() */
struct ringbuffer tty_input;
char *tty_linebuf;
};
extern void register_tty_console(void);
extern void redirect_printk_to_tty(struct device *dest);
extern kern_status_t tty_bootstrap(void);
extern struct tty_ldisc *tty_default_line_discipline(void);
extern struct device *tty_device_create(void);
extern kern_status_t tty_device_register(struct device *dev, struct tty_driver *owner, struct device *parent);
extern void tty_set_foreground(struct device *tty);
extern kern_status_t tty_connect_foreground_input_device(struct device *input);
extern struct tty_driver *tty_driver_create(struct kext *self, const char *name);
extern kern_status_t tty_driver_destroy(struct tty_driver *drv);
extern kern_status_t tty_driver_register(struct tty_driver *drv);
extern kern_status_t tty_driver_unregister(struct tty_driver *drv);
static inline struct driver *tty_driver_base(struct tty_driver *drv)
{
return &drv->tty_base;
}
extern kern_status_t tty_read(struct device *tty, void *buf, size_t offset, size_t max, size_t *nr_read, socks_flags_t flags);
extern kern_status_t tty_write(struct device *tty, const void *buf, size_t offset, size_t len, size_t *nr_written, socks_flags_t flags);
extern kern_status_t tty_report_event(struct device *tty, const struct input_event *ev);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,4 +1,4 @@
#include <socks/init.h>
#include <mango/init.h>
int do_initcalls(void)

View File

@@ -1,48 +1,52 @@
#include <socks/arg.h>
#include <socks/clock.h>
#include <socks/cpu.h>
#include <socks/device.h>
#include <socks/init.h>
#include <socks/input.h>
#include <socks/kext.h>
#include <socks/libc/stdio.h>
#include <socks/machine/init.h>
#include <socks/object.h>
#include <socks/panic.h>
#include <socks/printk.h>
#include <socks/sched.h>
#include <socks/test.h>
#include <socks/tty.h>
#include <mango/arg.h>
#include <mango/clock.h>
#include <mango/cpu.h>
#include <mango/init.h>
#include <mango/input.h>
#include <mango/libc/stdio.h>
#include <mango/machine/init.h>
#include <mango/object.h>
#include <mango/panic.h>
#include <mango/printk.h>
#include <mango/sched.h>
#include <mango/test.h>
#include <stdint.h>
#ifdef KEXT_NET_DOORSTUCK_SOCKS_FBCON
#include <socks/fbcon.h>
#endif
extern unsigned long get_rflags(void);
extern char __pstart[], __pend[];
void print_kernel_banner(void)
{
printk("Socks kernel version " BUILD_ID);
printk("Mango kernel version " BUILD_ID);
}
static void hang(void)
{
struct task *self = current_task();
struct thread *thread = current_thread();
while (1) {
printk("%d: tick", this_cpu());
printk("[cpu %u, task %u, thread %u]: tick",
this_cpu(),
self->t_id,
thread->tr_id);
milli_sleep(2000);
}
}
void background_thread(void)
{
struct task *self = current_task();
struct thread *thread = current_thread();
printk("background_thread() running on processor %u", this_cpu());
milli_sleep(1000);
while (1) {
printk("%d: tock", this_cpu());
printk("[cpu %u, task %u, thread %u]: tock",
this_cpu(),
self->t_id,
thread->tr_id);
milli_sleep(2000);
}
}

View File

@@ -1,6 +1,6 @@
#include <socks/arg.h>
#include <socks/libc/string.h>
#include <socks/libc/ctype.h>
#include <mango/arg.h>
#include <mango/libc/string.h>
#include <mango/libc/ctype.h>
static char g_cmdline[CMDLINE_MAX + 1] = {0};

View File

@@ -1,6 +1,6 @@
#include <socks/clock.h>
#include <socks/printk.h>
#include <socks/compiler.h>
#include <mango/clock.h>
#include <mango/printk.h>
#include <mango/compiler.h>
static clock_ticks_t ticks_per_sec = 0;
volatile clock_ticks_t clock_ticks = 0;

View File

@@ -1,7 +1,7 @@
#include <socks/console.h>
#include <socks/queue.h>
#include <socks/locks.h>
#include <socks/libc/string.h>
#include <mango/console.h>
#include <mango/queue.h>
#include <mango/locks.h>
#include <mango/libc/string.h>
static struct queue consoles;
static spin_lock_t consoles_lock = SPIN_LOCK_INIT;

View File

@@ -1,6 +1,6 @@
#include <socks/cpu.h>
#include <socks/percpu.h>
#include <socks/bitmap.h>
#include <mango/cpu.h>
#include <mango/percpu.h>
#include <mango/bitmap.h>
DECLARE_BITMAP(cpu_available, CPU_MAX);
DECLARE_BITMAP(cpu_online, CPU_MAX);

View File

@@ -1,6 +1,6 @@
#include <socks/object.h>
#include <socks/queue.h>
#include <socks/locks.h>
#include <mango/locks.h>
#include <mango/object.h>
#include <mango/queue.h>
#define HAS_OP(obj, opname) ((obj)->ob_type->ob_ops.opname)
@@ -9,9 +9,6 @@ static spin_lock_t object_types_lock = SPIN_LOCK_INIT;
kern_status_t object_bootstrap(void)
{
init_set_objects();
init_link_objects();
init_global_namespace();
return KERN_OK;
}
@@ -56,7 +53,8 @@ struct object *object_create(struct object_type *type)
memset(obj_buf, 0x00, type->ob_size);
struct object *obj = (struct object *)((unsigned char *)obj_buf + type->ob_header_offset);
struct object *obj = (struct object *)((unsigned char *)obj_buf
+ type->ob_header_offset);
obj->ob_type = type;
obj->ob_lock = SPIN_LOCK_INIT;
@@ -131,64 +129,3 @@ struct object *object_header(void *p)
return obj;
}
kern_status_t object_read(struct object *obj, void *p, size_t offset,
size_t max, size_t *nr_read, socks_flags_t flags)
{
kern_status_t status = KERN_UNSUPPORTED;
if (obj->ob_type->ob_ops.read) {
status = obj->ob_type->ob_ops.read(obj, p, offset, &max, flags);
} else {
max = 0;
}
if (nr_read) {
*nr_read = max;
}
return status;
}
kern_status_t object_write(struct object *obj, const void *p, size_t offset,
size_t max, size_t *nr_written, socks_flags_t flags)
{
kern_status_t status = KERN_UNSUPPORTED;
if (obj->ob_type->ob_ops.write) {
status = obj->ob_type->ob_ops.write(obj, p, offset, &max, flags);
}
return status;
}
kern_status_t object_get_child_named(struct object *obj, const char *name, struct object **out)
{
kern_status_t status = KERN_UNSUPPORTED;
if (HAS_OP(obj, get_named)) {
status = obj->ob_type->ob_ops.get_named(obj, name, out);
}
return status;
}
kern_status_t object_get_child_at(struct object *obj, size_t at, struct object **out)
{
kern_status_t status = KERN_UNSUPPORTED;
if (HAS_OP(obj, get_at)) {
status = obj->ob_type->ob_ops.get_at(obj, at, out);
}
return status;
}
kern_status_t object_query_name(struct object *obj, char name[OBJECT_NAME_MAX])
{
if (HAS_OP(obj, query_name)) {
return obj->ob_type->ob_ops.query_name(obj, name);
}
return KERN_UNSUPPORTED;
}

View File

@@ -1,9 +1,9 @@
#include <stdarg.h>
#include <socks/machine/panic.h>
#include <socks/libc/stdio.h>
#include <socks/printk.h>
#include <socks/sched.h>
#include <socks/cpu.h>
#include <mango/machine/panic.h>
#include <mango/libc/stdio.h>
#include <mango/printk.h>
#include <mango/sched.h>
#include <mango/cpu.h>
static int has_panicked = 0;

View File

@@ -1,6 +1,6 @@
#include <socks/percpu.h>
#include <socks/cpu.h>
#include <socks/vm.h>
#include <mango/percpu.h>
#include <mango/cpu.h>
#include <mango/vm.h>
#include <stdint.h>
#include <stddef.h>

View File

@@ -1,7 +1,7 @@
#include <socks/printk.h>
#include <socks/locks.h>
#include <socks/console.h>
#include <socks/libc/stdio.h>
#include <mango/printk.h>
#include <mango/locks.h>
#include <mango/console.h>
#include <mango/libc/stdio.h>
#include <stdarg.h>
#define LOG_BUFFER_SIZE 0x40000

View File

@@ -1,4 +1,4 @@
#include <socks/status.h>
#include <mango/status.h>
#define ERROR_STRING_CASE(code) \
case code: \

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_LIBC_TYPES_H_
#define SOCKS_LIBC_TYPES_H_
#ifndef MANGO_LIBC_TYPES_H_
#define MANGO_LIBC_TYPES_H_
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_STDIO_H_
#define SOCKS_STDIO_H_
#ifndef MANGO_STDIO_H_
#define MANGO_STDIO_H_
#include <stdarg.h>
#include <stddef.h>

View File

@@ -1,5 +1,5 @@
#ifndef SOCKS_LIBC_STRING_H_
#define SOCKS_LIBC_STRING_H_
#ifndef MANGO_LIBC_STRING_H_
#define MANGO_LIBC_STRING_H_
#include <stdint.h>
#include <stddef.h>

View File

@@ -30,7 +30,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <socks/console.h>
#include <mango/console.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

Some files were not shown because too many files have changed in this diff Show More