Changeset 657 for trunk/kernel/syscalls


Ignore:
Timestamp:
Mar 18, 2020, 11:16:59 PM (4 years ago)
Author:
alain
Message:

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

Location:
trunk/kernel/syscalls
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_fbf.h

    r642 r657  
    11/*
    2  * shared_framebuffer.h - Shared mnemonics used by the frame buffer related syscalls.
     2 * shared_fbf.h - Shared mnemonics used by the frame buffer related syscalls.
    33 *
    4  * Author  Alain Greiner (2016,2017,2018,2019)
     4 * Author  Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2626
    2727/*******************************************************************************************
    28  * This enum defines the operation mnemonics for frame buffer access.
     28 * This enum defines the user operation mnemonics for frame buffer access.
    2929 ******************************************************************************************/
    3030
    3131typedef enum
    3232{
    33     FBF_GET_CONFIG = 0,     
    34     FBF_READ       = 1,
    35     FBF_WRITE      = 2,
     33    FBF_GET_CONFIG     = 0,     
     34    FBF_DIRECT_READ    = 1,
     35    FBF_DIRECT_WRITE   = 2,
     36    FBF_CREATE_WINDOW  = 3,
     37    FBF_DELETE_WINDOW  = 4,
     38    FBF_REFRESH_WINDOW = 5,
     39    FBF_MOVE_WINDOW    = 6,
     40    FBF_RESIZE_WINDOW  = 7,
    3641}
    37 fbf_operation_type_t;
     42fbf_usr_operation_type_t;
    3843
    3944#endif  // _SHARED_FRAMEBUFFER_H_
  • trunk/kernel/syscalls/shared_include/syscalls_numbers.h

    r642 r657  
    9393    SYS_GET_THREAD_INFO = 55,
    9494    SYS_FBF             = 56,
     95    SYS_SOCKET          = 57,
    9596
    96     SYSCALLS_NR         = 57,
     97    SYSCALLS_NR         = 58,
    9798
    9899} syscalls_t;
  • trunk/kernel/syscalls/sys_display.c

    r656 r657  
    22 * sys_display.c - display the current state of a kernel structure on TXT0
    33 *
    4  * Author    Alain Greiner (2016,2017,2018, 2019)
     4 * Author    Alain Greiner (2016,2017,2018,2019,2020)
    55 * 
    66 * Copyright (c) UPMC Sorbonne Universites
     
    380380
    381381            // get extended pointer on target page
    382             page_xp = mapper_remote_get_page( mapper_xp , page_id );
     382            page_xp = mapper_get_page( mapper_xp , page_id );
    383383
    384384            if( page_xp == XPTR_NULL )
     
    446446        case DISPLAY_FAT:
    447447        {
    448             uint32_t  entries = (uint32_t)arg1;
    449 
    450             if( entries > 4096 )
     448            uint32_t  slots = (uint32_t)arg1;
     449
     450            if( slots > 1024 )
    451451                {
    452452
    453453#if DEBUG_SYSCALLS_ERROR
    454 printk("\n[ERROR] in %s for FAT : nb_entries larger than 4096\n",
     454printk("\n[ERROR] in %s for FAT : nb_slots larger than 1024\n",
    455455__FUNCTION__ );
    456456#endif
     
    459459                }
    460460
    461             if( entries == 0 )  // display fat context in cluster cxy
     461            if( slots == 0 )  // display fat context in cluster cxy
    462462            {
    463463                uint32_t  cxy = (uint32_t)arg0;
     
    476476                fatfs_display_ctx( cxy );
    477477            }
    478             else                  // display nb_entries in page
     478            else                  // display nb_slots in page
    479479            {                       
    480                 uint32_t page = (uint32_t)arg0;
    481 
    482                 fatfs_display_fat( page , 0 , entries );
     480                uint32_t min = (uint32_t)arg0;
     481
     482                fatfs_display_fat( min , slots );
    483483            }
    484484
  • trunk/kernel/syscalls/sys_fbf.c

    r647 r657  
    22 * sys_fbf.c - Acces the frame buffer peripheral.
    33 *
    4  * Authors     Alain Greiner (2016,2017,2018,2019)
     4 * Authors     Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3333#include <syscalls.h>
    3434
    35 //////////////////////////////////
    36 int sys_fbf( uint32_t   operation,
    37              void     * arg0,           
    38              void     * arg1,
    39              void     * arg2 )
     35////////////////////////
     36int sys_fbf( reg_t arg0,
     37             reg_t arg1,
     38             reg_t arg2,
     39             reg_t arg3 )
    4040{
    4141        vseg_t         * vseg;        // for vaddr check
    4242    error_t          error;
    4343
     44#if (DEBUG_SYS_FBF || CONFIG_INSTRUMENTATION_SYSCALLS)
     45uint64_t     tm_start = hal_get_cycles();
     46#endif
     47
    4448    thread_t       * this    = CURRENT_THREAD;
    4549    process_t      * process = this->process;
    4650
    47 #if (DEBUG_SYS_FBF || CONFIG_INSTRUMENTATION_SYSCALLS)
    48 uint64_t     tm_start = hal_get_cycles();
    49 #endif
     51    // for some operations, the MSB of arg0 can contain the wid
     52    uint32_t operation = arg0 & 0xFFFF;
    5053
    5154#if DEBUG_SYS_FBF
    5255if( DEBUG_SYS_FBF < tm_start )
    53 printk("\n[%s] thread[%x,%x] enter for %s / cycle %d\n",
    54 __FUNCTION__, process->pid, this->trdid, dev_fbf_cmd_str( operation ), (uint32_t)tm_start );
     56printk("\n[%s] thread[%x,%x] enter for %s / arg1 %x / arg2 %x / arg3 %x / cycle %d\n",
     57__FUNCTION__, process->pid, this->trdid, dev_fbf_cmd_str( operation ),
     58arg1, arg2, arg3, (uint32_t)tm_start );
    5559#endif
    5660
     
    6569            uint32_t type;
    6670
    67             // check arg0 (width) in user vspace
    68                 error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
    69                 if( error )
    70             {
    71 
    72 #if DEBUG_SYSCALLS_ERROR
    73 printk("\n[ERROR] in %s : unmapped arg0 %x for %s / thread[%x,%x]\n",
    74 __FUNCTION__ , arg0, dev_fbf_cmd_str(operation), process->pid, this->trdid );
    75 #endif
    76                 this->errno = EINVAL;
    77                 return -1;
    78             }
    79 
    80             // check arg1 (height) in user vspace
     71            // check "width" in user vspace
    8172                error = vmm_get_vseg( process , (intptr_t)arg1 , &vseg );
    8273                if( error )
     
    8879#endif
    8980                this->errno = EINVAL;
    90                 return -1;
    91             }
    92 
    93             // check arg2 (type) in user vspace
    94                 error = vmm_get_vseg( process , (intptr_t)arg2 , &vseg );
     81            }
     82
     83            // check "height" in user vspace
     84                error |= vmm_get_vseg( process , (intptr_t)arg2 , &vseg );
    9585                if( error )
    9686            {
     
    10191#endif
    10292                this->errno = EINVAL;
    103                 return -1;
     93            }
     94
     95            // check "type" in user vspace
     96                error |= vmm_get_vseg( process , (intptr_t)arg3 , &vseg );
     97                if( error )
     98            {
     99
     100#if DEBUG_SYSCALLS_ERROR
     101printk("\n[ERROR] in %s : unmapped arg3 %x for %s / thread[%x,%x]\n",
     102__FUNCTION__ , arg3, dev_fbf_cmd_str(operation), process->pid, this->trdid );
     103#endif
     104                this->errno = EINVAL;
    104105            }
    105106
     
    107108            dev_fbf_get_config( &width , &height , &type );
    108109
    109             // transfer to user space
    110             hal_copy_to_uspace( arg0 , XPTR( local_cxy , &width )  , sizeof(uint32_t) );
    111             hal_copy_to_uspace( arg1 , XPTR( local_cxy , &height ) , sizeof(uint32_t) );
    112             hal_copy_to_uspace( arg2 , XPTR( local_cxy , &type )   , sizeof(uint32_t) );
    113        
    114             break;
    115         }
    116         //////////////
    117         case FBF_READ:
    118         case FBF_WRITE:
    119         {
    120             // check arg0 (buffer) in user space
    121                 error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
    122                 if( error )
    123             {
    124 
    125 #if DEBUG_SYSCALLS_ERROR
    126 printk("\n[ERROR] in %s : unmapped arg0 %x for %s / thread[%x,%x]\n",
    127 __FUNCTION__ , arg0, dev_fbf_cmd_str(operation), process->pid, this->trdid );
    128 #endif
    129                 this->errno = EINVAL;
    130                 return -1;
    131             }
    132 
    133             // get length and offset values
    134 
    135             uint32_t length = (uint32_t)(intptr_t)arg1;
    136             uint32_t offset = (uint32_t)(intptr_t)arg2;
     110            // transfer to user space if no error
     111            if( error == 0 )
     112            {
     113                hal_copy_to_uspace( (void*)arg1, XPTR(local_cxy , &width ), sizeof(uint32_t) );
     114                hal_copy_to_uspace( (void*)arg2, XPTR(local_cxy , &height), sizeof(uint32_t) );
     115                hal_copy_to_uspace( (void*)arg3, XPTR(local_cxy , &type  ), sizeof(uint32_t) );
     116            }
     117            break;
     118        }
     119        /////////////////////
     120        case FBF_DIRECT_READ:
     121        case FBF_DIRECT_WRITE:
     122        {
     123            void    * buffer   = (void *)arg1;
     124            uint32_t  npixels  = arg2;
     125            uint32_t  offset   = arg3;
     126            bool_t    is_write = (operation == FBF_DIRECT_WRITE);
     127           
     128            // check buffer in user space
     129                error = vmm_get_vseg( process , (intptr_t)buffer , &vseg );
     130                if( error )
     131            {
     132
     133#if DEBUG_SYSCALLS_ERROR
     134printk("\n[ERROR] in %s : unmapped buffer %x for %s / thread[%x,%x]\n",
     135__FUNCTION__ , buffer, dev_fbf_cmd_str(operation), process->pid, this->trdid );
     136#endif
     137                this->errno = EINVAL;
     138            }
     139            else
     140            {
     141                // call relevant kernel function
     142                error |= dev_fbf_move_data( is_write, buffer, npixels, offset );           
     143
     144                if( error )
     145                {
     146
     147#if DEBUG_SYSCALLS_ERROR
     148printk("\n[ERROR] in %s : cannot move data for %s / buffer %x / thread[%x,%x]\n",
     149__FUNCTION__ , dev_fbf_cmd_str(operation), buffer, process->pid, this->trdid );
     150#endif
     151                    this->errno = EINVAL;
     152                }
     153            }
     154            break;
     155        }
     156        ///////////////////////
     157        case FBF_CREATE_WINDOW:
     158        {
     159            uint32_t   l_zero  = arg1 >> 16;
     160            uint32_t   p_zero  = arg1 & 0xFFFF;
     161            uint32_t   nlines  = arg2 >> 16;
     162            uint32_t   npixels = arg2 & 0xFFFF;
     163
     164            // check buffer in user space
     165                error = vmm_get_vseg( process , (intptr_t)arg3 , &vseg );
     166                if( error )
     167            {
     168
     169#if DEBUG_SYSCALLS_ERROR
     170printk("\n[ERROR] in %s : unmapped user buffer %x for %s / thread[%x,%x]\n",
     171__FUNCTION__ , (intptr_t)arg3, dev_fbf_cmd_str(operation), process->pid, this->trdid );
     172#endif
     173                this->errno = EINVAL;
     174            }
     175            else
     176            {
     177                // allocated buffer base address
     178                intptr_t  user_buffer;
     179     
     180                // call relevant kernel function
     181                error = dev_fbf_create_window( nlines,
     182                                               npixels,
     183                                               l_zero,
     184                                               p_zero,
     185                                               &user_buffer );
     186                if( error == -1 )
     187                {
     188
     189#if DEBUG_SYSCALLS_ERROR
     190printk("\n[ERROR] in %s : cannot create window for %s / thread[%x,%x]\n",
     191__FUNCTION__ , dev_fbf_cmd_str(operation), process->pid, this->trdid );
     192#endif
     193                    this->errno = EINVAL;
     194                }
     195
     196                // copy vseg base address to user space buffer
     197                hal_copy_to_uspace( (void *)arg3,
     198                                    XPTR( local_cxy , &user_buffer ),
     199                                    sizeof(intptr_t) );
     200                hal_fence();
     201            }
     202            break;
     203        }
     204        ///////////////////////
     205        case FBF_DELETE_WINDOW:
     206        {
     207            uint32_t  wid = arg1;
     208
     209            // call relevant kernel function
     210            error = dev_fbf_delete_window( wid );
     211               
     212            if( error )
     213            {
     214
     215#if DEBUG_SYSCALLS_ERROR
     216printk("\n[ERROR] in %s : cannot delete window for %s / thread[%x,%x]\n",
     217__FUNCTION__ , dev_fbf_cmd_str(operation), process->pid, this->trdid );
     218#endif
     219                this->errno = EINVAL;
     220            }
     221            break;
     222        }
     223        ////////////////////////
     224        case FBF_REFRESH_WINDOW:
     225        {
     226            uint32_t  wid        = arg1;
     227            uint32_t  line_first = arg2;
     228            uint32_t  line_last  = arg3;
     229
     230            // call relevant kernel function
     231            error = dev_fbf_refresh_window( wid,
     232                                            line_first,
     233                                            line_last );
     234               
     235            if( error )
     236            {
     237
     238#if DEBUG_SYSCALLS_ERROR
     239printk("\n[ERROR] in %s : cannot refresh window for %s / thread[%x,%x]\n",
     240__FUNCTION__ , dev_fbf_cmd_str(operation), process->pid, this->trdid );
     241#endif
     242                this->errno = EINVAL;
     243            }
     244            break;
     245        }
     246        /////////////////////
     247        case FBF_MOVE_WINDOW:
     248        {
     249            uint32_t  wid      = arg1;
     250            uint32_t  l_zero   = arg2;
     251            uint32_t  p_zero   = arg3;
    137252
    138253            // call relevant kernel function to move data
    139             error = dev_fbf_move_data( operation , arg0 , length , offset );
     254            error = dev_fbf_move_window( wid, l_zero, p_zero );
    140255
    141256            if( error )
     
    143258
    144259#if DEBUG_SYSCALLS_ERROR
    145 printk("\n[ERROR] in %s : cannot move data for %s / buffer %x / thread[%x,%x]\n",
    146 __FUNCTION__ , dev_fbf_cmd_str(operation), arg0, process->pid, this->trdid );
    147 #endif
    148                 this->errno = EINVAL;
    149                 return -1;
    150             }
    151          
     260printk("\n[ERROR] in %s : cannot move window / thread[%x,%x]\n",
     261__FUNCTION__ , dev_fbf_cmd_str(operation), process->pid, this->trdid );
     262#endif
     263                this->errno = EINVAL;
     264            }
     265            break;
     266        }
     267        ///////////////////////
     268        case FBF_RESIZE_WINDOW:
     269        {
     270            uint32_t  wid      = arg1;
     271            uint32_t  width    = arg2;
     272            uint32_t  height   = arg3;
     273
     274            // call relevant kernel function to move data
     275            error = dev_fbf_resize_window( wid , width , height );
     276
     277            if( error )
     278            {
     279
     280#if DEBUG_SYSCALLS_ERROR
     281printk("\n[ERROR] in %s : cannot move window / thread[%x,%x]\n",
     282__FUNCTION__ , dev_fbf_cmd_str(operation), process->pid, this->trdid );
     283#endif
     284                this->errno = EINVAL;
     285            }
    152286            break;
    153287        }
     
    161295#endif
    162296            this->errno = EINVAL;
    163             return -1;
    164         }
     297            error = -1;
     298        }
     299        break;
    165300        }  // end switch on operation
    166301
     
    173308#if DEBUG_SYS_FBF
    174309if( DEBUG_SYS_FBF < tm_end )
    175 printk("\n[%s] thread[%x,%x] exit for %s / cost = %d / cycle %d\n",
    176 __FUNCTION__, process->pid, this->trdid, dev_fbf_cmd_str( operation ),
    177 (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     310printk("\n[%s] thread[%x,%x] exit for %s / cycle %d\n",
     311__FUNCTION__, process->pid, this->trdid, dev_fbf_cmd_str( operation ), (uint32_t)tm_end );
    178312#endif
    179313
     
    183317#endif
    184318
    185     return 0;
     319    return error;
    186320
    187321}  // end sys_fbf()
  • trunk/kernel/syscalls/sys_mmap.c

    r651 r657  
    22 * sys_mmap.c - map files, memory or devices into process virtual address space
    33 *
    4  * Authors       Alain Greiner (2016,2017,2018,2019)
     4 * Authors       Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/syscalls/syscalls.h

    r651 r657  
    22 * syscalls.h - Kernel side services for syscall handling.
    33 *
    4  * Author     Alain Greiner (2016,2017,2018,2019)
     4 * Author     Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    748748
    749749/******************************************************************************************
    750  * [56] This function implements the non-standard "fbf_get_config", "fbf_read" and
    751  * "fbf_write" syscalls, used to access the frame buffer peripheral.
    752  ******************************************************************************************
    753  * @ operation  : [in] operation type (defined in shared_fbf.h)
    754  * @ arg0       : if config : pointer on width   / else : pointer on user buffer 
    755  * @ arg1       : if config : pointer on height  / else : number of bytes to move
    756  * @ arg2       : if config : pointer on type    / else : offset in frame buffer
     750 * [56] This generic function implements the non-standard FBF related syscalls.
     751 * The operation types mnemonics are defined in the <shared_fbf> file.
     752 * The supported operations are defined in the <almosmkh.h> & <almosmkh.c> files.
     753 * This function ckecks the syscall arguments, and call the relevant kernel function.
     754 ******************************************************************************************
     755 * @ arg0       : operation type (mnemonics defined in shared_fbf.h)
     756 * @ arg1       : depends on operation type
     757 * @ arg2       : depends on operation type
     758 * @ arg3       : depends on operation type
    757759 * @ return 0 if success / return -1 if illegal argument.
    758760 *****************************************************************************************/
    759 int sys_fbf( uint32_t   operation,
    760              void     * arg0,
    761              void     * arg1,
    762              void     * arg2 );
     761int sys_fbf( reg_t   arg0,
     762             reg_t   arg1,
     763             reg_t   arg2,
     764             reg_t   arg3 );
     765
     766/******************************************************************************************
     767 * [57] This generic function implements the socket related syscalls.
     768 * The operation types mnemonics are defined in the <shared_socket> file.
     769 * The supported operations are defined in the <socket.h> & <socket.c> files.
     770 * This function ckecks the syscall arguments, and call the relevant kernel function.
     771 ******************************************************************************************
     772 * @ arg0       : operation type (mnemonics defined in shared_socket.h)
     773 * @ arg1       : depends on operation type
     774 * @ arg2       : depends on operation type
     775 * @ arg3       : depends on operation type
     776 * @ return 0 if success / return -1 if illegal argument.
     777 *****************************************************************************************/
     778int sys_socket( reg_t   arg0,
     779                reg_t   arg1,
     780                reg_t   arg2,
     781                reg_t   arg3 );
    763782
    764783#endif  // _SYSCALLS_H_
Note: See TracChangeset for help on using the changeset viewer.