Changeset 255
- Timestamp:
- Oct 9, 2013, 9:32:41 AM (11 years ago)
- Location:
- soft/giet_vm
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/boot/boot_init.c
r253 r255 69 69 #include <stdarg.h> 70 70 71 71 72 #if !defined(NB_CLUSTERS) 72 73 # error The NB_CLUSTERS value must be defined in the 'giet_config.h' file ! … … 80 81 # error The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file ! 81 82 #endif 83 84 #define max(x, y) (((x) > (y)) ? (x) : (y)) 85 82 86 83 87 //////////////////////////////////////////////////////////////////////////// … … 555 559 556 560 ///////////////////////////////////////////////////////////////////// 557 // This function build the page table for a given vspace.561 // This function builds the page table for a given vspace. 558 562 // The physical base addresses for all vsegs (global and private) 559 563 // must have been previously computed and stored in the mapping. … … 577 581 for (vseg_id = vspace[vspace_id].vseg_offset; 578 582 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 579 vseg_id++) 583 vseg_id++) 580 584 { 581 585 vpn = vseg[vseg_id].vbase >> 12; … … 597 601 boot_puts(" / npages = "); 598 602 boot_putd(npages); 603 boot_puts(" / vbase = "); 604 boot_putx(vseg[vseg_id].vbase); 599 605 boot_puts(" / pbase = "); 600 606 boot_putl(vseg[vseg_id].pbase); … … 614 620 { 615 621 vpn = vseg[vseg_id].vbase >> 12; 616 ppn = (unsigned int) (vseg[vseg_id].pbase >> 12);622 ppn = (unsigned int) (vseg[vseg_id].pbase >> 12); 617 623 npages = vseg[vseg_id].length >> 12; 618 624 if ((vseg[vseg_id].length & 0xFFF) != 0) npages++; … … 630 636 boot_puts(" / npages = "); 631 637 boot_putd(npages); 638 boot_puts(" / vbase = "); 639 boot_putx(vseg[vseg_id].vbase); 632 640 boot_puts(" / pbase = "); 633 641 boot_putl(vseg[vseg_id].pbase); … … 646 654 647 655 /////////////////////////////////////////////////////////////////////////// 648 // Align the value of paddr or vaddr to the required alignement,656 // Aligns the value of paddr or vaddr to the required alignement, 649 657 // defined by alignPow2 == L2(alignement). 650 658 /////////////////////////////////////////////////////////////////////////// … … 660 668 return ((vaddr + mask) & ~mask); 661 669 } 670 671 672 673 /////////////////////////////////////////////////////////// 674 // Maps vseg on a pbase with identity mapping required 675 // The pseg is already set 676 // The length of the vseg must already be known 677 /////////////////////////////////////////////////////////// 678 void boot_vseg_set_paddr_ident(mapping_vseg_t * vseg) { 679 unsigned int vseg_id; 680 681 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 682 mapping_vseg_t * vseg_base = boot_get_vseg_base(header); 683 684 if (vseg->pbase_set != 0) { 685 boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function (internal error):\n"); 686 boot_puts("*** vseg->pbase already set\n"); 687 boot_exit(); 688 } 689 690 for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { 691 // Already mapped vseg on the same pseg 692 if (vseg_base[vseg_id].psegid == vseg->psegid && vseg_base[vseg_id].pbase_set == 1) { 693 // Checking overlap condition 694 if (vseg->vbase == vseg_base[vseg_id].pbase || 695 ((vseg->vbase < vseg_base[vseg_id].pbase) && (vseg->vbase + vseg->length > vseg_base[vseg_id].pbase)) || 696 ((vseg->vbase > vseg_base[vseg_id].pbase) && (vseg_base[vseg_id].pbase + vseg_base[vseg_id].length > vseg->vbase))) { 697 boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr_ident() function\n"); 698 boot_puts("*** Overlapping segments:\n"); 699 boot_puts(" seg with base = "); 700 boot_putl(vseg->vbase); 701 boot_puts(" - length = "); 702 boot_putl(vseg->length); 703 boot_puts("\n"); 704 boot_puts(" seg with base = \n"); 705 boot_putl(vseg_base[vseg_id].vbase); 706 boot_puts(" - length = "); 707 boot_putl(vseg_base[vseg_id].length); 708 boot_puts("\n"); 709 boot_exit(); 710 } 711 } 712 } 713 vseg->pbase = vseg->vbase; 714 vseg->pbase_set = 1; 715 } 716 717 718 719 /////////////////////////////////////////////////////////// 720 // Maps vseg on a pbase with no identity mapping required 721 // The pseg is already set 722 // The length of the vseg must already be known 723 /////////////////////////////////////////////////////////// 724 void boot_vseg_set_paddr(mapping_vseg_t * vseg) { 725 unsigned int vseg_id; 726 unsigned int nb_vsegs_mapped = 0; 727 unsigned int mapped = 0; 728 int i = 0; 729 730 paddr_t prev_base; 731 paddr_t prev_length = 0; 732 paddr_t curr_base = 0; 733 paddr_t curr_length = 0; 734 paddr_t next_base = 0; 735 paddr_t next_length = 0; 736 737 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 738 mapping_vseg_t * vseg_base = boot_get_vseg_base(header); 739 mapping_vobj_t * vobj_base = boot_get_vobj_base(header); 740 mapping_pseg_t * pseg = boot_pseg_get(vseg->psegid); 741 742 const int align = max(vobj_base[vseg->vobj_offset].align, 12); 743 744 prev_base = pseg->base; 745 746 if (vseg->pbase_set != 0) { 747 boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function (internal error):\n"); 748 boot_puts("*** vseg->pbase already set\n"); 749 boot_exit(); 750 } 751 752 // We now determinine the physical base address of the vseg 753 // Method: 754 // Now that all identity segments have been mapped 755 // We are free to place the vseg where we want 756 // From a logical point of view, we have the list of mapped vsegs ordered by their pbase (increasing) 757 // We try to place the vseg between two consecutive elements of this list 758 // If this fails, we try between the next two mapped vsegs 759 760 // Counting the number of vsegs mapped on this pseg 761 // We also initialize curr_base and curr_length with some values 762 for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { 763 if (vseg_base[vseg_id].psegid == vseg->psegid && vseg_base[vseg_id].pbase_set == 1) { 764 nb_vsegs_mapped++; 765 curr_base = vseg_base[vseg_id].pbase; 766 curr_length = vseg_base[vseg_id].length; 767 } 768 } 769 770 if (nb_vsegs_mapped == 0) { 771 if (vseg->length <= pseg->length) { 772 vseg->pbase = pseg->base; 773 vseg->pbase_set = 1; 774 return; 775 } 776 else { 777 boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function\n"); 778 boot_puts("*** PSEG is too small for mapping vseg (base:"); 779 boot_putl(vseg->vbase); 780 boot_puts(" - length: "); 781 boot_putl(vseg->length); 782 boot_puts(")\n"); 783 boot_exit(); 784 } 785 } 786 787 // We look for the vseg mapped on the same pseg having the smallest vaddr 788 for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { 789 if (vseg_base[vseg_id].psegid == vseg->psegid 790 && &vseg_base[vseg_id] != vseg 791 && vseg_base[vseg_id].pbase_set == 1 792 && vseg_base[vseg_id].pbase < curr_base) { 793 curr_base = vseg_base[vseg_id].pbase; 794 curr_length = vseg_base[vseg_id].length; 795 } 796 } 797 798 // We iterate on each vseg mapped in the order of their growing pbase 799 // and try to insert the current vseg right after each 800 while (i < nb_vsegs_mapped) { 801 if (paddr_align_to(prev_base + prev_length, align) + vseg->length <= curr_base) { 802 vseg->pbase = paddr_align_to(prev_base + prev_length, align); 803 vseg->pbase_set = 1; 804 mapped = 1; 805 break; 806 } 807 else if (i < nb_vsegs_mapped - 1) { 808 int found = 0; 809 next_base = 0; 810 // We search for the vseg having the minimal pbase which is more than the pbase of the current vseg 811 for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { 812 if (vseg_base[vseg_id].psegid == vseg->psegid 813 && &vseg_base[vseg_id] != vseg 814 && vseg_base[vseg_id].pbase_set == 1 815 && (vseg_base[vseg_id].pbase < next_base || !found) 816 && vseg_base[vseg_id].pbase > curr_base) { 817 found = 1; 818 next_base = vseg_base[vseg_id].pbase; 819 next_length = vseg_base[vseg_id].length; 820 } 821 } 822 if (!found) { 823 boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function (internal error):\n"); 824 boot_puts("*** Next vseg not found\n"); 825 boot_exit(); 826 } 827 828 prev_base = curr_base; 829 prev_length = curr_length; 830 831 curr_base = next_base; 832 curr_length = next_length; 833 } 834 else { 835 // The current vseg is the last one (highest mapped paddr on this pseg) 836 // We try to insert the current vseg after it 837 if (paddr_align_to(curr_base + curr_length, align) + vseg->length <= pseg->base + pseg->length) { 838 vseg->pbase = paddr_align_to(curr_base + curr_length, align); 839 vseg->pbase_set = 1; 840 mapped = 1; 841 } 842 } 843 i++; 844 } 845 846 if (!mapped) { 847 boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function:\n"); 848 boot_puts("*** Not enough space to map vseg (base: "); 849 boot_putl(vseg->vbase); 850 boot_puts(" - length: "); 851 boot_putl(vseg->length); 852 boot_puts(")\n"); 853 boot_exit(); 854 } 855 } 856 662 857 663 858 /////////////////////////////////////////////////////////////////////////// … … 666 861 // It updates the pbase and the length fields of the vseg. 667 862 // It updates the pbase and vbase fields of all vobjs in the vseg. 668 // It updates the next_base field of the pseg, and checks overflow.669 863 // It updates the boot_ptabs_paddr[] and boot_ptabs_vaddr[] arrays. 670 864 // It is a global vseg if vspace_id = (-1). … … 675 869 unsigned int cur_vaddr; 676 870 paddr_t cur_paddr; 871 paddr_t cur_length; 677 872 unsigned int offset; 678 873 679 874 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 680 mapping_vobj_t * vobj = boot_get_vobj_base(header); 681 682 // get physical segment pointer 683 mapping_pseg_t* pseg = boot_pseg_get(vseg->psegid); 684 685 // compute vseg physical base address 686 if (vseg->ident != 0) // identity mapping required 687 { 688 vseg->pbase = vseg->vbase; 689 } 690 else // unconstrained mapping 691 { 692 vseg->pbase = pseg->next_base; 693 694 // test alignment constraint 695 if (vobj[vseg->vobj_offset].align) 696 { 697 vseg->pbase = paddr_align_to(vseg->pbase, vobj[vseg->vobj_offset].align); 698 } 699 } 875 mapping_vobj_t * vobj = boot_get_vobj_base(header); 876 877 // We make a first loop on the vobj of the vseg to determine the real length of the vseg 878 // This length is required to determine the pbase of the vseg 879 cur_length = 0; 880 for (vobj_id = vseg->vobj_offset; vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) { 881 if (vobj[vobj_id].align) { 882 cur_length = vaddr_align_to(cur_length, vobj[vobj_id].align); 883 } 884 cur_length += vobj[vobj_id].length; 885 } 886 vseg->length = paddr_align_to(cur_length, 12); 887 888 // We can now compute the vseg physical base address 889 if (vseg->ident != 0) { 890 // identity mapping required 891 boot_vseg_set_paddr_ident(vseg); 892 } 893 else { 894 // unconstrained mapping 895 boot_vseg_set_paddr(vseg); 896 } 897 700 898 701 899 // loop on vobjs contained in vseg to : 702 900 // (1) computes the length of the vseg, 703 901 // (2) initialize the vaddr and paddr fields of all vobjs, 704 // (3) initialize the page table pointers arrays 902 // (3) initialize the page table pointers arrays 705 903 706 904 cur_vaddr = vseg->vbase; 707 905 cur_paddr = vseg->pbase; 708 906 709 for (vobj_id = vseg->vobj_offset; 710 vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) 711 { 712 if (vobj[vobj_id].align) 713 { 907 for (vobj_id = vseg->vobj_offset; 908 vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) { 909 if (vobj[vobj_id].align) { 714 910 cur_paddr = paddr_align_to(cur_paddr, vobj[vobj_id].align); 715 911 cur_vaddr = vaddr_align_to(cur_vaddr, vobj[vobj_id].align); … … 729 925 } 730 926 // we need at least one PT2 731 if (vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE)) 927 if (vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE)) 732 928 { 733 929 boot_puts("\n[BOOT ERROR] in boot_vseg_map() function, "); … … 741 937 742 938 // reset all valid bits in PT1 743 for ( offset = 0 ; offset < 8192; offset = offset + 4)939 for (offset = 0; offset < 8192; offset = offset + 4) 744 940 { 745 941 boot_physical_write(cur_paddr + offset, 0); … … 754 950 cur_paddr = cur_paddr + vobj[vobj_id].length; 755 951 } // end for vobjs 756 757 //set the vseg length758 vseg->length = vaddr_align_to((unsigned int)(cur_paddr - vseg->pbase), 12);759 760 // checking pseg overflow761 if ((vseg->pbase < pseg->base) ||762 ((vseg->pbase + vseg->length) > (pseg->base + pseg->length)))763 {764 boot_puts("\n[BOOT ERROR] in boot_vseg_map() function\n");765 boot_puts("impossible mapping for virtual segment: ");766 boot_puts(vseg->name);767 boot_puts("\n");768 boot_puts("vseg pbase = ");769 boot_putl(vseg->pbase);770 boot_puts("\n");771 boot_puts("vseg length = ");772 boot_putx(vseg->length);773 boot_puts("\n");774 boot_puts("pseg pbase = ");775 boot_putl(pseg->base);776 boot_puts("\n");777 boot_puts("pseg length = ");778 boot_putl(pseg->length);779 boot_puts("\n");780 boot_exit();781 }782 952 783 953 #if BOOT_DEBUG_PT … … 792 962 #endif 793 963 794 // set the next_base field in pseg when it's a RAM795 if ( pseg->type == PSEG_TYPE_RAM )796 {797 pseg->next_base = vseg->pbase + vseg->length;798 }799 964 } // end boot_vseg_map() 800 965 … … 835 1000 836 1001 #if BOOT_DEBUG_MAPPING 837 boot_puts("\nclusters = ");838 boot_putd( header->clusters );839 boot_puts("\nprocs = ");840 boot_putd( header->procs );841 boot_puts("\nperiphs = ");842 boot_putd( header->periphs );843 boot_puts("\nvspaces = ");844 boot_putd( header->vspaces );845 boot_puts("\ntasks = ");846 boot_putd( header->tasks );847 boot_puts("\n");848 849 unsigned int cluster_id;850 mapping_cluster_t * cluster = boot_get_cluster_base(header);851 for (cluster_id = 0; cluster_id < NB_CLUSTERS; cluster_id++)852 {853 boot_puts("\n cluster = ");854 boot_putd( cluster_id );855 boot_puts("\n procs = ");856 boot_putd( cluster[cluster_id].procs );857 boot_puts("\n psegs = ");858 boot_putd( cluster[cluster_id].psegs );859 boot_puts("\n periphs = ");860 boot_putd( cluster[cluster_id].periphs );861 boot_puts("\n");862 }1002 boot_puts("\nclusters = "); 1003 boot_putd( header->clusters ); 1004 boot_puts("\nprocs = "); 1005 boot_putd( header->procs ); 1006 boot_puts("\nperiphs = "); 1007 boot_putd( header->periphs ); 1008 boot_puts("\nvspaces = "); 1009 boot_putd( header->vspaces ); 1010 boot_puts("\ntasks = "); 1011 boot_putd( header->tasks ); 1012 boot_puts("\n"); 1013 1014 unsigned int cluster_id; 1015 mapping_cluster_t * cluster = boot_get_cluster_base(header); 1016 for (cluster_id = 0; cluster_id < NB_CLUSTERS; cluster_id++) 1017 { 1018 boot_puts("\n cluster = "); 1019 boot_putd( cluster_id ); 1020 boot_puts("\n procs = "); 1021 boot_putd( cluster[cluster_id].procs ); 1022 boot_puts("\n psegs = "); 1023 boot_putd( cluster[cluster_id].psegs ); 1024 boot_puts("\n periphs = "); 1025 boot_putd( cluster[cluster_id].periphs ); 1026 boot_puts("\n"); 1027 } 863 1028 #endif 864 1029 … … 871 1036 } // end boot_check_mapping() 872 1037 873 /////////////////////////////////////////////////////////////////////874 // This function initialises the physical pages table allocators875 // for all psegs (i.e. next_base field of the pseg).876 /////////////////////////////////////////////////////////////////////877 void boot_psegs_init()878 {879 mapping_header_t* header = (mapping_header_t *) &seg_mapping_base;880 mapping_cluster_t* cluster = boot_get_cluster_base(header);881 mapping_pseg_t* pseg = boot_get_pseg_base(header);882 883 unsigned int cluster_id;884 unsigned int pseg_id;885 886 #if BOOT_DEBUG_PT887 boot_puts ("\n[BOOT DEBUG] ****** psegs allocators initialisation ******\n");888 #endif889 890 for (cluster_id = 0; cluster_id < header->clusters; cluster_id++)891 {892 if (cluster[cluster_id].procs > NB_PROCS_MAX)893 {894 boot_puts("\n[BOOT ERROR] The number of processors in cluster ");895 boot_putd(cluster_id);896 boot_puts(" is larger than NB_PROCS_MAX \n");897 boot_exit();898 }899 900 for (pseg_id = cluster[cluster_id].pseg_offset;901 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;902 pseg_id++)903 {904 pseg[pseg_id].next_base = pseg[pseg_id].base;905 906 #if BOOT_DEBUG_PT907 boot_puts("cluster ");908 boot_putd(cluster_id);909 boot_puts(" / pseg ");910 boot_puts(pseg[pseg_id].name);911 boot_puts(" : next_base = ");912 boot_putl(pseg[pseg_id].next_base);913 boot_puts("\n");914 #endif915 }916 }917 918 boot_puts("\n[BOOT] Pseg allocators initialisation completed at cycle ");919 boot_putd(boot_proctime());920 boot_puts("\n");921 922 } // end boot_psegs_init()923 1038 924 1039 ///////////////////////////////////////////////////////////////////// … … 941 1056 942 1057 #if BOOT_DEBUG_PT 943 boot_puts("\n[BOOT DEBUG] ****** mapping global vsegs ******\n");1058 boot_puts("\n[BOOT DEBUG] ****** mapping global vsegs ******\n"); 944 1059 #endif 945 1060 946 1061 // step 1 : loop on virtual spaces to map global vsegs 1062 // Identity vseg first 947 1063 for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 948 1064 { 949 boot_vseg_map(&vseg[vseg_id], ((unsigned int) (-1))); 950 } 1065 if (vseg[vseg_id].ident == 1) { 1066 boot_vseg_map(&vseg[vseg_id], ((unsigned int) (-1))); 1067 } 1068 } 1069 // Non identity vseg second 1070 for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 1071 { 1072 if (vseg[vseg_id].ident == 0) { 1073 boot_vseg_map(&vseg[vseg_id], ((unsigned int) (-1))); 1074 } 1075 } 1076 951 1077 952 1078 // step 2 : loop on virtual vspaces to map private vsegs … … 955 1081 956 1082 #if BOOT_DEBUG_PT 957 boot_puts("\n[BOOT DEBUG] ****** mapping private vsegs in vspace "); 958 boot_puts(vspace[vspace_id].name); 959 boot_puts(" ******\n"); 960 #endif 961 1083 boot_puts("\n[BOOT DEBUG] ****** mapping private vsegs in vspace "); 1084 boot_puts(vspace[vspace_id].name); 1085 boot_puts(" ******\n"); 1086 #endif 1087 1088 // Identity vseg first 962 1089 for (vseg_id = vspace[vspace_id].vseg_offset; 963 1090 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 964 vseg_id++) 965 { 966 boot_vseg_map(&vseg[vseg_id], vspace_id); 1091 vseg_id++) { 1092 if (vseg[vseg_id].ident == 1) { 1093 boot_vseg_map(&vseg[vseg_id], vspace_id); 1094 } 1095 } 1096 // Non identity vseg second 1097 for (vseg_id = vspace[vspace_id].vseg_offset; 1098 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 1099 vseg_id++) { 1100 if (vseg[vseg_id].ident == 0) { 1101 boot_vseg_map(&vseg[vseg_id], vspace_id); 1102 } 967 1103 } 968 1104 } … … 972 1108 { 973 1109 #if BOOT_DEBUG_PT 974 boot_puts("\n[BOOT DEBUG] ****** building page table for vspace "); 975 boot_puts(vspace[vspace_id].name); 976 boot_puts(" ******\n"); 977 #endif 1110 boot_puts("\n[BOOT DEBUG] ****** building page table for vspace "); 1111 boot_puts(vspace[vspace_id].name); 1112 boot_puts(" ******\n"); 1113 #endif 1114 978 1115 boot_vspace_pt_build(vspace_id); 979 1116 980 1117 #if BOOT_DEBUG_PT 981 boot_puts("\n>>> page table physical address = ");982 boot_putl(boot_ptabs_paddr[vspace_id]);983 boot_puts(", number of PT2 = ");984 boot_putd((unsigned int) boot_max_pt2[vspace_id]);985 boot_puts("\n");986 #endif 987 } 988 989 boot_puts("\n[BOOT] Page Tables initiali sation completed at cycle ");1118 boot_puts("\n>>> page table physical address = "); 1119 boot_putl(boot_ptabs_paddr[vspace_id]); 1120 boot_puts(", number of PT2 = "); 1121 boot_putd((unsigned int) boot_max_pt2[vspace_id]); 1122 boot_puts("\n"); 1123 #endif 1124 } 1125 1126 boot_puts("\n[BOOT] Page Tables initialization completed at cycle "); 990 1127 boot_putd(boot_proctime()); 991 1128 boot_puts("\n"); … … 999 1136 // Warning : The MMU is supposed to be activated... 1000 1137 /////////////////////////////////////////////////////////////////////////////// 1001 void boot_vobjs_init() 1138 void boot_vobjs_init() 1002 1139 { 1003 1140 mapping_header_t* header = (mapping_header_t *) & seg_mapping_base; … … 1011 1148 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 1012 1149 { 1150 boot_set_mmu_ptpr((unsigned int) (boot_ptabs_paddr[vspace_id] >> 13)); 1013 1151 1014 1152 #if BOOT_DEBUG_VOBJS 1015 boot_puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace ");1016 boot_puts(vspace[vspace_id].name);1017 boot_puts(" ******\n");1153 boot_puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace "); 1154 boot_puts(vspace[vspace_id].name); 1155 boot_puts(" ******\n"); 1018 1156 #endif 1019 1157 … … 1023 1161 for (vobj_id = vspace[vspace_id].vobj_offset; 1024 1162 vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); 1025 vobj_id++) 1163 vobj_id++) 1026 1164 { 1027 1165 switch (vobj[vobj_id].type) … … 1037 1175 mwmr->lock = 0; 1038 1176 #if BOOT_DEBUG_VOBJS 1039 boot_puts("MWMR : ");1040 boot_puts(vobj[vobj_id].name);1041 boot_puts(" / depth = ");1042 boot_putd(mwmr->depth);1043 boot_puts(" / width = ");1044 boot_putd(mwmr->width);1045 boot_puts("\n");1177 boot_puts("MWMR : "); 1178 boot_puts(vobj[vobj_id].name); 1179 boot_puts(" / depth = "); 1180 boot_putd(mwmr->depth); 1181 boot_puts(" / width = "); 1182 boot_putd(mwmr->width); 1183 boot_puts("\n"); 1046 1184 #endif 1047 1185 break; … … 1050 1188 { 1051 1189 #if BOOT_DEBUG_VOBJS 1052 boot_puts("ELF : ");1053 boot_puts(vobj[vobj_id].name);1054 boot_puts(" / length = ");1055 boot_putx(vobj[vobj_id].length);1056 boot_puts("\n");1190 boot_puts("ELF : "); 1191 boot_puts(vobj[vobj_id].name); 1192 boot_puts(" / length = "); 1193 boot_putx(vobj[vobj_id].length); 1194 boot_puts("\n"); 1057 1195 #endif 1058 1196 break; … … 1061 1199 { 1062 1200 #if BOOT_DEBUG_VOBJS 1063 boot_puts("BLOB : ");1064 boot_puts(vobj[vobj_id].name);1065 boot_puts(" / length = ");1066 boot_putx(vobj[vobj_id].length);1067 boot_puts("\n");1201 boot_puts("BLOB : "); 1202 boot_puts(vobj[vobj_id].name); 1203 boot_puts(" / length = "); 1204 boot_putx(vobj[vobj_id].length); 1205 boot_puts("\n"); 1068 1206 #endif 1069 1207 break; … … 1075 1213 barrier->init = vobj[vobj_id].init; 1076 1214 #if BOOT_DEBUG_VOBJS 1077 boot_puts("BARRIER : ");1078 boot_puts(vobj[vobj_id].name);1079 boot_puts(" / init_value = ");1080 boot_putd(barrier->init);1081 boot_puts("\n");1215 boot_puts("BARRIER : "); 1216 boot_puts(vobj[vobj_id].name); 1217 boot_puts(" / init_value = "); 1218 boot_putd(barrier->init); 1219 boot_puts("\n"); 1082 1220 #endif 1083 1221 break; … … 1088 1226 *lock = 0; 1089 1227 #if BOOT_DEBUG_VOBJS 1090 boot_puts("LOCK : ");1091 boot_puts(vobj[vobj_id].name);1092 boot_puts("\n");1228 boot_puts("LOCK : "); 1229 boot_puts(vobj[vobj_id].name); 1230 boot_puts("\n"); 1093 1231 #endif 1094 1232 break; … … 1097 1235 { 1098 1236 #if BOOT_DEBUG_VOBJS 1099 boot_puts("BUFFER : ");1100 boot_puts(vobj[vobj_id].name);1101 boot_puts(" / paddr = ");1102 boot_putl(vobj[vobj_id].paddr);1103 boot_puts(" / length = ");1104 boot_putx(vobj[vobj_id].length);1105 boot_puts("\n");1237 boot_puts("BUFFER : "); 1238 boot_puts(vobj[vobj_id].name); 1239 boot_puts(" / paddr = "); 1240 boot_putl(vobj[vobj_id].paddr); 1241 boot_puts(" / length = "); 1242 boot_putx(vobj[vobj_id].length); 1243 boot_puts("\n"); 1106 1244 #endif 1107 1245 break; … … 1109 1247 case VOBJ_TYPE_MEMSPACE: 1110 1248 { 1111 giet_memspace_t * memspace = (giet_memspace_t *) vobj[vobj_id].vaddr;1249 giet_memspace_t * memspace = (giet_memspace_t *) vobj[vobj_id].vaddr; 1112 1250 memspace->buffer = (void *) vobj[vobj_id].vaddr + 8; 1113 1251 memspace->size = vobj[vobj_id].length - 8; 1114 1252 #if BOOT_DEBUG_VOBJS 1115 boot_puts("MEMSPACE : ");1116 boot_puts(vobj[vobj_id].name);1117 boot_puts(" / vaddr = ");1118 boot_putx(vobj[vobj_id].vaddr);1119 boot_puts(" / length = ");1120 boot_putx(vobj[vobj_id].length);1121 boot_puts(" / buffer = ");1122 boot_putx((unsigned int)memspace->buffer);1123 boot_puts(" / size = ");1124 boot_putx(memspace->size);1125 boot_puts("\n");1253 boot_puts("MEMSPACE : "); 1254 boot_puts(vobj[vobj_id].name); 1255 boot_puts(" / vaddr = "); 1256 boot_putx(vobj[vobj_id].vaddr); 1257 boot_puts(" / length = "); 1258 boot_putx(vobj[vobj_id].length); 1259 boot_puts(" / buffer = "); 1260 boot_putx((unsigned int) memspace->buffer); 1261 boot_puts(" / size = "); 1262 boot_putx(memspace->size); 1263 boot_puts("\n"); 1126 1264 #endif 1127 1265 break; … … 1131 1269 ptab_found = 1; 1132 1270 #if BOOT_DEBUG_VOBJS 1133 boot_puts("PTAB : ");1134 boot_puts(vobj[vobj_id].name);1135 boot_puts(" / length = ");1136 boot_putx(vobj[vobj_id].length);1137 boot_puts("\n");1271 boot_puts("PTAB : "); 1272 boot_puts(vobj[vobj_id].name); 1273 boot_puts(" / length = "); 1274 boot_putx(vobj[vobj_id].length); 1275 boot_puts("\n"); 1138 1276 #endif 1139 1277 break; … … 1144 1282 *addr = vobj[vobj_id].init; 1145 1283 #if BOOT_DEBUG_VOBJS 1146 boot_puts("CONST : ");1147 boot_puts(vobj[vobj_id].name);1148 boot_puts(" / Paddr :");1149 boot_putl(vobj[vobj_id].paddr);1150 boot_puts(" / init = ");1151 boot_putx(*addr);1152 boot_puts("\n");1284 boot_puts("CONST : "); 1285 boot_puts(vobj[vobj_id].name); 1286 boot_puts(" / Paddr :"); 1287 boot_putl(vobj[vobj_id].paddr); 1288 boot_puts(" / init = "); 1289 boot_putx(*addr); 1290 boot_puts("\n"); 1153 1291 #endif 1154 1292 break; … … 1238 1376 1239 1377 #if BOOT_DEBUG_PERI 1240 boot_puts("\n[BOOT DEBUG] ****** peripherals initialisation in cluster ");1241 boot_putd(cluster_id);1242 boot_puts(" ******\n");1378 boot_puts("\n[BOOT DEBUG] ****** peripherals initialisation in cluster "); 1379 boot_putd(cluster_id); 1380 boot_puts(" ******\n"); 1243 1381 #endif 1244 1382 … … 1254 1392 1255 1393 #if BOOT_DEBUG_PERI 1256 boot_puts("- peripheral type : ");1257 boot_putd(type);1258 boot_puts(" / pbase = ");1259 boot_putl(pbase);1260 boot_puts(" / channels = ");1261 boot_putd(channels);1262 boot_puts("\n");1394 boot_puts("- peripheral type : "); 1395 boot_putd(type); 1396 boot_puts(" / pbase = "); 1397 boot_putl(pbase); 1398 boot_puts(" / channels = "); 1399 boot_putd(channels); 1400 boot_puts("\n"); 1263 1401 #endif 1264 1402 … … 1270 1408 boot_physical_write(paddr, 1); 1271 1409 #if BOOT_DEBUG_PERI 1272 boot_puts("- IOC initialised\n");1410 boot_puts("- IOC initialised\n"); 1273 1411 #endif 1274 1412 } … … 1281 1419 } 1282 1420 #if BOOT_DEBUG_PERI 1283 boot_puts("- DMA initialised\n");1421 boot_puts("- DMA initialised\n"); 1284 1422 #endif 1285 1423 break; … … 1290 1428 } 1291 1429 #if BOOT_DEBUG_PERI 1292 boot_puts("- NIC initialised\n");1430 boot_puts("- NIC initialised\n"); 1293 1431 #endif 1294 1432 break; 1295 1433 case PERIPH_TYPE_TTY: // vci_multi_tty component 1296 1434 #if BOOT_DEBUG_PERI 1297 boot_puts("- TTY initialised\n");1435 boot_puts("- TTY initialised\n"); 1298 1436 #endif 1299 1437 break; … … 1310 1448 } 1311 1449 #if BOOT_DEBUG_PERI 1312 boot_puts("- IOB initialised\n");1450 boot_puts("- IOB initialised\n"); 1313 1451 #endif 1314 1452 break; … … 1317 1455 1318 1456 #if BOOT_DEBUG_PERI 1319 boot_puts("\n[BOOT DEBUG] ****** coprocessors initialisation in cluster ");1320 boot_putd(cluster_id);1321 boot_puts(" ******\n");1457 boot_puts("\n[BOOT DEBUG] ****** coprocessors initialisation in cluster "); 1458 boot_putd(cluster_id); 1459 boot_puts(" ******\n"); 1322 1460 #endif 1323 1461 … … 1333 1471 1334 1472 #if BOOT_DEBUG_PERI 1335 boot_puts("- coprocessor name : ");1336 boot_puts(coproc[coproc_id].name);1337 boot_puts(" / nb ports = ");1338 boot_putd((unsigned int) coproc[coproc_id].ports);1339 boot_puts("\n");1473 boot_puts("- coprocessor name : "); 1474 boot_puts(coproc[coproc_id].name); 1475 boot_puts(" / nb ports = "); 1476 boot_putd((unsigned int) coproc[coproc_id].ports); 1477 boot_puts("\n"); 1340 1478 #endif 1341 1479 … … 1354 1492 { 1355 1493 #if BOOT_DEBUG_PERI 1356 boot_puts(" port direction: PORT_TO_COPROC");1494 boot_puts(" port direction: PORT_TO_COPROC"); 1357 1495 #endif 1358 1496 mwmr_hw_init(coproc_pbase, … … 1365 1503 { 1366 1504 #if BOOT_DEBUG_PERI 1367 boot_puts(" port direction: PORT_FROM_COPROC");1505 boot_puts(" port direction: PORT_FROM_COPROC"); 1368 1506 #endif 1369 1507 mwmr_hw_init(coproc_pbase, … … 1374 1512 } 1375 1513 #if BOOT_DEBUG_PERI 1376 boot_puts(", with mwmr: ");1377 boot_puts(vobj[vobj_id].name);1378 boot_puts(" of vspace: ");1379 boot_puts(vspace[vspace_id].name);1514 boot_puts(", with mwmr: "); 1515 boot_puts(vobj[vobj_id].name); 1516 boot_puts(" of vspace: "); 1517 boot_puts(vspace[vspace_id].name); 1380 1518 #endif 1381 1519 } // end for cp_ports … … 1473 1611 1474 1612 #if BOOT_DEBUG_SCHED 1475 boot_puts("\n[BOOT DEBUG] Initialise schedulers in cluster ");1476 boot_putd(cluster_id);1477 boot_puts("\n");1613 boot_puts("\n[BOOT DEBUG] Initialise schedulers in cluster "); 1614 boot_putd(cluster_id); 1615 boot_puts("\n"); 1478 1616 #endif 1479 1617 … … 1523 1661 1524 1662 #if BOOT_DEBUG_SCHED 1525 boot_puts("\nProc ");1526 boot_putd(lpid);1527 boot_puts(" : scheduler virtual base address = ");1528 boot_putx( sched_vbase + (lpid<<12) );1529 boot_puts("\n");1663 boot_puts("\nProc "); 1664 boot_putd(lpid); 1665 boot_puts(" : scheduler virtual base address = "); 1666 boot_putx( sched_vbase + (lpid<<12) ); 1667 boot_puts("\n"); 1530 1668 #endif 1531 1669 // current processor scheduler pointer : psched … … 1552 1690 1553 1691 #if BOOT_DEBUG_SCHED 1554 boot_puts("- IRQ : icu = ");1555 boot_putd(icu_id);1556 boot_puts(" / type = ");1557 boot_putd(type);1558 boot_puts(" / isr = ");1559 boot_putd(isr_id);1560 boot_puts(" / channel = ");1561 boot_putd(channel);1562 boot_puts(" => vector_entry = ");1563 boot_putx( value );1564 boot_puts("\n");1692 boot_puts("- IRQ : icu = "); 1693 boot_putd(icu_id); 1694 boot_puts(" / type = "); 1695 boot_putd(type); 1696 boot_puts(" / isr = "); 1697 boot_putd(isr_id); 1698 boot_puts(" / channel = "); 1699 boot_putd(channel); 1700 boot_puts(" => vector_entry = "); 1701 boot_putx( value ); 1702 boot_puts("\n"); 1565 1703 #endif 1566 1704 } … … 1580 1718 1581 1719 #if BOOT_DEBUG_SCHED 1582 boot_puts("\n[BOOT DEBUG] Initialise task contexts for vspace ");1583 boot_puts(vspace[vspace_id].name);1584 boot_puts("\n");1720 boot_puts("\n[BOOT DEBUG] Initialise task contexts for vspace "); 1721 boot_puts(vspace[vspace_id].name); 1722 boot_puts("\n"); 1585 1723 #endif 1586 1724 // We must set the PTPR depending on the vspace, because the start_vector … … 1781 1919 1782 1920 #if BOOT_DEBUG_SCHED 1783 boot_puts("\nTask ");1784 boot_puts(task[task_id].name);1785 boot_puts(" (");1786 boot_putd(task_id);1787 boot_puts(") allocated to processor ");1788 boot_putd(gpid);1789 boot_puts("\n - ctx[LTID] = ");1790 boot_putd(ltid);1791 boot_puts("\n - ctx[SR] = ");1792 boot_putx(ctx_sr);1793 boot_puts("\n - ctx[SR] = ");1794 boot_putx(ctx_sp);1795 boot_puts("\n - ctx[RA] = ");1796 boot_putx(ctx_ra);1797 boot_puts("\n - ctx[EPC] = ");1798 boot_putx(ctx_epc);1799 boot_puts("\n - ctx[PTPR] = ");1800 boot_putx(ctx_ptpr);1801 boot_puts("\n - ctx[TTY] = ");1802 boot_putd(ctx_tty);1803 boot_puts("\n - ctx[NIC] = ");1804 boot_putd(ctx_nic);1805 boot_puts("\n - ctx[CMA] = ");1806 boot_putd(ctx_cma);1807 boot_puts("\n - ctx[IOC] = ");1808 boot_putd(ctx_ioc);1809 boot_puts("\n - ctx[TIM] = ");1810 boot_putd(ctx_tim);1811 boot_puts("\n - ctx[DMA] = ");1812 boot_putd(ctx_dma);1813 boot_puts("\n - ctx[PTAB] = ");1814 boot_putx(ctx_ptab);1815 boot_puts("\n - ctx[GTID] = ");1816 boot_putd(task_id);1817 boot_puts("\n - ctx[VSID] = ");1818 boot_putd(vspace_id);1819 boot_puts("\n");1921 boot_puts("\nTask "); 1922 boot_puts(task[task_id].name); 1923 boot_puts(" ("); 1924 boot_putd(task_id); 1925 boot_puts(") allocated to processor "); 1926 boot_putd(gpid); 1927 boot_puts("\n - ctx[LTID] = "); 1928 boot_putd(ltid); 1929 boot_puts("\n - ctx[SR] = "); 1930 boot_putx(ctx_sr); 1931 boot_puts("\n - ctx[SR] = "); 1932 boot_putx(ctx_sp); 1933 boot_puts("\n - ctx[RA] = "); 1934 boot_putx(ctx_ra); 1935 boot_puts("\n - ctx[EPC] = "); 1936 boot_putx(ctx_epc); 1937 boot_puts("\n - ctx[PTPR] = "); 1938 boot_putx(ctx_ptpr); 1939 boot_puts("\n - ctx[TTY] = "); 1940 boot_putd(ctx_tty); 1941 boot_puts("\n - ctx[NIC] = "); 1942 boot_putd(ctx_nic); 1943 boot_puts("\n - ctx[CMA] = "); 1944 boot_putd(ctx_cma); 1945 boot_puts("\n - ctx[IOC] = "); 1946 boot_putd(ctx_ioc); 1947 boot_puts("\n - ctx[TIM] = "); 1948 boot_putd(ctx_tim); 1949 boot_puts("\n - ctx[DMA] = "); 1950 boot_putd(ctx_dma); 1951 boot_puts("\n - ctx[PTAB] = "); 1952 boot_putx(ctx_ptab); 1953 boot_puts("\n - ctx[GTID] = "); 1954 boot_putd(task_id); 1955 boot_puts("\n - ctx[VSID] = "); 1956 boot_putd(vspace_id); 1957 boot_puts("\n"); 1820 1958 #endif 1821 1959 … … 1848 1986 boot_check_mapping(); 1849 1987 1850 // pseg allocators initialisation1851 boot_psegs_init();1852 1853 1988 // page table building 1854 1989 boot_pt_init(); 1855 1990 1856 // mmu activation ( with page table [0])1991 // mmu activation (with page table [0]) 1857 1992 boot_set_mmu_ptpr((unsigned int) (boot_ptabs_paddr[0] >> 13)); 1858 1993 boot_set_mmu_mode(0xF); … … 1864 1999 // vobjs initialisation 1865 2000 boot_vobjs_init(); 2001 2002 // reset ptpr with page table 0 2003 boot_set_mmu_ptpr((unsigned int) (boot_ptabs_paddr[0] >> 13)); 1866 2004 1867 2005 // peripherals initialisation -
soft/giet_vm/libs/spin_lock.c
r244 r255 39 39 "sc $3, 0($16) \n" /* try to get lock */ 40 40 "bnez $3, giet_lock_ok \n" /* exit if atomic */ 41 "nop \n" 41 42 42 43 "giet_lock_delay: \n" -
soft/giet_vm/libs/stdio.c
r253 r255 45 45 #define SYSCALL_NIC_SYNC_READ 0x1E 46 46 #define SYSCALL_NIC_SYNC_WRITE 0x1F 47 #define SYSCALL_SIM_HELPER_ACCESS 0x20 47 48 48 49 ////////////////////////////////////////////////////////////////////////////////// … … 851 852 852 853 854 //////////////////////////////////////////////////////////////////////////////////// 855 // giet_sc_stop() 856 // This function causes the Sim Helper to cause sc_stop() 857 //////////////////////////////////////////////////////////////////////////////////// 858 unsigned int giet_sc_stop() 859 { 860 unsigned int reg_index = 0; // Index of the SIMHELPER_SC_STOP register 861 return sys_call(SYSCALL_SIM_HELPER_ACCESS, reg_index, 0, 0, 0); 862 } 863 864 865 //////////////////////////////////////////////////////////////////////////////////// 866 // giet_end_simu() 867 // This function causes the Sim Helper to cause exit(val) 868 //////////////////////////////////////////////////////////////////////////////////// 869 unsigned int giet_end_simu(unsigned int val) 870 { 871 unsigned int reg_index = 1; // Index of the SIMHELPER_END_WITH_RETVAL register 872 return sys_call(SYSCALL_SIM_HELPER_ACCESS, reg_index, val, 0, 0); 873 } 874 875 876 //////////////////////////////////////////////////////////////////////////////////// 877 // giet_throw_soclib_exception() 878 // This function causes the Sim Helper to launch a soclib exception with val in message 879 //////////////////////////////////////////////////////////////////////////////////// 880 unsigned int giet_throw_soclib_exception(unsigned int val) 881 { 882 unsigned int reg_index = 2; // Index of the SIMHELPER_EXCEPT_WITH_VAL register 883 return sys_call(SYSCALL_SIM_HELPER_ACCESS, reg_index, val, 0, 0); 884 } 885 886 887 //////////////////////////////////////////////////////////////////////////////////// 888 // giet_pause_simu() 889 // This function causes the Sim Helper to pause the simulation 890 //////////////////////////////////////////////////////////////////////////////////// 891 unsigned int giet_pause_simu() 892 { 893 unsigned int reg_index = 3; // Index of the SIMHELPER_PAUSE_SIM register 894 return sys_call(SYSCALL_SIM_HELPER_ACCESS, reg_index, 0, 0, 0); 895 } 896 897 898 //////////////////////////////////////////////////////////////////////////////////// 899 // giet_raise_sigint() 900 // This function causes the Sim Helper to call raise(SIGINT) to interrupt simulation 901 //////////////////////////////////////////////////////////////////////////////////// 902 unsigned int giet_raise_sigint() 903 { 904 unsigned int reg_index = 5; // Index of the SIMHELPER_PAUSE_SIM register 905 return sys_call(SYSCALL_SIM_HELPER_ACCESS, reg_index, 0, 0, 0); 906 } 907 908 909 //////////////////////////////////////////////////////////////////////////////////// 910 // giet_simhelper_cycles() 911 // This function causes the Sim Helper to write the number of simulated cycles 912 // at address *retval 913 //////////////////////////////////////////////////////////////////////////////////// 914 unsigned int giet_simhelper_cycles(unsigned int * retval) 915 { 916 unsigned int reg_index = 4; // Index of the SIMHELPER_PAUSE_SIM register 917 return sys_call(SYSCALL_SIM_HELPER_ACCESS, reg_index, 0, (unsigned int) retval, 0); 918 } 919 920 921 853 922 // Local Variables: 854 923 // tab-width: 4 -
soft/giet_vm/libs/stdio.h
r253 r255 50 50 unsigned int giet_fb_cma_stop(); 51 51 52 /* Network controller relate functions */52 /* Network controller related functions */ 53 53 unsigned int giet_nic_cma_rx_init(void* buf0, void* buf1, unsigned int length); 54 54 unsigned int giet_nic_cma_tx_init(void* buf0, void* buf1, unsigned int length); 55 55 unsigned int giet_nic_cma_stop(); 56 57 /* Simulation Helper related functions */ 58 unsigned int giet_sc_stop(); 59 unsigned int giet_end_simu(unsigned int retval); 60 unsigned int giet_throw_soclib_exception(unsigned int val); 61 unsigned int giet_pause_simu(); 62 unsigned int giet_raise_sigint(); 63 unsigned int giet_simhelper_cycles(unsigned int * retval); 56 64 57 65 /* Misc */ -
soft/giet_vm/memo/include/pseg.h
r238 r255 58 58 public: 59 59 60 int32_t m_align; // alignment of the first vobj 60 61 bool m_ident; // identity mapping required if true 61 62 … … 66 67 size_t length() const; 67 68 size_t type() const; 68 //void add( VObj& vobj );//add a VObj69 69 70 void print( std::ostream &o) const;70 void print(std::ostream &o) const; 71 71 friend std::ostream &operator<<( std::ostream &o, const VSeg &s ) 72 72 { … … 75 75 } 76 76 77 VSeg& operator=( const VSeg &ref);77 VSeg& operator=(const VSeg &ref); 78 78 79 79 VSeg(); 80 VSeg( const VSeg &ref);80 VSeg(const VSeg &ref); 81 81 VSeg(std::string& binaryName, 82 82 std::string& name, … … 97 97 size_t m_type; 98 98 99 paddr_t m_pageLimit; // m_lma + m_length aligned on page size 100 paddr_t m_nextLma; // next free base 101 102 void confNextLma(); // check m_nextLma is whithin the seg limits 99 static size_t m_pageSize; 103 100 104 101 public: … … 106 103 std::vector<VSeg> m_vsegs; 107 104 108 paddr_t m_limit; // m_lma + m_length109 110 105 const std::string& name() const; 111 106 paddr_t lma() const; 112 107 paddr_t length() const; 113 108 size_t type() const; 114 paddr_t limit() const;115 paddr_t nextLma() const;116 109 117 110 void check() const; 118 111 119 112 void setName(std::string& name); 120 void setLma( 113 void setLma(paddr_t lma); 121 114 void setLength(paddr_t length); 122 115 123 static paddr_t align( 124 static paddr_t pageAlign( paddr_t toAlign);116 static paddr_t align(paddr_t toAlign, unsigned alignPow2); 117 static paddr_t pageAlign(paddr_t toAlign); 125 118 126 static void setPageSize(size_t pg); 119 static void setPageSize(size_t pg) { 120 m_pageSize = pg; 121 } 122 static size_t pageSize() { 123 return m_pageSize; 124 } 127 125 128 static size_t& pageSize(); 126 void add(VSeg& vseg); //add a VSeg 127 void addIdent(VSeg& vseg); 129 128 130 void add( VSeg& vseg ); //add a VSeg131 void addIdent( VSeg& vseg );132 129 133 void setNextLma( paddr_t nextLma); 134 void incNextLma( size_t inc); 130 void print(std::ostream &o) const; 135 131 136 void print( std::ostream &o ) const; 137 138 friend std::ostream &operator<<( std::ostream &o, const PSeg &s ) 132 friend std::ostream &operator<<(std::ostream &o, const PSeg &s ) 139 133 { 140 134 s.print(o); 141 135 return o; 142 136 } 143 PSeg & operator=( const PSeg &ref);137 PSeg & operator=(const PSeg &ref); 144 138 145 139 PSeg(); 146 PSeg( const PSeg &ref ); 147 PSeg( const std::string &name); 148 PSeg( const paddr_t lma); 149 PSeg( const std::string &name, 150 paddr_t lma, 151 paddr_t length, 152 size_t type); 140 PSeg(const PSeg &ref ); 141 PSeg(const std::string &name); 142 PSeg(const std::string &name, 143 paddr_t lma, 144 paddr_t length, 145 size_t type); 153 146 ~PSeg(); 154 147 }; -
soft/giet_vm/memo/src/memo.cpp
r238 r255 41 41 //#define MOVER_DEBUG 42 42 43 size_t PSeg::m_pageSize; 44 45 43 46 //////////////////////////////////////////// 44 MeMo::MeMo( 45 47 MeMo::MeMo(const std::string &filename, 48 const size_t pageSize) 46 49 : m_path(filename), 47 50 m_pathHandler(filename), … … 58 61 m_size = load_bin(m_path, m_data); 59 62 60 // checking signature 63 // checking signature 61 64 mapping_header_t* header = (mapping_header_t*)m_data; 62 65 if((IN_MAPPING_SIGNATURE != header->signature)) … … 92 95 93 96 ///////////////////////////////////////// 94 void MeMo::print( std::ostream &o) const97 void MeMo::print(std::ostream &o) const 95 98 { 96 99 std::cout << "All sections:" << std::endl; 97 FOREACH( sect, m_generator->get_section_table())100 FOREACH(sect, m_generator->get_section_table()) 98 101 { 99 102 assert(&*sect != NULL); … … 340 343 void MeMo::vseg_map( mapping_vseg_t* vseg) 341 344 { 342 mapping_vobj_t * vobj = get_vobj_base((mapping_header_t*) m_data );343 PSeg *ps = &(m_psegh.get(vseg->psegid));344 elfpp::section *sect = NULL;345 mapping_vobj_t * vobj = get_vobj_base((mapping_header_t*) m_data ); 346 PSeg * ps = &(m_psegh.get(vseg->psegid)); 347 elfpp::section * sect = NULL; 345 348 size_t cur_vaddr; 346 paddr_t cur_ paddr;349 paddr_t cur_length; 347 350 bool first = true; 348 351 bool aligned = false; 349 VSeg *vSO = new VSeg;350 mapping_vobj_t *cur_vobj;352 VSeg * vSO = new VSeg; 353 mapping_vobj_t * cur_vobj; 351 354 352 355 vSO->m_name = std::string(vseg->name); 353 356 vSO->m_vma = vseg->vbase; 354 vSO->m_lma = ps->nextLma();357 vSO->m_lma = 0; 355 358 356 359 cur_vaddr = vseg->vbase; 357 cur_paddr = ps->nextLma(); 358 359 size_t simple_size = 0; //for debug 360 361 #ifdef MOVER_DEBUG 362 std::cout << "--------------- vseg_map "<< vseg->name <<" ------------------" << std::endl; 363 #endif 364 365 for ( size_t vobj_id = vseg->vobj_offset ; 366 vobj_id < (vseg->vobj_offset + vseg->vobjs) ; vobj_id++ ) 360 cur_length = 0; // curr_length of the vseg; a new vseg is necessarily aligned on a page boundary 361 362 #ifdef MOVER_DEBUG 363 std::cout << "--------------- vseg_map "<< vseg->name <<" ------------------" << std::endl; 364 #endif 365 366 for (size_t vobj_id = vseg->vobj_offset; 367 vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) 367 368 { 368 369 cur_vobj = &vobj[vobj_id]; 369 370 370 371 #ifdef MOVER_DEBUG 371 std::cout << std::hex << "current vobj("<< vobj_id <<"): " << cur_vobj->name372 << " (" <<cur_vobj->vaddr << ")"373 << " size: "<< cur_vobj->length374 << " type: " << cur_vobj->type << std::endl;375 #endif 376 if (cur_vobj->type == VOBJ_TYPE_BLOB)372 std::cout << std::hex << "current vobj("<< vobj_id <<"): " << cur_vobj->name 373 << " (" <<cur_vobj->vaddr << ")" 374 << " size: "<< cur_vobj->length 375 << " type: " << cur_vobj->type << std::endl; 376 #endif 377 if (cur_vobj->type == VOBJ_TYPE_BLOB) 377 378 { 378 379 size_t blob_size; … … 380 381 381 382 #ifdef MOVER_DEBUG 382 std::cout << std::hex << "Handling: " << filePath << " ..." << std::endl;383 #endif 384 385 if (!filePath.compare(m_path)) // local blob: map_info386 { 387 #ifdef MOVER_DEBUG 388 std::cout << "Found the vseg of the mapping info" << std::endl;383 std::cout << std::hex << "Handling: " << filePath << " ..." << std::endl; 384 #endif 385 386 if (!filePath.compare(m_path)) // local blob: map_info 387 { 388 #ifdef MOVER_DEBUG 389 std::cout << "Found the vseg of the mapping info" << std::endl; 389 390 #endif 390 391 blob_size = this->m_size; … … 394 395 { 395 396 #ifdef MOVER_DEBUG 396 std::cout << "Found an BLOB vseg" << std::endl;397 std::cout << "Found an BLOB vseg" << std::endl; 397 398 #endif 398 399 blob_size = bin_size(filePath); … … 408 409 assert(sect->get_content());//check allocation 409 410 410 if (!filePath.compare(m_path))//local blob: map_info411 if (!filePath.compare(m_path)) { //local blob: map_info 411 412 //memcpy(sect->get_content(), m_data, sect->get_size()); 412 413 /* this way the modification of the elf size are propageted to the giet */ 413 414 sect->set_content(this->m_data); 415 } 414 416 else 417 { 415 418 load_bin(filePath, sect->get_content()); 416 417 418 if(blob_size > cur_vobj->length) 419 } 420 421 422 if (blob_size > cur_vobj->length) 419 423 { 420 424 std::cout << std::hex << "!!! Warning, specified blob type vobj ("<< … … 424 428 } 425 429 426 cur_vobj->length = blob_size; //set the true size of this BLOB vobj430 cur_vobj->length = blob_size; //set the true size of this BLOB vobj 427 431 428 432 vSO->m_file = filePath; 429 433 vSO->m_loadable = true; 430 434 } 431 else if (cur_vobj->type == VOBJ_TYPE_ELF)435 else if (cur_vobj->type == VOBJ_TYPE_ELF) 432 436 { 433 if (!first)437 if (!first) 434 438 throw exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg")); 435 439 … … 440 444 std::cout << "Found an ELF vseg" << std::endl; 441 445 #endif 442 if (m_loaders.count(filePath) == 0)446 if (m_loaders.count(filePath) == 0) 443 447 m_loaders[filePath] = new elfpp::object(filePath); 444 elfpp::object * loader = m_loaders[filePath];//TODO:free!?445 446 sect = new elfpp::section(*get_sect_by_addr(loader, cur_vaddr)); //copy: for the case we replicate the code448 elfpp::object * loader = m_loaders[filePath]; //TODO:free!? 449 450 sect = new elfpp::section(*get_sect_by_addr(loader, cur_vaddr)); //copy: for the case we replicate the code 447 451 if (!sect) 448 452 { … … 457 461 assert((elf_size > 0) and "ELF section empty ?"); 458 462 459 if (!m_ginit)463 if (!m_ginit) 460 464 { 461 465 /** Initailising the header of the generator from the first binary, 462 466 ** we suppose that the header is the same for all the binarys **/ 463 467 m_generator->copy_info(*loader, 64); 464 m_ginit =true;465 } 466 467 if (elf_size > cur_vobj->length)468 { 469 std::cout << "Warning, specified elf type vobj (" <<470 cur_vobj->name << ") size is "<< cur_vobj->length << ", the actual size is "468 m_ginit = true; 469 } 470 471 if (elf_size > cur_vobj->length) 472 { 473 std::cout << "Warning, specified elf type vobj (" << 474 cur_vobj->name << ") size is " << cur_vobj->length << ", the actual size is " 471 475 << elf_size << std::endl; 472 //assert((elf_size < cur_vobj->length) and "elf vobj length smaller than the actual content" );//??? 473 assert((0) and "elf vobj length smaller than the actual content" );//??? 476 assert((0) and "elf vobj length smaller than the actual content"); 474 477 } 475 478 … … 481 484 482 485 //aligning the vobj->paddr if necessary 483 // 484 if(cur_vobj->align) 486 if (cur_vobj->align) 485 487 { 486 cur_ paddr = PSeg::align(cur_paddr, cur_vobj->align);488 cur_length = PSeg::align(cur_length, cur_vobj->align); 487 489 aligned = true; 488 490 } 489 491 490 492 cur_vaddr += cur_vobj->length; 491 cur_paddr += cur_vobj->length; 492 simple_size += cur_vobj->length; 493 cur_length += cur_vobj->length; 493 494 first = false; 494 495 } 495 496 496 assert((cur_vaddr >= vseg->vbase )); 497 assert((cur_paddr >= ps->nextLma() )); 498 499 vSO->m_length = (cur_paddr - ps->nextLma()); //pageAlign is done by the psegs 500 501 #ifdef MOVER_DEBUG 502 if(aligned) 503 { 504 std::cout << "vseg base "<< std::hex << ps->nextLma() 505 <<(ps->nextLma()+simple_size) <<" size " << std::dec << simple_size << 506 std::endl; 507 508 std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma() 509 <<" to "<< std::hex << ps->nextLma()+vSO->m_length<< " size " << std::dec << 510 vSO->m_length << std::endl; 511 } 512 #endif 513 497 assert(cur_vaddr >= vseg->vbase); 498 499 vSO->m_length = cur_length; //pageAlign is done by the psegs 514 500 vSO->m_ident = vseg->ident; 501 vSO->m_align = vobj[vseg->vobj_offset].align; 515 502 516 503 //set the lma for vseg that are not peripherals 517 if(ps->type() != PSEG_TYPE_PERI) 518 { 519 if ( vseg->ident != 0 ) ps->addIdent( *vSO ); 520 else ps->add( *vSO ); 521 } 522 523 // increment NextLma if required 524 if(ps->type() == PSEG_TYPE_RAM) 525 { 526 ps->incNextLma( vSO->m_length ); 527 } 528 529 if(!sect) return; 504 if (ps->type() != PSEG_TYPE_PERI) 505 { 506 if (vseg->ident != 0) ps->addIdent(*vSO); 507 else ps->add(*vSO); 508 } 509 510 if (!sect) return; 530 511 531 512 #ifdef MOVER_DEBUG … … 540 521 541 522 /////////////////////////////// 542 void MeMo::buildMap(void * desc)543 { 544 mapping_header_t * header = (mapping_header_t*)desc;545 546 mapping_cluster_t * cluster = get_cluster_base( header);547 mapping_vspace_t * vspace = get_vspace_base( header);548 mapping_pseg_t * pseg = get_pseg_base( header);549 mapping_vseg_t * vseg = get_vseg_base( header);523 void MeMo::buildMap(void * desc) 524 { 525 mapping_header_t * header = (mapping_header_t *) desc; 526 527 mapping_cluster_t * cluster = get_cluster_base(header); 528 mapping_vspace_t * vspace = get_vspace_base(header); 529 mapping_pseg_t * pseg = get_pseg_base(header); 530 mapping_vseg_t * vseg = get_vseg_base(header); 550 531 551 532 // get the psegs 552 533 553 534 #ifdef MOVER_DEBUG 554 std::cout << "\n******* Storing Pseg information *********\n" << std::endl; 555 #endif 556 557 for ( size_t cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 558 { 559 for ( size_t pseg_id = cluster[cluster_id].pseg_offset ; 560 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs ; 561 pseg_id++ ) 562 { 535 std::cout << "\n******* Storing Pseg information *********\n" << std::endl; 536 #endif 537 538 for (size_t cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 539 for (size_t pseg_id = cluster[cluster_id].pseg_offset; 540 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; 541 pseg_id++) { 563 542 std::string name(pseg[pseg_id].name); 564 PSeg *ps = new PSeg( 565 566 567 pseg[pseg_id].type);543 PSeg *ps = new PSeg(name, 544 pseg[pseg_id].base, 545 pseg[pseg_id].length, 546 pseg[pseg_id].type); 568 547 m_psegh.m_pSegs.push_back(*ps); 569 548 } … … 573 552 574 553 #ifdef MOVER_DEBUG 575 std::cout << "\n******* mapping global vsegs *********\n" << std::endl; 576 #endif 577 578 for ( size_t vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 579 { 580 vseg_map( &vseg[vseg_id]); 581 } 554 std::cout << "\n******* mapping global vsegs *********\n" << std::endl; 555 #endif 556 557 // Mapping identity segments first 558 for (size_t vseg_id = 0; vseg_id < header->globals; vseg_id++) { 559 if (vseg[vseg_id].ident == 1) { 560 vseg_map(&vseg[vseg_id]); 561 } 562 } 563 564 // Mapping non-identity segments second 565 for (size_t vseg_id = 0; vseg_id < header->globals; vseg_id++) { 566 if (vseg[vseg_id].ident == 0) { 567 vseg_map(&vseg[vseg_id]); 568 } 569 } 570 571 582 572 583 573 // loop on virtual spaces to map private vsegs 584 for (size_t vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 585 { 586 587 #ifdef MOVER_DEBUG 588 std::cout << "\n******* mapping all vsegs of " << vspace[vspace_id].name << " *********\n" << std::endl; 589 #endif 590 591 for ( size_t vseg_id = vspace[vspace_id].vseg_offset ; 592 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; 593 vseg_id++ ) 594 { 595 vseg_map( &vseg[vseg_id]); 574 for (size_t vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 575 #ifdef MOVER_DEBUG 576 std::cout << "\n******* mapping all vsegs of " << vspace[vspace_id].name << " *********\n" << std::endl; 577 #endif 578 for (size_t vseg_id = vspace[vspace_id].vseg_offset; 579 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 580 vseg_id++) { 581 if (vseg[vseg_id].ident == 1) { 582 vseg_map(&vseg[vseg_id]); 583 } 584 } 585 586 for (size_t vseg_id = vspace[vspace_id].vseg_offset; 587 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 588 vseg_id++) { 589 if (vseg[vseg_id].ident == 0) { 590 vseg_map(&vseg[vseg_id]); 591 } 596 592 } 597 593 } 598 599 594 } // end buildMap() 600 595 -
soft/giet_vm/memo/src/pseg.cpp
r238 r255 35 35 #include <iomanip> 36 36 37 #include <cstdio> 38 37 39 #include "pseg.h" 38 40 #include "exception.h" 41 42 43 #define max(x, y) (((x) > (y)) ? (x) : (y)) 39 44 40 45 … … 44 49 45 50 ////////////////////////////////////// 46 const std::string & VSeg::name() const 47 { 51 const std::string & VSeg::name() const { 48 52 return m_name; 49 53 } 50 54 51 55 ////////////////////////////////////// 52 const std::string & VSeg::file() const 53 { 56 const std::string & VSeg::file() const { 54 57 return m_file; 55 58 } 56 59 57 60 /////////////////////////// 58 uintptr_t VSeg::vma() const 59 { 61 uintptr_t VSeg::vma() const { 60 62 return m_vma; 61 63 } 62 64 63 65 ///////////////////////// 64 paddr_t VSeg::lma() const 65 { 66 paddr_t VSeg::lma() const { 66 67 return m_lma; 67 68 } 68 69 69 70 /////////////////////////// 70 size_t VSeg::length() const 71 { 71 size_t VSeg::length() const { 72 72 return m_length; 73 73 } 74 74 75 75 ///////////////////////// 76 size_t VSeg::type() const 77 { 76 size_t VSeg::type() const { 78 77 return m_type; 79 78 } 80 79 81 80 ///////////////////////////////////////// 82 void VSeg::print( std::ostream &o) const81 void VSeg::print(std::ostream &o) const 83 82 { 84 83 o << std::hex << std::noshowbase … … 89 88 << m_lma << ", size: 0x" 90 89 << std::setw (8) << std::setfill('0') 91 << m_length << ",ident: "92 << (m_ident ? "yes" : "no") << ", in(file): "93 << m_file << ", name: " << m_name << ">";90 << m_length << ",ident: " 91 << (m_ident ? "yes" : "no") << ", in(file): " 92 << m_file << ", name: " << m_name << ">"; 94 93 } 95 94 96 95 ///////////// 97 VSeg::~VSeg() 98 { 99 } 96 VSeg::~VSeg() {} 100 97 101 98 ///////////////////////////////////////// 102 VSeg & VSeg::operator=( const VSeg &ref)103 { 104 if ( &ref == this)99 VSeg & VSeg::operator=(const VSeg & ref) 100 { 101 if (&ref == this) 105 102 return *this; 106 103 107 m_name = ref.m_name ,104 m_name = ref.m_name; 108 105 m_file = ref.m_file; 109 106 m_vma = ref.m_vma; … … 111 108 m_length = ref.m_length; 112 109 m_ident = ref.m_ident; 113 110 return *this; 114 111 } 115 112 … … 117 114 VSeg::VSeg() 118 115 : m_name("No Name"), 119 120 121 122 123 116 m_file("Empty section"), 117 m_vma(0), 118 m_length(0), 119 m_loadable(false), 120 m_ident(0) 124 121 { 125 122 } … … 127 124 //////////////////////////////////// 128 125 VSeg::VSeg(std::string& binaryName, 129 130 131 132 133 134 135 136 137 138 139 126 std::string& name, 127 uintptr_t vma, 128 size_t length, 129 bool loadable, 130 bool ident) 131 : m_name(name), 132 m_file(binaryName), 133 m_vma(vma), 134 m_length(length), 135 m_loadable(loadable), 136 m_ident(ident) 140 137 { 141 138 } 142 139 143 140 ///////////////////////////// 144 VSeg::VSeg( const VSeg &ref )145 : m_name("To be copied"),146 m_file("Empty"),147 m_vma(0),148 m_length(0),149 m_loadable(false),150 m_ident(0)141 VSeg::VSeg(const VSeg &ref): 142 m_name(ref.m_name), 143 m_file(ref.m_file), 144 m_vma(ref.m_vma), 145 m_length(ref.m_length), 146 m_loadable(ref.m_loadable), 147 m_ident(ref.m_ident) 151 148 { 152 149 (*this) = ref; … … 159 156 160 157 ///////////////////////// 161 paddr_t PSeg::lma() const 162 { 163 return m_lma; 158 paddr_t PSeg::lma() const { 159 return m_lma; 164 160 } 165 161 166 162 /////////////////////////// 167 paddr_t PSeg::limit() const 168 { 169 return m_limit; 170 } 171 172 ///////////////////////////// 173 paddr_t PSeg::length() const 174 { 175 return m_length; 163 paddr_t PSeg::length() const { 164 return m_length; 176 165 } 177 166 178 167 ///////////////////////// 179 size_t PSeg::type() const 180 { 181 return m_type; 182 } 183 184 ///////////////////////////// 185 paddr_t PSeg::nextLma() const 186 { 187 return m_nextLma; 168 size_t PSeg::type() const { 169 return m_type; 188 170 } 189 171 190 172 ////////////////////////////////////// 191 const std::string & PSeg::name() const 192 { 193 return m_name; 173 const std::string & PSeg::name() const { 174 return m_name; 194 175 } 195 176 … … 198 179 { 199 180 200 if (this->m_type == PSEG_TYPE_PERI)181 if (this->m_type == PSEG_TYPE_PERI) 201 182 return; 202 183 … … 204 185 size_t size = m_vsegs.size(); 205 186 paddr_t used[size][2]; // lma, lma+length 206 size_t i, j,error=0;207 208 for (it = m_vsegs.begin(), i= 0 ; it < m_vsegs.end(); it++, i++)187 size_t i, j, error = 0; 188 189 for (it = m_vsegs.begin(), i = 0; it < m_vsegs.end(); it++, i++) 209 190 { 210 191 paddr_t it_limit = (*it).lma() + (*it).length(); 211 for(j =0; j< i; j++)192 for(j = 0; j < i; j++) 212 193 { 213 if( used[j][0] == (*it).lma() ) //not the same lma , 214 { 215 error = 1; 216 std::cout << "ok \n"; 217 } 218 if( used[j][1] == it_limit ) // and not the same limit 194 if (used[j][0] == (*it).lma()) //not the same lma , 195 { 196 error = 1; 197 } 198 if (used[j][1] == it_limit) // and not the same limit 219 199 { 220 200 error = 2; 221 201 } 222 if ( (used[j][0] < (*it).lma()) and ((*it).lma() < used[j][1])) // lma within202 if ((used[j][0] < (*it).lma()) and ((*it).lma() < used[j][1])) // lma within 223 203 { 224 204 error = 3; 225 205 } 226 if ( ((used[j][0] < it_limit) and (it_limit < used[j][1] ))) // limit no within206 if (((used[j][0] < it_limit) and (it_limit < used[j][1]))) // limit no within 227 207 { 228 208 error = 4; … … 232 212 std::cout << "used[j][1]: " << std::hex << used[j][1] << std::endl; 233 213 } 234 if (error)214 if (error) 235 215 { 236 216 std::ostringstream err; 237 err << " Error" << error << " ,ovelapping Buffers:" << std::endl217 err << " Error" << error << ", ovelapping Buffers:" << std::endl 238 218 << *it << std::endl << m_vsegs[j] << std::endl; 239 219 throw exception::RunTimeError( err.str().c_str() ); … … 246 226 } 247 227 248 //////////////////////////////////////249 void PSeg::setName(std::string& name )250 {251 m_name = name;252 }253 228 254 229 ///////////////////////////////////////////////////////// 255 paddr_t PSeg::align( paddr_t toAlign, unsigned alignPow2) 256 { 230 paddr_t PSeg::align(paddr_t toAlign, unsigned alignPow2) { 257 231 return ((toAlign + (1 << alignPow2) - 1 ) >> alignPow2) << alignPow2; 258 232 } 259 233 260 234 ////////////////////////////////////////// 261 paddr_t PSeg::pageAlign( paddr_t toAlign ) 262 { 235 paddr_t PSeg::pageAlign(paddr_t toAlign) { 263 236 size_t pgs = pageSize(); 264 237 size_t pageSizePow2 = __builtin_ctz(pgs); 265 238 266 239 return align(toAlign, pageSizePow2); 267 240 } 268 241 269 //////////////////////////////// 270 void PSeg::setLma( paddr_t lma ) 271 { 272 m_lma = lma; 273 274 m_nextLma = pageAlign(lma); 275 276 m_pageLimit = pageAlign(m_lma+m_length); 277 278 m_limit = (m_lma + m_length); 279 } 280 281 ///////////////////////////////////// 282 void PSeg::setLength( paddr_t length ) 283 { 284 m_length = length; 285 286 m_pageLimit = pageAlign(m_lma+m_length); 287 288 m_limit = (m_lma + m_length); 289 } 242 290 243 291 244 //////////////////////////// 292 void PSeg::add( VSeg& vseg ) 293 { 294 vseg.m_lma = m_nextLma; 295 // incNextLma(vseg.length()); //for the next vseg 245 void PSeg::add(VSeg& vseg) { 246 std::vector<VSeg>::iterator it; 247 int nb_elems = m_vsegs.size(); 248 int i = 0; 249 bool mapped = false; 250 paddr_t prev_base = m_lma; 251 paddr_t prev_length = 0x0; 252 paddr_t curr_base = 0x0; 253 paddr_t curr_length = 0x0; 254 paddr_t next_base = 0x0; 255 paddr_t next_length = 0x0; 256 257 const int alignment = max(vseg.m_align, __builtin_ctz(pageSize())); // 12 258 259 if (vseg.length() == 0) { 260 std::cout << "*** Error: Adding a vseg of size 0 (base " << vseg.vma() << ")" << std::endl; 261 exit(1); 262 } 263 264 if (nb_elems == 0) { 265 if (vseg.length() <= m_length) { 266 vseg.m_lma = m_lma; 267 m_vsegs.push_back(vseg); 268 return; 269 } 270 else { 271 std::cout << "*** Error: Not enough space to map first VSeg (base = " 272 << std::hex << vseg.vma() << " - Size = " << vseg.length() << ")" << std::endl; 273 std::cout << " PSeg too small! (base = " << m_lma << " - size = " 274 << m_length << ")" << std::endl; 275 exit(1); 276 } 277 } 278 279 curr_base = m_vsegs[0].lma(); // Initialisation avant recherche du min 280 curr_length = m_vsegs[0].length(); 281 for (it = m_vsegs.begin(); it != m_vsegs.end(); it++) { 282 if ((*it).lma() < curr_base) { 283 curr_base = (*it).lma(); 284 curr_length = (*it).length(); 285 } 286 } 287 288 while (i < nb_elems) { 289 if (align(prev_base + prev_length, alignment) + vseg.length() <= curr_base) { 290 vseg.m_lma = align(prev_base + prev_length, alignment); 291 mapped = true; 292 break; 293 } 294 else if (i < nb_elems - 1) { 295 // Searching for the vseg already mapped with lowest paddr > curr_base 296 next_base = 0; 297 bool found = false; 298 for (it = m_vsegs.begin(); it != m_vsegs.end(); it++) { 299 if ((!found || (*it).lma() < next_base) && (*it).lma() > curr_base) { 300 found = true; 301 next_base = (*it).lma(); 302 next_length = (*it).length(); 303 } 304 } 305 assert(found); 306 307 prev_base = curr_base; 308 prev_length = curr_length; 309 310 curr_base = next_base; 311 curr_length = next_length; 312 } 313 else { 314 if (align(curr_base + curr_length, alignment) + vseg.length() <= m_lma + m_length) { 315 vseg.m_lma = align(curr_base + curr_length, alignment); 316 mapped = true; 317 } 318 } 319 i++; 320 } 321 322 if (!mapped) { 323 std::cout << "*** Error: Not enough space to map VSeg (base = " << std::hex << vseg.vma() << " - Size = " << vseg.length() << ")" << std::endl; 324 exit(1); 325 } 326 296 327 m_vsegs.push_back(vseg); 297 328 } 298 329 330 299 331 ///////////////////////////////// 300 void PSeg::addIdent( VSeg& vseg ) 301 { 332 void PSeg::addIdent(VSeg& vseg) { 333 std::vector<VSeg>::iterator it; 334 335 for (it = m_vsegs.begin(); it != m_vsegs.end(); it++) { 336 if ((vseg.vma() == (*it).lma()) || 337 ((vseg.vma() < (*it).lma()) && (vseg.vma() + vseg.length() > (*it).lma())) || 338 ((vseg.vma() > (*it).lma()) && ((*it).lma() + (*it).length() > vseg.vma()))) { 339 std::cout << "*** Error: Identity VSeg overlaps another segment:" << std::endl 340 << "Added Segment Base : " << std::hex << vseg.vma() 341 << " - Size : " << vseg.length() << std::endl; 342 std::cout << "Existing Segment Base : " << (*it).lma() 343 << " - size : " << (*it).length() << std::endl; 344 exit(1); 345 } 346 } 347 302 348 vseg.m_lma = vseg.m_vma; 303 349 m_vsegs.push_back(vseg); 304 350 } 305 351 352 306 353 ///////////////////////////////////////// 307 void PSeg::setNextLma( paddr_t nextLma) 308 { 309 m_nextLma = nextLma; 310 confNextLma(); 311 } 312 313 ////////////////////////////////// 314 void PSeg::incNextLma( size_t inc) 315 { 316 m_nextLma += inc; 317 confNextLma(); 318 } 319 320 //////////////////////// 321 void PSeg::confNextLma() 322 { 323 if(m_nextLma > m_limit) 324 { 325 std::cerr << "Erreur pseg overflow... nextLma: " 326 << std::hex << m_nextLma << ", limit: " 327 << m_limit << std::endl; 328 exit(1); 329 } 330 331 m_nextLma = pageAlign( m_nextLma ); 332 333 if(m_nextLma > m_pageLimit) 334 { 335 std::cerr << "Erreur pseg page overflow... nextLma: " 336 << std::hex << m_nextLma << ", limit: " 337 << m_pageLimit << std::endl; 338 exit(1); 339 } 340 } 341 342 ///////////////////////////////// 343 void PSeg::setPageSize(size_t pg) 344 { 345 if( pg == 0) 346 { 347 std::cerr << "PageSize must be positive" << std::endl; 348 return; 349 } 350 pageSize() = pg; 351 } 352 353 //////////////////////// 354 size_t& PSeg::pageSize() 355 { 356 static size_t m_pageSize; 357 return m_pageSize; 358 } 359 360 ///////////////////////////////////////// 361 PSeg & PSeg::operator=( const PSeg &ref ) 362 { 363 if ( &ref == this ) 354 PSeg & PSeg::operator=(const PSeg &ref) { 355 if (&ref == this) { 364 356 return *this; 357 } 365 358 366 359 m_name = ref.m_name; 367 360 m_length = ref.m_length; 368 m_limit = ref.m_limit;369 m_pageLimit = ref.m_pageLimit;370 361 m_lma = ref.m_lma; 371 m_nextLma = ref.m_nextLma;372 362 m_vsegs = ref.m_vsegs; 373 363 m_type = ref.m_type; … … 377 367 378 368 ////////////////////////////////////////// 379 void PSeg::print( std::ostream &o) const369 void PSeg::print(std::ostream &o) const 380 370 { 381 371 o << "<Physical segment " 382 372 << std::showbase << m_name 383 373 << ", from: " << std::hex 384 << m_lma << " to " << m_limit374 << m_lma 385 375 << ", size : " << m_length 386 << ", filled to: " << m_nextLma387 376 << ", type : " << m_type 388 377 << ", containing: "<< std::endl; … … 403 392 m_length = length; 404 393 m_type = type; 405 406 setLma(lma); 394 m_lma = lma; 407 395 } 408 396 409 397 //////////////////////////////////// 410 PSeg::PSeg( 398 PSeg::PSeg(const std::string &name): 411 399 m_lma(0), 412 m_length(0), 413 m_nextLma(0), 414 m_limit(0) 415 { 400 m_length(0) { 416 401 m_name = name; 417 402 } 418 403 419 //////////////////////// 420 PSeg::PSeg( paddr_t lma): 421 m_name("No name"), 422 m_lma(0), 423 m_length(0), 424 m_nextLma(0), 425 m_limit(0) 426 { 427 setLma(lma); 428 } 429 430 //////////// 431 PSeg::PSeg() 432 : 433 m_name("Empty section"), 434 m_lma(0), 435 m_length(0), 436 m_nextLma(0), 437 m_limit(0) 438 { 439 } 440 441 ///////////////////////////// 442 PSeg::PSeg( const PSeg &ref ) 443 : m_name("To be copied"), 444 m_lma(0), 445 m_length(0), 446 m_nextLma(0), 447 m_limit(0) 448 { 449 (*this) = ref; 450 } 451 452 PSeg::~PSeg() 453 { 454 } 404 405 //////////////////////////////////// 406 PSeg::PSeg(const PSeg& pseg) { 407 m_name = pseg.m_name; 408 m_length = pseg.m_length; 409 m_lma = pseg.m_lma; 410 m_vsegs = pseg.m_vsegs; 411 m_type = pseg.m_type; 412 413 (*this) = pseg; 414 } 415 416 PSeg::~PSeg() {} 455 417 456 418 -
soft/giet_vm/sys/common.h
r253 r255 31 31 extern _ld_symbol_t seg_mmc_base; 32 32 extern _ld_symbol_t seg_cma_base; 33 extern _ld_symbol_t seg_sim_base; 33 34 34 35 extern _ld_symbol_t vseg_cluster_increment; -
soft/giet_vm/sys/drivers.c
r254 r255 1834 1834 } 1835 1835 1836 1837 //////////////////////////////////////////////////////////////////////////////// 1838 // _sim_helper_access() 1839 // Accesses the Simulation Helper Component 1840 // If the access is on a writable register (except SIMHELPER_PAUSE_SIM), 1841 // the function should never return since the simulation will stop before 1842 // If the access is on a readable register, returns 0 on success, 1 on failure, 1843 // and writes the return value at address retval 1844 //////////////////////////////////////////////////////////////////////////////// 1845 unsigned int _sim_helper_access(unsigned int register_index, 1846 unsigned int value, 1847 unsigned int * retval) { 1848 unsigned int * sim_helper_address = (unsigned int *) &seg_sim_base; 1849 1850 if (register_index == SIMHELPER_SC_STOP || 1851 register_index == SIMHELPER_END_WITH_RETVAL || 1852 register_index == SIMHELPER_EXCEPT_WITH_VAL || 1853 register_index == SIMHELPER_PAUSE_SIM || 1854 register_index == SIMHELPER_SIGINT) { 1855 sim_helper_address[register_index] = value; 1856 } 1857 else if (register_index == SIMHELPER_CYCLES) { 1858 *retval = sim_helper_address[register_index]; 1859 } 1860 else { 1861 _get_lock(&_tty_put_lock); 1862 _puts("\n[GIET ERROR] in _sim_helper_access() : access to unmapped register\n"); 1863 _release_lock(&_tty_put_lock); 1864 return -1; 1865 } 1866 1867 return 0; 1868 } 1869 1870 1871 1836 1872 // Local Variables: 1837 1873 // tab-width: 4 -
soft/giet_vm/sys/drivers.h
r253 r255 132 132 133 133 /////////////////////////////////////////////////////////////////////////////////// 134 // Sim Helper access function 135 /////////////////////////////////////////////////////////////////////////////////// 136 unsigned int _sim_helper_access(unsigned int register_index, 137 unsigned int value, 138 unsigned int * retval); 139 140 /////////////////////////////////////////////////////////////////////////////////// 134 141 // MEMC access functions 135 142 /////////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/sys/giet.s
r219 r255 9 9 * - the _cause_vector[16] array defines the 16 causes to enter the GIET 10 10 * it is initialized in th exc_handler.c file 11 * - the _syscall_vector[ 32] array defines the 32system calls entry points11 * - the _syscall_vector[64] array defines the 64 system calls entry points 12 12 * it is initialised in the sys_handler.c file 13 13 ***********************************************************************************/ … … 38 38 * 39 39 * A system call is handled as a special function call. 40 * - $2 contains the system call index (< 16).40 * - $2 contains the system call index (< 64). 41 41 * - $3 is used to store the syscall address 42 42 * - $4, $5, $6, $7 contain the arguments values. … … 62 62 sw $27, 20($29) /* save it in the stack */ 63 63 64 andi $26, $2, 0x 1F /* $26 <= syscall index (i < 32) */64 andi $26, $2, 0x3F /* $26 <= syscall index (i < 64) */ 65 65 sll $26, $26, 2 /* $26 <= index * 4 */ 66 66 la $27, _syscall_vector /* $27 <= &_syscall_vector[0] */ -
soft/giet_vm/sys/hwr_mapping.h
r253 r255 192 192 }; 193 193 194 enum SoclibSimhelperRegisters 195 { 196 SIMHELPER_SC_STOP, 197 SIMHELPER_END_WITH_RETVAL, 198 SIMHELPER_EXCEPT_WITH_VAL, 199 SIMHELPER_PAUSE_SIM, 200 SIMHELPER_CYCLES, 201 SIMHELPER_SIGINT, 202 }; 203 204 205 194 206 #endif 195 207 -
soft/giet_vm/sys/sys_handler.c
r253 r255 6 6 /////////////////////////////////////////////////////////////////////////////////// 7 7 // The sys_handler.c and sys_handler.h files are part of the GIET-VM nano-kernel. 8 // It define the syscall_vector[] (at the end of this file), as well as the8 // It defines the syscall_vector[], as well as the 9 9 // associated syscall handlers that are not related to peripherals. 10 10 // The syscall handlers for peripherals are defined in the drivers.c file. … … 21 21 // Initialize the syscall vector with syscall handlers 22 22 //////////////////////////////////////////////////////////////////////////// 23 const void * _syscall_vector[ 32] =23 const void * _syscall_vector[64] = 24 24 { 25 25 &_procid, /* 0x00 */ … … 55 55 &_nic_sync_read, /* 0x1E */ 56 56 &_nic_sync_write, /* 0x1F */ 57 &_sim_helper_access, /* 0x20 */ 57 58 }; 58 59 -
soft/giet_vm/sys/sys_handler.h
r238 r255 13 13 ////////////////////////////////////////////////////////////////////////////////// 14 14 15 extern const void * _syscall_vector[ 32];15 extern const void * _syscall_vector[64]; 16 16 17 17 ////////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/xml/mapping_info.h
r253 r255 106 106 PERIPH_TYPE_GCD = 10, 107 107 PERIPH_TYPE_XCU = 11, 108 109 PERIPH_TYPE_MAX_VALUE = 12, 108 PERIPH_TYPE_SIM = 12, 109 110 PERIPH_TYPE_MAX_VALUE = 13, 110 111 }; 111 112 … … 142 143 unsigned int iob_cluster; // index of cluster containing IOB controler 143 144 unsigned int iob_cluster_bis; // index of cluster containing second IOB controler 145 unsigned int sim_cluster; // index of cluster containing the Simulation Helper 146 unsigned int sim_cluster_bis; // index of cluster containing the Simulation Helper 144 147 145 148 unsigned int psegs; // total number of physical segments (for all clusters) … … 182 185 unsigned int type; // RAM / ROM / PERI 183 186 unsigned int cluster; // index of cluster containing pseg 184 paddr_t next_base; // first free page base address185 187 } mapping_pseg_t; 186 188 … … 206 208 unsigned int vbase; // base address in virtual space 207 209 paddr_t pbase; // base address in physical space 210 unsigned int pbase_set; 208 211 unsigned int length; // size (bytes) 209 212 unsigned int psegid; // physical segment global index … … 234 237 235 238 ///////////////////////////// 236 typedef struct __attribute__((packed)) mapping_vobj_s 239 typedef struct __attribute__((packed)) mapping_vobj_s 237 240 { 238 241 char name[32]; // vobj name (unique in a vspace) -
soft/giet_vm/xml/xml_parser.c
r253 r255 748 748 ////////// set vobj_offset attributes 749 749 vseg[vseg_index]->vobj_offset = vobj_index; 750 // Init pbase_set to false 751 vseg[vseg_index]->pbase_set = 0; 750 752 751 753 #if XML_PARSER_DEBUG … … 1273 1275 } 1274 1276 } 1277 else if (strcmp(str, "SIM") == 0) 1278 { 1279 periph[periph_index]->type = PERIPH_TYPE_SIM; 1280 if (header->sim_cluster == 0xFFFFFFFF) 1281 { 1282 header->sim_cluster = cluster_index; 1283 } 1284 else if (header->sim_cluster_bis == 0xFFFFFFFF) 1285 { 1286 header->sim_cluster_bis = cluster_index; 1287 } 1288 else 1289 { 1290 error = 1; 1291 } 1292 } 1275 1293 // The TIM, ICU, XICU, DMA, MEMC peripherals are replicated in all clusters 1276 1294 // but it must exist only one component of each type per cluster … … 2086 2104 header->cma_cluster = 0xFFFFFFFF; 2087 2105 header->iob_cluster = 0xFFFFFFFF; 2106 header->sim_cluster = 0xFFFFFFFF; 2088 2107 header->tty_cluster_bis = 0xFFFFFFFF; 2089 2108 header->nic_cluster_bis = 0xFFFFFFFF; … … 2092 2111 header->cma_cluster_bis = 0xFFFFFFFF; 2093 2112 header->iob_cluster_bis = 0xFFFFFFFF; 2113 header->sim_cluster_bis = 0xFFFFFFFF; 2094 2114 2095 2115 ///////// set signature … … 2162 2182 } 2163 2183 2164 //#if XML_PARSER_DEBUG2184 #if XML_PARSER_DEBUG 2165 2185 printf("%s\n", file_path); 2166 //#endif2186 #endif 2167 2187 2168 2188 return fdout; … … 2424 2444 ld_write(fdout, "seg_iob_base ", periph_vbase_array[PERIPH_TYPE_IOB]); 2425 2445 ld_write(fdout, "seg_gcd_base ", periph_vbase_array[PERIPH_TYPE_GCD]); 2446 ld_write(fdout, "seg_sim_base ", periph_vbase_array[PERIPH_TYPE_SIM]); 2426 2447 2427 2448 file_write(fdout, "\n");
Note: See TracChangeset
for help on using the changeset viewer.