提交 dee0d8b5 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

more c++

上级 577f85e1
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++;
...@@ -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 "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,6 +51,7 @@ dosegment(uptr a0, u64 a1) ...@@ -50,6 +51,7 @@ dosegment(uptr a0, u64 a1)
goto bad; goto bad;
} }
{
uptr va_start = PGROUNDDOWN(ph.vaddr); uptr va_start = PGROUNDDOWN(ph.vaddr);
uptr va_end = PGROUNDUP(ph.vaddr + ph.memsz); uptr va_end = PGROUNDUP(ph.vaddr + ph.memsz);
...@@ -70,6 +72,7 @@ dosegment(uptr a0, u64 a1) ...@@ -70,6 +72,7 @@ dosegment(uptr a0, u64 a1)
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,
......
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) {
...@@ -100,7 +102,7 @@ initpg(void) ...@@ -100,7 +102,7 @@ initpg(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;
} }
} }
...@@ -154,7 +156,7 @@ freepm(pme_t *pm, int level) ...@@ -154,7 +156,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);
} }
} }
...@@ -176,7 +178,7 @@ freevm(pml4e_t *pml4) ...@@ -176,7 +178,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);
} }
} }
......
...@@ -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
......
...@@ -288,10 +288,11 @@ void syscall(void); ...@@ -288,10 +288,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
...@@ -379,3 +380,38 @@ void initnet(void); ...@@ -379,3 +380,38 @@ void initnet(void);
void initsched(void); void initsched(void);
void initlockstat(void); void initlockstat(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*);
// other exported functions
void cmain(u64 mbmagic, u64 mbaddr);
void mpboot(void);
// 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
......
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"
}
static volatile int bstate; static volatile int bstate;
...@@ -30,7 +32,7 @@ bootothers(void) ...@@ -30,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++){
...@@ -40,7 +42,7 @@ bootothers(void) ...@@ -40,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;
......
...@@ -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)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "proc.h" #include "proc.h"
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "net.h"
void void
netfree(void *va) netfree(void *va)
......
#pragma once
void netclose(int sock);
int netread(int, char *, int);
int netwrite(int, char *, int);
// 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;
......
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 "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;
} }
// 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,35 +146,6 @@ kmemcpy(void *umem, void *src, u64 size) ...@@ -146,35 +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*);
#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) = {
......
// 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);
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论