source: soft/giet_vm/sys/sys_handler.c @ 203

Last change on this file since 203 was 203, checked in by alain, 12 years ago

Introducing support for XICU

File size: 6.3 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : sys_handler.c
3// Date     : 01/04/2012
4// Author   : alain greiner and joel porquet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The sys_handler.c and sys_handler.h files are part of the GIET-VM nano-kernel.
8// It define the syscall_vector[] (at the end of this file), as well as the
9// associated syscall handlers that are not related to peripherals.
10// The syscall handlers for peripherals are defined in the drivers.c file.
11///////////////////////////////////////////////////////////////////////////////////
12
13#include <sys_handler.h>
14#include <drivers.h>
15#include <ctx_handler.h>
16#include <common.h>
17#include <giet_config.h>
18#include <mapping_info.h>
19
20////////////////////////////////////////////////////////////////////////////
21//      Initialize the syscall vector with syscall handlers
22////////////////////////////////////////////////////////////////////////////
23const void *_syscall_vector[32] = {
24    &_procid,           /* 0x00 */
25    &_proctime,         /* 0x01 */
26    &_tty_write,        /* 0x02 */
27    &_tty_read,         /* 0x03 */
28    &_timer_start,      /* 0x04 */
29    &_timer_stop,       /* 0x05 */
30    &_gcd_write,        /* 0x06 */
31    &_gcd_read,         /* 0x07 */
32    &_sys_ukn,          /* 0x08 */
33    &_sys_ukn,          /* 0x09 */
34    &_tty_read_irq,     /* 0x0A */
35    &_sys_ukn,          /* 0x0B */
36    &_sys_ukn,          /* 0x0C */
37    &_ctx_switch,       /* 0x0D */
38    &_exit,             /* 0x0E */
39    &_procs_number,     /* 0x0F */
40    &_fb_sync_write,    /* 0x10 */
41    &_fb_sync_read,     /* 0x11 */
42    &_fb_write,         /* 0x12 */
43    &_fb_read,          /* 0x13 */
44    &_fb_completed,     /* 0x14 */
45    &_ioc_write,        /* 0x15 */
46    &_ioc_read,         /* 0x16 */
47    &_ioc_completed,    /* 0x17 */
48    &_sys_ukn,          /* 0x18 */
49    &_sys_ukn,          /* 0x19 */
50    &_vobj_get_vbase,   /* 0x1A */
51    &_sys_ukn,          /* 0x1B */
52    &_sys_ukn,          /* 0x1C */
53    &_sys_ukn,          /* 0x1D */
54    &_sys_ukn,          /* 0x1E */
55    &_sys_ukn,          /* 0x1F */
56};
57
58//////////////////////////////////////////////////////////////////////////////
59// function executed in case of undefined syscall
60//////////////////////////////////////////////////////////////////////////////
61void _sys_ukn()
62{
63    unsigned int        epc;
64    asm volatile("mfc0 %0, $14" : "=r"(epc));
65
66    _puts("\n\n!!! Undefined System Call !!!\n");
67    _puts("\nEPC = ");
68    _putw( epc );
69    _exit();
70}
71////////////////////////////////////////////////////////////////////////////
72// _exit()
73// Task suicide... after printing a death message.
74////////////////////////////////////////////////////////////////////////////
75void _exit()
76{
77    unsigned int date    = _proctime();
78    unsigned int proc_id = _procid();
79    unsigned int task_id = _get_current_task_id();
80
81     // print death message
82    _get_lock(&_tty_put_lock);
83    _puts("\n[GIET] Exit task ");
84    _putd( task_id );
85    _puts(" on processor ");
86    _putd( proc_id );
87    _puts(" at cycle ");
88    _putd( date );
89    _puts("\n\n");
90    _release_lock(&_tty_put_lock);
91   
92    // goes to sleeping state
93    _set_context_slot( task_id, CTX_RUN_ID, 0 );
94   
95    // deschedule
96    _ctx_switch();
97} 
98//////////////////////////////////////////////////////////////////////////////
99// _procid()
100// Access CP0 and returns current processor's identifier.
101// Max number or processors is 1024.
102//////////////////////////////////////////////////////////////////////////////
103unsigned int _procid()
104{
105    unsigned int ret;
106    asm volatile("mfc0 %0, $15, 1" : "=r"(ret));
107    return (ret & 0xFFF);
108}
109//////////////////////////////////////////////////////////////////////////////
110// _proctime()
111// Access CP0 and returns current processor's elapsed clock cycles since boot.
112//////////////////////////////////////////////////////////////////////////////
113unsigned int _proctime()
114{
115    unsigned int ret;
116    asm volatile("mfc0 %0, $9" : "=r"(ret));
117    return ret;
118}
119//////////////////////////////////////////////////////////////////////////////
120// _procnumber()
121// returns in buffer argument the number of processors in the cluster
122// specified by the cluster_id argument.
123//////////////////////////////////////////////////////////////////////////////
124unsigned int _procs_number( unsigned int        cluster_id,
125                            unsigned int*       buffer)
126{
127    mapping_header_t*   header  = (mapping_header_t*)&seg_mapping_base;
128    mapping_cluster_t*  cluster = _get_cluster_base( header );
129
130    if ( cluster_id < header->clusters )
131    {
132        *buffer = cluster[cluster_id].procs;
133        return 0;
134    }
135    else
136    {
137         return 1;
138    }
139}
140
141/////////////////////////////////////////////////////////////////////////////
142// _vobj_get_vbase()
143// This function writes in vobj_buffer the virtual base address of a vobj
144// identified by the (vspace_name / vobj_name ) couple.
145// The vobj_type argument is redundant, and for checking purpose.
146// returns 0: success, else: failed.
147/////////////////////////////////////////////////////////////////////////////
148unsigned int _vobj_get_vbase( char*                     vspace_name, 
149                              char*                     vobj_name,
150                              unsigned int      vobj_type, 
151                              unsigned int* vobj_vaddr )
152{
153    mapping_header_t* header = (mapping_header_t*)&seg_mapping_base;
154    mapping_vspace_t* vspace = _get_vspace_base( header );
155    mapping_vobj_t*    vobj  = _get_vobj_base( header );
156
157    unsigned int    vspace_id;
158    unsigned int    vobj_id;
159       
160
161    // scan vspaces
162    for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ )
163    {
164        if ( _strncmp( vspace[vspace_id].name, vspace_name, 31) == 0 )
165        {
166            // scan vobjs
167            for( vobj_id = vspace[vspace_id].vobj_offset; 
168                 vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); 
169                 vobj_id++)
170            {
171
172                if ( _strncmp( vobj[vobj_id].name, vobj_name, 31) == 0 )
173                {
174                    if(vobj[vobj_id].type != vobj_type)
175                        return -1;                                                      //wrong type
176
177                    *vobj_vaddr = (unsigned int)vobj[vobj_id].vaddr;
178                    return 0;
179                }
180            } 
181        }
182    } 
183    return -2;          //not found
184}
185
Note: See TracBrowser for help on using the repository browser.