Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
b5f17007
提交
b5f17007
7月 17, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
standarize on unix-like lowercase struct names
上级
e0966f45
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
59 行增加
和
59 行删除
+59
-59
bootmain.c
bootmain.c
+3
-3
elf.h
elf.h
+2
-2
main.c
main.c
+6
-6
mmu.h
mmu.h
+7
-7
mp.c
mp.c
+20
-20
mp.h
mp.h
+6
-6
proc.c
proc.c
+3
-3
proc.h
proc.h
+3
-3
trap.c
trap.c
+2
-2
x86.h
x86.h
+7
-7
没有找到文件。
bootmain.c
浏览文件 @
b5f17007
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
**********************************************************************/
**********************************************************************/
#define SECTSIZE 512
#define SECTSIZE 512
#define ELFHDR ((struct
Elf
*) 0x10000) // scratch space
#define ELFHDR ((struct
elfhdr
*) 0x10000) // scratch space
void
readsect
(
void
*
,
uint32_t
);
void
readsect
(
void
*
,
uint32_t
);
void
readseg
(
uint32_t
,
uint32_t
,
uint32_t
);
void
readseg
(
uint32_t
,
uint32_t
,
uint32_t
);
...
@@ -39,7 +39,7 @@ void readseg(uint32_t, uint32_t, uint32_t);
...
@@ -39,7 +39,7 @@ void readseg(uint32_t, uint32_t, uint32_t);
void
void
cmain
(
void
)
cmain
(
void
)
{
{
struct
P
roghdr
*
ph
,
*
eph
;
struct
p
roghdr
*
ph
,
*
eph
;
// read 1st page off disk
// read 1st page off disk
readseg
((
uint32_t
)
ELFHDR
,
SECTSIZE
*
8
,
0
);
readseg
((
uint32_t
)
ELFHDR
,
SECTSIZE
*
8
,
0
);
...
@@ -49,7 +49,7 @@ cmain(void)
...
@@ -49,7 +49,7 @@ cmain(void)
goto
bad
;
goto
bad
;
// load each program segment (ignores ph flags)
// load each program segment (ignores ph flags)
ph
=
(
struct
P
roghdr
*
)
((
uint8_t
*
)
ELFHDR
+
ELFHDR
->
phoff
);
ph
=
(
struct
p
roghdr
*
)
((
uint8_t
*
)
ELFHDR
+
ELFHDR
->
phoff
);
eph
=
ph
+
ELFHDR
->
phnum
;
eph
=
ph
+
ELFHDR
->
phnum
;
for
(;
ph
<
eph
;
ph
++
)
for
(;
ph
<
eph
;
ph
++
)
readseg
(
ph
->
va
,
ph
->
memsz
,
ph
->
offset
);
readseg
(
ph
->
va
,
ph
->
memsz
,
ph
->
offset
);
...
...
elf.h
浏览文件 @
b5f17007
#define ELF_MAGIC 0x464C457FU
/* "\x7FELF" in little endian */
#define ELF_MAGIC 0x464C457FU
/* "\x7FELF" in little endian */
struct
Elf
{
struct
elfhdr
{
uint32_t
magic
;
// must equal ELF_MAGIC
uint32_t
magic
;
// must equal ELF_MAGIC
uint8_t
elf
[
12
];
uint8_t
elf
[
12
];
uint16_t
type
;
uint16_t
type
;
...
@@ -18,7 +18,7 @@ struct Elf {
...
@@ -18,7 +18,7 @@ struct Elf {
uint16_t
shstrndx
;
uint16_t
shstrndx
;
};
};
struct
P
roghdr
{
struct
p
roghdr
{
uint32_t
type
;
uint32_t
type
;
uint32_t
offset
;
uint32_t
offset
;
uint32_t
va
;
uint32_t
va
;
...
...
main.c
浏览文件 @
b5f17007
...
@@ -57,8 +57,8 @@ main0(void)
...
@@ -57,8 +57,8 @@ main0(void)
p
->
mem
=
kalloc
(
p
->
sz
);
p
->
mem
=
kalloc
(
p
->
sz
);
memset
(
p
->
mem
,
0
,
p
->
sz
);
memset
(
p
->
mem
,
0
,
p
->
sz
);
p
->
kstack
=
kalloc
(
KSTACKSIZE
);
p
->
kstack
=
kalloc
(
KSTACKSIZE
);
p
->
tf
=
(
struct
Trapframe
*
)
(
p
->
kstack
+
KSTACKSIZE
-
sizeof
(
struct
T
rapframe
));
p
->
tf
=
(
struct
trapframe
*
)
(
p
->
kstack
+
KSTACKSIZE
-
sizeof
(
struct
t
rapframe
));
memset
(
p
->
tf
,
0
,
sizeof
(
struct
T
rapframe
));
memset
(
p
->
tf
,
0
,
sizeof
(
struct
t
rapframe
));
p
->
tf
->
es
=
p
->
tf
->
ds
=
p
->
tf
->
ss
=
(
SEG_UDATA
<<
3
)
|
3
;
p
->
tf
->
es
=
p
->
tf
->
ds
=
p
->
tf
->
ss
=
(
SEG_UDATA
<<
3
)
|
3
;
p
->
tf
->
cs
=
(
SEG_UCODE
<<
3
)
|
3
;
p
->
tf
->
cs
=
(
SEG_UCODE
<<
3
)
|
3
;
p
->
tf
->
eflags
=
FL_IF
;
p
->
tf
->
eflags
=
FL_IF
;
...
@@ -110,11 +110,11 @@ void
...
@@ -110,11 +110,11 @@ void
load_icode
(
struct
proc
*
p
,
uint8_t
*
binary
,
uint
size
)
load_icode
(
struct
proc
*
p
,
uint8_t
*
binary
,
uint
size
)
{
{
int
i
;
int
i
;
struct
Elf
*
elf
;
struct
elfhdr
*
elf
;
struct
P
roghdr
*
ph
;
struct
p
roghdr
*
ph
;
// Check magic number on binary
// Check magic number on binary
elf
=
(
struct
Elf
*
)
binary
;
elf
=
(
struct
elfhdr
*
)
binary
;
cprintf
(
"elf %x magic %x
\n
"
,
elf
,
elf
->
magic
);
cprintf
(
"elf %x magic %x
\n
"
,
elf
,
elf
->
magic
);
if
(
elf
->
magic
!=
ELF_MAGIC
)
if
(
elf
->
magic
!=
ELF_MAGIC
)
panic
(
"load_icode: not an ELF binary"
);
panic
(
"load_icode: not an ELF binary"
);
...
@@ -123,7 +123,7 @@ load_icode(struct proc *p, uint8_t *binary, uint size)
...
@@ -123,7 +123,7 @@ load_icode(struct proc *p, uint8_t *binary, uint size)
p
->
tf
->
esp
=
p
->
sz
;
p
->
tf
->
esp
=
p
->
sz
;
// Map and load segments as directed.
// Map and load segments as directed.
ph
=
(
struct
P
roghdr
*
)
(
binary
+
elf
->
phoff
);
ph
=
(
struct
p
roghdr
*
)
(
binary
+
elf
->
phoff
);
for
(
i
=
0
;
i
<
elf
->
phnum
;
i
++
,
ph
++
)
{
for
(
i
=
0
;
i
<
elf
->
phnum
;
i
++
,
ph
++
)
{
if
(
ph
->
type
!=
ELF_PROG_LOAD
)
if
(
ph
->
type
!=
ELF_PROG_LOAD
)
continue
;
continue
;
...
...
mmu.h
浏览文件 @
b5f17007
...
@@ -60,7 +60,7 @@
...
@@ -60,7 +60,7 @@
#else // not __ASSEMBLER__
#else // not __ASSEMBLER__
// Segment Descriptors
// Segment Descriptors
struct
S
egdesc
{
struct
s
egdesc
{
uint
lim_15_0
:
16
;
// Low bits of segment limit
uint
lim_15_0
:
16
;
// Low bits of segment limit
uint
base_15_0
:
16
;
// Low bits of segment base address
uint
base_15_0
:
16
;
// Low bits of segment base address
uint
base_23_16
:
8
;
// Middle bits of segment base address
uint
base_23_16
:
8
;
// Middle bits of segment base address
...
@@ -76,15 +76,15 @@ struct Segdesc {
...
@@ -76,15 +76,15 @@ struct Segdesc {
uint
base_31_24
:
8
;
// High bits of segment base address
uint
base_31_24
:
8
;
// High bits of segment base address
};
};
// Null segment
// Null segment
#define SEG_NULL (struct
S
egdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
#define SEG_NULL (struct
s
egdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
// Segment that is loadable but faults when used
// Segment that is loadable but faults when used
#define SEG_FAULT (struct
S
egdesc){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
#define SEG_FAULT (struct
s
egdesc){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
// Normal segment
// Normal segment
#define SEG(type, base, lim, dpl) (struct
S
egdesc) \
#define SEG(type, base, lim, dpl) (struct
s
egdesc) \
{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1, \
type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1, \
(uint) (base) >> 24 }
(uint) (base) >> 24 }
#define SEG16(type, base, lim, dpl) (struct
S
egdesc) \
#define SEG16(type, base, lim, dpl) (struct
s
egdesc) \
{ (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
{ (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
(uint) (base) >> 24 }
(uint) (base) >> 24 }
...
@@ -123,7 +123,7 @@ struct Segdesc {
...
@@ -123,7 +123,7 @@ struct Segdesc {
#ifndef __ASSEMBLER__
#ifndef __ASSEMBLER__
// Task state segment format (as described by the Pentium architecture book)
// Task state segment format (as described by the Pentium architecture book)
struct
T
askstate
{
struct
t
askstate
{
uint32_t
link
;
// Old ts selector
uint32_t
link
;
// Old ts selector
uintptr_t
esp0
;
// Stack pointers and segment selectors
uintptr_t
esp0
;
// Stack pointers and segment selectors
uint16_t
ss0
;
// after an increase in privilege level
uint16_t
ss0
;
// after an increase in privilege level
...
@@ -164,7 +164,7 @@ struct Taskstate {
...
@@ -164,7 +164,7 @@ struct Taskstate {
};
};
// Gate descriptors for interrupts and traps
// Gate descriptors for interrupts and traps
struct
G
atedesc
{
struct
g
atedesc
{
uint
off_15_0
:
16
;
// low 16 bits of offset in segment
uint
off_15_0
:
16
;
// low 16 bits of offset in segment
uint
ss
:
16
;
// segment selector
uint
ss
:
16
;
// segment selector
uint
args
:
5
;
// # args, 0 for interrupt/trap gates
uint
args
:
5
;
// # args, 0 for interrupt/trap gates
...
...
mp.c
浏览文件 @
b5f17007
...
@@ -31,12 +31,12 @@ static char* buses[] = {
...
@@ -31,12 +31,12 @@ static char* buses[] = {
#define APBOOTCODE 0x7000 // XXX hack
#define APBOOTCODE 0x7000 // XXX hack
static
struct
MP
*
mp
;
// The MP floating point structure
static
struct
mp
*
mp
;
// The MP floating point structure
struct
cpu
cpus
[
NCPU
];
struct
cpu
cpus
[
NCPU
];
int
ncpu
;
int
ncpu
;
static
struct
cpu
*
bcpu
;
static
struct
cpu
*
bcpu
;
static
struct
MP
*
static
struct
mp
*
mp_scan
(
uint8_t
*
addr
,
int
len
)
mp_scan
(
uint8_t
*
addr
,
int
len
)
{
{
uint8_t
*
e
,
*
p
,
sum
;
uint8_t
*
e
,
*
p
,
sum
;
...
@@ -44,24 +44,24 @@ mp_scan(uint8_t *addr, int len)
...
@@ -44,24 +44,24 @@ mp_scan(uint8_t *addr, int len)
cprintf
(
"scanning: 0x%x
\n
"
,
(
uint32_t
)
addr
);
cprintf
(
"scanning: 0x%x
\n
"
,
(
uint32_t
)
addr
);
e
=
addr
+
len
;
e
=
addr
+
len
;
for
(
p
=
addr
;
p
<
e
;
p
+=
sizeof
(
struct
MP
)){
for
(
p
=
addr
;
p
<
e
;
p
+=
sizeof
(
struct
mp
)){
if
(
memcmp
(
p
,
"_MP_"
,
4
))
if
(
memcmp
(
p
,
"_MP_"
,
4
))
continue
;
continue
;
sum
=
0
;
sum
=
0
;
for
(
i
=
0
;
i
<
sizeof
(
struct
MP
);
i
++
)
for
(
i
=
0
;
i
<
sizeof
(
struct
mp
);
i
++
)
sum
+=
p
[
i
];
sum
+=
p
[
i
];
if
(
sum
==
0
)
if
(
sum
==
0
)
return
(
struct
MP
*
)
p
;
return
(
struct
mp
*
)
p
;
}
}
return
0
;
return
0
;
}
}
static
struct
MP
*
static
struct
mp
*
mp_search
(
void
)
mp_search
(
void
)
{
{
uint8_t
*
bda
;
uint8_t
*
bda
;
uint32_t
p
;
uint32_t
p
;
struct
MP
*
mp
;
struct
mp
*
mp
;
/*
/*
* Search for the MP Floating Pointer Structure, which according to the
* Search for the MP Floating Pointer Structure, which according to the
...
@@ -86,7 +86,7 @@ mp_search(void)
...
@@ -86,7 +86,7 @@ mp_search(void)
static
int
static
int
mp_detect
(
void
)
mp_detect
(
void
)
{
{
struct
MPCTB
*
pcmp
;
struct
mpctb
*
pcmp
;
uint8_t
*
p
,
sum
;
uint8_t
*
p
,
sum
;
uint32_t
length
;
uint32_t
length
;
...
@@ -100,7 +100,7 @@ mp_detect(void)
...
@@ -100,7 +100,7 @@ mp_detect(void)
if
((
mp
=
mp_search
())
==
0
||
mp
->
physaddr
==
0
)
if
((
mp
=
mp_search
())
==
0
||
mp
->
physaddr
==
0
)
return
1
;
return
1
;
pcmp
=
(
struct
MPCTB
*
)
mp
->
physaddr
;
pcmp
=
(
struct
mpctb
*
)
mp
->
physaddr
;
if
(
memcmp
(
pcmp
,
"PCMP"
,
4
))
if
(
memcmp
(
pcmp
,
"PCMP"
,
4
))
return
2
;
return
2
;
...
@@ -121,9 +121,9 @@ mp_init(void)
...
@@ -121,9 +121,9 @@ mp_init(void)
{
{
int
r
;
int
r
;
uint8_t
*
p
,
*
e
;
uint8_t
*
p
,
*
e
;
struct
MPCTB
*
mpctb
;
struct
mpctb
*
mpctb
;
struct
MPPE
*
proc
;
struct
mppe
*
proc
;
struct
MPBE
*
bus
;
struct
mpbe
*
bus
;
int
i
;
int
i
;
ncpu
=
0
;
ncpu
=
0
;
...
@@ -136,40 +136,40 @@ mp_init(void)
...
@@ -136,40 +136,40 @@ mp_init(void)
* application processors and initialising any I/O APICs. The table
* application processors and initialising any I/O APICs. The table
* is guaranteed to be in order such that only one pass is necessary.
* is guaranteed to be in order such that only one pass is necessary.
*/
*/
mpctb
=
(
struct
MPCTB
*
)
mp
->
physaddr
;
mpctb
=
(
struct
mpctb
*
)
mp
->
physaddr
;
lapicaddr
=
(
uint32_t
*
)
mpctb
->
lapicaddr
;
lapicaddr
=
(
uint32_t
*
)
mpctb
->
lapicaddr
;
cprintf
(
"apicaddr: %x
\n
"
,
lapicaddr
);
cprintf
(
"apicaddr: %x
\n
"
,
lapicaddr
);
p
=
((
uint8_t
*
)
mpctb
)
+
sizeof
(
struct
MPCTB
);
p
=
((
uint8_t
*
)
mpctb
)
+
sizeof
(
struct
mpctb
);
e
=
((
uint8_t
*
)
mpctb
)
+
mpctb
->
length
;
e
=
((
uint8_t
*
)
mpctb
)
+
mpctb
->
length
;
while
(
p
<
e
)
{
while
(
p
<
e
)
{
switch
(
*
p
){
switch
(
*
p
){
case
MPPROCESSOR
:
case
MPPROCESSOR
:
proc
=
(
struct
MPPE
*
)
p
;
proc
=
(
struct
mppe
*
)
p
;
cpus
[
ncpu
].
apicid
=
proc
->
apicid
;
cpus
[
ncpu
].
apicid
=
proc
->
apicid
;
cprintf
(
"a processor %x
\n
"
,
cpus
[
ncpu
].
apicid
);
cprintf
(
"a processor %x
\n
"
,
cpus
[
ncpu
].
apicid
);
if
(
proc
->
flags
&
MPBP
)
{
if
(
proc
->
flags
&
MPBP
)
{
bcpu
=
&
cpus
[
ncpu
];
bcpu
=
&
cpus
[
ncpu
];
}
}
ncpu
++
;
ncpu
++
;
p
+=
sizeof
(
struct
MPPE
);
p
+=
sizeof
(
struct
mppe
);
continue
;
continue
;
case
MPBUS
:
case
MPBUS
:
bus
=
(
struct
MPBE
*
)
p
;
bus
=
(
struct
mpbe
*
)
p
;
for
(
i
=
0
;
buses
[
i
];
i
++
){
for
(
i
=
0
;
buses
[
i
];
i
++
){
if
(
strncmp
(
buses
[
i
],
bus
->
string
,
sizeof
(
bus
->
string
))
==
0
)
if
(
strncmp
(
buses
[
i
],
bus
->
string
,
sizeof
(
bus
->
string
))
==
0
)
break
;
break
;
}
}
cprintf
(
"a bus %d
\n
"
,
i
);
cprintf
(
"a bus %d
\n
"
,
i
);
p
+=
sizeof
(
struct
MPBE
);
p
+=
sizeof
(
struct
mpbe
);
continue
;
continue
;
case
MPIOAPIC
:
case
MPIOAPIC
:
cprintf
(
"an I/O APIC
\n
"
);
cprintf
(
"an I/O APIC
\n
"
);
p
+=
sizeof
(
struct
MPIOAPIC
);
p
+=
sizeof
(
struct
mpioapic
);
continue
;
continue
;
case
MPIOINTR
:
case
MPIOINTR
:
cprintf
(
"an I/O intr
\n
"
);
cprintf
(
"an I/O intr
\n
"
);
p
+=
sizeof
(
struct
MPIE
);
p
+=
sizeof
(
struct
mpie
);
continue
;
continue
;
default:
default:
cprintf
(
"mpinit: unknown PCMP type 0x%x (e-p 0x%x)
\n
"
,
*
p
,
e
-
p
);
cprintf
(
"mpinit: unknown PCMP type 0x%x (e-p 0x%x)
\n
"
,
*
p
,
e
-
p
);
...
...
mp.h
浏览文件 @
b5f17007
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* Credit: Plan 9 sources
* Credit: Plan 9 sources
*/
*/
struct
MP
{
/* floating pointer */
struct
mp
{
/* floating pointer */
uint8_t
signature
[
4
];
/* "_MP_" */
uint8_t
signature
[
4
];
/* "_MP_" */
physaddr_t
physaddr
;
/* physical address of MP configuration table */
physaddr_t
physaddr
;
/* physical address of MP configuration table */
uint8_t
length
;
/* 1 */
uint8_t
length
;
/* 1 */
...
@@ -15,7 +15,7 @@ struct MP { /* floating pointer */
...
@@ -15,7 +15,7 @@ struct MP { /* floating pointer */
uint8_t
reserved
[
3
];
uint8_t
reserved
[
3
];
};
};
struct
MPCTB
{
/* configuration table header */
struct
mpctb
{
/* configuration table header */
uint8_t
signature
[
4
];
/* "PCMP" */
uint8_t
signature
[
4
];
/* "PCMP" */
uint16_t
length
;
/* total table length */
uint16_t
length
;
/* total table length */
uint8_t
version
;
/* [14] */
uint8_t
version
;
/* [14] */
...
@@ -30,7 +30,7 @@ struct MPCTB { /* configuration table header */
...
@@ -30,7 +30,7 @@ struct MPCTB { /* configuration table header */
uint8_t
reserved
;
uint8_t
reserved
;
};
};
struct
MPPE
{
/* processor table entry */
struct
mppe
{
/* processor table entry */
uint8_t
type
;
/* entry type (0) */
uint8_t
type
;
/* entry type (0) */
uint8_t
apicid
;
/* local APIC id */
uint8_t
apicid
;
/* local APIC id */
uint8_t
version
;
/* local APIC verison */
uint8_t
version
;
/* local APIC verison */
...
@@ -40,13 +40,13 @@ struct MPPE { /* processor table entry */
...
@@ -40,13 +40,13 @@ struct MPPE { /* processor table entry */
uint8_t
reserved
[
8
];
uint8_t
reserved
[
8
];
};
};
struct
MPBE
{
/* bus table entry */
struct
mpbe
{
/* bus table entry */
uint8_t
type
;
/* entry type (1) */
uint8_t
type
;
/* entry type (1) */
uint8_t
busno
;
/* bus id */
uint8_t
busno
;
/* bus id */
char
string
[
6
];
/* bus type string */
char
string
[
6
];
/* bus type string */
};
};
struct
MPIOAPIC
{
/* I/O APIC table entry */
struct
mpioapic
{
/* I/O APIC table entry */
uint8_t
type
;
/* entry type (2) */
uint8_t
type
;
/* entry type (2) */
uint8_t
apicno
;
/* I/O APIC id */
uint8_t
apicno
;
/* I/O APIC id */
uint8_t
version
;
/* I/O APIC version */
uint8_t
version
;
/* I/O APIC version */
...
@@ -54,7 +54,7 @@ struct MPIOAPIC { /* I/O APIC table entry */
...
@@ -54,7 +54,7 @@ struct MPIOAPIC { /* I/O APIC table entry */
uintptr_t
addr
;
/* I/O APIC address */
uintptr_t
addr
;
/* I/O APIC address */
};
};
struct
MPIE
{
/* interrupt table entry */
struct
mpie
{
/* interrupt table entry */
uint8_t
type
;
/* entry type ([34]) */
uint8_t
type
;
/* entry type ([34]) */
uint8_t
intr
;
/* interrupt type */
uint8_t
intr
;
/* interrupt type */
uint16_t
flags
;
/* interrupt flag */
uint16_t
flags
;
/* interrupt flag */
...
...
proc.c
浏览文件 @
b5f17007
...
@@ -13,7 +13,7 @@ struct proc proc[NPROC];
...
@@ -13,7 +13,7 @@ struct proc proc[NPROC];
struct
proc
*
curproc
[
NCPU
];
struct
proc
*
curproc
[
NCPU
];
int
next_pid
=
1
;
int
next_pid
=
1
;
extern
void
forkret
(
void
);
extern
void
forkret
(
void
);
extern
void
forkret1
(
struct
T
rapframe
*
);
extern
void
forkret1
(
struct
t
rapframe
*
);
/*
/*
* set up a process's task state and segment descriptors
* set up a process's task state and segment descriptors
...
@@ -24,7 +24,7 @@ extern void forkret1(struct Trapframe*);
...
@@ -24,7 +24,7 @@ extern void forkret1(struct Trapframe*);
void
void
setupsegs
(
struct
proc
*
p
)
setupsegs
(
struct
proc
*
p
)
{
{
memset
(
&
p
->
ts
,
0
,
sizeof
(
struct
T
askstate
));
memset
(
&
p
->
ts
,
0
,
sizeof
(
struct
t
askstate
));
p
->
ts
.
ss0
=
SEG_KDATA
<<
3
;
p
->
ts
.
ss0
=
SEG_KDATA
<<
3
;
p
->
ts
.
esp0
=
(
uint
)(
p
->
kstack
+
KSTACKSIZE
);
p
->
ts
.
esp0
=
(
uint
)(
p
->
kstack
+
KSTACKSIZE
);
...
@@ -100,7 +100,7 @@ copyproc(struct proc* p)
...
@@ -100,7 +100,7 @@ copyproc(struct proc* p)
setupsegs
(
np
);
setupsegs
(
np
);
// Copy trapframe registers from parent.
// Copy trapframe registers from parent.
np
->
tf
=
(
struct
T
rapframe
*
)(
np
->
kstack
+
KSTACKSIZE
)
-
1
;
np
->
tf
=
(
struct
t
rapframe
*
)(
np
->
kstack
+
KSTACKSIZE
)
-
1
;
*
np
->
tf
=
*
p
->
tf
;
*
np
->
tf
=
*
p
->
tf
;
// Clear %eax so that fork system call returns 0 in child.
// Clear %eax so that fork system call returns 0 in child.
...
...
proc.h
浏览文件 @
b5f17007
...
@@ -48,14 +48,14 @@ struct proc{
...
@@ -48,14 +48,14 @@ struct proc{
int
killed
;
int
killed
;
struct
fd
*
fds
[
NOFILE
];
struct
fd
*
fds
[
NOFILE
];
struct
T
askstate
ts
;
// only to give cpu address of kernel stack
struct
t
askstate
ts
;
// only to give cpu address of kernel stack
struct
S
egdesc
gdt
[
NSEGS
];
struct
s
egdesc
gdt
[
NSEGS
];
uint
esp
;
// kernel stack pointer
uint
esp
;
// kernel stack pointer
uint
ebp
;
// kernel frame pointer
uint
ebp
;
// kernel frame pointer
struct
jmpbuf
jmpbuf
;
struct
jmpbuf
jmpbuf
;
struct
T
rapframe
*
tf
;
// points into kstack, used to find user regs
struct
t
rapframe
*
tf
;
// points into kstack, used to find user regs
};
};
extern
struct
proc
proc
[];
extern
struct
proc
proc
[];
...
...
trap.c
浏览文件 @
b5f17007
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "traps.h"
#include "traps.h"
#include "syscall.h"
#include "syscall.h"
struct
G
atedesc
idt
[
256
];
struct
g
atedesc
idt
[
256
];
extern
uint
vectors
[];
/* vectors.S, array of 256 entry point addresses */
extern
uint
vectors
[];
/* vectors.S, array of 256 entry point addresses */
extern
void
trapenter
(
void
);
extern
void
trapenter
(
void
);
...
@@ -31,7 +31,7 @@ idtinit(void)
...
@@ -31,7 +31,7 @@ idtinit(void)
}
}
void
void
trap
(
struct
T
rapframe
*
tf
)
trap
(
struct
t
rapframe
*
tf
)
{
{
int
v
=
tf
->
trapno
;
int
v
=
tf
->
trapno
;
...
...
x86.h
浏览文件 @
b5f17007
...
@@ -12,10 +12,10 @@ static __inline void outsw(int port, const void *addr, int cnt) __attribute__((a
...
@@ -12,10 +12,10 @@ static __inline void outsw(int port, const void *addr, int cnt) __attribute__((a
static
__inline
void
outsl
(
int
port
,
const
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outsl
(
int
port
,
const
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outl
(
int
port
,
uint32_t
data
)
__attribute__
((
always_inline
));
static
__inline
void
outl
(
int
port
,
uint32_t
data
)
__attribute__
((
always_inline
));
static
__inline
void
invlpg
(
void
*
addr
)
__attribute__
((
always_inline
));
static
__inline
void
invlpg
(
void
*
addr
)
__attribute__
((
always_inline
));
struct
S
egdesc
;
struct
s
egdesc
;
static
__inline
void
lgdt
(
struct
S
egdesc
*
p
,
int
)
__attribute__
((
always_inline
));
static
__inline
void
lgdt
(
struct
s
egdesc
*
p
,
int
)
__attribute__
((
always_inline
));
struct
G
atedesc
;
struct
g
atedesc
;
static
__inline
void
lidt
(
struct
G
atedesc
*
p
,
int
)
__attribute__
((
always_inline
));
static
__inline
void
lidt
(
struct
g
atedesc
*
p
,
int
)
__attribute__
((
always_inline
));
static
__inline
void
lldt
(
uint16_t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
lldt
(
uint16_t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
ltr
(
uint16_t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
ltr
(
uint16_t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
lcr0
(
uint32_t
val
)
__attribute__
((
always_inline
));
static
__inline
void
lcr0
(
uint32_t
val
)
__attribute__
((
always_inline
));
...
@@ -144,7 +144,7 @@ invlpg(void *addr)
...
@@ -144,7 +144,7 @@ invlpg(void *addr)
}
}
static
__inline
void
static
__inline
void
lgdt
(
struct
S
egdesc
*
p
,
int
size
)
lgdt
(
struct
s
egdesc
*
p
,
int
size
)
{
{
volatile
uint16_t
pd
[
3
];
volatile
uint16_t
pd
[
3
];
...
@@ -156,7 +156,7 @@ lgdt(struct Segdesc *p, int size)
...
@@ -156,7 +156,7 @@ lgdt(struct Segdesc *p, int size)
}
}
static
__inline
void
static
__inline
void
lidt
(
struct
G
atedesc
*
p
,
int
size
)
lidt
(
struct
g
atedesc
*
p
,
int
size
)
{
{
volatile
uint16_t
pd
[
3
];
volatile
uint16_t
pd
[
3
];
...
@@ -339,7 +339,7 @@ sti(void)
...
@@ -339,7 +339,7 @@ sti(void)
__asm__
volatile
(
"sti"
);
__asm__
volatile
(
"sti"
);
}
}
struct
T
rapframe
{
struct
t
rapframe
{
/* registers as pushed by pusha */
/* registers as pushed by pusha */
uint32_t
edi
;
uint32_t
edi
;
uint32_t
esi
;
uint32_t
esi
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论