system.cc revision 1835
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @file
31 * Modifications for the FreeBSD kernel.
32 * Based on kern/linux/linux_system.cc.
33 * Currently only used to skip DELAY function.
34 *
35 */
36
37#include "base/loader/symtab.hh"
38#include "cpu/exec_context.hh"
39#include "kern/freebsd/freebsd_system.hh"
40#include "mem/functional/memory_control.hh"
41#include "mem/functional/physical.hh"
42#include "sim/builder.hh"
43#include "targetarch/vtophys.hh"
44
45using namespace std;
46
47FreebsdSystem::FreebsdSystem(Params *p)
48    : System(p)
49{
50    Addr addr = 0;
51
52    /**
53     * Any time DELAY is called just skip the function.
54     * Replace calibrate_clocks with function below.
55     */
56    skipDelayEvent = new SkipFuncEvent(&pcEventQueue, "DELAY");
57    if (kernelSymtab->findAddress("DELAY", addr))
58        skipDelayEvent->schedule(addr+sizeof(MachInst));
59
60    skipCalibrateClocks = new FreebsdSkipCalibrateClocksEvent(&pcEventQueue, "calibrate_clocks");
61    if (kernelSymtab->findAddress("calibrate_clocks", addr))
62        skipCalibrateClocks->schedule(addr + sizeof(MachInst) * 2);
63
64}
65
66
67FreebsdSystem::~FreebsdSystem()
68{
69    delete skipDelayEvent;
70    delete skipCalibrateClocks;
71}
72
73
74void
75FreebsdSystem::doCalibrateClocks(ExecContext *xc)
76{
77    Addr ppc_vaddr = 0;
78    Addr timer_vaddr = 0;
79    Addr ppc_paddr = 0;
80    Addr timer_paddr = 0;
81
82    ppc_vaddr = (Addr)xc->regs.intRegFile[ArgumentReg1];
83    timer_vaddr = (Addr)xc->regs.intRegFile[ArgumentReg2];
84
85    ppc_paddr = vtophys(physmem, ppc_vaddr);
86    timer_paddr = vtophys(physmem, timer_vaddr);
87
88    uint8_t *ppc = physmem->dma_addr(ppc_paddr, sizeof(uint32_t));
89    uint8_t *timer = physmem->dma_addr(timer_paddr, sizeof(uint32_t));
90
91    *(uint32_t *)ppc = 2000000000;
92    *(uint32_t *)timer = 1193180;
93}
94
95
96BEGIN_DECLARE_SIM_OBJECT_PARAMS(FreebsdSystem)
97
98    Param<Tick> boot_cpu_frequency;
99    SimObjectParam<MemoryController *> memctrl;
100    SimObjectParam<PhysicalMemory *> physmem;
101
102    Param<string> kernel;
103    Param<string> console;
104    Param<string> pal;
105
106    Param<string> boot_osflags;
107    Param<string> readfile;
108    Param<unsigned int> init_param;
109
110    Param<uint64_t> system_type;
111    Param<uint64_t> system_rev;
112
113    Param<bool> bin;
114    VectorParam<string> binned_fns;
115    Param<bool> bin_int;
116
117END_DECLARE_SIM_OBJECT_PARAMS(FreebsdSystem)
118
119BEGIN_INIT_SIM_OBJECT_PARAMS(FreebsdSystem)
120
121    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
122    INIT_PARAM(memctrl, "memory controller"),
123    INIT_PARAM(physmem, "phsyical memory"),
124    INIT_PARAM(kernel, "file that contains the kernel code"),
125    INIT_PARAM(console, "file that contains the console code"),
126    INIT_PARAM(pal, "file that contains palcode"),
127    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
128                    "a"),
129    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
130    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
131    INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
132    INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10),
133    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
134    INIT_PARAM(binned_fns, "functions to be broken down and binned"),
135    INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true)
136
137END_INIT_SIM_OBJECT_PARAMS(FreebsdSystem)
138
139CREATE_SIM_OBJECT(FreebsdSystem)
140{
141    System::Params *p = new System::Params;
142    p->name = getInstanceName();
143    p->boot_cpu_frequency = boot_cpu_frequency;
144    p->memctrl = memctrl;
145    p->physmem = physmem;
146    p->kernel_path = kernel;
147    p->console_path = console;
148    p->palcode = pal;
149    p->boot_osflags = boot_osflags;
150    p->init_param = init_param;
151    p->readfile = readfile;
152    p->system_type = system_type;
153    p->system_rev = system_rev;
154    p->bin = bin;
155    p->binned_fns = binned_fns;
156    p->bin_int = bin_int;
157    return new FreebsdSystem(p);
158}
159
160REGISTER_SIM_OBJECT("FreebsdSystem", FreebsdSystem)
161
162