Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
74afa70d
提交
74afa70d
5月 31, 2009
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add serial port input/output.
Delete parallel port output. Works well with qemu -nographic mode.
上级
0ca9ca0c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
87 行增加
和
23 行删除
+87
-23
console.c
console.c
+5
-23
trap.c
trap.c
+5
-0
traps.h
traps.h
+1
-0
uart.c
uart.c
+76
-0
没有找到文件。
console.c
浏览文件 @
74afa70d
// Console input and output.
// Input is from the keyboard o
nly
.
// Output is written to the screen and
the printer
port.
// Input is from the keyboard o
r serial port
.
// Output is written to the screen and
serial
port.
#include "types.h"
#include "defs.h"
...
...
@@ -13,31 +13,13 @@
#include "x86.h"
#define CRTPORT 0x3d4
#define LPTPORT 0x378
#define BACKSPACE 0x100
static
ushort
*
crt
=
(
ushort
*
)
0xb8000
;
// CGA memory
static
struct
spinlock
console_lock
;
int
panicked
=
0
;
int
use_console_lock
=
0
;
// Copy console output to parallel port, which you can tell
// .bochsrc to copy to the stdout:
// parport1: enabled=1, file="/dev/stdout"
static
void
lptputc
(
int
c
)
{
int
i
;
for
(
i
=
0
;
!
(
inb
(
LPTPORT
+
1
)
&
0x80
)
&&
i
<
12800
;
i
++
)
;
if
(
c
==
BACKSPACE
)
c
=
'\b'
;
outb
(
LPTPORT
+
0
,
c
);
outb
(
LPTPORT
+
2
,
0x08
|
0x04
|
0x01
);
outb
(
LPTPORT
+
2
,
0x08
);
}
volatile
int
use_console_lock
=
0
;
static
void
cgaputc
(
int
c
)
...
...
@@ -80,14 +62,14 @@ consputc(int c)
;
}
lp
tputc
(
c
);
uar
tputc
(
c
);
cgaputc
(
c
);
}
void
printint
(
int
xx
,
int
base
,
int
sgn
)
{
static
char
digits
[]
=
"0123456789
ABCDEF
"
;
static
char
digits
[]
=
"0123456789
abcdef
"
;
char
buf
[
16
];
int
i
=
0
,
neg
=
0
;
uint
x
;
...
...
trap.c
浏览文件 @
74afa70d
...
...
@@ -62,6 +62,11 @@ trap(struct trapframe *tf)
kbdintr
();
lapiceoi
();
break
;
case
IRQ_OFFSET
+
IRQ_COM1
:
uartintr
();
lapiceoi
();
break
;
case
IRQ_OFFSET
+
7
:
case
IRQ_OFFSET
+
IRQ_SPURIOUS
:
cprintf
(
"cpu%d: spurious interrupt at %x:%x
\n
"
,
cpu
(),
tf
->
cs
,
tf
->
eip
);
...
...
traps.h
浏览文件 @
74afa70d
...
...
@@ -31,6 +31,7 @@
#define IRQ_TIMER 0
#define IRQ_KBD 1
#define IRQ_COM1 4
#define IRQ_IDE 14
#define IRQ_ERROR 19
#define IRQ_SPURIOUS 31
uart.c
0 → 100644
浏览文件 @
74afa70d
// Intel 8250 serial port (UART).
#include "types.h"
#include "defs.h"
#include "param.h"
#include "traps.h"
#include "spinlock.h"
#include "dev.h"
#include "mmu.h"
#include "proc.h"
#include "x86.h"
#define COM1 0x3f8
static
int
uart
;
// is there a uart?
void
uartinit
(
void
)
{
char
*
p
;
// Turn off the FIFO
outb
(
COM1
+
2
,
0
);
// 9600 baud, 8 data bits, 1 stop bit, parity off.
outb
(
COM1
+
3
,
0x80
);
// Unlock divisor
outb
(
COM1
+
0
,
115200
/
9600
);
outb
(
COM1
+
1
,
0
);
outb
(
COM1
+
3
,
0x03
);
// Lock divisor, 8 data bits.
outb
(
COM1
+
4
,
0
);
outb
(
COM1
+
1
,
0x01
);
// Enable receive interrupts.
// If status is 0xFF, no serial port.
if
(
inb
(
COM1
+
5
)
==
0xFF
)
return
;
uart
=
1
;
// Acknowledge pre-existing interrupt conditions;
// enable interrupts.
inb
(
COM1
+
2
);
inb
(
COM1
+
0
);
picenable
(
IRQ_COM1
);
ioapicenable
(
IRQ_COM1
,
0
);
// Announce that we're here.
for
(
p
=
"xv6...
\n
"
;
*
p
;
p
++
)
uartputc
(
*
p
);
}
void
uartputc
(
int
c
)
{
int
i
;
if
(
!
uart
)
return
;
for
(
i
=
0
;
i
<
128
&&
!
(
inb
(
COM1
+
5
)
&
0x20
);
i
++
)
microdelay
(
10
);
outb
(
COM1
+
0
,
c
);
}
static
int
uartgetc
(
void
)
{
if
(
!
uart
)
return
-
1
;
if
(
!
(
inb
(
COM1
+
5
)
&
0x01
))
return
-
1
;
return
inb
(
COM1
+
0
);
}
void
uartintr
(
void
)
{
consoleintr
(
uartgetc
);
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论