Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/amd64/stand/prekern Fix/remove some half-baked stuf...



details:   https://anonhg.NetBSD.org/src/rev/e91ef1c9865e
branches:  trunk
changeset: 449752:e91ef1c9865e
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Mar 19 19:15:57 2019 +0000

description:
Fix/remove some half-baked stuff I left in the prekern:

 - Page-align the idt store, to be extra sure.
 - Remove unneeded prototypes.
 - Drop the TSS, we don't care and aren't even using it.
 - Initialize %ss with a default value.
 - Fix three exception handlers, no need to push an error code.

No actual impact, because these things are used only when returning from
exceptions received in the prekern; these exceptions are not supposed to
be ever received, never are, and if they were we wouldn't return anyway.

diffstat:

 sys/arch/amd64/stand/prekern/locore.S  |   7 ++-
 sys/arch/amd64/stand/prekern/prekern.c |  63 +++------------------------------
 sys/arch/amd64/stand/prekern/trap.S    |   8 ++--
 3 files changed, 14 insertions(+), 64 deletions(-)

diffs (162 lines):

diff -r b6ff8ebe5e52 -r e91ef1c9865e sys/arch/amd64/stand/prekern/locore.S
--- a/sys/arch/amd64/stand/prekern/locore.S     Tue Mar 19 16:56:29 2019 +0000
+++ b/sys/arch/amd64/stand/prekern/locore.S     Tue Mar 19 19:15:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.10 2019/03/09 08:42:25 maxv Exp $ */
+/*     $NetBSD: locore.S,v 1.11 2019/03/19 19:15:57 maxv Exp $ */
 
 /*
  * Copyright (c) 1998, 2000, 2007, 2008, 2016, 2017 The NetBSD Foundation, Inc.
@@ -193,8 +193,6 @@
        .quad 0x0000000000000000        /* always empty */
        .quad 0x00af9a000000ffff        /* kernel CS */
        .quad 0x00cf92000000ffff        /* kernel DS */
-       .quad 0x0000000000000000        /* kernel TSS [1/2] */
-       .quad 0x0000000000000000        /* kernel TSS [2/2] */
 END(gdt64_start)
 gdt64_end:
 
@@ -569,6 +567,9 @@
        movw    %ax,%gs
        movw    %ax,%fs
 
+       movw    $GSEL(GDATA_SEL, SEL_KPL),%ax
+       movw    %ax,%ss
+
        /* The first physical page available. */
        leaq    (TABLESIZE)(%rsi),%rdi
 
diff -r b6ff8ebe5e52 -r e91ef1c9865e sys/arch/amd64/stand/prekern/prekern.c
--- a/sys/arch/amd64/stand/prekern/prekern.c    Tue Mar 19 16:56:29 2019 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.c    Tue Mar 19 19:15:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prekern.c,v 1.10 2018/08/12 12:42:54 maxv Exp $        */
+/*     $NetBSD: prekern.c,v 1.11 2019/03/19 19:15:57 maxv Exp $        */
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -46,15 +46,7 @@
 
 extern paddr_t kernpa_start, kernpa_end;
 
-static uint8_t idtstore[PAGE_SIZE];
-static uint8_t faultstack[PAGE_SIZE];
-static struct x86_64_tss prekern_tss;
-
-/* GDT offsets */
-#define PREKERN_GDT_NUL_OFF    (0 * 8)
-#define PREKERN_GDT_CS_OFF     (1 * 8)
-#define PREKERN_GDT_DS_OFF     (2 * 8)
-#define PREKERN_GDT_TSS_OFF    (3 * 8)
+static uint8_t idtstore[PAGE_SIZE] __aligned(PAGE_SIZE);
 
 #define IDTVEC(name) __CONCAT(X, name)
 typedef void (vector)(void);
@@ -83,14 +75,6 @@
        uint64_t sf_ss;
 };
 
-static void setregion(struct region_descriptor *, void *, uint16_t);
-static void setgate(struct gate_descriptor *, void *, int, int, int, int);
-static void set_sys_segment(struct sys_segment_descriptor *, void *,
-    size_t, int, int, int);
-static void set_sys_gdt(int, void *, size_t, int, int, int);
-static void init_tss(void);
-static void init_idt(void);
-
 void trap(struct smallframe *);
 
 static char *trap_type[] = {
@@ -142,6 +126,8 @@
        while (1);
 }
 
+/* -------------------------------------------------------------------------- */
+
 static void
 setregion(struct region_descriptor *rd, void *base, uint16_t limit)
 {
@@ -167,42 +153,6 @@
 }
 
 static void
-set_sys_segment(struct sys_segment_descriptor *sd, void *base, size_t limit,
-    int type, int dpl, int gran)
-{
-       memset(sd, 0, sizeof(*sd));
-       sd->sd_lolimit = (unsigned)limit;
-       sd->sd_lobase = (uint64_t)base;
-       sd->sd_type = type;
-       sd->sd_dpl = dpl;
-       sd->sd_p = 1;
-       sd->sd_hilimit = (unsigned)limit >> 16;
-       sd->sd_gran = gran;
-       sd->sd_hibase = (uint64_t)base >> 24;
-}
-
-static void
-set_sys_gdt(int slotoff, void *base, size_t limit, int type, int dpl, int gran)
-{
-       struct sys_segment_descriptor sd;
-       extern uint64_t *gdt64_start;
-
-       set_sys_segment(&sd, base, limit, type, dpl, gran);
-
-       memcpy(&gdt64_start + slotoff, &sd, sizeof(sd));
-}
-
-static void
-init_tss(void)
-{
-       memset(&prekern_tss, 0, sizeof(prekern_tss));
-       prekern_tss.tss_ist[0] = (uintptr_t)(&faultstack[PAGE_SIZE-1]) & ~0xf;
-
-       set_sys_gdt(PREKERN_GDT_TSS_OFF, &prekern_tss,
-           sizeof(struct x86_64_tss) - 1, SDT_SYS386TSS, SEL_KPL, 0);
-}
-
-static void
 init_idt(void)
 {
        struct region_descriptor region;
@@ -331,10 +281,9 @@
        mm_init(pa_start);
 
        /*
-        * Init the TSS and IDT. We mostly don't care about this, they are just
-        * here to properly handle traps.
+        * Init the IDT. We mostly don't care about this, it's just here
+        * to properly handle traps.
         */
-       init_tss();
        init_idt();
 
        print_state(true, "Prekern loaded");
diff -r b6ff8ebe5e52 -r e91ef1c9865e sys/arch/amd64/stand/prekern/trap.S
--- a/sys/arch/amd64/stand/prekern/trap.S       Tue Mar 19 16:56:29 2019 +0000
+++ b/sys/arch/amd64/stand/prekern/trap.S       Tue Mar 19 19:15:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.S,v 1.4 2018/07/14 14:29:40 maxv Exp $    */
+/*     $NetBSD: trap.S,v 1.5 2019/03/19 19:15:57 maxv Exp $    */
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -95,15 +95,15 @@
 IDTVEC_END(trap10)
 
 IDTVEC(trap11)
-       ZTRAPENTRY(T_SEGNPFLT)
+       TRAPENTRY(T_SEGNPFLT)
 IDTVEC_END(trap11)
 
 IDTVEC(trap12)
-       ZTRAPENTRY(T_STKFLT)
+       TRAPENTRY(T_STKFLT)
 IDTVEC_END(trap12)
 
 IDTVEC(trap13)
-       ZTRAPENTRY(T_PROTFLT)
+       TRAPENTRY(T_PROTFLT)
 IDTVEC_END(trap13)
 
 IDTVEC(trap14)



Home | Main Index | Thread Index | Old Index