Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
47ab9b8c
提交
47ab9b8c
2月 11, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use kernel fmt.cc for userspace
上级
c576c80d
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
20 行增加
和
99 行删除
+20
-99
Makefile
Makefile
+1
-1
compiler.h
compiler.h
+8
-0
fmt.cc
fmt.cc
+2
-1
kernel.h
kernel.h
+1
-1
printf.cc
printf.cc
+5
-91
string.cc
string.cc
+1
-1
ulib.c
ulib.c
+0
-0
user.h
user.h
+2
-4
没有找到文件。
Makefile
浏览文件 @
47ab9b8c
...
...
@@ -80,7 +80,7 @@ OBJS = \
incbin.o
OBJS
:=
$
(
addprefix
$(O)
/,
$(OBJS)
)
ULIB
=
ulib.o usys.o printf.o umalloc.o uthread.o
ULIB
=
ulib.o usys.o printf.o umalloc.o uthread.o
fmt.o
ULIB
:=
$
(
addprefix
$(O)
/,
$(ULIB)
)
UPROGS
=
\
...
...
compiler.h
浏览文件 @
47ab9b8c
...
...
@@ -2,3 +2,11 @@
#define __mpalign__ __attribute__((aligned(CACHELINE)))
#define __noret__ __attribute__((noreturn))
#define barrier() __asm volatile("" ::: "memory")
#ifdef __cplusplus
#define BEGIN_DECLS extern "C" {
#define END_DECLS }
#else
#define BEGIN_DECLS
#define END_DECLS
#endif
fmt.cc
浏览文件 @
47ab9b8c
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include <stddef.h>
#include <stdarg.h>
#include "fmt.h"
#include "lib.h"
unsigned
int
strlen
(
const
char
*
);
}
//
...
...
kernel.h
浏览文件 @
47ab9b8c
...
...
@@ -294,7 +294,7 @@ void* memmove(void*, const void*, u32);
void
*
memset
(
void
*
,
int
,
u32
);
void
*
memcpy
(
void
*
,
const
void
*
,
u32
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
u32
);
int
strlen
(
const
char
*
);
unsigned
int
strlen
(
const
char
*
);
int
strncmp
(
const
char
*
,
const
char
*
,
u32
);
char
*
strncpy
(
char
*
,
const
char
*
,
u32
);
int
strcmp
(
const
char
*
p
,
const
char
*
q
);
...
...
printf.cc
浏览文件 @
47ab9b8c
#include "types.h"
#include "stat.h"
#include "user.h"
extern
"C"
{
#include <stdarg.h>
static
void
printint
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
s64
xx
,
int
base
,
int
sgn
)
{
const
static
char
digits
[]
=
"0123456789ABCDEF"
;
char
buf
[
21
];
int
i
,
neg
;
s64
x
;
neg
=
0
;
if
(
sgn
&&
xx
<
0
){
neg
=
1
;
x
=
-
xx
;
}
else
{
x
=
xx
;
}
i
=
0
;
do
{
buf
[
i
++
]
=
digits
[
x
%
base
];
}
while
((
x
/=
base
)
!=
0
);
if
(
neg
)
buf
[
i
++
]
=
'-'
;
while
(
--
i
>=
0
)
putch
(
putarg
,
buf
[
i
]);
}
// Only understands %d, %x, %p, %s.
void
vprintfmt
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
const
char
*
fmt
,
va_list
ap
)
{
const
char
*
s
;
int
c
,
i
,
state
;
state
=
0
;
for
(
i
=
0
;
fmt
[
i
];
i
++
){
c
=
fmt
[
i
]
&
0xff
;
if
(
state
==
0
){
if
(
c
==
'%'
){
state
=
'%'
;
}
else
{
putch
(
putarg
,
c
);
}
}
else
if
(
state
==
'%'
){
if
(
c
==
'd'
){
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u32
),
10
,
1
);
}
else
if
(
c
==
'x'
)
{
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u32
),
16
,
0
);
}
else
if
(
c
==
'l'
)
{
state
=
'l'
;
continue
;
}
else
if
(
c
==
's'
){
s
=
(
const
char
*
)
va_arg
(
ap
,
const
char
*
);
if
(
s
==
0
)
s
=
"(null)"
;
while
(
*
s
!=
0
){
putch
(
putarg
,
*
s
);
s
++
;
}
}
else
if
(
c
==
'c'
){
putch
(
putarg
,
va_arg
(
ap
,
u32
));
}
else
if
(
c
==
'%'
){
putch
(
putarg
,
c
);
}
else
{
// Unknown % sequence. Print it to draw attention.
putch
(
putarg
,
'%'
);
putch
(
putarg
,
c
);
}
state
=
0
;
}
else
if
(
state
==
'l'
)
{
if
(
c
==
'x'
)
{
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u64
),
16
,
0
);
}
else
if
(
c
==
'u'
)
{
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u64
),
10
,
0
);
}
else
{
// Unknown % sequence. Print it to draw attention.
putch
(
putarg
,
'%'
);
putch
(
putarg
,
c
);
}
state
=
0
;
}
}
#include "fmt.h"
}
// Print to the given fd.
static
void
writec
(
void
*
arg
,
char
c
)
writec
(
int
c
,
void
*
arg
)
{
int
fd
=
(
int
)
(
u64
)
arg
;
int
fd
=
(
int
)
(
u64
)
arg
;
write
(
fd
,
&
c
,
1
);
}
...
...
@@ -117,7 +31,7 @@ struct bufstate {
};
static
void
writebuf
(
void
*
arg
,
char
c
)
writebuf
(
int
c
,
void
*
arg
)
{
struct
bufstate
*
bs
=
(
bufstate
*
)
arg
;
if
(
bs
->
p
<
bs
->
e
)
{
...
...
string.cc
浏览文件 @
47ab9b8c
...
...
@@ -92,7 +92,7 @@ safestrcpy(char *s, const char *t, u32 n)
return
os
;
}
int
unsigned
int
strlen
(
const
char
*
s
)
{
int
n
;
...
...
ulib.c
c
→
ulib.c
浏览文件 @
47ab9b8c
移动文件
user.h
浏览文件 @
47ab9b8c
BEGIN_DECLS
struct
stat
;
// system calls
extern
"C"
{
int
fork
(
int
);
int
exit
(
void
)
__attribute__
((
noreturn
));
int
wait
(
void
);
...
...
@@ -28,7 +28,6 @@ int unmap(void *addr, int len);
void
halt
(
void
);
ssize_t
pread
(
int
,
void
*
,
size_t
,
off_t
);
int
kernlet
(
int
,
size_t
,
off_t
);
}
// ulib.c
int
stat
(
char
*
,
struct
stat
*
);
...
...
@@ -46,11 +45,10 @@ void free(void*);
int
atoi
(
const
char
*
);
// uthread.S
extern
"C"
{
int
forkt
(
void
*
sp
,
void
*
pc
,
void
*
arg
);
}
// printf.c
void
printf
(
int
,
const
char
*
,
...);
void
snprintf
(
char
*
buf
,
unsigned
int
n
,
const
char
*
fmt
,
...);
void
die
(
const
char
*
errstr
,
...)
__attribute__
((
noreturn
));
END_DECLS
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论