system.cc revision 9261:f795ce1feb5b
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 */
42
43#include "arch/arm/linux/atag.hh"
44#include "arch/arm/linux/system.hh"
45#include "arch/arm/isa_traits.hh"
46#include "arch/arm/utility.hh"
47#include "base/loader/object_file.hh"
48#include "base/loader/symtab.hh"
49#include "cpu/thread_context.hh"
50#include "debug/Loader.hh"
51#include "kern/linux/events.hh"
52#include "mem/fs_translating_port_proxy.hh"
53#include "mem/physical.hh"
54
55using namespace ArmISA;
56using namespace Linux;
57
58LinuxArmSystem::LinuxArmSystem(Params *p)
59    : ArmSystem(p)
60{
61#ifndef NDEBUG
62    kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic");
63    if (!kernelPanicEvent)
64        panic("could not find kernel symbol \'panic\'");
65#endif
66
67    // With ARM udelay() is #defined to __udelay
68    Addr addr = 0;
69    if (kernelSymtab->findAddress("__udelay", addr)) {
70        uDelaySkipEvent = new UDelayEvent(&pcEventQueue, "__udelay",
71                fixFuncEventAddr(addr), 1000, 0);
72    } else {
73        panic("couldn't find kernel symbol \'udelay\'");
74    }
75
76    // constant arguments to udelay() have some precomputation done ahead of
77    // time. Constant comes from code.
78    if (kernelSymtab->findAddress("__const_udelay", addr)) {
79        constUDelaySkipEvent = new UDelayEvent(&pcEventQueue, "__const_udelay",
80                fixFuncEventAddr(addr), 1000, 107374);
81    } else {
82        panic("couldn't find kernel symbol \'udelay\'");
83    }
84
85    secDataPtrAddr = 0;
86    secDataAddr = 0;
87    penReleaseAddr = 0;
88    kernelSymtab->findAddress("__secondary_data", secDataPtrAddr);
89    kernelSymtab->findAddress("secondary_data", secDataAddr);
90    kernelSymtab->findAddress("pen_release", penReleaseAddr);
91
92    secDataPtrAddr &= ~ULL(0x7F);
93    secDataAddr &= ~ULL(0x7F);
94    penReleaseAddr &= ~ULL(0x7F);
95}
96
97bool
98LinuxArmSystem::adderBootUncacheable(Addr a)
99{
100    Addr block = a & ~ULL(0x7F);
101    if (block == secDataPtrAddr || block == secDataAddr ||
102            block == penReleaseAddr)
103        return true;
104    return false;
105}
106
107void
108LinuxArmSystem::initState()
109{
110    // Moved from the constructor to here since it relies on the
111    // address map being resolved in the interconnect
112
113    // Call the initialisation of the super class
114    ArmSystem::initState();
115
116    // Load symbols at physical address, we might not want
117    // to do this permanently, for but early bootup work
118    // it is helpful.
119    if (params()->early_kernel_symbols) {
120        kernel->loadGlobalSymbols(kernelSymtab, loadAddrMask);
121        kernel->loadGlobalSymbols(debugSymbolTable, loadAddrMask);
122    }
123
124    // Setup boot data structure
125    Addr addr = 0;
126    // Check if the kernel image has a symbol that tells us it supports
127    // device trees.
128    bool kernel_has_fdt_support =
129        kernelSymtab->findAddress("unflatten_device_tree", addr);
130    bool dtb_file_specified = params()->dtb_filename != "";
131
132    if (kernel_has_fdt_support && dtb_file_specified) {
133        // Kernel supports flattened device tree and dtb file specified.
134        // Using Device Tree Blob to describe system configuration.
135        inform("Loading DTB file: %s\n", params()->dtb_filename);
136
137        ObjectFile *dtb_file = createObjectFile(params()->dtb_filename, true);
138        if (!dtb_file) {
139            fatal("couldn't load DTB file: %s\n", params()->dtb_filename);
140        }
141        dtb_file->setTextBase(params()->atags_addr);
142        dtb_file->loadSections(physProxy);
143        delete dtb_file;
144    } else {
145        // Using ATAGS
146        // Warn if the kernel supports FDT and we haven't specified one
147        if (kernel_has_fdt_support) {
148            assert(!dtb_file_specified);
149            warn("Kernel supports device tree, but no DTB file specified\n");
150        }
151        // Warn if the kernel doesn't support FDT and we have specified one
152        if (dtb_file_specified) {
153            assert(!kernel_has_fdt_support);
154            warn("DTB file specified, but no device tree support in kernel\n");
155        }
156
157        AtagCore *ac = new AtagCore;
158        ac->flags(1); // read-only
159        ac->pagesize(8192);
160        ac->rootdev(0);
161
162        AddrRangeList atagRanges = physmem.getConfAddrRanges();
163        if (atagRanges.size() != 1) {
164            fatal("Expected a single ATAG memory entry but got %d\n",
165                  atagRanges.size());
166        }
167        AtagMem *am = new AtagMem;
168        am->memSize(atagRanges.begin()->size());
169        am->memStart(atagRanges.begin()->start);
170
171        AtagCmdline *ad = new AtagCmdline;
172        ad->cmdline(params()->boot_osflags);
173
174        DPRINTF(Loader, "boot command line %d bytes: %s\n", ad->size() <<2, params()->boot_osflags.c_str());
175
176        AtagNone *an = new AtagNone;
177
178        uint32_t size = ac->size() + am->size() + ad->size() + an->size();
179        uint32_t offset = 0;
180        uint8_t *boot_data = new uint8_t[size << 2];
181
182        offset += ac->copyOut(boot_data + offset);
183        offset += am->copyOut(boot_data + offset);
184        offset += ad->copyOut(boot_data + offset);
185        offset += an->copyOut(boot_data + offset);
186
187        DPRINTF(Loader, "Boot atags was %d bytes in total\n", size << 2);
188        DDUMP(Loader, boot_data, size << 2);
189
190        physProxy.writeBlob(params()->atags_addr, boot_data, size << 2);
191    }
192
193    for (int i = 0; i < threadContexts.size(); i++) {
194        threadContexts[i]->setIntReg(0, 0);
195        threadContexts[i]->setIntReg(1, params()->machine_type);
196        threadContexts[i]->setIntReg(2, params()->atags_addr);
197    }
198}
199
200LinuxArmSystem::~LinuxArmSystem()
201{
202    if (uDelaySkipEvent)
203        delete uDelaySkipEvent;
204    if (constUDelaySkipEvent)
205        delete constUDelaySkipEvent;
206}
207
208LinuxArmSystem *
209LinuxArmSystemParams::create()
210{
211    return new LinuxArmSystem(this);
212}
213