Skip to content

Commit

Permalink
shuffle and tweak for formatting.
Browse files Browse the repository at this point in the history
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 0aef891
Show file tree
Hide file tree
Showing 24 changed files with 338 additions and 319 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ PRINT = runoff.list $(FILES)

xv6.pdf: $(PRINT)
./runoff
ls -l xv6.pdf

print: xv6.pdf

Expand Down
14 changes: 7 additions & 7 deletions bootother.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
229 changes: 113 additions & 116 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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];
Expand All @@ -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, ...)
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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(;;)
;
}

1 change: 1 addition & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions dev.h

This file was deleted.

18 changes: 0 additions & 18 deletions elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading

0 comments on commit 0aef891

Please sign in to comment.