gamma_aint.c
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright (C) 1998 by the Board of Trustees
* of Leland Stanford Junior University.
* Copyright (C) 1998 Digital Equipment Corporation
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
#include <setjmp.h>
#include <alpha/inst.h>
#include <alpha/pal.h>
#include "simtypes.h"
#include "sim_error.h"
#include "gamma.h"
#include "thread.h"
#include "event.h"
#include "opcodes.h"
#include "globals.h"
#include "alpha_regs.h"
#include "memory.h"
#include "subst.h"
#include "header.h"
#include "mmu.h"
#include "disassembler.h"
/* #define DEBUG_PAL */
static Result GammaExitThread(AlphaState *P);
extern jmp_buf jmpEnv;
int PALOpcode(AlphaState *P, int func)
{
if (func==PAL_callsys) {
Reg oldPC = P->PC;
Reg newPC;
SyscallStatus status;
#ifdef DEBUG_PAL
CPUWarning("PAL opcode at pc=0x%lx v0=%lx a0=0x%lx \n",
P->PC,P->reg[REG_V0],P->reg[REG_A0]);
#endif
status = callsys_f(P->aintThread);
switch(status) {
case SYSCALL_NEXT:
newPC = oldPC +4;
break;
case SYSCALL_SAME:
newPC =oldPC;
break;
case SYSCALL_EXIT:
return GammaExitThread(P);
default:
newPC = 0;
ASSERT(0);
}
P->PC = newPC;
return SUCCESS;
}
ASSERT(0);
return SUCCESS;
}
static Result GammaExitThread(AlphaState *P)
{
int i,j=-1;
thread_ptr ptr = P->aintThread;
P->cpuState = cpu_halted;
ptr->runstate = R_DONE;
ptr->time = 12; /* random, bogus */
for(i=0;gammaThreads[i];i++) {
if (gammaThreads[i]==P) j = i;
}
if (i<=1) {
longjmp(jmpEnv,1);
}
ASSERT(j>=0);
if (j==i-1) {
gammaThreads[j]= 0;
} else {
gammaThreads[j] = gammaThreads[i-1];
gammaThreads[i-1] = 0;
}
return SUCCESS;
}
void GammaNewThread(thread_ptr child)
{
AlphaState *ch = &child->st;
int i;
ch->aintThread = child;
ch->cpuState = cpu_running;
for (i=0; gammaThreads[i];i++) {
}
gammaThreads[i] = ch;
#ifdef DEBUG_PAL
CPUWarning("NewThread %d at 0x%lx. thread 0 at %lx \n",
child->pid,ch->PC);
#endif
}