Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
be0a7eac
提交
be0a7eac
6月 15, 2006
创建
作者:
rtm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sleep, wakeup, wait, exit
上级
a4c03dea
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
93 行增加
和
6 行删除
+93
-6
Makefile
Makefile
+4
-2
defs.h
defs.h
+2
-0
main.c
main.c
+9
-0
proc.c
proc.c
+27
-1
proc.h
proc.h
+4
-1
syscall.c
syscall.c
+46
-2
syscall.h
syscall.h
+1
-0
没有找到文件。
Makefile
浏览文件 @
be0a7eac
...
...
@@ -5,7 +5,7 @@ CC = i386-jos-elf-gcc
LD
=
i386-jos-elf-ld
OBJCOPY
=
i386-jos-elf-objcopy
OBJDUMP
=
i386-jos-elf-objdump
CFLAGS
=
-nostdinc
-I
.
-O
-Wall
CFLAGS
=
-nostdinc
-I
.
-O
-Wall
-MD
xv6.img
:
bootblock kernel
dd
if
=
/dev/zero
of
=
xv6.img
count
=
10000
...
...
@@ -27,5 +27,7 @@ kernel : $(OBJS)
vectors.S
:
vectors.pl
perl vectors.pl
>
vectors.S
-include
*.d
clean
:
rm
-f
*
.o bootblock kernel kernel.asm xv6.img
rm
-f
*
.o bootblock kernel kernel.asm xv6.img
*
.d
defs.h
浏览文件 @
be0a7eac
...
...
@@ -12,6 +12,8 @@ struct proc;
void
setupsegs
(
struct
proc
*
);
struct
proc
*
newproc
(
void
);
void
swtch
(
void
);
void
sleep
(
void
*
);
void
wakeup
(
void
*
);
// trap.c
void
tinit
(
void
);
...
...
main.c
浏览文件 @
be0a7eac
...
...
@@ -42,6 +42,8 @@ main()
p
->
tf
->
tf_es
=
p
->
tf
->
tf_ds
=
p
->
tf
->
tf_ss
=
(
SEG_UDATA
<<
3
)
|
3
;
p
->
tf
->
tf_cs
=
(
SEG_UCODE
<<
3
)
|
3
;
p
->
tf
->
tf_eflags
=
FL_IF
;
p
->
pid
=
0
;
p
->
ppid
=
0
;
setupsegs
(
p
);
p
=
newproc
();
...
...
@@ -56,6 +58,13 @@ main()
p
->
mem
[
i
++
]
=
0xcd
;
// int
p
->
mem
[
i
++
]
=
T_SYSCALL
;
p
->
mem
[
i
++
]
=
0xb8
;
// mov ..., %eax
p
->
mem
[
i
++
]
=
SYS_wait
;
p
->
mem
[
i
++
]
=
0
;
p
->
mem
[
i
++
]
=
0
;
p
->
mem
[
i
++
]
=
0
;
p
->
mem
[
i
++
]
=
0xcd
;
// int
p
->
mem
[
i
++
]
=
T_SYSCALL
;
p
->
mem
[
i
++
]
=
0xb8
;
// mov ..., %eax
p
->
mem
[
i
++
]
=
SYS_exit
;
p
->
mem
[
i
++
]
=
0
;
p
->
mem
[
i
++
]
=
0
;
...
...
proc.c
浏览文件 @
be0a7eac
...
...
@@ -7,6 +7,7 @@
struct
proc
proc
[
NPROC
];
struct
proc
*
curproc
;
int
next_pid
=
1
;
/*
* set up a process's task state and segment descriptors
...
...
@@ -54,6 +55,8 @@ newproc()
if
(
np
>=
&
proc
[
NPROC
])
return
0
;
np
->
pid
=
next_pid
++
;
np
->
ppid
=
curproc
->
pid
;
np
->
sz
=
curproc
->
sz
;
np
->
mem
=
kalloc
(
curproc
->
sz
);
if
(
np
->
mem
==
0
)
...
...
@@ -111,7 +114,12 @@ swtch()
// XXX callee-saved registers?
// XXX probably ought to lgdt on trap return too
// h/w sets busy bit in TSS descriptor sometimes, and faults
// if it's set in LTR. so clear tss descriptor busy bit.
curproc
->
gdt
[
SEG_TSS
].
sd_type
=
STS_T32A
;
// XXX probably ought to lgdt on trap return too, in case
// a system call has moved a program or changed its size.
asm
volatile
(
"lgdt %0"
:
:
"g"
(
np
->
gdt_pd
.
pd_lim
));
ltr
(
SEG_TSS
<<
3
);
...
...
@@ -122,3 +130,21 @@ swtch()
asm
volatile
(
"movl %0, %%esp"
:
:
"g"
(
np
->
esp
));
asm
volatile
(
"movl %0, %%ebp"
:
:
"g"
(
np
->
ebp
));
}
void
sleep
(
void
*
chan
)
{
curproc
->
chan
=
chan
;
curproc
->
state
=
WAITING
;
swtch
();
}
void
wakeup
(
void
*
chan
)
{
struct
proc
*
p
;
for
(
p
=
proc
;
p
<
&
proc
[
NPROC
];
p
++
)
if
(
p
->
state
==
WAITING
&&
p
->
chan
==
chan
)
p
->
state
=
RUNNABLE
;
}
proc.h
浏览文件 @
be0a7eac
...
...
@@ -20,7 +20,10 @@ struct proc{
char
*
mem
;
// start of process's physical memory
unsigned
sz
;
// total size of mem, including kernel stack
char
*
kstack
;
// kernel stack, separate from mem so it doesn't move
enum
{
UNUSED
,
RUNNABLE
,
WAITING
}
state
;
enum
{
UNUSED
,
RUNNABLE
,
WAITING
,
ZOMBIE
}
state
;
int
pid
;
int
ppid
;
void
*
chan
;
// sleep
struct
Taskstate
ts
;
// only to give cpu address of kernel stack
struct
Segdesc
gdt
[
NSEGS
];
...
...
syscall.c
浏览文件 @
be0a7eac
...
...
@@ -24,12 +24,53 @@ sys_fork()
void
sys_exit
()
{
curproc
->
state
=
UNUSED
;
// XXX free resources. notify parent. abandon children.
struct
proc
*
p
;
curproc
->
state
=
ZOMBIE
;
// wake up parent
for
(
p
=
proc
;
p
<
&
proc
[
NPROC
];
p
++
)
if
(
p
->
pid
==
curproc
->
ppid
)
wakeup
(
p
);
// abandon children
for
(
p
=
proc
;
p
<
&
proc
[
NPROC
];
p
++
)
if
(
p
->
ppid
==
curproc
->
pid
)
p
->
pid
=
1
;
swtch
();
}
void
sys_wait
()
{
struct
proc
*
p
;
int
any
;
cprintf
(
"waid pid %d ppid %d
\n
"
,
curproc
->
pid
,
curproc
->
ppid
);
while
(
1
){
any
=
0
;
for
(
p
=
proc
;
p
<
&
proc
[
NPROC
];
p
++
){
if
(
p
->
state
==
ZOMBIE
&&
p
->
ppid
==
curproc
->
pid
){
kfree
(
p
->
mem
,
p
->
sz
);
kfree
(
p
->
kstack
,
KSTACKSIZE
);
p
->
state
=
UNUSED
;
cprintf
(
"%x collected %x
\n
"
,
curproc
,
p
);
return
;
}
if
(
p
->
state
!=
UNUSED
&&
p
->
ppid
==
curproc
->
pid
)
any
=
1
;
}
if
(
any
==
0
){
cprintf
(
"%x nothing to wait for
\n
"
,
curproc
);
return
;
}
sleep
(
curproc
);
}
}
void
syscall
()
{
int
num
=
curproc
->
tf
->
tf_regs
.
reg_eax
;
...
...
@@ -42,6 +83,9 @@ syscall()
case
SYS_exit
:
sys_exit
();
break
;
case
SYS_wait
:
sys_wait
();
break
;
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
...
...
syscall.h
浏览文件 @
be0a7eac
#define SYS_fork 1
#define SYS_exit 2
#define SYS_wait 3
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论