simple_disk.cc revision 11264
12SN/A/* 21762SN/A * 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. 272665SN/A * 282665SN/A * Authors: Nathan Binkert 292SN/A */ 302SN/A 312SN/A/* @file 322SN/A * Simple disk interface for the system console 332SN/A */ 342SN/A 3511264Sandreas.sandberg@arm.com#include "dev/storage/simple_disk.hh" 3611264Sandreas.sandberg@arm.com 3711264Sandreas.sandberg@arm.com#include <fcntl.h> 382SN/A#include <sys/types.h> 392SN/A#include <sys/uio.h> 402SN/A#include <unistd.h> 412SN/A 42146SN/A#include <cstring> 43146SN/A#include <string> 44146SN/A 45146SN/A#include "base/misc.hh" 46146SN/A#include "base/trace.hh" 478232SN/A#include "debug/SimpleDisk.hh" 488232SN/A#include "debug/SimpleDiskData.hh" 4911264Sandreas.sandberg@arm.com#include "dev/storage/disk_image.hh" 508706SN/A#include "mem/port_proxy.hh" 512522SN/A#include "sim/system.hh" 522SN/A 532SN/Ausing namespace std; 542SN/A 555034SN/ASimpleDisk::SimpleDisk(const Params *p) 565034SN/A : SimObject(p), system(p->system), image(p->disk) 572SN/A{} 582SN/A 592SN/ASimpleDisk::~SimpleDisk() 602SN/A{} 612SN/A 622SN/A 632SN/Avoid 642SN/ASimpleDisk::read(Addr addr, baddr_t block, int count) const 652SN/A{ 662522SN/A uint8_t *data = new uint8_t[SectorSize * count]; 672SN/A 682SN/A if (count & (SectorSize - 1)) 692SN/A panic("Not reading a multiple of a sector (count = %d)", count); 702SN/A 712SN/A for (int i = 0, j = 0; i < count; i += SectorSize, j++) 722SN/A image->read(data + i, block + j); 732SN/A 748852SN/A system->physProxy.writeBlob(addr, data, count); 752522SN/A 762SN/A DPRINTF(SimpleDisk, "read block=%#x len=%d\n", (uint64_t)block, count); 772SN/A DDUMP(SimpleDiskData, data, count); 782522SN/A 798994SN/A delete [] data; 802SN/A} 812SN/A 822SN/Avoid 832SN/ASimpleDisk::write(Addr addr, baddr_t block, int count) 842SN/A{ 852SN/A panic("unimplemented!\n"); 862SN/A 872SN/A#if 0 882SN/A uint8_t *data = physmem->dma_addr(addr, count); 892SN/A if (!data) 902SN/A panic("dma out of range! write addr=%#x count=%d\n", addr, count); 912SN/A 922SN/A image->write(data, block, count); 932SN/A#endif 942SN/A} 952SN/A 964762SN/ASimpleDisk * 974762SN/ASimpleDiskParams::create() 982SN/A{ 995034SN/A return new SimpleDisk(this); 1002SN/A} 101