e820.cc revision 11793
17110Sgblack@eecs.umich.edu/*
27110Sgblack@eecs.umich.edu * Copyright (c) 2008 The Hewlett-Packard Development Company
37110Sgblack@eecs.umich.edu * All rights reserved.
47110Sgblack@eecs.umich.edu *
57110Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67110Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77110Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87110Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97110Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107110Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117110Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127110Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137110Sgblack@eecs.umich.edu *
147110Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
156253Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
166253Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
176253Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
186253Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
196253Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
206253Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
216253Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
226253Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
236253Sgblack@eecs.umich.edu * this software without specific prior written permission.
246253Sgblack@eecs.umich.edu *
256253Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
266253Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
276253Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
286253Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
296253Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
306253Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
316253Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326253Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
336253Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
346253Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
356253Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
366253Sgblack@eecs.umich.edu *
376253Sgblack@eecs.umich.edu * Authors: Gabe Black
386253Sgblack@eecs.umich.edu */
396253Sgblack@eecs.umich.edu
406253Sgblack@eecs.umich.edu#include "arch/x86/bios/e820.hh"
416253Sgblack@eecs.umich.edu
426253Sgblack@eecs.umich.edu#include "arch/x86/isa_traits.hh"
436253Sgblack@eecs.umich.edu#include "mem/port_proxy.hh"
446253Sgblack@eecs.umich.edu#include "sim/byteswap.hh"
456253Sgblack@eecs.umich.edu
466253Sgblack@eecs.umich.eduusing namespace std;
476253Sgblack@eecs.umich.eduusing namespace X86ISA;
486306Sgblack@eecs.umich.edu
496253Sgblack@eecs.umich.edutemplate<class T>
506253Sgblack@eecs.umich.eduvoid writeVal(T val, PortProxy& proxy, Addr &addr)
517142Sgblack@eecs.umich.edu{
527142Sgblack@eecs.umich.edu    T guestVal = htog(val);
537142Sgblack@eecs.umich.edu    proxy.writeBlob(addr, (uint8_t *)&guestVal, sizeof(T));
547142Sgblack@eecs.umich.edu    addr += sizeof(T);
557142Sgblack@eecs.umich.edu}
567142Sgblack@eecs.umich.edu
577142Sgblack@eecs.umich.eduvoid X86ISA::E820Table::writeTo(PortProxy& proxy, Addr countAddr, Addr addr)
587142Sgblack@eecs.umich.edu{
597142Sgblack@eecs.umich.edu    uint8_t e820Nr = entries.size();
607142Sgblack@eecs.umich.edu
616306Sgblack@eecs.umich.edu    // Make sure the number of entries isn't bigger than what the kernel
626306Sgblack@eecs.umich.edu    // would be capable of handling.
636306Sgblack@eecs.umich.edu    assert(e820Nr <= 128);
646306Sgblack@eecs.umich.edu
657110Sgblack@eecs.umich.edu    uint8_t guestE820Nr = htog(e820Nr);
666306Sgblack@eecs.umich.edu
676306Sgblack@eecs.umich.edu    proxy.writeBlob(countAddr, (uint8_t *)&guestE820Nr, sizeof(guestE820Nr));
687142Sgblack@eecs.umich.edu
697142Sgblack@eecs.umich.edu    for (int i = 0; i < e820Nr; i++) {
707142Sgblack@eecs.umich.edu        writeVal(entries[i]->addr, proxy, addr);
717142Sgblack@eecs.umich.edu        writeVal(entries[i]->size, proxy, addr);
727142Sgblack@eecs.umich.edu        writeVal(entries[i]->type, proxy, addr);
737142Sgblack@eecs.umich.edu    }
747142Sgblack@eecs.umich.edu}
757142Sgblack@eecs.umich.edu
767142Sgblack@eecs.umich.eduE820Table *
777142Sgblack@eecs.umich.eduX86E820TableParams::create()
787142Sgblack@eecs.umich.edu{
797142Sgblack@eecs.umich.edu    return new E820Table(this);
807142Sgblack@eecs.umich.edu}
817142Sgblack@eecs.umich.edu
827142Sgblack@eecs.umich.eduE820Entry *
837142Sgblack@eecs.umich.eduX86E820EntryParams::create()
847142Sgblack@eecs.umich.edu{
857142Sgblack@eecs.umich.edu    return new E820Entry(this);
867142Sgblack@eecs.umich.edu}
877142Sgblack@eecs.umich.edu