/* * printk.c - Kernel Log & debug messages API implementation. * * authors Alain Greiner (2016) * * Copyright (c) UPMC Sorbonne Universites * * This file is part of ALMOS-MKH.. * * ALMOS-MKH. is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2.0 of the License. * * ALMOS-MKH. is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ALMOS-MKH.; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////////// // Extern variables /////////////////////////////////////////////////////////////////////////////////// extern chdev_t txt0_chdev; // allocated in kernel_init.c /////////////////////////////////////////////////////////////////////////////////// // This static function is called by kernel_printf() to display a string on the // TXT channel defined by the argument. // The access mode is defined by the argument: // - if is true, it uses the dev_txt_sync_write() function, that takes the // TXT lock, and call directly the relevant TXT driver, without descheduling. // - if >4))) break; } len = i + 1; pbuf = &buf[7 - i]; break; } case ('X'): /* 32 bits hexadecimal unsigned on 10 char */ { uint32_t val = va_arg( *args , uint32_t ); txt_write( channel, busy, "0x" , 2 ); for(i = 0; i < 8; i++) { buf[7 - i] = HexaTab[val & 0xF]; val = (val>>4); } len = 8; pbuf = buf; break; } case ('l'): /* 64 bits hexadecimal unsigned */ { uint64_t val = va_arg( *args , uint64_t ); txt_write( channel, busy, "0x" , 2 ); for(i = 0; i < 16; i++) { buf[15 - i] = HexaTab[val & 0xF]; if (!(val = (val>>4))) break; } len = i + 1; pbuf = &buf[15 - i]; break; } case ('L'): /* 64 bits hexadecimal unsigned on 18 char */ { uint64_t val = va_arg( *args , uint64_t ); txt_write( channel, busy, "0x" , 2 ); for(i = 0; i < 16; i++) { buf[15 - i] = HexaTab[val & 0xF]; val = (val>>4); } len = 16; pbuf = buf; break; } case ('s'): /* string */ { char* str = va_arg( *args , char* ); while (str[len]) { len++; } pbuf = str; break; } default: { txt_write( channel , busy, "\n[PANIC] in kernel_printf() : illegal format\n", 45 ); } } if( pbuf != NULL ) txt_write( channel, busy, pbuf, len ); goto printf_text; } } // end kernel_printf() ///////////////////////////////// void printk( char * format , ...) { va_list args; uint32_t save_sr; // get extended pointer on remote TXT0 chdev lock xptr_t txt0_lock_xp = XPTR( LOCAL_CLUSTER->io_cxy , &txt0_chdev.wait_lock ); // get TXT0 lock in busy waiting mode remote_spinlock_lock_busy( txt0_lock_xp , &save_sr ); // call kernel_printf in busy waiting mode va_start( args , format ); kernel_printf( 0 , 1 , format , &args ); va_end( args ); // release lock remote_spinlock_unlock_busy( txt0_lock_xp , save_sr ); } ////////////////////////////////////// void user_printk( char * format , ...) { va_list args; // get calling thread TXT channel TODO uint32_t channel = 0; // call kernel_printf in descheduling mode va_start( args , format ); kernel_printf( channel, 0 , format , &args ); va_end( args ); } /////////////////////////////////////////// inline void assert( bool_t condition, const char * function_name, char * string ) { if( condition == false ) { printk("\n[PANIC] in %s : %s\n" , function_name , string ); hal_core_sleep(); } } // Local Variables: // tab-width: 4 // c-basic-offset: 4 // c-file-offsets:((innamespace . 0)(inline-open . 0)) // indent-tabs-mode: nil // End: // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4