use crate::tests::helpers;
use crate::*;

#[test]
// this tests the emu.linux_call64() ARM ABI (used in linux calls)
pub fn linux_call64() {
    helpers::setup();

    /*
         int test(int p1, int p2, int p3, int p4, int p5, int p6, int p7) {
            return p1+p2+p3+p4+p5+p6+p7;
        }
     */

    let mut emu = emu64();
    let opcodes: Vec<u8> = vec![
        0x55, 0x48, 0x89, 0xe5, 0x89, 0x7d, 0xfc, 0x89, 0x75, 0xf8, 0x89, 0x55, 
        0xf4, 0x89, 0x4d, 0xf0, 0x44, 0x89, 0x45, 0xec, 0x44, 0x89, 0x4d, 0xe8, 
        0x8b, 0x55, 0xfc, 0x8b, 0x45, 0xf8, 0x01, 0xc2, 0x8b, 0x45, 0xf4, 0x01,
        0xc2, 0x8b, 0x45, 0xf0, 0x01, 0xc2, 0x8b, 0x45, 0xec, 0x01, 0xc2, 0x8b,
        0x45, 0xe8, 0x01, 0xc2, 0x8b, 0x45, 0x10, 0x01, 0xd0, 0x5d, 0xc3
    ];
    emu.set_verbose(0);
    emu.linux = true;
    emu.load_code_bytes(&opcodes);
    emu.regs_mut().rax = 0;
    let rax = emu.linux_call64(emu.regs().rip, &[1,2,3,4,5,6,7]).unwrap();
    assert_eq!(rax, emu.regs().rax);
    assert_eq!(emu.regs().rax, 1+2+3+4+5+6+7);
}
