Esempio n. 1
0
void restart()
{
    /* Perform some initialization to restart a program */
    memcpy(hwa_to_va(LOADER_START), loader, loader_len);
    tlb_init();

    /* General initialization */
    cpu.eip = LOADER_START;
    cpu.ebp = 0;
    cpu.esp = 0x8000000;
    cpu.eflags = 0x2;
    cpu.eax = 0;
    cpu.ecx = 0;
    cpu.edx = 0;
    cpu.cr0.paging = 0;
    cpu.cr0.protect_enable = 0;
    cpu.INTR = 0;
    FLAG_CHG(IF, 0);

    /* Segment initialization */
    cpu.gdtr.limit = 0;
    cpu.gdtr.base = 0;
    cpu.cr[0] = 0; // Set PE to 0

    load_prog();

   // trigger = TRIGGER_INIT;

    init_dram();

}
Esempio n. 2
0
static void load_entry() {
	int ret;
	FILE *fp = fopen("entry", "rb");
	Assert(fp, "Can not open 'entry'");

	fseek(fp, 0, SEEK_END);
	size_t file_size = ftell(fp);

	fseek(fp, 0, SEEK_SET);
	ret = fread(hwa_to_va(ENTRY_START), file_size, 1, fp);
	assert(ret == 1);
	fclose(fp);
}
Esempio n. 3
0
static void init_ramdisk() {
	int ret;
	const int ramdisk_max_size = 0xa0000;
	FILE *fp = fopen(exec_file, "rb");
	Assert(fp, "Can not open '%s'", exec_file);

	fseek(fp, 0, SEEK_END);
	size_t file_size = ftell(fp);
	Assert(file_size < ramdisk_max_size, "file size(%zd) too large", file_size);

	fseek(fp, 0, SEEK_SET);
	ret = fread(hwa_to_va(0), file_size, 1, fp);
	assert(ret == 1);
	fclose(fp);
}
Esempio n. 4
0
void load_prog() {
	struct stat st;
	stat(exec_file, &st);
	assert(st.st_size < 0xa0000);

	FILE *fp = fopen(exec_file, "rb");
	assert(fp);

	/* We do not have a virtual hard disk now. Before we have a virutal hard disk,
	 * the beginning of physical memory is used as a "disk". The loader in NEMU
	 * will load the program from this "disk" (at the beginning of the physical
	 * memory).
	 */
	fread(hwa_to_va(0), st.st_size, 1, fp);
	fclose(fp);
}
Esempio n. 5
0
void bmr_io_handler(ioaddr_t addr, size_t len, bool is_write) {
	int ret;
	if(is_write) {
		if(addr - BMR_PORT == 0) {
			if(bmr_base[0] & 0x1) {
				/* DMA start command */
				if(bmr_base[0] & 0x8) {
					/* DMA read */

					/* the address of Physical Region Descriptor Table */
					hwaddr_t prdt_addr = *(uint32_t *)(bmr_base + 4);

					hwaddr_t addr = hwaddr_read(prdt_addr, 4);
					uint32_t hi_entry = hwaddr_read(prdt_addr + 4, 4);
					uint16_t byte_cnt = hi_entry & 0xffff;

					sector = (ide_port_base[6] & 0x1f) << 24 | ide_port_base[5] << 16
						| ide_port_base[4] << 8 | ide_port_base[3];
					disk_idx = sector << 9;
					fseek(disk_fp, disk_idx, SEEK_SET);

					ret = fread((void *)hwa_to_va(addr), byte_cnt, 1, disk_fp);
					assert(ret == 1|| feof(disk_fp));

					/* We only implement PRDT of single entry. */
					assert(hi_entry & 0x80000000);

					/* finish */
					ide_port_base[7] = 0x40;
					i8259_raise_intr(IDE_IRQ);
				}
				else {
					/* DMA write is not implemented */
					assert(0);
				}
			}
		}
	}
}
Esempio n. 6
0
void restart() {
	/* Perform some initialization to restart a program */
	load_prog();
	memcpy(hwa_to_va(LOADER_START), loader, loader_len);

	cpu.eip = LOADER_START;
	cpu.ebp = 0;
	cpu.esp = 0x8000000;
	cpu.eflags = 2;

	init_dram();
	init_cache1();
	init_cache2();
	init_TLB();

	/* initialize limit of cs in gdt */
//	printf("%x\n",cpu.gdtr.base);
//	uint16_t *cs_limit =(void *)(0x90901700 + 64);
//	*cs_limit = 0xffff;
	seg_cache[1].limit = 0xffffffff;//can't modify memory in 0x90901700

//	*cs_limit = 0xffff;//other bits are initialized by 0
}