RPA Toolkit
dev
authormstoilov <mstoilov@b0bb84a5-424d-4f98-af44-3ef3f117eb03>
Tue, 28 Sep 2010 07:53:25 +0000 (00:53 -0700)
committermstoilov <mstoilov@b0bb84a5-424d-4f98-af44-3ef3f117eb03>
Tue, 28 Sep 2010 07:53:25 +0000 (00:53 -0700)
git-svn-id: svn+ssh://svn.crossrain.com/svn/rpase/trunk/rtk@189 b0bb84a5-424d-4f98-af44-3ef3f117eb03

rvm/rvmcodegen.h
rvm/rvmcpu.c
rvm/rvmcpu.h
rvm/rvmerror.h [new file with mode: 0644]
tests/opmap-test.c

index 3c07aa0..2dfc285 100644 (file)
@@ -2,6 +2,7 @@
 #define _RVMCODEGEN_H_
 
 #include "rtypes.h"
+#include "rvmerror.h"
 #include "rarray.h"
 #include "rhash.h"
 #include "rvmcpu.h"
@@ -13,6 +14,7 @@ extern "C" {
 #endif
 
 #define RVM_CODEGEN_FUNCINITOFFSET 4
+#define RVM_CODEGEN_E_NONE 0
 
 typedef struct rvm_codegen_s {
        rarray_t *code;
index 86e85e2..3477ff5 100644 (file)
@@ -781,11 +781,11 @@ static void rvm_cpu_dumpregs(rvm_asmins_t *pi, rvm_cpu_t *vm)
        buffer[50] = '\0';
        rvm_printf("%s", buffer);
 
-       rvm_printf("0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, FP=%ld, SP=%ld, LR=%ld, PC=%ld, S( %c%c%c%c )",
+       rvm_printf("0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, FP=%ld, SP=%ld, LR=%ld, PC=%ld, DA=0x%lx, S( %c%c%c%c )",
                RVM_GET_REGU(vm, 0), RVM_GET_REGU(vm, 1), RVM_GET_REGU(vm, 2), RVM_GET_REGU(vm, 3),
                RVM_GET_REGU(vm, 4), RVM_GET_REGU(vm, 5), RVM_GET_REGU(vm, 6), RVM_GET_REGU(vm, 7),
                RVM_GET_REGU(vm, 8), (long int)RVM_GET_REGU(vm, FP), (long int)RVM_GET_REGU(vm, SP),
-               (long int)RVM_GET_REGU(vm, LR), (long int)RVM_GET_REGU(vm, PC),
+               (long int)RVM_GET_REGU(vm, LR), (long int)RVM_GET_REGU(vm, PC), RVM_GET_REGU(vm, DA),
                vm->status & RVM_STATUS_V ? 'V' : '_',
                vm->status & RVM_STATUS_C ? 'C' : '_',
                vm->status & RVM_STATUS_N ? 'N' : '_',
index 8128b84..674b181 100644 (file)
@@ -174,6 +174,7 @@ do { \
 #define RVM_INC_REGM(__cpu__, __r__, __val__) do {rvm_asmins_t *p = RVM_GET_REGM(__cpu__, __r__); (__cpu__)->r[(__r__)].v.p = (rpointer)(p + (__val__)); } while (0)
 #define RVM_REG_INFO(__r__) (__r__)->info
 #define RVM_REG_SIZE(__r__) (__r__)->size
+#define RVM_REG_PTR(__cpu__, __r__) (&(__cpu__)->r[(__r__)])
 #define RVM_GET_REG(__cpu__, __r__) (__cpu__)->r[(__r__)]
 #define RVM_SET_REG(__cpu__, __r__, val) do { (__cpu__)->r[(__r__)] = (rvm_reg_t)(val); } while (0)
 #define RVM_SWI_TABLE(__op__) ((__op__) >> 16)
diff --git a/rvm/rvmerror.h b/rvm/rvmerror.h
new file mode 100644 (file)
index 0000000..5366f42
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _RVMERROR_H_
+#define _RVMERROR_H_
+
+#define RVM_E_NONE 0
+
+#include "rtypes.h"
+
+typedef ruint rvm_error_t;
+
+#define RVM_ERROR_BITS 16
+#define RVM_ERROR_MASK ((1 << RVM_ERROR_BITS) - 1)
+
+#define rvm_make_error(__m__, __c__) ((rvm_error_t)(((__m__) << RVM_ERROR_BITS) | ((__c__) & RVM_ERROR_MASK)))
+#define rvm_set_error(__p__, __m__, __c__) do { (*(__p__) = rvm_make_error(__m__, __c__)); } while (0)
+#define rvm_error_code(__e__) ((__e__) & RVM_ERROR_MASK)
+#define rvm_error_module(__e__) ((__e__) >> RVM_ERROR_BITS)
+
+#endif
index e199620..1db1d09 100644 (file)
@@ -10,12 +10,12 @@ typedef struct rvm_testctx_s {
 } rvm_testctx_t;
 
 
-static void test_swi_print_r0(rvm_cpu_t *cpu, rvm_asmins_t *ins)
+static void test_swi_print_r(rvm_cpu_t *cpu, rvm_asmins_t *ins)
 {
-       if (rvm_reg_gettype(&cpu->r[R0]) == RVM_DTYPE_LONG)
-               fprintf(stdout, "R0 = %ld\n", RVM_GET_REGL(cpu, R0));
-       else if (rvm_reg_gettype(&cpu->r[R0]) == RVM_DTYPE_DOUBLE)
-               fprintf(stdout, "R0 = %5.2f\n", RVM_GET_REGD(cpu, R0));
+       if (rvm_reg_gettype(RVM_REG_PTR(cpu, ins->op2)) == RVM_DTYPE_LONG)
+               fprintf(stdout, "R%d = %ld\n", ins->op2, RVM_GET_REGL(cpu, ins->op2));
+       else if (rvm_reg_gettype(RVM_REG_PTR(cpu, ins->op2)) == RVM_DTYPE_DOUBLE)
+               fprintf(stdout, "R%d = %5.2f\n", ins->op2, RVM_GET_REGD(cpu, ins->op2));
        else
                fprintf(stdout, "Unknown type\n");
 }
@@ -24,28 +24,28 @@ static void test_swi_print_r0(rvm_cpu_t *cpu, rvm_asmins_t *ins)
 static void test_swi_add(rvm_cpu_t *cpu, rvm_asmins_t *ins)
 {
        rvm_testctx_t *ctx = (rvm_testctx_t *)cpu->userdata;
-       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_ADD, cpu, &cpu->r[R0], &cpu->r[R1], &cpu->r[R2]);
+       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_ADD, cpu, RVM_REG_PTR(cpu, R0), RVM_REG_PTR(cpu, ins->op2), RVM_REG_PTR(cpu, ins->op3));
 }
 
 
 static void test_swi_sub(rvm_cpu_t *cpu, rvm_asmins_t *ins)
 {
        rvm_testctx_t *ctx = (rvm_testctx_t *)cpu->userdata;
-       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_SUB, cpu, &cpu->r[R0], &cpu->r[R1], &cpu->r[R2]);
+       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_SUB, cpu, RVM_REG_PTR(cpu, R0), RVM_REG_PTR(cpu, ins->op2), RVM_REG_PTR(cpu, ins->op3));
 }
 
 
 static void test_swi_mul(rvm_cpu_t *cpu, rvm_asmins_t *ins)
 {
        rvm_testctx_t *ctx = (rvm_testctx_t *)cpu->userdata;
-       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_MUL, cpu, &cpu->r[R0], &cpu->r[R1], &cpu->r[R2]);
+       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_MUL, cpu, RVM_REG_PTR(cpu, R0), RVM_REG_PTR(cpu, ins->op2), RVM_REG_PTR(cpu, ins->op3));
 }
 
 
 static void test_swi_div(rvm_cpu_t *cpu, rvm_asmins_t *ins)
 {
        rvm_testctx_t *ctx = (rvm_testctx_t *)cpu->userdata;
-       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_DIV, cpu, &cpu->r[R0], &cpu->r[R1], &cpu->r[R2]);
+       rvm_opmap_invoke_binary_handler(ctx->opmap, RVM_OPID_DIV, cpu, RVM_REG_PTR(cpu, R0), RVM_REG_PTR(cpu, ins->op2), RVM_REG_PTR(cpu, ins->op3));
 }
 
 
@@ -54,7 +54,7 @@ static rvm_switable_t switable[] = {
                {"sub", test_swi_sub},
                {"mul", test_swi_mul},
                {"div", test_swi_div},
-               {"print", test_swi_print_r0},
+               {"print", test_swi_print_r},
                {NULL, NULL},
 };
 
@@ -83,9 +83,11 @@ int main(int argc, char *argv[])
        code[off++] = rvm_asmd(RVM_MOV, R1, DA, XX, 1);
        code[off++] = rvm_asml(RVM_MOV, R2, DA, XX, 3.2);
 //     code[off++] = rvm_asm(RVM_SWI, DA, XX, XX, RVM_SWI_ID(ntable, 1));                      // mul
-
-       code[off++] = rvm_asm(RVM_SWI, DA, XX, XX, rvm_cpu_getswi(cpu, "add"));         // add
-       code[off++] = rvm_asm(RVM_SWI, DA, XX, XX, rvm_cpu_getswi(cpu, "print"));       // print
+       code[off++] = rvm_asm(RVM_MOV, R0, DA, XX, rvm_cpu_getswi(cpu, "add"));         // add
+       code[off++] = rvm_asm(RVM_SWI, R0, R1, R2, 0);
+       code[off++] = rvm_asm(RVM_SWI, DA, R1, XX, rvm_cpu_getswi(cpu, "print"));       // print
+       code[off++] = rvm_asm(RVM_SWI, DA, R2, XX, rvm_cpu_getswi(cpu, "print"));       // print
+       code[off++] = rvm_asm(RVM_SWI, DA, R0, XX, rvm_cpu_getswi(cpu, "print"));       // print
 
        code[off++] = rvm_asm(RVM_EXT, XX, XX, XX, 0);