Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
930810d3
提交
930810d3
11月 14, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tweaks for real hardware serial ports.
上级
8a620c2e
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
37 行增加
和
20 行删除
+37
-20
console.c
console.c
+12
-3
traps.h
traps.h
+1
-0
uart.c
uart.c
+24
-17
没有找到文件。
console.c
浏览文件 @
930810d3
...
@@ -60,10 +60,19 @@ consputc(int c)
...
@@ -60,10 +60,19 @@ consputc(int c)
;
;
}
}
if
(
c
==
BACKSPACE
){
switch
(
c
)
{
uartputc
(
'\b'
);
uartputc
(
' '
);
uartputc
(
'\b'
);
case
BACKSPACE
:
}
else
uartputc
(
'\b'
);
uartputc
(
' '
);
uartputc
(
'\b'
);
break
;
case
'\n'
:
uartputc
(
'\r'
);
// fall through
default:
uartputc
(
c
);
uartputc
(
c
);
}
cgaputc
(
c
);
cgaputc
(
c
);
}
}
...
...
traps.h
浏览文件 @
930810d3
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#define IRQ_TIMER 0
#define IRQ_TIMER 0
#define IRQ_KBD 1
#define IRQ_KBD 1
#define IRQ_COM2 3
#define IRQ_COM1 4
#define IRQ_COM1 4
#define IRQ_IDE 14
#define IRQ_IDE 14
#define IRQ_ERROR 19
#define IRQ_ERROR 19
...
...
uart.c
浏览文件 @
930810d3
// Intel 8250 serial port (UART).
// Intel 8250 serial port (UART).
// http://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming
#include "types.h"
#include "types.h"
#include "kernel.h"
#include "kernel.h"
#include "amd64.h"
#include "amd64.h"
#include "traps.h"
#include "traps.h"
#define COM2 0x2f8
#define COM1 0x3f8
#define COM1 0x3f8
#define COM COM2
#define IRQ_COM IRQ_COM2
static
int
uart
;
// is there a uart?
static
int
uart
;
// is there a uart?
void
void
...
@@ -15,9 +20,9 @@ uartputc(char c)
...
@@ -15,9 +20,9 @@ uartputc(char c)
if
(
!
uart
)
if
(
!
uart
)
return
;
return
;
for
(
i
=
0
;
i
<
128
&&
!
(
inb
(
COM
1
+
5
)
&
0x20
);
i
++
)
for
(
i
=
0
;
i
<
128
&&
!
(
inb
(
COM
+
5
)
&
0x20
);
i
++
)
microdelay
(
10
);
microdelay
(
10
);
outb
(
COM
1
+
0
,
c
);
outb
(
COM
+
0
,
c
);
}
}
static
int
static
int
...
@@ -25,9 +30,9 @@ uartgetc(void)
...
@@ -25,9 +30,9 @@ uartgetc(void)
{
{
if
(
!
uart
)
if
(
!
uart
)
return
-
1
;
return
-
1
;
if
(
!
(
inb
(
COM
1
+
5
)
&
0x01
))
if
(
!
(
inb
(
COM
+
5
)
&
0x01
))
return
-
1
;
return
-
1
;
return
inb
(
COM
1
+
0
);
return
inb
(
COM
+
0
);
}
}
void
void
...
@@ -42,27 +47,29 @@ inituart(void)
...
@@ -42,27 +47,29 @@ inituart(void)
char
*
p
;
char
*
p
;
// Turn off the FIFO
// Turn off the FIFO
outb
(
COM
1
+
2
,
0
);
outb
(
COM
+
2
,
0
);
// 9600 baud, 8 data bits, 1 stop bit, parity off.
// 19200 baud
outb
(
COM1
+
3
,
0x80
);
// Unlock divisor
outb
(
COM
+
3
,
0x80
);
// Unlock divisor
outb
(
COM1
+
0
,
115200
/
9600
);
outb
(
COM
+
0
,
115200
/
19200
);
outb
(
COM1
+
1
,
0
);
outb
(
COM
+
1
,
0
);
outb
(
COM1
+
3
,
0x03
);
// Lock divisor, 8 data bits.
// 8 bits, one stop bit, no parity
outb
(
COM1
+
4
,
0
);
outb
(
COM
+
3
,
0x03
);
// Lock divisor, 8 data bits.
outb
(
COM1
+
1
,
0x01
);
// Enable receive interrupts.
outb
(
COM
+
1
,
0x01
);
// Enable receive interrupts.
// Data terminal ready
outb
(
COM
+
4
,
0x0
);
// If status is 0xFF, no serial port.
// If status is 0xFF, no serial port.
if
(
inb
(
COM
1
+
5
)
==
0xFF
)
if
(
inb
(
COM
+
5
)
==
0xFF
)
return
;
return
;
uart
=
1
;
uart
=
1
;
// Acknowledge pre-existing interrupt conditions;
// Acknowledge pre-existing interrupt conditions;
// enable interrupts.
// enable interrupts.
inb
(
COM
1
+
2
);
inb
(
COM
+
2
);
inb
(
COM
1
+
0
);
inb
(
COM
+
0
);
picenable
(
IRQ_COM
1
);
picenable
(
IRQ_COM
);
ioapicenable
(
IRQ_COM
1
,
0
);
ioapicenable
(
IRQ_COM
,
0
);
// Announce that we're here.
// Announce that we're here.
for
(
p
=
"uart..
\n
"
;
*
p
;
p
++
)
for
(
p
=
"uart..
\n
"
;
*
p
;
p
++
)
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论