2001-03-11 01:29:38 +01:00
|
|
|
#ifndef __vthread_H
|
|
|
|
|
#define __vthread_H
|
|
|
|
|
/*
|
2009-12-07 00:34:14 +01:00
|
|
|
* Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
|
2001-03-11 01:29:38 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-03-11 01:29:38 +01:00
|
|
|
*/
|
|
|
|
|
|
2005-08-27 04:34:42 +02:00
|
|
|
# include "vvp_net.h"
|
|
|
|
|
|
2012-06-25 00:33:40 +02:00
|
|
|
# include <string>
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
/*
|
|
|
|
|
* A vthread is a simulation thread that executes instructions when
|
|
|
|
|
* they are scheduled. This structure contains all the thread specific
|
|
|
|
|
* context needed to run an instruction.
|
|
|
|
|
*
|
|
|
|
|
* Included in a thread are its program counter, local bits and
|
|
|
|
|
* members needed for tracking the thread. The thread runs by fetching
|
|
|
|
|
* instructions from code space, interpreting the instruction, then
|
|
|
|
|
* fetching the next instruction.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-07-03 22:03:36 +02:00
|
|
|
typedef struct vthread_s* vthread_t;
|
|
|
|
|
typedef struct vvp_code_s*vvp_code_t;
|
2001-03-11 01:29:38 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This creates a new simulation thread, with the given start
|
|
|
|
|
* address. The generated thread is ready to run, but is not yet
|
|
|
|
|
* scheduled.
|
|
|
|
|
*/
|
2003-07-03 22:03:36 +02:00
|
|
|
extern vthread_t vthread_new(vvp_code_t sa, struct __vpiScope*scope);
|
2001-03-11 01:29:38 +01:00
|
|
|
|
2001-04-21 02:34:39 +02:00
|
|
|
/*
|
|
|
|
|
* This function marks the thread as scheduled. It is used only by the
|
|
|
|
|
* schedule_vthread function.
|
|
|
|
|
*/
|
|
|
|
|
extern void vthread_mark_scheduled(vthread_t thr);
|
|
|
|
|
|
2009-12-07 00:34:14 +01:00
|
|
|
/*
|
|
|
|
|
* This function causes deletion of the currently running thread to
|
|
|
|
|
* be delayed until after all sync events have been processed for the
|
|
|
|
|
* time step in which the thread terminates. It is only used by the
|
|
|
|
|
* schedule_generic function.
|
|
|
|
|
*/
|
|
|
|
|
extern void vthread_delay_delete();
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
/*
|
|
|
|
|
* Cause this thread to execute instructions until in is put to sleep
|
|
|
|
|
* by executing some sort of delay or wait instruction.
|
|
|
|
|
*/
|
|
|
|
|
extern void vthread_run(vthread_t thr);
|
|
|
|
|
|
2001-03-26 06:00:39 +02:00
|
|
|
/*
|
|
|
|
|
* This function schedules all the threads in the list to be scheduled
|
2001-04-13 05:55:18 +02:00
|
|
|
* for execution with delay 0. The thr pointer is taken to be the head
|
|
|
|
|
* of a list, and all the threads in the list are presumably placed in
|
|
|
|
|
* the list by the %wait instruction.
|
2001-03-26 06:00:39 +02:00
|
|
|
*/
|
|
|
|
|
extern void vthread_schedule_list(vthread_t thr);
|
|
|
|
|
|
2010-01-07 01:08:20 +01:00
|
|
|
extern struct __vpiScope*vthread_scope(vthread_t thr);
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
/*
|
|
|
|
|
* This function returns a handle to the writable context of the currently
|
|
|
|
|
* running thread. Normally the writable context is the context allocated
|
|
|
|
|
* to the scope associated with that thread. However, between executing a
|
|
|
|
|
* %alloc instruction and executing the associated %fork instruction, the
|
|
|
|
|
* writable context changes to the newly allocated context, thus allowing
|
|
|
|
|
* the input parameters of an automatic task or function to be written to
|
|
|
|
|
* the task/function local variables.
|
|
|
|
|
*/
|
|
|
|
|
extern vvp_context_t vthread_get_wt_context();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function returns a handle to the readable context of the currently
|
|
|
|
|
* running thread. Normally the readable context is the context allocated
|
|
|
|
|
* to the scope associated with that thread. However, between executing a
|
|
|
|
|
* %join instruction and executing the associated %free instruction, the
|
|
|
|
|
* readable context changes to the context allocated to the newly joined
|
|
|
|
|
* thread, thus allowing the output parameters of an automatic task or
|
|
|
|
|
* function to be read from the task/function local variables.
|
|
|
|
|
*/
|
|
|
|
|
extern vvp_context_t vthread_get_rd_context();
|
|
|
|
|
|
2008-09-27 01:54:13 +02:00
|
|
|
/*
|
|
|
|
|
* This function returns a handle to an item in the writable context
|
2008-10-28 18:52:39 +01:00
|
|
|
* of the currently running thread.
|
2008-09-27 01:54:13 +02:00
|
|
|
*/
|
|
|
|
|
extern vvp_context_item_t vthread_get_wt_context_item(unsigned context_idx);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function returns a handle to an item in the readable context
|
2008-10-28 18:52:39 +01:00
|
|
|
* of the currently running thread.
|
2008-09-27 01:54:13 +02:00
|
|
|
*/
|
|
|
|
|
extern vvp_context_item_t vthread_get_rd_context_item(unsigned context_idx);
|
2001-03-26 06:00:39 +02:00
|
|
|
|
2001-05-10 02:26:53 +02:00
|
|
|
/*
|
2001-05-20 02:45:43 +02:00
|
|
|
* Return a bit from the thread's bit space. These are used, for
|
|
|
|
|
* example, when a VPI implementation function needs to access the bit
|
|
|
|
|
* space of the thread.
|
|
|
|
|
*/
|
2005-08-27 04:34:42 +02:00
|
|
|
extern vvp_bit4_t vthread_get_bit(struct vthread_s*thr, unsigned addr);
|
|
|
|
|
extern void vthread_put_bit(struct vthread_s*thr, unsigned addr, vvp_bit4_t bit);
|
2001-05-10 02:26:53 +02:00
|
|
|
|
2012-10-23 02:20:43 +02:00
|
|
|
extern void vthread_push_real(struct vthread_s*thr, double val);
|
|
|
|
|
|
|
|
|
|
extern void vthread_pop_str(struct vthread_s*thr, unsigned count);
|
|
|
|
|
extern void vthread_pop_real(struct vthread_s*thr, unsigned count);
|
|
|
|
|
|
2003-01-26 19:16:22 +01:00
|
|
|
|
2012-06-25 00:33:40 +02:00
|
|
|
/* Get the string from the requested position in the vthread string
|
|
|
|
|
stack. The top of the stack is depth==0, and items below are
|
|
|
|
|
depth==1, etc. */
|
2012-10-23 02:37:51 +02:00
|
|
|
extern const std::string&vthread_get_str_stack(struct vthread_s*thr, unsigned depth);
|
2012-10-23 02:20:43 +02:00
|
|
|
extern double vthread_get_real_stack(struct vthread_s*thr, unsigned depth);
|
2012-06-25 00:33:40 +02:00
|
|
|
|
2008-03-21 03:01:20 +01:00
|
|
|
/* This is used to actually delete a thread once we are done with it. */
|
|
|
|
|
extern void vthread_delete(vthread_t thr);
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
#endif
|