@@ -1514,64 +1514,66 @@ static void test_x86_64_not_overwriting_tmp0_for_pc_update()
1514
1514
}
1515
1515
1516
1516
#define MEM_BASE 0x40000000
1517
- #define MEM_SIZE 1024* 1024
1517
+ #define MEM_SIZE 1024 * 1024
1518
1518
#define MEM_STACK MEM_BASE + (MEM_SIZE / 2)
1519
1519
#define MEM_TEXT MEM_STACK + 4096
1520
1520
1521
- static void test_fxsave_fpip_x86 (void ) {
1521
+ static void test_fxsave_fpip_x86 (void )
1522
+ {
1522
1523
// note: fxsave was introduced in Pentium II
1523
1524
uint8_t code_x86 [] = {
1524
1525
// help testing through NOP offset [disassembly in at&t syntax]
1525
- 0x90 , 0x90 , 0x90 , 0x90 , // nop nop nop nop
1526
- // run a floating point instruction
1527
- 0xdb , 0xc9 , // fcmovne %st(1), %st
1528
- // fxsave needs 512 bytes of storage space
1529
- 0x81 , 0xec , 0x00 , 0x02 , 0x00 , 0x00 , // subl $512, %esp
1530
- // fxsave needs a 16-byte aligned address for storage
1531
- 0x83 , 0xe4 , 0xf0 , // andl $0xfffffff0, %esp
1532
- // store fxsave data on the stack
1533
- 0x0f , 0xae , 0x04 , 0x24 , // fxsave (%esp)
1534
- // fxsave stores FPIP at an 8-byte offset, move FPIP to eax register
1535
- 0x8b , 0x44 , 0x24 , 0x08 // movl 0x8(%esp), %eax
1526
+ 0x90 , 0x90 , 0x90 , 0x90 , // nop nop nop nop
1527
+ // run a floating point instruction
1528
+ 0xdb , 0xc9 , // fcmovne %st(1), %st
1529
+ // fxsave needs 512 bytes of storage space
1530
+ 0x81 , 0xec , 0x00 , 0x02 , 0x00 , 0x00 , // subl $512, %esp
1531
+ // fxsave needs a 16-byte aligned address for storage
1532
+ 0x83 , 0xe4 , 0xf0 , // andl $0xfffffff0, %esp
1533
+ // store fxsave data on the stack
1534
+ 0x0f , 0xae , 0x04 , 0x24 , // fxsave (%esp)
1535
+ // fxsave stores FPIP at an 8-byte offset, move FPIP to eax register
1536
+ 0x8b , 0x44 , 0x24 , 0x08 // movl 0x8(%esp), %eax
1536
1537
};
1537
1538
uc_err err ;
1538
1539
uint32_t X86_NOP_OFFSET = 4 ;
1539
- uint32_t stack_top = (uint32_t ) MEM_STACK ;
1540
+ uint32_t stack_top = (uint32_t )MEM_STACK ;
1540
1541
uint32_t value ;
1541
1542
uc_engine * uc ;
1542
1543
1543
1544
// initialize emulator in X86-32bit mode
1544
1545
OK (uc_open (UC_ARCH_X86 , UC_MODE_32 , & uc ));
1545
-
1546
+
1546
1547
// map 1MB of memory for this emulation
1547
1548
OK (uc_mem_map (uc , MEM_BASE , MEM_SIZE , UC_PROT_ALL ));
1548
1549
OK (uc_mem_write (uc , MEM_TEXT , code_x86 , sizeof (code_x86 )));
1549
1550
OK (uc_reg_write (uc , UC_X86_REG_ESP , & stack_top ));
1550
1551
OK (uc_emu_start (uc , MEM_TEXT , MEM_TEXT + sizeof (code_x86 ), 0 , 0 ));
1551
1552
OK (uc_reg_read (uc , UC_X86_REG_EAX , & value ));
1552
- TEST_CHECK (value == ((uint32_t ) MEM_TEXT + X86_NOP_OFFSET ));
1553
+ TEST_CHECK (value == ((uint32_t )MEM_TEXT + X86_NOP_OFFSET ));
1553
1554
OK (uc_mem_unmap (uc , MEM_BASE , MEM_SIZE ));
1554
1555
OK (uc_close (uc ));
1555
1556
}
1556
1557
1557
- static void test_fxsave_fpip_x64 (void ) {
1558
+ static void test_fxsave_fpip_x64 (void )
1559
+ {
1558
1560
uint8_t code_x64 [] = {
1559
1561
// help testing through NOP offset [disassembly in at&t]
1560
- 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , // nops
1561
- // run a floating point instruction
1562
- 0xdb , 0xc9 , // fcmovne %st(1), %st
1563
- // fxsave64 needs 512 bytes of storage space
1564
- 0x48 , 0x81 , 0xec , 0x00 , 0x02 , 0x00 , 0x00 , // subq $512, %rsp
1565
- // fxsave needs a 16-byte aligned address for storage
1566
- 0x48 , 0x83 , 0xe4 , 0xf0 , // andq 0xfffffffffffffff0, %rsp
1567
- // store fxsave64 data on the stack
1568
- 0x48 , 0x0f , 0xae , 0x04 , 0x24 , // fxsave64 (%rsp)
1569
- // fxsave64 stores FPIP at an 8-byte offset, move FPIP to rax register
1570
- 0x48 , 0x8b , 0x44 , 0x24 , 0x08 , // movq 0x8(%rsp), %rax
1562
+ 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , // nops
1563
+ // run a floating point instruction
1564
+ 0xdb , 0xc9 , // fcmovne %st(1), %st
1565
+ // fxsave64 needs 512 bytes of storage space
1566
+ 0x48 , 0x81 , 0xec , 0x00 , 0x02 , 0x00 , 0x00 , // subq $512, %rsp
1567
+ // fxsave needs a 16-byte aligned address for storage
1568
+ 0x48 , 0x83 , 0xe4 , 0xf0 , // andq 0xfffffffffffffff0, %rsp
1569
+ // store fxsave64 data on the stack
1570
+ 0x48 , 0x0f , 0xae , 0x04 , 0x24 , // fxsave64 (%rsp)
1571
+ // fxsave64 stores FPIP at an 8-byte offset, move FPIP to rax register
1572
+ 0x48 , 0x8b , 0x44 , 0x24 , 0x08 , // movq 0x8(%rsp), %rax
1571
1573
};
1572
1574
1573
1575
uc_err err ;
1574
- uint64_t stack_top = (uint64_t ) MEM_STACK ;
1576
+ uint64_t stack_top = (uint64_t )MEM_STACK ;
1575
1577
uint64_t X64_NOP_OFFSET = 8 ;
1576
1578
uint64_t value ;
1577
1579
uc_engine * uc ;
@@ -1585,7 +1587,7 @@ static void test_fxsave_fpip_x64(void) {
1585
1587
OK (uc_reg_write (uc , UC_X86_REG_RSP , & stack_top ));
1586
1588
OK (uc_emu_start (uc , MEM_TEXT , MEM_TEXT + sizeof (code_x64 ), 0 , 0 ));
1587
1589
OK (uc_reg_read (uc , UC_X86_REG_RAX , & value ));
1588
- TEST_CHECK (value == ((uint64_t ) MEM_TEXT + X64_NOP_OFFSET ));
1590
+ TEST_CHECK (value == ((uint64_t )MEM_TEXT + X64_NOP_OFFSET ));
1589
1591
OK (uc_mem_unmap (uc , MEM_BASE , MEM_SIZE ));
1590
1592
OK (uc_close (uc ));
1591
1593
}
0 commit comments