Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
ef2bd07a
提交
ef2bd07a
7月 16, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
standardize on not using foo_ prefix in struct foo
上级
6b765c48
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
181 行增加
和
180 行删除
+181
-180
bootmain.c
bootmain.c
+5
-5
defs.h
defs.h
+2
-0
elf.h
elf.h
+25
-29
main.c
main.c
+15
-15
mmu.h
mmu.h
+82
-82
proc.c
proc.c
+11
-11
proc.h
proc.h
+9
-9
syscall.c
syscall.c
+6
-3
trap.c
trap.c
+4
-4
x86.h
x86.h
+22
-22
没有找到文件。
bootmain.c
浏览文件 @
ef2bd07a
...
...
@@ -45,18 +45,18 @@ cmain(void)
readseg
((
uint32_t
)
ELFHDR
,
SECTSIZE
*
8
,
0
);
// is this a valid ELF?
if
(
ELFHDR
->
e_
magic
!=
ELF_MAGIC
)
if
(
ELFHDR
->
magic
!=
ELF_MAGIC
)
goto
bad
;
// load each program segment (ignores ph flags)
ph
=
(
struct
Proghdr
*
)
((
uint8_t
*
)
ELFHDR
+
ELFHDR
->
e_
phoff
);
eph
=
ph
+
ELFHDR
->
e_
phnum
;
ph
=
(
struct
Proghdr
*
)
((
uint8_t
*
)
ELFHDR
+
ELFHDR
->
phoff
);
eph
=
ph
+
ELFHDR
->
phnum
;
for
(;
ph
<
eph
;
ph
++
)
readseg
(
ph
->
p_va
,
ph
->
p_memsz
,
ph
->
p_
offset
);
readseg
(
ph
->
va
,
ph
->
memsz
,
ph
->
offset
);
// call the entry point from the ELF header
// note: does not return!
((
void
(
*
)(
void
))
(
ELFHDR
->
e
_e
ntry
&
0xFFFFFF
))();
((
void
(
*
)(
void
))
(
ELFHDR
->
entry
&
0xFFFFFF
))();
bad:
outw
(
0x8A00
,
0x8A00
);
...
...
defs.h
浏览文件 @
ef2bd07a
...
...
@@ -64,6 +64,8 @@ int cpu(void);
struct
spinlock
;
void
acquire
(
struct
spinlock
*
lock
);
void
release
(
struct
spinlock
*
lock
);
void
acquire1
(
struct
spinlock
*
lock
,
struct
proc
*
);
void
release1
(
struct
spinlock
*
lock
,
struct
proc
*
);
// main.c
void
load_icode
(
struct
proc
*
p
,
uint8_t
*
binary
,
unsigned
size
);
...
...
elf.h
浏览文件 @
ef2bd07a
#ifndef JOS_INC_ELF_H
#define JOS_INC_ELF_H
#define ELF_MAGIC 0x464C457FU
/* "\x7FELF" in little endian */
struct
Elf
{
uint32_t
e_
magic
;
// must equal ELF_MAGIC
uint8_t
e
_e
lf
[
12
];
uint16_t
e_
type
;
uint16_t
e_
machine
;
uint32_t
e_
version
;
uint32_t
e
_e
ntry
;
uint32_t
e_
phoff
;
uint32_t
e_
shoff
;
uint32_t
e_
flags
;
uint16_t
e
_e
hsize
;
uint16_t
e_
phentsize
;
uint16_t
e_
phnum
;
uint16_t
e_
shentsize
;
uint16_t
e_
shnum
;
uint16_t
e_
shstrndx
;
uint32_t
magic
;
// must equal ELF_MAGIC
uint8_t
elf
[
12
];
uint16_t
type
;
uint16_t
machine
;
uint32_t
version
;
uint32_t
entry
;
uint32_t
phoff
;
uint32_t
shoff
;
uint32_t
flags
;
uint16_t
ehsize
;
uint16_t
phentsize
;
uint16_t
phnum
;
uint16_t
shentsize
;
uint16_t
shnum
;
uint16_t
shstrndx
;
};
struct
Proghdr
{
uint32_t
p_
type
;
uint32_t
p_
offset
;
uint32_t
p_
va
;
uint32_t
p
_p
a
;
uint32_t
p_
filesz
;
uint32_t
p_
memsz
;
uint32_t
p_
flags
;
uint32_t
p_
align
;
uint32_t
type
;
uint32_t
offset
;
uint32_t
va
;
uint32_t
pa
;
uint32_t
filesz
;
uint32_t
memsz
;
uint32_t
flags
;
uint32_t
align
;
};
// Values for Proghdr
::p_
type
// Values for Proghdr
type
#define ELF_PROG_LOAD 1
// Flag bits for Proghdr
::p_
flags
// Flag bits for Proghdr
flags
#define ELF_PROG_FLAG_EXEC 1
#define ELF_PROG_FLAG_WRITE 2
#define ELF_PROG_FLAG_READ 4
#endif
/* !JOS_INC_ELF_H */
main.c
浏览文件 @
ef2bd07a
...
...
@@ -62,9 +62,9 @@ main()
p
->
kstack
=
kalloc
(
KSTACKSIZE
);
p
->
tf
=
(
struct
Trapframe
*
)
(
p
->
kstack
+
KSTACKSIZE
-
sizeof
(
struct
Trapframe
));
memset
(
p
->
tf
,
0
,
sizeof
(
struct
Trapframe
));
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
->
tf
->
es
=
p
->
tf
->
ds
=
p
->
tf
->
ss
=
(
SEG_UDATA
<<
3
)
|
3
;
p
->
tf
->
cs
=
(
SEG_UCODE
<<
3
)
|
3
;
p
->
tf
->
eflags
=
FL_IF
;
p
->
pid
=
0
;
p
->
ppid
=
0
;
setupsegs
(
p
);
...
...
@@ -103,26 +103,26 @@ load_icode(struct proc *p, uint8_t *binary, unsigned size)
// Check magic number on binary
elf
=
(
struct
Elf
*
)
binary
;
cprintf
(
"elf %x magic %x
\n
"
,
elf
,
elf
->
e_
magic
);
if
(
elf
->
e_
magic
!=
ELF_MAGIC
)
cprintf
(
"elf %x magic %x
\n
"
,
elf
,
elf
->
magic
);
if
(
elf
->
magic
!=
ELF_MAGIC
)
panic
(
"load_icode: not an ELF binary"
);
p
->
tf
->
tf_eip
=
elf
->
e_
entry
;
p
->
tf
->
tf_
esp
=
p
->
sz
;
p
->
tf
->
eip
=
elf
->
entry
;
p
->
tf
->
esp
=
p
->
sz
;
// Map and load segments as directed.
ph
=
(
struct
Proghdr
*
)
(
binary
+
elf
->
e_
phoff
);
for
(
i
=
0
;
i
<
elf
->
e_
phnum
;
i
++
,
ph
++
)
{
if
(
ph
->
p_
type
!=
ELF_PROG_LOAD
)
ph
=
(
struct
Proghdr
*
)
(
binary
+
elf
->
phoff
);
for
(
i
=
0
;
i
<
elf
->
phnum
;
i
++
,
ph
++
)
{
if
(
ph
->
type
!=
ELF_PROG_LOAD
)
continue
;
cprintf
(
"va %x memsz %d
\n
"
,
ph
->
p_va
,
ph
->
p_
memsz
);
if
(
ph
->
p_va
+
ph
->
p_memsz
<
ph
->
p_
va
)
cprintf
(
"va %x memsz %d
\n
"
,
ph
->
va
,
ph
->
memsz
);
if
(
ph
->
va
+
ph
->
memsz
<
ph
->
va
)
panic
(
"load_icode: overflow in elf header segment"
);
if
(
ph
->
p_va
+
ph
->
p_
memsz
>=
p
->
sz
)
if
(
ph
->
va
+
ph
->
memsz
>=
p
->
sz
)
panic
(
"load_icode: icode wants to be above UTOP"
);
// Load/clear the segment
memmove
(
p
->
mem
+
ph
->
p_va
,
binary
+
ph
->
p_offset
,
ph
->
p_
filesz
);
memset
(
p
->
mem
+
ph
->
p_va
+
ph
->
p_filesz
,
0
,
ph
->
p_memsz
-
ph
->
p_
filesz
);
memmove
(
p
->
mem
+
ph
->
va
,
binary
+
ph
->
offset
,
ph
->
filesz
);
memset
(
p
->
mem
+
ph
->
va
+
ph
->
filesz
,
0
,
ph
->
memsz
-
ph
->
filesz
);
}
}
mmu.h
浏览文件 @
ef2bd07a
...
...
@@ -147,19 +147,19 @@
// Segment Descriptors
struct
Segdesc
{
unsigned
sd_
lim_15_0
:
16
;
// Low bits of segment limit
unsigned
sd_
base_15_0
:
16
;
// Low bits of segment base address
unsigned
sd_
base_23_16
:
8
;
// Middle bits of segment base address
unsigned
sd_
type
:
4
;
// Segment type (see STS_ constants)
unsigned
s
d_s
:
1
;
// 0 = system, 1 = application
unsigned
sd_
dpl
:
2
;
// Descriptor Privilege Level
unsigned
sd_
p
:
1
;
// Present
unsigned
sd_
lim_19_16
:
4
;
// High bits of segment limit
unsigned
sd_
avl
:
1
;
// Unused (available for software use)
unsigned
sd_
rsv1
:
1
;
// Reserved
unsigned
sd_
db
:
1
;
// 0 = 16-bit segment, 1 = 32-bit segment
unsigned
sd_
g
:
1
;
// Granularity: limit scaled by 4K when set
unsigned
sd_
base_31_24
:
8
;
// High bits of segment base address
unsigned
lim_15_0
:
16
;
// Low bits of segment limit
unsigned
base_15_0
:
16
;
// Low bits of segment base address
unsigned
base_23_16
:
8
;
// Middle bits of segment base address
unsigned
type
:
4
;
// Segment type (see STS_ constants)
unsigned
s
:
1
;
// 0 = system, 1 = application
unsigned
dpl
:
2
;
// Descriptor Privilege Level
unsigned
p
:
1
;
// Present
unsigned
lim_19_16
:
4
;
// High bits of segment limit
unsigned
avl
:
1
;
// Unused (available for software use)
unsigned
rsv1
:
1
;
// Reserved
unsigned
db
:
1
;
// 0 = 16-bit segment, 1 = 32-bit segment
unsigned
g
:
1
;
// Granularity: limit scaled by 4K when set
unsigned
base_31_24
:
8
;
// High bits of segment base address
};
// Null segment
#define SEG_NULL (struct Segdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
...
...
@@ -210,56 +210,56 @@ struct Segdesc {
// Task state segment format (as described by the Pentium architecture book)
struct
Taskstate
{
uint32_t
ts_
link
;
// Old ts selector
uintptr_t
ts_
esp0
;
// Stack pointers and segment selectors
uint16_t
ts_
ss0
;
// after an increase in privilege level
uint16_t
ts_
padding1
;
uintptr_t
ts_
esp1
;
uint16_t
ts_
ss1
;
uint16_t
ts_
padding2
;
uintptr_t
ts_
esp2
;
uint16_t
ts_
ss2
;
uint16_t
ts_
padding3
;
physaddr_t
ts_
cr3
;
// Page directory base
uintptr_t
ts_
eip
;
// Saved state from last task switch
uint32_t
ts_
eflags
;
uint32_t
ts_
eax
;
// More saved state (registers)
uint32_t
ts_
ecx
;
uint32_t
ts_
edx
;
uint32_t
ts_
ebx
;
uintptr_t
ts_
esp
;
uintptr_t
ts_
ebp
;
uint32_t
ts_
esi
;
uint32_t
ts_
edi
;
uint16_t
ts_
es
;
// Even more saved state (segment selectors)
uint16_t
ts_
padding4
;
uint16_t
ts_
cs
;
uint16_t
ts_
padding5
;
uint16_t
ts_
ss
;
uint16_t
ts_
padding6
;
uint16_t
ts_
ds
;
uint16_t
ts_
padding7
;
uint16_t
ts_
fs
;
uint16_t
ts_
padding8
;
uint16_t
ts_
gs
;
uint16_t
ts_
padding9
;
uint16_t
ts_
ldt
;
uint16_t
ts_
padding10
;
uint16_t
t
s_t
;
// Trap on task switch
uint16_t
ts_
iomb
;
// I/O map base address
uint32_t
link
;
// Old ts selector
uintptr_t
esp0
;
// Stack pointers and segment selectors
uint16_t
ss0
;
// after an increase in privilege level
uint16_t
padding1
;
uintptr_t
esp1
;
uint16_t
ss1
;
uint16_t
padding2
;
uintptr_t
esp2
;
uint16_t
ss2
;
uint16_t
padding3
;
physaddr_t
cr3
;
// Page directory base
uintptr_t
eip
;
// Saved state from last task switch
uint32_t
eflags
;
uint32_t
eax
;
// More saved state (registers)
uint32_t
ecx
;
uint32_t
edx
;
uint32_t
ebx
;
uintptr_t
esp
;
uintptr_t
ebp
;
uint32_t
esi
;
uint32_t
edi
;
uint16_t
es
;
// Even more saved state (segment selectors)
uint16_t
padding4
;
uint16_t
cs
;
uint16_t
padding5
;
uint16_t
ss
;
uint16_t
padding6
;
uint16_t
ds
;
uint16_t
padding7
;
uint16_t
fs
;
uint16_t
padding8
;
uint16_t
gs
;
uint16_t
padding9
;
uint16_t
ldt
;
uint16_t
padding10
;
uint16_t
t
;
// Trap on task switch
uint16_t
iomb
;
// I/O map base address
};
// Gate descriptors for interrupts and traps
struct
Gatedesc
{
unsigned
gd_
off_15_0
:
16
;
// low 16 bits of offset in segment
unsigned
gd_
ss
:
16
;
// segment selector
unsigned
gd_
args
:
5
;
// # args, 0 for interrupt/trap gates
unsigned
gd_
rsv1
:
3
;
// reserved(should be zero I guess)
unsigned
gd_
type
:
4
;
// type(STS_{TG,IG32,TG32})
unsigned
gd_
s
:
1
;
// must be 0 (system)
unsigned
gd_
dpl
:
2
;
// descriptor(meaning new) privilege level
unsigned
gd_
p
:
1
;
// Present
unsigned
gd_
off_31_16
:
16
;
// high bits of offset in segment
unsigned
off_15_0
:
16
;
// low 16 bits of offset in segment
unsigned
ss
:
16
;
// segment selector
unsigned
args
:
5
;
// # args, 0 for interrupt/trap gates
unsigned
rsv1
:
3
;
// reserved(should be zero I guess)
unsigned
type
:
4
;
// type(STS_{TG,IG32,TG32})
unsigned
s
:
1
;
// must be 0 (system)
unsigned
dpl
:
2
;
// descriptor(meaning new) privilege level
unsigned
p
:
1
;
// Present
unsigned
off_31_16
:
16
;
// high bits of offset in segment
};
// Set up a normal interrupt/trap gate descriptor.
...
...
@@ -269,38 +269,38 @@ struct Gatedesc {
// - dpl: Descriptor Privilege Level -
// the privilege level required for software to invoke
// this interrupt/trap gate explicitly using an int instruction.
#define SETGATE(gate, istrap, sel, off, d
pl
) \
#define SETGATE(gate, istrap, sel, off, d) \
{ \
(gate).
gd_
off_15_0 = (uint32_t) (off) & 0xffff; \
(gate).
gd_
ss = (sel); \
(gate).
gd_
args = 0; \
(gate).
gd_
rsv1 = 0; \
(gate).
gd_
type = (istrap) ? STS_TG32 : STS_IG32; \
(gate).
gd_
s = 0; \
(gate).
gd_dpl = (dpl
); \
(gate).
gd_
p = 1; \
(gate).
gd_
off_31_16 = (uint32_t) (off) >> 16; \
(gate).off_15_0 = (uint32_t) (off) & 0xffff; \
(gate).ss = (sel); \
(gate).args = 0; \
(gate).rsv1 = 0; \
(gate).type = (istrap) ? STS_TG32 : STS_IG32; \
(gate).s = 0; \
(gate).
dpl = (d
); \
(gate).p = 1; \
(gate).off_31_16 = (uint32_t) (off) >> 16; \
}
// Set up a call gate descriptor.
#define SETCALLGATE(gate, ss, off, d
pl
) \
#define SETCALLGATE(gate, ss, off, d) \
{ \
(gate).
gd_
off_15_0 = (uint32_t) (off) & 0xffff; \
(gate).
gd_
ss = (ss); \
(gate).
gd_
args = 0; \
(gate).
gd_
rsv1 = 0; \
(gate).
gd_
type = STS_CG32; \
(gate).
gd_
s = 0; \
(gate).
gd_dpl = (dpl
); \
(gate).
gd_
p = 1; \
(gate).
gd_
off_31_16 = (uint32_t) (off) >> 16; \
(gate).off_15_0 = (uint32_t) (off) & 0xffff; \
(gate).ss = (ss); \
(gate).args = 0; \
(gate).rsv1 = 0; \
(gate).type = STS_CG32; \
(gate).s = 0; \
(gate).
dpl = (d
); \
(gate).p = 1; \
(gate).off_31_16 = (uint32_t) (off) >> 16; \
}
// Pseudo-descriptors used for LGDT, LLDT and LIDT instructions.
struct
Pseudodesc
{
uint16_t
pd_
_garbage
;
// LGDT supposed to be from address 4N+2
uint16_t
pd_
lim
;
// Limit
uint32_t
pd_
base
__attribute__
((
packed
));
// Base address
uint16_t
_garbage
;
// LGDT supposed to be from address 4N+2
uint16_t
lim
;
// Limit
uint32_t
base
__attribute__
((
packed
));
// Base address
};
#define PD_ADDR(desc) (&(desc).pd_lim)
...
...
proc.c
浏览文件 @
ef2bd07a
...
...
@@ -25,8 +25,8 @@ void
setupsegs
(
struct
proc
*
p
)
{
memset
(
&
p
->
ts
,
0
,
sizeof
(
struct
Taskstate
));
p
->
ts
.
ts_
ss0
=
SEG_KDATA
<<
3
;
p
->
ts
.
ts_
esp0
=
(
unsigned
)(
p
->
kstack
+
KSTACKSIZE
);
p
->
ts
.
ss0
=
SEG_KDATA
<<
3
;
p
->
ts
.
esp0
=
(
unsigned
)(
p
->
kstack
+
KSTACKSIZE
);
// XXX it may be wrong to modify the current segment table!
...
...
@@ -35,12 +35,12 @@ setupsegs(struct proc *p)
p
->
gdt
[
SEG_KDATA
]
=
SEG
(
STA_W
,
0
,
0xffffffff
,
0
);
p
->
gdt
[
SEG_TSS
]
=
SEG16
(
STS_T32A
,
(
unsigned
)
&
p
->
ts
,
sizeof
(
p
->
ts
),
0
);
p
->
gdt
[
SEG_TSS
].
s
d_s
=
0
;
p
->
gdt
[
SEG_TSS
].
s
=
0
;
p
->
gdt
[
SEG_UCODE
]
=
SEG
(
STA_X
|
STA_R
,
(
unsigned
)
p
->
mem
,
p
->
sz
,
3
);
p
->
gdt
[
SEG_UDATA
]
=
SEG
(
STA_W
,
(
unsigned
)
p
->
mem
,
p
->
sz
,
3
);
p
->
gdt_pd
.
pd_
_garbage
=
0
;
p
->
gdt_pd
.
pd_
lim
=
sizeof
(
p
->
gdt
)
-
1
;
p
->
gdt_pd
.
pd_
base
=
(
unsigned
)
p
->
gdt
;
p
->
gdt_pd
.
_garbage
=
0
;
p
->
gdt_pd
.
lim
=
sizeof
(
p
->
gdt
)
-
1
;
p
->
gdt_pd
.
base
=
(
unsigned
)
p
->
gdt
;
}
// Look in the process table for an UNUSED proc.
...
...
@@ -107,12 +107,12 @@ copyproc(struct proc* p)
*
np
->
tf
=
*
p
->
tf
;
// Clear %eax so that fork system call returns 0 in child.
np
->
tf
->
tf_regs
.
reg_
eax
=
0
;
np
->
tf
->
regs
.
eax
=
0
;
// Set up new jmpbuf to start executing at forkret (see below).
memset
(
&
np
->
jmpbuf
,
0
,
sizeof
np
->
jmpbuf
);
np
->
jmpbuf
.
jb_
eip
=
(
unsigned
)
forkret
;
np
->
jmpbuf
.
jb_
esp
=
(
unsigned
)
np
->
tf
;
np
->
jmpbuf
.
eip
=
(
unsigned
)
forkret
;
np
->
jmpbuf
.
esp
=
(
unsigned
)
np
->
tf
;
// Copy file descriptors
for
(
i
=
0
;
i
<
NOFILE
;
i
++
){
...
...
@@ -153,13 +153,13 @@ scheduler(void)
// It can run on the other stack.
// h/w sets busy bit in TSS descriptor sometimes, and faults
// if it's set in LTR. so clear tss descriptor busy bit.
p
->
gdt
[
SEG_TSS
].
sd_
type
=
STS_T32A
;
p
->
gdt
[
SEG_TSS
].
type
=
STS_T32A
;
// XXX should probably have an lgdt() function in x86.h
// to confine all the inline assembly.
// 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"
(
p
->
gdt_pd
.
pd_
lim
));
asm
volatile
(
"lgdt %0"
:
:
"g"
(
p
->
gdt_pd
.
lim
));
ltr
(
SEG_TSS
<<
3
);
// Switch to chosen process. It is the process's job
...
...
proc.h
浏览文件 @
ef2bd07a
...
...
@@ -22,15 +22,15 @@ struct jmpbuf {
// they are constant across kernel contexts
// save all the regular registers so we don't care which are caller save
// don't save eax because that's the return register
// layout known to s
wtch
.S
int
jb_
ebx
;
int
jb_
ecx
;
int
jb_
edx
;
int
jb_
esi
;
int
jb_
edi
;
int
jb_
esp
;
int
jb_
ebp
;
int
jb_
eip
;
// layout known to s
etjmp
.S
int
ebx
;
int
ecx
;
int
edx
;
int
esi
;
int
edi
;
int
esp
;
int
ebp
;
int
eip
;
};
enum
proc_state
{
UNUSED
,
EMBRYO
,
SLEEPING
,
RUNNABLE
,
RUNNING
,
ZOMBIE
};
...
...
syscall.c
浏览文件 @
ef2bd07a
...
...
@@ -51,7 +51,7 @@ fetcharg(int argno, void *ip)
{
unsigned
esp
;
esp
=
(
unsigned
)
curproc
[
cpu
()]
->
tf
->
tf_
esp
;
esp
=
(
unsigned
)
curproc
[
cpu
()]
->
tf
->
esp
;
return
fetchint
(
curproc
[
cpu
()],
esp
+
4
+
4
*
argno
,
ip
);
}
...
...
@@ -263,7 +263,7 @@ void
syscall
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
int
num
=
cp
->
tf
->
tf_regs
.
reg_
eax
;
int
num
=
cp
->
tf
->
regs
.
eax
;
int
ret
=
-
1
;
//cprintf("%x sys %d\n", cp, num);
...
...
@@ -301,10 +301,13 @@ syscall(void)
case
SYS_panic
:
ret
=
sys_panic
();
break
;
case
SYS_cons_puts
:
ret
=
sys_cons_puts
();
break
;
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
break
;
}
cp
->
tf
->
tf_regs
.
reg_
eax
=
ret
;
cp
->
tf
->
regs
.
eax
=
ret
;
}
trap.c
浏览文件 @
ef2bd07a
...
...
@@ -28,17 +28,17 @@ tvinit()
void
idtinit
()
{
asm
volatile
(
"lidt %0"
:
:
"g"
(
idt_pd
.
pd_
lim
));
asm
volatile
(
"lidt %0"
:
:
"g"
(
idt_pd
.
lim
));
}
void
trap
(
struct
Trapframe
*
tf
)
{
int
v
=
tf
->
t
f_t
rapno
;
int
v
=
tf
->
trapno
;
if
(
v
==
T_SYSCALL
){
struct
proc
*
cp
=
curproc
[
cpu
()];
int
num
=
cp
->
tf
->
tf_regs
.
reg_
eax
;
int
num
=
cp
->
tf
->
regs
.
eax
;
if
(
cp
==
0
)
panic
(
"syscall with no proc"
);
if
(
cp
->
killed
)
...
...
@@ -78,7 +78,7 @@ trap(struct Trapframe *tf)
// (If the kernel was executing at time of interrupt,
// don't kill the process. Let the process get back
// out to its regular system call return.)
if
((
tf
->
tf_
cs
&
3
)
==
3
&&
cp
->
killed
)
if
((
tf
->
cs
&
3
)
==
3
&&
cp
->
killed
)
proc_exit
();
// Force process to give up CPU and let others run.
...
...
x86.h
浏览文件 @
ef2bd07a
...
...
@@ -320,33 +320,33 @@ sti(void)
struct
PushRegs
{
/* registers as pushed by pusha */
uint32_t
reg_
edi
;
uint32_t
reg_
esi
;
uint32_t
reg_
ebp
;
uint32_t
reg_
oesp
;
/* Useless */
uint32_t
reg_
ebx
;
uint32_t
reg_
edx
;
uint32_t
reg_
ecx
;
uint32_t
reg_
eax
;
uint32_t
edi
;
uint32_t
esi
;
uint32_t
ebp
;
uint32_t
oesp
;
/* Useless */
uint32_t
ebx
;
uint32_t
edx
;
uint32_t
ecx
;
uint32_t
eax
;
};
struct
Trapframe
{
struct
PushRegs
tf_
regs
;
uint16_t
tf_
es
;
uint16_t
tf_
padding1
;
uint16_t
tf_
ds
;
uint16_t
tf_
padding2
;
uint32_t
t
f_t
rapno
;
struct
PushRegs
regs
;
uint16_t
es
;
uint16_t
padding1
;
uint16_t
ds
;
uint16_t
padding2
;
uint32_t
trapno
;
/* below here defined by x86 hardware */
uint32_t
tf_
err
;
uintptr_t
tf_
eip
;
uint16_t
tf_
cs
;
uint16_t
tf_
padding3
;
uint32_t
tf_
eflags
;
uint32_t
err
;
uintptr_t
eip
;
uint16_t
cs
;
uint16_t
padding3
;
uint32_t
eflags
;
/* below here only when crossing rings, such as from user to kernel */
uintptr_t
tf_
esp
;
uint16_t
tf_
ss
;
uint16_t
tf_
padding4
;
uintptr_t
esp
;
uint16_t
ss
;
uint16_t
padding4
;
};
#define MAX_IRQS 16 // Number of IRQs
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论