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

compile vm code as c++

上级 15c7f34b
......@@ -14,16 +14,19 @@ HW ?= qemu
O = o.$(HW)
CC = $(TOOLPREFIX)gcc
CXX = $(TOOLPREFIX)g++
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
NM = $(TOOLPREFIX)nm
OBJCOPY = $(TOOLPREFIX)objcopy
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb \
-m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -mno-red-zone \
-I$(QEMUSRC) \
-fno-omit-frame-pointer -DHW_$(HW) -include param.h -include compiler.h
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
COMFLAGS := -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall \
-MD -ggdb -m64 -Werror -fms-extensions -mno-sse \
-mcmodel=large -mno-red-zone -I$(QEMUSRC) -fno-omit-frame-pointer \
-DHW_$(HW) -include param.h -include compiler.h
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
ASFLAGS = -m64 -gdwarf-2 -MD
LDFLAGS += -m elf_x86_64
......@@ -112,6 +115,10 @@ $(O)/%.o: %.c
@echo " CC $@"
$(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: $(O)/initcode $(O)/bootother $(O)/fs.img
$(O)/%.o: %.S
......
......@@ -77,7 +77,7 @@ writebuf(int c, void *arg)
}
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 };
vprintfmt(writebuf, (void*) &bs, fmt, ap);
......@@ -85,7 +85,7 @@ vsnprintf(char *buf, u32 n, char *fmt, va_list ap)
}
void
snprintf(char *buf, u32 n, char *fmt, ...)
snprintf(char *buf, u32 n, const char *fmt, ...)
{
va_list ap;
......
......@@ -8,7 +8,7 @@
#define KDSEG (3<<3) /* kernel data segment */
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 cilkframe;
......@@ -48,7 +48,7 @@ void cprintf(const char*, ...) __attribute__((format(printf, 1, 2)));
void panic(const char*, ...)
__noret__ __attribute__((format(printf, 1, 2)));
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));
#define assert(c) if (!(c)) { cprintf("%s:%d: ", __FILE__, __LINE__); panic("assertion failure"); }
......@@ -307,8 +307,10 @@ void uartputc(char c);
void uartintr(void);
// vm.c
enum vmntype { EAGER, ONDEMAND };
struct vmap * vmap_alloc(void);
struct vmnode* vmn_alloc(u64, u32);
struct vmnode* vmn_alloc(u64, enum vmntype);
struct vmnode* vmn_allocpg(u64);
int vmap_insert(struct vmap*, struct vmnode *, uptr);
struct vma * vmap_lookup(struct vmap*, uptr, uptr);
......
......@@ -127,7 +127,7 @@ writebuf(void *arg, char c)
}
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 };
vprintfmt(writebuf, (void*) &bs, fmt, ap);
......@@ -135,7 +135,7 @@ vsnprintf(char *buf, u32 n, char *fmt, va_list ap)
}
void
snprintf(char *buf, u32 n, char *fmt, ...)
snprintf(char *buf, u32 n, const char *fmt, ...)
{
va_list ap;
......
......@@ -46,5 +46,5 @@ int forkt(void *sp, void *pc, void *arg);
// printf.c
void printf(int, 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));
extern "C" {
#include "types.h"
#include "amd64.h"
#include "mmu.h"
......@@ -10,6 +11,7 @@
#include "condvar.h"
#include "proc.h"
#include "vm.h"
}
static void vmap_free(void *p);
......@@ -18,7 +20,7 @@ enum { vm_debug = 0 };
static struct vma *
vma_alloc(void)
{
struct vma *e = kmalloc(sizeof(struct vma));
struct vma *e = (struct vma *) kmalloc(sizeof(struct vma));
if (e == 0)
return 0;
memset(e, 0, sizeof(struct vma));
......@@ -103,7 +105,7 @@ vmap_decref(struct vmap *m)
struct vmap *
vmap_alloc(void)
{
struct vmap *m = kmalloc(sizeof(struct vmap));
struct vmap *m = (struct vmap *) kmalloc(sizeof(struct vmap));
if (m == 0)
return 0;
memset(m, 0, sizeof(struct vmap));
......@@ -130,7 +132,7 @@ vmn_doload(struct vmnode *vmn, struct inode *ip, u64 offset, u64 sz)
{
for(u64 i = 0; i < sz; i += PGSIZE){
char *p = vmn->page[i / PGSIZE];
u64 n;
s64 n;
if(sz - i < PGSIZE)
n = sz - i;
else
......@@ -295,7 +297,7 @@ copyout(struct vmap *vmap, uptr va, void *p, u64 len)
struct vmnode *
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) {
cprintf("out of vmnodes");
return 0;
......@@ -541,7 +543,7 @@ vmap_copy(struct vmap *m, int share)
return 0;
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)
continue;
c->e[i] = vma_alloc();
......@@ -583,7 +585,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len)
{
acquire(&m->lock);
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]->va_start != va_start || m->e[i]->va_end != va_end) {
release(&m->lock);
......
......@@ -13,7 +13,6 @@ struct vma {
};
// A memory object (physical pages or inode).
enum vmntype { EAGER, ONDEMAND};
struct vmnode {
u64 npages;
char *page[128];
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论