6
var PMTIMER_FREQ_SECONDS = 3579545;
22
0x86, 0x80, 0x13, 0x71, 0x07, 0x00, 0x80, 0x02, 0x08, 0x00, 0x80, 0x06, 0x00, 0x00, 0x80, 0x00,
23
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00,
32
cpu.devices.pci.register_device(acpi);
34
this.timer_last_value = 0;
35
this.timer_imprecision_offset = 0;
40
this.last_timer = this.get_timer(v86.microtick());
42
this.gpe = new Uint8Array(4);
44
io.register_read(0xB000, this, undefined, function()
46
dbg_log("ACPI pm1_status read", LOG_ACPI);
47
return this.pm1_status;
49
io.register_write(0xB000, this, undefined, function(value)
51
dbg_log("ACPI pm1_status write: " + h(value, 4), LOG_ACPI);
52
this.pm1_status &= ~value;
55
io.register_read(0xB002, this, undefined, function()
57
dbg_log("ACPI pm1_enable read", LOG_ACPI);
58
return this.pm1_enable;
60
io.register_write(0xB002, this, undefined, function(value)
62
dbg_log("ACPI pm1_enable write: " + h(value), LOG_ACPI);
63
this.pm1_enable = value;
67
io.register_read(0xB004, this, undefined, function()
69
dbg_log("ACPI status read", LOG_ACPI);
72
io.register_write(0xB004, this, undefined, function(value)
74
dbg_log("ACPI status write: " + h(value), LOG_ACPI);
79
io.register_read(0xB008, this, undefined, undefined, function()
81
var value = this.get_timer(v86.microtick()) & 0xFFFFFF;
87
io.register_read(0xAFE0, this, function()
89
dbg_log("Read gpe#0", LOG_ACPI);
92
io.register_read(0xAFE1, this, function()
94
dbg_log("Read gpe#1", LOG_ACPI);
97
io.register_read(0xAFE2, this, function()
99
dbg_log("Read gpe#2", LOG_ACPI);
102
io.register_read(0xAFE3, this, function()
104
dbg_log("Read gpe#3", LOG_ACPI);
108
io.register_write(0xAFE0, this, function(value)
110
dbg_log("Write gpe#0: " + h(value), LOG_ACPI);
113
io.register_write(0xAFE1, this, function(value)
115
dbg_log("Write gpe#1: " + h(value), LOG_ACPI);
118
io.register_write(0xAFE2, this, function(value)
120
dbg_log("Write gpe#2: " + h(value), LOG_ACPI);
123
io.register_write(0xAFE3, this, function(value)
125
dbg_log("Write gpe#3: " + h(value), LOG_ACPI);
130
ACPI.prototype.timer = function(now)
132
var timer = this.get_timer(now);
133
var highest_bit_changed = ((timer ^ this.last_timer) & (1 << 23)) !== 0;
135
if((this.pm1_enable & 1) && highest_bit_changed)
137
dbg_log("ACPI raise irq", LOG_ACPI);
138
this.pm1_status |= 1;
139
this.cpu.device_raise_irq(9);
143
this.cpu.device_lower_irq(9);
146
this.last_timer = timer;
150
ACPI.prototype.get_timer = function(now)
152
const t = Math.round(now * (PMTIMER_FREQ_SECONDS / 1000));
157
if(t === this.timer_last_value)
161
if(this.timer_imprecision_offset < PMTIMER_FREQ_SECONDS / 1000)
163
this.timer_imprecision_offset++;
168
dbg_assert(t > this.timer_last_value);
170
const previous_timer = this.timer_last_value + this.timer_imprecision_offset;
174
if(previous_timer <= t)
176
this.timer_imprecision_offset = 0;
177
this.timer_last_value = t;
181
dbg_log("Warning: Overshot pmtimer, waiting;" +
183
" last=" + this.timer_last_value +
184
" offset=" + this.timer_imprecision_offset, LOG_ACPI);
188
return this.timer_last_value + this.timer_imprecision_offset;
191
ACPI.prototype.get_state = function()
194
state[0] = this.status;
195
state[1] = this.pm1_status;
196
state[2] = this.pm1_enable;
201
ACPI.prototype.set_state = function(state)
203
this.status = state[0];
204
this.pm1_status = state[1];
205
this.pm1_enable = state[2];