Skip to content

Commit

Permalink
no /* */ comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Sep 6, 2006
1 parent 9e9bcaf commit f552738
Show file tree
Hide file tree
Showing 22 changed files with 350 additions and 374 deletions.
57 changes: 27 additions & 30 deletions bootmain.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
#include "types.h"
#include "elf.h"
#include "x86.h"

/**********************************************************************
* This a dirt simple boot loader, whose sole job is to boot
* an elf kernel image from the first IDE hard disk.
*
* DISK LAYOUT
* * This program(boot.S and main.c) is the bootloader. It should
* be stored in the first sector of the disk.
*
* * The 2nd sector onward holds the kernel image.
*
* * The kernel image must be in ELF format.
*
* BOOT UP STEPS
* * when the CPU boots it loads the BIOS into memory and executes it
*
* * the BIOS intializes devices, sets of the interrupt routines, and
* reads the first sector of the boot device(e.g., hard-drive)
* into memory and jumps to it.
*
* * Assuming this boot loader is stored in the first sector of the
* hard-drive, this code takes over...
*
* * control starts in bootloader.S -- which sets up protected mode,
* and a stack so C code then run, then calls cmain()
*
* * cmain() in this file takes over, reads in the kernel and jumps to it.
**********************************************************************/
// This a dirt simple boot loader, whose sole job is to boot
// an elf kernel image from the first IDE hard disk.
//
// DISK LAYOUT
// * This program(boot.S and main.c) is the bootloader. It should
// be stored in the first sector of the disk.
//
// * The 2nd sector onward holds the kernel image.
//
// * The kernel image must be in ELF format.
//
// BOOT UP STEPS
// * when the CPU boots it loads the BIOS into memory and executes it
//
// * the BIOS intializes devices, sets of the interrupt routines, and
// reads the first sector of the boot device(e.g., hard-drive)
// into memory and jumps to it.
//
// * Assuming this boot loader is stored in the first sector of the
// hard-drive, this code takes over...
//
// * control starts in bootloader.S -- which sets up protected mode,
// and a stack so C code then run, then calls cmain()
//
// * cmain() in this file takes over, reads in the kernel and jumps to it.

#define SECTSIZE 512
#define ELFHDR ((struct elfhdr*) 0x10000) // scratch space
Expand Down Expand Up @@ -62,7 +59,7 @@ cmain(void)
outw(0x8A00, 0x8A00);
outw(0x8A00, 0x8E00);
while(1)
/* do nothing */;
;
}

// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
Expand Down Expand Up @@ -96,7 +93,7 @@ waitdisk(void)
{
// wait for disk reaady
while((inb(0x1F7) & 0xC0) != 0x40)
/* do nothing */;
;
}

void
Expand Down
71 changes: 42 additions & 29 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ struct spinlock console_lock;
int panicked = 0;
int use_console_lock = 0;

/*
* copy console output to parallel port, which you can tell
* .bochsrc to copy to the stdout:
* parport1: enabled=1, file="/dev/stdout"
*/
// Copy console output to parallel port, which you can tell
// .bochsrc to copy to the stdout:
// parport1: enabled=1, file="/dev/stdout"
static void
lpt_putc(int c)
{
Expand Down Expand Up @@ -97,9 +95,7 @@ printint(int xx, int base, int sgn)
cons_putc(buf[i]);
}

/*
* print to the console. only understands %d, %x, %p, %s.
*/
// Print to the console. only understands %d, %x, %p, %s.
void
cprintf(char *fmt, ...)
{
Expand Down Expand Up @@ -182,10 +178,10 @@ console_write(int minor, char *buf, int n)
}


/* This is i8042reg.h + kbdreg.h from NetBSD. */
#define KBSTATP 0x64 /* kbd controller status port(I) */
#define KBS_DIB 0x01 /* kbd data in buffer */
#define KBDATAP 0x60 /* kbd data port(I) */
// This is i8042reg.h + kbdreg.h from NetBSD.
#define KBSTATP 0x64 // kbd controller status port(I)
#define KBS_DIB 0x01 // kbd data in buffer
#define KBDATAP 0x60 // kbd data port(I)

#define NO 0

Expand Down Expand Up @@ -241,12 +237,18 @@ static uchar normalmap[256] =
NO, NO, NO, NO, NO, NO, NO, '7', // 0x40
'8', '9', '-', '4', '5', '6', '+', '1',
'2', '3', '0', '.', NO, NO, NO, NO, // 0x50
[0x97] KEY_HOME, [0x9C] '\n' /*KP_Enter*/,
[0xB5] '/' /*KP_Div*/, [0xC8] KEY_UP,
[0xC9] KEY_PGUP, [0xCB] KEY_LF,
[0xCD] KEY_RT, [0xCF] KEY_END,
[0xD0] KEY_DN, [0xD1] KEY_PGDN,
[0xD2] KEY_INS, [0xD3] KEY_DEL
[0x97] KEY_HOME,
[0x9C] '\n', // KP_Enter
[0xB5] '/', // KP_Div
[0xC8] KEY_UP,
[0xC9] KEY_PGUP,
[0xCB] KEY_LF,
[0xCD] KEY_RT,
[0xCF] KEY_END,
[0xD0] KEY_DN,
[0xD1] KEY_PGDN,
[0xD2] KEY_INS,
[0xD3] KEY_DEL
};

static uchar shiftmap[256] =
Expand All @@ -262,12 +264,18 @@ static uchar shiftmap[256] =
NO, NO, NO, NO, NO, NO, NO, '7', // 0x40
'8', '9', '-', '4', '5', '6', '+', '1',
'2', '3', '0', '.', NO, NO, NO, NO, // 0x50
[0x97] KEY_HOME, [0x9C] '\n' /*KP_Enter*/,
[0xB5] '/' /*KP_Div*/, [0xC8] KEY_UP,
[0xC9] KEY_PGUP, [0xCB] KEY_LF,
[0xCD] KEY_RT, [0xCF] KEY_END,
[0xD0] KEY_DN, [0xD1] KEY_PGDN,
[0xD2] KEY_INS, [0xD3] KEY_DEL
[0x97] KEY_HOME,
[0x9C] '\n', // KP_Enter
[0xB5] '/', // KP_Div
[0xC8] KEY_UP,
[0xC9] KEY_PGUP,
[0xCB] KEY_LF,
[0xCD] KEY_RT,
[0xCF] KEY_END,
[0xD0] KEY_DN,
[0xD1] KEY_PGDN,
[0xD2] KEY_INS,
[0xD3] KEY_DEL
};

#define C(x) (x - '@')
Expand All @@ -282,11 +290,16 @@ static uchar ctlmap[256] =
NO, NO, NO, C('\\'), C('Z'), C('X'), C('C'), C('V'),
C('B'), C('N'), C('M'), NO, NO, C('/'), NO, NO,
[0x97] KEY_HOME,
[0xB5] C('/'), [0xC8] KEY_UP,
[0xC9] KEY_PGUP, [0xCB] KEY_LF,
[0xCD] KEY_RT, [0xCF] KEY_END,
[0xD0] KEY_DN, [0xD1] KEY_PGDN,
[0xD2] KEY_INS, [0xD3] KEY_DEL
[0xB5] C('/'), // KP_Div
[0xC8] KEY_UP,
[0xC9] KEY_PGUP,
[0xCB] KEY_LF,
[0xCD] KEY_RT,
[0xCF] KEY_END,
[0xD0] KEY_DN,
[0xD1] KEY_PGDN,
[0xD2] KEY_INS,
[0xD3] KEY_DEL
};

static uchar *charcode[4] = {
Expand Down
2 changes: 1 addition & 1 deletion elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// format of an ELF executable file
//

#define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */
#define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian

struct elfhdr {
uint magic; // must equal ELF_MAGIC
Expand Down
17 changes: 8 additions & 9 deletions fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ fd_init(void)
initlock(&fd_table_lock, "fd_table");
}

/*
* allocate a file descriptor number for curproc.
*/
// Allocate a file descriptor number for curproc.
int
fd_ualloc(void)
{
Expand All @@ -36,9 +34,7 @@ fd_ualloc(void)
return -1;
}

/*
* allocate a file descriptor structure
*/
// Allocate a file descriptor structure
struct fd*
fd_alloc(void)
{
Expand All @@ -57,9 +53,8 @@ fd_alloc(void)
return 0;
}

/*
* addr is a kernel address, pointing into some process's p->mem.
*/
// Write to file descriptor;
// addr is a kernel address, pointing into some process's p->mem.
int
fd_write(struct fd *fd, char *addr, int n)
{
Expand All @@ -81,6 +76,7 @@ fd_write(struct fd *fd, char *addr, int n)
}
}

// Read from file descriptor.
int
fd_read(struct fd *fd, char *addr, int n)
{
Expand All @@ -101,6 +97,7 @@ fd_read(struct fd *fd, char *addr, int n)
}
}

// Close file descriptor.
void
fd_close(struct fd *fd)
{
Expand Down Expand Up @@ -128,6 +125,7 @@ fd_close(struct fd *fd)
}
}

// Get metadata about file descriptor.
int
fd_stat(struct fd *fd, struct stat *st)
{
Expand All @@ -140,6 +138,7 @@ fd_stat(struct fd *fd, struct stat *st)
return -1;
}

// Increment file descriptor reference count.
void
fd_incref(struct fd *fd)
{
Expand Down
14 changes: 6 additions & 8 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ iinit(void)
initlock(&inode_table_lock, "inode_table");
}

/*
* allocate a disk block
*/
// Allocate a disk block.
static uint
balloc(uint dev)
{
Expand Down Expand Up @@ -90,11 +88,11 @@ bfree(int dev, uint b)
brelse(bp);
}

/*
* fetch an inode, from the in-core table if it's already
* in use, otherwise read from the disk.
* returns an inode with busy set and incremented reference count.
*/
// Find the inode with number inum on device dev
// and return an in-memory copy. Loads the inode
// from disk into the in-core table if necessary.
// The returned inode has busy set and has its ref count incremented.
// Caller must iput the return value when done with it.
struct inode*
iget(uint dev, uint inum)
{
Expand Down
8 changes: 3 additions & 5 deletions ide.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*
* Simple PIO-based (non-DMA) IDE driver code.
*/
// Simple PIO-based (non-DMA) IDE driver code.

#include "types.h"
#include "param.h"
Expand Down Expand Up @@ -38,7 +36,7 @@ ide_wait_ready(int check_error)
int r;

while(((r = inb(0x1F7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
/* do nothing */;
;

if(check_error && (r & (IDE_DF|IDE_ERR)) != 0)
return -1;
Expand Down Expand Up @@ -75,7 +73,7 @@ ide_probe_disk1(void)

// check for Device 1 to be ready for a while
for(x = 0; x < 1000 && (r = inb(0x1F7)) == 0; x++)
/* do nothing */;
;

// switch back to Device 0
outb(0x1F6, 0xE0 | (0<<4));
Expand Down
2 changes: 1 addition & 1 deletion init.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "fs.h"
#include "fcntl.h"

/* The initial user-level program */
// init: The initial user-level program

char *sh_args[] = { "sh", 0 };

Expand Down
Loading

0 comments on commit f552738

Please sign in to comment.