Changeset 455


Ignore:
Timestamp:
Dec 5, 2014, 3:34:16 PM (10 years ago)
Author:
alain
Message:

Introducing the tty0.c/tty0.h files defining access function to TTY0 (including the _printf().
Introducing the locks.c/locks.h files defining two types of spin-lock (with and without a waiting queue).

Location:
soft/giet_vm/giet_common
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_common/pmem.c

    r442 r455  
    66///////////////////////////////////////////////////////////////////////////////////
    77
     8#include <tty0.h>
    89#include <utils.h>
    910#include <pmem.h>
  • soft/giet_vm/giet_common/utils.c

    r442 r455  
    66///////////////////////////////////////////////////////////////////////////////////
    77// The utils.c and utils.h files are part of the GIET-VM nano-kernel.
    8 // They define more or less the GIET-VM HAL (Hardware Abstraction Layer),
    9 // and contains various utility functions, that can be used by both the
    10 // boot code and the kernel code.
    118///////////////////////////////////////////////////////////////////////////////////
    129
    1310#include <utils.h>
     11#include <tty0.h>
    1412#include <giet_config.h>
    1513#include <hard_config.h>
     
    411409}
    412410
    413 ///////////////////////////////////////////////////////////////////////////////////
    414 //                      Locks access functions
    415 ///////////////////////////////////////////////////////////////////////////////////
    416 
    417 ///////////////////////////////////
    418 void _get_lock( giet_lock_t* lock )
    419 {
    420     register unsigned int* plock = &(lock->value);
    421 
    422 #if NO_HARD_CC
    423 
    424     register unsigned int delay  = (_get_proctime() ^ _get_procid() << 4) & 0xFF;
    425     if (delay == 0) delay = 0x80;
    426 
    427     asm volatile (
    428             "_lock_llsc:             \n"
    429             "    ll   $2,    0(%0)       \n" /* $2 <= lock current value         */
    430             "    bnez $2,    _lock_delay \n" /* delay if lock already taken      */
    431             "    li   $3,    1           \n" /* $3 <= argument for sc            */
    432             "    sc   $3,    0(%0)       \n" /* try to set lock                  */
    433             "    bnez $3,    _lock_ok    \n" /* exit if atomic                   */
    434             "    _lock_delay:            \n"
    435             "    move $4,    %1          \n" /* $4 <= delay                      */
    436             "    _lock_loop:             \n"
    437             "    addi $4,    $4,    -1   \n" /* $4 <= $4 - 1                     */
    438             "    bnez $4,    _lock_loop  \n" /* test end delay                   */
    439             "    nop                     \n"
    440             "    j           _lock_llsc  \n" /* retry                            */
    441             "    nop                     \n"
    442             "    _lock_ok:               \n"
    443             :
    444             :"r"(plock), "r"(delay)
    445             :"$2", "$3", "$4", "memory");
    446 #else
    447 
    448     asm volatile (
    449             "_lock_llsc:                 \n"
    450             "    lw   $2,    0(%0)       \n" /* $2 <= lock current value         */
    451             "    bnez $2,    _lock_llsc  \n" /* retry if lock already taken      */
    452             "    nop                     \n"
    453             "    ll   $2,    0(%0)       \n" /* ll_buffer <= lock current value  */
    454             "    bnez $2,    _lock_llsc  \n" /* retry if lock already taken      */
    455             "    li   $3,    1           \n" /* $3 <= argument for sc            */
    456             "    sc   $3,    0(%0)       \n" /* try to set lock                  */
    457             "    beqz $3,    _lock_llsc  \n" /* retry if sc failure              */
    458             "    nop                     \n"
    459             :
    460             :"r"(plock)
    461             :"$2", "$3", "memory");
    462 #endif
    463 
    464 }
    465 
    466 ///////////////////////////////////////
    467 void _release_lock( giet_lock_t* lock )
    468 {
    469     asm volatile ( "sync\n" ::: "memory" );
    470     // sync is necessary because of the TSAR consistency model
    471     lock->value = 0;
    472 }
    473 
    474 ///////////////////////////////////////////////////////////////////////////////////
    475 //           Access functions to kernel terminal TTY0
    476 ///////////////////////////////////////////////////////////////////////////////////
    477 
    478 //////////////////////////
    479 void _puts( char* string )
    480 {
    481     unsigned int n = 0;
    482 
    483     while ( string[n] > 0 )
    484     {
    485         // test status register
    486         while ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) );
    487 
    488         // write one byte
    489         if ( string[n] == '\n') {
    490             _tty_set_register( 0, TTY_WRITE, (unsigned int)'\r' );
    491         }
    492         _tty_set_register( 0, TTY_WRITE, (unsigned int)string[n] );
    493         n++;
    494     }
    495 }
    496 
    497 //////////////////////////////
    498 void _putx( unsigned int val )
    499 {
    500     static const char HexaTab[] = "0123456789ABCDEF";
    501     char buf[11];
    502     unsigned int c;
    503 
    504     buf[0] = '0';
    505     buf[1] = 'x';
    506     buf[10] = 0;
    507 
    508     for (c = 0; c < 8; c++)
    509     {
    510         buf[9 - c] = HexaTab[val & 0xF];
    511         val = val >> 4;
    512     }
    513     _puts( buf );
    514 }
    515 
    516 ////////////////////////////////////
    517 void _putl( unsigned long long val )
    518 {
    519     static const char HexaTab[] = "0123456789ABCDEF";
    520     char buf[19];
    521     unsigned int c;
    522 
    523     buf[0] = '0';
    524     buf[1] = 'x';
    525     buf[18] = 0;
    526 
    527     for (c = 0; c < 16; c++)
    528     {
    529         buf[17 - c] = HexaTab[(unsigned int)val & 0xF];
    530         val = val >> 4;
    531     }
    532     _puts( buf );
    533 }
    534 
    535 //////////////////////////////
    536 void _putd( unsigned int val )
    537 {
    538     static const char DecTab[] = "0123456789";
    539     char buf[11];
    540     unsigned int i;
    541     unsigned int first = 0;
    542 
    543     buf[10] = 0;
    544 
    545     for (i = 0; i < 10; i++)
    546     {
    547         if ((val != 0) || (i == 0))
    548         {
    549             buf[9 - i] = DecTab[val % 10];
    550             first = 9 - i;
    551         }
    552         else
    553         {
    554             break;
    555         }
    556         val /= 10;
    557     }
    558     _puts( &buf[first] );
    559 }
    560 
    561 /////////////////////////
    562 void _getc( char*  byte )
    563 {
    564     // test status register
    565     while ( _tty_get_register( 0, TTY_STATUS ) == 0 );
    566 
    567     // read one byte
    568     *byte = (char)_tty_get_register( 0, TTY_READ );
    569 }
    570411
    571412
     
    767608    _puts(",");
    768609    _putd( lpid );
    769     _puts("] exit at cycle");
     610    _puts("] exit at cycle ");
    770611    _putd( _get_proctime() );
    771612    _puts(" ...\n");
  • soft/giet_vm/giet_common/utils.h

    r442 r455  
    66///////////////////////////////////////////////////////////////////////////////////
    77// The utils.c and utils.h files are part of the GIET-VM nano-kernel.
    8 // They define more or less the GIET-VM Hardware Abstraction Layer,
    9 // and contains various utility functions, that can be used by both the
     8// They define various utility functions, that can be used by both the
    109// boot code and the kernel code (but not by the user applications).
    1110///////////////////////////////////////////////////////////////////////////////////
     
    2120
    2221#define NULL (void *)0
    23 
    24 ///////////////////////////////////////////////////////////////////////////////////
    25 // This structure is used to have one single lock in a cache line
    26 ///////////////////////////////////////////////////////////////////////////////////
    27 
    28 typedef struct giet_lock_s { unsigned int value;
    29                              unsigned int padding[15]; } giet_lock_t;
    3022
    3123///////////////////////////////////////////////////////////////////////////////////
     
    109101extern void         _io_extended_write( unsigned int* vaddr,
    110102                                        unsigned int  value );
    111 
    112 ///////////////////////////////////////////////////////////////////////////////////
    113 //      Locks access functions
    114 ///////////////////////////////////////////////////////////////////////////////////
    115 
    116 extern void         _get_lock(giet_lock_t* lock);
    117 
    118 extern void         _release_lock(giet_lock_t* lock);
    119 
    120 ///////////////////////////////////////////////////////////////////////////////////
    121 //       Access functions to kernel terminal TTY0
    122 ///////////////////////////////////////////////////////////////////////////////////
    123 
    124 extern void         _puts( char*  string );
    125 
    126 extern void         _putx( unsigned int val );
    127 
    128 extern void         _putl( unsigned long long val );
    129 
    130 extern void         _putd( unsigned int val );
    131 
    132 extern void         _getc( char* byte );       
    133 
    134103
    135104///////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_common/vmem.c

    r442 r455  
    66///////////////////////////////////////////////////////////////////////////////////
    77
     8#include <tty0.h>
    89#include <utils.h>
    910#include <vmem.h>
Note: See TracChangeset for help on using the changeset viewer.