Exemple #1
0
//! Load a ROM into memory
int loadrom(const char* ROMFILE, void* addr, uint32_t total_mem)
{
	uint32_t rom_file_size;
	//! open the file in Read + Binary mode
	FILE *p = fopen(ROMFILE, "r+b");
	if (p == NULL)
	{
		FVM_EXIT(FVM_NO_ROM);
	}
	//! Get File Size
	fseek(p, 0L, SEEK_END);
	rom_file_size = ftell(p);
	fseek(p, 0L, SEEK_SET);
	printf("\nSize of ROM File : [%d] and Virtual Machine Memory : [%d]", rom_file_size, total_mem);
	//! Is size of ROM larger than available memory?
	if (rom_file_size > total_mem)
	{
		//! Yes. Exit
		FVM_EXIT(FVM_LARGE_ROM);
	}
	printf("\nROM Address to be loaded at : [%p]", (void*) addr);
	printf("\nReading ROM Image......");
	//! read the file
	fread(addr, sizeof(uint8_t), rom_file_size, p);
	printf("\nROM Reading Done.");
	return 9;
}
Exemple #2
0
FV11_RETURN_t* fv11_load(FVM_BYTE_t* Memory, int32_t memsize)
{
	/** Parse the headers**/
	 FV11_HEADER_t* ROM_HEADER = ( FV11_HEADER_t*)&Memory[0];
	if(ROM_HEADER->magic != FV11_MAGIC)
	{
		printf("ERR: [FATAL] ROM doesn't match processor version.\n");
		FVM_EXIT(FVM_PROGRAM_ERR);
	}
	int32_t _start_address = ROM_HEADER->start_addr;
	int32_t _where_to_load = ROM_HEADER->where_to_load;
	int32_t _length_of_text_section = ROM_HEADER->length_of_text;
	int32_t _start_of_data = ROM_HEADER->start_of_data;
	int32_t _where_to_load_data = ROM_HEADER->where_to_load_data;
	int32_t _length_of_data = ROM_HEADER->length_of_data;
	printf("Generating Executable Information....\n");
	printf("text_section (OFFSET) : 0x%x\ntext_section (IP) : 0x%x\ntext_section (LENGTH) : 0x%x\ndata_section (OFFSET) : 0x%x\ndata_section (IP) : 0x%x\ndata_section (LENGTH) : 0x%x\nbss_section (OFFSET) : 0x%x\nbss_section (LENGTH) : 0x%x\nstack_buf: 0x%x\n", _start_address, _where_to_load, _length_of_text_section, _start_of_data, _where_to_load_data, _length_of_data, ROM_HEADER->bss_start, ROM_HEADER->bss_length, ROM_HEADER->bss_length); 
	if(memsize < _where_to_load || memsize < _where_to_load_data || memsize < ROM_HEADER->stack_buf)
	{
		printf("fatal: This ROM requires more memory than provided [%d] [%d] [%d] [%d]\n", memsize, _where_to_load, _where_to_load_data, ROM_HEADER->stack_buf);
		FVM_EXIT(FVM_LESS_MEM_ERR);
	}
	// Do a memcpy!
	memcpy(Memory + _where_to_load, Memory + _start_address, _length_of_text_section);
	memcpy(Memory + _where_to_load_data, Memory + _start_of_data, _length_of_data);
	// Next set the pointer properly (currently it's relative to 0, we want it relative to memory)
	if(ROM_HEADER->isclassreq > 0) // Are classes required for this program?
	{
		// Yup! Load them!
		class_header_t* classes_required = (class_header_t*)&(Memory[ROM_HEADER->pointer_to_class_set]);
		for(int i = 0; i < ROM_HEADER->isclassreq; i++)
		{
			UNUSED(classes_required[0]);
		}	
	}
	//if(ROM_HEADER->isreloc > 0) // Does this executable have a relocation section?
	//{
	//	reloc_label_t* reloc_table = (reloc_label_t*)&(Memory[ROM_HEADER->pointer_to_reloc_function_table]);
	//	for(int i = 0; i < ROM_HEADER->isreloc; i++)
	//	{
	//		reloc_table[i].address += _where_to_load; // Set it to the load address.
	//	}
	//}
	// Zero out BSS
	memset(Memory + ROM_HEADER->bss_start, '\0', ROM_HEADER->bss_length);
	returnval.r11 = _where_to_load / 4;
	returnval.sp =  ROM_HEADER->stack_buf / 4;
	return &returnval;
}
Exemple #3
0
void load_file_from_disk(uint8_t* mem, const char* file_name, uint8_t* buffer, int memsize)
{
	initrd_header_t* header = (initrd_header_t*)&buffer[0];
	initrd_file_header_t* file_headers = (initrd_file_header_t*)&buffer[sizeof(initrd_header_t)];
	unsigned int i = 0;
	for(i = 0; i < header->files; i++)
	{
		if(strcmp(file_headers[i].name, file_name) == 0)
		{
			if((int)file_headers[i].length > memsize) { FVM_EXIT(FVM_LARGE_ROM); }
			memcpy(mem, buffer + file_headers[i].offset, file_headers[i].length);
			i = 0;
			break;
		}
		i++;
	}
	if(i != 0)
	{
		printf("error: Requested executable not found\n");
		FVM_EXIT(FVM_ROM_ERR);
	}
}
Exemple #4
0
void update_ppu_display(PPU_t* ppu)
{
	int buf_len = screen->pitch * screen->h;
	if(buf_len < TOTAL_PPU_MEM) { printf(" [FATAL: Current Video State cannot support PPU display\n"); FVM_EXIT(FVM_PROGRAM_ERR); }
	printf("screen_formakt: %d %d\n", screen->w, screen->h);
	uint32_t* ppu32_mem = (uint32_t*)ppu->memory;
	int j, k;
	k = 0; j = 0;
	for(int i = 0; i < TOTAL_PPU_MEM; i++)
	{
		if(j >= screen->w) { k++; j = 0; }
		if(k >= screen->h) { break; }
		display_pixel(j, k, ppu32_mem[i]);
		j++;
	}
	//private_ppu_check(ppu);
	printf("TOTAL_PPU_MEM: %d\n", TOTAL_PPU_MEM);
	FVM_SDL_updatedisplay(screen);
}