Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/sommerfeld_i386mp_1]: src/sys/arch/i386 Set up per-cpu GDT.



details:   https://anonhg.NetBSD.org/src/rev/907956813198
branches:  sommerfeld_i386mp_1
changeset: 482475:907956813198
user:      sommerfeld <sommerfeld%NetBSD.org@localhost>
date:      Sat Dec 29 23:30:58 2001 +0000

description:
Set up per-cpu GDT.
Use %fs for per-cpu data access.

diffstat:

 sys/arch/i386/i386/apm.c          |   18 +--
 sys/arch/i386/i386/cpu.c          |   21 ++--
 sys/arch/i386/i386/db_interface.c |    6 +-
 sys/arch/i386/i386/gdt.c          |  115 +++++++++++++++++------
 sys/arch/i386/i386/genassym.cf    |    6 +-
 sys/arch/i386/i386/ioapic.c       |   13 ++-
 sys/arch/i386/i386/ipifuncs.c     |    6 +-
 sys/arch/i386/i386/locore.s       |  185 +++++++++++++++++--------------------
 sys/arch/i386/i386/machdep.c      |   77 ++++++++------
 sys/arch/i386/i386/mpbios.c       |    6 +-
 sys/arch/i386/i386/mptramp.s      |   74 ++++++--------
 sys/arch/i386/i386/svr4_sigcode.s |   35 ++----
 sys/arch/i386/i386/trap.c         |   29 +++--
 sys/arch/i386/include/cpu.h       |   41 ++++----
 sys/arch/i386/include/gdt.h       |   13 ++-
 sys/arch/i386/include/i82489var.h |    8 +-
 sys/arch/i386/include/intr.h      |    5 +-
 sys/arch/i386/include/pcb.h       |    8 +-
 sys/arch/i386/include/segments.h  |    6 +-
 sys/arch/i386/isa/icu.s           |    6 +-
 20 files changed, 368 insertions(+), 310 deletions(-)

diffs (truncated from 1788 to 300 lines):

diff -r c196c7d9f721 -r 907956813198 sys/arch/i386/i386/apm.c
--- a/sys/arch/i386/i386/apm.c  Sat Dec 29 23:22:13 2001 +0000
+++ b/sys/arch/i386/i386/apm.c  Sat Dec 29 23:30:58 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apm.c,v 1.56.2.7 2001/12/29 21:09:05 sommerfeld Exp $ */
+/*     $NetBSD: apm.c,v 1.56.2.8 2001/12/29 23:30:58 sommerfeld Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.56.2.7 2001/12/29 21:09:05 sommerfeld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.56.2.8 2001/12/29 23:30:58 sommerfeld Exp $");
 
 #include "apm.h"
 #if NAPM > 1
@@ -1353,13 +1353,11 @@
            apminfo.apm_code32_seg_len,
            apminfo.apm_data_seg_len,
            apmsc->sc_dev.dv_xname));
-       setsegment(&gdt[GAPM32CODE_SEL].sd,
-           ISA_HOLE_VADDR(apminfo.apm_code32_seg_base),
+       setgdt(GAPM32CODE_SEL, ISA_HOLE_VADDR(apminfo.apm_code32_seg_base),
            apminfo.apm_code32_seg_len - 1,
            SDT_MEMERA, SEL_KPL, 1, 0);
 #ifdef GAPM16CODE_SEL
-       setsegment(&gdt[GAPM16CODE_SEL].sd,
-           ISA_HOLE_VADDR(apminfo.apm_code16_seg_base),
+       setgdt(GAPM16CODE_SEL, ISA_HOLE_VADDR(apminfo.apm_code16_seg_base),
            apminfo.apm_code16_seg_len - 1,
            SDT_MEMERA, SEL_KPL, 0, 0);
 #endif
@@ -1369,7 +1367,7 @@
                 * descriptor to just the first byte of the code
                 * segment, read only.
                 */
-               setsegment(&gdt[GAPMDATA_SEL].sd,
+               setgdt(GAPMDATA_SEL,
                    ISA_HOLE_VADDR(apminfo.apm_code32_seg_base),
                    0, SDT_MEMROA, SEL_KPL, 0, 0);
        } else if (apminfo.apm_data_seg_base < IOM_BEGIN) {
@@ -1392,13 +1390,11 @@
                    ("mapping bios data area %x @ 0x%lx\n%s: ",
                    apminfo.apm_data_seg_base, memh,
                    apmsc->sc_dev.dv_xname));
-               setsegment(&gdt[GAPMDATA_SEL].sd,
-                   (void *)memh,
+               setgdt(GAPMDATA_SEL, (void *)memh,
                    apminfo.apm_data_seg_len - 1,
                    SDT_MEMRWA, SEL_KPL, 1, 0);
        } else
-               setsegment(&gdt[GAPMDATA_SEL].sd,
-                   ISA_HOLE_VADDR(apminfo.apm_data_seg_base),
+               setgdt(GAPMDATA_SEL, ISA_HOLE_VADDR(apminfo.apm_data_seg_base),
                    apminfo.apm_data_seg_len - 1,
                    SDT_MEMRWA, SEL_KPL, 1, 0);
 
diff -r c196c7d9f721 -r 907956813198 sys/arch/i386/i386/cpu.c
--- a/sys/arch/i386/i386/cpu.c  Sat Dec 29 23:22:13 2001 +0000
+++ b/sys/arch/i386/i386/cpu.c  Sat Dec 29 23:30:58 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.1.2.24 2001/09/22 23:01:04 sommerfeld Exp $ */
+/* $NetBSD: cpu.c,v 1.1.2.25 2001/12/29 23:30:59 sommerfeld Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  * CPU, on uniprocessors).  The CPU info list is initialized to
  * point at it.
  */
-struct cpu_info cpu_info_primary;
+struct cpu_info cpu_info_primary = { 0, &cpu_info_primary };
 struct cpu_info *cpu_info_list = &cpu_info_primary;
 
 #ifdef MULTIPROCESSOR
@@ -151,7 +151,7 @@
 void
 cpu_init_first()
 {
-       int cpunum = cpu_number();
+       int cpunum = lapic_cpu_number();
 
        if (cpunum != 0) {
                cpu_info[0] = NULL;
@@ -240,14 +240,15 @@
        } else {
                ci = &cpu_info_primary;
 #if defined(MULTIPROCESSOR)
-               if (cpunum != cpu_number()) {
+               if (cpunum != lapic_cpu_number()) {
                        panic("%s: running cpu is at apic %d"
                            " instead of at expected %d\n",
-                           sc->sc_dev.dv_xname, cpu_number(), cpunum);
+                           sc->sc_dev.dv_xname, lapic_cpu_number(), cpunum);
                }
 #endif
        }
 
+       ci->ci_self = ci;
        sc->sc_info = ci;
 
        ci->ci_dev = self;
@@ -318,6 +319,7 @@
                printf("apid %d (application processor)\n", caa->cpu_number);
 
 #if defined(MULTIPROCESSOR)
+               gdt_alloc_cpu(ci);
                cpu_start_secondary(ci);
                if (ci->ci_flags & CPUF_PRESENT) {
                        identifycpu(ci);
@@ -415,7 +417,7 @@
 
 #ifdef MULTIPROCESSOR
        ci->ci_flags |= CPUF_RUNNING;
-       cpus_running |= 1 << cpu_number();
+       cpus_running |= 1 << ci->ci_cpuid;
 #endif
 }
 
@@ -515,8 +517,6 @@
        }
 }
 
-
-
 /*
  * The CPU ends up here when its ready to run
  * This is called from code in mptramp.s; at this point, we are running
@@ -553,9 +553,9 @@
 
        lcr0(ci->ci_idle_pcb->pcb_cr0);
        lapic_set_lvt();
+       gdt_init_cpu(ci);
        npxinit(ci);
        cpu_init_idt();
-       gdt_init_cpu();
 
        lldt(GSEL(GLDT_SEL, SEL_KPL));
 
@@ -563,7 +563,8 @@
 
        s = splhigh();
        enable_intr();
-       printf("%s: CPU %d running\n",ci->ci_dev->dv_xname, cpu_number());
+
+       printf("%s: CPU %ld running\n",ci->ci_dev->dv_xname, ci->ci_cpuid);
 #if defined(I586_CPU) || defined(I686_CPU)
        if (ci->ci_feature_flags & CPUID_TSC)
                tsc_microset(ci);
diff -r c196c7d9f721 -r 907956813198 sys/arch/i386/i386/db_interface.c
--- a/sys/arch/i386/i386/db_interface.c Sat Dec 29 23:22:13 2001 +0000
+++ b/sys/arch/i386/i386/db_interface.c Sat Dec 29 23:30:58 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_interface.c,v 1.30.2.7 2001/12/29 21:09:06 sommerfeld Exp $ */
+/*     $NetBSD: db_interface.c,v 1.30.2.8 2001/12/29 23:30:59 sommerfeld Exp $ */
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.30.2.7 2001/12/29 21:09:06 sommerfeld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.30.2.8 2001/12/29 23:30:59 sommerfeld Exp $");
 
 #include "opt_ddb.h"
 
@@ -50,6 +50,8 @@
 #include <machine/db_machdep.h>
 #include <machine/cpuvar.h>
 #include <machine/i82093var.h>
+#include <machine/i82489reg.h>
+#include <machine/i82489var.h>
 #include <machine/atomic.h>
 
 #include <ddb/db_sym.h>
diff -r c196c7d9f721 -r 907956813198 sys/arch/i386/i386/gdt.c
--- a/sys/arch/i386/i386/gdt.c  Sat Dec 29 23:22:13 2001 +0000
+++ b/sys/arch/i386/i386/gdt.c  Sat Dec 29 23:30:58 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gdt.c,v 1.22.2.5 2001/12/29 21:09:06 sommerfeld Exp $  */
+/*     $NetBSD: gdt.c,v 1.22.2.6 2001/12/29 23:31:00 sommerfeld Exp $  */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.22.2.5 2001/12/29 21:09:06 sommerfeld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.22.2.6 2001/12/29 23:31:00 sommerfeld Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -49,9 +49,6 @@
 
 #include <machine/gdt.h>
 
-#define        MINGDTSIZ       512
-#define        MAXGDTSIZ       8192
-
 int gdt_size;          /* total number of GDT entries */
 int gdt_count;         /* number of GDT entries in use */
 int gdt_next;          /* next available slot for sweeping */
@@ -61,10 +58,14 @@
 
 static __inline void gdt_lock __P((void));
 static __inline void gdt_unlock __P((void));
+#if 0
 void gdt_compact __P((void));
+#endif
 void gdt_init __P((void));
 void gdt_grow __P((void));
+#if 0
 void gdt_shrink __P((void));
+#endif
 int gdt_get_slot __P((void));
 void gdt_put_slot __P((int));
 
@@ -91,6 +92,20 @@
        (void) lockmgr(&gdt_lock_store, LK_RELEASE, NULL);
 }
 
+void
+setgdt(int sel, void *base, size_t limit,
+    int type, int dpl, int def32, int gran)
+{
+       struct segment_descriptor *sd = &gdt[sel].sd;
+       CPU_INFO_ITERATOR cii;
+       struct cpu_info *ci;
+       
+       setsegment(sd, base, limit, type, dpl, def32, gran);
+       for (CPU_INFO_FOREACH(cii, ci))
+               ci->ci_gdt[sel].sd = *sd;
+}
+
+#if 0
 /*
  * Compact the GDT as follows:
  * 0) We partition the GDT into two areas, one of the slots before gdt_count,
@@ -135,7 +150,7 @@
                        pmap->pm_ldt_sel = GSEL(slot, SEL_KPL);
                        /*
                         * XXXSMP: if the pmap is in use on other
-                        * processors, they need to reload thier
+                        * processors, they need to reload their
                         * LDT!
                         */
                }
@@ -151,6 +166,7 @@
        gdt_free = GNULL_SEL;
        proclist_unlock_read();
 }
+#endif
 
 /*
  * Initialize the GDT.
@@ -160,6 +176,7 @@
 {
        size_t max_len, min_len;
        union descriptor *old_gdt;
+       struct cpu_info *ci = curcpu();
        struct vm_page *pg;
        vaddr_t va;
 
@@ -184,24 +201,57 @@
                    VM_PROT_READ | VM_PROT_WRITE);
        }
        memcpy(gdt, old_gdt, NGDT * sizeof(gdt[0]));
+       ci->ci_gdt = gdt;
+       setsegment(&ci->ci_gdt[GCPU_SEL].sd, ci, sizeof(struct cpu_info)-1,
+           SDT_MEMRWA, SEL_KPL, 1, 1);
+       gdt_init_cpu(ci);
+}
 
-       gdt_init_cpu();
+void
+gdt_alloc_cpu(struct cpu_info *ci)
+{
+       int max_len = MAXGDTSIZ * sizeof(gdt[0]);
+       int min_len = MINGDTSIZ * sizeof(gdt[0]);
+
+       ci->ci_gdt = (union descriptor *)uvm_km_valloc(kernel_map, max_len);
+       uvm_map_pageable(kernel_map, (vaddr_t)ci->ci_gdt,
+           (vaddr_t)ci->ci_gdt + min_len, FALSE, FALSE);
+       memcpy(ci->ci_gdt, gdt, min_len);
+       setsegment(&ci->ci_gdt[GCPU_SEL].sd, ci, sizeof(struct cpu_info)-1,
+           SDT_MEMRWA, SEL_KPL, 1, 1);
 }
 
+
 /*
  * Load appropriate gdt descriptor.
  */
 
-void gdt_init_cpu()
+void
+gdt_init_cpu(struct cpu_info *ci)



Home | Main Index | Thread Index | Old Index