summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-11-11 08:35:24 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-11-11 08:35:24 -0500
commitae4a9d5bf564285502734c7c4f3eb67507bd6c56 (patch)
tree5d63800df15573b1d02ec1238bb613cf38d217bb
parent7991b36c56f4361fee92a4a03c3b3d640c8e7f98 (diff)
downloadmodit-slim-ae4a9d5bf564285502734c7c4f3eb67507bd6c56.tar.gz
modit-slim-ae4a9d5bf564285502734c7c4f3eb67507bd6c56.tar.bz2
modit-slim-ae4a9d5bf564285502734c7c4f3eb67507bd6c56.zip
squash root user directory; add rpcsrv to init; fix crti constructor calls
-rw-r--r--.gitignore2
-rw-r--r--Makefile10
-rw-r--r--app/init/Makefile2
-rw-r--r--app/init/main.c15
-rw-r--r--app/init/rpcsrv.c3
-rw-r--r--app/init/rpcsrv.h2
-rw-r--r--app/init/scheduler.c32
-rw-r--r--app/init/scheduler.h3
-rw-r--r--app/ld/main.c30
m---------kernel0
-rw-r--r--lib/c/libc.c4
-rw-r--r--lib/crt/x86/64/crt0.s4
-rw-r--r--lib/crt/x86/64/crti.s18
-rw-r--r--lib/rpc/call.c14
-rw-r--r--lib/rpc/rpc.c4
-rw-r--r--root/include/elf/elf.h (renamed from root/usr/include/elf/elf.h)0
-rw-r--r--root/include/rpc/api.h (renamed from root/usr/include/rpc/api.h)2
-rw-r--r--root/include/rpc/rpc.h (renamed from root/usr/include/rpc/rpc.h)0
-rw-r--r--root/include/stdlib.h (renamed from root/usr/include/stdlib.h)0
-rw-r--r--root/include/string.h (renamed from root/usr/include/string.h)0
-rw-r--r--root/include/sys/alloc.h (renamed from root/usr/include/sys/alloc.h)0
-rw-r--r--root/include/sys/cid.h (renamed from root/usr/include/sys/cid.h)0
-rw-r--r--root/include/sys/ipc.h (renamed from root/usr/include/sys/ipc.h)0
-rw-r--r--root/include/sys/port.h (renamed from root/usr/include/sys/port.h)0
-rw-r--r--tools/patches/gcc.patch8
25 files changed, 108 insertions, 45 deletions
diff --git a/.gitignore b/.gitignore
index 2b21c41..975d14d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,4 @@ bochsout.txt
*.a
*.o
initrd
-root/usr/include/modit
+root/include/modit
diff --git a/Makefile b/Makefile
index b1e1d21..55682ba 100644
--- a/Makefile
+++ b/Makefile
@@ -33,9 +33,9 @@ kernel: tools/$(ARCH)_$(BITS) Makefile
mv kernel/kernel.elf root/boot/
mkdir -p $(PWD)/root/usr/include/modit
mkdir -p $(PWD)/initrd
- cp kernel/include/arch_$(ARCH)/$(BITS)/* root/usr/include/modit/
- cp kernel/include/arch_$(ARCH)/common/* root/usr/include/modit/
- cp kernel/include/arch_common/* root/usr/include/modit/
+ cp kernel/include/arch_$(ARCH)/$(BITS)/* root/include/modit/
+ cp kernel/include/arch_$(ARCH)/common/* root/include/modit/
+ cp kernel/include/arch_common/* root/include/modit/
.PHONY: initrd
initrd: tools/$(ARCH)_$(BITS) apps Makefile
@@ -44,13 +44,13 @@ initrd: tools/$(ARCH)_$(BITS) apps Makefile
.PHONY: apps
apps: libs
@for app in ${APPS} ; do \
- $(MAKE) -C $$app ARCH=$(ARCH) BITS=$(BITS) CC=$(CC) LD=$(LD) AS=$(AS) AR=$(AR) INCDIR=$(PWD)/root/usr/include LIBDIR=$(PWD)/root/lib OUTDIR=$(PWD)/initrd ; \
+ $(MAKE) -C $$app ARCH=$(ARCH) BITS=$(BITS) CC=$(CC) LD=$(LD) AS=$(AS) AR=$(AR) INCDIR=$(PWD)/root/include LIBDIR=$(PWD)/root/lib OUTDIR=$(PWD)/initrd ; \
done
.PHONY: libs
libs: kernel
@for lib in $(wildcard $(PWD)/lib/*) ; do \
- $(MAKE) -C $$lib ARCh=$(ARCH) BITS=$(BITS) CC=$(CC) LD=$(LD) AS=$(AS) AR=$(AR) INCDIR=$(PWD)/root/usr/include LIBDIR=$(PWD)/root/lib ; \
+ $(MAKE) -C $$lib ARCh=$(ARCH) BITS=$(BITS) CC=$(CC) LD=$(LD) AS=$(AS) AR=$(AR) INCDIR=$(PWD)/root/include LIBDIR=$(PWD)/root/lib ; \
done
limine:
diff --git a/app/init/Makefile b/app/init/Makefile
index f7345f1..b8474b6 100644
--- a/app/init/Makefile
+++ b/app/init/Makefile
@@ -4,7 +4,7 @@ CFILES += $(wildcard *.s)
CC ?= gcc
WARNS := -Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wdouble-promotion -Wshadow -Wcast-align
-CFLAGS := $(WARNS) -I$(INCDIR)
+CFLAGS := $(WARNS)
OUT := init
.PHONY: all
diff --git a/app/init/main.c b/app/init/main.c
index fde73c0..407959f 100644
--- a/app/init/main.c
+++ b/app/init/main.c
@@ -4,6 +4,7 @@
#include "sys/cid.h"
#include "sys/ipc.h"
#include "modit/syscall.h"
+#include "rpc/api.h"
#include <string.h>
@@ -13,13 +14,23 @@ void prints(const char *msg) {
_syscall_print(&data);
}
+intmax_t rpc_test(struct rpcargs *args) {
+ return 0;
+}
+
int
main(int argc, char **argv)
{
(void)argc;
(void)argv;
+ rpcsrv_setup();
scheduler_setup();
- rpcsrv_start();
- while(1);
+ cid_t forked = fork_ghost();
+ if(forked != 0) {
+ scheduler_addctx(forked, "test", 1);
+ }else{
+ rpc_export(rpc_define(0, 0, "", 'i'), "test", rpc_test);
+ }
+ //rpc_handle(false);
}
diff --git a/app/init/rpcsrv.c b/app/init/rpcsrv.c
index 4b3422b..2808560 100644
--- a/app/init/rpcsrv.c
+++ b/app/init/rpcsrv.c
@@ -62,12 +62,11 @@ rpcs_export(struct rpc_args *args)
}
void
-rpcsrv_start(void)
+rpcsrv_setup(void)
{
srv_entries = NULL;
srv_entc = 0;
rpc_export_internal(rpc_define(0, 0, "s", 'v'), rpcs_import);
rpc_export_internal(rpc_define(0, 1, "sv", 'i'), rpcs_export);
- rpc_handle(false);
}
diff --git a/app/init/rpcsrv.h b/app/init/rpcsrv.h
index 8e3ce2d..8c899a7 100644
--- a/app/init/rpcsrv.h
+++ b/app/init/rpcsrv.h
@@ -1,6 +1,6 @@
#ifndef INIT_RPCSRV_H
#define INIT_RPCSRV_H 1
-void rpcsrv_start(void);
+void rpcsrv_setup(void);
#endif
diff --git a/app/init/scheduler.c b/app/init/scheduler.c
index f573c99..1980ebb 100644
--- a/app/init/scheduler.c
+++ b/app/init/scheduler.c
@@ -2,6 +2,9 @@
#include <stddef.h>
#include <stdlib.h>
#include "sys/cid.h"
+#include "rpc/rpc.h"
+#include "rpc/api.h"
+#include <string.h>
struct clnode { //Round list
struct clnode *next;
@@ -11,15 +14,32 @@ struct clnode { //Round list
struct clnode *context_tail = NULL;
struct clnode *context_current = NULL;
+static struct clnode*
+findbyid(cid_t id) {
+ for(struct clnode *node = context_tail; node; node = node->next) {
+ if(node->ctx->cid == id) return node;
+ }
+ return NULL;
+}
+
+static struct clnode*
+findbyname(char *name) {
+ for(struct clnode *node = context_tail; node; node = node->next) {
+ if(strcmp(node->ctx->name, name) == 0) return node;
+ }
+ return NULL;
+}
+
void
-scheduler_addctx(cid_t id, uint8_t p)
+scheduler_addctx(cid_t id, char *name, uint8_t p)
{
struct clnode *node = malloc(sizeof(struct clnode));
- struct context *ctx = malloc(sizeof(struct context));
+ struct context *ctx = malloc(sizeof(struct context) + strlen(name));
ctx->cid = id;
ctx->priority = p;
ctx->scheduled = true;
+ strcpy(ctx->name, name);
node->ctx = ctx;
node->next = context_tail;
@@ -49,14 +69,14 @@ scheduler_loop(void)
void
scheduler_setup(void)
{
- cid_t forked = fork_ghost();
- if(forked != 0) {
- swapto(forked);
+ cid_t scid = fork_ghost();
+ if(scid != 0) {
+ swapto(scid);
return;
}
//Add init and scheduler to context list
- scheduler_addctx(1, 1);
+ scheduler_addctx(1, "init", 1);
context_current = context_tail;
scheduler_loop();
diff --git a/app/init/scheduler.h b/app/init/scheduler.h
index d028fec..478f32b 100644
--- a/app/init/scheduler.h
+++ b/app/init/scheduler.h
@@ -14,9 +14,10 @@ struct context
bool scheduled;
uint8_t priority;
+ char name[];
};
-void scheduler_addctx(cid_t id, uint8_t p);
+void scheduler_addctx(cid_t id, char *name, uint8_t p);
/* Assumes init is CID 1 */
void scheduler_setup(void);
diff --git a/app/ld/main.c b/app/ld/main.c
index 3cbb49d..8613a0c 100644
--- a/app/ld/main.c
+++ b/app/ld/main.c
@@ -44,6 +44,13 @@ memset(void *restrict dest, char b, size_t n)
return dest;
}
+int
+strcmp(char *a, char *b) {
+ size_t i = 0;
+ while(a[i] == b[i] && a[i] != 0) i++;
+ return a[i] - b[i];
+}
+
void
elf_run(uintptr_t entry)
{
@@ -51,8 +58,7 @@ elf_run(uintptr_t entry)
//if(stack_data->argv != NULL)
// while(stack_data->argv[argc++] != 0);
- asm volatile("xchg %%bx, %%bx; \
- movq %0, %%rdi; \
+ asm volatile("movq %0, %%rdi; \
movq %1, %%rsi; \
movq %2, %%rdx; \
jmp %3"::
@@ -65,18 +71,18 @@ elf_run(uintptr_t entry)
void
elf_parse_exec()
{
- struct elf64_header *header = (struct elf64_header*)stack_data->data;
- struct elf64_program_header *phdrs = (struct elf64_program_header*)((uintptr_t)header + header->e_phoff);
+ struct elf64_header *header = (struct elf64_header*)stack_data->data;
+ struct elf64_program_header *phdrs = (struct elf64_program_header*)((uintptr_t)header + header->e_phoff);
- for(size_t i = 0; i < header->e_phnum; i++) {
- struct elf64_program_header *phdr = &phdrs[i];
- if(phdr->p_type != ELF_PT_LOAD) continue;
+ for(size_t i = 0; i < header->e_phnum; i++) {
+ struct elf64_program_header *phdr = &phdrs[i];
+ if(phdr->p_type != ELF_PT_LOAD) continue;
- alloc(phdr->p_vaddr, phdr->p_memsz);
- memset((void*)(phdr->p_vaddr), 0, phdr->p_memsz);
- memcpy((void*)(phdr->p_vaddr), (void*)((uintptr_t)stack_data->data + phdr->p_offset), phdr->p_filesz);
- }
-
+ alloc(phdr->p_vaddr, phdr->p_memsz);
+ memset((void*)(phdr->p_vaddr), 0, phdr->p_memsz);
+ memcpy((void*)(phdr->p_vaddr), (void*)((uintptr_t)stack_data->data + phdr->p_offset), phdr->p_filesz);
+ }
+
elf_run(header->e_entry);
}
diff --git a/kernel b/kernel
-Subproject 216e17bebb84483c33b0de40ab05778eef58560
+Subproject a310ca40440e4798eea01107646b92253a3f788
diff --git a/lib/c/libc.c b/lib/c/libc.c
index 4da0ca1..4773d88 100644
--- a/lib/c/libc.c
+++ b/lib/c/libc.c
@@ -2,7 +2,7 @@
extern void __stdlib_heap_init();
void
-__init_mocksl(void)
+__init_libc(void)
{
- __stdlib_heap_init();
+ __stdlib_heap_init();
}
diff --git a/lib/crt/x86/64/crt0.s b/lib/crt/x86/64/crt0.s
index dbba387..09cf55c 100644
--- a/lib/crt/x86/64/crt0.s
+++ b/lib/crt/x86/64/crt0.s
@@ -13,11 +13,13 @@ _start:
pushq %rdi
//Setup mocksl (argc=rdi, argv=rsi, envp=rdx)
- call __init_mocksl
+ call __init_libc
//Call constructors
call _init
+
+
//Restore args for main
popq %rdi
popq %rsi
diff --git a/lib/crt/x86/64/crti.s b/lib/crt/x86/64/crti.s
index f6d48be..1ef6f12 100644
--- a/lib/crt/x86/64/crti.s
+++ b/lib/crt/x86/64/crti.s
@@ -1,8 +1,22 @@
.section .init
.global _init
+
_init:
push %rbp
movq %rsp, %rbp
+ call _init_init_array
+
+.section .text
+.global _init_init_array
+_init_init_array:
+ movq $__init_array_start, %rax
+_init_ias_iterate:
+ push %rax
+ call *(%rax)
+ pop %rax
+ addq $8, %rax
+ cmpq $-1, (%rax)
+ jne _init_ias_iterate
.section .fini
.global _fini
@@ -10,3 +24,7 @@ _fini:
push %rbp
movq %rsp, %rbp
+.section .init_array
+.global __init_array_start
+__init_array_start:
+
diff --git a/lib/rpc/call.c b/lib/rpc/call.c
index a1407f8..a589e1e 100644
--- a/lib/rpc/call.c
+++ b/lib/rpc/call.c
@@ -30,20 +30,20 @@ marshall(const char *fmt, char *buffer, va_list ap)
break;
}
if(*c == 's') {
- val = (intmax_t)va_arg(ap, char*);
- vallen = strlen((const char*)val);
- if(buffer != NULL) strcpy(&buffer[size], (char*)val);
+ char *str = va_arg(ap, char*);
+ vallen = strlen(str);
+ if(buffer != NULL) strcpy(&(buffer[size]), str);
size += vallen;
}else if(*c == 'v') {
vallen = va_arg(ap, size_t);
val = (intmax_t)va_arg(ap, unsigned char*);
if(buffer != NULL) {
- memcpy(&buffer[size], &vallen, sizeof(size_t));
- memcpy(&buffer[size + sizeof(size_t)], (void*)val, vallen);
+ memcpy(&(buffer[size]), &vallen, sizeof(size_t));
+ memcpy(&(buffer[size + sizeof(size_t)]), (void*)val, vallen);
}
size += vallen + sizeof(size_t);
}else{
- if(buffer != NULL) memcpy(&buffer[size], &val, vallen);
+ if(buffer != NULL) memcpy(&(buffer[size]), &val, vallen);
size += vallen;
}
}
@@ -85,7 +85,6 @@ rpc_vcall(RPCFUNC *func, va_list ap)
buffer = malloc(retsize);
port_read(resultport, buffer, retsize);
port_close(resultport);
-
//Return result
intmax_t r = 0;
int rlen = 0;
@@ -99,6 +98,7 @@ rpc_vcall(RPCFUNC *func, va_list ap)
return buffer;
}else if(func->returns == 'v') {
memcpy(&rlen, buffer, sizeof(size_t));
+ if(rlen == 0) return NULL;
struct rpc_vlvpack *pack = malloc(sizeof(struct rpc_vlvpack) + rlen);
pack->len = rlen;
memcpy(pack->data, buffer + sizeof(size_t), rlen);
diff --git a/lib/rpc/rpc.c b/lib/rpc/rpc.c
index e637d64..e5ac718 100644
--- a/lib/rpc/rpc.c
+++ b/lib/rpc/rpc.c
@@ -7,10 +7,14 @@ rpcid_t rpcc = 0;
RPCFUNC *rpc_init_import;
RPCFUNC *rpc_init_export;
+RPCFUNC *rpc_init_regc;
__attribute__((constructor))
void rpc_constructor(void)
{
+ prints("Registered RPCs\n");
+
rpc_init_import = rpc_define(1, RPC_INIT_IMPORT, "s", 'v');
rpc_init_export = rpc_define(1, RPC_INIT_EXPORT, "sv", 'i');
+ rpc_init_regc = rpc_define(1, RPC_INIT_REGC, "is", "i");
}
diff --git a/root/usr/include/elf/elf.h b/root/include/elf/elf.h
index f7967ea..f7967ea 100644
--- a/root/usr/include/elf/elf.h
+++ b/root/include/elf/elf.h
diff --git a/root/usr/include/rpc/api.h b/root/include/rpc/api.h
index 5b511e4..7b4913e 100644
--- a/root/usr/include/rpc/api.h
+++ b/root/include/rpc/api.h
@@ -6,6 +6,7 @@
#define RPC_INIT_IMPORT 0
#define RPC_INIT_EXPORT 1
+#define RPC_INIT_REGC 2
#define RPC_IMPORT(name) \
RPCFUNC *rpc_##name = NULL; \
@@ -28,5 +29,6 @@ intmax_t rpc_func_##name (bool wait, ...) { \
extern RPCFUNC *rpc_init_import;
extern RPCFUNC *rpc_init_export;
+extern RPCFUNC *rpc_init_regc;
#endif
diff --git a/root/usr/include/rpc/rpc.h b/root/include/rpc/rpc.h
index 509b243..509b243 100644
--- a/root/usr/include/rpc/rpc.h
+++ b/root/include/rpc/rpc.h
diff --git a/root/usr/include/stdlib.h b/root/include/stdlib.h
index 7a90436..7a90436 100644
--- a/root/usr/include/stdlib.h
+++ b/root/include/stdlib.h
diff --git a/root/usr/include/string.h b/root/include/string.h
index 2e7f763..2e7f763 100644
--- a/root/usr/include/string.h
+++ b/root/include/string.h
diff --git a/root/usr/include/sys/alloc.h b/root/include/sys/alloc.h
index a674196..a674196 100644
--- a/root/usr/include/sys/alloc.h
+++ b/root/include/sys/alloc.h
diff --git a/root/usr/include/sys/cid.h b/root/include/sys/cid.h
index af7899e..af7899e 100644
--- a/root/usr/include/sys/cid.h
+++ b/root/include/sys/cid.h
diff --git a/root/usr/include/sys/ipc.h b/root/include/sys/ipc.h
index 981b83e..981b83e 100644
--- a/root/usr/include/sys/ipc.h
+++ b/root/include/sys/ipc.h
diff --git a/root/usr/include/sys/port.h b/root/include/sys/port.h
index 45ee787..45ee787 100644
--- a/root/usr/include/sys/port.h
+++ b/root/include/sys/port.h
diff --git a/tools/patches/gcc.patch b/tools/patches/gcc.patch
index 8ddf6b2..e63fe17 100644
--- a/tools/patches/gcc.patch
+++ b/tools/patches/gcc.patch
@@ -46,10 +46,10 @@ diff -rcN gcc/gcc/config/modit.h gcc-modified/gcc/config/modit.h
+ #define LIB_SPEC "-lc -lrpc" /* link against c and rpc library */
+
+ #undef STARTFILE_SPEC
-+ #define STARTFILE_SPEC "crt0.o%s crti.o%s %{!shared:crtbegin.o%s}"
++ #define STARTFILE_SPEC "crt0.o%s crti.o%s crtbegin.o%s"
+
+ #undef ENDFILE_SPEC
-+ #define ENDFILE_SPEC "%{!shared:crtend.o%s} crtn.o%s"
++ #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
+
+ #undef STANDARD_STARTFILE_PREFIX
+ #define STANDARD_STARTFILE_PREFIX "/lib/"
@@ -111,11 +111,11 @@ diff -rcN gcc/libgcc/config.host gcc-modified/libgcc/config.host
extra_parts="crt0.o"
;;
+ i[34567]86-*-modit*)
-+ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o"
++ extra_parts="$extra_parts crtbegin.o crtend.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
+ x86_64-*-modit*)
-+ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o"
++ extra_parts="$extra_parts crtbegin.o crtend.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
*)