simple_disk.cc revision 8232
12SN/A/* 24039Sbinkertn@umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu */ 302SN/A 312SN/A/* @file 321354SN/A * Simple disk interface for the system console 331354SN/A */ 342SN/A 354046Sbinkertn@umich.edu#include <sys/types.h> 362SN/A#include <sys/uio.h> 372SN/A#include <fcntl.h> 3856SN/A#include <unistd.h> 391031SN/A 404046Sbinkertn@umich.edu#include <cstring> 416214Snate@binkert.org#include <string> 424167Sbinkertn@umich.edu 432SN/A#include "base/misc.hh" 442SN/A#include "base/trace.hh" 452SN/A#include "debug/SimpleDisk.hh" 464046Sbinkertn@umich.edu#include "debug/SimpleDiskData.hh" 474046Sbinkertn@umich.edu#include "dev/disk_image.hh" 482SN/A#include "dev/simple_disk.hh" 494046Sbinkertn@umich.edu#include "mem/port.hh" 504046Sbinkertn@umich.edu#include "sim/system.hh" 514046Sbinkertn@umich.edu 524046Sbinkertn@umich.eduusing namespace std; 534046Sbinkertn@umich.edu 544046Sbinkertn@umich.eduSimpleDisk::SimpleDisk(const Params *p) 552SN/A : SimObject(p), system(p->system), image(p->disk) 564046Sbinkertn@umich.edu{} 574046Sbinkertn@umich.edu 582SN/ASimpleDisk::~SimpleDisk() 594046Sbinkertn@umich.edu{} 604046Sbinkertn@umich.edu 614046Sbinkertn@umich.edu 622SN/Avoid 637811Ssteve.reinhardt@amd.comSimpleDisk::read(Addr addr, baddr_t block, int count) const 644039Sbinkertn@umich.edu{ 651070SN/A uint8_t *data = new uint8_t[SectorSize * count]; 661070SN/A 671070SN/A if (count & (SectorSize - 1)) 681070SN/A panic("Not reading a multiple of a sector (count = %d)", count); 691070SN/A 701070SN/A for (int i = 0, j = 0; i < count; i += SectorSize, j++) 711070SN/A image->read(data + i, block + j); 721070SN/A 731070SN/A system->functionalPort->writeBlob(addr, data, count); 742SN/A 752SN/A DPRINTF(SimpleDisk, "read block=%#x len=%d\n", (uint64_t)block, count); 762SN/A DDUMP(SimpleDiskData, data, count); 772SN/A 782SN/A delete data; 792SN/A} 802SN/A 812SN/Avoid 822SN/ASimpleDisk::write(Addr addr, baddr_t block, int count) 832SN/A{ 842SN/A panic("unimplemented!\n"); 852SN/A 862SN/A#if 0 872SN/A uint8_t *data = physmem->dma_addr(addr, count); 884042Sbinkertn@umich.edu if (!data) 892SN/A panic("dma out of range! write addr=%#x count=%d\n", addr, count); 904041Sbinkertn@umich.edu 914041Sbinkertn@umich.edu image->write(data, block, count); 924046Sbinkertn@umich.edu#endif 932SN/A} 942SN/A 954041Sbinkertn@umich.eduSimpleDisk * 964041Sbinkertn@umich.eduSimpleDiskParams::create() 974041Sbinkertn@umich.edu{ 982SN/A return new SimpleDisk(this); 992SN/A} 1005806Ssaidi@eecs.umich.edu