Commit 019817da authored by Julian Kranz's avatar Julian Kranz

X86 Tester

- X86 Generator
parent 4fd5b276
......@@ -36,5 +36,6 @@ struct generator_opcodes_data {
extern struct generator *generator_init(enum generator_type type);
extern void generator_free(struct generator *generator);
extern void generator_print(struct generator *generator);
extern void generator_execute(struct generator *generator, FILE *stream);
#endif /* GENERATOR_H_ */
......@@ -41,5 +41,6 @@ extern struct generator_tree_node *generator_tree_generator_build(
extern struct generator_tree_node *generator_tree_branch(size_t branches_length,
...);
extern void generator_tree_print(struct generator_tree_node *root);
extern void generator_tree_execute(struct generator_tree_node *root, FILE *stream);
#endif /* GENERATOR_TREE_H_ */
......@@ -10,13 +10,6 @@
#include <generator.h>
#include <util.h>
extern size_t generator_x86_prefixes_generate(FILE *stream);
extern size_t generator_x86_opcode_generate(FILE *stream);
extern size_t generator_x86_modrm_generate(FILE *stream);
extern size_t generator_x86_immediate_generate(FILE *stream);
extern size_t generator_x86_rex_generate(FILE *stream);
extern size_t generator_x86_vex_generate(FILE *stream);
size_t generator_x86_prefixes_generate(FILE *stream) {
size_t size = 0;
while(rand() > RAND_MAX / 2) {
......@@ -47,6 +40,26 @@ size_t generator_x86_prefixes_generate(FILE *stream) {
return size;
}
size_t generator_x86_opcode_generate(FILE *stream) {
return 0;
}
size_t generator_x86_modrm_generate(FILE *stream) {
return 0;
}
size_t generator_x86_immediate_generate(FILE *stream) {
return 0;
}
size_t generator_x86_rex_generate(FILE *stream) {
return 0;
}
size_t generator_x86_vex_generate(FILE *stream) {
return 0;
}
struct generator *generator_init(enum generator_type type) {
struct generator *generator = (struct generator*)malloc(
sizeof(struct generator));
......@@ -111,6 +124,35 @@ void generator_print(struct generator *generator) {
}
}
void generator_execute(struct generator *generator, FILE *stream) {
switch(generator->type) {
case GENERATOR_TYPE_PREFIXES: {
generator_x86_prefixes_generate(stream);
break;
}
case GENERATOR_TYPE_OPCODE: {
generator_x86_opcode_generate(stream);
break;
}
case GENERATOR_TYPE_MODRM: {
generator_x86_modrm_generate(stream);
break;
}
case GENERATOR_TYPE_IMMEDIATE: {
generator_x86_immediate_generate(stream);
break;
}
case GENERATOR_TYPE_REX: {
generator_x86_rex_generate(stream);
break;
}
case GENERATOR_TYPE_VEX: {
generator_x86_vex_generate(stream);
break;
}
}
}
void generator_free(struct generator *generator) {
}
......@@ -71,7 +71,7 @@ void generator_tree_print(struct generator_tree_node *root) {
}
}
void generator_tree_execute(struct generator_tree_node *root) {
void generator_tree_execute(struct generator_tree_node *root, FILE *stream) {
if(!root)
return;
switch(root->type) {
......@@ -82,14 +82,20 @@ void generator_tree_execute(struct generator_tree_node *root) {
weights += root->branches[i].weight;
int interval = RAND_MAX / weights;
int current = 0;
for(size_t i = 0; i < root->branches_length; ++i)
if(random >= interval * current
&& random < interval * (current + root->branches[i].weight)) {
generator_tree_execute(root->branches[i].node);
for(size_t i = 0; i < root->branches_length; ++i) {
if((random >= interval * current
&& random < interval * (current + root->branches[i].weight))
|| i == root->branches_length) {
generator_tree_execute(root->branches[i].node, stream);
break;
}
current += root->branches[i].weight;
}
break;
}
case GENERATOR_TREE_NODE_TYPE_GENERATOR: {
generator_execute(root->generator, stream);
break;
}
}
}
......@@ -16,7 +16,7 @@ struct generator_tree_node *x86_generator_tree_get() {
struct generator_tree_node *vex_op_rm_imm = generator_tree_generator_build(generator_init(GENERATOR_TYPE_VEX), op_rm_imm);
struct generator_tree_node *root = generator_tree_branch(2, pref_rex_op_rm_imm, 1, vex_op_rm_imm, 1);
struct generator_tree_node *root = generator_tree_branch(2, pref_rex_op_rm_imm, 3, vex_op_rm_imm, 2);
return root;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment