Make this compile again under -current. The modifications to io.c

and bios.S were small enough and have been merged back into their
respective files in biosboot/, conditionalized on CDBOOT.  Other
files might be merged at a later stage.

Caveat emptor: i cannot test this right now.
This commit is contained in:
Joerg Wunsch 1997-07-12 10:23:31 +00:00
parent 3afd214946
commit f88ef34060
6 changed files with 168 additions and 708 deletions

View File

@ -24,7 +24,7 @@
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.2 92/04/04 11:34:26 rpd
* $Id: bios.S,v 1.9 1997/02/22 09:30:05 peter Exp $
* $Id: bios.S,v 1.10 1997/05/16 10:39:59 bde Exp $
*/
/*
@ -50,11 +50,46 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Extensions for El Torito CD-ROM booting:
*
* Copyright © 1997 Pluto Technologies International, Inc. Boulder CO
* Copyright © 1997 interface business GmbH, Dresden.
* All rights reserved.
*
* This code has been written by Jörg Wunsch, Dresden.
* Direct comments to <joerg_wunsch@interface-business.de>.
*
* 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(S) ``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(S) 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.
*
*/
.file "bios.s"
#include "asm.h"
.text
#ifndef CDBOOT
/*
* biosread(dev, cyl, head, sec, nsec, offset)
* Read "nsec" sectors from disk to offset "offset" in boot segment
@ -115,6 +150,97 @@ ENTRY(biosread)
ret
#else /* CDBOOT */
/*
* int
* getbootspec(struct specpacket *offset)
*
* Read CD-ROM boot specification packet to "offset".
*/
ENTRY(getbootspec)
push %ebp
mov %esp, %ebp
push %esi
push %ebx
movw 0x8(%ebp), %si
mov $0x7f, %edx
/* prot_to_real will set %es to BOOTSEG */
call EXT(prot_to_real) /* enter real mode */
movw $0x4b01, %ax /* (do not) terminate disk emulation */
movb $0x7f, %dl /* any drive */
sti
int $0x13
cli
/* save return value (actually movw %ax, %bx) */
mov %eax, %ebx
data32
call EXT(real_to_prot) /* back to protected mode */
xor %eax, %eax
movb %bh, %al /* return value in %ax */
pop %ebx
pop %esi
pop %ebp
ret
/*
* int
* biosreadlba(struct daddrpacket *daddr)
* Read sectors using the BIOS "read extended" function
* BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
* Call with %ah = 0x42
* %dl = drive (0x0 for floppy disk, or emulated CD)
* %ds:%si = ptr to disk address packet
* Return:
* %ah = 0x0 on success; err code on failure
*/
ENTRY(biosreadlba)
push %ebp
mov %esp, %ebp
push %ebx
push %esi
movw 8(%ebp), %si
movl $0, %edx /* emulated CD is always drive 0 */
/* prot_to_real will set %es to BOOTSEG */
call EXT(prot_to_real) /* enter real mode */
movw $0x4200, %ax /* subfunction */
movb $0, %dl
sti
int $0x13
cli
/* save return value (actually movw %ax, %bx) */
mov %eax, %ebx
data32
call EXT(real_to_prot) /* back to protected mode */
xor %eax, %eax
movb %bh, %al /* return value in %ax */
pop %esi
pop %ebx
pop %ebp
ret
#endif /* !CDBOOT */
/*
* putc(ch)

View File

@ -24,7 +24,7 @@
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.2 92/04/04 11:35:03 rpd
* $Id: boot.h,v 1.18 1997/05/27 16:26:39 bde Exp $
* $Id: boot.h,v 1.19 1997/06/09 05:10:55 bde Exp $
*/
#include <sys/param.h>
@ -81,8 +81,12 @@ void printf(const char *format, ...);
void putchar(int c);
void delay1ms(void);
int gets(char *buf);
#ifndef CDBOOT
int strcmp(const char *s1, const char *s2);
void bcopy(const char *from, char *to, int len);
#else /* CDBOOT */
int strncasecmp(const char *s1, const char *s2, size_t s);
#endif /* !CDBOOT */
void bcopy(const void *from, void *to, size_t len);
void twiddle(void);
/* probe_keyboard.c */

View File

@ -24,7 +24,7 @@
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.2 92/04/04 11:35:57 rpd
* $Id: io.c,v 1.22 1997/05/27 16:26:39 bde Exp $
* $Id: io.c,v 1.23 1997/06/09 05:10:55 bde Exp $
*/
#include "boot.h"
@ -56,7 +56,7 @@ gateA20(void)
{
#ifdef IBM_L40
outb(0x92, 0x2);
#else IBM_L40
#else /* !IBM_L40 */
while (inb(K_STATUS) & K_IBUF_FUL);
while (inb(K_STATUS) & K_OBUF_FUL)
(void)inb(K_RDWR);
@ -65,7 +65,7 @@ gateA20(void)
while (inb(K_STATUS) & K_IBUF_FUL);
outb(K_RDWR, KB_A20);
while (inb(K_STATUS) & K_IBUF_FUL);
#endif IBM_L40
#endif /* IBM_L40 */
}
/* printf - only handles %d as decimal, %c as char, %s as string */
@ -258,6 +258,8 @@ gets(char *buf)
return 0;
}
#ifndef CDBOOT
int
strcmp(const char *s1, const char *s2)
{
@ -269,11 +271,36 @@ strcmp(const char *s1, const char *s2)
return 1;
}
void
bcopy(const char *from, char *to, int len)
#else /* CDBOOT */
int
strncasecmp(const char *s1, const char *s2, size_t s)
{
/*
* We only consider ASCII chars and don't anticipate
* control characters (they are invalid in filenames
* anyway).
*/
while (s > 0 && (*s1 & 0x5f) == (*s2 & 0x5f)) {
if (!*s1++)
return 0;
s2++;
}
if (s == 0)
return 0;
return 1;
}
#endif /* !CDBOOT */
void
bcopy(const void *from, void *to, size_t len)
{
char *fp = (char *)from;
char *tp = (char *)to;
while (len-- > 0)
*to++ = *from++;
*tp++ = *fp++;
}
/* To quote Ken: "You are not expected to understand this." :) */

View File

@ -1,4 +1,4 @@
# $Id$
# $Id: Makefile,v 1.1 1997/07/11 05:52:34 joerg Exp $
#
PROG= boot
@ -15,6 +15,7 @@ CFLAGS= -O2 -malign-functions=0 -malign-jumps=0 -malign-loops=0 \
-DDO_BAD144 -DBOOTWAIT=${BOOTWAIT} -DTIMEOUT=${TIMEOUT}
CFLAGS+= -DBOOTSEG=${BOOTSEG} -DBOOTSTACK=${BOOTSTACK}
CFLAGS+= -I${.CURDIR}/../../.. -I${.CURDIR}/../biosboot
CFLAGS+= -DCDBOOT
CFLAGS+= ${CWARNFLAGS}
#CFLAGS+= -DDEBUG

View File

@ -1,411 +0,0 @@
/*
* 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$
*/
/*
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.
*/
/*
* Extensions for El Torito CD-ROM booting:
*
* Copyright © 1997 Pluto Technologies International, Inc. Boulder CO
* Copyright © 1997 interface business GmbH, Dresden.
* All rights reserved.
*
* This code has been written by Jörg Wunsch, Dresden.
* Direct comments to <joerg_wunsch@interface-business.de>.
*
* 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(S) ``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(S) 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.
*
*/
.file "bios.s"
#include "asm.h"
.text
/*
* int
* getbootspec(struct specpacket *offset)
*
* Read CD-ROM boot specification packet to "offset".
*/
ENTRY(getbootspec)
push %ebp
mov %esp, %ebp
push %esi
push %ebx
movw 0x8(%ebp), %si
mov $0x7f, %edx
/* prot_to_real will set %es to BOOTSEG */
call EXT(prot_to_real) /* enter real mode */
movw $0x4b01, %ax /* (do not) terminate disk emulation */
movb $0x7f, %dl /* any drive */
sti
int $0x13
cli
/* save return value (actually movw %ax, %bx) */
mov %eax, %ebx
data32
call EXT(real_to_prot) /* back to protected mode */
xor %eax, %eax
movb %bh, %al /* return value in %ax */
pop %ebx
pop %esi
pop %ebp
ret
/*
* int
* biosreadlba(struct daddrpacket *daddr)
* Read sectors using the BIOS "read extended" function
* BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
* Call with %ah = 0x42
* %dl = drive (0x0 for floppy disk, or emulated CD)
* %ds:%si = ptr to disk address packet
* Return:
* %ah = 0x0 on success; err code on failure
*/
ENTRY(biosreadlba)
push %ebp
mov %esp, %ebp
push %ebx
push %esi
movw 8(%ebp), %si
movl $0, %edx /* emulated CD is always drive 0 */
/* prot_to_real will set %es to BOOTSEG */
call EXT(prot_to_real) /* enter real mode */
movw $0x4200, %ax /* subfunction */
movb $0, %dl
sti
int $0x13
cli
/* save return value (actually movw %ax, %bx) */
mov %eax, %ebx
data32
call EXT(real_to_prot) /* back to protected mode */
xor %eax, %eax
movb %bh, %al /* return value in %ax */
pop %esi
pop %ebx
pop %ebp
ret
/*
* putc(ch)
* BIOS call "INT 10H Function 0Eh" to write character to console
* Call with %ah = 0x0e
* %al = character
* %bh = page
* %bl = foreground color ( graphics modes)
*/
ENTRY(putc)
push %ebp
mov %esp, %ebp
push %ebx
push %esi
push %edi
movb 0x8(%ebp), %cl
call EXT(prot_to_real)
data32
mov $0x1, %ebx /* %bh=0, %bl=1 (blue) */
movb $0xe, %ah
movb %cl, %al
sti
int $0x10 /* display a byte */
cli
data32
call EXT(real_to_prot)
pop %edi
pop %esi
pop %ebx
pop %ebp
ret
/*
* getc()
* BIOS call "INT 16H Function 00H" to read character from keyboard
* Call with %ah = 0x0
* Return: %ah = keyboard scan code
* %al = ASCII character
*/
ENTRY(getc)
push %ebp
mov %esp, %ebp
push %ebx /* save %ebx */
push %esi
push %edi
call EXT(prot_to_real)
movb $0x0, %ah
sti
int $0x16
cli
movb %al, %bl /* real_to_prot uses %eax */
data32
call EXT(real_to_prot)
xor %eax, %eax
movb %bl, %al
pop %edi
pop %esi
pop %ebx
pop %ebp
ret
/*
* ischar()
* if there is a character pending, return it; otherwise return 0
* BIOS call "INT 16H Function 01H" to check whether a character is pending
* Call with %ah = 0x1
* Return:
* If key waiting to be input:
* %ah = keyboard scan code
* %al = ASCII character
* Zero flag = clear
* else
* Zero flag = set
*/
ENTRY(ischar)
push %ebp
mov %esp, %ebp
push %ebx
push %esi
push %edi
call EXT(prot_to_real) /* enter real mode */
xor %ebx, %ebx
movb $0x1, %ah
sti
int $0x16
cli
data32
jz nochar
movb %al, %bl
nochar:
data32
call EXT(real_to_prot)
xor %eax, %eax
movb %bl, %al
pop %edi
pop %esi
pop %ebx
pop %ebp
ret
/*
*
* get_diskinfo(): return a word that represents the
* max number of sectors and heads and drives for this device
*
*/
ENTRY(get_diskinfo)
push %ebp
mov %esp, %ebp
push %ebx
push %esi
push %edi
movb 0x8(%ebp), %dl /* diskinfo(drive #) */
call EXT(prot_to_real) /* enter real mode */
movb $0x8, %ah /* ask for disk info */
sti
int $0x13
cli
jnc ok
/*
* Urk. Call failed. It is not supported for floppies by old BIOS's.
* Guess it's a 15-sector floppy.
*/
subb %ah, %ah /* %ax = 0 */
movb %al, %al
movb %ah, %bh /* %bh = 0 */
movb $2, %bl /* %bl bits 0-3 = drive type,
bit 2 = 1.2M */
movb $79, %ch /* max track */
movb $15, %cl /* max sector */
movb $1, %dh /* max head */
movb $1, %dl /* # floppy drives installed */
/* es:di = parameter table */
/* carry = 0 */
ok:
data32
call EXT(real_to_prot) /* back to protected mode */
/*
* form a longword representing all this gunk:
* 6 bit zero
* 10 bit max cylinder (0 based)
* 8 bit max head (0 based)
* 8 bit zero
* 6 bit max sector (1 based) = # sectors
*/
movb %cl, %al /* Upper two bits of cylinder count */
andl $192,%eax
leal 0(,%eax,4),%eax /* << 2 */
movb %ch, %al /* Lower 8 bits */
sall $16,%eax /* << 16 */
movb %dh, %ah /* max head */
andb $0x3f, %cl /* mask of cylinder gunk */
movb %cl, %al /* max sector (and # sectors) */
pop %edi
pop %esi
pop %ebx
pop %ebp
ret
/*
*
* memsize(i) : return the memory size in KB. i == 0 for conventional memory,
* i == 1 for extended memory
* BIOS call "INT 12H" to get conventional memory size
* BIOS call "INT 15H, AH=88H" to get extended memory size
* Both have the return value in AX.
*
*/
ENTRY(memsize)
push %ebp
mov %esp, %ebp
push %ebx
push %esi
push %edi
mov 8(%ebp), %ebx
call EXT(prot_to_real) /* enter real mode */
cmpb $0x1, %bl
data32
je xext
sti
int $0x12
cli
data32
jmp xdone
xext: movb $0x88, %ah
sti
int $0x15
cli
xdone:
pushl $0 /* actually pushw $0 */
pushl %eax /* actually pushw %ax */
data32
call EXT(real_to_prot)
pop %eax
pop %edi
pop %esi
pop %ebx
pop %ebp
ret

View File

@ -1,287 +0,0 @@
/*
* 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:35:57 rpd
* $Id$
*/
#include "boot.h"
#include <machine/cpufunc.h>
#include <sys/reboot.h>
#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
#define K_STATUS 0x64 /* keyboard status */
#define K_CMD 0x64 /* keybd ctlr command (write-only) */
#define K_OBUF_FUL 0x01 /* output buffer full */
#define K_IBUF_FUL 0x02 /* input buffer full */
#define KC_CMD_WIN 0xd0 /* read output port */
#define KC_CMD_WOUT 0xd1 /* write output port */
#define KB_A20 0xdf /* enable A20,
enable output buffer full interrupt
enable data line
enable clock line */
static int getchar(int in_buf);
/*
* Gate A20 for high memory
*/
void
gateA20(void)
{
#ifdef IBM_L40
outb(0x92, 0x2);
#else /* IBM_L40 */
while (inb(K_STATUS) & K_IBUF_FUL);
while (inb(K_STATUS) & K_OBUF_FUL)
(void)inb(K_RDWR);
outb(K_CMD, KC_CMD_WOUT);
while (inb(K_STATUS) & K_IBUF_FUL);
outb(K_RDWR, KB_A20);
while (inb(K_STATUS) & K_IBUF_FUL);
#endif /* IBM_L40 */
}
/* printf - only handles %d as decimal, %c as char, %s as string */
void
printf(const char *format, ...)
{
int *dataptr = (int *)&format;
char c;
dataptr++;
while ((c = *format++))
if (c != '%')
putchar(c);
else
switch (c = *format++) {
case 'd': {
int num = *dataptr++;
char buf[10], *ptr = buf;
if (num<0) {
num = -num;
putchar('-');
}
do
*ptr++ = '0'+num%10;
while (num /= 10);
do
putchar(*--ptr);
while (ptr != buf);
break;
}
case 'x': {
unsigned int num = *dataptr++, dig;
char buf[8], *ptr = buf;
do
*ptr++ = (dig=(num&0xf)) > 9?
'a' + dig - 10 :
'0' + dig;
while (num >>= 4);
do
putchar(*--ptr);
while (ptr != buf);
break;
}
case 'c': putchar((*dataptr++)&0xff); break;
case 's': {
char *ptr = (char *)*dataptr++;
while ((c = *ptr++))
putchar(c);
break;
}
}
}
void
putchar(int c)
{
if (c == '\n') {
if (loadflags & RB_SERIAL)
serial_putc('\r');
else
putc('\r');
}
if (loadflags & RB_SERIAL)
serial_putc(c);
else
putc(c);
}
static int
getchar(int in_buf)
{
int c;
loop:
if ((c = ((loadflags & RB_SERIAL) ? serial_getc() : getc())) == '\r')
c = '\n';
if (c == '\b') {
if (in_buf != 0) {
putchar('\b');
putchar(' ');
} else {
goto loop;
}
}
putchar(c);
return(c);
}
#ifdef PROBE_KEYBOARD
/*
* This routine uses an inb to an unused port, the time to execute that
* inb is approximately 1.25uS. This value is pretty constant across
* all CPU's and all buses, with the exception of some PCI implentations
* that do not forward this I/O adress to the ISA bus as they know it
* is not a valid ISA bus address, those machines execute this inb in
* 60 nS :-(.
*
* XXX this should be converted to use bios_tick.
*/
void
delay1ms(void)
{
int i = 800;
while (--i >= 0)
(void)inb(0x84);
}
#endif /* PROBE_KEYBOARD */
static __inline int
isch(void)
{
int isc;
/*
* Checking the keyboard has the side effect of enabling clock
* interrupts so that bios_tick works. Check the keyboard to
* get this side effect even if we only want the serial status.
*/
isc = ischar();
if (!(loadflags & RB_SERIAL))
return (isc);
return (serial_ischar());
}
static __inline unsigned
pword(unsigned physaddr)
{
unsigned result;
/*
* Give the fs prefix separately because gas omits it for
* "movl %fs:0x46c, %eax".
*/
__asm __volatile("fs; movl %1, %0" : "=r" (result)
: "m" (*(unsigned *)physaddr));
return (result);
}
int
gets(char *buf)
{
#define bios_tick pword(0x46c)
#define BIOS_TICK_MS 55
unsigned initial_bios_tick;
char *ptr=buf;
#if BOOTWAIT
for (initial_bios_tick = bios_tick;
bios_tick - initial_bios_tick < BOOTWAIT / BIOS_TICK_MS;)
#endif
if (isch())
for (;;) {
switch(*ptr = getchar(ptr - buf) & 0xff) {
case '\n':
case '\r':
*ptr = '\0';
return 1;
case '\b':
if (ptr > buf) ptr--;
continue;
default:
ptr++;
}
#if TIMEOUT + 0
#if !BOOTWAIT
#error "TIMEOUT without BOOTWAIT"
#endif
for (initial_bios_tick = bios_tick;;) {
if (isch())
break;
if (bios_tick - initial_bios_tick >=
TIMEOUT / BIOS_TICK_MS)
return 0;
}
#endif
}
return 0;
}
int
strncasecmp(const char *s1, const char *s2, size_t s)
{
/*
* We only consider ASCII chars and don't anticipate
* control characters (they are invalid in filenames
* anyway).
*/
while (s > 0 && (*s1 & 0x5f) == (*s2 & 0x5f)) {
if (!*s1++)
return 0;
s2++;
}
if (s == 0)
return 0;
return 1;
}
void
bcopy(const void *from, void *to, size_t len)
{
char *fp = (char *)from;
char *tp = (char *)to;
while (len-- > 0)
*tp++ = *fp++;
}
/* To quote Ken: "You are not expected to understand this." :) */
void
twiddle(void)
{
putchar((char)tw_chars);
tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);
putchar('\b');
}