Changeset 228 for soft/giet_vm/sys/sys_handler.c
- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sys/sys_handler.c
r218 r228 17 17 #include <giet_config.h> 18 18 #include <mapping_info.h> 19 20 //////////////////////////////////////////////////////////////////////////// 21 // Initialize the syscall vector with syscall handlers 22 //////////////////////////////////////////////////////////////////////////// 23 const 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 &_sys_ukn, /* 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 &_nic_write, /* 0x1B */ 52 &_nic_read, /* 0x1C */ 53 &_nic_completed, /* 0x1D */ 54 &_sys_ukn, /* 0x1E */ 55 &_sys_ukn, /* 0x1F */ 19 #include <srl_memspace.h> 20 21 //////////////////////////////////////////////////////////////////////////// 22 // Initialize the syscall vector with syscall handlers 23 //////////////////////////////////////////////////////////////////////////// 24 const void * _syscall_vector[32] = { 25 &_procid, /* 0x00 */ 26 &_proctime, /* 0x01 */ 27 &_tty_write, /* 0x02 */ 28 &_tty_read, /* 0x03 */ 29 &_timer_start, /* 0x04 */ 30 &_timer_stop, /* 0x05 */ 31 &_gcd_write, /* 0x06 */ 32 &_gcd_read, /* 0x07 */ 33 &_sys_ukn, /* 0x08 */ 34 &_get_current_task_id, /* 0x09 */ 35 &_sys_ukn, /* 0x0A */ 36 &_sys_ukn, /* 0x0B */ 37 &_sys_ukn, /* 0x0C */ 38 &_context_switch, /* 0x0D */ 39 &_exit, /* 0x0E */ 40 &_procs_number, /* 0x0F */ 41 &_fb_sync_write, /* 0x10 */ 42 &_fb_sync_read, /* 0x11 */ 43 &_fb_write, /* 0x12 */ 44 &_fb_read, /* 0x13 */ 45 &_fb_completed, /* 0x14 */ 46 &_ioc_write, /* 0x15 */ 47 &_ioc_read, /* 0x16 */ 48 &_ioc_completed, /* 0x17 */ 49 &_sys_ukn, /* 0x18 */ 50 &_sys_ukn, /* 0x19 */ 51 &_vobj_get_vbase, /* 0x1A */ 52 &_nic_write, /* 0x1B */ 53 &_nic_read, /* 0x1C */ 54 &_nic_completed, /* 0x1D */ 55 &_sys_ukn, /* 0x1E */ 56 &_sys_ukn, /* 0x1F */ 56 57 }; 57 58 … … 59 60 // function executed in case of undefined syscall 60 61 ////////////////////////////////////////////////////////////////////////////// 61 void _sys_ukn() 62 { 63 unsigned int epc; 64 asm volatile("mfc0 %0, $14" : "=r"(epc)); 62 void _sys_ukn() { 63 unsigned int epc; 64 asm volatile("mfc0 %0, $14" : "=r" (epc)); 65 65 66 66 _puts("\n\n!!! Undefined System Call !!!\n"); 67 67 _puts("\nEPC = "); 68 _putx( epc);68 _putx(epc); 69 69 _exit(); 70 70 } 71 72 71 73 //////////////////////////////////////////////////////////////////////////// 72 74 // _exit() 73 75 // Task suicide... after printing a death message. 74 76 //////////////////////////////////////////////////////////////////////////// 75 void _exit() 76 { 77 unsigned int date = _proctime(); 77 void _exit() { 78 unsigned int date = _proctime(); 78 79 unsigned int proc_id = _procid(); 79 80 unsigned int task_id = _get_current_task_id(); 80 81 81 82 // print death message 82 83 _get_lock(&_tty_put_lock); 83 84 _puts("\n[GIET] Exit task "); 84 _putd( task_id);85 _putd(task_id); 85 86 _puts(" on processor "); 86 _putd( proc_id);87 _putd(proc_id); 87 88 _puts(" at cycle "); 88 _putd( date);89 _putd(date); 89 90 _puts("\n\n"); 90 91 _release_lock(&_tty_put_lock); 91 92 92 93 // goes to sleeping state 93 _set_context_slot( task_id, CTX_RUN_ID, 0 94 94 _set_context_slot( task_id, CTX_RUN_ID, 0); 95 95 96 // deschedule 96 97 _ctx_switch(); 97 98 } 99 100 98 101 ////////////////////////////////////////////////////////////////////////////// 99 102 // _procid() … … 101 104 // Max number or processors is 1024. 102 105 ////////////////////////////////////////////////////////////////////////////// 103 unsigned int _procid() 104 { 105 unsigned int ret; 106 asm volatile("mfc0 %0, $15, 1" : "=r"(ret)); 106 unsigned int _procid() { 107 unsigned int ret; 108 asm volatile("mfc0 %0, $15, 1" : "=r" (ret)); 107 109 return (ret & 0xFFF); 108 110 } 111 112 109 113 ////////////////////////////////////////////////////////////////////////////// 110 114 // _proctime() 111 115 // Access CP0 and returns current processor's elapsed clock cycles since boot. 112 116 ////////////////////////////////////////////////////////////////////////////// 113 unsigned int _proctime() 114 { 115 unsigned int ret; 116 asm volatile("mfc0 %0, $9" : "=r"(ret)); 117 unsigned int _proctime() { 118 unsigned int ret; 119 asm volatile("mfc0 %0, $9" : "=r" (ret)); 117 120 return ret; 118 121 } 122 123 119 124 ////////////////////////////////////////////////////////////////////////////// 120 125 // _procnumber() … … 122 127 // specified by the cluster_id argument. 123 128 ////////////////////////////////////////////////////////////////////////////// 124 unsigned 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 { 129 unsigned int _procs_number(unsigned int cluster_id, unsigned int * buffer) { 130 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 131 mapping_cluster_t * cluster = _get_cluster_base(header); 132 133 if (cluster_id < header->clusters) { 132 134 *buffer = cluster[cluster_id].procs; 133 135 return 0; 134 136 } 135 else 136 { 137 return 1; 138 } 139 } 140 141 int _get_vobj( char* vspace_name, char* vobj_name, unsigned int vobj_type, mapping_vobj_t** res_vobj) 142 { 143 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 144 mapping_vspace_t* vspace = _get_vspace_base( header ); 145 mapping_vobj_t* vobj = _get_vobj_base( header ); 146 147 unsigned int vspace_id; 148 unsigned int vobj_id; 149 137 else { 138 return 1; 139 } 140 } 141 142 143 int _get_vobj(char * vspace_name, char * vobj_name, unsigned int vobj_type, mapping_vobj_t ** res_vobj) { 144 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 145 mapping_vspace_t * vspace = _get_vspace_base(header); 146 mapping_vobj_t * vobj = _get_vobj_base(header); 147 148 unsigned int vspace_id; 149 unsigned int vobj_id; 150 150 151 151 152 // scan vspaces 152 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 153 { 154 if ( _strncmp( vspace[vspace_id].name, vspace_name, 31) == 0 ) 155 { 153 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 154 if (_strncmp( vspace[vspace_id].name, vspace_name, 31) == 0) { 156 155 // scan vobjs 157 for (vobj_id = vspace[vspace_id].vobj_offset;156 for (vobj_id = vspace[vspace_id].vobj_offset; 158 157 vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); 159 vobj_id++) 160 { 161 162 if ( _strncmp( vobj[vobj_id].name, vobj_name, 31) == 0 ) 163 { 164 if(vobj[vobj_id].type != vobj_type) 165 return -1; //wrong type 166 158 vobj_id++) { 159 160 if (_strncmp(vobj[vobj_id].name, vobj_name, 31) == 0) { 161 if (vobj[vobj_id].type != vobj_type) { 162 _get_lock(&_tty_put_lock); 163 _puts("*** Error in _get_obj: wrong type\n"); 164 _release_lock(&_tty_put_lock); 165 return -1; //wrong type 166 } 167 167 *res_vobj = &vobj[vobj_id]; 168 169 168 return 0; 170 169 } … … 172 171 } 173 172 } 174 return -2; //not found 175 176 } 173 _get_lock(&_tty_put_lock); 174 _puts("*** Error in _get_obj: object not found\n"); 175 _release_lock(&_tty_put_lock); 176 177 return -2; //not found 178 } 179 180 177 181 ///////////////////////////////////////////////////////////////////////////// 178 182 // _vobj_get_vbase() … … 182 186 // returns 0: success, else: failed. 183 187 ///////////////////////////////////////////////////////////////////////////// 184 unsigned int _vobj_get_vbase( char* vspace_name, 185 char* vobj_name, 186 unsigned int vobj_type, 187 unsigned int* vobj_vaddr ) 188 { 189 mapping_vobj_t* res_vobj; 190 unsigned int ret; 191 if( (ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj)) ) 192 { 188 unsigned int _vobj_get_vbase( 189 char * vspace_name, 190 char * vobj_name, 191 unsigned int vobj_type, 192 unsigned int * vobj_vaddr) { 193 mapping_vobj_t * res_vobj; 194 unsigned int ret; 195 if ((ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj))) { 193 196 return ret; 194 197 } 195 198 196 199 *vobj_vaddr = res_vobj->vaddr; 197 198 200 return 0; 199 201 } 202 200 203 201 204 ///////////////////////////////////////////////////////////////////////////// … … 206 209 // returns 0: success, else: failed. 207 210 ///////////////////////////////////////////////////////////////////////////// 208 unsigned int _vobj_get_length(char* vspace_name, 209 char* vobj_name, 210 unsigned int vobj_type, 211 unsigned int* vobj_length ) 212 { 213 214 mapping_vobj_t* res_vobj; 215 unsigned int ret; 216 if( (ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj)) ) 217 { 211 unsigned int _vobj_get_length( 212 char * vspace_name, 213 char * vobj_name, 214 unsigned int vobj_type, 215 unsigned int * vobj_length) { 216 217 mapping_vobj_t * res_vobj; 218 unsigned int ret; 219 if ((ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj))) { 218 220 return ret; 219 221 } 220 222 221 223 *vobj_length = res_vobj->length; 222 224 223 225 return 0; 224 226 } 227 228 229 //////////////////////////////////////////////////////////////// 230 // _context_switch() 231 // This functions masks interruptions before calling _ctx_switch 232 // (They are usually masked when we receive a isr_switch interrupt 233 // because we execute isrs with interrupt masked) 234 //////////////////////////////////////////////////////////////// 235 void _context_switch() { 236 _it_mask(); 237 _ctx_switch(); 238 _it_restore(); 239 } 240 241 242 // Local Variables: 243 // tab-width: 4 244 // c-basic-offset: 4 245 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 246 // indent-tabs-mode: nil 247 // End: 248 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 249
Note: See TracChangeset
for help on using the changeset viewer.