summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp117
-rw-r--r--src/core/arm/interpreter/armemu.cpp14
-rw-r--r--src/core/arm/interpreter/armsupp.cpp8
-rw-r--r--src/core/arm/skyeye_common/armdefs.h2
-rw-r--r--src/core/arm/skyeye_common/armemu.h1
-rw-r--r--src/core/hle/service/soc_u.cpp2
6 files changed, 91 insertions, 53 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index d347496e5..bc55a082f 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -930,6 +930,8 @@ typedef struct _smlad_inst {
930 unsigned int Rd; 930 unsigned int Rd;
931 unsigned int Ra; 931 unsigned int Ra;
932 unsigned int Rn; 932 unsigned int Rn;
933 unsigned int op1;
934 unsigned int op2;
933} smlad_inst; 935} smlad_inst;
934 936
935typedef struct _smla_inst { 937typedef struct _smla_inst {
@@ -2313,25 +2315,40 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(smla)(unsigned int inst, int index)
2313 2315
2314 return inst_base; 2316 return inst_base;
2315} 2317}
2316ARM_INST_PTR INTERPRETER_TRANSLATE(smlad)(unsigned int inst, int index){
2317 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
2318 smlad_inst *inst_cream = (smlad_inst *)inst_base->component;
2319 2318
2320 inst_base->cond = BITS(inst, 28, 31); 2319ARM_INST_PTR INTERPRETER_TRANSLATE(smlad)(unsigned int inst, int index)
2321 inst_base->idx = index; 2320{
2322 inst_base->br = NON_BRANCH; 2321 arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
2322 smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
2323
2324 inst_base->cond = BITS(inst, 28, 31);
2325 inst_base->idx = index;
2326 inst_base->br = NON_BRANCH;
2323 inst_base->load_r15 = 0; 2327 inst_base->load_r15 = 0;
2324 2328
2325 inst_cream->m = BIT(inst, 4); 2329 inst_cream->m = BIT(inst, 5);
2326 inst_cream->Rn = BITS(inst, 0, 3); 2330 inst_cream->Rn = BITS(inst, 0, 3);
2327 inst_cream->Rm = BITS(inst, 8, 11); 2331 inst_cream->Rm = BITS(inst, 8, 11);
2328 inst_cream->Rd = BITS(inst, 16, 19); 2332 inst_cream->Rd = BITS(inst, 16, 19);
2329 inst_cream->Ra = BITS(inst, 12, 15); 2333 inst_cream->Ra = BITS(inst, 12, 15);
2334 inst_cream->op1 = BITS(inst, 20, 22);
2335 inst_cream->op2 = BITS(inst, 5, 7);
2330 2336
2331 if (CHECK_RM )
2332 inst_base->load_r15 = 1;
2333 return inst_base; 2337 return inst_base;
2334} 2338}
2339ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index)
2340{
2341 return INTERPRETER_TRANSLATE(smlad)(inst, index);
2342}
2343ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index)
2344{
2345 return INTERPRETER_TRANSLATE(smlad)(inst, index);
2346}
2347ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index)
2348{
2349 return INTERPRETER_TRANSLATE(smlad)(inst, index);
2350}
2351
2335ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index) 2352ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index)
2336{ 2353{
2337 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umlal_inst)); 2354 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umlal_inst));
@@ -2355,12 +2372,10 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index)
2355ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); } 2372ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); }
2356ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALD"); } 2373ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALD"); }
2357ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLAW"); } 2374ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLAW"); }
2358ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSD"); }
2359ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSLD"); } 2375ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSLD"); }
2360ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLA"); } 2376ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLA"); }
2361ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLS"); } 2377ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLS"); }
2362ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMUL"); } 2378ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMUL"); }
2363ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMUAD"); }
2364ARM_INST_PTR INTERPRETER_TRANSLATE(smul)(unsigned int inst, int index) 2379ARM_INST_PTR INTERPRETER_TRANSLATE(smul)(unsigned int inst, int index)
2365{ 2380{
2366 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smul_inst)); 2381 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smul_inst));
@@ -2423,7 +2438,6 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(smulw)(unsigned int inst, int index)
2423 inst_base->load_r15 = 1; 2438 inst_base->load_r15 = 1;
2424 return inst_base; 2439 return inst_base;
2425} 2440}
2426ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMUSD"); }
2427ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); } 2441ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); }
2428ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index) 2442ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index)
2429{ 2443{
@@ -5358,44 +5372,59 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
5358 FETCH_INST; 5372 FETCH_INST;
5359 GOTO_NEXT_INST; 5373 GOTO_NEXT_INST;
5360 } 5374 }
5375
5361 SMLAD_INST: 5376 SMLAD_INST:
5377 SMLSD_INST:
5378 SMUAD_INST:
5379 SMUSD_INST:
5362 { 5380 {
5363 if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) { 5381 if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
5364 smlad_inst *inst_cream = (smlad_inst *)inst_base->component; 5382 smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
5365 long long int rm = cpu->Reg[inst_cream->Rm]; 5383 const u8 op2 = inst_cream->op2;
5366 long long int rn = cpu->Reg[inst_cream->Rn];
5367 long long int ra = cpu->Reg[inst_cream->Ra];
5368 5384
5369 // See SMUAD 5385 u32 rm_val = cpu->Reg[inst_cream->Rm];
5370 if(inst_cream->Ra == 15) 5386 const u32 rn_val = cpu->Reg[inst_cream->Rn];
5371 CITRA_IGNORE_EXIT(-1);
5372 int operand2 = (inst_cream->m)? ROTATE_RIGHT_32(rm, 16):rm;
5373 int half_rn, half_operand2;
5374 5387
5375 half_rn = rn & 0xFFFF; 5388 if (inst_cream->m)
5376 half_rn = (half_rn & 0x8000)? (0xFFFF0000|half_rn) : half_rn; 5389 rm_val = (((rm_val & 0xFFFF) << 16) | (rm_val >> 16));
5377 5390
5378 half_operand2 = operand2 & 0xFFFF; 5391 const s16 rm_lo = (rm_val & 0xFFFF);
5379 half_operand2 = (half_operand2 & 0x8000)? (0xFFFF0000|half_operand2) : half_operand2; 5392 const s16 rm_hi = ((rm_val >> 16) & 0xFFFF);
5393 const s16 rn_lo = (rn_val & 0xFFFF);
5394 const s16 rn_hi = ((rn_val >> 16) & 0xFFFF);
5380 5395
5381 long long int product1 = half_rn * half_operand2; 5396 const u32 product1 = (rn_lo * rm_lo);
5397 const u32 product2 = (rn_hi * rm_hi);
5382 5398
5383 half_rn = (rn & 0xFFFF0000) >> 16; 5399 // SMUAD and SMLAD
5384 half_rn = (half_rn & 0x8000)? (0xFFFF0000|half_rn) : half_rn; 5400 if (BIT(op2, 1) == 0) {
5401 RD = (product1 + product2);
5385 5402
5386 half_operand2 = (operand2 & 0xFFFF0000) >> 16; 5403 if (inst_cream->Ra != 15) {
5387 half_operand2 = (half_operand2 & 0x8000)? (0xFFFF0000|half_operand2) : half_operand2; 5404 RD += cpu->Reg[inst_cream->Ra];
5388 5405
5389 long long int product2 = half_rn * half_operand2; 5406 if (ARMul_AddOverflowQ(product1 + product2, cpu->Reg[inst_cream->Ra]))
5407 cpu->Cpsr |= (1 << 27);
5408 }
5390 5409
5391 long long int signed_ra = (ra & 0x80000000)? (0xFFFFFFFF00000000LL) | ra : ra; 5410 if (ARMul_AddOverflowQ(product1, product2))
5392 long long int result = product1 + product2 + signed_ra; 5411 cpu->Cpsr |= (1 << 27);
5393 cpu->Reg[inst_cream->Rd] = result & 0xFFFFFFFF; 5412 }
5413 // SMUSD and SMLSD
5414 else {
5415 RD = (product1 - product2);
5394 5416
5395 // TODO: FIXME should check Signed overflow 5417 if (inst_cream->Ra != 15) {
5418 RD += cpu->Reg[inst_cream->Ra];
5419
5420 if (ARMul_AddOverflowQ(product1 - product2, cpu->Reg[inst_cream->Ra]))
5421 cpu->Cpsr |= (1 << 27);
5422 }
5423 }
5396 } 5424 }
5425
5397 cpu->Reg[15] += GET_INST_SIZE(cpu); 5426 cpu->Reg[15] += GET_INST_SIZE(cpu);
5398 INC_PC(sizeof(umlal_inst)); 5427 INC_PC(sizeof(smlad_inst));
5399 FETCH_INST; 5428 FETCH_INST;
5400 GOTO_NEXT_INST; 5429 GOTO_NEXT_INST;
5401 } 5430 }
@@ -5428,15 +5457,15 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
5428 FETCH_INST; 5457 FETCH_INST;
5429 GOTO_NEXT_INST; 5458 GOTO_NEXT_INST;
5430 } 5459 }
5460
5431 SMLALXY_INST: 5461 SMLALXY_INST:
5432 SMLALD_INST: 5462 SMLALD_INST:
5433 SMLAW_INST: 5463 SMLAW_INST:
5434 SMLSD_INST:
5435 SMLSLD_INST: 5464 SMLSLD_INST:
5436 SMMLA_INST: 5465 SMMLA_INST:
5437 SMMLS_INST: 5466 SMMLS_INST:
5438 SMMUL_INST: 5467 SMMUL_INST:
5439 SMUAD_INST: 5468
5440 SMUL_INST: 5469 SMUL_INST:
5441 { 5470 {
5442 if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) { 5471 if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
@@ -5504,8 +5533,8 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
5504 GOTO_NEXT_INST; 5533 GOTO_NEXT_INST;
5505 } 5534 }
5506 5535
5507 SMUSD_INST:
5508 SRS_INST: 5536 SRS_INST:
5537
5509 SSAT_INST: 5538 SSAT_INST:
5510 { 5539 {
5511 if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) { 5540 if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
diff --git a/src/core/arm/interpreter/armemu.cpp b/src/core/arm/interpreter/armemu.cpp
index 43b1ba40e..12166bf79 100644
--- a/src/core/arm/interpreter/armemu.cpp
+++ b/src/core/arm/interpreter/armemu.cpp
@@ -6470,17 +6470,23 @@ L_stm_s_takeabort:
6470 6470
6471 if (BITS(12, 15) != 15) { 6471 if (BITS(12, 15) != 15) {
6472 state->Reg[rd_idx] += state->Reg[ra_idx]; 6472 state->Reg[rd_idx] += state->Reg[ra_idx];
6473 ARMul_AddOverflowQ(state, product1 + product2, state->Reg[ra_idx]); 6473 if (ARMul_AddOverflowQ(product1 + product2, state->Reg[ra_idx]))
6474 SETQ;
6474 } 6475 }
6475 6476
6476 ARMul_AddOverflowQ(state, product1, product2); 6477 if (ARMul_AddOverflowQ(product1, product2))
6478 SETQ;
6477 } 6479 }
6478 // SMUSD and SMLSD 6480 // SMUSD and SMLSD
6479 else { 6481 else {
6480 state->Reg[rd_idx] = product1 - product2; 6482 state->Reg[rd_idx] = product1 - product2;
6481 6483
6482 if (BITS(12, 15) != 15) 6484 if (BITS(12, 15) != 15) {
6483 state->Reg[rd_idx] += state->Reg[ra_idx]; 6485 state->Reg[rd_idx] += state->Reg[ra_idx];
6486
6487 if (ARMul_AddOverflowQ(product1 - product2, state->Reg[ra_idx]))
6488 SETQ;
6489 }
6484 } 6490 }
6485 6491
6486 return 1; 6492 return 1;
diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp
index 426b67831..eec34143e 100644
--- a/src/core/arm/interpreter/armsupp.cpp
+++ b/src/core/arm/interpreter/armsupp.cpp
@@ -453,12 +453,14 @@ ARMul_AddOverflow (ARMul_State * state, ARMword a, ARMword b, ARMword result)
453 ASSIGNV (AddOverflow (a, b, result)); 453 ASSIGNV (AddOverflow (a, b, result));
454} 454}
455 455
456/* Assigns the Q flag if the given result is considered an overflow from the addition of a and b */ 456// Returns true if the Q flag should be set as a result of overflow.
457void ARMul_AddOverflowQ(ARMul_State* state, ARMword a, ARMword b) 457bool ARMul_AddOverflowQ(ARMword a, ARMword b)
458{ 458{
459 u32 result = a + b; 459 u32 result = a + b;
460 if (((result ^ a) & (u32)0x80000000) && ((a ^ b) & (u32)0x80000000) == 0) 460 if (((result ^ a) & (u32)0x80000000) && ((a ^ b) & (u32)0x80000000) == 0)
461 SETQ; 461 return true;
462
463 return false;
462} 464}
463 465
464/* Assigns the C flag after an subtraction of a and b to give result. */ 466/* Assigns the C flag after an subtraction of a and b to give result. */
diff --git a/src/core/arm/skyeye_common/armdefs.h b/src/core/arm/skyeye_common/armdefs.h
index 8611d7392..c2c78cd5a 100644
--- a/src/core/arm/skyeye_common/armdefs.h
+++ b/src/core/arm/skyeye_common/armdefs.h
@@ -790,6 +790,8 @@ extern void ARMul_FixSPSR(ARMul_State*, ARMword, ARMword);
790extern void ARMul_ConsolePrint(ARMul_State*, const char*, ...); 790extern void ARMul_ConsolePrint(ARMul_State*, const char*, ...);
791extern void ARMul_SelectProcessor(ARMul_State*, unsigned); 791extern void ARMul_SelectProcessor(ARMul_State*, unsigned);
792 792
793extern bool ARMul_AddOverflowQ(ARMword, ARMword);
794
793extern u8 ARMul_SignedSaturatedAdd8(u8, u8); 795extern u8 ARMul_SignedSaturatedAdd8(u8, u8);
794extern u8 ARMul_SignedSaturatedSub8(u8, u8); 796extern u8 ARMul_SignedSaturatedSub8(u8, u8);
795extern u16 ARMul_SignedSaturatedAdd16(u16, u16); 797extern u16 ARMul_SignedSaturatedAdd16(u16, u16);
diff --git a/src/core/arm/skyeye_common/armemu.h b/src/core/arm/skyeye_common/armemu.h
index 3ea14b5a3..e1b286f0f 100644
--- a/src/core/arm/skyeye_common/armemu.h
+++ b/src/core/arm/skyeye_common/armemu.h
@@ -602,7 +602,6 @@ extern ARMword ARMul_SwitchMode (ARMul_State *, ARMword, ARMword);
602extern void ARMul_MSRCpsr (ARMul_State *, ARMword, ARMword); 602extern void ARMul_MSRCpsr (ARMul_State *, ARMword, ARMword);
603extern void ARMul_SubOverflow (ARMul_State *, ARMword, ARMword, ARMword); 603extern void ARMul_SubOverflow (ARMul_State *, ARMword, ARMword, ARMword);
604extern void ARMul_AddOverflow (ARMul_State *, ARMword, ARMword, ARMword); 604extern void ARMul_AddOverflow (ARMul_State *, ARMword, ARMword, ARMword);
605extern void ARMul_AddOverflowQ(ARMul_State*, ARMword, ARMword);
606extern void ARMul_SubCarry (ARMul_State *, ARMword, ARMword, ARMword); 605extern void ARMul_SubCarry (ARMul_State *, ARMword, ARMword, ARMword);
607extern void ARMul_AddCarry (ARMul_State *, ARMword, ARMword, ARMword); 606extern void ARMul_AddCarry (ARMul_State *, ARMword, ARMword, ARMword);
608extern tdstate ARMul_ThumbDecode (ARMul_State *, ARMword, ARMword, ARMword *); 607extern tdstate ARMul_ThumbDecode (ARMul_State *, ARMword, ARMword, ARMword *);
diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp
index 9fbf18b26..8e7abcf9c 100644
--- a/src/core/hle/service/soc_u.cpp
+++ b/src/core/hle/service/soc_u.cpp
@@ -404,7 +404,7 @@ static void Fcntl(Service::Interface* self) {
404 } 404 }
405#endif 405#endif
406 } else { 406 } else {
407 LOG_ERROR(Service_SOC, "Unsupported command (%d) in fcntl call"); 407 LOG_ERROR(Service_SOC, "Unsupported command (%d) in fcntl call", ctr_cmd);
408 result = TranslateError(EINVAL); // TODO: Find the correct error 408 result = TranslateError(EINVAL); // TODO: Find the correct error
409 posix_ret = -1; 409 posix_ret = -1;
410 return; 410 return;