From 5e1539077b37df24318edf5f501d22ddd51d6707 Mon Sep 17 00:00:00 2001 From: Antti Kantee Date: Thu, 30 Apr 2015 10:20:41 +0000 Subject: [PATCH] allow alternative console implementations, not just the vga console --- platform/baremetal/arch/i386/Makefile.inc | 1 + platform/baremetal/arch/i386/vgacons.c | 85 +++++++++++++++++++++++ platform/baremetal/kernel.c | 68 ------------------ 3 files changed, 86 insertions(+), 68 deletions(-) create mode 100644 platform/baremetal/arch/i386/vgacons.c diff --git a/platform/baremetal/arch/i386/Makefile.inc b/platform/baremetal/arch/i386/Makefile.inc index 7f44935..7b918c4 100644 --- a/platform/baremetal/arch/i386/Makefile.inc +++ b/platform/baremetal/arch/i386/Makefile.inc @@ -1,4 +1,5 @@ OBJS_BMK+= arch/i386/locore32.o arch/i386/machdep.o arch/i386/boot.o +OBJS_BMK+= arch/i386/vgacons.o LDSCRIPT= arch/i386/kern.ldscript CFLAGS+= -mno-sse -mno-mmx -march=i686 diff --git a/platform/baremetal/arch/i386/vgacons.c b/platform/baremetal/arch/i386/vgacons.c new file mode 100644 index 0000000..5020814 --- /dev/null +++ b/platform/baremetal/arch/i386/vgacons.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2014 Antti Kantee. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#define CONS_WIDTH 80 +#define CONS_HEIGHT 25 +#define CONS_MAGENTA 0x500 +static volatile uint16_t *cons_buf = (volatile uint16_t *)0xb8000; + +static void +cons_putat(int c, int x, int y) +{ + + cons_buf[x + y*CONS_WIDTH] = CONS_MAGENTA|c; +} + +/* display a character in the next available slot */ +void +bmk_cons_putc(int c) +{ + static int cons_x; + static int cons_y; + int x; + int doclear = 0; + + if (c == '\n') { + cons_x = 0; + cons_y++; + doclear = 1; + } else if (c == '\r') { + cons_x = 0; + } else if (c == '\t') { + cons_x = (cons_x+8) & ~7; + } else { + cons_putat(c, cons_x++, cons_y); + } + if (cons_x == CONS_WIDTH) { + cons_x = 0; + cons_y++; + doclear = 1; + } + if (cons_y == CONS_HEIGHT) { + cons_y--; + /* scroll screen up one line */ + for (x = 0; x < (CONS_HEIGHT-1)*CONS_WIDTH; x++) + cons_buf[x] = cons_buf[x+CONS_WIDTH]; + } + if (doclear) { + for (x = 0; x < CONS_WIDTH; x++) + cons_putat(' ', x, cons_y); + } +} + +void +bmk_init(void) +{ + int x; + + for (x = 0; x < CONS_HEIGHT * CONS_WIDTH; x++) + cons_putat(' ', x % CONS_WIDTH, x / CONS_WIDTH); +} diff --git a/platform/baremetal/kernel.c b/platform/baremetal/kernel.c index 301e75b..c1c6428 100644 --- a/platform/baremetal/kernel.c +++ b/platform/baremetal/kernel.c @@ -155,75 +155,7 @@ bmk_platform_splx(unsigned long x) return; /* XXX */ } - -/* - * console. quick, cheap, dirty, etc. - * Should eventually keep an in-memory log. printf-debugging is currently - * a bit, hmm, limited. - */ -#define CONS_WIDTH 80 -#define CONS_HEIGHT 25 -#define CONS_MAGENTA 0x500 -static volatile uint16_t *cons_buf = (volatile uint16_t *)0xb8000; - -static void -cons_putat(int c, int x, int y) -{ - - cons_buf[x + y*CONS_WIDTH] = CONS_MAGENTA|c; -} - -/* display a character in the next available slot */ -void -bmk_cons_putc(int c) -{ - static int cons_x; - static int cons_y; - int x; - int doclear = 0; - - if (c == '\n') { - cons_x = 0; - cons_y++; - doclear = 1; - } else if (c == '\r') { - cons_x = 0; - } else if (c == '\t') { - cons_x = (cons_x+8) & ~7; - } else { - cons_putat(c, cons_x++, cons_y); - } - if (cons_x == CONS_WIDTH) { - cons_x = 0; - cons_y++; - doclear = 1; - } - if (cons_y == CONS_HEIGHT) { - cons_y--; - /* scroll screen up one line */ - for (x = 0; x < (CONS_HEIGHT-1)*CONS_WIDTH; x++) - cons_buf[x] = cons_buf[x+CONS_WIDTH]; - } - if (doclear) { - for (x = 0; x < CONS_WIDTH; x++) - cons_putat(' ', x, cons_y); - } -} - -/* - * init. currently just clears the console. - * rest is done in bmk_main() - */ -void -bmk_init(void) -{ - int x; - - for (x = 0; x < CONS_HEIGHT * CONS_WIDTH; x++) - cons_putat(' ', x % CONS_WIDTH, x / CONS_WIDTH); -} - void bmk_run(char *cmdline) { -- 2.39.5