Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
dee0d8b5
提交
dee0d8b5
2月 10, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more c++
上级
577f85e1
隐藏空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
157 行增加
和
109 行删除
+157
-109
cga.cc
cga.cc
+3
-1
cilk.cc
cilk.cc
+0
-0
condvar.cc
condvar.cc
+2
-0
console.cc
console.cc
+3
-3
exec.cc
exec.cc
+23
-23
file.cc
file.cc
+14
-15
fmt.cc
fmt.cc
+2
-0
hwvm.cc
hwvm.cc
+8
-6
ioapic.cc
ioapic.cc
+2
-0
kernel.h
kernel.h
+38
-2
lapic.cc
lapic.cc
+2
-0
main.cc
main.cc
+4
-2
mmu.h
mmu.h
+4
-4
mp.cc
mp.cc
+3
-1
net.c
net.c
+1
-0
net.h
net.h
+6
-0
picirq.cc
picirq.cc
+3
-0
pipe.cc
pipe.cc
+4
-2
prof.cc
prof.cc
+2
-0
prof.h
prof.h
+6
-0
queue.h
queue.h
+2
-2
rnd.cc
rnd.cc
+2
-0
sampler.cc
sampler.cc
+8
-12
spinlock.cc
spinlock.cc
+2
-0
string.cc
string.cc
+7
-4
syscall.c
syscall.c
+0
-29
uart.cc
uart.cc
+6
-3
没有找到文件。
cga.c
→
cga.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include "amd64.h"
}
#define BACKSPACE 0x100
#define CRTPORT 0x3d4
...
...
@@ -42,7 +44,7 @@ cgaputc(int c)
void
initcga
(
void
)
{
char
*
p
;
c
onst
c
har
*
p
;
int
i
;
for
(
i
=
0
;
i
<
80
*
25
;
i
++
)
...
...
cilk.c
→
cilk.c
c
浏览文件 @
dee0d8b5
移动文件
condvar.c
→
condvar.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "amd64.h"
#include "mmu.h"
...
...
@@ -7,6 +8,7 @@
#include "proc.h"
#include "kernel.h"
#include "cpu.h"
}
struct
spinlock
tickslock
__mpalign__
;
struct
condvar
cv_ticks
__mpalign__
;
...
...
console.c
→
console.c
c
浏览文件 @
dee0d8b5
...
...
@@ -2,6 +2,7 @@
// Input is from the keyboard or serial port.
// Output is written to the screen and serial port.
extern
"C"
{
#include "types.h"
#include "cpu.h"
#include "kernel.h"
...
...
@@ -17,6 +18,7 @@
#include <stdarg.h>
#include "fmt.h"
#include <stddef.h>
}
#define BACKSPACE 0x100
...
...
@@ -69,7 +71,7 @@ struct bufstate {
static
void
writebuf
(
int
c
,
void
*
arg
)
{
struct
bufstate
*
bs
=
arg
;
struct
bufstate
*
bs
=
(
bufstate
*
)
arg
;
if
(
bs
->
p
<
bs
->
e
)
{
bs
->
p
[
0
]
=
c
;
bs
->
p
++
;
...
...
@@ -147,7 +149,6 @@ printtrace(u64 rbp)
void
__noret__
kerneltrap
(
struct
trapframe
*
tf
)
{
extern
void
sys_halt
();
const
char
*
name
=
"(no name)"
;
void
*
kstack
=
NULL
;
int
pid
=
0
;
...
...
@@ -178,7 +179,6 @@ kerneltrap(struct trapframe *tf)
void
panic
(
const
char
*
fmt
,
...)
{
extern
void
sys_halt
();
va_list
ap
;
cli
();
...
...
exec.c
→
exec.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "mmu.h"
#include "spinlock.h"
...
...
@@ -14,6 +15,7 @@
#include "vm.h"
#include "prof.h"
#include <stddef.h>
}
#define USTACKPAGES 2
#define BRK (USERTOP >> 1)
...
...
@@ -31,8 +33,7 @@ struct eargs {
static
void
dosegment
(
uptr
a0
,
u64
a1
)
{
static
DEFINE_PROFCTR
(
dosegment_prof
);
struct
eargs
*
args
=
(
void
*
)
a0
;
struct
eargs
*
args
=
(
eargs
*
)
a0
;
u64
off
=
a1
;
struct
vmnode
*
vmn
=
NULL
;
struct
proghdr
ph
;
...
...
@@ -50,26 +51,28 @@ dosegment(uptr a0, u64 a1)
goto
bad
;
}
uptr
va_start
=
PGROUNDDOWN
(
ph
.
vaddr
);
uptr
va_end
=
PGROUNDUP
(
ph
.
vaddr
+
ph
.
memsz
);
{
uptr
va_start
=
PGROUNDDOWN
(
ph
.
vaddr
);
uptr
va_end
=
PGROUNDUP
(
ph
.
vaddr
+
ph
.
memsz
);
int
npg
=
(
va_end
-
va_start
)
/
PGSIZE
;
if
(
odp
)
{
if
((
vmn
=
vmn_alloc
(
npg
,
ONDEMAND
))
==
0
)
goto
bad
;
}
else
{
if
((
vmn
=
vmn_allocpg
(
npg
))
==
0
)
int
npg
=
(
va_end
-
va_start
)
/
PGSIZE
;
if
(
odp
)
{
if
((
vmn
=
vmn_alloc
(
npg
,
ONDEMAND
))
==
0
)
goto
bad
;
}
else
{
if
((
vmn
=
vmn_allocpg
(
npg
))
==
0
)
goto
bad
;
}
if
(
vmn_load
(
vmn
,
args
->
ip
,
ph
.
offset
,
ph
.
filesz
)
<
0
)
goto
bad
;
}
if
(
vmn_load
(
vmn
,
args
->
ip
,
ph
.
offset
,
ph
.
filesz
)
<
0
)
goto
bad
;
if
(
vmap_insert
(
args
->
vmap
,
vmn
,
ph
.
vaddr
)
<
0
)
goto
bad
;
if
(
vmap_insert
(
args
->
vmap
,
vmn
,
ph
.
vaddr
)
<
0
)
goto
bad
;
prof_end
(
dosegment_prof
);
return
;
prof_end
(
dosegment_prof
);
return
;
}
bad:
panic
(
"dosegment: Oops"
);
...
...
@@ -77,9 +80,8 @@ bad:
static
void
dostack
(
uptr
a0
,
u64
a1
)
{
static
DEFINE_PROFCTR
(
dostack_prof
);
struct
vmnode
*
vmn
=
NULL
;
struct
eargs
*
args
=
(
void
*
)
a0
;
struct
eargs
*
args
=
(
eargs
*
)
a0
;
int
argc
;
uptr
sp
;
uptr
ustack
[
1
+
MAXARG
+
1
];
...
...
@@ -132,9 +134,8 @@ bad:
static
void
doheap
(
uptr
a0
,
u64
a1
)
{
static
DEFINE_PROFCTR
(
doheap_prof
);
struct
vmnode
*
vmn
=
NULL
;
struct
eargs
*
args
=
(
void
*
)
a0
;
struct
eargs
*
args
=
(
eargs
*
)
a0
;
prof_start
(
doheap_prof
);
// Allocate a vmnode for the heap.
...
...
@@ -155,7 +156,6 @@ bad:
int
exec
(
char
*
path
,
char
**
argv
)
{
static
DEFINE_PROFCTR
(
exec_prof
);
struct
inode
*
ip
=
NULL
;
struct
vmap
*
vmap
=
NULL
;
struct
vmnode
*
vmn
=
NULL
;
...
...
file.c
→
file.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "spinlock.h"
#include "condvar.h"
...
...
@@ -5,6 +6,8 @@
#include "fs.h"
#include "file.h"
#include "stat.h"
#include "net.h"
}
struct
devsw
__mpalign__
devsw
[
NDEV
];
...
...
@@ -12,7 +15,7 @@ struct devsw __mpalign__ devsw[NDEV];
struct
file
*
filealloc
(
void
)
{
struct
file
*
f
=
kmalloc
(
sizeof
(
struct
file
));
struct
file
*
f
=
(
file
*
)
kmalloc
(
sizeof
(
struct
file
));
f
->
ref
=
1
;
return
f
;
}
...
...
@@ -30,16 +33,14 @@ filedup(struct file *f)
void
fileclose
(
struct
file
*
f
)
{
extern
void
netclose
(
int
sock
);
if
(
subfetch
(
&
f
->
ref
,
1
)
>
0
)
return
;
if
(
f
->
type
==
FD_PIPE
)
if
(
f
->
type
==
file
::
FD_PIPE
)
pipeclose
(
f
->
pipe
,
f
->
writable
);
else
if
(
f
->
type
==
FD_INODE
)
else
if
(
f
->
type
==
file
::
FD_INODE
)
iput
(
f
->
ip
);
else
if
(
f
->
type
==
FD_SOCKET
)
else
if
(
f
->
type
==
file
::
FD_SOCKET
)
netclose
(
f
->
socket
);
else
panic
(
"fileclose bad type"
);
...
...
@@ -50,7 +51,7 @@ fileclose(struct file *f)
int
filestat
(
struct
file
*
f
,
struct
stat
*
st
)
{
if
(
f
->
type
==
FD_INODE
){
if
(
f
->
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
0
);
if
(
f
->
ip
->
type
==
0
)
panic
(
"filestat"
);
...
...
@@ -65,14 +66,13 @@ filestat(struct file *f, struct stat *st)
int
fileread
(
struct
file
*
f
,
char
*
addr
,
int
n
)
{
extern
int
netread
(
int
,
char
*
,
int
);
int
r
;
if
(
f
->
readable
==
0
)
return
-
1
;
if
(
f
->
type
==
FD_PIPE
)
if
(
f
->
type
==
file
::
FD_PIPE
)
return
piperead
(
f
->
pipe
,
addr
,
n
);
if
(
f
->
type
==
FD_INODE
){
if
(
f
->
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
0
);
if
(
f
->
ip
->
type
==
0
)
panic
(
"fileread"
);
...
...
@@ -81,7 +81,7 @@ fileread(struct file *f, char *addr, int n)
iunlock
(
f
->
ip
);
return
r
;
}
if
(
f
->
type
==
FD_SOCKET
)
if
(
f
->
type
==
file
::
FD_SOCKET
)
return
netread
(
f
->
socket
,
addr
,
n
);
panic
(
"fileread"
);
}
...
...
@@ -90,14 +90,13 @@ fileread(struct file *f, char *addr, int n)
int
filewrite
(
struct
file
*
f
,
char
*
addr
,
int
n
)
{
extern
int
netwrite
(
int
,
char
*
,
int
);
int
r
;
if
(
f
->
writable
==
0
)
return
-
1
;
if
(
f
->
type
==
FD_PIPE
)
if
(
f
->
type
==
file
::
FD_PIPE
)
return
pipewrite
(
f
->
pipe
,
addr
,
n
);
if
(
f
->
type
==
FD_INODE
){
if
(
f
->
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
1
);
if
(
f
->
ip
->
type
==
0
||
f
->
ip
->
type
==
T_DIR
)
panic
(
"filewrite but 0 or T_DIR"
);
...
...
@@ -106,7 +105,7 @@ filewrite(struct file *f, char *addr, int n)
iunlock
(
f
->
ip
);
return
r
;
}
if
(
f
->
type
==
FD_SOCKET
)
if
(
f
->
type
==
file
::
FD_SOCKET
)
return
netwrite
(
f
->
socket
,
addr
,
n
);
panic
(
"filewrite"
);
}
fmt.c
→
fmt.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include <stddef.h>
#include <stdarg.h>
#include "fmt.h"
}
//
// Print a number (base <= 16) in reverse order,
...
...
hwvm.c
→
hwvm.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "amd64.h"
#include "mmu.h"
...
...
@@ -11,6 +12,7 @@
#include "proc.h"
#include "vm.h"
#include <stddef.h>
}
extern
pml4e_t
kpml4
[];
...
...
@@ -24,7 +26,7 @@ retry:
dir
=
&
dir
[
PX
(
level
,
va
)];
entry
=
*
dir
;
if
(
entry
&
PTE_P
)
{
next
=
p2v
(
PTE_ADDR
(
entry
));
next
=
(
pme_t
*
)
p2v
(
PTE_ADDR
(
entry
));
}
else
{
if
(
!
create
)
return
NULL
;
...
...
@@ -69,8 +71,8 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm)
char
*
a
,
*
last
;
pme_t
*
pte
;
a
=
PGROUNDDOWN
(
begin
);
last
=
PGROUNDDOWN
(
end
);
a
=
(
char
*
)
PGROUNDDOWN
(
begin
);
last
=
(
char
*
)
PGROUNDDOWN
(
end
);
for
(;;)
{
pte
=
walkpgdir
(
pml4
,
a
,
1
);
if
(
pte
!=
0
)
{
...
...
@@ -100,7 +102,7 @@ initpg(void)
if
(
va
>=
(
void
*
)
end
)
flags
|=
PTE_NX
;
*
sp
=
pa
|
flags
;
va
+=
PGSIZE
*
512
;
va
=
(
char
*
)
va
+
PGSIZE
*
512
;
pa
+=
PGSIZE
*
512
;
}
}
...
...
@@ -154,7 +156,7 @@ freepm(pme_t *pm, int level)
if
(
level
!=
0
)
{
for
(
i
=
0
;
i
<
512
;
i
++
)
{
if
(
pm
[
i
]
&
PTE_P
)
freepm
(
p2v
(
PTE_ADDR
(
pm
[
i
])),
level
-
1
);
freepm
(
(
pme_t
*
)
p2v
(
PTE_ADDR
(
pm
[
i
])),
level
-
1
);
}
}
...
...
@@ -176,7 +178,7 @@ freevm(pml4e_t *pml4)
k
=
PX
(
3
,
KBASE
);
for
(
i
=
0
;
i
<
k
;
i
++
)
{
if
(
pml4
[
i
]
&
PTE_P
)
{
freepm
(
p2v
(
PTE_ADDR
(
pml4
[
i
])),
2
);
freepm
(
(
pme_t
*
)
p2v
(
PTE_ADDR
(
pml4
[
i
])),
2
);
}
}
...
...
ioapic.c
→
ioapic.c
c
浏览文件 @
dee0d8b5
...
...
@@ -2,9 +2,11 @@
// http://www.intel.com/design/chipsets/datashts/29056601.pdf
// See also picirq.c.
extern
"C"
{
#include "types.h"
#include "traps.h"
#include "kernel.h"
}
#define IOAPIC (KBASE + 0xFEC00000) // Default physical address of IO APIC
...
...
kernel.h
浏览文件 @
dee0d8b5
...
...
@@ -288,10 +288,11 @@ void syscall(void);
int
memcmp
(
const
void
*
,
const
void
*
,
u32
);
void
*
memmove
(
void
*
,
const
void
*
,
u32
);
void
*
memset
(
void
*
,
int
,
u32
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
int
);
void
*
memcpy
(
void
*
,
const
void
*
,
u32
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
u32
);
int
strlen
(
const
char
*
);
int
strncmp
(
const
char
*
,
const
char
*
,
u32
);
char
*
strncpy
(
char
*
,
const
char
*
,
int
);
char
*
strncpy
(
char
*
,
const
char
*
,
u32
);
int
strcmp
(
const
char
*
p
,
const
char
*
q
);
// swtch.S
...
...
@@ -379,3 +380,38 @@ void initnet(void);
void
initsched
(
void
);
void
initlockstat
(
void
);
// syscalls
long
sys_chdir
(
void
);
long
sys_close
(
void
);
long
sys_dup
(
void
);
long
sys_exec
(
void
);
long
sys_exit
(
void
);
long
sys_fork
(
void
);
long
sys_fstat
(
void
);
long
sys_getpid
(
void
);
long
sys_kill
(
void
);
long
sys_link
(
void
);
long
sys_mkdir
(
void
);
long
sys_mknod
(
void
);
long
sys_open
(
void
);
long
sys_pipe
(
void
);
long
sys_read
(
void
);
long
sys_sbrk
(
void
);
long
sys_sleep
(
void
);
long
sys_unlink
(
void
);
long
sys_wait
(
void
);
long
sys_write
(
void
);
long
sys_uptime
(
void
);
long
sys_map
(
void
);
long
sys_unmap
(
void
);
long
sys_halt
(
void
);
long
sys_socket
(
int
,
int
,
int
);
long
sys_bind
(
int
,
void
*
,
int
);
long
sys_listen
(
int
,
int
);
long
sys_accept
(
int
,
void
*
,
void
*
);
// other exported functions
void
cmain
(
u64
mbmagic
,
u64
mbaddr
);
void
mpboot
(
void
);
lapic.c
→
lapic.c
c
浏览文件 @
dee0d8b5
// The local APIC manages internal (non-I/O) interrupts.
// See Chapter 8 & Appendix C of Intel processor manual volume 3.
extern
"C"
{
#include "types.h"
#include "amd64.h"
#include "kernel.h"
#include "traps.h"
#include "bits.h"
}
// Local APIC registers, divided by 4 for use as uint[] indices.
#define ID (0x0020/4) // ID
...
...
main.c
→
main.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "multiboot.h"
#include "kernel.h"
#include "cpu.h"
#include "amd64.h"
}
static
volatile
int
bstate
;
...
...
@@ -30,7 +32,7 @@ bootothers(void)
// Write bootstrap code to unused memory at 0x7000.
// The linker has placed the image of bootother.S in
// _binary_bootother_start.
code
=
p2v
(
0x7000
);
code
=
(
u8
*
)
p2v
(
0x7000
);
memmove
(
code
,
_bootother_start
,
_bootother_size
);
for
(
c
=
cpus
;
c
<
cpus
+
ncpu
;
c
++
){
...
...
@@ -40,7 +42,7 @@ bootothers(void)
// Tell bootother.S what stack to use and the address of apstart;
// it expects to find these two addresses stored just before
// its first instruction.
stack
=
ksalloc
(
slab_stack
);
stack
=
(
char
*
)
ksalloc
(
slab_stack
);
*
(
u32
*
)(
code
-
4
)
=
(
u32
)
v2p
(
&
apstart
);
*
(
u64
*
)(
code
-
12
)
=
(
u64
)
stack
+
KSTACKSIZE
;
...
...
mmu.h
浏览文件 @
dee0d8b5
...
...
@@ -39,17 +39,17 @@ struct segdesc {
// SEGDESC constructs a segment descriptor literal
// with the given, base, limit, and type bits.
#define SEGDESC(base, limit, bits) { \
(limit)&0xffff, (
base)&0xffff
, \
(
(base)>>16)&0xff
, \
(limit)&0xffff, (
u16) ((base)&0xffff)
, \
(
u8) (((base)>>16)&0xff)
, \
(bits)&0xff, \
(((bits)>>4)&0xf0) | ((limit>>16)&0xf), \
(
(base)>>24)&0xff
, \
(
u8) (((base)>>24)&0xff)
, \
}
// SEGDESCHI constructs an extension segment descriptor
// literal that records the high bits of base.
#define SEGDESCHI(base) { \
(
(base)>>32)&0xffff, ((base)>>48)&0xffff
, \
(
u16) (((base)>>32)&0xffff), (u16) (((base)>>48)&0xffff)
, \
}
// Segment selectors (indexes) in our GDTs.
...
...
mp.c
→
mp.c
c
浏览文件 @
dee0d8b5
...
...
@@ -2,11 +2,13 @@
// Search memory for MP description structures.
// http://developer.intel.com/design/pentium/datashts/24201606.pdf
extern
"C"
{
#include "types.h"
#include "amd64.h"
#include "mp.h"
#include "kernel.h"
#include "cpu.h"
}
struct
cpu
cpus
[
NCPU
];
static
struct
cpu
*
bcpu
__mpalign__
;
...
...
@@ -37,7 +39,7 @@ mpsearch1(u8 *addr, int len)
{
u8
*
e
,
*
p
;
addr
=
p2v
((
uptr
)
addr
);
addr
=
(
u8
*
)
p2v
((
uptr
)
addr
);
e
=
addr
+
len
;
for
(
p
=
addr
;
p
<
e
;
p
+=
sizeof
(
struct
mp
))
if
(
memcmp
(
p
,
"_MP_"
,
4
)
==
0
&&
sum
(
p
,
sizeof
(
struct
mp
))
==
0
)
...
...
net.c
浏览文件 @
dee0d8b5
...
...
@@ -21,6 +21,7 @@
#include "proc.h"
#include "fs.h"
#include "file.h"
#include "net.h"
void
netfree
(
void
*
va
)
...
...
net.h
0 → 100644
浏览文件 @
dee0d8b5
#pragma once
void
netclose
(
int
sock
);
int
netread
(
int
,
char
*
,
int
);
int
netwrite
(
int
,
char
*
,
int
);
picirq.c
→
picirq.c
c
浏览文件 @
dee0d8b5
// Intel 8259A programmable interrupt controllers.
extern
"C"
{
#include "types.h"
#include "amd64.h"
#include "traps.h"
#include "kernel.h"
}
// I/O Addresses of the two programmable interrupt controllers
#define IO_PIC1 0x20 // Master (IRQs 0-7)
...
...
pipe.c
→
pipe.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "mmu.h"
#include "kernel.h"
...
...
@@ -8,6 +9,7 @@
#include "fs.h"
#include "file.h"
#include "cpu.h"
}
#define PIPESIZE 512
...
...
@@ -38,11 +40,11 @@ pipealloc(struct file **f0, struct file **f1)
p
->
nread
=
0
;
initlock
(
&
p
->
lock
,
"pipe"
,
LOCKSTAT_PIPE
);
initcondvar
(
&
p
->
cv
,
"pipe"
);
(
*
f0
)
->
type
=
FD_PIPE
;
(
*
f0
)
->
type
=
file
::
FD_PIPE
;
(
*
f0
)
->
readable
=
1
;
(
*
f0
)
->
writable
=
0
;
(
*
f0
)
->
pipe
=
p
;
(
*
f1
)
->
type
=
FD_PIPE
;
(
*
f1
)
->
type
=
file
::
FD_PIPE
;
(
*
f1
)
->
readable
=
0
;
(
*
f1
)
->
writable
=
1
;
(
*
f1
)
->
pipe
=
p
;
...
...
prof.c
→
prof.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include "spinlock.h"
...
...
@@ -7,6 +8,7 @@
#include "prof.h"
#include "bits.h"
#include "amd64.h"
}
extern
profctr_t
sprof
[];
extern
profctr_t
eprof
[];
...
...
prof.h
浏览文件 @
dee0d8b5
...
...
@@ -10,6 +10,7 @@ typedef struct profctr {
__padout__
;
}
profctr_t
;
#if 0 /* not for c++ */
#define DEFINE_PROFCTR(xname) \
profctr_t xname __attribute__((section(".prof"))) = { .name = #xname };
...
...
@@ -24,3 +25,8 @@ typedef struct profctr {
name.rec[__profid].cnt++; \
} \
} while (0)
#else
#define DEFINE_PROFCTR(x)
#define prof_start(x)
#define prof_end(x)
#endif
queue.h
浏览文件 @
dee0d8b5
...
...
@@ -209,7 +209,7 @@ struct { \
(varp) = &SLIST_NEXT((var), field))
#define SLIST_INIT(head) do { \
SLIST_FIRST((head)) =
NULL
; \
SLIST_FIRST((head)) =
0
; \
} while (0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
...
...
@@ -403,7 +403,7 @@ struct { \
(var) = (tvar))
#define LIST_INIT(head) do { \
LIST_FIRST((head)) =
NULL;
\
LIST_FIRST((head)) =
0;
\
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
...
...
rnd.c
→
rnd.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "param.h"
#include "types.h"
#include "kernel.h"
#include "cpu.h"
}
struct
seed
{
u64
v
;
...
...
sampler.c
→
sampler.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "spinlock.h"
#include "condvar.h"
...
...
@@ -8,6 +9,7 @@
#include "amd64.h"
#include "cpu.h"
#include "sampler.h"
}
static
const
u64
debug_sel
=
0UL
<<
32
|
...
...
@@ -47,10 +49,7 @@ amdconfig(u64 ctr, u64 sel, u64 val)
writemsr
(
MSR_AMD_PERF_SEL0
|
ctr
,
sel
);
}
struct
pmu
amdpmu
=
{
.
config
=
amdconfig
,
.
cntval_bits
=
48
,
};
struct
pmu
amdpmu
=
{
amdconfig
,
48
};
//
// Intel stuff
...
...
@@ -64,10 +63,7 @@ intelconfig(u64 ctr, u64 sel, u64 val)
}
// XXX
struct
pmu
intelpmu
=
{
.
config
=
intelconfig
,
.
cntval_bits
=
48
,
};
struct
pmu
intelpmu
=
{
intelconfig
,
48
};
void
sampdump
(
void
)
...
...
@@ -177,7 +173,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
u64
len
=
hdrlen
;
u64
cc
;
hdr
=
kmalloc
(
len
);
hdr
=
(
logheader
*
)
kmalloc
(
len
);
if
(
hdr
==
NULL
)
return
-
1
;
hdr
->
ncpus
=
NCPU
;
...
...
@@ -189,7 +185,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
}
cc
=
MIN
(
hdrlen
-
off
,
n
);
memmove
(
dst
,
(
void
*
)
hdr
+
off
,
cc
);
memmove
(
dst
,
(
char
*
)
hdr
+
off
,
cc
);
kmfree
(
hdr
);
n
-=
cc
;
...
...
@@ -229,9 +225,9 @@ initsamp(void)
void
*
p
=
ksalloc
(
slab_perf
);
if
(
p
==
NULL
)
panic
(
"initprof: ksalloc"
);
pmulog
[
cpunum
()].
event
=
p
;
pmulog
[
cpunum
()].
event
=
(
pmuevent
*
)
p
;
pmulog
[
cpunum
()].
capacity
=
PERFSIZE
/
sizeof
(
struct
pmuevent
);
devsw
[
SAMPLER
].
write
=
NULL
;
devsw
[
SAMPLER
].
write
=
0
;
devsw
[
SAMPLER
].
read
=
sampread
;
}
spinlock.c
→
spinlock.c
c
浏览文件 @
dee0d8b5
// Mutual exclusion spin locks.
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include "amd64.h"
...
...
@@ -10,6 +11,7 @@
#include "condvar.h"
#include "fs.h"
#include "file.h"
}
#if LOCKSTAT
static
int
lockstat_enable
;
...
...
string.c
→
string.c
c
浏览文件 @
dee0d8b5
extern
"C"
{
#include "types.h"
#include "amd64.h"
#include "kernel.h"
}
void
*
memset
(
void
*
dst
,
int
c
,
u32
n
)
...
...
@@ -13,8 +16,8 @@ memcmp(const void *v1, const void *v2, u32 n)
{
const
u8
*
s1
,
*
s2
;
s1
=
v1
;
s2
=
v2
;
s1
=
(
const
u8
*
)
v1
;
s2
=
(
const
u8
*
)
v2
;
while
(
n
--
>
0
){
if
(
*
s1
!=
*
s2
)
return
*
s1
-
*
s2
;
...
...
@@ -30,8 +33,8 @@ memmove(void *dst, const void *src, u32 n)
const
char
*
s
;
char
*
d
;
s
=
src
;
d
=
dst
;
s
=
(
const
char
*
)
src
;
d
=
(
char
*
)
dst
;
if
(
s
<
d
&&
s
+
n
>
d
){
s
+=
n
;
d
+=
n
;
...
...
syscall.c
浏览文件 @
dee0d8b5
...
...
@@ -146,35 +146,6 @@ kmemcpy(void *umem, void *src, u64 size)
return
0
;
}
extern
long
sys_chdir
(
void
);
extern
long
sys_close
(
void
);
extern
long
sys_dup
(
void
);
extern
long
sys_exec
(
void
);
extern
long
sys_exit
(
void
);
extern
long
sys_fork
(
void
);
extern
long
sys_fstat
(
void
);
extern
long
sys_getpid
(
void
);
extern
long
sys_kill
(
void
);
extern
long
sys_link
(
void
);
extern
long
sys_mkdir
(
void
);
extern
long
sys_mknod
(
void
);
extern
long
sys_open
(
void
);
extern
long
sys_pipe
(
void
);
extern
long
sys_read
(
void
);
extern
long
sys_sbrk
(
void
);
extern
long
sys_sleep
(
void
);
extern
long
sys_unlink
(
void
);
extern
long
sys_wait
(
void
);
extern
long
sys_write
(
void
);
extern
long
sys_uptime
(
void
);
extern
long
sys_map
(
void
);
extern
long
sys_unmap
(
void
);
extern
long
sys_halt
(
void
);
extern
long
sys_socket
(
int
,
int
,
int
);
extern
long
sys_bind
(
int
,
void
*
,
int
);
extern
long
sys_listen
(
int
,
int
);
extern
long
sys_accept
(
int
,
void
*
,
void
*
);
#define SYSCALL(name) [SYS_##name] = (void*)sys_##name
static
long
(
*
syscalls
[])(
u64
,
u64
,
u64
,
u64
,
u64
,
u64
)
=
{
...
...
uart.c
→
uart.c
c
浏览文件 @
dee0d8b5
// Intel 8250 serial port (UART).
// http://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include "amd64.h"
#include "traps.h"
}
#define COM2 0x2f8
#define COM1 0x3f8
...
...
@@ -48,9 +51,9 @@ inituart(void)
int
irq
;
}
conf
[]
=
{
// Try COM2 (aka ttyS1) first, because it usually does SOL for IPMI.
{
.
com
=
COM2
,
.
irq
=
IRQ_COM2
},
{
COM2
,
IRQ_COM2
},
// Still try COM1 (aka ttyS0), because it is what QEMU emulates.
{
.
com
=
COM1
,
.
irq
=
IRQ_COM1
}
{
COM1
,
IRQ_COM1
}
};
int
i
;
...
...
@@ -87,6 +90,6 @@ inituart(void)
ioapicenable
(
irq_com
,
0
);
// Announce that we're here.
for
(
char
*
p
=
"uart..
\n
"
;
*
p
;
p
++
)
for
(
c
onst
c
har
*
p
=
"uart..
\n
"
;
*
p
;
p
++
)
uartputc
(
*
p
);
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论