Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
83ec933a
提交
83ec933a
2月 24, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
-mcmodel=kernel generates somewhat faster and more readable code
上级
d871d353
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
32 行增加
和
25 行删除
+32
-25
kernel.hh
include/kernel.hh
+16
-2
Makefrag
kernel/Makefrag
+2
-2
boot.S
kernel/boot.S
+8
-10
hwvm.cc
kernel/hwvm.cc
+2
-6
kalloc.cc
kernel/kalloc.cc
+3
-4
kernel.ld
kernel/kernel.ld
+1
-1
没有找到文件。
include/kernel.hh
浏览文件 @
83ec933a
...
@@ -8,14 +8,28 @@ extern "C" {
...
@@ -8,14 +8,28 @@ extern "C" {
#include <stdarg.h>
#include <stdarg.h>
#define KBASE 0xFFFFFF0000000000ull
#define KBASE 0xFFFFFF0000000000ull
#define KCODE 0xFFFFFFFFC0000000ull
#define KSHARED 0xFFFFF00000000000ull
#define KSHARED 0xFFFFF00000000000ull
#define USERTOP 0x0000800000000000ull
#define USERTOP 0x0000800000000000ull
#define KCSEG (2<<3)
/* kernel code segment */
#define KCSEG (2<<3)
/* kernel code segment */
#define KDSEG (3<<3)
/* kernel data segment */
#define KDSEG (3<<3)
/* kernel data segment */
static
inline
uptr
v2p
(
void
*
a
)
{
return
(
uptr
)
a
-
KBASE
;
}
static
inline
uptr
v2p
(
void
*
a
)
{
static
inline
void
*
p2v
(
uptr
a
)
{
return
(
u8
*
)
a
+
KBASE
;
}
uptr
ua
=
(
uptr
)
a
;
if
(
ua
>=
KCODE
)
return
ua
-
KCODE
;
else
return
ua
-
KBASE
;
}
static
inline
void
*
p2v
(
uptr
a
)
{
uptr
ac
=
a
+
KCODE
;
if
(
ac
>=
KCODE
)
return
(
void
*
)
ac
;
else
return
(
u8
*
)
a
+
KBASE
;
}
struct
trapframe
;
struct
trapframe
;
struct
cilkframe
;
struct
cilkframe
;
...
...
kernel/Makefrag
浏览文件 @
83ec933a
...
@@ -63,8 +63,8 @@ $(O)/kernel/%.o: lib/%.cc
...
@@ -63,8 +63,8 @@ $(O)/kernel/%.o: lib/%.cc
$(Q)mkdir -p $(@D)
$(Q)mkdir -p $(@D)
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
$(O)/kernel/%.o: CFLAGS+=-mcmodel=
large
$(O)/kernel/%.o: CFLAGS+=-mcmodel=
kernel
$(O)/kernel/%.o: CXXFLAGS+=-mcmodel=
large
$(O)/kernel/%.o: CXXFLAGS+=-mcmodel=
kernel
$(O)/kernel/incbin.o: ASFLAGS+=-DMAKE_OUT=$(O)
$(O)/kernel/incbin.o: ASFLAGS+=-DMAKE_OUT=$(O)
$(O)/kernel/incbin.o: $(O)/kernel/initcode $(O)/kernel/bootother $(O)/fs.img
$(O)/kernel/incbin.o: $(O)/kernel/initcode $(O)/kernel/bootother $(O)/fs.img
...
...
kernel/boot.S
浏览文件 @
83ec933a
...
@@ -6,17 +6,17 @@
...
@@ -6,17 +6,17 @@
#include "mmu.h"
#include "mmu.h"
# KADDR is the kernel virtual address of the first byte of physical memory.
# KADDR is the kernel virtual address of the first byte of physical memory.
# The linker loads the executable as if starting at K
BAS
E+2MB, but we
# The linker loads the executable as if starting at K
COD
E+2MB, but we
# ask the loader to load the kernel at physical 2MB and then set up the
# ask the loader to load the kernel at physical 2MB and then set up the
# necessary memory mapping to switch to the higher address.
# necessary memory mapping to switch to the higher address.
# The value of K
BAS
E must match the definitions in kernel.h and kernel.ld.
# The value of K
COD
E must match the definitions in kernel.h and kernel.ld.
#define K
BASE 0xFFFFFF000
0000000
#define K
CODE 0xFFFFFFFFC
0000000
# PADDR(x) is the physical memory address corresponding to x.
# PADDR(x) is the physical memory address corresponding to x.
# Until we set up the memory map, fairly late in this file, we have to
# Until we set up the memory map, fairly late in this file, we have to
# refer to PADDR(symbol) instead of symbol, so that we use the
# refer to PADDR(symbol) instead of symbol, so that we use the
# physical address.
# physical address.
#define PADDR(x) ((x) - K
BAS
E)
#define PADDR(x) ((x) - K
COD
E)
# STACK is the size of the bootstrap stack.
# STACK is the size of the bootstrap stack.
#define STACK 8192
#define STACK 8192
...
@@ -126,7 +126,7 @@ tramp64:
...
@@ -126,7 +126,7 @@ tramp64:
# running at PADDR(tramp64), so use an explicit calculation to
# running at PADDR(tramp64), so use an explicit calculation to
# load and jump to the correct address. %rax should hold the
# load and jump to the correct address. %rax should hold the
# physical address of the jmp target.
# physical address of the jmp target.
movq $K
BAS
E, %r11
movq $K
COD
E, %r11
addq %r11, %rax
addq %r11, %rax
jmp *%rax
jmp *%rax
...
@@ -134,7 +134,7 @@ tramp64:
...
@@ -134,7 +134,7 @@ tramp64:
.comm stack, STACK
.comm stack, STACK
# Page tables. See section 4.5 of 253668.pdf.
# Page tables. See section 4.5 of 253668.pdf.
# We map the first GB of physical memory at 0 and at K
BAS
E. At boot
# We map the first GB of physical memory at 0 and at K
COD
E. At boot
# time we are using the mapping at 0 but during ordinary execution we
# time we are using the mapping at 0 but during ordinary execution we
# use the high mapping.
# use the high mapping.
# The intent is that after bootstrap the kernel can expand this mapping
# The intent is that after bootstrap the kernel can expand this mapping
...
@@ -145,10 +145,8 @@ tramp64:
...
@@ -145,10 +145,8 @@ tramp64:
.global kpml4
.global kpml4
kpml4:
kpml4:
.quad PADDR(pdpt0) + (1<<0) + (1<<1) // present, read/write
.quad PADDR(pdpt0) + (1<<0) + (1<<1) // present, read/write
.quad 0
.space 4096 - 2*8
.space 4096 - 2*16
.quad PADDR(pdpt1) + (1<<0) + (1<<1) // present, read/write
.quad PADDR(pdpt1) + (1<<0) + (1<<1) // present, read/write
.quad 0
.align 4096
.align 4096
pdpt0:
pdpt0:
.quad PADDR(pdt) + (1<<0) + (1<<1) // present, read/write
.quad PADDR(pdt) + (1<<0) + (1<<1) // present, read/write
...
@@ -156,8 +154,8 @@ pdpt0:
...
@@ -156,8 +154,8 @@ pdpt0:
.align 4096
.align 4096
pdpt1:
pdpt1:
.quad PADDR(pdt) + (1<<0) + (1<<1) // present, read/write
.space 4096 - 8
.space 4096 - 8
.quad PADDR(pdt) + (1<<0) + (1<<1) // present, read/write
.align 4096
.align 4096
pdt:
pdt:
...
...
kernel/hwvm.cc
浏览文件 @
83ec933a
...
@@ -63,7 +63,6 @@ walkpgdir(pgmap *pml4, u64 va, int create)
...
@@ -63,7 +63,6 @@ walkpgdir(pgmap *pml4, u64 va, int create)
void
void
initpg
(
void
)
initpg
(
void
)
{
{
extern
char
end
[];
u64
va
=
KBASE
;
u64
va
=
KBASE
;
paddr
pa
=
0
;
paddr
pa
=
0
;
...
@@ -71,12 +70,9 @@ initpg(void)
...
@@ -71,12 +70,9 @@ initpg(void)
auto
pdp
=
descend
(
&
kpml4
,
va
,
0
,
1
,
3
);
auto
pdp
=
descend
(
&
kpml4
,
va
,
0
,
1
,
3
);
auto
pd
=
descend
(
pdp
,
va
,
0
,
1
,
2
);
auto
pd
=
descend
(
pdp
,
va
,
0
,
1
,
2
);
atomic
<
pme_t
>
*
sp
=
&
pd
->
e
[
PX
(
1
,
va
)];
atomic
<
pme_t
>
*
sp
=
&
pd
->
e
[
PX
(
1
,
va
)];
u64
flags
=
PTE_W
|
PTE_P
|
PTE_PS
;
u64
flags
=
PTE_W
|
PTE_P
|
PTE_PS
|
PTE_NX
;
// Set NX for non-code pages
if
(
va
>=
(
u64
)
end
)
flags
|=
PTE_NX
;
*
sp
=
pa
|
flags
;
*
sp
=
pa
|
flags
;
va
=
va
+
PGSIZE
*
512
;
va
+=
PGSIZE
*
512
;
pa
+=
PGSIZE
*
512
;
pa
+=
PGSIZE
*
512
;
}
}
}
}
...
...
kernel/kalloc.cc
浏览文件 @
83ec933a
...
@@ -118,8 +118,6 @@ kfree_pool(struct kmem *m, char *v)
...
@@ -118,8 +118,6 @@ kfree_pool(struct kmem *m, char *v)
if
((
uptr
)
v
%
PGSIZE
)
if
((
uptr
)
v
%
PGSIZE
)
panic
(
"kfree_pool: misaligned %p"
,
v
);
panic
(
"kfree_pool: misaligned %p"
,
v
);
if
(
v
<
end
)
panic
(
"kfree_pool: less than end %p"
,
v
);
if
(
memsize
(
v
)
==
-
1ull
)
if
(
memsize
(
v
)
==
-
1ull
)
panic
(
"kfree_pool: unknown region %p"
,
v
);
panic
(
"kfree_pool: unknown region %p"
,
v
);
...
@@ -261,7 +259,8 @@ initkalloc(u64 mbaddr)
...
@@ -261,7 +259,8 @@ initkalloc(u64 mbaddr)
n
=
PGROUNDDOWN
(
n
);
n
=
PGROUNDDOWN
(
n
);
p
=
(
char
*
)
PGROUNDUP
((
uptr
)
newend
);
p
=
(
char
*
)
PGROUNDUP
((
uptr
)
newend
);
k
=
(((
uptr
)
p
)
-
KBASE
);
k
=
(((
uptr
)
p
)
-
KCODE
);
p
=
(
char
*
)
KBASE
+
k
;
for
(
int
c
=
0
;
c
<
NCPU
;
c
++
)
{
for
(
int
c
=
0
;
c
<
NCPU
;
c
++
)
{
// Fill slab allocators
// Fill slab allocators
strncpy
(
slabmem
[
slab_stack
][
c
].
name
,
" kstack"
,
MAXNAME
);
strncpy
(
slabmem
[
slab_stack
][
c
].
name
,
" kstack"
,
MAXNAME
);
...
@@ -317,7 +316,7 @@ verifyfree(char *ptr, u64 nbytes)
...
@@ -317,7 +316,7 @@ verifyfree(char *ptr, u64 nbytes)
for
(;
p
<
e
;
p
++
)
{
for
(;
p
<
e
;
p
++
)
{
// Search for pointers in the ptr region
// Search for pointers in the ptr region
u64
x
=
*
(
uptr
*
)
p
;
u64
x
=
*
(
uptr
*
)
p
;
if
(
KBASE
<
x
&&
x
<
KBASE
+
(
128ull
<<
30
))
{
if
(
(
KBASE
<
x
&&
x
<
KBASE
+
(
128ull
<<
30
))
||
(
KCODE
<
x
))
{
struct
klockstat
*
kls
=
(
struct
klockstat
*
)
x
;
struct
klockstat
*
kls
=
(
struct
klockstat
*
)
x
;
if
(
kls
->
magic
==
LOCKSTAT_MAGIC
)
if
(
kls
->
magic
==
LOCKSTAT_MAGIC
)
panic
(
"LOCKSTAT_MAGIC %p(%lu):%p->%p"
,
panic
(
"LOCKSTAT_MAGIC %p(%lu):%p->%p"
,
...
...
kernel/kernel.ld
浏览文件 @
83ec933a
...
@@ -4,7 +4,7 @@ ENTRY(xxx)
...
@@ -4,7 +4,7 @@ ENTRY(xxx)
SECTIONS
SECTIONS
{
{
. = 0xFFFFFF
000
0100000;
. = 0xFFFFFF
FFC
0100000;
PROVIDE(text = .);
PROVIDE(text = .);
.text : AT(0x100000) {
.text : AT(0x100000) {
*(.text .stub .text.* .gnu.linkonce.t.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论