Started work on NVRAM

Tried to also fix some issued with MSVC
This commit is contained in:
dingusdev 2020-01-05 09:52:46 -07:00
parent 0221bcb9a2
commit b5074e4ce1
7 changed files with 119 additions and 25 deletions

View File

@ -161,7 +161,7 @@ extern uint32_t rev_endian32(uint32_t insert_int);
extern uint64_t rev_endian64(uint64_t insert_int);
/* The precise reason for the termination of a basic block. */
enum BB_end_reason {
enum class BB_end_reason {
BB_BRANCH = 1, /* a branch instruction is encountered */
BB_EXCEPTION, /* an exception is occured */
BB_RFI /* the rfi instruction is encountered */

View File

@ -862,7 +862,7 @@ void ppc_mulhwu(){
ppc_grab_regsdab();
uiproduct = (uint64_t) ppc_result_a * (uint64_t) ppc_result_b;
uiproduct = uiproduct >> 32;
ppc_result_d = uiproduct;
ppc_result_d = (uint32_t) uiproduct;
ppc_store_result_regd();
}
@ -870,7 +870,7 @@ void ppc_mulhwudot(){
ppc_grab_regsdab();
uiproduct = (uint64_t) ppc_result_a * (uint64_t) ppc_result_b;
uiproduct = uiproduct >> 32;
ppc_result_d = uiproduct;
ppc_result_d = (uint32_t)uiproduct;
ppc_changecrf0(ppc_result_d);
ppc_store_result_regd();
}
@ -902,7 +902,7 @@ void ppc_mullw(){
void ppc_mullwdot(){
ppc_grab_regsdab();
siproduct = ppc_result_a * ppc_result_b;
siproduct = (int64_t)ppc_result_a * (int64_t)ppc_result_b;
siproduct &= 4294967295;
ppc_result_d = (uint32_t) siproduct;
ppc_changecrf0(ppc_result_d);
@ -912,7 +912,7 @@ void ppc_mullwdot(){
void ppc_mullwo(){
ppc_grab_regsdab();
ppc_setsoov(ppc_result_a, ppc_result_b);
siproduct = ppc_result_a * ppc_result_b;
siproduct = (int64_t)ppc_result_a * (int64_t)ppc_result_b;
siproduct &= 4294967295;
ppc_result_d = (uint32_t) siproduct;
ppc_store_result_regd();
@ -921,7 +921,7 @@ void ppc_mullwo(){
void ppc_mullwodot(){
ppc_grab_regsdab();
ppc_setsoov(ppc_result_a, ppc_result_b);
siproduct = ppc_result_a * ppc_result_b;
siproduct = (int64_t)ppc_result_a * (int64_t)ppc_result_b;
siproduct &= 4294967295;
ppc_result_d = (uint32_t) siproduct;
ppc_changecrf0(ppc_result_d);
@ -1406,7 +1406,7 @@ void ppc_b(){
ppc_next_instruction_address = (uint32_t)(ppc_state.ppc_pc + adr_li);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
void ppc_bl(){
@ -1416,7 +1416,7 @@ void ppc_bl(){
ppc_state.ppc_spr[8] = (uint32_t)(ppc_state.ppc_pc + 4);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
void ppc_ba(){
@ -1425,7 +1425,7 @@ void ppc_ba(){
ppc_next_instruction_address = adr_li;
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
void ppc_bla(){
@ -1435,7 +1435,7 @@ void ppc_bla(){
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
void ppc_bc()
@ -1456,7 +1456,7 @@ void ppc_bc()
ppc_next_instruction_address = (ppc_state.ppc_pc + br_bd);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
}
@ -1478,7 +1478,7 @@ void ppc_bca()
ppc_next_instruction_address = br_bd;
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
}
@ -1500,7 +1500,7 @@ void ppc_bcl()
ppc_next_instruction_address = (ppc_state.ppc_pc + br_bd);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
@ -1523,7 +1523,7 @@ void ppc_bcla()
ppc_next_instruction_address = br_bd;
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
@ -1539,7 +1539,7 @@ void ppc_bcctr()
ppc_next_instruction_address = (ppc_state.ppc_spr[9] & 0xFFFFFFFCUL);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
}
@ -1554,7 +1554,7 @@ void ppc_bcctrl()
ppc_next_instruction_address = (ppc_state.ppc_spr[9] & 0xFFFFFFFCUL);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
@ -1576,7 +1576,7 @@ void ppc_bclr()
ppc_next_instruction_address = (ppc_state.ppc_spr[8] & 0xFFFFFFFCUL);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
}
@ -1597,7 +1597,7 @@ void ppc_bclrl()
ppc_next_instruction_address = (ppc_state.ppc_spr[8] & 0xFFFFFFFCUL);
grab_branch = 1;
bb_end = true;
bb_kind = BB_BRANCH;
bb_kind = BB_end_reason::BB_BRANCH;
}
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
@ -1751,7 +1751,7 @@ void ppc_rfi(){
grab_return = true;
bb_end = true;
bb_kind = BB_RFI;
bb_kind = BB_end_reason::BB_RFI;
}
void ppc_sc(){

View File

@ -14,7 +14,9 @@ using namespace std;
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow")
{
this->viacuda = new ViaCuda();
this->nvram = new NVram();
assert(this->viacuda); // FIXME: do proper exception handling!
assert(this->nvram); // FIXME: do proper exception handling!
}
HeathrowIC::~HeathrowIC()
@ -75,7 +77,7 @@ uint32_t HeathrowIC::read(uint32_t offset, int size)
res = this->viacuda->read((offset - 0x16000) >> 9);
break;
default:
cout << "unmapped I/O space" << endl;
cout << "unmapped I/O space: " << sub_dev << endl;
}
return res;
@ -102,7 +104,7 @@ void HeathrowIC::write(uint32_t offset, uint32_t value, int size)
this->viacuda->write((offset - 0x16000) >> 9, value);
break;
default:
cout << "unmapped I/O space" << endl;
cout << "unmapped I/O space: " << sub_dev << endl;
}
}

View File

@ -36,6 +36,7 @@
#include "mmiodevice.h"
#include "pcihost.h"
#include "viacuda.h"
#include "nvram.h"
/**
Heathrow ASIC emulation
@ -104,6 +105,7 @@ private:
/* device cells */
ViaCuda *viacuda; /* VIA cell with Cuda MCU attached to it */
NVram *nvram; /* NVRAM cell */
};
#endif /* MACIO_H */

58
devices/nvram.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
#include <fstream>
#include <cinttypes>
#include "nvram.h"
using namespace std;
NVram::NVram()
{
this->nvram_init();
}
NVram::~NVram()
{
this->nvram_save();
}
void NVram::nvram_init() {
NVram::nvram_file.open("nvram.bin", ios::in | ios::out | ios::binary);
if (nvram_file.fail()) {
std::cout << "Warning: Could not find the NVRAM file. This will be blank. \n" << endl;
NVram::nvram_file.write(0x00, 8192);
return;
}
NVram::nvram_file.seekg(0, nvram_file.end);
NVram::nvram_filesize = nvram_file.tellg();
NVram::nvram_file.seekg(0, nvram_file.beg);
if (NVram::nvram_filesize != 0x2000) {
NVram::nvram_file.write(0x00, 8192);
}
char temp_storage[8192];
NVram::nvram_file.read(temp_storage, 8192);
//hack copying to the NVRAM Array GO!
for (int i = 0; i < 8192; i++)
{
NVram::nvram_storage[i] = (uint8_t) temp_storage[i];
}
}
void NVram::nvram_save() {
NVram::nvram_file.write((char*)nvram_storage, 8192);
}
uint8_t NVram::nvram_read(uint32_t nvram_offset){
nvram_value = NVram::nvram_storage[nvram_offset];
return nvram_value;
}
void NVram::nvram_write(uint32_t nvram_offset, uint8_t write_val){
NVram::nvram_storage[nvram_offset] = write_val;
}

32
devices/nvram.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef NVRAM_H
#define NVRAM_H
#include <iostream>
#include <fstream>
#include <cinttypes>
class NVram
{
public:
NVram();
~NVram();
uint8_t read(int value);
void write(int reg, uint8_t value);
private:
std::fstream nvram_file; //NVRAM file for storing and reading values
/* NVRAM state. */
uint32_t nvram_offset;
uint32_t nvram_filesize;
uint8_t nvram_value;
uint8_t nvram_storage[8192];
void nvram_init();
void nvram_save();
uint8_t nvram_read(uint32_t nvram_offset);
void nvram_write(uint32_t nvram_offset, uint8_t write_val);
};
#endif /* NVRAM_H */

View File

@ -130,7 +130,7 @@ void ppc_exception_handler(uint32_t exception_type, uint32_t handle_args){
ppc_next_instruction_address = 0x0; //used to construct a new address
grab_exception = true;
bb_end = 0;
bb_kind = BB_EXCEPTION;
bb_kind = BB_end_reason::BB_EXCEPTION;
printf("MSR VALUE: %x \n Exception Type: %x", ppc_state.ppc_msr, exception_type);
@ -356,7 +356,7 @@ int main(int argc, char **argv)
//Calculate and validate ROM file size.
romFile.seekg(0, romFile.end);
rom_filesize = romFile.tellg();
rom_filesize = (uint32_t) romFile.tellg();
printf("Rom SIZE: %d \n", rom_filesize);
romFile.seekg (0, romFile.beg);
@ -424,7 +424,7 @@ int main(int argc, char **argv)
switch(rom_id) {
case 0x476F7373: {
cout << "Initialize Gossamer hardware...";
cout << "Initialize Gossamer hardware..." << endl;
MPC106 *mpc106 = new MPC106();
mem_ctrl_instance = mpc106;
if (!mem_ctrl_instance->add_rom_region(0xFFC00000, 0x400000)) {
@ -479,7 +479,7 @@ int main(int argc, char **argv)
char elf_memoffset [4];
elfFile.seekg(0, elfFile.end);
elf_file_setsize = elfFile.tellg();
elf_file_setsize = (uint32_t) elfFile.tellg();
elfFile.seekg (0, elfFile.beg);
if (elf_file_setsize < 45){