Changeset 23 for trunk/hal/tsar_mips32
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- Location:
- trunk/hal/tsar_mips32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/hal_atomic.c
r8 r23 79 79 } 80 80 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 93 81 ////////////////////////////////////// 94 82 bool_t hal_atomic_cas( uint32_t * ptr, -
trunk/hal/tsar_mips32/hal_gpt.c
r1 r23 162 162 163 163 // compute is_ref 164 is_ref = process->is_ref;164 is_ref = ( GET_CXY( process->ref_xp ) == local_cxy ); 165 165 166 166 // get pointer on PT1 … … 238 238 239 239 printk("*** Page Table for process %x in cluster %x ***\n", 240 CURRENT_ PROCESS->pid , local_cxy );240 CURRENT_THREAD->process->pid , local_cxy ); 241 241 242 242 pt1 = (uint32_t *)gpt->ptr; … … 539 539 req.flags = AF_KERNEL | AF_ZERO; 540 540 page = (page_t *)kmem_alloc( &req ); 541 541 542 if( page == NULL ) 542 543 { … … 545 546 return ENOMEM; 546 547 } 548 547 549 pt2_ppn = ppm_page2ppn( page ); 548 550 pt2 = ppm_page2base( page ); … … 665 667 } // end hal_gpt_unlock_pte() 666 668 667 668 669 670 671 672 673 669 /////////////////////////////////////// 670 error_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.