From 7b814133e42568b2eca3362731cc0968f6e034b0 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:13:20 -0400 Subject: [PATCH 01/15] Acknowledge patches --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 286d336..c46ec2a 100644 --- a/README +++ b/README @@ -20,6 +20,9 @@ The following people made contributions: Cliff Frey (MP) Xiao Yu (MP) +In addition, we are grateful for the patches submitted by Greg Price, +Yandong Mao, and Hitoshi Mitake. + The code in the files that constitute xv6 is Copyright 2006-2007 Frans Kaashoek, Robert Morris, and Russ Cox. From 04be8fb232ef0f1f52444b0e513a9a256c5a031f Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:18:44 -0400 Subject: [PATCH 02/15] Rebalance TOC --- runoff.list | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runoff.list b/runoff.list index 3258398..01147ea 100644 --- a/runoff.list +++ b/runoff.list @@ -23,7 +23,6 @@ proc.c swtch.S kalloc.c vm.c - # system calls traps.h vectors.pl @@ -46,8 +45,6 @@ file.c sysfile.c exec.c - - # pipes pipe.c @@ -73,3 +70,5 @@ init.c sh.c + + From 7472b2b451f100162fa4542f5bfe260385f861ad Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:26:08 -0400 Subject: [PATCH 03/15] Fix too-long lines --- proc.c | 3 ++- trap.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/proc.c b/proc.c index 5ac2780..0dc77b8 100644 --- a/proc.c +++ b/proc.c @@ -120,7 +120,8 @@ userinit(void) panic("userinit: out of memory?"); if (!allocuvm(p->pgdir, 0x0, (int)_binary_initcode_size)) panic("userinit: out of memory?"); - inituvm(p->pgdir, 0x0, _binary_initcode_start, (int)_binary_initcode_size); + inituvm(p->pgdir, 0x0, _binary_initcode_start, + (int)_binary_initcode_size); p->sz = PGROUNDUP((int)_binary_initcode_size); memset(p->tf, 0, sizeof(*p->tf)); p->tf->cs = (SEG_UCODE << 3) | DPL_USER; diff --git a/trap.c b/trap.c index daee22f..ae26739 100644 --- a/trap.c +++ b/trap.c @@ -83,7 +83,8 @@ trap(struct trapframe *tf) panic("trap"); } // In user space, assume process misbehaved. - cprintf("pid %d %s: trap %d err %d on cpu %d eip 0x%x addr 0x%x--kill proc\n", + cprintf("pid %d %s: trap %d err %d on cpu %d " + "eip 0x%x addr 0x%x--kill proc\n", proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip, rcr2()); proc->killed = 1; From 37ee75f42e9d35a96b84fe0c95479178cd41efac Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:42:05 -0400 Subject: [PATCH 04/15] Rearrange for better page breaking --- x86.h | 85 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/x86.h b/x86.h index b9fa8b8..71427b3 100644 --- a/x86.h +++ b/x86.h @@ -90,25 +90,36 @@ readeflags(void) return eflags; } -static inline uint -xchg(volatile uint *addr, uint newval) -{ - uint result; - - // The + in "+m" denotes a read-modify-write operand. - asm volatile("lock; xchgl %0, %1" : - "+m" (*addr), "=a" (result) : - "1" (newval) : - "cc"); - return result; -} - static inline void loadgs(ushort v) { asm volatile("movw %0, %%gs" : : "r" (v)); } +static inline void lebp(uint val) +{ + asm volatile("movl %0,%%ebp" : : "r" (val)); +} + +static inline uint rebp(void) +{ + uint val; + asm volatile("movl %%ebp,%0" : "=r" (val)); + return val; +} + +static inline void lesp(uint val) +{ + asm volatile("movl %0,%%esp" : : "r" (val)); +} + +static inline uint resp(void) +{ + uint val; + asm volatile("movl %%esp,%0" : "=r" (val)); + return val; +} + static inline void cli(void) { @@ -121,6 +132,25 @@ sti(void) asm volatile("sti"); } +static inline void nop_pause(void) +{ + asm volatile("pause" : :); +} + +//PAGEBREAK! +static inline uint +xchg(volatile uint *addr, uint newval) +{ + uint result; + + // The + in "+m" denotes a read-modify-write operand. + asm volatile("lock; xchgl %0, %1" : + "+m" (*addr), "=a" (result) : + "1" (newval) : + "cc"); + return result; +} + static inline void lcr0(uint val) { asm volatile("movl %0,%%cr0" : : "r" (val)); @@ -152,35 +182,6 @@ static inline uint rcr3(void) return val; } -static inline void lebp(uint val) -{ - asm volatile("movl %0,%%ebp" : : "r" (val)); -} - -static inline uint rebp(void) -{ - uint val; - asm volatile("movl %%ebp,%0" : "=r" (val)); - return val; -} - -static inline void lesp(uint val) -{ - asm volatile("movl %0,%%esp" : : "r" (val)); -} - -static inline uint resp(void) -{ - uint val; - asm volatile("movl %%esp,%0" : "=r" (val)); - return val; -} - -static inline void nop_pause(void) -{ - asm volatile("pause" : :); -} - //PAGEBREAK: 36 // Layout of the trap frame built on the stack by the // hardware and by trapasm.S, and passed to trap(). From 92639b6ba95d1d960a9e808c7163f6d171b2e4a3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:43:41 -0400 Subject: [PATCH 05/15] Follow xv6 code style. Also fixes indexing for these functions --- x86.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/x86.h b/x86.h index 71427b3..1f903b2 100644 --- a/x86.h +++ b/x86.h @@ -132,7 +132,8 @@ sti(void) asm volatile("sti"); } -static inline void nop_pause(void) +static inline void +nop_pause(void) { asm volatile("pause" : :); } @@ -151,31 +152,36 @@ xchg(volatile uint *addr, uint newval) return result; } -static inline void lcr0(uint val) +static inline void +lcr0(uint val) { asm volatile("movl %0,%%cr0" : : "r" (val)); } -static inline uint rcr0(void) +static inline uint +rcr0(void) { uint val; asm volatile("movl %%cr0,%0" : "=r" (val)); return val; } -static inline uint rcr2(void) +static inline uint +rcr2(void) { uint val; asm volatile("movl %%cr2,%0" : "=r" (val)); return val; } -static inline void lcr3(uint val) +static inline void +lcr3(uint val) { asm volatile("movl %0,%%cr3" : : "r" (val)); } -static inline uint rcr3(void) +static inline uint +rcr3(void) { uint val; asm volatile("movl %%cr3,%0" : "=r" (val)); From b5592b4d2f0ea5f536b206979f829038c55d7ade Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:47:50 -0400 Subject: [PATCH 06/15] Start PDE defs on new page --- mmu.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mmu.h b/mmu.h index db40f25..0975efd 100644 --- a/mmu.h +++ b/mmu.h @@ -62,8 +62,6 @@ struct segdesc { #define STA_R 0x2 // Readable (executable segments) #define STA_A 0x1 // Accessed -// - // System segment type bits #define STS_T16A 0x1 // Available 16-bit TSS #define STS_LDT 0x2 // Local Descriptor Table @@ -78,7 +76,7 @@ struct segdesc { #define STS_IG32 0xE // 32-bit Interrupt Gate #define STS_TG32 0xF // 32-bit Trap Gate - +//PAGEBREAK! // A linear address 'la' has a three-part structure as follows: // // +--------10------+-------10-------+---------12----------+ From 7914ab721436d3c21623010dfab2dc326bf49279 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 16:54:50 -0400 Subject: [PATCH 07/15] Page breaking of mmu.h --- mmu.h | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/mmu.h b/mmu.h index 0975efd..475eae8 100644 --- a/mmu.h +++ b/mmu.h @@ -24,6 +24,20 @@ #define FL_VIP 0x00100000 // Virtual Interrupt Pending #define FL_ID 0x00200000 // ID flag +// Control Register flags +#define CR0_PE 0x00000001 // Protection Enable +#define CR0_MP 0x00000002 // Monitor coProcessor +#define CR0_EM 0x00000004 // Emulation +#define CR0_TS 0x00000008 // Task Switched +#define CR0_ET 0x00000010 // Extension Type +#define CR0_NE 0x00000020 // Numeric Errror +#define CR0_WP 0x00010000 // Write Protect +#define CR0_AM 0x00040000 // Alignment Mask +#define CR0_NW 0x20000000 // Not Writethrough +#define CR0_CD 0x40000000 // Cache Disable +#define CR0_PG 0x80000000 // Paging + +//PAGEBREAK! // Segment Descriptor struct segdesc { uint lim_15_0 : 16; // Low bits of segment limit @@ -46,7 +60,6 @@ struct segdesc { { ((lim) >> 12) & 0xffff, (uint)(base) & 0xffff, \ ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \ (uint)(lim) >> 28, 0, 0, 1, 1, (uint)(base) >> 24 } - #define SEG16(type, base, lim, dpl) (struct segdesc) \ { (lim) & 0xffff, (uint)(base) & 0xffff, \ ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \ @@ -76,7 +89,6 @@ struct segdesc { #define STS_IG32 0xE // 32-bit Interrupt Gate #define STS_TG32 0xF // 32-bit Trap Gate -//PAGEBREAK! // A linear address 'la' has a three-part structure as follows: // // +--------10------+-------10-------+---------12----------+ @@ -128,21 +140,6 @@ struct segdesc { typedef uint pte_t; -// Control Register flags -#define CR0_PE 0x00000001 // Protection Enable -#define CR0_MP 0x00000002 // Monitor coProcessor -#define CR0_EM 0x00000004 // Emulation -#define CR0_TS 0x00000008 // Task Switched -#define CR0_ET 0x00000010 // Extension Type -#define CR0_NE 0x00000020 // Numeric Errror -#define CR0_WP 0x00010000 // Write Protect -#define CR0_AM 0x00040000 // Alignment Mask -#define CR0_NW 0x20000000 // Not Writethrough -#define CR0_CD 0x40000000 // Cache Disable -#define CR0_PG 0x80000000 // Paging - - -// PAGEBREAK: 40 // Task state segment format struct taskstate { uint link; // Old ts selector From 29c054df817d55ae6e0fc3bd4c9e2343a2b4ca75 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:07:54 -0400 Subject: [PATCH 08/15] We don't use lesp/lebp and using them at all from C would be fraught with peril. Keep resp/rebp, but fix their code style. --- x86.h | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/x86.h b/x86.h index 1f903b2..33e240d 100644 --- a/x86.h +++ b/x86.h @@ -96,24 +96,16 @@ loadgs(ushort v) asm volatile("movw %0, %%gs" : : "r" (v)); } -static inline void lebp(uint val) -{ - asm volatile("movl %0,%%ebp" : : "r" (val)); -} - -static inline uint rebp(void) +static inline uint +rebp(void) { uint val; asm volatile("movl %%ebp,%0" : "=r" (val)); return val; } -static inline void lesp(uint val) -{ - asm volatile("movl %0,%%esp" : : "r" (val)); -} - -static inline uint resp(void) +static inline uint +resp(void) { uint val; asm volatile("movl %%esp,%0" : "=r" (val)); @@ -132,13 +124,6 @@ sti(void) asm volatile("sti"); } -static inline void -nop_pause(void) -{ - asm volatile("pause" : :); -} - -//PAGEBREAK! static inline uint xchg(volatile uint *addr, uint newval) { @@ -152,6 +137,13 @@ xchg(volatile uint *addr, uint newval) return result; } +static inline void +nop_pause(void) +{ + asm volatile("pause" : :); +} + +//PAGEBREAK! static inline void lcr0(uint val) { From 51e2a7b324020a90bf963d514a0959d930120d71 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:30:31 -0400 Subject: [PATCH 09/15] print depends on runoff.spec --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8f820e1..37924e2 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,7 @@ clean: # make a printout FILES = $(shell grep -v '^\#' runoff.list) -PRINT = runoff.list $(FILES) +PRINT = runoff.list runoff.spec $(FILES) xv6.pdf: $(PRINT) ./runoff From c7ceb71d5757db21a2228ec33bde2f4da1677094 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:33:04 -0400 Subject: [PATCH 10/15] Sheet 1 is a right page now because of the (much) longer cross-ref --- runoff | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runoff b/runoff index 21ee8ed..0e0e49e 100755 --- a/runoff +++ b/runoff @@ -89,16 +89,17 @@ perl -e ' print STDERR "Have no toc for $file\n"; next; } - # this assumes that sheet 1 of code is a left page - # double-check the PDF + # this assumes that sheet 1 of code is a right page + # double-check the PDF. swap the two regexps below + # otherwise. if(!$leftwarn++) { - print STDERR "assuming that sheet 1 is a left page. double-check!\n"; + print STDERR "assuming that sheet 1 is a right page. double-check!\n"; } - if($what eq "left" && !($toc{$file} =~ /^\d[13579]0/)){ + if($what eq "left" && !($toc{$file} =~ /^\d[02468]0/)){ print STDERR "$file does not start on a fresh left page [$toc{$file}]\n"; } # why does this not work if I inline $x in the if? - $x = ($toc{$file} =~ /^\d[02468]0/); + $x = ($toc{$file} =~ /^\d[13579]0/); if($what eq "right" && !$x){ print STDERR "$file does not start on a fresh right page [$toc{$file}] [$x]\n"; } From 6a6bf37c3c3dcab6f464d031bf94c56a770b6df6 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:35:17 -0400 Subject: [PATCH 11/15] Swap bootmain.c and bootother.S. This puts the whole boot process on one spread, though it separates the two asm files. --- runoff.list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runoff.list b/runoff.list index 01147ea..025bbe2 100644 --- a/runoff.list +++ b/runoff.list @@ -9,8 +9,8 @@ elf.h # startup bootasm.S -bootother.S bootmain.c +bootother.S main.c # locks From fd462b6a01735cc7a14b9cb11c99242c5ed03c03 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:40:21 -0400 Subject: [PATCH 12/15] Got the meat of spinlocks on one spread --- runoff.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/runoff.spec b/runoff.spec index e4cfd42..46dcc09 100644 --- a/runoff.spec +++ b/runoff.spec @@ -17,6 +17,7 @@ even: main.c # spinlock.h either # spinlock.c either +right: spinlock.c # mild preference even: proc.h # mild preference # goal is to have two action-packed 2-page spreads, From 13b3f4d2e32eee81ba039ad3c6a6c97bfc9d4638 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:46:30 -0400 Subject: [PATCH 13/15] Make it possible to express half-page preferences --- runoff | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/runoff b/runoff index 0e0e49e..14db252 100755 --- a/runoff +++ b/runoff @@ -82,9 +82,10 @@ perl -e ' next; } - if(/(left|right): (.*)/){ + if(/(left|right)(\+?): (.*)/){ $what = $1; - $file = $2; + $tens = ($2 eq "+" ? "5" : "0"); + $file = $3; if(!defined($toc{$file})){ print STDERR "Have no toc for $file\n"; next; @@ -95,11 +96,11 @@ perl -e ' if(!$leftwarn++) { print STDERR "assuming that sheet 1 is a right page. double-check!\n"; } - if($what eq "left" && !($toc{$file} =~ /^\d[02468]0/)){ + if($what eq "left" && !($toc{$file} =~ /^\d[02468]$tens/)){ print STDERR "$file does not start on a fresh left page [$toc{$file}]\n"; } # why does this not work if I inline $x in the if? - $x = ($toc{$file} =~ /^\d[13579]0/); + $x = ($toc{$file} =~ /^\d[13579]$tens/); if($what eq "right" && !$x){ print STDERR "$file does not start on a fresh right page [$toc{$file}] [$x]\n"; } From 87b2099ae44039b119267d41a710a56b4784dbe0 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:49:47 -0400 Subject: [PATCH 14/15] Our proc.c alignment is perfect. Since ksegment/usegment went away, we get a column back, so we get our two action-packed spreads. --- runoff.spec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runoff.spec b/runoff.spec index 46dcc09..e6f5a95 100644 --- a/runoff.spec +++ b/runoff.spec @@ -16,16 +16,15 @@ even: main.c # odd: init.c # spinlock.h either -# spinlock.c either right: spinlock.c # mild preference even: proc.h # mild preference # goal is to have two action-packed 2-page spreads, # one with -# ksegment usegment allocproc userinit growproc fork +# allocproc userinit growproc fork # and another with # scheduler sched yield forkret sleep wakeup1 wakeup -right: proc.c # VERY important +right+: proc.c # VERY important # setjmp.S either # vm.c either From 5048762c7e27789a014cc1e74e1002e749c924ce Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:52:03 -0400 Subject: [PATCH 15/15] Page break kalloc.c --- kalloc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kalloc.c b/kalloc.c index 8c9ff93..7653242 100644 --- a/kalloc.c +++ b/kalloc.c @@ -30,6 +30,7 @@ kinit(void) kfree(p1); } +//PAGEBREAK: 21 // Free the page of physical memory pointed at by v, // which normally should have been returned by a // call to kalloc(). (The exception is when