linux.cc revision 5795
17753SWilliam.Wang@arm.com/* 29394Sandreas.hansson@arm.com * Copyright (c) 2009 The Regents of The University of Michigan 37753SWilliam.Wang@arm.com * All rights reserved. 47753SWilliam.Wang@arm.com * 57753SWilliam.Wang@arm.com * Redistribution and use in source and binary forms, with or without 67753SWilliam.Wang@arm.com * modification, are permitted provided that the following conditions are 77753SWilliam.Wang@arm.com * met: redistributions of source code must retain the above copyright 87753SWilliam.Wang@arm.com * notice, this list of conditions and the following disclaimer; 97753SWilliam.Wang@arm.com * redistributions in binary form must reproduce the above copyright 107753SWilliam.Wang@arm.com * notice, this list of conditions and the following disclaimer in the 117753SWilliam.Wang@arm.com * documentation and/or other materials provided with the distribution; 127753SWilliam.Wang@arm.com * neither the name of the copyright holders nor the names of its 137753SWilliam.Wang@arm.com * contributors may be used to endorse or promote products derived from 147753SWilliam.Wang@arm.com * this software without specific prior written permission. 157753SWilliam.Wang@arm.com * 167753SWilliam.Wang@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177753SWilliam.Wang@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187753SWilliam.Wang@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197753SWilliam.Wang@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207753SWilliam.Wang@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217753SWilliam.Wang@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227753SWilliam.Wang@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237753SWilliam.Wang@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247753SWilliam.Wang@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257753SWilliam.Wang@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267753SWilliam.Wang@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277753SWilliam.Wang@arm.com * 287753SWilliam.Wang@arm.com * Authors: Ali Saidi 297753SWilliam.Wang@arm.com */ 307753SWilliam.Wang@arm.com 317753SWilliam.Wang@arm.com#include <string> 327753SWilliam.Wang@arm.com 337753SWilliam.Wang@arm.com#include "cpu/thread_context.hh" 347753SWilliam.Wang@arm.com#include "kern/linux/linux.hh" 357753SWilliam.Wang@arm.com#include "sim/process.hh" 367753SWilliam.Wang@arm.com#include "sim/system.hh" 377753SWilliam.Wang@arm.com 387950SAli.Saidi@ARM.comint 397753SWilliam.Wang@arm.comLinux::openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc) 407753SWilliam.Wang@arm.com{ 419330Schander.sudanthi@arm.com DPRINTF(SyscallVerbose, "Opening special file: %s\n", path.c_str()); 427950SAli.Saidi@ARM.com if (path.compare(0, 13, "/proc/meminfo") == 0) { 437950SAli.Saidi@ARM.com std::string data = Linux::procMeminfo(process, tc); 447753SWilliam.Wang@arm.com FILE *f = tmpfile(); 458245Snate@binkert.org int fd = fileno(f); 468245Snate@binkert.org int ret M5_VAR_USED = fwrite(data.c_str(), 1, data.size(), f); 477753SWilliam.Wang@arm.com assert(ret == data.size()); 489525SAndreas.Sandberg@ARM.com rewind(f); 497753SWilliam.Wang@arm.com return fd; 507753SWilliam.Wang@arm.com } 517753SWilliam.Wang@arm.com 529525SAndreas.Sandberg@ARM.com warn("Attempting to open special file: %s. Ignorning. Simulation may" 537753SWilliam.Wang@arm.com " take un-expected code path or be non-deterministic until proper" 548737Skoansin.tan@gmail.com " handling is implemented.\n", path.c_str()); 558737Skoansin.tan@gmail.com return -1; 568737Skoansin.tan@gmail.com} 578737Skoansin.tan@gmail.com 587753SWilliam.Wang@arm.comstd::string 597753SWilliam.Wang@arm.comLinux::procMeminfo(LiveProcess *process, ThreadContext *tc) 607753SWilliam.Wang@arm.com{ 617753SWilliam.Wang@arm.com return csprintf("MemTotal:%12d kB\nMemFree: %12d kB\n", 627950SAli.Saidi@ARM.com process->system->memSize() >> 10, 637753SWilliam.Wang@arm.com process->system->freeMemSize() >> 10); 647753SWilliam.Wang@arm.com} 659157Sandreas.hansson@arm.com 669530SChris.Emmons@arm.com