rem: dbg_add_command(&dump_region_list, "regions", "Dump a list of all regions"); dbg_add_command(&dump_region, "region", "Dump info about a particular region"); dbg_add_command(&dump_aspace_list, "aspaces", "Dump a list of all address spaces"); dbg_add_command(&dump_aspace, "aspace", "Dump info about a particular address space"); dbg_add_command(&dump_cache_ref, "cache_ref", "Dump cache_ref data structure"); dbg_add_command(&dump_cache, "cache", "Dump cache_ref data structure");  dbg_add_command(&display_mem, "dw", "dump memory words (32-bit)"); dbg_add_command(&display_mem, "ds", "dump memory shorts (16-bit)"); dbg_add_command(&display_mem, "db", "dump memory bytes (8-bit)");
add: add_debugger_command("regions", &dump_region_list, "Dump a list of all regions"); add_debugger_command("region", &dump_region, "Dump info about a particular region"); add_debugger_command("aspaces", &dump_aspace_list, "Dump a list of all address spaces"); add_debugger_command("aspace", &dump_aspace, "Dump info about a particular address space"); add_debugger_command("cache_ref", &dump_cache_ref, "Dump cache_ref data structure"); add_debugger_command("cache", &dump_cache, "Dump cache_ref data structure");  add_debugger_command("dw", &display_mem, "dump memory words (32-bit)"); add_debugger_command("ds", &display_mem, "dump memory shorts (16-bit)"); add_debugger_command("db", &display_mem, "dump memory bytes (8-bit)");
context: int vm_init(kernel_args *ka){	int err = 0;	unsigned int i;//	int last_used_virt_range = -1;//	int last_used_phys_range = -1;	addr heap_base;	void *null_addr;	dprintf("vm_init: entry\n");	err = vm_translation_map_module_init(ka);	err = arch_vm_init(ka);	// initialize some globals	kernel_aspace = NULL;	next_region_id = 0;	region_hash_sem = -1;	next_aspace_id = 0;	aspace_hash_sem = -1;	max_commit = 0; // will be increased in vm_page_init	max_commit_lock = 0;	// map in the new heap and initialize it	heap_base = vm_alloc_from_ka_struct(ka, HEAP_SIZE, LOCK_KERNEL|LOCK_RW);	dprintf("heap at 0x%lx\n", heap_base);	heap_init(heap_base, HEAP_SIZE);	// initialize the free page list and physical page mapper	vm_page_init(ka);	// initialize the hash table that stores the pages mapped to caches	vm_cache_init(ka);	// create the region and address space hash tables	{		vm_address_space *aspace;		aspace_table = hash_init(ASPACE_HASH_TABLE_SIZE, (addr)&aspace->hash_next - (addr)aspace,			&aspace_compare, &aspace_hash);		if(aspace_table == NULL)			panic("vm_init: error creating aspace hash table\n");	}	{		vm_region *region;		region_table = hash_init(REGION_HASH_TABLE_SIZE, (addr)&region->hash_next - (addr)region,			&region_compare, &region_hash);		if(region_table == NULL)			panic("vm_init: error creating aspace hash table\n");	}	// create the initial kernel address space	{		aspace_id aid;		aid = vm_create_aspace("kernel_land", KERNEL_BASE, KERNEL_SIZE, true);		if(aid < 0)			panic("vm_init: error creating kernel address space!\n");		kernel_aspace = vm_get_aspace_by_id(aid);		vm_put_aspace(kernel_aspace);	}	// do any further initialization that the architecture dependant layers may need now	vm_translation_map_module_init2(ka);	arch_vm_init2(ka);	vm_page_init2(ka);	// allocate regions to represent stuff that already exists	null_addr = (void *)ROUNDOWN(heap_base, PAGE_SIZE);	vm_create_anonymous_region(vm_get_kernel_aspace_id(), "kernel_heap", &null_addr, REGION_ADDR_EXACT_ADDRESS,		HEAP_SIZE, REGION_WIRING_WIRED_ALREADY, LOCK_RW|LOCK_KERNEL);	null_addr = (void *)ROUNDOWN(ka->kernel_seg0_addr.start, PAGE_SIZE);	vm_create_anonymous_region(vm_get_kernel_aspace_id(), "kernel_ro", &null_addr, REGION_ADDR_EXACT_ADDRESS,		PAGE_ALIGN(ka->kernel_seg0_addr.size), REGION_WIRING_WIRED_ALREADY, LOCK_RW|LOCK_KERNEL);	if(ka->kernel_seg1_addr.size > 0) {		null_addr = (void *)ROUNDOWN(ka->kernel_seg1_addr.start, PAGE_SIZE);		vm_create_anonymous_region(vm_get_kernel_aspace_id(), "kernel_rw", &null_addr, REGION_ADDR_EXACT_ADDRESS,			PAGE_ALIGN(ka->kernel_seg1_addr.size), REGION_WIRING_WIRED_ALREADY, LOCK_RW|LOCK_KERNEL);	}	for(i=0; i < ka->num_cpus; i++) {		char temp[64];		sprintf(temp, "idle_thread%d_kstack", i);		null_addr = (void *)ka->cpu_kstack[i].start;		vm_create_anonymous_region(vm_get_kernel_aspace_id(), temp, &null_addr, REGION_ADDR_EXACT_ADDRESS,			ka->cpu_kstack[i].size, REGION_WIRING_WIRED_ALREADY, LOCK_RW|LOCK_KERNEL);	}	{		void *null;		vm_map_physical_memory(vm_get_kernel_aspace_id(), "bootdir", &null, REGION_ADDR_ANY_ADDRESS,			ka->bootdir_addr.size, LOCK_RO|LOCK_KERNEL, ka->bootdir_addr.start);	}	arch_vm_init_endvm(ka);	// add some debugger commands	dbg_add_command(&dump_region_list, "regions", "Dump a list of all regions");	dbg_add_command(&dump_region, "region", "Dump info about a particular region");	dbg_add_command(&dump_aspace_list, "aspaces", "Dump a list of all address spaces");	dbg_add_command(&dump_aspace, "aspace", "Dump info about a particular address space");	dbg_add_command(&dump_cache_ref, "cache_ref", "Dump cache_ref data structure");	dbg_add_command(&dump_cache, "cache", "Dump cache_ref data structure");//	dbg_add_command(&display_mem, "dl", "dump memory long words (64-bit)");	dbg_add_command(&display_mem, "dw", "dump memory words (32-bit)");	dbg_add_command(&display_mem, "ds", "dump memory shorts (16-bit)");	dbg_add_command(&display_mem, "db", "dump memory bytes (8-bit)");	dprintf("vm_init: exit\n");	return err;}