Example #1
0
        public tlb(int BA_N, int PT_N, int V_T_S, int P_T_S)
        {
            VIRTUAL_SIZE = V_T_S;
            PHYSICAL_SIZE = P_T_S;

            INDEX_SIZE = Globals.VIRTUAL_ADD_LEN - VIRTUAL_SIZE - Globals.PAGE_OFF_LEN;

            BANK_NUM = BA_N;
            PTE_NUM = PT_N;

            bankS_pte = new pte[PTE_NUM, BANK_NUM];
            for (int i = 0; i < PTE_NUM; i++)
                for (int j = 0; j < BANK_NUM; j++)
                    bankS_pte[i, j] = new pte(VIRTUAL_SIZE, PHYSICAL_SIZE);
        }
        public void initialize()
        {
            // initialize the PTPTEs
            for(int i=0; i<size; i++)
            {
                entries[i] = new pte();
            }

            string line;
            // Read the file and display it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader("../../test.hex");
            char[] delimiterChars = { ' ' };
            while ((line = file.ReadLine()) != null)
            {
                string[] words = line.Split(delimiterChars);
                int page_size = Convert.ToInt32(words[1]);
                ulong address = Convert.ToUInt64(words[0]);

                ulong temp_address = address;

                for (int i=2; i<(page_size+2); i++)
                {
                    ulong instruction = Convert.ToUInt64(words[i], 16);
                    Simulator.my_hard_disk.add_instruction(instruction, (address + Convert.ToUInt64(8 * (i-2))));

                    // add the page_table entry if it's not already there
                    ulong vaddress = ((address + Convert.ToUInt64(8 * (i - 2))) >> 12);
                    bool found = false;
                    for(int j=0; j<real_size; j++)
                    {
                        if (entries[j].virtual_address == vaddress)
                            found = true;
                    }

                    if(!found)
                    {
                        entries[real_size].virtual_address = vaddress;
                        entries[real_size].physical_address = Convert.ToUInt64(Simulator.rand.Next(Convert.ToInt32(Simulator.my_memory.size >> 12)));
                        real_size++;
                    }
                }
            }
            file.Close();
        }