Changeset 686 for trunk/hal/tsar_mips32/core
- Timestamp:
- Jan 13, 2021, 12:47:53 AM (4 years ago)
- Location:
- trunk/hal/tsar_mips32/core
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/core/hal_context.c
r679 r686 2 2 * hal_context.c - implementation of Thread Context API for TSAR-MIPS32 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019 )4 * Author Alain Greiner (2016,2017,2018,2019,2019) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 121 121 { 122 122 123 assert( __FUNCTION__, (sizeof(hal_cpu_context_t) <= CONFIG_CPU_CTX_SIZE), "illegal CPU context size" ); 123 assert( __FUNCTION__, (sizeof(hal_cpu_context_t) <= CONFIG_CPU_CTX_SIZE), 124 "illegal CPU context size" ); 124 125 125 126 // allocate memory for cpu_context 126 kmem_req_t req; 127 req.type = KMEM_KCM; 128 req.order = bits_log2( sizeof(hal_cpu_context_t) ); 129 req.flags = AF_KERNEL | AF_ZERO; 130 131 hal_cpu_context_t * context = kmem_alloc( &req ); 132 127 hal_cpu_context_t * context = kmem_alloc( bits_log2( sizeof(hal_cpu_context_t) ), 128 AF_KERNEL | AF_ZERO); 133 129 if( context == NULL ) return -1; 134 130 … … 152 148 hal_cpu_context_t * context = (hal_cpu_context_t *)thread->cpu_context; 153 149 154 assert( __FUNCTION__, (context != NULL ), "CPU context not allocated" ); 150 assert( __FUNCTION__, (context != NULL ), 151 "CPU context not allocated" ); 155 152 156 153 // compute the PPN for the GPT PT1 … … 405 402 void hal_cpu_context_destroy( thread_t * thread ) 406 403 { 407 kmem_req_t req; 408 404 // get pointer on CPU context 409 405 hal_cpu_context_t * ctx = thread->cpu_context; 410 406 411 407 // release CPU context if required 412 if( ctx != NULL ) 413 { 414 req.type = KMEM_KCM; 415 req.ptr = ctx; 416 kmem_free( &req ); 417 } 408 if( ctx != NULL ) kmem_free( ctx , bits_log2( sizeof(hal_cpu_context_t)) ); 418 409 419 410 } // end hal_cpu_context_destroy() … … 434 425 435 426 // allocate memory for fpu_context 436 kmem_req_t req; 437 req.type = KMEM_KCM; 438 req.flags = AF_KERNEL | AF_ZERO; 439 req.order = bits_log2( sizeof(hal_fpu_context_t) ); 440 441 hal_fpu_context_t * context = kmem_alloc( &req ); 427 hal_fpu_context_t * context = kmem_alloc( bits_log2( sizeof(hal_fpu_context_t) ), 428 AF_KERNEL | AF_ZERO ); 442 429 443 430 if( context == NULL ) return -1; … … 454 441 hal_fpu_context_t * context = thread->fpu_context; 455 442 456 assert( __FUNCTION__, (context != NULL) , "fpu context not allocated" ); 443 assert( __FUNCTION__, (context != NULL) , 444 "fpu context not allocated" ); 457 445 458 446 memset( context , 0 , sizeof(hal_fpu_context_t) ); … … 478 466 void hal_fpu_context_destroy( thread_t * thread ) 479 467 { 480 kmem_req_t req; 481 482 hal_fpu_context_t * context = thread->fpu_context; 468 // get pointer on FPU context 469 hal_fpu_context_t * ctx = thread->fpu_context; 483 470 484 471 // release FPU context if required 485 if( context != NULL ) 486 { 487 req.type = KMEM_KCM; 488 req.ptr = context; 489 kmem_free( &req ); 490 } 472 if( ctx != NULL ) kmem_free( ctx , bits_log2( sizeof(hal_fpu_context_t)) ); 491 473 492 474 } // end hal_fpu_context_destroy() -
trunk/hal/tsar_mips32/core/hal_drivers.c
r679 r686 2 2 * hal_drivers.c - Driver initializers for TSAR 3 3 * 4 * Copyright (c) 2017 Maxime Villard 4 * Author Maxime Villard (2017) 5 * 6 * Copyright (c) UPMC Sorbonne Universites 5 7 * 6 8 * This file is part of ALMOS-MKH. -
trunk/hal/tsar_mips32/core/hal_exception.c
r635 r686 228 228 // try to map the unmapped PTE 229 229 error = vmm_handle_page_fault( process, 230 bad_vaddr >> CONFIG_PPM_PAGE_ SHIFT);230 bad_vaddr >> CONFIG_PPM_PAGE_ORDER ); 231 231 232 232 if( error == EXCP_NON_FATAL ) // page-fault successfully handled … … 278 278 // try to handle a possible COW 279 279 error = vmm_handle_cow( process, 280 bad_vaddr >> CONFIG_PPM_PAGE_ SHIFT);280 bad_vaddr >> CONFIG_PPM_PAGE_ORDER ); 281 281 282 282 if( error == EXCP_NON_FATAL ) // COW successfully handled … … 358 358 remote_busylock_acquire( lock_xp ); 359 359 360 nolock_printk("\n=== thread(%x,%x) / core[% d] / cycle %d ===\n",361 process->pid, this->trdid, core->lid, (uint32_t)hal_get_cycles() );360 nolock_printk("\n=== thread(%x,%x) / core[%x,%d] / cycle %d ===\n", 361 process->pid, this->trdid, process->pid, core->lid, (uint32_t)hal_get_cycles() ); 362 362 363 363 nolock_printk("busylocks = %d / blocked_vector = %X / flags = %X\n\n", -
trunk/hal/tsar_mips32/core/hal_gpt.c
r679 r686 2 2 * hal_gpt.c - implementation of the Generic Page Table API for TSAR-MIPS32 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 37 37 38 38 //////////////////////////////////////////////////////////////////////////////////////// 39 // The Page Table for the TSAR-MIPS32 MMU is defined as a two levels radix tree. 40 // 41 // It defines two page sizes : 4 Kbytes pages, and 2 Mbytes pages. 42 // The virtual address space size is 4 Gbytes (32 bits virtual addresses). 43 // The physical address space is limited to 1 Tbytes (40 bits physical addresses). 44 // - For a 4 Kbytes page, the VPN uses 20 bits, and the PPN requires 28 bits. 45 // - For a 2 Mbytes page, the PPN uses 11 bits, and the PPN requires 19 bits. 46 // 47 // The first level array (PT1) contains 2048 entries, each entry contains 4 bytes, 48 // and this array is aligned on a 8K bytes boundary. 49 // 50 // The second level array (PT2) contains 512 entries, each entry contains 8 bytes, 51 // and this array is ligned on a 4K bytes boundary. 52 //////////////////////////////////////////////////////////////////////////////////////// 53 54 55 //////////////////////////////////////////////////////////////////////////////////////// 39 56 // This define the masks for the TSAR MMU PTE attributes (from TSAR MMU specification) 40 57 //////////////////////////////////////////////////////////////////////////////////////// … … 152 169 153 170 // check page size 154 assert( __FUNCTION__, (CONFIG_PPM_PAGE_SIZE == 4096) , "the TSAR page size must be 4 Kbytes\n" ); 155 156 // allocates 2 physical pages for PT1 157 kmem_req_t req; 158 req.type = KMEM_PPM; 159 req.order = 1; // 2 small pages 160 req.flags = AF_KERNEL | AF_ZERO; 161 base = kmem_alloc( &req ); 171 assert( __FUNCTION__, (CONFIG_PPM_PAGE_SIZE == 4096) , 172 "the TSAR page size must be 4 Kbytes\n" ); 173 174 // allocates 8 Kbytes for PT1 175 base = kmem_alloc( 13 , AF_ZERO ); 162 176 163 177 if( base == NULL ) … … 197 211 uint32_t * pt2; 198 212 uint32_t attr; 199 kmem_req_t req;200 213 201 214 thread_t * this = CURRENT_THREAD; … … 241 254 } 242 255 243 // release the page allocated for the PT2 244 req.type = KMEM_PPM; 245 req.ptr = pt2; 246 kmem_free( &req ); 256 // release the 4K bytes allocated for the PT2 257 kmem_free( pt2 , 12 ); 247 258 } 248 259 } 249 260 } 250 261 251 // release the PT1 252 req.type = KMEM_PPM; 253 req.ptr = pt1; 254 kmem_free( &req ); 262 // release the 8K bytes allocated for PT1 263 kmem_free( pt1 , 13 ); 255 264 256 265 #if DEBUG_HAL_GPT_DESTROY … … 272 281 xptr_t pte1_xp; // extended pointer on PT1[x1] entry 273 282 uint32_t pte1; // value of PT1[x1] entry 274 275 kmem_req_t req; // kmem request fro PT2 allocation276 277 283 uint32_t * pt2; // local pointer on PT2 base 278 284 ppn_t pt2_ppn; // PPN of page containing PT2 … … 334 340 hal_disable_irq( &sr_save ); 335 341 336 req.type = KMEM_PPM; 337 req.order = 0; 338 req.flags = AF_ZERO | AF_KERNEL; 339 pt2 = kmem_remote_alloc( gpt_cxy , &req ); 342 // allocate a 4K bytes PT2 343 pt2 = kmem_remote_alloc( gpt_cxy , 12 , AF_ZERO ); 340 344 341 345 if( pt2 == NULL ) … … 863 867 uint32_t * dst_pt2; // local pointer on DST PT2 864 868 865 kmem_req_t req; // for PT2 allocation866 867 869 uint32_t src_pte1; 868 870 uint32_t dst_pte1; … … 917 919 if( (dst_pte1 & TSAR_PTE_MAPPED) == 0 ) 918 920 { 919 // allocate one physical page for a new PT2 920 req.type = KMEM_PPM; 921 req.order = 0; // 1 small page 922 req.flags = AF_KERNEL | AF_ZERO; 923 dst_pt2 = kmem_alloc( &req ); 921 // allocate one 4K bytes physical page for a new PT2 922 dst_pt2 = kmem_alloc( 12 , AF_ZERO ); 924 923 925 924 if( dst_pt2 == NULL ) -
trunk/hal/tsar_mips32/core/hal_ppm.c
r632 r686 79 79 80 80 // compute number of pages required to store page descriptor array 81 uint32_t pages_tbl_nr = bytes >> CONFIG_PPM_PAGE_ SHIFT;81 uint32_t pages_tbl_nr = bytes >> CONFIG_PPM_PAGE_ORDER; 82 82 83 83 // compute total number of reserved pages (kernel code & pages_tbl[]) … … 90 90 ppm->vaddr_base = NULL; 91 91 ppm->pages_tbl = (page_t*)( ppm->vaddr_base + 92 (pages_tbl_offset << CONFIG_PPM_PAGE_ SHIFT) );92 (pages_tbl_offset << CONFIG_PPM_PAGE_ORDER) ); 93 93 94 94 // initialize all page descriptors in pages_tbl[] -
trunk/hal/tsar_mips32/core/hal_special.c
r658 r686 2 2 * hal_special.c - implementation of Generic Special Register Access API for TSAR-MIPS32 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 55 55 // For the TSAR architecture, this function register the physical address of 56 56 // the first level page table (PT1) in the PTPR register. 57 // It activates the intructions MMU, and de-activates the data MMU. 57 // It activates the intructions MMU, and de-activates the data MMU, that is NOT 58 // used by the kernel for 32 bits architectures. 58 59 ///////////////////////////////////////////////////////////////////////////////// 59 60 void hal_mmu_init( gpt_t * gpt ) -
trunk/hal/tsar_mips32/core/hal_uspace.c
r679 r686 49 49 uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp ); 50 50 51 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), "must be called by an user thread" ); 51 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), 52 "must be called by an user thread" ); 52 53 53 54 #if DEBUG_HAL_USPACE … … 147 148 uint32_t cxy = (uint32_t)GET_CXY( k_src_xp ); 148 149 149 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), "must be called by an user thread" ); 150 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), 151 "must be called by an user thread" ); 150 152 151 153 #if DEBUG_HAL_USPACE … … 236 238 uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp ); 237 239 238 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), "must be called by an user thread" ); 240 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), 241 "must be called by an user thread" ); 239 242 240 243 hal_disable_irq( &save_sr ); … … 291 294 uint32_t cxy = (uint32_t)GET_CXY( k_src_xp ); 292 295 293 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), "must be called by an user thread" ); 296 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), 297 "must be called by an user thread" ); 294 298 295 299 hal_disable_irq( &save_sr ); … … 343 347 uint32_t str = (uint32_t)u_str; 344 348 345 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), "must be called by an user thread" ); 349 assert( __FUNCTION__, (CURRENT_THREAD->process->pid > 0), 350 "must be called by an user thread" ); 346 351 347 352 hal_disable_irq( &save_sr ); … … 352 357 "mfc2 $15, $1 \n" /* $15 <= MMU_MODE (DTLB off) */ 353 358 "ori $14, $15, 0x4 \n" /* $14 <= mode DTLB on */ 359 "mtc2 $14, $1 \n" /* set DTLB on */ 354 360 "1: \n" 355 "mtc2 $14, $1 \n" /* set DTLB on */356 361 "lb $12, 0($13) \n" /* $12 <= one byte from u_space */ 362 "beq $12, $0, 2f \n" /* exit loop when NUL found */ 363 "addi $13, $13, 1 \n" /* increment address */ 364 "j 1b \n" /* jump to next iteration */ 365 "addi %0, %0, 1 \n" /* increment count if not NUL */ 366 "2: \n" 357 367 "mtc2 $15, $1 \n" /* set DTLB off */ 358 "addi $13, $13, 1 \n" /* increment address */359 "bne $12, $0, 1b \n" /* loop until NUL found */360 "addi %0, %0, 1 \n" /* increment count */361 368 ".set reorder \n" 362 369 : "+r"(count)
Note: See TracChangeset
for help on using the changeset viewer.