aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorLionel Ulmer2002-05-03 18:24:16 +0000
committerLionel Ulmer2002-05-03 18:24:16 +0000
commit0e6d4da0588962cbb9bd9598286c854a90904d4a (patch)
tree0f4f9efeec83186040110601d3596574fa1a2df3 /main.cpp
parent9419cef7a1826fb59aba5cfa7d36107a8cf93187 (diff)
downloadscummvm-rg350-0e6d4da0588962cbb9bd9598286c854a90904d4a.tar.gz
scummvm-rg350-0e6d4da0588962cbb9bd9598286c854a90904d4a.tar.bz2
scummvm-rg350-0e6d4da0588962cbb9bd9598286c854a90904d4a.zip
Add a quick dynamic test to see if the memory options (endianness and
alignement) corresponds to what the CPU expects. This could help stop bugs early on some platforms to almost no loss of start-up speed. svn-id: r4182
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
index d49c029c9a..1f729e8ab7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -52,6 +52,45 @@ Config * scummcfg;
#define DEFAULT_CONFIG_FILE "scummvm.ini"
#endif
+#if defined(UNIX) || defined(UNIX_X11)
+#include <signal.h>
+
+static void handle_errors(int sig_num) {
+ error("Your system does not support unaligned memory accesses. Please rebuild with SCUMM_NEED_ALIGNMENT ");
+}
+
+/* This function is here to test if the endianness / alignement compiled it is matching
+ with the one at run-time. */
+static void do_memory_test(void) {
+ unsigned char test[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
+ unsigned int value;
+ /* First test endianness */
+#ifdef SCUMM_LITTLE_ENDIAN
+ if (*((int *) test) != 0x44332211) {
+ error("Compiled as LITTLE_ENDIAN on a big endian system. Please rebuild ");
+ }
+ value = 0x55443322;
+#else
+ if (*((int *) test) != 0x11223344) {
+ error("Compiled as BIG_ENDIAN on a little endian system. Please rebuild ");
+ }
+ value = 0x22334455;
+#endif
+ /* Then check if one really supports unaligned memory accesses */
+#ifndef SCUMM_NEED_ALIGNMENT
+ signal(SIGBUS, handle_errors);
+ signal(SIGABRT, handle_errors);
+ signal(SIGSEGV, handle_errors);
+ if (*((int *) ((char *) test + 1)) != value) {
+ error("Your system does not support unaligned memory accesses. Please rebuild with SCUMM_NEED_ALIGNMENT ");
+ }
+ signal(SIGBUS, SIG_DFL);
+ signal(SIGABRT, SIG_DFL);
+ signal(SIGSEGV, SIG_DFL);
+#endif
+}
+
+#endif
int main(int argc, char *argv[])
{
@@ -95,6 +134,9 @@ int main(int argc, char *argv[])
sprintf(scummhome,"%s/%s", getenv("HOME"), DEFAULT_CONFIG_FILE);
else strcpy(scummhome,DEFAULT_CONFIG_FILE);
scummcfg = new Config(scummhome, "scummvm");
+
+ /* On Unix, do a quick endian / alignement check before starting */
+ do_memory_test();
#else
scummcfg = new Config(DEFAULT_CONFIG_FILE, "scummvm");
#endif