Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xv6-19au
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
csep551
xv6-19au
Commits
30f5bf05
Commit
30f5bf05
authored
14 years ago
by
Frans Kaashoek
Browse files
Options
Downloads
Patches
Plain Diff
some cleanup
parent
af03ab14
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
defs.h
+9
-10
9 additions, 10 deletions
defs.h
mmu.h
+0
-1
0 additions, 1 deletion
mmu.h
proc.c
+1
-1
1 addition, 1 deletion
proc.c
types.h
+1
-0
1 addition, 0 deletions
types.h
vm.c
+34
-20
34 additions, 20 deletions
vm.c
with
45 additions
and
32 deletions
defs.h
+
9
−
10
View file @
30f5bf05
...
...
@@ -155,23 +155,22 @@ void uartputc(int);
// vm.c
#define PGROUNDUP(sz) ((sz+PGSIZE-1) & ~(PGSIZE-1))
extern
pde_t
*
kpgdir
;
void
pminit
(
void
);
void
ksegment
(
void
);
void
kvmalloc
(
void
);
void
loadkvm
(
void
);
void
vminit
(
void
);
void
jkstack
();
void
printstack
(
void
);
void
printpgdir
(
uint
*
);
uin
t
*
setupkvm
(
void
);
// XXX need pde_t*
char
*
uva2ka
(
uin
t
*
,
char
*
);
int
allocuvm
(
uin
t
*
,
char
*
,
uint
);
// XXX need pde_t*
void
freevm
(
uin
t
*
);
void
inituvm
(
uin
t
*
,
char
*
,
char
*
,
uint
);
int
loaduvm
(
uin
t
*
,
char
*
,
struct
inode
*
ip
,
uint
,
uint
);
uin
t
*
copyuvm
(
uin
t
*
,
uint
);
void
printpgdir
(
pde_t
*
);
pde_
t
*
setupkvm
(
void
);
char
*
uva2ka
(
pde_
t
*
,
char
*
);
int
allocuvm
(
pde_
t
*
,
char
*
,
uint
);
void
freevm
(
pde_
t
*
);
void
inituvm
(
pde_
t
*
,
char
*
,
char
*
,
uint
);
int
loaduvm
(
pde_
t
*
,
char
*
,
struct
inode
*
ip
,
uint
,
uint
);
pde_
t
*
copyuvm
(
pde_
t
*
,
uint
);
void
loadvm
(
struct
proc
*
);
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
This diff is collapsed.
Click to expand it.
mmu.h
+
0
−
1
View file @
30f5bf05
...
...
@@ -148,7 +148,6 @@ struct segdesc {
#define PTE_ADDR(pte) ((uint) (pte) & ~0xFFF)
typedef
uint
pte_t
;
typedef
uint
pde_t
;
// Control Register flags
#define CR0_PE 0x00000001 // Protection Enable
...
...
This diff is collapsed.
Click to expand it.
proc.c
+
1
−
1
View file @
30f5bf05
...
...
@@ -242,7 +242,7 @@ sched(void)
panic
(
"sched running"
);
if
(
readeflags
()
&
FL_IF
)
panic
(
"sched interruptible"
);
l
oadkvm
(
);
// Switch to the kernel page table
l
cr3
(
PADDR
(
kpgdir
)
);
// Switch to the kernel page table
intena
=
cpu
->
intena
;
swtch
(
&
proc
->
context
,
cpu
->
scheduler
);
cpu
->
intena
=
intena
;
...
...
This diff is collapsed.
Click to expand it.
types.h
+
1
−
0
View file @
30f5bf05
typedef
unsigned
int
uint
;
typedef
unsigned
short
ushort
;
typedef
unsigned
char
uchar
;
typedef
uint
pde_t
;
This diff is collapsed.
Click to expand it.
vm.c
+
34
−
20
View file @
30f5bf05
...
...
@@ -6,13 +6,33 @@
#include
"proc.h"
#include
"elf.h"
static
uint
kerntext
;
// linear/physical address of start of kernel text
static
uint
kerntsz
;
// The mappings from logical to linear are one to one (i.e.,
// segmentation doesn't do anything).
// The mapping from linear to physical are one to one for the kernel.
// The mappings for the kernel include all of physical memory (until
// PHYSTOP), including the I/O hole, and the top of physical address
// space, where additional devices are located.
// The kernel itself is linked to be at 1MB, and its physical memory
// is also at 1MB.
// Physical memory for user programs is allocated from physical memory
// between kernend and the end of physical memory (PHYSTOP).
// The virtual address space of each user program includes the kernel
// (which is inaccessible in user mode). The user program addresses
// range from 0 till 640KB (USERTOP), which where the I/O hole starts
// (both in physical memory and in the kernel's virtual address
// space).
#define PHYSTOP 0x300000
#define USERTOP 0xA0000
static
uint
kerntext
;
// Linker start kernel at 1MB
static
uint
kerntsz
;
static
uint
kerndata
;
static
uint
kerndsz
;
static
uint
kernend
;
static
uint
freesz
;
static
pde_t
*
kpgdir
;
pde_t
*
kpgdir
;
// One kernel page table for scheduler procs
void
printstack
()
...
...
@@ -140,13 +160,14 @@ loadvm(struct proc *p)
lcr3
(
PADDR
(
p
->
pgdir
));
// switch to new address space
popcli
();
// Conservatively flush other processor's TLBs (XXX lazy--just 2 cpus)
// Conservatively flush other processor's TLBs
// XXX lazy--just 2 cpus, but xv6 doesn't need shootdown anyway.
if
(
cpu
->
id
==
0
)
lapic_tlbflush
(
1
);
else
lapic_tlbflush
(
0
);
}
// Setup kernel part of page table. Linear adresses map one-to-one
on
// physical addresses.
// Setup kernel part of
a
page table. Linear adresses map one-to-one
//
on
physical addresses.
pde_t
*
setupkvm
(
void
)
{
...
...
@@ -157,7 +178,7 @@ setupkvm(void)
return
0
;
memset
(
pgdir
,
0
,
PGSIZE
);
// Map IO space from 640K to 1Mbyte
if
(
!
mappages
(
pgdir
,
(
void
*
)
0xA0000
,
0x60000
,
0xA0000
,
PTE_W
,
0
))
if
(
!
mappages
(
pgdir
,
(
void
*
)
USERTOP
,
0x60000
,
USERTOP
,
PTE_W
,
0
))
return
0
;
// Map kernel text from kern text addr read-only
if
(
!
mappages
(
pgdir
,
(
void
*
)
kerntext
,
kerntsz
,
kerntext
,
0
,
0
))
...
...
@@ -190,7 +211,7 @@ allocuvm(pde_t *pgdir, char *addr, uint sz)
char
*
mem
;
n
=
PGROUNDUP
(
sz
);
if
(
addr
+
n
>=
0xA0000
)
if
(
addr
+
n
>=
USERTOP
)
return
0
;
for
(
i
=
0
;
i
<
n
;
i
+=
PGSIZE
)
{
if
(
!
(
mem
=
kalloc
(
PGSIZE
)))
{
// XXX cleanup what we did?
...
...
@@ -217,7 +238,7 @@ freevm(pde_t *pgdir)
if
(
pgtab
[
j
]
!=
0
)
{
uint
pa
=
PTE_ADDR
(
pgtab
[
j
]);
uint
va
=
PGADDR
(
i
,
j
,
0
);
if
(
va
>=
0xA0000
)
// done with user part?
if
(
va
>=
USERTOP
)
// done with user part?
break
;
kfree
((
void
*
)
pa
,
PGSIZE
);
pgtab
[
j
]
=
0
;
...
...
@@ -305,12 +326,12 @@ pminit(void)
kerndata
=
ph
[
1
].
va
;
kerntsz
=
kerndata
-
kerntext
;
kerndsz
=
kernend
-
kerndata
;
freesz
=
0x300000
-
kernend
;
// XXX no more than 3 Mbyte of phys mem
freesz
=
PHYSTOP
-
kernend
;
cprintf
(
"kerntext@0x%x(sz=0x%x), kerndata@0x%x(sz=0x%x), kernend 0x%x freesz = 0x%x
\n
"
,
kerntext
,
kerntsz
,
kerndata
,
kerndsz
,
kernend
,
freesz
);
kinit
((
char
*
)
kernend
,
freesz
);
// XXX should be called once on bootcpu
kinit
((
char
*
)
kernend
,
freesz
);
}
// Jump to mainc on a properly-allocated kernel stack
...
...
@@ -331,20 +352,13 @@ kvmalloc(void)
kpgdir
=
setupkvm
();
}
// Switch to the kernel page table (used by the scheduler)
void
loadkvm
(
void
)
{
lcr3
(
PADDR
(
kpgdir
));
}
// Turn on paging.
void
vminit
(
void
)
{
uint
cr0
;
loadkvm
();
// Turn on paging.
lcr3
(
PADDR
(
kpgdir
));
cr0
=
rcr0
();
cr0
|=
CR0_PE
|
CR0_PG
|
CR0_AM
|
CR0_WP
|
CR0_NE
|
CR0_TS
|
CR0_EM
|
CR0_MP
;
cr0
&=
~
(
CR0_TS
|
CR0_EM
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment