Module Name: src Committed By: maxv Date: Wed Feb 8 09:39:32 UTC 2017
Modified Files: src/sys/arch/amd64/amd64: gdt.c src/sys/arch/amd64/include: gdt.h src/sys/arch/i386/i386: gdt.c src/sys/arch/i386/include: segments.h Log Message: Localify, add a comment and merge some others. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/gdt.c cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/include/gdt.h cvs rdiff -u -r1.57 -r1.58 src/sys/arch/i386/i386/gdt.c cvs rdiff -u -r1.58 -r1.59 src/sys/arch/i386/include/segments.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/gdt.c diff -u src/sys/arch/amd64/amd64/gdt.c:1.34 src/sys/arch/amd64/amd64/gdt.c:1.35 --- src/sys/arch/amd64/amd64/gdt.c:1.34 Sun Aug 21 10:42:33 2016 +++ src/sys/arch/amd64/amd64/gdt.c Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.34 2016/08/21 10:42:33 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.35 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.34 2016/08/21 10:42:33 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.35 2017/02/08 09:39:32 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -63,6 +63,7 @@ int gdt_dynavail; int gdt_next; /* next available slot for sweeping */ int gdt_free; /* next free slot; terminated with GNULL_SEL */ +static void set_sys_gdt(int, void *, size_t, int, int, int); void gdt_init(void); void @@ -84,7 +85,10 @@ update_descriptor(void *tp, void *ep) #endif } -void +/* + * Called on a newly-allocated GDT slot, so no race between CPUs. + */ +static void set_sys_gdt(int slot, void *base, size_t limit, int type, int dpl, int gran) { union { Index: src/sys/arch/amd64/include/gdt.h diff -u src/sys/arch/amd64/include/gdt.h:1.8 src/sys/arch/amd64/include/gdt.h:1.9 --- src/sys/arch/amd64/include/gdt.h:1.8 Sat Aug 20 18:31:06 2016 +++ src/sys/arch/amd64/include/gdt.h Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.h,v 1.8 2016/08/20 18:31:06 maxv Exp $ */ +/* $NetBSD: gdt.h,v 1.9 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -44,8 +44,6 @@ void tss_free(int); int ldt_alloc(void *, size_t); void ldt_free(int); - -void set_sys_gdt(int, void *, size_t, int, int, int); #endif #define MINGDTSIZ PAGE_SIZE Index: src/sys/arch/i386/i386/gdt.c diff -u src/sys/arch/i386/i386/gdt.c:1.57 src/sys/arch/i386/i386/gdt.c:1.58 --- src/sys/arch/i386/i386/gdt.c:1.57 Sun Feb 5 10:42:21 2017 +++ src/sys/arch/i386/i386/gdt.c Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.57 2017/02/05 10:42:21 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.58 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.57 2017/02/05 10:42:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.58 2017/02/08 09:39:32 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -60,6 +60,7 @@ int gdt_free[2]; /* next free slot; term static int ldt_count; /* number of LDTs */ static int ldt_max = 1000;/* max number of LDTs */ +static void setgdt(int, const void *, size_t, int, int, int, int); void gdt_init(void); static void gdt_grow(int); static int gdt_get_slot1(int); @@ -81,7 +82,10 @@ update_descriptor(union descriptor *tabl #endif } -void +/* + * Called on a newly-allocated GDT slot, so no race between CPUs. + */ +static void setgdt(int sel, const void *base, size_t limit, int type, int dpl, int def32, int gran) { @@ -104,7 +108,8 @@ setgdt(int sel, const void *base, size_t } /* - * Initialize the GDT subsystem. Called from autoconf(). + * Initialize the GDT. We already have a gdtstore, which was temporarily used + * by the bootstrap code. Now, we allocate a new gdtstore, and put it in cpu0. */ void gdt_init(void) @@ -152,7 +157,8 @@ gdt_init(void) } /* - * Allocate shadow GDT for a slave CPU. + * Allocate shadow GDT for a secondary CPU. It contains the same values as the + * GDT present in cpu0 (gdtstore). */ void gdt_alloc_cpu(struct cpu_info *ci) @@ -180,10 +186,9 @@ gdt_alloc_cpu(struct cpu_info *ci) sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0); } - /* - * Load appropriate gdt descriptor; we better be running on *ci - * (for the most part, this is how a CPU knows who it is). + * Load appropriate GDT descriptor into the currently running CPU, which must + * be ci. */ void gdt_init_cpu(struct cpu_info *ci) @@ -227,7 +232,6 @@ gdt_init_cpu(struct cpu_info *ci) } #if defined(MULTIPROCESSOR) && !defined(XEN) - void gdt_reload_cpu(struct cpu_info *ci) { @@ -240,9 +244,10 @@ gdt_reload_cpu(struct cpu_info *ci) } #endif - /* - * Grow the GDT. + * Grow the GDT. The GDT is present on each CPU, so we need to iterate over all + * of them. We already have the virtual memory, we only need to grow the + * physical memory. */ void gdt_grow(int which) Index: src/sys/arch/i386/include/segments.h diff -u src/sys/arch/i386/include/segments.h:1.58 src/sys/arch/i386/include/segments.h:1.59 --- src/sys/arch/i386/include/segments.h:1.58 Sun Feb 5 10:42:21 2017 +++ src/sys/arch/i386/include/segments.h Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: segments.h,v 1.58 2017/02/05 10:42:21 maxv Exp $ */ +/* $NetBSD: segments.h,v 1.59 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -197,7 +197,6 @@ void setgate(struct gate_descriptor *, v void setregion(struct region_descriptor *, void *, size_t); void setsegment(struct segment_descriptor *, const void *, size_t, int, int, int, int); -void setgdt(int, const void *, size_t, int, int, int, int); void unsetgate(struct gate_descriptor *); void cpu_init_idt(void); void update_descriptor(union descriptor *, union descriptor *);