source: soft/giet_vm/giet_drivers/sim_driver.c @ 401

Last change on this file since 401 was 345, checked in by cfuguet, 10 years ago

giet_vm optimizations:

  • Several modifications in GIET_VM in order to support compilation with GCC optimizations (-O2) activated.
  • Adding missing volatile in some global variables.
  • Using ioread and iowrite utility functions in peripheral drivers which prevent GCC to remove writes or reads in hardware memory mapped registers.
  • Code refactoring of stdio printf functions. Now, shr_printf and tty_printf function reuse the same function body. The only difference is that shr_printf wraps printf function call with TTY get lock and release lock.
File size: 2.4 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : sim_driver.c
3// Date     : 23/11/2013
4// Author   : alain greiner / cesar fuguet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The sim_driver.c and sim_driver.h files are part ot the GIET-VM nano-kernel.
8// This driver supports the vci_sim_helper component.
9// There is at most one such component in the architecture.
10//
11// The SEG_SIM_BASE address must be defined in the hard_config.h file.
12////////////////////////////////////////////////////////////////////////////////
13
14#include <hard_config.h>
15#include <giet_config.h>
16#include <sim_driver.h>
17
18#if !defined(SEG_SIM_BASE)
19# error: You must define SEG_SIM_BASE in the hard_config.h file
20#endif
21
22////////////////////////////////////////////////////////////////////////////////
23// _sim_helper_access()
24// Accesses the Simulation Helper Component.
25//
26// If the access is on a writable register (except SIMHELPER_PAUSE_SIM),
27// the simulation will stop.
28// If the access is on a readable register, value is written in retval buffer.
29// Returns 0 on success, 1 on failure.
30////////////////////////////////////////////////////////////////////////////////
31unsigned int _sim_helper_access( unsigned int register_index,
32                                 unsigned int value,
33                                 unsigned int * retval) 
34{
35    volatile unsigned int* sim_helper_address = (unsigned int*)&seg_sim_base;
36   
37    if (register_index == SIMHELPER_SC_STOP         ||
38        register_index == SIMHELPER_END_WITH_RETVAL ||
39        register_index == SIMHELPER_EXCEPT_WITH_VAL ||
40        register_index == SIMHELPER_PAUSE_SIM       ||
41        register_index == SIMHELPER_SIGINT) 
42    {
43        sim_helper_address[register_index] = value;
44        return 0;
45    }
46    else if (register_index == SIMHELPER_CYCLES) 
47    {
48        *retval = sim_helper_address[register_index];
49        return 0;
50    }
51    else 
52    {
53        _tty_get_lock( 0 );
54        _puts("\n[GIET ERROR] in _sim_helper_access() : access to unmapped register\n");
55        _tty_release_lock( 0 );
56        return 1;
57    }
58}
59
60// Local Variables:
61// tab-width: 4
62// c-basic-offset: 4
63// c-file-offsets:((innamespace . 0)(inline-open . 0))
64// indent-tabs-mode: nil
65// End:
66// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
67
Note: See TracBrowser for help on using the repository browser.