/[dynamips]/trunk/jit_op.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/jit_op.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (11 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 2176 byte(s)
make working copy

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2007 Christophe Fillot (cf@utc.fr)
4 *
5 * JIT operations.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <sys/mman.h>
15 #include <signal.h>
16 #include <fcntl.h>
17 #include <assert.h>
18
19 #include "cpu.h"
20 #include "jit_op.h"
21
22 u_int jit_op_blk_sizes[JIT_OP_POOL_NR] = {
23 0, 32, 64, 128, 256, 384, 512, 1024,
24 };
25
26 /* Get a JIT op (allocate one if necessary) */
27 jit_op_t *jit_op_get(cpu_gen_t *cpu,int size_index,u_int opcode)
28 {
29 jit_op_t *op;
30 size_t len;
31
32 assert(size_index < JIT_OP_POOL_NR);
33 op = cpu->jit_op_pool[size_index];
34
35 if (op != NULL) {
36 assert(op->ob_size_index == size_index);
37 cpu->jit_op_pool[size_index] = op->next;
38 } else {
39 /* no block found, allocate one */
40 len = sizeof(*op) + jit_op_blk_sizes[size_index];
41
42 op = malloc(len);
43 assert(op != NULL);
44 op->ob_size_index = size_index;
45 }
46
47 op->opcode = opcode;
48 op->param[0] = op->param[1] = op->param[2] = -1;
49 op->next = NULL;
50 op->ob_ptr = op->ob_data;
51 op->arg_ptr = NULL;
52 op->insn_name = NULL;
53 return op;
54 }
55
56 /* Release a JIT op */
57 void jit_op_free(cpu_gen_t *cpu,jit_op_t *op)
58 {
59 assert(op->ob_size_index < JIT_OP_POOL_NR);
60 op->next = cpu->jit_op_pool[op->ob_size_index];
61 cpu->jit_op_pool[op->ob_size_index] = op;
62 }
63
64 /* Free a list of JIT ops */
65 void jit_op_free_list(cpu_gen_t *cpu,jit_op_t *op_list)
66 {
67 jit_op_t *op,*opn;
68
69 for(op=op_list;op;op=opn) {
70 opn = op->next;
71 jit_op_free(cpu,op);
72 }
73 }
74
75 /* Initialize JIT op pools for the specified CPU */
76 int jit_op_init_cpu(cpu_gen_t *cpu)
77 {
78 cpu->jit_op_array = calloc(cpu->jit_op_array_size,sizeof(jit_op_t *));
79
80 if (!cpu->jit_op_array)
81 return(-1);
82
83 memset(cpu->jit_op_pool,0,sizeof(cpu->jit_op_pool));
84 return(0);
85 }
86
87 /* Free memory used by pools */
88 void jit_op_free_pools(cpu_gen_t *cpu)
89 {
90 jit_op_t *op,*opn;
91 int i;
92
93 for(i=0;i<JIT_OP_POOL_NR;i++) {
94 for(op=cpu->jit_op_pool[i];op;op=opn) {
95 opn = op->next;
96 free(op);
97 }
98
99 cpu->jit_op_pool[i] = NULL;
100 }
101 }

  ViewVC Help
Powered by ViewVC 1.1.26