summaryrefslogtreecommitdiffstats
path: root/sys/amd64
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2000-08-11 09:05:12 +0000
committerpeter <peter@FreeBSD.org>2000-08-11 09:05:12 +0000
commit85c9a2ddc16cd13cfb2434396af3929dc95adaa7 (patch)
treea1d63ef83e1b24436737dd8dbb2a0ddde4775a56 /sys/amd64
parent97323158dcf5188b2f7e901cf8d11ae44de87e76 (diff)
downloadFreeBSD-src-85c9a2ddc16cd13cfb2434396af3929dc95adaa7.zip
FreeBSD-src-85c9a2ddc16cd13cfb2434396af3929dc95adaa7.tar.gz
Clean up some low level bootstrap code:
- stop using the evil 'struct trapframe' argument for mi_startup() (formerly main()). There are much better ways of doing it. - do not use prepare_usermode() - setregs() in execve() will do it all for us as long as the p_md.md_regs pointer is set. (which is now done in machdep.c rather than init_main.c. The Alpha port did it this way all along and is much cleaner). - collect all the magic %cr0 etc register settings into one place and have the AP's call that instead of using magic numbers (!!) that keep changing over and over again. - Make it safe to call kthread_create() earlier, including during the device probe sequence. It doesn't need the callback mechanism that NetBSD's version uses. - kthreads created this way are root-less as they exist before the root filesystem is mounted. init(1) is set up so that it aquires the root pointers prior to running. If other kthreads want filesystem acccess we can make this code more generic. - set all threads start times once we have decided what time it is. - init uses a trampoline rather than the evil prepare_usermode() hack. - kern_descrip.c has a couple of tweaks to deal with forking when there is no rootdir or cwd etc. - adjust the early SYSINIT() sequence so that a few prereqisites are in place. eg: make sure the run queue is initialized before doing forks. With this, the USB code can easily create a kthread to do the device tree discovery. (I have tested it, it works nicely). There are still some open issues before this is truely useful. - tsleep() does not like working before the clock is running. It sort-of tries to spin wait, but it can do more useful things now. - stopping a kthread in kld code at unload time is "interesting" but we have a solution for that. The Alpha code needs no changes for this. It already uses pretty much the same strategies, but a little cleaner.
Diffstat (limited to 'sys/amd64')
-rw-r--r--sys/amd64/amd64/locore.S45
-rw-r--r--sys/amd64/amd64/locore.s45
-rw-r--r--sys/amd64/amd64/machdep.c19
-rw-r--r--sys/amd64/amd64/mp_machdep.c13
-rw-r--r--sys/amd64/amd64/mptable.c13
-rw-r--r--sys/amd64/amd64/vm_machdep.c15
-rw-r--r--sys/amd64/include/cpu.h1
-rw-r--r--sys/amd64/include/md_var.h1
-rw-r--r--sys/amd64/include/mptable.h13
9 files changed, 34 insertions, 131 deletions
diff --git a/sys/amd64/amd64/locore.S b/sys/amd64/amd64/locore.S
index a573052..bddd7d5 100644
--- a/sys/amd64/amd64/locore.S
+++ b/sys/amd64/amd64/locore.S
@@ -361,56 +361,11 @@ begin:
call _init386 /* wire 386 chip for unix operation */
popl %esi
- .globl __ucodesel,__udatasel
-
- pushl $0 /* unused */
- pushl __udatasel /* ss */
- pushl $0 /* esp - filled in by execve() */
- pushl $PSL_USER /* eflags (IOPL 0, int enab) */
- pushl __ucodesel /* cs */
- pushl $0 /* eip - filled in by execve() */
- subl $(13*4),%esp /* space for rest of registers */
-
- pushl %esp /* call main with frame pointer */
call _mi_startup /* autoconfiguration, mountroot etc */
hlt /* never returns to here */
/*
- * When starting init, call this to configure the process for user
- * mode. This will be inherited by other processes.
- */
-NON_GPROF_ENTRY(prepare_usermode)
- /*
- * Now we've run main() and determined what cpu-type we are, we can
- * enable write protection and alignment checking on i486 cpus and
- * above.
- */
-#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
- cmpl $CPUCLASS_386,_cpu_class
- je 1f
- movl %cr0,%eax /* get control word */
- orl $CR0_WP|CR0_AM,%eax /* enable i486 features */
- movl %eax,%cr0 /* and do it */
-1:
-#endif
- /*
- * on return from main(), we are process 1
- * set up address space and stack so that we can 'return' to user mode
- */
- movl __ucodesel,%eax
- movl __udatasel,%ecx
-
-#if 0 /* ds/es/fs are in trap frame */
- mov %cx,%ds
- mov %cx,%es
- mov %cx,%fs
-#endif
- mov %cx,%gs /* and ds to gs */
- ret /* goto user! */
-
-
-/*
* Signal trampoline, copied to top of user stack
*/
NON_GPROF_ENTRY(sigcode)
diff --git a/sys/amd64/amd64/locore.s b/sys/amd64/amd64/locore.s
index a573052..bddd7d5 100644
--- a/sys/amd64/amd64/locore.s
+++ b/sys/amd64/amd64/locore.s
@@ -361,56 +361,11 @@ begin:
call _init386 /* wire 386 chip for unix operation */
popl %esi
- .globl __ucodesel,__udatasel
-
- pushl $0 /* unused */
- pushl __udatasel /* ss */
- pushl $0 /* esp - filled in by execve() */
- pushl $PSL_USER /* eflags (IOPL 0, int enab) */
- pushl __ucodesel /* cs */
- pushl $0 /* eip - filled in by execve() */
- subl $(13*4),%esp /* space for rest of registers */
-
- pushl %esp /* call main with frame pointer */
call _mi_startup /* autoconfiguration, mountroot etc */
hlt /* never returns to here */
/*
- * When starting init, call this to configure the process for user
- * mode. This will be inherited by other processes.
- */
-NON_GPROF_ENTRY(prepare_usermode)
- /*
- * Now we've run main() and determined what cpu-type we are, we can
- * enable write protection and alignment checking on i486 cpus and
- * above.
- */
-#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
- cmpl $CPUCLASS_386,_cpu_class
- je 1f
- movl %cr0,%eax /* get control word */
- orl $CR0_WP|CR0_AM,%eax /* enable i486 features */
- movl %eax,%cr0 /* and do it */
-1:
-#endif
- /*
- * on return from main(), we are process 1
- * set up address space and stack so that we can 'return' to user mode
- */
- movl __ucodesel,%eax
- movl __udatasel,%ecx
-
-#if 0 /* ds/es/fs are in trap frame */
- mov %cx,%ds
- mov %cx,%es
- mov %cx,%fs
-#endif
- mov %cx,%gs /* and ds to gs */
- ret /* goto user! */
-
-
-/*
* Signal trampoline, copied to top of user stack
*/
NON_GPROF_ENTRY(sigcode)
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index f4d019a..2c916ac 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -240,6 +240,7 @@ vm_offset_t phys_avail[10];
static vm_offset_t buffer_sva, buffer_eva;
vm_offset_t clean_sva, clean_eva;
static vm_offset_t pager_sva, pager_eva;
+static struct trapframe proc0_tf;
#define offsetof(type, member) ((size_t)(&((type *)0)->member))
@@ -434,6 +435,7 @@ again:
mp_start(); /* fire up the APs and APICs */
mp_announce();
#endif /* SMP */
+ cpu_setregs();
}
int
@@ -1077,6 +1079,22 @@ setregs(p, entry, stack, ps_strings)
p->p_retval[1] = 0;
}
+void
+cpu_setregs(void)
+{
+ unsigned int cr0;
+
+ cr0 = rcr0();
+ cr0 |= CR0_NE; /* Done by npxinit() */
+ cr0 |= CR0_MP | CR0_TS; /* Done at every execve() too. */
+#ifdef I386_CPU
+ if (cpu_class != CPUCLASS_386)
+#endif
+ cr0 |= CR0_WP | CR0_AM;
+ load_cr0(cr0);
+ load_gs(_udatasel);
+}
+
static int
sysctl_machdep_adjkerntz(SYSCTL_HANDLER_ARGS)
{
@@ -1981,6 +1999,7 @@ init386(first)
proc0.p_addr->u_pcb.pcb_mpnest = 1;
#endif
proc0.p_addr->u_pcb.pcb_ext = 0;
+ proc0.p_md.md_regs = &proc0_tf;
}
#if defined(I586_CPU) && !defined(NO_F00F_HACK)
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 50d1ce7..61c5ecf 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -487,8 +487,6 @@ init_secondary(void)
common_tssd = *tss_gdt;
ltr(gsel_tss);
- load_cr0(0x8005003b); /* XXX! */
-
pmap_set_opt();
}
@@ -623,13 +621,6 @@ mp_enable(u_int boot_addr)
/* start each Application Processor */
start_all_aps(boot_addr);
-
- /*
- * The init process might be started on a different CPU now,
- * and the boot CPU might not call prepare_usermode to get
- * cr0 correctly configured. Thus we initialize cr0 here.
- */
- load_cr0(rcr0() | CR0_WP | CR0_AM);
}
@@ -2375,8 +2366,8 @@ ap_init()
printf("SMP: AP CPU #%d Launched!\n", cpuid);
- /* XXX FIXME: i386 specific, and redundant: Setup the FPU. */
- load_cr0((rcr0() & ~CR0_EM) | CR0_MP | CR0_NE | CR0_TS);
+ /* set up CPU registers and state */
+ cpu_setregs();
/* set up FPU state on the AP */
npxinit(__INITIAL_NPXCW__);
diff --git a/sys/amd64/amd64/mptable.c b/sys/amd64/amd64/mptable.c
index 50d1ce7..61c5ecf 100644
--- a/sys/amd64/amd64/mptable.c
+++ b/sys/amd64/amd64/mptable.c
@@ -487,8 +487,6 @@ init_secondary(void)
common_tssd = *tss_gdt;
ltr(gsel_tss);
- load_cr0(0x8005003b); /* XXX! */
-
pmap_set_opt();
}
@@ -623,13 +621,6 @@ mp_enable(u_int boot_addr)
/* start each Application Processor */
start_all_aps(boot_addr);
-
- /*
- * The init process might be started on a different CPU now,
- * and the boot CPU might not call prepare_usermode to get
- * cr0 correctly configured. Thus we initialize cr0 here.
- */
- load_cr0(rcr0() | CR0_WP | CR0_AM);
}
@@ -2375,8 +2366,8 @@ ap_init()
printf("SMP: AP CPU #%d Launched!\n", cpuid);
- /* XXX FIXME: i386 specific, and redundant: Setup the FPU. */
- load_cr0((rcr0() & ~CR0_EM) | CR0_MP | CR0_NE | CR0_TS);
+ /* set up CPU registers and state */
+ cpu_setregs();
/* set up FPU state on the AP */
npxinit(__INITIAL_NPXCW__);
diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c
index 7b4030e..cfb6cee 100644
--- a/sys/amd64/amd64/vm_machdep.c
+++ b/sys/amd64/amd64/vm_machdep.c
@@ -92,6 +92,7 @@ static void cpu_reset_proxy __P((void));
static u_int cpu_reset_proxyid;
static volatile u_int cpu_reset_proxy_active;
#endif
+extern int _ucodesel, _udatasel;
/*
* quick version of vm_fault
@@ -156,18 +157,18 @@ cpu_fork(p1, p2, flags)
*/
p2->p_md.md_regs = (struct trapframe *)
((int)p2->p_addr + UPAGES * PAGE_SIZE - 16) - 1;
- *p2->p_md.md_regs = *p1->p_md.md_regs;
+ bcopy(p1->p_md.md_regs, p2->p_md.md_regs, sizeof(*p2->p_md.md_regs));
/*
* Set registers for trampoline to user mode. Leave space for the
* return address on stack. These are the kernel mode register values.
*/
pcb2->pcb_cr3 = vtophys(vmspace_pmap(p2->p_vmspace)->pm_pdir);
- pcb2->pcb_edi = p2->p_md.md_regs->tf_edi;
- pcb2->pcb_esi = (int)fork_return;
- pcb2->pcb_ebp = p2->p_md.md_regs->tf_ebp;
+ pcb2->pcb_edi = 0;
+ pcb2->pcb_esi = (int)fork_return; /* fork_trampoline argument */
+ pcb2->pcb_ebp = 0;
pcb2->pcb_esp = (int)p2->p_md.md_regs - sizeof(void *);
- pcb2->pcb_ebx = (int)p2;
+ pcb2->pcb_ebx = (int)p2; /* fork_trampoline argument */
pcb2->pcb_eip = (int)fork_trampoline;
/*
* pcb2->pcb_ldt: duplicated below, if necessary.
@@ -200,8 +201,8 @@ cpu_fork(p1, p2, flags)
* Now, cpu_switch() can schedule the new process.
* pcb_esp is loaded pointing to the cpu_switch() stack frame
* containing the return address when exiting cpu_switch.
- * This will normally be to proc_trampoline(), which will have
- * %ebx loaded with the new proc's pointer. proc_trampoline()
+ * This will normally be to fork_trampoline(), which will have
+ * %ebx loaded with the new proc's pointer. fork_trampoline()
* will set up a stack to call fork_return(p, frame); to complete
* the return to user-mode.
*/
diff --git a/sys/amd64/include/cpu.h b/sys/amd64/include/cpu.h
index c6aa46f..ffabf7f 100644
--- a/sys/amd64/include/cpu.h
+++ b/sys/amd64/include/cpu.h
@@ -56,7 +56,6 @@
#define cpu_exec(p) /* nothing */
#define cpu_swapin(p) /* nothing */
#define cpu_setstack(p, ap) ((p)->p_md.md_regs[SP] = (ap))
-#define cpu_set_init_frame(p, fp) ((p)->p_md.md_regs = (fp))
#define CLKF_USERMODE(framep) \
((ISPL((framep)->cf_cs) == SEL_UPL) || (framep->cf_eflags & PSL_VM))
diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h
index 1c3fe64..4c05237 100644
--- a/sys/amd64/include/md_var.h
+++ b/sys/amd64/include/md_var.h
@@ -70,6 +70,7 @@ void bcopyb __P((const void *from, void *to, size_t len));
void busdma_swi __P((void));
void cpu_halt __P((void));
void cpu_reset __P((void));
+void cpu_setregs __P((void));
void cpu_switch_load_gs __P((void)) __asm(__STRING(cpu_switch_load_gs));
void doreti_iret __P((void)) __asm(__STRING(doreti_iret));
void doreti_iret_fault __P((void)) __asm(__STRING(doreti_iret_fault));
diff --git a/sys/amd64/include/mptable.h b/sys/amd64/include/mptable.h
index 50d1ce7..61c5ecf 100644
--- a/sys/amd64/include/mptable.h
+++ b/sys/amd64/include/mptable.h
@@ -487,8 +487,6 @@ init_secondary(void)
common_tssd = *tss_gdt;
ltr(gsel_tss);
- load_cr0(0x8005003b); /* XXX! */
-
pmap_set_opt();
}
@@ -623,13 +621,6 @@ mp_enable(u_int boot_addr)
/* start each Application Processor */
start_all_aps(boot_addr);
-
- /*
- * The init process might be started on a different CPU now,
- * and the boot CPU might not call prepare_usermode to get
- * cr0 correctly configured. Thus we initialize cr0 here.
- */
- load_cr0(rcr0() | CR0_WP | CR0_AM);
}
@@ -2375,8 +2366,8 @@ ap_init()
printf("SMP: AP CPU #%d Launched!\n", cpuid);
- /* XXX FIXME: i386 specific, and redundant: Setup the FPU. */
- load_cr0((rcr0() & ~CR0_EM) | CR0_MP | CR0_NE | CR0_TS);
+ /* set up CPU registers and state */
+ cpu_setregs();
/* set up FPU state on the AP */
npxinit(__INITIAL_NPXCW__);
OpenPOWER on IntegriCloud