Permalink
Browse files

shuffle and tweak for formatting.

pdf has very good page breaks now.
would be a good copy for fall 2009.
  • Loading branch information...
rsc committed Aug 8, 2009
1 parent b3bebfc commit 0aef8914959af9e472852611eb6352c211093d35
Showing with 338 additions and 319 deletions.
  1. +1 −0 Makefile
  2. +7 −7 bootother.S
  3. +113 −116 console.c
  4. +1 −0 defs.h
  5. +0 −8 dev.h
  6. +0 −18 elf.h
  7. +4 −2 exec.c
  8. +1 −1 file.c
  9. +32 −0 file.h
  10. +1 −2 fs.c
  11. +0 −18 fsvar.h
  12. +29 −0 picirq.c
  13. +2 −1 pipe.c
  14. +104 −102 proc.c
  15. +25 −1 runoff
  16. +1 −3 runoff.list
  17. +13 −5 runoff.spec
  18. +0 −1 sysfile.c
  19. +0 −33 timer.c
  20. +1 −0 trap.c
  21. +2 −1 uart.c
  22. +1 −0 x86.h
  23. BIN xv6.pdf
  24. BIN xv6.ps
View
@@ -128,6 +128,7 @@ PRINT = runoff.list $(FILES)
xv6.pdf: $(PRINT)
./runoff
+ ls -l xv6.pdf
print: xv6.pdf
View
@@ -38,7 +38,7 @@ start:
//PAGEBREAK!
# Switch from real to protected mode, using a bootstrap GDT
# and segment translation that makes virtual addresses
- # identical to their physical addresses, so that the
+ # identical to physical addresses, so that the
# effective memory map does not change during the switch.
lgdt gdtdesc
movl %cr0, %eax
@@ -47,10 +47,10 @@ start:
# Jump to next instruction, but in 32-bit code segment.
# Switches processor into 32-bit mode.
- ljmp $(SEG_KCODE<<3), $protcseg
+ ljmp $(SEG_KCODE<<3), $start32
- .code32 # Assemble for 32-bit mode
-protcseg:
+.code32 # Assemble for 32-bit mode
+start32:
# Set up the protected-mode data segment registers
movw $(SEG_KDATA<<3), %ax # Our data segment selector
movw %ax, %ds # -> DS: Data Segment
@@ -60,11 +60,11 @@ protcseg:
movw %ax, %fs # -> FS
movw %ax, %gs # -> GS
+ # Set up the stack pointer and call into C.
movl start-4, %esp
- movl start-8, %eax
- call *%eax
+ call *(start-8)
- # If bootmain returns (it shouldn't), trigger a Bochs
+ # If the call returns (it shouldn't), trigger a Bochs
# breakpoint if running under Bochs, then loop.
movw $0x8a00, %ax # 0x8a00 -> port 0x8a00
movw %ax, %dx
View
229 console.c
@@ -7,69 +7,22 @@
#include "param.h"
#include "traps.h"
#include "spinlock.h"
-#include "dev.h"
+#include "fs.h"
+#include "file.h"
#include "mmu.h"
#include "proc.h"
#include "x86.h"
-#define CRTPORT 0x3d4
-#define BACKSPACE 0x100
+static void consputc(int);
-static ushort *crt = (ushort*)0xb8000; // CGA memory
+static int panicked = 0;
static struct {
struct spinlock lock;
int locking;
} cons;
-static int panicked = 0;
-
static void
-cgaputc(int c)
-{
- int pos;
-
- // Cursor position: col + 80*row.
- outb(CRTPORT, 14);
- pos = inb(CRTPORT+1) << 8;
- outb(CRTPORT, 15);
- pos |= inb(CRTPORT+1);
-
- if(c == '\n')
- pos += 80 - pos%80;
- else if(c == BACKSPACE){
- if(pos > 0)
- crt[--pos] = ' ' | 0x0700;
- } else
- crt[pos++] = (c&0xff) | 0x0700; // black on white
-
- if((pos/80) >= 24){ // Scroll up.
- memmove(crt, crt+80, sizeof(crt[0])*23*80);
- pos -= 80;
- memset(crt+pos, 0, sizeof(crt[0])*(24*80 - pos));
- }
-
- outb(CRTPORT, 14);
- outb(CRTPORT+1, pos>>8);
- outb(CRTPORT, 15);
- outb(CRTPORT+1, pos);
- crt[pos] = ' ' | 0x0700;
-}
-
-void
-consputc(int c)
-{
- if(panicked){
- cli();
- for(;;)
- ;
- }
-
- uartputc(c);
- cgaputc(c);
-}
-
-void
printint(int xx, int base, int sgn)
{
static char digits[] = "0123456789abcdef";
@@ -79,10 +32,9 @@ printint(int xx, int base, int sgn)
if(sgn && xx < 0){
neg = 1;
- x = 0 - xx;
- } else {
+ x = -xx;
+ } else
x = xx;
- }
do{
buf[i++] = digits[x % base];
@@ -94,6 +46,7 @@ printint(int xx, int base, int sgn)
consputc(buf[i]);
}
+//PAGEBREAK: 50
// Print to the console. only understands %d, %x, %p, %s.
void
cprintf(char *fmt, ...)
@@ -108,42 +61,35 @@ cprintf(char *fmt, ...)
argp = (uint*)(void*)&fmt + 1;
state = 0;
- for(i = 0; fmt[i]; i++){
- c = fmt[i] & 0xff;
- switch(state){
- case 0:
- if(c == '%')
- state = '%';
- else
- consputc(c);
+ for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
+ if(c != '%'){
+ consputc(c);
+ continue;
+ }
+ c = fmt[++i] & 0xff;
+ if(c == 0)
+ break;
+ switch(c){
+ case 'd':
+ printint(*argp++, 10, 1);
+ break;
+ case 'x':
+ case 'p':
+ printint(*argp++, 16, 0);
+ break;
+ case 's':
+ if((s = (char*)*argp++) == 0)
+ s = "(null)";
+ for(; *s; s++)
+ consputc(*s);
break;
-
case '%':
- switch(c){
- case 'd':
- printint(*argp++, 10, 1);
- break;
- case 'x':
- case 'p':
- printint(*argp++, 16, 0);
- break;
- case 's':
- s = (char*)*argp++;
- if(s == 0)
- s = "(null)";
- for(; *s; s++)
- consputc(*s);
- break;
- case '%':
- consputc('%');
- break;
- default:
- // Print unknown % sequence to draw attention.
- consputc('%');
- consputc(c);
- break;
- }
- state = 0;
+ consputc('%');
+ break;
+ default:
+ // Print unknown % sequence to draw attention.
+ consputc('%');
+ consputc(c);
break;
}
}
@@ -152,21 +98,76 @@ cprintf(char *fmt, ...)
release(&cons.lock);
}
-int
-consolewrite(struct inode *ip, char *buf, int n)
+void
+panic(char *s)
{
int i;
+ uint pcs[10];
+
+ cli();
+ cons.locking = 0;
+ cprintf("cpu%d: panic: ", cpu());
+ cprintf(s);
+ cprintf("\n");
+ getcallerpcs(&s, pcs);
+ for(i=0; i<10; i++)
+ cprintf(" %p", pcs[i]);
+ panicked = 1; // freeze other CPU
+ for(;;)
+ ;
+}
- iunlock(ip);
- acquire(&cons.lock);
- for(i = 0; i < n; i++)
- consputc(buf[i] & 0xff);
- release(&cons.lock);
- ilock(ip);
+//PAGEBREAK: 50
+#define BACKSPACE 0x100
+#define CRTPORT 0x3d4
+static ushort *crt = (ushort*)0xb8000; // CGA memory
- return n;
+static void
+cgaputc(int c)
+{
+ int pos;
+
+ // Cursor position: col + 80*row.
+ outb(CRTPORT, 14);
+ pos = inb(CRTPORT+1) << 8;
+ outb(CRTPORT, 15);
+ pos |= inb(CRTPORT+1);
+
+ if(c == '\n')
+ pos += 80 - pos%80;
+ else if(c == BACKSPACE){
+ if(pos > 0)
+ crt[--pos] = ' ' | 0x0700;
+ } else
+ crt[pos++] = (c&0xff) | 0x0700; // black on white
+
+ if((pos/80) >= 24){ // Scroll up.
+ memmove(crt, crt+80, sizeof(crt[0])*23*80);
+ pos -= 80;
+ memset(crt+pos, 0, sizeof(crt[0])*(24*80 - pos));
+ }
+
+ outb(CRTPORT, 14);
+ outb(CRTPORT+1, pos>>8);
+ outb(CRTPORT, 15);
+ outb(CRTPORT+1, pos);
+ crt[pos] = ' ' | 0x0700;
+}
+
+void
+consputc(int c)
+{
+ if(panicked){
+ cli();
+ for(;;)
+ ;
+ }
+
+ uartputc(c);
+ cgaputc(c);
}
+//PAGEBREAK: 50
#define INPUT_BUF 128
struct {
struct spinlock lock;
@@ -255,6 +256,21 @@ consoleread(struct inode *ip, char *dst, int n)
return target - n;
}
+int
+consolewrite(struct inode *ip, char *buf, int n)
+{
+ int i;
+
+ iunlock(ip);
+ acquire(&cons.lock);
+ for(i = 0; i < n; i++)
+ consputc(buf[i] & 0xff);
+ release(&cons.lock);
+ ilock(ip);
+
+ return n;
+}
+
void
consoleinit(void)
{
@@ -269,22 +285,3 @@ consoleinit(void)
ioapicenable(IRQ_KBD, 0);
}
-void
-panic(char *s)
-{
- int i;
- uint pcs[10];
-
- cli();
- cons.locking = 0;
- cprintf("cpu%d: panic: ", cpu());
- cprintf(s);
- cprintf("\n");
- getcallerpcs(&s, pcs);
- for(i=0; i<10; i++)
- cprintf(" %p", pcs[i]);
- panicked = 1; // freeze other CPU
- for(;;)
- ;
-}
-
View
1 defs.h
@@ -91,6 +91,7 @@ void pipeclose(struct pipe*, int);
int piperead(struct pipe*, char*, int);
int pipewrite(struct pipe*, char*, int);
+//PAGEBREAK: 16
// proc.c
struct proc* copyproc(struct proc*);
void exit(void);
View
8 dev.h
@@ -1,8 +0,0 @@
-struct devsw {
- int (*read)(struct inode*, char*, int);
- int (*write)(struct inode*, char*, int);
-};
-
-extern struct devsw devsw[];
-
-#define CONSOLE 1
View
18 elf.h
@@ -40,21 +40,3 @@ struct proghdr {
#define ELF_PROG_FLAG_EXEC 1
#define ELF_PROG_FLAG_WRITE 2
#define ELF_PROG_FLAG_READ 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// Blank page.
Oops, something went wrong.

0 comments on commit 0aef891

Please sign in to comment.