aboutsummaryrefslogtreecommitdiff
path: root/test/lol.c
blob: 846cb5d13b187be8cab820fcfe0c76509e7839d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#define IF_BOTHER_WITH_MODIFY(...) __VA_ARGS__
#include "dis.h"

typedef struct tc {
    struct dis_ctx_base base;
    struct arch_dis_ctx arch;
} *tdis_ctx;
#define P(x) P_##x
#define DIS_MAY_MODIFY 0

static enum {
    NOPPY,
    JUMPY,
    BAD
} type;

NOINLINE UNUSED
static void P_data(UNUSED struct tc *ctx, unsigned o0, unsigned o1, unsigned o2,
                   unsigned o3, unsigned out_mask) {
    unsigned ops[] = {o0, o1, o2, o3};
    type = NOPPY;
    for (int i = 0; i < 4; i++) {
        if (ops[i] != null_op && (out_mask & (1 << i))) {
            if (ops[i] == 15) {
                type = JUMPY;
                break;
            } else if (ops[i] != 12 && ops[i] != 9) {
                type = BAD;
            }
        }
    }
}
NOINLINE UNUSED
static void P_pcrel(UNUSED struct tc *ctx, uint32_t dpc,
                    UNUSED struct arch_pcrel_info info) {
    return P_data(ctx, info.reg, null_op, null_op, null_op, 1);
}
NOINLINE UNUSED
static void P_thumb_it(UNUSED struct tc *ctx) {
    type = NOPPY;
}

NOINLINE UNUSED
static void P_ret(UNUSED struct tc *ctx) {
    type = JUMPY;
}

NOINLINE UNUSED
static void P_indirect_call(UNUSED struct tc *ctx) {
    type = JUMPY;
}

NOINLINE UNUSED
static void P_branch(UNUSED struct tc *ctx, uint64_t dpc, int cc) {
    type = BAD;
}

NOINLINE UNUSED
static void P_unidentified(UNUSED struct tc *ctx) {
    type = BAD;
}

NOINLINE UNUSED
static void P_bad(UNUSED struct tc *ctx) {
    type = JUMPY;
}

#include "arm/dis-main.inc.h"

int main(UNUSED int argc, char **argv) {
    struct tc ctx;
    ctx.base.pc = 0xdead0000;
    memset(ctx.base.newop, 0, sizeof(ctx.base.newop));
    ctx.base.modify = false;
    for (uint32_t hi = 0; hi < (1 << 12); hi++) {
        for (uint32_t lo = 0; lo < (1 << 13); lo++) {
            uint32_t op = (0b1111 << 28) | (hi << 16) | (0b111 << 13) | lo;

            if ((op & 0x0f100010) == 0x0e100010)
                continue;
            
            ctx.base.ptr = &op;
            ctx.arch.pc_low_bit = false;
            type = BAD;
            P(dis)(&ctx);
            if (type != JUMPY)
                continue;
            ctx.arch.pc_low_bit = true;
            type = BAD;
            P(dis)(&ctx);
            if (type != NOPPY)
                continue;
            printf("%x\n", op);
        }
    }

}