From owner-svn-src-projects@FreeBSD.ORG Sun May 4 10:54:59 2014 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4664A98E; Sun, 4 May 2014 10:54:59 +0000 (UTC) Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by mx1.freebsd.org (Postfix) with ESMTP id B16581885; Sun, 4 May 2014 10:54:58 +0000 (UTC) Received: from c122-106-147-133.carlnfd1.nsw.optusnet.com.au (c122-106-147-133.carlnfd1.nsw.optusnet.com.au [122.106.147.133]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 53A2C420E8C; Sun, 4 May 2014 20:54:50 +1000 (EST) Date: Sun, 4 May 2014 20:54:49 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Andrew Turner Subject: Re: svn commit: r265268 - projects/arm64/sys/arm64/arm64 In-Reply-To: <20140504105608.70a60909@bender.Home> Message-ID: <20140504202222.H1763@besplex.bde.org> References: <201405031527.s43FRUTg019278@svn.freebsd.org> <20140504182755.K1388@besplex.bde.org> <20140504105608.70a60909@bender.Home> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=U6SrU4bu c=1 sm=1 tr=0 a=7NqvjVvQucbO2RlWB8PEog==:117 a=PO7r1zJSAAAA:8 a=IFCUVFEhucQA:10 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=8gIP7tmpFHogKcjyKYcA:9 a=CjuIK1q_8ugA:10 Cc: svn-src-projects@freebsd.org, src-committers@freebsd.org, Bruce Evans X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 May 2014 10:54:59 -0000 On Sun, 4 May 2014, Andrew Turner wrote: > On Sun, 4 May 2014 19:25:06 +1000 (EST) > Bruce Evans wrote: > >> On Sat, 3 May 2014, Andrew Turner wrote: >> >>> Log: >>> Replace panic with printf in spinlock_{enter,exit} as panic makes >>> use of spinlocks. >> >> printf has been broken to use spinlocks too. It used to be careful to >> use atomic operations to avoid locking. Most console drivers are >> broken too. Some serial ones avoid locking in debugger mode only. > > This is a stub function. I need to implement it, however I'm working on > other parts of the early code and would prefer it if panic at least > told me what called it even if it is broken. > > I'm not yet using a console driver and instead using EARLY_PRINTF with > a function that relies on the early boot code mapping the UART with an > identity map. This contains no locking and will produce incorrect > output when too many characters are sent to it, however as this code is > only run on a hardware simulator that appears to output data with no > latency this has not been a problem. In 386BSD, I used a combination of my debugger and "LED"s faked on the vga frame buffer and never bothered to make printf work very early (my debugger has its own vga and serial output routines, so it is independent of the kernel i/o, but this depends on the vga mode being text and not changing too much). Here is my vga splatting code for syscons. This is very suitable for EARLY_PRINTF too if you have a vga (or just a text-mode frame buffer). It has full (atomic) locking but no formatting (not even linefeeds) to keep it simple. It is not quite as simple as for a simple uart. Pixel mode would be harder. Setting up fonts for text mode would be hard if the early boot (BIOS) code didn't do it. USB uarts would be much harder. And we really should have ethernet consoles by now. syscons.c.dif: @ ... @ *************** @ *** 246,249 **** @ --- 251,315 ---- @ }; @ @ + static char bde_putc_log[0x40000]; @ + static int bde_putc_logindex; @ + static int bde_putc_scrindex; @ + @ + static void @ + bde_putc(int c) @ + { @ + static u_short attrs[2] = { FG_YELLOW << 8, FG_LIGHTRED << 8 }; Color coding for 2 CPUs. Could use more colors/attributes for more CPUs. The output may be interleaved, and then it is difficult to read even with this color coding. Nice patterns though. EARLY_PRINTF probably doesn't need this. @ + static u_short * const scrptr = (short *)0xc00b8000; We need to know the frame buffer address and not much else. @ + int attr, ind; @ + @ + attr = attrs[PCPU_GET(cpuid) % 2]; @ + do @ + ind = bde_putc_scrindex; @ + while (atomic_cmpset_rel_int(&bde_putc_scrindex, ind, ind + 1) == 0); @ + scrptr[5 * 80 + (ind % (15 * 80))] = attr | (c & 0xff); Partially formatted for 80x25. 80 is the width, and 5 and 15 are to keep it far away from the top and bottom edges (to reduces problems from scrolling for normal output). @ + bde_putc_log[ind % sizeof(bde_putc_log)] = c; @ + } @ + @ + static void @ + bde_puts(const char *s) @ + { @ + while (*s != '\0') @ + bde_putc(*s++); @ + } @ + @ + static void @ + bde_wait(void) @ + { @ + int timeout; @ + @ + if (bde_kill_bde_wait) @ + return; @ + if (!bde_wait_verbose) { @ + DELAY(bde_wait_delay); @ + return; @ + } @ + bde_puts("hit any key to abort wait of 300 seconds..."); Callers should use this function to wait occasonally so that the special output doesn't overwrite itself or get overwritten with normal output by the screen refresh. @ + timeout = 300 * 1000; @ + do { @ + if (cncheckc() != -1) @ + break; @ + DELAY(1000); @ + } while (--timeout != 0); @ + bde_puts("done"); @ + } @ + @ + void bde_printf_emerg(const char *fmt, ...); @ + void @ + bde_printf_emerg(const char *fmt, ...) @ + { @ + va_list ap; @ + char buf[256]; @ + @ + va_start(ap, fmt); @ + vsnprintf(buf, sizeof(buf) - 3, fmt, ap); @ + // strcat(buf, "!E!"); @ + bde_puts(buf); @ + // bde_wait(); @ + } @ + @ int @ sc_probe_unit(int unit, int flags) Bruce