Ignore:
Timestamp:
Jul 4, 2012, 2:51:18 PM (12 years ago)
Author:
alain
Message:

Introducing various modifications in kernel initialisation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/libs/stdio.c

    r160 r165  
    1717#define SYSCALL_TTY_WRITE       0x02
    1818#define SYSCALL_TTY_READ        0x03
    19 #define SYSCALL_TIMER_WRITE     0x04
    20 #define SYSCALL_TIMER_READ      0x05
    2119#define SYSCALL_GCD_WRITE       0x06
    2220#define SYSCALL_GCD_READ        0x07
     
    3735
    3836//////////////////////////////////////////////////////////////////////////////////
    39 //      sys_call()
     37// sys_call()
    4038// This generic C function is used to implement all system calls.
     39// It writes the system call arguments in the proper registers,
     40// and tells GCC what has been modified by system call execution.
    4141//////////////////////////////////////////////////////////////////////////////////
    4242static inline unsigned int sys_call( unsigned int call_no,
     
    8383
    8484////////////////////////////////////////////////////////////////////////////////////
    85 //      procid()
     85// giet_procid()
     86////////////////////////////////////////////////////////////////////////////////////
    8687// This function returns the processor identifier.
    8788////////////////////////////////////////////////////////////////////////////////////
    88 unsigned int procid()
     89unsigned int giet_procid()
    8990{
    9091    return sys_call(SYSCALL_PROCID,
     
    9293}
    9394////////////////////////////////////////////////////////////////////////////////////
    94 //      proctime()
     95// giet_proctime()
     96////////////////////////////////////////////////////////////////////////////////////
    9597// This function returns the local processor time (clock cycles since boot)
    9698////////////////////////////////////////////////////////////////////////////////////
    97 unsigned int proctime()
     99unsigned int giet_proctime()
    98100{
    99101    return sys_call(SYSCALL_PROCTIME,
     
    104106
    105107////////////////////////////////////////////////////////////////////////////////////
    106 //      tty_putc()
     108// giet_tty_putc()
     109////////////////////////////////////////////////////////////////////////////////////
    107110// This function displays a single ascii character on a terminal.
    108111// The terminal index must be defined in the task context in the boot phase.
     
    110113// - Returns 1 if the character has been written, 0 otherwise.
    111114////////////////////////////////////////////////////////////////////////////////////
    112 unsigned int tty_putc(char byte)
     115unsigned int giet_tty_putc(char byte)
    113116{
    114117    return sys_call(SYSCALL_TTY_WRITE,
     
    118121}
    119122////////////////////////////////////////////////////////////////////////////////////
    120 //       tty_puts()
     123// giet_tty_puts()
     124////////////////////////////////////////////////////////////////////////////////////
    121125// This function displays a string on a terminal.
    122126// The terminal index must be defined in the task context in the boot phase.
     
    125129// - Returns the number of written characters.
    126130////////////////////////////////////////////////////////////////////////////////////
    127 unsigned int tty_puts(char *buf)
     131unsigned int giet_tty_puts(char *buf)
    128132{
    129133    unsigned int length = 0;
     
    138142}
    139143////////////////////////////////////////////////////////////////////////////////////
    140 //      tty_putw()
     144// giet_tty_putw()
     145////////////////////////////////////////////////////////////////////////////////////
    141146// This function displays the value of a 32-bit word with decimal characters.
    142147// The terminal index must be defined in the task context in the boot phase.
     
    144149// Returns the number of written characters (should be equal to ten).
    145150////////////////////////////////////////////////////////////////////////////////////
    146 unsigned int tty_putw(unsigned int val)
     151unsigned int giet_tty_putw(unsigned int val)
    147152{
    148153    char buf[10];
     
    160165
    161166////////////////////////////////////////////////////////////////////////////////////
    162 // tty_getc()
     167// giet_tty_getc_no_irq()
     168////////////////////////////////////////////////////////////////////////////////////
    163169// This blocking function fetches a single ascii character from a terminal.
    164170// The terminal index must be defined in the task context in the boot phase.
     
    166172// - Returns necessarily 0 when completed.
    167173////////////////////////////////////////////////////////////////////////////////////
    168 unsigned int tty_getc(char *byte)
     174unsigned int giet_tty_getc_no_irq(char *byte)
    169175{
    170176    unsigned int ret = 0;
     
    179185}
    180186////////////////////////////////////////////////////////////////////////////////////
    181 //       tty_getc_irq()
     187// giet_tty_getc()
     188////////////////////////////////////////////////////////////////////////////////////
    182189// This blocking function fetches a single ascii character from a terminal.
    183190// The terminal index must be defined in the task context in the boot phase.
     
    185192// - Returns 0 when completed.
    186193////////////////////////////////////////////////////////////////////////////////////
    187 unsigned int tty_getc_irq(char *byte)
     194unsigned int giet_tty_getc(char *byte)
    188195{
    189196    unsigned int ret = 0;
     
    198205}
    199206////////////////////////////////////////////////////////////////////////////////////
    200 //      tty_gets_irq()
     207// giet_tty_gets()
     208////////////////////////////////////////////////////////////////////////////////////
    201209// This blocking function fetches a string from a terminal to a fixed length buffer.
    202210// The terminal index must be defined in the task context in the boot phase.
     
    211219//   removed from the target buffer.
    212220////////////////////////////////////////////////////////////////////////////////////
    213 unsigned int tty_gets_irq(char *buf, unsigned int bufsize)
     221unsigned int giet_tty_gets( char*                       buf,
     222                            unsigned int        bufsize )
    214223{
    215224    unsigned int ret;
     
    240249}
    241250////////////////////////////////////////////////////////////////////////////////////
    242 //      tty_getw_irq()
     251// giet_tty_getw()
     252////////////////////////////////////////////////////////////////////////////////////
    243253// This blocking function fetches a string of decimal characters (most
    244254// significant digit first) to build a 32-bit unsigned integer.
     
    256266//   bits range, the zero value is returned.
    257267////////////////////////////////////////////////////////////////////////////////////
    258 unsigned int tty_getw_irq(unsigned int *val)
     268unsigned int giet_tty_getw(unsigned int *val)
    259269{
    260270    unsigned char buf[32];
     
    281291            buf[max] = byte;
    282292            max++;
    283             tty_putc(byte);
     293            giet_tty_putc(byte);
    284294        }
    285295        else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */
     
    292302            {
    293303                max--; /* cancel the character */
    294                 tty_putc(0x08);
    295                 tty_putc(0x20);
    296                 tty_putc(0x08);
     304                giet_tty_putc(0x08);
     305                giet_tty_putc(0x20);
     306                giet_tty_putc(0x08);
    297307            }
    298308        }
     
    301311            for (i = 0; i < max; i++) /* cancel the string */
    302312            {
    303                 tty_putc(0x08);
    304                 tty_putc(0x20);
    305                 tty_putc(0x08);
     313                giet_tty_putc(0x08);
     314                giet_tty_putc(0x20);
     315                giet_tty_putc(0x08);
    306316            }
    307             tty_putc(0x30);
     317            giet_tty_putc(0x30);
    308318            *val = 0; /* return 0 value */
    309319            return 0;
     
    329339        for (i = 0; i < max; i++) /* cancel the string */
    330340        {
    331             tty_putc(0x08);
    332             tty_putc(0x20);
    333             tty_putc(0x08);
    334         }
    335         tty_putc(0x30);
     341            giet_tty_putc(0x08);
     342            giet_tty_putc(0x20);
     343            giet_tty_putc(0x08);
     344        }
     345        giet_tty_putc(0x30);
    336346        *val = 0; /* return 0 value */
    337347    }
     
    339349}
    340350////////////////////////////////////////////////////////////////////////////////////
    341 // tty_printf()
     351// giet_tty_printf()
     352////////////////////////////////////////////////////////////////////////////////////
    342353// This function is a simplified version of the mutek_printf() function.
    343354// The terminal index must be defined in the calling task context.
     
    351362// - Returns 0 if success, > 0 if error.
    352363////////////////////////////////////////////////////////////////////////////////////
    353 unsigned int tty_printf(char *format, ...)
     364unsigned int giet_tty_printf(char *format, ...)
    354365{
    355366    va_list ap;
     
    450461}
    451462
    452 /////  Timer device related system calls /////
    453 
    454 #define TIMER_VALUE     0
    455 #define TIMER_MODE      1
    456 #define TIMER_PERIOD    2
    457 #define TIMER_RESETIRQ  3
    458 
    459 /*
    460  * timer_set_mode()
    461  *
    462  * This function defines the operation mode of a timer. The possible values for
    463  * this mode are:
    464  * - 0x0 : Timer not activated
    465  * - 0x1 : Timer activated, but no interrupt is generated
    466  * - 0x3 : Timer activarted and periodic interrupts generated
    467  *
    468  * - Returns 0 if success, > 0 if error.
    469  */
    470 unsigned int timer_set_mode(unsigned int val)
    471 {
    472     return sys_call(SYSCALL_TIMER_WRITE,
    473             TIMER_MODE,
    474             val,
    475             0, 0);
    476 }
    477 
    478 /*
    479  * timer_set_period()
    480  *
    481  * This function defines the period value of a timer to enable a periodic
    482  * interrupt.
    483  * - Returns 0 if success, > 0 if error.
    484  */
    485 unsigned int timer_set_period(unsigned int val)
    486 {
    487     return sys_call(SYSCALL_TIMER_WRITE,
    488             TIMER_PERIOD,
    489             val,
    490             0, 0);
    491 }
    492 
    493 /*
    494  * timer_reset_irq()
    495  *
    496  * This function resets the interrupt signal issued by a timer.
    497  * - Returns 0 if success, > 0 if error.
    498  */
    499 unsigned int timer_reset_irq()
    500 {
    501     return sys_call(SYSCALL_TIMER_WRITE,
    502             TIMER_RESETIRQ,
    503             0, 0, 0);
    504 }
    505 
    506 /*
    507  * timer_get_time()
    508  *
    509  * This function returns the current timing value of a timer.
    510  * - Returns 0 if success, > 0 if error.
    511  */
    512 unsigned int timer_get_time(unsigned int *time)
    513 {
    514     return sys_call(SYSCALL_TIMER_READ,
    515             TIMER_VALUE,
    516             (unsigned int)time,
    517             0, 0);
    518 }
    519 
    520 /////  GCD (Greatest Common Divider) device related system calls
     463/////  GCD (Greatest Common Divider) related system calls
    521464
    522465#define GCD_OPA     0
     
    526469
    527470//////////////////////////////////////////////////////////////////////////////////
    528 //      gcd_set_opa()
     471// giet_gcd_set_opa()
     472//////////////////////////////////////////////////////////////////////////////////
    529473// This function sets the operand A in the GCD coprocessor.
    530474// - Returns 0 if success, > 0 if error.
    531475//////////////////////////////////////////////////////////////////////////////////
    532 unsigned int gcd_set_opa(unsigned int val)
     476unsigned int giet_gcd_set_opa(unsigned int val)
    533477{
    534478    return sys_call(SYSCALL_GCD_WRITE,
     
    538482}
    539483//////////////////////////////////////////////////////////////////////////////////
    540 //      gcd_set_opb()
     484//      giet_gcd_set_opb()
     485//////////////////////////////////////////////////////////////////////////////////
    541486// This function sets operand B in the GCD coprocessor.
    542487// - Returns 0 if success, > 0 if error.
    543488//////////////////////////////////////////////////////////////////////////////////
    544 unsigned int gcd_set_opb(unsigned int val)
     489unsigned int giet_gcd_set_opb(unsigned int val)
    545490{
    546491    return sys_call(SYSCALL_GCD_WRITE,
     
    550495}
    551496//////////////////////////////////////////////////////////////////////////////////
    552 //      gcd_start()
     497//      giet_gcd_start()
     498//////////////////////////////////////////////////////////////////////////////////
    553499// This function starts the computation in the GCD coprocessor.
    554500// - Returns 0 if success, > 0 if error.
    555501//////////////////////////////////////////////////////////////////////////////////
    556 unsigned int gcd_start()
     502unsigned int giet_gcd_start()
    557503{
    558504    return sys_call(SYSCALL_GCD_WRITE,
     
    561507}
    562508//////////////////////////////////////////////////////////////////////////////////
    563 //      gcd_get_status()
     509//      giet_gcd_get_status()
     510//////////////////////////////////////////////////////////////////////////////////
    564511// This function gets the status fromn the GCD coprocessor.
    565512// - The value is 0 when the coprocessor is idle (computation completed).
    566513//////////////////////////////////////////////////////////////////////////////////
    567 unsigned int gcd_get_status(unsigned int *val)
     514unsigned int giet_gcd_get_status(unsigned int *val)
    568515{
    569516    return sys_call(SYSCALL_GCD_READ,
     
    573520}
    574521//////////////////////////////////////////////////////////////////////////////////
    575 //      gcd_get_result()
     522//      giet_gcd_get_result()
     523//////////////////////////////////////////////////////////////////////////////////
    576524// This function gets the result of the computation from the GCD coprocessor.
    577525//////////////////////////////////////////////////////////////////////////////////
    578 unsigned int gcd_get_result(unsigned int *val)
     526unsigned int giet_gcd_get_result(unsigned int *val)
    579527{
    580528    return sys_call(SYSCALL_GCD_READ,
     
    587535
    588536//////////////////////////////////////////////////////////////////////////////////
    589 //      ioc_write()
     537//      giet_ioc_write()
     538//////////////////////////////////////////////////////////////////////////////////
    590539// Transfer data from a memory buffer to a file on the block_device.
    591540//     lba    : Logical Block Address (first block index)
     
    594543// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    595544//////////////////////////////////////////////////////////////////////////////////
    596 unsigned int ioc_write(unsigned int lba, void *buffer, unsigned int count)
     545unsigned int giet_ioc_write( unsigned int       lba,
     546                             void*                      buffer,
     547                             unsigned int       count)
    597548{
    598549    return sys_call(SYSCALL_IOC_WRITE,
     
    603554}
    604555//////////////////////////////////////////////////////////////////////////////////
    605 //      ioc_read()
     556// giet_ioc_read()
     557//////////////////////////////////////////////////////////////////////////////////
    606558// Transfer data from a file on the block_device to a memory buffer.
    607559//     lba    : Logical Block Address (first block index)
     
    610562// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    611563//////////////////////////////////////////////////////////////////////////////////
    612 unsigned int ioc_read(unsigned int lba, void *buffer, unsigned int count)
     564unsigned int giet_ioc_read( unsigned int                lba,
     565                            void*                               buffer,
     566                            unsigned int                count )
    613567{
    614568    return sys_call(SYSCALL_IOC_READ,
     
    619573}
    620574//////////////////////////////////////////////////////////////////////////////////
    621 //      ioc_completed()
     575// giet_ioc_completed()
     576//////////////////////////////////////////////////////////////////////////////////
    622577// This blocking function returns 0 when the I/O transfer is
    623578// successfully completed, and returns 1 if an address error has been detected.
    624579//////////////////////////////////////////////////////////////////////////////////
    625 unsigned int ioc_completed()
     580unsigned int giet_ioc_completed()
    626581{
    627582    return sys_call(SYSCALL_IOC_COMPLETED,
     
    632587
    633588//////////////////////////////////////////////////////////////////////////////////
    634 //      fb_sync_write()
     589// giet_fb_sync_write()
     590//////////////////////////////////////////////////////////////////////////////////
    635591// This blocking function use a memory copy strategy to transfer data from a
    636592// user buffer to the frame buffer device in kernel space.
     
    640596// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    641597//////////////////////////////////////////////////////////////////////////////////
    642 unsigned int fb_sync_write(unsigned int offset, void *buffer, unsigned int length)
     598unsigned int giet_fb_sync_write( unsigned int   offset,
     599                                 void*                  buffer,
     600                                 unsigned int   length )
    643601{
    644602    return sys_call(SYSCALL_FB_SYNC_WRITE,
     
    649607}
    650608//////////////////////////////////////////////////////////////////////////////////
    651 //      fb_sync_read()
     609// giet_fb_sync_read()
     610//////////////////////////////////////////////////////////////////////////////////
    652611// This blocking function use a memory copy strategy to transfer data from the
    653612// frame buffer device in kernel space to an user buffer.
     
    657616// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    658617//////////////////////////////////////////////////////////////////////////////////
    659 unsigned int fb_sync_read(unsigned int offset, void *buffer, unsigned int length)
     618unsigned int giet_fb_sync_read( unsigned int    offset,
     619                                void*                   buffer,
     620                                unsigned int    length )
    660621{
    661622    return sys_call(SYSCALL_FB_SYNC_READ,
     
    666627}
    667628//////////////////////////////////////////////////////////////////////////////////
    668 //      fb_write()
     629// giet_fb_write()
     630//////////////////////////////////////////////////////////////////////////////////
    669631// This non-blocking function use the DMA coprocessor to transfer data from a
    670632// user buffer to the frame buffer device in kernel space.
     
    676638// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    677639//////////////////////////////////////////////////////////////////////////////////
    678 unsigned int fb_write(unsigned int offset, void *buffer, unsigned int length)
     640unsigned int giet_fb_write( unsigned int        offset,
     641                            void*                       buffer,
     642                            unsigned int        length )
    679643{
    680644    return sys_call(SYSCALL_FB_WRITE,
     
    685649}
    686650//////////////////////////////////////////////////////////////////////////////////
    687 //       fb_read()
     651// giet_fb_read()
     652//////////////////////////////////////////////////////////////////////////////////
    688653// This non-blocking function use the DMA coprocessor to transfer data from the
    689654// frame buffer device in kernel space to an user buffer.
     
    695660// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    696661//////////////////////////////////////////////////////////////////////////////////
    697 unsigned int fb_read( unsigned int offset,
    698                       void *buffer,
    699                       unsigned int length )
     662unsigned int giet_fb_read( unsigned int         offset,
     663                           void*                        buffer,
     664                           unsigned int         length )
    700665{
    701666    return sys_call(SYSCALL_FB_READ,
     
    706671}
    707672//////////////////////////////////////////////////////////////////////////////////
    708 //      fb_completed()
     673// giet_fb_completed()
     674//////////////////////////////////////////////////////////////////////////////////
    709675// This blocking function returns when the transfer is completed.
    710676// - Returns 0 if success, > 0 if error.
    711677//////////////////////////////////////////////////////////////////////////////////
    712 unsigned int fb_completed()
     678unsigned int giet_fb_completed()
    713679{
    714680    return sys_call(SYSCALL_FB_COMPLETED,
     
    716682}
    717683
    718 ///// Platform or mapping related system calls /////
    719 
    720 //////////////////////////////////////////////////////////////////////////////////
    721 //      mwmr_base()
    722 //      TODO!
    723 // This function returns in argument buffer the virtual base address
    724 // of a MWMR communication channel, identified by the two arguments
    725 // vspace_name and channel_name.
    726 // As the GIET does not support dynamic allocation, the MWMR channel
    727 // must be declared in the mapping_info data structure to be initialised
    728 // in the boot phase.
    729 // - Returns the address if success,  0 if error ( channel not defined )
    730 //////////////////////////////////////////////////////////////////////////////////
    731 unsigned int vobj_get_vbase( char* vspace_name, char* vobj_name,
    732                         unsigned int vobj_type, unsigned int* vobj_buffer)
     684///// Miscellaneous related system calls /////
     685
     686//////////////////////////////////////////////////////////////////////////////////
     687// giet_vobj_get_vbase()
     688//////////////////////////////////////////////////////////////////////////////////
     689// This function writes in argument (vobj_vaddr) the virtual base address
     690// of a vobj (defined in the mapping_info data structure), identified by
     691// the two arguments (vspace_name and vobj_name).
     692// The (vobj_type) argument is redundant, and used for coherence checking.
     693// - Returns the address if success,  0 if error ( not defined or wrong type )
     694//////////////////////////////////////////////////////////////////////////////////
     695unsigned int giet_vobj_get_vbase( char*                 vspace_name,
     696                                  char*                 vobj_name,
     697                                  unsigned int  vobj_type,
     698                                  unsigned int* vobj_vaddr )
    733699{
    734700    return sys_call(SYSCALL_VOBJ_GET_VBASE,
     
    736702                    (unsigned int)vobj_name,
    737703                    (unsigned int)vobj_type,
    738                     (unsigned int)vobj_buffer);
    739 }
    740 ////////////////////////////////////////////////////////////////////////////////////
    741 //      proc_number()
     704                    (unsigned int)vobj_vaddr);
     705}
     706
     707////////////////////////////////////////////////////////////////////////////////////
     708// giet_proc_number()
     709////////////////////////////////////////////////////////////////////////////////////
    742710// This function returns in the buffer argument the number of processors
    743711// in the cluster specified by the cluster_id argument.
    744712// - Returns 0 if success, > 0 if error ( cluster index too large )
    745713////////////////////////////////////////////////////////////////////////////////////
    746 unsigned int proc_number( unsigned int cluster_id,
    747                           unsigned int* buffer )
     714unsigned int giet_proc_number( unsigned int             cluster_id,
     715                               unsigned int*    buffer )
    748716{
    749717    return sys_call(SYSCALL_PROC_NUMBER,
     
    756724
    757725//////////////////////////////////////////////////////////////////////////////////
    758 // exit()
     726// giet_task_exit()
     727//////////////////////////////////////////////////////////////////////////////////
    759728// This function stops execution of the calling task with a TTY message,
    760729// and enter an infinite loop.
    761730// The task is blocked, but it still consume processor cycles ...
    762731//////////////////////////////////////////////////////////////////////////////////
    763 void exit()
    764 {
    765     unsigned int proc_index = procid();
     732void giet_exit()
     733{
    766734    sys_call(SYSCALL_EXIT,
    767              proc_index,
    768              0, 0, 0);
     735             0, 0, 0, 0);
    769736}
    770737///////////////////////////////////////////////////////////////////////////////////
    771 //      rand()
     738// giet_rand()
    772739// This function returns a pseudo-random value derived from the processor cycle
    773740// count. This value is comprised between 0 & 65535.
    774741///////////////////////////////////////////////////////////////////////////////////
    775 unsigned int rand()
     742unsigned int giet_rand()
    776743{
    777744    unsigned int x = sys_call(SYSCALL_PROCTIME,
     
    783750}
    784751//////////////////////////////////////////////////////////////////////////////////
    785 //      ctx_switch()
     752// giet_ctx_switch()
    786753// The user task calling this function is descheduled and
    787754// the processor is allocated to another task.
    788755//////////////////////////////////////////////////////////////////////////////////
    789 unsigned int ctx_switch()
     756unsigned int giet_ctx_switch()
    790757{
    791758    return sys_call(SYSCALL_CTX_SWITCH,
Note: See TracChangeset for help on using the changeset viewer.