From owner-svn-src-head@freebsd.org Sun Sep 25 14:56:25 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 A5FC6BE9605; Sun, 25 Sep 2016 14:56:25 +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 7E5E798E; Sun, 25 Sep 2016 14:56:25 +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 u8PEuOD4067751; Sun, 25 Sep 2016 14:56:24 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8PEuO0S067749; Sun, 25 Sep 2016 14:56:24 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201609251456.u8PEuO0S067749@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Sun, 25 Sep 2016 14:56:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306310 - in head/sys: amd64/amd64 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.23 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, 25 Sep 2016 14:56:25 -0000 Author: bde Date: Sun Sep 25 14:56:24 2016 New Revision: 306310 URL: https://svnweb.freebsd.org/changeset/base/306310 Log: Fix vm86 initialization, part 3 of 2 and a half. (Actually, just fix early printfs and debugging of vm86 initialization and some other early initialization in some cases.) Add an option debug.late_console (with default 1=off) to move console and kdb initialization back where it was. Do the same for amd64 although there is no vm86 there. On my test system, debug.late_console=0 works for the syscons, sio and uart console drivers on amd64 and i386, and for vt on i386 but not on amd64. The early printfs fixed by debug.late_console=0 are: - on i386, the message about lost memory above 4G - with -v in otherwise normal use, about 20 printfs for SMAP - other debugging messages for memory sizing. Mostly under -v and not printed in normal use. Document in a comment how much earlier the initialization and early printf()s can be. That is very early for the console. Not much more than curthread is needed. kdb use obviously needs to be not so early, since it needs IDT initialization and that is done relatively late for convenience and historical reasons. Modified: head/sys/amd64/amd64/machdep.c head/sys/i386/i386/machdep.c Modified: head/sys/amd64/amd64/machdep.c ============================================================================== --- head/sys/amd64/amd64/machdep.c Sun Sep 25 13:52:55 2016 (r306309) +++ head/sys/amd64/amd64/machdep.c Sun Sep 25 14:56:24 2016 (r306310) @@ -1506,6 +1506,16 @@ native_parse_preload_data(u_int64_t modu return (kmdp); } +static void +amd64_kdb_init(void) +{ + kdb_init(); +#ifdef KDB + if (boothowto & RB_KDB) + kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); +#endif +} + u_int64_t hammer_time(u_int64_t modulep, u_int64_t physfree) { @@ -1517,6 +1527,7 @@ hammer_time(u_int64_t modulep, u_int64_t u_int64_t msr; char *env; size_t kstack0_sz; + int late_console; /* * This may be done better later if it gets more high level @@ -1561,6 +1572,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree += DPCPU_SIZE; PCPU_SET(prvspace, pc); PCPU_SET(curthread, &thread0); + /* Non-late cninit() and printf() can be moved up to here. */ PCPU_SET(tssp, &common_tss[0]); PCPU_SET(commontssp, &common_tss[0]); PCPU_SET(tss, (struct system_segment_descriptor *)&gdt[GPROC0_SEL]); @@ -1660,12 +1672,26 @@ hammer_time(u_int64_t modulep, u_int64_t wrmsr(MSR_STAR, msr); wrmsr(MSR_SF_MASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D); + /* + * The console and kdb should be initialized even earlier than here, + * but some console drivers don't work until after getmemsize(). + * Default to late console initialization to support these drivers. + * This loses mainly printf()s in getmemsize() and early debugging. + */ + late_console = 1; + TUNABLE_INT_FETCH("debug.late_console", &late_console); + if (!late_console) { + cninit(); + amd64_kdb_init(); + } + getmemsize(kmdp, physfree); init_param2(physmem); /* now running on new page tables, configured,and u/iom is accessible */ - cninit(); + if (late_console) + cninit(); #ifdef DEV_ISA #ifdef DEV_ATPIC @@ -1686,13 +1712,8 @@ hammer_time(u_int64_t modulep, u_int64_t #error "have you forgotten the isa device?"; #endif - kdb_init(); - -#ifdef KDB - if (boothowto & RB_KDB) - kdb_enter(KDB_WHY_BOOTFLAGS, - "Boot flags requested debugger"); -#endif + if (late_console) + amd64_kdb_init(); msgbufinit(msgbufp, msgbufsize); fpuinit(); Modified: head/sys/i386/i386/machdep.c ============================================================================== --- head/sys/i386/i386/machdep.c Sun Sep 25 13:52:55 2016 (r306309) +++ head/sys/i386/i386/machdep.c Sun Sep 25 14:56:24 2016 (r306310) @@ -2089,7 +2089,6 @@ getmemsize(int first) * use that and do not make any VM86 calls. */ physmap_idx = 0; - smapbase = NULL; kmdp = preload_search_by_type("elf kernel"); if (kmdp == NULL) kmdp = preload_search_by_type("elf32 kernel"); @@ -2223,6 +2222,9 @@ physmap_done: * highest page of the physical address space. It should be * called something like "Maxphyspage". We may adjust this * based on ``hw.physmem'' and the results of the memory test. + * + * This is especially confusing when it is much larger than the + * memory size and is displayed as "realmem". */ Maxmem = atop(physmap[physmap_idx + 1]); @@ -2428,6 +2430,19 @@ do_next: } #endif /* PC98 */ +static void +i386_kdb_init(void) +{ +#ifdef DDB + db_fetch_ksymtab(bootinfo.bi_symtab, bootinfo.bi_esymtab); +#endif + kdb_init(); +#ifdef KDB + if (boothowto & RB_KDB) + kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); +#endif +} + register_t init386(first) int first; @@ -2438,6 +2453,7 @@ init386(first) #ifdef CPU_ENABLE_SSE struct xstate_hdr *xhdr; #endif + int late_console; thread0.td_kstack = proc0kstack; thread0.td_kstack_pages = TD0_KSTACK_PAGES; @@ -2502,6 +2518,7 @@ init386(first) first += DPCPU_SIZE; PCPU_SET(prvspace, pc); PCPU_SET(curthread, &thread0); + /* Non-late cninit() and printf() can be moved up to here. */ /* * Initialize mutexes. @@ -2668,30 +2685,33 @@ init386(first) #endif #endif + /* + * The console and kdb should be initialized even earlier than here, + * but some console drivers don't work until after getmemsize(). + * Default to late console initialization to support these drivers. + * This loses mainly printf()s in getmemsize() and early debugging. + */ + late_console = 1; + TUNABLE_INT_FETCH("debug.late_console", &late_console); + if (!late_console) { + cninit(); + i386_kdb_init(); + } + vm86_initialize(); getmemsize(first); init_param2(physmem); /* now running on new page tables, configured,and u/iom is accessible */ - /* - * Initialize the console before we print anything out. - */ - cninit(); + if (late_console) + cninit(); if (metadata_missing) printf("WARNING: loader(8) metadata is missing!\n"); -#ifdef DDB - db_fetch_ksymtab(bootinfo.bi_symtab, bootinfo.bi_esymtab); -#endif - - kdb_init(); - -#ifdef KDB - if (boothowto & RB_KDB) - kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); -#endif + if (late_console) + i386_kdb_init(); msgbufinit(msgbufp, msgbufsize); #ifdef DEV_NPX