CeDOS - Commit 85c8930b

Added arguments to processes
Celina Kalus
Tue, 14 Mar 2023 17:57:29 +0100
7 files changed, 24 insertions(+), 11 deletions(-)
M include/cedos/elf.hinclude/cedos/elf.h

@@ -7,6 +7,6 @@

/*! * Executes an elf file from memory */ -PROCESS_ID elf_exec(VIRT_ADDR elf_pointer, uint32_t size, char *name); +PROCESS_ID elf_exec(VIRT_ADDR elf_pointer, uint32_t size, char *name, char *args); #endif
M include/cedos/sched/process.hinclude/cedos/sched/process.h

@@ -31,7 +31,7 @@

/*! * Defines the prototype for process entry functions. */ -typedef int PROCESS_MAIN(void); +typedef int PROCESS_MAIN(char *args); /*! * Struct that saves context information for a process.

@@ -60,6 +60,9 @@ PROCESS_ID id;

//! Name of the process. const char *name; + + //! String of arguments for the process + char *args; //! Current state of the process. PROCESS_STATE state;
M include/cedos/sched/sched.hinclude/cedos/sched/sched.h

@@ -32,7 +32,7 @@

/*! * Creates a new process and returns its process ID. */ -PROCESS_ID sched_create(const char *name); +PROCESS_ID sched_create(const char *name, char *args); /*! * Copies a piece of memory into the memory space of some process.
M src/apps/start.csrc/apps/start.c

@@ -4,9 +4,15 @@ #include <stdint.h>

extern void fib(void); -int start(void) { +int start(char *args) { //uint32_t eip, esp, ebp; //__asm__ volatile ("call jump; jump: pop %0; mov %%esp, %1; mov %%ebp, %2" : "=m" (eip), "=m" (esp), "=m" (ebp)); + + int pid = get_pid(); + while (1) { + printf("Process #%i says: \"%s\".\n", pid, args); + yield(); + } fib();
M src/kernel/elf.csrc/kernel/elf.c

@@ -115,9 +115,9 @@ printk("\n");

} } -PROCESS_ID elf_exec(VIRT_ADDR elf_pointer, uint32_t size, char *name) { +PROCESS_ID elf_exec(VIRT_ADDR elf_pointer, uint32_t size, char *name, char *args) { printk("Creating process %s...", name); - PROCESS_ID pid = sched_create(name); + PROCESS_ID pid = sched_create(name, args); printk("done, PID: %i.\n", pid); ELF_HEADER *header = (ELF_HEADER*)elf_pointer;
M src/kernel/main.csrc/kernel/main.c

@@ -138,7 +138,9 @@ // create test tasks

printk("Creating tasks.\n"); printk("Loading ELF executable.\n"); - elf_exec(SS_VMA + (ELF_LMA - SS_LMA), ELF_SIZE, "my_apps"); + elf_exec(SS_VMA + (ELF_LMA - SS_LMA), ELF_SIZE, "app1", "Hello World!"); + elf_exec(SS_VMA + (ELF_LMA - SS_LMA), ELF_SIZE, "app2", "Hello World!"); + elf_exec(SS_VMA + (ELF_LMA - SS_LMA), ELF_SIZE, "app3", "Hello World!"); printk("Starting scheduler.\n"); sched_start();
M src/kernel/sched/sched.csrc/kernel/sched/sched.c

@@ -37,7 +37,7 @@

/*! * Creates a new process and returns its process ID. */ -PROCESS_ID sched_create(const char *name) { +PROCESS_ID sched_create(const char *name, char *args) { crit_enter(); PHYS_ADDR page_dir = create_empty_page_dir();

@@ -45,6 +45,8 @@

// set process context PROCESS *p = get_slot(); p->name = name; + p->args = args; + // TODO: copy name and args instead of linking! p->page_dir = page_dir; p->eip = sched_dispatcher; p->ebp = USER_STACK;

@@ -169,7 +171,7 @@

pic1_eoi(); } -void entry_idle(void) { +void entry_idle(char *args) { while (1) { //printk("idle.\n"); }

@@ -184,7 +186,7 @@

current_pid = 0; // create idle process - PROCESS_ID idle = sched_create("idle"); + PROCESS_ID idle = sched_create("idle", NULL); sched_exec(idle, entry_idle); return 1;

@@ -257,7 +259,7 @@ PROCESS* this = get_process(current_pid);

PROCESS_MAIN* entry = this->entry; // enter the actual program - entry(); + entry(this->args); //printk("Process %i terminated.\n", current_pid);