Exemple #1
0
int main(int argc, char* argv[]) 
{
	char* image = "image";
	if (argc > 1)
		image = argv[1];

	vm_init();

	mop_add(0, 1, 0, 0, 10); // r1 = 10
	mop_add(8, 2, 0, 0, 20); // r2 = 20
	mop_push(16, 1); // push r1
	mop_push(24, 2); // push r2
	mop_add(32, 2, 0, 0, 0); // r2 = 0
	mop_sub(40, 1, 1, 0, 1); // r1--
	mop_prti(48, 1); // print r1
	mop_jnz(64, 1, 32);
	mop_pop(72, 2); // pop r2
	mop_pop(80, 1); // pop r1
	mop_prti(88, 1); // print r1, should be 10
	mop_prti(96, 2); // print r2
	mop_exit(104);

	vm_run(0);

	vm_exit();

/*
	vm_init();
	vm_load(image);
	vm_run(ENTRY_POINT);
*/	
	return exitval;
}
Exemple #2
0
int		main(int argc, char **argv)
{
	t_vm	vm;


	vm_init(&vm);
	if (argc > 1)
	{
		ft_handle_args(argc, argv, &vm);
	}
	else
	{
		//ft_error("Not enough arguments");
		print_options();
		return(0);
	}
	ft_init_arena(&vm);
	ft_init_lst_proc(&vm);
	ft_print_header(&vm);
	cpu(&vm);

//system("clear");
//	print_t_proc(&vm);
	print_finish(&vm);

	return (0);
}
Exemple #3
0
program_t *colm_new_program( struct colm_sections *rtd )
{
	program_t *prg = malloc(sizeof(program_t));
	memset( prg, 0, sizeof(program_t) );

	assert( sizeof(str_t)      <= sizeof(tree_t) );
	assert( sizeof(pointer_t)  <= sizeof(tree_t) );

	prg->rtd = rtd;
	prg->ctx_dep_parsing = 1;

	init_pool_alloc( &prg->kid_pool, sizeof(kid_t) );
	init_pool_alloc( &prg->tree_pool, sizeof(tree_t) );
	init_pool_alloc( &prg->parse_tree_pool, sizeof(parse_tree_t) );
	init_pool_alloc( &prg->head_pool, sizeof(head_t) );
	init_pool_alloc( &prg->location_pool, sizeof(location_t) );

	prg->true_val = (tree_t*) 1;
	prg->false_val = (tree_t*) 0;

	/* Allocate the global variable. */
	colm_alloc_global( prg );

	/* Allocate the VM stack. */
	vm_init( prg );

	rtd->init_need();

	prg->stream_fns = malloc( sizeof(char*) * 1 );
	prg->stream_fns[0] = 0;
	return prg;
}
Exemple #4
0
RState* r_state_new (RAllocFunc alloc_fn, rpointer aux)
{
    RState* r;
    RState zero = { { 0 } };

    r = alloc_fn (NULL, NULL, sizeof (RState));

    if (!r)
        goto exit;

    *r = zero;

    /* Initialize memory allocator */
    r->alloc_fn = alloc_fn;
    r->alloc_aux = aux;

    /* Initialize error handling facilities */
    r->last_error = R_UNDEFINED;

    gc_init (r);

    init_builtin_types (r);
    init_global_objects (r);

    vm_init (r);
    gc_enable (r);

exit:
    return r;
}
/********************
 * dres_init
 ********************/
EXPORTED dres_t *
dres_init(char *prefix)
{
    dres_t *dres;
    int     status;
    
    if (ALLOC_OBJ(dres) == NULL) {
        errno = ENOMEM;
        return NULL;
    }

    if (vm_init(&dres->vm, 32))
        goto fail;

    if (dres_store_init(dres))
        goto fail;

    if ((status = dres_register_builtins(dres)) != 0)
        goto fail;

    dres->stamp = 1;

    if (prefix != NULL && prefix[0] != '\0')
        DRES_WARNING("ignoring deprecated DRES prefix \"%s\"", prefix);
    
    return dres;
    
 fail:
    dres_dump_targets(dres);
    dres_exit(dres);
    return NULL;
}
Exemple #6
0
int main(int argc, char** argv)
{
    vm_init();

    // Test mode
    if (argc == 2 && strcmp(argv[1], "--test") == 0)
    {
        test_vm();
        test_parser();
        test_interp();
        return 0;
    }

    // File name passed
    if (argc == 2)
    {
        char* cstr = read_file(argv[1]);

        if (cstr == NULL)
            return -1;

        // Evaluate the code string
        eval_str(cstr);

        free(cstr);
    }

    // No file names passed. Read-eval-print loop.
    if (argc == 1)
    {
        run_repl();
    }

    return 0;
}
Exemple #7
0
/**
 *	Initializes the SCN 2.0 library.
 *	Called when the app starts up.
 */
int scn20_initialize(void)
{
	if (!vm_init())
		return 0;

	return 1;
}
Exemple #8
0
void __init start_vmm ( const struct multiboot_info *mbi )
{
	//Initialize serial port COM1, this must be done before calling outf
	setup_serial();
	outf("\n\n\n!!!!!!!!!!!BEGIN!!!!!!!!!!!\n\n\n");

	//Parse the command line that user pass to GRUB
	struct cmdline_option opt = parse_cmdline ( mbi );

	//Set up memory layout and store the layout in pml
	struct pmem_layout pml;
	setup_memory(mbi, &opt, &pml);

	struct vm_info vm;
	vm_create (&vm, pml.vmm_pmem_start, opt.vmm_pmem_size, &(pml.e820));

	outf("\n++++++ New virtual machine created. Going to start the VM\n");
	vm_init (&vm);

	//Debug
	//e820_print_map(&(pml.e820));

	outf ("\n++++++ Going to GRUB for the 2nd time\n");
	vm_boot (&vm);
}
Exemple #9
0
void kmain(s64 magic, s64 info)
{
	//vga_clear(COLOR_BLACK);
    idt_init();
    isr_init();

    serial_init();
	set_debug_traps();
    BREAKPOINT();

	cpuid_print();
	multiboot(magic, info);
	kmem_map();
    page_init();
    kmalloc_init();
    //vesa_init();

    root_init();
    pci_init();
    vm_init();
    syscall_init();
    timer_init();
    kbd_init();
    //mouse_init();

    console_init();

 	create_kthread(NULL, idle_thread, THREAD_PRI_LOW, NULL, NULL);
 	create_kthread(NULL, init_thread, THREAD_PRI_NORMAL, NULL, NULL);

    thread_schedule();
}
Exemple #10
0
int main(int argc, char *argv[])
{
	vm_t vm;
	vm_init(&vm);
	vm_begin(&vm);
	vm_quit(&vm);
	return 0;
}
Exemple #11
0
int main()
{
    FILE * f = fopen("eforth.img","rb");
    vm_init(&vm, f, VM_SIZE);
    fclose(f);
    vm_run(&vm,0);
    return 1;
}
Exemple #12
0
// This start is what u-boot calls. It's just a wrapper around setting up the
// virtual memory for the kernel.
void start(uint32_t *p_bootargs)
{
	// Initialize the virtual memory
	print_uart0("Enabling MMU...\n");
	vm_init();
	os_printf("Initialized VM datastructures.\n");
	mmap(p_bootargs);
}
Exemple #13
0
int main(int argc, char **argv)
{
	struct vm vm;
	struct vcpu vcpu;
	enum {
		REAL_MODE,
		PROTECTED_MODE,
		PAGED_32BIT_MODE,
		LONG_MODE,
	} mode = REAL_MODE;
	int opt;

	while ((opt = getopt(argc, argv, "rspl")) != -1) {
		switch (opt) {
		case 'r':
			mode = REAL_MODE;
			break;

		case 's':
			mode = PROTECTED_MODE;
			break;

		case 'p':
			mode = PAGED_32BIT_MODE;
			break;

		case 'l':
			mode = LONG_MODE;
			break;

		default:
			fprintf(stderr, "Usage: %s [ -r | -s | -p | -l ]\n",
				argv[0]);
			return 1;
		}
	}

	vm_init(&vm, 0x200000);
	vcpu_init(&vm, &vcpu);

	switch (mode) {
	case REAL_MODE:
		return !run_real_mode(&vm, &vcpu);

	case PROTECTED_MODE:
		return !run_protected_mode(&vm, &vcpu);

	case PAGED_32BIT_MODE:
		return !run_paged_32bit_mode(&vm, &vcpu);

	case LONG_MODE:
		return !run_long_mode(&vm, &vcpu);
	}

	return 1;
}
Exemple #14
0
void gamed_init(void)
{
    libevent_init();
    config_init();
    log_init("gated", 0);
    socket_init();
    vm_init();
    //signal_init();

}
Exemple #15
0
/*
 * Initialization code.
 *
 * Called from kernel_start() routine that is
 * implemented in HAL.
 * We assume that the following machine state has
 * been already set before this routine.
 *	- Kernel BSS section is filled with 0.
 *	- Kernel stack is configured.
 *	- All interrupts are disabled.
 *	- Minimum page table is set. (MMU systems only)
 */
int
main(void)
{

	sched_lock();
	diag_init();
	DPRINTF((BANNER));

	/*
	 * Initialize memory managers.
	 */
	page_init();
	kmem_init();

	/*
	 * Do machine-dependent
	 * initialization.
	 */
	machine_startup();

	/*
	 * Initialize kernel core.
	 */
	vm_init();
	task_init();
	thread_init();
	sched_init();
	exception_init();
	timer_init();
	object_init();
	msg_init();

	/*
	 * Enable interrupt and
	 * initialize devices.
	 */
	irq_init();
	clock_init();
	device_init();

	/*
	 * Set up boot tasks.
	 */
	task_bootstrap();

	/*
	 * Start scheduler and
	 * enter idle loop.
	 */
	sched_unlock();
	thread_idle();

	/* NOTREACHED */
	return 0;
}
Exemple #16
0
// The kernel main function. Initialize everything and start the kernel
// debugger. The two arguments are the physical address of the Multiboot info
// structure and the bootloader magic number respectively.
void
init()
{
    int r;

    // Initialize the console first to print messages during the initialization
    cons_init();

    kprintf("Argentum Operating System\n");

    arch_init();

    kmem_cache_init();
    kmem_cache_sizes_init();

    vm_init();
    process_init();
    thread_init();
    ipc_init();
    scheduler_init();
    sync_init();
    clock_init();

    if ((r = process_create_system(system_main, NULL)) < 0)
        kprintf("Cannot create system process: %s\n", strerror(-r));

    if (module_start) {
        Boot_image *image = (Boot_image *) module_start;
    
        if(image->magic != 0x12345678)
            panic("invalid bootimage");

        for (unsigned i = 0; i < image->length; i++) {
            uint8_t *binary = (uint8_t *) image + image->headers[i].offset;
            size_t size = image->headers[i].length;

            if (binary < module_start || binary >= module_end)
                panic("invalid bootimage");
            if ((binary + size) <= module_start || (binary + size) > module_end)
                panic("invalid bootimage");

            r = process_create((uint8_t *) image + image->headers[i].offset,
                    image->headers[i].length, PROCESS_TYPE_USER, NULL);
            if (r < 0)
                panic("Cannot create process: %s", strerror(-r));
        }

    }

    scheduler_start();

    for (;;) {
        kdb_main(NULL);
    }
}
Exemple #17
0
static void init_first_hart()
{
  file_init();

  struct mainvars arg_buffer;
  struct mainvars *args = parse_args(&arg_buffer);

  memory_init();
  vm_init();
  boot_loader(args);
}
Exemple #18
0
int runtest(char*code,uint32_t correct_stacktop)
{
  vm_init();
  vm_compile(code);
  while(!vm.stopped) vm_run();
  if(vm.stack[vm.sp]==correct_stacktop) return 0;
  fprintf(stderr,"unit test failed with code \"%s\"\n",code);
  fprintf(stderr,"stacktop=%x (should have been %x)\n",
    vm.stack[vm.sp],correct_stacktop);
  exit(1);
}
Exemple #19
0
int main(int argc, char **argv) {

//loader_receive();

  nvmfile_init();

  vm_init();

  nvmfile_call_main();
  for(;;);  // reset wdt if in use

  return 0;
}
Exemple #20
0
void start_hypervisor()
{
    int i;
    uint8_t nr_vcpus = 1; // TODO: It will be read from configuration file.

    uint32_t pcpu = smp_processor_id();

    if (pcpu == 0) {
        timemanager_init();
        sched_init();

        vm_setup();

        for (i = 0; i < NUM_GUESTS_STATIC; i++) {
            vmid_t vmid;

            if ((vmid = vm_create(nr_vcpus)) == VM_CREATE_FAILED) {
                printf("vm_create(vm[%d]) is failed\n", i);
                goto error;
            }
            if (vm_init(vmid) != HALTED) {
                printf("vm_init(vm[%d]) is failed\n", i);
                goto error;
            }
            if (vm_start(vmid) != RUNNING) {
                printf("vm_start(vm[%d]) is failed\n", i);
                goto error;
            }
        }

        smp_pen = 1;
    } else {
        while (!smp_pen) ;
        printf("cpu[%d] is enabled\n", pcpu);
    }

    /*
     * TODO: Add a function - return vmid or vcpu_id to execute for the first time.
     * TODO: Rename guest_sched_start to do_schedule or something others.
     *       do_schedule(vmid) or do_schedule(vcpu_id)
     */
    printf("sched_start!!!\n");
    sched_start();

    /* The code flow must not reach here */
error:
    printf("-------- [%s] ERROR: K-Hypervisor must not reach here\n", __func__);
    abort();
}
Exemple #21
0
void
kern_init()
{
	kprintf("Loading IncOS ...\n");

	vm_init();
	proc_init();
	sched_init();

	run_boot_modules();

	enable_interrupts();

	for (;;);
}
Exemple #22
0
void interpret_bc(Program* p) {
    vm_init(p);
    //printf("Interpreting Bytecode Program:\n");
    //print_prog(p);
    while (1) {
        if (pc == NULL)
            break;
        switch (pc->tag)
        {
        default:
            break;
        }
    }
    
    printf("\n");
}
void		scene(t_data *d, t_dmlx *m)
{
	if (m->scene == VM)
		vm(&d->vm, d->vm.cperloop);
	else if (m->scene == VM_INIT)
		vm_init(d, &d->vm);
	else if (m->scene == INTRO_LOAD)
		intro_load(m, &m->scene_img[0][0], &m->scene_img[0][1]);
	else if (m->scene == INTRO_MENU)
		intro_menu(&m->scene_img[0][2], &m->scene_img[0][1]);
	else if (m->scene == INTRO_OUT)
		intro_out(d, &m->scene_img[0][0], &m->scene_img[0][1]
			, &m->scene_img[0][3]);
	else if (m->scene == END)
		vm_end(m, &data()->vm, &m->scene_img[0][0]);
}
Exemple #24
0
void init_all(int argc, char **argv) {
    // process command line arguments
    char *filename = NULL;
    FILE *fp = stdin;
    EmObject *ob;

    if (argc > 1)
        filename = argv[1];

    if (filename != NULL) {
        if ((fp = fopen(filename, "r")) == NULL) {
            fprintf(stderr, "Cannot open file %s\n", filename);
            exit(1);
        }
        source.type = SOURCE_TYPE_FILE;
    } else {
        source.type = SOURCE_TYPE_PROMPT;
    }
    source.filename = filename;
    source.fp = fp;

    // Constant hash table
    literalTable = newhashobject();
    // Add commonly used literals
    ob = newintobject(1);
    hashobject_insert_by_string(literalTable, "1", ob);
    DECREF(ob);
    ob = newintobject(-1);
    hashobject_insert_by_string(literalTable, "-1", ob);
    DECREF(ob);
    ob = newintobject(0);
    hashobject_insert_by_string(literalTable, "0", ob);
    DECREF(ob);

    ob = newstringobject("*");
    hashobject_insert_by_string(literalTable, "*", ob);
    DECREF(ob);

    hashobject_insert_by_string(literalTable, "null", &nulobj);


    // initialize the lexer
    lexer_init();

    // initialize the VM
    vm_init();
}
Exemple #25
0
int
main(void)
{
	D(bug("%s\n", __func__));

	int i, j;

	vm_init();

	vm_uintptr_t page_size = vm_get_page_size();
	
	char *area;
	const int n_pages = 7;
	const int area_size = n_pages * page_size;
	const int map_options = VM_MAP_DEFAULT | VM_MAP_WRITE_WATCH;
	if ((area = (char *)vm_acquire(area_size, map_options)) == VM_MAP_FAILED)
		return 1;

	unsigned int n_modified_pages_expected = 0;
	static const int touch_page[n_pages] = { 0, 1, 1, 0, 1, 0, 1 };
	for (i = 0; i < n_pages; i++) {
		if (touch_page[i]) {
			area[i * page_size] = 1;
			++n_modified_pages_expected;
		}
	}

	char *modified_pages[n_pages];
	unsigned int n_modified_pages = n_pages;
	if (vm_get_write_watch(area, area_size, (void **)modified_pages, &n_modified_pages) < 0)
		return 2;
	if (n_modified_pages != n_modified_pages_expected)
		return 3;
	for (i = 0, j = 0; i < n_pages; i++) {
		char v = area[i * page_size];
		if ((touch_page[i] && !v) || (!touch_page[i] && v))
			return 4;
		if (!touch_page[i])
			continue;
		if (modified_pages[j] != (area + i * page_size))
			return 5;
		++j;
	}

	vm_release(area, area_size);
	return 0;
}
Exemple #26
0
int
vm_reinit(struct vm *vm)
{
	int error;

	/*
	 * A virtual machine can be reset only if all vcpus are suspended.
	 */
	if (CPU_CMP(&vm->suspended_cpus, &vm->active_cpus) == 0) {
		vm_cleanup(vm, false);
		vm_init(vm, false);
		error = 0;
	} else {
		error = EBUSY;
	}

	return (error);
}
Exemple #27
0
void vmem_write(int address, int data) {
	if(vmem == NULL) {			//Überprüfen ob mit shared Memory verbunden
		vm_init();
	}
	int page = address/VMEM_PAGESIZE;
	int offset = address%VMEM_PAGESIZE;
	
	vmem->adm.req_pageno = page;
	
	sem_wait(&vmem->adm.sema);
	if((vmem->pt.entries[page].flags & PTF_PRESENT) == PTF_PRESENT) {
		write_page(page, offset, data);								/* Seite schreiben */
	} else {
		kill(vmem->adm.mmanage_pid, SIGUSR1);
		sem_wait(&vmem->adm.sema);
		write_page(page, offset, data);								/* Seite schreiben */
	}
	sem_post(&vmem->adm.sema);
}
Exemple #28
0
/*
 * Kernel entry point
 */
void kmain(void) {
    // initialise the platform
    pexpert_init();

    // Initialise paging and VM subsystem
    vm_init();

    // print some info
    KINFO("PMK %s (build %u): Copyright 2014 Tristan Seifert <*****@*****.**>. All rights reserved.\n", KERNEL_VERSION, (unsigned int) &BUILD_NUMBER);
    KDEBUG("Loading IO services from RAM disk...\n");

    // Load any additional drivers from RAM disk

    // Initialise scheduler
    scheduler_init();

    // Start driver and initialisation processes

    // Run scheduler
}
Exemple #29
0
int
vm_create(struct vm **retvm)
{
	struct vm *vm;

	if (!vmm_initialized)
		return (ENXIO);

	vm = malloc(sizeof(struct vm));
	assert(vm);
	bzero(vm, sizeof(struct vm));
	vm->num_mem_segs = 0;
	pthread_mutex_init(&vm->rendezvous_mtx, NULL);
	pthread_cond_init(&vm->rendezvous_sleep_cnd, NULL);

	vm_init(vm, true);

	*retvm = vm;
	return (0);
}
Exemple #30
0
int vmem_read(int address) {
	if(vmem == NULL) {							/* Pruefen ob eine Verbindung zum Shared Memory besteht*/
		vm_init();
	}
	int data;
	int page = address/VMEM_PAGESIZE;					/* Ermitlung der Pagenummer */
	int offset = address%VMEM_PAGESIZE;					/* Ermittlung des Offsets */

	vmem->adm.req_pageno = page;						/* Angeforderte Seite */
	
	sem_wait(&vmem->adm.sema);
	if((vmem->pt.entries[page].flags & PTF_PRESENT) == PTF_PRESENT) {	/* Ist die Seite im Speicher? */
		data = read_page(page, offset);					/* Wenn ja, Seite lesen */
	} else {								/* Wenn nein, Seite anfordern */
		kill(vmem->adm.mmanage_pid, SIGUSR1);				/* Sende Signal an mmanage*/
		sem_wait(&vmem->adm.sema);					/* Warte bis mmanage den Semaphor freigibt */
		data = read_page(page, offset);					/* Page lesen*/
	}
	sem_post(&vmem->adm.sema);
	return data;
}