Changeset 23 for trunk/hal


Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (8 years ago)
Author:
alain
Message:

Introduce syscalls.

Location:
trunk/hal
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/generic/hal_atomic.h

    r17 r23  
    6767
    6868/*****************************************************************************************
    69  * This blocking function atomically increments a 32 bits unsigned int shared variable,
    70  * returning only when atomic increment is successful.
    71  *****************************************************************************************
    72  * @ ptr     : pointer on the shared variable
    73  * @ return shared variable value before increment
    74  ****************************************************************************************/
    75 uint32_t hal_atomic_inc( uint32_t * ptr );
    76 
    77 /*****************************************************************************************
    78  * This blocking function atomically decrements a 32 bits unsigned int shared variable,
    79  * returning only when atomic decrement is successful.
    80  *****************************************************************************************
    81  * @ ptr     : pointer on the shared variable
    82  * @ return shared variable value before decrement
    83  ****************************************************************************************/
    84 uint32_t hal_atomic_dec( uint32_t * ptr );
    85 
    86 /*****************************************************************************************
    8769 * This NON blocking function makes an atomic Compare-And-Swap on a 32 bits unsigned int
    8870 * shared variable, returning a Boolean to indicate both success and atomicity.
  • trunk/hal/generic/hal_gpt.h

    r17 r23  
    166166                      uint32_t * attr,
    167167                      ppn_t    * ppn );
     168/****************************************************************************************
     169 * This function copies all valid entries from the source <src_gpt> to the <dst_pgt>.
     170 * The <src_gpt> and the <dst_gpt> point on the same physical pages.
     171 * If the <cow> argument is true, the GPT_WRITABLE attribute is reset for all writable
     172 * entries in both <src_gpt> and <dst_gpt>, and the PG_COW flag is registered in all
     173 * writable physical page descriptors, to support the Copy-On-Write mechanism.
     174 ****************************************************************************************
     175 * @ dst_gpt   : [in]  pointer on the destination GPT.
     176 * @ src_gpt   : [in]  pointer on the source GPT.
     177 * @ cow       : [in]  activate the COPY-On-Write mechanism if true.
     178 ***************************************************************************************/
     179error_t hal_gpt_copy( gpt_t    * dst_gpt,
     180                      gpt_t    * src_gpt,
     181                      bool_t     cow );
    168182
    169183
  • trunk/hal/generic/hal_uspace.h

    r17 r23  
    22 * hal_uspace.h - Generic User Space Access API definition
    33 *
    4  * Authors   Mohamed Karaoui  (2015)
    5  *           Alain Greiner    (2016)
     4 * Authors    Alain Greiner (2016,2017)
    65 *
    76 * Copyright (c)  UPMC Sorbonne Universites
     
    3332// When moving data between user space and kernel space, the user address is always
    3433// a virtual address, but the kernel address can be a physical address, on some
    35 // architectures. Therefore, data transfers must use the following API.
     34// architectures. For sake of portability, data transfers must use the following API.
    3635//////////////////////////////////////////////////////////////////////////////////////////
    3736
     
    3938/*****************************************************************************************
    4039 * This function tranfers a data buffer from the user space to the kernel space.
    41  * As the kernel is using physical addresses on the TSAR architecture, it activates
    42  * the MMU to access the user buffer.
     40 * If the kernel uses physical addresses, it activates the MMU to access the user buffer.
    4341 *****************************************************************************************
    4442 * @ k_dst     : destination address in kernel space.
     
    5250/*****************************************************************************************
    5351 * This function tranfers a data buffer from the kernel space to the user space.
    54  * As the kernel is using physical addresses on the TSAR architecture, it activates
    55  * the MMU to access the user buffer.
     52 * If the kernel uses physical addresses, it activates the MMU to access the user buffer.
    5653 *****************************************************************************************
    57  * @ u_dst     : destination buffer address and size in user space.
     54 * @ u_dst     : destination buffer address in user space.
    5855 * @ k_src     : source address in kernel space.
    5956 * @ size      : size (number of bytes).
    6057 ****************************************************************************************/
    61 extern void hal_copy_to_uspace( void     * udst,
    62                                 void     * ksrc,
     58extern void hal_copy_to_uspace( void     * u_dst,
     59                                void     * k_src,
    6360                                uint32_t   size );
    6461
    6562/*****************************************************************************************
    66  * This function activates the MMU to compute the length of a string in user space,
    67  * and returns it to a kernel buffer.
     63 * This function computes the length of a string in user space.
     64 * If the kernel uses physical addresses, it activates the MMU to access the user buffer.
    6865 *****************************************************************************************
    6966 * @ u_str     : string address in user space.
  • trunk/hal/tsar_mips32/hal_atomic.c

    r8 r23  
    7979}
    8080
    81 ///////////////////////////////////////
    82 int32_t hal_atomic_inc( uint32_t * ptr)
    83 {
    84         return hal_atomic_add( ptr , 1 );
    85 }
    86 
    87 ///////////////////////////////////////
    88 int32_t hal_atomic_dec( uint32_t * ptr)
    89 {
    90         return hal_atomic_add( ptr , -1 );
    91 }
    92 
    9381//////////////////////////////////////
    9482bool_t hal_atomic_cas( uint32_t * ptr,
  • trunk/hal/tsar_mips32/hal_gpt.c

    r1 r23  
    162162
    163163    // compute is_ref
    164     is_ref = process->is_ref;
     164    is_ref = ( GET_CXY( process->ref_xp ) == local_cxy );
    165165
    166166    // get pointer on PT1
     
    238238
    239239    printk("*** Page Table for process %x in cluster %x ***\n",
    240            CURRENT_PROCESS->pid , local_cxy );
     240           CURRENT_THREAD->process->pid , local_cxy );
    241241
    242242    pt1 = (uint32_t *)gpt->ptr;
     
    539539            req.flags = AF_KERNEL | AF_ZERO;
    540540            page = (page_t *)kmem_alloc( &req );
     541
    541542        if( page == NULL )
    542543        {
     
    545546            return ENOMEM;
    546547        }
     548
    547549        pt2_ppn = ppm_page2ppn( page );
    548550        pt2     = ppm_page2base( page );
     
    665667}  // end hal_gpt_unlock_pte()
    666668
    667 
    668 
    669 
    670 
    671 
    672 
    673 
     669///////////////////////////////////////
     670error_t hal_gpt_copy( gpt_t  * dst_gpt,
     671                      gpt_t  * src_gpt,
     672                      bool_t   cow )
     673{
     674    uint32_t     ix1;       // index in PT1
     675    uint32_t     ix2;       // index in PT2
     676
     677        uint32_t   * src_pt1;   // local pointer on PT1 for SRC_GPT
     678        uint32_t   * dst_pt1;   // local pointer on PT1 for DST_GPT
     679    uint32_t   * dst_pt2;   // local pointer on PT2 for DST_GPT
     680    uint32_t   * src_pt2;   // local pointer on PT2 for SRC_GPT
     681
     682    uint32_t     pte1;
     683    uint32_t     pte2_attr;
     684    uint32_t     pte2_ppn;
     685    uint32_t     pte2_writable;
     686
     687    page_t     * page;
     688
     689    ppn_t        src_pt2_ppn;
     690    ppn_t        dst_pt2_ppn;
     691
     692    // get pointers on PT1 for src_gpt & dst_gpt
     693    src_pt1 = (uint32_t *)src_gpt->ptr;
     694    dst_pt1 = (uint32_t *)dst_gpt->ptr;
     695
     696    // scan the SRC_PT1
     697        for( ix1 = 0 ; ix1 < 2048 ; ix1++ )
     698        {
     699        pte1 = src_pt1[ix1];
     700                if( (pte1 & GPT_MAPPED) != 0 )
     701        {
     702            if( (pte1 & GPT_SMALL) == 0 )  // PTE1 => big kernel page
     703            {
     704                // big kernel pages are shared by all processes => copy it
     705                dst_pt1[ix1] = pte1;
     706            }
     707            else                           // PTD1 => smal pages
     708            {
     709                // allocate one physical page for a PT2 in DST_GPT
     710                    kmem_req_t req;
     711                    req.type  = KMEM_PAGE;
     712                    req.size  = 0;                     // 1 small page
     713                    req.flags = AF_KERNEL | AF_ZERO;
     714                    page = (page_t *)kmem_alloc( &req );
     715
     716                if( page == NULL )
     717                {
     718                    // TODO release all memory allocated to DST_GPT
     719                                printk("\n[ERROR] in %s : cannot allocate PT2\n", __FUNCTION__ );
     720                    return ENOMEM;
     721                }
     722
     723                // get pointer on new PT2 in DST_GPT
     724                dst_pt2 = (uint32_t *)ppm_page2base( page );
     725
     726                // set a new PTD1 in DST_GPT
     727                dst_pt2_ppn  = (ppn_t)ppm_page2ppn( page );
     728                dst_pt1[ix1] = TSAR_MMU_PRESENT | TSAR_MMU_PTD1 | dst_pt2_ppn;
     729
     730                // get pointer on PT2 in SRC_GPT
     731                src_pt2_ppn = (ppn_t)TSAR_MMU_PTBA_FROM_PTE1( pte1 );
     732                src_pt2     = (uint32_t *)ppm_ppn2base( src_pt2_ppn );
     733
     734                // scan the SRC_PT2
     735                for( ix2 = 0 ; ix2 < 512 ; ix2++ )
     736                {
     737                    // get attr & ppn from PTE2
     738                    pte2_attr = TSAR_MMU_ATTR_FROM_PTE2( src_pt2[2 * ix2] );
     739
     740                            if( (pte2_attr & GPT_MAPPED) != 0 )  // valid PTE2 in SRC_GPT
     741                    {
     742                        // get GPT_WRITABLE & PPN
     743                        pte2_writable = pte2_attr & GPT_WRITABLE;
     744                        pte2_ppn      = TSAR_MMU_PPN_FROM_PTE2(  src_pt2[2 * ix2 + 1] );
     745
     746                        // set a new PTE2 in DST_GPT
     747                        dst_pt2[2*ix2]     = pte2_attr;
     748                        dst_pt2[2*ix2 + 1] = pte2_ppn;
     749                       
     750                        // handle Copy-On-Write
     751                        if( cow && pte2_writable )
     752                        {
     753                            // reset GPT_WRITABLE in both SRC_GPT and DST_GPT
     754                            hal_atomic_and( &dst_pt2[2*ix2] , ~GPT_WRITABLE );
     755                            hal_atomic_and( &src_pt2[2*ix2] , ~GPT_WRITABLE );
     756
     757                            // register PG_COW in page descriptor
     758                            page = ppm_ppn2page( pte2_ppn );
     759                            hal_atomic_or( &page->flags , PG_COW );
     760                                                        hal_atomic_add( &page->fork_nr , 1 );
     761                        }
     762                    }
     763                }  // end loop on ix2
     764            }
     765        }
     766    }  // end loop ix1
     767
     768    hal_wbflush();
     769
     770    return 0;
     771
     772}  // end hal_gpt_copy()
     773
Note: See TracChangeset for help on using the changeset viewer.