Defines the memory interface and adds a dump_memory function.

This commit is contained in:
Felix Queißner 2016-05-21 19:17:08 +02:00
parent d4129cce0e
commit c404e99e59
2 changed files with 108 additions and 26 deletions

View file

@ -2,6 +2,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void vm_assert(int assertion, const char *msg)
{
if(assertion != 0)
return;
printf("Assertion failed: %s\n", msg);
exit(1);
}
void vm_syscall(Process *p, CommandInfo *info)
{
switch(info->additional)
{
case 0: // EXIT
p->tag = NULL;
break;
case 1:
printf("%c", info->input0);
break;
case 2:
printf("%d", info->input0);
break;
default:
printf("Some syscall: (%d, %d, %d, %d)\n",
info->input0,
info->input1,
info->argument,
info->additional);
break;
}
}
void vm_hwio(Process *p, CommandInfo *info)
{
printf("Some hardware IO: (%d, %d, %d, %d)\n",
info->input0,
info->input1,
info->argument,
info->additional);
}
void dump_proc(Process *process)
{
@ -27,30 +70,32 @@ void dump_proc(Process *process)
printf("]\n");
}
void vm_assert(int assertion, const char *msg)
void dump_memory(Process *process)
{
if(assertion != 0)
return;
printf("Assertion failed: %s\n", msg);
exit(1);
}
printf("Memory Dump:\n");
void vm_syscall(Process *p, CommandInfo *info)
{
printf("Some syscall: (%d, %d, %d, %d)\n",
info->input0,
info->input1,
info->argument,
info->additional);
}
for(int i = 0; i < process->mmap.length; i++) {
printf("Page %d\n", i);
void vm_hwio(Process *p, CommandInfo *info)
{
printf("Some hardware IO: (%d, %d, %d, %d)\n",
info->input0,
info->input1,
info->argument,
info->additional);
// Just assume that pageSize is a multiple of 16
for(int j = 0; j < process->mmap.pageSize; j++) {
if(j % 16 == 0)
printf("%3x ", j);
printf("%2.2X ", process->mmap.pages[i][j]);
if(j % 16 == 15) {
printf(" '");
for(int x = 16*(j/16); x < 16*(j/16+1); x++) {
char c = process->mmap.pages[i][x];
if(c < 0x20) c = '.';
if(c > 0x7E) c = '.';
printf("%c", c);
}
printf("'\n");
}
}
}
}
int main(int argc, const char **argv)
@ -92,14 +137,42 @@ int main(int argc, const char **argv)
c.execZ);
}
Process process = { &module, 0, 0, 0, 0 };
Process *p = &process;
uint8_t page0[64];
uint8_t page1[64];
strcpy((char*)page0, "Hallo Welt!");
uint8_t *mmapDirectory[2] = {
page0,
page1,
};
VirtualMemoryMap mmap = {
.pageSize = 64,
.length = 2,
.pages = mmapDirectory,
};
Process process = {
&module,
.codePointer = 0,
.stackPointer = 0,
.basePointer = 0,
.flags = 0,
.mmap = mmap,
};
Process *p = &process;
p->tag = p;
dump_memory(p);
dump_proc(p);
while(vm_step_process(p)) {
while(vm_step_process(p) && p->tag) {
dump_proc(p);
}
dump_proc(p);
dump_memory(p);
return 0;
}

View file

@ -83,6 +83,13 @@ typedef struct
uint32_t length;
} Module;
typedef struct
{
uint32_t pageSize;
uint32_t length;
uint8_t **pages;
} VirtualMemoryMap;
typedef struct
{
Module *module;
@ -94,6 +101,8 @@ typedef struct
uint32_t flags;
uint32_t stack[VM_STACKSIZE];
VirtualMemoryMap mmap;
} Process;
typedef struct