[158] | 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 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 <boot_handler.h> |
---|
| 15 | #include <drivers.h> |
---|
| 16 | #include <ctx_handler.h> |
---|
| 17 | #include <common.h> |
---|
| 18 | #include <giet_config.h> |
---|
| 19 | #include <mapping_info.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_write, /* 0x04 */ |
---|
| 30 | &_timer_read, /* 0x05 */ |
---|
| 31 | &_gcd_write, /* 0x06 */ |
---|
| 32 | &_gcd_read, /* 0x07 */ |
---|
| 33 | &_sys_ukn, /* 0x08 */ |
---|
| 34 | &_sys_ukn, /* 0x09 */ |
---|
| 35 | &_tty_read_irq, /* 0x0A */ |
---|
| 36 | &_sys_ukn, /* 0x0B */ |
---|
| 37 | &_sys_ukn, /* 0x0C */ |
---|
| 38 | &_ctx_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 | &_mwmr_base, /* 0x1A */ |
---|
| 52 | &_sys_ukn, /* 0x1B */ |
---|
| 53 | &_sys_ukn, /* 0x1C */ |
---|
| 54 | &_sys_ukn, /* 0x1D */ |
---|
| 55 | &_sys_ukn, /* 0x1E */ |
---|
| 56 | &_sys_ukn, /* 0x1F */ |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 60 | // function executed in case of undefined syscall |
---|
| 61 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 62 | void _sys_ukn() |
---|
| 63 | { |
---|
| 64 | unsigned int epc; |
---|
| 65 | asm volatile("mfc0 %0, $14" : "=r"(epc)); |
---|
| 66 | |
---|
| 67 | _puts("\n\n!!! Undefined System Call !!!\n"); |
---|
| 68 | _puts("\nEPC = "); |
---|
| 69 | _putw( epc ); |
---|
| 70 | _exit(); |
---|
| 71 | } |
---|
| 72 | //////////////////////////////////////////////////////////////////////////// |
---|
| 73 | // _exit() |
---|
| 74 | // Task suicide... after printing a death message. |
---|
| 75 | //////////////////////////////////////////////////////////////////////////// |
---|
| 76 | void _exit() |
---|
| 77 | { |
---|
| 78 | unsigned int proc_id = _procid(); |
---|
| 79 | unsigned int task_id = _scheduler[proc_id].current; |
---|
| 80 | |
---|
| 81 | // print death message |
---|
| 82 | _puts("\n\n!!! Exit task "); |
---|
| 83 | _putw( task_id ); |
---|
| 84 | _puts(" on processor "); |
---|
| 85 | _putw( proc_id ); |
---|
| 86 | |
---|
| 87 | /* infinite loop */ |
---|
| 88 | while (1) asm volatile("nop"); |
---|
| 89 | } |
---|
| 90 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 91 | // _procid() |
---|
| 92 | // Access CP0 and returns current processor's identifier. |
---|
| 93 | // Max number or processors is 1024. |
---|
| 94 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 95 | unsigned int _procid() |
---|
| 96 | { |
---|
| 97 | unsigned int ret; |
---|
| 98 | asm volatile("mfc0 %0, $15, 1" : "=r"(ret)); |
---|
| 99 | return (ret & 0x3FF); |
---|
| 100 | } |
---|
| 101 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 102 | // _proctime() |
---|
| 103 | // Access CP0 and returns current processor's elapsed clock cycles since boot. |
---|
| 104 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 105 | unsigned int _proctime() |
---|
| 106 | { |
---|
| 107 | unsigned int ret; |
---|
| 108 | asm volatile("mfc0 %0, $9" : "=r"(ret)); |
---|
| 109 | return ret; |
---|
| 110 | } |
---|
| 111 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 112 | // _procnumber() |
---|
| 113 | // returns in buffer argument the number of processors in the cluster |
---|
| 114 | // specified by the cluster_id argument. |
---|
| 115 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 116 | unsigned int _procs_number( unsigned int cluster_id, |
---|
| 117 | unsigned int* buffer) |
---|
| 118 | { |
---|
| 119 | mapping_header_t* header = (mapping_header_t*)&seg_boot_mapping_base; |
---|
| 120 | mapping_cluster_t* cluster = _get_cluster_base( header ); |
---|
| 121 | |
---|
| 122 | if ( cluster_id < header->clusters ) |
---|
| 123 | { |
---|
| 124 | *buffer = cluster[cluster_id].procs; |
---|
| 125 | return 0; |
---|
| 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
| 129 | return 1; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 133 | // _mwmr_base() |
---|
| 134 | // returns in buffer argument the base address of the MWMR channel |
---|
| 135 | // identified by the (vspace_name / channel_name) couple. |
---|
| 136 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 137 | unsigned int _mwmr_base( char* vspace_name, |
---|
| 138 | char* channel_name, |
---|
| 139 | unsigned int* buffer ) |
---|
| 140 | { |
---|
| 141 | mapping_header_t* header = (mapping_header_t*)&seg_boot_mapping_base; |
---|
| 142 | mapping_vspace_t* vspace = _get_vspace_base( header ); |
---|
| 143 | mapping_vseg_t* vseg = _get_vseg_base( header ); |
---|
| 144 | |
---|
| 145 | unsigned int vspace_id; |
---|
| 146 | unsigned int vseg_id; |
---|
| 147 | |
---|
| 148 | // scan vspaces |
---|
| 149 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 150 | { |
---|
| 151 | if ( _strncmp( vspace[vspace_id].name, vspace_name, 31) == 0 ) |
---|
| 152 | { |
---|
| 153 | // scan vsegs |
---|
| 154 | for ( vseg_id = vspace[vspace_id].vseg_offset ; |
---|
| 155 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; |
---|
| 156 | vseg_id++ ) |
---|
| 157 | { |
---|
| 158 | if ( _strncmp( vseg[vseg_id].name, channel_name, 31) == 0 ) |
---|
| 159 | { |
---|
| 160 | *buffer = vseg[vseg_id].vbase; |
---|
| 161 | return 0; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | // not found !!! |
---|
| 167 | return 1; |
---|
| 168 | } |
---|
| 169 | |
---|