Skip to content

Commit 802c8bb

Browse files
committed
Fixed compilation errors of i386-linux-user and mips-linux-user targets
1 parent e8f6a31 commit 802c8bb

File tree

6 files changed

+42
-51
lines changed

6 files changed

+42
-51
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ $ git clone [email protected]:BinaryAnalysisPlatform/qemu.git -b tracewrap
5454
Change folder to qemu and build tracer with command
5555
```bash
5656
$ ./configure --prefix=$HOME --with-tracewrap=`realpath ../bap-traces` \
57-
--extra-ldflags=-Lprotobuf --target-list=arm-linux-user
57+
--extra-ldflags=-Lprotobuf --target-list="arm-linux-user i386-linux-user \
58+
mips-linux-user"
5859
$ make -C protobuf
5960
$ make
6061
$ make install
@@ -65,11 +66,14 @@ $ make install
6566
To run executable `exec` and to save the trace data to `exec.trace`, use
6667

6768
```bash
68-
$ qemu-arm -tracefile exec.trace exec
69+
$ qemu-arm -tracefile exec.trace exec # trace ARM target executable
70+
$ qemu-i386 -tracefile exec.trace exec # trace X86 target executable
71+
$ qemu-mips -tracefile exec.trace exec # trace MIPS target executable
6972
```
7073

7174
Hints: use option -L to set the elf interpreter prefix to 'path'. Use
72-
fetchlibs.sh to download arm libraries.
75+
[fetchlibs.sh](https://raw.githubusercontent.com/BinaryAnalysisPlatform/bap-traces/master/test/fetchlibs.sh)
76+
to download arm and x86 libraries.
7377

7478
# Notes
75-
Only ARM target is supported in this branch.
79+
Only ARM, X86, MIPS targets are supported in this branch.
File renamed without changes.

target-i386/helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ DEF_HELPER_2(idivq_EAX, void, env, tl)
1919
#endif
2020

2121
#ifdef HAS_TRACEWRAP
22-
DEF_HELPER_1(trace_newframe, void, i32)
23-
DEF_HELPER_3(trace_endframe, void, env, i32, i32)
22+
DEF_HELPER_1(trace_newframe, void, tl)
23+
DEF_HELPER_3(trace_endframe, void, env, tl, i32)
2424
DEF_HELPER_2(trace_load_reg, void, i32, i32)
2525
DEF_HELPER_2(trace_store_reg, void, i32, i32)
2626
DEF_HELPER_3(trace_ld, void, env, i32, i32)

target-i386/trace_helper.c

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ void HELPER(trace_newframe)(target_ulong pc)
1515
qemu_trace_newframe(pc, 0);
1616
}
1717

18-
void HELPER(trace_endframe)(CPUX86State *env, target_ulong old_pc, size_t size)
18+
void HELPER(trace_endframe)(CPUArchState *env, target_ulong old_pc, uint32_t size)
1919
{
2020
//qemu_trace_endframe(env, env->eip - size, size);
2121
qemu_trace_endframe(env, old_pc, size);
2222
}
2323

24-
OperandInfo * load_store_reg(uint32_t reg, uint32_t val[4], int size, int ls)
24+
OperandInfo * load_store_reg(uint32_t reg, uint32_t val, int ls)
2525
{
2626
//fprintf(stderr, "load_store_reg: reg: (%s) 0x%d, val: 0x%08x, ls: %d\n", (reg < CPU_NB_REGS) ? regs[reg] : "EFLAGS", reg, val, ls);
2727
RegOperand * ro = (RegOperand *)malloc(sizeof(RegOperand));
@@ -52,12 +52,12 @@ OperandInfo * load_store_reg(uint32_t reg, uint32_t val[4], int size, int ls)
5252
}
5353
OperandInfo *oi = (OperandInfo *)malloc(sizeof(OperandInfo));
5454
operand_info__init(oi);
55-
oi->bit_length = size * 8;
55+
oi->bit_length = 0;
5656
oi->operand_info_specific = ois;
5757
oi->operand_usage = ou;
58-
oi->value.len = size;
58+
oi->value.len = 4;
5959
oi->value.data = malloc(oi->value.len);
60-
memcpy(oi->value.data, val, size);
60+
memcpy(oi->value.data, &val, 4);
6161

6262
return oi;
6363
}
@@ -66,56 +66,43 @@ void HELPER(trace_load_reg)(uint32_t reg, uint32_t val)
6666
{
6767
qemu_log("This register (r%d) was read. Value 0x%x\n", reg, val);
6868

69-
uint32_t vals[4];
70-
71-
vals[0] = val;
72-
73-
OperandInfo *oi = load_store_reg(reg, vals, 4, 0);
69+
OperandInfo *oi = load_store_reg(reg, val, 0);
7470

7571
qemu_trace_add_operand(oi, 0x1);
7672
}
7773

7874
void HELPER(trace_store_reg)(uint32_t reg, uint32_t val)
7975
{
80-
81-
uint32_t vals[4];
82-
83-
vals[0] = val;
84-
8576
qemu_log("This register (r%d) was written. Value: 0x%x\n", reg, val);
8677

87-
OperandInfo *oi = load_store_reg(reg, vals, 4, 1);
78+
OperandInfo *oi = load_store_reg(reg, val, 1);
8879

8980
qemu_trace_add_operand(oi, 0x2);
9081
}
9182

92-
void HELPER(trace_load_eflags)(CPUX86State *env)
83+
void HELPER(trace_load_eflags)(CPUArchState *env)
9384
{
94-
uint32_t vals[4];
95-
96-
vals[0] = cpu_compute_eflags(env);
85+
uint32_t val = cpu_compute_eflags(env);
9786

98-
OperandInfo *oi = load_store_reg(REG_EFLAGS, vals, 4, 0);
87+
OperandInfo *oi = load_store_reg(REG_EFLAGS, val, 0);
9988

10089
//OperandInfo *oi = load_store_reg(REG_EFLAGS, cpu_compute_eflags(env), 0);
10190

10291
qemu_trace_add_operand(oi, 0x1);
10392
}
10493

105-
void HELPER(trace_store_eflags)(CPUX86State *env)
94+
void HELPER(trace_store_eflags)(CPUArchState *env)
10695
{
107-
uint32_t vals[4];
108-
109-
vals[0] = cpu_compute_eflags(env);
96+
uint32_t val = cpu_compute_eflags(env);
11097

111-
OperandInfo *oi = load_store_reg(REG_EFLAGS, vals, 4, 1);
98+
OperandInfo *oi = load_store_reg(REG_EFLAGS, val, 1);
11299

113100
//OperandInfo *oi = load_store_reg(REG_EFLAGS, cpu_compute_eflags(env), 1);
114101

115102
qemu_trace_add_operand(oi, 0x2);
116103
}
117104

118-
OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls)
105+
OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls, int len)
119106
{
120107
//fprintf(stderr, "load_store_mem: addr: 0x%08x, val: 0x%08x, ls: %d\n", addr, val, ls);
121108
MemOperand * mo = (MemOperand *)malloc(sizeof(MemOperand));
@@ -137,30 +124,30 @@ OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls)
137124
}
138125
OperandInfo *oi = (OperandInfo *)malloc(sizeof(OperandInfo));
139126
operand_info__init(oi);
140-
oi->bit_length = 32;
127+
oi->bit_length = len*8;
141128
oi->operand_info_specific = ois;
142129
oi->operand_usage = ou;
143-
oi->value.len = 4;
130+
oi->value.len = len;
144131
oi->value.data = malloc(oi->value.len);
145-
memcpy(oi->value.data, &val, 4);
132+
memcpy(oi->value.data, &val, len);
146133

147134
return oi;
148135
}
149136

150-
void HELPER(trace_ld)(CPUX86State *env, uint32_t val, uint32_t addr)
137+
void HELPER(trace_ld)(CPUArchState *env, uint32_t val, uint32_t addr)
151138
{
152-
qemu_log("This was a read 0x%x addr:0x%x value:0x%x\n", env->eip, addr, val);
139+
qemu_log("This was a read 0x" TARGET_FMT_lx " addr:0x%x value:0x%x\n", env->eip, addr, val);
153140

154-
OperandInfo *oi = load_store_mem(addr, val, 0);
141+
OperandInfo *oi = load_store_mem(addr, val, 0, 4);
155142

156143
qemu_trace_add_operand(oi, 0x1);
157144
}
158145

159-
void HELPER(trace_st)(CPUX86State *env, uint32_t val, uint32_t addr)
146+
void HELPER(trace_st)(CPUArchState *env, uint32_t val, uint32_t addr)
160147
{
161-
qemu_log("This was a store 0x%x addr:0x%x value:0x%x\n", env->eip, addr, val);
148+
qemu_log("This was a store 0x" TARGET_FMT_lx " addr:0x%x value:0x%x\n", env->eip, addr, val);
162149

163-
OperandInfo *oi = load_store_mem(addr, val, 1);
150+
OperandInfo *oi = load_store_mem(addr, val, 1, 4);
164151

165152
qemu_trace_add_operand(oi, 0x2);
166153
}

target-mips/helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ DEF_HELPER_FLAGS_1(dclz, TCG_CALL_NO_RWG_SE, tl, tl)
2727
#endif
2828

2929
#ifdef HAS_TRACEWRAP
30-
DEF_HELPER_1(trace_newframe, void, i32)
31-
DEF_HELPER_3(trace_endframe, void, env, i32, i32)
30+
DEF_HELPER_1(trace_newframe, void, tl)
31+
DEF_HELPER_3(trace_endframe, void, env, tl, i32)
3232
DEF_HELPER_2(trace_load_reg, void, i32, i32)
3333
DEF_HELPER_2(trace_store_reg, void, i32, i32)
3434
DEF_HELPER_3(trace_ld, void, env, i32, i32)

target-mips/trace_helper.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void HELPER(trace_newframe)(target_ulong pc)
1212
qemu_trace_newframe(pc, 0);
1313
}
1414

15-
void HELPER(trace_endframe)(CPUMIPSState *env, target_ulong old_pc, size_t size)
15+
void HELPER(trace_endframe)(CPUMIPSState *env, target_ulong old_pc, uint32_t size)
1616
{
1717
qemu_trace_endframe(env, old_pc, size);
1818
}
@@ -84,7 +84,7 @@ void HELPER(trace_store_reg)(uint32_t reg, uint32_t val)
8484
//}
8585
//
8686

87-
OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls)
87+
OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls, int len)
8888
{
8989
MemOperand * mo = (MemOperand *)malloc(sizeof(MemOperand));
9090
mem_operand__init(mo);
@@ -105,12 +105,12 @@ OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls)
105105
}
106106
OperandInfo *oi = (OperandInfo *)malloc(sizeof(OperandInfo));
107107
operand_info__init(oi);
108-
oi->bit_length = 0;
108+
oi->bit_length = len*8;
109109
oi->operand_info_specific = ois;
110110
oi->operand_usage = ou;
111-
oi->value.len = 4;
111+
oi->value.len = len;
112112
oi->value.data = malloc(oi->value.len);
113-
memcpy(oi->value.data, &val, 4);
113+
memcpy(oi->value.data, &val, len);
114114

115115
return oi;
116116
}
@@ -119,7 +119,7 @@ void HELPER(trace_ld)(CPUMIPSState *env, uint32_t val, uint32_t addr)
119119
{
120120
qemu_log("This was a read 0x%x addr:0x%x value:0x%x\n", env->active_tc.PC, addr, val);
121121

122-
OperandInfo *oi = load_store_mem(addr, val, 0);
122+
OperandInfo *oi = load_store_mem(addr, val, 0, 4);
123123

124124
qemu_trace_add_operand(oi, 0x1);
125125
}
@@ -128,7 +128,7 @@ void HELPER(trace_st)(CPUMIPSState *env, uint32_t val, uint32_t addr)
128128
{
129129
qemu_log("This was a store 0x%x addr:0x%x value:0x%x\n", env->active_tc.PC, addr, val);
130130

131-
OperandInfo *oi = load_store_mem(addr, val, 1);
131+
OperandInfo *oi = load_store_mem(addr, val, 1, 4);
132132

133133
qemu_trace_add_operand(oi, 0x2);
134134
}

0 commit comments

Comments
 (0)