9os

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

commit 62b384ed5e65b1e716234a4654e6770723fe25de
parent e8e5be17b225adac3d1da1c83e0d3a8235f2fb1c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  3 Aug 2021 20:03:04 +0200

os9: Add basic kproc()

This is the function called to create a kernel
task. It is needed in order to create any process
because any process begins in the kernel.

Change-Id: I45597977fb07a979f128bc812783781045c8376d

Diffstat:
Minclude/os9/os9.h | 44+++++++++++++++++++++++++++++++++++++++++---
Msrc/os9/dev/devproc.c | 4++--
Msrc/os9/proc.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 107 insertions(+), 7 deletions(-)

diff --git a/include/os9/os9.h b/include/os9/os9.h @@ -95,6 +95,7 @@ enum tstates { enum start_reason { SNORMAL, + SKERNEL, }; enum map_attr { @@ -162,14 +163,50 @@ struct mpoint { mutex_t m; }; +/** + * @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). + * @prio: + * @baseprio: + * @retainprio: + * @wait: + * @locklevel: Denotes the current lock level of the task within the + * process that has preemption locked. + * @affinity: Core mask indicating cores where task can execute. + * @period: Process period. + * @duration: The amount of execution time required by the partition + * within one partition period. + * @capacity: + * @deadline: + * @deadtime: + * @state: + * @flags: + * @mode: Denotes process's execution state. + * @start: Denotes the reason the process is started. + * @ctx: + * @ptable: + * @text: + * @data: + * @stack: + * @ns: + * @fds: + */ struct task { int tid; int ptid; int pid; int ppid; - char *name; - void *entry; + char *tname; + void *tentry; + char *pname; + void *pentry; int prio; int baseprio; @@ -177,7 +214,7 @@ struct task { int wait; int locklevel; - unsigned long affinity; + unsigned long long affinity; long period; long duration; @@ -224,6 +261,7 @@ extern int decref(Ref *); extern int getntask(int n, Task **); extern Task *gettask(int); extern int mapseg(Map *); +extern Task *kproc(void *); extern Map *newstack(Task *); /* alloc.c */ diff --git a/src/os9/dev/devproc.c b/src/os9/dev/devproc.c @@ -93,9 +93,9 @@ taskattrread(Chan *c, void *buf, int n) "period: %ld\n" "capacity: %ld\n" "deadline: %ld\n", - tp->name, + tp->tname, tp->tid, - tp->entry, + tp->tentry, tp->stack, tp->prio, tp->period, diff --git a/src/os9/proc.c b/src/os9/proc.c @@ -20,6 +20,11 @@ struct fdset { static Task tasktab[NR_TASKS]; static Task *freel; +static void +initfn(void) +{ +} + void iproc(void) { @@ -30,6 +35,9 @@ iproc(void) tp->next = (tp < &tasktab[NR_TASKS-1]) ? tp+1 : NULL; } freel = tasktab; + + if (!kproc(initfn)) + panic("init task failed"); } void @@ -325,8 +333,6 @@ rfork(int flags) Fdset *fds; Map *data; - tp = parent = task; - if ((flags & (RFMEM|RFPROC)) == 0 || (flags & (RFNAMEG|RFCNAMEG)) == (RFNAMEG|RFCNAMEG) || (flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG)) { @@ -334,6 +340,7 @@ rfork(int flags) return -1; } + tp = parent = task; ns = NULL; fds = NULL; data = NULL; @@ -401,3 +408,58 @@ err: return -1; } + +Task * +kproc(void *fn) +{ + Task *tp; + + if ((tp = newslot()) == NULL) + return NULL; + + 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->tname = "init"; + tp->tentry = fn; + tp->pname = "init"; + tp->pentry = fn; + + tp->prio = 0; + tp->baseprio = 0; + tp->retainprio = 0; + + tp->wait = 0; + tp->locklevel = 0; + tp->affinity = 0; + + tp->period = 0; + tp->duration = 0; + tp->capacity = 0; + + tp->deadline = 0; + tp->deadtime = 0; + + tp->state = 0; + tp->flags = 0; + + tp->mode = PNORMAL; + tp->start = SKERNEL; + + tp->m = 0; + + if (ictx(tp, fn) < 0) { + deltask(tp); + return NULL; + } + + return tp; +}