OBJS_BMK+= arch/amd64/machdep.o
OBJS_BMK+= arch/x86/boot.o
-OBJS_BMK+= arch/x86/vgacons.o
+OBJS_BMK+= arch/x86/cons.o arch/x86/vgacons.o arch/x86/serialcons.o
OBJS_BMK+= arch/x86/cpu_subr.o
OBJS_BMK+= arch/x86/x86_subr.o
OBJS_BMK+= arch/x86/clock.o
OBJS_BMK+= arch/i386/locore.o arch/i386/machdep.o
OBJS_BMK+= arch/x86/boot.o
-OBJS_BMK+= arch/x86/vgacons.o
+OBJS_BMK+= arch/x86/cons.o arch/x86/vgacons.o arch/x86/serialcons.o
OBJS_BMK+= arch/x86/cpu_subr.o
OBJS_BMK+= arch/x86/x86_subr.o
OBJS_BMK+= arch/x86/clock.o
x86_boot(struct multiboot_info *mbi)
{
- bmk_printf_init(cons_putc, NULL);
+ cons_init();
bmk_printf("rump kernel bare metal bootstrap\n\n");
cpu_init();
--- /dev/null
+/*-
+ * Copyright (c) 2015 Martin Lucina. 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 <hw/types.h>
+#include <hw/kernel.h>
+
+#include <arch/x86/cons.h>
+
+#include <bmk-core/printf.h>
+
+static void (*vcons_putc)(int) = vgacons_putc;
+static uint16_t *bios_com1_base = (uint16_t *)BIOS_COM1_BASE;
+static uint16_t *bios_crtc_base = (uint16_t *)BIOS_CRTC_BASE;
+
+void
+cons_init(void)
+{
+
+ /*
+ * If the BIOS says no CRTC is present and a serial port is present,
+ * use the serial console. Otherwise use the VGA console.
+ */
+ if (*bios_crtc_base == 0 && *bios_com1_base != 0) {
+ serialcons_init(*bios_com1_base, 115200);
+ vcons_putc = serialcons_putc;
+ }
+ bmk_printf_init(vcons_putc, NULL);
+}
+
+void
+cons_putc(int c)
+{
+
+ vcons_putc(c);
+}
+
+void
+cons_puts(const char *s)
+{
+ int c;
+
+ while ((c = *s++) != 0)
+ vcons_putc(c);
+}
--- /dev/null
+/*-
+ * Copyright (c) 2015 Martin Lucina. 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 <hw/types.h>
+#include <hw/kernel.h>
+
+#include <arch/x86/cons.h>
+
+static uint16_t combase = 0;
+
+void
+serialcons_init(uint16_t combase_init, int speed)
+{
+ uint16_t divisor = 115200 / speed;
+
+ combase = combase_init;
+ outb(combase + COM_IER, 0x00);
+ outb(combase + COM_LCTL, 0x80);
+ outb(combase + COM_DLBL, divisor & 0xff);
+ outb(combase + COM_DLBH, divisor >> 8);
+ outb(combase + COM_LCTL, 0x03);
+ outb(combase + COM_FIFO, 0xc7);
+}
+
+void
+serialcons_putc(int c)
+{
+
+ if (!combase)
+ return;
+
+ /*
+ * Write a single character at a time, while the output FIFO has space.
+ */
+ while ((inb(combase + COM_LSR) & 0x20) == 0)
+ ;
+ outb(combase + COM_DATA, c);
+}
#include <hw/types.h>
#include <hw/kernel.h>
+#include <arch/x86/cons.h>
+
#define CONS_MAGENTA 0x500
static volatile uint16_t *cons_buf = (volatile uint16_t *)CONS_ADDRESS;
/* display a character in the next available slot */
void
-cons_putc(int c)
+vgacons_putc(int c)
{
static int cons_x;
static int cons_y;
cons_putat(' ', x, cons_y);
}
}
-
-void
-cons_puts(const char *s)
-{
- int c;
-
- while ((c = *s++) != 0)
- cons_putc(c);
-}
--- /dev/null
+void serialcons_init(uint16_t, int);
+void serialcons_putc(int);
+void vgacons_putc(int);
+
#define CONS_WIDTH 80
#define CONS_HEIGHT 25
#define CONS_ADDRESS 0xb8000
+
+#define COM_DATA 0
+#define COM_DLBL 0
+#define COM_DLBH 1
+#define COM_IER 1
+#define COM_FIFO 2
+#define COM_LCTL 3
+#define COM_LSR 5
+
+#define BIOS_COM1_BASE 0x400
+#define BIOS_CRTC_BASE 0x463
struct multiboot_info;
void multiboot(struct multiboot_info *);
+void cons_init(void);
void cons_putc(int);
void cons_puts(const char *);