Changeset 408 for trunk/hal/generic


Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

Location:
trunk/hal/generic
Files:
8 edited

Legend:

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

    r108 r408  
    6868/*****************************************************************************************
    6969 * This NON blocking function makes an atomic Compare-And-Swap on a 32 bits unsigned int
    70  * shared variable, returning a Boolean to indicate both success and atomicity.
     70 * shared variable, returning a Boolean to indicate success.
    7171 *****************************************************************************************
    7272 * @ ptr     : pointer on the shared variable
    7373 * @ old     : expected value for the shared variable
    7474 * @ new     : value to be written if success
    75  * @ return true if (current == old) and (access is atomic)
     75 * @ return true if success.
    7676 ****************************************************************************************/
    7777bool_t hal_atomic_cas( uint32_t * ptr,
  • trunk/hal/generic/hal_context.h

    r407 r408  
    5757
    5858/****************************************************************************************
    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
     59 * This function is used to implement the fork() system call.
     60 * 1) It saves in a remote (child) thread CPU context the current CPU registers values.
     61 *    Three slots are not simple copies of the parent registers values :
     62 *    - the thread pointer is set to the child thread local pointer.
     63 *    - the stack pointer is set to parrent SP + (child_base - parent_base).
     64 *    - the status register is set to kernel mode with IRQ disabled.
     65 * 2) It copies the content of the calling (parent) thread kernel_stack,
     66 *    to the remote (child) thread kernel_stack.
    6367 ****************************************************************************************
    64  * @ thread  : local pointer on the thread descriptor.
     68 * @ thread_xp  : extended pointer on the remote thread descriptor.
    6569 ***************************************************************************************/
    66 void hal_cpu_context_display( struct thread_s * thread );
     70void hal_cpu_context_fork( xptr_t    thread_xp );
     71
     72/****************************************************************************************
     73 * This function display some slots of the CPU context.
     74 * - For the MIPS32 :
     75 *   . GPR : gp_28 , sp_29 , ra_31
     76 *   . CP0 : c0_sr , c0_th , c0_epc
     77 *   . CP2 : c2_ptpr , c2-mode
     78 * - For X86 TODO :
     79 ****************************************************************************************
     80 * @ thread_xp  : extended pointer on the thread descriptor.
     81 ***************************************************************************************/
     82void hal_cpu_context_display( xptr_t  thread_xp );
    6783
    6884/****************************************************************************************
     
    106122
    107123/****************************************************************************************
    108  * This function saves in the thread uzone the FPU registers values.
     124 * This function is used to implement the fork() system call.
     125 * It saves in a remote thread FPU context the current FPU registers values.
    109126 ****************************************************************************************
    110  * @ thread  : pointer on the thread descriptor.
     127 * @ thread_xp  : extended pointer on the remote thread descriptor.
    111128 ***************************************************************************************/
    112 void hal_fpu_context_save( struct thread_s * thread );
     129void hal_fpu_context_save( xptr_t thread_xp );
    113130
    114131/****************************************************************************************
    115  * This function restores from the thread uzone the FPU registers values.
     132 * This function restores from the calling thread FPU context the FPU registers values.
    116133 ****************************************************************************************
    117134 * @ thread  : pointer on the thread descriptor.
  • trunk/hal/generic/hal_exception.h

    r380 r408  
    4545//      a message on TXT0, disable IRQs and call the hal_core_sleep() function.
    4646//
    47 // For all exceptions, the faulty core context has been saved in a registers array
    48 // stored in the user thread descriptor (for a core in user mode), and in the
    49 // kernel stack (for a core in kernel mode).
    50 //
    51 // Any architecture specific implementation must implement this API.
     47// For all exceptions, the faulty core registers have been saved in the "uzone"
     48// that can be accessed through the "uzone" pointer stored in thread descriptor.
    5249//////////////////////////////////////////////////////////////////////////////////////////
    5350
    54 /**** forward declaration  ****/
    55 
    56 struct thread_s;
    5751
    5852/*****************************************************************************************
    5953 * This function is called by the hal_kentry() function when an exception is detected by
    6054 * the hardware for a given thread running on a given core.
    61  *****************************************************************************************
    62  * @ this      : pointer on the faulty thread descriptor.
    63  * @ regs_tbl  : array containing the core registers values saved by hal_kentry().
    6455 ****************************************************************************************/
    65 void hal_do_exception( struct thread_s * this,
    66                        reg_t           * regs_tbl );
     56void hal_do_exception();
    6757
    6858#endif  // _HAL_EXCEPTION_H_
  • trunk/hal/generic/hal_gpt.h

    r407 r408  
    3535//   dependent, and is defined as (CONFIG_USER_SPACE_SIZE / CONFIG_PPM_PAGE_SIZE).
    3636// - Each entry contains a Physical Page Number (ppn_t type), and a set of attributes,
    37 //   defined as masks on a 32 bits-vector.
     37//   defined as a 32 bits-vector.
    3838//
    3939// Any arch-specific implementation must implement this API.
     
    126126
    127127/****************************************************************************************
    128  * This function maps a page table entry identified by its VPN, from values defined
     128 * This function map a local GPT entry identified by its VPN, from values defined
    129129 * by the ppn and attr arguments. It allocates physical memory for the local generic
    130130 * page table itself if required.
     
    132132 * @ gpt       : [in] pointer on the page table
    133133 * @ vpn       : [in] virtual page number
     134 * @ attr      : [in] generic attributes
    134135 * @ ppn       : [in] physical page number
    135  * @ attr      : [in] generic attributes
    136136 * @ returns 0 if success / returns ENOMEM if error
    137137 ***************************************************************************************/
    138138error_t hal_gpt_set_pte( gpt_t    * gpt,
    139139                         vpn_t      vpn,
    140                          ppn_t      ppn,
    141                          uint32_t   attr );
     140                         uint32_t   attr,
     141                         ppn_t      ppn );
    142142
    143143/****************************************************************************************
     
    153153
    154154/****************************************************************************************
    155  * This function returns in the ppn and attr arguments the value of a page table
    156  * entry identified by its VPN.  It returns attr == 0 if the page is not mapped.
    157  ****************************************************************************************
    158  * @ gpt       : [in]  pointer on the page table
     155 * This function returns in the <attr> and <ppn> arguments the current values
     156 * stored in a GPT entry, identified by the <gpt> and <vpn> arguments.
     157 ****************************************************************************************
     158 * @ gpt_xp    : [in]  pointer on the page table
    159159 * @ vpn       : [in]  virtual page number
    160160 * @ attr      : [out] generic attributes
     
    167167
    168168/****************************************************************************************
    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>.
     169 * This function is used to implement the "fork" system call: It copies one GPT entry
     170 * identified by the <vpn> argument, from a remote <src_gpt_xp> to a local <dst_gpt>.
     171 * It does nothing if the source PTE is not MAPPED and SMALL.
    172172 * 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).
    176  ****************************************************************************************
    177  * @ dst_gpt   : [in]  pointer on the destination GPT.
    178  * @ 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.
    181  * @ cow       : [in]  activate the COPY-On-Write mechanism if true.
    182  ***************************************************************************************/
    183 error_t hal_gpt_copy( gpt_t    * dst_gpt,
    184                       gpt_t    * src_gpt,
    185                       vpn_t      vpn_base,
    186                       vpn_t      vpn_size,
    187                       bool_t     cow );
    188 
    189 /****************************************************************************************
    190  * This function returns GPT_COW flag for a PTE defined by <gpt> and <vpn> arguments.
     173 * true: the GPT_WRITABLE flag is reset, and the GPT_COW flag is set.
     174 * A new second level PT2(s) is allocated for destination GPT if required.
     175 * It returns in the <ppn> and <mapped> arguments the PPN value for the copied PTE,
     176 * and a boolean indicating if the PTE is mapped and small, and was actually copied.
     177 ****************************************************************************************
     178 * @ dst_gpt      : [in]  local pointer on the local destination GPT.
     179 * @ src_gpt_xp   : [in]  extended pointer on the remote source GPT.
     180 * @ vpn_base     : [in]  vpn defining the PTE to be copied.
     181 * @ cow          : [in]  activate the COPY-On-Write mechanism if true.
     182 * @ ppn          : [out] PPN value (only if mapped is true).
     183 * @ mapped       : [out] true if src_gpt[vpn] actually copied to dst_gpt[vpn].
     184 * @ return 0 if success / return -1 if no memory for a new PT2.
     185 ***************************************************************************************/
     186error_t hal_gpt_pte_copy( gpt_t    * dst_gpt,
     187                          xptr_t     src_gpt_xp,
     188                          vpn_t      vpn,
     189                          bool_t     cow,
     190                          ppn_t    * ppn,
     191                          bool_t   * mapped );
     192
     193/****************************************************************************************
     194 * This function returns true if the MAPPED and SMALL flags are both set
     195 * for a PTE defined by <gpt> and <vpn> arguments.
    191196 ****************************************************************************************
    192197 * @ gpt       : [in]  pointer on the page table
    193198 * @ vpn       : [in]  virtual page number
    194  * @ returns true if GPT_COW is set.
     199 * @ returns true if MAPPED is set.
     200 ***************************************************************************************/
     201bool_t hal_gpt_pte_is_mapped( gpt_t * gpt,
     202                              vpn_t   vpn );
     203
     204/****************************************************************************************
     205 * This function returns true if the MAPPED, SMALL, and COW flags are all set
     206 * for a PTE defined by <gpt> and <vpn> arguments.
     207 ****************************************************************************************
     208 * @ gpt       : [in]  pointer on the page table
     209 * @ vpn       : [in]  virtual page number
     210 * @ returns true if COW is set.
    195211 ***************************************************************************************/
    196212bool_t hal_gpt_pte_is_cow( gpt_t * gpt,
    197213                           vpn_t   vpn );
    198214
     215/****************************************************************************************
     216 * This function atomically flip the COW flag and WRITABLE flag for all PTEs
     217 * of a remote GPT identified by the <gpt_xp>, <vpn_base>, and <vpn_size arguments.
     218 * - it set COW and reset WRITABLE when <set_cow> argument is true and PTE is WRITABLE.
     219 * - it set WRITABLE and reset COW when <set_cow> is false and PTE is COW.
     220 * It does nothing if the remote PTE is not MAPPED and SMALL.
     221 * It is called when a fork is executed, or when a COW must be resolved.
     222 ****************************************************************************************
     223 * @ set_cow   : [in]  set COW & reset WRITABLE if true / do the opposite if false.
     224 * @ gpt_xp    : [in]  extended pointer on the remote GPT.
     225 * @ vpn_base  : [in]  first virtual page.
     226 * @ vpn_size  : [in]  number of pages.
     227 ***************************************************************************************/
     228void hal_gpt_flip_cow( bool_t  set_cow,
     229                       xptr_t  gpt_xp,
     230                       vpn_t   vpn_base,
     231                       vpn_t   vpn_size );
     232
     233/****************************************************************************************
     234 * This function is used to maintain coherence amongst the multiple GPT copies.
     235 * It modifies an existing entry identified by the <vpn> argument in a remote GPT
     236 * identified by the <gpt_xp> argument, using remote accesses.
     237 * It cannot fail, because only MAPPED & SMALL entries are modified.
     238 ****************************************************************************************
     239 * @ gpt_xp    : [in] extended pointer on the page table
     240 * @ vpn       : [in] virtual page number
     241 * @ attr      : [in] generic attributes
     242 * @ ppn       : [in] physical page number
     243 ***************************************************************************************/
     244void hal_gpt_update_pte( xptr_t     gpt_xp,
     245                         vpn_t      vpn,
     246                         uint32_t   attr,
     247                         ppn_t      ppn );
     248
    199249
    200250#endif  /* _GPT_H_ */
     251
  • trunk/hal/generic/hal_interrupt.h

    r17 r408  
    2727#include <hal_types.h>
    2828
    29 //////////////////////////////////////////////////////////////////////////////////////////
     29///////////////////////////////////////////////////////////////////////////////////////
    3030//     Architecture specific interrupt handler API
    3131//
    32 // The interrupted thread context (core registers) has been saved by the hal_kentry
    33 // function, in the cpu_uzone array stored in the user thread descriptor (for a core in
    34 // user mode), or in the kernel stack (for a core in kernel mode).
    35 // This array can be used (or not) by the specific interrupt handler.
    36 //
    37 // Any architecture specific implementation must implement this API.
    38 //////////////////////////////////////////////////////////////////////////////////////////
     32// The interrupted thread context (CPU registers) has been saved by the hal_kentry
     33// function, in the uzone array, that can be accessed through the "uzone" pointer
     34// stored in the thread descriptor.
     35///////////////////////////////////////////////////////////////////////////////////////
    3936
    40 /**** forward declaration  ****/
    4137
    42 struct thread_s;
    43 
    44 /******************************************************************************************
     38/**************************************************************************************
    4539 * This function implements the TSAR_MIPS32 specific interrupt handler.
    46  ******************************************************************************************
    47  * @ this     : pointer on the interrupted thread.
    48  * @ regs_tbl : array containing the core registers values, saved by hal_kentry.
    49  *****************************************************************************************/
    50 void hal_do_interrupt( struct thread_s * this,
    51                                reg_t           * regs_tbl );
     40 *************************************************************************************/
     41void hal_do_interrupt();
    5242
    5343
  • trunk/hal/generic/hal_special.h

    r407 r408  
    4949/*****************************************************************************************
    5050 * This function returns the current value of the hardware cycles counter.
     51 * This cycle counter is reset when the core is initialised (at each boot).
    5152 ****************************************************************************************/
    5253inline reg_t hal_time_stamp();
  • trunk/hal/generic/hal_switch.h

    r407 r408  
    4646/*************************************************************************************
    4747 * 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
     48 * hal_cpu_context_save() functio to save the calling CPU register values to a
    4949 * CPU context identified by the <ctx> pointer.
    5050 * This function does NOT modify any register before saving values into context.
    5151 * The architecture specific hal_cpu_context_t structure used to store a CPU context
    5252 * 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.
    5753 * When the save is completed, it simply returns to the calling function.
    5854 *************************************************************************************
    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).
     55 * @ ctx     : local pointer on CPU context.
    6256 ************************************************************************************/
    63 void hal_do_cpu_save( void * ctx,
    64                       void * thread,
    65                       int    offset );
     57void hal_do_cpu_save( void * ctx );
    6658
    6759#endif  /* _HAL_SWITCH_H_ */
  • trunk/hal/generic/hal_syscall.h

    r407 r408  
    2727#include <hal_types.h>
    2828
    29 //////////////////////////////////////////////////////////////////////////////////////////
     29///////////////////////////////////////////////////////////////////////////////////////
    3030//     Kernel-side syscall handler API
    3131//
    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.
     32// This hal_do_syscall() function extract from the calling thread uzone array
     33// the syscall index, and the four syscall arguments.
     34// Then it calls the generic do_syscall() function,
     35// that calls itself the relevant kernel function, depending on the syscall index.
    3536//
    36 // Any architecture specific implementation must implement this API.
    37 //////////////////////////////////////////////////////////////////////////////////////////
    38 
    39 /**** forward declaration  ****/
    40 
    41 struct thread_s;
     37// When the generic do_syscall function returns, it saves the return value
     38// in the UZ_VO slot of the returning thread uzone, and update the UZ_EPC slot.
     39//
     40// WARNING: The returning thread can be different from the entering thread
     41// in the case of a sys_fork() system call.
     42///////////////////////////////////////////////////////////////////////////////////////
    4243
    4344
    44 /*****************************************************************************************
    45  * This function implements the ALMOS-MKH kernel_side syscall handler.
    46  *****************************************************************************************
    47  * @ this     : pointer on the calling thread.
    48  * @ regs_tbl : array containing the core registers values, saved by hal_kentry.
    49  ****************************************************************************************/
    50 void hal_do_syscall( struct thread_s * this,
    51                      reg_t           * regs_tbl );
     45/**************************************************************************************
     46 * This function implements the syscall handler for the TSAR architecture.
     47 *************************************************************************************/
     48void hal_do_syscall();
    5249
    5350
Note: See TracChangeset for help on using the changeset viewer.