From ba3db9e7f6f8d2be5a5170dbac3f12c789306970 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 6 Oct 2014 01:51:00 +0300 Subject: [PATCH] don't pass trash in MSB bits to write8 and write16 handlers otherwise it effectively breaks the C ABI --- Ea.cpp | 30 ++++++++++++++++++++++++++---- OpMove.cpp | 23 ++++++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Ea.cpp b/Ea.cpp index effd4c2..fc4dff9 100644 --- a/Ea.cpp +++ b/Ea.cpp @@ -338,7 +338,7 @@ int EaRead(int a,int v,int ea,int size,int mask,EaRWType type,int set_nz) if (lsl>0) ot(" ldr%s r%d,[r7,r%d,lsl #%i]\n",Narm[nsarm],v,a,lsl); else if (lsl<0) ot(" ldr%s r%d,[r7,r%d,lsr #%i]\n",Narm[nsarm],v,a,-lsl); - else ot(" ldr%s r%d,[r7,r%d]\n",Sarm[nsarm],v,a); + else ot(" ldr%s r%d,[r7,r%d]\n",type==earwt_sign_extend?Sarm[nsarm]:Narm[nsarm],v,a); if (type == earwt_shifted_up && shift) ot(" mov%s r%d,r%d,asl #%d\n",s,v,v,shift); @@ -472,7 +472,7 @@ int EaWrite(int a,int v,int ea,int size,int mask,EaRWType type) } ot(";@ EaWrite: r%d into register[r%d]:\n",v,a); - if (shift) ot(" mov r%d,r%d,asr #%d\n",v,v,shift); + if (shift) ot(" mov r%d,r%d,lsr #%d\n",v,v,shift); if (lsl>0) ot(" str%s r%d,[r7,r%d,lsl #%i]\n",Narm[size&3],v,a,lsl); else if (lsl<0) ot(" str%s r%d,[r7,r%d,lsr #%i]\n",Narm[size&3],v,a,-lsl); @@ -485,8 +485,30 @@ int EaWrite(int a,int v,int ea,int size,int mask,EaRWType type) if (ea==0x3c) { ot("Error! Write EA=0x%x\n\n",ea); return 1; } - if (shift) ot(" mov r1,r%d,asr #%d\n",v,shift); - else if (v!=1) ot(" mov r1,r%d\n",v); + if (shift) + { + ot(" mov r1,r%d,lsr #%d\n",v,shift); + } + else if (v != 1 || (size < 2 && type != earwt_zero_extend)) + { + switch (size) { + case 0: + ot(" and r1,r%d,#0xff\n",v); + break; + case 1: + if (type != earwt_zero_extend) + { + ot(" mov r1,r%d,lsl #16\n",v); + ot(" mov r1,r1,lsr #16\n"); + break; + } + // fallthrough + case 2: + default: + ot(" mov r1,r%d\n",v); + break; + } + } MemHandler(1,size,a,eawrite_check_addrerr); // Call write handler diff --git a/OpMove.cpp b/OpMove.cpp index 3d893de..44842ee 100644 --- a/OpMove.cpp +++ b/OpMove.cpp @@ -96,6 +96,7 @@ void SuperChange(int op,int srh_reg) // Emit a Move opcode, 00xxdddd ddssssss int OpMove(int op) { + EaRWType eatype; int sea=0,tea=0; int size=0,use=0; int movea=0; @@ -133,13 +134,25 @@ int OpMove(int op) if (movea==0) { - EaCalcRead(-1,1,sea,size,0x003f,earwt_sign_extend,1); - OpGetFlagsNZ(1); + if (sea < 0x10 && size < 2) + { + eatype = earwt_zero_extend; + EaCalcRead(-1,1,sea,size,0x003f,eatype); + ot(" movs r2,r1,lsl #%d\n",size?16:24); + OpGetFlagsNZ(2); + } + else + { + eatype = earwt_shifted_up; + EaCalcRead(-1,1,sea,size,0x003f,eatype,1); + OpGetFlagsNZ(1); + } ot("\n"); } else { - EaCalcRead(-1,1,sea,size,0x003f,earwt_sign_extend); + eatype = earwt_sign_extend; + EaCalcRead(-1,1,sea,size,0x003f,eatype); size=2; // movea always expands to 32-bits } @@ -155,8 +168,8 @@ int OpMove(int op) else #endif { - EaCalc (0,0x0e00,tea,size,earwt_msb_dont_care); - EaWrite(0, 1,tea,size,0x0e00,earwt_msb_dont_care); + EaCalc (0,0x0e00,tea,size,eatype); + EaWrite(0, 1,tea,size,0x0e00,eatype); } #if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES -- 2.39.5