summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2014-02-28 23:08:56 +0100
committerPierre Bourdon <delroth@gmail.com>2014-02-28 23:08:56 +0100
commitbc844a168fe54174cd4de04e17ef23849e1fcccb (patch)
tree1293208fb1072c1f13cdf16006190a18a7882dfd /Source/Core/Common
parent1a7e3b3227070fcac6499e6e9eaa8d8ad3ef3e49 (diff)
parent892012dc02d13229e88db1809f7b785fc3516787 (diff)
Merge pull request #100 from Tilka/misc_fixes
Misc fixes
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/ArmEmitter.cpp110
-rw-r--r--Source/Core/Common/ArmEmitter.h2
-rw-r--r--Source/Core/Common/CDUtils.cpp2
-rw-r--r--Source/Core/Common/Common.h8
-rw-r--r--Source/Core/Common/Crypto/bn.cpp27
-rw-r--r--Source/Core/Common/Crypto/bn.h16
-rw-r--r--Source/Core/Common/Crypto/ec.cpp66
-rw-r--r--Source/Core/Common/Crypto/ec.h13
-rw-r--r--Source/Core/Common/Crypto/tools.h22
-rw-r--r--Source/Core/Common/ExtendedTrace.cpp2
-rw-r--r--Source/Core/Common/FPURoundMode.h16
-rw-r--r--Source/Core/Common/GenericFPURoundMode.cpp6
-rw-r--r--Source/Core/Common/IniFile.cpp3
-rw-r--r--Source/Core/Common/MemArena.cpp2
-rw-r--r--Source/Core/Common/MemoryUtil.cpp397
-rw-r--r--Source/Core/Common/x64FPURoundMode.cpp66
16 files changed, 369 insertions, 389 deletions
diff --git a/Source/Core/Common/ArmEmitter.cpp b/Source/Core/Common/ArmEmitter.cpp
index d35f7f6afa..c64ca16444 100644
--- a/Source/Core/Common/ArmEmitter.cpp
+++ b/Source/Core/Common/ArmEmitter.cpp
@@ -335,7 +335,7 @@ void ARMXEmitter::NOP(int count)
void ARMXEmitter::SETEND(bool BE)
{
//SETEND is non-conditional
- Write32( 0xF1010000 | (BE << 9));
+ Write32(0xF1010000 | (BE << 9));
}
void ARMXEmitter::BKPT(u16 arg)
{
@@ -380,9 +380,8 @@ FixupBranch ARMXEmitter::B_CC(CCFlags Cond)
void ARMXEmitter::B_CC(CCFlags Cond, const void *fnptr)
{
s32 distance = (s32)fnptr - (s32(code) + 8);
- _dbg_assert_msg_(DYNA_REC, distance > -33554432
- && distance <= 33554432,
- "B_CC out of range (%p calls %p)", code, fnptr);
+ _dbg_assert_msg_(DYNA_REC, distance > -0x2000000 && distance <= 0x2000000,
+ "B_CC out of range (%p calls %p)", code, fnptr);
Write32((Cond << 28) | 0x0A000000 | ((distance >> 2) & 0x00FFFFFF));
}
@@ -399,23 +398,17 @@ FixupBranch ARMXEmitter::BL_CC(CCFlags Cond)
void ARMXEmitter::SetJumpTarget(FixupBranch const &branch)
{
s32 distance = (s32(code) - 8) - (s32)branch.ptr;
- _dbg_assert_msg_(DYNA_REC, distance > -33554432
- && distance <= 33554432,
- "SetJumpTarget out of range (%p calls %p)", code,
- branch.ptr);
- if(branch.type == 0) // B
- *(u32*)branch.ptr = (u32)(branch.condition | (10 << 24) | ((distance >> 2) &
- 0x00FFFFFF));
- else // BL
- *(u32*)branch.ptr = (u32)(branch.condition | 0x0B000000 | ((distance >> 2)
- & 0x00FFFFFF));
-}
-void ARMXEmitter::B (const void *fnptr)
+ _dbg_assert_msg_(DYNA_REC, distance > -0x2000000 && distance <= 0x2000000,
+ "SetJumpTarget out of range (%p calls %p)", code, branch.ptr);
+ u32 instr = (u32)(branch.condition | ((distance >> 2) & 0x00FFFFFF));
+ instr |= branch.type ? /* B */ 0x0A000000 : /* BL */ 0x0B000000;
+ *(u32*)branch.ptr = instr;
+}
+void ARMXEmitter::B(const void *fnptr)
{
s32 distance = (s32)fnptr - (s32(code) + 8);
- _dbg_assert_msg_(DYNA_REC, distance > -33554432
- && distance <= 33554432,
- "B out of range (%p calls %p)", code, fnptr);
+ _dbg_assert_msg_(DYNA_REC, distance > -0x2000000 && distance <= 0x2000000,
+ "B out of range (%p calls %p)", code, fnptr);
Write32(condition | 0x0A000000 | ((distance >> 2) & 0x00FFFFFF));
}
@@ -427,7 +420,7 @@ void ARMXEmitter::B(ARMReg src)
bool ARMXEmitter::BLInRange(const void *fnptr) {
s32 distance = (s32)fnptr - (s32(code) + 8);
- if (distance <= -33554432 || distance > 33554432)
+ if (distance <= -0x2000000 || distance > 0x2000000)
return false;
else
return true;
@@ -436,9 +429,8 @@ bool ARMXEmitter::BLInRange(const void *fnptr) {
void ARMXEmitter::BL(const void *fnptr)
{
s32 distance = (s32)fnptr - (s32(code) + 8);
- _dbg_assert_msg_(DYNA_REC, distance > -33554432
- && distance <= 33554432,
- "BL out of range (%p calls %p)", code, fnptr);
+ _dbg_assert_msg_(DYNA_REC, distance > -0x2000000 && distance <= 0x2000000,
+ "BL out of range (%p calls %p)", code, fnptr);
Write32(condition | 0x0B000000 | ((distance >> 2) & 0x00FFFFFF));
}
void ARMXEmitter::BL(ARMReg src)
@@ -487,42 +479,42 @@ void ARMXEmitter::WriteShiftedDataOp(u32 op, bool SetFlags, ARMReg dest, ARMReg
// IMM, REG, IMMSREG, RSR
// -1 for invalid if the instruction doesn't support that
const s32 InstOps[][4] = {{16, 0, 0, 0}, // AND(s)
- {17, 1, 1, 1}, // EOR(s)
- {18, 2, 2, 2}, // SUB(s)
- {19, 3, 3, 3}, // RSB(s)
- {20, 4, 4, 4}, // ADD(s)
- {21, 5, 5, 5}, // ADC(s)
- {22, 6, 6, 6}, // SBC(s)
- {23, 7, 7, 7}, // RSC(s)
- {24, 8, 8, 8}, // TST
- {25, 9, 9, 9}, // TEQ
- {26, 10, 10, 10}, // CMP
- {27, 11, 11, 11}, // CMN
- {28, 12, 12, 12}, // ORR(s)
- {29, 13, 13, 13}, // MOV(s)
- {30, 14, 14, 14}, // BIC(s)
- {31, 15, 15, 15}, // MVN(s)
- {24, -1, -1, -1}, // MOVW
- {26, -1, -1, -1}, // MOVT
- };
-
-const char *InstNames[] = { "AND",
- "EOR",
- "SUB",
- "RSB",
- "ADD",
- "ADC",
- "SBC",
- "RSC",
- "TST",
- "TEQ",
- "CMP",
- "CMN",
- "ORR",
- "MOV",
- "BIC",
- "MVN"
- };
+ {17, 1, 1, 1}, // EOR(s)
+ {18, 2, 2, 2}, // SUB(s)
+ {19, 3, 3, 3}, // RSB(s)
+ {20, 4, 4, 4}, // ADD(s)
+ {21, 5, 5, 5}, // ADC(s)
+ {22, 6, 6, 6}, // SBC(s)
+ {23, 7, 7, 7}, // RSC(s)
+ {24, 8, 8, 8}, // TST
+ {25, 9, 9, 9}, // TEQ
+ {26, 10, 10, 10}, // CMP
+ {27, 11, 11, 11}, // CMN
+ {28, 12, 12, 12}, // ORR(s)
+ {29, 13, 13, 13}, // MOV(s)
+ {30, 14, 14, 14}, // BIC(s)
+ {31, 15, 15, 15}, // MVN(s)
+ {24, -1, -1, -1}, // MOVW
+ {26, -1, -1, -1}, // MOVT
+ };
+
+const char *InstNames[] = {"AND",
+ "EOR",
+ "SUB",
+ "RSB",
+ "ADD",
+ "ADC",
+ "SBC",
+ "RSC",
+ "TST",
+ "TEQ",
+ "CMP",
+ "CMN",
+ "ORR",
+ "MOV",
+ "BIC",
+ "MVN"
+ };
void ARMXEmitter::AND (ARMReg Rd, ARMReg Rn, Operand2 Rm) { WriteInstruction(0, Rd, Rn, Rm); }
void ARMXEmitter::ANDS(ARMReg Rd, ARMReg Rn, Operand2 Rm) { WriteInstruction(0, Rd, Rn, Rm, true); }
diff --git a/Source/Core/Common/ArmEmitter.h b/Source/Core/Common/ArmEmitter.h
index 837a931e4c..405cacf991 100644
--- a/Source/Core/Common/ArmEmitter.h
+++ b/Source/Core/Common/ArmEmitter.h
@@ -735,8 +735,8 @@ public:
{
#ifndef __SYMBIAN32__
FreeMemoryPages(region, region_size);
-#endif
region = NULL;
+#endif
region_size = 0;
}
diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp
index 4adcf7cee9..9652b98f08 100644
--- a/Source/Core/Common/CDUtils.cpp
+++ b/Source/Core/Common/CDUtils.cpp
@@ -196,7 +196,7 @@ std::vector<std::string> cdio_get_devices ()
for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j)
{
std::string drive = StringFromFormat(checklist[i].format, j);
- if ( (is_cdrom(drive, NULL)) > 0 )
+ if (is_cdrom(drive, NULL))
{
drives.push_back(std::move(drive));
}
diff --git a/Source/Core/Common/Common.h b/Source/Core/Common/Common.h
index 7d9362e408..77307e73e3 100644
--- a/Source/Core/Common/Common.h
+++ b/Source/Core/Common/Common.h
@@ -25,6 +25,14 @@ extern const char *netplay_dolphin_ver;
#define LOGGING 1
#endif
+#if defined(__GNUC__) || __clang__
+// Disable "unused function" warnings for the ones manually marked as such.
+#define UNUSED __attribute__((unused))
+#else
+// Not sure MSVC even checks this...
+#define UNUSED
+#endif
+
#define STACKALIGN
#if __cplusplus >= 201103 || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__)
diff --git a/Source/Core/Common/Crypto/bn.cpp b/Source/Core/Common/Crypto/bn.cpp
index e2a9dd6a4a..4f7c93e841 100644
--- a/Source/Core/Common/Crypto/bn.cpp
+++ b/Source/Core/Common/Crypto/bn.cpp
@@ -6,31 +6,18 @@
#include <string.h>
#include "Common/Common.h"
-#include "Common/Crypto/tools.h"
-
-/*static void bn_print(char *name, u8 *a, u32 n)
-{
- u32 i;
-
- printf("%s = ", name);
-
- for (i = 0; i < n; i++)
- printf("%02x", a[i]);
-
- printf("\n");
-}*/
static void bn_zero(u8 *d, u32 n)
{
memset(d, 0, n);
}
-static void bn_copy(u8 *d, u8 *a, u32 n)
+static void bn_copy(u8 *d, const u8 *a, u32 n)
{
memcpy(d, a, n);
}
-int bn_compare(u8 *a, u8 *b, u32 n)
+int bn_compare(const u8 *a, const u8 *b, u32 n)
{
u32 i;
@@ -44,7 +31,7 @@ int bn_compare(u8 *a, u8 *b, u32 n)
return 0;
}
-void bn_sub_modulus(u8 *a, u8 *N, u32 n)
+void bn_sub_modulus(u8 *a, const u8 *N, u32 n)
{
u32 i;
u32 dig;
@@ -58,7 +45,7 @@ void bn_sub_modulus(u8 *a, u8 *N, u32 n)
}
}
-void bn_add(u8 *d, u8 *a, u8 *b, u8 *N, u32 n)
+void bn_add(u8 *d, const u8 *a, const u8 *b, const u8 *N, u32 n)
{
u32 i;
u32 dig;
@@ -78,7 +65,7 @@ void bn_add(u8 *d, u8 *a, u8 *b, u8 *N, u32 n)
bn_sub_modulus(d, N, n);
}
-void bn_mul(u8 *d, u8 *a, u8 *b, u8 *N, u32 n)
+void bn_mul(u8 *d, const u8 *a, const u8 *b, const u8 *N, u32 n)
{
u32 i;
u8 mask;
@@ -93,7 +80,7 @@ void bn_mul(u8 *d, u8 *a, u8 *b, u8 *N, u32 n)
}
}
-void bn_exp(u8 *d, u8 *a, u8 *N, u32 n, u8 *e, u32 en)
+void bn_exp(u8 *d, const u8 *a, const u8 *N, u32 n, const u8 *e, u32 en)
{
u8 t[512];
u32 i;
@@ -112,7 +99,7 @@ void bn_exp(u8 *d, u8 *a, u8 *N, u32 n, u8 *e, u32 en)
}
// only for prime N -- stupid but lazy, see if I care
-void bn_inv(u8 *d, u8 *a, u8 *N, u32 n)
+void bn_inv(u8 *d, const u8 *a, const u8 *N, u32 n)
{
u8 t[512], s[512];
diff --git a/Source/Core/Common/Crypto/bn.h b/Source/Core/Common/Crypto/bn.h
new file mode 100644
index 0000000000..0a6ce0111d
--- /dev/null
+++ b/Source/Core/Common/Crypto/bn.h
@@ -0,0 +1,16 @@
+// Copyright 2014 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "Common/CommonTypes.h"
+
+// bignum arithmetic
+
+int bn_compare(const u8 *a, const u8 *b, u32 n);
+void bn_sub_modulus(u8 *a, const u8 *N, u32 n);
+void bn_add(u8 *d, const u8 *a, const u8 *b, const u8 *N, u32 n);
+void bn_mul(u8 *d, const u8 *a, const u8 *b, const u8 *N, u32 n);
+void bn_inv(u8 *d, const u8 *a, const u8 *N, u32 n); // only for prime N
+void bn_exp(u8 *d, const u8 *a, const u8 *N, u32 n, const u8 *e, u32 en);
diff --git a/Source/Core/Common/Crypto/ec.cpp b/Source/Core/Common/Crypto/ec.cpp
index 727f5d828c..acbbac1a8c 100644
--- a/Source/Core/Common/Crypto/ec.cpp
+++ b/Source/Core/Common/Crypto/ec.cpp
@@ -12,38 +12,26 @@
#include <string.h>
#include "Common/Common.h"
-#include "Common/Crypto/tools.h"
+#include "Common/Crypto/bn.h"
+#include "Common/Crypto/ec.h"
+
// y**2 + x*y = x**3 + x + b
-/*
-static u8 ec_b[30] =
+UNUSED static const u8 ec_b[30] =
{0x00,0x66,0x64,0x7e,0xde,0x6c,0x33,0x2c,0x7f,0x8c,0x09,0x23,0xbb,0x58,0x21
,0x3b,0x33,0x3b,0x20,0xe9,0xce,0x42,0x81,0xfe,0x11,0x5f,0x7d,0x8f,0x90,0xad};
-*/
// order of the addition group of points
-static u8 ec_N[30] =
+static const u8 ec_N[30] =
{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x13,0xe9,0x74,0xe7,0x2f,0x8a,0x69,0x22,0x03,0x1d,0x26,0x03,0xcf,0xe0,0xd7};
// base point
-static u8 ec_G[60] =
+static const u8 ec_G[60] =
{0x00,0xfa,0xc9,0xdf,0xcb,0xac,0x83,0x13,0xbb,0x21,0x39,0xf1,0xbb,0x75,0x5f
,0xef,0x65,0xbc,0x39,0x1f,0x8b,0x36,0xf8,0xf8,0xeb,0x73,0x71,0xfd,0x55,0x8b
,0x01,0x00,0x6a,0x08,0xa4,0x19,0x03,0x35,0x06,0x78,0xe5,0x85,0x28,0xbe,0xbf
,0x8a,0x0b,0xef,0xf8,0x67,0xa7,0xca,0x36,0x71,0x6f,0x7e,0x01,0xf8,0x10,0x52};
-/*static void elt_print(char *name, u8 *a)
-{
- u32 i;
-
- printf("%s = ", name);
-
- for (i = 0; i < 30; i++)
- printf("%02x", a[i]);
-
- printf("\n");
-}*/
-
static void elt_copy(u8 *d, const u8 *a)
{
memcpy(d, a, 30);
@@ -54,7 +42,7 @@ static void elt_zero(u8 *d)
memset(d, 0, 30);
}
-static int elt_is_zero(u8 *d)
+static int elt_is_zero(const u8 *d)
{
u32 i;
@@ -65,7 +53,7 @@ static int elt_is_zero(u8 *d)
return 1;
}
-static void elt_add(u8 *d, u8 *a, u8 *b)
+static void elt_add(u8 *d, const u8 *a, const u8 *b)
{
u32 i;
@@ -73,7 +61,7 @@ static void elt_add(u8 *d, u8 *a, u8 *b)
d[i] = a[i] ^ b[i];
}
-static void elt_mul_x(u8 *d, u8 *a)
+static void elt_mul_x(u8 *d, const u8 *a)
{
u8 carry, x, y;
u32 i;
@@ -91,7 +79,7 @@ static void elt_mul_x(u8 *d, u8 *a)
d[20] ^= carry << 2;
}
-static void elt_mul(u8 *d, u8 *a, u8 *b)
+static void elt_mul(u8 *d, const u8 *a, const u8 *b)
{
u32 i, n;
u8 mask;
@@ -115,9 +103,9 @@ static void elt_mul(u8 *d, u8 *a, u8 *b)
}
static const u8 square[16] =
-{0x00,0x01,0x04,0x05,0x10,0x11,0x14,0x15,0x40,0x41,0x44,0x45,0x50,0x51,0x54,0x55};
+ {0x00,0x01,0x04,0x05,0x10,0x11,0x14,0x15,0x40,0x41,0x44,0x45,0x50,0x51,0x54,0x55};
-static void elt_square_to_wide(u8 *d, u8 *a)
+static void elt_square_to_wide(u8 *d, const u8 *a)
{
u32 i;
@@ -152,7 +140,7 @@ static void wide_reduce(u8 *d)
d[30] &= 1;
}
-static void elt_square(u8 *d, u8 *a)
+static void elt_square(u8 *d, const u8 *a)
{
u8 wide[60];
@@ -162,7 +150,7 @@ static void elt_square(u8 *d, u8 *a)
elt_copy(d, wide + 30);
}
-static void itoh_tsujii(u8 *d, u8 *a, u8 *b, u32 j)
+static void itoh_tsujii(u8 *d, const u8 *a, const u8 *b, u32 j)
{
u8 t[30];
@@ -175,7 +163,7 @@ static void itoh_tsujii(u8 *d, u8 *a, u8 *b, u32 j)
elt_mul(d, t, b);
}
-static void elt_inv(u8 *d, u8 *a)
+static void elt_inv(u8 *d, const u8 *a)
{
u8 t[30];
u8 s[30];
@@ -193,7 +181,7 @@ static void elt_inv(u8 *d, u8 *a)
elt_square(d, s);
}
-/*static int point_is_on_curve(u8 *p)
+UNUSED static int point_is_on_curve(u8 *p)
{
u8 s[30], t[30];
u8 *x, *y;
@@ -216,16 +204,17 @@ static void elt_inv(u8 *d, u8 *a)
return elt_is_zero(s);
}
-*/
-static int point_is_zero(u8 *p)
+
+static int point_is_zero(const u8 *p)
{
return elt_is_zero(p) && elt_is_zero(p + 30);
}
-static void point_double(u8 *r, u8 *p)
+static void point_double(u8 *r, const u8 *p)
{
u8 s[30], t[30];
- u8 *px, *py, *rx, *ry;
+ const u8 *px, *py;
+ u8 *rx, *ry;
px = p;
py = p + 30;
@@ -254,10 +243,11 @@ static void point_double(u8 *r, u8 *p)
elt_add(ry, ry, t);
}
-static void point_add(u8 *r, u8 *p, u8 *q)
+static void point_add(u8 *r, const u8 *p, const u8 *q)
{
u8 s[30], t[30], u[30];
- u8 *px, *py, *qx, *qy, *rx, *ry;
+ const u8 *px, *py, *qx, *qy;
+ u8 *rx, *ry;
px = p;
py = p + 30;
@@ -307,7 +297,7 @@ static void point_add(u8 *r, u8 *p, u8 *q)
elt_add(ry, s, rx);
}
-void point_mul(u8 *d, const u8 *a, u8 *b) // a is bignum
+void point_mul(u8 *d, const u8 *a, const u8 *b) // a is bignum
{
u32 i;
u8 mask;
@@ -323,7 +313,7 @@ void point_mul(u8 *d, const u8 *a, u8 *b) // a is bignum
}
}
-void silly_random(u8 * rndArea, u8 count)
+static void silly_random(u8 * rndArea, u8 count)
{
u16 i;
srand((unsigned) (time(NULL)));
@@ -334,7 +324,7 @@ void silly_random(u8 * rndArea, u8 count)
}
}
-void generate_ecdsa(u8 *R, u8 *S, const u8 *k, u8 *hash)
+void generate_ecdsa(u8 *R, u8 *S, const u8 *k, const u8 *hash)
{
u8 e[30];
u8 kk[30];
@@ -372,7 +362,7 @@ void generate_ecdsa(u8 *R, u8 *S, const u8 *k, u8 *hash)
bn_mul(S, minv, kk, ec_N, 30);
}
-int check_ecdsa(u8 *Q, u8 *R, u8 *S, u8 *hash)
+UNUSED static int check_ecdsa(u8 *Q, u8 *R, u8 *S, const u8 *hash)
{
u8 Sinv[30];
u8 e[30];
diff --git a/Source/Core/Common/Crypto/ec.h b/Source/Core/Common/Crypto/ec.h
new file mode 100644
index 0000000000..14329d41cc
--- /dev/null
+++ b/Source/Core/Common/Crypto/ec.h
@@ -0,0 +1,13 @@
+// Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
+// Licensed under the terms of the GNU GPL, version 2
+// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+
+#pragma once
+
+#include "Common/CommonTypes.h"
+
+void point_mul(u8 *d, const u8 *a, const u8 *b);
+
+void generate_ecdsa(u8 *R, u8 *S, const u8 *k, const u8 *hash);
+
+void ec_priv_to_pub(const u8 *k, u8 *Q);
diff --git a/Source/Core/Common/Crypto/tools.h b/Source/Core/Common/Crypto/tools.h
deleted file mode 100644
index 0e4d49be1a..0000000000
--- a/Source/Core/Common/Crypto/tools.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
-// Licensed under the terms of the GNU GPL, version 2
-// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
-
-#ifndef _TOOLS_H
-#define _TOOLS_H
-#include <polarssl/sha1.h>
-
-// bignum
-int bn_compare(u8 *a, u8 *b, u32 n);
-void bn_sub_modulus(u8 *a, u8 *N, u32 n);
-void bn_add(u8 *d, u8 *a, u8 *b, u8 *N, u32 n);
-void bn_mul(u8 *d, u8 *a, u8 *b, u8 *N, u32 n);
-void bn_inv(u8 *d, u8 *a, u8 *N, u32 n); // only for prime N
-void bn_exp(u8 *d, u8 *a, u8 *N, u32 n, u8 *e, u32 en);
-void point_mul(u8 *d, const u8 *a, u8 *b);
-
-void generate_ecdsa(u8 *R, u8 *S, const u8 *k, u8 *hash);
-
-void ec_priv_to_pub(const u8 *k, u8 *Q);
-
-#endif
diff --git a/Source/Core/Common/ExtendedTrace.cpp b/Source/Core/Common/ExtendedTrace.cpp
index 527b8609ab..e3586e4fb7 100644
--- a/Source/Core/Common/ExtendedTrace.cpp
+++ b/Source/Core/Common/ExtendedTrace.cpp
@@ -362,8 +362,6 @@ void StackTrace(HANDLE hThread, const char* lpszMessage, FILE *file, DWORD eip,
{
STACKFRAME callStack;
BOOL bResult;
- TCHAR symInfo[BUFFERSIZE] = _T("?");
- TCHAR srcInfo[BUFFERSIZE] = _T("?");
HANDLE hProcess = GetCurrentProcess();
// If it's not this thread, let's suspend it, and resume it at the end
diff --git a/Source/Core/Common/FPURoundMode.h b/Source/Core/Common/FPURoundMode.h
index e7b4884cb0..ebed4cbe96 100644
--- a/Source/Core/Common/FPURoundMode.h
+++ b/Source/Core/Common/FPURoundMode.h
@@ -11,20 +11,20 @@ namespace FPURoundMode
enum RoundModes
{
ROUND_NEAR = 0,
- ROUND_CHOP,
- ROUND_UP,
- ROUND_DOWN
+ ROUND_CHOP = 1,
+ ROUND_UP = 2,
+ ROUND_DOWN = 3
};
enum PrecisionModes {
PREC_24 = 0,
- PREC_53,
- PREC_64
+ PREC_53 = 1,
+ PREC_64 = 2
};
- void SetRoundMode(u32 mode);
+ void SetRoundMode(RoundModes mode);
- void SetPrecisionMode(u32 mode);
+ void SetPrecisionMode(PrecisionModes mode);
- void SetSIMDMode(u32 roundingMode, u32 nonIEEEMode);
+ void SetSIMDMode(RoundModes rounding_mode, bool non_ieee_mode);
/*
* There are two different flavors of float to int conversion:
diff --git a/Source/Core/Common/GenericFPURoundMode.cpp b/Source/Core/Common/GenericFPURoundMode.cpp
index 548e029fb9..61343514a5 100644
--- a/Source/Core/Common/GenericFPURoundMode.cpp
+++ b/Source/Core/Common/GenericFPURoundMode.cpp
@@ -21,13 +21,13 @@
// Generic, do nothing
namespace FPURoundMode
{
- void SetRoundMode(u32 mode)
+ void SetRoundMode(RoundModes mode)
{
}
- void SetPrecisionMode(u32 mode)
+ void SetPrecisionMode(PrecisionModes mode)
{
}
- void SetSIMDMode(u32 mode, u32 nonIEEEMode)
+ void SetSIMDMode(RoundModes rounding_mode, bool non_ieee_mode)
{
}
void SaveSIMDState()
diff --git a/Source/Core/Common/IniFile.cpp b/Source/Core/Common/IniFile.cpp
index 0637342a3d..2cc1a97e60 100644
--- a/Source/Core/Common/IniFile.cpp
+++ b/Source/Core/Common/IniFile.cpp
@@ -124,13 +124,12 @@ bool IniFile::Section::Get(const std::string& key, std::vector<std::string>& out
}
// ignore starting , if any
size_t subStart = temp.find_first_not_of(",");
- size_t subEnd;
// split by ,
while (subStart != std::string::npos)
{
// Find next ,
- subEnd = temp.find_first_of(",", subStart);
+ size_t subEnd = temp.find_first_of(",", subStart);
if (subStart != subEnd)
// take from first char until next ,
out.push_back(StripSpaces(temp.substr(subStart, subEnd - subStart)));
diff --git a/Source/Core/Common/MemArena.cpp b/Source/Core/Common/MemArena.cpp
index e4e68fcc80..63ccd63df1 100644
--- a/Source/Core/Common/MemArena.cpp
+++ b/Source/Core/Common/MemArena.cpp
@@ -36,7 +36,7 @@ int AshmemCreateFileMapping(const char *name, size_t size)
return fd;
// We don't really care if we can't set the name, it is optional
- ret = ioctl(fd, ASHMEM_SET_NAME, name);
+ ioctl(fd, ASHMEM_SET_NAME, name);
ret = ioctl(fd, ASHMEM_SET_SIZE, size);
if (ret < 0)
diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp
index cc6d569036..cfdc3ad730 100644
--- a/Source/Core/Common/MemoryUtil.cpp
+++ b/Source/Core/Common/MemoryUtil.cpp
@@ -1,199 +1,198 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include <cstddef>
-#include <cstdlib>
-#include <string>
-
-#include "Common/Common.h"
-
-#ifdef _WIN32
-#include <windows.h>
-#include <psapi.h>
-#include "Common/StringUtil.h"
-#else
-#include <stdio.h>
-#include <sys/mman.h>
-#endif
-
-#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
-#include <unistd.h>
-#define PAGE_MASK (getpagesize() - 1)
-#define round_page(x) ((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
-#endif
-
-// This is purposely not a full wrapper for virtualalloc/mmap, but it
-// provides exactly the primitive operations that Dolphin needs.
-
-void* AllocateExecutableMemory(size_t size, bool low)
-{
-#if defined(_WIN32)
- void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
-#else
- static char *map_hint = 0;
-#if defined(__x86_64__) && !defined(MAP_32BIT)
- // This OS has no flag to enforce allocation below the 4 GB boundary,
- // but if we hint that we want a low address it is very likely we will
- // get one.
- // An older version of this code used MAP_FIXED, but that has the side
- // effect of discarding already mapped pages that happen to be in the
- // requested virtual memory range (such as the emulated RAM, sometimes).
- if (low && (!map_hint))
- map_hint = (char*)round_page(512*1024*1024); /* 0.5 GB rounded up to the next page */
-#endif
- void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_ANON | MAP_PRIVATE
-#if defined(__x86_64__) && defined(MAP_32BIT)
- | (low ? MAP_32BIT : 0)
-#endif
- , -1, 0);
-#endif /* defined(_WIN32) */
-
- // printf("Mapped executable memory at %p (size %ld)\n", ptr,
- // (unsigned long)size);
-
-#if defined(__FreeBSD__)
- if (ptr == MAP_FAILED)
- {
- ptr = NULL;
-#else
- if (ptr == NULL)
- {
-#endif
- PanicAlert("Failed to allocate executable memory");
- }
-#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
- else
- {
- if (low)
- {
- map_hint += size;
- map_hint = (char*)round_page(map_hint); /* round up to the next page */
- // printf("Next map will (hopefully) be at %p\n", map_hint);
- }
- }
-#endif
-
-#if defined(_M_X64)
- if ((u64)ptr >= 0x80000000 && low == true)
- PanicAlert("Executable memory ended up above 2GB!");
-#endif
-
- return ptr;
-}
-
-void* AllocateMemoryPages(size_t size)
-{
-#ifdef _WIN32
- void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-#else
- void* ptr = mmap(0, size, PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_PRIVATE, -1, 0);
-#endif
-
- // printf("Mapped memory at %p (size %ld)\n", ptr,
- // (unsigned long)size);
-
- if (ptr == NULL)
- PanicAlert("Failed to allocate raw memory");
-
- return ptr;
-}
-
-void* AllocateAlignedMemory(size_t size,size_t alignment)
-{
-#ifdef _WIN32
- void* ptr = _aligned_malloc(size,alignment);
-#else
- void* ptr = NULL;
-#ifdef ANDROID
- ptr = memalign(alignment, size);
-#else
- if (posix_memalign(&ptr, alignment, size) != 0)
- ERROR_LOG(MEMMAP, "Failed to allocate aligned memory");
-#endif
-#endif
-
- // printf("Mapped memory at %p (size %ld)\n", ptr,
- // (unsigned long)size);
-
- if (ptr == NULL)
- PanicAlert("Failed to allocate aligned memory");
-
- return ptr;
-}
-
-void FreeMemoryPages(void* ptr, size_t size)
-{
- if (ptr)
- {
-#ifdef _WIN32
-
- if (!VirtualFree(ptr, 0, MEM_RELEASE))
- PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
- ptr = NULL; // Is this our responsibility?
-
-#else
- munmap(ptr, size);
-#endif
- }
-}
-
-void FreeAlignedMemory(void* ptr)
-{
- if (ptr)
- {
-#ifdef _WIN32
- _aligned_free(ptr);
-#else
- free(ptr);
-#endif
- }
-}
-
-void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
-{
-#ifdef _WIN32
- DWORD oldValue;
- if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
- PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
-#else
- mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
-#endif
-}
-
-void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
-{
-#ifdef _WIN32
- DWORD oldValue;
- if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue))
- PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
-#else
- mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
-#endif
-}
-
-std::string MemUsage()
-{
-#ifdef _WIN32
-#pragma comment(lib, "psapi")
- DWORD processID = GetCurrentProcessId();
- HANDLE hProcess;
- PROCESS_MEMORY_COUNTERS pmc;
- std::string Ret;
-
- // Print information about the memory usage of the process.
-
- hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
- if (NULL == hProcess) return "MemUsage Error";
-
- if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
- Ret = StringFromFormat("%s K", ThousandSeparate(pmc.WorkingSetSize / 1024, 7).c_str());
-
- CloseHandle(hProcess);
- return Ret;
-#else
- return "";
-#endif
-}
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <cstddef>
+#include <cstdlib>
+#include <string>
+
+#include "Common/Common.h"
+
+#ifdef _WIN32
+#include <windows.h>
+#include <psapi.h>
+#include "Common/StringUtil.h"
+#else
+#include <stdio.h>
+#include <sys/mman.h>
+#endif
+
+#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
+#include <unistd.h>
+#define PAGE_MASK (getpagesize() - 1)
+#define round_page(x) ((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
+#endif
+
+// This is purposely not a full wrapper for virtualalloc/mmap, but it
+// provides exactly the primitive operations that Dolphin needs.
+
+void* AllocateExecutableMemory(size_t size, bool low)
+{
+#if defined(_WIN32)
+ void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+#else
+ static char *map_hint = 0;
+#if defined(__x86_64__) && !defined(MAP_32BIT)
+ // This OS has no flag to enforce allocation below the 4 GB boundary,
+ // but if we hint that we want a low address it is very likely we will
+ // get one.
+ // An older version of this code used MAP_FIXED, but that has the side
+ // effect of discarding already mapped pages that happen to be in the
+ // requested virtual memory range (such as the emulated RAM, sometimes).
+ if (low && (!map_hint))
+ map_hint = (char*)round_page(512*1024*1024); /* 0.5 GB rounded up to the next page */
+#endif
+ void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_ANON | MAP_PRIVATE
+#if defined(__x86_64__) && defined(MAP_32BIT)
+ | (low ? MAP_32BIT : 0)
+#endif
+ , -1, 0);
+#endif /* defined(_WIN32) */
+
+ // printf("Mapped executable memory at %p (size %ld)\n", ptr,
+ // (unsigned long)size);
+
+#if defined(__FreeBSD__)
+ if (ptr == MAP_FAILED)
+ {
+ ptr = NULL;
+#else
+ if (ptr == NULL)
+ {
+#endif
+ PanicAlert("Failed to allocate executable memory");
+ }
+#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
+ else
+ {
+ if (low)
+ {
+ map_hint += size;
+ map_hint = (char*)round_page(map_hint); /* round up to the next page */
+ // printf("Next map will (hopefully) be at %p\n", map_hint);
+ }
+ }
+#endif
+
+#if defined(_M_X64)
+ if ((u64)ptr >= 0x80000000 && low == true)
+ PanicAlert("Executable memory ended up above 2GB!");
+#endif
+
+ return ptr;
+}
+
+void* AllocateMemoryPages(size_t size)
+{
+#ifdef _WIN32
+ void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
+#else
+ void* ptr = mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+#endif
+
+ // printf("Mapped memory at %p (size %ld)\n", ptr,
+ // (unsigned long)size);
+
+ if (ptr == NULL)
+ PanicAlert("Failed to allocate raw memory");
+
+ return ptr;
+}
+
+void* AllocateAlignedMemory(size_t size,size_t alignment)
+{
+#ifdef _WIN32
+ void* ptr = _aligned_malloc(size,alignment);
+#else
+ void* ptr = NULL;
+#ifdef ANDROID
+ ptr = memalign(alignment, size);
+#else
+ if (posix_memalign(&ptr, alignment, size) != 0)
+ ERROR_LOG(MEMMAP, "Failed to allocate aligned memory");
+#endif
+#endif
+
+ // printf("Mapped memory at %p (size %ld)\n", ptr,
+ // (unsigned long)size);
+
+ if (ptr == NULL)
+ PanicAlert("Failed to allocate aligned memory");
+
+ return ptr;
+}
+
+void FreeMemoryPages(void* ptr, size_t size)
+{
+ if (ptr)
+ {
+#ifdef _WIN32
+ if (!VirtualFree(ptr, 0, MEM_RELEASE))
+ {
+ PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
+ }
+#else
+ munmap(ptr, size);
+#endif
+ }
+}
+
+void FreeAlignedMemory(void* ptr)
+{
+ if (ptr)
+ {
+#ifdef _WIN32
+ _aligned_free(ptr);
+#else
+ free(ptr);
+#endif
+ }
+}
+
+void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
+{
+#ifdef _WIN32
+ DWORD oldValue;
+ if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
+ PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
+#else
+ mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
+#endif
+}
+
+void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
+{
+#ifdef _WIN32
+ DWORD oldValue;
+ if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue))
+ PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
+#else
+ mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
+#endif
+}
+
+std::string MemUsage()
+{
+#ifdef _WIN32
+#pragma comment(lib, "psapi")
+ DWORD processID = GetCurrentProcessId();
+ HANDLE hProcess;
+ PROCESS_MEMORY_COUNTERS pmc;
+ std::string Ret;
+
+ // Print information about the memory usage of the process.
+
+ hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
+ if (NULL == hProcess) return "MemUsage Error";
+
+ if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
+ Ret = StringFromFormat("%s K", ThousandSeparate(pmc.WorkingSetSize / 1024, 7).c_str());
+
+ CloseHandle(hProcess);
+ return Ret;
+#else
+ return "";
+#endif
+}
diff --git a/Source/Core/Common/x64FPURoundMode.cpp b/Source/Core/Common/x64FPURoundMode.cpp
index e7dd9db0f7..5876ffbd0e 100644
--- a/Source/Core/Common/x64FPURoundMode.cpp
+++ b/Source/Core/Common/x64FPURoundMode.cpp
@@ -4,30 +4,21 @@
#include "Common/Common.h"
#include "Common/CPUDetect.h"
+#include "Common/FPURoundMode.h"
-#ifndef _WIN32
-static const unsigned short FPU_ROUND_NEAR = 0 << 10;
-static const unsigned short FPU_ROUND_DOWN = 1 << 10;
-static const unsigned short FPU_ROUND_UP = 2 << 10;
-static const unsigned short FPU_ROUND_CHOP = 3 << 10;
-static const unsigned short FPU_ROUND_MASK = 3 << 10;
-#include <xmmintrin.h>
+#ifdef _WIN32
+# include <mmintrin.h>
+#else
+# include <xmmintrin.h>
#endif
-// OR-mask for disabling FPU exceptions (bits 7-12 in the MXCSR register)
-static const u32 EXCEPTION_MASK = 0x1F80;
-// Denormals-Are-Zero (non-IEEE mode: denormal inputs are set to +/- 0)
-static const u32 DAZ = 0x40;
-// Flush-To-Zero (non-IEEE mode: denormal outputs are set to +/- 0)
-static const u32 FTZ = 0x8000;
-
namespace FPURoundMode
{
// Get the default SSE states here.
static u32 saved_sse_state = _mm_getcsr();
static const u32 default_sse_state = _mm_getcsr();
- void SetRoundMode(u32 mode)
+ void SetRoundMode(RoundModes mode)
{
// Set FPU rounding mode to mimic the PowerPC's
#ifdef _M_IX86
@@ -42,22 +33,23 @@ namespace FPURoundMode
};
_set_controlfp(_MCW_RC, table[mode]);
#else
- const unsigned short table[4] =
+ const unsigned short X87_ROUND_MASK = 3 << 10;
+ const unsigned short x87_rounding_table[] =
{
- FPU_ROUND_NEAR,
- FPU_ROUND_CHOP,
- FPU_ROUND_UP,
- FPU_ROUND_DOWN
+ 0 << 10, // nearest
+ 3 << 10, // zero
+ 2 << 10, // +inf
+ 1 << 10, // -inf
};
unsigned short _mode;
- asm ("fstcw %0" : "=m" (_mode) : );
- _mode = (_mode & ~FPU_ROUND_MASK) | table[mode];
+ asm ("fstcw %0" : "=m" (_mode));
+ _mode = (_mode & ~X87_ROUND_MASK) | x87_rounding_table[mode];
asm ("fldcw %0" : : "m" (_mode));
#endif
#endif
}
- void SetPrecisionMode(u32 mode)
+ void SetPrecisionMode(PrecisionModes mode)
{
#ifdef _M_IX86
// sets the floating-point lib to 53-bit
@@ -66,15 +58,15 @@ namespace FPURoundMode
#ifdef _WIN32
_control87(_PC_53, MCW_PC);
#else
- const unsigned short table[4] = {
- 0 << 8, // FPU_PREC_24
- 2 << 8, // FPU_PREC_53
- 3 << 8, // FPU_PREC_64
- 3 << 8, // FPU_PREC_MASK
+ const unsigned short PRECISION_MASK = 3 << 8;
+ const unsigned short precision_table[] = {
+ 0 << 8, // 24 bits
+ 2 << 8, // 53 bits
+ 3 << 8, // 64 bits
};
unsigned short _mode;
asm ("fstcw %0" : "=m" (_mode));
- _mode = (_mode & ~table[3]) | table[mode];
+ _mode = (_mode & ~PRECISION_MASK) | precision_table[mode];
asm ("fldcw %0" : : "m" (_mode));
#endif
#else
@@ -83,24 +75,32 @@ namespace FPURoundMode
#endif
}
- void SetSIMDMode(u32 roundingMode, u32 nonIEEEMode)
+ void SetSIMDMode(RoundModes rounding_mode, bool non_ieee_mode)
{
+ // OR-mask for disabling FPU exceptions (bits 7-12 in the MXCSR register)
+ const u32 EXCEPTION_MASK = 0x1F80;
+ // Denormals-Are-Zero (non-IEEE mode: denormal inputs are set to +/- 0)
+ const u32 DAZ = 0x40;
+ // Flush-To-Zero (non-IEEE mode: denormal outputs are set to +/- 0)
+ const u32 FTZ = 0x8000;
// lookup table for FPSCR.RN-to-MXCSR.RC translation
- static const u32 roundingModeLUT[4] =
+ static const u32 simd_rounding_table[] =
{
(0 << 13) | EXCEPTION_MASK, // nearest
(3 << 13) | EXCEPTION_MASK, // -inf
(2 << 13) | EXCEPTION_MASK, // +inf
(1 << 13) | EXCEPTION_MASK, // zero
};
- u32 csr = roundingModeLUT[roundingMode];
+ u32 csr = simd_rounding_table[rounding_mode];
+ // Some initial steppings of Pentium 4 CPUs support FTZ but not DAZ.
+ // They will not flush input operands but flushing outputs only is better than nothing.
static const u32 denormalLUT[2] =
{
FTZ, // flush-to-zero only
FTZ | DAZ, // flush-to-zero and denormals-are-zero (may not be supported)
};
- if (nonIEEEMode)
+ if (non_ieee_mode)
{
csr |= denormalLUT[cpu_info.bFlushToZero];
}