... | ... |
@@ -1155,8 +1155,10 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char |
1155 | 1155 |
break; |
1156 | 1156 |
} |
1157 | 1157 |
} |
1158 |
- if (inst.opcode == OP_BC_COPY) |
|
1158 |
+ if (inst.opcode == OP_BC_STORE) |
|
1159 | 1159 |
inst.type = bcfunc->types[inst.u.binop[0]]&0x7fff; |
1160 |
+ if (inst.opcode == OP_BC_COPY) |
|
1161 |
+ inst.type = bcfunc->types[inst.u.binop[1]]&0x7fff; |
|
1160 | 1162 |
if (!ok) { |
1161 | 1163 |
cli_errmsg("Invalid instructions or operands\n"); |
1162 | 1164 |
return CL_EMALFDB; |
... | ... |
@@ -1711,6 +1713,9 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
1711 | 1711 |
case OP_BC_MEMCPY: |
1712 | 1712 |
case OP_BC_MEMMOVE: |
1713 | 1713 |
case OP_BC_MEMCMP: |
1714 |
+ MAP(inst->u.three[0]); |
|
1715 |
+ MAP(inst->u.three[1]); |
|
1716 |
+ MAP(inst->u.three[2]); |
|
1714 | 1717 |
/*TODO*/ |
1715 | 1718 |
break; |
1716 | 1719 |
case OP_BC_ISBIGENDIAN: |
... | ... |
@@ -953,8 +953,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
953 | 953 |
{ |
954 | 954 |
uint8_t *ptr; |
955 | 955 |
uint8_t v; |
956 |
- READP(ptr, BINOP(0), 1); |
|
957 |
- READ1(v, BINOP(1)); |
|
956 |
+ READP(ptr, BINOP(1), 1); |
|
957 |
+ READ1(v, BINOP(0)); |
|
958 | 958 |
*ptr = v; |
959 | 959 |
break; |
960 | 960 |
} |
... | ... |
@@ -962,8 +962,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
962 | 962 |
{ |
963 | 963 |
uint8_t *ptr; |
964 | 964 |
uint8_t v; |
965 |
- READP(ptr, BINOP(0), 1); |
|
966 |
- READ8(v, BINOP(1)); |
|
965 |
+ READP(ptr, BINOP(1), 1); |
|
966 |
+ READ8(v, BINOP(0)); |
|
967 | 967 |
*ptr = v; |
968 | 968 |
break; |
969 | 969 |
} |
... | ... |
@@ -971,8 +971,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
971 | 971 |
{ |
972 | 972 |
union unaligned_16 *ptr; |
973 | 973 |
uint16_t v; |
974 |
- READP(ptr, BINOP(0), 2); |
|
975 |
- READ16(v, BINOP(1)); |
|
974 |
+ READP(ptr, BINOP(1), 2); |
|
975 |
+ READ16(v, BINOP(0)); |
|
976 | 976 |
ptr->una_s16 = v; |
977 | 977 |
break; |
978 | 978 |
} |
... | ... |
@@ -980,8 +980,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
980 | 980 |
{ |
981 | 981 |
union unaligned_32 *ptr; |
982 | 982 |
uint32_t v; |
983 |
- READP(ptr, BINOP(0), 4); |
|
984 |
- READ32(v, BINOP(1)); |
|
983 |
+ READP(ptr, BINOP(1), 4); |
|
984 |
+ READ32(v, BINOP(0)); |
|
985 | 985 |
ptr->una_u32 = v; |
986 | 986 |
break; |
987 | 987 |
} |
... | ... |
@@ -989,8 +989,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
989 | 989 |
{ |
990 | 990 |
union unaligned_64 *ptr; |
991 | 991 |
uint64_t v; |
992 |
- READP(ptr, BINOP(0), 8); |
|
993 |
- READ64(v, BINOP(1)); |
|
992 |
+ READP(ptr, BINOP(1), 8); |
|
993 |
+ READ64(v, BINOP(0)); |
|
994 | 994 |
ptr->una_u64 = v; |
995 | 995 |
break; |
996 | 996 |
} |
... | ... |
@@ -1011,6 +1011,72 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
1011 | 1011 |
} |
1012 | 1012 |
break; |
1013 | 1013 |
} |
1014 |
+ DEFINE_OP(OP_BC_MEMCMP) { |
|
1015 |
+ int32_t arg3; |
|
1016 |
+ void *arg1, *arg2; |
|
1017 |
+ READ32(arg3, inst->u.three[2]); |
|
1018 |
+ READP(arg1, inst->u.three[0], arg3); |
|
1019 |
+ READP(arg2, inst->u.three[1], arg3); |
|
1020 |
+ WRITE32(inst->dest, memcmp(arg1, arg2, arg3)); |
|
1021 |
+ break; |
|
1022 |
+ } |
|
1023 |
+ DEFINE_OP(OP_BC_MEMCPY) { |
|
1024 |
+ int32_t arg3; |
|
1025 |
+ void *arg1, *arg2, *resp; |
|
1026 |
+ int64_t res; |
|
1027 |
+ |
|
1028 |
+ READ32(arg3, inst->u.three[2]); |
|
1029 |
+ READP(arg1, inst->u.three[0], arg3); |
|
1030 |
+ READP(arg2, inst->u.three[1], arg3); |
|
1031 |
+ memcpy(arg1, arg2, arg3); |
|
1032 |
+ READ64(res, inst->u.three[0]); |
|
1033 |
+ WRITE64(inst->dest, res); |
|
1034 |
+ break; |
|
1035 |
+ } |
|
1036 |
+ DEFINE_OP(OP_BC_MEMMOVE) { |
|
1037 |
+ int32_t arg3; |
|
1038 |
+ void *arg1, *arg2, *resp; |
|
1039 |
+ int64_t res; |
|
1040 |
+ |
|
1041 |
+ READ32(arg3, inst->u.three[2]); |
|
1042 |
+ READP(arg1, inst->u.three[0], arg3); |
|
1043 |
+ READP(arg2, inst->u.three[1], arg3); |
|
1044 |
+ memmove(arg1, arg2, arg3); |
|
1045 |
+ READ64(res, inst->u.three[0]); |
|
1046 |
+ WRITE64(inst->dest, res); |
|
1047 |
+ break; |
|
1048 |
+ } |
|
1049 |
+ DEFINE_OP(OP_BC_MEMSET) { |
|
1050 |
+ int32_t arg2, arg3; |
|
1051 |
+ void *arg1; |
|
1052 |
+ int64_t res; |
|
1053 |
+ |
|
1054 |
+ READ32(arg3, inst->u.three[2]); |
|
1055 |
+ READP(arg1, inst->u.three[0], arg3); |
|
1056 |
+ READ32(arg2, inst->u.three[1]); |
|
1057 |
+ memset(arg1, arg2, arg3); |
|
1058 |
+ READ64(res, inst->u.three[0]); |
|
1059 |
+ WRITE64(inst->dest, res); |
|
1060 |
+ break; |
|
1061 |
+ } |
|
1062 |
+ DEFINE_OP(OP_BC_BSWAP16) { |
|
1063 |
+ int16_t arg1; |
|
1064 |
+ READ16(arg1, inst->u.unaryop); |
|
1065 |
+ WRITE16(inst->dest, cbswap16(arg1)); |
|
1066 |
+ break; |
|
1067 |
+ } |
|
1068 |
+ DEFINE_OP(OP_BC_BSWAP32) { |
|
1069 |
+ int32_t arg1; |
|
1070 |
+ READ32(arg1, inst->u.unaryop); |
|
1071 |
+ WRITE32(inst->dest, cbswap32(arg1)); |
|
1072 |
+ break; |
|
1073 |
+ } |
|
1074 |
+ DEFINE_OP(OP_BC_BSWAP64) { |
|
1075 |
+ int32_t arg1; |
|
1076 |
+ READ64(arg1, inst->u.unaryop); |
|
1077 |
+ WRITE64(inst->dest, cbswap64(arg1)); |
|
1078 |
+ break; |
|
1079 |
+ } |
|
1014 | 1080 |
/* TODO: implement OP_BC_GEP1, OP_BC_GEP2, OP_BC_GEPN */ |
1015 | 1081 |
default: |
1016 | 1082 |
cli_errmsg("Opcode %u of type %u is not implemented yet!\n", |