Ejemplo n.º 1
0
void virtual_push(asmjit::X86Assembler& a, MemoryMapper& m, T value) {
	a.mov(REG_TMP, 0x0100);
	// @CLEANUP TMP is rax, but we can't or with a larger register
	a.add(asmjit::x86::al, REG_SP);
	m.emitDynamicStore(a, REG_TMP, value);
	a.dec(REG_SP);
}
Ejemplo n.º 2
0
void virtual_pop(asmjit::X86Assembler& a, MemoryMapper& m, T dst) {
	a.inc(REG_SP);
	a.mov(REG_TMP, 0x0100);
	// @CLEANUP TMP is rax, but we can't or with a larger register
	a.add(asmjit::x86::al, REG_SP);
	m.emitDynamicLoad(a, REG_TMP, dst);
}
Ejemplo n.º 3
0
bool LDXImmInstr::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.mov(REG_X, this->m_value);
	// Immediate mode knows the value at compile time, so just emit the right
	// thing
	if(this->m_value == 0)
		a.bts(REG_S, S_ZERO);
	else
		a.btr(REG_S, S_ZERO);
	return true;
}
Ejemplo n.º 4
0
bool RTS::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	// Use rbx because that's safe during a call
	virtual_pop(a, m, asmjit::x86::bl);
	a.shl(asmjit::x86::bx, 8);
	virtual_pop(a, m, asmjit::x86::dl);
	a.or_(asmjit::x86::bx, asmjit::x86::dx);
	a.mov(asmjit::x86::rdi, asmjit::x86::rbx);
	a.jmp((uint64_t)&jit_and_jump);
	return false;
}
Ejemplo n.º 5
0
bool JSRAbsInstr::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	// Push the virtual PC to the stack
	// @COMPLETENESS: This order is likely wrong!
	virtual_push(a, m, static_cast<uint8_t>(next & 0xFF));
	virtual_push(a, m, static_cast<uint8_t>(next >> 8));

	a.mov(asmjit::x86::di, this->target);
	a.jmp((uint64_t)&jit_and_jump);
	return false;
}
Ejemplo n.º 6
0
static void emitDump(asmjit::X86Assembler& a) {
	a.push(asmjit::x86::r10);
	a.push(asmjit::x86::r11);

	a.mov(asmjit::x86::dil, REG_A);
	a.mov(asmjit::x86::sil, REG_X);
	a.mov(asmjit::x86::dl, REG_Y);
	a.mov(asmjit::x86::cl, REG_S);
	a.call((uint64_t)&dump);

	a.pop(asmjit::x86::r11);
	a.pop(asmjit::x86::r10);
}
Ejemplo n.º 7
0
bool BEQRelInstr::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	auto NotSet = a.newLabel();

	a.bt(REG_S, S_ZERO);
	a.jnc(NotSet);
	a.mov(asmjit::x86::di, this->next + this->target);
	a.jmp((uint64_t)&jit_and_jump);
	a.bind(NotSet);
	a.mov(asmjit::x86::di, this->next);
	a.jmp((uint64_t)&jit_and_jump);
	return false;
}
Ejemplo n.º 8
0
bool BPLRelInstr::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	auto Set = a.newLabel();

	a.bt(REG_S, S_NEGATIVE);
	a.jc(Set);
	a.mov(asmjit::x86::di, this->next + this->target);
	a.jmp((uint64_t)&jit_and_jump);
	a.bind(Set);
	a.mov(asmjit::x86::di, this->next);
	a.jmp((uint64_t)&jit_and_jump);
	return false;
}
Ejemplo n.º 9
0
bool CLC::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.btr(REG_S, S_CARRY);
	return true;
}
Ejemplo n.º 10
0
bool NOP::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.nop();
	return true;
}
Ejemplo n.º 11
0
void RamMemoryBank::emitLoad(asmjit::X86Assembler& a, uint16_t addr, asmjit::X86Gp dest) {
	auto temp = asmjit::x86::rax;
	a.mov(temp, (uint64_t)this->memory.get() + addr);
	a.mov(dest, asmjit::x86::byte_ptr(temp));
}
Ejemplo n.º 12
0
bool ANDImm::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.and_(REG_A, this->operand);
	return true;
}
Ejemplo n.º 13
0
bool CLD::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.btr(REG_S, S_DECIMAL);
	return true;
}
Ejemplo n.º 14
0
bool SEI::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.bts(REG_S, S_INTER_DISABLE);
	return true;
}
Ejemplo n.º 15
0
bool CMPImm::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.cmp(REG_A, this->operand);

	{
		a.pushfd();
		a.btr(REG_S, S_CARRY);
		a.popfd();
		auto End = a.newLabel();
		a.jnc(End);
		a.pushfd();
		a.bts(REG_S, S_CARRY);
		a.popfd();
		a.bind(End);
	}

	{
		a.pushfd();
		a.btr(REG_S, S_ZERO);
		a.popfd();


		auto End = a.newLabel();
		a.jne(End);
		a.pushfd();
		a.bts(REG_S, S_ZERO);
		a.popfd();
		a.bind(End);
	}

	{
		a.pushfd();
		a.btr(REG_S, S_NEGATIVE);
		a.popfd();


		auto End = a.newLabel();
		a.jns(End);
		a.pushfd();
		a.bts(REG_S, S_NEGATIVE);
		a.popfd();
		a.bind(End);
	}
	return true;
}
Ejemplo n.º 16
0
bool BITZeroP::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	m.emitLoad(a, operand, asmjit::x86::al);
	// @COMPLETENESS: We should check and set the S_ flags here before the and
	a.push(asmjit::x86::rax);

	a.and_(asmjit::x86::al, REG_A);
	auto Zero = a.newLabel();
	auto Exit = a.newLabel();
	a.jz(Zero);

	//Not zero
	a.btr(REG_S, S_ZERO);
	a.jmp(Exit);
	a.bind(Zero);
	a.bts(REG_S, S_ZERO);
	a.bind(Exit);

	a.pop(asmjit::x86::rax);

	{
		a.btr(REG_S, S_OVERFLOW);
		a.bt(asmjit::x86::al, 6);
		auto End = a.newLabel();
		a.jnc(End);
		a.bts(REG_S, S_OVERFLOW);
		a.bind(End);
	}

	{
		a.btr(REG_S, S_NEGATIVE);
		a.bt(asmjit::x86::al, 7);
		auto End = a.newLabel();
		a.jnc(End);
		a.bts(REG_S, S_NEGATIVE);
		a.bind(End);
	}
	return true;
}
Ejemplo n.º 17
0
bool LDAAbsXInstr::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	auto temp = asmjit::x86::rax;
	a.mov(temp, this->base);
	a.add(temp, REG_X);
	auto tmpPtr = asmjit::x86::byte_ptr(temp);

	{
		auto NotZero = a.newLabel();
		auto Exit = a.newLabel();
		a.cmp(tmpPtr, 0);
		a.jne(NotZero);
		// Value was 0
		a.bts(REG_S, S_ZERO);
		a.jmp(Exit);

		// Value was not 0
		a.bind(NotZero);
		a.btr(REG_S, S_ZERO);
		//No jmp required, just fall though

		a.bind(Exit);
	}

	a.mov(REG_A, tmpPtr);
	return true;
}
Ejemplo n.º 18
0
void RamMemoryBank::emitStore(asmjit::X86Assembler& a, uint16_t addr, asmjit::X86Gp src) {
	auto temp = asmjit::x86::rax;
	a.mov(temp, (uint64_t)this->memory.get() + addr);
	a.mov(asmjit::x86::byte_ptr(temp), src);
}
Ejemplo n.º 19
0
bool JMPAbsInstr::exp(asmjit::X86Assembler& a, MemoryMapper& m) {
	a.mov(asmjit::x86::di, this->m_target);
	a.jmp((uint64_t)&jit_and_jump);
	return false;
}