Module Name:    src
Committed By:   maxv
Date:           Tue Mar 19 19:15:57 UTC 2019

Modified Files:
        src/sys/arch/amd64/stand/prekern: locore.S prekern.c trap.S

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/stand/prekern/locore.S \
    src/sys/arch/amd64/stand/prekern/prekern.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/stand/prekern/trap.S

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/stand/prekern/locore.S
diff -u src/sys/arch/amd64/stand/prekern/locore.S:1.10 src/sys/arch/amd64/stand/prekern/locore.S:1.11
--- src/sys/arch/amd64/stand/prekern/locore.S:1.10	Sat Mar  9 08:42:25 2019
+++ src/sys/arch/amd64/stand/prekern/locore.S	Tue Mar 19 19:15:57 2019
@@ -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 @@ LABEL(gdt64_start)
 	.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 @@ longmode:
 	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
 
Index: src/sys/arch/amd64/stand/prekern/prekern.c
diff -u src/sys/arch/amd64/stand/prekern/prekern.c:1.10 src/sys/arch/amd64/stand/prekern/prekern.c:1.11
--- src/sys/arch/amd64/stand/prekern/prekern.c:1.10	Sun Aug 12 12:42:54 2018
+++ src/sys/arch/amd64/stand/prekern/prekern.c	Tue Mar 19 19:15:57 2019
@@ -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 @@ struct bootinfo bootinfo;
 
 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 @@ struct smallframe {
 	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 @@ trap(struct smallframe *sf)
 	while (1);
 }
 
+/* -------------------------------------------------------------------------- */
+
 static void
 setregion(struct region_descriptor *rd, void *base, uint16_t limit)
 {
@@ -167,42 +153,6 @@ setgate(struct gate_descriptor *gd, void
 }
 
 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 @@ init_prekern(paddr_t pa_start)
 	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");

Index: src/sys/arch/amd64/stand/prekern/trap.S
diff -u src/sys/arch/amd64/stand/prekern/trap.S:1.4 src/sys/arch/amd64/stand/prekern/trap.S:1.5
--- src/sys/arch/amd64/stand/prekern/trap.S:1.4	Sat Jul 14 14:29:40 2018
+++ src/sys/arch/amd64/stand/prekern/trap.S	Tue Mar 19 19:15:57 2019
@@ -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(trap10)
 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)

Reply via email to