summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-11-21 13:46:14 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-11-21 13:46:14 -0500
commit5943a515fdda7b2c148122e779aed16312be7cb4 (patch)
treef61adea4114a73dc3c95263117a60adfbad10f3f
parenta310ca40440e4798eea01107646b92253a3f7881 (diff)
downloadmodit-kernel-5943a515fdda7b2c148122e779aed16312be7cb4.tar.gz
modit-kernel-5943a515fdda7b2c148122e779aed16312be7cb4.tar.bz2
modit-kernel-5943a515fdda7b2c148122e779aed16312be7cb4.zip
add hook for initrd_get; add functions to getcid; move initrd files to bin
-rw-r--r--include/arch_x86/64/page.h1
-rw-r--r--include/arch_x86/common/syscall.h13
-rw-r--r--src/arch_common/init/init.c25
-rw-r--r--src/arch_common/initrd/tar.c3
-rw-r--r--src/arch_x86/64/task/load.c1
-rw-r--r--src/arch_x86/common/panic/main.c7
-rw-r--r--src/arch_x86/common/syscall/syscall.c11
7 files changed, 40 insertions, 21 deletions
diff --git a/include/arch_x86/64/page.h b/include/arch_x86/64/page.h
index ee530ed..e86076b 100644
--- a/include/arch_x86/64/page.h
+++ b/include/arch_x86/64/page.h
@@ -13,6 +13,7 @@
#define PAGE_MASSIVE 0b10000000
#define PAGE_OS_LAZY 0b00000001
+#define PAGE_OS_DUP 0b00000010
#define PAGE_SIZE 0x1000
diff --git a/include/arch_x86/common/syscall.h b/include/arch_x86/common/syscall.h
index 280a55f..4ea4755 100644
--- a/include/arch_x86/common/syscall.h
+++ b/include/arch_x86/common/syscall.h
@@ -35,6 +35,8 @@ enum {
SYSCALL_MESSAGE_SEND,
SYSCALL_MESSAGE_RECV,
+
+ SYSCALL_INITRD_GET,
SYSCALL_MAX
};
extern syscall_t syscalls[SYSCALL_MAX];
@@ -82,6 +84,10 @@ struct syscall_switch_data {
int id;
};
+struct syscall_cid_data {
+ int id;
+};
+
struct syscall_tick_data {
int ms;
};
@@ -99,4 +105,11 @@ struct syscall_message_data {
size_t len;
};
+struct syscall_initrd_data {
+ const char *path;
+ char *buffer;
+ size_t length;
+ size_t index;
+};
+
#endif
diff --git a/src/arch_common/init/init.c b/src/arch_common/init/init.c
index 548507f..a53c0b0 100644
--- a/src/arch_common/init/init.c
+++ b/src/arch_common/init/init.c
@@ -11,12 +11,6 @@
#include "string.h"
#include <stdbool.h>
-static void
-kernel_idle(void)
-{
- while(true) asm("hlt");
-}
-
struct ldexpect {
char **argv;
char **envp;
@@ -31,9 +25,12 @@ init_spawn(struct initrd_file *init, struct initrd_file *ld)
ldstk->envp = NULL;
memcpy(&(ldstk->elf), init->data, init->size);
- struct execution_context *initctx = excontext_spawn(ld->data, ld->size, (const uint8_t*)ldstk, init->size + (2 * sizeof(uintptr_t)));
+ struct execution_context *initctx = excontext_spawn(ld->data, ld->size,
+ (const uint8_t*)ldstk,
+ init->size + (2 * sizeof(uintptr_t)));
excontext_switch(initctx);
+ while(1) asm("hlt");
}
MODULE static void
@@ -42,18 +39,18 @@ init_constructor(void)
struct initrd_file *init_file = NULL;
struct initrd_file *ld_file = NULL;
- sll_foreach(struct initrd_file, initrd_head) { //node
- if(!strcmp(node->name, "ld")) ld_file = node;
- if(!strcmp(node->name, "init")) init_file = node;
+ sll_foreach(struct initrd_file, initrd_head) {
+ if(!strcmp(node->name, "bin/ld")) ld_file = node;
+ if(!strcmp(node->name, "bin/init")) init_file = node;
}
- if(init_file == NULL) {
- panic("initrd is missing init program\n");
- }
if(ld_file == NULL) {
panic("initrd is missing linker program\n");
}
+ if(init_file == NULL) {
+ panic("initrd is missing init program\n");
+ }
+
init_spawn(init_file, ld_file);
- kernel_idle();
}
diff --git a/src/arch_common/initrd/tar.c b/src/arch_common/initrd/tar.c
index 5d15870..26819be 100644
--- a/src/arch_common/initrd/tar.c
+++ b/src/arch_common/initrd/tar.c
@@ -29,7 +29,6 @@ tar_parse_file(struct tar_header *block)
return file;
}
-
void
tar_parse(uintptr_t addr)
{
@@ -43,7 +42,7 @@ tar_parse(uintptr_t addr)
if(initrd_head == NULL) {
initrd_head = file;
- }else sll_append(initrd_head, file);
+ }else sll_appbeg(initrd_head, file);
blocks += fileblocks + 1;
block = (struct tar_header*)(addr + (blocks * TAR_BLOCKSIZE));
diff --git a/src/arch_x86/64/task/load.c b/src/arch_x86/64/task/load.c
index 2a00b1a..c1b65d6 100644
--- a/src/arch_x86/64/task/load.c
+++ b/src/arch_x86/64/task/load.c
@@ -40,7 +40,6 @@ excontext_spawn_secondhalf(const uint8_t *bin, size_t binsz, const uint8_t *stac
vmptr_t ustk = MODIT_USER_STACK;
UPUSH(ustk, stack, stacksz);
- printk(KERNEL_INFO, "STK %lX\n", ustk);
UPUSHV(ustk, ustk + 8);
//User stack leeway
diff --git a/src/arch_x86/common/panic/main.c b/src/arch_x86/common/panic/main.c
index 741d661..3384989 100644
--- a/src/arch_x86/common/panic/main.c
+++ b/src/arch_x86/common/panic/main.c
@@ -2,6 +2,7 @@
#include "panic.h"
#include "stdio.h"
#include "vgatxt.h"
+#include "task.h"
#include <stdbool.h>
@@ -51,10 +52,14 @@ panic_except(struct intregs *regs, const char *exceptstr)
printf("Unhandled kernel exception\n%s\n", exceptstr);
+#if defined(BITS_64)
if(regs != NULL) {
printf("ERR %i\n", regs->err);
- printf("IP %lX\n", regs->rip);
+ printf("IP %l016X CTX %i\n", regs->rip, current_excontext->id);
}
+#else
+
+#endif
panic_end();
}
diff --git a/src/arch_x86/common/syscall/syscall.c b/src/arch_x86/common/syscall/syscall.c
index 45fccf7..5a54d7a 100644
--- a/src/arch_x86/common/syscall/syscall.c
+++ b/src/arch_x86/common/syscall/syscall.c
@@ -88,10 +88,15 @@ syscall_switch(struct syscall_switch_data *data)
}
int
-syscall_cid(void *unused)
+syscall_cid(struct syscall_cid_data *data)
{
- (void)unused;
- return current_excontext->id;
+ struct execution_context *tgt = current_excontext;
+ POINTER_CHECK(data);
+ if(data->id != 0) {
+ tgt = excontext_find(data->id);
+ }
+ if(!tgt) return -SYSCALL_ERR_NOTFOUND;
+ return tgt->id;
}
int