Port reset_cpu to rust

This commit is contained in:
Fabian 2021-03-30 20:56:37 -05:00
parent d7fd55e4f1
commit 9ab71cd39a
5 changed files with 104 additions and 87 deletions

View file

@ -213,6 +213,8 @@ CPU.prototype.wasm_patch = function()
return f;
};
this.reset_cpu = get_import("reset_cpu");
this.getiopl = get_import("getiopl");
this.vm86_mode = get_import("vm86_mode");
this.get_eflags = get_import("get_eflags");
@ -223,7 +225,6 @@ CPU.prototype.wasm_patch = function()
this.trigger_np = get_import("trigger_np");
this.trigger_ss = get_import("trigger_ss");
this.switch_cs_real_mode = get_import("switch_cs_real_mode");
this.pic_call_irq = get_import("pic_call_irq");
this.do_many_cycles_native = get_import("do_many_cycles_native");
@ -592,96 +593,16 @@ CPU.prototype.main_run = function()
CPU.prototype.reboot_internal = function()
{
this.reset();
this.load_bios();
};
this.reset_cpu();
CPU.prototype.reset = function()
{
this.segment_is_null.fill(0);
this.segment_limits.fill(0);
//this.segment_infos = new Uint32Array(8);
this.segment_offsets.fill(0);
this.reg32.fill(0);
this.sreg.fill(0);
this.dreg.fill(0);
this.fpu_st.fill(0);
this.fpu_stack_empty[0] = 0xFF;
this.fpu_stack_ptr[0] = 0;
this.fpu_control_word[0] = 0x37F;
this.fpu_status_word[0] = 0;
this.fpu_ip[0] = 0;
this.fpu_ip_selector[0] = 0;
this.fpu_opcode[0] = 0;
this.fpu_dp[0] = 0;
this.fpu_dp_selector[0] = 0;
this.reg_xmm32s.fill(0);
this.mxcsr[0] = 0x1F80;
this.full_clear_tlb();
this.protected_mode[0] = +false;
// http://www.sandpile.org/x86/initial.htm
this.idtr_size[0] = 0;
this.idtr_offset[0] = 0;
this.gdtr_size[0] = 0;
this.gdtr_offset[0] = 0;
this.page_fault[0] = 0;
this.cr[0] = 1 << 30 | 1 << 29 | 1 << 4;
this.cr[2] = 0;
this.cr[3] = 0;
this.cr[4] = 0;
this.dreg[6] = 0xFFFF0FF0|0;
this.dreg[7] = 0x400;
this.cpl[0] = 0;
this.is_32[0] = +false;
this.stack_size_32[0] = +false;
this.prefixes[0] = 0;
this.last_virt_eip[0] = -1;
this.instruction_counter[0] = 0;
this.previous_ip[0] = 0;
this.in_hlt[0] = +false;
this.sysenter_cs[0] = 0;
this.sysenter_esp[0] = 0;
this.sysenter_eip[0] = 0;
this.flags[0] = flags_default;
this.flags_changed.fill(0);
this.last_result.fill(0);
this.last_op1.fill(0);
this.last_op_size.fill(0);
this.set_tsc(0, 0);
this.instruction_pointer[0] = 0xFFFF0;
this.switch_cs_real_mode(0xF000);
this.sreg[reg_ss] = 0x30;
this.segment_is_null[reg_ss] = 0;
this.segment_offsets[reg_ss] = 0x30 << 4;
this.stack_size_32[0] = +false;
this.reg32[reg_esp] = 0x100;
this.fw_value = [];
if(this.devices.virtio)
{
this.devices.virtio.reset();
}
this.fw_value = [];
this.jit_clear_cache();
this.load_bios();
};
CPU.prototype.reset_memory = function()
@ -728,7 +649,7 @@ CPU.prototype.init = function(settings, device_bus)
this.acpi_enabled[0] = +settings.acpi;
this.reset();
this.reset_cpu();
var io = new IO(this);
this.io = io;

View file

@ -72,7 +72,7 @@ v86.prototype.destroy = function()
v86.prototype.restart = function()
{
this.cpu.reset();
this.cpu.reset_cpu();
this.cpu.load_bios();
};

View file

@ -3971,3 +3971,83 @@ pub unsafe fn check_page_switch(block_addr: u32, next_block_addr: u32) {
dbg_assert!(x.is_ok());
dbg_assert!(x == Ok(next_block_addr));
}
#[no_mangle]
pub unsafe fn reset_cpu() {
for i in 0..8 {
*segment_is_null.offset(i) = false;
*segment_limits.offset(i) = 0;
*segment_offsets.offset(i) = 0;
*reg32.offset(i) = 0;
*sreg.offset(i) = 0;
*dreg.offset(i) = 0;
write_xmm128_2(i as i32, 0, 0);
*fpu_st.offset(i) = ::softfloat::F80::ZERO;
}
*fpu_stack_empty = 0xFF;
*fpu_stack_ptr = 0;
*fpu_control_word = 0x37F;
*fpu_status_word = 0;
*fpu_ip = 0;
*fpu_ip_selector = 0;
*fpu_opcode = 0;
*fpu_dp = 0;
*fpu_dp_selector = 0;
*mxcsr = 0x1F80;
full_clear_tlb();
*protected_mode = false;
// http://www.sandpile.org/x86/initial.htm
*idtr_size = 0;
*idtr_offset = 0;
*gdtr_size = 0;
*gdtr_offset = 0;
*page_fault = false;
*cr = 1 << 30 | 1 << 29 | 1 << 4;
*cr.offset(2) = 0;
*cr.offset(3) = 0;
*cr.offset(4) = 0;
*dreg.offset(6) = 0xFFFF0FF0u32 as i32;
*dreg.offset(7) = 0x400;
*cpl = 0;
*is_32 = false;
*stack_size_32 = false;
*prefixes = 0;
*last_virt_eip = -1;
*instruction_counter = 0;
*previous_ip = 0;
*in_hlt = false;
*sysenter_cs = 0;
*sysenter_esp = 0;
*sysenter_eip = 0;
*flags = FLAGS_DEFAULT;
*flags_changed = 0;
*last_result = 0;
*last_op1 = 0;
*last_op_size = 0;
set_tsc(0, 0);
*instruction_pointer = 0xFFFF0;
switch_cs_real_mode(0xF000);
switch_seg(SS, 0x30);
write_reg32(ESP, 0x100);
jit::jit_clear_cache(jit::get_jit_state());
}

View file

@ -200,6 +200,22 @@ if(cluster.isMaster)
},
],
},
{
name: "Linux 3 reboot",
cdrom: root_path + "/images/linux3.iso",
timeout: 90,
expected_texts: [
"~%",
"SeaBIOS ",
"~%",
],
actions: [
{
on_text: "~%",
run: "reboot\n",
},
],
},
{
name: "KolibriOS",
fda: root_path + "/images/kolibri.img",

View file

@ -264,7 +264,7 @@ else {
assert(!emulator.running);
cpu.reset();
cpu.reboot_internal();
cpu.reset_memory();
cpu.load_multiboot(fs.readFileSync(TEST_DIR + current_test.img_name).buffer);