Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (7 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/printk.c

    r406 r407  
    190190        goto xprintf_text;
    191191    }
    192 } // end xprintf()
    193 
    194 ///////////////////////////////////////////////////////////////////////////////////
    195 // This static function is called by kernel_printf() to display a string on the
    196 // TXT channel defined by the <channel> argument.
    197 // The access mode is defined by the <busy> argument:
    198 // - if <busy> is true, it uses the dev_txt_sync_write() function, that takes the
    199 //   TXT lock, and call directly the relevant TXT driver, without descheduling.
    200 // - if <busy is false, it uses the dev_txt_write() function, that register the
    201 //   write buffer in the relevant TXT chdev queue, and uses a descheduling policy.
    202 ///////////////////////////////////////////////////////////////////////////////////
    203 // @ channel  : TXT channel.
    204 // @ busy     : TXT device acces mode (busy waiting if non zero).
    205 // @ buf      : buffer containing the characters.
    206 // @ nc       : number of characters.
    207 // return 0 if success / return -1 if TTY0 busy after 10000 retries.
    208 ///////////////////////////////////////////////////////////////////////////////////
    209 static error_t txt_write( uint32_t  channel,
    210                           uint32_t  busy,
    211                           char    * buffer,
    212                           uint32_t  count )
    213 {
    214     if( busy ) return dev_txt_sync_write( channel , buffer , count );
    215     else       return dev_txt_write( channel , buffer , count );
    216 
     192} // end snprintf()
    217193
    218194//////////////////////////////////////////////////////////////////////////////////////
    219 // This static function is called by printk(), assert() and nolock_printk() to build
    220 // a formated string.
     195// This static function is called by printk(), assert() and nolock_printk()
     196// to display a formated string on TXT0, using a busy waiting policy.
    221197//////////////////////////////////////////////////////////////////////////////////////
    222 // @ channel   : channel index.
    223 // @ busy      : TXT device access mode (busy waiting if non zero).
    224198// @ format    : printf like format.
    225 // @ args      : format arguments.
     199// @ args      : va_list of arguments.
    226200//////////////////////////////////////////////////////////////////////////////////////
    227 static void kernel_printf( uint32_t   channel,
    228                            uint32_t   busy,
    229                            char     * format,
     201static void kernel_printf( char     * format,
    230202                           va_list  * args )
    231203{
     
    239211        if (i)
    240212        {
    241             txt_write( channel, busy, format, i );
     213            dev_txt_sync_write( format, i );
    242214            format += i;
    243215        }
     
    276248                {
    277249                    val = -val;
    278                     txt_write( channel, busy, "-" , 1 );
     250                    dev_txt_sync_write( "-" , 1 );
    279251                }
    280252                for(i = 0; i < 10; i++)
     
    302274            {
    303275                uint32_t val = va_arg( *args , uint32_t );
    304                 txt_write( channel, busy, "0x" , 2 );
     276                dev_txt_sync_write( "0x" , 2 );
    305277                for(i = 0; i < 8; i++)
    306278                {
     
    315287            {
    316288                uint32_t val = va_arg( *args , uint32_t );
    317                 txt_write( channel, busy, "0x" , 2 );
     289                dev_txt_sync_write( "0x" , 2 );
    318290                for(i = 0; i < 8; i++)
    319291                {
     
    328300            {
    329301                unsigned long long val = va_arg( *args , unsigned long long );
    330                 txt_write( channel, busy, "0x" , 2 );
     302                dev_txt_sync_write( "0x" , 2 );
    331303                for(i = 0; i < 16; i++)
    332304                {
     
    341313            {
    342314                unsigned long long val = va_arg( *args , unsigned long long );
    343                 txt_write( channel, busy, "0x" , 2 );
     315                dev_txt_sync_write( "0x" , 2 );
    344316                for(i = 0; i < 16; i++)
    345317                {
     
    363335            default:
    364336            {
    365                 txt_write( channel , busy,
    366                            "\n[PANIC] in kernel_printf() : illegal format\n", 45 );
    367             }
    368         }
    369 
    370         if( pbuf != NULL ) txt_write( channel, busy, pbuf, len );
     337                dev_txt_sync_write( "\n[PANIC] in kernel_printf() : illegal format\n", 45 );
     338            }
     339        }
     340
     341        if( pbuf != NULL ) dev_txt_sync_write( pbuf, len );
    371342       
    372343        goto printf_text;
     
    382353
    383354    // get pointers on TXT0 chdev
    384     xptr_t    txt0_xp  = chdev_dir.txt[0];
     355    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
    385356    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
    386357    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
     
    394365    // call kernel_printf on TXT0, in busy waiting mode
    395366    va_start( args , format );
    396     kernel_printf( 0 , 1 , format , &args );
     367    kernel_printf( format , &args );
    397368    va_end( args );
    398369
     
    408379    // call kernel_printf on TXT0, in busy waiting mode
    409380    va_start( args , format );
    410     kernel_printf( 0 , 1 , format , &args );
     381    kernel_printf( format , &args );
    411382    va_end( args );
    412383}
     
    419390
    420391    // get pointers on TXT0 chdev
    421     xptr_t    txt0_xp  = chdev_dir.txt[0];
     392    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
    422393    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
    423394    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
     
    431402    // call kernel_printf on TXT0, in busy waiting mode
    432403    va_start( args , format );
    433     kernel_printf( 0 , 1 , format , &args );
     404    kernel_printf( format , &args );
    434405    va_end( args );
    435406
     
    456427    {
    457428        // get pointers on TXT0 chdev
    458         xptr_t    txt0_xp  = chdev_dir.txt[0];
     429        xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
    459430        cxy_t     txt0_cxy = GET_CXY( txt0_xp );
    460431        chdev_t * txt0_ptr = GET_PTR( txt0_xp );
     
    471442        // call kernel_printf on TXT0, in busy waiting to print format
    472443        va_start( args , format );
    473         kernel_printf( 0 , 1 , format , &args );
     444        kernel_printf( format , &args );
    474445        va_end( args );
    475446
Note: See TracChangeset for help on using the changeset viewer.