Changeset 407 for trunk/hal/generic
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (7 years ago)
- 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 40 40 41 41 /**************************************************************************************** 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 ***************************************************************************************/ 47 error_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. 44 52 **************************************************************************************** 45 53 * @ thread : pointer on the thread descriptor. 46 * @ return 0 if success / return ENOMEM if error54 * @ return 0 if success / return -1 if failure. 47 55 ***************************************************************************************/ 48 56 error_t hal_cpu_context_create( struct thread_s * thread ); 49 57 50 58 /**************************************************************************************** 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 54 63 **************************************************************************************** 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. 58 65 ***************************************************************************************/ 59 error_t hal_cpu_context_copy( struct thread_s * dst, 60 struct thread_s * src ); 66 void hal_cpu_context_display( struct thread_s * thread ); 61 67 62 68 /**************************************************************************************** … … 67 73 void hal_cpu_context_destroy( struct thread_s * thread ); 68 74 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 77 80 78 81 /**************************************************************************************** 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. 82 84 **************************************************************************************** 83 85 * @ thread : pointer on the thread descriptor. 86 * @ return 0 if success / return -1 if failure. 84 87 ***************************************************************************************/ 85 void hal_cpu_context_load( struct thread_s * thread );88 error_t hal_fpu_context_alloc( struct thread_s * thread ); 86 89 87 90 /**************************************************************************************** 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. 100 93 **************************************************************************************** 101 94 * @ dst : pointer on the destination thread descriptor. 102 95 * @ src : pointer on the source thread descriptor. 103 * @ return 0 if success / return ENOMEM if error104 96 ***************************************************************************************/ 105 error_thal_fpu_context_copy( struct thread_s * dst,97 void hal_fpu_context_copy( struct thread_s * dst, 106 98 struct thread_s * src ); 107 99 -
trunk/hal/generic/hal_gpt.h
r406 r407 43 43 44 44 struct page_s; 45 struct process_s; 45 46 46 47 /**************************************************************************************** … … 48 49 ***************************************************************************************/ 49 50 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 */ 63 64 64 65 /**************************************************************************************** … … 70 71 void * ptr; /*! local pointer on GPT root */ 71 72 ppn_t ppn; /*! PPN of GPT root */ 72 struct page_s * page; /*! local pointer on GPT root page descriptor */73 73 } 74 74 gpt_t; … … 98 98 * This function prints on the kernel terminal the content of a generic page table. 99 99 **************************************************************************************** 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 ***************************************************************************************/ 102 void hal_gpt_display( struct process_s * process ); 105 103 106 104 /**************************************************************************************** … … 169 167 170 168 /**************************************************************************************** 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). 176 176 **************************************************************************************** 177 177 * @ dst_gpt : [in] pointer on the destination GPT. 178 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. 179 181 * @ cow : [in] activate the COPY-On-Write mechanism if true. 180 182 ***************************************************************************************/ 181 183 error_t hal_gpt_copy( gpt_t * dst_gpt, 182 184 gpt_t * src_gpt, 185 vpn_t vpn_base, 186 vpn_t vpn_size, 183 187 bool_t cow ); 184 188 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 ***************************************************************************************/ 196 bool_t hal_gpt_pte_is_cow( gpt_t * gpt, 197 vpn_t vpn ); 198 185 199 186 200 #endif /* _GPT_H_ */ -
trunk/hal/generic/hal_ppm.h
r315 r407 54 54 error_t hal_ppm_init( boot_info_t * info ); 55 55 56 /****************************************************************************************57 * This function initializes the architecture specific core registers, for the58 * 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 64 56 #endif /* HAL_PPM_H_ */ -
trunk/hal/generic/hal_remote.h
r313 r407 133 133 * @ xp : extended pointer to remote data 134 134 * @ mask : local mask value. 135 * @ return old value (before increment) of the remote integer135 * @ return old value (before mask) of the remote integer 136 136 ****************************************************************************************/ 137 137 uint32_t hal_remote_atomic_and( xptr_t xp, … … 144 144 * @ xp : extended pointer to remote data 145 145 * @ mask : local mask value. 146 * @ return old value (before increment) of the remote integer146 * @ return old value (before mask) of the remote integer 147 147 ****************************************************************************************/ 148 148 uint32_t hal_remote_atomic_or( xptr_t xp, -
trunk/hal/generic/hal_special.h
r401 r407 70 70 71 71 /***************************************************************************************** 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 /*****************************************************************************************77 72 * This function writes into the proper core register to enable the floating point unit. 78 73 ****************************************************************************************/ … … 128 123 129 124 /***************************************************************************************** 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. 131 127 ****************************************************************************************/ 132 void hal_fixed_delay( );128 void hal_fixed_delay( uint32_t delay ); 133 129 134 130 /***************************************************************************************** -
trunk/hal/generic/hal_switch.h
r405 r407 1 1 /* 2 * hal_switch.h - TSARarchitecture context switch function2 * hal_switch.h - Generic architecture context switch function 3 3 * 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 6 7 * 7 * This file is part of ALMOS- kernel.8 * This file is part of ALMOS-MKH. 8 9 * 9 * ALMOS- kernelis free software; you can redistribute it and/or modify it10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 11 * under the terms of the GNU General Public License as published by 11 12 * the Free Software Foundation; version 2.0 of the License. 12 13 * 13 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 14 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 18 * 18 19 * 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, 20 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ … … 24 25 #define _HAL_SWITCH_H_ 25 26 27 struct thread_s; 28 26 29 /************************************************************************************* 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. 38 39 ************************************************************************************* 39 * @ ctx_ old : local pointer on the old threadcontext.40 * @ ctx_ne w : local pointer on the new threadcontext.40 * @ ctx_current : local pointer on current thread CPU context. 41 * @ ctx_next : local pointer on new thread CPU context. 41 42 ************************************************************************************/ 42 void hal_do_ switch( void * ctx_old,43 void * ctx_new );43 void hal_do_cpu_switch( void * ctx_old, 44 void * ctx_new ); 44 45 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 ************************************************************************************/ 63 void hal_do_cpu_save( void * ctx, 64 void * thread, 65 int offset ); 45 66 46 67 #endif /* _HAL_SWITCH_H_ */ -
trunk/hal/generic/hal_syscall.h
r405 r407 1 1 /* 2 * hal_ syscall.h - Architecture specificsyscall handler API definition.2 * hal_kernel_syscall.h - Architecture specific kernel_side syscall handler API definition. 3 3 * 4 4 * Author Alain Greiner (2016,2017) … … 22 22 */ 23 23 24 #ifndef _HAL_ SYSCALL_H_25 #define _HAL_ SYSCALL_H_24 #ifndef _HAL_KERNEL_SYSCALL_H_ 25 #define _HAL_KERNEL_SYSCALL_H_ 26 26 27 27 #include <hal_types.h> 28 28 29 29 ////////////////////////////////////////////////////////////////////////////////////////// 30 // ARchitecture specificsyscall handler API30 // Kernel-side syscall handler API 31 31 // 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. 36 35 // 37 36 // Any architecture specific implementation must implement this API. … … 44 43 45 44 /***************************************************************************************** 46 * This function implements the ALMOS-MKH syscall handler.45 * This function implements the ALMOS-MKH kernel_side syscall handler. 47 46 ***************************************************************************************** 48 47 * @ this : pointer on the calling thread. … … 53 52 54 53 55 #endif // _HAL_ SYSCALL_H_54 #endif // _HAL_KERNEL_SYSCALL_H_ -
trunk/hal/generic/hal_uspace.h
r299 r407 62 62 63 63 /***************************************************************************************** 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. 65 67 * 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 handling67 68 ***************************************************************************************** 68 69 * @ u_dst : destination buffer address in user space. … … 70 71 * @ max_size : max number of characters to be copied. 71 72 ****************************************************************************************/ 72 extern error_thal_strcpy_from_uspace( char * k_dst,73 74 73 extern void hal_strcpy_from_uspace( char * k_dst, 74 char * u_src, 75 uint32_t max_size ); 75 76 76 77 /***************************************************************************************** 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. 78 81 * 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 handling80 82 ***************************************************************************************** 81 83 * @ u_dst : destination buffer address in user space. … … 83 85 * @ max_size : max number of characters to be copied. 84 86 ****************************************************************************************/ 85 extern error_thal_strcpy_to_uspace( char * u_dst,86 87 87 extern void hal_strcpy_to_uspace( char * u_dst, 88 char * k_src, 89 uint32_t max_size ); 88 90 89 91 /*****************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.