currently I only am trying to get all of the 8086 opcodes..
if anyone knows something about x86 archietecture such as modrm and such...
attached is a fairly updated list of what all opcodes I have implemented..
now I know that it is hard to just step into a project and code stuff for it...so I will allow basic incorrect stuff that I will have to make minor modifications to
here's a short list of how to do a bit of stuff
memory stuff:
MemRead8(short segment,short offset) for reading memory(and change 8 to 16 or whatever)
MemWrite8(short segment,short offset, byte) for writing memory
flags:
just use something like
to set CF use flags->cf=1; and IF use flags->_if=1; (prevent the if conflict)
registers:
use *gregs8[register] for 8bit registers such as
*gregs8[AH]=0xFF; and this will set AH to 0xff..(make sure not to forget the *)
and then use gregs8[register] for 16bit registers such as
gregs16[AX]=0xFFFF; and this will set AX to 0xFFFF
finally, for segment registers use sregs[segment] such as
sregs[DS]=0xFFFF; adn this will set DS to 0xFFFF
if I have an opcode listed that is similar to what you want to implement, then I probably already have a simple "template" stub function, such as..
for sub al,imm8 I have a function called result=sub8(char base,char subtractor);
so instead of doing all the flag stuff for sub, you can just use that function..
for the SVN code goto http://sourceforge.net/projects/open86
you can either submit a patch file to the SF project site, or you can post your code here..
now then!
if you want to go EVEN further!
for modrm you can use these fairly simple templates..
Code: Select all
/******MODRM templates!!!!
these are some simple templates to make using modrm instructions much easier to use
void template_modrm16_r16(){
unsigned short *ptr;
unsigned int tmp;
mod_rm rm[1];
ip++;
MemRead8(CS,ip,rm); //store rm because we need 'extra'
tmp=GetModRM_write16(&ptr);
if(tmp==0){ //is normal and ptr contains the memory address
(unsigned long)ptr=(unsigned long)ptr+(unsigned long)core;
//*ptr is the destination, gregs16[rm[0].extra] is the source/operand
return;
}
if(tmp==OPCODE_SPECIFIC){
//gregs16[rm[0].rm] is the destination, gregs16[rm[0].extra] is the source/operand
return;
}
panic("errors not yet handled!!");
}
void template_modrm8_r8(){
unsigned char *ptr;
unsigned int tmp;
mod_rm rm[1];
ip++;
MemRead8(CS,ip,rm); //store rm because we need 'extra'
tmp=GetModRM_write8(&ptr);
if(tmp==0){ //is normal and ptr contains the memory address
ptr=ptr+(unsigned long)core;
//*ptr is the destination, *gregs8[rm[0].extra] is the source/operand
return;
}
if(tmp==OPCODE_SPECIFIC){
//*gregs8[rm[0].rm] is the destination, *gregs8[rm[0].extra] is the source/operand
return;
}
panic("errors not yet handled!!");
}
void template_r8_modrm8(){
unsigned char *ptr;
unsigned int tmp;
mod_rm rm[1];
ip++;
MemRead8(CS,ip,rm); //store rm because we need 'extra'
tmp=GetModRM_read8(&ptr);
if(tmp==0){ //is normal and ptr contains the memory address
ptr=ptr+(unsigned long)core;
//*gregs8[rm[0].extra] is the destination, *ptr is source/operand
return;
}
if(tmp==OPCODE_SPECIFIC){
//*gregs8[rm[0].extra] is the destination, *gregs8[rm[0].rm] is the source/operand
return;
}
panic("errors not yet handled!!");
}
void template_r16_modrm16(){
unsigned short *ptr;
unsigned int tmp;
mod_rm rm[1];
ip++;
MemRead8(CS,ip,rm); //store rm because we need 'extra'
tmp=GetModRM_read16(&ptr);
if(tmp==0){ //is normal and ptr contains the memory address
(unsigned long)ptr=(unsigned long)ptr+(unsigned long)core;
//gregs16[rm[0].extra] is the destination, *ptr is source/operand
return;
}
if(tmp==OPCODE_SPECIFIC){
//gregs16[rm[0].extra] is the destination, gregs16[rm[0].rm] is the source/operand
return;
}
panic("errors not yet handled!!");
}
void template_sreg16_modrm16(){
unsigned short *ptr;
unsigned int tmp;
mod_rm rm[1];
ip++;
MemRead8(CS,ip,rm); //store rm because we need 'extra'
tmp=GetModRM_read16(&ptr);
if(tmp==0){ //is normal and ptr contains the memory address
(unsigned long)ptr=(unsigned long)ptr+(unsigned long)core;
//sregs[rm[0].extra] is the destination, *ptr is source/operand
return;
}
if(tmp==OPCODE_SPECIFIC){
//gregs16 should USUALLY be the proper one, but being opcode specific this could be
//other things..
//sregs[rm[0].extra] is the destination, gregs16[rm[0].rm] is the source/operand
return;
}
panic("errors not yet handled!!");
}
void template_modrm16_sreg16(){
unsigned short *ptr;
unsigned int tmp;
mod_rm rm[1];
ip++;
MemRead8(CS,ip,rm); //store rm because we need 'extra'
tmp=GetModRM_write16(&ptr);
if(tmp==0){ //is normal and ptr contains the memory address
(unsigned long)ptr=(unsigned long)ptr+(unsigned long)core;
//*ptr is the destination, sregs[rm[0].extra] is the source/operand
return;
}
if(tmp==OPCODE_SPECIFIC){
//gregs16 should USUALLY be the proper one, but being opcode specific this could be
//other things..(including an invalid opcode exception)
//gregs16[rm[0].rm] is the destination, sregs[rm[0].extra] is the source/operand
return;
}
panic("errors not yet handled!!");
}
there a bit hard to understand maybe..but you should get the just of it..
btw, put your code in the "if(tmp==..){" (right after the comments but before the "}"