Procesor Simulation

Name

Procesor Simulation -- Simulation of the processor

Synopsis


struct      simul_data_t;
struct      simul_io_event_t;
struct      simul_mem_t;
struct      event_data_t;
void        init_CPU_simulation             (void);
void        init_CPU_simulation_in_proc     (proc_t *proc);
void        end_CPU_simulation_in_proc      (proc_t *proc);
void        cpy_CPU_simulation_data         (simul_data_t *dest,
                                             simul_data_t *src);
simul_data_t* dup_CPU_simulation_data       (simul_data_t *data);
void        free_CPU_simulation_data        (simul_data_t *data);
void        free_CPU_proc_simulation_data   (proc_t *proc);
void        next_CPU_simulation_in_proc     (proc_t *proc);
gint        CPU_proc_current_page           (proc_t *proc);
gint        CPU_proc_next_page              (proc_t *proc);
gboolean    CPU_proc_current_page_is_write  (proc_t *proc);
void        fix_simulation_in_proc          (proc_t *proc);
#define     IO_BLOCK                        (event)

Description

This functions serve to manage the CPU's simulation and it's data structures.

Details

struct simul_data_t

typedef struct {		/* simulation data for a process */
	gint start_time;	/* time of creation */
	gint end_time;		/* length of the process */
	/* IO properties */
	/* this list is never modified until process destruction */
	simul_io_event_t *io_events;		/* list of all io events */
	simul_io_event_t *next_io_event;	/* pointer to the next event */
	simul_io_event_t *last_io_event;	/* pointer to the last event */
	/* MEM properties */
	simul_mem_t *pages;	/* list of memory accesses */
	gint n_pages;		/* number of memory accesses */
	gint cur_access;	/* index to the current access */
} simul_data_t;


struct simul_io_event_t

typedef struct {	/* data for an IO event */
	gint block;	/* block to read */
	gint time;	/* time to read @block */
} simul_io_event_t;


struct simul_mem_t

typedef struct {	/* data for a page access */
	gint8 page;	/* page to access */
	gint8 write;	/* is it a write access? */
} simul_mem_t;


struct event_data_t

typedef struct {	/* io event data known by all the code */
	gint io_block;	/* block to access */
} event_data_t;


init_CPU_simulation ()

void        init_CPU_simulation             (void);

Initializes the simulation code.


init_CPU_simulation_in_proc ()

void        init_CPU_simulation_in_proc     (proc_t *proc);

prepares the data structures for simulation in process proc.

proc : process involved.


end_CPU_simulation_in_proc ()

void        end_CPU_simulation_in_proc      (proc_t *proc);

cleans up simulation data in proc to prepare it for termination.

Note: currently does nothing.

proc : the process involved.


cpy_CPU_simulation_data ()

void        cpy_CPU_simulation_data         (simul_data_t *dest,
                                             simul_data_t *src);

Copies the contents of src into dest, allocating dynamic memory when needed.

dest : the target of the copy
src : the source for the copy


dup_CPU_simulation_data ()

simul_data_t* dup_CPU_simulation_data       (simul_data_t *data);

Duplicates a simul_data_t structure.

data : a pointer to the data to be copied
Returns : a pointer to newly allocated memory with the same content of data


free_CPU_simulation_data ()

void        free_CPU_simulation_data        (simul_data_t *data);

Frees all dynamic memory asociated to data, including data itself.

data : the data to be freed


free_CPU_proc_simulation_data ()

void        free_CPU_proc_simulation_data   (proc_t *proc);

Free all simulation related dynamic memory from the proc structure.

proc : a pointer to a proc_t structure


next_CPU_simulation_in_proc ()

void        next_CPU_simulation_in_proc     (proc_t *proc);

Once the process had an event it prepares the process for its next event, making it a termination event if necesary.

proc : the process involved.


CPU_proc_current_page ()

gint        CPU_proc_current_page           (proc_t *proc);

proc : the process involved.
Returns : the page which proc is using on this very moment.


CPU_proc_next_page ()

gint        CPU_proc_next_page              (proc_t *proc);

Makes the process move to its next memory page and should be called once for each "clock tick" that proc is running.

proc : the process involved.
Returns : the new page which the process is using.


CPU_proc_current_page_is_write ()

gboolean    CPU_proc_current_page_is_write  (proc_t *proc);

Checks if proc is writing to memory or only reading.

proc : the process involved.
Returns : TRUE when proc is writing to its current page.


fix_simulation_in_proc ()

void        fix_simulation_in_proc          (proc_t *proc);

Makes the simulation parameters of a process coherent, prevents: multiple events at the same time, events after process termination, determines the next event ...

proc : process whose simulation data should be fixed.


IO_BLOCK()

#define IO_BLOCK(event) (((event_data_t *)(event.data))->io_block)

Extracts the block from a IO event.

event : process event.