9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 186b917a8d3a79d58afd3f7ae1e4b0eccaae52bc
parent ac71c050b4623f0182157b9d77163ae5f30caf91
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  2 Dec 2022 07:26:48 +0100

Merge branch 'master' into HEAD

Diffstat:
MMakefile | 35++++++-----------------------------
Dconfig/toolchain/armclang.mk | 5-----
Dconfig/toolchain/clang.mk | 10----------
Dconfig/toolchain/gnu-darwin.mk | 4----
Dconfig/toolchain/gnu.mk | 19-------------------
Dconfig/toolchain/pcc.mk | 3---
Dinclude/arinc653/ARINC653.h | 11-----------
Dinclude/arinc653/buffers.h | 52----------------------------------------------------
Dinclude/arinc653/error.h | 63---------------------------------------------------------------
Dinclude/arinc653/event.h | 48------------------------------------------------
Dinclude/arinc653/mutex.h | 62--------------------------------------------------------------
Dinclude/arinc653/partition.h | 48------------------------------------------------
Dinclude/arinc653/process.h | 127-------------------------------------------------------------------------------
Dinclude/arinc653/queing.h | 57---------------------------------------------------------
Dinclude/arinc653/sampling.h | 53-----------------------------------------------------
Dinclude/arinc653/semaphore.h | 50--------------------------------------------------
Dinclude/arinc653/time.h | 19-------------------
Dinclude/arinc653/types.h | 91-------------------------------------------------------------------------------
Minclude/bits/amd64/arch/types.h | 1+
Minclude/bits/arm64/arch/types.h | 1+
Minclude/libk.h | 1+
Minclude/os9/os9.h | 90+++++++++++++++++++++++++++++++------------------------------------------------
Rconfig/amd64-darwin.mk -> scripts/build/conf/amd64-darwin.mk | 0
Rconfig/amd64-dragonfly.mk -> scripts/build/conf/amd64-dragonfly.mk | 0
Rconfig/amd64-linux.mk -> scripts/build/conf/amd64-linux.mk | 0
Rconfig/amd64-netbsd.mk -> scripts/build/conf/amd64-netbsd.mk | 0
Rconfig/amd64-openbsd.mk -> scripts/build/conf/amd64-openbsd.mk | 0
Rconfig/arm32-linux.mk -> scripts/build/conf/arm32-linux.mk | 0
Rconfig/arm64-linux.mk -> scripts/build/conf/arm64-linux.mk | 0
Rconfig/arm64-os9.mk -> scripts/build/conf/arm64-os9.mk | 0
Rconfig/toolchain/armclang.ld -> scripts/build/tool/armclang.ld | 0
Ascripts/build/tool/armclang.mk | 3+++
Ascripts/build/tool/clang.mk | 10++++++++++
Ascripts/build/tool/gnu-darwin.mk | 4++++
Rconfig/toolchain/gnu.ld -> scripts/build/tool/gnu.ld | 0
Ascripts/build/tool/gnu.mk | 19+++++++++++++++++++
Ascripts/build/tool/pcc.mk | 3+++
Mscripts/fvp.sh | 4++--
Mscripts/host.sh | 2+-
Mscripts/mklib | 4+++-
Mscripts/pi3.sh | 22++++++++++++++--------
Ascripts/pi4.sh | 14++++++++++++++
Mscripts/rules.mk | 96++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/Makefile | 9++-------
Msrc/libc/Makefile | 11++++-------
Msrc/libc/Makefile.libc | 2+-
Msrc/libc/arch/amd64/Makefile | 15++++++++-------
Msrc/libc/arch/amd64/darwin/Makefile | 2+-
Msrc/libc/arch/amd64/dragonfly/Makefile | 2+-
Msrc/libc/arch/amd64/linux/Makefile | 2+-
Msrc/libc/arch/amd64/netbsd/Makefile | 2+-
Msrc/libc/arch/amd64/openbsd/Makefile | 2+-
Msrc/libc/arch/arm32/Makefile | 4+++-
Msrc/libc/arch/arm32/linux/Makefile | 2+-
Msrc/libc/arch/arm64/Makefile | 10+++-------
Msrc/libio/Makefile | 2+-
Msrc/libk/Makefile | 3++-
Asrc/libk/getline.c | 21+++++++++++++++++++++
Msrc/libk/ksnprint.c | 2+-
Asrc/os9/.gitignore | 1+
Msrc/os9/Makefile | 23+++++++++++++----------
Msrc/os9/arch/Makefile | 6++----
Msrc/os9/arch/arm64/.gitignore | 1-
Msrc/os9/arch/arm64/Makefile | 14++++----------
Msrc/os9/arch/arm64/arch.h | 2--
Msrc/os9/arch/arm64/arch.s | 6------
Dsrc/os9/arch/arm64/cache.c | 102-------------------------------------------------------------------------------
Msrc/os9/arch/arm64/crt.s | 1-
Msrc/os9/arch/arm64/ctx.c | 17+++++++++++++++--
Msrc/os9/arch/arm64/fvp.c | 2+-
Msrc/os9/arch/arm64/main.c | 20--------------------
Msrc/os9/arch/arm64/mmu.c | 1+
Msrc/os9/arch/arm64/pi3.c | 11+++++------
Dsrc/os9/cfg/9fvp | 7-------
Asrc/os9/cfg/9fvp/conf | 9+++++++++
Asrc/os9/cfg/9fvp/kernel | 11+++++++++++
Dsrc/os9/cfg/9hosted | 9---------
Asrc/os9/cfg/9hosted/conf | 5+++++
Asrc/os9/cfg/9hosted/kernel | 10++++++++++
Dsrc/os9/cfg/9pi3 | 7-------
Asrc/os9/cfg/9pi3/conf | 8++++++++
Asrc/os9/cfg/9pi3/kernel | 9+++++++++
Msrc/os9/dev/Makefile | 8++++----
Msrc/os9/dev/Makefile.drv | 10++++++----
Msrc/os9/dev/dev.c | 18+++++++++++-------
Msrc/os9/dev/devproc.c | 89++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/os9/dev/devuart.c | 3+++
Msrc/os9/dev/dummyuart.c | 1+
Msrc/os9/dev/mkblob | 4++--
Msrc/os9/dev/mkblobh | 2+-
Msrc/os9/dev/mkdev | 2+-
Msrc/os9/dev/mkdevc | 2+-
Msrc/os9/dev/pl011.c | 1+
Msrc/os9/dev/uart.h | 1+
Msrc/os9/dlang.c | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Msrc/os9/hosted/Makefile | 8+++-----
Msrc/os9/hosted/arch.c | 19++++++++++---------
Msrc/os9/hosted/ctx.c | 12++++++++----
Msrc/os9/hosted/main.c | 11+----------
Msrc/os9/hosted/mmu.c | 5+++--
Rsrc/os9/arch/arm64/mkver -> src/os9/mkver | 0
Msrc/os9/proc.c | 332+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Dsrc/os9/sched.c | 74--------------------------------------------------------------------------
Msrc/os9/sys.c | 113++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
104 files changed, 821 insertions(+), 1399 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,9 +1,10 @@ .POSIX: PROJECTDIR = . -include scripts/rules.mk DIRS = src +include scripts/rules.mk + all: src src: lib bin @@ -11,35 +12,11 @@ src: lib bin bin lib: mkdir $@ -$(DIRS): FORCE - +@. $(ENVIRON) && cd $@ && $(MAKE) - -gen: $(ENVIRON) FORCE - +@. $(ENVIRON) && cd src && $(MAKE) gen +gen: FORCE + +@cd src && $(MAKE) gen pi3 host fvp: scripts/$@.sh -$(DIRS): $(ENVIRON) - -$(ENVIRON): - @rm -f $@; \ - trap 'r=$?;rm -f $$$$.tmp;exit $r' EXIT HUP INT QUIT TERM; \ - echo PATH=$$PATH:$$PWD/$(SCRIPTDIR):. > $$$$.tmp && \ - echo CC=\"$(CC)\" >> $$$$.tmp && \ - echo AS=\"$(AS)\" >> $$$$.tmp && \ - echo LD=\"$(LD)\" >> $$$$.tmp && \ - echo OC=\"$(OC)\" >> $$$$.tmp && \ - echo OD=\"$(OD)\" >> $$$$.tmp && \ - echo AR=\"$(AR)\" >> $$$$.tmp && \ - echo RL=\"$(RL)\" >> $$$$.tmp && \ - echo MAKE=\"$(MAKE)\" >> $$$$.tmp && \ - echo ARFLAGS=\"$(ARFLAGS)\" >> $$$$.tmp && \ - echo RLFLAGS=\"$(RLFLAGS)\" >> $$$$.tmp && \ - echo export PATH CC AS LD OC MAKE >> $$$$.tmp && \ - echo export OD RLFLAGS NM AR RL ARFLAGS >> $$$$.tmp && \ - mv $$$$.tmp $@ - -clean: $(ENVIRON) - $(FORALL) - rm -rf lib bin $(ENVIRON) +clean: + rm -rf lib bin diff --git a/config/toolchain/armclang.mk b/config/toolchain/armclang.mk @@ -1,5 +0,0 @@ -include $(PROJECTDIR)/config/clang.mk - -RMODE_CFLAGS = -mgeneral-regs-only -target aarch64-elf -fno-jump-tables -RMODE_ASFLAGS = -fintegrated-as -c -target aarch64-arm-none-eabi -LINKSCRIPT = -T $(CONFDIR)/$(CONFDIR)/toolchain/armclang.ld diff --git a/config/toolchain/clang.mk b/config/toolchain/clang.mk @@ -1,10 +0,0 @@ -include $(PROJECTDIR)/config/toolchain/gnu.mk - -COMP = clang -ASM = clang -LINKER = ld.lld -OBJCOPY = llvm-objcopy -OBJDUMP = llvm-objdump -LINKSCRIPT = -T $(CONFDIR)/clang.ld -RCODE_CFLAGS = -mgeneral-regs-only -target aarch64-elf -fno-jump-tables -RCODE_ASFLAGS = -fintegrated-as -c -target aarch64-elf diff --git a/config/toolchain/gnu-darwin.mk b/config/toolchain/gnu-darwin.mk @@ -1,4 +0,0 @@ -include $(PROJECTDIR)/config/toolchain/gnu.mk - -TOOLLDFLAGS = -static -RANLIBFLAGS = -c diff --git a/config/toolchain/gnu.mk b/config/toolchain/gnu.mk @@ -1,19 +0,0 @@ -TOOLCFLAGS = -g -static -nostdinc -ffreestanding -std=c99 -fno-stack-protector -MD -Wall -TOOLLDFLAGS = -static -z nodefaultlib - -COMP = gcc -ASM = as -LINKER = ld -OBJDUMP = objdump -OBJCOPY = objcopy -RANLIB = ranlib -ARCHIVE = ar - -ARFLAGS = -U -LINKSCRIPT = -T $(CONFDIR)/toolchain/gnu.ld -NOPIE_CFLAGS = -nopie -NOPIE_LDFLAGS = -nopie -OS9_CFLAGS = -mgeneral-regs-only --no-pie -march=armv8.1-a -ARM32_CFLAGS = -marm -ARM32_LDFLAGS = -lgcc -ARMV81_ASFLAGS = -march=armv8.1-a diff --git a/config/toolchain/pcc.mk b/config/toolchain/pcc.mk @@ -1,3 +0,0 @@ -include $(PROJECTDIR)/config/toolchain/gnu.mk - -COMP = pcc diff --git a/include/arinc653/ARINC653.h b/include/arinc653/ARINC653.h @@ -1,11 +0,0 @@ -#include "buffers.h" -#include "error.h" -#include "event.h" -#include "mutex.h" -#include "partition.h" -#include "process.h" -#include "queing.h" -#include "sampling.h" -#include "semaphore.h" -#include "time.h" -#include "types.h" diff --git a/include/arinc653/buffers.h b/include/arinc653/buffers.h @@ -1,52 +0,0 @@ -#ifndef APEX_BUFFER -#define APEX_BUFFER - -#define MAX_NUMBER_OF_BUFFERS SYSTEM_LIMIT_NUMBER_OF_BUFFERS - -typedef NAME_TYPE BUFFER_NAME_TYPE; - -typedef APEX_INTEGER BUFFER_ID_TYPE; - -typedef - struct { - MESSAGE_RANGE_TYPE NB_MESSAGE; - MESSAGE_RANGE_TYPE MAX_NB_MESSAGE; - MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE; - WAITING_RANGE_TYPE WAITING_PROCESSES; - } BUFFER_STATUS_TYPE; - - - -extern void CREATE_BUFFER ( - /*in */ BUFFER_NAME_TYPE BUFFER_NAME, - /*in */ MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE, - /*in */ MESSAGE_RANGE_TYPE MAX_NB_MESSAGE, - /*in */ QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, - /*out*/ BUFFER_ID_TYPE *BUFFER_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SEND_BUFFER ( - /*in */ BUFFER_ID_TYPE BUFFER_ID, - /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, /* by reference */ - /*in */ MESSAGE_SIZE_TYPE LENGTH, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void RECEIVE_BUFFER ( - /*in */ BUFFER_ID_TYPE BUFFER_ID, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ MESSAGE_ADDR_TYPE MESSAGE_ADDR, - /*out*/ MESSAGE_SIZE_TYPE *LENGTH, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_BUFFER_ID ( - /*in */ BUFFER_NAME_TYPE BUFFER_NAME, - /*out*/ BUFFER_ID_TYPE *BUFFER_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_BUFFER_STATUS ( - /*in */ BUFFER_ID_TYPE BUFFER_ID, - /*out*/ BUFFER_STATUS_TYPE *BUFFER_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/error.h b/include/arinc653/error.h @@ -1,63 +0,0 @@ -#ifndef APEX_ERROR -#define APEX_ERROR - -#define MAX_ERROR_MESSAGE_SIZE 128 - -typedef APEX_INTEGER ERROR_MESSAGE_SIZE_TYPE; - -typedef APEX_BYTE ERROR_MESSAGE_TYPE[MAX_ERROR_MESSAGE_SIZE]; - -typedef - enum { - DEADLINE_MISSED = 0, - APPLICATION_ERROR = 1, - NUMERIC_ERROR = 2, - ILLEGAL_REQUEST = 3, - STACK_OVERFLOW = 4, - MEMORY_VIOLATION = 5, - HARDWARE_FAULT = 6, - POWER_FAIL = 7 - } ERROR_CODE_TYPE; - -typedef - struct { - ERROR_CODE_TYPE ERROR_CODE; - ERROR_MESSAGE_SIZE_TYPE LENGTH; - PROCESS_ID_TYPE FAILED_PROCESS_ID; - SYSTEM_ADDRESS_TYPE FAILED_ADDRESS; - ERROR_MESSAGE_TYPE MESSAGE; - } ERROR_STATUS_TYPE; - -typedef - enum { - PROCESSES_PAUSE = 0, - PROCESSES_SCHEDULED = 1 - } ERROR_HANDLER_CONCURRENCY_CONTROL_TYPE; - -extern void REPORT_APPLICATION_MESSAGE ( - /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, - /*in */ MESSAGE_SIZE_TYPE LENGTH, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void CREATE_ERROR_HANDLER ( - /*in */ SYSTEM_ADDRESS_TYPE ENTRY_POINT, - /*in */ STACK_SIZE_TYPE STACK_SIZE, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_ERROR_STATUS ( - /*out*/ ERROR_STATUS_TYPE *ERROR_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void RAISE_APPLICATION_ERROR ( - /*in */ ERROR_CODE_TYPE ERROR_CODE, - /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, - - /*in */ ERROR_MESSAGE_SIZE_TYPE LENGTH, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void CONFIGURE_ERROR_HANDLER ( - /*in */ ERROR_HANDLER_CONCURRENCY_CONTROL_TYPE CONCURRENCY_CONTROL, - /*in */ PROCESSOR_CORE_ID_TYPE PROCESSOR_CORE_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/event.h b/include/arinc653/event.h @@ -1,48 +0,0 @@ -#ifndef APEX_EVENT -#define APEX_EVENT - -#define MAX_NUMBER_OF_EVENTS SYSTEM_LIMIT_NUMBER_OF_EVENTS - -typedef NAME_TYPE EVENT_NAME_TYPE; - -typedef APEX_INTEGER EVENT_ID_TYPE; - -typedef enum { DOWN = 0, UP = 1 } EVENT_STATE_TYPE; - -typedef - struct { - EVENT_STATE_TYPE EVENT_STATE; - WAITING_RANGE_TYPE WAITING_PROCESSES; - } EVENT_STATUS_TYPE; - - - -extern void CREATE_EVENT ( - /*in */ EVENT_NAME_TYPE EVENT_NAME, - /*out*/ EVENT_ID_TYPE *EVENT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SET_EVENT ( - /*in */ EVENT_ID_TYPE EVENT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void RESET_EVENT ( - /*in */ EVENT_ID_TYPE EVENT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void WAIT_EVENT ( - /*in */ EVENT_ID_TYPE EVENT_ID, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_EVENT_ID ( - /*in */ EVENT_NAME_TYPE EVENT_NAME, - /*out*/ EVENT_ID_TYPE *EVENT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_EVENT_STATUS ( - /*in */ EVENT_ID_TYPE EVENT_ID, - /*out*/ EVENT_STATUS_TYPE *EVENT_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/mutex.h b/include/arinc653/mutex.h @@ -1,62 +0,0 @@ -#ifndef APEX_MUTEX -#define APEX_MUTEX - -#define MAX_NUMBER_OF_MUTEXES SYSTEM_LIMIT_NUMBER_OF_MUTEXES - -typedef NAME_TYPE MUTEX_NAME_TYPE; - -typedef APEX_INTEGER MUTEX_ID_TYPE; -#define NO_MUTEX_OWNED -2 -#define PREEMPTION_LOCK_MUTEX -3 - -typedef APEX_INTEGER LOCK_COUNT_TYPE; - -typedef enum { AVAILABLE = 0, OWNED = 1 } MUTEX_STATE_TYPE; - - -typedef - struct { - MUTEX_STATE_TYPE MUTEX_STATE; - PROCESS_ID_TYPE MUTEX_OWNER; - PRIORITY_TYPE MUTEX_PRIORITY; - LOCK_COUNT_TYPE LOCK_COUNT; - WAITING_RANGE_TYPE WAITING_PROCESSES; - } MUTEX_STATUS_TYPE; - -extern void CREATE_MUTEX ( - /*in */ MUTEX_NAME_TYPE MUTEX_NAME, - /*in */ PRIORITY_TYPE MUTEX_PRIORITY, - /*in */ QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, - /*out*/ MUTEX_ID_TYPE *MUTEX_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void ACQUIRE_MUTEX ( - /*in */ MUTEX_ID_TYPE MUTEX_ID, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void RELEASE_MUTEX ( - /*in */ MUTEX_ID_TYPE MUTEX_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void RESET_MUTEX ( - /*in */ MUTEX_ID_TYPE MUTEX_ID, - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_MUTEX_ID ( - /*in */ MUTEX_NAME_TYPE MUTEX_NAME, - /*out*/ MUTEX_ID_TYPE *MUTEX_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_MUTEX_STATUS ( - /*in */ MUTEX_ID_TYPE MUTEX_ID, - /*out*/ MUTEX_STATUS_TYPE *MUTEX_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_PROCESS_MUTEX_STATE ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ MUTEX_ID_TYPE *MUTEX_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/partition.h b/include/arinc653/partition.h @@ -1,48 +0,0 @@ - -#ifndef APEX_PARTITION -#define APEX_PARTITION - -#define MAX_NUMBER_OF_PARTITIONS SYSTEM_LIMIT_NUMBER_OF_PARTITIONS - -typedef - enum { - IDLE = 0, - COLD_START = 1, - WARM_START = 2, - NORMAL = 3 - } OPERATING_MODE_TYPE; - -typedef APEX_INTEGER PARTITION_ID_TYPE; - -typedef APEX_UNSIGNED NUM_CORES_TYPE; - - -typedef - enum { - NORMAL_START = 0, - PARTITION_RESTART = 1, - HM_MODULE_RESTART = 2, - HM_PARTITION_RESTART = 3 - } START_CONDITION_TYPE; - -typedef - struct { - SYSTEM_TIME_TYPE PERIOD; - SYSTEM_TIME_TYPE DURATION; - PARTITION_ID_TYPE IDENTIFIER; - LOCK_LEVEL_TYPE LOCK_LEVEL; - OPERATING_MODE_TYPE OPERATING_MODE; - START_CONDITION_TYPE START_CONDITION; - NUM_CORES_TYPE NUM_ASSIGNED_CORES; - } PARTITION_STATUS_TYPE; - - -extern void GET_PARTITION_STATUS ( - /*out*/ PARTITION_STATUS_TYPE *PARTITION_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SET_PARTITION_MODE ( - /*in */ OPERATING_MODE_TYPE OPERATING_MODE, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/process.h b/include/arinc653/process.h @@ -1,127 +0,0 @@ -#ifndef APEX_PROCESS -#define APEX_PROCESS - -#define MAX_NUMBER_OF_PROCESSES SYSTEM_LIMIT_NUMBER_OF_PROCESSES - -#define MIN_PRIORITY_VALUE 1 - -#define MAX_PRIORITY_VALUE 239 - -#define MAX_LOCK_LEVEL 16 - -typedef NAME_TYPE PROCESS_NAME_TYPE; - -typedef APEX_INTEGER PROCESS_ID_TYPE; - -#define NULL_PROCESS_ID 0 -#define MAIN_PROCESS_ID -1 - -typedef APEX_INTEGER LOCK_LEVEL_TYPE; - -typedef APEX_UNSIGNED STACK_SIZE_TYPE; - -typedef APEX_INTEGER WAITING_RANGE_TYPE; - -typedef APEX_INTEGER PRIORITY_TYPE; - -typedef - enum { - DORMANT = 0, - READY = 1, - RUNNING = 2, - WAITING = 3, - FAULTED = 4 - } PROCESS_STATE_TYPE; - -typedef enum { SOFT = 0, HARD = 1 } DEADLINE_TYPE; - -typedef - struct { - SYSTEM_TIME_TYPE PERIOD; - SYSTEM_TIME_TYPE TIME_CAPACITY; - SYSTEM_ADDRESS_TYPE ENTRY_POINT; - STACK_SIZE_TYPE STACK_SIZE; - PRIORITY_TYPE BASE_PRIORITY; - DEADLINE_TYPE DEADLINE; - PROCESS_NAME_TYPE NAME; - } PROCESS_ATTRIBUTE_TYPE; - -typedef - struct { - SYSTEM_TIME_TYPE DEADLINE_TIME; - PRIORITY_TYPE CURRENT_PRIORITY; - PROCESS_STATE_TYPE PROCESS_STATE; - PROCESS_ATTRIBUTE_TYPE ATTRIBUTES; - } PROCESS_STATUS_TYPE; - - -extern void CREATE_PROCESS ( - /*in */ PROCESS_ATTRIBUTE_TYPE *ATTRIBUTES, - /*out*/ PROCESS_ID_TYPE *PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SET_PRIORITY ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*in */ PRIORITY_TYPE PRIORITY, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SUSPEND_SELF ( - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SUSPEND ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void RESUME ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void STOP_SELF (void); - -extern void STOP ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - - -extern void START ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void DELAYED_START ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*in */ SYSTEM_TIME_TYPE DELAY_TIME, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void LOCK_PREEMPTION ( - /*out*/ LOCK_LEVEL_TYPE *LOCK_LEVEL, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void UNLOCK_PREEMPTION ( - /*out*/ LOCK_LEVEL_TYPE *LOCK_LEVEL, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_MY_ID ( - /*out*/ PROCESS_ID_TYPE *PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_PROCESS_ID ( - /*in */ PROCESS_NAME_TYPE PROCESS_NAME, - /*out*/ PROCESS_ID_TYPE *PROCESS_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_PROCESS_STATUS ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*out*/ PROCESS_STATUS_TYPE *PROCESS_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void INITIALIZE_PROCESS_CORE_AFFINITY ( - /*in */ PROCESS_ID_TYPE PROCESS_ID, - /*in */ PROCESSOR_CORE_ID_TYPE PROCESSOR_CORE_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_MY_PROCESSOR_CORE_ID ( - /*out*/ PROCESSOR_CORE_ID_TYPE *PROCESSOR_CORE_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/queing.h b/include/arinc653/queing.h @@ -1,57 +0,0 @@ -#ifndef APEX_QUEUING -#define APEX_QUEUING - -#define MAX_NUMBER_OF_QUEUING_PORTS SYSTEM_LIMIT_NUMBER_OF_QUEUING_PORTS - -typedef NAME_TYPE QUEUING_PORT_NAME_TYPE; - -typedef APEX_INTEGER QUEUING_PORT_ID_TYPE; - -typedef - struct { - MESSAGE_RANGE_TYPE NB_MESSAGE; - MESSAGE_RANGE_TYPE MAX_NB_MESSAGE; - MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE; - PORT_DIRECTION_TYPE PORT_DIRECTION; - WAITING_RANGE_TYPE WAITING_PROCESSES; - } QUEUING_PORT_STATUS_TYPE; - - -extern void CREATE_QUEUING_PORT ( - /*in */ QUEUING_PORT_NAME_TYPE QUEUING_PORT_NAME, - /*in */ MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE, - /*in */ MESSAGE_RANGE_TYPE MAX_NB_MESSAGE, - /*in */ PORT_DIRECTION_TYPE PORT_DIRECTION, - /*in */ QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, - /*out*/ QUEUING_PORT_ID_TYPE *QUEUING_PORT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SEND_QUEUING_MESSAGE ( - /*in */ QUEUING_PORT_ID_TYPE QUEUING_PORT_ID, - /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, /* by reference */ - /*in */ MESSAGE_SIZE_TYPE LENGTH, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE); - -extern void RECEIVE_QUEUING_MESSAGE ( - /*in */ QUEUING_PORT_ID_TYPE QUEUING_PORT_ID, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ MESSAGE_ADDR_TYPE MESSAGE_ADDR, - /*out*/ MESSAGE_SIZE_TYPE *LENGTH, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_QUEUING_PORT_ID ( - /*in */ QUEUING_PORT_NAME_TYPE QUEUING_PORT_NAME, - /*out*/ QUEUING_PORT_ID_TYPE *QUEUING_PORT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_QUEUING_PORT_STATUS ( - /*in */ QUEUING_PORT_ID_TYPE QUEUING_PORT_ID, - /*out*/ QUEUING_PORT_STATUS_TYPE *QUEUING_PORT_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void CLEAR_QUEUING_PORT ( - /*in */ QUEUING_PORT_ID_TYPE QUEUING_PORT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/sampling.h b/include/arinc653/sampling.h @@ -1,53 +0,0 @@ -#ifndef APEX_SAMPLING -#define APEX_SAMPLING - -#define MAX_NUMBER_OF_SAMPLING_PORTS SYSTEM_LIMIT_NUMBER_OF_SAMPLING_PORTS - -typedef NAME_TYPE SAMPLING_PORT_NAME_TYPE; - -typedef APEX_INTEGER SAMPLING_PORT_ID_TYPE; - -typedef enum { INVALID = 0, VALID = 1 } VALIDITY_TYPE; - -typedef - struct { - SYSTEM_TIME_TYPE REFRESH_PERIOD; - MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE; - PORT_DIRECTION_TYPE PORT_DIRECTION; - VALIDITY_TYPE LAST_MSG_VALIDITY; - } SAMPLING_PORT_STATUS_TYPE; - - - -extern void CREATE_SAMPLING_PORT ( - /*in */ SAMPLING_PORT_NAME_TYPE SAMPLING_PORT_NAME, - /*in */ MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE, - /*in */ PORT_DIRECTION_TYPE PORT_DIRECTION, - /*in */ SYSTEM_TIME_TYPE REFRESH_PERIOD, - /*out*/ SAMPLING_PORT_ID_TYPE *SAMPLING_PORT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void WRITE_SAMPLING_MESSAGE ( - /*in */ SAMPLING_PORT_ID_TYPE SAMPLING_PORT_ID, - /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, /* by reference */ - /*in */ MESSAGE_SIZE_TYPE LENGTH, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void READ_SAMPLING_MESSAGE ( - /*in */ SAMPLING_PORT_ID_TYPE SAMPLING_PORT_ID, - /*out*/ MESSAGE_ADDR_TYPE MESSAGE_ADDR, - /*out*/ MESSAGE_SIZE_TYPE *LENGTH, - /*out*/ VALIDITY_TYPE *VALIDITY, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_SAMPLING_PORT_ID ( - /*in */ SAMPLING_PORT_NAME_TYPE SAMPLING_PORT_NAME, - /*out*/ SAMPLING_PORT_ID_TYPE *SAMPLING_PORT_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_SAMPLING_PORT_STATUS ( - /*in */ SAMPLING_PORT_ID_TYPE SAMPLING_PORT_ID, - /*out*/ SAMPLING_PORT_STATUS_TYPE *SAMPLING_PORT_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/semaphore.h b/include/arinc653/semaphore.h @@ -1,50 +0,0 @@ -#ifndef APEX_SEMAPHORE -#define APEX_SEMAPHORE - -#define MAX_NUMBER_OF_SEMAPHORES SYSTEM_LIMIT_NUMBER_OF_SEMAPHORES - -#define MAX_SEMAPHORE_VALUE 32767 - -typedef NAME_TYPE SEMAPHORE_NAME_TYPE; - -typedef APEX_INTEGER SEMAPHORE_ID_TYPE; - -typedef APEX_INTEGER SEMAPHORE_VALUE_TYPE; - -typedef - struct { - SEMAPHORE_VALUE_TYPE CURRENT_VALUE; - SEMAPHORE_VALUE_TYPE MAXIMUM_VALUE; - WAITING_RANGE_TYPE WAITING_PROCESSES; - } SEMAPHORE_STATUS_TYPE; - - - -extern void CREATE_SEMAPHORE ( - /*in */ SEMAPHORE_NAME_TYPE SEMAPHORE_NAME, - /*in */ SEMAPHORE_VALUE_TYPE CURRENT_VALUE, - /*in */ SEMAPHORE_VALUE_TYPE MAXIMUM_VALUE, - /*in */ QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, - /*out*/ SEMAPHORE_ID_TYPE *SEMAPHORE_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void WAIT_SEMAPHORE ( - /*in */ SEMAPHORE_ID_TYPE SEMAPHORE_ID, - /*in */ SYSTEM_TIME_TYPE TIME_OUT, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void SIGNAL_SEMAPHORE ( - /*in */ SEMAPHORE_ID_TYPE SEMAPHORE_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_SEMAPHORE_ID ( - /*in */ SEMAPHORE_NAME_TYPE SEMAPHORE_NAME, - /*out*/ SEMAPHORE_ID_TYPE *SEMAPHORE_ID, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_SEMAPHORE_STATUS ( - /*in */ SEMAPHORE_ID_TYPE SEMAPHORE_ID, - /*out*/ SEMAPHORE_STATUS_TYPE *SEMAPHORE_STATUS, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/time.h b/include/arinc653/time.h @@ -1,19 +0,0 @@ -#ifndef APEX_TIME -#define APEX_TIME - -extern void TIMED_WAIT ( - /*in */ SYSTEM_TIME_TYPE DELAY_TIME, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void PERIODIC_WAIT ( - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void GET_TIME ( - /*out*/ SYSTEM_TIME_TYPE *SYSTEM_TIME, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -extern void REPLENISH ( - /*in */ SYSTEM_TIME_TYPE BUDGET_TIME, - /*out*/ RETURN_CODE_TYPE *RETURN_CODE ); - -#endif diff --git a/include/arinc653/types.h b/include/arinc653/types.h @@ -1,91 +0,0 @@ -#ifndef APEX_TYPES -#define APEX_TYPES - -/*---------------------------*/ -/* Domain limits */ -/*---------------------------*/ - -/* Implementation Dependent */ -/* These values define the domain limits and are implementation dependent. */ - -#define SYSTEM_LIMIT_NUMBER_OF_PARTITIONS 32 /* module scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_MESSAGES 512 /* module scope */ - -#define SYSTEM_LIMIT_MESSAGE_SIZE 8192 /* module scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_PROCESSES 128 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_SAMPLING_PORTS 512 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_QUEUING_PORTS 512 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_BUFFERS 256 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_BLACKBOARDS 256 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_SEMAPHORES 256 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_EVENTS 256 /* partition scope */ - -#define SYSTEM_LIMIT_NUMBER_OF_MUTEXES 256 /* partition scope */ - -/*----------------------*/ -/* Base APEX types */ -/*----------------------*/ - -/* Implementation Dependent */ -/* The actual size of these base types is system specific and the */ -/* sizes must match the sizes used by the implementation of the */ -/* underlying Operating System. */ - -typedef unsigned char APEX_BYTE; /* 8-bit unsigned */ - -typedef long APEX_INTEGER; /* 32-bit signed */ - -typedef unsigned long APEX_UNSIGNED; /* 32-bit unsigned */ - -typedef long long APEX_LONG_INTEGER; /* 64-bit signed */ - -/*----------------------*/ -/* General APEX types */ -/*----------------------*/ - -typedef - enum { - NO_ERROR = 0, /* request valid and operation performed */ - NO_ACTION = 1, /* status of system unaffected by request */ - NOT_AVAILABLE = 2, /* resource required by request unavailable */ - INVALID_PARAM = 3, /* invalid parameter specified in request */ - INVALID_CONFIG = 4, /* parameter incompatible with configuration */ - INVALID_MODE = 5, /* request incompatible with current mode */ - TIMED_OUT = 6 /* time-out tied up with request has expired */ - } RETURN_CODE_TYPE; - -#define MAX_NAME_LENGTH 32 - -typedef char NAME_TYPE[MAX_NAME_LENGTH]; - -typedef void (* SYSTEM_ADDRESS_TYPE); - -typedef APEX_BYTE * MESSAGE_ADDR_TYPE; - -typedef APEX_INTEGER MESSAGE_SIZE_TYPE; - -typedef APEX_INTEGER MESSAGE_RANGE_TYPE; - -typedef enum { SOURCE = 0, DESTINATION = 1 } PORT_DIRECTION_TYPE; - -typedef enum { FIFO = 0, PRIORITY = 1 } QUEUING_DISCIPLINE_TYPE; - -typedef APEX_LONG_INTEGER SYSTEM_TIME_TYPE; - /* 64-bit signed integer with a 1 nanosecond LSB */ - -#define INFINITE_TIME_VALUE -1 - -typedef APEX_INTEGER PROCESSOR_CORE_ID_TYPE; - -#define CORE_AFFINITY_NO_PREFERENCE -1 - - -#endif diff --git a/include/bits/amd64/arch/types.h b/include/bits/amd64/arch/types.h @@ -1,6 +1,7 @@ /* TODO: Move these bits to other place */ #define STACKADDR 0x7FFFFFFFFFFFFFF0 +#define KSTACKADDR 0xFFFFFFFFFFFFFFF0 #define MAXTID 32767 #define NR_TASKS 16 #define NR_WINS 32 diff --git a/include/bits/arm64/arch/types.h b/include/bits/arm64/arch/types.h @@ -1,6 +1,7 @@ /* TODO: Move these bits to other place */ #define STACKADDR 0x7FFFFFFFFFFFFFF0 +#define KSTACKADDR 0xFFFFFFFFFFFFFFF0 #define MAXTID 32767 #define NR_TASKS 16 #define NR_WINS 32 diff --git a/include/libk.h b/include/libk.h @@ -19,6 +19,7 @@ extern void kassert(char *exp, char *file, long line); extern int p9todir(Dir *, unsigned char *, int); extern int dirtop9(Dir *, unsigned char *, int); extern int dirstat(char *name, Dir *dir); +extern int getline(Chan *, char *, int); #endif /* external dependencies of the library */ diff --git a/include/os9/os9.h b/include/os9/os9.h @@ -41,7 +41,6 @@ typedef struct ptable Ptable; typedef struct context Context; -typedef struct proc Proc; typedef struct task Task; typedef struct win Win; typedef struct chan Chan; @@ -80,30 +79,17 @@ enum pstates { PSYSTEM = 1 << 0, }; -enum pmodes { - PDISABLED = 'D', - PCOLD_START = 'C', - PWARM_START = 'W', - PIDLE = 'I', - PNORMAL = 'N', -}; - enum tflags { TLOCK_PREEMP = 1 << 0, - TENABLED = 1 << 1, }; -enum tstates { - TDORMANT, +enum tmode { + TINIT, TREADY, TRUNNING, TWAITING, - FAULTED, -}; - -enum start_reason { - SNORMAL, - SKERNEL, + TFAULTED, + TFREE, }; enum map_attr { @@ -171,15 +157,21 @@ struct mpoint { mutex_t m; }; + +struct nspace { + Ref ref; + mutex_t m; + struct mpoint mpoints[NR_MPOINTS]; +}; + +struct fdset { + Ref ref; + mutex_t m; + Chan fdset[NR_CHANS]; +}; + /** - * @tid: Task identifier. - * @ptid: Parent Task identifier. -1 if it is the main task of a process. - * @pid: Process identifier. - * @ppid: Parent process identifier. -1 for all the task of the bootup process. - * @tname: Name of the task. - * @tentry: Entry point for the task. - * @pname: Name of the process. - * @pentry: Entry point for the process (start/restart address). + * @entry: Entry point for the task. * @prio: * @baseprio: * @retainprio: @@ -193,10 +185,8 @@ struct mpoint { * @capacity: * @deadline: * @deadtime: - * @state: * @flags: - * @mode: Denotes process's execution state. - * @start: Denotes the reason the process is started. + * @state: * @ctx: * @ptable: * @text: @@ -206,15 +196,10 @@ struct mpoint { * @fds: */ struct task { - int tid; - int ptid; int pid; int ppid; - char *tname; - void *tentry; - char *pname; - void *pentry; + void *entry; int prio; int baseprio; @@ -231,37 +216,26 @@ struct task { long deadline; long deadtime; - int state; int flags; - - atomic_t mode; - int start; + int state; mutex_t m; Context ctx; Ptable ptable; - void *kstack; - /* communication ports */ - /* healt monitor table */ - /* Task *errhdl; */ Map *text; Map *data; Map stack; + Map kstack; + Nspace *ns; Fdset *fds; + Chan slash; Task *next; }; -struct win { - int wid; - long offset; - long duration; - int pid; -}; - /* proc.c */ extern void iproc(void); extern void initref(Ref *); @@ -272,14 +246,18 @@ extern Task *gettask(int); extern int mapseg(Map *); extern Task *kproc(void *); extern Map *newstack(Task *); +extern void sched(void); +extern void locktask(Task *); +extern void unlocktask(Task *); /* alloc.c */ extern void *alloc(size_t); extern void *allocb(int); extern void freeb(void *); -/* init.c */ +/* sys.c */ extern void isys(void); +extern void info(void); /* dlang.c */ extern int debug(void); @@ -306,8 +284,10 @@ extern noreturn void fault(const char *msg, Context *ctx); extern noreturn void swtch(Context *ctx); extern noreturn void trap(Context *ctx); extern Ptable *initptable(Task *); -extern int ictx(Task *, void *); +extern void ictx(Task *, void *); +extern int dupctx(Task *); extern char *getconf(char *); +extern void idle(void); /* dev functions */ extern void idev(void); @@ -315,9 +295,10 @@ extern Chan *devopen(char *name, int mode); extern int devwrite(Chan *c, void *buf, int n); extern int devread(Chan *c, void *buf, int n); extern int devclose(Chan *c); +extern int mount(char *, char *, char *); +extern int bind(char *, char *); /* sched.c */ -extern void sched(void); /* globals */ extern Chan *console; @@ -325,7 +306,6 @@ extern Mach mach; extern char buffertab[NR_BUFFERS][PAGESIZE]; /* per cpu globals */ -extern Proc *proc; -extern Task *task; +extern Task *proc; extern int cpuid; extern long long now; diff --git a/config/amd64-darwin.mk b/scripts/build/conf/amd64-darwin.mk diff --git a/config/amd64-dragonfly.mk b/scripts/build/conf/amd64-dragonfly.mk diff --git a/config/amd64-linux.mk b/scripts/build/conf/amd64-linux.mk diff --git a/config/amd64-netbsd.mk b/scripts/build/conf/amd64-netbsd.mk diff --git a/config/amd64-openbsd.mk b/scripts/build/conf/amd64-openbsd.mk diff --git a/config/arm32-linux.mk b/scripts/build/conf/arm32-linux.mk diff --git a/config/arm64-linux.mk b/scripts/build/conf/arm64-linux.mk diff --git a/config/arm64-os9.mk b/scripts/build/conf/arm64-os9.mk diff --git a/config/toolchain/armclang.ld b/scripts/build/tool/armclang.ld diff --git a/scripts/build/tool/armclang.mk b/scripts/build/tool/armclang.mk @@ -0,0 +1,3 @@ +include $(BUILDDIR)/tool/clang.mk + +LINKSCRIPT = -T $(BUILDDIR)/tool/armclang.ld diff --git a/scripts/build/tool/clang.mk b/scripts/build/tool/clang.mk @@ -0,0 +1,10 @@ +include $(BUILDDIR)/tool/gnu.mk + +COMP = clang +ASM = clang +LINKER = ld.lld +OBJCOPY = llvm-objcopy +OBJDUMP = llvm-objdump +LINKSCRIPT = -T $(CONFDIR)/clang.ld +RCODE_CFLAGS = -mgeneral-regs-only -target aarch64-elf -fno-jump-tables +RCODE_ASFLAGS = -fintegrated-as -c -target aarch64-elf diff --git a/scripts/build/tool/gnu-darwin.mk b/scripts/build/tool/gnu-darwin.mk @@ -0,0 +1,4 @@ +include $(BUILDDIR)/tool/gnu.mk + +TOOLLDFLAGS = -static +RANLIBFLAGS = -c diff --git a/config/toolchain/gnu.ld b/scripts/build/tool/gnu.ld diff --git a/scripts/build/tool/gnu.mk b/scripts/build/tool/gnu.mk @@ -0,0 +1,19 @@ +TOOLCFLAGS = -g -static -nostdinc -ffreestanding -std=c99 -fno-stack-protector -MD -Wall +TOOLLDFLAGS = -static -z nodefaultlib + +COMP = gcc +ASM = as +LINKER = ld +OBJDUMP = objdump +OBJCOPY = objcopy +RANLIB = ranlib +ARCHIVE = ar + +ARFLAGS = -U +LINKSCRIPT = -T $(BUILDDIR)/tool/gnu.ld +NOPIE_CFLAGS = -nopie +NOPIE_LDFLAGS = -nopie +OS9_CFLAGS = -mgeneral-regs-only --no-pie -march=armv8.1-a +ARM32_CFLAGS = -marm +ARM32_LDFLAGS = -lgcc +ARMV81_ASFLAGS = -march=armv8.1-a diff --git a/scripts/build/tool/pcc.mk b/scripts/build/tool/pcc.mk @@ -0,0 +1,3 @@ +include $(BUILDDIR)/tool/gnu.mk + +COMP = pcc diff --git a/scripts/fvp.sh b/scripts/fvp.sh @@ -1,6 +1,6 @@ #!/bin/sh -os=bin/os9.bin +os=bin/9fvp.bin uart0=uart0.out uart3=uart3.out bl31=$TFA_PATH/build/fvp/debug/bl31.bin @@ -20,7 +20,7 @@ $FVP_PATH/FVP_Base_RevC-2xAEMv8A \ -C cluster1.cpu3.RVBAR=0x04001000 \ --data cluster0.cpu0=$bl31@0x04001000 \ --data cluster0.cpu0=$os@0x80000000 \ -# --plugin /home/k0ga/models/FVP_Base_RevC-2xAEMv8A/plugins/Linux64_GCC-6.4/TarmacTrace.so \ +# --plugin /home/k0ga/models/FVP_Base_RevC-2xAEMv8A/plugins/Linux64_GCC-6.4/TarmacTrace.so \ # -C bp.pl011_uart0.out_file=$uart0 \ # -C bp.pl011_uart3.out_file=$uart3 \ diff --git a/scripts/host.sh b/scripts/host.sh @@ -7,4 +7,4 @@ trap 'stty $stty' EXIT HUP INT TERM cd bin stty -echo raw min 1 -./romfw.elf +./9hosted.elf diff --git a/scripts/mklib b/scripts/mklib @@ -2,6 +2,8 @@ set -e +PATH=`dirname $0`:$PATH + usage() { echo usage: mklib [-o library] file ... >&2 @@ -17,7 +19,7 @@ do ;; --) shift - break; + break ;; -*) usage diff --git a/scripts/pi3.sh b/scripts/pi3.sh @@ -1,13 +1,19 @@ #!/bin/sh -os=bin/os9.bin +os=bin/9pi3.bin -qemu-system-aarch64 \ - -machine type=raspi3\ - -m 1024 - -bios $os \ +qemu-system-aarch64\ + -M raspi3 -m 1024 \ -serial mon:stdio\ + -nographic\ + -no-reboot\ -gdb tcp::7000 -S\ - -no-reboot \ - -nographic \ - -bios $os \ + -kernel $os & + +aarch64-linux-musl-gdb bin/9pi3.elf + +kill $! + +# -machine type=raspi3\ +#image must be a multiple of 4 bytes +#kernel execution begins at 0x80000 diff --git a/scripts/pi4.sh b/scripts/pi4.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +os=bin/os9.bin + +qemu-system-aarch64 \ + -M virt\ + -m 1024\ + -smp 4\ + -cpu cortex-a53\ + -serial mon:stdio\ + -gdb tcp::7000 -S\ + -no-reboot \ + -nographic \ + -bios $os \ diff --git a/scripts/rules.mk b/scripts/rules.mk @@ -1,8 +1,11 @@ +# Define the target all as default +all: + +# Define default configuration variables CONF = amd64-linux TOOL = gnu -include $(PROJECTDIR)/config/$(CONF).mk -include $(PROJECTDIR)/config/toolchain/$(TOOL).mk +# Define helper macros for project directories INCDIR = $(PROJECTDIR)/include LIBDIR = $(PROJECTDIR)/lib BINDIR = $(PROJECTDIR)/bin @@ -10,36 +13,50 @@ DRVDIR = $(PROJECTDIR)/drivers FSDIR = $(PROJECTDIR)/fs SRCDIR = $(PROJECTDIR)/src SCRIPTDIR = $(PROJECTDIR)/scripts +BUILDDIR = $(PROJECTDIR)/scripts/build CONFDIR = $(PROJECTDIR)/config + +# library dependences helpers +LIBDEP =\ + $(LIBDIR)/libk.a\ + $(LIBDIR)/libc.a\ + $(LIBDIR)/lib9p.a\ + +# Include configuration definitions +include $(BUILDDIR)/conf/$(CONF).mk +include $(BUILDDIR)/tool/$(TOOL).mk + +# Locations for -I or -L in compiler, assembler or linker INCLUDES = -I$(INCDIR) -I$(INCDIR)/bits/$(ARCH)/ -I$(INCDIR)/bits/$(SYS) -ENVIRON = $(SCRIPTDIR)/env.sh - -LIBDEP = $(LIBDIR)/libk.a \ - $(LIBDIR)/libc.a \ - $(LIBDIR)/lib9p.a \ - -PROJ_CFLAGS = $(MORECFLAGS) \ - $(INCLUDES) \ - $(TOOLCFLAGS) \ - $(SYSCFLAGS) \ - $(CFLAGS) - -PROJ_LDFLAGS = $(MORELDFLAGS) \ - -L$(LIBDIR) \ - $(TOOLLDFLAGS) \ - $(SYSLDFLAGS) \ - $(LDFLAGS) - -PROJ_ASFLAGS = $(MOREASFLAGS) \ - $(TOOLASFLAGS) \ - $(SYSASFLAGS) \ - $(ASFLAGS) - -PROJ_LDLIBS = $(MORELDLIBS) \ - $(TOOLLDLIBS) \ - $(SYSLDLIBS) \ - $(LDLIBS) +# Definition of command line for cc, as, ld and emu +PROJ_CFLAGS =\ + $(MORECFLAGS)\ + $(INCLUDES)\ + $(TOOLCFLAGS)\ + $(SYSCFLAGS)\ + $(CFLAGS) + +PROJ_LDFLAGS =\ + $(MORELDFLAGS)\ + -L$(LIBDIR)\ + $(TOOLLDFLAGS)\ + $(SYSLDFLAGS)\ + $(LDFLAGS) + +PROJ_ASFLAGS =\ + $(MOREASFLAGS)\ + $(TOOLASFLAGS)\ + $(SYSASFLAGS)\ + $(ASFLAGS) + +PROJ_LDLIBS =\ + $(MORELDLIBS)\ + $(TOOLLDLIBS)\ + $(SYSLDLIBS)\ + $(LDLIBS) + +# Definition of tools CC = $(CROSS_COMPILE)$(COMP) AS = $(CROSS_COMPILE)$(ASM) LD = $(CROSS_COMPILE)$(LINKER) @@ -50,15 +67,17 @@ AR = $(CROSS_COMPILE)$(ARCHIVE) HOSTCC=$(COMP) FORALL= +@set -e ;\ - . $(ENVIRON); \ - pwd=$$PWD; \ for i in $(DIRS); \ do \ cd $$i; \ $(MAKE) $@; \ - cd $$pwd; \ + cd -; \ done +$(DIRS): FORCE + +@cd $@ && $(MAKE) + +# Generic rules .SUFFIXES: .map .dump .elf .bin .i .c.o: @@ -88,11 +107,18 @@ FORALL= +@set -e ;\ .elf.map: $(LD) -Map=$@ $< -o /dev/null -all: - FORCE: -clean: clean-files +clean: clean-files clean-dirs + +clean-dirs: + +@set -e; \ + for i in $(DIRS); \ + do \ + cd $$i; \ + $(MAKE) clean; \ + cd -; \ + done clean-files: rm -f *.i *.d *.o *.a $(TARGET) diff --git a/src/Makefile b/src/Makefile @@ -1,6 +1,5 @@ .POSIX: PROJECTDIR=.. -include $(PROJECTDIR)/scripts/rules.mk LIBS =\ libio\ @@ -11,12 +10,8 @@ DIRS =\ os9\ $(LIBS)\ +include $(PROJECTDIR)/scripts/rules.mk + all: os9 os9: $(LIBS) - -$(DIRS): FORCE - +@cd $@ && $(MAKE) - -clean: - $(FORALL) diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -1,7 +1,5 @@ .POSIX: PROJECTDIR =../.. -include $(PROJECTDIR)/scripts/rules.mk -include rules.mk DIRS = arch\ assert\ @@ -12,15 +10,14 @@ DIRS = arch\ string\ time\ +include $(PROJECTDIR)/scripts/rules.mk +include rules.mk + all: objlst.mk +@$(MAKE) -f Makefile.libc -$(DIRS): FORCE - +@cd $@ && $(MAKE) - objlst.mk: $(DIRS) FORCE - mklst $@ + ./mklst $@ clean: - $(FORALL) rm -f objlst.mk diff --git a/src/libc/Makefile.libc b/src/libc/Makefile.libc @@ -11,7 +11,7 @@ TARGET = $(LIBC) $(CRT) all: $(TARGET) $(LIBC): $(OBJS) - mklib -o $@ $? + $(SCRIPTDIR)/mklib -o $@ $? $(CRT): arch/$(ARCH)/$(SYS)/crt.o cp arch/$(ARCH)/$(SYS)/crt.o $@ diff --git a/src/libc/arch/amd64/Makefile b/src/libc/arch/amd64/Makefile @@ -1,15 +1,16 @@ .POSIX: PROJECTDIR =../../../.. + +DIRS =\ + netbsd\ + openbsd\ + dragonfly\ + linux\ + darwin\ + include $(PROJECTDIR)/scripts/rules.mk include ../../rules.mk OBJS = longjmp.o setjmp.o -DIRS = netbsd openbsd dragonfly linux darwin all: $(OBJS) $(SYS) - -$(SYS): FORCE - +@cd $@ && $(MAKE) - -clean: - $(FORALL) diff --git a/src/libc/arch/amd64/darwin/Makefile b/src/libc/arch/amd64/darwin/Makefile @@ -30,7 +30,7 @@ objs: $(OBJS) crt.o: ../crt-posix.s syscall: syscall.lst - gensys.sh syscall.lst + ./gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/dragonfly/Makefile b/src/libc/arch/amd64/dragonfly/Makefile @@ -31,7 +31,7 @@ objs: $(OBJS) crt.o: crt-posix.s syscall: syscall.lst - gensys.sh syscall.lst + ./gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/linux/Makefile b/src/libc/arch/amd64/linux/Makefile @@ -33,7 +33,7 @@ objs: $(OBJS) crt.o: ../crt-posix.s syscall: syscall.lst - gensys.sh syscall.lst + ./gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/netbsd/Makefile b/src/libc/arch/amd64/netbsd/Makefile @@ -34,7 +34,7 @@ objs: $(OBJS) crt.o: ../crt-posix.s ../../crt-netbsd.s syscall: syscall.lst - gensys.sh syscall.lst + ./gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/openbsd/Makefile b/src/libc/arch/amd64/openbsd/Makefile @@ -31,7 +31,7 @@ objs: $(OBJS) crt.o: ../crt-posix.s ../../crt-openbsd.s syscall: syscall.lst - gensys.sh syscall.lst + ./gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/arm32/Makefile b/src/libc/arch/arm32/Makefile @@ -1,10 +1,12 @@ .POSIX: PROJECTDIR =../../../.. + +DIRS = linux + include $(PROJECTDIR)/scripts/rules.mk include ../../rules.mk OBJS = longjmp.o setjmp.o -DIRS = linux all: $(OBJS) $(SYS) diff --git a/src/libc/arch/arm32/linux/Makefile b/src/libc/arch/arm32/linux/Makefile @@ -33,7 +33,7 @@ objs: $(OBJS) crt.o: ../crt-posix.s syscall: syscall.lst - gensys.sh syscall.lst + ./gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/arm64/Makefile b/src/libc/arch/arm64/Makefile @@ -1,15 +1,11 @@ .POSIX: PROJECTDIR =../../../.. + +DIRS = linux os9 + include $(PROJECTDIR)/scripts/rules.mk include ../../rules.mk OBJS = longjmp.o setjmp.o -DIRS = linux os9 all: $(OBJS) $(SYS) - -$(SYS): FORCE - +@cd $@ && $(MAKE) - -clean: - $(FORALL) diff --git a/src/libio/Makefile b/src/libio/Makefile @@ -12,4 +12,4 @@ TARGET = $(LIBDIR)/lib9p.a all: $(TARGET) $(TARGET): $(OBJS) - mklib -o $@ $? + $(SCRIPTDIR)/mklib -o $@ $? diff --git a/src/libk/Makefile b/src/libk/Makefile @@ -11,6 +11,7 @@ OBJS =\ tokenize.o\ frombytes.o\ fromstring.o\ + getline.o\ tobytes.o\ tostring.o\ kassert.o\ @@ -23,4 +24,4 @@ TARGET = $(LIBDIR)/libk.a all: $(TARGET) $(TARGET): $(OBJS) - mklib -o $@ $? + $(SCRIPTDIR)/mklib -o $@ $? diff --git a/src/libk/getline.c b/src/libk/getline.c @@ -0,0 +1,21 @@ +#include <os9/os9.h> + +#include <libk.h> + +int +getline(Chan *c, char *line, int size) +{ + int n, r; + char ch; + + for (ch = n = 0; n < size-1 && ch != '\n'; ++n) { + if ((r = devread(c, &ch, 1)) < 0) + return -1; + if (r == 0) + break; + line[n] = ch; + } + line[n] = '\0'; + + return n; +} diff --git a/src/libk/ksnprint.c b/src/libk/ksnprint.c @@ -19,7 +19,7 @@ ksnprint(char *str, size_t len, const char *fmt, ...) doprnt(&stream, fmt, ap); va_end(ap); - str[stream.cnt++] = '\0'; + str[stream.cnt] = '\0'; return stream.cnt; } diff --git a/src/os9/.gitignore b/src/os9/.gitignore @@ -0,0 +1 @@ +version.h diff --git a/src/os9/Makefile b/src/os9/Makefile @@ -1,22 +1,27 @@ .POSIX: PROJECTDIR=../.. + +DIRS =\ + arch\ + dev\ + hosted\ + include $(PROJECTDIR)/scripts/rules.mk OBJS =\ alloc.o\ dlang.o\ proc.o\ - sched.o\ sys.o\ dev/builtin.o\ -DIRS =\ - arch\ - dev\ - hosted\ - all: image +version.h: + ./mkver + +sys.o: version.h + image: builtin.o FORCE +test $(MODE) = hosted && cd hosted || cd arch && $(MAKE) @@ -24,9 +29,7 @@ builtin.o: $(OBJS) $(LD) $(PROJ_LDFLAGS) -r -o $@ $(OBJS) dev/builtin.o: dev - -$(DIRS): FORCE - +@cd $@ && $(MAKE) + touch $@ clean: - $(FORALL) + rm -f version.h diff --git a/src/os9/arch/Makefile b/src/os9/arch/Makefile @@ -1,11 +1,9 @@ .POSIX: PROJECTDIR=../../.. -include $(PROJECTDIR)/scripts/rules.mk DIRS=arm64 +include $(PROJECTDIR)/scripts/rules.mk + all: +@cd $(ARCH) && $(MAKE) - -clean: - $(FORALL) diff --git a/src/os9/arch/arm64/.gitignore b/src/os9/arch/arm64/.gitignore @@ -1,4 +1,3 @@ ecstr.c sysreg.h sysreg.s -version.h diff --git a/src/os9/arch/arm64/Makefile b/src/os9/arch/arm64/Makefile @@ -15,7 +15,6 @@ COMMON_OBJS =\ crt.o\ fpu.o\ mmu.o\ - cache.o\ gic.o\ $(SRCDIR)/os9/builtin.o \ @@ -34,20 +33,15 @@ TARGET = $(BINDIR)/$(OS9).bin all: $(TARGET) ecstr.c: ec.h - mkecstr ec.h + ./mkecstr ec.h $(COMMON_OBJS): sysreg.h -main.o: version.h - sysreg.h: sysreg.lst - mksysreg -h sysreg.lst + ./mksysreg -h sysreg.lst sysreg.s: sysreg.lst - mksysreg -s sysreg.lst - -version.h: - mkver + ./mksysreg -s sysreg.lst $(BINDIR)/9fvp.elf: $(9FVP_OBJS) $(LIBDEP) $(LD) $(FLAGS) $(9FVP_OBJS) -lk -lc $(PROJ_LDLIBS) -o $@ @@ -58,4 +52,4 @@ $(BINDIR)/9pi3.elf: $(9RPI3_OBJS) $(LIBDEP) clean: rm -f ecstr.c rm -f $(TARGET) - rm -f sysreg.h sysreg.s version.h + rm -f sysreg.h sysreg.s diff --git a/src/os9/arch/arm64/arch.h b/src/os9/arch/arm64/arch.h @@ -23,13 +23,11 @@ extern void main(Mach *); extern void syswr(int, unsigned long long); extern unsigned long long sysrd(int); -extern void invicache(void); extern void invalltlb(void); extern void invtlb(uintptr_t); extern void invdcachesetway(void *); extern void *outsync(void); -extern void icache(void); extern void immu(void); extern void ifpu(void); extern void igic(void); diff --git a/src/os9/arch/arm64/arch.s b/src/os9/arch/arm64/arch.s @@ -49,12 +49,6 @@ invdcachesetway: RET .TEXT - .GLOBL invicache -invicache: - IC IALLU - RET - - .TEXT .GLOBL inm8 inm8: LDRB W0,[X0] diff --git a/src/os9/arch/arm64/cache.c b/src/os9/arch/arm64/cache.c @@ -1,102 +0,0 @@ -#include <os9/os9.h> - -#include "sysreg.h" -#include "arch.h" - -#define NR_LEVELS 7 - -/* clidr_el1 */ -#define LOC_SHIFT 24 -#define LOC_MASK 0x7 -#define CTYPE_MASK 0x7 - -/* ccsidr_el1 */ -#define NSETS_SHIFT 13 -#define NSETS_MASK 0x7fff -#define NWAYS_SHIFT 3 -#define NWAYS_MASK 0x3ff -#define LINE_MASK 0x7 - -/* csselr_el1 */ -#define LEVEL_SHIFT 1 - - -static unsigned -log2(unsigned long long v, unsigned width) -{ - unsigned nbits, i = width; - - for (nbits = 0; i-- > 0; nbits++) { - if ((v & (1ull << i)) != 0) - break; - } - return width - nbits - 1; -} - -static void -invdcachelvl(unsigned l) -{ - unsigned long long ccsidr; - unsigned nsets, nways, size, shift, i, j; - - syswr(CSSELR_EL1, l << LEVEL_SHIFT); - barrier(CODE); - - ccsidr = sysrd(CCSIDR_EL1); - nsets = ((ccsidr >> NSETS_SHIFT) & NSETS_MASK) + 1; - nways = ((ccsidr >> NWAYS_SHIFT) & NWAYS_MASK) + 1; - size = (ccsidr & LINE_MASK) + 4; - shift = 32 - log2(nways, 32); - - for (i = 0; i < nways; i++) { - for (j = 0; j < nsets; j++) { - uintptr_t addr; - - addr = (uintptr_t)i << shift | j << size | l << 1; - invdcachesetway((void *)addr); - } - } - barrier(DATA); -} - -static void -invdcache(void) -{ - unsigned long long clidr; - unsigned l; - enum cachetype { - NOCACHE, - ICACHE, - DCACHE, - HARVARD, - UNIFIED - } type; - - barrier(DATA); - - clidr = sysrd(CLIDR_EL1); - if (((clidr >> LOC_SHIFT) & LOC_MASK) == 0) - return; - - for (l = 0; l < NR_LEVELS; l++) { - type = clidr & CTYPE_MASK; - if (type == NOCACHE || type == ICACHE) - continue; - - invdcachelvl(l); - clidr >>= 3; - } -} - -void -icache(void) -{ - uint64_t sctlr; - - invicache(); - invdcache(); - - sctlr = sysrd(SCTLR_EL1); - sctlr |= C | I; - syswr(SCTLR_EL1, sctlr); -} diff --git a/src/os9/arch/arm64/crt.s b/src/os9/arch/arm64/crt.s @@ -48,7 +48,6 @@ EL1: BL memset BL imach - BL icache BL immu BL initmap BL mmuon diff --git a/src/os9/arch/arm64/ctx.c b/src/os9/arch/arm64/ctx.c @@ -108,6 +108,21 @@ panic(const char *msg) } int +dupctx(Task *tp) +{ + proc->ctx.r[X29] = 1; + getctx(&tp->ctx); + tp->ctx[X29] = 0; + + /* + * When this function is called tp and proc are different pointers + * but when the context of tp is restored and the execution comes + * here then tp and proc are the same pointer + */ + return proc->ctx.r[X29]; +} + +void ictx(Task *tp, void *fn) { uint64_t *rp; @@ -119,6 +134,4 @@ ictx(Task *tp, void *fn) rp[SP_EL1] = (uint64_t) tp->kstack; rp[SPSR] = sysrd(SPSR_EL1); rp[ELR] = (uint64_t) fn; - - return 0; } diff --git a/src/os9/arch/arm64/fvp.c b/src/os9/arch/arm64/fvp.c @@ -24,7 +24,7 @@ putch(int c) } else { if (c == '\n') putch('\r'); - while (inm32(early+ 6) & 1<<5) + while (inm32(early+6) & 1<<5) ; outm32(c, early); } diff --git a/src/os9/arch/arm64/main.c b/src/os9/arch/arm64/main.c @@ -6,26 +6,6 @@ #include "sysreg.h" #include "arch.h" -static void -info(void) -{ - kprint("Booting os9\n"); - kprint("os9: version %s\n", - OS9VERSION); -} - -char * -getconf(char *name) -{ - static char constxt[] = - "addin #t0/raw\n" - "addout #t0/raw\n" - "echo on\n" - "cooked on\n"; - - return constxt; -} - int getch(void) { diff --git a/src/os9/arch/arm64/mmu.c b/src/os9/arch/arm64/mmu.c @@ -274,6 +274,7 @@ taskmap(void) /* * TODO: setup SCTLR_EL1.WXN + * TODO: setup TTBR0_EL1 */ } diff --git a/src/os9/arch/arm64/pi3.c b/src/os9/arch/arm64/pi3.c @@ -4,13 +4,12 @@ #include "arch.h" -static uint32_t *early = (uint32_t *) 0x1C090000; - +static uint32_t *early = (uint32_t *) 0x3F201000; Mach mach = { - .phystack = 0x00080000, - .phytext = 0x00000000, - .kzero = 0xFFFFFF0000000000 - 0x00000000, + .phystack = 0x80000, + .phytext = 0x80000, + .kzero = 0xFFFFFF0000000000 - 0x80000, }; void @@ -24,7 +23,7 @@ putch(int c) } else { if (c == '\n') putch('\r'); - while (inm32(early+ 6) & 1<<5) + while (inm32(early+6) & 1<<5) ; outm32(c, early); } diff --git a/src/os9/cfg/9fvp b/src/os9/cfg/9fvp @@ -1,7 +0,0 @@ -dev - root - uart - pl011 base=0x1C090000,clk=24000000,rate=115200 - pl011 base=0x1c0c0000,clk=24000000,rate=115200 - cons -end diff --git a/src/os9/cfg/9fvp/conf b/src/os9/cfg/9fvp/conf @@ -0,0 +1,9 @@ +write #c/ctl addin #t0/raw +write #c/ctl addout #t0/raw +write #c/ctl echo on +write #c/ctl cooked on +bind #c /dev/cons +bind #p /proc +bind #t0 /dev/uart0 +bind #t1 /dev/uart1 +mount #F /fips /blobs/fip.bin diff --git a/src/os9/cfg/9fvp/kernel b/src/os9/cfg/9fvp/kernel @@ -0,0 +1,11 @@ +dev + root + uart + pl011 base=0x1C090000,clk=24000000,rate=115200 + pl011 base=0x1c0c0000,clk=24000000,rate=115200 + cons + fip +blob + fip.bin 0x8000000,0x80000 + ../cfg/9fvp/conf +end diff --git a/src/os9/cfg/9hosted b/src/os9/cfg/9hosted @@ -1,9 +0,0 @@ -dev - root - uart - dummyuart base=0x1c0c0000,clk=24000000,cfg=b115200 l8 #t0 - dummyuart base=0x1c0c0100,clk=24000000 #t1 - cons - ar - proc -end diff --git a/src/os9/cfg/9hosted/conf b/src/os9/cfg/9hosted/conf @@ -0,0 +1,5 @@ +write #c/ctl addin #t0/raw +write #c/ctl addout #t0/raw +bind #p /proc +bind #c /dev/cons +bind #t0 /dev/uart0 diff --git a/src/os9/cfg/9hosted/kernel b/src/os9/cfg/9hosted/kernel @@ -0,0 +1,10 @@ +dev + root + uart + dummyuart base=0x1c0c0000,clk=24000000,cfg=b115200 l8 #t0 + cons + ar + proc +blob + ../cfg/9hosted/conf +end diff --git a/src/os9/cfg/9pi3 b/src/os9/cfg/9pi3 @@ -1,7 +0,0 @@ -dev - root - uart - pl011 base=0x1C090000,clk=24000000,rate=115200 - pl011 base=0x1c0c0000,clk=24000000,rate=115200 - cons -end diff --git a/src/os9/cfg/9pi3/conf b/src/os9/cfg/9pi3/conf @@ -0,0 +1,8 @@ +write #c/ctl addin #t0/raw +write #c/ctl addout #t0/raw +write #c/ctl echo on +write #c/ctl cooked on +bind #c /dev/cons +bind #p /proc +bind #t0 /dev/uart0 +bind #t1 /dev/uart1 diff --git a/src/os9/cfg/9pi3/kernel b/src/os9/cfg/9pi3/kernel @@ -0,0 +1,9 @@ +dev + root + uart + pl011 base=0x1C090000,clk=24000000,rate=115200 + pl011 base=0x1c0c0000,clk=24000000,rate=115200 + cons +blob + ../cfg/9fvp/conf +end diff --git a/src/os9/dev/Makefile b/src/os9/dev/Makefile @@ -5,8 +5,8 @@ include $(PROJECTDIR)/scripts/rules.mk all clean: devs.mk blobs.mk $(MAKE) -f Makefile.drv $@ -devs.mk: ../cfg/$(OS9) - mkdev ../cfg/$(OS9) +devs.mk: ../cfg/$(OS9)/kernel + ./mkdev ../cfg/$(OS9)/kernel -blobs.mk: ../cfg/$(OS9) - mkblob ../cfg/$(OS9) +blobs.mk: ../cfg/$(OS9)/kernel + ./mkblob ../cfg/$(OS9)/kernel diff --git a/src/os9/dev/Makefile.drv b/src/os9/dev/Makefile.drv @@ -14,13 +14,15 @@ all: builtin.o builtin.o: $(OBJS) $(LD) $(PROJ_LDFLAGS) -r -o $@ $(OBJS) -devc.c: ../cfg/$(OS9) - mkdevc ../cfg/$(OS9) +devc.c: ../cfg/$(OS9)/kernel + ./mkdevc ../cfg/$(OS9)/kernel + +blobfil.h: ../cfg/$(OS9)/kernel devroot.c: blobfil.h blobs.h -blobs.h: ../cfg/$(OS9) - mkblobh ../cfg/$(OS9) +blobs.h: ../cfg/$(OS9)/kernel + ./mkblobh ../cfg/$(OS9)/kernel clean: rm -f blobfil.h blobs.h blobs.mk devs.mk devc.c diff --git a/src/os9/dev/dev.c b/src/os9/dev/dev.c @@ -19,9 +19,6 @@ * The use of mutexes is then transparent for the drivers. */ -static Chan fdset[NR_CHANS]; -static Chan slash; -static struct mpoint mpoints[NR_MPOINTS]; int sameqid(Qid q1, Qid q2) @@ -32,8 +29,9 @@ sameqid(Qid q1, Qid q2) Chan * newchan(unsigned char type) { - Chan *c = NULL; int i; + Chan *c = NULL; + Chan *fdset = proc->fds->fdset; for (i = 0; i < NR_CHANS; i++) { c = &fdset[i]; @@ -66,13 +64,14 @@ static Chan * fd2chan(int fd) { Chan *c; + Chan *fdset = proc->fds->fdset; if (fd < 0 || fd >= NR_CHANS) goto badfd; c = &fdset[fd]; lock(&c->mutex); - if (fdset[fd].type == NODEV) + if (c->type == NODEV) goto ubadfd; return c; @@ -86,6 +85,8 @@ badfd: static int chan2fd(Chan *c) { + Chan *fdset = proc->fds->fdset; + return (c == NULL) ? -1 : (c - fdset); } @@ -168,6 +169,7 @@ mntpoint(int type, Qid qid) { Chan *cn; struct mpoint *mp; + struct mpoint *mpoints = proc->ns->mpoints; for (mp = mpoints; mp < &mpoints[NR_MPOINTS]; mp++) { lock(&mp->m); @@ -223,7 +225,7 @@ namec(char *name, int mode) c = NULL; switch (name[0]) { case '/': - c = clone(&slash, NULL); + c = clone(&proc->slash, NULL); s = name; break; case '#': @@ -646,6 +648,7 @@ addmntpoint(Chan *c, char *new) int i; Chan *cn; struct mpoint *mp; + struct mpoint *mpoints = proc->ns->mpoints; if ((cn = namec(new, O_READ)) == NULL) goto err0; @@ -726,6 +729,7 @@ void idev(void) { Chan *c; + Chan *fdset = proc->fds->fdset; for (c = fdset; c < &fdset[NR_CHANS]; c++) c->type = NODEV; @@ -733,7 +737,7 @@ idev(void) if ((c = attach('/', 0)) == NULL) panic("idev:attach"); - if (!clone(c, &slash)) + if (!clone(c, &proc->slash)) panic("idev:clone"); delchan(c); diff --git a/src/os9/dev/devproc.c b/src/os9/dev/devproc.c @@ -24,34 +24,45 @@ static Dirtab tasktab[] = { }; static int -procfsgen(Chan *c, Dirtab *tab, int ntab, int n, Dir *dir) +procfsgen(Chan *c, int n, Dir *dir) { Task *tp; char nam[NAMELEN]; - n = getntask(n, &tp); - if (n <= 0) - return 0; - - ksnprint(nam, NAMELEN, "%d", tp->tid); - mkentry(c, dir, - nam, 0, - QID(CHDIR, 0, PATH(Qtaskdir, tp->tid)), - O_READ); - - return 1; + switch (n) { + case NR_TASKS: + mkentry(c, dir, + "cur", 0, + QID(CHDIR, 0, PATH(Qtaskdir, proc->pid)), + O_READ); + return 1; + case NR_TASKS+1: + return -1; + default: + n = getntask(n, &tp); + if (n < 0) + return -1; + if (n == 0) + return 0; + + ksnprint(nam, NAMELEN, "%d", tp->pid); + mkentry(c, dir, + nam, 0, + QID(CHDIR, 0, PATH(Qtaskdir, tp->pid)), + O_READ); + unlocktask(tp); + return 1; + } } static int -taskgen(Chan *c, Dirtab *tab, int ntab, int n, Dir *dir) +taskgen(Chan *c, int n, Dir *dir) { - int tid = TASK(c->qid); - - if (!devgen(c, tasktab, NELEM(tasktab), n, dir)) - return 0; - dir->qid.path = PATH(dir->qid.path, tid); + int r, pid = TASK(c->qid); - return 1; + if ((r = devgen(c, tasktab, NELEM(tasktab), n, dir)) == 1) + dir->qid.path = PATH(dir->qid.path, pid); + return r; } static int @@ -59,9 +70,9 @@ procgen(Chan *c, Dirtab *tab, int ntab, int n, Dir *dir) { switch (TYPE(c->qid)) { case Qprocfs: - return procfsgen(c, tab, ntab, n, dir); + return procfsgen(c, n, dir); case Qtaskdir: - return taskgen(c, tab, ntab, n, dir); + return taskgen(c, n, dir); default: return 0; } @@ -81,26 +92,25 @@ taskattrread(Chan *c, void *buf, int n) char tmp[1024]; if ((tp = gettask(TASK(c->qid))) == NULL) - panic(""); + panic("taskattrread:gettask"); len = ksnprint(tmp, sizeof(tmp), - "name: %s\n" - "tid: %d\n" + "pid: %d\n" "entry: %p\n" "stack size: %zd\n" "base prio: %d\n" "period: %ld\n" "capacity: %ld\n" "deadline: %ld\n", - tp->tname, - tp->tid, - tp->tentry, + tp->pid, + tp->entry, tp->stack, tp->prio, tp->period, tp->capacity, tp->deadline); + unlocktask(tp); if (len == sizeof(tmp)) panic("temporary buffer too short"); @@ -114,11 +124,11 @@ taskstatusread(Chan *c, void *buf, int n) Task *tp; char tmp[1024]; static char *states[] = { - [TDORMANT] = "dormant", + [TINIT] = "init", [TREADY] = "ready", [TRUNNING] = "running", [TWAITING] = "waiting", - [FAULTED] = "faulted", + [TFAULTED] = "faulted", }; if ((tp = gettask(TASK(c->qid))) == NULL) @@ -138,6 +148,7 @@ taskstatusread(Chan *c, void *buf, int n) states[tp->state], tp->affinity, tp->retainprio); + unlock(&tp->m); if (len == sizeof(tmp)) panic("temporary buffer too short"); @@ -167,14 +178,14 @@ procstat(Chan *c, char *file, unsigned char *buf, int n) } Dev procdevtab = { - .id = 'p', - .stat = procstat, - .clone = devclone, - .attach = devattach, - .walk = procwalk, - .read = procread, - .write = deverrwrite, - .mount = deverrmount, - .seek = devseek, - .sync = devsync, + .id = 'p', + .stat = procstat, + .clone = devclone, + .attach = devattach, + .walk = procwalk, + .read = procread, + .write = deverrwrite, + .mount = deverrmount, + .seek = devseek, + .sync = devsync, }; diff --git a/src/os9/dev/devuart.c b/src/os9/dev/devuart.c @@ -219,6 +219,7 @@ uartlink(Uartphy *phy, Attr *attr) Attr *a; char *cfg = NULL; + kprint("uart: Linking uart%d %s", nuarts, phy->name); if (nuarts == NR_UARTS) panic("uartlink1"); @@ -228,6 +229,7 @@ uartlink(Uartphy *phy, Attr *attr) uarts[nuarts++] = up; for (a = attr; a->key; a++) { + kprint(" %s=%s", a->key, a->value); if (!strcmp(a->key, "base")) up->base = (void *) strtoull(a->value, NULL, 0); else if (!strcmp(a->key, "clk")) @@ -235,6 +237,7 @@ uartlink(Uartphy *phy, Attr *attr) else if (!strcmp(a->key, "cfg")) cfg = a->value; } + kprint("\n"); (*phy->init)(up, attr); if (!cfg) diff --git a/src/os9/dev/dummyuart.c b/src/os9/dev/dummyuart.c @@ -78,6 +78,7 @@ dummyuartstatus(Uart *up, struct uartstat *st) } Uartphy dummyuartphy = { + .name = "dummyuart", .init = dummyuartinit, .setbauds = setbauds, .read = dummyuartread, diff --git a/src/os9/dev/mkblob b/src/os9/dev/mkblob @@ -4,7 +4,7 @@ set -e trap 'rm -f $$.tmp' EXIT HUP INT QUIT TERM rm -f blobs.mk -section blob $@ | +./section blob $@ | awk -v type=${type=k} ' NF==1 {blobfil[$1] = 1} END {mkrules()} @@ -17,6 +17,6 @@ function mkrules() print "" printf "blobfil.h: $(BLOBS)\n" - printf "\tmkblobfil $(BLOBS)\n" + printf "\t./mkblobfil $(BLOBS)\n" } '> $$.tmp && mv $$.tmp blobs.mk diff --git a/src/os9/dev/mkblobh b/src/os9/dev/mkblobh @@ -5,7 +5,7 @@ trap 'rm -f $$.tmp' EXIT HUP INT QUIT TERM rm -f blobs.h -section blob $@ | +./section blob $@ | awk -v type=${type=k} ' NF==2 {blobaddr[$1] = $2} {blob[$1] = 1} diff --git a/src/os9/dev/mkdev b/src/os9/dev/mkdev @@ -2,7 +2,7 @@ trap 'rm -f $$.tmp' EXIT HUP INT QUIT TERM -section dev $@ | +./section dev $@ | awk ' BEGIN {print "DEVS =\\"} /^\t\t/ {objs[$1 ".o"] = 1; next} diff --git a/src/os9/dev/mkdevc b/src/os9/dev/mkdevc @@ -2,7 +2,7 @@ trap 'rm -f $$.tmp' EXIT HUP INT QUIT TERM -section dev $@ | +./section dev $@ | awk ' /^\t\t/ {devs[dev]++ phys[$1] = dev diff --git a/src/os9/dev/pl011.c b/src/os9/dev/pl011.c @@ -378,6 +378,7 @@ pl011status(Uart *up, struct uartstat *st) } Uartphy pl011phy = { + .name = "pl011", .init = pl011init, .setbauds = setbauds, .read = pl011read, diff --git a/src/os9/dev/uart.h b/src/os9/dev/uart.h @@ -41,6 +41,7 @@ struct uart { }; struct uartphy { + char *name; void (*init)(Uart *up, Attr *attr); int (*setbauds)(Uart *up, long rate); int (*signal)(Uart *up, int mask, int val); diff --git a/src/os9/dlang.c b/src/os9/dlang.c @@ -10,6 +10,7 @@ #include <string.h> #define PREFIX "> " +#define PREFIX2 "# " #define NR_ARGC_MAX 5 struct args { @@ -76,23 +77,33 @@ do_help(const struct cmd *cmd, struct args *args) { for (cmd = cmds; cmd->name; cmd++) { char *s = cmd->helpmsg; - kprint("%s\n", s); + kprint(PREFIX2 "%s\n", s); } return 0; } static int -do_cat(const struct cmd *cmd, struct args *args) +do_read(const struct cmd *cmd, struct args *args) { - int n; + int n, ch; Chan *c; - char buf[100]; + char buf[100], *bp; if ((c = devopen(args->argv[1], O_READ)) == NULL) goto err; - while ((n = devread(c, buf, sizeof(buf))) > 0) - devwrite(console, buf, n); + ch = -1; + kprint(PREFIX2); + while ((n = devread(c, buf, sizeof(buf))) > 0) { + for (bp = buf; bp < &buf[n]; bp++) { + if (ch == '\n') + kprint(PREFIX2); + ch = *bp; + kprint("%c", ch); + } + } + if (ch != '\n') + kprint("\n"); if (devclose(c) < 0 || n < 0) goto err; @@ -100,7 +111,7 @@ do_cat(const struct cmd *cmd, struct args *args) return 0; err: - kprint(PREFIX "ERR cat: %e\n"); + kprint(PREFIX "ERR read: %e\n"); return 0; } @@ -118,23 +129,21 @@ do_ls(const struct cmd *cmd, struct args *args) while ((n = devread(c, buf, DIRLEN)) > 0) { if (p9todir(&dentry, buf, n) < 0) goto err; - kprint("%s\n", dentry.name); + kprint(PREFIX2 "%s\n", dentry.name); } - devclose(c); - - if ( n < 0) + if (devclose(c) || n < 0) goto err; return 0; err: - kprint(PREFIX "ERR ls:%e"); + kprint(PREFIX "ERR ls:%e\n"); return 0; } static int -do_echo(const struct cmd *cmd, struct args *args) +do_write(const struct cmd *cmd, struct args *args) { int i, len, offset, n; Chan *c; @@ -161,7 +170,7 @@ do_echo(const struct cmd *cmd, struct args *args) return 0; err: - kprint(PREFIX "ERR echo:%e"); + kprint(PREFIX "ERR write:%e\n"); return 0; } @@ -172,12 +181,12 @@ do_stat(const struct cmd *cmd, struct args *args) if (dirstat(args->argv[1], &dir) < 0) goto err; - kprint("name: %s\n" - "length: %ld\n" - "mode: %x\n" - "type: %d\n" - "dev: %d\n" - "qid: %x,%lx,%llx\n", + kprint(PREFIX2 "name: %s\n" + PREFIX2 "length: %ld\n" + PREFIX2 "mode: %x\n" + PREFIX2 "type: %d\n" + PREFIX2 "dev: %d\n" + PREFIX2 "qid: %x,%lx,%llx\n", dir.name, dir.length, dir.mode, @@ -188,7 +197,23 @@ do_stat(const struct cmd *cmd, struct args *args) return 0; err: - kprint(PREFIX "ERR stat:%e"); + kprint(PREFIX "ERR stat:%e\n"); + return 0; +} + +static int +do_bind(const struct cmd *cmd, struct args *args) +{ + if (bind(args->argv[1], args->argv[2]) < 0) + kprint(PREFIX "ERR bind:%e\n"); + return 0; +} + +static int +do_mount(const struct cmd *cmd, struct args *args) +{ + if (mount(args->argv[1], args->argv[2], args->argv[3]) < 0) + kprint(PREFIX "ERR mount:%e\n"); return 0; } @@ -218,24 +243,24 @@ do_x(const struct cmd *cmd, struct args *args) case 'x': u16 = addr; while (n-- > 0) - kprint("%x\n", (int) *u16++); + kprint(PREFIX2 "%x\n", (int) *u16++); return 0; case 'X': u32 = addr; while (n-- > 0) - kprint("%lx\n", (long) *u32++); + kprint(PREFIX2 "%lx\n", (long) *u32++); return 0; case 'Y': u64 = addr; while (n-- > 0) - kprint("%x\n", (long long) *u64++); + kprint(PREFIX2 "%x\n", (long long) *u64++); return 0; default: goto badfmt; } badfmt: - kprint(PREFIX "ERR x: bad format"); + kprint(PREFIX "ERR x: bad format\n"); return 0; } @@ -337,18 +362,18 @@ static const struct cmd cmds[] = { .helpmsg = "List content of a directory: ls path", }, { - .name = "cat", - .eval = do_cat, + .name = "read", + .eval = do_read, .min = 2, .max = 2, - .helpmsg = "Read content from a file: cat path", + .helpmsg = "Read content from a file: read path", }, { - .name = "echo", - .eval = do_echo, + .name = "write", + .eval = do_write, .min = 3, .max = NR_ARGC_MAX, - .helpmsg = "Write content to a file: echo path string ...", + .helpmsg = "Write content to a file: write path string ...", }, { .name = "stat", @@ -358,6 +383,20 @@ static const struct cmd cmds[] = { .helpmsg = "Display stat attribute: stat path", }, { + .name = "bind", + .eval = do_bind, + .min = 3, + .max = 3, + .helpmsg = "bind one directory in other: bind from to", + }, + { + .name = "mount", + .eval = do_mount, + .min = 4, + .max = 4, + .helpmsg = "mount one directory in other: mount from to spec", + }, + { .name = "x", .eval = do_x, .min = 2, diff --git a/src/os9/hosted/Makefile b/src/os9/hosted/Makefile @@ -4,18 +4,16 @@ include $(PROJECTDIR)/scripts/rules.mk OBJS =\ arch.o\ + ctx.o\ mmu.o\ lock.o\ main.o\ $(LIBDIR)/crt.o\ $(SRCDIR)/os9/builtin.o\ -TARGET = $(BINDIR)/os9.elf +TARGET = $(BINDIR)/$(OS9).elf all: $(TARGET) -$(DIRS): FORCE - cd $@ && $(MAKE) - -$(BINDIR)/os9.elf: $(OBJS) $(LIBDEP) +$(TARGET): $(OBJS) $(LIBDEP) $(LD) $(PROJ_LDFLAGS) $(OBJS) $(PROJ_LDLIBS) -lk -lc -o $@ diff --git a/src/os9/hosted/arch.c b/src/os9/hosted/arch.c @@ -17,10 +17,17 @@ halt(void) abort(); } +/* + * we don't implement context switch in hosted mode + * so, this function is going to be called only once + * with the entry point of the initial task + */ void swtch(Context *ctx) { - longjmp(recover, 1); + void (*fn)(void) = (void (*)(void)) ctx->entry; + + (*fn)(); } uint8_t @@ -59,13 +66,7 @@ outm32(uint32_t val, void *addr) return 0; } -int -ictx(Task *tp, void *fn) +void +idle(void) { - if (!newstack(tp)) - return -1; - tp->ctx.stack = (void *) tp->stack.va; - tp->ctx.entry = fn; - - return 0; } diff --git a/src/os9/hosted/ctx.c b/src/os9/hosted/ctx.c @@ -1,12 +1,16 @@ #include <os9/os9.h> int +dupctx(Task *tp) +{ + tp->ctx.entry = proc->ctx.entry; + + return 1; +} + +void ictx(Task *tp, void *fn) { - if (!newstack(tp)) - return -1; tp->ctx.stack = (void *) tp->stack.va; tp->ctx.entry = fn; - - return 0; } diff --git a/src/os9/hosted/main.c b/src/os9/hosted/main.c @@ -53,19 +53,10 @@ imach(void) exit(EXIT_FAILURE); } -char * -getconf(char *name) -{ - static char constxt[] = - "addin #t0/raw\n" - "addout #t0/raw\n"; - - return constxt; -} - int main(int argc, char *argv[]) { + info(); imach(); isys(); diff --git a/src/os9/hosted/mmu.c b/src/os9/hosted/mmu.c @@ -3,11 +3,12 @@ int vmap(phyaddr_t pa, uintptr_t va, int flags) { - return -1; + return 0; } Ptable * initptable(Task *tp) { - return NULL; + tp->ptable.assid = 0; + return &tp->ptable; } diff --git a/src/os9/arch/arm64/mkver b/src/os9/mkver diff --git a/src/os9/proc.c b/src/os9/proc.c @@ -5,40 +5,13 @@ #include <libk.h> -struct nspace { - Ref ref; - mutex_t m; - struct mpoint mpoints[NR_MPOINTS]; -}; - -struct fdset { - Ref ref; - mutex_t m; - Chan fdset[NR_CHANS]; -}; - static Task tasktab[NR_TASKS]; -static Task *freel; - -static void -initfn(void) -{ -} - -void -iproc(void) -{ - Task *tp; - - for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) { - tp->tid = tp->ptid = tp->pid = tp->ppid = -1; - tp->next = (tp < &tasktab[NR_TASKS-1]) ? tp+1 : NULL; - } - freel = tasktab; +static mutex_t procm; - if (!kproc(initfn)) - panic("init task failed"); -} +/* per cpu globals */ +Task *proc; +long long now; +int cpuid; void initref(Ref *rp) @@ -67,6 +40,20 @@ decref(Ref *rp) return r; } +void +locktask(Task *tp) +{ + if (tp != proc) + lock(&tp->m); +} + +void +unlocktask(Task *tp) +{ + if (tp != proc) + unlock(&tp->m); +} + int getntask(int n, Task **tpp) { @@ -78,9 +65,9 @@ getntask(int n, Task **tpp) } tp = &tasktab[n]; - lock(&tp->m); - if (tp->mode == PDISABLED) { - unlock(&tp->m); + locktask(tp); + if (tp->state == TFREE) { + unlocktask(tp); return 0; } @@ -89,18 +76,23 @@ getntask(int n, Task **tpp) } Task * -gettask(int tid) +gettask(int pid) { - Task *tp; + Task *tp, *p; - for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) { - lock(&tp->m); - if (tp->mode != PDISABLED && tp->tid == tid) - return tp; - unlock(&tp->m); + tp = NULL; + lock(&procm); + for (p = tasktab; p < &tasktab[NR_TASKS]; ++p) { + locktask(p); + if (p->pid == pid && p->state != TFREE) { + tp = p; + break; + } + unlocktask(p); } + unlock(&procm); - return NULL; + return tp; } int @@ -163,24 +155,43 @@ newstack(Task *tp) return mp; } +Map * +newkstack(Task *tp) +{ + Map *mp = &tp->kstack; + + initref(&mp->ref); + mp->name = "kstack"; + mp->perm = MW | MR; + + mp->pa = -1; + mp->va = KSTACKADDR & (STACKADDR-1); + mp->siz = PAGESIZE; + + if (mapseg(mp) < 0) + return NULL; + + return mp; +} + static Task * newslot(void) { Task *tp; - static mutex_t m; - lock(&m); - if (!freel) { - tp = NULL; - errno = ENOMEM; - } else { - tp = freel; - freel = tp->next; + lock(&procm); + for (tp = tasktab; tp < &tasktab[NR_TASKS]; tp++) { + locktask(tp); + if (tp->state == TFREE) + break; + unlocktask(tp); } - lock(&tp->m); - unlock(&m); + unlock(&procm); - tp->next = NULL; + if (tp == &tasktab[NR_TASKS]) { + errno = ENOMEM; + return NULL; + } return tp; } @@ -188,7 +199,7 @@ newslot(void) static Task * newtask(void) { - int tid; + int pid; Task *tp; static int last; static mutex_t m; @@ -197,24 +208,29 @@ newtask(void) lock(&m); tp = NULL; - tid = last; + pid = last; for (;;) { - if (tid == MAXTID) - tid = -1; - tid++; - if (tid == last) + if (pid == MAXTID) + pid = 0; + pid++; + if (pid == last) goto err; - if ((tp = gettask(tid)) == NULL) + if ((tp = gettask(pid)) == NULL) break; - unlock(&tp->m); + unlocktask(tp); } if ((tp = newslot()) == NULL) goto err; + if (!newkstack(tp)) + goto err; + + last = pid; + tp->pid = pid; + tp->ppid = 0; + tp->state = TINIT; - last = tid; - tp->tid = tid; unlock(&m); return tp; @@ -260,6 +276,7 @@ newmap(Map *from) if ((mp = alloc(sizeof(*mp))) == NULL) return NULL; + *mp = *from; initref(&mp->ref); mapseg(mp); /* FIXME: we have to duplicate the pages */ @@ -298,29 +315,51 @@ clone(Task *parent) if ((tp = newtask()) == NULL) return NULL; - tp->ptid = parent->tid; - tp->pid = parent->pid; - tp->ppid = parent->ppid; - if (!initptable(tp) || !newstack(tp)) goto err; - incref(&parent->text->ref); + tp->ppid = parent->pid; + + tp->entry = parent->entry; + + tp->prio = parent->prio; + tp->baseprio = parent->baseprio; + tp->retainprio = parent->retainprio; + + tp->wait = parent->wait; + tp->locklevel = parent->locklevel; + tp->affinity = parent->affinity; + + tp->period = parent->period; + tp->duration = parent->duration; + tp->capacity = parent->capacity; + + tp->deadline = parent->deadline; + tp->deadtime = parent->deadtime; + + tp->flags = parent->flags; + tp->state = TREADY; + tp->text = parent->text; + if (tp->text) + incref(&parent->text->ref); - incref(&parent->data->ref); tp->data = parent->data; + if (tp->data) + incref(&parent->data->ref); - incref(&parent->ns->ref); tp->ns = parent->ns; + if (tp->ns) + incref(&parent->ns->ref); - incref(&parent->fds->ref); tp->fds = parent->fds; + if (tp->fds) + incref(&parent->fds->ref); return tp; err: - unlock(&tp->m); + unlocktask(tp); deltask(tp); return NULL; } @@ -328,33 +367,39 @@ err: int rfork(int flags) { - Task *tp, *parent; + Task *tp; Nspace *ns; Fdset *fds; Map *data; if ((flags & (RFMEM|RFPROC)) == 0 || (flags & (RFNAMEG|RFCNAMEG)) == (RFNAMEG|RFCNAMEG) - || (flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG)) { + || (flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG)) { errno = EINVAL; return -1; } - tp = parent = task; + tp = proc; ns = NULL; fds = NULL; data = NULL; if ((flags & RFPROC) != 0) { - if ((tp = clone(parent)) == NULL) + if ((tp = clone(proc)) == NULL) return -1; + /* + * if dupctx() returns 0 then we are the child and + * the mutex was already released by the parent + */ + if (dupctx(tp) == 0) + return 0; } if ((flags & RFCNAMEG) != 0) { if ((ns = newspace(NULL)) == NULL) goto err; } if ((flags & RFNAMEG) != 0) { - if ((ns = newspace(parent->ns)) == NULL) + if ((ns = newspace(proc->ns)) == NULL) goto err; } if ((flags & RFCFDG) != 0) { @@ -362,11 +407,11 @@ rfork(int flags) goto err; } if ((flags & RFFDG) != 0) { - if ((fds = newfds(parent->fds)) == NULL) + if ((fds = newfds(proc->fds)) == NULL) goto err; } if ((flags & RFMEM) == 0) { - if ((data = newmap(parent->data)) == NULL) + if ((data = newmap(proc->data)) == NULL) goto err; } @@ -386,10 +431,8 @@ rfork(int flags) tp->data = data; } - if (flags & RFPROC) { - unlock(&tp->m); - return tp->tid; - } + if (flags & RFPROC) + unlocktask(tp); return 0; @@ -402,7 +445,7 @@ err: freespace(ns); if (flags & RFPROC) { - unlock(&tp->m); + unlocktask(tp); deltask(tp); } @@ -412,26 +455,91 @@ err: Task * kproc(void *fn) { + Task *tp, *zero; + + zero = gettask(0); + if ((tp = clone(zero)) == NULL) + panic("kproc failed"); + + tp->entry = fn; + ictx(tp, fn); + unlocktask(tp); + unlocktask(zero); + + return tp; +} + +void +sched(void) +{ + Task *new, *tp; + int prio; + long long wait, mask; + + if (proc->state == TRUNNING) { + if (proc->flags&TLOCK_PREEMP) + swtch(&proc->ctx); + proc->state = TREADY; + } + unlock(&proc->m); + +repeat: + new = NULL; + prio = -1; + wait = -1; + mask = 1ul << cpuid; + + lock(&procm); + for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) { + lock(&tp->m); + + if (tp->state == TREADY + && (tp->affinity & mask) != 0 + && tp->prio >= prio + && (tp->prio != prio || tp->wait > wait)) { + new = tp; + prio = tp->prio; + wait = tp->wait; + } + + unlock(&tp->m); + } + + if (!new) { + unlock(&procm); + idle(); + goto repeat; + } + + proc = new; + lock(&proc->m); + proc->state = TRUNNING; + unlock(&procm); + + swtch(&proc->ctx); +} + +static void +initfn(void) +{ + debug(); +} + +static Task * +inittask(void) +{ Task *tp; - if ((tp = newslot()) == NULL) + if ((tp = newtask()) == NULL) return NULL; + tp->pid = 0; tp->text = NULL; tp->data = NULL; - tp->fds = NULL; - tp->ns = NULL; - - tp->tid = 1; - tp->pid = 1; - - tp->ptid = -1; - tp->ppid = -1; + tp->fds = newfds(NULL); + tp->ns = newspace(NULL); - tp->tname = "init"; - tp->tentry = fn; - tp->pname = "init"; - tp->pentry = fn; + tp->entry = initfn; tp->prio = 0; tp->baseprio = 0; @@ -439,7 +547,7 @@ kproc(void *fn) tp->wait = 0; tp->locklevel = 0; - tp->affinity = 0; + tp->affinity = -1; tp->period = 0; tp->duration = 0; @@ -448,21 +556,25 @@ kproc(void *fn) tp->deadline = 0; tp->deadtime = 0; - tp->state = 0; tp->flags = 0; + tp->state = TREADY; - tp->mode = PNORMAL; - tp->start = SKERNEL; + ictx(tp, initfn); - if ((tp->kstack = allocb(1)) == NULL) - goto err; + return tp; +} - if (ictx(tp, fn) < 0) - goto err; +void +iproc(void) +{ + Task *tp; - return tp; + for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) { + tp->pid = tp->ppid = -1; + tp->state = TFREE; + } -err: - deltask(tp); - return NULL; + if ((tp = inittask()) == NULL) + panic("init task failed"); + proc = tp; } diff --git a/src/os9/sched.c b/src/os9/sched.c @@ -1,74 +0,0 @@ -#include <os9/os9.h> - -#include <errno.h> - -static Win wintab[NR_WINS]; - -/* per cpu globals */ -Task *task; -long long now; -int cpuid; - -#if 0 -void -sched(void) -{ - Task *new, *tp, **p, **tasks; - int prio; - long long wait, mask; - static mutex_t m; - - lock(&m); - new = proc->errhdl; - if (new && new->state == READY) - goto found; - - new = task; - if (task->mode == RUNNING && task->flags&LOCK_PREEMP) - goto found; - - tasks = proc->tasks; - prio = -1; - wait = -1; - mask = 1ul << cpuid; - for (p = tasks; p < &tasks[NR_TASKS]; ++p) { - tp = p; - - if (tp->mode != READY - || (tp->affinity & mask) == 0 - || tp->prio < prio - || tp->prio == prio && new->wait <= wait) { - continue; - } - - new = tp; - prio = tp->prio; - wait = tp->wait; - } - -found: - if (cur->mode == RUNNIG) - cur->mode = READY; - cur->wait = now; - cur = new; - cur->mode = RUNNING; - unlock(&m); - - swtch(&cur->ctx); -} - -void -minframe(void) -{ - static Win *wp = &wintab[0]; - - if (++wp == &wintab[nr_wins]) - wp = wintab; - - proc = wp->proc; - cur = idle; - mmap(proc); - - sched(); -} -#endif diff --git a/src/os9/sys.c b/src/os9/sys.c @@ -1,39 +1,122 @@ #include <os9/os9.h> +#include <libk.h> + +#include <ctype.h> #include <string.h> +#include "version.h" + Chan *console; static void icons(void) { - char *cfg, *p; + if ((console = devopen("#c/raw", O_RDWR)) == NULL) + panic("icons:#c/raw open"); +} + +static void +writeline(char *line) +{ Chan *c; + char *p, *file, *data; + + file = p = line; + while (*p && !isspace(*p)) + ++p; + while (isspace(*p)) + *p++ = '\0'; + data = p; - if ((cfg = getconf("console")) == NULL) - panic("missed console configuration"); + if ((c = devopen(file, O_WRITE)) < 0) + panic("writeline:open"); + if (devwrite(c, data, strlen(data)) < 0) + panic("writeline:write"); + devclose(c); +} + +static void +bindline(char *line) +{ + int n; + char *tokens[10]; - if ((c = devopen("#c/ctl", O_WRITE)) == NULL) - panic("namec:/dev/cons/ctl open"); + n = tokenize(line, strlen(line), tokens, NELEM(tokens)); + if (n != 2) + panic("bindline:params"); + if (bind(tokens[0], tokens[1]) < 0) + panic("bindline:bind"); +} + +static void +mountline(char *line) +{ + int n; + char *tokens[10]; - while ((p =strchr(cfg, '\n')) != NULL) { - if (devwrite(c, cfg, p - cfg) < 0) - panic("writing console configuration"); - cfg = p+1; + n = tokenize(line, strlen(line), tokens, NELEM(tokens)); + if (n != 3) + panic("mountline:params"); + if (mount(tokens[0], tokens[1], tokens[2]) < 0) + panic("mountline:mount"); +} + +static void +iconf(void) +{ + int n; + Chan *c; + char line[80], *s, *p; + + if ((c = devopen("/blobs/conf", O_READ)) == NULL) { + kprint("missed kernel namespace configuration\n"); + return; } - if (devclose(c) < 0) - panic("devclose"); + while ((n = getline(c, line, sizeof(line))) > 0) { + if (line[n-1] != '\n') { + kprint("iconf: truncated configuration line\n"); + continue; + } + for (p = line; isspace(*p); ++p) + ; + s = p; + while (*p && !isspace(*p)) + ++p; + while (isspace(*p)) + *p++ = '\0'; - if ((console = devopen("#c/raw", O_RDWR)) == NULL) - panic("namec:#c/raw read"); + if (strcmp(s, "write") == 0) { + writeline(p); + } else if (strcmp(s, "bind") == 0) { + bindline(p); + } else if (strcmp(s, "mount") == 0) { + mountline(p); + } else { + kprint("iconf: incorrect verb '%s'\n", s); + continue; + } + } + if (n < 0) + kprint("iconf: error reading configuration:%r\n"); + + devclose(c); +} + +void +info(void) +{ + kprint("Booting os9\n"); + kprint("os9: version %s\n", OS9VERSION); } void isys(void) { + iproc(); idev(); + iconf(); icons(); - iproc(); - debug(); + sched(); }