ms_wrklst.c
1.57 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
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*
* ms_wrklst.c - Implement the worklist mechanism for the
* simulator.
*
* The worklist mechanism is designed to handle instructions
* that take multiple cycles to complete, such as floating
* point operations, or cache accesses. These instructions
* are handled by locking their destination register, and then
* scheduling their completion for the appropriate cycle.
*
* Jim Bennett
* 1993, 1994
*/
#include <stdlib.h>
#include "ms.h"
#ifndef INLINE
void Add_to_worklist(struct s_cpu_state *st, int inc,
void (*func)(void *st, void *a2),
void *argument2)
{
WorkList *wd_w, *wd_wlp;
int wd_c;
wd_w = st->free_head;
if (wd_w == NULL)
{
fprintf (stderr, "Out of work items!!\r\n");
ms_break (st, NULL, "ERR");
}
st->free_head = wd_w->next;
wd_c = st->work_cycle+(inc);
wd_wlp = st->work_tail;
if (wd_wlp == NULL)
{
wd_w->next = NULL;
st->work_head = wd_w;
st->work_tail = wd_w;
}
else if (wd_c < wd_wlp->cycle)
{
wd_wlp = st->work_head;
if (wd_c < wd_wlp->cycle)
{
wd_w->next = wd_wlp;
st->work_head = wd_w;
}
else
{
for (; wd_wlp->next->cycle < wd_c;
wd_wlp = wd_wlp->next);
wd_w->next = wd_wlp->next;
wd_wlp->next = wd_w;
}
}
else
{
wd_w->next = NULL;
wd_wlp->next = wd_w;
st->work_tail = wd_w;
}
wd_w->cycle = wd_c;
wd_w->f = func;
wd_w->arg2 = argument2;
}
#endif