2 * Copyright (c) 2001 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: codes.cc,v 1.14 2003/08/01 00:58:03 steve Exp $"
24 # include "statistics.h"
29 * The code space is broken into chunks, to make for efficient
30 * allocation of large amounts. Each chunk is an array of vvp_code_s
31 * structures, with the last opcode loaded with an of_CHUNK_LINK
32 * instruction to branch to the next chunk. This handles the case
33 * where the program counter steps off the end of a chunk.
35 const unsigned code_chunk_size
= 1024;
37 static struct vvp_code_s
*first_chunk
= 0;
38 static struct vvp_code_s
*current_chunk
= 0;
39 static unsigned current_within_chunk
= 0;
42 * This initializes the code space. It sets up the first code chunk,
43 * and places at address 0 a ZOMBIE instruction.
45 void codespace_init(void)
47 assert(current_chunk
== 0);
48 first_chunk
= new struct vvp_code_s
[code_chunk_size
];
49 current_chunk
= first_chunk
;
51 current_chunk
[0].opcode
= &of_ZOMBIE
;
53 current_chunk
[code_chunk_size
-1].opcode
= &of_CHUNK_LINK
;
54 current_chunk
[code_chunk_size
-1].cptr
= 0;
56 current_within_chunk
= 1;
59 size_opcodes
+= code_chunk_size
* sizeof (struct vvp_code_s
);
62 vvp_code_t
codespace_next(void)
64 if (current_within_chunk
== (code_chunk_size
-1)) {
65 current_chunk
[code_chunk_size
-1].cptr
66 = new struct vvp_code_s
[code_chunk_size
];
67 current_chunk
= current_chunk
[code_chunk_size
-1].cptr
;
69 /* Put a link opcode on the end of the chunk. */
70 current_chunk
[code_chunk_size
-1].opcode
= &of_CHUNK_LINK
;
71 current_chunk
[code_chunk_size
-1].cptr
= 0;
73 current_within_chunk
= 0;
75 size_opcodes
+= code_chunk_size
* sizeof (struct vvp_code_s
);
78 vvp_code_t res
= current_chunk
+ current_within_chunk
;
82 vvp_code_t
codespace_allocate(void)
84 vvp_code_t res
= codespace_next();
85 current_within_chunk
+= 1;
88 memset(res
, 0, sizeof(*res
));
93 vvp_code_t
codespace_null(void)
95 return first_chunk
+ 0;
100 * Revision 1.14 2003/08/01 00:58:03 steve
101 * Initialize allocated memory.
103 * Revision 1.13 2003/07/03 20:03:36 steve
104 * Remove the vvp_cpoint_t indirect code pointer.
106 * Revision 1.12 2002/08/12 01:35:07 steve
107 * conditional ident string using autoconfig.
109 * Revision 1.11 2002/07/05 03:46:43 steve
110 * Track opcode memory space.
112 * Revision 1.10 2002/07/05 02:50:58 steve
113 * Remove the vpi object symbol table after compile.