system.cc revision 2036
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 *
34 */
35
36#include "base/loader/symtab.hh"
37#include "cpu/exec_context.hh"
38#include "kern/freebsd/freebsd_system.hh"
39#include "mem/functional/memory_control.hh"
40#include "mem/functional/physical.hh"
41#include "sim/builder.hh"
42#include "sim/byteswap.hh"
43#include "targetarch/vtophys.hh"
44
45#define TIMER_FREQUENCY 1193180
46
47using namespace std;
48
49FreebsdSystem::FreebsdSystem(Params *p)
50    : System(p)
51{
52    /**
53     * Any time DELAY is called just skip the function.
54     * Shouldn't we actually emulate the delay?
55     */
56    skipDelayEvent = addKernelFuncEvent<SkipFuncEvent>("DELAY");
57    skipCalibrateClocks =
58        addKernelFuncEvent<SkipCalibrateClocksEvent>("calibrate_clocks");
59}
60
61
62FreebsdSystem::~FreebsdSystem()
63{
64    delete skipDelayEvent;
65    delete skipCalibrateClocks;
66}
67
68
69void
70FreebsdSystem::doCalibrateClocks(ExecContext *xc)
71{
72    Addr ppc_vaddr = 0;
73    Addr timer_vaddr = 0;
74    Addr ppc_paddr = 0;
75    Addr timer_paddr = 0;
76
77    ppc_vaddr = (Addr)xc->regs.intRegFile[ArgumentReg1];
78    timer_vaddr = (Addr)xc->regs.intRegFile[ArgumentReg2];
79
80    ppc_paddr = vtophys(physmem, ppc_vaddr);
81    timer_paddr = vtophys(physmem, timer_vaddr);
82
83    uint8_t *ppc = physmem->dma_addr(ppc_paddr, sizeof(uint32_t));
84    uint8_t *timer = physmem->dma_addr(timer_paddr, sizeof(uint32_t));
85
86    *(uint32_t *)ppc = LittleEndianGuest::htog((uint32_t)Clock::Frequency);
87    *(uint32_t *)timer = LittleEndianGuest::htog((uint32_t)TIMER_FREQUENCY);
88}
89
90
91void
92FreebsdSystem::SkipCalibrateClocksEvent::process(ExecContext *xc)
93{
94    SkipFuncEvent::process(xc);
95    ((FreebsdSystem *)xc->system)->doCalibrateClocks(xc);
96}
97
98
99BEGIN_DECLARE_SIM_OBJECT_PARAMS(FreebsdSystem)
100
101    Param<Tick> boot_cpu_frequency;
102    SimObjectParam<MemoryController *> memctrl;
103    SimObjectParam<PhysicalMemory *> physmem;
104
105    Param<string> kernel;
106    Param<string> console;
107    Param<string> pal;
108
109    Param<string> boot_osflags;
110    Param<string> readfile;
111    Param<unsigned int> init_param;
112
113    Param<uint64_t> system_type;
114    Param<uint64_t> system_rev;
115
116    Param<bool> bin;
117    VectorParam<string> binned_fns;
118    Param<bool> bin_int;
119
120END_DECLARE_SIM_OBJECT_PARAMS(FreebsdSystem)
121
122BEGIN_INIT_SIM_OBJECT_PARAMS(FreebsdSystem)
123
124    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
125    INIT_PARAM(memctrl, "memory controller"),
126    INIT_PARAM(physmem, "phsyical memory"),
127    INIT_PARAM(kernel, "file that contains the kernel code"),
128    INIT_PARAM(console, "file that contains the console code"),
129    INIT_PARAM(pal, "file that contains palcode"),
130    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
131                    "a"),
132    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
133    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
134    INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
135    INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10),
136    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
137    INIT_PARAM(binned_fns, "functions to be broken down and binned"),
138    INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true)
139
140END_INIT_SIM_OBJECT_PARAMS(FreebsdSystem)
141
142CREATE_SIM_OBJECT(FreebsdSystem)
143{
144    System::Params *p = new System::Params;
145    p->name = getInstanceName();
146    p->boot_cpu_frequency = boot_cpu_frequency;
147    p->memctrl = memctrl;
148    p->physmem = physmem;
149    p->kernel_path = kernel;
150    p->console_path = console;
151    p->palcode = pal;
152    p->boot_osflags = boot_osflags;
153    p->init_param = init_param;
154    p->readfile = readfile;
155    p->system_type = system_type;
156    p->system_rev = system_rev;
157    p->bin = bin;
158    p->binned_fns = binned_fns;
159    p->bin_int = bin_int;
160    return new FreebsdSystem(p);
161}
162
163REGISTER_SIM_OBJECT("FreebsdSystem", FreebsdSystem)
164
165