1 //===-- RegisterContextNetBSDTest_i386.cpp --------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #if defined(__i386__) || defined(__x86_64__) 10 11 // clang-format off 12 #include <sys/types.h> 13 #include <i386/reg.h> 14 // clang-format on 15 16 #include "gmock/gmock.h" 17 #include "gtest/gtest.h" 18 19 #include "Plugins/Process/Utility/lldb-x86-register-enums.h" 20 #include "Plugins/Process/Utility/RegisterContextNetBSD_i386.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 static std::pair<size_t, size_t> GetRegParams(RegisterInfoInterface &ctx, 26 uint32_t reg) { 27 const RegisterInfo &info = ctx.GetRegisterInfo()[reg]; 28 return {info.byte_offset, info.byte_size}; 29 } 30 31 #define EXPECT_OFF(regname, offset, size) \ 32 EXPECT_THAT(GetRegParams(reg_ctx, lldb_##regname), \ 33 ::testing::Pair(offset + base_offset, size)) 34 35 #define EXPECT_GPR_I386(regname) \ 36 EXPECT_THAT(GetRegParams(reg_ctx, lldb_##regname##_i386), \ 37 ::testing::Pair(offsetof(reg, r_##regname), \ 38 sizeof(reg::r_##regname))) 39 #define EXPECT_DBR_I386(num) \ 40 EXPECT_OFF(dr##num##_i386, offsetof(dbreg, dr[num]), \ 41 sizeof(dbreg::dr[num])) 42 43 TEST(RegisterContextNetBSDTest, i386) { 44 ArchSpec arch{"i686-unknown-netbsd"}; 45 RegisterContextNetBSD_i386 reg_ctx{arch}; 46 47 EXPECT_GPR_I386(eax); 48 EXPECT_GPR_I386(ecx); 49 EXPECT_GPR_I386(edx); 50 EXPECT_GPR_I386(ebx); 51 EXPECT_GPR_I386(esp); 52 EXPECT_GPR_I386(ebp); 53 EXPECT_GPR_I386(esi); 54 EXPECT_GPR_I386(edi); 55 EXPECT_GPR_I386(eip); 56 EXPECT_GPR_I386(eflags); 57 EXPECT_GPR_I386(cs); 58 EXPECT_GPR_I386(ss); 59 EXPECT_GPR_I386(ds); 60 EXPECT_GPR_I386(es); 61 EXPECT_GPR_I386(fs); 62 EXPECT_GPR_I386(gs); 63 64 // fctrl is the first FPR field, it is used to determine offset of the whole 65 // FPR struct 66 size_t base_offset = reg_ctx.GetRegisterInfo()[lldb_fctrl_i386].byte_offset; 67 68 // assert against FXSAVE struct 69 EXPECT_OFF(fctrl_i386, 0x00, 2); 70 EXPECT_OFF(fstat_i386, 0x02, 2); 71 // TODO: This is a known bug, abridged ftag should is 8 bits in length. 72 EXPECT_OFF(ftag_i386, 0x04, 2); 73 EXPECT_OFF(fop_i386, 0x06, 2); 74 // NB: Technically fiseg/foseg are 16-bit long and the higher 16 bits 75 // are reserved. However, we use them to access/recombine 64-bit FIP/FDP. 76 EXPECT_OFF(fioff_i386, 0x08, 4); 77 EXPECT_OFF(fiseg_i386, 0x0C, 4); 78 EXPECT_OFF(fooff_i386, 0x10, 4); 79 EXPECT_OFF(foseg_i386, 0x14, 4); 80 EXPECT_OFF(mxcsr_i386, 0x18, 4); 81 EXPECT_OFF(mxcsrmask_i386, 0x1C, 4); 82 EXPECT_OFF(st0_i386, 0x20, 10); 83 EXPECT_OFF(st1_i386, 0x30, 10); 84 EXPECT_OFF(st2_i386, 0x40, 10); 85 EXPECT_OFF(st3_i386, 0x50, 10); 86 EXPECT_OFF(st4_i386, 0x60, 10); 87 EXPECT_OFF(st5_i386, 0x70, 10); 88 EXPECT_OFF(st6_i386, 0x80, 10); 89 EXPECT_OFF(st7_i386, 0x90, 10); 90 EXPECT_OFF(mm0_i386, 0x20, 8); 91 EXPECT_OFF(mm1_i386, 0x30, 8); 92 EXPECT_OFF(mm2_i386, 0x40, 8); 93 EXPECT_OFF(mm3_i386, 0x50, 8); 94 EXPECT_OFF(mm4_i386, 0x60, 8); 95 EXPECT_OFF(mm5_i386, 0x70, 8); 96 EXPECT_OFF(mm6_i386, 0x80, 8); 97 EXPECT_OFF(mm7_i386, 0x90, 8); 98 EXPECT_OFF(xmm0_i386, 0xA0, 16); 99 EXPECT_OFF(xmm1_i386, 0xB0, 16); 100 EXPECT_OFF(xmm2_i386, 0xC0, 16); 101 EXPECT_OFF(xmm3_i386, 0xD0, 16); 102 EXPECT_OFF(xmm4_i386, 0xE0, 16); 103 EXPECT_OFF(xmm5_i386, 0xF0, 16); 104 EXPECT_OFF(xmm6_i386, 0x100, 16); 105 EXPECT_OFF(xmm7_i386, 0x110, 16); 106 107 base_offset = reg_ctx.GetRegisterInfo()[lldb_dr0_i386].byte_offset; 108 EXPECT_DBR_I386(0); 109 EXPECT_DBR_I386(1); 110 EXPECT_DBR_I386(2); 111 EXPECT_DBR_I386(3); 112 EXPECT_DBR_I386(4); 113 EXPECT_DBR_I386(5); 114 EXPECT_DBR_I386(6); 115 EXPECT_DBR_I386(7); 116 } 117 118 #endif // defined(__i386__) || defined(__x86_64__) 119