From 15f38a96d7d693f2d2c2ebe736bfa90606d96fc3 Mon Sep 17 00:00:00 2001 From: Thomas Graichen Date: Fri, 22 Nov 1996 11:11:34 +0000 Subject: fix booting with serial console - i replaced the bios code from OpenBSD with FreeBSD's polling code so that it works with all serial terminals - if you now remove the comment in front of #CPPFLAGS+=-DSERIAL -D... - the bootprompt should appear on the serial console note: i had to rename "geometry" in one printf of sys.c to "geom." to get the bootblocks small enough for serial console booting --- sys/arch/i386/boot/Makefile | 5 +- sys/arch/i386/boot/bios.S | 46 +--------- sys/arch/i386/boot/boot.c | 5 +- sys/arch/i386/boot/serial.S | 207 ++++++++++++++++++++++++++++++++++++++++++++ sys/arch/i386/boot/sys.c | 2 +- 5 files changed, 219 insertions(+), 46 deletions(-) create mode 100644 sys/arch/i386/boot/serial.S (limited to 'sys') diff --git a/sys/arch/i386/boot/Makefile b/sys/arch/i386/boot/Makefile index e272ec29953..7e10e288ade 100644 --- a/sys/arch/i386/boot/Makefile +++ b/sys/arch/i386/boot/Makefile @@ -41,10 +41,11 @@ CFLAGS= -O6 -D_KERNEL -DI386_CPU -DI486_CPU -DI586_CPU CFLAGS+=-DDO_BAD144 -I. -I${.CURDIR} -I$S -I${.CURDIR}/../.. # Uncomment this to make the boot block talk to a serial port. -#CPPFLAGS+=-DSERIAL +#CPPFLAGS+=-DSERIAL -DCOMCONSOLE=0x3F8 -DCONSPEED=9600 # start.o should be first -OBJS= start.o table.o boot.o asm.o bios.o io.o disk.o sys.o version.o +OBJS= start.o table.o boot.o asm.o bios.o io.o disk.o sys.o version.o \ + serial.o boot: ${OBJS} ${LD} -Bstatic -e start -N -T 0 -o boot ${OBJS} diff --git a/sys/arch/i386/boot/bios.S b/sys/arch/i386/boot/bios.S index b6f79b5e5eb..fc2bc99fd4a 100644 --- a/sys/arch/i386/boot/bios.S +++ b/sys/arch/i386/boot/bios.S @@ -213,19 +213,14 @@ ok3: popl %ebp ret #endif -/* + #ifndef SERIAL +/* # BIOS call "INT 10H Function 0Eh" to write character to console # Call with %ah = 0x0e # %al = character # %bh = page # %bl = foreground color -#else -# BIOS call "INT 14H Function 01h" to write character to console -# Call with %ah = 0x01 -# %al = character -# %dx = port number -#endif */ ENTRY(putc) pushl %ebp @@ -240,16 +235,10 @@ ENTRY(putc) movb %cl, %al -#ifndef SERIAL movb $0x0e, %ah data32 movl $0x0001, %ebx int $0x10 # display a byte -#else - movb $0x01, %ah - xorl %edx, %edx - int $0x14 # display a byte -#endif data32 call _C_LABEL(real_to_prot) @@ -262,18 +251,10 @@ ENTRY(putc) /* -#ifndef SERIAL # BIOS call "INT 16H Function 00H" to read character from the keyboard # Call with %ah = 0x00 # Return: %ah = keyboard scan code # %al = ASCII character -#else -# BIOS call "INT 14H Function 02H" to read character from the serial port -# Call with %ah = 0x02 -# %dx = port number -# Return: %ah = line status -# %al = ASCII character -#endif */ ENTRY(getc) pushl %ebp @@ -284,14 +265,8 @@ ENTRY(getc) call _C_LABEL(prot_to_real) -#ifndef SERIAL movb $0x00, %ah int $0x16 -#else - movb $0x02, %ah - xorl %edx, %edx - int $0x14 -#endif movb %al, %bl # real_to_prot uses %eax @@ -309,7 +284,6 @@ ENTRY(getc) /* -#ifndef SERIAL # BIOS call "INT 16H Function 01H" to check whether a character is pending # Call with %ah = 0x01 # Return: @@ -319,13 +293,6 @@ ENTRY(getc) # ZF = clear # else # ZF = set -#else -# BIOS call "INT 14H Function 03H" to check whether a character is pending -# Call with %ah = 0x03 -# %dx = port number -# Return: %ah = line status -# %al = modem status -#endif */ ENTRY(ischar) pushl %ebp @@ -336,16 +303,9 @@ ENTRY(ischar) call _C_LABEL(prot_to_real) -#ifndef SERIAL movb $0x01, %ah int $0x16 setnz %ah -#else - movb $0x03, %ah - xorl %edx, %edx - int $0x14 - andb $0x1f, %ah -#endif movb %ah, %bl # real_to_prot uses %eax @@ -361,6 +321,8 @@ ENTRY(ischar) popl %ebp ret +#endif /* #ifndef SERIAL */ + /* # # get_diskinfo(): return a word that represents the diff --git a/sys/arch/i386/boot/boot.c b/sys/arch/i386/boot/boot.c index 648535dfa41..ecb5dda2d78 100644 --- a/sys/arch/i386/boot/boot.c +++ b/sys/arch/i386/boot/boot.c @@ -82,7 +82,10 @@ boot(drive) { int loadflags, currname = 0; char *t; - + +#ifdef SERIAL + init_serial(); +#endif printf("\n" ">> OpenBSD BOOT: %d/%d k [%s]\n" "use ? for file list, or carriage return for defaults\n" diff --git a/sys/arch/i386/boot/serial.S b/sys/arch/i386/boot/serial.S new file mode 100644 index 00000000000..2fe4a1b3022 --- /dev/null +++ b/sys/arch/i386/boot/serial.S @@ -0,0 +1,207 @@ +/* + * Mach Operating System + * Copyright (c) 1992, 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * from: Mach, Revision 2.2 92/04/04 11:34:26 rpd + * $Id: serial.S,v 1.1 1996/11/22 11:11:32 graichen Exp $ + */ + +/* + Copyright 1988, 1989, 1990, 1991, 1992 + by Intel Corporation, Santa Clara, California. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appears in all +copies and that both the copyright notice and this permission notice +appear in supporting documentation, and that the name of Intel +not be used in advertising or publicity pertaining to distribution +of the software without specific, written prior permission. + +INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, +NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/* + * Serial bootblock interface routines + * Copyright (c) 1994, J"org Wunsch + * + * Adaption to OpenBSD - Thomas Graichen + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * THE AUTHOR ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. THE AUTHOR DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + */ + +#ifdef SERIAL + + .file "serial.s" + +#include +#include "../../../dev/isa/comreg.h" +#define COMBRD(x) (1843200 / (16*(x))) + .text + +/* + * The serial port interface routines implement a simple polled i/o + * interface to a standard serial port. Due to the space restrictions + * for the boot blocks, no BIOS support is used (since BIOS requires + * expensive real/protected mode switches), instead the rudimentary + * BIOS support is duplicated here. + * + * The base address for the i/o port is passed from the Makefile in + * the COMCONSOLE preprocessor macro. Console parameters are currently + * hard-coded to CONSPEED (9600) Bd, 8 bit. This can be changed in the + * init_serial() function. + */ + +/* + * void putc(ch) char ch; + * send ch to serial port + * + */ + +ENTRY(putc) + push %ebp + mov %esp, %ebp + push %edx + + mov $COMCONSOLE + 5, %edx # line status reg +1: inb %dx, %al + test $0x20, %al + jz 1b # TX buffer not empty + + movb 0x8(%ebp), %al + + sub $5, %edx # TX output reg + outb %al, %dx # send this one + + pop %edx + pop %ebp + ret + +/* + * int getc(void) + * read a character from serial port + */ + +ENTRY(getc) + push %ebp + mov %esp, %ebp + push %edx + + mov $COMCONSOLE + 5, %edx # line status reg +1: + inb %dx, %al + testb $0x01, %al + jz 1b # no RX char available + + xor %eax, %eax + sub $5, %edx # RX buffer reg + inb %dx, %al # fetch (first) character + + and $0x7F, %eax # remove any parity bits we get + cmp $0x7F, %eax # make DEL... + jne 2f + mov $0x08, %eax # look like BS +2: + pop %edx + pop %ebp + ret + +/* + * int ischar(void) + * if there is a character pending, return true; otherwise return 0 + */ +ENTRY(ischar) + push %ebp + mov %esp, %ebp + push %edx + + xorl %eax, %eax + mov $COMCONSOLE + 5, %edx # line status reg + inb %dx, %al + andb $0x01, %al # RX char available? + + pop %edx + pop %ebp + ret + +/* + * void init_serial(void) + * initialize the serial console port to 9600 Bd, 8 bpc + */ +ENTRY(init_serial) + push %ebp + mov %esp, %ebp + push %edx + + mov $COMCONSOLE + 3, %edx # line control reg + movb $0x80, %al + outb %al, %dx # enable DLAB + + sub $3, %edx # divisor latch, low byte + mov $COMBRD(CONSPEED), %ax # 9600 Bd by default + outb %al, %dx + inc %edx # divisor latch, high byte + movb %ah, %al + outb %al, %dx + + add $2, %edx # line control reg + movb $0x13, %al + outb %al, %dx # 8 bit, no parity, 1 stop bit + + inc %edx # modem control reg + mov $3, %al + outb %al, %dx # enable DTR/RTS + + /* now finally, flush the input buffer */ + inc %edx # line status reg +1: + inb %dx, %al + testb $0x01, %al + jz 2f # no more characters buffered + sub $5, %edx # rx buffer reg + inb %dx, %al # throw away + add $5, %edx + jmp 1b +2: + pop %edx + pop %ebp + ret + +#endif /* #ifdef SERIAL */ diff --git a/sys/arch/i386/boot/sys.c b/sys/arch/i386/boot/sys.c index 811031ca80d..bd22e78f755 100644 --- a/sys/arch/i386/boot/sys.c +++ b/sys/arch/i386/boot/sys.c @@ -152,7 +152,7 @@ loop: } dp = (struct dirent *)(iodest + off); if (dp->d_reclen < 8) { - printf("dir corrupt (geometry mismatch?)\n"); + printf("dir corrupt (geom. mismatch?)\n"); return 0; } loc += dp->d_reclen; -- cgit v1.2.3