Merge ARM into the head. ARM will compile but may not actually work.
[gem5.git] / src / cpu / cpuevent.hh
1 /*
2 * Copyright (c) 2006 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 * Authors: Ali Saidi
29 */
30
31 #ifndef __CPU_CPUEVENT_HH__
32 #define __CPU_CPUEVENT_HH__
33
34 #include <vector>
35 #include "sim/eventq.hh"
36
37 class ThreadContext;
38
39 /**
40 * This class creates a global list of events that need a pointer to a
41 * thread context. When a switchover takes place the events can be
42 * migrated to the new thread context, otherwise you could have a wake
43 * timer interrupt go off on a switched out cpu or other unfortunate
44 * events. This object MUST be dynamically allocated to avoid it being
45 * deleted after a cpu switch happens.
46 */
47 class CpuEvent : public Event
48 {
49 protected:
50 /** type of global list of cpu events. */
51 typedef std::vector<CpuEvent *> CpuEventList;
52
53 /** Static list of cpu events that is searched every time a cpu switch
54 * happens. */
55 static CpuEventList cpuEventList;
56
57 /** The thread context that is switched to the new cpus. */
58 ThreadContext *tc;
59
60 public:
61 CpuEvent(ThreadContext *_tc, Priority p = Default_Pri)
62 : Event(p), tc(_tc)
63 { cpuEventList.push_back(this); }
64
65 /** delete the cpu event from the global list. */
66 ~CpuEvent();
67
68 /** Update all events switching old tc to new tc.
69 * @param oldTc the old thread context we are switching from
70 * @param newTc the new thread context we are switching to.
71 */
72 static void replaceThreadContext(ThreadContext *oldTc,
73 ThreadContext *newTc);
74 ThreadContext* getTC() { return tc; }
75 };
76
77 template <class T, void (T::* F)(ThreadContext *tc)>
78 class CpuEventWrapper : public CpuEvent
79 {
80 private:
81 T *object;
82
83 public:
84 CpuEventWrapper(T *obj, ThreadContext *_tc, Priority p = Default_Pri)
85 : CpuEvent(_tc, p), object(obj)
86 { }
87 void process() { (object->*F)(tc); }
88 };
89
90 #endif // __CPU_CPUEVENT_HH__
91