Changeset 407 for trunk/hal/generic


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

First implementation of fork/exec.

Location:
trunk/hal/generic
Files:
1 added
6 edited
1 copied
1 moved

Legend:

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

    r337 r407  
    4040
    4141/****************************************************************************************
    42  * This function allocates, from the local cluster, the physical memory required for
    43  * the thread CPU context, initialises it, and links the context to the thread.
     42 * This function allocates memory for a CPU context and links it to the thread
     43 * identified by the <thread> argument. The context is not initialised.
     44 ****************************************************************************************
     45 * @ return 0 if success / return -1 if failure.
     46 ***************************************************************************************/
     47error_t hal_cpu_context_alloc( struct thread_s * thread );
     48
     49/****************************************************************************************
     50 * This function allocates memory for a CPU context, initialize it from scratch,
     51 * and links it to the thread identified by the <thread> argument.
    4452 ****************************************************************************************
    4553 * @ thread  : pointer on the thread descriptor.
    46  * @ return 0 if success / return ENOMEM if error
     54 * @ return 0 if success / return -1 if failure.
    4755 ***************************************************************************************/
    4856error_t hal_cpu_context_create( struct thread_s * thread );
    4957
    5058/****************************************************************************************
    51  * This function allocates, from the local cluster, the physical memory required for
    52  * a thread CPU context, initialises it from values contained in "src" thread context,
    53  * and links the context to the "dst" thread.
     59 * This function display the following slots of a thread CPU context:
     60 * - GPR : gp_28 , sp_29 , ra_31
     61 * - CP0 : c0_sr , c0_th , c0_epc
     62 * - CP2 : c2_ptpr , c2-mode
    5463 ****************************************************************************************
    55  * @ dst  : pointer on the destination thread descriptor.
    56  * @ src  : pointer on the source thread descriptor.
    57  * @ return 0 if success / return ENOMEM if error
     64 * @ thread  : local pointer on the thread descriptor.
    5865 ***************************************************************************************/
    59 error_t hal_cpu_context_copy( struct thread_s * dst,
    60                               struct thread_s * src );
     66void hal_cpu_context_display( struct thread_s * thread );
    6167
    6268/****************************************************************************************
     
    6773void hal_cpu_context_destroy( struct thread_s * thread );
    6874
    69 /****************************************************************************************
    70  * This function performs a context switch, saving the CPU register values into the
    71  * old thread, and initializing these registers with the values of the new thread.
    72  ****************************************************************************************
    73  * @ old     : pointer on current thread.
    74  * @ new     : pointer on the thread we want to switch to.
    75  ***************************************************************************************/
    76 void hal_cpu_context_switch( struct thread_s * old , struct thread_s * new );
     75
     76
     77
     78
     79
    7780
    7881/****************************************************************************************
    79  * This function loads the relevant CPU registers from values contained in
    80  * the thread context. It should be called for a thread that has not been executed yet.
    81  * It reset the loadable flag in thread descriptor.
     82 * This function allocates memory for a FPU context, reset all entries,
     83 * and links it to the thread identified by the <thread> argument.
    8284 ****************************************************************************************
    8385 * @ thread  : pointer on the thread descriptor.
     86 * @ return 0 if success / return -1 if failure.
    8487 ***************************************************************************************/
    85 void hal_cpu_context_load( struct thread_s * thread );
     88error_t hal_fpu_context_alloc( struct thread_s * thread );
    8689
    8790/****************************************************************************************
    88  * This function allocates, from the local cluster, the physical memory required for
    89  * the thread FPU context, and initialises the thread pointer.
    90  ****************************************************************************************
    91  * @ thread  : pointer on the thread descriptor.
    92  * @ return 0 if success / return ENOMEM if error
    93  ***************************************************************************************/
    94 error_t hal_fpu_context_create( struct thread_s * thread );
    95 
    96 /****************************************************************************************
    97  * This function allocates, from the local cluster, the physical memory required for
    98  * a thread FPU context, initialises it from values contained in "src" thread context,
    99  * and link the context to the "dst" thread.
     91 * This function copies a FPU context defined by the <src> argument to the FPU context
     92 * defined by the <dst> argument. It is used by the fork system call.
    10093 ****************************************************************************************
    10194 * @ dst  : pointer on the destination thread descriptor.
    10295 * @ src  : pointer on the source thread descriptor.
    103  * @ return 0 if success / return ENOMEM if error
    10496 ***************************************************************************************/
    105 error_t hal_fpu_context_copy( struct thread_s * dst,
     97void hal_fpu_context_copy( struct thread_s * dst,
    10698                           struct thread_s * src );
    10799
  • trunk/hal/generic/hal_gpt.h

    r406 r407  
    4343
    4444struct page_s;
     45struct process_s;
    4546
    4647/****************************************************************************************
     
    4849 ***************************************************************************************/
    4950
    50 #define GPT_MAPPED      0x0001  /*! PTE is mapped                                 */
    51 #define GPT_SMALL       0x0002  /*! PTE is a small page                           */
    52 #define GPT_READABLE    0x0004  /*! PTE is readable                               */
    53 #define GPT_WRITABLE    0x0008  /*! PTE is writable                               */
    54 #define GPT_EXECUTABLE  0x0010  /*! PTE is executable                             */
    55 #define GPT_CACHABLE    0x0020  /*! PTE can be cached                             */
    56 #define GPT_USER        0x0040  /*! PTE is user accessible                        */
    57 #define GPT_DIRTY       0x0080  /*! PTE has been "recently" written               */
    58 #define GPT_ACCESSED    0x0100  /*! PTE has been "recently" accessed              */
    59 #define GPT_GLOBAL      0x0200  /*! PTE is kept in TLB at context switch          */
    60 #define GPT_COW         0x0400  /*! PTE must be copied on write                   */
    61 #define GPT_SWAP        0x0800  /*! PTE swapped on disk (not implemented yet)     */
    62 #define GPT_LOCKED      0x1000  /*! PTE is protected against concurrent access    */
     51#define GPT_MAPPED      0x0001       /*! PTE is mapped                                 */
     52#define GPT_SMALL       0x0002       /*! PTE is a small page                           */
     53#define GPT_READABLE    0x0004       /*! PTE is readable                               */
     54#define GPT_WRITABLE    0x0008       /*! PTE is writable                               */
     55#define GPT_EXECUTABLE  0x0010       /*! PTE is executable                             */
     56#define GPT_CACHABLE    0x0020       /*! PTE can be cached                             */
     57#define GPT_USER        0x0040       /*! PTE is user accessible                        */
     58#define GPT_DIRTY       0x0080       /*! PTE has been "recently" written               */
     59#define GPT_ACCESSED    0x0100       /*! PTE has been "recently" accessed              */
     60#define GPT_GLOBAL      0x0200       /*! PTE is kept in TLB at context switch          */
     61#define GPT_COW         0x0400       /*! PTE must be copied on write                   */
     62#define GPT_SWAP        0x0800       /*! PTE swapped on disk (not implemented yet)     */
     63#define GPT_LOCKED      0x1000       /*! PTE is protected against concurrent access    */
    6364
    6465/****************************************************************************************
     
    7071        void           * ptr;    /*! local pointer on GPT root                             */
    7172        ppn_t            ppn;    /*! PPN of GPT root                                       */
    72         struct page_s  * page;   /*! local pointer on GPT root page descriptor             */
    7373}
    7474gpt_t;
     
    9898 * This function prints on the kernel terminal the content of a generic page table.
    9999 ****************************************************************************************
    100  * @ gpt     : pointer on generic page table descriptor.
    101  * @ pid     : process identifier.
    102  ***************************************************************************************/
    103 void hal_gpt_print( gpt_t * gpt,
    104                     pid_t   pid );
     100 * @ process : pointer on local process descriptor.
     101 ***************************************************************************************/
     102void hal_gpt_display( struct process_s * process );
    105103
    106104/****************************************************************************************
     
    169167
    170168/****************************************************************************************
    171  * This function copies all valid entries from the source <src_gpt> to the <dst_gpt>.
    172  * The <src_gpt> and the <dst_gpt> point on the same physical pages.
    173  * If the <cow> argument is true, the GPT_WRITABLE attribute is reset for all writable
    174  * entries in both <src_gpt> and <dst_gpt>, and the PG_COW flag is registered in all
    175  * writable physical page descriptors, to support the Copy-On-Write mechanism.
     169 * This function is used to implement the "fork" system call: It copies all valid GPT
     170 * entries for a given vseg identified by the <vpn_base> and <vpn_size> arguments,
     171 * from the source <src_gpt> to the <dst_gpt>.
     172 * It optionnally activates the "Copy on Write" mechanism: when the <cow> argument is
     173 * true, the GPT_WRITABLE flag is reset, and the GPT_COW flag is set for each valid
     174 * entry in the destination GPT (The data page will be dynamically allocated an copied
     175 * when a write access is detected).
    176176 ****************************************************************************************
    177177 * @ dst_gpt   : [in]  pointer on the destination GPT.
    178178 * @ src_gpt   : [in]  pointer on the source GPT.
     179 * @ vpn_base  : [in]  first vpn in vseg.
     180 * @ vpn_size  : [in]  number of pages in vseg.
    179181 * @ cow       : [in]  activate the COPY-On-Write mechanism if true.
    180182 ***************************************************************************************/
    181183error_t hal_gpt_copy( gpt_t    * dst_gpt,
    182184                      gpt_t    * src_gpt,
     185                      vpn_t      vpn_base,
     186                      vpn_t      vpn_size,
    183187                      bool_t     cow );
    184188
     189/****************************************************************************************
     190 * This function returns GPT_COW flag for a PTE defined by <gpt> and <vpn> arguments.
     191 ****************************************************************************************
     192 * @ gpt       : [in]  pointer on the page table
     193 * @ vpn       : [in]  virtual page number
     194 * @ returns true if GPT_COW is set.
     195 ***************************************************************************************/
     196bool_t hal_gpt_pte_is_cow( gpt_t * gpt,
     197                           vpn_t   vpn );
     198
    185199
    186200#endif  /* _GPT_H_ */
  • trunk/hal/generic/hal_ppm.h

    r315 r407  
    5454error_t hal_ppm_init( boot_info_t * info );
    5555
    56 /****************************************************************************************
    57  * This function initializes the architecture specific core registers, for the
    58  * calling core. It is executed by all cores during kernel_init().
    59  ****************************************************************************************
    60  * @ info       : pointer on the boot_info structure.
    61  ***************************************************************************************/
    62 void hal_core_init( boot_info_t * info );
    63 
    6456#endif  /* HAL_PPM_H_ */
  • trunk/hal/generic/hal_remote.h

    r313 r407  
    133133 * @ xp      : extended pointer to remote data
    134134 * @ mask    : local mask value.
    135  * @ return old value (before increment) of the remote integer
     135 * @ return old value (before mask) of the remote integer
    136136 ****************************************************************************************/
    137137uint32_t hal_remote_atomic_and( xptr_t    xp,
     
    144144 * @ xp      : extended pointer to remote data
    145145 * @ mask    : local mask value.
    146  * @ return old value (before increment) of the remote integer
     146 * @ return old value (before mask) of the remote integer
    147147 ****************************************************************************************/
    148148uint32_t hal_remote_atomic_or( xptr_t    xp,
  • trunk/hal/generic/hal_special.h

    r401 r407  
    7070
    7171/*****************************************************************************************
    72  * This function registers a new kentry base address in the relevant core register.
    73  ****************************************************************************************/
    74 void hal_set_ebase( reg_t base );
    75 
    76 /*****************************************************************************************
    7772 * This function writes into the proper core register to enable the floating point unit.
    7873 ****************************************************************************************/
     
    128123
    129124/*****************************************************************************************
    130  * This function returns after a fixed delay of (4 * delay) cycles.
     125 * This function returns after approximately <delay> cycles.
     126 * @ delay  : number of cycles.
    131127 ****************************************************************************************/
    132 void hal_fixed_delay();
     128void hal_fixed_delay( uint32_t delay );
    133129
    134130/*****************************************************************************************
  • trunk/hal/generic/hal_switch.h

    r405 r407  
    11/*
    2  * hal_switch.h - TSAR architecture context switch function
     2 * hal_switch.h - Generic architecture context switch function
    33 *
    4  * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    5  * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     4 * Authorg   Alain Greiner  (2017)
     5 *
     6 * Copyright (c) UPMC Sorbonne Universites
    67 *
    7  * This file is part of ALMOS-kernel.
     8 * This file is part of ALMOS-MKH.
    89 *
    9  * ALMOS-kernel is free software; you can redistribute it and/or modify it
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1011 * under the terms of the GNU General Public License as published by
    1112 * the Free Software Foundation; version 2.0 of the License.
    1213 *
    13  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1415 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1516 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1718 *
    1819 * You should have received a copy of the GNU General Public License
    19  * along with ALMOS-kernel; if not, write to the Free Software Foundation,
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    2021 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2122 */
     
    2425#define _HAL_SWITCH_H_
    2526
     27struct thread_s;
     28
    2629/*************************************************************************************
    27  * The hal_do_switch() function is an assembly level code called by the
    28  * hal_cpu_context_switch() function to make the actual context swich.
    29  * The hal_cpu_context_t structure used to store a core context is defined
    30  * in the TSAR specific hal_context.c file.
    31  * The following core registers are saved in the old context & and restored
    32  * from the new context:
    33  * - GPR : all, but (zero, k0, k1), plus (hi, lo)
    34  * - CP0 : c0_th , c0_sr
    35  * - CP2 : c2_ptpr , C2_mode, C2_epc
    36  * When the switch is completed, it jumps to address contained in register $31
    37  * of the new context.
     30 * The hal_do_cpu_switch() function is an assembly level function, called by the
     31 * sched_yield() function, to make a CPU context switch.
     32 * The current thread CPU context is identified by the <ctx_current> pointer.
     33 * The new thread CPU context is identified by the <ctx_next> pointer.
     34 * The architecture specific hal_cpu_context_t structure used to store a CPU context
     35 * is defined in the architecture specific hal_context.c file.
     36 * This function does NOT modify any register before saving values into context.
     37 * When the switch is completed, it jumps to address contained in the relevant
     38 * register of the new thread CPU context.
    3839 *************************************************************************************
    39  * @ ctx_old  : local pointer on the old thread context.
    40  * @ ctx_new  : local pointer on the new thread context.
     40 * @ ctx_current  : local pointer on current thread CPU context.
     41 * @ ctx_next     : local pointer on new thread CPU context.
    4142 ************************************************************************************/
    42 void hal_do_switch( void * ctx_old,
    43                     void * ctx_new );
     43void hal_do_cpu_switch( void * ctx_old,
     44                        void * ctx_new );
    4445
     46/*************************************************************************************
     47 * The hal_do_cpu_save() function is an assembly level function, called by the
     48 * sys_fork() system call to save the parent thread register values to a child
     49 * CPU context identified by the <ctx> pointer.
     50 * This function does NOT modify any register before saving values into context.
     51 * The architecture specific hal_cpu_context_t structure used to store a CPU context
     52 * is defined in the architecture specific hal_context.c file.
     53 * Two context slots are not saved from the calling thread registers values :
     54 * - the "current_thread" slot is set from the value defined by the <thread> argument.
     55 * - the "stack_pointer" slot is set by adding the value defined by the <offset>
     56 *   argument to the current sp register value.
     57 * When the save is completed, it simply returns to the calling function.
     58 *************************************************************************************
     59 * @ ctx     : local pointer on target thread CPU context.
     60 * @ thread  : local pointer on target thread descriptor.
     61 * @ offset  : kernel stack pointer offset (&child - &parent).
     62 ************************************************************************************/
     63void hal_do_cpu_save( void * ctx,
     64                      void * thread,
     65                      int    offset );
    4566
    4667#endif  /* _HAL_SWITCH_H_ */
  • trunk/hal/generic/hal_syscall.h

    r405 r407  
    11/*
    2  * hal_syscall.h - Architecture specific syscall handler API definition.
     2 * hal_kernel_syscall.h - Architecture specific kernel_side syscall handler API definition.
    33 *
    44 * Author      Alain Greiner (2016,2017)
     
    2222 */
    2323
    24 #ifndef _HAL_SYSCALL_H_
    25 #define _HAL_SYSCALL_H_
     24#ifndef _HAL_KERNEL_SYSCALL_H_
     25#define _HAL_KERNEL_SYSCALL_H_
    2626
    2727#include <hal_types.h>
    2828
    2929//////////////////////////////////////////////////////////////////////////////////////////
    30 //     ARchitecture specific syscall handler API
     30//     Kernel-side syscall handler API
    3131//
    32 // The calling thread context has been saved in the cpu_uzone array,
    33 // stored in the user thread descriptor by the hal_kentry function.
    34 // The architecture specific handler must use this array to get the syscall
    35 // index and the arguments values.
     32// This hal_do_syscall() function extract from the regs_tbl[] array the syscall index,
     33// and the four syscall arguments. Then it calls the generic do_syscall() kernel function,
     34// that call itself the relevant kernel function, depending on the syscall index.
    3635//
    3736// Any architecture specific implementation must implement this API.
     
    4443
    4544/*****************************************************************************************
    46  * This function implements the ALMOS-MKH syscall handler.
     45 * This function implements the ALMOS-MKH kernel_side syscall handler.
    4746 *****************************************************************************************
    4847 * @ this     : pointer on the calling thread.
     
    5352
    5453
    55 #endif   // _HAL_SYSCALL_H_
     54#endif   // _HAL_KERNEL_SYSCALL_H_
  • trunk/hal/generic/hal_uspace.h

    r299 r407  
    6262
    6363/*****************************************************************************************
    64  * This function tranfers a NUL terminated string from the user space to the kernel space.
     64 * This function tranfers a string from the user space to the kernel space.
     65 * The transfer stops after the first encountered NUL character, and no more than
     66 * <max_size> characters are actually copied to target buffer.
    6567 * If the kernel uses physical addresses, it activates the MMU to access the user buffer.
    66  * TODO : implement the max_size argument handling, and error handling
    6768 *****************************************************************************************
    6869 * @ u_dst     : destination buffer address in user space.
     
    7071 * @ max_size  : max number of characters to be copied.
    7172 ****************************************************************************************/
    72 extern error_t hal_strcpy_from_uspace( char     * k_dst,
    73                                        char     * u_src,
    74                                        uint32_t   max_size );
     73extern void hal_strcpy_from_uspace( char     * k_dst,
     74                                    char     * u_src,
     75                                    uint32_t   max_size );
    7576
    7677/*****************************************************************************************
    77  * This function tranfers a NUL terminated string from the kernel space to the user space.
     78 * This function tranfers a string from the kernel space to the user space.
     79 * The transfer stops after the first encountered NUL character, and no more than
     80 * <max_size> characters are actually copied to target buffer.
    7881 * If the kernel uses physical addresses, it activates the MMU to access the user buffer.
    79  * TODO : implement the max_size argument handling, and error handling
    8082 *****************************************************************************************
    8183 * @ u_dst     : destination buffer address in user space.
     
    8385 * @ max_size  : max number of characters to be copied.
    8486 ****************************************************************************************/
    85 extern error_t hal_strcpy_to_uspace( char     * u_dst,
    86                                      char     * k_src,
    87                                      uint32_t   max_size );
     87extern void hal_strcpy_to_uspace( char     * u_dst,
     88                                  char     * k_src,
     89                                  uint32_t   max_size );
    8890
    8991/*****************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.