提交 ce3ea511 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Handle reads and writes to T_DEV.

上级 d00a87f6
......@@ -7,10 +7,15 @@
#include "cpu.h"
#include "kernel.h"
#include "spinlock.h"
#include "fs.h"
#include "condvar.h"
#include "file.h"
#include "x86.h"
#include <stdarg.h>
#define BACKSPACE 0x100
static struct {
struct spinlock lock;
int locking;
......@@ -42,12 +47,30 @@ printint(void (*putch) (void*, char), void *putarg,
putch(putarg, buf[i]);
}
static void
consputc(int c)
{
// XXX(sbw)
#if 0
if(panicked){
cli();
for(;;)
;
}
#endif
if(c == BACKSPACE){
uartputc('\b'); uartputc(' '); uartputc('\b');
} else
uartputc(c);
cgaputc(c);
}
// Print to the console.
static void
writecons(void *arg, char c)
{
uartputc(c);
cgaputc(c);
consputc(c);
}
// Only understands %d, %u, %x, %s, %lx.
......@@ -189,10 +212,34 @@ panic(const char *s)
;
}
static int
consolewrite(struct inode *ip, char *buf, int n)
{
int i;
iunlock(ip);
acquire(&cons.lock);
for(i = 0; i < n; i++)
consputc(buf[i] & 0xff);
release(&cons.lock);
ilock(ip, 1);
return n;
}
static int
consoleread(struct inode *ip, char *dst, int n)
{
panic("consoleread");
}
void
initconsole(void)
{
initlock(&cons.lock, "console");
devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread;
// XXX(sbw) enable once we setup %gs
cons.locking = 0;
}
......@@ -7,7 +7,7 @@
#include "file.h"
#include "stat.h"
struct devsw __attribute__ ((aligned (CACHELINE))) devsw[NDEV];
struct devsw __mpalign__ devsw[NDEV];
// Allocate a file structure.
struct file*
......
......@@ -515,13 +515,9 @@ readi(struct inode *ip, char *dst, u32 off, u32 n)
struct buf *bp;
if(ip->type == T_DEV){
// XXX(sbw)
panic("readi T_DEV");
#if 0
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read)
return -1;
return devsw[ip->major].read(ip, dst, n);
#endif
}
if(off > ip->size || off + n < off)
......@@ -547,13 +543,9 @@ writei(struct inode *ip, char *src, u32 off, u32 n)
struct buf *bp;
if(ip->type == T_DEV){
// XXX(sbw)
panic("writei T_DEV");
#if 0
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
return -1;
return devsw[ip->major].write(ip, src, n);
#endif
}
if(off > ip->size || off + n < off)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论