Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
29270816
提交
29270816
7月 20, 2006
创建
作者:
rtm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uint32_t -> uint &c
上级
bd228a81
显示空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
251 行增加
和
270 行删除
+251
-270
bootmain.c
bootmain.c
+8
-8
console.c
console.c
+1
-1
defs.h
defs.h
+6
-6
elf.h
elf.h
+23
-23
ide.c
ide.c
+7
-13
lapic.c
lapic.c
+3
-3
main.c
main.c
+7
-7
mmu.h
mmu.h
+41
-41
mp.c
mp.c
+19
-19
mp.h
mp.h
+41
-41
picirq.c
picirq.c
+2
-2
proc.h
proc.h
+1
-1
spinlock.h
spinlock.h
+1
-1
string.c
string.c
+3
-3
syscall.c
syscall.c
+2
-0
types.h
types.h
+2
-8
x86.h
x86.h
+84
-93
没有找到文件。
bootmain.c
浏览文件 @
29270816
...
@@ -33,8 +33,8 @@
...
@@ -33,8 +33,8 @@
#define SECTSIZE 512
#define SECTSIZE 512
#define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
#define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
void
readsect
(
void
*
,
uint
32_t
);
void
readsect
(
void
*
,
uint
);
void
readseg
(
uint
32_t
,
uint32_t
,
uint32_
t
);
void
readseg
(
uint
,
uint
,
uin
t
);
void
void
cmain
(
void
)
cmain
(
void
)
...
@@ -42,14 +42,14 @@ cmain(void)
...
@@ -42,14 +42,14 @@ cmain(void)
struct
proghdr
*
ph
,
*
eph
;
struct
proghdr
*
ph
,
*
eph
;
// read 1st page off disk
// read 1st page off disk
readseg
((
uint
32_t
)
ELFHDR
,
SECTSIZE
*
8
,
0
);
readseg
((
uint
)
ELFHDR
,
SECTSIZE
*
8
,
0
);
// is this a valid ELF?
// is this a valid ELF?
if
(
ELFHDR
->
magic
!=
ELF_MAGIC
)
if
(
ELFHDR
->
magic
!=
ELF_MAGIC
)
goto
bad
;
goto
bad
;
// load each program segment (ignores ph flags)
// load each program segment (ignores ph flags)
ph
=
(
struct
proghdr
*
)
((
u
int8_t
*
)
ELFHDR
+
ELFHDR
->
phoff
);
ph
=
(
struct
proghdr
*
)
((
u
char
*
)
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
);
...
@@ -68,9 +68,9 @@ bad:
...
@@ -68,9 +68,9 @@ bad:
// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
// Might copy more than asked
// Might copy more than asked
void
void
readseg
(
uint
32_t
va
,
uint32_t
count
,
uint32_
t
offset
)
readseg
(
uint
va
,
uint
count
,
uin
t
offset
)
{
{
uint
32_t
end_va
;
uint
end_va
;
va
&=
0xFFFFFF
;
va
&=
0xFFFFFF
;
end_va
=
va
+
count
;
end_va
=
va
+
count
;
...
@@ -85,7 +85,7 @@ readseg(uint32_t va, uint32_t count, uint32_t offset)
...
@@ -85,7 +85,7 @@ readseg(uint32_t va, uint32_t count, uint32_t offset)
// We'd write more to memory than asked, but it doesn't matter --
// We'd write more to memory than asked, but it doesn't matter --
// we load in increasing order.
// we load in increasing order.
while
(
va
<
end_va
)
{
while
(
va
<
end_va
)
{
readsect
((
u
int8_t
*
)
va
,
offset
);
readsect
((
u
char
*
)
va
,
offset
);
va
+=
SECTSIZE
;
va
+=
SECTSIZE
;
offset
++
;
offset
++
;
}
}
...
@@ -100,7 +100,7 @@ waitdisk(void)
...
@@ -100,7 +100,7 @@ waitdisk(void)
}
}
void
void
readsect
(
void
*
dst
,
uint
32_t
offset
)
readsect
(
void
*
dst
,
uint
offset
)
{
{
// wait for disk to be ready
// wait for disk to be ready
waitdisk
();
waitdisk
();
...
...
console.c
浏览文件 @
29270816
...
@@ -28,7 +28,7 @@ static void
...
@@ -28,7 +28,7 @@ static void
cons_putc
(
int
c
)
cons_putc
(
int
c
)
{
{
int
crtport
=
0x3d4
;
// io port of CGA
int
crtport
=
0x3d4
;
// io port of CGA
u
int16_t
*
crt
=
(
uint16_
t
*
)
0xB8000
;
// base of CGA memory
u
short
*
crt
=
(
ushor
t
*
)
0xB8000
;
// base of CGA memory
int
ind
;
int
ind
;
if
(
panicked
){
if
(
panicked
){
...
...
defs.h
浏览文件 @
29270816
...
@@ -40,8 +40,8 @@ int strncmp(const char *p, const char *q, uint n);
...
@@ -40,8 +40,8 @@ int strncmp(const char *p, const char *q, uint n);
void
syscall
(
void
);
void
syscall
(
void
);
// picirq.c
// picirq.c
extern
u
int16_
t
irq_mask_8259A
;
extern
u
shor
t
irq_mask_8259A
;
void
irq_setmask_8259A
(
u
int16_
t
mask
);
void
irq_setmask_8259A
(
u
shor
t
mask
);
void
pic_init
(
void
);
void
pic_init
(
void
);
// mp.c
// mp.c
...
@@ -50,9 +50,9 @@ void mp_startthem(void);
...
@@ -50,9 +50,9 @@ void mp_startthem(void);
int
mp_bcpu
(
void
);
int
mp_bcpu
(
void
);
// lapic
// lapic
extern
uint
32_t
*
lapicaddr
;
extern
uint
*
lapicaddr
;
void
lapic_init
(
int
);
void
lapic_init
(
int
);
void
lapic_startap
(
u
int8_t
,
int
);
void
lapic_startap
(
u
char
,
int
);
void
lapic_timerinit
(
void
);
void
lapic_timerinit
(
void
);
void
lapic_timerintr
(
void
);
void
lapic_timerintr
(
void
);
void
lapic_enableintr
(
void
);
void
lapic_enableintr
(
void
);
...
@@ -66,7 +66,7 @@ void release(struct spinlock*);
...
@@ -66,7 +66,7 @@ void release(struct spinlock*);
int
holding
(
struct
spinlock
*
);
int
holding
(
struct
spinlock
*
);
// main.c
// main.c
void
load_icode
(
struct
proc
*
p
,
u
int8_t
*
binary
,
uint
size
);
void
load_icode
(
struct
proc
*
p
,
u
char
*
binary
,
uint
size
);
// pipe.c
// pipe.c
struct
pipe
;
struct
pipe
;
...
@@ -87,6 +87,6 @@ void fd_incref(struct fd *fd);
...
@@ -87,6 +87,6 @@ void fd_incref(struct fd *fd);
// ide.c
// ide.c
void
ide_init
(
void
);
void
ide_init
(
void
);
void
ide_intr
(
void
);
void
ide_intr
(
void
);
void
*
ide_start_read
(
uint
32_t
secno
,
void
*
dst
,
uint
nsecs
);
void
*
ide_start_read
(
uint
secno
,
void
*
dst
,
uint
nsecs
);
int
ide_finish_read
(
void
*
);
int
ide_finish_read
(
void
*
);
elf.h
浏览文件 @
29270816
#define ELF_MAGIC 0x464C457FU
/* "\x7FELF" in little endian */
#define ELF_MAGIC 0x464C457FU
/* "\x7FELF" in little endian */
struct
elfhdr
{
struct
elfhdr
{
uint
32_t
magic
;
// must equal ELF_MAGIC
uint
magic
;
// must equal ELF_MAGIC
u
int8_t
elf
[
12
];
u
char
elf
[
12
];
u
int16_
t
type
;
u
shor
t
type
;
u
int16_
t
machine
;
u
shor
t
machine
;
uint
32_t
version
;
uint
version
;
uint
32_t
entry
;
uint
entry
;
uint
32_t
phoff
;
uint
phoff
;
uint
32_t
shoff
;
uint
shoff
;
uint
32_t
flags
;
uint
flags
;
u
int16_
t
ehsize
;
u
shor
t
ehsize
;
u
int16_
t
phentsize
;
u
shor
t
phentsize
;
u
int16_
t
phnum
;
u
shor
t
phnum
;
u
int16_
t
shentsize
;
u
shor
t
shentsize
;
u
int16_
t
shnum
;
u
shor
t
shnum
;
u
int16_
t
shstrndx
;
u
shor
t
shstrndx
;
};
};
struct
proghdr
{
struct
proghdr
{
uint
32_t
type
;
uint
type
;
uint
32_t
offset
;
uint
offset
;
uint
32_t
va
;
uint
va
;
uint
32_t
pa
;
uint
pa
;
uint
32_t
filesz
;
uint
filesz
;
uint
32_t
memsz
;
uint
memsz
;
uint
32_t
flags
;
uint
flags
;
uint
32_t
align
;
uint
align
;
};
};
// Values for Proghdr type
// Values for Proghdr type
...
...
ide.c
浏览文件 @
29270816
...
@@ -18,7 +18,8 @@
...
@@ -18,7 +18,8 @@
#define IDE_ERR 0x01
#define IDE_ERR 0x01
struct
ide_request
{
struct
ide_request
{
uint32_t
secno
;
int
diskno
;
uint
secno
;
void
*
dst
;
void
*
dst
;
uint
nsecs
;
uint
nsecs
;
};
};
...
@@ -26,7 +27,6 @@ struct ide_request request[NREQUEST];
...
@@ -26,7 +27,6 @@ struct ide_request request[NREQUEST];
int
head
,
tail
;
int
head
,
tail
;
struct
spinlock
ide_lock
;
struct
spinlock
ide_lock
;
static
int
diskno
=
0
;
int
disk_channel
;
int
disk_channel
;
static
int
static
int
...
@@ -80,14 +80,6 @@ ide_probe_disk1(void)
...
@@ -80,14 +80,6 @@ ide_probe_disk1(void)
}
}
void
void
ide_set_disk
(
int
d
)
{
if
(
d
!=
0
&&
d
!=
1
)
panic
(
"bad disk number"
);
diskno
=
d
;
}
void
ide_start_request
(
void
)
ide_start_request
(
void
)
{
{
struct
ide_request
*
r
;
struct
ide_request
*
r
;
...
@@ -100,13 +92,13 @@ ide_start_request (void)
...
@@ -100,13 +92,13 @@ ide_start_request (void)
outb
(
0x1F3
,
r
->
secno
&
0xFF
);
outb
(
0x1F3
,
r
->
secno
&
0xFF
);
outb
(
0x1F4
,
(
r
->
secno
>>
8
)
&
0xFF
);
outb
(
0x1F4
,
(
r
->
secno
>>
8
)
&
0xFF
);
outb
(
0x1F5
,
(
r
->
secno
>>
16
)
&
0xFF
);
outb
(
0x1F5
,
(
r
->
secno
>>
16
)
&
0xFF
);
outb
(
0x1F6
,
0xE0
|
((
diskno
&
1
)
<<
4
)
|
((
r
->
secno
>>
24
)
&
0x0F
));
outb
(
0x1F6
,
0xE0
|
((
r
->
diskno
&
1
)
<<
4
)
|
((
r
->
secno
>>
24
)
&
0x0F
));
outb
(
0x1F7
,
0x20
);
// CMD 0x20 means read sector
outb
(
0x1F7
,
0x20
);
// CMD 0x20 means read sector
}
}
}
}
void
*
void
*
ide_start_read
(
uint
32_t
secno
,
void
*
dst
,
uint
nsecs
)
ide_start_read
(
uint
secno
,
void
*
dst
,
uint
nsecs
)
{
{
struct
ide_request
*
r
;
struct
ide_request
*
r
;
if
(
!
holding
(
&
ide_lock
))
if
(
!
holding
(
&
ide_lock
))
...
@@ -122,6 +114,7 @@ ide_start_read(uint32_t secno, void *dst, uint nsecs)
...
@@ -122,6 +114,7 @@ ide_start_read(uint32_t secno, void *dst, uint nsecs)
r
->
secno
=
secno
;
r
->
secno
=
secno
;
r
->
dst
=
dst
;
r
->
dst
=
dst
;
r
->
nsecs
=
nsecs
;
r
->
nsecs
=
nsecs
;
r
->
diskno
=
0
;
ide_start_request
();
ide_start_request
();
...
@@ -155,9 +148,10 @@ ide_finish_read(void *c)
...
@@ -155,9 +148,10 @@ ide_finish_read(void *c)
}
}
int
int
ide_write
(
uint
32_t
secno
,
const
void
*
src
,
uint
nsecs
)
ide_write
(
uint
secno
,
const
void
*
src
,
uint
nsecs
)
{
{
int
r
;
int
r
;
int
diskno
=
0
;
if
(
nsecs
>
256
)
if
(
nsecs
>
256
)
panic
(
"ide_write"
);
panic
(
"ide_write"
);
...
...
lapic.c
浏览文件 @
29270816
...
@@ -92,7 +92,7 @@ enum { /* LAPIC_TDCR */
...
@@ -92,7 +92,7 @@ enum { /* LAPIC_TDCR */
LAPIC_X1
=
0x0000000B
,
/* divide by 1 */
LAPIC_X1
=
0x0000000B
,
/* divide by 1 */
};
};
uint
32_t
*
lapicaddr
;
uint
*
lapicaddr
;
static
int
static
int
lapic_read
(
int
r
)
lapic_read
(
int
r
)
...
@@ -127,7 +127,7 @@ lapic_timerintr(void)
...
@@ -127,7 +127,7 @@ lapic_timerintr(void)
void
void
lapic_init
(
int
c
)
lapic_init
(
int
c
)
{
{
uint
32_t
r
,
lvt
;
uint
r
,
lvt
;
cprintf
(
"lapic_init %d
\n
"
,
c
);
cprintf
(
"lapic_init %d
\n
"
,
c
);
...
@@ -180,7 +180,7 @@ cpu(void)
...
@@ -180,7 +180,7 @@ cpu(void)
}
}
void
void
lapic_startap
(
u
int8_t
apicid
,
int
v
)
lapic_startap
(
u
char
apicid
,
int
v
)
{
{
int
crhi
,
i
;
int
crhi
,
i
;
volatile
int
j
=
0
;
volatile
int
j
=
0
;
...
...
main.c
浏览文件 @
29270816
...
@@ -11,9 +11,9 @@
...
@@ -11,9 +11,9 @@
#include "spinlock.h"
#include "spinlock.h"
extern
char
edata
[],
end
[];
extern
char
edata
[],
end
[];
extern
u
int8_t
_binary_user1_start
[],
_binary_user1_size
[];
extern
u
char
_binary_user1_start
[],
_binary_user1_size
[];
extern
u
int8_t
_binary_usertests_start
[],
_binary_usertests_size
[];
extern
u
char
_binary_usertests_start
[],
_binary_usertests_size
[];
extern
u
int8_t
_binary_userfs_start
[],
_binary_userfs_size
[];
extern
u
char
_binary_userfs_start
[],
_binary_userfs_size
[];
extern
int
use_console_lock
;
extern
int
use_console_lock
;
...
@@ -73,7 +73,7 @@ main0(void)
...
@@ -73,7 +73,7 @@ main0(void)
lapic_enableintr
();
lapic_enableintr
();
// init disk device
// init disk device
//
ide_init();
ide_init
();
// Enable interrupts on this processor.
// Enable interrupts on this processor.
cpus
[
cpu
()].
nlock
--
;
cpus
[
cpu
()].
nlock
--
;
...
@@ -81,8 +81,8 @@ main0(void)
...
@@ -81,8 +81,8 @@ main0(void)
p
=
copyproc
(
&
proc
[
0
]);
p
=
copyproc
(
&
proc
[
0
]);
load_icode
(
p
,
_binary_usertests_start
,
(
uint
)
_binary_usertests_size
);
//
load_icode(p, _binary_usertests_start, (uint) _binary_usertests_size);
//
load_icode(p, _binary_userfs_start, (uint) _binary_userfs_size);
load_icode
(
p
,
_binary_userfs_start
,
(
uint
)
_binary_userfs_size
);
p
->
state
=
RUNNABLE
;
p
->
state
=
RUNNABLE
;
cprintf
(
"loaded userfs
\n
"
);
cprintf
(
"loaded userfs
\n
"
);
...
@@ -107,7 +107,7 @@ mpmain(void)
...
@@ -107,7 +107,7 @@ mpmain(void)
}
}
void
void
load_icode
(
struct
proc
*
p
,
u
int8_t
*
binary
,
uint
size
)
load_icode
(
struct
proc
*
p
,
u
char
*
binary
,
uint
size
)
{
{
int
i
;
int
i
;
struct
elfhdr
*
elf
;
struct
elfhdr
*
elf
;
...
...
mmu.h
浏览文件 @
29270816
...
@@ -124,43 +124,43 @@ struct segdesc {
...
@@ -124,43 +124,43 @@ struct segdesc {
// Task state segment format (as described by the Pentium architecture book)
// Task state segment format (as described by the Pentium architecture book)
struct
taskstate
{
struct
taskstate
{
uint
32_t
link
;
// Old ts selector
uint
link
;
// Old ts selector
uint
ptr_t
esp0
;
// Stack pointers and segment selectors
uint
*
esp0
;
// Stack pointers and segment selectors
u
int16_
t
ss0
;
// after an increase in privilege level
u
shor
t
ss0
;
// after an increase in privilege level
u
int16_
t
padding1
;
u
shor
t
padding1
;
uint
ptr_t
esp1
;
uint
*
esp1
;
u
int16_
t
ss1
;
u
shor
t
ss1
;
u
int16_
t
padding2
;
u
shor
t
padding2
;
uint
ptr_t
esp2
;
uint
*
esp2
;
u
int16_
t
ss2
;
u
shor
t
ss2
;
u
int16_
t
padding3
;
u
shor
t
padding3
;
physaddr_t
cr3
;
// Page directory base
void
*
cr3
;
// Page directory base
uint
ptr_t
eip
;
// Saved state from last task switch
uint
*
eip
;
// Saved state from last task switch
uint
32_t
eflags
;
uint
eflags
;
uint
32_t
eax
;
// More saved state (registers)
uint
eax
;
// More saved state (registers)
uint
32_t
ecx
;
uint
ecx
;
uint
32_t
edx
;
uint
edx
;
uint
32_t
ebx
;
uint
ebx
;
uint
ptr_t
esp
;
uint
*
esp
;
uint
ptr_t
ebp
;
uint
*
ebp
;
uint
32_t
esi
;
uint
esi
;
uint
32_t
edi
;
uint
edi
;
u
int16_
t
es
;
// Even more saved state (segment selectors)
u
shor
t
es
;
// Even more saved state (segment selectors)
u
int16_
t
padding4
;
u
shor
t
padding4
;
u
int16_
t
cs
;
u
shor
t
cs
;
u
int16_
t
padding5
;
u
shor
t
padding5
;
u
int16_
t
ss
;
u
shor
t
ss
;
u
int16_
t
padding6
;
u
shor
t
padding6
;
u
int16_
t
ds
;
u
shor
t
ds
;
u
int16_
t
padding7
;
u
shor
t
padding7
;
u
int16_
t
fs
;
u
shor
t
fs
;
u
int16_
t
padding8
;
u
shor
t
padding8
;
u
int16_
t
gs
;
u
shor
t
gs
;
u
int16_
t
padding9
;
u
shor
t
padding9
;
u
int16_
t
ldt
;
u
shor
t
ldt
;
u
int16_
t
padding10
;
u
shor
t
padding10
;
u
int16_
t
t
;
// Trap on task switch
u
shor
t
t
;
// Trap on task switch
u
int16_
t
iomb
;
// I/O map base address
u
shor
t
iomb
;
// I/O map base address
};
};
// Gate descriptors for interrupts and traps
// Gate descriptors for interrupts and traps
...
@@ -185,7 +185,7 @@ struct gatedesc {
...
@@ -185,7 +185,7 @@ struct gatedesc {
// this interrupt/trap gate explicitly using an int instruction.
// this interrupt/trap gate explicitly using an int instruction.
#define SETGATE(gate, istrap, sel, off, d) \
#define SETGATE(gate, istrap, sel, off, d) \
{ \
{ \
(gate).off_15_0 = (uint
32_t
) (off) & 0xffff; \
(gate).off_15_0 = (uint) (off) & 0xffff; \
(gate).ss = (sel); \
(gate).ss = (sel); \
(gate).args = 0; \
(gate).args = 0; \
(gate).rsv1 = 0; \
(gate).rsv1 = 0; \
...
@@ -193,13 +193,13 @@ struct gatedesc {
...
@@ -193,13 +193,13 @@ struct gatedesc {
(gate).s = 0; \
(gate).s = 0; \
(gate).dpl = (d); \
(gate).dpl = (d); \
(gate).p = 1; \
(gate).p = 1; \
(gate).off_31_16 = (uint
32_t
) (off) >> 16; \
(gate).off_31_16 = (uint) (off) >> 16; \
}
}
// Set up a call gate descriptor.
// Set up a call gate descriptor.
#define SETCALLGATE(gate, ss, off, d) \
#define SETCALLGATE(gate, ss, off, d) \
{ \
{ \
(gate).off_15_0 = (uint
32_t
) (off) & 0xffff; \
(gate).off_15_0 = (uint) (off) & 0xffff; \
(gate).ss = (ss); \
(gate).ss = (ss); \
(gate).args = 0; \
(gate).args = 0; \
(gate).rsv1 = 0; \
(gate).rsv1 = 0; \
...
@@ -207,7 +207,7 @@ struct gatedesc {
...
@@ -207,7 +207,7 @@ struct gatedesc {
(gate).s = 0; \
(gate).s = 0; \
(gate).dpl = (d); \
(gate).dpl = (d); \
(gate).p = 1; \
(gate).p = 1; \
(gate).off_31_16 = (uint
32_t
) (off) >> 16; \
(gate).off_31_16 = (uint) (off) >> 16; \
}
}
#endif
/* !__ASSEMBLER__ */
#endif
/* !__ASSEMBLER__ */
...
...
mp.c
浏览文件 @
29270816
...
@@ -37,12 +37,12 @@ int ncpu;
...
@@ -37,12 +37,12 @@ int ncpu;
static
struct
cpu
*
bcpu
;
static
struct
cpu
*
bcpu
;
static
struct
mp
*
static
struct
mp
*
mp_scan
(
u
int8_t
*
addr
,
int
len
)
mp_scan
(
u
char
*
addr
,
int
len
)
{
{
u
int8_t
*
e
,
*
p
,
sum
;
u
char
*
e
,
*
p
,
sum
;
int
i
;
int
i
;
cprintf
(
"scanning: 0x%x
\n
"
,
(
uint
32_t
)
addr
);
cprintf
(
"scanning: 0x%x
\n
"
,
(
uint
)
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
))
...
@@ -59,8 +59,8 @@ mp_scan(uint8_t *addr, int len)
...
@@ -59,8 +59,8 @@ mp_scan(uint8_t *addr, int len)
static
struct
mp
*
static
struct
mp
*
mp_search
(
void
)
mp_search
(
void
)
{
{
u
int8_t
*
bda
;
u
char
*
bda
;
uint
32_t
p
;
uint
p
;
struct
mp
*
mp
;
struct
mp
*
mp
;
/*
/*
...
@@ -70,25 +70,25 @@ mp_search(void)
...
@@ -70,25 +70,25 @@ mp_search(void)
* 2) in the last KB of system base memory;
* 2) in the last KB of system base memory;
* 3) in the BIOS ROM between 0xE0000 and 0xFFFFF.
* 3) in the BIOS ROM between 0xE0000 and 0xFFFFF.
*/
*/
bda
=
(
u
int8_t
*
)
0x400
;
bda
=
(
u
char
*
)
0x400
;
if
((
p
=
(
bda
[
0x0F
]
<<
8
)
|
bda
[
0x0E
])){
if
((
p
=
(
bda
[
0x0F
]
<<
8
)
|
bda
[
0x0E
])){
if
((
mp
=
mp_scan
((
u
int8_t
*
)
p
,
1024
)))
if
((
mp
=
mp_scan
((
u
char
*
)
p
,
1024
)))
return
mp
;
return
mp
;
}
}
else
{
else
{
p
=
((
bda
[
0x14
]
<<
8
)
|
bda
[
0x13
])
*
1024
;
p
=
((
bda
[
0x14
]
<<
8
)
|
bda
[
0x13
])
*
1024
;
if
((
mp
=
mp_scan
((
u
int8_t
*
)
p
-
1024
,
1024
)))
if
((
mp
=
mp_scan
((
u
char
*
)
p
-
1024
,
1024
)))
return
mp
;
return
mp
;
}
}
return
mp_scan
((
u
int8_t
*
)
0xF0000
,
0x10000
);
return
mp_scan
((
u
char
*
)
0xF0000
,
0x10000
);
}
}
static
int
static
int
mp_detect
(
void
)
mp_detect
(
void
)
{
{
struct
mpctb
*
pcmp
;
struct
mpctb
*
pcmp
;
u
int8_t
*
p
,
sum
;
u
char
*
p
,
sum
;
uint
32_t
length
;
uint
length
;
/*
/*
* Search for an MP configuration table. For now,
* Search for an MP configuration table. For now,
...
@@ -106,7 +106,7 @@ mp_detect(void)
...
@@ -106,7 +106,7 @@ mp_detect(void)
length
=
pcmp
->
length
;
length
=
pcmp
->
length
;
sum
=
0
;
sum
=
0
;
for
(
p
=
(
u
int8_t
*
)
pcmp
;
length
;
length
--
)
for
(
p
=
(
u
char
*
)
pcmp
;
length
;
length
--
)
sum
+=
*
p
++
;
sum
+=
*
p
++
;
if
(
sum
||
(
pcmp
->
version
!=
1
&&
pcmp
->
version
!=
4
))
if
(
sum
||
(
pcmp
->
version
!=
1
&&
pcmp
->
version
!=
4
))
...
@@ -120,7 +120,7 @@ void
...
@@ -120,7 +120,7 @@ void
mp_init
(
void
)
mp_init
(
void
)
{
{
int
r
;
int
r
;
u
int8_t
*
p
,
*
e
;
u
char
*
p
,
*
e
;
struct
mpctb
*
mpctb
;
struct
mpctb
*
mpctb
;
struct
mppe
*
proc
;
struct
mppe
*
proc
;
struct
mpbe
*
bus
;
struct
mpbe
*
bus
;
...
@@ -137,10 +137,10 @@ mp_init(void)
...
@@ -137,10 +137,10 @@ mp_init(void)
* 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
=
(
uint
32_t
*
)
mpctb
->
lapicaddr
;
lapicaddr
=
(
uint
*
)
mpctb
->
lapicaddr
;
cprintf
(
"apicaddr: %x
\n
"
,
lapicaddr
);
cprintf
(
"apicaddr: %x
\n
"
,
lapicaddr
);
p
=
((
u
int8_t
*
)
mpctb
)
+
sizeof
(
struct
mpctb
);
p
=
((
u
char
*
)
mpctb
)
+
sizeof
(
struct
mpctb
);
e
=
((
u
int8_t
*
)
mpctb
)
+
mpctb
->
length
;
e
=
((
u
char
*
)
mpctb
)
+
mpctb
->
length
;
while
(
p
<
e
)
{
while
(
p
<
e
)
{
switch
(
*
p
){
switch
(
*
p
){
...
@@ -195,18 +195,18 @@ extern void mpmain(void);
...
@@ -195,18 +195,18 @@ extern void mpmain(void);
void
void
mp_startthem
(
void
)
mp_startthem
(
void
)
{
{
extern
u
int8_t
_binary_bootother_start
[],
_binary_bootother_size
[];
extern
u
char
_binary_bootother_start
[],
_binary_bootother_size
[];
extern
int
main
();
extern
int
main
();
int
c
;
int
c
;
memmove
((
void
*
)
APBOOTCODE
,
_binary_bootother_start
,
memmove
((
void
*
)
APBOOTCODE
,
_binary_bootother_start
,
(
uint
32_t
)
_binary_bootother_size
);
(
uint
)
_binary_bootother_size
);
for
(
c
=
0
;
c
<
ncpu
;
c
++
){
for
(
c
=
0
;
c
<
ncpu
;
c
++
){
if
(
c
==
cpu
())
continue
;
if
(
c
==
cpu
())
continue
;
cprintf
(
"starting processor %d
\n
"
,
c
);
cprintf
(
"starting processor %d
\n
"
,
c
);
*
(
uint
*
)(
APBOOTCODE
-
4
)
=
(
uint
)
(
cpus
[
c
].
mpstack
)
+
MPSTACK
;
// tell it what to use for %esp
*
(
uint
*
)(
APBOOTCODE
-
4
)
=
(
uint
)
(
cpus
[
c
].
mpstack
)
+
MPSTACK
;
// tell it what to use for %esp
*
(
uint
*
)(
APBOOTCODE
-
8
)
=
(
uint
)
mpmain
;
// tell it where to jump to
*
(
uint
*
)(
APBOOTCODE
-
8
)
=
(
uint
)
mpmain
;
// tell it where to jump to
lapic_startap
(
cpus
[
c
].
apicid
,
(
uint
32_t
)
APBOOTCODE
);
lapic_startap
(
cpus
[
c
].
apicid
,
(
uint
)
APBOOTCODE
);
}
}
}
}
mp.h
浏览文件 @
29270816
...
@@ -5,63 +5,63 @@
...
@@ -5,63 +5,63 @@
*/
*/
struct
mp
{
/* floating pointer */
struct
mp
{
/* floating pointer */
u
int8_t
signature
[
4
];
/* "_MP_" */
u
char
signature
[
4
];
/* "_MP_" */
physaddr_t
physaddr
;
/* physical address of MP configuration table */
void
*
physaddr
;
/* physical address of MP configuration table */
u
int8_t
length
;
/* 1 */
u
char
length
;
/* 1 */
u
int8_t
specrev
;
/* [14] */
u
char
specrev
;
/* [14] */
u
int8_t
checksum
;
/* all bytes must add up to 0 */
u
char
checksum
;
/* all bytes must add up to 0 */
u
int8_t
type
;
/* MP system configuration type */
u
char
type
;
/* MP system configuration type */
u
int8_t
imcrp
;
u
char
imcrp
;
u
int8_t
reserved
[
3
];
u
char
reserved
[
3
];
};
};
struct
mpctb
{
/* configuration table header */
struct
mpctb
{
/* configuration table header */
u
int8_t
signature
[
4
];
/* "PCMP" */
u
char
signature
[
4
];
/* "PCMP" */
u
int16_
t
length
;
/* total table length */
u
shor
t
length
;
/* total table length */
u
int8_t
version
;
/* [14] */
u
char
version
;
/* [14] */
u
int8_t
checksum
;
/* all bytes must add up to 0 */
u
char
checksum
;
/* all bytes must add up to 0 */
u
int8_t
product
[
20
];
/* product id */
u
char
product
[
20
];
/* product id */
uint
ptr_t
oemtable
;
/* OEM table pointer */
uint
*
oemtable
;
/* OEM table pointer */
u
int16_
t
oemlength
;
/* OEM table length */
u
shor
t
oemlength
;
/* OEM table length */
u
int16_
t
entry
;
/* entry count */
u
shor
t
entry
;
/* entry count */
uint
ptr_t
lapicaddr
;
/* address of local APIC */
uint
*
lapicaddr
;
/* address of local APIC */
u
int16_
t
xlength
;
/* extended table length */
u
shor
t
xlength
;
/* extended table length */
u
int8_t
xchecksum
;
/* extended table checksum */
u
char
xchecksum
;
/* extended table checksum */
u
int8_t
reserved
;
u
char
reserved
;
};
};
struct
mppe
{
/* processor table entry */
struct
mppe
{
/* processor table entry */
u
int8_t
type
;
/* entry type (0) */
u
char
type
;
/* entry type (0) */
u
int8_t
apicid
;
/* local APIC id */
u
char
apicid
;
/* local APIC id */
u
int8_t
version
;
/* local APIC verison */
u
char
version
;
/* local APIC verison */
u
int8_t
flags
;
/* CPU flags */
u
char
flags
;
/* CPU flags */
u
int8_t
signature
[
4
];
/* CPU signature */
u
char
signature
[
4
];
/* CPU signature */
uint
32_t
feature
;
/* feature flags from CPUID instruction */
uint
feature
;
/* feature flags from CPUID instruction */
u
int8_t
reserved
[
8
];
u
char
reserved
[
8
];
};
};
struct
mpbe
{
/* bus table entry */
struct
mpbe
{
/* bus table entry */
u
int8_t
type
;
/* entry type (1) */
u
char
type
;
/* entry type (1) */
u
int8_t
busno
;
/* bus id */
u
char
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 */
u
int8_t
type
;
/* entry type (2) */
u
char
type
;
/* entry type (2) */
u
int8_t
apicno
;
/* I/O APIC id */
u
char
apicno
;
/* I/O APIC id */
u
int8_t
version
;
/* I/O APIC version */
u
char
version
;
/* I/O APIC version */
u
int8_t
flags
;
/* I/O APIC flags */
u
char
flags
;
/* I/O APIC flags */
uint
ptr_t
addr
;
/* I/O APIC address */
uint
*
addr
;
/* I/O APIC address */
};
};
struct
mpie
{
/* interrupt table entry */
struct
mpie
{
/* interrupt table entry */
u
int8_t
type
;
/* entry type ([34]) */
u
char
type
;
/* entry type ([34]) */
u
int8_t
intr
;
/* interrupt type */
u
char
intr
;
/* interrupt type */
u
int16_
t
flags
;
/* interrupt flag */
u
shor
t
flags
;
/* interrupt flag */
u
int8_t
busno
;
/* source bus id */
u
char
busno
;
/* source bus id */
u
int8_t
irq
;
/* source bus irq */
u
char
irq
;
/* source bus irq */
u
int8_t
apicno
;
/* destination APIC id */
u
char
apicno
;
/* destination APIC id */
u
int8_t
intin
;
/* destination APIC [L]INTIN# */
u
char
intin
;
/* destination APIC [L]INTIN# */
};
};
enum
{
/* table entry types */
enum
{
/* table entry types */
...
...
picirq.c
浏览文件 @
29270816
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// Current IRQ mask.
// Current IRQ mask.
// Initial IRQ mask has interrupt 2 enabled (for slave 8259A).
// Initial IRQ mask has interrupt 2 enabled (for slave 8259A).
u
int16_
t
irq_mask_8259A
=
0xFFFF
&
~
(
1
<<
IRQ_SLAVE
);
u
shor
t
irq_mask_8259A
=
0xFFFF
&
~
(
1
<<
IRQ_SLAVE
);
/* Initialize the 8259A interrupt controllers. */
/* Initialize the 8259A interrupt controllers. */
void
void
...
@@ -71,7 +71,7 @@ pic_init(void)
...
@@ -71,7 +71,7 @@ pic_init(void)
}
}
void
void
irq_setmask_8259A
(
u
int16_
t
mask
)
irq_setmask_8259A
(
u
shor
t
mask
)
{
{
int
i
;
int
i
;
irq_mask_8259A
=
mask
;
irq_mask_8259A
=
mask
;
...
...
proc.h
浏览文件 @
29270816
...
@@ -65,7 +65,7 @@ extern struct proc *curproc[NCPU]; // can be NULL if no proc running.
...
@@ -65,7 +65,7 @@ extern struct proc *curproc[NCPU]; // can be NULL if no proc running.
#define MPSTACK 512
#define MPSTACK 512
struct
cpu
{
struct
cpu
{
u
int8_t
apicid
;
// Local APIC ID
u
char
apicid
;
// Local APIC ID
struct
jmpbuf
jmpbuf
;
struct
jmpbuf
jmpbuf
;
char
mpstack
[
MPSTACK
];
// per-cpu start-up stack, only used to get into main()
char
mpstack
[
MPSTACK
];
// per-cpu start-up stack, only used to get into main()
struct
proc
*
lastproc
;
// last proc scheduled on this cpu (never NULL)
struct
proc
*
lastproc
;
// last proc scheduled on this cpu (never NULL)
...
...
spinlock.h
浏览文件 @
29270816
struct
spinlock
{
struct
spinlock
{
uint
locked
;
uint
locked
;
uint
32_t
pc
;
uint
pc
;
int
cpu
;
int
cpu
;
};
};
string.c
浏览文件 @
29270816
...
@@ -15,8 +15,8 @@ memset(void *dst, int c, uint n)
...
@@ -15,8 +15,8 @@ memset(void *dst, int c, uint n)
int
int
memcmp
(
const
void
*
v1
,
const
void
*
v2
,
uint
n
)
memcmp
(
const
void
*
v1
,
const
void
*
v2
,
uint
n
)
{
{
const
u
int8_t
*
s1
=
(
const
uint8_t
*
)
v1
;
const
u
char
*
s1
=
(
const
uchar
*
)
v1
;
const
u
int8_t
*
s2
=
(
const
uint8_t
*
)
v2
;
const
u
char
*
s2
=
(
const
uchar
*
)
v2
;
while
(
n
--
>
0
)
{
while
(
n
--
>
0
)
{
if
(
*
s1
!=
*
s2
)
if
(
*
s1
!=
*
s2
)
...
@@ -55,7 +55,7 @@ strncmp(const char *p, const char *q, uint n)
...
@@ -55,7 +55,7 @@ strncmp(const char *p, const char *q, uint n)
if
(
n
==
0
)
if
(
n
==
0
)
return
0
;
return
0
;
else
else
return
(
int
)
((
u
int8_t
)
*
p
-
(
uint8_t
)
*
q
);
return
(
int
)
((
u
char
)
*
p
-
(
uchar
)
*
q
);
}
}
// Memcpy is deprecated and should NOT be called.
// Memcpy is deprecated and should NOT be called.
...
...
syscall.c
浏览文件 @
29270816
...
@@ -235,8 +235,10 @@ sys_block(void)
...
@@ -235,8 +235,10 @@ sys_block(void)
if
((
c
=
ide_start_read
(
i
,
buf
,
1
))
==
0
)
{
if
((
c
=
ide_start_read
(
i
,
buf
,
1
))
==
0
)
{
panic
(
"couldn't start read
\n
"
);
panic
(
"couldn't start read
\n
"
);
}
}
#if 0
cprintf("call sleep\n");
cprintf("call sleep\n");
sleep (c, &ide_lock);
sleep (c, &ide_lock);
#endif
if
(
ide_finish_read
(
c
))
{
if
(
ide_finish_read
(
c
))
{
panic
(
"couldn't do read
\n
"
);
panic
(
"couldn't do read
\n
"
);
}
}
...
...
types.h
浏览文件 @
29270816
typedef
unsigned
int
uint
;
typedef
unsigned
int
uint
;
typedef
unsigned
short
ushort
;
typedef
unsigned
long
long
uint64_t
;
typedef
unsigned
char
uchar
;
typedef
unsigned
int
uint32_t
;
typedef
unsigned
short
uint16_t
;
typedef
unsigned
char
uint8_t
;
typedef
uint32_t
uintptr_t
;
typedef
uint32_t
physaddr_t
;
x86.h
浏览文件 @
29270816
static
__inline
void
breakpoint
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
breakpoint
(
void
)
__attribute__
((
always_inline
));
static
__inline
u
int8_t
inb
(
int
port
)
__attribute__
((
always_inline
));
static
__inline
u
char
inb
(
int
port
)
__attribute__
((
always_inline
));
static
__inline
void
insb
(
int
port
,
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
insb
(
int
port
,
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
u
int16_
t
inw
(
int
port
)
__attribute__
((
always_inline
));
static
__inline
u
shor
t
inw
(
int
port
)
__attribute__
((
always_inline
));
static
__inline
void
insw
(
int
port
,
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
insw
(
int
port
,
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
uint
32_t
inl
(
int
port
)
__attribute__
((
always_inline
));
static
__inline
uint
inl
(
int
port
)
__attribute__
((
always_inline
));
static
__inline
void
insl
(
int
port
,
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
insl
(
int
port
,
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outb
(
int
port
,
u
int8_t
data
)
__attribute__
((
always_inline
));
static
__inline
void
outb
(
int
port
,
u
char
data
)
__attribute__
((
always_inline
));
static
__inline
void
outsb
(
int
port
,
const
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outsb
(
int
port
,
const
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outw
(
int
port
,
u
int16_
t
data
)
__attribute__
((
always_inline
));
static
__inline
void
outw
(
int
port
,
u
shor
t
data
)
__attribute__
((
always_inline
));
static
__inline
void
outsw
(
int
port
,
const
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outsw
(
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
outsl
(
int
port
,
const
void
*
addr
,
int
cnt
)
__attribute__
((
always_inline
));
static
__inline
void
outl
(
int
port
,
uint
32_t
data
)
__attribute__
((
always_inline
));
static
__inline
void
outl
(
int
port
,
uint
data
)
__attribute__
((
always_inline
));
static
__inline
void
invlpg
(
void
*
addr
)
__attribute__
((
always_inline
));
static
__inline
void
invlpg
(
void
*
addr
)
__attribute__
((
always_inline
));
struct
segdesc
;
struct
segdesc
;
static
__inline
void
lgdt
(
struct
segdesc
*
p
,
int
)
__attribute__
((
always_inline
));
static
__inline
void
lgdt
(
struct
segdesc
*
p
,
int
)
__attribute__
((
always_inline
));
struct
gatedesc
;
struct
gatedesc
;
static
__inline
void
lidt
(
struct
gatedesc
*
p
,
int
)
__attribute__
((
always_inline
));
static
__inline
void
lidt
(
struct
gatedesc
*
p
,
int
)
__attribute__
((
always_inline
));
static
__inline
void
lldt
(
u
int16_
t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
lldt
(
u
shor
t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
ltr
(
u
int16_
t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
ltr
(
u
shor
t
sel
)
__attribute__
((
always_inline
));
static
__inline
void
lcr0
(
uint
32_t
val
)
__attribute__
((
always_inline
));
static
__inline
void
lcr0
(
uint
val
)
__attribute__
((
always_inline
));
static
__inline
uint
32_t
rcr0
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
rcr0
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
32_t
rcr2
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
rcr2
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
lcr3
(
uint
32_t
val
)
__attribute__
((
always_inline
));
static
__inline
void
lcr3
(
uint
val
)
__attribute__
((
always_inline
));
static
__inline
uint
32_t
rcr3
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
rcr3
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
lcr4
(
uint
32_t
val
)
__attribute__
((
always_inline
));
static
__inline
void
lcr4
(
uint
val
)
__attribute__
((
always_inline
));
static
__inline
uint
32_t
rcr4
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
rcr4
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
tlbflush
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
tlbflush
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint32_t
read_eflags
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
read_eflags
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
write_eflags
(
uint32_t
eflags
)
__attribute__
((
always_inline
));
static
__inline
void
write_eflags
(
uint
eflags
)
__attribute__
((
always_inline
));
static
__inline
uint32_t
read_ebp
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
read_ebp
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint32_t
read_esp
(
void
)
__attribute__
((
always_inline
));
static
__inline
uint
read_esp
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
cpuid
(
uint32_t
info
,
uint32_t
*
eaxp
,
uint32_t
*
ebxp
,
uint32_t
*
ecxp
,
uint32_t
*
edxp
);
static
__inline
void
cpuid
(
uint
info
,
uint
*
eaxp
,
uint
*
ebxp
,
uint
*
ecxp
,
uint
*
edxp
);
static
__inline
uint64_t
read_tsc
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
cli
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
cli
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
sti
(
void
)
__attribute__
((
always_inline
));
static
__inline
void
sti
(
void
)
__attribute__
((
always_inline
));
...
@@ -41,10 +40,10 @@ breakpoint(void)
...
@@ -41,10 +40,10 @@ breakpoint(void)
__asm
__volatile
(
"int3"
);
__asm
__volatile
(
"int3"
);
}
}
static
__inline
u
int8_t
static
__inline
u
char
inb
(
int
port
)
inb
(
int
port
)
{
{
u
int8_t
data
;
u
char
data
;
__asm
__volatile
(
"inb %w1,%0"
:
"=a"
(
data
)
:
"d"
(
port
));
__asm
__volatile
(
"inb %w1,%0"
:
"=a"
(
data
)
:
"d"
(
port
));
return
data
;
return
data
;
}
}
...
@@ -58,10 +57,10 @@ insb(int port, void *addr, int cnt)
...
@@ -58,10 +57,10 @@ insb(int port, void *addr, int cnt)
"memory"
,
"cc"
);
"memory"
,
"cc"
);
}
}
static
__inline
u
int16_
t
static
__inline
u
shor
t
inw
(
int
port
)
inw
(
int
port
)
{
{
u
int16_
t
data
;
u
shor
t
data
;
__asm
__volatile
(
"inw %w1,%0"
:
"=a"
(
data
)
:
"d"
(
port
));
__asm
__volatile
(
"inw %w1,%0"
:
"=a"
(
data
)
:
"d"
(
port
));
return
data
;
return
data
;
}
}
...
@@ -75,10 +74,10 @@ insw(int port, void *addr, int cnt)
...
@@ -75,10 +74,10 @@ insw(int port, void *addr, int cnt)
"memory"
,
"cc"
);
"memory"
,
"cc"
);
}
}
static
__inline
uint
32_t
static
__inline
uint
inl
(
int
port
)
inl
(
int
port
)
{
{
uint
32_t
data
;
uint
data
;
__asm
__volatile
(
"inl %w1,%0"
:
"=a"
(
data
)
:
"d"
(
port
));
__asm
__volatile
(
"inl %w1,%0"
:
"=a"
(
data
)
:
"d"
(
port
));
return
data
;
return
data
;
}
}
...
@@ -93,7 +92,7 @@ insl(int port, void *addr, int cnt)
...
@@ -93,7 +92,7 @@ insl(int port, void *addr, int cnt)
}
}
static
__inline
void
static
__inline
void
outb
(
int
port
,
u
int8_t
data
)
outb
(
int
port
,
u
char
data
)
{
{
__asm
__volatile
(
"outb %0,%w1"
:
:
"a"
(
data
),
"d"
(
port
));
__asm
__volatile
(
"outb %0,%w1"
:
:
"a"
(
data
),
"d"
(
port
));
}
}
...
@@ -108,7 +107,7 @@ outsb(int port, const void *addr, int cnt)
...
@@ -108,7 +107,7 @@ outsb(int port, const void *addr, int cnt)
}
}
static
__inline
void
static
__inline
void
outw
(
int
port
,
u
int16_
t
data
)
outw
(
int
port
,
u
shor
t
data
)
{
{
__asm
__volatile
(
"outw %0,%w1"
:
:
"a"
(
data
),
"d"
(
port
));
__asm
__volatile
(
"outw %0,%w1"
:
:
"a"
(
data
),
"d"
(
port
));
}
}
...
@@ -132,7 +131,7 @@ outsl(int port, const void *addr, int cnt)
...
@@ -132,7 +131,7 @@ outsl(int port, const void *addr, int cnt)
}
}
static
__inline
void
static
__inline
void
outl
(
int
port
,
uint
32_t
data
)
outl
(
int
port
,
uint
data
)
{
{
__asm
__volatile
(
"outl %0,%w1"
:
:
"a"
(
data
),
"d"
(
port
));
__asm
__volatile
(
"outl %0,%w1"
:
:
"a"
(
data
),
"d"
(
port
));
}
}
...
@@ -146,7 +145,7 @@ invlpg(void *addr)
...
@@ -146,7 +145,7 @@ invlpg(void *addr)
static
__inline
void
static
__inline
void
lgdt
(
struct
segdesc
*
p
,
int
size
)
lgdt
(
struct
segdesc
*
p
,
int
size
)
{
{
volatile
u
int16_
t
pd
[
3
];
volatile
u
shor
t
pd
[
3
];
pd
[
0
]
=
size
-
1
;
pd
[
0
]
=
size
-
1
;
pd
[
1
]
=
(
uint
)
p
;
pd
[
1
]
=
(
uint
)
p
;
...
@@ -158,7 +157,7 @@ lgdt(struct segdesc *p, int size)
...
@@ -158,7 +157,7 @@ lgdt(struct segdesc *p, int size)
static
__inline
void
static
__inline
void
lidt
(
struct
gatedesc
*
p
,
int
size
)
lidt
(
struct
gatedesc
*
p
,
int
size
)
{
{
volatile
u
int16_
t
pd
[
3
];
volatile
u
shor
t
pd
[
3
];
pd
[
0
]
=
size
-
1
;
pd
[
0
]
=
size
-
1
;
pd
[
1
]
=
(
uint
)
p
;
pd
[
1
]
=
(
uint
)
p
;
...
@@ -168,63 +167,63 @@ lidt(struct gatedesc *p, int size)
...
@@ -168,63 +167,63 @@ lidt(struct gatedesc *p, int size)
}
}
static
__inline
void
static
__inline
void
lldt
(
u
int16_
t
sel
)
lldt
(
u
shor
t
sel
)
{
{
__asm
__volatile
(
"lldt %0"
:
:
"r"
(
sel
));
__asm
__volatile
(
"lldt %0"
:
:
"r"
(
sel
));
}
}
static
__inline
void
static
__inline
void
ltr
(
u
int16_
t
sel
)
ltr
(
u
shor
t
sel
)
{
{
__asm
__volatile
(
"ltr %0"
:
:
"r"
(
sel
));
__asm
__volatile
(
"ltr %0"
:
:
"r"
(
sel
));
}
}
static
__inline
void
static
__inline
void
lcr0
(
uint
32_t
val
)
lcr0
(
uint
val
)
{
{
__asm
__volatile
(
"movl %0,%%cr0"
:
:
"r"
(
val
));
__asm
__volatile
(
"movl %0,%%cr0"
:
:
"r"
(
val
));
}
}
static
__inline
uint
32_t
static
__inline
uint
rcr0
(
void
)
rcr0
(
void
)
{
{
uint
32_t
val
;
uint
val
;
__asm
__volatile
(
"movl %%cr0,%0"
:
"=r"
(
val
));
__asm
__volatile
(
"movl %%cr0,%0"
:
"=r"
(
val
));
return
val
;
return
val
;
}
}
static
__inline
uint
32_t
static
__inline
uint
rcr2
(
void
)
rcr2
(
void
)
{
{
uint
32_t
val
;
uint
val
;
__asm
__volatile
(
"movl %%cr2,%0"
:
"=r"
(
val
));
__asm
__volatile
(
"movl %%cr2,%0"
:
"=r"
(
val
));
return
val
;
return
val
;
}
}
static
__inline
void
static
__inline
void
lcr3
(
uint
32_t
val
)
lcr3
(
uint
val
)
{
{
__asm
__volatile
(
"movl %0,%%cr3"
:
:
"r"
(
val
));
__asm
__volatile
(
"movl %0,%%cr3"
:
:
"r"
(
val
));
}
}
static
__inline
uint
32_t
static
__inline
uint
rcr3
(
void
)
rcr3
(
void
)
{
{
uint
32_t
val
;
uint
val
;
__asm
__volatile
(
"movl %%cr3,%0"
:
"=r"
(
val
));
__asm
__volatile
(
"movl %%cr3,%0"
:
"=r"
(
val
));
return
val
;
return
val
;
}
}
static
__inline
void
static
__inline
void
lcr4
(
uint
32_t
val
)
lcr4
(
uint
val
)
{
{
__asm
__volatile
(
"movl %0,%%cr4"
:
:
"r"
(
val
));
__asm
__volatile
(
"movl %0,%%cr4"
:
:
"r"
(
val
));
}
}
static
__inline
uint
32_t
static
__inline
uint
rcr4
(
void
)
rcr4
(
void
)
{
{
uint
32_t
cr4
;
uint
cr4
;
__asm
__volatile
(
"movl %%cr4,%0"
:
"=r"
(
cr4
));
__asm
__volatile
(
"movl %%cr4,%0"
:
"=r"
(
cr4
));
return
cr4
;
return
cr4
;
}
}
...
@@ -232,69 +231,69 @@ rcr4(void)
...
@@ -232,69 +231,69 @@ rcr4(void)
static
__inline
void
static
__inline
void
tlbflush
(
void
)
tlbflush
(
void
)
{
{
uint
32_t
cr3
;
uint
cr3
;
__asm
__volatile
(
"movl %%cr3,%0"
:
"=r"
(
cr3
));
__asm
__volatile
(
"movl %%cr3,%0"
:
"=r"
(
cr3
));
__asm
__volatile
(
"movl %0,%%cr3"
:
:
"r"
(
cr3
));
__asm
__volatile
(
"movl %0,%%cr3"
:
:
"r"
(
cr3
));
}
}
static
__inline
uint
32_t
static
__inline
uint
read_eflags
(
void
)
read_eflags
(
void
)
{
{
uint
32_t
eflags
;
uint
eflags
;
__asm
__volatile
(
"pushfl; popl %0"
:
"=r"
(
eflags
));
__asm
__volatile
(
"pushfl; popl %0"
:
"=r"
(
eflags
));
return
eflags
;
return
eflags
;
}
}
static
__inline
void
static
__inline
void
write_eflags
(
uint
32_t
eflags
)
write_eflags
(
uint
eflags
)
{
{
__asm
__volatile
(
"pushl %0; popfl"
:
:
"r"
(
eflags
));
__asm
__volatile
(
"pushl %0; popfl"
:
:
"r"
(
eflags
));
}
}
static
__inline
uint
32_t
static
__inline
uint
read_ebp
(
void
)
read_ebp
(
void
)
{
{
uint
32_t
ebp
;
uint
ebp
;
__asm
__volatile
(
"movl %%ebp,%0"
:
"=r"
(
ebp
));
__asm
__volatile
(
"movl %%ebp,%0"
:
"=r"
(
ebp
));
return
ebp
;
return
ebp
;
}
}
static
__inline
uint
32_t
static
__inline
uint
read_esp
(
void
)
read_esp
(
void
)
{
{
uint
32_t
esp
;
uint
esp
;
__asm
__volatile
(
"movl %%esp,%0"
:
"=r"
(
esp
));
__asm
__volatile
(
"movl %%esp,%0"
:
"=r"
(
esp
));
return
esp
;
return
esp
;
}
}
static
__inline
uint
32_t
static
__inline
uint
read_esi
(
void
)
read_esi
(
void
)
{
{
uint
32_t
esi
;
uint
esi
;
__asm
__volatile
(
"movl %%esi,%0"
:
"=r"
(
esi
));
__asm
__volatile
(
"movl %%esi,%0"
:
"=r"
(
esi
));
return
esi
;
return
esi
;
}
}
static
__inline
uint
32_t
static
__inline
uint
read_edi
(
void
)
read_edi
(
void
)
{
{
uint
32_t
edi
;
uint
edi
;
__asm
__volatile
(
"movl %%edi,%0"
:
"=r"
(
edi
));
__asm
__volatile
(
"movl %%edi,%0"
:
"=r"
(
edi
));
return
edi
;
return
edi
;
}
}
static
__inline
uint
32_t
static
__inline
uint
read_ebx
(
void
)
read_ebx
(
void
)
{
{
uint
32_t
ebx
;
uint
ebx
;
__asm
__volatile
(
"movl %%ebx,%0"
:
"=r"
(
ebx
));
__asm
__volatile
(
"movl %%ebx,%0"
:
"=r"
(
ebx
));
return
ebx
;
return
ebx
;
}
}
static
__inline
void
static
__inline
void
cpuid
(
uint
32_t
info
,
uint32_t
*
eaxp
,
uint32_t
*
ebxp
,
uint32_t
*
ecxp
,
uint32_
t
*
edxp
)
cpuid
(
uint
info
,
uint
*
eaxp
,
uint
*
ebxp
,
uint
*
ecxp
,
uin
t
*
edxp
)
{
{
uint
32_t
eax
,
ebx
,
ecx
,
edx
;
uint
eax
,
ebx
,
ecx
,
edx
;
asm
volatile
(
"cpuid"
asm
volatile
(
"cpuid"
:
"=a"
(
eax
),
"=b"
(
ebx
),
"=c"
(
ecx
),
"=d"
(
edx
)
:
"=a"
(
eax
),
"=b"
(
ebx
),
"=c"
(
ecx
),
"=d"
(
edx
)
:
"a"
(
info
));
:
"a"
(
info
));
...
@@ -308,10 +307,10 @@ cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *e
...
@@ -308,10 +307,10 @@ cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *e
*
edxp
=
edx
;
*
edxp
=
edx
;
}
}
static
__inline
uint
32_t
static
__inline
uint
cmpxchg
(
uint
32_t
oldval
,
uint32_t
newval
,
volatile
uint32_
t
*
lock_addr
)
cmpxchg
(
uint
oldval
,
uint
newval
,
volatile
uin
t
*
lock_addr
)
{
{
uint
32_t
result
;
uint
result
;
__asm__
__volatile__
(
__asm__
__volatile__
(
"lock; cmpxchgl %2, %0"
"lock; cmpxchgl %2, %0"
:
"+m"
(
*
lock_addr
),
"=a"
(
result
)
:
"r"
(
newval
),
"1"
(
oldval
)
:
"cc"
:
"+m"
(
*
lock_addr
),
"=a"
(
result
)
:
"r"
(
newval
),
"1"
(
oldval
)
:
"cc"
...
@@ -319,14 +318,6 @@ cmpxchg(uint32_t oldval, uint32_t newval, volatile uint32_t* lock_addr)
...
@@ -319,14 +318,6 @@ cmpxchg(uint32_t oldval, uint32_t newval, volatile uint32_t* lock_addr)
return
result
;
return
result
;
}
}
static
__inline
uint64_t
read_tsc
(
void
)
{
uint64_t
tsc
;
__asm
__volatile
(
"rdtsc"
:
"=A"
(
tsc
));
return
tsc
;
}
static
__inline
void
static
__inline
void
cli
(
void
)
cli
(
void
)
{
{
...
@@ -341,30 +332,30 @@ sti(void)
...
@@ -341,30 +332,30 @@ sti(void)
struct
trapframe
{
struct
trapframe
{
/* registers as pushed by pusha */
/* registers as pushed by pusha */
uint
32_t
edi
;
uint
edi
;
uint
32_t
esi
;
uint
esi
;
uint
32_t
ebp
;
uint
ebp
;
uint
32_t
oesp
;
/* Useless */
uint
oesp
;
/* Useless */
uint
32_t
ebx
;
uint
ebx
;
uint
32_t
edx
;
uint
edx
;
uint
32_t
ecx
;
uint
ecx
;
uint
32_t
eax
;
uint
eax
;
/* rest of trap frame */
/* rest of trap frame */
u
int16_
t
es
;
u
shor
t
es
;
u
int16_
t
padding1
;
u
shor
t
padding1
;
u
int16_
t
ds
;
u
shor
t
ds
;
u
int16_
t
padding2
;
u
shor
t
padding2
;
uint
32_t
trapno
;
uint
trapno
;
/* below here defined by x86 hardware */
/* below here defined by x86 hardware */
uint
32_t
err
;
uint
err
;
uint
ptr_t
eip
;
uint
eip
;
u
int16_
t
cs
;
u
shor
t
cs
;
u
int16_
t
padding3
;
u
shor
t
padding3
;
uint
32_t
eflags
;
uint
eflags
;
/* below here only when crossing rings, such as from user to kernel */
/* below here only when crossing rings, such as from user to kernel */
uint
ptr_t
esp
;
uint
esp
;
u
int16_
t
ss
;
u
shor
t
ss
;
u
int16_
t
padding4
;
u
shor
t
padding4
;
};
};
#define MAX_IRQS 16 // Number of IRQs
#define MAX_IRQS 16 // Number of IRQs
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论