From 2ac01c5ae31706ccbe4919224d99f55b51ce67e3 Mon Sep 17 00:00:00 2001 From: julianb0 Date: Wed, 15 May 2019 21:56:42 +0200 Subject: [PATCH] stuff --- instr/INSTRS | 4 +- instr/instrs.c | 2 +- instr/instrs.h | 2 +- instr/instrs.py | 2 +- instrs.c | 141 ------------------------------------------------ karch/main.c | 2 +- 6 files changed, 6 insertions(+), 147 deletions(-) delete mode 100644 instrs.c diff --git a/instr/INSTRS b/instr/INSTRS index 4ccddfd..4476fd6 100644 --- a/instr/INSTRS +++ b/instr/INSTRS @@ -1,5 +1,5 @@ # The OS/K Team licences this file to you under the MIT license. -# See the LICENCE file in the project root for more information. +# See the LICENSE file in the project root for more information. add r r add r i @@ -19,7 +19,7 @@ sub m m mul r mul i - rax = hi(rax * %0) + rdx = hi(rax * %0) rax = lo(rax * %0) div r diff --git a/instr/instrs.c b/instr/instrs.c index f19cdb1..86bff40 100644 --- a/instr/instrs.c +++ b/instr/instrs.c @@ -1,5 +1,5 @@ // The OS/K Team licences this file to you under the MIT license. -// See the LICENCE file in the project root for more information. +// See the LICENSE file in the project root for more information. #include "instrs.h" diff --git a/instr/instrs.h b/instr/instrs.h index df7e94a..6562f54 100644 --- a/instr/instrs.h +++ b/instr/instrs.h @@ -1,5 +1,5 @@ // The OS/K Team licences this file to you under the MIT license. -// See the LICENCE file in the project root for more information. +// See the LICENSE file in the project root for more information. #include "arch.h" diff --git a/instr/instrs.py b/instr/instrs.py index 2a3f597..b817271 100644 --- a/instr/instrs.py +++ b/instr/instrs.py @@ -1,7 +1,7 @@ #!/usr/bin/python # The OS/K Team licences this file to you under the MIT license. -# See the LICENCE file in the project root for more information. +# See the LICENSE file in the project root for more information. fi = open("instr/INSTRS") hd = open("instr/arch_i.h", "w") diff --git a/instrs.c b/instrs.c deleted file mode 100644 index f4cce91..0000000 --- a/instrs.c +++ /dev/null @@ -1,141 +0,0 @@ -// The OS/K Team licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#include "arch.h" - -void i_add(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->type != A_REG) { - _except(ctx, E_ILL, "ADD into IMM"); - } - - if (p1->mem || p2->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ctx->r[p1->val].val += p2->type >= A_IMM16 ? p2->val - : ctx->r[p2->val].val; -} - -void i_sub(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->type != A_REG) { - _except(ctx, E_ILL, "SUB into IMM"); - } - - if (p1->mem || p2->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ctx->r[p1->val].val -= p2->type >= A_IMM16 ? p2->val - : ctx->r[p2->val].val; -} - -void i_mul(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - // Adapted from www.codeproject.com/Tips/618570/UInt-Multiplication-Squaring - - ulong u = p1->type >= A_IMM16 ? p1->val : ctx->r[p1->val].val; - ulong v = ctx->r[RAX].val; - ulong u1 = u & 0xffffffff; - ulong v1 = v & 0xffffffff; - ulong t = (u1 * v1); - ulong w3 = (t & 0xffffffff); - ulong k = (t >> 32); - - u >>= 32; - t = (u * v1) + k; - k = (t & 0xffffffff); - ulong w1 = (t >> 32); - - v >>= 32; - t = (u1 * v) + k; - k = (t >> 32); - - ctx->r[RDX].val = (u * v) + w1 + k; - ctx->r[RAX].val = (t << 32) + w3; -} - -void i_div(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ulong val = p1->type >= A_IMM16 ? p1->val : ctx->r[p1->val].val; - - ctx->r[RDX].val = ctx->r[RAX].val % val; - ctx->r[RAX].val = ctx->r[RAX].val / val; -} - -void i_inc(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->type != A_REG) { - _except(ctx, E_ILL, "INC on an IMM"); - } - - if (p1->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ctx->r[p1->val].val++; -} - -void i_dec(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->type != A_REG) { - _except(ctx, E_ILL, "DEC on an IMM"); - } - - if (p1->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ctx->r[p1->val].val--; -} - -void i_mov(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->type != A_REG) { - _except(ctx, E_ILL, "MOV into IMM"); - } - - if (p1->mem || p2->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ctx->r[p1->val].val = p2->type >= A_IMM16 ? p2->val - : ctx->r[p2->val].val; -} - -void i_xchg(ctx_t *ctx, acc_t *p1, acc_t *p2) -{ - if (p1->type != A_REG || p2->type != A_REG) { - _except(ctx, E_ILL, "XCHG of IMM(s)"); - } - - if (p1->mem || p2->mem) { - _except(ctx, E_IMP, "Memory access"); - } - - ulong temp = ctx->r[p1->val].val; - ctx->r[p1->val].val = ctx->r[p2->val].val; - ctx->r[p2->val].val = temp; -} - -instr_t arch_i[NINSTRS] = -{ - [I_ADD] = { "ADD", 2, i_add }, - [I_SUB] = { "SUB", 2, i_sub }, - [I_MUL] = { "MUL", 1, i_mul }, - [I_DIV] = { "DIV", 1, i_div }, - [I_INC] = { "INC", 1, i_inc }, - [I_DEC] = { "DEC", 1, i_dec }, - [I_MOV] = { "MOV", 2, i_mov }, - [I_XCHG] = { "XCHG", 2, i_xchg }, -}; - diff --git a/karch/main.c b/karch/main.c index 20d83eb..9486fa1 100644 --- a/karch/main.c +++ b/karch/main.c @@ -1,5 +1,5 @@ // The OS/K Team licences this file to you under the MIT license. -// See the LICENCE file in the project root for more information. +// See the LICENSE file in the project root for more information. #include "arch.h"