Skip to content
Snippets Groups Projects
Verified Commit b0731913 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

> Manual commit: [DO NOT BUILD] tmp save my work

U201614531
recolic
Linux RECOLICPC 5.4.2-arch1-1 #1 SMP PREEMPT Thu, 05 Dec 2019 12:29:40 +0000 x86_64 GNU/Linux
 17:50:19 up 3 days, 22:58,  1 user,  load average: 0.86, 0.51, 0.48
66e2b24dcce06cb614c08d513ef02c8b8d206c20
parent e0036b79
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ include Makefile.git ...@@ -19,7 +19,7 @@ include Makefile.git
CXX ?= g++ CXX ?= g++
LD = $(CXX) LD = $(CXX)
INCLUDES = $(addprefix -I, $(INC_DIR)) INCLUDES = $(addprefix -I, $(INC_DIR))
CFLAGS += -O2 -MMD -Wall -ggdb3 $(INCLUDES) -fomit-frame-pointer CFLAGS += -O2 -MMD -Wall -ggdb3 $(INCLUDES) -fomit-frame-pointer -std=c++17
CFLAGS += -DDIFF_TEST_QEMU CFLAGS += -DDIFF_TEST_QEMU
# Files to be compiled # Files to be compiled
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "util/c_op.h" #include "util/c_op.h"
#include "cpu/relop.h" #include "cpu/relop.h"
#include "cpu/rtl-wrapper.h" #include "cpu/rtl-wrapper.h"
#include <util/util.h>
extern rtlreg_t t0, t1, t2, t3, at; extern rtlreg_t t0, t1, t2, t3, at;
...@@ -159,7 +160,17 @@ static inline void rtl_not(rtlreg_t *dest, const rtlreg_t* src1) { ...@@ -159,7 +160,17 @@ static inline void rtl_not(rtlreg_t *dest, const rtlreg_t* src1) {
static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) { static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) {
// dest <- signext(src1[(width * 8 - 1) .. 0]) // dest <- signext(src1[(width * 8 - 1) .. 0])
TODO(); switch(width) {
case 1:
*dest = rlib::signed_extend_low_bytes<1>(*src1);
return;
case 2:
*dest = rlib::signed_extend_low_bytes<2>(*src1);
return;
case 4:
*dest = rlib::signed_extend_low_bytes<4>(*src1);
return;
}
} }
template <int OperandBytes> template <int OperandBytes>
......
#ifndef RLIB_HUST_UTIL_HPP_
#define RLIB_HUST_UTIL_HPP_ 1
#include <common.h>
namespace rlib {
static inline int32_t signed_extend_low8b(const int32_t &val) {
return (int8_t)val;
}
}
#endif
#ifndef RLIB_HUST_UTIL_HPP_
#define RLIB_HUST_UTIL_HPP_ 1
#include <common.h>
namespace rlib {
template <size_t BytesCount>
static inline int32_t signed_extend_low_bytes(const int32_t &val) {
static_assert(BytesCount == 1 || BytesCount == 2 || BytesCount == 4);
if constexpr(BytesCount == 1)
return (int8_t)val;
else if constexpr(BytesCount == 2)
return (int16_t)val;
else return val;
}
}
#endif
#include "cpu/exec.h" #include "cpu/exec.h"
#include <util.h> #include <util/util.h>
make_EHelper(add) { make_EHelper(add) {
TODO(); rtl_sext(&t1, &id_dest->val, id_dest->width);
rtl_sext(&t2, &id_src->val, id_src->width);
rtl_add(&t0, &t1, &t2);
t3 = (t0 < t1);
rtl_set_CF(&t3);
t3 = ((((int32_t)(t1) >= 0) ^ (((int32_t)(t2) >= 0 ))) && (((int32_t)(t0) < 0) ^ (((int32_t)(t2) >= 0 )) ));
rtl_set_OF(&t3);
rtl_update_ZFSF(&t0, 4);
operand_write(id_dest, &t0);
print_asm_template2(add); print_asm_template2(add);
} }
make_EHelper(sub) { make_EHelper(sub) {
t1 = id_dest->val; rtl_sext(&t1, &id_dest->val, id_dest->width);
rtl_sext(&t2, &id_src->val, id_src->width);
if(id_src->width == 1 && id_dest->width > 1) {
uint32_t extended = rlib::signed_extend_low8b(id_src->simm);
rtl_sub(&id_dest->val, &id_dest->val, &extended);
}
else {
rtl_sub(&id_dest->val, &id_dest->val, &id_src->imm);
}
//int sr = get_s(id_dest->val, id_dest->width);
operand_write(id_dest, &id_dest->val);
rtl_setrelop(RELOP_LTU, &t0, &t1, &id_dest->val);
rtl_set_CF(&t0);
rtl_xor(&t0, &t1, &id_src->val);
rtl_xor(&t2, &id_dest->val, &t1);
rtl_and(&t0, &t0, &t2);
rtl_msb(&t0, &t0, id_dest->width);
rtl_set_OF(&t0);
rtl_update_ZFSF(&id_dest->val, id_dest->width); rtl_sub(&t0, &t1, &t2);
t3 = (t0 > t1);
rtl_set_CF(&t3);
t3 = ((((int32_t)(t1) < 0) == (((int32_t)(t2) >> 31) == 0)) && (((int32_t)(t0) < 0) != ((int32_t)(t1) < 0)));
rtl_set_OF(&t3);
rtl_update_ZFSF(&t0, 4);
operand_write(id_dest, &t0);
print_asm_template2(sub); print_asm_template2(sub);
} }
...@@ -38,19 +34,44 @@ make_EHelper(sub) { ...@@ -38,19 +34,44 @@ make_EHelper(sub) {
make_EHelper(cmp) { make_EHelper(cmp) {
TODO(); rtl_sext(&t1, &id_dest->val, id_dest->width);
rtl_sext(&t2, &id_src->val, id_src->width);
rtl_sub(&t0, &t1, &t2);
t3 = (t0 > t1);
rtl_set_CF(&t3);
t3 = ((((int32_t)(t1) < 0) == (((int32_t)(t2) >> 31) == 0)) && (((int32_t)(t0) < 0) != ((int32_t)(t1) < 0)));
rtl_set_OF(&t3);
rtl_update_ZFSF(&t0, 4);
print_asm_template2(cmp); print_asm_template2(cmp);
} }
make_EHelper(inc) { make_EHelper(inc) {
TODO(); rtl_addi(&t2, &id_dest->val, 1);
operand_write(id_dest, &t2);
rtl_update_ZFSF(&t2, id_dest->width);
rtl_xor(&t0, &id_dest->val, &id_src->val);
rtl_not(&t0, &t0);
rtl_xor(&t1, &id_dest->val, &t2);
rtl_and(&t0, &t0, &t1);
rtl_msb(&t0, &t0, id_dest->width);
rtl_set_OF(&t0);
print_asm_template1(inc); print_asm_template1(inc);
} }
make_EHelper(dec) { make_EHelper(dec) {
TODO(); rtl_subi(&t2, &id_dest->val, 1);
operand_write(id_dest, &t2);
rtl_update_ZFSF(&t2, id_dest->width);
rtl_xor(&t0, &id_dest->val, &id_src->val);
rtl_xor(&t1, &id_dest->val, &t2);
rtl_and(&t0, &t0, &t1);
rtl_msb(&t0, &t0, id_dest->width);
rtl_set_OF(&t0);
print_asm_template1(dec); print_asm_template1(dec);
} }
......
...@@ -14,14 +14,27 @@ void rtl_setcc(rtlreg_t* dest, uint8_t subcode) { ...@@ -14,14 +14,27 @@ void rtl_setcc(rtlreg_t* dest, uint8_t subcode) {
// TODO: Query EFLAGS to determine whether the condition code is satisfied. // TODO: Query EFLAGS to determine whether the condition code is satisfied.
// dest <- ( cc is satisfied ? 1 : 0) // dest <- ( cc is satisfied ? 1 : 0)
switch (subcode & 0xe) { switch (subcode & 0xe) {
case CC_O: case CC_O: //0
case CC_B: *dest = cpu_eflags::get<cpu_eflags::OF>();
case CC_E: break;
case CC_BE: case CC_B: //2
case CC_S: *dest = cpu_eflags::get<cpu_eflags::CF>();
case CC_L: break;
case CC_LE: case CC_E: //4
TODO(); *dest = cpu_eflags::get<cpu_eflags::ZF>();
break;
case CC_BE: //6
*dest = ((cpu_eflags::get<cpu_eflags::CF>()) || (cpu_eflags::get<cpu_eflags::ZF>()));
break;
case CC_S: //8
*dest = cpu_eflags::get<cpu_eflags::SF>();
break;
case CC_L: //12 c
*dest = (cpu_eflags::get<cpu_eflags::SF>() != cpu_eflags::get<cpu_eflags::OF>());
break;
case CC_LE: //14 e
*dest = ((cpu_eflags::get<cpu_eflags::ZF>()) || (cpu_eflags::get<cpu_eflags::SF>() != cpu_eflags::get<cpu_eflags::OF>()));
break;
default: panic("should not reach here"); default: panic("should not reach here");
case CC_P: panic("n86 does not have PF"); case CC_P: panic("n86 does not have PF");
} }
......
...@@ -47,7 +47,15 @@ make_EHelper(popa) { ...@@ -47,7 +47,15 @@ make_EHelper(popa) {
} }
make_EHelper(leave) { make_EHelper(leave) {
TODO(); rtl_mv(&cpu.esp, &cpu.ebp);
if(decoding.is_operand_size_16) {
rtlreg_t tmpReg;
rtl_pop<2>(&tmpReg);
reg_w(R_BP) = (uint16_t)tmpReg;
}
else {
rtl_pop<4>(&cpu.ebp);
}
print_asm("leave"); print_asm("leave");
} }
......
...@@ -2,13 +2,21 @@ ...@@ -2,13 +2,21 @@
#include "cpu/cc.h" #include "cpu/cc.h"
make_EHelper(test) { make_EHelper(test) {
TODO(); // `and` without write_back.
rtl_and(&t1, &id_dest->val, &id_src->val);
rtl_update_ZFSF(&t1, id_dest->width);
cpu_eflags::get<cpu_eflags::CF>() = cpu_eflags::get<cpu_eflags::OF>() = false;
print_asm_template2(test); print_asm_template2(test);
} }
make_EHelper(and) { make_EHelper(and) {
TODO(); rtl_and(&id_dest->val, &id_dest->val, &id_src->val);
operand_write(id_dest, &id_dest->val);
rtl_update_ZFSF(&id_dest->val, id_dest->width);
cpu_eflags::get<cpu_eflags::CF>() = cpu_eflags::get<cpu_eflags::OF>() = false;
print_asm_template2(and); print_asm_template2(and);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment