linux.hh revision 10037
11897Sstever@eecs.umich.edu/* 24130Ssaidi@eecs.umich.edu * Copyright (c) 2010, 2011-2012 ARM Limited 31897Sstever@eecs.umich.edu * All rights reserved 41897Sstever@eecs.umich.edu * 51897Sstever@eecs.umich.edu * The license below extends only to copyright in the software and shall 61897Sstever@eecs.umich.edu * not be construed as granting a license to any other intellectual 71897Sstever@eecs.umich.edu * property including but not limited to intellectual property relating 81897Sstever@eecs.umich.edu * to a hardware implementation of the functionality of the software 91897Sstever@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 101897Sstever@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 111897Sstever@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 121897Sstever@eecs.umich.edu * modified or unmodified, in source code or in binary form. 131897Sstever@eecs.umich.edu * 141897Sstever@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan 151897Sstever@eecs.umich.edu * Copyright (c) 2007-2008 The Florida State University 161897Sstever@eecs.umich.edu * All rights reserved. 171897Sstever@eecs.umich.edu * 181897Sstever@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 191897Sstever@eecs.umich.edu * modification, are permitted provided that the following conditions are 201897Sstever@eecs.umich.edu * met: redistributions of source code must retain the above copyright 211897Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 221897Sstever@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 231897Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 241897Sstever@eecs.umich.edu * documentation and/or other materials provided with the distribution; 251897Sstever@eecs.umich.edu * neither the name of the copyright holders nor the names of its 261897Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from 271897Sstever@eecs.umich.edu * this software without specific prior written permission. 281897Sstever@eecs.umich.edu * 291897Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 301897Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 311897Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 321897Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 331897Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 344961Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 351897Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 361897Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 371897Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 381897Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 397047Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 408319Ssteve.reinhardt@amd.com * 417047Snate@binkert.org * Authors: Ali Saidi 428319Ssteve.reinhardt@amd.com * Stephen Hines 438811Sandreas.hansson@arm.com */ 4410007Snilay@cs.wisc.edu 458811Sandreas.hansson@arm.com#ifndef __ARCH_ARM_LINUX_LINUX_HH__ 468811Sandreas.hansson@arm.com#define __ARCH_ARM_LINUX_LINUX_HH__ 478811Sandreas.hansson@arm.com 489850Sandreas.hansson@arm.com#include "kern/linux/linux.hh" 498811Sandreas.hansson@arm.com 508811Sandreas.hansson@arm.comclass ArmLinux32 : public Linux 5110007Snilay@cs.wisc.edu{ 528811Sandreas.hansson@arm.com public: 537047Snate@binkert.org 548811Sandreas.hansson@arm.com /// This table maps the target open() flags to the corresponding 558811Sandreas.hansson@arm.com /// host open() flags. 568811Sandreas.hansson@arm.com static OpenFlagTransTable openFlagTable[]; 578319Ssteve.reinhardt@amd.com 588319Ssteve.reinhardt@amd.com /// Number of entries in openFlagTable[]. 598319Ssteve.reinhardt@amd.com static const int NUM_OPEN_FLAGS; 608319Ssteve.reinhardt@amd.com 618319Ssteve.reinhardt@amd.com //@{ 628319Ssteve.reinhardt@amd.com /// Basic ARM Linux types 638319Ssteve.reinhardt@amd.com typedef uint32_t size_t; 647047Snate@binkert.org typedef uint32_t off_t; 658319Ssteve.reinhardt@amd.com typedef int32_t time_t; 668319Ssteve.reinhardt@amd.com typedef int32_t clock_t; 677047Snate@binkert.org //@} 687047Snate@binkert.org 698319Ssteve.reinhardt@amd.com //@{ 708319Ssteve.reinhardt@amd.com /// open(2) flag values. 718319Ssteve.reinhardt@amd.com static const int TGT_O_RDONLY = 00000000; //!< O_RDONLY 727047Snate@binkert.org static const int TGT_O_WRONLY = 00000001; //!< O_WRONLY 737047Snate@binkert.org static const int TGT_O_RDWR = 00000002; //!< O_RDWR 747047Snate@binkert.org static const int TGT_O_CREAT = 00000100; //!< O_CREAT 751897Sstever@eecs.umich.edu static const int TGT_O_EXCL = 00000200; //!< O_EXCL 761897Sstever@eecs.umich.edu static const int TGT_O_NOCTTY = 00000400; //!< O_NOCTTY 771897Sstever@eecs.umich.edu static const int TGT_O_TRUNC = 00001000; //!< O_TRUNC 781897Sstever@eecs.umich.edu static const int TGT_O_APPEND = 00002000; //!< O_APPEND 798319Ssteve.reinhardt@amd.com static const int TGT_O_NONBLOCK = 00004000; //!< O_NONBLOCK 808319Ssteve.reinhardt@amd.com static const int TGT_O_SYNC = 00010000; //!< O_SYNC 818319Ssteve.reinhardt@amd.com static const int TGT_FASYNC = 00020000; //!< FASYNC 828319Ssteve.reinhardt@amd.com static const int TGT_O_DIRECT = 00040000; //!< O_DIRECT 838319Ssteve.reinhardt@amd.com static const int TGT_O_LARGEFILE = 00100000; //!< O_LARGEFILE 848319Ssteve.reinhardt@amd.com static const int TGT_O_DIRECTORY = 00200000; //!< O_DIRECTORY 858319Ssteve.reinhardt@amd.com static const int TGT_O_NOFOLLOW = 00400000; //!< O_NOFOLLOW 861897Sstever@eecs.umich.edu static const int TGT_O_NOATIME = 01000000; //!< O_NOATIME 878319Ssteve.reinhardt@amd.com static const int TGT_O_CLOEXEC = 02000000; //!< O_NOATIME 888811Sandreas.hansson@arm.com 898319Ssteve.reinhardt@amd.com 908319Ssteve.reinhardt@amd.com //@} 911897Sstever@eecs.umich.edu 927047Snate@binkert.org /// For mmap(). 937047Snate@binkert.org static const unsigned TGT_MAP_ANONYMOUS = 0x20; 941897Sstever@eecs.umich.edu static const unsigned TGT_MAP_FIXED = 0x10; 951897Sstever@eecs.umich.edu 964961Ssaidi@eecs.umich.edu /// For table(). 974961Ssaidi@eecs.umich.edu static const int TBL_SYSINFO = 12; 984961Ssaidi@eecs.umich.edu 994961Ssaidi@eecs.umich.edu /// Limit struct for getrlimit/setrlimit. 1004961Ssaidi@eecs.umich.edu struct rlimit { 1014961Ssaidi@eecs.umich.edu uint32_t rlim_cur; //!< soft limit 1024961Ssaidi@eecs.umich.edu uint32_t rlim_max; //!< hard limit 1034961Ssaidi@eecs.umich.edu }; 1044961Ssaidi@eecs.umich.edu 1054961Ssaidi@eecs.umich.edu /// For gettimeofday(). 1064961Ssaidi@eecs.umich.edu struct timeval { 1074961Ssaidi@eecs.umich.edu int32_t tv_sec; //!< seconds 1084961Ssaidi@eecs.umich.edu int32_t tv_usec; //!< microseconds 1094961Ssaidi@eecs.umich.edu }; 1101897Sstever@eecs.umich.edu 1118319Ssteve.reinhardt@amd.com // For writev/readv 1121897Sstever@eecs.umich.edu struct tgt_iovec { 1138319Ssteve.reinhardt@amd.com uint32_t iov_base; // void * 1148319Ssteve.reinhardt@amd.com uint32_t iov_len; 1158816Sgblack@eecs.umich.edu }; 1168319Ssteve.reinhardt@amd.com 1178319Ssteve.reinhardt@amd.com 1188319Ssteve.reinhardt@amd.com typedef struct { 1198811Sandreas.hansson@arm.com uint32_t st_dev; 1204961Ssaidi@eecs.umich.edu uint32_t st_ino; 1218319Ssteve.reinhardt@amd.com uint16_t st_mode; 1228811Sandreas.hansson@arm.com uint16_t st_nlink; 1238814Sgblack@eecs.umich.edu uint16_t st_uid; 1248319Ssteve.reinhardt@amd.com uint16_t st_gid; 1258811Sandreas.hansson@arm.com uint32_t st_rdev; 1268811Sandreas.hansson@arm.com uint32_t __pad1; 1278811Sandreas.hansson@arm.com uint32_t st_size; 1288811Sandreas.hansson@arm.com uint32_t st_blksize; 1298811Sandreas.hansson@arm.com uint32_t __pad2; 1308811Sandreas.hansson@arm.com uint32_t st_blocks; 1318811Sandreas.hansson@arm.com uint32_t st_atimeX; 1328811Sandreas.hansson@arm.com uint32_t st_atime_nsec; 1338811Sandreas.hansson@arm.com uint32_t st_mtimeX; 1341897Sstever@eecs.umich.edu uint32_t st_mtime_nsec; 1357047Snate@binkert.org uint32_t st_ctimeX; 1367047Snate@binkert.org uint32_t st_ctime_nsec; 1377047Snate@binkert.org } tgt_stat; 1387047Snate@binkert.org 1397047Snate@binkert.org typedef struct { 1407047Snate@binkert.org uint64_t st_dev; 1417047Snate@binkert.org uint8_t __pad0[4]; 1427047Snate@binkert.org uint32_t __st_ino; 1437047Snate@binkert.org uint32_t st_mode; 1447047Snate@binkert.org uint32_t st_nlink; 1457047Snate@binkert.org uint32_t st_uid; 1467047Snate@binkert.org uint32_t st_gid; 1477047Snate@binkert.org uint64_t st_rdev; 1487047Snate@binkert.org uint8_t __pad3[4]; 1494961Ssaidi@eecs.umich.edu int64_t __attribute__ ((aligned (8))) st_size; 1504961Ssaidi@eecs.umich.edu uint32_t st_blksize; 1517047Snate@binkert.org uint64_t __attribute__ ((aligned (8))) st_blocks; 1527047Snate@binkert.org uint32_t st_atimeX; 1534961Ssaidi@eecs.umich.edu uint32_t st_atime_nsec; 1545247Sstever@gmail.com uint32_t st_mtimeX; 1555247Sstever@gmail.com uint32_t st_mtime_nsec; 1568319Ssteve.reinhardt@amd.com uint32_t st_ctimeX; 1578319Ssteve.reinhardt@amd.com uint32_t st_ctime_nsec; 1583725Sstever@eecs.umich.edu uint64_t st_ino; 1599843Ssteve.reinhardt@amd.com } tgt_stat64; 1609843Ssteve.reinhardt@amd.com 1619843Ssteve.reinhardt@amd.com typedef struct { 1629843Ssteve.reinhardt@amd.com int32_t uptime; /* Seconds since boot */ 1639843Ssteve.reinhardt@amd.com uint32_t loads[3]; /* 1, 5, and 15 minute load averages */ 1649843Ssteve.reinhardt@amd.com uint32_t totalram; /* Total usable main memory size */ 1658120Sgblack@eecs.umich.edu uint32_t freeram; /* Available memory size */ 1667047Snate@binkert.org uint32_t sharedram; /* Amount of shared memory */ 1677047Snate@binkert.org uint32_t bufferram; /* Memory used by buffers */ 1687047Snate@binkert.org uint32_t totalswap; /* Total swap space size */ 1697047Snate@binkert.org uint32_t freeswap; /* swap space still available */ 1707047Snate@binkert.org uint16_t procs; /* Number of current processes */ 171 uint32_t totalhigh; /* Total high memory size */ 172 uint32_t freehigh; /* Available high memory size */ 173 uint32_t mem_unit; /* Memory unit size in bytes */ 174 } tgt_sysinfo; 175 176 /// For getrusage(). 177 struct rusage { 178 struct timeval ru_utime; //!< user time used 179 struct timeval ru_stime; //!< system time used 180 int32_t ru_maxrss; //!< max rss 181 int32_t ru_ixrss; //!< integral shared memory size 182 int32_t ru_idrss; //!< integral unshared data " 183 int32_t ru_isrss; //!< integral unshared stack " 184 int32_t ru_minflt; //!< page reclaims - total vmfaults 185 int32_t ru_majflt; //!< page faults 186 int32_t ru_nswap; //!< swaps 187 int32_t ru_inblock; //!< block input operations 188 int32_t ru_oublock; //!< block output operations 189 int32_t ru_msgsnd; //!< messages sent 190 int32_t ru_msgrcv; //!< messages received 191 int32_t ru_nsignals; //!< signals received 192 int32_t ru_nvcsw; //!< voluntary context switches 193 int32_t ru_nivcsw; //!< involuntary " 194 }; 195 196 /// For times(). 197 struct tms { 198 int32_t tms_utime; //!< user time 199 int32_t tms_stime; //!< system time 200 int32_t tms_cutime; //!< user time of children 201 int32_t tms_cstime; //!< system time of children 202 }; 203}; 204 205class ArmLinux64 : public Linux 206{ 207 public: 208 209 /// This table maps the target open() flags to the corresponding 210 /// host open() flags. 211 static OpenFlagTransTable openFlagTable[]; 212 213 /// Number of entries in openFlagTable[]. 214 static const int NUM_OPEN_FLAGS; 215 216 //@{ 217 /// Basic ARM Linux types 218 typedef uint64_t size_t; 219 typedef uint64_t off_t; 220 typedef int64_t time_t; 221 typedef int64_t clock_t; 222 //@} 223 224 //@{ 225 /// open(2) flag values. 226 static const int TGT_O_RDONLY = 00000000; //!< O_RDONLY 227 static const int TGT_O_WRONLY = 00000001; //!< O_WRONLY 228 static const int TGT_O_RDWR = 00000002; //!< O_RDWR 229 static const int TGT_O_CREAT = 00000100; //!< O_CREAT 230 static const int TGT_O_EXCL = 00000200; //!< O_EXCL 231 static const int TGT_O_NOCTTY = 00000400; //!< O_NOCTTY 232 static const int TGT_O_TRUNC = 00001000; //!< O_TRUNC 233 static const int TGT_O_APPEND = 00002000; //!< O_APPEND 234 static const int TGT_O_NONBLOCK = 00004000; //!< O_NONBLOCK 235 static const int TGT_O_SYNC = 00010000; //!< O_SYNC 236 static const int TGT_FASYNC = 00020000; //!< FASYNC 237 static const int TGT_O_DIRECT = 00040000; //!< O_DIRECT 238 static const int TGT_O_LARGEFILE = 00100000; //!< O_LARGEFILE 239 static const int TGT_O_DIRECTORY = 00200000; //!< O_DIRECTORY 240 static const int TGT_O_NOFOLLOW = 00400000; //!< O_NOFOLLOW 241 static const int TGT_O_NOATIME = 01000000; //!< O_NOATIME 242 static const int TGT_O_CLOEXEC = 02000000; //!< O_NOATIME 243 //@} 244 245 /// For mmap(). 246 static const unsigned TGT_MAP_ANONYMOUS = 0x20; 247 static const unsigned TGT_MAP_FIXED = 0x10; 248 249 //@{ 250 /// For getrusage(). 251 static const int TGT_RUSAGE_SELF = 0; 252 static const int TGT_RUSAGE_CHILDREN = -1; 253 static const int TGT_RUSAGE_BOTH = -2; 254 //@} 255 256 //@{ 257 /// ioctl() command codes. 258 static const unsigned TIOCGETP_ = 0x5401; 259 static const unsigned TIOCSETP_ = 0x80067409; 260 static const unsigned TIOCSETN_ = 0x8006740a; 261 static const unsigned TIOCSETC_ = 0x80067411; 262 static const unsigned TIOCGETC_ = 0x40067412; 263 static const unsigned FIONREAD_ = 0x4004667f; 264 static const unsigned TIOCISATTY_ = 0x2000745e; 265 static const unsigned TIOCGETS_ = 0x402c7413; 266 static const unsigned TIOCGETA_ = 0x5405; 267 static const unsigned TCSETAW_ = 0x5407; // 2.6.15 kernel 268 //@} 269 270 /// For table(). 271 static const int TBL_SYSINFO = 12; 272 273 /// Resource enumeration for getrlimit(). 274 enum rlimit_resources { 275 TGT_RLIMIT_CPU = 0, 276 TGT_RLIMIT_FSIZE = 1, 277 TGT_RLIMIT_DATA = 2, 278 TGT_RLIMIT_STACK = 3, 279 TGT_RLIMIT_CORE = 4, 280 TGT_RLIMIT_RSS = 5, 281 TGT_RLIMIT_NPROC = 6, 282 TGT_RLIMIT_NOFILE = 7, 283 TGT_RLIMIT_MEMLOCK = 8, 284 TGT_RLIMIT_AS = 9, 285 TGT_RLIMIT_LOCKS = 10 286 }; 287 288 /// Limit struct for getrlimit/setrlimit. 289 struct rlimit { 290 uint64_t rlim_cur; //!< soft limit 291 uint64_t rlim_max; //!< hard limit 292 }; 293 294 /// For gettimeofday(). 295 struct timeval { 296 int64_t tv_sec; //!< seconds 297 int64_t tv_usec; //!< microseconds 298 }; 299 300 // For writev/readv 301 struct tgt_iovec { 302 uint64_t iov_base; // void * 303 uint64_t iov_len; 304 }; 305 306 typedef struct { 307 uint64_t st_dev; 308 uint64_t st_ino; 309 uint64_t st_nlink; 310 uint32_t st_mode; 311 uint32_t st_uid; 312 uint32_t st_gid; 313 uint32_t __pad0; 314 uint64_t st_rdev; 315 uint64_t st_size; 316 uint64_t st_blksize; 317 uint64_t st_blocks; 318 uint64_t st_atimeX; 319 uint64_t st_atime_nsec; 320 uint64_t st_mtimeX; 321 uint64_t st_mtime_nsec; 322 uint64_t st_ctimeX; 323 uint64_t st_ctime_nsec; 324 } tgt_stat; 325 326 typedef struct { 327 uint64_t st_dev; 328 uint64_t st_ino; 329 uint32_t st_mode; 330 uint32_t st_nlink; 331 uint32_t st_uid; 332 uint32_t st_gid; 333 uint32_t __pad0; 334 uint64_t st_rdev; 335 uint64_t st_size; 336 uint64_t st_blksize; 337 uint64_t st_blocks; 338 uint64_t st_atimeX; 339 uint64_t st_atime_nsec; 340 uint64_t st_mtimeX; 341 uint64_t st_mtime_nsec; 342 uint64_t st_ctimeX; 343 uint64_t st_ctime_nsec; 344 } tgt_stat64; 345 346 typedef struct { 347 int64_t uptime; /* Seconds since boot */ 348 uint64_t loads[3]; /* 1, 5, and 15 minute load averages */ 349 uint64_t totalram; /* Total usable main memory size */ 350 uint64_t freeram; /* Available memory size */ 351 uint64_t sharedram; /* Amount of shared memory */ 352 uint64_t bufferram; /* Memory used by buffers */ 353 uint64_t totalswap; /* Total swap space size */ 354 uint64_t freeswap; /* swap space still available */ 355 uint16_t procs; /* Number of current processes */ 356 uint16_t pad; 357 uint64_t totalhigh; /* Total high memory size */ 358 uint64_t freehigh; /* Available high memory size */ 359 uint32_t mem_unit; /* Memory unit size in bytes */ 360 } tgt_sysinfo; 361 362 /// For getrusage(). 363 struct rusage { 364 struct timeval ru_utime; //!< user time used 365 struct timeval ru_stime; //!< system time used 366 int64_t ru_maxrss; //!< max rss 367 int64_t ru_ixrss; //!< integral shared memory size 368 int64_t ru_idrss; //!< integral unshared data " 369 int64_t ru_isrss; //!< integral unshared stack " 370 int64_t ru_minflt; //!< page reclaims - total vmfaults 371 int64_t ru_majflt; //!< page faults 372 int64_t ru_nswap; //!< swaps 373 int64_t ru_inblock; //!< block input operations 374 int64_t ru_oublock; //!< block output operations 375 int64_t ru_msgsnd; //!< messages sent 376 int64_t ru_msgrcv; //!< messages received 377 int64_t ru_nsignals; //!< signals received 378 int64_t ru_nvcsw; //!< voluntary context switches 379 int64_t ru_nivcsw; //!< involuntary " 380 }; 381 382 /// For times(). 383 struct tms { 384 int64_t tms_utime; //!< user time 385 int64_t tms_stime; //!< system time 386 int64_t tms_cutime; //!< user time of children 387 int64_t tms_cstime; //!< system time of children 388 }; 389}; 390 391#endif 392