Skip to content

Commit

Permalink
Merge branch 'master' of git+ssh://amsterdam.csail.mit.edu/home/am0/6…
Browse files Browse the repository at this point in the history
….828/xv6
  • Loading branch information
Frans Kaashoek committed Sep 27, 2011
2 parents 9b972c0 + 1e6f014 commit 0ca1c04
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 785 deletions.
701 changes: 0 additions & 701 deletions LucidaSans-Typewriter83

This file was deleted.

6 changes: 3 additions & 3 deletions bootasm.S
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
start:
cli # BIOS enabled interrupts; disable

# Set up the important data segment registers (DS, ES, SS).
xorw %ax,%ax # Segment number zero
# Zero data segment registers DS, ES, and SS.
xorw %ax,%ax # Set %ax to zero
movw %ax,%ds # -> Data Segment
movw %ax,%es # -> Extra Segment
movw %ax,%ss # -> Stack Segment
Expand All @@ -37,7 +37,7 @@ seta20.2:
outb %al,$0x60

# Switch from real to protected mode. Use a bootstrap GDT that makes
# virtual addresses map dierctly to physical addresses so that the
# virtual addresses map directly to physical addresses so that the
# effective memory map doesn't change during the transition.
lgdt gdtdesc
movl %cr0, %eax
Expand Down
3 changes: 1 addition & 2 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ printint(int xx, int base, int sign)
void
cprintf(char *fmt, ...)
{
int i, c, state, locking;
int i, c, locking;
uint *argp;
char *s;

Expand All @@ -65,7 +65,6 @@ cprintf(char *fmt, ...)
panic("null fmt");

argp = (uint*)(void*)(&fmt + 1);
state = 0;
for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
if(c != '%'){
consputc(c);
Expand Down
7 changes: 3 additions & 4 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ extern uchar ioapicid;
void ioapicinit(void);

// kalloc.c
char* enter_alloc(void);
char* kalloc(void);
void kfree(char*);
void kinit(void);
uint detect_memory(void);
void kinit1(void*, void*);
void kinit2(void*, void*);

// kbd.c
void kbdintr(void);
Expand Down Expand Up @@ -165,7 +164,7 @@ void uartputc(int);
void seginit(void);
void kvmalloc(void);
void vmenable(void);
pde_t* setupkvm(char* (*alloc)());
pde_t* setupkvm();
char* uva2ka(pde_t*, char*);
int allocuvm(pde_t*, uint, uint);
int deallocuvm(pde_t*, uint, uint);
Expand Down
2 changes: 1 addition & 1 deletion entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ multiboot_header:
.globl _start
_start = V2P_WO(entry)

# Entering xv6 on boot processor. Machine is mostly set up.
# Entering xv6 on boot processor, with paging off.
.globl entry
entry:
# Turn on page size extension for 4Mbyte pages
Expand Down
55 changes: 31 additions & 24 deletions kalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,45 @@
#include "mmu.h"
#include "spinlock.h"

void freerange(void *vstart, void *vend);
extern char end[]; // first address after kernel loaded from ELF file

struct run {
struct run *next;
};

struct {
struct spinlock lock;
int use_lock;
struct run *freelist;
} kmem;

extern char end[]; // first address after kernel loaded from ELF file
static char *newend;

// A simple page allocator to get off the ground during entry
char *
enter_alloc(void)
// Initialization happens in two phases.
// 1. main() calls kinit1() while still using entrypgdir to place just
// the pages mapped by entrypgdir on free list.
// 2. main() calls kinit2() with the rest of the physical pages
// after installing a full page table that maps them on all cores.
void
kinit1(void *vstart, void *vend)
{
if (newend == 0)
newend = end;
initlock(&kmem.lock, "kmem");
kmem.use_lock = 0;
freerange(vstart, vend);
}

if ((uint) newend >= KERNBASE + 0x400000)
panic("only first 4Mbyte are mapped during entry");
void *p = (void*)PGROUNDUP((uint)newend);
memset(p, 0, PGSIZE);
newend = newend + PGSIZE;
return p;
void
kinit2(void *vstart, void *vend)
{
freerange(vstart, vend);
kmem.use_lock = 1;
}

// Initialize free list of physical pages.
void
kinit(void)
freerange(void *vstart, void *vend)
{
char *p;

initlock(&kmem.lock, "kmem");
p = (char*)PGROUNDUP((uint)newend);
for(; p + PGSIZE <= (char*)p2v(PHYSTOP); p += PGSIZE)
p = (char*)PGROUNDUP((uint)vstart);
for(; p + PGSIZE <= (char*)vend; p += PGSIZE)
kfree(p);
}

Expand All @@ -64,11 +67,13 @@ kfree(char *v)
// Fill with junk to catch dangling refs.
memset(v, 1, PGSIZE);

acquire(&kmem.lock);
if(kmem.use_lock)
acquire(&kmem.lock);
r = (struct run*)v;
r->next = kmem.freelist;
kmem.freelist = r;
release(&kmem.lock);
if(kmem.use_lock)
release(&kmem.lock);
}

// Allocate one 4096-byte page of physical memory.
Expand All @@ -79,11 +84,13 @@ kalloc(void)
{
struct run *r;

acquire(&kmem.lock);
if(kmem.use_lock)
acquire(&kmem.lock);
r = kmem.freelist;
if(r)
kmem.freelist = r->next;
release(&kmem.lock);
if(kmem.use_lock)
release(&kmem.lock);
return (char*)r;
}

19 changes: 8 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
static void startothers(void);
static void mpmain(void) __attribute__((noreturn));
extern pde_t *kpgdir;
extern char end[]; // first address after kernel loaded from ELF file

// Bootstrap processor starts running C code here.
// Allocate a real stack and switch to it, first
// doing some setup required for memory allocator to work.
int
main(void)
{
kinit1(end, P2V(4*1024*1024)); // phys page allocator
kvmalloc(); // kernel page table
mpinit(); // collect info about this machine
lapicinit(mpbcpu());
Expand All @@ -33,9 +35,9 @@ main(void)
ideinit(); // disk
if(!ismp)
timerinit(); // uniprocessor timer
startothers(); // start other processors (must come before kinit)
kinit(); // initialize memory allocator
userinit(); // first user process (must come after kinit)
startothers(); // start other processors
kinit2(P2V(4*1024*1024), P2V(PHYSTOP)); // must come after startothers()
userinit(); // first user process
// Finish setting up this processor in mpmain.
mpmain();
}
Expand Down Expand Up @@ -84,12 +86,7 @@ startothers(void)
// Tell entryother.S what stack to use, where to enter, and what
// pgdir to use. We cannot use kpgdir yet, because the AP processor
// is running in low memory, so we use entrypgdir for the APs too.
// kalloc can return addresses above 4Mbyte (the machine may have
// much more physical memory than 4Mbyte), which aren't mapped by
// entrypgdir, so we must allocate a stack using enter_alloc();
// this introduces the constraint that xv6 cannot use kalloc until
// after these last enter_alloc invocations.
stack = enter_alloc();
stack = kalloc();
*(void**)(code-4) = stack + KSTACKSIZE;
*(void**)(code-8) = mpenter;
*(int**)(code-12) = (void *) v2p(entrypgdir);
Expand All @@ -109,9 +106,9 @@ startothers(void)
__attribute__((__aligned__(PGSIZE)))
pde_t entrypgdir[NPDENTRIES] = {
// Map VA's [0, 4MB) to PA's [0, 4MB)
[0] = (0) + PTE_P + PTE_W + PTE_PS,
[0] = (0) | PTE_P | PTE_W | PTE_PS,
// Map VA's [KERNBASE, KERNBASE+4MB) to PA's [0, 4MB)
[KERNBASE>>PDXSHIFT] = (0) + PTE_P + PTE_W + PTE_PS,
[KERNBASE>>PDXSHIFT] = (0) | PTE_P | PTE_W | PTE_PS,
};

//PAGEBREAK!
Expand Down
8 changes: 4 additions & 4 deletions memlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#ifndef __ASSEMBLER__

static inline uint v2p(void *a) { return (uint) a - KERNBASE; }
static inline void *p2v(uint a) { return (void *) a + KERNBASE; }
static inline uint v2p(void *a) { return ((uint) (a)) - KERNBASE; }
static inline void *p2v(uint a) { return (void *) ((a) + KERNBASE); }

#endif

#define V2P(a) ((uint) a - KERNBASE)
#define P2V(a) ((void *) a + KERNBASE)
#define V2P(a) (((uint) (a)) - KERNBASE)
#define P2V(a) (((void *) (a)) + KERNBASE)

#define V2P_WO(x) ((x) - KERNBASE) // same as V2P, but without casts
#define P2V_WO(x) ((x) + KERNBASE) // same as V2P, but without casts
12 changes: 9 additions & 3 deletions runoff
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,17 @@ awk '
grep Pages: all.ps

# if we have the nice font, use it
nicefont=../LucidaSans-Typewriter83
if [ -f $nicefont ]
nicefont=LucidaSans-Typewriter83
if [ ! -f ../$nicefont ]
then
if git cat-file blob font:$nicefont > ../$nicefont~; then
mv ../$nicefont~ ../$nicefont
fi
fi
if [ -f ../$nicefont ]
then
echo nicefont
(sed 1q all.ps; cat $nicefont; sed '1d; s/Courier/LucidaSans-Typewriter83/' all.ps) >allf.ps
(sed 1q all.ps; cat ../$nicefont; sed "1d; s/Courier/$nicefont/" all.ps) >allf.ps
else
echo ugly font!
cp all.ps allf.ps
Expand Down
Loading

0 comments on commit 0ca1c04

Please sign in to comment.