1/* 2 * Copyright (c) 2010-2012, 2015 ARM Limited 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 --- 578 unchanged lines hidden (view full) --- 587} 588 589uint64_t 590writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 591 Addr filename_addr) 592{ 593 DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n", 594 vaddr, len, offset, filename_addr); |
595 596 // copy out target filename 597 char fn[100]; 598 std::string filename; 599 CopyStringOut(tc, fn, filename_addr, 100); 600 filename = std::string(fn); 601 |
602 OutputStream *out; |
603 if (offset == 0) { 604 // create a new file (truncate) |
605 out = simout.create(filename, true, true); |
606 } else { 607 // do not truncate file if offset is non-zero 608 // (ios::in flag is required as well to keep the existing data 609 // intact, otherwise existing data will be zeroed out.) |
610 out = simout.open(filename, ios::in | ios::out | ios::binary, true); |
611 } |
612 613 ostream *os(out->stream()); |
614 if (!os) 615 panic("could not open file %s\n", filename); 616 617 // seek to offset 618 os->seekp(offset); 619 620 // copy out data and write to file 621 char *buf = new char[len]; 622 CopyOut(tc, buf, vaddr, len); 623 os->write(buf, len); 624 if (os->fail() || os->bad()) 625 panic("Error while doing writefile!\n"); 626 |
627 simout.close(out); |
628 629 delete [] buf; 630 631 return len; 632} 633 634void 635debugbreak(ThreadContext *tc) --- 133 unchanged lines hidden --- |