port div32

This commit is contained in:
Awal Garg 2017-07-27 16:46:24 +05:30 committed by Fabian
parent 30dae42b52
commit 18b8ebf4ba
4 changed files with 27 additions and 2 deletions

View file

@ -195,7 +195,6 @@ function V86Starter(options)
"_load_tr": function() { return cpu.load_tr.apply(cpu, arguments); },
"_idiv16": function() { return cpu.idiv16.apply(cpu, arguments); },
"_div32": function() { return cpu.div32.apply(cpu, arguments); },
"_idiv32": function() { return cpu.idiv32.apply(cpu, arguments); },
"_insb": function() { return cpu.insb.apply(cpu, arguments); },
"_insw": function() { return cpu.insw.apply(cpu, arguments); },

View file

@ -278,6 +278,7 @@ CPU.prototype.wasm_patch = function(wm)
this.raise_exception_with_code = this.wm.funcs['_raise_exception_with_code'];
this.trigger_de = this.wm.funcs['_trigger_de'];
this.trigger_gp = this.wm.funcs['_trigger_gp'];
this.div32 = this.wm.funcs['_div32'];
this.shl8 = this.wm.funcs['_shl8'];
this.shl16 = this.wm.funcs['_shl16'];

View file

@ -815,6 +815,31 @@ void div16(uint32_t source_operand)
}
}
void div32(uint32_t source_operand)
{
if(source_operand == 0)
{
trigger_de();
return;
}
uint32_t target_low = reg32s[EAX];
uint32_t target_high = reg32s[EDX];
uint64_t target_operand = (((uint64_t) target_high) << 32) | ((uint64_t) target_low);
uint64_t result = target_operand / source_operand;
if(result > UINT32_MAX)
{
trigger_de();
return;
}
int32_t mod = target_operand % source_operand;
reg32s[EAX] = result;
reg32s[EDX] = mod;
}
int32_t shl8(int32_t dest_operand, int32_t count)
{
if(count == 0)

View file

@ -183,7 +183,7 @@ int32_t rcr32(int32_t, int32_t);
int32_t rcl32(int32_t, int32_t);
int32_t idiv16(int32_t);
int32_t div32(int32_t);
void div32(uint32_t);
int32_t idiv32(int32_t);