aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-06-28 23:12:32 -0400
committerIan Moffett <ian@osmora.org>2024-06-28 23:12:32 -0400
commit45ab1dd925162659d59d65a95105120d9dc96978 (patch)
tree8054643780fefb3f8ed979ceff83c8cff83ccf50 /sys
parent1bc9042af8907260659f28e8941837213dd37a8b (diff)
kernel/amd64: Focus md_td_init() to fork MD code
Rename md_td_init() to md_fork() and change up what it does to keep things as simple as possible. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/proc_machdep.c23
-rw-r--r--sys/include/sys/proc.h2
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/kern_fork.c8
4 files changed, 12 insertions, 24 deletions
diff --git a/sys/arch/amd64/amd64/proc_machdep.c b/sys/arch/amd64/amd64/proc_machdep.c
index eb3866a..d2eb599 100644
--- a/sys/arch/amd64/amd64/proc_machdep.c
+++ b/sys/arch/amd64/amd64/proc_machdep.c
@@ -46,12 +46,12 @@
* @ip: Instruction pointer.
*/
int
-md_td_init(struct proc *p, struct proc *parent, uintptr_t ip)
+md_fork(struct proc *p, struct proc *parent, uintptr_t ip)
{
uintptr_t stack_base;
- struct trapframe *tfp, *parent_tfp;
+ struct trapframe *tfp;
struct pcb *pcbp;
- uint8_t rpl;
+ uint8_t rpl = 0;
int error;
tfp = &p->tf;
@@ -61,18 +61,15 @@ md_td_init(struct proc *p, struct proc *parent, uintptr_t ip)
if ((error = pmap_new_vas(&pcbp->addrsp)) != 0)
return error;
+ memcpy(tfp, &parent->tf, sizeof(p->tf));
+
/*
- * If parent is NULL, assume kernel space and zero the
- * trapframe. Otherwise we can just set it up normally.
+ * Kernel threads cannot be on the lower half.
+ * If 'ip' is on the lower half, assume that it
+ * is a userspace program and set RPL to ring 3.
*/
- if (parent == NULL) {
- rpl = 0;
- memset(tfp, 0, sizeof(*tfp));
- } else {
- parent_tfp = &parent->tf;
- rpl = parent_tfp->cs & 3;
- memcpy(tfp, &parent->tf, sizeof(*tfp));
- }
+ if (ip < VM_HIGHER_HALF)
+ rpl = 3;
/*
* RPL being 3 indicates that the parent thread is in
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index c74bca5..684742a 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -52,7 +52,7 @@ struct proc {
};
struct proc *this_td(void);
-int md_td_init(struct proc *p, struct proc *parent, uintptr_t ip);
+int md_fork(struct proc *p, struct proc *parent, uintptr_t ip);
int fork1(struct proc *cur, int flags, void(*ip)(void), struct proc **newprocp);
#endif /* _KERNEL */
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index df955ee..a5bdf1c 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -56,9 +56,6 @@ main(void)
/* Startup the BSP */
cpu_startup(&g_bsp_ci);
- /* Init process 0 */
- md_td_init(&proc0, NULL, 0);
-
/* Init the virtual file system */
vfs_init();
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 64e0caf..ce5f3a6 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -54,13 +54,7 @@ fork1(struct proc *cur, int flags, void(*ip)(void), struct proc **newprocp)
if (newproc == NULL)
return -ENOMEM;
- /*
- * We want to zero the proc to ensure it is in known
- * state. We then want to initialize machine dependent
- * fields.
- */
- memset(newproc, 0, sizeof(*newproc));
- status = md_td_init(newproc, cur, (uintptr_t)ip);
+ status = md_fork(newproc, cur, (uintptr_t)ip);
if (status != 0)
goto done;