Merge pull request #8 from maximumspatium/master

Fix for conditional branches and some more cleanup.
This commit is contained in:
dingusdev 2019-08-03 06:59:35 -07:00 committed by GitHub
commit 53cb4206d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 126 deletions

View File

@ -197,7 +197,7 @@ extern void ppc_grab_regssab();
extern void ppc_grab_regsdasimm();
extern void ppc_grab_regsdauimm();
extern void ppc_grab_regssasimm();
extern void ppc_grab_regsasimm();
extern void ppc_grab_regssauimm();
extern void ppc_grab_regsfpdb();

View File

@ -772,22 +772,21 @@ void address_quickgrab_translate(uint32_t address_grab, uint8_t num_bytes)
//regular grabbing
else if (address_grab < 0x80000000){
if ((address_grab >= 0x40000000) && (address_grab < 0x40400000) && is_nubus){
storage_area = address_grab % rom_file_setsize;
grab_macmem_ptr = machine_sysrom_mem;
ppc_set_return_val(storage_area, num_bytes);
return;
}
if (mpc106_check_membound(address_grab)){
if (address_grab > 0x03ffffff){ //for debug purposes
storage_area = address_grab;
grab_macmem_ptr = machine_sysram_mem;
}
else if ((address_grab >= 0x40000000) && (address_grab < 0x40400000)){
if (is_nubus){
storage_area = address_grab % rom_file_setsize;
grab_macmem_ptr = machine_sysrom_mem;
ppc_set_return_val(storage_area, num_bytes);
return;
}
else{
storage_area = address_grab;
grab_macmem_ptr = machine_sysram_mem;
}
storage_area = address_grab;
grab_macmem_ptr = machine_sysram_mem;
}
else if ((address_grab >= 0x5fffe000) && (address_grab <= 0x5fffffff)){
storage_area = address_grab % 0x2000;

View File

@ -30,8 +30,6 @@
uint32_t xercon;
uint32_t cmp_c;
uint32_t crm;
uint32_t br_bo;
uint32_t br_bi;
uint32_t rot_sh;
uint32_t rot_mb;
uint32_t rot_me;
@ -43,7 +41,6 @@
uint32_t ppc_to;
int32_t simm;
int32_t adr_li;
int32_t br_bd;
//Used for GP calcs
uint32_t ppc_result_a = 0;
@ -115,12 +112,10 @@ void ppc_grab_regsdauimm(){
ppc_result_a = ppc_state.ppc_gpr[reg_a];
}
void ppc_grab_regssasimm(){
reg_s = (ppc_cur_instruction >> 21) & 31;
void ppc_grab_regsasimm(){
reg_a = (ppc_cur_instruction >> 16) & 31;
simm = (int32_t)((int16_t)((ppc_cur_instruction) & 65535));
simm = (int32_t)((int16_t)(ppc_cur_instruction & 65535));
ppc_result_a = ppc_state.ppc_gpr[reg_a];
ppc_result_d = ppc_state.ppc_gpr[reg_s];
}
void ppc_grab_regssauimm(){
@ -1560,41 +1555,39 @@ void ppc_bla(){
grab_branch = 1;
}
void ppc_bc(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
uint32_t ctr_ok = 1;
uint32_t cnd_ok = 1;
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));
if (!(br_bo & 0x04)){
(ppc_state.ppc_spr[9])--;
(ppc_state.ppc_spr[9])--; /* decrement CTR */
}
ctr_ok = ((br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) ^ (br_bo & 0x02)));
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) == !(br_bo & 0x02));
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok){
ppc_next_instruction_address = (ppc_state.ppc_pc + br_bd);
grab_branch = 1;
}
/*
else{
printf("BRANCH FAILED: %d %d", ctr_ok, cnd_ok);
}*/
}
void ppc_bca(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
uint32_t ctr_ok = 1;
uint32_t cnd_ok = 1;
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));
if (!(br_bo & 0x04)){
(ppc_state.ppc_spr[9])--;
(ppc_state.ppc_spr[9])--; /* decrement CTR */
}
ctr_ok = ((br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) ^ (br_bo & 0x02)));
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) == !(br_bo & 0x02));
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok){
ppc_next_instruction_address = br_bd;
@ -1602,19 +1595,19 @@ void ppc_bca(){
}
}
void ppc_bcl(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
uint32_t ctr_ok = 1;
uint32_t cnd_ok = 1;
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));
if (!(br_bo & 0x04)){
(ppc_state.ppc_spr[9])--;
(ppc_state.ppc_spr[9])--; /* decrement CTR */
}
ctr_ok = ((br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) ^ (br_bo & 0x02)));
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) == !(br_bo & 0x02));
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok){
ppc_next_instruction_address = (ppc_state.ppc_pc + br_bd);
@ -1623,19 +1616,19 @@ void ppc_bcl(){
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
void ppc_bcla(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
br_bd = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFC));
uint32_t ctr_ok = 1;
uint32_t cnd_ok = 1;
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));
if (!(br_bo & 0x04)){
(ppc_state.ppc_spr[9])--;
(ppc_state.ppc_spr[9])--; /* decrement CTR */
}
ctr_ok = ((br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) ^ (br_bo & 0x02)));
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) == !(br_bo & 0x02));
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok){
ppc_next_instruction_address = br_bd;
@ -1644,66 +1637,64 @@ void ppc_bcla(){
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
void ppc_bcctr(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
void ppc_bcctr()
{
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
uint32_t cnd_ok = 1;
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
uint32_t cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (cnd_ok){
adr_li = (ppc_state.ppc_spr[9] & 0xFFFFFFFC);
ppc_next_instruction_address = adr_li;
ppc_next_instruction_address = (ppc_state.ppc_spr[9] & 0xFFFFFFFC);
grab_branch = 1;
}
}
void ppc_bcctrl(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
void ppc_bcctrl()
{
uint32_t br_bo = (ppc_cur_instruction >> 21) & 31;
uint32_t br_bi = (ppc_cur_instruction >> 16) & 31;
uint32_t cnd_ok = 1;
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
uint32_t cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (cnd_ok){
adr_li = (ppc_state.ppc_spr[9] & 0xFFFFFFFC);
ppc_next_instruction_address = adr_li;
ppc_next_instruction_address = (ppc_state.ppc_spr[9] & 0xFFFFFFFC);
grab_branch = 1;
}
ppc_state.ppc_spr[8] = ppc_state.ppc_pc + 4;
}
void ppc_bclr(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
uint32_t ctr_ok = 1;
uint32_t cnd_ok = 1;
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;
if (!(br_bo & 0x04)){
(ppc_state.ppc_spr[9])--;
(ppc_state.ppc_spr[9])--; /* decrement CTR */
}
ctr_ok = ((br_bo & 0x04) | ((ppc_state.ppc_spr[9] != 0) ^ (br_bo & 0x02)));
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) == !(br_bo & 0x02));
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok){
ppc_next_instruction_address = (ppc_state.ppc_spr[8] & 0xFFFFFFFC);
grab_branch = 1;
}
else{
printf("Branch failed. \n");
}
}
void ppc_bclrl(){
br_bo = (ppc_cur_instruction >> 21) & 31;
br_bi = (ppc_cur_instruction >> 16) & 31;
uint32_t ctr_ok = 1;
uint32_t cnd_ok = 1;
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;
if (!(br_bo & 0x04)){
(ppc_state.ppc_spr[9])--;
(ppc_state.ppc_spr[9])--; /* decrement CTR */
}
ctr_ok = ((br_bo & 0x04) | ((ppc_state.ppc_spr[9] != 0) ^ (br_bo & 0x02)));
cnd_ok = ((br_bo & 0x10) || !((ppc_state.ppc_cr & (0x80000000 >> br_bi)) ^ (br_bo & 0x08)));
ctr_ok = (br_bo & 0x04) || ((ppc_state.ppc_spr[9] != 0) == !(br_bo & 0x02));
cnd_ok = (br_bo & 0x10) || (!(ppc_state.ppc_cr & (0x80000000 >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok){
ppc_next_instruction_address = (ppc_state.ppc_spr[8] & 0xFFFFFFFC);
@ -1728,45 +1719,51 @@ void ppc_cmp(){
}
void ppc_cmpi(){
//if (!((ppc_cur_instruction >> 21) && 0x1)){
crf_d = (ppc_cur_instruction >> 23) & 7;
crf_d = crf_d << 2;
ppc_grab_regssasimm();
xercon = (ppc_state.ppc_spr[1] & 0x80000000) >> 3;
cmp_c = (((int32_t)ppc_result_a) == simm) ? 0x20000000 : (((int32_t)ppc_result_a) > simm) ? 0x40000000 : 0x80000000;
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000 >> crf_d)) | ((cmp_c + xercon) >> crf_d));
// }
//else{
// printf("Warning: Invalid CMP Instruction.");
//}
#ifdef CHECK_INVALID
if (ppc_cur_instruction & 0x200000) {
printf("WARNING: invalid CMPI instruction form (L=1)!\n");
return;
}
#endif
crf_d = (ppc_cur_instruction >> 23) & 7;
crf_d = crf_d << 2;
ppc_grab_regsasimm();
xercon = (ppc_state.ppc_spr[1] & 0x80000000) >> 3;
cmp_c = (((int32_t)ppc_result_a) == simm) ? 0x20000000 : (((int32_t)ppc_result_a) > simm) ? 0x40000000 : 0x80000000;
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000 >> crf_d)) | ((cmp_c + xercon) >> crf_d));
}
void ppc_cmpl(){
//if (!((ppc_cur_instruction >> 21) && 0x1)){
crf_d = (ppc_cur_instruction >> 23) & 7;
crf_d = crf_d << 2;
ppc_grab_regssab();
xercon = (ppc_state.ppc_spr[1] & 0x80000000) >> 3;
cmp_c = (ppc_result_a == ppc_result_b) ? 0x20000000 : (ppc_result_a > ppc_result_b) ? 0x40000000 : 0x80000000;
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000 >> crf_d)) | ((cmp_c + xercon) >> crf_d));
//}
//else{
// printf("Warning: Invalid CMP Instruction.");
//}
#ifdef CHECK_INVALID
if (ppc_cur_instruction & 0x200000) {
printf("WARNING: invalid CMPL instruction form (L=1)!\n");
return;
}
#endif
crf_d = (ppc_cur_instruction >> 23) & 7;
crf_d = crf_d << 2;
ppc_grab_regssab();
xercon = (ppc_state.ppc_spr[1] & 0x80000000) >> 3;
cmp_c = (ppc_result_a == ppc_result_b) ? 0x20000000 : (ppc_result_a > ppc_result_b) ? 0x40000000 : 0x80000000;
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000 >> crf_d)) | ((cmp_c + xercon) >> crf_d));
}
void ppc_cmpli(){
// if (!((ppc_cur_instruction >> 21) && 0x1)){
crf_d = (ppc_cur_instruction >> 23) & 7;
crf_d = crf_d << 2;
ppc_grab_regssauimm();
xercon = (ppc_state.ppc_spr[1] & 0x80000000) >> 3;
cmp_c = (ppc_result_a == uimm) ? 0x20000000 : (ppc_result_a > uimm) ? 0x40000000 : 0x80000000;
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000 >> crf_d)) | ((cmp_c + xercon) >> crf_d));
// }
//else{
// printf("Warning: Invalid CMP Instruction.");
// }
#ifdef CHECK_INVALID
if (ppc_cur_instruction & 0x200000) {
printf("WARNING: invalid CMPLI instruction form (L=1)!\n");
return;
}
#endif
crf_d = (ppc_cur_instruction >> 23) & 7;
crf_d = crf_d << 2;
ppc_grab_regssauimm();
xercon = (ppc_state.ppc_spr[1] & 0x80000000) >> 3;
cmp_c = (ppc_result_a == uimm) ? 0x20000000 : (ppc_result_a > uimm) ? 0x40000000 : 0x80000000;
ppc_state.ppc_cr = ((ppc_state.ppc_cr & ~(0xf0000000 >> crf_d)) | ((cmp_c + xercon) >> crf_d));
}
//Condition Register Changes