1 /***************************************************************************** 2 Copyright (C) 1987-2015 by Jeffery P. Hansen 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 18 Last edit by hansen on Thu Jan 29 10:04:52 2009 19 ****************************************************************************/ 20 #ifndef __bytecode_h 21 #define __bytecode_h 22 23 /***************************************************************************** 24 * 25 * This file implements the simulation byte code classes. The basic byte code 26 * oepration is handled by the ByteCode object. A sequence of instructions is 27 * stored in an array in which instructions are executed ni sequence. Each 28 * thread is handled by a VGThread object which contains the current thread 29 * state. At any given time there may be a number of active threads and one 30 * current thread. Execution on the current thread continues until it is 31 * suspended for some reason either by executing an event wait or a delay. 32 * At that time the next ative thread is invoked until it is suspened and so 33 * on. When there are no longer any active threads, simulation time is 34 * advanced until more threads can become active. 35 * 36 * List of ByteCode instructions: 37 * 38 * BCOpr Execute an operation on Values. 39 * BCCopy Copy a Value to another Value 40 * BCCopyRange Copy a range of a Value to another Value 41 * BCMemFetch Fetch a value from a memory 42 * BCMemPut Put a value into a memory 43 * BCNbMemPut Non-blocking store of value into a memory 44 * BCRaise Raise an event 45 * BCAsgn Assign a Value to a Net 46 * BCNbAsgnD Non-blocking assign a Value to a reg Net after delay 47 * BCNbAsgnE Non-blocking assign a Value to a reg Net after event 48 * BCWireAsgnD Non-blocking assign a Value to a wire Net after delay 49 * BCEnd End the current thread 50 * BCNoop Do a No-op 51 * BCGoto Conditional or unconditional jump to a new address 52 * BCTask Execute a system task 53 * BCDelay Suspend task and schedule wake up time 54 * BCTrigger Suspend task and wait for a triggering event 55 * BCSpawn Spawn a new bytecode task 56 * BCLock Begin a critical section (wait for reg=0, then set reg=1) 57 * BCWait Wait for child tasks to complete 58 * BCSubr Jump to a subroutine 59 * BCReturn Return from a subroutine 60 * BCDebugPrint Print a string for debugging purposes 61 * 62 *****************************************************************************/ 63 64 #define BCODE_BLOCKSIZE 64 65 66 /***************************************************************************** 67 * 68 * Thread states 69 * 70 *****************************************************************************/ 71 typedef enum { 72 TS_ACTIVE = 0x0, /**< Thread is actively executing */ 73 #define TS_ACTIVE TS_ACTIVE 74 TS_BLOCKED = 0x1, /**< Thread is blocked waiting for event */ 75 #define TS_BLOCKED TS_BLOCKED 76 TS_DISABLED = 0x2, /**< Thread is disabled */ 77 #define TS_DISABLED TS_DISABLED 78 } VGThreadState; 79 80 /***************************************************************************** 81 * 82 * VGFrame - Represents a stack frame for a thread. 83 * 84 *****************************************************************************/ 85 typedef struct VGFrame_str VGFrame; 86 struct VGFrame_str { 87 ByteCode *f_pc; /* Instruction to which to return */ 88 VGFrame *f_next; /* Next address on stack */ 89 }; 90 91 /***************************************************************************** 92 * 93 * VGThread - Thread state 94 * 95 *****************************************************************************/ 96 struct VGThread_str { 97 Event *t_pending; /* Pointer to event if pending, null otherwise */ 98 VGThreadState t_state; /* State of the thread (active, blocked, paused, etc.) */ 99 int t_isLive; /* Non-zero if this thread is live */ 100 int t_wait; /* Suspend until this many threads end */ 101 CodeBlock *t_start_block; /* CodeBlock to use for starting thread */ 102 unsigned t_start_pc; /* Offset into starting thread for PC */ 103 ByteCode *t_pc; /* Thread program counter */ 104 ModuleInst *t_modCtx; /* Module context in which thread was initiated */ 105 ModuleItem *t_mitem; /* Module item of thead (if applicable) */ 106 int t_numChild; /* Number of running child tasks */ 107 VGThread *t_parent; /* Parent task */ 108 VGThread *t_next; /* Next pointer when we are in the active queue */ 109 VGFrame *t_callStack; /* Call stack for any calls to user tasks/functions */ 110 }; 111 112 /***************************************************************************** 113 * 114 * BCOpr - Do a basic 1 to 3 operand operation 115 * 116 *****************************************************************************/ 117 typedef struct { 118 BCfunc *o_func; /* Function for */ 119 valueop_f *o_op; /* Operation function */ 120 Value *o_dest; /* Destination state */ 121 Value *o_opr[3]; /* Operand states */ 122 } BCOpr; 123 124 /***************************************************************************** 125 * 126 * BCMemFetch - Fetch a value from a memory 127 * 128 *****************************************************************************/ 129 typedef struct { 130 BCfunc *m_func; /* Handler function */ 131 Net *m_net; /* Net for memory */ 132 Value *m_addr; /* Address we are operating on */ 133 Value *m_data; /* Value to store/retrieve from memory */ 134 } BCMemFetch; 135 136 /***************************************************************************** 137 * 138 * BCMemPut - Put a value into memory 139 * 140 *****************************************************************************/ 141 typedef struct { 142 BCfunc *m_func; /* Handler function */ 143 Net *m_net; /* Net for memory */ 144 Value *m_addr; /* Address we are operating on */ 145 Value *m_netLsb; /* LSB on net (memory) */ 146 Value *m_data; /* Value to store/retrieve from memory */ 147 unsigned m_valLsb; /* Lsb in value */ 148 unsigned m_width; /* Width of assignment */ 149 } BCMemPut; 150 151 /***************************************************************************** 152 * 153 * BCNbMemPutD - Non-blocking store of a value into memory 154 * 155 *****************************************************************************/ 156 typedef struct { 157 BCfunc *m_func; /* Handler function */ 158 Net *m_net; /* Net for memory */ 159 Value *m_addr; /* Address we are operating on */ 160 Value *m_netLsb; /* LSB on net (memory) */ 161 Value *m_data; /* Value to store/retrieve from memory */ 162 unsigned m_valLsb; /* Lsb in value */ 163 unsigned m_width; /* Width of assignment */ 164 deltatime_t m_delay; /* Delay for assignment */ 165 } BCNbMemPutD; 166 167 /***************************************************************************** 168 * 169 * BCNbMemPutE - Non-blocking store of a value into memory 170 * 171 *****************************************************************************/ 172 typedef struct { 173 BCfunc *m_func; /* Handler function */ 174 Net *m_net; /* Net for memory */ 175 Value *m_addr; /* Address we are operating on */ 176 Value *m_netLsb; /* LSB on net (memory) */ 177 Value *m_data; /* Value to store/retrieve from memory */ 178 unsigned m_valLsb; /* Lsb in value */ 179 unsigned m_width; /* Width of assignment */ 180 Trigger *m_trigger; /* Trigger for assignment */ 181 } BCNbMemPutE; 182 183 /***************************************************************************** 184 * 185 * BCCopy - Copy a value with possible mismatch in bit size. 186 * 187 *****************************************************************************/ 188 typedef struct { 189 BCfunc *c_func; /* Function for */ 190 Value *c_dst; /* Destination state */ 191 Value *c_src; /* Source states */ 192 } BCCopy; 193 194 /***************************************************************************** 195 * 196 * BCCopyRange - Copy a range of bits from a value. 197 * 198 *****************************************************************************/ 199 typedef struct { 200 BCfunc *r_func; /* Function for */ 201 Value *r_dst; /* Destination value */ 202 unsigned r_dLsb; /* LSB in destination */ 203 Value *r_src; /* Source value */ 204 Value *r_sLsb; /* Least significant bit in Net (null for full assignment) */ 205 unsigned r_width; /* Number of bits to assign */ 206 } BCCopyRange; 207 208 /***************************************************************************** 209 * 210 * BCAsgn - Assign a value to a net and invoke any resulting actions 211 * 212 *****************************************************************************/ 213 typedef struct { 214 BCfunc *a_func; /* Function for */ 215 Net *a_net; /* Destination net */ 216 Value *a_value; /* Value to assign */ 217 unsigned a_width; /* Number of bits to assign */ 218 unsigned a_valLsb; /* Least significant bit in Value */ 219 Value *a_netLsb; /* Least significant bit in Net (null for full assignment) */ 220 } BCAsgn; 221 222 /***************************************************************************** 223 * 224 * BCRaise - Raise an event 225 * 226 *****************************************************************************/ 227 typedef struct { 228 BCfunc *r_func; /* Function for */ 229 Net *r_net; /* Destination net */ 230 } BCRaise; 231 232 /***************************************************************************** 233 * 234 * BCNbAsgnD - Non-blocking assign a value to a net and invoke any resulting 235 * actions after a specified (possibly 0) delay. 236 * 237 *****************************************************************************/ 238 typedef struct { 239 BCfunc *a_func; /* Function for */ 240 Net *a_net; /* Destination net */ 241 Value *a_value; /* Value to assign */ 242 unsigned a_width; /* Number of bits to assign */ 243 unsigned a_valLsb; /* Least significant bit in Value */ 244 Value *a_netLsb; /* Least significant bit in Net (null for full assignment) */ 245 deltatime_t a_delay; /* Delay for assignment */ 246 } BCNbAsgnD; 247 248 /***************************************************************************** 249 * 250 * BCNbAsgnE - Non-blocking assign a value to a net and invoke any resulting 251 * actions after a triggering event. 252 * 253 *****************************************************************************/ 254 typedef struct { 255 BCfunc *a_func; /* Function for */ 256 Net *a_net; /* Destination net */ 257 Value *a_value; /* Value to assign */ 258 unsigned a_width; /* Number of bits to assign */ 259 unsigned a_valLsb; /* Least significant bit in Value */ 260 Value *a_netLsb; /* Least significant bit in Net (null for full assignment) */ 261 Trigger *a_trigger; /* Event trigger */ 262 } BCNbAsgnE; 263 264 /***************************************************************************** 265 * 266 * BCWireAsgnD - Non-blocking assign a value to a wire net and invoke any 267 * resulting actions after a specified (possibly 0) delay. 268 * 269 *****************************************************************************/ 270 typedef struct { 271 BCfunc *a_func; /* Function for */ 272 Net *a_net; /* Destination net */ 273 int a_id; /* Driver ID for net driver that is changing */ 274 Value *a_value; /* Value to assign */ 275 unsigned a_width; /* Number of bits to assign */ 276 unsigned a_valLsb; /* Least significant bit in Value */ 277 Value *a_netLsb; /* Least significant bit in Net (null for full assignment) */ 278 deltatime_t a_delay; /* Delay for assignment */ 279 } BCWireAsgnD; 280 281 /***************************************************************************** 282 * 283 * BCWireAsgnDF - Same as BCWireAsgnD but assumes value and net are the 284 * same bit size. 285 * 286 *****************************************************************************/ 287 typedef struct { 288 BCfunc *a_func; /* Function for */ 289 Net *a_net; /* Destination net */ 290 int a_id; /* Driver ID for net driver that is changing */ 291 Value *a_value; /* Value to assign */ 292 deltatime_t a_delay; /* Delay for assignment */ 293 } BCWireAsgnDF; 294 295 /***************************************************************************** 296 * 297 * BCEnd - End execution of a thread 298 * 299 *****************************************************************************/ 300 typedef struct { 301 BCfunc *e_func; 302 } BCEnd; 303 304 /***************************************************************************** 305 * 306 * BCNoop - Null opperation 307 * 308 *****************************************************************************/ 309 typedef struct { 310 BCfunc *n_func; 311 } BCNoop; 312 313 /***************************************************************************** 314 * 315 * BCGoto - Conditional/unconditional goto 316 * 317 *****************************************************************************/ 318 typedef struct { 319 BCfunc *g_func; /* Handler function */ 320 Value *g_cond; /* Condition or null for unconditional jump */ 321 CodeBlock *g_block; /* Destination block of jump */ 322 unsigned g_offset; /* Offset into block of jump */ 323 int g_neg; /* Jump on negative of condition */ 324 } BCGoto; 325 326 /***************************************************************************** 327 * 328 * BCSpawn - Spawn a child thread 329 * 330 *****************************************************************************/ 331 typedef struct { 332 BCfunc *s_func; /* Handler function */ 333 CodeBlock *s_block; /* Codeblock for child thread */ 334 unsigned s_offset; /* Offset for child thread */ 335 } BCSpawn; 336 337 /***************************************************************************** 338 * 339 * BCWait - Suspend current thread until something interesting happends. 340 * 341 *****************************************************************************/ 342 typedef struct { 343 BCfunc *w_func; /* Handler function */ 344 } BCWait; 345 346 /***************************************************************************** 347 * 348 * BCTask - Invoke a task 349 * 350 *****************************************************************************/ 351 typedef struct { 352 BCfunc *t_func; /* Handler function */ 353 systask_f *t_task; /* Task function */ 354 TaskContext *t_context; /* Task context if used */ 355 Value *t_rvalue; /* Return value for task */ 356 int t_numArgs; /* Number of arguments */ 357 void **t_args; /* Array of arguments */ 358 } BCTask; 359 360 /***************************************************************************** 361 * 362 * BCDelay - Delay current task (corresponds to #n ) 363 * 364 *****************************************************************************/ 365 typedef struct { 366 BCfunc *d_func; /* Handler function */ 367 deltatime_t d_delay; /* Relative delay time */ 368 } BCDelay; 369 370 /***************************************************************************** 371 * 372 * BCTrigger - Wait for a triggering event (corresponds to @(a) ) 373 * 374 *****************************************************************************/ 375 typedef struct { 376 BCfunc *t_func; /* Handler function */ 377 Trigger *t_trigger; /* Trigger event to wait for */ 378 } BCTrigger; 379 380 /***************************************************************************** 381 * 382 * BCLock - Wait for semephore to be zero, set semaphore to 1 and advance 383 * 384 *****************************************************************************/ 385 typedef struct { 386 BCfunc *l_func; /* Handler function */ 387 Trigger *l_trigger; /* Trigger indicating change in semephore value */ 388 Value *l_value; /* Value of semephore variable */ 389 } BCLock; 390 391 /***************************************************************************** 392 * 393 * BCSubr - Jump to a subroutine 394 * 395 *****************************************************************************/ 396 typedef struct { 397 BCfunc *s_func; /* Handler function */ 398 CodeBlock *s_block; /* Codeblock in which to jump to */ 399 unsigned s_offset; /* Offsets of instructions to jump to */ 400 } BCSubr; 401 402 /***************************************************************************** 403 * 404 * BCReturn - Jump to a subroutine 405 * 406 *****************************************************************************/ 407 typedef struct { 408 BCfunc *r_func; 409 } BCReturn; 410 411 /***************************************************************************** 412 * 413 * BCSubr - Jump to a subroutine 414 * 415 *****************************************************************************/ 416 typedef struct { 417 BCfunc *dp_func; 418 char *dp_message; /* Message to print */ 419 } BCDebugPrint; 420 421 422 /***************************************************************************** 423 * 424 * ByteCode - A single byte code instruction. 425 * 426 *****************************************************************************/ 427 union ByteCode_union { 428 BCfunc *bc_func; /* Handler function for operation */ 429 BCOpr bc_opr; /* Basic operation */ 430 BCEnd bc_end; /* End thread */ 431 BCNoop bc_noop; /* No-op */ 432 BCGoto bc_goto; /* Goto (conditional or unconditional) */ 433 BCSpawn bc_spawn; /* Spawn child thread */ 434 BCCopy bc_copy; /* Copy */ 435 BCCopyRange bc_copyrange; /* Copy of range */ 436 BCTask bc_task; /* Invoke a task */ 437 BCAsgn bc_asgn; /* Net assignment */ 438 BCRaise bc_raise; /* Raise an event */ 439 BCNbAsgnD bc_nbasgnd; /* Non-blocking reg net assignment (on delay) */ 440 BCNbAsgnE bc_nbasgne; /* Non-blocking reg net assignment (on trigger) */ 441 BCWireAsgnD bc_wireasgnd; /* Non-blocking wire net assignment (on trigger) */ 442 BCWait bc_wait; /* Suspend current thread */ 443 BCDelay bc_delay; /* Delay current task */ 444 BCTrigger bc_trigger; /* Suspend and wait for trigger */ 445 BCLock bc_lock; /* Lock/semephore */ 446 BCMemFetch bc_memfetch; /* Memory fetch */ 447 BCMemPut bc_memput; /* Memory store */ 448 BCNbMemPutD bc_nbmemputd; /* Non-blocking memory store (on delay) */ 449 BCNbMemPutE bc_nbmempute; /* Non-blocking memory store (on trigger) */ 450 BCSubr bc_subr; /* Jump to a subroutine */ 451 BCReturn bc_ret; /* Return from a subroutine */ 452 BCDebugPrint bc_dbgprint; /* Print a debugging message */ 453 }; 454 455 /***************************************************************************** 456 * 457 * CodeBlock - a block of bytecode instructions. 458 * 459 *****************************************************************************/ 460 struct CodeBlock_str { 461 int cb_length; /* Number of generated instructions */ 462 int cb_nalloced; /* Number of allocated entries */ 463 ModuleInst *cb_module; /* Module instance we are in */ 464 ByteCode *cb_instructions; /* Vector of instructions */ 465 }; 466 467 /***************************************************************************** 468 * CodeBlock member functions 469 *****************************************************************************/ 470 CodeBlock *new_CodeBlock(ModuleInst *mi); 471 void delete_CodeBlock(CodeBlock *); 472 void CodeBlock_init(CodeBlock *cb,ModuleInst *mi); 473 void CodeBlock_uninit(CodeBlock *cb); 474 ByteCode *CodeBlock_nextEmpty(CodeBlock *cb); 475 #define CodeBlock_first(cb) (cb)->cb_instructions 476 #define CodeBlock_size(cb) (cb)->cb_length 477 #define CodeBlock_get(cb,offset) (&(cb)->cb_instructions[offset]) 478 #define CodeBlock_getModuleInst(cb) ((cb)->cb_module) 479 void CodeBlock_close(CodeBlock*); 480 void CodeBlock_copy(CodeBlock *dst,unsigned dpos,CodeBlock *src,unsigned start,unsigned stop); 481 482 /***************************************************************************** 483 * ByteCode member functions 484 *****************************************************************************/ 485 #define ByteCode_exec(bc,t) (*bc->bc_func)(bc,t) 486 487 /***************************************************************************** 488 * BCEnd - member functions 489 *****************************************************************************/ 490 void BCEnd_init(ByteCode*); 491 void BCEnd_exec(BCEnd *bc,VGThread *t); 492 493 /***************************************************************************** 494 * BCNoop - member functions 495 *****************************************************************************/ 496 void BCNoop_init(ByteCode*); 497 void BCNoop_exec(BCNoop *bc,VGThread *t); 498 499 /***************************************************************************** 500 * BCOpr - member functions 501 *****************************************************************************/ 502 void BCOpr_init(ByteCode*,valueop_f*S,Value*r,Value*a,Value*b,Value*c); 503 void BCOpr_exec(BCOpr *bc,VGThread *t); 504 505 /***************************************************************************** 506 * BCCopy - member functions 507 *****************************************************************************/ 508 void BCCopy_init(ByteCode *bc, Value*dst, Value*src); 509 void BCCopy_exec(BCCopy *bc, VGThread *t); 510 511 /***************************************************************************** 512 * BCCopyRange - member functions 513 *****************************************************************************/ 514 void BCCopyRange_init(ByteCode *bc, Value *dst, unsigned dLsb,Value *src,Value *srcLsb, unsigned width); 515 void BCCopyRange_exec(BCCopyRange *bc, VGThread *t); 516 517 /***************************************************************************** 518 * BCAsgn - member functions 519 *****************************************************************************/ 520 void BCAsgn_init(ByteCode *bc, Net *net, Value *netLsb, Value *value, unsigned valLsb, unsigned width); 521 void BCAsgn_exec(BCAsgn *bc, VGThread *t); 522 523 /***************************************************************************** 524 * BCRaise - member functions 525 *****************************************************************************/ 526 void BCRaise_init(ByteCode *bc, Net *net); 527 void BCRaise_exec(BCRaise *br, VGThread *t); 528 529 /***************************************************************************** 530 * BCNbAsgnD - member functions 531 *****************************************************************************/ 532 void BCNbAsgnD_init(ByteCode *bc, Net *net, Value *netLsb, Value *value, unsigned valLsb, unsigned width,deltatime_t delay); 533 void BCNbAsgnD_exec(BCNbAsgnD *bc, VGThread *t); 534 535 /***************************************************************************** 536 * BCNbAsgnE - member functions 537 *****************************************************************************/ 538 void BCNbAsgnE_init(ByteCode *bc, Net *net, Value *netLsb, Value *value, unsigned valLsb, unsigned width,Trigger *trigger); 539 void BCNbAsgnE_exec(BCNbAsgnE *bc, VGThread *t); 540 541 /***************************************************************************** 542 * BCWireAsgnD - member functions 543 *****************************************************************************/ 544 void BCWireAsgnD_init(ByteCode *bc, Net *net, int id, Value *netLsb, Value *value, unsigned valLsb, unsigned width,deltatime_t delay); 545 void BCWireAsgnD_exec(BCWireAsgnD *bc, VGThread *t); 546 547 /***************************************************************************** 548 * BCGoto - member functions 549 *****************************************************************************/ 550 void BCGoto_init(ByteCode *g,Value*cond,int neg,CodeBlock *cb,unsigned offset); 551 void BCGoto_exec(BCGoto *g,VGThread *t); 552 #define BCGoto_setOffset(g,offset) ((g)->g_offset = (offset)) 553 554 /***************************************************************************** 555 * BCSpawn - member functions 556 *****************************************************************************/ 557 void BCSpawn_init(ByteCode *s,CodeBlock *cb,unsigned offset); 558 void BCSpawn_exec(BCSpawn *s,VGThread *t); 559 #define BCSpawn_setOffset(s,offset) ((s)->s_offset = (offset)) 560 561 /***************************************************************************** 562 * BCWait - member functions 563 *****************************************************************************/ 564 void BCWait_init(ByteCode *w); 565 void BCWait_exec(BCWait *w,VGThread *t); 566 567 /***************************************************************************** 568 * BCTask - member functions 569 *****************************************************************************/ 570 void BCTask_init(ByteCode *g,systask_f*, TaskContext *tctx, Value *rval,int numArgs,void **args); 571 void BCTask_exec(BCTask *g,VGThread *t); 572 573 /***************************************************************************** 574 * BCDelay - member functions 575 *****************************************************************************/ 576 void BCDelay_init(ByteCode *d,deltatime_t t); 577 void BCDelay_exec(BCDelay *d,VGThread *t); 578 579 /***************************************************************************** 580 * BCTrigger - member functions 581 *****************************************************************************/ 582 void BCTrigger_init(ByteCode *bct,Trigger *t); 583 void BCTrigger_exec(BCTrigger *bct,VGThread *t); 584 585 /***************************************************************************** 586 * BCLock - member functions 587 *****************************************************************************/ 588 void BCLock_init(ByteCode *bc,Trigger *t, Value *value); 589 void BCLock_exec(BCLock *lt,VGThread *t); 590 591 /***************************************************************************** 592 * BCMemFetch - member functions 593 *****************************************************************************/ 594 void BCMemFetch_init(ByteCode *bct,Net *n, Value *addr, Value *data); 595 void BCMemFetch_exec(BCMemFetch *,VGThread *t); 596 597 /***************************************************************************** 598 * BCMemPut - member functions 599 *****************************************************************************/ 600 void BCMemPut_init(ByteCode *bc,Net *n, Value *addr, Value *netLsb, Value *data,unsigned valLsb,unsigned width); 601 void BCMemPut_exec(BCMemPut *bct,VGThread *t); 602 603 /***************************************************************************** 604 * BCNbMemPutD - member functions 605 *****************************************************************************/ 606 void BCNbMemPutD_init(ByteCode *bc,Net *n, Value *addr, Value *netLsb, Value *data,unsigned valLsb,unsigned width,deltatime_t t); 607 void BCNbMemPutD_exec(BCNbMemPutD *bct,VGThread *t); 608 609 /***************************************************************************** 610 * BCNbMemPutE - member functions 611 *****************************************************************************/ 612 void BCNbMemPutE_init(ByteCode *bc,Net *n, Value *addr, Value *netLsb, Value *data,unsigned valLsb,unsigned width,Trigger *t); 613 void BCNbMemPutE_exec(BCNbMemPutE *bct,VGThread *t); 614 615 /***************************************************************************** 616 * BCSubr - member functions 617 *****************************************************************************/ 618 void BCSubr_init(ByteCode *bc,CodeBlock *block,unsigned offset); 619 void BCSubr_exec(BCSubr *s,VGThread *t); 620 621 /***************************************************************************** 622 * BCReturn - member functions 623 *****************************************************************************/ 624 void BCReturn_init(ByteCode *bc); 625 void BCReturn_exec(BCReturn *r,VGThread *t); 626 627 /***************************************************************************** 628 * BCDebugPrint - member functions 629 *****************************************************************************/ 630 void BCDebugPrint_init(ByteCode *bc,char *msg,...); 631 void BCDebugPrint_exec(BCDebugPrint *dp,VGThread *t); 632 633 /***************************************************************************** 634 * VGFrame - member functions 635 *****************************************************************************/ 636 VGFrame *new_VGFrame(ByteCode *bc,VGFrame *next); 637 void delete_VGFrame(VGFrame *); 638 639 /***************************************************************************** 640 * VGThread - member functions 641 *****************************************************************************/ 642 VGThread *new_VGThread(CodeBlock *cb,unsigned pc,ModuleInst *modCtx,ModuleItem *mitem); 643 void delete_VGThread(VGThread *); 644 void VGThread_init(VGThread *thread,CodeBlock *cb,unsigned pc,ModuleInst *modCtx,ModuleItem *mitem); 645 void VGThread_uninit(VGThread *thread); 646 void VGThread_exec(VGThread *thread); 647 void VGThread_delay(VGThread *thread,deltatime_t); 648 void VGThread_delayToEnd(VGThread *thread); 649 void VGThread_eventWait(VGThread *thread,Trigger *t); 650 void VGThread_start(VGThread *thread); 651 void VGThread_childEndNotify(VGThread *thread); 652 VGThread *VGThread_spawn(VGThread *parent,CodeBlock *cb,unsigned offset); 653 void VGThread_goto(VGThread *thread,CodeBlock *codeBlock,unsigned offset); 654 void VGThread_kill(VGThread *thread); 655 #define VGThread_getModCtx(thread) (thread)->t_modCtx 656 #define VGThread_getCircuit(thread) (thread)->t_modCtx->mc_circuit 657 #define VGThread_getQueue(thread) Circuit_getQueue((thread)->t_modCtx->mc_circuit) 658 #define VGThread_suspend(t) ((t)->t_state |= TS_BLOCKED) 659 #define VGThread_resume(t) ((t)->t_state &= ~TS_BLOCKED) 660 #define VGThread_enable(t) ((t)->t_state &= ~TS_DISABLED) 661 #define VGThread_disable(t) ((t)->t_state |= TS_DISABLED) 662 #define VGThread_isActive(t) ((t)->t_state == TS_ACTIVE) 663 #define VGThread_doNextInsruction(t) (*t->t_pc->bc_func)(t->t_pc,t) 664 #define VGThread_getMItem(t) (t)->t_mitem 665 666 #endif 667