Make code more portable and port to cygwin
authorNathan Binkert <binkertn@umich.edu>
Fri, 22 Apr 2005 17:12:03 +0000 (13:12 -0400)
committerNathan Binkert <binkertn@umich.edu>
Fri, 22 Apr 2005 17:12:03 +0000 (13:12 -0400)
arch/alpha/alpha_tru64_process.cc:
    getdirent isn't implemented by cygwin.  panic if this function is
    executed.  (It shouldn't be too much to emulate it using opendir,
    readdir, etc.)
arch/alpha/pseudo_inst.cc:
    Use lseek once and read instead pread.
base/intmath.hh:
    we want int, long, and long long variations of FloorLog2 instead
    of int32_t, int64_t.  Otherwise, we leave one out.
base/socket.cc:
    Fix define that seems to be for apple
sim/serialize.cc:
    don't use the intXX_t stuff, instead, use the real types
    so we're sure that we cover all of them.

--HG--
extra : convert_revision : 9fccaff583100b06bbaafd95a162c4e19beed59e

arch/alpha/alpha_tru64_process.cc
arch/alpha/pseudo_inst.cc
base/intmath.hh
base/socket.cc
sim/serialize.cc

index 441e7c89fee1c9cc8c357adc94c08678b7f1eac6..0910ec552cba2e5965a93ddb9b06a7228f5859a9 100644 (file)
@@ -622,6 +622,9 @@ class Tru64 {
     getdirentriesFunc(SyscallDesc *desc, int callnum, Process *process,
                       ExecContext *xc)
     {
+#ifdef __CYGWIN__
+        panic("getdirent not implemented on cygwin!");
+#else
         int fd = process->sim_fd(xc->getSyscallArg(0));
         Addr tgt_buf = xc->getSyscallArg(1);
         int tgt_nbytes = xc->getSyscallArg(2);
@@ -670,6 +673,7 @@ class Tru64 {
         basep.copyOut(xc->mem);
 
         return tgt_buf_ptr - tgt_buf;
+#endif
     }
 
     /// Target sigreturn() handler.
index 3c3b37928179b06eb342699118ca04cfe7f8afa9..a4af891af738147478b35b3365c4cdc4441e073d 100644 (file)
@@ -26,6 +26,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <cstdio>
@@ -180,15 +181,17 @@ namespace AlphaPseudo
         if (fd < 0)
             panic("could not open file %s\n", file);
 
+        if (::lseek(fd, offset, SEEK_SET) < 0)
+            panic("could not seek: %s", strerror(errno));
+
         char *buf = new char[len];
         char *p = buf;
         while (len > 0) {
-            int bytes = ::pread(fd, p, len, offset);
+            int bytes = ::read(fd, p, len);
             if (bytes <= 0)
                 break;
 
             p += bytes;
-            offset += bytes;
             result += bytes;
             len -= bytes;
         }
index 5ffe2710393c78cd5d746f4e3a60f42f6d19caf0..0cf48b41bad9b09070979bc6c61a0255fbc42491 100644 (file)
@@ -73,7 +73,7 @@ IsPowerOf2(T n)
 }
 
 inline int
-FloorLog2(uint32_t x)
+FloorLog2(unsigned x)
 {
     assert(x > 0);
 
@@ -89,7 +89,26 @@ FloorLog2(uint32_t x)
 }
 
 inline int
-FloorLog2(uint64_t x)
+FloorLog2(unsigned long x)
+{
+    assert(x > 0);
+
+    int y = 0;
+
+#if defined(__LP64__)
+    if (x & ULL(0xffffffff00000000)) { y += 32; x >>= 32; }
+#endif
+    if (x & 0xffff0000) { y += 16; x >>= 16; }
+    if (x & 0x0000ff00) { y +=  8; x >>=  8; }
+    if (x & 0x000000f0) { y +=  4; x >>=  4; }
+    if (x & 0x0000000c) { y +=  2; x >>=  2; }
+    if (x & 0x00000002) { y +=  1; }
+
+    return y;
+}
+
+inline int
+FloorLog2(unsigned long long x)
 {
     assert(x > 0);
 
@@ -106,17 +125,24 @@ FloorLog2(uint64_t x)
 }
 
 inline int
-FloorLog2(int32_t x)
+FloorLog2(int x)
+{
+    assert(x > 0);
+    return FloorLog2((unsigned)x);
+}
+
+inline int
+FloorLog2(long x)
 {
     assert(x > 0);
-    return FloorLog2((uint32_t)x);
+    return FloorLog2((unsigned long)x);
 }
 
 inline int
-FloorLog2(int64_t x)
+FloorLog2(long long x)
 {
     assert(x > 0);
-    return FloorLog2((uint64_t)x);
+    return FloorLog2((unsigned long long)x);
 }
 
 #if defined(__APPLE__)
index ee87dc057f8498b27b871558e92f483a493144e0..c2e9e70e0400df2596937e8f23ad5516af55cebc 100644 (file)
@@ -93,7 +93,7 @@ ListenSocket::listen(int port, bool reuse)
     return true;
 }
 
-#if !defined(__OpenBSD__) && !defined(linux)
+#if defined(__APPLE__)
 typedef int socklen_t;
 #endif
 
index 52008c3949309285e13648073355f8ac030b80d7..ca0bc2bb09eda7a9259275db44a731dad63bc4d9 100644 (file)
@@ -172,15 +172,16 @@ template void                                                             \
 arrayParamIn(Checkpoint *cp, const std::string &section,               \
              const std::string &name, type *param, int size);
 
-
-INSTANTIATE_PARAM_TEMPLATES(int8_t)
-INSTANTIATE_PARAM_TEMPLATES(uint8_t)
-INSTANTIATE_PARAM_TEMPLATES(int16_t)
-INSTANTIATE_PARAM_TEMPLATES(uint16_t)
-INSTANTIATE_PARAM_TEMPLATES(int32_t)
-INSTANTIATE_PARAM_TEMPLATES(uint32_t)
-INSTANTIATE_PARAM_TEMPLATES(int64_t)
-INSTANTIATE_PARAM_TEMPLATES(uint64_t)
+INSTANTIATE_PARAM_TEMPLATES(signed char)
+INSTANTIATE_PARAM_TEMPLATES(unsigned char)
+INSTANTIATE_PARAM_TEMPLATES(signed short)
+INSTANTIATE_PARAM_TEMPLATES(unsigned short)
+INSTANTIATE_PARAM_TEMPLATES(signed int)
+INSTANTIATE_PARAM_TEMPLATES(unsigned int)
+INSTANTIATE_PARAM_TEMPLATES(signed long)
+INSTANTIATE_PARAM_TEMPLATES(unsigned long)
+INSTANTIATE_PARAM_TEMPLATES(signed long long)
+INSTANTIATE_PARAM_TEMPLATES(unsigned long long)
 INSTANTIATE_PARAM_TEMPLATES(bool)
 INSTANTIATE_PARAM_TEMPLATES(string)