提交 8b32de47 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Merge c++ stuff

...@@ -14,16 +14,19 @@ HW ?= qemu ...@@ -14,16 +14,19 @@ HW ?= qemu
O = o.$(HW) O = o.$(HW)
CC = $(TOOLPREFIX)gcc CC = $(TOOLPREFIX)gcc
CXX = $(TOOLPREFIX)g++
AS = $(TOOLPREFIX)gas AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld LD = $(TOOLPREFIX)ld
NM = $(TOOLPREFIX)nm NM = $(TOOLPREFIX)nm
OBJCOPY = $(TOOLPREFIX)objcopy OBJCOPY = $(TOOLPREFIX)objcopy
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb \ COMFLAGS := -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall \
-m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -mno-red-zone \ -MD -ggdb -m64 -Werror -fms-extensions -mno-sse \
-I$(QEMUSRC) \ -mcmodel=large -mno-red-zone -I$(QEMUSRC) -fno-omit-frame-pointer \
-fno-omit-frame-pointer -DHW_$(HW) -include param.h -include compiler.h -DHW_$(HW) -include param.h -include compiler.h -DXV6
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) COMFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
CFLAGS := $(COMFLAGS) -std=c99
CXXFLAGS := $(COMFLAGS) -std=c++0x -Wno-sign-compare
ASFLAGS = -m64 -gdwarf-2 -MD ASFLAGS = -m64 -gdwarf-2 -MD
LDFLAGS += -m elf_x86_64 LDFLAGS += -m elf_x86_64
...@@ -115,6 +118,10 @@ $(O)/%.o: %.c ...@@ -115,6 +118,10 @@ $(O)/%.o: %.c
@echo " CC $@" @echo " CC $@"
$(Q)$(CC) $(CFLAGS) -c -o $@ $< $(Q)$(CC) $(CFLAGS) -c -o $@ $<
$(O)/%.o: %.cc
@echo " CXX $@"
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
$(O)/incbin.o: ASFLAGS+=-DMAKE_OUT=$(O) $(O)/incbin.o: ASFLAGS+=-DMAKE_OUT=$(O)
$(O)/incbin.o: $(O)/initcode $(O)/bootother $(O)/fs.img $(O)/incbin.o: $(O)/initcode $(O)/bootother $(O)/fs.img
$(O)/%.o: %.S $(O)/%.o: %.S
......
...@@ -21,11 +21,13 @@ ...@@ -21,11 +21,13 @@
// * B_DIRTY: the buffer data has been modified // * B_DIRTY: the buffer data has been modified
// and needs to be written to disk. // and needs to be written to disk.
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.h" #include "condvar.h"
#include "buf.h" #include "buf.h"
}
static struct ns *bufns; static struct ns *bufns;
...@@ -34,7 +36,7 @@ enum { writeback = 0 }; ...@@ -34,7 +36,7 @@ enum { writeback = 0 };
static void * static void *
evict(void *vkey, void *bp, void *arg) evict(void *vkey, void *bp, void *arg)
{ {
struct buf *b = bp; struct buf *b = (buf*) bp;
acquire(&b->lock); acquire(&b->lock);
if ((b->flags & (B_BUSY | B_DIRTY | B_VALID)) == 0) if ((b->flags & (B_BUSY | B_DIRTY | B_VALID)) == 0)
return b; return b;
...@@ -45,7 +47,7 @@ evict(void *vkey, void *bp, void *arg) ...@@ -45,7 +47,7 @@ evict(void *vkey, void *bp, void *arg)
static void * static void *
evict_valid(void *vkey, void *bp, void *arg) evict_valid(void *vkey, void *bp, void *arg)
{ {
struct buf *b = bp; struct buf *b = (buf*) bp;
acquire(&b->lock); acquire(&b->lock);
if ((b->flags & (B_BUSY | B_DIRTY)) == 0) if ((b->flags & (B_BUSY | B_DIRTY)) == 0)
return b; return b;
...@@ -65,7 +67,7 @@ bget(u32 dev, u64 sector, int *writer) ...@@ -65,7 +67,7 @@ bget(u32 dev, u64 sector, int *writer)
// Try for cached block. // Try for cached block.
// XXX ignore dev // XXX ignore dev
gc_begin_epoch(); gc_begin_epoch();
b = ns_lookup(bufns, KII(dev, sector)); b = (buf*) ns_lookup(bufns, KII(dev, sector));
if (b) { if (b) {
if (b->dev != dev || b->sector != sector) if (b->dev != dev || b->sector != sector)
panic("block mismatch"); panic("block mismatch");
...@@ -89,9 +91,9 @@ bget(u32 dev, u64 sector, int *writer) ...@@ -89,9 +91,9 @@ bget(u32 dev, u64 sector, int *writer)
gc_end_epoch(); gc_end_epoch();
// Allocate fresh block. // Allocate fresh block.
struct buf *victim = ns_enumerate(bufns, evict, 0); struct buf *victim = (buf*) ns_enumerate(bufns, evict, 0);
if (victim == 0) if (victim == 0)
victim = ns_enumerate(bufns, evict_valid, 0); victim = (buf*) ns_enumerate(bufns, evict_valid, 0);
if (victim == 0) if (victim == 0)
panic("bget all busy"); panic("bget all busy");
victim->flags |= B_BUSY; victim->flags |= B_BUSY;
...@@ -100,7 +102,7 @@ bget(u32 dev, u64 sector, int *writer) ...@@ -100,7 +102,7 @@ bget(u32 dev, u64 sector, int *writer)
destroylock(&victim->lock); destroylock(&victim->lock);
gc_delayed(victim, kmfree); gc_delayed(victim, kmfree);
b = kmalloc(sizeof(*b)); b = (buf*) kmalloc(sizeof(*b));
b->dev = dev; b->dev = dev;
b->sector = sector; b->sector = sector;
b->flags = B_BUSY; b->flags = B_BUSY;
...@@ -166,7 +168,7 @@ initbio(void) ...@@ -166,7 +168,7 @@ initbio(void)
bufns = nsalloc(0); bufns = nsalloc(0);
for (u64 i = 0; i < NBUF; i++) { for (u64 i = 0; i < NBUF; i++) {
struct buf *b = kmalloc(sizeof(*b)); struct buf *b = (buf*) kmalloc(sizeof(*b));
b->dev = 0xdeadbeef; b->dev = 0xdeadbeef;
b->sector = -i; /* dummy to pre-allocate NBUF spaces for evict */ b->sector = -i; /* dummy to pre-allocate NBUF spaces for evict */
b->flags = 0; b->flags = 0;
......
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "amd64.h" #include "amd64.h"
}
#define BACKSPACE 0x100 #define BACKSPACE 0x100
#define CRTPORT 0x3d4 #define CRTPORT 0x3d4
...@@ -42,7 +44,7 @@ cgaputc(int c) ...@@ -42,7 +44,7 @@ cgaputc(int c)
void void
initcga(void) initcga(void)
{ {
char *p; const char *p;
int i; int i;
for (i = 0; i < 80*25; i++) for (i = 0; i < 80*25; i++)
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "mmu.h" #include "mmu.h"
...@@ -7,6 +8,7 @@ ...@@ -7,6 +8,7 @@
#include "proc.h" #include "proc.h"
#include "kernel.h" #include "kernel.h"
#include "cpu.h" #include "cpu.h"
}
struct spinlock tickslock __mpalign__; struct spinlock tickslock __mpalign__;
struct condvar cv_ticks __mpalign__; struct condvar cv_ticks __mpalign__;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Input is from the keyboard or serial port. // Input is from the keyboard or serial port.
// Output is written to the screen and serial port. // Output is written to the screen and serial port.
extern "C" {
#include "types.h" #include "types.h"
#include "cpu.h" #include "cpu.h"
#include "kernel.h" #include "kernel.h"
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "fmt.h" #include "fmt.h"
#include <stddef.h> #include <stddef.h>
}
#define BACKSPACE 0x100 #define BACKSPACE 0x100
...@@ -69,7 +71,7 @@ struct bufstate { ...@@ -69,7 +71,7 @@ struct bufstate {
static void static void
writebuf(int c, void *arg) writebuf(int c, void *arg)
{ {
struct bufstate *bs = arg; struct bufstate *bs = (bufstate*) arg;
if (bs->p < bs->e) { if (bs->p < bs->e) {
bs->p[0] = c; bs->p[0] = c;
bs->p++; bs->p++;
...@@ -77,7 +79,7 @@ writebuf(int c, void *arg) ...@@ -77,7 +79,7 @@ writebuf(int c, void *arg)
} }
void void
vsnprintf(char *buf, u32 n, char *fmt, va_list ap) vsnprintf(char *buf, u32 n, const char *fmt, va_list ap)
{ {
struct bufstate bs = { buf, buf+n-1 }; struct bufstate bs = { buf, buf+n-1 };
vprintfmt(writebuf, (void*) &bs, fmt, ap); vprintfmt(writebuf, (void*) &bs, fmt, ap);
...@@ -85,7 +87,7 @@ vsnprintf(char *buf, u32 n, char *fmt, va_list ap) ...@@ -85,7 +87,7 @@ vsnprintf(char *buf, u32 n, char *fmt, va_list ap)
} }
void void
snprintf(char *buf, u32 n, char *fmt, ...) snprintf(char *buf, u32 n, const char *fmt, ...)
{ {
va_list ap; va_list ap;
...@@ -147,7 +149,6 @@ printtrace(u64 rbp) ...@@ -147,7 +149,6 @@ printtrace(u64 rbp)
void __noret__ void __noret__
kerneltrap(struct trapframe *tf) kerneltrap(struct trapframe *tf)
{ {
extern void sys_halt();
const char *name = "(no name)"; const char *name = "(no name)";
void *kstack = NULL; void *kstack = NULL;
int pid = 0; int pid = 0;
...@@ -178,7 +179,6 @@ kerneltrap(struct trapframe *tf) ...@@ -178,7 +179,6 @@ kerneltrap(struct trapframe *tf)
void void
panic(const char *fmt, ...) panic(const char *fmt, ...)
{ {
extern void sys_halt();
va_list ap; va_list ap;
cli(); cli();
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "kernel.h" #include "kernel.h"
#include "pci.h" #include "pci.h"
#include "spinlock.h" #include "spinlock.h"
#include "e1000reg.h" #include "e1000reg.h"
}
#define TX_RING_SIZE 64 #define TX_RING_SIZE 64
#define RX_RING_SIZE 64 #define RX_RING_SIZE 64
...@@ -34,7 +36,7 @@ static inline u32 ...@@ -34,7 +36,7 @@ static inline u32
erd(u32 reg) erd(u32 reg)
{ {
paddr pa = e1000.membase + reg; paddr pa = e1000.membase + reg;
volatile u32 *ptr = p2v(pa); volatile u32 *ptr = (u32*) p2v(pa);
return *ptr; return *ptr;
} }
...@@ -42,7 +44,7 @@ static inline void ...@@ -42,7 +44,7 @@ static inline void
ewr(u32 reg, u32 val) ewr(u32 reg, u32 val)
{ {
paddr pa = e1000.membase + reg; paddr pa = e1000.membase + reg;
volatile u32 *ptr = p2v(pa); volatile u32 *ptr = (u32*) p2v(pa);
*ptr = val; *ptr = val;
} }
......
extern "C" {
#include "types.h" #include "types.h"
#include "mmu.h" #include "mmu.h"
#include "spinlock.h" #include "spinlock.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "vm.h" #include "vm.h"
#include "prof.h" #include "prof.h"
#include <stddef.h> #include <stddef.h>
}
#define USTACKPAGES 2 #define USTACKPAGES 2
#define BRK (USERTOP >> 1) #define BRK (USERTOP >> 1)
...@@ -31,8 +33,7 @@ struct eargs { ...@@ -31,8 +33,7 @@ struct eargs {
static void static void
dosegment(uptr a0, u64 a1) dosegment(uptr a0, u64 a1)
{ {
static DEFINE_PROFCTR(dosegment_prof); struct eargs *args = (eargs*) a0;
struct eargs *args = (void*) a0;
u64 off = a1; u64 off = a1;
struct vmnode *vmn = NULL; struct vmnode *vmn = NULL;
struct proghdr ph; struct proghdr ph;
...@@ -50,26 +51,28 @@ dosegment(uptr a0, u64 a1) ...@@ -50,26 +51,28 @@ dosegment(uptr a0, u64 a1)
goto bad; goto bad;
} }
uptr va_start = PGROUNDDOWN(ph.vaddr); {
uptr va_end = PGROUNDUP(ph.vaddr + ph.memsz); uptr va_start = PGROUNDDOWN(ph.vaddr);
uptr va_end = PGROUNDUP(ph.vaddr + ph.memsz);
int npg = (va_end - va_start) / PGSIZE; int npg = (va_end - va_start) / PGSIZE;
if (odp) { if (odp) {
if ((vmn = vmn_alloc(npg, ONDEMAND)) == 0) if ((vmn = vmn_alloc(npg, ONDEMAND)) == 0)
goto bad; goto bad;
} else { } else {
if ((vmn = vmn_allocpg(npg)) == 0) if ((vmn = vmn_allocpg(npg)) == 0)
goto bad;
}
if(vmn_load(vmn, args->ip, ph.offset, ph.filesz) < 0)
goto bad; goto bad;
}
if(vmn_load(vmn, args->ip, ph.offset, ph.filesz) < 0) if(vmap_insert(args->vmap, vmn, ph.vaddr) < 0)
goto bad; goto bad;
if(vmap_insert(args->vmap, vmn, ph.vaddr) < 0)
goto bad;
prof_end(dosegment_prof); prof_end(dosegment_prof);
return; return;
}
bad: bad:
panic("dosegment: Oops"); panic("dosegment: Oops");
...@@ -77,9 +80,8 @@ bad: ...@@ -77,9 +80,8 @@ bad:
static void dostack(uptr a0, u64 a1) static void dostack(uptr a0, u64 a1)
{ {
static DEFINE_PROFCTR(dostack_prof);
struct vmnode *vmn = NULL; struct vmnode *vmn = NULL;
struct eargs *args = (void*) a0; struct eargs *args = (eargs*) a0;
int argc; int argc;
uptr sp; uptr sp;
uptr ustack[1+MAXARG+1]; uptr ustack[1+MAXARG+1];
...@@ -132,9 +134,8 @@ bad: ...@@ -132,9 +134,8 @@ bad:
static void doheap(uptr a0, u64 a1) static void doheap(uptr a0, u64 a1)
{ {
static DEFINE_PROFCTR(doheap_prof);
struct vmnode *vmn = NULL; struct vmnode *vmn = NULL;
struct eargs *args = (void*) a0; struct eargs *args = (eargs*) a0;
prof_start(doheap_prof); prof_start(doheap_prof);
// Allocate a vmnode for the heap. // Allocate a vmnode for the heap.
...@@ -155,7 +156,6 @@ bad: ...@@ -155,7 +156,6 @@ bad:
int int
exec(char *path, char **argv) exec(char *path, char **argv)
{ {
static DEFINE_PROFCTR(exec_prof);
struct inode *ip = NULL; struct inode *ip = NULL;
struct vmap *vmap = NULL; struct vmap *vmap = NULL;
struct vmnode *vmn = NULL; struct vmnode *vmn = NULL;
......
extern "C" {
#include "types.h" #include "types.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.h" #include "condvar.h"
...@@ -5,6 +6,8 @@ ...@@ -5,6 +6,8 @@
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "stat.h" #include "stat.h"
#include "net.h"
}
struct devsw __mpalign__ devsw[NDEV]; struct devsw __mpalign__ devsw[NDEV];
...@@ -12,7 +15,7 @@ struct devsw __mpalign__ devsw[NDEV]; ...@@ -12,7 +15,7 @@ struct devsw __mpalign__ devsw[NDEV];
struct file* struct file*
filealloc(void) filealloc(void)
{ {
struct file *f = kmalloc(sizeof(struct file)); struct file *f = (file*) kmalloc(sizeof(struct file));
f->ref = 1; f->ref = 1;
return f; return f;
} }
...@@ -30,16 +33,14 @@ filedup(struct file *f) ...@@ -30,16 +33,14 @@ filedup(struct file *f)
void void
fileclose(struct file *f) fileclose(struct file *f)
{ {
extern void netclose(int sock);
if (subfetch(&f->ref, 1) > 0) if (subfetch(&f->ref, 1) > 0)
return; return;
if(f->type == FD_PIPE) if(f->type == file::FD_PIPE)
pipeclose(f->pipe, f->writable); pipeclose(f->pipe, f->writable);
else if(f->type == FD_INODE) else if(f->type == file::FD_INODE)
iput(f->ip); iput(f->ip);
else if(f->type == FD_SOCKET) else if(f->type == file::FD_SOCKET)
netclose(f->socket); netclose(f->socket);
else else
panic("fileclose bad type"); panic("fileclose bad type");
...@@ -50,7 +51,7 @@ fileclose(struct file *f) ...@@ -50,7 +51,7 @@ fileclose(struct file *f)
int int
filestat(struct file *f, struct stat *st) filestat(struct file *f, struct stat *st)
{ {
if(f->type == FD_INODE){ if(f->type == file::FD_INODE){
ilock(f->ip, 0); ilock(f->ip, 0);
if(f->ip->type == 0) if(f->ip->type == 0)
panic("filestat"); panic("filestat");
...@@ -65,14 +66,13 @@ filestat(struct file *f, struct stat *st) ...@@ -65,14 +66,13 @@ filestat(struct file *f, struct stat *st)
int int
fileread(struct file *f, char *addr, int n) fileread(struct file *f, char *addr, int n)
{ {
extern int netread(int, char *, int);
int r; int r;
if(f->readable == 0) if(f->readable == 0)
return -1; return -1;
if(f->type == FD_PIPE) if(f->type == file::FD_PIPE)
return piperead(f->pipe, addr, n); return piperead(f->pipe, addr, n);
if(f->type == FD_INODE){ if(f->type == file::FD_INODE){
ilock(f->ip, 0); ilock(f->ip, 0);
if(f->ip->type == 0) if(f->ip->type == 0)
panic("fileread"); panic("fileread");
...@@ -81,7 +81,7 @@ fileread(struct file *f, char *addr, int n) ...@@ -81,7 +81,7 @@ fileread(struct file *f, char *addr, int n)
iunlock(f->ip); iunlock(f->ip);
return r; return r;
} }
if(f->type == FD_SOCKET) if(f->type == file::FD_SOCKET)
return netread(f->socket, addr, n); return netread(f->socket, addr, n);
panic("fileread"); panic("fileread");
} }
...@@ -90,14 +90,13 @@ fileread(struct file *f, char *addr, int n) ...@@ -90,14 +90,13 @@ fileread(struct file *f, char *addr, int n)
int int
filewrite(struct file *f, char *addr, int n) filewrite(struct file *f, char *addr, int n)
{ {
extern int netwrite(int, char *, int);
int r; int r;
if(f->writable == 0) if(f->writable == 0)
return -1; return -1;
if(f->type == FD_PIPE) if(f->type == file::FD_PIPE)
return pipewrite(f->pipe, addr, n); return pipewrite(f->pipe, addr, n);
if(f->type == FD_INODE){ if(f->type == file::FD_INODE){
ilock(f->ip, 1); ilock(f->ip, 1);
if(f->ip->type == 0 || f->ip->type == T_DIR) if(f->ip->type == 0 || f->ip->type == T_DIR)
panic("filewrite but 0 or T_DIR"); panic("filewrite but 0 or T_DIR");
...@@ -106,7 +105,7 @@ filewrite(struct file *f, char *addr, int n) ...@@ -106,7 +105,7 @@ filewrite(struct file *f, char *addr, int n)
iunlock(f->ip); iunlock(f->ip);
return r; return r;
} }
if(f->type == FD_SOCKET) if(f->type == file::FD_SOCKET)
return netwrite(f->socket, addr, n); return netwrite(f->socket, addr, n);
panic("filewrite"); panic("filewrite");
} }
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include "fmt.h" #include "fmt.h"
}
// //
// Print a number (base <= 16) in reverse order, // Print a number (base <= 16) in reverse order,
......
...@@ -18,7 +18,7 @@ execbench(void) ...@@ -18,7 +18,7 @@ execbench(void)
exit(); exit();
} }
if (pid == 0) { if (pid == 0) {
char *av[] = { "forkexecbench", "x", 0 }; const char *av[] = { "forkexecbench", "x", 0 };
exec("forkexecbench", av); exec("forkexecbench", av);
printf(1, "exec failed\n"); printf(1, "exec failed\n");
exit(); exit();
......
...@@ -28,7 +28,7 @@ forktree(int depth) ...@@ -28,7 +28,7 @@ forktree(int depth)
depth++; depth++;
char depthbuf[16]; char depthbuf[16];
snprintf(depthbuf, sizeof(depthbuf), "%d", depth); snprintf(depthbuf, sizeof(depthbuf), "%d", depth);
char *av[] = { "forkexectree", depthbuf }; const char *av[] = { "forkexectree", depthbuf };
exec("forkexectree", av); exec("forkexectree", av);
} }
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// routines. The (higher-level) system call implementations // routines. The (higher-level) system call implementations
// are in sysfile.c. // are in sysfile.c.
extern "C" {
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "mmu.h" #include "mmu.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "cpu.h" #include "cpu.h"
}
#define min(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
static void itrunc(struct inode*); static void itrunc(struct inode*);
...@@ -204,7 +206,7 @@ iupdate(struct inode *ip) ...@@ -204,7 +206,7 @@ iupdate(struct inode *ip)
static void * static void *
evict(void *vkey, void *p, void *arg) evict(void *vkey, void *p, void *arg)
{ {
struct inode *ip = p; struct inode *ip = (inode*) p;
if (ip->ref || ip->type == T_DIR) if (ip->ref || ip->type == T_DIR)
return 0; return 0;
...@@ -225,7 +227,7 @@ evict(void *vkey, void *p, void *arg) ...@@ -225,7 +227,7 @@ evict(void *vkey, void *p, void *arg)
static void static void
ifree(void *arg) ifree(void *arg)
{ {
struct inode *ip = arg; struct inode *ip = (inode*) arg;
if (ip->dir) { if (ip->dir) {
ns_remove(ip->dir, KD("."), 0); ns_remove(ip->dir, KD("."), 0);
...@@ -246,7 +248,7 @@ iget(u32 dev, u32 inum) ...@@ -246,7 +248,7 @@ iget(u32 dev, u32 inum)
retry: retry:
// Try for cached inode. // Try for cached inode.
gc_begin_epoch(); gc_begin_epoch();
ip = ns_lookup(ins, KII(dev, inum)); ip = (inode*) ns_lookup(ins, KII(dev, inum));
if (ip) { if (ip) {
// tricky: first bump ref, then check free flag // tricky: first bump ref, then check free flag
__sync_fetch_and_add(&ip->ref, 1); __sync_fetch_and_add(&ip->ref, 1);
...@@ -271,7 +273,7 @@ iget(u32 dev, u32 inum) ...@@ -271,7 +273,7 @@ iget(u32 dev, u32 inum)
(void) 0; (void) 0;
u32 cur_free = icache_free[mycpu()->id].x; u32 cur_free = icache_free[mycpu()->id].x;
if (cur_free == 0) { if (cur_free == 0) {
struct inode *victim = ns_enumerate(ins, evict, 0); struct inode *victim = (inode*) ns_enumerate(ins, evict, 0);
if (!victim) if (!victim)
panic("iget out of space"); panic("iget out of space");
// tricky: first flag as free, then check refcnt, then remove from ns // tricky: first flag as free, then check refcnt, then remove from ns
...@@ -289,7 +291,7 @@ iget(u32 dev, u32 inum) ...@@ -289,7 +291,7 @@ iget(u32 dev, u32 inum)
goto retry_evict; goto retry_evict;
} }
ip = kmalloc(sizeof(*ip)); ip = (inode*) kmalloc(sizeof(*ip));
ip->dev = dev; ip->dev = dev;
ip->inum = inum; ip->inum = inum;
ip->ref = 1; ip->ref = 1;
...@@ -613,8 +615,8 @@ struct flush_state { ...@@ -613,8 +615,8 @@ struct flush_state {
static void * static void *
dir_flush_cb(void *key, void *val, void *arg) dir_flush_cb(void *key, void *val, void *arg)
{ {
struct flush_state *fs = arg; struct flush_state *fs = (flush_state*) arg;
char *name = key; char *name = (char*) key;
u32 inum = (u64) val; u32 inum = (u64) val;
struct dirent de; struct dirent de;
...@@ -658,7 +660,7 @@ dirlookup(struct inode *dp, char *name) ...@@ -658,7 +660,7 @@ dirlookup(struct inode *dp, char *name)
// Write a new directory entry (name, inum) into the directory dp. // Write a new directory entry (name, inum) into the directory dp.
int int
dirlink(struct inode *dp, char *name, u32 inum) dirlink(struct inode *dp, const char *name, u32 inum)
{ {
dir_init(dp); dir_init(dp);
...@@ -684,10 +686,10 @@ dirlink(struct inode *dp, char *name, u32 inum) ...@@ -684,10 +686,10 @@ dirlink(struct inode *dp, char *name, u32 inum)
// skipelem("", name) = skipelem("////", name) = 0 // skipelem("", name) = skipelem("////", name) = 0
// //
static int static int
skipelem(char **rpath, char *name) skipelem(const char **rpath, char *name)
{ {
char *path = *rpath; const char *path = *rpath;
char *s; const char *s;
int len; int len;
while(*path == '/') while(*path == '/')
...@@ -714,7 +716,7 @@ skipelem(char **rpath, char *name) ...@@ -714,7 +716,7 @@ skipelem(char **rpath, char *name)
// If parent != 0, return the inode for the parent and copy the final // If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes. // path element into name, which must have room for DIRSIZ bytes.
static struct inode* static struct inode*
namex(char *path, int nameiparent, char *name) namex(const char *path, int nameiparent, char *name)
{ {
struct inode *ip, *next; struct inode *ip, *next;
int r; int r;
...@@ -759,7 +761,7 @@ namex(char *path, int nameiparent, char *name) ...@@ -759,7 +761,7 @@ namex(char *path, int nameiparent, char *name)
} }
struct inode* struct inode*
namei(char *path) namei(const char *path)
{ {
char name[DIRSIZ]; char name[DIRSIZ];
struct inode *r = namex(path, 0, name); struct inode *r = namex(path, 0, name);
......
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "mmu.h" #include "mmu.h"
...@@ -7,6 +8,7 @@ ...@@ -7,6 +8,7 @@
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.h"
#include "cpu.h" #include "cpu.h"
}
// GC scheme based on Fraser's: // GC scheme based on Fraser's:
// a machine has a global_epoch // a machine has a global_epoch
...@@ -61,7 +63,7 @@ u64 global_epoch __mpalign__; ...@@ -61,7 +63,7 @@ u64 global_epoch __mpalign__;
struct gc * struct gc *
gc_alloc() gc_alloc()
{ {
struct gc *r = kmalloc(sizeof(struct gc)); struct gc *r = (gc*) kmalloc(sizeof(struct gc));
assert(r); assert(r);
__sync_fetch_and_add(&gc_state[mycpu()->id].ndelayed, 1); __sync_fetch_and_add(&gc_state[mycpu()->id].ndelayed, 1);
return r; return r;
...@@ -69,7 +71,7 @@ gc_alloc() ...@@ -69,7 +71,7 @@ gc_alloc()
static void * static void *
gc_min(void *vkey, void *v, void *arg){ gc_min(void *vkey, void *v, void *arg){
u64 *min_epoch_p = arg; u64 *min_epoch_p = (u64*) arg;
struct proc *p = (struct proc *) v; struct proc *p = (struct proc *) v;
// Some threads may never call begin/end_epoch(), and never update // Some threads may never call begin/end_epoch(), and never update
// p->epoch, so gc_thread does it for them. XXX get rid off lock? // p->epoch, so gc_thread does it for them. XXX get rid off lock?
...@@ -175,7 +177,7 @@ gc_delayfreelist(void) ...@@ -175,7 +177,7 @@ gc_delayfreelist(void)
u64 min = global; u64 min = global;
// make that global_epoch doesn't run into a core's min_epoch // make that global_epoch doesn't run into a core's min_epoch
for (int c = 0; c < ncpu; c++) { for (int c = 0; c < ncpu; c++) {
int w = gc_state[c].min_epoch + NEPOCH-1; u64 w = gc_state[c].min_epoch + NEPOCH-1;
if (w < min) { if (w < min) {
min = w; min = w;
} }
...@@ -322,7 +324,7 @@ initgc(void) ...@@ -322,7 +324,7 @@ initgc(void)
initcondvar(&gc_state[i].cv, "gc_cv"); initcondvar(&gc_state[i].cv, "gc_cv");
} }
for (u32 c = 0; c < ncpu; c++) { for (int c = 0; c < ncpu; c++) {
struct proc *gcp; struct proc *gcp;
gcp = threadalloc(gc_worker, NULL); gcp = threadalloc(gc_worker, NULL);
......
extern "C" {
#include "types.h" #include "types.h"
#include "user.h" #include "user.h"
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
......
...@@ -19,7 +19,7 @@ static int xwrite(int fd, const void *buf, u64 n) ...@@ -19,7 +19,7 @@ static int xwrite(int fd, const void *buf, u64 n)
printf(1, "xwrite: failed %d\n", r); printf(1, "xwrite: failed %d\n", r);
return -1; return -1;
} }
buf += r; buf = (char *) buf + r;
n -= r; n -= r;
} }
...@@ -208,7 +208,7 @@ parse(const char *b, char **rurl) ...@@ -208,7 +208,7 @@ parse(const char *b, char **rurl)
b++; b++;
len = b - url; len = b - url;
r = malloc(len+1); r = (char *) malloc(len+1);
if (r == NULL) if (r == NULL)
return -1; return -1;
memmove(r, url, len); memmove(r, url, len);
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "mmu.h" #include "mmu.h"
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
#include "proc.h" #include "proc.h"
#include "vm.h" #include "vm.h"
#include <stddef.h> #include <stddef.h>
}
extern pml4e_t kpml4[]; extern pml4e_t kpml4[];
...@@ -24,7 +26,7 @@ retry: ...@@ -24,7 +26,7 @@ retry:
dir = &dir[PX(level, va)]; dir = &dir[PX(level, va)];
entry = *dir; entry = *dir;
if (entry & PTE_P) { if (entry & PTE_P) {
next = p2v(PTE_ADDR(entry)); next = (pme_t*) p2v(PTE_ADDR(entry));
} else { } else {
if (!create) if (!create)
return NULL; return NULL;
...@@ -69,8 +71,8 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm) ...@@ -69,8 +71,8 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm)
char *a, *last; char *a, *last;
pme_t *pte; pme_t *pte;
a = PGROUNDDOWN(begin); a = (char*) PGROUNDDOWN(begin);
last = PGROUNDDOWN(end); last = (char*) PGROUNDDOWN(end);
for (;;) { for (;;) {
pte = walkpgdir(pml4, a, 1); pte = walkpgdir(pml4, a, 1);
if(pte != 0) { if(pte != 0) {
...@@ -85,7 +87,7 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm) ...@@ -85,7 +87,7 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm)
// Map from 0 to 128Gbytes starting at KBASE. // Map from 0 to 128Gbytes starting at KBASE.
void void
initpg(char* (*alloc)(void)) initpg(void)
{ {
extern char end[]; extern char end[];
void *va = (void*)KBASE; void *va = (void*)KBASE;
...@@ -100,7 +102,7 @@ initpg(char* (*alloc)(void)) ...@@ -100,7 +102,7 @@ initpg(char* (*alloc)(void))
if (va >= (void*) end) if (va >= (void*) end)
flags |= PTE_NX; flags |= PTE_NX;
*sp = pa | flags; *sp = pa | flags;
va += PGSIZE*512; va = (char*)va + PGSIZE*512;
pa += PGSIZE*512; pa += PGSIZE*512;
} }
} }
...@@ -124,7 +126,7 @@ int ...@@ -124,7 +126,7 @@ int
setupkshared(pml4e_t *pml4, char *kshared) setupkshared(pml4e_t *pml4, char *kshared)
{ {
for (u64 off = 0; off < KSHAREDSIZE; off+=4096) { for (u64 off = 0; off < KSHAREDSIZE; off+=4096) {
pme_t *pte = walkpgdir(pml4, (void*)KSHARED+off, 1); pme_t *pte = walkpgdir(pml4, (void*)(KSHARED+off), 1);
if (pte == NULL) if (pte == NULL)
panic("setupkshared: oops"); panic("setupkshared: oops");
*pte = v2p(kshared+off) | PTE_P | PTE_U | PTE_W; *pte = v2p(kshared+off) | PTE_P | PTE_U | PTE_W;
...@@ -166,7 +168,7 @@ freepm(pme_t *pm, int level) ...@@ -166,7 +168,7 @@ freepm(pme_t *pm, int level)
if (level != 0) { if (level != 0) {
for (i = 0; i < 512; i++) { for (i = 0; i < 512; i++) {
if (pm[i] & PTE_P) if (pm[i] & PTE_P)
freepm(p2v(PTE_ADDR(pm[i])), level - 1); freepm((pme_t*) p2v(PTE_ADDR(pm[i])), level - 1);
} }
} }
...@@ -188,7 +190,7 @@ freevm(pml4e_t *pml4) ...@@ -188,7 +190,7 @@ freevm(pml4e_t *pml4)
k = PX(3, KBASE); k = PX(3, KBASE);
for (i = 0; i < k; i++) { for (i = 0; i < k; i++) {
if (pml4[i] & PTE_P) { if (pml4[i] & PTE_P) {
freepm(p2v(PTE_ADDR(pml4[i])), 2); freepm((pme_t*) p2v(PTE_ADDR(pml4[i])), 2);
} }
} }
......
// Intel 8253/8254/82C54 Programmable Interval Timer (PIT). // Intel 8253/8254/82C54 Programmable Interval Timer (PIT).
// http://en.wikipedia.org/wiki/Intel_8253 // http://en.wikipedia.org/wiki/Intel_8253
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "kernel.h" #include "kernel.h"
}
#define IO_TIMER1 0x040 // 8253 Timer #1 #define IO_TIMER1 0x040 // 8253 Timer #1
#define TIMER_FREQ 1193182 #define TIMER_FREQ 1193182
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "fcntl.h" #include "fcntl.h"
#include "lib.h" #include "lib.h"
static char *sh_argv[] = { "sh", 0 }; static const char *sh_argv[] = { "sh", 0 };
static char *app_argv[][MAXARG] = { static const char *app_argv[][MAXARG] = {
#ifdef LWIP #ifdef LWIP
{ "telnetd", 0 }, { "telnetd", 0 },
{ "httpd", 0 }, { "httpd", 0 },
...@@ -15,7 +15,7 @@ static char *app_argv[][MAXARG] = { ...@@ -15,7 +15,7 @@ static char *app_argv[][MAXARG] = {
}; };
static int static int
startone(char **argv) startone(const char **argv)
{ {
int pid; int pid;
...@@ -52,7 +52,7 @@ main(void) ...@@ -52,7 +52,7 @@ main(void)
if (mknod("/dev/lockstat", 4, 1) < 0) if (mknod("/dev/lockstat", 4, 1) < 0)
printf(2, "init: mknod lockstat failed\n"); printf(2, "init: mknod lockstat failed\n");
for (int i = 0; i < NELEM(app_argv); i++) for (u32 i = 0; i < NELEM(app_argv); i++)
startone(app_argv[i]); startone(app_argv[i]);
for(;;){ for(;;){
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
// http://www.intel.com/design/chipsets/datashts/29056601.pdf // http://www.intel.com/design/chipsets/datashts/29056601.pdf
// See also picirq.c. // See also picirq.c.
extern "C" {
#include "types.h" #include "types.h"
#include "traps.h" #include "traps.h"
#include "kernel.h" #include "kernel.h"
}
#define IOAPIC (KBASE + 0xFEC00000) // Default physical address of IO APIC #define IOAPIC (KBASE + 0xFEC00000) // Default physical address of IO APIC
......
...@@ -39,7 +39,6 @@ extern char end[]; // first address after kernel loaded from ELF file ...@@ -39,7 +39,6 @@ extern char end[]; // first address after kernel loaded from ELF file
char *newend; char *newend;
static int kinited __mpalign__; static int kinited __mpalign__;
extern void kminit();
static struct Mbmem * static struct Mbmem *
memsearch(paddr pa) memsearch(paddr pa)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define KDSEG (3<<3) /* kernel data segment */ #define KDSEG (3<<3) /* kernel data segment */
static inline uptr v2p(void *a) { return (uptr) a - KBASE; } static inline uptr v2p(void *a) { return (uptr) a - KBASE; }
static inline void *p2v(uptr a) { return (void *) a + KBASE; } static inline void *p2v(uptr a) { return (u8 *) a + KBASE; }
struct trapframe; struct trapframe;
struct cilkframe; struct cilkframe;
...@@ -50,7 +50,7 @@ void cprintf(const char*, ...) __attribute__((format(printf, 1, 2))); ...@@ -50,7 +50,7 @@ void cprintf(const char*, ...) __attribute__((format(printf, 1, 2)));
void panic(const char*, ...) void panic(const char*, ...)
__noret__ __attribute__((format(printf, 1, 2))); __noret__ __attribute__((format(printf, 1, 2)));
void kerneltrap(struct trapframe *tf) __noret__; void kerneltrap(struct trapframe *tf) __noret__;
void snprintf(char *buf, u32 n, char *fmt, ...); void snprintf(char *buf, u32 n, const char *fmt, ...);
void consoleintr(int(*)(void)); void consoleintr(int(*)(void));
#define assert(c) if (!(c)) { cprintf("%s:%d: ", __FILE__, __LINE__); panic("assertion failure"); } #define assert(c) if (!(c)) { cprintf("%s:%d: ", __FILE__, __LINE__); panic("assertion failure"); }
...@@ -101,7 +101,7 @@ int filewrite(struct file*, char*, int n); ...@@ -101,7 +101,7 @@ int filewrite(struct file*, char*, int n);
int namecmp(const char*, const char*); int namecmp(const char*, const char*);
struct inode* dirlookup(struct inode*, char*); struct inode* dirlookup(struct inode*, char*);
struct inode* ialloc(u32, short); struct inode* ialloc(u32, short);
struct inode* namei(char*); struct inode* namei(const char*);
void iput(struct inode*); void iput(struct inode*);
struct inode* iget(u32 dev, u32 inum); struct inode* iget(u32 dev, u32 inum);
void ilock(struct inode*, int writer); void ilock(struct inode*, int writer);
...@@ -113,7 +113,7 @@ void stati(struct inode*, struct stat*); ...@@ -113,7 +113,7 @@ void stati(struct inode*, struct stat*);
int writei(struct inode*, char*, u32, u32); int writei(struct inode*, char*, u32, u32);
struct inode* idup(struct inode*); struct inode* idup(struct inode*);
struct inode* nameiparent(char*, char*); struct inode* nameiparent(char*, char*);
int dirlink(struct inode*, char*, u32); int dirlink(struct inode*, const char*, u32);
void dir_init(struct inode *dp); void dir_init(struct inode *dp);
void dir_flush(struct inode *dp); void dir_flush(struct inode *dp);
...@@ -135,6 +135,7 @@ pme_t * walkpgdir(pml4e_t*, const void*, int); ...@@ -135,6 +135,7 @@ pme_t * walkpgdir(pml4e_t*, const void*, int);
// hz.c // hz.c
void microdelay(u64); void microdelay(u64);
u64 nsectime(void); u64 nsectime(void);
void inithz(void);
// ide.c // ide.c
void ideinit(void); void ideinit(void);
...@@ -159,6 +160,7 @@ void kmfree(void*); ...@@ -159,6 +160,7 @@ void kmfree(void*);
int kmalign(void **p, int align, u64 size); int kmalign(void **p, int align, u64 size);
void kmalignfree(void *); void kmalignfree(void *);
void verifyfree(char *ptr, u64 nbytes); void verifyfree(char *ptr, u64 nbytes);
void kminit(void);
// kbd.c // kbd.c
void kbdintr(void); void kbdintr(void);
...@@ -200,7 +202,7 @@ struct nskey { ...@@ -200,7 +202,7 @@ struct nskey {
u64 b; u64 b;
} ii; } ii;
char *s; char *s;
char *dirname; const char *dirname;
struct { struct {
u64 a; u64 a;
u64 b; u64 b;
...@@ -209,10 +211,10 @@ struct nskey { ...@@ -209,10 +211,10 @@ struct nskey {
} u; } u;
}; };
#define KI(v) (struct nskey){.type=nskey_int,.u.i=v} #define KI(v) (struct nskey){type: nskey_int, u: { i: v }}
#define KII(x,y) (struct nskey){.type=nskey_ii,.u.ii.a=x,.u.ii.b=y} #define KII(x,y) (struct nskey){type: nskey_ii, u: {ii: {a:x, b:y}}}
#define KS(v) (struct nskey){.type=nskey_str,.u.s=v} #define KS(v) (struct nskey){.type=nskey_str,.u.s=v}
#define KD(v) (struct nskey){.type=nskey_dirname,.u.dirname=v} #define KD(v) (struct nskey){type: nskey_dirname, u: { dirname: v }}
#define KIIS(x,y,z) (struct nskey){.type=nskey_iis,.u.iis.a=x, \ #define KIIS(x,y,z) (struct nskey){.type=nskey_iis,.u.iis.a=x, \
.u.iis.b=y, \ .u.iis.b=y, \
.u.iis.s=z} .u.iis.s=z}
...@@ -291,10 +293,11 @@ void syscall(void); ...@@ -291,10 +293,11 @@ void syscall(void);
int memcmp(const void*, const void*, u32); int memcmp(const void*, const void*, u32);
void* memmove(void*, const void*, u32); void* memmove(void*, const void*, u32);
void* memset(void*, int, u32); void* memset(void*, int, u32);
char* safestrcpy(char*, const char*, int); void* memcpy(void*, const void *, u32);
char* safestrcpy(char*, const char*, u32);
int strlen(const char*); int strlen(const char*);
int strncmp(const char*, const char*, u32); int strncmp(const char*, const char*, u32);
char* strncpy(char*, const char*, int); char* strncpy(char*, const char*, u32);
int strcmp(const char *p, const char *q); int strcmp(const char *p, const char *q);
// swtch.S // swtch.S
...@@ -311,8 +314,10 @@ void uartputc(char c); ...@@ -311,8 +314,10 @@ void uartputc(char c);
void uartintr(void); void uartintr(void);
// vm.c // vm.c
enum vmntype { EAGER, ONDEMAND };
struct vmap * vmap_alloc(void); struct vmap * vmap_alloc(void);
struct vmnode* vmn_alloc(u64, u32); struct vmnode* vmn_alloc(u64, enum vmntype);
struct vmnode* vmn_allocpg(u64); struct vmnode* vmn_allocpg(u64);
int vmap_insert(struct vmap*, struct vmnode *, uptr); int vmap_insert(struct vmap*, struct vmnode *, uptr);
struct vma * vmap_lookup(struct vmap*, uptr, uptr); struct vma * vmap_lookup(struct vmap*, uptr, uptr);
...@@ -352,3 +357,70 @@ void initcilkframe(struct cilkframe *wq); ...@@ -352,3 +357,70 @@ void initcilkframe(struct cilkframe *wq);
#define cilk_trywork() 0 #define cilk_trywork() 0
#define initcilkframe(x) do { } while (0) #define initcilkframe(x) do { } while (0)
#endif #endif
// various init functions
void initpic(void);
void initioapic(void);
void inituart(void);
void initcga(void);
void initconsole(void);
void initpg(void);
void initmp(void);
void initlapic(void);
void inittls(void);
void inittrap(void);
void initseg(void);
void initkalloc(u64 mbaddr);
void initrcu(void);
void initproc(void);
void initbio(void);
void initinode(void);
void initdisk(void);
void inituser(void);
void initcilk(void);
void initsamp(void);
void initpci(void);
void initnet(void);
void initsched(void);
void initlockstat(void);
void initwq(void);
// syscalls
long sys_chdir(void);
long sys_close(void);
long sys_dup(void);
long sys_exec(void);
long sys_exit(void);
long sys_fork(void);
long sys_fstat(void);
long sys_getpid(void);
long sys_kill(void);
long sys_link(void);
long sys_mkdir(void);
long sys_mknod(void);
long sys_open(void);
long sys_pipe(void);
long sys_read(void);
long sys_sbrk(void);
long sys_sleep(void);
long sys_unlink(void);
long sys_wait(void);
long sys_write(void);
long sys_uptime(void);
long sys_map(void);
long sys_unmap(void);
long sys_halt(void);
long sys_socket(int, int, int);
long sys_bind(int, void*, int);
long sys_listen(int, int);
long sys_accept(int, void*, void*);
long sys_pread(int fd, void *ubuf, size_t count, off_t offset);
long sys_kernlet(int, size_t, off_t);
// other exported/imported functions
void cmain(u64 mbmagic, u64 mbaddr);
void mpboot(void);
void trapret(void);
void threadstub(void);
void threadhelper(void (*fn)(void *), void *arg);
extern "C" {
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
}
int int
main(int argc, char **argv) main(int argc, char **argv)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Allocate objects smaller than a page. // Allocate objects smaller than a page.
// //
extern "C" {
#include "types.h" #include "types.h"
#include "mmu.h" #include "mmu.h"
#include "kernel.h" #include "kernel.h"
...@@ -9,6 +10,7 @@ ...@@ -9,6 +10,7 @@
#include "kalloc.h" #include "kalloc.h"
#include "mtrace.h" #include "mtrace.h"
#include "cpu.h" #include "cpu.h"
}
// allocate in power-of-two sizes up to 2^KMMAX // allocate in power-of-two sizes up to 2^KMMAX
// must be < 12 // must be < 12
...@@ -78,7 +80,7 @@ kmalloc(u64 nbytes) ...@@ -78,7 +80,7 @@ kmalloc(u64 nbytes)
if(h){ if(h){
freelists[c].buckets[b] = h->next; freelists[c].buckets[b] = h->next;
r = h + 1; r = h + 1;
h->next = (void *) (long) b; h->next = (header*) (long) b;
} }
release(&freelists[c].lock); release(&freelists[c].lock);
...@@ -103,7 +105,7 @@ kmfree(void *ap) ...@@ -103,7 +105,7 @@ kmfree(void *ap)
if(b < 0 || b > KMMAX) if(b < 0 || b > KMMAX)
panic("kmfree bad bucket"); panic("kmfree bad bucket");
verifyfree(ap, (1<<b) - sizeof(struct header)); verifyfree((char*) ap, (1<<b) - sizeof(struct header));
if (ALLOC_MEMSET) if (ALLOC_MEMSET)
memset(ap, 3, (1<<b) - sizeof(struct header)); memset(ap, 3, (1<<b) - sizeof(struct header));
......
// The local APIC manages internal (non-I/O) interrupts. // The local APIC manages internal (non-I/O) interrupts.
// See Chapter 8 & Appendix C of Intel processor manual volume 3. // See Chapter 8 & Appendix C of Intel processor manual volume 3.
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "kernel.h" #include "kernel.h"
#include "traps.h" #include "traps.h"
#include "bits.h" #include "bits.h"
}
// Local APIC registers, divided by 4 for use as uint[] indices. // Local APIC registers, divided by 4 for use as uint[] indices.
#define ID (0x0020/4) // ID #define ID (0x0020/4) // ID
......
...@@ -50,7 +50,7 @@ stats(void) ...@@ -50,7 +50,7 @@ stats(void)
} }
int int
main(int ac, char *av[]) main(int ac, const char *av[])
{ {
int fd = open("/dev/lockstat", O_RDWR); int fd = open("/dev/lockstat", O_RDWR);
if (fd < 0) if (fd < 0)
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
#include "user.h" #include "user.h"
#include "fs.h" #include "fs.h"
char* const char*
fmtname(char *path) fmtname(const char *path)
{ {
static char buf[DIRSIZ+1]; static char buf[DIRSIZ+1];
char *p; const char *p;
// Find first character after last slash. // Find first character after last slash.
for(p=path+strlen(path); p >= path && *p != '/'; p--) for(p=path+strlen(path); p >= path && *p != '/'; p--)
...@@ -23,7 +23,7 @@ fmtname(char *path) ...@@ -23,7 +23,7 @@ fmtname(char *path)
} }
void void
ls(char *path) ls(const char *path)
{ {
char buf[512], *p; char buf[512], *p;
int fd; int fd;
......
extern "C" {
#include "types.h" #include "types.h"
#include "multiboot.h" #include "multiboot.h"
#include "kernel.h" #include "kernel.h"
#include "cpu.h" #include "cpu.h"
#include "amd64.h" #include "amd64.h"
}
extern void initpic(void);
extern void initioapic(void);
extern void inituart(void);
extern void initcga(void);
extern void initconsole(void);
extern void initpg(void);
extern void initmp(void);
extern void initlapic(void);
extern void inittls(void);
extern void inittrap(void);
extern void initseg(void);
extern void initkalloc(u64 mbaddr);
extern void initrcu(void);
extern void initproc(void);
extern void initbio(void);
extern void initinode(void);
extern void initdisk(void);
extern void inituser(void);
extern void inithz(void);
extern void initwq(void);
extern void initcilk(void);
extern void initsamp(void);
extern void initpci(void);
extern void initnet(void);
extern void initsched(void);
extern void initlockstat(void);
static volatile int bstate; static volatile int bstate;
...@@ -57,7 +32,7 @@ bootothers(void) ...@@ -57,7 +32,7 @@ bootothers(void)
// Write bootstrap code to unused memory at 0x7000. // Write bootstrap code to unused memory at 0x7000.
// The linker has placed the image of bootother.S in // The linker has placed the image of bootother.S in
// _binary_bootother_start. // _binary_bootother_start.
code = p2v(0x7000); code = (u8*) p2v(0x7000);
memmove(code, _bootother_start, _bootother_size); memmove(code, _bootother_start, _bootother_size);
for(c = cpus; c < cpus+ncpu; c++){ for(c = cpus; c < cpus+ncpu; c++){
...@@ -67,7 +42,7 @@ bootothers(void) ...@@ -67,7 +42,7 @@ bootothers(void)
// Tell bootother.S what stack to use and the address of apstart; // Tell bootother.S what stack to use and the address of apstart;
// it expects to find these two addresses stored just before // it expects to find these two addresses stored just before
// its first instruction. // its first instruction.
stack = ksalloc(slab_stack); stack = (char*) ksalloc(slab_stack);
*(u32*)(code-4) = (u32)v2p(&apstart); *(u32*)(code-4) = (u32)v2p(&apstart);
*(u64*)(code-12) = (u64)stack + KSTACKSIZE; *(u64*)(code-12) = (u64)stack + KSTACKSIZE;
......
...@@ -13,8 +13,8 @@ void ...@@ -13,8 +13,8 @@ void
thr(void *arg) thr(void *arg)
{ {
u64 tid = (u64)arg; u64 tid = (u64)arg;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 10000; i++) {
volatile char *p = (char*) (0x40000UL + tid * 8 * 4096); volatile char *p = (char*) (0x40000UL + tid * 8 * 4096);
if (map((void *) p, 8 * 4096) < 0) { if (map((void *) p, 8 * 4096) < 0) {
printf(1, "%d: map failed\n", tid); printf(1, "%d: map failed\n", tid);
...@@ -57,7 +57,7 @@ main(int ac, char **av) ...@@ -57,7 +57,7 @@ main(int ac, char **av)
sbrk(8192); sbrk(8192);
void *tstack = sbrk(0); void *tstack = sbrk(0);
// printf(1, "tstack %lx\n", tstack); // printf(1, "tstack %lx\n", tstack);
int tid = forkt(tstack, thr, (void *)(u64)i); int tid = forkt(tstack, (void*) thr, (void *)(u64)i);
if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid); if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid);
} }
...@@ -68,7 +68,7 @@ main(int ac, char **av) ...@@ -68,7 +68,7 @@ main(int ac, char **av)
if(lastc==nthread) if(lastc==nthread)
break; break;
while(tcount==lastc) while(tcount==lastc)
__asm __volatile(""); __asm __volatile("":::"memory");
acquire(&l); acquire(&l);
} }
release(&l); release(&l);
......
...@@ -55,7 +55,7 @@ main(void) ...@@ -55,7 +55,7 @@ main(void)
} }
sbrk(4096); sbrk(4096);
forkt(sbrk(0), thr, 0); forkt(sbrk(0), (void*) thr, 0);
acquire(&l); acquire(&l);
state = 1; state = 1;
......
// Fake IDE disk; stores blocks in memory. // Fake IDE disk; stores blocks in memory.
// Useful for running kernel without scratch disk. // Useful for running kernel without scratch disk.
extern "C" {
#include "types.h" #include "types.h"
#include "mmu.h" #include "mmu.h"
#include "kernel.h" #include "kernel.h"
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
#include "amd64.h" #include "amd64.h"
#include "traps.h" #include "traps.h"
#include "buf.h" #include "buf.h"
}
extern u8 _fs_img_start[]; extern u8 _fs_img_start[];
extern u64 _fs_img_size; extern u64 _fs_img_size;
......
...@@ -39,17 +39,17 @@ struct segdesc { ...@@ -39,17 +39,17 @@ struct segdesc {
// SEGDESC constructs a segment descriptor literal // SEGDESC constructs a segment descriptor literal
// with the given, base, limit, and type bits. // with the given, base, limit, and type bits.
#define SEGDESC(base, limit, bits) { \ #define SEGDESC(base, limit, bits) { \
(limit)&0xffff, (base)&0xffff, \ (limit)&0xffff, (u16) ((base)&0xffff), \
((base)>>16)&0xff, \ (u8) (((base)>>16)&0xff), \
(bits)&0xff, \ (bits)&0xff, \
(((bits)>>4)&0xf0) | ((limit>>16)&0xf), \ (((bits)>>4)&0xf0) | ((limit>>16)&0xf), \
((base)>>24)&0xff, \ (u8) (((base)>>24)&0xff), \
} }
// SEGDESCHI constructs an extension segment descriptor // SEGDESCHI constructs an extension segment descriptor
// literal that records the high bits of base. // literal that records the high bits of base.
#define SEGDESCHI(base) { \ #define SEGDESCHI(base) { \
((base)>>32)&0xffff, ((base)>>48)&0xffff, \ (u16) (((base)>>32)&0xffff), (u16) (((base)>>48)&0xffff), \
} }
// Segment selectors (indexes) in our GDTs. // Segment selectors (indexes) in our GDTs.
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
// Search memory for MP description structures. // Search memory for MP description structures.
// http://developer.intel.com/design/pentium/datashts/24201606.pdf // http://developer.intel.com/design/pentium/datashts/24201606.pdf
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "mp.h" #include "mp.h"
#include "kernel.h" #include "kernel.h"
#include "cpu.h" #include "cpu.h"
}
struct cpu cpus[NCPU]; struct cpu cpus[NCPU];
static struct cpu *bcpu __mpalign__; static struct cpu *bcpu __mpalign__;
...@@ -37,7 +39,7 @@ mpsearch1(u8 *addr, int len) ...@@ -37,7 +39,7 @@ mpsearch1(u8 *addr, int len)
{ {
u8 *e, *p; u8 *e, *p;
addr = p2v((uptr) addr); addr = (u8*) p2v((uptr) addr);
e = addr+len; e = addr+len;
for(p = addr; p < e; p += sizeof(struct mp)) for(p = addr; p < e; p += sizeof(struct mp))
if(memcmp(p, "_MP_", 4) == 0 && sum(p, sizeof(struct mp)) == 0) if(memcmp(p, "_MP_", 4) == 0 && sum(p, sizeof(struct mp)) == 0)
......
#ifdef LWIP #ifdef LWIP
extern "C" {
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes" #pragma GCC diagnostic ignored "-Wattributes"
#include "lwip/tcp_impl.h" #include "lwip/tcp_impl.h"
...@@ -9,8 +10,10 @@ ...@@ -9,8 +10,10 @@
#include "lwip/sockets.h" #include "lwip/sockets.h"
#include "netif/etharp.h" #include "netif/etharp.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
}
#endif #endif
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "queue.h" #include "queue.h"
...@@ -21,6 +24,11 @@ ...@@ -21,6 +24,11 @@
#include "proc.h" #include "proc.h"
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "net.h"
err_t if_init(struct netif *netif);
void if_input(struct netif *netif, void *buf, u16 len);
}
void void
netfree(void *va) netfree(void *va)
...@@ -66,8 +74,6 @@ int errno; ...@@ -66,8 +74,6 @@ int errno;
void void
netrx(void *va, u16 len) netrx(void *va, u16 len)
{ {
extern void if_input(struct netif *netif, void *buf, u16 len);
lwip_core_lock(); lwip_core_lock();
if_input(&nif, va, len); if_input(&nif, va, len);
lwip_core_unlock(); lwip_core_unlock();
...@@ -114,8 +120,6 @@ static void ...@@ -114,8 +120,6 @@ static void
lwip_init(struct netif *nif, void *if_state, lwip_init(struct netif *nif, void *if_state,
u32 init_addr, u32 init_mask, u32 init_gw) u32 init_addr, u32 init_mask, u32 init_gw)
{ {
extern err_t if_init(struct netif *netif);
struct ip_addr ipaddr, netmask, gateway; struct ip_addr ipaddr, netmask, gateway;
ipaddr.addr = init_addr; ipaddr.addr = init_addr;
netmask.addr = init_mask; netmask.addr = init_mask;
...@@ -134,7 +138,7 @@ lwip_init(struct netif *nif, void *if_state, ...@@ -134,7 +138,7 @@ lwip_init(struct netif *nif, void *if_state,
static void static void
tcpip_init_done(void *arg) tcpip_init_done(void *arg)
{ {
volatile long *tcpip_done = arg; volatile long *tcpip_done = (volatile long*) arg;
*tcpip_done = 1; *tcpip_done = 1;
} }
...@@ -289,7 +293,7 @@ netbind(int sock, void *xaddr, int xaddrlen) ...@@ -289,7 +293,7 @@ netbind(int sock, void *xaddr, int xaddrlen)
return -1; return -1;
lwip_core_lock(); lwip_core_lock();
r = lwip_bind(sock, addr, xaddrlen); r = lwip_bind(sock, (const sockaddr*) addr, xaddrlen);
lwip_core_unlock(); lwip_core_unlock();
kmfree(addr); kmfree(addr);
return r; return r;
...@@ -309,7 +313,7 @@ netlisten(int sock, int backlog) ...@@ -309,7 +313,7 @@ netlisten(int sock, int backlog)
long long
netaccept(int sock, void *xaddr, void *xaddrlen) netaccept(int sock, void *xaddr, void *xaddrlen)
{ {
socklen_t *lenptr = xaddrlen; socklen_t *lenptr = (socklen_t*) xaddrlen;
socklen_t len; socklen_t len;
void *addr; void *addr;
int ss; int ss;
...@@ -322,7 +326,7 @@ netaccept(int sock, void *xaddr, void *xaddrlen) ...@@ -322,7 +326,7 @@ netaccept(int sock, void *xaddr, void *xaddrlen)
return -1; return -1;
lwip_core_lock(); lwip_core_lock();
ss = lwip_accept(sock, addr, &len); ss = lwip_accept(sock, (sockaddr*) addr, &len);
lwip_core_unlock(); lwip_core_unlock();
if (ss < 0) { if (ss < 0) {
kmfree(addr); kmfree(addr);
......
#pragma once
void netclose(int sock);
int netread(int, char *, int);
int netwrite(int, char *, int);
long netsocket(int, int, int);
long netbind(int, void *, int);
long netlisten(int, int);
long netaccept(int, void *, void *);
...@@ -13,12 +13,13 @@ UPROGS += \ ...@@ -13,12 +13,13 @@ UPROGS += \
$(O)/_telnetd \ $(O)/_telnetd \
$(O)/_httpd $(O)/_httpd
CFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP CFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
CXXFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
LWIP_CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb \ LWIP_CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb \
-m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -I$(QEMUSRC) \ -m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -I$(QEMUSRC) \
-fno-omit-frame-pointer -DHW_$(HW) -include param.h -include compiler.h \ -fno-omit-frame-pointer -DHW_$(HW) -include param.h -include compiler.h \
-Wno-attributes -Wno-address -Wno-char-subscripts \ -DXV6 -Wno-attributes -Wno-address -Wno-char-subscripts \
-Wno-unused-but-set-variable -Wno-format -Wno-unused-but-set-variable -Wno-format
LWIP_CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) LWIP_CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
......
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "spinlock.h" #include "spinlock.h"
#include "fs.h" #include "fs.h"
#include <stddef.h> #include <stddef.h>
}
// name spaces // name spaces
// XXX maybe use open hash table, no chain, better cache locality // XXX maybe use open hash table, no chain, better cache locality
...@@ -54,7 +56,7 @@ nsalloc(int allowdup) ...@@ -54,7 +56,7 @@ nsalloc(int allowdup)
{ {
struct ns *ns = 0; struct ns *ns = 0;
ns = kmalloc(sizeof(struct ns)); ns = (struct ns*) kmalloc(sizeof(struct ns));
if (ns == 0) if (ns == 0)
panic("nsalloc"); panic("nsalloc");
memset(ns, 0, sizeof(struct ns)); memset(ns, 0, sizeof(struct ns));
...@@ -102,7 +104,7 @@ elemalloc(struct nskey *k) ...@@ -102,7 +104,7 @@ elemalloc(struct nskey *k)
panic("key type"); panic("key type");
} }
e = kmalloc(sz); e = (elem*) kmalloc(sz);
if (e == 0) if (e == 0)
return 0; return 0;
memset(e, 0, sz); memset(e, 0, sz);
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "kernel.h" #include "kernel.h"
#include "pci.h" #include "pci.h"
#include "pcireg.h" #include "pcireg.h"
}
extern int e1000attach(struct pci_func *pcif); extern int e1000attach(struct pci_func *pcif);
extern int e1000eattach(struct pci_func *pcif); extern int e1000eattach(struct pci_func *pcif);
...@@ -45,26 +47,26 @@ struct pci_driver pci_attach_vendor[] = { ...@@ -45,26 +47,26 @@ struct pci_driver pci_attach_vendor[] = {
static const char *pci_class[] = static const char *pci_class[] =
{ {
[0x0] = "Unknown", "Unknown",
[0x1] = "Storage controller", "Storage controller",
[0x2] = "Network controller", "Network controller",
[0x3] = "Display controller", "Display controller",
[0x4] = "Multimedia device", "Multimedia device",
[0x5] = "Memory controller", "Memory controller",
[0x6] = "Bridge device", "Bridge device",
}; };
static void static void
pci_print_func(struct pci_func *f) pci_print_func(struct pci_func *f)
{ {
const char *class = pci_class[0]; const char *classname = pci_class[0];
if (PCI_CLASS(f->dev_class) < sizeof(pci_class) / sizeof(pci_class[0])) if (PCI_CLASS(f->dev_class) < sizeof(pci_class) / sizeof(pci_class[0]))
class = pci_class[PCI_CLASS(f->dev_class)]; classname = pci_class[PCI_CLASS(f->dev_class)];
cprintf("PCI: %x:%x.%d: %x:%x: class: %x.%x (%s) irq: %d\n", cprintf("PCI: %x:%x.%d: %x:%x: class: %x.%x (%s) irq: %d\n",
f->bus->busno, f->dev, f->func, f->bus->busno, f->dev, f->func,
PCI_VENDOR(f->dev_id), PCI_PRODUCT(f->dev_id), PCI_VENDOR(f->dev_id), PCI_PRODUCT(f->dev_id),
PCI_CLASS(f->dev_class), PCI_SUBCLASS(f->dev_class), class, PCI_CLASS(f->dev_class), PCI_SUBCLASS(f->dev_class), classname,
f->irq_line); f->irq_line);
} }
......
// Intel 8259A programmable interrupt controllers. // Intel 8259A programmable interrupt controllers.
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "traps.h" #include "traps.h"
#include "kernel.h"
}
// I/O Addresses of the two programmable interrupt controllers // I/O Addresses of the two programmable interrupt controllers
#define IO_PIC1 0x20 // Master (IRQs 0-7) #define IO_PIC1 0x20 // Master (IRQs 0-7)
......
extern "C" {
#include "types.h" #include "types.h"
#include "mmu.h" #include "mmu.h"
#include "kernel.h" #include "kernel.h"
...@@ -8,6 +9,7 @@ ...@@ -8,6 +9,7 @@
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "cpu.h" #include "cpu.h"
}
#define PIPESIZE 512 #define PIPESIZE 512
...@@ -38,11 +40,11 @@ pipealloc(struct file **f0, struct file **f1) ...@@ -38,11 +40,11 @@ pipealloc(struct file **f0, struct file **f1)
p->nread = 0; p->nread = 0;
initlock(&p->lock, "pipe", LOCKSTAT_PIPE); initlock(&p->lock, "pipe", LOCKSTAT_PIPE);
initcondvar(&p->cv, "pipe"); initcondvar(&p->cv, "pipe");
(*f0)->type = FD_PIPE; (*f0)->type = file::FD_PIPE;
(*f0)->readable = 1; (*f0)->readable = 1;
(*f0)->writable = 0; (*f0)->writable = 0;
(*f0)->pipe = p; (*f0)->pipe = p;
(*f1)->type = FD_PIPE; (*f1)->type = file::FD_PIPE;
(*f1)->readable = 0; (*f1)->readable = 0;
(*f1)->writable = 1; (*f1)->writable = 1;
(*f1)->pipe = p; (*f1)->pipe = p;
......
...@@ -37,7 +37,7 @@ void ...@@ -37,7 +37,7 @@ void
vprintfmt(void (*putch) (void*, char), void *putarg, vprintfmt(void (*putch) (void*, char), void *putarg,
const char *fmt, va_list ap) const char *fmt, va_list ap)
{ {
char *s; const char *s;
int c, i, state; int c, i, state;
state = 0; state = 0;
...@@ -58,7 +58,7 @@ vprintfmt(void (*putch) (void*, char), void *putarg, ...@@ -58,7 +58,7 @@ vprintfmt(void (*putch) (void*, char), void *putarg,
state = 'l'; state = 'l';
continue; continue;
} else if(c == 's'){ } else if(c == 's'){
s = (char*) va_arg(ap, char*); s = (const char*) va_arg(ap, const char*);
if(s == 0) if(s == 0)
s = "(null)"; s = "(null)";
while(*s != 0){ while(*s != 0){
...@@ -101,7 +101,7 @@ writec(void *arg, char c) ...@@ -101,7 +101,7 @@ writec(void *arg, char c)
} }
void void
printf(int fd, char *fmt, ...) printf(int fd, const char *fmt, ...)
{ {
va_list ap; va_list ap;
...@@ -119,7 +119,7 @@ struct bufstate { ...@@ -119,7 +119,7 @@ struct bufstate {
static void static void
writebuf(void *arg, char c) writebuf(void *arg, char c)
{ {
struct bufstate *bs = arg; struct bufstate *bs = (bufstate*) arg;
if (bs->p < bs->e) { if (bs->p < bs->e) {
bs->p[0] = c; bs->p[0] = c;
bs->p++; bs->p++;
...@@ -127,7 +127,7 @@ writebuf(void *arg, char c) ...@@ -127,7 +127,7 @@ writebuf(void *arg, char c)
} }
void void
vsnprintf(char *buf, u32 n, char *fmt, va_list ap) vsnprintf(char *buf, u32 n, const char *fmt, va_list ap)
{ {
struct bufstate bs = { buf, buf+n-1 }; struct bufstate bs = { buf, buf+n-1 };
vprintfmt(writebuf, (void*) &bs, fmt, ap); vprintfmt(writebuf, (void*) &bs, fmt, ap);
...@@ -135,7 +135,7 @@ vsnprintf(char *buf, u32 n, char *fmt, va_list ap) ...@@ -135,7 +135,7 @@ vsnprintf(char *buf, u32 n, char *fmt, va_list ap)
} }
void void
snprintf(char *buf, u32 n, char *fmt, ...) snprintf(char *buf, u32 n, const char *fmt, ...)
{ {
va_list ap; va_list ap;
......
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "mmu.h" #include "mmu.h"
...@@ -11,8 +12,7 @@ ...@@ -11,8 +12,7 @@
#include "kmtrace.h" #include "kmtrace.h"
#include "vm.h" #include "vm.h"
#include "sched.h" #include "sched.h"
}
extern void threadstub(void);
int __mpalign__ idle[NCPU]; int __mpalign__ idle[NCPU];
struct ns *nspid __mpalign__; struct ns *nspid __mpalign__;
...@@ -139,7 +139,7 @@ exit(void) ...@@ -139,7 +139,7 @@ exit(void)
// Kernel threads might not have a cwd // Kernel threads might not have a cwd
if (myproc()->cwd != NULL) { if (myproc()->cwd != NULL) {
iput(myproc()->cwd); iput(myproc()->cwd);
myproc()->cwd = NULL; myproc()->cwd = 0;
} }
// Pass abandoned children to init. // Pass abandoned children to init.
...@@ -185,11 +185,10 @@ freeproc(struct proc *p) ...@@ -185,11 +185,10 @@ freeproc(struct proc *p)
static struct proc* static struct proc*
allocproc(void) allocproc(void)
{ {
extern void trapret(void);
struct proc *p; struct proc *p;
char *sp; char *sp;
p = kmalloc(sizeof(struct proc)); p = (proc*) kmalloc(sizeof(struct proc));
if (p == 0) return 0; if (p == 0) return 0;
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
...@@ -212,7 +211,7 @@ allocproc(void) ...@@ -212,7 +211,7 @@ allocproc(void)
panic("allocproc: ns_insert"); panic("allocproc: ns_insert");
// Allocate kernel stack if possible. // Allocate kernel stack if possible.
if((p->kstack = ksalloc(slab_stack)) == NULL){ if((p->kstack = (char*) ksalloc(slab_stack)) == 0){
if (ns_remove(nspid, KI(p->pid), p) == 0) if (ns_remove(nspid, KI(p->pid), p) == 0)
panic("allocproc: ns_remove"); panic("allocproc: ns_remove");
freeproc(p); freeproc(p);
...@@ -272,7 +271,7 @@ inituser(void) ...@@ -272,7 +271,7 @@ inituser(void)
p->tf->rip = 0x0; // beginning of initcode.S p->tf->rip = 0x0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name)); safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = NULL; // forkret will fix in the process's context p->cwd = 0; // forkret will fix in the process's context
acquire(&p->lock); acquire(&p->lock);
addrun(p); addrun(p);
release(&p->lock); release(&p->lock);
...@@ -496,13 +495,13 @@ kill(int pid) ...@@ -496,13 +495,13 @@ kill(int pid)
void *procdump(void *vk, void *v, void *arg) void *procdump(void *vk, void *v, void *arg)
{ {
static char *states[] = { static const char *states[] = {
[UNUSED] = "unused", /* [UNUSED] = */ "unused",
[EMBRYO] = "embryo", /* [EMBRYO] = */ "embryo",
[SLEEPING] = "sleep ", /* [SLEEPING] = */ "sleep ",
[RUNNABLE] = "runble", /* [RUNNABLE] = */ "runble",
[RUNNING] = "run ", /* [RUNNING] = */ "run ",
[ZOMBIE] = "zombie" /* [ZOMBIE] = */ "zombie"
}; };
struct proc *p = (struct proc *) v; struct proc *p = (struct proc *) v;
const char *name = "(no name)"; const char *name = "(no name)";
...@@ -556,7 +555,7 @@ fork(int flags) ...@@ -556,7 +555,7 @@ fork(int flags)
// Copy process state from p. // Copy process state from p.
if((np->vmap = vmap_copy(myproc()->vmap, cow)) == 0){ if((np->vmap = vmap_copy(myproc()->vmap, cow)) == 0){
ksfree(slab_stack, np->kstack); ksfree(slab_stack, np->kstack);
np->kstack = NULL; np->kstack = 0;
np->state = UNUSED; np->state = UNUSED;
if (ns_remove(nspid, KI(np->pid), np) == 0) if (ns_remove(nspid, KI(np->pid), np) == 0)
panic("fork: ns_remove"); panic("fork: ns_remove");
...@@ -617,7 +616,7 @@ wait(void) ...@@ -617,7 +616,7 @@ wait(void)
SLIST_REMOVE(&myproc()->childq, p, proc, child_next); SLIST_REMOVE(&myproc()->childq, p, proc, child_next);
release(&myproc()->lock); release(&myproc()->lock);
ksfree(slab_stack, p->kstack); ksfree(slab_stack, p->kstack);
p->kstack = NULL; p->kstack = 0;
vmap_decref(p->vmap); vmap_decref(p->vmap);
p->state = UNUSED; p->state = UNUSED;
if (ns_remove(nspid, KI(p->pid), p) == 0) if (ns_remove(nspid, KI(p->pid), p) == 0)
...@@ -661,18 +660,18 @@ threadalloc(void (*fn)(void *), void *arg) ...@@ -661,18 +660,18 @@ threadalloc(void (*fn)(void *), void *arg)
p = allocproc(); p = allocproc();
if (p == NULL) if (p == NULL)
return NULL; return 0;
p->vmap = vmap_alloc(); p->vmap = vmap_alloc();
if (p->vmap == NULL) { if (p->vmap == NULL) {
freeproc(p); freeproc(p);
return NULL; return 0;
} }
p->context->rip = (u64)threadstub; p->context->rip = (u64)threadstub;
p->context->r12 = (u64)fn; p->context->r12 = (u64)fn;
p->context->r13 = (u64)arg; p->context->r13 = (u64)arg;
p->parent = myproc(); p->parent = myproc();
p->cwd = NULL; p->cwd = 0;
return p; return p;
} }
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "spinlock.h" #include "spinlock.h"
...@@ -7,6 +8,7 @@ ...@@ -7,6 +8,7 @@
#include "prof.h" #include "prof.h"
#include "bits.h" #include "bits.h"
#include "amd64.h" #include "amd64.h"
}
extern profctr_t sprof[]; extern profctr_t sprof[];
extern profctr_t eprof[]; extern profctr_t eprof[];
......
...@@ -10,6 +10,7 @@ typedef struct profctr { ...@@ -10,6 +10,7 @@ typedef struct profctr {
__padout__; __padout__;
} profctr_t; } profctr_t;
#if 0 /* not for c++ */
#define DEFINE_PROFCTR(xname) \ #define DEFINE_PROFCTR(xname) \
profctr_t xname __attribute__((section(".prof"))) = { .name = #xname }; profctr_t xname __attribute__((section(".prof"))) = { .name = #xname };
...@@ -24,3 +25,8 @@ typedef struct profctr { ...@@ -24,3 +25,8 @@ typedef struct profctr {
name.rec[__profid].cnt++; \ name.rec[__profid].cnt++; \
} \ } \
} while (0) } while (0)
#else
#define DEFINE_PROFCTR(x)
#define prof_start(x)
#define prof_end(x)
#endif
...@@ -209,7 +209,7 @@ struct { \ ...@@ -209,7 +209,7 @@ struct { \
(varp) = &SLIST_NEXT((var), field)) (varp) = &SLIST_NEXT((var), field))
#define SLIST_INIT(head) do { \ #define SLIST_INIT(head) do { \
SLIST_FIRST((head)) = NULL; \ SLIST_FIRST((head)) = 0; \
} while (0) } while (0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
...@@ -403,7 +403,7 @@ struct { \ ...@@ -403,7 +403,7 @@ struct { \
(var) = (tvar)) (var) = (tvar))
#define LIST_INIT(head) do { \ #define LIST_INIT(head) do { \
LIST_FIRST((head)) = NULL; \ LIST_FIRST((head)) = 0; \
} while (0) } while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \ #define LIST_INSERT_AFTER(listelm, elm, field) do { \
......
extern "C" {
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
......
extern "C" {
#include "param.h" #include "param.h"
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "cpu.h" #include "cpu.h"
}
struct seed { struct seed {
u64 v; u64 v;
......
extern "C" {
#include "types.h" #include "types.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.h" #include "condvar.h"
...@@ -8,6 +9,7 @@ ...@@ -8,6 +9,7 @@
#include "amd64.h" #include "amd64.h"
#include "cpu.h" #include "cpu.h"
#include "sampler.h" #include "sampler.h"
}
static const u64 debug_sel = static const u64 debug_sel =
0UL << 32 | 0UL << 32 |
...@@ -47,10 +49,7 @@ amdconfig(u64 ctr, u64 sel, u64 val) ...@@ -47,10 +49,7 @@ amdconfig(u64 ctr, u64 sel, u64 val)
writemsr(MSR_AMD_PERF_SEL0 | ctr, sel); writemsr(MSR_AMD_PERF_SEL0 | ctr, sel);
} }
struct pmu amdpmu = { struct pmu amdpmu = { amdconfig, 48 };
.config = amdconfig,
.cntval_bits = 48,
};
// //
// Intel stuff // Intel stuff
...@@ -64,10 +63,7 @@ intelconfig(u64 ctr, u64 sel, u64 val) ...@@ -64,10 +63,7 @@ intelconfig(u64 ctr, u64 sel, u64 val)
} }
// XXX // XXX
struct pmu intelpmu = { struct pmu intelpmu = { intelconfig, 48 };
.config = intelconfig,
.cntval_bits = 48,
};
void void
sampdump(void) sampdump(void)
...@@ -177,7 +173,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n) ...@@ -177,7 +173,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
u64 len = hdrlen; u64 len = hdrlen;
u64 cc; u64 cc;
hdr = kmalloc(len); hdr = (logheader*) kmalloc(len);
if (hdr == NULL) if (hdr == NULL)
return -1; return -1;
hdr->ncpus = NCPU; hdr->ncpus = NCPU;
...@@ -189,7 +185,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n) ...@@ -189,7 +185,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
} }
cc = MIN(hdrlen-off, n); cc = MIN(hdrlen-off, n);
memmove(dst, (void*)hdr + off, cc); memmove(dst, (char*)hdr + off, cc);
kmfree(hdr); kmfree(hdr);
n -= cc; n -= cc;
...@@ -229,9 +225,9 @@ initsamp(void) ...@@ -229,9 +225,9 @@ initsamp(void)
void *p = ksalloc(slab_perf); void *p = ksalloc(slab_perf);
if (p == NULL) if (p == NULL)
panic("initprof: ksalloc"); panic("initprof: ksalloc");
pmulog[cpunum()].event = p; pmulog[cpunum()].event = (pmuevent*) p;
pmulog[cpunum()].capacity = PERFSIZE / sizeof(struct pmuevent); pmulog[cpunum()].capacity = PERFSIZE / sizeof(struct pmuevent);
devsw[SAMPLER].write = NULL; devsw[SAMPLER].write = 0;
devsw[SAMPLER].read = sampread; devsw[SAMPLER].read = sampread;
} }
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "mmu.h" #include "mmu.h"
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
#include "vm.h" #include "vm.h"
#include "sched.h" #include "sched.h"
#include <stddef.h> #include <stddef.h>
}
enum { sched_debug = 0 }; enum { sched_debug = 0 };
......
...@@ -19,7 +19,7 @@ struct cmd { ...@@ -19,7 +19,7 @@ struct cmd {
struct execcmd { struct execcmd {
int type; int type;
char *argv[MAXARGS]; const char *argv[MAXARGS];
char *eargv[MAXARGS]; char *eargv[MAXARGS];
}; };
...@@ -50,7 +50,7 @@ struct backcmd { ...@@ -50,7 +50,7 @@ struct backcmd {
}; };
int fork1(void); // Fork but panics on failure. int fork1(void); // Fork but panics on failure.
void panic(char*); void panic(const char*);
struct cmd *parsecmd(char*); struct cmd *parsecmd(char*);
// Execute cmd. Never returns. // Execute cmd. Never returns.
...@@ -173,7 +173,7 @@ main(void) ...@@ -173,7 +173,7 @@ main(void)
} }
void void
panic(char *s) panic(const char *s)
{ {
printf(2, "%s\n", s); printf(2, "%s\n", s);
exit(); exit();
...@@ -198,7 +198,7 @@ execcmd(void) ...@@ -198,7 +198,7 @@ execcmd(void)
{ {
struct execcmd *cmd; struct execcmd *cmd;
cmd = malloc(sizeof(*cmd)); cmd = (struct execcmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd));
cmd->type = EXEC; cmd->type = EXEC;
return (struct cmd*)cmd; return (struct cmd*)cmd;
...@@ -209,7 +209,7 @@ redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd) ...@@ -209,7 +209,7 @@ redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd)
{ {
struct redircmd *cmd; struct redircmd *cmd;
cmd = malloc(sizeof(*cmd)); cmd = (struct redircmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd));
cmd->type = REDIR; cmd->type = REDIR;
cmd->cmd = subcmd; cmd->cmd = subcmd;
...@@ -225,7 +225,7 @@ pipecmd(struct cmd *left, struct cmd *right) ...@@ -225,7 +225,7 @@ pipecmd(struct cmd *left, struct cmd *right)
{ {
struct pipecmd *cmd; struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd)); cmd = (struct pipecmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd));
cmd->type = PIPE; cmd->type = PIPE;
cmd->left = left; cmd->left = left;
...@@ -238,7 +238,7 @@ listcmd(struct cmd *left, struct cmd *right) ...@@ -238,7 +238,7 @@ listcmd(struct cmd *left, struct cmd *right)
{ {
struct listcmd *cmd; struct listcmd *cmd;
cmd = malloc(sizeof(*cmd)); cmd = (struct listcmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd));
cmd->type = LIST; cmd->type = LIST;
cmd->left = left; cmd->left = left;
...@@ -251,7 +251,7 @@ backcmd(struct cmd *subcmd) ...@@ -251,7 +251,7 @@ backcmd(struct cmd *subcmd)
{ {
struct backcmd *cmd; struct backcmd *cmd;
cmd = malloc(sizeof(*cmd)); cmd = (struct backcmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd));
cmd->type = BACK; cmd->type = BACK;
cmd->cmd = subcmd; cmd->cmd = subcmd;
...@@ -309,7 +309,7 @@ gettoken(char **ps, char *es, char **q, char **eq) ...@@ -309,7 +309,7 @@ gettoken(char **ps, char *es, char **q, char **eq)
} }
int int
peek(char **ps, char *es, char *toks) peek(char **ps, char *es, const char *toks)
{ {
char *s; char *s;
......
// Mutual exclusion spin locks. // Mutual exclusion spin locks.
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "amd64.h" #include "amd64.h"
...@@ -10,6 +11,7 @@ ...@@ -10,6 +11,7 @@
#include "condvar.h" #include "condvar.h"
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
}
#if LOCKSTAT #if LOCKSTAT
static int lockstat_enable; static int lockstat_enable;
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "kernel.h"
}
void* void*
memset(void *dst, int c, u32 n) memset(void *dst, int c, u32 n)
...@@ -13,8 +16,8 @@ memcmp(const void *v1, const void *v2, u32 n) ...@@ -13,8 +16,8 @@ memcmp(const void *v1, const void *v2, u32 n)
{ {
const u8 *s1, *s2; const u8 *s1, *s2;
s1 = v1; s1 = (const u8*) v1;
s2 = v2; s2 = (const u8*) v2;
while(n-- > 0){ while(n-- > 0){
if(*s1 != *s2) if(*s1 != *s2)
return *s1 - *s2; return *s1 - *s2;
...@@ -30,8 +33,8 @@ memmove(void *dst, const void *src, u32 n) ...@@ -30,8 +33,8 @@ memmove(void *dst, const void *src, u32 n)
const char *s; const char *s;
char *d; char *d;
s = src; s = (const char*) src;
d = dst; d = (char*) dst;
if(s < d && s + n > d){ if(s < d && s + n > d){
s += n; s += n;
d += n; d += n;
......
...@@ -146,37 +146,6 @@ kmemcpy(void *umem, void *src, u64 size) ...@@ -146,37 +146,6 @@ kmemcpy(void *umem, void *src, u64 size)
return 0; return 0;
} }
extern long sys_chdir(void);
extern long sys_close(void);
extern long sys_dup(void);
extern long sys_exec(void);
extern long sys_exit(void);
extern long sys_fork(void);
extern long sys_fstat(void);
extern long sys_getpid(void);
extern long sys_kill(void);
extern long sys_link(void);
extern long sys_mkdir(void);
extern long sys_mknod(void);
extern long sys_open(void);
extern long sys_pipe(void);
extern long sys_read(void);
extern long sys_sbrk(void);
extern long sys_sleep(void);
extern long sys_unlink(void);
extern long sys_wait(void);
extern long sys_write(void);
extern long sys_uptime(void);
extern long sys_map(void);
extern long sys_unmap(void);
extern long sys_halt(void);
extern long sys_socket(int, int, int);
extern long sys_bind(int, void*, int);
extern long sys_listen(int, int);
extern long sys_accept(int, void*, void*);
extern long sys_pread(int fd, void *ubuf, size_t count, off_t offset);
extern long sys_kernlet(int, size_t, off_t);
#define SYSCALL(name) [SYS_##name] = (void*)sys_##name #define SYSCALL(name) [SYS_##name] = (void*)sys_##name
static long (*syscalls[])(u64, u64, u64, u64, u64, u64) = { static long (*syscalls[])(u64, u64, u64, u64, u64, u64) = {
......
extern "C" {
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "mmu.h" #include "mmu.h"
...@@ -10,6 +11,8 @@ ...@@ -10,6 +11,8 @@
#include "file.h" #include "file.h"
#include "fcntl.h" #include "fcntl.h"
#include "cpu.h" #include "cpu.h"
#include "net.h"
}
// Fetch the nth word-sized system call argument as a file descriptor // Fetch the nth word-sized system call argument as a file descriptor
// and return both the descriptor and the corresponding struct file. // and return both the descriptor and the corresponding struct file.
...@@ -82,11 +85,11 @@ sys_pread(int fd, void *ubuf, size_t count, off_t offset) ...@@ -82,11 +85,11 @@ sys_pread(int fd, void *ubuf, size_t count, off_t offset)
return -1; return -1;
// XXX(sbw) assuming ubuf is ok // XXX(sbw) assuming ubuf is ok
if(f->type == FD_INODE){ if(f->type == file::FD_INODE){
ilock(f->ip, 0); ilock(f->ip, 0);
if(f->ip->type == 0) if(f->ip->type == 0)
panic("fileread"); panic("fileread");
r = readi(f->ip, ubuf, offset, count); r = readi(f->ip, (char*)ubuf, offset, count);
iunlock(f->ip); iunlock(f->ip);
return r; return r;
} }
...@@ -124,7 +127,7 @@ sys_fstat(void) ...@@ -124,7 +127,7 @@ sys_fstat(void)
struct file *f; struct file *f;
struct stat *st; struct stat *st;
if(argfd(0, 0, &f) < 0 || argptr(1, (void*)&st, sizeof(*st)) < 0) if(argfd(0, 0, &f) < 0 || argptr(1, (char**)&st, sizeof(*st)) < 0)
return -1; return -1;
return filestat(f, st); return filestat(f, st);
} }
...@@ -133,10 +136,10 @@ sys_fstat(void) ...@@ -133,10 +136,10 @@ sys_fstat(void)
long long
sys_link(void) sys_link(void)
{ {
char name[DIRSIZ], *new, *old; char name[DIRSIZ], *newn, *old;
struct inode *dp, *ip; struct inode *dp, *ip;
if(argstr(0, &old) < 0 || argstr(1, &new) < 0) if(argstr(0, &old) < 0 || argstr(1, &newn) < 0)
return -1; return -1;
if((ip = namei(old)) == 0) if((ip = namei(old)) == 0)
return -1; return -1;
...@@ -149,7 +152,7 @@ sys_link(void) ...@@ -149,7 +152,7 @@ sys_link(void)
iupdate(ip); iupdate(ip);
iunlock(ip); iunlock(ip);
if((dp = nameiparent(new, name)) == 0) if((dp = nameiparent(newn, name)) == 0)
goto bad; goto bad;
if(dp->dev != ip->dev || dirlink(dp, name, ip->inum) < 0) if(dp->dev != ip->dev || dirlink(dp, name, ip->inum) < 0)
goto bad; goto bad;
...@@ -170,7 +173,7 @@ bad: ...@@ -170,7 +173,7 @@ bad:
static void* static void*
check_empty(void *k, void *v, void *arg) check_empty(void *k, void *v, void *arg)
{ {
char *name = k; char *name = (char*) k;
if (strcmp(name, ".") && strcmp(name, "..")) if (strcmp(name, ".") && strcmp(name, ".."))
return (void*)1; return (void*)1;
return 0; return 0;
...@@ -331,7 +334,7 @@ sys_open(void) ...@@ -331,7 +334,7 @@ sys_open(void)
} }
iunlock(ip); iunlock(ip);
f->type = FD_INODE; f->type = file::FD_INODE;
f->ip = ip; f->ip = ip;
f->off = 0; f->off = 0;
f->readable = !(omode & O_WRONLY); f->readable = !(omode & O_WRONLY);
...@@ -421,7 +424,7 @@ sys_pipe(void) ...@@ -421,7 +424,7 @@ sys_pipe(void)
struct file *rf, *wf; struct file *rf, *wf;
int fd0, fd1; int fd0, fd1;
if(argptr(0, (void*)&fd, 2*sizeof(fd[0])) < 0) if(argptr(0, (char**)&fd, 2*sizeof(fd[0])) < 0)
return -1; return -1;
if(pipealloc(&rf, &wf) < 0) if(pipealloc(&rf, &wf) < 0)
return -1; return -1;
...@@ -451,7 +454,7 @@ getsocket(int fd, struct file **ret) ...@@ -451,7 +454,7 @@ getsocket(int fd, struct file **ret)
struct file *f; struct file *f;
if (fd < 0 || fd >= NOFILE || (f=myproc()->ofile[fd]) == 0) if (fd < 0 || fd >= NOFILE || (f=myproc()->ofile[fd]) == 0)
return -1; return -1;
if (f->type != FD_SOCKET) if (f->type != file::FD_SOCKET)
return -1; return -1;
*ret = f; *ret = f;
...@@ -474,7 +477,7 @@ allocsocket(struct file **rf, int *rfd) ...@@ -474,7 +477,7 @@ allocsocket(struct file **rf, int *rfd)
return fd; return fd;
} }
f->type = FD_SOCKET; f->type = file::FD_SOCKET;
f->off = 0; f->off = 0;
f->readable = 1; f->readable = 1;
f->writable = 1; f->writable = 1;
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "kernel.h" #include "kernel.h"
...@@ -8,6 +9,7 @@ ...@@ -8,6 +9,7 @@
#include "proc.h" #include "proc.h"
#include "cpu.h" #include "cpu.h"
#include "vm.h" #include "vm.h"
}
long long
sys_fork(void) sys_fork(void)
......
...@@ -46,7 +46,7 @@ main(void) ...@@ -46,7 +46,7 @@ main(void)
continue; continue;
} }
if (pid == 0) { if (pid == 0) {
static char *argv[] = { "sh", 0 }; static const char *argv[] = { "sh", 0 };
close(0); close(0);
close(1); close(1);
close(2); close(2);
......
...@@ -28,7 +28,7 @@ main(void) ...@@ -28,7 +28,7 @@ main(void)
for(int i = 0; i < nthread; i++) { for(int i = 0; i < nthread; i++) {
sbrk(8192); sbrk(8192);
void *tstack = sbrk(0); void *tstack = sbrk(0);
int tid = forkt(tstack, thr, (void*)(u64)(0xc0ffee00|i)); int tid = forkt(tstack, (void*) thr, (void*)(u64)(0xc0ffee00|i));
printf(1, "thrtest[%d]: child %d\n", getpid(), tid); printf(1, "thrtest[%d]: child %d\n", getpid(), tid);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "amd64.h" #include "amd64.h"
int int
main(int ac, char *av[]) main(int ac, const char *av[])
{ {
u64 t0 = rdtsc(); u64 t0 = rdtsc();
......
...@@ -13,7 +13,9 @@ typedef uptr paddr; ...@@ -13,7 +13,9 @@ typedef uptr paddr;
typedef u64 pme_t; typedef u64 pme_t;
typedef pme_t pml4e_t; typedef pme_t pml4e_t;
#ifdef XV6
// POSIX types // POSIX types
typedef s64 ssize_t; typedef s64 ssize_t;
typedef u64 size_t; typedef u64 size_t;
typedef u64 off_t; typedef u64 off_t;
#endif
// Intel 8250 serial port (UART). // Intel 8250 serial port (UART).
// http://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming // http://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "amd64.h" #include "amd64.h"
#include "traps.h" #include "traps.h"
}
#define COM2 0x2f8 #define COM2 0x2f8
#define COM1 0x3f8 #define COM1 0x3f8
...@@ -48,9 +51,9 @@ inituart(void) ...@@ -48,9 +51,9 @@ inituart(void)
int irq; int irq;
} conf[] = { } conf[] = {
// Try COM2 (aka ttyS1) first, because it usually does SOL for IPMI. // Try COM2 (aka ttyS1) first, because it usually does SOL for IPMI.
{ .com = COM2, .irq = IRQ_COM2 }, { COM2, IRQ_COM2 },
// Still try COM1 (aka ttyS0), because it is what QEMU emulates. // Still try COM1 (aka ttyS0), because it is what QEMU emulates.
{ .com = COM1, .irq = IRQ_COM1 } { COM1, IRQ_COM1 }
}; };
int i; int i;
...@@ -87,6 +90,6 @@ inituart(void) ...@@ -87,6 +90,6 @@ inituart(void)
ioapicenable(irq_com, 0); ioapicenable(irq_com, 0);
// Announce that we're here. // Announce that we're here.
for (char *p="uart..\n"; *p; p++) for (const char *p="uart..\n"; *p; p++)
uartputc(*p); uartputc(*p);
} }
...@@ -15,7 +15,7 @@ strncpy(char *s, const char *t, int n) ...@@ -15,7 +15,7 @@ strncpy(char *s, const char *t, int n)
} }
char* char*
strcpy(char *s, char *t) strcpy(char *s, const char *t)
{ {
char *os; char *os;
...@@ -124,8 +124,8 @@ memmove(void *vdst, const void *vsrc, int n) ...@@ -124,8 +124,8 @@ memmove(void *vdst, const void *vsrc, int n)
const char *src; const char *src;
char *dst; char *dst;
dst = vdst; dst = (char*) vdst;
src = vsrc; src = (const char*) vsrc;
while(n-- > 0) while(n-- > 0)
*dst++ = *src++; *dst++ = *src++;
return vdst; return vdst;
......
#ifdef LWIP #ifdef LWIP
extern "C" {
#include "lwip/sockets.h" #include "lwip/sockets.h"
// system calls // system calls
...@@ -7,6 +8,7 @@ extern int bind(int sockfd, const struct sockaddr *addr, ...@@ -7,6 +8,7 @@ extern int bind(int sockfd, const struct sockaddr *addr,
socklen_t addrlen); socklen_t addrlen);
extern int listen(int sockfd, int backlog); extern int listen(int sockfd, int backlog);
extern int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); extern int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
}
static inline const char * static inline const char *
ipaddr(struct sockaddr_in *sin) ipaddr(struct sockaddr_in *sin)
......
struct stat; struct stat;
// system calls // system calls
extern "C" {
int fork(int); int fork(int);
int exit(void) __attribute__((noreturn)); int exit(void) __attribute__((noreturn));
int wait(void); int wait(void);
...@@ -9,14 +10,14 @@ int write(int, const void*, int); ...@@ -9,14 +10,14 @@ int write(int, const void*, int);
int read(int, void*, int); int read(int, void*, int);
int close(int); int close(int);
int kill(int); int kill(int);
int exec(char*, char**); int exec(const char*, const char**);
int open(const char*, int); int open(const char*, int);
int mknod(char*, short, short); int mknod(const char*, short, short);
int unlink(char*); int unlink(const char*);
int fstat(int fd, struct stat*); int fstat(int fd, struct stat*);
int link(char*, char*); int link(const char*, const char*);
int mkdir(char*); int mkdir(const char*);
int chdir(char*); int chdir(const char*);
int dup(int); int dup(int);
int getpid(void); int getpid(void);
char* sbrk(int); char* sbrk(int);
...@@ -27,10 +28,11 @@ int unmap(void *addr, int len); ...@@ -27,10 +28,11 @@ int unmap(void *addr, int len);
void halt(void); void halt(void);
ssize_t pread(int, void*, size_t, off_t); ssize_t pread(int, void*, size_t, off_t);
int kernlet(int, size_t, off_t); int kernlet(int, size_t, off_t);
}
// ulib.c // ulib.c
int stat(char*, struct stat*); int stat(char*, struct stat*);
char* strcpy(char*, char*); char* strcpy(char*, const char*);
void *memmove(void*, const void*, int); void *memmove(void*, const void*, int);
char* strchr(const char*, char c); char* strchr(const char*, char c);
int strcmp(const char*, const char*); int strcmp(const char*, const char*);
...@@ -44,9 +46,11 @@ void free(void*); ...@@ -44,9 +46,11 @@ void free(void*);
int atoi(const char*); int atoi(const char*);
// uthread.S // uthread.S
extern "C" {
int forkt(void *sp, void *pc, void *arg); int forkt(void *sp, void *pc, void *arg);
}
// printf.c // printf.c
void printf(int, char*, ...); void printf(int, const char*, ...);
void snprintf(char *buf, unsigned int n, char *fmt, ...); void snprintf(char *buf, unsigned int n, const char *fmt, ...);
void die(const char* errstr, ...) __attribute__((noreturn)); void die(const char* errstr, ...) __attribute__((noreturn));
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
char buf[2048]; char buf[2048];
char name[3]; char name[3];
char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 }; const char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
int stdout = 1; int stdout = 1;
// simple file system tests // simple file system tests
...@@ -85,7 +85,7 @@ writetest(void) ...@@ -85,7 +85,7 @@ writetest(void)
void void
writetest1(void) writetest1(void)
{ {
int i, fd, n; int fd, n;
printf(stdout, "big files test\n"); printf(stdout, "big files test\n");
...@@ -95,7 +95,7 @@ writetest1(void) ...@@ -95,7 +95,7 @@ writetest1(void)
exit(); exit();
} }
for(i = 0; i < MAXFILE; i++){ for(u32 i = 0; i < MAXFILE; i++){
((int*)buf)[0] = i; ((int*)buf)[0] = i;
if(write(fd, buf, 512) != 512){ if(write(fd, buf, 512) != 512){
printf(stdout, "error: write big file failed\n", i); printf(stdout, "error: write big file failed\n", i);
...@@ -113,7 +113,7 @@ writetest1(void) ...@@ -113,7 +113,7 @@ writetest1(void)
n = 0; n = 0;
for(;;){ for(;;){
i = read(fd, buf, 512); u32 i = read(fd, buf, 512);
if(i == 0){ if(i == 0){
if(n == MAXFILE - 1){ if(n == MAXFILE - 1){
printf(stdout, "read only %d blocks from big", n); printf(stdout, "read only %d blocks from big", n);
...@@ -331,7 +331,7 @@ mem(void) ...@@ -331,7 +331,7 @@ mem(void)
if((pid = fork(0)) == 0){ if((pid = fork(0)) == 0){
m1 = 0; m1 = 0;
while((m2 = malloc(10001)) != 0){ while((m2 = malloc(10001)) != 0){
*(char**)m2 = m1; *(char**)m2 = (char*) m1;
m1 = m2; m1 = m2;
} }
while(m1){ while(m1){
...@@ -410,7 +410,7 @@ void ...@@ -410,7 +410,7 @@ void
twofiles(void) twofiles(void)
{ {
int fd, pid, i, j, n, total; int fd, pid, i, j, n, total;
char *fname; const char *fname;
printf(1, "twofiles test\n"); printf(1, "twofiles test\n");
...@@ -1450,7 +1450,7 @@ bigargtest(void) ...@@ -1450,7 +1450,7 @@ bigargtest(void)
pid = fork(0); pid = fork(0);
if(pid == 0){ if(pid == 0){
char *args[32+1]; const char *args[32+1];
int i; int i;
for(i = 0; i < 32; i++) for(i = 0; i < 32; i++)
args[i] = "bigargs test: failed\n "; args[i] = "bigargs test: failed\n ";
...@@ -1467,7 +1467,7 @@ bigargtest(void) ...@@ -1467,7 +1467,7 @@ bigargtest(void)
} }
void void
uox(char *name, char *data) uox(char *name, const char *data)
{ {
int fd = open(name, O_CREATE|O_RDWR); int fd = open(name, O_CREATE|O_RDWR);
if(fd < 0){ if(fd < 0){
......
extern "C" {
#include "types.h" #include "types.h"
#include "amd64.h" #include "amd64.h"
#include "mmu.h" #include "mmu.h"
...@@ -10,6 +11,7 @@ ...@@ -10,6 +11,7 @@
#include "condvar.h" #include "condvar.h"
#include "proc.h" #include "proc.h"
#include "vm.h" #include "vm.h"
}
static void vmap_free(void *p); static void vmap_free(void *p);
...@@ -18,7 +20,7 @@ enum { vm_debug = 0 }; ...@@ -18,7 +20,7 @@ enum { vm_debug = 0 };
static struct vma * static struct vma *
vma_alloc(void) vma_alloc(void)
{ {
struct vma *e = kmalloc(sizeof(struct vma)); struct vma *e = (struct vma *) kmalloc(sizeof(struct vma));
if (e == 0) if (e == 0)
return 0; return 0;
memset(e, 0, sizeof(struct vma)); memset(e, 0, sizeof(struct vma));
...@@ -103,7 +105,7 @@ vmap_decref(struct vmap *m) ...@@ -103,7 +105,7 @@ vmap_decref(struct vmap *m)
struct vmap * struct vmap *
vmap_alloc(void) vmap_alloc(void)
{ {
struct vmap *m = kmalloc(sizeof(struct vmap)); struct vmap *m = (struct vmap *) kmalloc(sizeof(struct vmap));
if (m == 0) if (m == 0)
return 0; return 0;
memset(m, 0, sizeof(struct vmap)); memset(m, 0, sizeof(struct vmap));
...@@ -117,7 +119,7 @@ vmap_alloc(void) ...@@ -117,7 +119,7 @@ vmap_alloc(void)
kmfree(m); kmfree(m);
return 0; return 0;
} }
m->kshared = ksalloc(slab_kshared); m->kshared = (char*)ksalloc(slab_kshared);
if (m->kshared == NULL || setupkshared(m->pml4, m->kshared)) { if (m->kshared == NULL || setupkshared(m->pml4, m->kshared)) {
cprintf("vmap_alloc: kshared out of memory\n"); cprintf("vmap_alloc: kshared out of memory\n");
freevm(m->pml4); freevm(m->pml4);
...@@ -138,7 +140,7 @@ vmn_doload(struct vmnode *vmn, struct inode *ip, u64 offset, u64 sz) ...@@ -138,7 +140,7 @@ vmn_doload(struct vmnode *vmn, struct inode *ip, u64 offset, u64 sz)
{ {
for(u64 i = 0; i < sz; i += PGSIZE){ for(u64 i = 0; i < sz; i += PGSIZE){
char *p = vmn->page[i / PGSIZE]; char *p = vmn->page[i / PGSIZE];
u64 n; s64 n;
if(sz - i < PGSIZE) if(sz - i < PGSIZE)
n = sz - i; n = sz - i;
else else
...@@ -303,7 +305,7 @@ copyout(struct vmap *vmap, uptr va, void *p, u64 len) ...@@ -303,7 +305,7 @@ copyout(struct vmap *vmap, uptr va, void *p, u64 len)
struct vmnode * struct vmnode *
vmn_alloc(u64 npg, enum vmntype type) vmn_alloc(u64 npg, enum vmntype type)
{ {
struct vmnode *n = kmalloc(sizeof(struct vmnode)); struct vmnode *n = (struct vmnode *) kmalloc(sizeof(struct vmnode));
if (n == 0) { if (n == 0) {
cprintf("out of vmnodes"); cprintf("out of vmnodes");
return 0; return 0;
...@@ -435,17 +437,15 @@ vmap_copy(struct vmap *m, int share) ...@@ -435,17 +437,15 @@ vmap_copy(struct vmap *m, int share)
return 0; return 0;
acquire(&m->lock); acquire(&m->lock);
struct state *st = kmalloc(sizeof(struct state)); struct state st;
st->share = share; st.share = share;
st->pml4 = m->pml4; st.pml4 = m->pml4;
st->cr = c->cr; st.cr = c->cr;
if (!crange_foreach(m->cr, vmap_copy_vma, st)) { if (!crange_foreach(m->cr, vmap_copy_vma, &st)) {
vmap_free(c); vmap_free(c);
release(&m->lock); release(&m->lock);
kmfree(st);
return 0; return 0;
} }
kmfree(st);
if (share) if (share)
lcr3(v2p(m->pml4)); // Reload hardware page table lcr3(v2p(m->pml4)); // Reload hardware page table
...@@ -552,7 +552,7 @@ vmap_copy(struct vmap *m, int share) ...@@ -552,7 +552,7 @@ vmap_copy(struct vmap *m, int share)
return 0; return 0;
acquire(&m->lock); acquire(&m->lock);
for(int i = 0; i < NELEM(m->e); i++) { for(u32 i = 0; i < NELEM(m->e); i++) {
if(m->e[i] == 0) if(m->e[i] == 0)
continue; continue;
c->e[i] = vma_alloc(); c->e[i] = vma_alloc();
...@@ -594,7 +594,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len) ...@@ -594,7 +594,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len)
{ {
acquire(&m->lock); acquire(&m->lock);
uptr va_end = va_start + len; uptr va_end = va_start + len;
for(int i = 0; i < NELEM(m->e); i++) { for(u32 i = 0; i < NELEM(m->e); i++) {
if(m->e[i] && (m->e[i]->va_start < va_end && m->e[i]->va_end > va_start)) { if(m->e[i] && (m->e[i]->va_start < va_end && m->e[i]->va_end > va_start)) {
if(m->e[i]->va_start != va_start || m->e[i]->va_end != va_end) { if(m->e[i]->va_start != va_start || m->e[i]->va_end != va_end) {
release(&m->lock); release(&m->lock);
......
...@@ -13,7 +13,6 @@ struct vma { ...@@ -13,7 +13,6 @@ struct vma {
}; };
// A memory object (physical pages or inode). // A memory object (physical pages or inode).
enum vmntype { EAGER, ONDEMAND};
struct vmnode { struct vmnode {
u64 npages; u64 npages;
char *page[128]; char *page[128];
......
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "spinlock.h" #include "spinlock.h"
#include "amd64.h" #include "amd64.h"
#include "cpu.h" #include "cpu.h"
#include "wq.h" #include "wq.h"
}
#define NSLOTS (1 << WQSHIFT) #define NSLOTS (1 << WQSHIFT)
...@@ -84,7 +86,7 @@ wq_push1(void (*fn)(struct work *w, void *a0), void *a0) ...@@ -84,7 +86,7 @@ wq_push1(void (*fn)(struct work *w, void *a0), void *a0)
struct work *w = allocwork(); struct work *w = allocwork();
if (w == NULL) if (w == NULL)
return -1; return -1;
w->rip = fn; w->rip = (void*) fn;
w->arg0 = a0; w->arg0 = a0;
if (wq_push(w) < 0) { if (wq_push(w) < 0) {
freework(w); freework(w);
...@@ -99,7 +101,7 @@ wq_push2(void (*fn)(struct work*, void*, void*), void *a0, void *a1) ...@@ -99,7 +101,7 @@ wq_push2(void (*fn)(struct work*, void*, void*), void *a0, void *a1)
struct work *w = allocwork(); struct work *w = allocwork();
if (w == NULL) if (w == NULL)
return -1; return -1;
w->rip = fn; w->rip = (void*) fn;
w->arg0 = a0; w->arg0 = a0;
w->arg1 = a1; w->arg1 = a1;
if (wq_push(w) < 0) { if (wq_push(w) < 0) {
...@@ -121,7 +123,7 @@ __wq_pop(int c) ...@@ -121,7 +123,7 @@ __wq_pop(int c)
i = wq->head; i = wq->head;
if ((i - wq->tail) == 0) { if ((i - wq->tail) == 0) {
release(&wq->lock); release(&wq->lock);
return NULL; return 0;
} }
i = (i-1) & (NSLOTS-1); i = (i-1) & (NSLOTS-1);
w = wq->w[i]; w = wq->w[i];
...@@ -144,7 +146,7 @@ __wq_steal(int c) ...@@ -144,7 +146,7 @@ __wq_steal(int c)
i = wq->tail; i = wq->tail;
if ((i - wq->head) == 0) { if ((i - wq->head) == 0) {
release(&wq->lock); release(&wq->lock);
return NULL; return 0;
} }
i = i & (NSLOTS-1); i = i & (NSLOTS-1);
w = wq->w[i]; w = wq->w[i];
...@@ -158,7 +160,7 @@ __wq_steal(int c) ...@@ -158,7 +160,7 @@ __wq_steal(int c)
static void static void
__wq_run(struct work *w) __wq_run(struct work *w)
{ {
void (*fn)(struct work*, void*, void*, void*, void*) = w->rip; void (*fn)(struct work*, void*, void*, void*, void*) = (void(*)(work*,void*,void*,void*,void*))w->rip;
fn(w, w->arg0, w->arg1, w->arg2, w->arg3); fn(w, w->arg0, w->arg1, w->arg2, w->arg3);
freework(w); freework(w);
} }
...@@ -207,7 +209,7 @@ __test_stub(struct work *w, void *a0, void *a1) ...@@ -207,7 +209,7 @@ __test_stub(struct work *w, void *a0, void *a1)
{ {
//long i = (long)a0; //long i = (long)a0;
//cprintf("%u: %lu\n", cpunum(), i); //cprintf("%u: %lu\n", cpunum(), i);
volatile int *running = a1; volatile int *running = (volatile int*) a1;
subfetch(running, 1); subfetch(running, 1);
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论