From owner-svn-src-head@freebsd.org Sun Aug 28 14:03:26 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9F3D6B778A6; Sun, 28 Aug 2016 14:03:26 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5E239213; Sun, 28 Aug 2016 14:03:26 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7SE3PQ2003758; Sun, 28 Aug 2016 14:03:25 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7SE3POl003757; Sun, 28 Aug 2016 14:03:25 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201608281403.u7SE3POl003757@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Sun, 28 Aug 2016 14:03:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304957 - head/sys/i386/i386 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Aug 2016 14:03:26 -0000 Author: bde Date: Sun Aug 28 14:03:25 2016 New Revision: 304957 URL: https://svnweb.freebsd.org/changeset/base/304957 Log: Fix vm86 initialization, part 1 of 2 and a half. vm86 uses the tss, but r273995 moved tss initialization to after where it may be first used, just because tss_esp0 now depends on later initializations and/or amd64 does it later. vm86 is first used for memory sizing in cases where the loader can't figure out the size or is not used. Its initialization is placed immediately before memory sizing to support this, and the tss was initialized a little earlier. Move everything in the tss initialization except for tss_esp0 back to almost where it was, immediately before vm86 initialization (the combined move is from before dblflt_tss initialization to after). Add only early initialization of tss_esp0, later reloading of the tss, and comments. The initial tss_esp0 no longer has space for the pcb since initially the size of the pcb is not known and no pcb is needed. (Later changes broke debugging at this point, so the nonexistent pcb cannot be used by debuggers, and at the time of 273995 when ddb was almost able to debug this problem it didn't need the pcb.) The iniitial tss_esp0 still has a magic 16 bytes reserved for vm86 although I think this is unused too. Modified: head/sys/i386/i386/machdep.c Modified: head/sys/i386/i386/machdep.c ============================================================================== --- head/sys/i386/i386/machdep.c Sun Aug 28 12:05:34 2016 (r304956) +++ head/sys/i386/i386/machdep.c Sun Aug 28 14:03:25 2016 (r304957) @@ -2636,6 +2636,16 @@ init386(first) dblfault_tss.tss_cs = GSEL(GCODE_SEL, SEL_KPL); dblfault_tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL); + /* Initialize the tss (except for the final esp0) early for vm86. */ + PCPU_SET(common_tss.tss_esp0, thread0.td_kstack + + thread0.td_kstack_pages * PAGE_SIZE - 16); + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); + PCPU_SET(tss_gdt, &gdt[GPROC0_SEL].sd); + PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); + PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); + ltr(gsel_tss); + vm86_initialize(); getmemsize(first); init_param2(physmem); @@ -2701,14 +2711,10 @@ init386(first) } #endif PCPU_SET(curpcb, thread0.td_pcb); - /* make an initial tss so cpu can get interrupt stack on syscall! */ + /* Move esp0 in the tss to its final place. */ /* Note: -16 is so we can grow the trapframe if we came from vm86 */ PCPU_SET(common_tss.tss_esp0, (vm_offset_t)thread0.td_pcb - 16); - PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); - gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); - PCPU_SET(tss_gdt, &gdt[GPROC0_SEL].sd); - PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); - PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); + gdt[GPROC0_SEL].sd.sd_type = SDT_SYS386TSS; /* clear busy bit */ ltr(gsel_tss); /* make a call gate to reenter kernel with */