Compare commits

..

No commits in common. "05793ad4ae677696fa93d17797440599a9bc2511" and "1afdc0db58a12002f97dad341e0ce1bf9c09ff48" have entirely different histories.

4 changed files with 1 additions and 258 deletions

141
asm/asm.c
View File

@ -1,6 +1,4 @@
#include "asm.h"
#include "common/arch.h"
#include "common/fmt_binary.h"
#include "common/op_str.h"
#include <stdbool.h>
#include <stddef.h>
@ -109,58 +107,6 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
ADD_LABEL(op1);
break;
}
case LineTy_JmpFar_Reg_Reg: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Jmp;
ins |= 1 << 7;
add_op1_reg(&ins, op1);
add_op2_reg(&ins, op2);
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_JmpFar_Reg_Imm: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.imm;
uint32_t ins = Op_Jmp;
ins |= 1 << 7;
ins |= 1 << 8;
add_op1_reg(&ins, op1);
out[ip++] = (uint16_t)ins;
out[ip++] = op2;
break;
}
case LineTy_JmpFar_Imm_Reg: {
uint16_t op1 = line->op1.imm;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Jmp;
ins |= 1 << 7;
set_is_imm(&ins);
add_op2_reg(&ins, op2);
out[ip++] = (uint16_t)ins;
out[ip++] = op1;
break;
}
case LineTy_JmpFar_Imm_Imm: {
uint16_t op1 = line->op1.imm;
uint16_t op2 = line->op2.imm;
uint32_t ins = Op_Jmp;
ins |= 1 << 7;
ins |= 1 << 8;
set_is_imm(&ins);
out[ip++] = (uint16_t)ins;
out[ip++] = op2;
out[ip++] = op1;
break;
}
case LineTy_Jnz_Reg: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.reg;
@ -484,17 +430,6 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
ADD_LABEL(dst);
break;
}
case LineTy_In_Reg: {
uint16_t dst = line->dst.reg;
uint16_t op1 = line->op1.reg;
uint32_t ins = Op_In;
add_op1_reg(&ins, op1);
add_dst_reg(&ins, dst);
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_In_Imm: {
uint16_t dst = line->dst.reg;
uint16_t op1 = line->op1.imm;
@ -507,15 +442,6 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
out[ip++] = op1;
break;
}
case LineTy_Call_Reg: {
uint16_t op1 = line->op1.reg;
uint32_t ins = Op_Call;
add_op1_reg(&ins, op1);
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_Call_Imm: {
uint16_t op1 = line->op1.imm;
@ -536,78 +462,11 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
ADD_LABEL(op1);
break;
}
case LineTy_CallFar_Reg_Reg: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
add_op1_reg(&ins, op1);
ins |= (op2 << 7) & 0x7;
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_CallFar_Reg_Imm: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.imm;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
ins |= 1 << 14;
add_op1_reg(&ins, op1);
out[ip++] = (uint16_t)ins;
out[ip++] = op2;
break;
}
case LineTy_CallFar_Imm_Reg: {
uint16_t op1 = line->op1.imm;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
set_is_imm(&ins);
ins |= (op2 << 7) & 0x7;
out[ip++] = (uint16_t)ins;
out[ip++] = op1;
break;
}
case LineTy_CallFar_Imm_Imm: {
uint16_t op1 = line->op1.imm;
uint16_t op2 = line->op2.imm;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
ins |= 1 << 14;
set_is_imm(&ins);
out[ip++] = (uint16_t)ins;
out[ip++] = op2;
out[ip++] = op1;
break;
}
case LineTy_Ret: {
uint32_t ins = Op_Ret;
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_RetFar: {
uint32_t ins = Op_Ret;
ins |= 1 << 6;
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_Lit_Reg: {
uint16_t op1 = line->op1.reg;
uint32_t ins = Op_Lit;
add_op1_reg(&ins, op1);
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_Lit_Imm: {
uint16_t op1 = line->op1.imm;

View File

@ -13,10 +13,6 @@ typedef enum {
LineTy_Jmp_Reg,
LineTy_Jmp_Imm,
LineTy_Jmp_Label,
LineTy_JmpFar_Reg_Reg,
LineTy_JmpFar_Reg_Imm,
LineTy_JmpFar_Imm_Reg,
LineTy_JmpFar_Imm_Imm,
LineTy_Jnz_Reg,
LineTy_Jnz_Imm,
LineTy_Jnz_Label,
@ -42,18 +38,10 @@ typedef enum {
LineTy_Mov16_MemImm_Reg,
LineTy_Mov16_MemImm_Imm,
LineTy_Mov16_MemLabel_Reg,
LineTy_In_Reg,
LineTy_In_Imm,
LineTy_Call_Reg,
LineTy_Call_Imm,
LineTy_Call_Label,
LineTy_CallFar_Reg_Reg,
LineTy_CallFar_Reg_Imm,
LineTy_CallFar_Imm_Reg,
LineTy_CallFar_Imm_Imm,
LineTy_Ret,
LineTy_RetFar,
LineTy_Lit_Reg,
LineTy_Lit_Imm,
LineTy_Lit_Label,
LineTy_Int,
@ -125,10 +113,6 @@ Line s_hlt(void);
Line s_jmp_r(Reg op1_reg);
Line s_jmp_i(uint16_t op1_imm);
Line s_jmp_l(int op1_label);
Line s_jmpf_r_r(Reg op1_reg, Reg op2_reg);
Line s_jmpf_r_i(Reg op1_reg, uint16_t op2_imm);
Line s_jmpf_i_r(uint16_t op1_imm, Reg op2_reg);
Line s_jmpf_i_i(uint16_t op1_imm, uint16_t op2_imm);
Line s_jnz_r(Reg op1_reg, Reg op2_reg);
Line s_jnz_i(Reg op1_reg, uint16_t op2_imm);
Line s_jnz_l(Reg op1_reg, int op2_label);
@ -154,18 +138,10 @@ Line s_mov16_mr_i(Reg dst_reg, uint16_t dst_offset, uint16_t op2_imm);
Line s_mov16_mi_r(uint16_t dst_imm, Reg op2_reg);
Line s_mov16_mi_i(uint16_t dst_imm, uint16_t op2_imm);
Line s_mov16_ml_r(int dst_label, Reg op2_reg);
Line s_in_r(Reg dst_reg, Reg op1_reg);
Line s_in_i(Reg dst_reg, uint16_t op1_imm);
Line s_call_r(Reg op1_reg);
Line s_call_i(uint16_t op1_imm);
Line s_call_l(int op1_label);
Line s_callf_r_r(Reg op1_reg, Reg op2_reg);
Line s_callf_r_i(Reg op1_reg, uint16_t op2_imm);
Line s_callf_i_r(uint16_t op1_imm, Reg op2_reg);
Line s_callf_i_i(uint16_t op1_imm, uint16_t op2_imm);
Line s_ret(void);
Line s_retf(void);
Line s_lit_r(Reg op1_reg);
Line s_lit_i(uint16_t op1_imm);
Line s_lit_l(int op1_label);
Line s_int(uint8_t int_id);

View File

@ -53,43 +53,10 @@ Line s_jmp_l(int op1_label)
.op1 = (Ex) { .label = op1_label },
};
}
Line s_jmpf_r_r(Reg op1_reg, Reg op2_reg)
{
return (Line) {
.ty = LineTy_JmpFar_Reg_Reg,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_jmpf_r_i(Reg op1_reg, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_JmpFar_Reg_Imm,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .imm = op2_imm },
};
}
Line s_jmpf_i_r(uint16_t op1_imm, Reg op2_reg)
{
return (Line) {
.ty = LineTy_JmpFar_Imm_Reg,
.op1 = (Ex) { .imm = op1_imm },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_jmpf_i_i(uint16_t op1_imm, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_JmpFar_Imm_Imm,
.op1 = (Ex) { .imm = op1_imm },
.op2 = (Ex) { .imm = op2_imm },
};
}
Line s_jnz_r(Reg op1_reg, Reg op2_reg)
{
return (Line) {
.ty = LineTy_Jnz_Reg,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
@ -97,7 +64,6 @@ Line s_jnz_i(Reg op1_reg, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_Jnz_Imm,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .imm = op2_imm },
};
}
@ -288,14 +254,6 @@ Line s_mov16_ml_r(int dst_label, Reg op2_reg)
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_in_r(Reg dst_reg, Reg op1_reg)
{
return (Line) {
.ty = LineTy_In_Reg,
.dst = (Ex) { .reg = (uint16_t)dst_reg },
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
};
}
Line s_in_i(Reg dst_reg, uint16_t op1_imm)
{
return (Line) {
@ -304,13 +262,6 @@ Line s_in_i(Reg dst_reg, uint16_t op1_imm)
.op1 = (Ex) { .imm = op1_imm },
};
}
Line s_call_r(Reg op1_reg)
{
return (Line) {
.ty = LineTy_Call_Reg,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
};
}
Line s_call_i(uint16_t op1_imm)
{
return (Line) {
@ -325,53 +276,10 @@ Line s_call_l(int op1_label)
.op1 = (Ex) { .label = op1_label },
};
}
Line s_callf_r_r(Reg op1_reg, Reg op2_reg)
{
return (Line) {
.ty = LineTy_CallFar_Reg_Reg,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_callf_r_i(Reg op1_reg, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_CallFar_Reg_Imm,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .imm = op2_imm },
};
}
Line s_callf_i_r(uint16_t op1_imm, Reg op2_reg)
{
return (Line) {
.ty = LineTy_CallFar_Imm_Reg,
.op1 = (Ex) { .imm = op1_imm },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_callf_i_i(uint16_t op1_imm, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_CallFar_Imm_Imm,
.op1 = (Ex) { .imm = op1_imm },
.op2 = (Ex) { .imm = op2_imm },
};
}
Line s_ret(void)
{
return (Line) { .ty = LineTy_Ret };
}
Line s_retf(void)
{
return (Line) { .ty = LineTy_RetFar };
}
Line s_lit_r(Reg op1_reg)
{
return (Line) {
.ty = LineTy_Lit_Imm,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
};
}
Line s_lit_i(uint16_t op1_imm)
{
return (Line) {

View File

@ -1,4 +1,4 @@
#include "common/fmt_binary.h"
#include "asm/asm.h"
#include "common/op_str.h"
#include "common/video_character_display.h"
#include "vm.h"