Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
a4b213cf
提交
a4b213cf
8月 15, 2011
创建
作者:
Frans Kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid "boot" in xv6
上级
94496468
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
43 行增加
和
51 行删除
+43
-51
Makefile
Makefile
+1
-1
defs.h
defs.h
+1
-1
entry.S
entry.S
+5
-5
entryother.S
entryother.S
+5
-5
kalloc.c
kalloc.c
+3
-3
lapic.c
lapic.c
+2
-2
main.c
main.c
+21
-29
mp.c
mp.c
+1
-1
proc.h
proc.h
+1
-1
sysproc.c
sysproc.c
+1
-1
vm.c
vm.c
+2
-2
没有找到文件。
Makefile
浏览文件 @
a4b213cf
...
@@ -110,7 +110,7 @@ initcode: initcode.S
...
@@ -110,7 +110,7 @@ initcode: initcode.S
$(OBJDUMP)
-S
initcode.o
>
initcode.asm
$(OBJDUMP)
-S
initcode.o
>
initcode.asm
kernel
:
$(OBJS) entry.o data.o entryother initcode
kernel
:
$(OBJS) entry.o data.o entryother initcode
$(LD)
$(LDFLAGS)
-T
kernel.ld
-e
multiboot_
entry
-o
kernel entry.o data.o
$(OBJS)
-b
binary initcode entryother
$(LD)
$(LDFLAGS)
-T
kernel.ld
-e
entry
-o
kernel entry.o data.o
$(OBJS)
-b
binary initcode entryother
$(OBJDUMP)
-S
kernel
>
kernel.asm
$(OBJDUMP)
-S
kernel
>
kernel.asm
$(OBJDUMP)
-t
kernel |
sed
'1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d'
>
kernel.sym
$(OBJDUMP)
-t
kernel |
sed
'1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d'
>
kernel.sym
...
...
defs.h
浏览文件 @
a4b213cf
...
@@ -62,7 +62,7 @@ extern uchar ioapicid;
...
@@ -62,7 +62,7 @@ extern uchar ioapicid;
void
ioapicinit
(
void
);
void
ioapicinit
(
void
);
// kalloc.c
// kalloc.c
char
*
boot
_alloc
(
void
);
char
*
enter
_alloc
(
void
);
char
*
kalloc
(
void
);
char
*
kalloc
(
void
);
void
kfree
(
char
*
);
void
kfree
(
char
*
);
void
kinit
(
void
);
void
kinit
(
void
);
...
...
entry.S
浏览文件 @
a4b213cf
...
@@ -34,17 +34,17 @@ multiboot_header:
...
@@ -34,17 +34,17 @@ multiboot_header:
.long multiboot_header
.long multiboot_header
.long edata
.long edata
.long end
.long end
.long
multiboot_
entry
.long entry
#
Multiboot entry point
. Machine is mostly set up.
#
Entering xv6 on boot processor
. Machine is mostly set up.
.globl
multiboot_
entry
.globl entry
multiboot_
entry:
entry:
# Turn on page size extension for 4Mbyte pages
# Turn on page size extension for 4Mbyte pages
movl %cr4, %eax
movl %cr4, %eax
orl $(CR4_PSE), %eax
orl $(CR4_PSE), %eax
movl %eax, %cr4
movl %eax, %cr4
# Set page directory
# Set page directory
movl $(V2P_WO(
boot
pgdir)), %eax
movl $(V2P_WO(
enter
pgdir)), %eax
movl %eax, %cr3
movl %eax, %cr3
# Turn on paging.
# Turn on paging.
movl %cr0, %eax
movl %cr0, %eax
...
...
entryother.S
浏览文件 @
a4b213cf
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
# Bootothers (in main.c) sends the STARTUPs one at a time.
# Bootothers (in main.c) sends the STARTUPs one at a time.
# It copies this code (start) at 0x7000.
# It copies this code (start) at 0x7000.
# It puts the address of a newly allocated per-core stack in start-4,
# It puts the address of a newly allocated per-core stack in start-4,
# the address of the place to jump to (mp
boot
) in start-8, and the physical
# the address of the place to jump to (mp
enter
) in start-8, and the physical
# address of
boot
pgdir in start-12.
# address of
enter
pgdir in start-12.
#
#
#
#
# This code is identical to bootasm.S except:
# This code is identical to bootasm.S except:
...
@@ -54,7 +54,7 @@ start32:
...
@@ -54,7 +54,7 @@ start32:
movl %cr4, %eax
movl %cr4, %eax
orl $(CR4_PSE), %eax
orl $(CR4_PSE), %eax
movl %eax, %cr4
movl %eax, %cr4
# Use
boot
pgdir as our initial page table
# Use
enter
pgdir as our initial page table
movl (start-12), %eax
movl (start-12), %eax
movl %eax, %cr3
movl %eax, %cr3
# Turn on paging.
# Turn on paging.
...
@@ -62,9 +62,9 @@ start32:
...
@@ -62,9 +62,9 @@ start32:
orl $(CR0_PE|CR0_PG|CR0_WP), %eax
orl $(CR0_PE|CR0_PG|CR0_WP), %eax
movl %eax, %cr0
movl %eax, %cr0
# Switch to the stack allocated by
enter
others()
# Switch to the stack allocated by
start
others()
movl (start-4), %esp
movl (start-4), %esp
# Call mp
boot
()
# Call mp
enter
()
call *(start-8)
call *(start-8)
movw $0x8a00, %ax
movw $0x8a00, %ax
...
...
kalloc.c
浏览文件 @
a4b213cf
...
@@ -21,15 +21,15 @@ struct {
...
@@ -21,15 +21,15 @@ struct {
extern
char
end
[];
// first address after kernel loaded from ELF file
extern
char
end
[];
// first address after kernel loaded from ELF file
char
*
newend
;
char
*
newend
;
// simple page allocator to get off the ground during
boot
// simple page allocator to get off the ground during
entry
char
*
char
*
boot
_alloc
(
void
)
enter
_alloc
(
void
)
{
{
if
(
newend
==
0
)
if
(
newend
==
0
)
newend
=
end
;
newend
=
end
;
if
((
uint
)
newend
>=
KERNBASE
+
0x400000
)
if
((
uint
)
newend
>=
KERNBASE
+
0x400000
)
panic
(
"only first 4Mbyte are mapped during
boot
"
);
panic
(
"only first 4Mbyte are mapped during
entry
"
);
void
*
p
=
(
void
*
)
PGROUNDUP
((
uint
)
newend
);
void
*
p
=
(
void
*
)
PGROUNDUP
((
uint
)
newend
);
memset
(
p
,
0
,
PGSIZE
);
memset
(
p
,
0
,
PGSIZE
);
newend
=
newend
+
PGSIZE
;
newend
=
newend
+
PGSIZE
;
...
...
lapic.c
浏览文件 @
a4b213cf
...
@@ -132,7 +132,7 @@ microdelay(int us)
...
@@ -132,7 +132,7 @@ microdelay(int us)
#define IO_RTC 0x70
#define IO_RTC 0x70
// Start additional processor running
bootstrap
code at addr.
// Start additional processor running
entry
code at addr.
// See Appendix B of MultiProcessor Specification.
// See Appendix B of MultiProcessor Specification.
void
void
...
@@ -158,7 +158,7 @@ lapicstartap(uchar apicid, uint addr)
...
@@ -158,7 +158,7 @@ lapicstartap(uchar apicid, uint addr)
lapicw
(
ICRLO
,
INIT
|
LEVEL
);
lapicw
(
ICRLO
,
INIT
|
LEVEL
);
microdelay
(
100
);
// should be 10ms, but too slow in Bochs!
microdelay
(
100
);
// should be 10ms, but too slow in Bochs!
// Send startup IPI (twice!) to enter
bootstrap
code.
// Send startup IPI (twice!) to enter code.
// Regular hardware is supposed to only accept a STARTUP
// Regular hardware is supposed to only accept a STARTUP
// when it is in the halted state due to an INIT. So the second
// when it is in the halted state due to an INIT. So the second
// should be ignored, but it is part of the official Intel algorithm.
// should be ignored, but it is part of the official Intel algorithm.
...
...
main.c
浏览文件 @
a4b213cf
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include "proc.h"
#include "proc.h"
#include "x86.h"
#include "x86.h"
static
void
enter
others
(
void
);
static
void
start
others
(
void
);
static
void
mpmain
(
void
)
__attribute__
((
noreturn
));
static
void
mpmain
(
void
)
__attribute__
((
noreturn
));
extern
pde_t
*
kpgdir
;
extern
pde_t
*
kpgdir
;
...
@@ -33,7 +33,7 @@ main(void)
...
@@ -33,7 +33,7 @@ main(void)
ideinit
();
// disk
ideinit
();
// disk
if
(
!
ismp
)
if
(
!
ismp
)
timerinit
();
// uniprocessor timer
timerinit
();
// uniprocessor timer
enterothers
();
// start other processors (must come before kinit; must use boot
_alloc)
startothers
();
// start other processors (must come before kinit; must use enter
_alloc)
kinit
();
// initialize memory allocator
kinit
();
// initialize memory allocator
userinit
();
// first user process (must come after kinit)
userinit
();
// first user process (must come after kinit)
// Finish setting up this processor in mpmain.
// Finish setting up this processor in mpmain.
...
@@ -42,7 +42,7 @@ main(void)
...
@@ -42,7 +42,7 @@ main(void)
// Other CPUs jump here from entryother.S.
// Other CPUs jump here from entryother.S.
static
void
static
void
mp
boot
(
void
)
mp
enter
(
void
)
{
{
switchkvm
();
switchkvm
();
seginit
();
seginit
();
...
@@ -56,22 +56,22 @@ mpmain(void)
...
@@ -56,22 +56,22 @@ mpmain(void)
{
{
cprintf
(
"cpu%d: starting
\n
"
,
cpu
->
id
);
cprintf
(
"cpu%d: starting
\n
"
,
cpu
->
id
);
idtinit
();
// load idt register
idtinit
();
// load idt register
xchg
(
&
cpu
->
booted
,
1
);
// tell enter
others() we're up
xchg
(
&
cpu
->
started
,
1
);
// tell start
others() we're up
scheduler
();
// start running processes
scheduler
();
// start running processes
}
}
pde_t
boot
pgdir
[];
pde_t
enter
pgdir
[];
// Start the non-boot processors.
// Start the non-boot
(AP)
processors.
static
void
static
void
enter
others
(
void
)
start
others
(
void
)
{
{
extern
uchar
_binary_entryother_start
[],
_binary_entryother_size
[];
extern
uchar
_binary_entryother_start
[],
_binary_entryother_size
[];
uchar
*
code
;
uchar
*
code
;
struct
cpu
*
c
;
struct
cpu
*
c
;
char
*
stack
;
char
*
stack
;
// Write
bootstrap
code to unused memory at 0x7000.
// Write
entry
code to unused memory at 0x7000.
// The linker has placed the image of entryother.S in
// The linker has placed the image of entryother.S in
// _binary_entryother_start.
// _binary_entryother_start.
code
=
p2v
(
0x7000
);
code
=
p2v
(
0x7000
);
...
@@ -81,44 +81,36 @@ enterothers(void)
...
@@ -81,44 +81,36 @@ enterothers(void)
if
(
c
==
cpus
+
cpunum
())
// We've started already.
if
(
c
==
cpus
+
cpunum
())
// We've started already.
continue
;
continue
;
// Tell entryother.S what stack to use, the address of mp
boot
and pgdir;
// Tell entryother.S what stack to use, the address of mp
enter
and pgdir;
// We cannot use kpgdir yet, because the AP processor is running in low
// We cannot use kpgdir yet, because the AP processor is running in low
// memory, so we use
boot
pgdir for the APs too. kalloc can return addresses
// memory, so we use
enter
pgdir for the APs too. kalloc can return addresses
// above 4Mbyte (the machine may have much more physical memory than 4Mbyte), which
// above 4Mbyte (the machine may have much more physical memory than 4Mbyte), which
// aren't mapped by
bootpgdir, so we must allocate a stack using boot
_alloc();
// aren't mapped by
enterpgdir, so we must allocate a stack using enter
_alloc();
// This introduces the constraint that xv6 cannot use kalloc until after these
// This introduces the constraint that xv6 cannot use kalloc until after these
// last
boot
_alloc invocations.
// last
enter
_alloc invocations.
stack
=
boot
_alloc
();
stack
=
enter
_alloc
();
*
(
void
**
)(
code
-
4
)
=
stack
+
KSTACKSIZE
;
*
(
void
**
)(
code
-
4
)
=
stack
+
KSTACKSIZE
;
*
(
void
**
)(
code
-
8
)
=
mp
boot
;
*
(
void
**
)(
code
-
8
)
=
mp
enter
;
*
(
int
**
)(
code
-
12
)
=
(
void
*
)
v2p
(
boot
pgdir
);
*
(
int
**
)(
code
-
12
)
=
(
void
*
)
v2p
(
enter
pgdir
);
lapicstartap
(
c
->
id
,
v2p
(
code
));
lapicstartap
(
c
->
id
,
v2p
(
code
));
// wait for cpu to finish mpmain()
// wait for cpu to finish mpmain()
while
(
c
->
boo
ted
==
0
)
while
(
c
->
star
ted
==
0
)
;
;
}
}
}
}
// Boot page table used in
multiboot
.S and entryother.S.
// Boot page table used in
entry
.S and entryother.S.
// Page directories (and page tables), must start on a page boundary,
// Page directories (and page tables), must start on a page boundary,
// hence the "__aligned__" attribute. Also, because of restrictions
// hence the "__aligned__" attribute.
// related to linking and static initializers, we use "x + PTE_P"
// here, rather than the more standard "x | PTE_P". Everywhere else
// you should use "|" to combine flags.
// Use PTE_PS in page directory entry to enable 4Mbyte pages.
// Use PTE_PS in page directory entry to enable 4Mbyte pages.
pte_t
dev_pgtable
[
NPTENTRIES
];
pte_t
entry_pgtable
[
NPTENTRIES
];
__attribute__
((
__aligned__
(
PGSIZE
)))
__attribute__
((
__aligned__
(
PGSIZE
)))
pde_t
boot
pgdir
[
NPDENTRIES
]
=
{
pde_t
enter
pgdir
[
NPDENTRIES
]
=
{
// Map VA's [0, 4MB) to PA's [0, 4MB)
// Map VA's [0, 4MB) to PA's [0, 4MB)
[
0
]
[
0
]
=
(
0
)
+
PTE_P
+
PTE_W
+
PTE_PS
,
=
(
0
)
+
PTE_P
+
PTE_W
+
PTE_PS
,
// Map VA's [KERNBASE, KERNBASE+4MB) to PA's [0, 4MB)
// Map VA's [KERNBASE, KERNBASE+4MB) to PA's [0, 4MB)
[
KERNBASE
>>
PDXSHIFT
]
[
KERNBASE
>>
PDXSHIFT
]
=
(
0
)
+
PTE_P
+
PTE_W
+
PTE_PS
,
=
(
0
)
+
PTE_P
+
PTE_W
+
PTE_PS
,
};
};
//PAGEBREAK!
//PAGEBREAK!
...
...
mp.c
浏览文件 @
a4b213cf
// Multiprocessor
bootstrap.
// Multiprocessor
support
// Search memory for MP description structures.
// Search memory for MP description structures.
// http://developer.intel.com/design/pentium/datashts/24201606.pdf
// http://developer.intel.com/design/pentium/datashts/24201606.pdf
...
...
proc.h
浏览文件 @
a4b213cf
...
@@ -7,7 +7,7 @@ struct cpu {
...
@@ -7,7 +7,7 @@ struct cpu {
struct
context
*
scheduler
;
// swtch() here to enter scheduler
struct
context
*
scheduler
;
// swtch() here to enter scheduler
struct
taskstate
ts
;
// Used by x86 to find stack for interrupt
struct
taskstate
ts
;
// Used by x86 to find stack for interrupt
struct
segdesc
gdt
[
NSEGS
];
// x86 global descriptor table
struct
segdesc
gdt
[
NSEGS
];
// x86 global descriptor table
volatile
uint
boo
ted
;
// Has the CPU started?
volatile
uint
star
ted
;
// Has the CPU started?
int
ncli
;
// Depth of pushcli nesting.
int
ncli
;
// Depth of pushcli nesting.
int
intena
;
// Were interrupts enabled before pushcli?
int
intena
;
// Were interrupts enabled before pushcli?
...
...
sysproc.c
浏览文件 @
a4b213cf
...
@@ -77,7 +77,7 @@ sys_sleep(void)
...
@@ -77,7 +77,7 @@ sys_sleep(void)
}
}
// return how many clock tick interrupts have occurred
// return how many clock tick interrupts have occurred
// since
boo
t.
// since
star
t.
int
int
sys_uptime
(
void
)
sys_uptime
(
void
)
{
{
...
...
vm.c
浏览文件 @
a4b213cf
...
@@ -12,7 +12,7 @@ pde_t *kpgdir; // for use in scheduler()
...
@@ -12,7 +12,7 @@ pde_t *kpgdir; // for use in scheduler()
struct
segdesc
gdt
[
NSEGS
];
struct
segdesc
gdt
[
NSEGS
];
// Set up CPU's kernel segment descriptors.
// Set up CPU's kernel segment descriptors.
// Run once
at boot time
on each CPU.
// Run once
on entry
on each CPU.
void
void
seginit
(
void
)
seginit
(
void
)
{
{
...
@@ -146,7 +146,7 @@ setupkvm(char* (*alloc)(void))
...
@@ -146,7 +146,7 @@ setupkvm(char* (*alloc)(void))
void
void
kvmalloc
(
void
)
kvmalloc
(
void
)
{
{
kpgdir
=
setupkvm
(
boot
_alloc
);
kpgdir
=
setupkvm
(
enter
_alloc
);
switchkvm
();
switchkvm
();
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论