Ajout visualisateur de mémoire

This commit is contained in:
Horde Nicolas 2021-07-11 18:20:28 +02:00
parent d52a76a88e
commit 7c57e86f81
3 changed files with 45 additions and 10 deletions

View File

@ -676,12 +676,41 @@ uint32_t VMEngine::getNextInstr()
return 0;
}
std::string VMEngine::getRam(int segment, int address,int lines, int linesize)
{
int reallinesize=(int)((linesize-16)/4);
int size=reallinesize*(lines-3);
uint32_t realaddress=segment*16+address;
uint8_t *code=new uint8_t[512];
std::string result="";
std::string line;
err = uc_mem_read(uc, realaddress, code, 500);
if (err)
throw Error("VM IA86 - voir mémoire............................[ERREUR]");
for(size_t i=0;i<size;i++)
{
if ((i%reallinesize)==0)
{
if (i!=0)
result+=" | "+line+"\n";
result+=intToHexString(address+i,8)+" | ";
line="";
}
result+=intToHexString(code[i],2)+" ";
if (std::isprint(code[i]))
line+=(char)code[i];
else
line+='.';
}
result+=" | "+line+"\n";
return result;
}
std::vector<std::array<std::string, 5>> VMEngine::getInstr(int segment, int address,int size)
{
uint32_t realaddress=segment*16+address;
if (realaddress<bufferaddress || realaddress+(size*7)>bufferaddress+500)
{
log->append("read");
bufferaddress=realaddress-30;
if (bufferaddress<0)
bufferaddress=0x00000000;
@ -695,7 +724,6 @@ std::vector<std::array<std::string, 5>> VMEngine::getInstr(int segment, int addr
crc = crc32(0, code, 500);
if (crc != crc_old)
{
log->append("unasm");
unasmer.Desassemble(code, address_old, 500, &unasm);
if (unasm.src.size()==0)
throw Error("VM IA86 - cache instructions......................[ERREUR]");
@ -945,10 +973,7 @@ void VMEngine::Run(uint32_t end,uint64_t timeout)
{
err=uc_emu_start(uc, this->getCurrent(), end, timeout, 0);
if (err)
{
this->Halt();
throw Error("VM IA86 - execution...............................[ERREUR]");
}
else
{
if (!this->executed)
@ -959,6 +984,7 @@ void VMEngine::Run(uint32_t end,uint64_t timeout)
}
catch(exception const& e)
{
this->Halt();
log->append(e.what());
}
}
@ -1288,6 +1314,7 @@ void Menu::showInstr()
{
debug.set(vm.getInstr(vm.getCS(),vm.getEIP(),debug.getHeight()-3));
debug.setmark(vm.getLine());
mem.set(vm.getRam(vm.getDS(), 0x0000, mem.getHeight(),mem.getWidth()));
}
}
catch(exception const& e)
@ -1303,6 +1330,8 @@ void Menu::refresh()
{
regs.set("En attente d'initialisation...");
flags.set("Attente...");
stack.set("Attente...");
mem.set("En attente d'initialisation...");
}
else
{

6
ia86.h
View File

@ -309,6 +309,7 @@ class VMEngine
std::vector<std::array<std::string, 5>> getInstr(int segment, int address,int size);
void SetMem(Code *code);
void SetRegs(State *init);
std::string getRam(int segment, int address,int lines, int linesize);
int verify();
bool isExecuted();
bool isInitialized();
@ -385,6 +386,11 @@ class Menu final : public finalcut::FDialog
finalcut::FMenuItem Line2{&Game};
finalcut::FMenuItem Quit{"&Quitter", &Game};
finalcut::FMenu Options{"&Options", &Menubar};
//finalcut::FMenu Memory{"&Mémoire", &Options};
//finalcut::FRadioMenuItem Ds_esi{"DS:ESI", &Memory};
//finalcut::FRadioMenuItem Es_edi{"ES:EDI", &Memory};
//finalcut::FRadioMenuItem Cs_eip{"CS:EIP", &Memory};
//finalcut::FRadioMenuItem Ss_sp{"SS:SP", &Memory};
finalcut::FMenu Tools{"&Outils", &Menubar};
finalcut::FMenuItem Assemble{"&Compilation", &Tools};
finalcut::FMenuItem Rearange{"&Ordonne les fenêtres", &Tools};

View File

@ -56,14 +56,14 @@ mov es,ax
"niveau_description" : "Il faut connaitre...",
"niveau_tutoriel" : "Ceci vous...",
"niveau_code" : "mov ax,0x545
pop:
_pour:
inc dx
lea ebx,[pop]
lea ebx,[_pour]
db 'c','e','c','i',' ','e','s','t',' ','u','n',' ','t','e','s','t',0
.org 0x9000
pop:
_pour:
db 0x00
lea eax,[pop]
lea eax,[_pour]
mov esi,0x44441234
.org 0x3002
hlt",