Merge branch 'master' into native-exit
This commit is contained in:
commit
3f003e387f
|
@ -13,9 +13,11 @@ static int pmem_fd = 0;
|
|||
static char pmem_shm_file[] = "/native-pmem-XXXXXX";
|
||||
static void *pmem = NULL;
|
||||
static ucontext_t uc_example = {};
|
||||
static int sys_pgsz;
|
||||
sigset_t __am_intr_sigmask = {};
|
||||
__am_cpu_t *__am_cpu_struct = NULL;
|
||||
int __am_ncpu = 0;
|
||||
int __am_pgsize;
|
||||
|
||||
static void save_context_handler(int sig, siginfo_t *info, void *ucontext) {
|
||||
memcpy(&uc_example, ucontext, sizeof(uc_example));
|
||||
|
@ -74,7 +76,8 @@ static void init_platform() {
|
|||
thiscpu->cur_as = NULL;
|
||||
|
||||
// create trap page to receive syscall and yield by SIGSEGV
|
||||
void *ret = mmap(TRAP_PAGE_START, 4096, PROT_NONE,
|
||||
sys_pgsz = sysconf(_SC_PAGESIZE);
|
||||
void *ret = mmap(TRAP_PAGE_START, sys_pgsz, PROT_NONE,
|
||||
MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
|
||||
assert(ret != (void *)-1);
|
||||
|
||||
|
@ -142,10 +145,15 @@ static void init_platform() {
|
|||
_intr_write(0);
|
||||
|
||||
// set ncpu
|
||||
char *smp = getenv("smp");
|
||||
const char *smp = getenv("smp");
|
||||
__am_ncpu = smp ? atoi(smp) : 1;
|
||||
assert(0 < __am_ncpu && __am_ncpu <= MAX_CPU);
|
||||
|
||||
// set pgsize
|
||||
const char *pgsize = getenv("pgsize");
|
||||
__am_pgsize = pgsize ? atoi(pgsize) : sys_pgsz;
|
||||
assert(__am_pgsize > 0 && __am_pgsize % sys_pgsz == 0);
|
||||
|
||||
const char *args = getenv("mainargs");
|
||||
_halt(main(args ? args : "")); // call main here!
|
||||
}
|
||||
|
@ -167,13 +175,13 @@ void __am_shm_mmap(void *va, void *pa, int prot) {
|
|||
// all readable pages executable as well
|
||||
if (prot | _PROT_READ) mmap_prot |= PROT_READ | PROT_EXEC;
|
||||
if (prot | _PROT_WRITE) mmap_prot |= PROT_WRITE;
|
||||
void *ret = mmap(va, 4096, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
void *ret = mmap(va, __am_pgsize, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_SHARED | MAP_FIXED, pmem_fd, (uintptr_t)(pa - pmem));
|
||||
assert(ret != (void *)-1);
|
||||
}
|
||||
|
||||
void __am_shm_munmap(void *va) {
|
||||
int ret = munmap(va, 4096);
|
||||
int ret = munmap(va, __am_pgsize);
|
||||
assert(ret == 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#define USER_SPACE RANGE(0x40000000, 0xc0000000)
|
||||
|
||||
#define PGSIZE 4096
|
||||
|
||||
typedef struct PageMap {
|
||||
void *va;
|
||||
void *pa;
|
||||
|
@ -15,6 +13,7 @@ typedef struct PageMap {
|
|||
#define list_foreach(p, head) \
|
||||
for (p = head; p != NULL; p = p->next)
|
||||
|
||||
extern int __am_pgsize;
|
||||
static int vme_enable = 0;
|
||||
static void* (*pgalloc)(size_t) = NULL;
|
||||
static void (*pgfree)(void *) = NULL;
|
||||
|
@ -29,7 +28,7 @@ int _vme_init(void* (*pgalloc_f)(size_t), void (*pgfree_f)(void*)) {
|
|||
void _protect(_AddressSpace *as) {
|
||||
assert(as != NULL);
|
||||
as->ptr = NULL;
|
||||
as->pgsize = PGSIZE;
|
||||
as->pgsize = __am_pgsize;
|
||||
as->area = USER_SPACE;
|
||||
}
|
||||
|
||||
|
@ -67,8 +66,8 @@ void __am_switch(_Context *c) {
|
|||
|
||||
void _map(_AddressSpace *as, void *va, void *pa, int prot) {
|
||||
assert(IN_RANGE(va, USER_SPACE));
|
||||
assert((uintptr_t)va % PGSIZE == 0);
|
||||
assert((uintptr_t)pa % PGSIZE == 0);
|
||||
assert((uintptr_t)va % __am_pgsize == 0);
|
||||
assert((uintptr_t)pa % __am_pgsize == 0);
|
||||
assert(as != NULL);
|
||||
PageMap *pp;
|
||||
list_foreach(pp, as->ptr) {
|
||||
|
@ -82,7 +81,7 @@ void _map(_AddressSpace *as, void *va, void *pa, int prot) {
|
|||
}
|
||||
}
|
||||
|
||||
pp = pgalloc(PGSIZE); // this will waste memory, any better idea?
|
||||
pp = pgalloc(__am_pgsize); // this will waste memory, any better idea?
|
||||
pp->va = va;
|
||||
pp->pa = pa;
|
||||
pp->prot = prot;
|
||||
|
|
|
@ -33,6 +33,7 @@ _Context* vm_handler(_Event ev, _Context *ctx) {
|
|||
break;
|
||||
case _EVENT_SYSCALL:
|
||||
_intr_write(1);
|
||||
for (int volatile i = 0; i < 1000000; i++) ;
|
||||
printf("%d ", ctx->GPRx);
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue