port movsb

This commit is contained in:
Awal Garg 2017-07-30 18:04:09 +05:30 committed by Fabian
parent b3c16638fc
commit f64fc51036
3 changed files with 62 additions and 1 deletions

View file

@ -200,7 +200,6 @@ function V86Starter(options)
"_outsb": function() { return cpu.outsb.apply(cpu, arguments); },
"_outsw": function() { return cpu.outsw.apply(cpu, arguments); },
"_outsd": function() { return cpu.outsd.apply(cpu, arguments); },
"_movsb": function() { return cpu.movsb.apply(cpu, arguments); },
"_movsw": function() { return cpu.movsw.apply(cpu, arguments); },
"_movsd": function() { return cpu.movsd.apply(cpu, arguments); },
"_cmpsb": function() { return cpu.cmpsb.apply(cpu, arguments); },

View file

@ -343,6 +343,7 @@ CPU.prototype.wasm_patch = function(wm)
this.get_reg_asize = this.wm.funcs['_get_reg_asize'];
this.set_ecx_asize = this.wm.funcs['_set_ecx_asize'];
this.add_reg_asize = this.wm.funcs['_add_reg_asize'];
this.movsb = this.wm.funcs['_movsb'];
};
CPU.prototype.get_state = function()

View file

@ -23,3 +23,64 @@ int32_t string_get_cycle_count2(int32_t size, int32_t addr1, int32_t addr2)
return MIN(c1, c2);
}
void movsb_rep()
{
int32_t src = get_seg_prefix(DS) + get_reg_asize(ESI);
int32_t dest = get_seg(ES) + get_reg_asize(EDI);
int32_t size = *flags & FLAG_DIRECTION ? -1 : 1;
int32_t count = get_reg_asize(ECX) >> 0;
if(count == 0) return;
int32_t cont = false;
int32_t start_count = count;
int32_t cycle_counter = MAX_COUNT_PER_CYCLE;
int32_t phys_src = translate_address_read(src);
int32_t phys_dest = translate_address_write(dest);
if(*paging)
{
cycle_counter = string_get_cycle_count2(size, src, dest);
}
do
{
write8(phys_dest, read8(phys_src));
phys_dest += size;
phys_src += size;
cont = --count != 0;
}
while(cont && cycle_counter--);
int32_t diff = size * (start_count - count) | 0;
add_reg_asize(EDI, diff);
add_reg_asize(ESI, diff);
set_ecx_asize(count);
*timestamp_counter += start_count - count;
if(cont)
{
*instruction_pointer = *previous_ip;
}
diverged();
}
void movsb_no_rep()
{
int32_t src = get_seg_prefix(DS) + get_reg_asize(ESI);
int32_t dest = get_seg(ES) + get_reg_asize(EDI);
int32_t size = *flags & FLAG_DIRECTION ? -1 : 1;
safe_write8(dest, safe_read8(src));
add_reg_asize(EDI, size);
add_reg_asize(ESI, size);
diverged();
}
void movsb()
{
if(*prefixes & PREFIX_MASK_REP)
{
movsb_rep();
}
else
{
movsb_no_rep();
}
}