2020-01-05 17:38:32 +00:00
|
|
|
//DingusPPC
|
2019-10-16 04:15:12 +00:00
|
|
|
//Written by divingkatae and maximum
|
|
|
|
//(c)2018-20 (theweirdo) spatium
|
2019-07-02 02:15:33 +00:00
|
|
|
//Please ask for permission
|
|
|
|
//if you want to distribute this.
|
2020-01-05 17:38:32 +00:00
|
|
|
//(divingkatae#1017 or powermax#2286 on Discord)
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
// General opcodes for the processor - ppcopcodes.cpp
|
|
|
|
|
2020-02-24 05:36:31 +00:00
|
|
|
#include <thirdparty/loguru.hpp>
|
2019-07-02 02:15:33 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <array>
|
|
|
|
#include <thread>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdexcept>
|
2019-12-27 19:10:36 +00:00
|
|
|
#include "ppcemu.h"
|
2019-12-27 19:00:53 +00:00
|
|
|
#include "ppcmmu.h"
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
uint32_t crf_d;
|
|
|
|
uint32_t crf_s;
|
|
|
|
uint32_t reg_s;
|
|
|
|
uint32_t reg_d;
|
|
|
|
uint32_t reg_a;
|
|
|
|
uint32_t reg_b;
|
|
|
|
uint32_t reg_c; //used only for floating point multiplication operations
|
|
|
|
uint32_t xercon;
|
|
|
|
uint32_t cmp_c;
|
|
|
|
uint32_t crm;
|
|
|
|
uint32_t uimm;
|
|
|
|
uint32_t grab_sr;
|
|
|
|
uint32_t grab_inb; //This is for grabbing the number of immediate bytes for loading and storing
|
|
|
|
uint32_t ppc_to;
|
|
|
|
int32_t simm;
|
|
|
|
int32_t adr_li;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
//Used for GP calcs
|
2020-01-26 02:30:55 +00:00
|
|
|
uint32_t ppc_result_a = 0;
|
|
|
|
uint32_t ppc_result_b = 0;
|
|
|
|
uint32_t ppc_result_c = 0;
|
|
|
|
uint32_t ppc_result_d = 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
uint32_t strwrd_replace_value;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Extract the registers desired and the values of the registers
|
|
|
|
This also takes the MSR into account, mainly to determine
|
|
|
|
what endian the numbers are to be stored in.
|
|
|
|
**/
|
|
|
|
|
|
|
|
//Storage and register retrieval functions for the integer functions.
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_store_result_regd() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_result_d;
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_store_result_rega() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_result_a;
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regsdasimm() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
simm = (int32_t)((int16_t)((ppc_cur_instruction) & 65535));
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regsdauimm() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
uimm = (uint32_t)((uint16_t)((ppc_cur_instruction) & 65535));
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regsasimm() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
2019-08-03 04:38:23 +00:00
|
|
|
simm = (int32_t)((int16_t)(ppc_cur_instruction & 65535));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regssauimm() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
uimm = (uint32_t)((uint16_t)((ppc_cur_instruction) & 65535));
|
|
|
|
ppc_result_d = ppc_state.ppc_gpr[reg_s];
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regsdab() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
reg_b = (ppc_cur_instruction >> 11) & 31;
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
ppc_result_b = ppc_state.ppc_gpr[reg_b];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regssab() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
reg_b = (ppc_cur_instruction >> 11) & 31;
|
|
|
|
ppc_result_d = ppc_state.ppc_gpr[reg_s];
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
ppc_result_b = ppc_state.ppc_gpr[reg_b];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regssa() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
ppc_result_d = ppc_state.ppc_gpr[reg_s];
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regssb() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
2019-07-19 17:00:18 +00:00
|
|
|
reg_b = (ppc_cur_instruction >> 11) & 31;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_d = ppc_state.ppc_gpr[reg_s];
|
|
|
|
ppc_result_b = ppc_state.ppc_gpr[reg_b];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regsda() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_a = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
ppc_result_a = ppc_state.ppc_gpr[reg_a];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_grab_regsdb() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
reg_b = (ppc_cur_instruction >> 11) & 31;
|
|
|
|
ppc_result_b = ppc_state.ppc_gpr[reg_b];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Affects CR Field 0 - For integer operations
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_changecrf0(uint32_t set_result) {
|
2020-02-10 22:07:39 +00:00
|
|
|
ppc_state.ppc_cr &= 0x0FFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (set_result == 0) {
|
2019-10-09 01:39:39 +00:00
|
|
|
ppc_state.ppc_cr |= 0x20000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 22:07:39 +00:00
|
|
|
if (set_result & 0x80000000) {
|
|
|
|
ppc_state.ppc_cr |= 0x80000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 22:07:39 +00:00
|
|
|
ppc_state.ppc_cr |= 0x40000000UL;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 22:07:39 +00:00
|
|
|
/* copy XER[SO] into CR0[SO]. */
|
|
|
|
ppc_state.ppc_cr |= (ppc_state.ppc_spr[SPR::XER] >> 3) & 0x10000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Affects the XER register's Carry Bit
|
2020-02-09 07:01:26 +00:00
|
|
|
inline void ppc_carry(uint32_t a, uint32_t b) {
|
|
|
|
if (b < a) {
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 06:41:03 +00:00
|
|
|
inline void ppc_carry_sub(uint32_t a, uint32_t b) {
|
2020-02-09 07:01:26 +00:00
|
|
|
if (b >= a) {
|
2020-02-09 06:41:03 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 02:15:33 +00:00
|
|
|
//Affects the XER register's SO and OV Bits
|
|
|
|
|
2020-02-03 18:42:33 +00:00
|
|
|
inline void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
|
|
|
if ((a ^ b) & (a ^ d) & 0x80000000UL) {
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
The core functionality of this PPC emulation is within all of these void functions.
|
|
|
|
This is where the opcode tables in the ppcemumain.h come into play - reducing the number of comparisons needed.
|
|
|
|
This means loads of functions, but less CPU cycles needed to determine the function (theoretically).
|
|
|
|
**/
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addi() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdasimm();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_d = (reg_a == 0) ? simm : (ppc_result_a + simm);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addic() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdasimm();
|
|
|
|
ppc_result_d = (ppc_result_a + simm);
|
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addicdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdasimm();
|
|
|
|
ppc_result_d = (ppc_result_a + simm);
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addis() {
|
|
|
|
ppc_grab_regsdasimm();
|
|
|
|
ppc_result_d = (reg_a == 0) ? (simm << 16) : (ppc_result_a + (simm << 16));
|
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_add() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_adddot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
|
|
|
//addo + addodot
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addc() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addcdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addco() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addcodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_adde() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-17 15:40:19 +00:00
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addedot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addeo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addeodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addme() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + xer_ca - 1;
|
2020-01-26 02:30:55 +00:00
|
|
|
if (((xer_ca - 1) < 0xFFFFFFFFUL) | (ppc_result_d < ppc_result_a)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addmedot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + xer_ca - 1;
|
2020-01-26 02:30:55 +00:00
|
|
|
if (((xer_ca - 1) < 0xFFFFFFFFUL) | (ppc_result_d < ppc_result_a)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addmeo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + xer_ca - 1;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, 0, ppc_result_d);
|
2020-01-26 02:30:55 +00:00
|
|
|
if (((xer_ca - 1) < 0xFFFFFFFFUL) | (ppc_result_d < ppc_result_a)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addmeodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-19 06:31:16 +00:00
|
|
|
ppc_result_d = ppc_result_a + xer_ca - 1;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, 0, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2020-01-26 02:30:55 +00:00
|
|
|
if (((xer_ca - 1) < 0xFFFFFFFFUL) | (ppc_result_d < ppc_result_a)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addze() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_d = ppc_result_a + grab_xer;
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ppc_result_d < ppc_result_a) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addzedot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_d = ppc_result_a + grab_xer;
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ppc_result_d < ppc_result_a) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addzeo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_d = ppc_result_a + grab_xer;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ppc_result_d < ppc_result_a) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_addzeodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_d = ppc_result_a + grab_xer;
|
2020-02-03 18:42:33 +00:00
|
|
|
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ppc_result_d < ppc_result_a) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subf() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-09 07:04:38 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfc() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
2020-02-09 06:41:03 +00:00
|
|
|
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfcdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
2020-02-09 06:41:03 +00:00
|
|
|
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfco() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 06:41:03 +00:00
|
|
|
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfcodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ppc_result_b - ppc_result_a;
|
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 06:41:03 +00:00
|
|
|
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfic() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdasimm();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = simm - ppc_result_a;
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfe() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + ppc_result_b + grab_xer;
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfedot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + ppc_result_b + grab_xer;
|
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-02-03 23:58:04 +00:00
|
|
|
void ppc_subfeo() {
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
|
|
|
ppc_result_d = ~ppc_result_a + ppc_result_b + grab_xer;
|
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_store_result_regd();
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ppc_subfeodot() {
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + ppc_result_b + grab_xer;
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfme() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + grab_xer - 1;
|
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfmedot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-03 18:42:33 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + grab_xer - 1;
|
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-02-03 23:58:04 +00:00
|
|
|
void ppc_subfmeo() {
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_grab_regsda();
|
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + grab_xer - 1;
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_store_result_regd();
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ppc_subfmeodot() {
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_grab_regsda();
|
|
|
|
uint32_t grab_xer = !!(ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + grab_xer - 1;
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 05:06:01 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfze() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + (ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_subfzedot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + (ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-02-03 23:58:04 +00:00
|
|
|
void ppc_subfzeo() {
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + (ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_store_result_regd();
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ppc_subfzeodot() {
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_grab_regsda();
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_result_d = ~ppc_result_a + (ppc_state.ppc_spr[SPR::XER] & 0x20000000);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2020-02-09 03:35:11 +00:00
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2020-02-04 05:32:56 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_and() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d & ppc_result_b;
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_anddot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d & ppc_result_b;
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_andc() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d & ~(ppc_result_b);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_andcdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d & ~(ppc_result_b);
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_andidot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssauimm();
|
|
|
|
ppc_result_a = ppc_result_d & uimm;
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_andisdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssauimm();
|
|
|
|
ppc_result_a = ppc_result_d & (uimm << 16);
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_nand() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ~(ppc_result_d & ppc_result_b);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_nanddot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ~(ppc_result_d & ppc_result_b);
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_or() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d | ppc_result_b;
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_ordot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d | ppc_result_b;
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_orc() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d | ~(ppc_result_b);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_orcdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d | ~(ppc_result_b);
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_ori() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssauimm();
|
|
|
|
ppc_result_a = ppc_result_d | uimm;
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_oris() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssauimm();
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_result_a = (uimm << 16) | ppc_result_d;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_eqv() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ~(ppc_result_d ^ ppc_result_b);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_eqvdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ~(ppc_result_d ^ ppc_result_b);
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_nor() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ~(ppc_result_d | ppc_result_b);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_nordot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ~(ppc_result_d | ppc_result_b);
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_xor() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d ^ ppc_result_b;
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_xordot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
|
|
|
ppc_result_a = ppc_result_d ^ ppc_result_b;
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_xori() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssauimm();
|
|
|
|
ppc_result_a = ppc_result_d ^ uimm;
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_xoris() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssauimm();
|
|
|
|
ppc_result_a = ppc_result_d ^ (uimm << 16);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_neg() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_d = ~(ppc_result_a)+1;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_negdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_d = ~(ppc_result_a)+1;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_nego() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_d = ~(ppc_result_a)+1;
|
2020-01-31 23:54:37 +00:00
|
|
|
if (ppc_result_a == 0x80000000)
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xc0000000;
|
|
|
|
else
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFF;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_negodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_d = ~(ppc_result_a)+1;
|
2020-01-31 23:54:37 +00:00
|
|
|
if (ppc_result_a == 0x80000000)
|
2020-02-01 04:06:06 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xc0000000;
|
2020-01-31 23:54:37 +00:00
|
|
|
else
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFF;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cntlzw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2019-10-09 01:39:39 +00:00
|
|
|
|
|
|
|
uint32_t lead = 0;
|
|
|
|
uint32_t bit_check = ppc_result_d;
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
#ifdef USE_GCC_BUILTINS
|
2019-10-09 01:39:39 +00:00
|
|
|
lead = __builtin_clz(bit_check);
|
2020-01-31 17:03:27 +00:00
|
|
|
#elif defined USE_VS_BUILTINS
|
|
|
|
lead = __lzcnt(bit_check);
|
2020-01-26 02:30:55 +00:00
|
|
|
#else
|
2020-01-31 17:03:27 +00:00
|
|
|
for (uint32_t mask = 0x80000000UL; mask; lead++, mask >>= 1) {
|
|
|
|
if (bit_check & mask)
|
|
|
|
break;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-10-09 01:39:39 +00:00
|
|
|
ppc_result_a = lead;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cntlzwdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2019-10-09 01:39:39 +00:00
|
|
|
|
|
|
|
uint32_t lead = 0;
|
|
|
|
uint32_t bit_check = ppc_result_d;
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
#ifdef USE_GCC_BUILTINS
|
2019-10-09 01:39:39 +00:00
|
|
|
lead = __builtin_clz(bit_check);
|
2020-01-31 17:03:27 +00:00
|
|
|
#elif defined USE_VS_BUILTINS
|
|
|
|
lead = __lzcnt(bit_check);
|
2020-01-26 02:30:55 +00:00
|
|
|
#else
|
2020-01-31 17:03:27 +00:00
|
|
|
for (uint32_t mask = 0x80000000UL; mask; lead++, mask >>= 1) {
|
|
|
|
if (bit_check & mask)
|
|
|
|
break;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-10-09 01:39:39 +00:00
|
|
|
ppc_result_a = lead;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mulhwu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
uint64_t product = (uint64_t)ppc_result_a * (uint64_t)ppc_result_b;
|
|
|
|
ppc_result_d = (uint32_t)(product >> 32);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mulhwudot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
uint64_t product = (uint64_t)ppc_result_a * (uint64_t)ppc_result_b;
|
|
|
|
ppc_result_d = (uint32_t)(product >> 32);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mulhw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)ppc_result_b;
|
|
|
|
ppc_result_d = product >> 32;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mulhwdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)ppc_result_b;
|
|
|
|
ppc_result_d = product >> 32;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mullw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)ppc_result_b;
|
|
|
|
ppc_result_d = (uint32_t)product;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mullwdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)ppc_result_b;
|
|
|
|
ppc_result_d = (uint32_t)product;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mullwo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)ppc_result_b;
|
|
|
|
if (product != (int64_t)(int32_t)product) {
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 17:36:20 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2020-01-31 23:54:37 +00:00
|
|
|
}
|
2020-02-10 17:36:20 +00:00
|
|
|
ppc_result_d = (uint32_t)product;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mullwodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)ppc_result_b;
|
|
|
|
if (product != (int64_t)(int32_t)product) {
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 17:36:20 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2020-01-31 23:54:37 +00:00
|
|
|
}
|
2020-02-10 17:36:20 +00:00
|
|
|
ppc_result_d = (uint32_t)product;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mulli() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdasimm();
|
2020-02-10 17:36:20 +00:00
|
|
|
int64_t product = (int64_t)(int32_t)ppc_result_a * (int64_t)(int32_t)simm;
|
|
|
|
ppc_result_d = (uint32_t)product;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 15:06:56 +00:00
|
|
|
if (!ppc_result_b) { /* handle the "anything / 0" case */
|
|
|
|
ppc_result_d = (ppc_result_a & 0x80000000) ? -1 : 0; /* UNDOCUMENTED! */
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) {
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = 0xFFFFFFFF;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else { /* normal signed devision */
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = (int32_t)ppc_result_a / (int32_t)ppc_result_b;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 15:06:56 +00:00
|
|
|
|
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 15:06:56 +00:00
|
|
|
if (!ppc_result_b) { /* handle the "anything / 0" case */
|
|
|
|
ppc_result_d = (ppc_result_a & 0x80000000) ? -1 : 0; /* UNDOCUMENTED! */
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) {
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = 0xFFFFFFFF;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else { /* normal signed devision */
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = (int32_t)ppc_result_a / (int32_t)ppc_result_b;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 15:06:56 +00:00
|
|
|
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-10-09 01:39:39 +00:00
|
|
|
|
2020-02-10 15:06:56 +00:00
|
|
|
if (!ppc_result_b) { /* handle the "anything / 0" case */
|
|
|
|
ppc_result_d = (ppc_result_a & 0x80000000) ? -1 : 0; /* UNDOCUMENTED! */
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) {
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = 0xFFFFFFFF;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else { /* normal signed devision */
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = (int32_t)ppc_result_a / (int32_t)ppc_result_b;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 15:06:56 +00:00
|
|
|
|
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 15:06:56 +00:00
|
|
|
if (!ppc_result_b) { /* handle the "anything / 0" case */
|
|
|
|
ppc_result_d = (ppc_result_a & 0x80000000) ? -1 : 0; /* UNDOCUMENTED! */
|
2020-02-01 04:06:06 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) {
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = 0xFFFFFFFF;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else { /* normal signed devision */
|
2020-02-10 15:06:56 +00:00
|
|
|
ppc_result_d = (int32_t)ppc_result_a / (int32_t)ppc_result_b;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 15:06:56 +00:00
|
|
|
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 16:16:18 +00:00
|
|
|
if (!ppc_result_b) { /* division by zero */
|
2019-07-12 05:27:14 +00:00
|
|
|
ppc_result_d = 0;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_result_d = ppc_result_a / ppc_result_b;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwudot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 16:16:18 +00:00
|
|
|
if (!ppc_result_b) { /* division by zero */
|
2019-07-12 05:27:14 +00:00
|
|
|
ppc_result_d = 0;
|
2020-02-01 04:06:06 +00:00
|
|
|
ppc_state.ppc_cr |= 0x20000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_result_d = ppc_result_a / ppc_result_b;
|
2019-08-14 04:29:14 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwuo() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 16:16:18 +00:00
|
|
|
if (!ppc_result_b) { /* division by zero */
|
2019-07-12 05:27:14 +00:00
|
|
|
ppc_result_d = 0;
|
2020-02-01 04:06:06 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_result_d = ppc_result_a / ppc_result_b;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_divwuodot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-02-10 16:16:18 +00:00
|
|
|
if (!ppc_result_b) { /* division by zero */
|
2019-07-12 05:27:14 +00:00
|
|
|
ppc_result_d = 0;
|
2020-02-01 04:06:06 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0xC0000000;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_result_d = ppc_result_a / ppc_result_b;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xBFFFFFFFUL;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Value shifting
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_slw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = 0;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = ppc_result_d << (ppc_result_b & 0x1F);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_slwdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = 0;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = ppc_result_d << (ppc_result_b & 0x1F);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_srw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = 0;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = ppc_result_d >> (ppc_result_b & 0x1F);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_srwdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = 0;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = ppc_result_d >> (ppc_result_b & 0x1F);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_sraw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = (int32_t)ppc_result_d >> 31;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= (ppc_result_a & 1) << 29;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
uint32_t shift = ppc_result_b & 0x1F;
|
2020-02-10 03:41:05 +00:00
|
|
|
uint32_t mask = (1 << shift) - 1;
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = (int32_t)ppc_result_d >> shift;
|
|
|
|
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_srawdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = (int32_t)ppc_result_d >> 31;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= (ppc_result_a & 1) << 29;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
uint32_t shift = ppc_result_b & 0x1F;
|
2020-02-10 03:41:05 +00:00
|
|
|
uint32_t mask = (1 << shift) - 1;
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = (int32_t)ppc_result_d >> shift;
|
|
|
|
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_srawi() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-02-03 19:36:22 +00:00
|
|
|
unsigned shift = (ppc_cur_instruction >> 11) & 0x1F;
|
2020-02-10 03:41:05 +00:00
|
|
|
uint32_t mask = (1 << shift) - 1;
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = (int32_t)ppc_result_d >> shift;
|
|
|
|
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_srawidot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-02-03 19:36:22 +00:00
|
|
|
unsigned shift = (ppc_cur_instruction >> 11) & 0x1F;
|
2020-02-10 03:41:05 +00:00
|
|
|
uint32_t mask = (1 << shift) - 1;
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_result_a = (int32_t)ppc_result_d >> shift;
|
|
|
|
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
|
|
|
ppc_state.ppc_spr[SPR::XER] |= 0x20000000UL;
|
2020-02-10 03:41:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-03 19:36:22 +00:00
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0xDFFFFFFFUL;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2019-08-05 16:42:15 +00:00
|
|
|
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
|
|
|
static inline uint32_t rot_mask(unsigned rot_mb, unsigned rot_me)
|
|
|
|
{
|
|
|
|
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
|
|
|
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
|
|
|
|
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_rlwimi() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2019-08-05 16:42:15 +00:00
|
|
|
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
|
|
|
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
|
|
|
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
|
|
|
uint32_t mask = rot_mask(rot_mb, rot_me);
|
2020-01-26 02:30:55 +00:00
|
|
|
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
2019-08-05 16:42:15 +00:00
|
|
|
ppc_result_a = (ppc_result_a & ~mask) | (r & mask);
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_cur_instruction & 0x01) == 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
}
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_rlwinm() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2019-08-05 16:42:15 +00:00
|
|
|
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
|
|
|
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
|
|
|
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
|
|
|
uint32_t mask = rot_mask(rot_mb, rot_me);
|
2020-01-26 02:30:55 +00:00
|
|
|
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
2019-08-05 16:42:15 +00:00
|
|
|
ppc_result_a = r & mask;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_cur_instruction & 0x01) == 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
}
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_rlwnm() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2019-08-05 16:42:15 +00:00
|
|
|
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
|
|
|
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
|
|
|
uint32_t mask = rot_mask(rot_mb, rot_me);
|
2020-01-26 02:30:55 +00:00
|
|
|
uint32_t r = ((ppc_result_d << ppc_result_b) | (ppc_result_d >> (32 - ppc_result_b)));
|
2019-08-05 16:42:15 +00:00
|
|
|
ppc_result_a = r & mask;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_cur_instruction & 0x01) == 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
}
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mfcr() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_cr;
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mtsr() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_msr & 0x4000) == 0) {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
grab_sr = (ppc_cur_instruction >> 16) & 15;
|
|
|
|
ppc_state.ppc_sr[grab_sr] = ppc_state.ppc_gpr[reg_s];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mtsrin() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_msr & 0x4000) == 0) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssb();
|
2019-07-19 17:00:18 +00:00
|
|
|
grab_sr = ppc_result_b >> 28;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_sr[grab_sr] = ppc_result_d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mfsr() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_msr & 0x4000) == 0) {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
grab_sr = (ppc_cur_instruction >> 16) & 15;
|
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_sr[grab_sr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mfsrin() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_msr & 0x4000) == 0) {
|
2020-01-17 02:25:41 +00:00
|
|
|
ppc_grab_regsdb();
|
2019-07-19 17:00:18 +00:00
|
|
|
grab_sr = ppc_result_b >> 28;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_sr[grab_sr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mfmsr() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-11 20:48:56 +00:00
|
|
|
if (ppc_state.ppc_msr & 0x4000) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x00040000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-11 20:48:56 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_msr;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mtmsr() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-11 20:48:56 +00:00
|
|
|
if (ppc_state.ppc_msr & 0x4000) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x00040000);
|
|
|
|
}
|
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
ppc_state.ppc_msr = ppc_state.ppc_gpr[reg_s];
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mfspr() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
|
2020-01-15 03:50:01 +00:00
|
|
|
|
2020-01-27 00:36:22 +00:00
|
|
|
#ifdef PROFILER
|
2020-01-15 03:50:01 +00:00
|
|
|
if (ref_spr > 31) {
|
|
|
|
supervisor_inst_num++;
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_spr[ref_spr];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mtspr() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
|
|
|
|
reg_s = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
|
2020-01-27 00:36:22 +00:00
|
|
|
#ifdef PROFILER
|
2020-01-15 03:50:01 +00:00
|
|
|
if (ref_spr > 31) {
|
|
|
|
supervisor_inst_num++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ref_spr != 287) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_spr[ref_spr] = ppc_state.ppc_gpr[reg_s];
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
switch (ref_spr) {
|
2019-07-02 02:15:33 +00:00
|
|
|
//Mirror the TBRs in the SPR range to the user-mode TBRs.
|
2020-01-30 03:47:12 +00:00
|
|
|
case 284:
|
2020-02-10 03:41:05 +00:00
|
|
|
ppc_state.ppc_spr[284] = (uint32_t)timebase_counter;
|
2020-01-30 04:08:42 +00:00
|
|
|
ppc_state.ppc_tbr[TBR::TBL] = (uint32_t)timebase_counter;
|
2020-01-26 02:30:55 +00:00
|
|
|
break;
|
2020-01-30 03:47:12 +00:00
|
|
|
case 285:
|
2020-02-10 03:41:05 +00:00
|
|
|
ppc_state.ppc_spr[285] = (uint32_t)(timebase_counter >> 32);
|
2020-01-30 04:08:42 +00:00
|
|
|
ppc_state.ppc_tbr[TBR::TBU] = (uint32_t)(timebase_counter >> 32);
|
2020-01-26 02:30:55 +00:00
|
|
|
break;
|
|
|
|
case 528:
|
|
|
|
case 529:
|
|
|
|
case 530:
|
|
|
|
case 531:
|
|
|
|
case 532:
|
|
|
|
case 533:
|
|
|
|
case 534:
|
|
|
|
case 535:
|
|
|
|
ibat_update(ref_spr);
|
|
|
|
break;
|
|
|
|
case 536:
|
|
|
|
case 537:
|
|
|
|
case 538:
|
|
|
|
case 539:
|
|
|
|
case 540:
|
|
|
|
case 541:
|
|
|
|
case 542:
|
|
|
|
case 543:
|
|
|
|
dbat_update(ref_spr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ppc_mftb() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
|
|
|
|
reg_d = (ppc_cur_instruction >> 21) & 31;
|
2020-01-26 02:30:55 +00:00
|
|
|
switch (ref_spr) {
|
|
|
|
case 268:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_tbr[TBR::TBL];
|
2020-01-26 02:30:55 +00:00
|
|
|
break;
|
|
|
|
case 269:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_gpr[reg_d] = ppc_state.ppc_tbr[TBR::TBU];
|
2020-01-26 02:30:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "Invalid TBR access attempted!" << std::endl;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mtcrf() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t cr_mask = 0;
|
|
|
|
ppc_grab_regssa();
|
|
|
|
crm = ((ppc_cur_instruction >> 12) & 255);
|
|
|
|
//check this
|
2019-07-02 12:18:41 +00:00
|
|
|
cr_mask += (crm & 128) ? 0xF0000000 : 0x00000000;
|
2020-01-26 02:30:55 +00:00
|
|
|
cr_mask += (crm & 64) ? 0x0F000000 : 0x00000000;
|
|
|
|
cr_mask += (crm & 32) ? 0x00F00000 : 0x00000000;
|
|
|
|
cr_mask += (crm & 16) ? 0x000F0000 : 0x00000000;
|
|
|
|
cr_mask += (crm & 8) ? 0x0000F000 : 0x00000000;
|
|
|
|
cr_mask += (crm & 4) ? 0x00000F00 : 0x00000000;
|
|
|
|
cr_mask += (crm & 2) ? 0x000000F0 : 0x00000000;
|
|
|
|
cr_mask += (crm & 1) ? 0x0000000F : 0x00000000;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_cr = (ppc_result_d & cr_mask) | (ppc_state.ppc_cr & ~(cr_mask));
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_mcrxr() {
|
2019-07-02 02:15:33 +00:00
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_cr = (ppc_state.ppc_cr & ~(0xF0000000UL >> crf_d)) | ((ppc_state.ppc_spr[SPR::XER] & 0xF0000000UL) >> crf_d);
|
|
|
|
ppc_state.ppc_spr[SPR::XER] &= 0x0FFFFFFF;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_extsb() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_result_d = ppc_result_d & 0xFF;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_a = (ppc_result_d < 0x80) ? (ppc_result_d & 0x000000FF) : (0xFFFFFF00UL | (ppc_result_d & 0x000000FF));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_extsbdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_result_d = ppc_result_d & 0xFF;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_a = (ppc_result_d < 0x80) ? (ppc_result_d & 0x000000FF) : (0xFFFFFF00UL | (ppc_result_d & 0x000000FF));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_extsh() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_result_d = ppc_result_d & 0xFFFF;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_a = (ppc_result_d < 0x8000) ? (ppc_result_d & 0x0000FFFF) : (0xFFFF0000UL | (ppc_result_d & 0x0000FFFF));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_extshdot() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-31 23:54:37 +00:00
|
|
|
ppc_result_d = ppc_result_d & 0xFFFF;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_result_a = (ppc_result_d < 0x8000) ? (ppc_result_d & 0x0000FFFF) : (0xFFFF0000UL | (ppc_result_d & 0x0000FFFF));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Branching Instructions
|
|
|
|
|
|
|
|
//The last two bytes of the instruction are used for determining how the branch happens.
|
|
|
|
//The middle 24 bytes are the 24-bit address to use for branching to.
|
|
|
|
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_b() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
|
2020-01-26 02:30:55 +00:00
|
|
|
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = (uint32_t)(ppc_state.ppc_pc + adr_li);
|
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_bl() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
|
2020-01-26 02:30:55 +00:00
|
|
|
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = (uint32_t)(ppc_state.ppc_pc + adr_li);
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::LR] = (uint32_t)(ppc_state.ppc_pc + 4);
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_ba() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
|
2020-01-26 02:30:55 +00:00
|
|
|
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = adr_li;
|
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_bla() {
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
|
2020-01-26 02:30:55 +00:00
|
|
|
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = adr_li;
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::LR] = ppc_state.ppc_pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bc()
|
|
|
|
{
|
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
int32_t br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
2019-08-14 04:29:14 +00:00
|
|
|
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.ppc_pc + br_bd);
|
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bca()
|
|
|
|
{
|
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
int32_t br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
2019-08-14 04:29:14 +00:00
|
|
|
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = br_bd;
|
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bcl()
|
|
|
|
{
|
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
int32_t br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
2019-08-14 04:29:14 +00:00
|
|
|
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.ppc_pc + br_bd);
|
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::LR] = ppc_state.ppc_pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bcla()
|
|
|
|
{
|
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
int32_t br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
2019-08-14 04:29:14 +00:00
|
|
|
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_next_instruction_address = br_bd;
|
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::LR] = ppc_state.ppc_pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bcctr()
|
|
|
|
{
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2019-08-14 04:29:14 +00:00
|
|
|
uint32_t cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (cnd_ok) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.ppc_spr[SPR::CTR] & 0xFFFFFFFCUL);
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bcctrl()
|
|
|
|
{
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2019-08-14 04:29:14 +00:00
|
|
|
uint32_t cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (cnd_ok) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.ppc_spr[SPR::CTR] & 0xFFFFFFFCUL);
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::LR] = ppc_state.ppc_pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bclr()
|
|
|
|
{
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
2019-08-14 04:29:14 +00:00
|
|
|
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.ppc_spr[SPR::LR] & 0xFFFFFFFCUL);
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:00:04 +00:00
|
|
|
void ppc_bclrl()
|
|
|
|
{
|
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-01-28 03:39:23 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
2019-08-14 04:29:14 +00:00
|
|
|
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.ppc_spr[SPR::LR] & 0xFFFFFFFCUL);
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_branch = 1;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::LR] = ppc_state.ppc_pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
//Compare Instructions
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cmp() {
|
2020-02-25 02:50:52 +00:00
|
|
|
#ifdef CHECK_INVALID
|
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
|
|
|
LOG_F(WARNING, "Invalid CMP instruction form (L=1)!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
|
|
|
ppc_grab_regssab();
|
2020-01-28 03:39:23 +00:00
|
|
|
xercon = (ppc_state.ppc_spr[SPR::XER] & 0x80000000UL) >> 3;
|
2020-01-26 02:30:55 +00:00
|
|
|
cmp_c = (((int32_t)ppc_result_a) == ((int32_t)ppc_result_b)) ? 0x20000000UL : (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) ? 0x40000000UL : 0x80000000UL;
|
|
|
|
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cmpi() {
|
|
|
|
#ifdef CHECK_INVALID
|
2019-08-03 04:38:23 +00:00
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMPI instruction form (L=1)!\n");
|
2019-08-03 04:38:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-08-03 04:38:23 +00:00
|
|
|
|
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
|
|
|
ppc_grab_regsasimm();
|
2020-01-28 03:39:23 +00:00
|
|
|
xercon = (ppc_state.ppc_spr[SPR::XER] & 0x80000000UL) >> 3;
|
2019-08-14 03:29:52 +00:00
|
|
|
cmp_c = (((int32_t)ppc_result_a) == simm) ? 0x20000000UL : (((int32_t)ppc_result_a) > simm) ? 0x40000000UL : 0x80000000UL;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cmpl() {
|
|
|
|
#ifdef CHECK_INVALID
|
2019-08-03 04:38:23 +00:00
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMPL instruction form (L=1)!\n");
|
2019-08-03 04:38:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-08-03 04:38:23 +00:00
|
|
|
|
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
|
|
|
ppc_grab_regssab();
|
2020-01-28 03:39:23 +00:00
|
|
|
xercon = (ppc_state.ppc_spr[SPR::XER] & 0x80000000UL) >> 3;
|
2019-08-14 03:29:52 +00:00
|
|
|
cmp_c = (ppc_result_a == ppc_result_b) ? 0x20000000UL : (ppc_result_a > ppc_result_b) ? 0x40000000UL : 0x80000000UL;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cmpli() {
|
|
|
|
#ifdef CHECK_INVALID
|
2019-08-03 04:38:23 +00:00
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMPLI instruction form (L=1)!\n");
|
2019-08-03 04:38:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-08-03 04:38:23 +00:00
|
|
|
|
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
|
|
|
ppc_grab_regssauimm();
|
2020-01-28 03:39:23 +00:00
|
|
|
xercon = (ppc_state.ppc_spr[SPR::XER] & 0x80000000UL) >> 3;
|
2019-08-14 03:29:52 +00:00
|
|
|
cmp_c = (ppc_result_a == uimm) ? 0x20000000UL : (ppc_result_a > uimm) ? 0x40000000UL : 0x80000000UL;
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Condition Register Changes
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_crand() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) && (ppc_state.ppc_cr & (0x80000000UL >> reg_b))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_crandc() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) && !(ppc_state.ppc_cr & (0x80000000UL >> reg_b))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_creqv() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) ^ (ppc_state.ppc_cr & (0x80000000UL >> reg_b)))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_crnand() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) && (ppc_state.ppc_cr & (0x80000000UL >> reg_b)))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_crnor() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) || (ppc_state.ppc_cr & (0x80000000UL >> reg_b)))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_cror() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) || (ppc_state.ppc_cr & (0x80000000UL >> reg_b))) {
|
2019-08-13 14:58:47 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-13 14:58:47 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_crorc() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) || !(ppc_state.ppc_cr & (0x80000000UL >> reg_b))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_crxor() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_state.ppc_cr & (0x80000000UL >> reg_a)) ^ (ppc_state.ppc_cr & (0x80000000UL >> reg_b))) {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
else {
|
2019-08-14 03:29:52 +00:00
|
|
|
ppc_state.ppc_cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Processor MGMT Fns.
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_rfi() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-01-28 03:39:23 +00:00
|
|
|
uint32_t new_srr1_val = (ppc_state.ppc_spr[SPR::SRR1] & 0x87C0FF73UL);
|
2019-10-09 01:39:39 +00:00
|
|
|
uint32_t new_msr_val = (ppc_state.ppc_msr & ~(0x87C0FF73UL));
|
|
|
|
ppc_state.ppc_msr = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_next_instruction_address = ppc_state.ppc_spr[SPR::SRR0] & 0xFFFFFFFCUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
grab_return = true;
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_RFI;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_sc() {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_SYSCALL, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_tw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_a = (ppc_cur_instruction >> 11) & 31;
|
|
|
|
reg_b = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
ppc_to = (ppc_cur_instruction >> 21) & 31;
|
2019-07-02 12:18:41 +00:00
|
|
|
if ((((int32_t)ppc_state.ppc_gpr[reg_a] < (int32_t)ppc_state.ppc_gpr[reg_b]) & (ppc_to & 0x10)) || \
|
2020-01-26 02:30:55 +00:00
|
|
|
(((int32_t)ppc_state.ppc_gpr[reg_a] > (int32_t)ppc_state.ppc_gpr[reg_b])& (ppc_to & 0x08)) || \
|
|
|
|
(((int32_t)ppc_state.ppc_gpr[reg_a] == (int32_t)ppc_state.ppc_gpr[reg_b]) & (ppc_to & 0x04)) || \
|
|
|
|
((ppc_state.ppc_gpr[reg_a] < ppc_state.ppc_gpr[reg_b]) & (ppc_to & 0x02)) || \
|
|
|
|
((ppc_state.ppc_gpr[reg_a] > ppc_state.ppc_gpr[reg_b])& (ppc_to & 0x01))) {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_twi() {
|
2019-07-02 02:15:33 +00:00
|
|
|
simm = (int32_t)((int16_t)((ppc_cur_instruction) & 65535));
|
|
|
|
reg_b = (ppc_cur_instruction >> 16) & 31;
|
|
|
|
ppc_to = (ppc_cur_instruction >> 21) & 31;
|
2019-07-02 12:18:41 +00:00
|
|
|
if ((((int32_t)ppc_state.ppc_gpr[reg_a] < simm) & (ppc_to & 0x10)) || \
|
2020-01-26 02:30:55 +00:00
|
|
|
(((int32_t)ppc_state.ppc_gpr[reg_a] > simm)& (ppc_to & 0x08)) || \
|
|
|
|
(((int32_t)ppc_state.ppc_gpr[reg_a] == simm) & (ppc_to & 0x04)) || \
|
|
|
|
((ppc_state.ppc_gpr[reg_a] < (uint32_t)simm) & (ppc_to & 0x02)) || \
|
|
|
|
((ppc_state.ppc_gpr[reg_a] > (uint32_t)simm)& (ppc_to & 0x01))) {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_eieio() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_isync() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_sync() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_icbi() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_dcbf() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_dcbi() {
|
|
|
|
#ifdef PROFILER
|
2020-01-15 03:50:01 +00:00
|
|
|
supervisor_inst_num++;
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_dcbst() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_dcbt() {
|
2019-07-02 02:15:33 +00:00
|
|
|
//Not needed, the HDI reg is touched to no-op this instruction.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_dcbtst() {
|
2019-07-02 02:15:33 +00:00
|
|
|
//Not needed, the HDI reg is touched to no-op this instruction.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_dcbz() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
|
|
|
if (!(ppc_state.ppc_pc & 32) && (ppc_state.ppc_pc < 0xFFFFFFE0UL)) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-02-10 03:41:05 +00:00
|
|
|
mem_write_qword(ppc_effective_address, 0);
|
|
|
|
mem_write_qword((ppc_effective_address + 8), 0);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_qword((ppc_effective_address + 16), 0);
|
|
|
|
mem_write_qword((ppc_effective_address + 24), 0);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x00000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2019-07-02 02:15:33 +00:00
|
|
|
//Integer Load and Store Functions
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stb() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stbx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stbu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-22 02:25:50 +00:00
|
|
|
if (reg_a != 0) {
|
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, ppc_result_d);
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_effective_address;
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stbux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-18 04:26:09 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, ppc_result_d);
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_effective_address;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_sth() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_word(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_sthu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-18 04:06:26 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_word(ppc_effective_address, ppc_result_d);
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_effective_address;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_sthux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-18 04:06:26 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-18 04:26:09 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_word(ppc_effective_address, ppc_result_d);
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_effective_address;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_sthx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_word(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_sthbrx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-12 21:51:07 +00:00
|
|
|
ppc_result_d = (uint32_t)(BYTESWAP_16((uint16_t)ppc_result_d));
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_word(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
|
|
|
void ppc_stw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stwx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stwcx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
//PLACEHOLDER CODE FOR STWCX - We need to check for reserve memory
|
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
|
|
|
if (ppc_state.ppc_reserve) {
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_cr |= (ppc_state.ppc_spr[SPR::XER] & 0x80000000) ? 0x30000000 : 0x20000000;
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_reserve = false;
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_cr |= (ppc_state.ppc_spr[SPR::XER] & 0x80000000) ? 0x10000000 : 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stwu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-18 04:06:26 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_effective_address;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stwux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-18 04:06:26 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-18 04:26:09 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2020-01-18 04:06:26 +00:00
|
|
|
ppc_state.ppc_gpr[reg_a] = ppc_effective_address;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stwbrx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-12 21:51:07 +00:00
|
|
|
ppc_result_d = BYTESWAP_32(ppc_result_d);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stmw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
//How many words to store in memory - using a do-while for this
|
2020-01-22 02:25:50 +00:00
|
|
|
do {
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_dword(ppc_effective_address, ppc_result_d);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address += 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d++;
|
2020-01-22 02:25:50 +00:00
|
|
|
} while (reg_d < 32);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lbz() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_byte(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lbzu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_byte(ppc_effective_address);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_regd();
|
|
|
|
ppc_store_result_rega();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lbzx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_byte(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lbzux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_byte(ppc_effective_address);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_regd();
|
|
|
|
ppc_store_result_rega();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhz() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_word(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhzu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_word(ppc_effective_address);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_regd();
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhzx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_word(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhzux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_word(ppc_effective_address);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_regd();
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lha() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
uint16_t val = mem_grab_word(ppc_effective_address);
|
|
|
|
if (val & 0x8000) {
|
|
|
|
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (uint32_t)val;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhau() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
uint16_t val = mem_grab_word(ppc_effective_address);
|
|
|
|
if (val & 0x8000) {
|
|
|
|
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (uint32_t)val;
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_store_result_regd();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_rega();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhaux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
uint16_t val = mem_grab_word(ppc_effective_address);
|
|
|
|
if (val & 0x8000) {
|
|
|
|
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (uint32_t)val;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhax() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
uint16_t val = mem_grab_word(ppc_effective_address);
|
|
|
|
if (val & 0x8000) {
|
|
|
|
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (uint32_t)val;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_store_result_regd();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lhbrx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (uint32_t)(BYTESWAP_16(mem_grab_word(ppc_effective_address)));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lwz() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_dword(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lwbrx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = BYTESWAP_32(mem_grab_dword(ppc_effective_address));
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lwzu() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
|
|
|
ppc_effective_address += ppc_result_a;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_dword(ppc_effective_address);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_rega();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lwzx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_dword(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lwzux() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((reg_a != reg_d) || reg_a != 0) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_dword(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_result_regd();
|
|
|
|
ppc_store_result_rega();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lwarx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
//Placeholder - Get the reservation of memory implemented!
|
|
|
|
ppc_grab_regsdab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_state.ppc_reserve = true;
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = mem_grab_dword(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lmw() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
|
|
|
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
//How many words to load in memory - using a do-while for this
|
2020-01-22 02:25:50 +00:00
|
|
|
do {
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_state.ppc_gpr[reg_d] = mem_grab_dword(ppc_effective_address);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address += 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
reg_d++;
|
2020-01-22 02:25:50 +00:00
|
|
|
} while (reg_d < 32);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lswi() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
|
|
|
ppc_effective_address = ppc_result_a;
|
|
|
|
grab_inb = (ppc_cur_instruction >> 11) & 31;
|
2019-10-09 01:39:39 +00:00
|
|
|
grab_inb = (grab_inb & 32) == 0 ? 32 : grab_inb;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
uint32_t shift_times = 0;
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
while (grab_inb > 0) {
|
|
|
|
switch (shift_times) {
|
2019-07-02 02:15:33 +00:00
|
|
|
case 0:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_state.ppc_gpr[reg_d] = (ppc_result_d & 0x00FFFFFFUL) |
|
|
|
|
(mem_grab_byte(ppc_effective_address) << 24);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0xFF00FFFFUL) |
|
|
|
|
(mem_grab_byte(ppc_effective_address) << 16);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0xFFFF00FFUL) |
|
|
|
|
(mem_grab_byte(ppc_effective_address) << 8);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0xFFFFFF00UL) |
|
|
|
|
mem_grab_byte(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
default:
|
2020-02-24 05:36:31 +00:00
|
|
|
LOG_F(ERROR, "Something really horrible happened with lswi. \n");
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
if (shift_times == 3) {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times = 0;
|
|
|
|
reg_d = (reg_d + 1) & 0x1F;
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times++;
|
|
|
|
}
|
|
|
|
ppc_effective_address++;
|
|
|
|
grab_inb--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_lswx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsdab();
|
|
|
|
//Invalid instruction forms
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((ppc_result_d == 0) && (ppc_result_a == 0)) {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x100000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((ppc_result_d == ppc_result_a) || (ppc_result_a == ppc_result_b)) {
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x100000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-28 03:39:23 +00:00
|
|
|
grab_inb = ppc_state.ppc_spr[SPR::XER] & 127;
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t shift_times = 0;
|
2020-01-22 02:25:50 +00:00
|
|
|
while (grab_inb > 0) {
|
|
|
|
switch (shift_times) {
|
2019-07-02 02:15:33 +00:00
|
|
|
case 0:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0x00FFFFFFUL) |
|
|
|
|
(mem_grab_byte(ppc_effective_address) << 24);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0xFF00FFFFUL) |
|
|
|
|
(mem_grab_byte(ppc_effective_address) << 16);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0xFFFF00FFUL) |
|
|
|
|
(mem_grab_byte(ppc_effective_address) << 8);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-01-27 00:36:22 +00:00
|
|
|
ppc_result_d = (ppc_result_d & 0xFFFFFF00UL) |
|
|
|
|
mem_grab_byte(ppc_effective_address);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_store_result_regd();
|
|
|
|
break;
|
|
|
|
default:
|
2020-02-24 05:36:31 +00:00
|
|
|
LOG_F(ERROR, "Something really horrible happened with lswx. \n");
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
if (shift_times == 3) {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times = 0;
|
|
|
|
reg_d = (reg_d + 1) & 0x1F;
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times++;
|
|
|
|
}
|
|
|
|
ppc_effective_address++;
|
|
|
|
grab_inb--;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stswi() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssa();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? 0 : ppc_result_a;
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_inb = (ppc_cur_instruction >> 11) & 31;
|
2019-10-09 01:39:39 +00:00
|
|
|
grab_inb = (grab_inb & 32) == 0 ? 32 : grab_inb;
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t shift_times = 0;
|
2020-01-22 02:25:50 +00:00
|
|
|
while (grab_inb > 0) {
|
|
|
|
switch (shift_times) {
|
2019-07-02 02:15:33 +00:00
|
|
|
case 0:
|
|
|
|
strwrd_replace_value = (ppc_result_d >> 24);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
strwrd_replace_value = (ppc_result_d >> 16);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strwrd_replace_value = (ppc_result_d >> 8);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strwrd_replace_value = (ppc_result_d);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-02-24 05:36:31 +00:00
|
|
|
LOG_F(ERROR, "Something really horrible happened with stswi. \n");
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
if (shift_times == 3) {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times = 0;
|
|
|
|
reg_s = (reg_s + 1) & 0x1F;
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times++;
|
|
|
|
}
|
|
|
|
ppc_effective_address++;
|
|
|
|
grab_inb--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
void ppc_stswx() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regssab();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
2020-01-28 03:39:23 +00:00
|
|
|
grab_inb = ppc_state.ppc_spr[SPR::XER] & 127;
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t shift_times = 0;
|
2020-01-22 02:25:50 +00:00
|
|
|
while (grab_inb > 0) {
|
|
|
|
switch (shift_times) {
|
2019-07-02 02:15:33 +00:00
|
|
|
case 0:
|
|
|
|
strwrd_replace_value = (ppc_result_d >> 24);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
strwrd_replace_value = (ppc_result_d >> 16);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strwrd_replace_value = (ppc_result_d >> 8);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strwrd_replace_value = (ppc_result_d);
|
2020-01-27 00:36:22 +00:00
|
|
|
mem_write_byte(ppc_effective_address, strwrd_replace_value);
|
2019-07-02 02:15:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-02-24 05:36:31 +00:00
|
|
|
LOG_F(ERROR, "Something really horrible happened with stswx. \n");
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
if (shift_times == 3) {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times = 0;
|
|
|
|
reg_s = (reg_s + 1) & 0x1F;
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
else {
|
2019-07-02 02:15:33 +00:00
|
|
|
shift_times++;
|
|
|
|
}
|
|
|
|
ppc_effective_address++;
|
|
|
|
grab_inb--;
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//TLB Instructions
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_tlbie() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_tlbia() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_tlbld() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_tlbli() {
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-15 03:50:01 +00:00
|
|
|
|
|
|
|
void ppc_tlbsync() {
|
|
|
|
#ifdef PROFILER
|
|
|
|
supervisor_inst_num++;
|
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
|
|
|
}
|