Wrap PIT counter value - always

After restore_state, the pit.counter_start_time can be larger
than the current timestamp, leading to negative diff values, and
as a result, when get_counter_value is called, it can return
values larger than 16 bit integers. Thus, when ISA ports 0x40, 0x41, or
0x42 are read, the high-byte that counter_write returns can be larger
than 8-bit. Ultimately, this error is caught by the asserts in io.js. By
always applying a positive modulo to the counter value, it is always
ensured that the counter value is between zero and the reload value.
This commit is contained in:
Ernest Wong 2017-11-15 08:57:03 +13:00 committed by Fabian
parent 5c0e87b3e9
commit 818a6c211f

View file

@ -132,11 +132,9 @@ PIT.prototype.get_counter_value = function(i, now)
dbg_log("diff=" + diff + " dticks=" + diff_in_ticks + " value=" + value + " reload=" + this.counter_reload[i], LOG_PIT);
if(value < 0)
{
var reload = this.counter_reload[i];
value = value % reload + reload;
}
// could be too large after restore_state
var reload = this.counter_reload[i];
value = (value % reload + reload) % reload;
return value;
};