simple_disk.cc revision 4762
16019Shines@cs.fsu.edu/* 210037SARM gem5 Developers * Copyright (c) 2001-2005 The Regents of The University of Michigan 37189Sgblack@eecs.umich.edu * All rights reserved. 47189Sgblack@eecs.umich.edu * 57189Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 67189Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 77189Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 87189Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 97189Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 107189Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 117189Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 127189Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 137189Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 146019Shines@cs.fsu.edu * this software without specific prior written permission. 156019Shines@cs.fsu.edu * 166019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276019Shines@cs.fsu.edu * 286019Shines@cs.fsu.edu * Authors: Nathan Binkert 296019Shines@cs.fsu.edu */ 306019Shines@cs.fsu.edu 316019Shines@cs.fsu.edu/* @file 326019Shines@cs.fsu.edu * Simple disk interface for the system console 336019Shines@cs.fsu.edu */ 346019Shines@cs.fsu.edu 356019Shines@cs.fsu.edu#include <sys/types.h> 366019Shines@cs.fsu.edu#include <sys/uio.h> 376019Shines@cs.fsu.edu#include <fcntl.h> 386019Shines@cs.fsu.edu#include <unistd.h> 396019Shines@cs.fsu.edu 406019Shines@cs.fsu.edu#include <cstring> 416735Sgblack@eecs.umich.edu#include <string> 426735Sgblack@eecs.umich.edu 4310037SARM gem5 Developers#include "base/misc.hh" 4410037SARM gem5 Developers#include "base/trace.hh" 456019Shines@cs.fsu.edu#include "dev/disk_image.hh" 466019Shines@cs.fsu.edu#include "dev/simple_disk.hh" 476019Shines@cs.fsu.edu#include "mem/port.hh" 486019Shines@cs.fsu.edu#include "params/SimpleDisk.hh" 496019Shines@cs.fsu.edu#include "sim/system.hh" 507362Sgblack@eecs.umich.edu 5110037SARM gem5 Developersusing namespace std; 526735Sgblack@eecs.umich.edu 538229Snate@binkert.orgSimpleDisk::SimpleDisk(const string &name, System *sys, DiskImage *img) 546019Shines@cs.fsu.edu : SimObject(name), system(sys), image(img) 558782Sgblack@eecs.umich.edu{} 566019Shines@cs.fsu.edu 576019Shines@cs.fsu.eduSimpleDisk::~SimpleDisk() 586019Shines@cs.fsu.edu{} 596019Shines@cs.fsu.edu 606019Shines@cs.fsu.edu 616735Sgblack@eecs.umich.eduvoid 626019Shines@cs.fsu.eduSimpleDisk::read(Addr addr, baddr_t block, int count) const 637362Sgblack@eecs.umich.edu{ 646019Shines@cs.fsu.edu uint8_t *data = new uint8_t[SectorSize * count]; 656019Shines@cs.fsu.edu 6610037SARM gem5 Developers if (count & (SectorSize - 1)) 6710037SARM gem5 Developers panic("Not reading a multiple of a sector (count = %d)", count); 6810037SARM gem5 Developers 6910037SARM gem5 Developers for (int i = 0, j = 0; i < count; i += SectorSize, j++) 7010037SARM gem5 Developers image->read(data + i, block + j); 7110037SARM gem5 Developers 7210037SARM gem5 Developers system->functionalPort.writeBlob(addr, data, count); 7310037SARM gem5 Developers 7410037SARM gem5 Developers DPRINTF(SimpleDisk, "read block=%#x len=%d\n", (uint64_t)block, count); 7510037SARM gem5 Developers DDUMP(SimpleDiskData, data, count); 766735Sgblack@eecs.umich.edu 7710037SARM gem5 Developers delete data; 786735Sgblack@eecs.umich.edu} 796019Shines@cs.fsu.edu 8010037SARM gem5 Developersvoid 8110037SARM gem5 DevelopersSimpleDisk::write(Addr addr, baddr_t block, int count) 8210037SARM gem5 Developers{ 8310037SARM gem5 Developers panic("unimplemented!\n"); 8410037SARM gem5 Developers 857362Sgblack@eecs.umich.edu#if 0 8610037SARM gem5 Developers uint8_t *data = physmem->dma_addr(addr, count); 8710037SARM gem5 Developers if (!data) 8810037SARM gem5 Developers panic("dma out of range! write addr=%#x count=%d\n", addr, count); 8910037SARM gem5 Developers 9010037SARM gem5 Developers image->write(data, block, count); 9110037SARM gem5 Developers#endif 9210037SARM gem5 Developers} 9310037SARM gem5 Developers 9410037SARM gem5 DevelopersSimpleDisk * 9510037SARM gem5 DevelopersSimpleDiskParams::create() 9610037SARM gem5 Developers{ 9710037SARM gem5 Developers return new SimpleDisk(name, system, disk); 9810037SARM gem5 Developers} 9910037SARM gem5 Developers