X86: Get rid of the unused getAllocator on the python base microop class.
[gem5.git] / src / arch / alpha / linux / threadinfo.hh
1 /*
2 * Copyright (c) 2004 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 * Nathan Binkert
30 */
31
32 #ifndef __ARCH_ALPHA_LINUX_LINUX_TREADNIFO_HH__
33 #define __ARCH_ALPHA_LINUX_LINUX_TREADNIFO_HH__
34
35 #include "cpu/thread_context.hh"
36 #include "sim/system.hh"
37 #include "sim/vptr.hh"
38
39 namespace Linux {
40
41 class ThreadInfo
42 {
43 private:
44 ThreadContext *tc;
45 System *sys;
46 Addr pcbb;
47
48 template <typename T>
49 bool
50 get_data(const char *symbol, T &data)
51 {
52 Addr addr = 0;
53 if (!sys->kernelSymtab->findAddress(symbol, addr))
54 return false;
55
56 CopyOut(tc, &data, addr, sizeof(T));
57
58 data = AlphaISA::gtoh(data);
59
60 return true;
61 }
62
63 public:
64 ThreadInfo(ThreadContext *_tc, Addr _pcbb = 0)
65 : tc(_tc), sys(tc->getSystemPtr()), pcbb(_pcbb)
66 {
67
68 }
69 ~ThreadInfo()
70 {}
71
72 inline Addr
73 curThreadInfo()
74 {
75 Addr addr = pcbb;
76 Addr sp;
77
78 if (!addr)
79 addr = tc->readMiscRegNoEffect(AlphaISA::IPR_PALtemp23);
80
81 FunctionalPort *p = tc->getPhysPort();
82 p->readBlob(addr, (uint8_t *)&sp, sizeof(Addr));
83
84 return sp & ~ULL(0x3fff);
85 }
86
87 inline Addr
88 curTaskInfo(Addr thread_info = 0)
89 {
90 int32_t offset;
91 if (!get_data("thread_info_task", offset))
92 return 0;
93
94 if (!thread_info)
95 thread_info = curThreadInfo();
96
97 Addr addr;
98 CopyOut(tc, &addr, thread_info + offset, sizeof(addr));
99
100 return addr;
101 }
102
103 int32_t
104 curTaskPID(Addr thread_info = 0)
105 {
106 Addr offset;
107 if (!get_data("task_struct_pid", offset))
108 return -1;
109
110 int32_t pid;
111 CopyOut(tc, &pid, curTaskInfo(thread_info) + offset, sizeof(pid));
112
113 return pid;
114 }
115
116 int64_t
117 curTaskStart(Addr thread_info = 0)
118 {
119 Addr offset;
120 if (!get_data("task_struct_start_time", offset))
121 return -1;
122
123 int64_t data;
124 // start_time is actually of type timespec, but if we just
125 // grab the first long, we'll get the seconds out of it
126 CopyOut(tc, &data, curTaskInfo(thread_info) + offset, sizeof(data));
127
128 return data;
129 }
130
131 std::string
132 curTaskName(Addr thread_info = 0)
133 {
134 int32_t offset;
135 int32_t size;
136
137 if (!get_data("task_struct_comm", offset))
138 return "FailureIn_curTaskName";
139
140 if (!get_data("task_struct_comm_size", size))
141 return "FailureIn_curTaskName";
142
143 char buffer[size + 1];
144 CopyStringOut(tc, buffer, curTaskInfo(thread_info) + offset, size);
145
146 return buffer;
147 }
148 };
149
150 } // namespace Linux
151
152 #endif // __ARCH_ALPHA_LINUX_LINUX_THREADINFO_HH__