#include <string.h>
#include <stdio.h>
#include <errno.h>
+#include <inttypes.h>
#include <sys/queue.h>
#include <arpa/inet.h>
struct instr_operand dst;
union {
struct instr_operand src;
- uint32_t src_val;
+ uint64_t src_val;
};
};
union {
struct instr_operand b;
- uint32_t b_val;
+ uint64_t b_val;
};
};
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* MOV_I. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
if (dst[0] == 'h')
- src_val = htonl(src_val);
+ src_val = hton64(src_val) >> (64 - fdst->n_bits);
instr->type = INSTR_MOV_I;
instr->mov.dst.struct_id = (uint8_t)dst_struct_id;
instr->mov.dst.n_bits = fdst->n_bits;
instr->mov.dst.offset = fdst->offset / 8;
- instr->mov.src_val = (uint32_t)src_val;
+ instr->mov.src_val = src_val;
return 0;
}
struct thread *t = &p->threads[p->thread_id];
struct instruction *ip = t->ip;
- TRACE("[Thread %2u] mov m.f %x\n",
+ TRACE("[Thread %2u] mov m.f %" PRIx64 "\n",
p->thread_id,
ip->mov.src_val);
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* ADD_MI, ADD_HI. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
instr->type = INSTR_ALU_ADD_MI;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* SUB_MI, SUB_HI. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
instr->type = INSTR_ALU_SUB_MI;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* SHL_MI, SHL_HI. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
instr->type = INSTR_ALU_SHL_MI;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* SHR_MI, SHR_HI. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
instr->type = INSTR_ALU_SHR_MI;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* AND_I. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
if (dst[0] == 'h')
- src_val = htonl(src_val);
+ src_val = hton64(src_val) >> (64 - fdst->n_bits);
instr->type = INSTR_ALU_AND_I;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* OR_I. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
if (dst[0] == 'h')
- src_val = htonl(src_val);
+ src_val = hton64(src_val) >> (64 - fdst->n_bits);
instr->type = INSTR_ALU_OR_I;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *dst = tokens[1], *src = tokens[2];
struct field *fdst, *fsrc;
- uint32_t dst_struct_id, src_struct_id, src_val;
+ uint64_t src_val;
+ uint32_t dst_struct_id, src_struct_id;
CHECK(n_tokens == 3, EINVAL);
}
/* XOR_I. */
- src_val = strtoul(src, &src, 0);
+ src_val = strtoull(src, &src, 0);
CHECK(!src[0], EINVAL);
if (dst[0] == 'h')
- src_val = htonl(src_val);
+ src_val = hton64(src_val) >> (64 - fdst->n_bits);
instr->type = INSTR_ALU_XOR_I;
instr->alu.dst.struct_id = (uint8_t)dst_struct_id;
instr->alu.dst.n_bits = fdst->n_bits;
instr->alu.dst.offset = fdst->offset / 8;
- instr->alu.src_val = (uint32_t)src_val;
+ instr->alu.src_val = src_val;
return 0;
}
{
char *a = tokens[2], *b = tokens[3];
struct field *fa, *fb;
- uint32_t a_struct_id, b_struct_id, b_val;
+ uint64_t b_val;
+ uint32_t a_struct_id, b_struct_id;
CHECK(n_tokens == 4, EINVAL);
}
/* JMP_EQ_I. */
- b_val = strtoul(b, &b, 0);
+ b_val = strtoull(b, &b, 0);
CHECK(!b[0], EINVAL);
if (a[0] == 'h')
- b_val = htonl(b_val);
+ b_val = hton64(b_val) >> (64 - fa->n_bits);
instr->type = INSTR_JMP_EQ_I;
instr->jmp.ip = NULL; /* Resolved later. */
instr->jmp.a.struct_id = (uint8_t)a_struct_id;
instr->jmp.a.n_bits = fa->n_bits;
instr->jmp.a.offset = fa->offset / 8;
- instr->jmp.b_val = (uint32_t)b_val;
+ instr->jmp.b_val = b_val;
return 0;
}
{
char *a = tokens[2], *b = tokens[3];
struct field *fa, *fb;
- uint32_t a_struct_id, b_struct_id, b_val;
+ uint64_t b_val;
+ uint32_t a_struct_id, b_struct_id;
CHECK(n_tokens == 4, EINVAL);
}
/* JMP_NEQ_I. */
- b_val = strtoul(b, &b, 0);
+ b_val = strtoull(b, &b, 0);
CHECK(!b[0], EINVAL);
if (a[0] == 'h')
- b_val = htonl(b_val);
+ b_val = hton64(b_val) >> (64 - fa->n_bits);
instr->type = INSTR_JMP_NEQ_I;
instr->jmp.ip = NULL; /* Resolved later. */
instr->jmp.a.struct_id = (uint8_t)a_struct_id;
instr->jmp.a.n_bits = fa->n_bits;
instr->jmp.a.offset = fa->offset / 8;
- instr->jmp.b_val = (uint32_t)b_val;
+ instr->jmp.b_val = b_val;
return 0;
}
{
char *a = tokens[2], *b = tokens[3];
struct field *fa, *fb;
- uint32_t a_struct_id, b_struct_id, b_val;
+ uint64_t b_val;
+ uint32_t a_struct_id, b_struct_id;
CHECK(n_tokens == 4, EINVAL);
}
/* JMP_LT_MI, JMP_LT_HI. */
- b_val = strtoul(b, &b, 0);
+ b_val = strtoull(b, &b, 0);
CHECK(!b[0], EINVAL);
instr->type = INSTR_JMP_LT_MI;
instr->jmp.a.struct_id = (uint8_t)a_struct_id;
instr->jmp.a.n_bits = fa->n_bits;
instr->jmp.a.offset = fa->offset / 8;
- instr->jmp.b_val = (uint32_t)b_val;
+ instr->jmp.b_val = b_val;
return 0;
}
{
char *a = tokens[2], *b = tokens[3];
struct field *fa, *fb;
- uint32_t a_struct_id, b_struct_id, b_val;
+ uint64_t b_val;
+ uint32_t a_struct_id, b_struct_id;
CHECK(n_tokens == 4, EINVAL);
}
/* JMP_GT_MI, JMP_GT_HI. */
- b_val = strtoul(b, &b, 0);
+ b_val = strtoull(b, &b, 0);
CHECK(!b[0], EINVAL);
instr->type = INSTR_JMP_GT_MI;
instr->jmp.a.struct_id = (uint8_t)a_struct_id;
instr->jmp.a.n_bits = fa->n_bits;
instr->jmp.a.offset = fa->offset / 8;
- instr->jmp.b_val = (uint32_t)b_val;
+ instr->jmp.b_val = b_val;
return 0;
}