process.cc (2665:a124942bacb8) process.cc (2680:246e7104f744)
1/*
2 * Copyright (c) 2001-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;

--- 26 unchanged lines hidden (view full) ---

35
36#include <string>
37
38#include "base/intmath.hh"
39#include "base/loader/object_file.hh"
40#include "base/loader/symtab.hh"
41#include "base/statistics.hh"
42#include "config/full_system.hh"
1/*
2 * Copyright (c) 2001-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;

--- 26 unchanged lines hidden (view full) ---

35
36#include <string>
37
38#include "base/intmath.hh"
39#include "base/loader/object_file.hh"
40#include "base/loader/symtab.hh"
41#include "base/statistics.hh"
42#include "config/full_system.hh"
43#include "cpu/exec_context.hh"
43#include "cpu/thread_context.hh"
44#include "mem/page_table.hh"
45#include "mem/physical.hh"
46#include "mem/translating_port.hh"
47#include "sim/builder.hh"
48#include "sim/process.hh"
49#include "sim/stats.hh"
50#include "sim/syscall_emul.hh"
51#include "sim/system.hh"

--- 77 unchanged lines hidden (view full) ---

129 fatal("can't open output file");
130 }
131
132 return fd;
133}
134
135
136int
44#include "mem/page_table.hh"
45#include "mem/physical.hh"
46#include "mem/translating_port.hh"
47#include "sim/builder.hh"
48#include "sim/process.hh"
49#include "sim/stats.hh"
50#include "sim/syscall_emul.hh"
51#include "sim/system.hh"

--- 77 unchanged lines hidden (view full) ---

129 fatal("can't open output file");
130 }
131
132 return fd;
133}
134
135
136int
137Process::registerExecContext(ExecContext *xc)
137Process::registerThreadContext(ThreadContext *tc)
138{
139 // add to list
138{
139 // add to list
140 int myIndex = execContexts.size();
141 execContexts.push_back(xc);
140 int myIndex = threadContexts.size();
141 threadContexts.push_back(tc);
142
143 // return CPU number to caller
144 return myIndex;
145}
146
147void
148Process::startup()
149{
142
143 // return CPU number to caller
144 return myIndex;
145}
146
147void
148Process::startup()
149{
150 if (execContexts.empty())
150 if (threadContexts.empty())
151 fatal("Process %s is not associated with any CPUs!\n", name());
152
151 fatal("Process %s is not associated with any CPUs!\n", name());
152
153 // first exec context for this process... initialize & enable
154 ExecContext *xc = execContexts[0];
153 // first thread context for this process... initialize & enable
154 ThreadContext *tc = threadContexts[0];
155
156 // mark this context as active so it will start ticking.
155
156 // mark this context as active so it will start ticking.
157 xc->activate(0);
157 tc->activate(0);
158
159 Port *mem_port;
160 mem_port = system->physmem->getPort("functional");
161 initVirtMem = new TranslatingPort("process init port", pTable, true);
162 mem_port->setPeer(initVirtMem);
163 initVirtMem->setPeer(mem_port);
164}
165
166void
158
159 Port *mem_port;
160 mem_port = system->physmem->getPort("functional");
161 initVirtMem = new TranslatingPort("process init port", pTable, true);
162 mem_port->setPeer(initVirtMem);
163 initVirtMem->setPeer(mem_port);
164}
165
166void
167Process::replaceExecContext(ExecContext *xc, int xcIndex)
167Process::replaceThreadContext(ThreadContext *tc, int tcIndex)
168{
168{
169 if (xcIndex >= execContexts.size()) {
170 panic("replaceExecContext: bad xcIndex, %d >= %d\n",
171 xcIndex, execContexts.size());
169 if (tcIndex >= threadContexts.size()) {
170 panic("replaceThreadContext: bad tcIndex, %d >= %d\n",
171 tcIndex, threadContexts.size());
172 }
173
172 }
173
174 execContexts[xcIndex] = xc;
174 threadContexts[tcIndex] = tc;
175}
176
177// map simulator fd sim_fd to target fd tgt_fd
178void
179Process::dup_fd(int sim_fd, int tgt_fd)
180{
181 if (tgt_fd < 0 || tgt_fd > MAX_FD)
182 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd);

--- 150 unchanged lines hidden (view full) ---

333 else
334 panic("Unknown int size");
335
336 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
337
338 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
339 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
340
175}
176
177// map simulator fd sim_fd to target fd tgt_fd
178void
179Process::dup_fd(int sim_fd, int tgt_fd)
180{
181 if (tgt_fd < 0 || tgt_fd > MAX_FD)
182 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd);

--- 150 unchanged lines hidden (view full) ---

333 else
334 panic("Unknown int size");
335
336 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
337
338 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
339 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
340
341 execContexts[0]->setIntReg(ArgumentReg0, argc);
342 execContexts[0]->setIntReg(ArgumentReg1, argv_array_base);
343 execContexts[0]->setIntReg(StackPointerReg, stack_min);
341 threadContexts[0]->setIntReg(ArgumentReg0, argc);
342 threadContexts[0]->setIntReg(ArgumentReg1, argv_array_base);
343 threadContexts[0]->setIntReg(StackPointerReg, stack_min);
344
345 Addr prog_entry = objFile->entryPoint();
344
345 Addr prog_entry = objFile->entryPoint();
346 execContexts[0]->setPC(prog_entry);
347 execContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
348 execContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
346 threadContexts[0]->setPC(prog_entry);
347 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
348 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
349
350 num_processes++;
351}
352
353void
349
350 num_processes++;
351}
352
353void
354LiveProcess::syscall(int64_t callnum, ExecContext *xc)
354LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
355{
356 num_syscalls++;
357
358 SyscallDesc *desc = getDesc(callnum);
359 if (desc == NULL)
360 fatal("Syscall %d out of range", callnum);
361
355{
356 num_syscalls++;
357
358 SyscallDesc *desc = getDesc(callnum);
359 if (desc == NULL)
360 fatal("Syscall %d out of range", callnum);
361
362 desc->doSyscall(callnum, this, xc);
362 desc->doSyscall(callnum, this, tc);
363}
364
365DEFINE_SIM_OBJECT_CLASS_NAME("LiveProcess", LiveProcess);
363}
364
365DEFINE_SIM_OBJECT_CLASS_NAME("LiveProcess", LiveProcess);