syscall_emul.hh (10794:75f10b3e7938) syscall_emul.hh (10796:5bcba8001c7e)
1/*
2 * Copyright (c) 2012-2013 ARM Limited
1/*
2 * Copyright (c) 2012-2013 ARM Limited
3 * Copyright (c) 2015 Advanced Micro Devices, Inc.
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated

--- 381 unchanged lines hidden (view full) ---

392
393/// Target getgidPseudo() handler.
394SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
395 LiveProcess *p, ThreadContext *tc);
396
397
398/// A readable name for 1,000,000, for converting microseconds to seconds.
399const int one_million = 1000000;
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated

--- 381 unchanged lines hidden (view full) ---

393
394/// Target getgidPseudo() handler.
395SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
396 LiveProcess *p, ThreadContext *tc);
397
398
399/// A readable name for 1,000,000, for converting microseconds to seconds.
400const int one_million = 1000000;
401/// A readable name for 1,000,000,000, for converting nanoseconds to seconds.
402const int one_billion = 1000000000;
400
401/// Approximate seconds since the epoch (1/1/1970). About a billion,
402/// by my reckoning. We want to keep this a constant (not use the
403/// real-world time) to keep simulations repeatable.
404const unsigned seconds_since_epoch = 1000000000;
405
406/// Helper function to convert current elapsed time to seconds and
407/// microseconds.
408template <class T1, class T2>
409void
403
404/// Approximate seconds since the epoch (1/1/1970). About a billion,
405/// by my reckoning. We want to keep this a constant (not use the
406/// real-world time) to keep simulations repeatable.
407const unsigned seconds_since_epoch = 1000000000;
408
409/// Helper function to convert current elapsed time to seconds and
410/// microseconds.
411template <class T1, class T2>
412void
410getElapsedTime(T1 &sec, T2 &usec)
413getElapsedTimeMicro(T1 &sec, T2 &usec)
411{
414{
412 int elapsed_usecs = curTick() / SimClock::Int::us;
415 uint64_t elapsed_usecs = curTick() / SimClock::Int::us;
413 sec = elapsed_usecs / one_million;
414 usec = elapsed_usecs % one_million;
415}
416
416 sec = elapsed_usecs / one_million;
417 usec = elapsed_usecs % one_million;
418}
419
420/// Helper function to convert current elapsed time to seconds and
421/// nanoseconds.
422template <class T1, class T2>
423void
424getElapsedTimeNano(T1 &sec, T2 &nsec)
425{
426 uint64_t elapsed_nsecs = curTick() / SimClock::Int::ns;
427 sec = elapsed_nsecs / one_billion;
428 nsec = elapsed_nsecs % one_billion;
429}
430
417//////////////////////////////////////////////////////////////////////
418//
419// The following emulation functions are generic, but need to be
420// templated to account for differences in types, constants, etc.
421//
422//////////////////////////////////////////////////////////////////////
423
424#if NO_STAT64

--- 853 unchanged lines hidden (view full) ---

1278 return -EINVAL;
1279 break;
1280 }
1281
1282 rlp.copyOut(tc->getMemProxy());
1283 return 0;
1284}
1285
431//////////////////////////////////////////////////////////////////////
432//
433// The following emulation functions are generic, but need to be
434// templated to account for differences in types, constants, etc.
435//
436//////////////////////////////////////////////////////////////////////
437
438#if NO_STAT64

--- 853 unchanged lines hidden (view full) ---

1292 return -EINVAL;
1293 break;
1294 }
1295
1296 rlp.copyOut(tc->getMemProxy());
1297 return 0;
1298}
1299
1300/// Target clock_gettime() function.
1301template <class OS>
1302SyscallReturn
1303clock_gettimeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1304{
1305 int index = 1;
1306 //int clk_id = p->getSyscallArg(tc, index);
1307 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1308
1309 getElapsedTimeNano(tp->tv_sec, tp->tv_nsec);
1310 tp->tv_sec += seconds_since_epoch;
1311 tp->tv_sec = TheISA::htog(tp->tv_sec);
1312 tp->tv_nsec = TheISA::htog(tp->tv_nsec);
1313
1314 tp.copyOut(tc->getMemProxy());
1315
1316 return 0;
1317}
1318
1286/// Target gettimeofday() handler.
1287template <class OS>
1288SyscallReturn
1289gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1290 ThreadContext *tc)
1291{
1292 int index = 0;
1293 TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
1294
1319/// Target gettimeofday() handler.
1320template <class OS>
1321SyscallReturn
1322gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1323 ThreadContext *tc)
1324{
1325 int index = 0;
1326 TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
1327
1295 getElapsedTime(tp->tv_sec, tp->tv_usec);
1328 getElapsedTimeMicro(tp->tv_sec, tp->tv_usec);
1296 tp->tv_sec += seconds_since_epoch;
1297 tp->tv_sec = TheISA::htog(tp->tv_sec);
1298 tp->tv_usec = TheISA::htog(tp->tv_usec);
1299
1300 tp.copyOut(tc->getMemProxy());
1301
1302 return 0;
1303}

--- 60 unchanged lines hidden (view full) ---

1364 rup->ru_msgsnd = 0;
1365 rup->ru_msgrcv = 0;
1366 rup->ru_nsignals = 0;
1367 rup->ru_nvcsw = 0;
1368 rup->ru_nivcsw = 0;
1369
1370 switch (who) {
1371 case OS::TGT_RUSAGE_SELF:
1329 tp->tv_sec += seconds_since_epoch;
1330 tp->tv_sec = TheISA::htog(tp->tv_sec);
1331 tp->tv_usec = TheISA::htog(tp->tv_usec);
1332
1333 tp.copyOut(tc->getMemProxy());
1334
1335 return 0;
1336}

--- 60 unchanged lines hidden (view full) ---

1397 rup->ru_msgsnd = 0;
1398 rup->ru_msgrcv = 0;
1399 rup->ru_nsignals = 0;
1400 rup->ru_nvcsw = 0;
1401 rup->ru_nivcsw = 0;
1402
1403 switch (who) {
1404 case OS::TGT_RUSAGE_SELF:
1372 getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
1405 getElapsedTimeMicro(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
1373 rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
1374 rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
1375 break;
1376
1377 case OS::TGT_RUSAGE_CHILDREN:
1378 // do nothing. We have no child processes, so they take no time.
1379 break;
1380

--- 37 unchanged lines hidden (view full) ---

1418
1419/// Target time() function.
1420template <class OS>
1421SyscallReturn
1422timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1423 ThreadContext *tc)
1424{
1425 typename OS::time_t sec, usec;
1406 rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
1407 rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
1408 break;
1409
1410 case OS::TGT_RUSAGE_CHILDREN:
1411 // do nothing. We have no child processes, so they take no time.
1412 break;
1413

--- 37 unchanged lines hidden (view full) ---

1451
1452/// Target time() function.
1453template <class OS>
1454SyscallReturn
1455timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1456 ThreadContext *tc)
1457{
1458 typename OS::time_t sec, usec;
1426 getElapsedTime(sec, usec);
1459 getElapsedTimeMicro(sec, usec);
1427 sec += seconds_since_epoch;
1428
1429 int index = 0;
1430 Addr taddr = (Addr)process->getSyscallArg(tc, index);
1431 if(taddr != 0) {
1432 typename OS::time_t t = sec;
1433 t = TheISA::htog(t);
1434 SETranslatingPortProxy &p = tc->getMemProxy();
1435 p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
1436 }
1437 return sec;
1438}
1439
1440
1441#endif // __SIM_SYSCALL_EMUL_HH__
1460 sec += seconds_since_epoch;
1461
1462 int index = 0;
1463 Addr taddr = (Addr)process->getSyscallArg(tc, index);
1464 if(taddr != 0) {
1465 typename OS::time_t t = sec;
1466 t = TheISA::htog(t);
1467 SETranslatingPortProxy &p = tc->getMemProxy();
1468 p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
1469 }
1470 return sec;
1471}
1472
1473
1474#endif // __SIM_SYSCALL_EMUL_HH__