Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch style, and move some i386-specific code into i386/
details: https://anonhg.NetBSD.org/src/rev/929772bafaa2
branches: trunk
changeset: 355999:929772bafaa2
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Aug 27 09:32:12 2017 +0000
description:
style, and move some i386-specific code into i386/
diffstat:
sys/arch/i386/i386/machdep.c | 80 +++++++++++++++++++++++++++++++-
sys/arch/x86/include/cpu.h | 10 ++--
sys/arch/x86/x86/cpu.c | 105 +++++-------------------------------------
3 files changed, 94 insertions(+), 101 deletions(-)
diffs (truncated from 347 to 300 lines):
diff -r b129732bafbd -r 929772bafaa2 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c Sun Aug 27 08:38:32 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c Sun Aug 27 09:32:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.791 2017/08/12 19:06:23 kre Exp $ */
+/* $NetBSD: machdep.c,v 1.792 2017/08/27 09:32:12 maxv Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.791 2017/08/12 19:06:23 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.792 2017/08/27 09:32:12 maxv Exp $");
#include "opt_beep.h"
#include "opt_compat_freebsd.h"
@@ -560,7 +560,80 @@
}
#endif /* XEN */
+/* XXX */
+#define IDTVEC(name) __CONCAT(X, name)
+typedef void (vector)(void);
+
#ifndef XEN
+static void tss_init(struct i386tss *, void *, void *);
+
+static void
+tss_init(struct i386tss *tss, void *stack, void *func)
+{
+ KASSERT(curcpu()->ci_pmap == pmap_kernel());
+
+ memset(tss, 0, sizeof *tss);
+ tss->tss_esp0 = tss->tss_esp = (int)((char *)stack + USPACE - 16);
+ tss->tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
+ tss->__tss_cs = GSEL(GCODE_SEL, SEL_KPL);
+ tss->tss_fs = GSEL(GCPU_SEL, SEL_KPL);
+ tss->tss_gs = tss->__tss_es = tss->__tss_ds =
+ tss->__tss_ss = GSEL(GDATA_SEL, SEL_KPL);
+ /* %cr3 contains the value associated to pmap_kernel */
+ tss->tss_cr3 = rcr3();
+ tss->tss_esp = (int)((char *)stack + USPACE - 16);
+ tss->tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
+ tss->__tss_eflags = PSL_MBO | PSL_NT; /* XXX not needed? */
+ tss->__tss_eip = (int)func;
+}
+
+extern vector IDTVEC(tss_trap08);
+#if defined(DDB) && defined(MULTIPROCESSOR)
+extern vector Xintrddbipi, Xx2apic_intrddbipi;
+extern int ddb_vec;
+#endif
+
+void
+cpu_set_tss_gates(struct cpu_info *ci)
+{
+ struct segment_descriptor sd;
+ void *doubleflt_stack;
+
+ doubleflt_stack = (void *)uvm_km_alloc(kernel_map, USPACE, 0,
+ UVM_KMF_WIRED);
+ tss_init(&ci->ci_doubleflt_tss, doubleflt_stack, IDTVEC(tss_trap08));
+
+ setsegment(&sd, &ci->ci_doubleflt_tss, sizeof(struct i386tss) - 1,
+ SDT_SYS386TSS, SEL_KPL, 0, 0);
+ ci->ci_gdt[GTRAPTSS_SEL].sd = sd;
+
+ setgate(&idt[8], NULL, 0, SDT_SYSTASKGT, SEL_KPL,
+ GSEL(GTRAPTSS_SEL, SEL_KPL));
+
+#if defined(DDB) && defined(MULTIPROCESSOR)
+ /*
+ * Set up separate handler for the DDB IPI, so that it doesn't
+ * stomp on a possibly corrupted stack.
+ *
+ * XXX overwriting the gate set in db_machine_init.
+ * Should rearrange the code so that it's set only once.
+ */
+ void *ddbipi_stack;
+
+ ddbipi_stack = (void *)uvm_km_alloc(kernel_map, USPACE, 0,
+ UVM_KMF_WIRED);
+ tss_init(&ci->ci_ddbipi_tss, ddbipi_stack,
+ x2apic_mode ? Xx2apic_intrddbipi : Xintrddbipi);
+
+ setsegment(&sd, &ci->ci_ddbipi_tss, sizeof(struct i386tss) - 1,
+ SDT_SYS386TSS, SEL_KPL, 0, 0);
+ ci->ci_gdt[GIPITSS_SEL].sd = sd;
+
+ setgate(&idt[ddb_vec], NULL, 0, SDT_SYSTASKGT, SEL_KPL,
+ GSEL(GIPITSS_SEL, SEL_KPL));
+#endif
+}
+
/*
* Set up TSS and I/O bitmap.
*/
@@ -904,8 +977,7 @@
sd->sd_hibase = (int)base >> 24;
}
-#define IDTVEC(name) __CONCAT(X, name)
-typedef void (vector)(void);
+/* XXX */
extern vector IDTVEC(syscall);
extern vector *IDTVEC(exceptions)[];
#ifdef XEN
diff -r b129732bafbd -r 929772bafaa2 sys/arch/x86/include/cpu.h
--- a/sys/arch/x86/include/cpu.h Sun Aug 27 08:38:32 2017 +0000
+++ b/sys/arch/x86/include/cpu.h Sun Aug 27 09:32:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.77 2017/08/27 08:38:32 maxv Exp $ */
+/* $NetBSD: cpu.h,v 1.78 2017/08/27 09:32:13 maxv Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -403,6 +403,9 @@
#define cpu_idle() (*x86_cpu_idle)()
/* machdep.c */
+#ifdef i386
+void cpu_set_tss_gates(struct cpu_info *);
+#endif
void cpu_reset(void);
/* longrun.c */
@@ -429,9 +432,6 @@
/* cpu_topology.c */
void x86_cpu_topology(struct cpu_info *);
-/* vm_machdep.c */
-void cpu_proc_fork(struct proc *, struct proc *);
-
/* locore.s */
struct region_descriptor;
void lgdt(struct region_descriptor *);
@@ -458,10 +458,10 @@
#endif
/* cpu.c */
-
void cpu_probe_features(struct cpu_info *);
/* vm_machdep.c */
+void cpu_proc_fork(struct proc *, struct proc *);
paddr_t kvtop(void *);
#ifdef USER_LDT
diff -r b129732bafbd -r 929772bafaa2 sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c Sun Aug 27 08:38:32 2017 +0000
+++ b/sys/arch/x86/x86/cpu.c Sun Aug 27 09:32:12 2017 +0000
@@ -1,6 +1,6 @@
-/* $NetBSD: cpu.c,v 1.133 2017/08/27 08:38:32 maxv Exp $ */
+/* $NetBSD: cpu.c,v 1.134 2017/08/27 09:32:12 maxv Exp $ */
-/*-
+/*
* Copyright (c) 2000-2012 NetBSD Foundation, Inc.
* All rights reserved.
*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.133 2017/08/27 08:38:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.134 2017/08/27 09:32:12 maxv Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -164,15 +164,13 @@
.ci_curldt = -1,
#ifdef TRAPLOG
.ci_tlog_base = &tlog_primary,
-#endif /* !TRAPLOG */
+#endif
};
struct cpu_info *cpu_info_list = &cpu_info_primary;
-static void cpu_set_tss_gates(struct cpu_info *);
-
#ifdef i386
-static void tss_init(struct i386tss *, void *, void *);
+void cpu_set_tss_gates(struct cpu_info *);
#endif
static void cpu_init_idle_lwp(struct cpu_info *);
@@ -187,8 +185,6 @@
* [6] structured extended features cpuid.7:%ecx
*/
-extern char x86_64_doubleflt_stack[];
-
#ifdef MULTIPROCESSOR
bool x86_mp_online;
paddr_t mp_trampoline_paddr = MP_TRAMPOLINE;
@@ -395,7 +391,9 @@
cpu_intr_init(ci);
cpu_get_tsc_freq(ci);
cpu_init(ci);
+#ifdef i386
cpu_set_tss_gates(ci);
+#endif
pmap_cpu_init_late(ci);
#if NLAPIC > 0
if (caa->cpu_role != CPU_ROLE_SP) {
@@ -434,7 +432,9 @@
*/
cpu_intr_init(ci);
gdt_alloc_cpu(ci);
+#ifdef i386
cpu_set_tss_gates(ci);
+#endif
pmap_cpu_init_late(ci);
cpu_start_secondary(ci);
if (ci->ci_flags & CPUF_PRESENT) {
@@ -501,7 +501,6 @@
cfaa.ci = ci;
if (ifattr_match(ifattr, "cpufeaturebus")) {
-
if (ci->ci_frequency == NULL) {
cfaa.name = "frequency";
ci->ci_frequency = config_found_ia(self,
@@ -799,7 +798,7 @@
cpu_probe(ci);
ci->ci_data.cpu_cc_freq = cpu_info_primary.ci_data.cpu_cc_freq;
- /* cpu_get_tsc_freq(ci); */
+ /* cpu_get_tsc_freq(ci); */
KDASSERT((ci->ci_flags & CPUF_PRESENT) == 0);
@@ -815,7 +814,7 @@
/*
* Wait to be brought online. Use 'monitor/mwait' if available,
* in order to make the TSC drift as much as possible. so that
- * we can detect it later. If not available, try 'pause'.
+ * we can detect it later. If not available, try 'pause'.
* We'd like to use 'hlt', but we have interrupts off.
*/
while ((ci->ci_flags & CPUF_GO) == 0) {
@@ -924,7 +923,7 @@
*/
extern u_char cpu_spinup_trampoline[];
extern u_char cpu_spinup_trampoline_end[];
-
+
vaddr_t mp_trampoline_vaddr;
mp_trampoline_vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
@@ -943,84 +942,6 @@
}
#endif
-#ifdef i386
-static void
-tss_init(struct i386tss *tss, void *stack, void *func)
-{
- KASSERT(curcpu()->ci_pmap == pmap_kernel());
-
- memset(tss, 0, sizeof *tss);
- tss->tss_esp0 = tss->tss_esp = (int)((char *)stack + USPACE - 16);
- tss->tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
- tss->__tss_cs = GSEL(GCODE_SEL, SEL_KPL);
- tss->tss_fs = GSEL(GCPU_SEL, SEL_KPL);
- tss->tss_gs = tss->__tss_es = tss->__tss_ds =
- tss->__tss_ss = GSEL(GDATA_SEL, SEL_KPL);
- /* %cr3 contains the value associated to pmap_kernel */
- tss->tss_cr3 = rcr3();
- tss->tss_esp = (int)((char *)stack + USPACE - 16);
- tss->tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
- tss->__tss_eflags = PSL_MBO | PSL_NT; /* XXX not needed? */
- tss->__tss_eip = (int)func;
-}
-
-/* XXX */
-#define IDTVEC(name) __CONCAT(X, name)
-typedef void (vector)(void);
-extern vector IDTVEC(tss_trap08);
-#if defined(DDB) && defined(MULTIPROCESSOR)
-extern vector Xintrddbipi, Xx2apic_intrddbipi;
-extern int ddb_vec;
-#endif
-
-static void
-cpu_set_tss_gates(struct cpu_info *ci)
-{
- struct segment_descriptor sd;
- void *doubleflt_stack;
-
- doubleflt_stack = (void *)uvm_km_alloc(kernel_map, USPACE, 0,
- UVM_KMF_WIRED);
- tss_init(&ci->ci_doubleflt_tss, doubleflt_stack, IDTVEC(tss_trap08));
-
- setsegment(&sd, &ci->ci_doubleflt_tss, sizeof(struct i386tss) - 1,
- SDT_SYS386TSS, SEL_KPL, 0, 0);
- ci->ci_gdt[GTRAPTSS_SEL].sd = sd;
Home |
Main Index |
Thread Index |
Old Index