test VEX decoding, rename "size" to "limit"

This commit is contained in:
mykola2312 2024-08-22 07:26:33 +03:00
parent 74e6ce1322
commit f312bc09e9
4 changed files with 31 additions and 10 deletions

View file

@ -48,6 +48,9 @@ rtdisasm: $(RTDISASM_OBJ) $(RTDISASM_DEPS)
$(PYTHON) genc.py xml/raw/x86/Intel/AZ.xml | $(CC) -x c $(CFLAGS) -c -o $(OBJ_DIR)/rtdisasm_table.o -
$(AR) -crs $(BIN_DIR)/librtdisasm.a $(RTDISASM_OBJ) $(OBJ_DIR)/rtdisasm_table.o
$(OBJ_DIR)/rtdisasm_test.o: $(SRC_DIR)/rtdisasm_test.c
$(CC) $(CFLAGS) -mavx -c -o $@ $<
rtdisasm_test: $(RTDISASM_TEST_OBJ) $(RTDISASM_TEST_DEPS)
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(RTDISASM_TEST_OBJ) $(LIB_DIR)/librtdisasm.a

View file

@ -4,18 +4,18 @@
#include <stdint.h>
#include "rtdisasm_table.h"
// "code" should point to place with machine instructions, and "size"
// "code" should point to place with machine instructions, and "limit"
// limits the area of analyze, so no segfaults would be triggered on
// page boundaries. if "found" is non-zero, on instruction hit it
// would be set to found instruction table entry
// returns 0 when no instruction was found, -1 when size limit reached
// returns 0 when no instruction was found, -1 when limit reached
// and non-negative-non-zero number of actual instruction size
int rtdisasm_analyze_single(const uint8_t* code, unsigned size, const instruction_t** found);
int rtdisasm_analyze_single(const uint8_t* code, unsigned limit, const instruction_t** found);
// analyze all instructions at "code" until "size" limit is reached or
// analyze all instructions at "code" until "limit" is reached or
// instruction of "rt_target" equal was found. returns -1 when size limit hit,
// 0 if rtdisasm encountered unknown instruction
// and non-zero integer is offset from "code"
int rtdisasm_find_target(const uint8_t* code, unsigned size, unsigned rt_target);
int rtdisasm_find_target(const uint8_t* code, unsigned limit, unsigned rt_target);
#endif

View file

@ -265,10 +265,10 @@ const instruction_t* is_special_instruction(const uint8_t* code)
return NULL;
}
int rtdisasm_analyze_single(const uint8_t* code, unsigned size, const instruction_t** found)
int rtdisasm_analyze_single(const uint8_t* code, unsigned limit, const instruction_t** found)
{
const uint8_t* cur = code;
const uint8_t* const end = code + size;
const uint8_t* const end = code + limit;
if (cur == end) return -1;
// look for any special instructions first
@ -366,11 +366,11 @@ int rtdisasm_analyze_single(const uint8_t* code, unsigned size, const instructio
return (int)((uintptr_t)cur-(uintptr_t)code);
}
int rtdisasm_find_target(const uint8_t* code, unsigned size, unsigned rt_target)
int rtdisasm_find_target(const uint8_t* code, unsigned limit, unsigned rt_target)
{
const uint8_t* cur = code;
const uint8_t* const end = code + size;
unsigned remaining = size;
const uint8_t* const end = code + limit;
unsigned remaining = limit;
if (cur == end) return -1;
do {

View file

@ -1,4 +1,5 @@
#include "rtdisasm.h"
#include <immintrin.h>
#include <stdio.h>
extern void test_1();
@ -29,6 +30,17 @@ static unsigned int test_2(unsigned char *message)
}
static void test_2_end() {}
// TEST 3 - VEX instructins
static void test_3()
{
__m256 evens = _mm256_set_ps(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0);
__m256 odds = _mm256_set_ps(1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0);
__m256 result = _mm256_sub_ps(evens, odds);
__asm__("nop"); // TARGET
}
static void test_3_end() {}
int main()
{
printf("== TEST 1 ==\n");
@ -51,5 +63,11 @@ int main()
printf("test2 %d\n", rtdisasm_find_target((const uint8_t*)test_2, size, RT_TARGET_NOP));
printf("\n== TEST 3 ==\n");
size = (uintptr_t)test_3_end - (uintptr_t)test_3;
printf("size %lu\n", size);
printf("test3 %d\n", rtdisasm_find_target((const uint8_t*)test_3, size, RT_TARGET_NOP));
return 0;
}