Changeset 5 for trunk/kernel/kern/printk.c
- Timestamp:
- Apr 26, 2017, 2:11:56 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/printk.c
r1 r5 24 24 #include <hal_types.h> 25 25 #include <hal_irqmask.h> 26 #include <printk.h> 27 #include <stdarg.h> 26 #include <hal_special.h> 28 27 #include <dev_txt.h> 29 28 #include <remote_spinlock.h> 30 29 #include <cluster.h> 30 #include <printk.h> 31 31 32 32 /////////////////////////////////////////////////////////////////////////////////// 33 // This static function is called by printk(), nolock_printk() and user_printk() 33 // This static function is called by kernel_printf() to display a string on the 34 // TXT channel defined by the <channel> argument. 35 // The access mode is defined by the <busy> argument: 36 // - if <busy> is true, it uses the dev_txt_sync_write() function, that takes the 37 // TXT lock, and call directly the relevant TXT driver, without descheduling. 38 // - if <busy is false, it uses the dev_txt_write() function, that register the 39 // write buffer in the relevant TXT chdev queue, and uses a descheduling policy. 34 40 /////////////////////////////////////////////////////////////////////////////////// 41 // @ channel : TXT channel. 42 // @ busy : TXT device acces mode. 43 // @ buf : buffer containing the characters. 44 // @ nc : number of characters. 45 // return 0 if success / return -1 if TTY0 busy after 10000 retries. 46 /////////////////////////////////////////////////////////////////////////////////// 47 static error_t txt_write( uint32_t channel, 48 uint32_t busy, 49 char * buffer, 50 uint32_t count ) 51 { 52 if( busy ) return dev_txt_sync_write( channel , buffer , count ); 53 else return dev_txt_write( channel , buffer , count ); 54 } 55 56 ////////////////////////////////////////////////////////////////////////////////////// 57 // This static function is called by printk() and user_printk() to build 58 // a formated string. 59 ////////////////////////////////////////////////////////////////////////////////////// 60 // @ channel : channel index. 61 // @ busy : TXT device access mode. 62 // @ format : printf like format. 63 // @ args : format arguments. 64 ////////////////////////////////////////////////////////////////////////////////////// 35 65 static void kernel_printf( uint32_t channel, 66 uint32_t busy, 36 67 char * format, 37 68 va_list * args ) … … 46 77 if (i) 47 78 { 48 dev_txt_sync_write( channel, format, i );79 txt_write( channel, busy, format, i ); 49 80 format += i; 50 81 } … … 83 114 { 84 115 val = -val; 85 dev_txt_sync_write( channel, "-" , 1 );116 txt_write( channel, busy, "-" , 1 ); 86 117 } 87 118 for(i = 0; i < 10; i++) … … 109 140 { 110 141 uint32_t val = va_arg( *args , uint32_t ); 111 dev_txt_sync_write( channel, "0x" , 2 );142 txt_write( channel, busy, "0x" , 2 ); 112 143 for(i = 0; i < 8; i++) 113 144 { 114 buf[7 - i] = HexaTab[val % 16];145 buf[7 - i] = HexaTab[val & 0xF]; 115 146 if (!(val = (val>>4))) break; 116 147 } … … 119 150 break; 120 151 } 121 case ('X'): /* 32 bits hexadecimal unsigned on 10 char */152 case ('X'): /* 32 bits hexadecimal unsigned on 10 char */ 122 153 { 123 154 uint32_t val = va_arg( *args , uint32_t ); 124 dev_txt_sync_write( channel, "0x" , 2 );155 txt_write( channel, busy, "0x" , 2 ); 125 156 for(i = 0; i < 8; i++) 126 157 { 127 buf[7 - i] = HexaTab[val % 16];158 buf[7 - i] = HexaTab[val & 0xF]; 128 159 val = (val>>4); 129 160 } … … 135 166 { 136 167 uint64_t val = va_arg( *args , uint64_t ); 137 dev_txt_sync_write( channel, "0x" , 2 );168 txt_write( channel, busy, "0x" , 2 ); 138 169 for(i = 0; i < 16; i++) 139 170 { 140 buf[15 - i] = HexaTab[val % 16];141 if (!(val /= 16)) break;171 buf[15 - i] = HexaTab[val & 0xF]; 172 if (!(val = (val>>4))) break; 142 173 } 143 174 len = i + 1; 144 175 pbuf = &buf[15 - i]; 176 break; 177 } 178 case ('L'): /* 64 bits hexadecimal unsigned on 18 char */ 179 { 180 uint64_t val = va_arg( *args , uint64_t ); 181 txt_write( channel, busy, "0x" , 2 ); 182 for(i = 0; i < 16; i++) 183 { 184 buf[15 - i] = HexaTab[val & 0xF]; 185 val = (val>>4); 186 } 187 len = 16; 188 pbuf = buf; 145 189 break; 146 190 } … … 157 201 default: 158 202 { 159 dev_txt_sync_write( channel,160 203 txt_write( channel , busy, 204 "\n[PANIC] in kernel_printf() : illegal format\n", 45 ); 161 205 } 162 206 } 163 207 164 if( pbuf != NULL ) dev_txt_sync_write( channel, pbuf, len );208 if( pbuf != NULL ) txt_write( channel, busy, pbuf, len ); 165 209 166 210 goto printf_text; … … 169 213 } // end kernel_printf() 170 214 171 //////////////////////////////// ///////172 void nolock_printk( char* format, ...)173 { 174 va_list args;215 //////////////////////////////// 216 void printk( char * format, ...) 217 { 218 va_list args; 175 219 176 220 // call kernel_printf 177 221 va_start( args , format ); 178 kernel_printf( 0 , format , &args );222 kernel_printf( 0 , 1 , format , &args ); 179 223 va_end( args ); 180 224 } 181 225 182 //////////////////////////////// 183 void printk( char* format, ...) 184 { 185 va_list args; 186 uint32_t save_sr; 187 188 // disable IRQs 189 hal_disable_irq( &save_sr ); 190 191 // get TXT0 lock 192 cluster_t * cluster = LOCAL_CLUSTER; 193 remote_spinlock_lock( XPTR( cluster->io_cxy , &cluster->txt0_lock ) ); 226 ///////////////////////////////////// 227 void user_printk( char* format, ...) 228 { 229 va_list args; 230 231 // get calling thread TXT channel TODO 232 uint32_t channel = 0; 194 233 195 234 // call kernel_printf 196 235 va_start( args , format ); 197 kernel_printf( 0, format , &args ); 198 va_end( args ); 199 200 // release TXT0 lock 201 remote_spinlock_unlock( XPTR( cluster->io_cxy , &cluster->txt0_lock ) ); 202 203 // restore IRQs 204 hal_restore_irq( save_sr ); 205 } 206 207 ///////////////////////////////////// 208 void user_printk( char* format, ...) 209 { 210 va_list args; 211 212 // get calling thread TXT channel TODO 213 uint32_t channel = 0; 214 215 // call kernel_printf 216 va_start( args , format ); 217 kernel_printf( channel, format , &args ); 236 kernel_printf( channel, 0 , format , &args ); 218 237 va_end( args ); 219 238 } 220 239 221 240 /////////////////////////////////////////// 241 inline void assert( bool_t condition, 242 const char * function_name, 243 char * string ) 244 { 245 if( condition == false ) 246 { 247 printk("\n[PANIC] in %s : %s\n" , function_name , string ); 248 hal_core_sleep(); 249 } 250 } 222 251 223 252 // Local Variables:
Note: See TracChangeset
for help on using the changeset viewer.