9boot: serial console support
This commit is contained in:
parent
364f1f78d4
commit
c9c06dd8ba
5 changed files with 103 additions and 31 deletions
|
@ -5,9 +5,8 @@ extern char bootname[];
|
||||||
|
|
||||||
/* l.s */
|
/* l.s */
|
||||||
void start(void *sp);
|
void start(void *sp);
|
||||||
int getc(void);
|
void cgaputc(int c);
|
||||||
int gotc(void);
|
int kbdgetc(void);
|
||||||
void putc(int c);
|
|
||||||
void usleep(int t);
|
void usleep(int t);
|
||||||
void halt(void);
|
void halt(void);
|
||||||
void jump(void *pc);
|
void jump(void *pc);
|
||||||
|
@ -17,6 +16,9 @@ int readn(void *f, void *data, int len);
|
||||||
void close(void *f);
|
void close(void *f);
|
||||||
void unload(void);
|
void unload(void);
|
||||||
|
|
||||||
|
int getc(void);
|
||||||
|
void putc(int c);
|
||||||
|
|
||||||
void memset(void *p, int v, int n);
|
void memset(void *p, int v, int n);
|
||||||
void memmove(void *dst, void *src, int n);
|
void memmove(void *dst, void *src, int n);
|
||||||
int memcmp(void *src, void *dst, int n);
|
int memcmp(void *src, void *dst, int n);
|
||||||
|
@ -36,3 +38,8 @@ ulong e820(ulong bx, void *p);
|
||||||
|
|
||||||
/* apm.s */
|
/* apm.s */
|
||||||
void apm(int id);
|
void apm(int id);
|
||||||
|
|
||||||
|
/* uart.s */
|
||||||
|
void uartinit(int p, int c);
|
||||||
|
void uartputc(int p, int c);
|
||||||
|
int uartgetc(int p);
|
||||||
|
|
|
@ -121,26 +121,20 @@ TEXT halt(SB), $0
|
||||||
_halt:
|
_halt:
|
||||||
JMP _halt
|
JMP _halt
|
||||||
|
|
||||||
TEXT getc(SB), $0
|
TEXT kbdgetc(SB), $0
|
||||||
CALL rmode16(SB)
|
|
||||||
STI
|
|
||||||
MOVB $0x00, AH
|
|
||||||
BIOSCALL(0x16)
|
|
||||||
_getcret:
|
|
||||||
CALL16(pmode32(SB))
|
|
||||||
ANDL $0xFF, AX
|
|
||||||
RET
|
|
||||||
|
|
||||||
TEXT gotc(SB), $0
|
|
||||||
CALL rmode16(SB)
|
CALL rmode16(SB)
|
||||||
STI
|
STI
|
||||||
MOVB $0x01, AH
|
MOVB $0x01, AH
|
||||||
BIOSCALL(0x16)
|
BIOSCALL(0x16)
|
||||||
JNZ _getcret
|
JNZ _gotkey
|
||||||
CLR(rAX)
|
CLR(rAX)
|
||||||
JMP _getcret
|
JMP _pret32
|
||||||
|
_gotkey:
|
||||||
|
CLR(rAX)
|
||||||
|
BIOSCALL(0x16)
|
||||||
|
JMP _pret32
|
||||||
|
|
||||||
TEXT putc(SB), $0
|
TEXT cgaputc(SB), $0
|
||||||
MOVL 4(SP),AX
|
MOVL 4(SP),AX
|
||||||
CALL rmode16(SB)
|
CALL rmode16(SB)
|
||||||
STI
|
STI
|
||||||
|
|
|
@ -36,7 +36,7 @@ pbs: pbs.$O
|
||||||
$LD -o $target -H3 -T0x0800 -l $prereq
|
$LD -o $target -H3 -T0x0800 -l $prereq
|
||||||
ls -l $target
|
ls -l $target
|
||||||
|
|
||||||
9boot&: l%.$O %.$O sub.$O apm.$O e820.$O a20.$O
|
9boot&: l%.$O %.$O sub.$O apm.$O e820.$O a20.$O uart.$O
|
||||||
$LD -o $target -H3 -T0x7c00 -l $prereq
|
$LD -o $target -H3 -T0x7c00 -l $prereq
|
||||||
ls -l $target
|
ls -l $target
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,37 @@
|
||||||
#include "fns.h"
|
#include "fns.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
|
int uart = -1;
|
||||||
|
|
||||||
|
void
|
||||||
|
putc(int c)
|
||||||
|
{
|
||||||
|
cgaputc(c);
|
||||||
|
if(uart != -1)
|
||||||
|
uartputc(uart, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
print(char *s)
|
||||||
|
{
|
||||||
|
while(*s != 0){
|
||||||
|
if(*s == '\n')
|
||||||
|
putc('\r');
|
||||||
|
putc(*s++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
getc(void)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = kbdgetc();
|
||||||
|
if(c == 0 && uart != -1)
|
||||||
|
c = uartgetc(uart);
|
||||||
|
return c & 0x7f;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
memset(void *dst, int v, int n)
|
memset(void *dst, int v, int n)
|
||||||
{
|
{
|
||||||
|
@ -68,16 +99,6 @@ strchr(char *s, int c)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
print(char *s)
|
|
||||||
{
|
|
||||||
while(*s != 0){
|
|
||||||
if(*s == '\n')
|
|
||||||
putc('\r');
|
|
||||||
putc(*s++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
readn(void *f, void *data, int len)
|
readn(void *f, void *data, int len)
|
||||||
{
|
{
|
||||||
|
@ -112,7 +133,9 @@ readline(void *f, char buf[64])
|
||||||
putc('>');
|
putc('>');
|
||||||
for(;;){
|
for(;;){
|
||||||
if(f == nil){
|
if(f == nil){
|
||||||
putc(*p = getc());
|
while((*p = getc()) == 0)
|
||||||
|
;
|
||||||
|
putc(*p);
|
||||||
if(*p == '\r')
|
if(*p == '\r')
|
||||||
putc('\n');
|
putc('\n');
|
||||||
else if(*p == '\b' && p > buf){
|
else if(*p == '\b' && p > buf){
|
||||||
|
@ -147,7 +170,7 @@ static int
|
||||||
timeout(int ms)
|
timeout(int ms)
|
||||||
{
|
{
|
||||||
while(ms > 0){
|
while(ms > 0){
|
||||||
if(gotc())
|
if(getc() != 0)
|
||||||
return 1;
|
return 1;
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
ms -= 100;
|
ms -= 100;
|
||||||
|
@ -164,6 +187,7 @@ char *confend;
|
||||||
|
|
||||||
static void apmconf(int);
|
static void apmconf(int);
|
||||||
static void e820conf(void);
|
static void e820conf(void);
|
||||||
|
static void uartconf(char*);
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
getconf(char *s, char *buf)
|
getconf(char *s, char *buf)
|
||||||
|
@ -261,9 +285,11 @@ Loop:
|
||||||
*p++ = 0;
|
*p++ = 0;
|
||||||
delconf(line);
|
delconf(line);
|
||||||
if(memcmp("apm", line, 3) == 0){
|
if(memcmp("apm", line, 3) == 0){
|
||||||
apmconf('0' - line[3]);
|
apmconf(line[3] - '0');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(memcmp("console", line, 8) == 0)
|
||||||
|
uartconf(p);
|
||||||
|
|
||||||
s = confend;
|
s = confend;
|
||||||
memmove(confend, line, n = strlen(line)); confend += n;
|
memmove(confend, line, n = strlen(line)); confend += n;
|
||||||
|
@ -392,6 +418,16 @@ e820conf(void)
|
||||||
print(s);
|
print(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
uartconf(char *s)
|
||||||
|
{
|
||||||
|
if(*s >= '0' && *s <= '3'){
|
||||||
|
uart = *s - '0';
|
||||||
|
uartinit(uart, (7<<5) | 3); /* b9660 l8 s1 */
|
||||||
|
} else
|
||||||
|
uart = -1;
|
||||||
|
}
|
||||||
|
|
||||||
static ulong
|
static ulong
|
||||||
beswal(ulong l)
|
beswal(ulong l)
|
||||||
{
|
{
|
||||||
|
|
35
sys/src/boot/pc/uart.s
Normal file
35
sys/src/boot/pc/uart.s
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include "x16.h"
|
||||||
|
|
||||||
|
TEXT uartinit(SB), $0
|
||||||
|
MOVL c+8(SP), AX
|
||||||
|
MOVB $0x00, AH
|
||||||
|
JMP _uartbios
|
||||||
|
|
||||||
|
TEXT uartputc(SB), $0
|
||||||
|
MOVL c+8(SP), AX
|
||||||
|
MOVB $0x01, AH
|
||||||
|
JMP _uartbios
|
||||||
|
|
||||||
|
TEXT uartgetc(SB), $0
|
||||||
|
MOVL p+4(SP), DX
|
||||||
|
CALL rmode16(SB)
|
||||||
|
STI
|
||||||
|
MOVB $0x03, AH
|
||||||
|
BIOSCALL(0x14)
|
||||||
|
CALL16(pmode32(SB))
|
||||||
|
ANDL $0x8100, AX
|
||||||
|
MOVL $0x0100, BX
|
||||||
|
CMPL BX, AX
|
||||||
|
JE _uartread
|
||||||
|
XORL AX, AX
|
||||||
|
RET
|
||||||
|
_uartread:
|
||||||
|
MOVB $0x02, AH
|
||||||
|
_uartbios:
|
||||||
|
MOVL p+4(SP), DX
|
||||||
|
CALL rmode16(SB)
|
||||||
|
STI
|
||||||
|
BIOSCALL(0x14)
|
||||||
|
CALL16(pmode32(SB))
|
||||||
|
ANDL $0xFF, AX
|
||||||
|
RET
|
Loading…
Reference in a new issue