⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linearaddressspace.java

📁 JPC: x86 PC Hardware Emulator. 牛津大学开发的一个纯JAVA的x86系统结构硬件模拟器。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	    setWriteIndexValue(idx, target.getWriteMemoryBlockAt(fourKStartAddress));
            return writeIndex[idx];
	}
    }

    public Memory getReadMemoryBlockAt(int offset)
    {
	return getReadIndexValue(offset >>> INDEX_SHIFT);
    }

    public Memory getWriteMemoryBlockAt(int offset)
    {
	return getWriteIndexValue(offset >>> INDEX_SHIFT);
    }

    void replaceBlocks(Memory oldBlock, Memory newBlock)
    {
	try {
	    for (int i = 0; i < INDEX_SIZE; i++)
		if (readUserIndex[i] == oldBlock)
		    readUserIndex[i] = newBlock;
	} catch (NullPointerException e) {}

	try {
	    for (int i = 0; i < INDEX_SIZE; i++)
		if (writeUserIndex[i] == oldBlock)
		    writeUserIndex[i] = newBlock;
	} catch (NullPointerException e) {}

	try {
	    for (int i = 0; i < INDEX_SIZE; i++)
		if (readSupervisorIndex[i] == oldBlock)
		    readSupervisorIndex[i] = newBlock;
	} catch (NullPointerException e) {}

	try {
	    for (int i = 0; i < INDEX_SIZE; i++)
		if (writeSupervisorIndex[i] == oldBlock)
		    writeSupervisorIndex[i] = newBlock;
	} catch (NullPointerException e) {}
    }

    public byte getByte(int offset)
    {        
        try 
        {
            return super.getByte(offset);
        } 
        catch (NullPointerException e) {}
        catch (ProcessorException p) {}

        return validateTLBEntryRead(offset).getByte(offset & BLOCK_MASK);
    }

    public short getWord(int offset)
    { 
        try 
        {
            return super.getWord(offset);
        } 
        catch (NullPointerException e) {}
        catch (ProcessorException p) {}

        Memory m = validateTLBEntryRead(offset);
        try
        {
            return m.getWord(offset & BLOCK_MASK);
        } 
        catch (ArrayIndexOutOfBoundsException e) 
        {
            return getWordInBytes(offset);
        }
    }

    public int getDoubleWord(int offset)
    {
        try 
        {
            return super.getDoubleWord(offset);
        } 
        catch (NullPointerException e) {}
        catch (ProcessorException p) {}

        Memory m = validateTLBEntryRead(offset);
        try
        {
            return m.getDoubleWord(offset & BLOCK_MASK);
        } 
        catch (ArrayIndexOutOfBoundsException e) 
        {
            return getDoubleWordInBytes(offset);
        }
    }

    public void setByte(int offset, byte data)
    {        
        try 
        {
            super.setByte(offset, data);
            return;
        } 
        catch (NullPointerException e) {}
        catch (ProcessorException p) {}

        validateTLBEntryWrite(offset).setByte(offset & BLOCK_MASK, data);
    }

    public void setWord(int offset, short data)
    { 
        try 
        {
            super.setWord(offset, data);
            return;
        } 
        catch (NullPointerException e) {}
        catch (ProcessorException p) {}

        Memory m = validateTLBEntryWrite(offset);
        try
        {
            m.setWord(offset & BLOCK_MASK, data);
        } 
        catch (ArrayIndexOutOfBoundsException e) 
        {
            setWordInBytes(offset, data);
        }
    }

    public void setDoubleWord(int offset, int data)
    {
        try 
        {
            super.setDoubleWord(offset, data);
            return;
        } 
        catch (NullPointerException e) {}
        catch (ProcessorException p) {}

        Memory m = validateTLBEntryWrite(offset);
        try
        {
            m.setDoubleWord(offset & BLOCK_MASK, data);
        } 
        catch (ArrayIndexOutOfBoundsException e) 
        {
            setDoubleWordInBytes(offset, data);
        }
    }

    public void clear()
    {
        target.clear();
    }

    public int execute(Processor cpu, int offset)
    {
	Memory memory = getReadMemoryBlockAt(offset);

	try {
	    return memory.execute(cpu, offset & AddressSpace.BLOCK_MASK);
	} catch (NullPointerException n) {
	    memory = validateTLBEntryRead(offset); //memory object was null (needs mapping)
	} catch (ProcessorException p) {
	    memory = validateTLBEntryRead(offset); //memory object caused a page fault (double check)
	}

	try {
	    return memory.execute(cpu, offset & AddressSpace.BLOCK_MASK);
	} catch (ProcessorException p) {
	    cpu.handleProtectedModeException(p.getVector(), p.hasErrorCode(), p.getErrorCode());
	    return 1;
	}
    }
    
    public CodeBlock decodeCodeBlockAt(Processor cpu, int offset)
    {
	Memory memory = getReadMemoryBlockAt(offset);


	try {
	    return memory.decodeCodeBlockAt(cpu, offset & AddressSpace.BLOCK_MASK);
	} catch (NullPointerException n) {
	    memory = validateTLBEntryRead(offset); //memory object was null (needs mapping)
	} catch (ProcessorException p) {
	    memory = validateTLBEntryRead(offset); //memory object caused a page fault (double check)
	}

	CodeBlock block= memory.decodeCodeBlockAt(cpu, offset & AddressSpace.BLOCK_MASK);
	return block;
    }

    public static final class PageFaultWrapper extends Memory
    {
        private ProcessorException pageFault;

        public PageFaultWrapper(int errorCode)
        {
            pageFault = new ProcessorException(Processor.PROC_EXCEPTION_PF, errorCode, true);
        }

        private final void fill()
        {
            //pageFault.fillInStackTrace();
        }

        public ProcessorException getFault()
        {
            return pageFault;
        }

        public void clear() {}

        public void clear(int start, int length) {}

        public void copyContentsInto(int address, byte[] buffer, int off, int len)
        {
            fill();
            throw pageFault;
        }

        public void copyContentsFrom(int address, byte[] buffer, int off, int len)
        {
            fill();
            throw pageFault;
        }

        public long getSize()
        {
            return 0;
        }

        public byte getByte(int offset)
        {
            fill();
            throw pageFault;
        }

        public short getWord(int offset)
        {
            fill();
            throw pageFault;
        }

        public int getDoubleWord(int offset)
        {
            fill();
            throw pageFault;
        }

        public long getQuadWord(int offset)
        {
            fill();
            throw pageFault;
        }

        public long getLowerDoubleQuadWord(int offset)
        {
            fill();
            throw pageFault;
        }

        public long getUpperDoubleQuadWord(int offset)
        {
            fill();
            throw pageFault;
        }

        public void setByte(int offset, byte data)
        {
            fill();
            throw pageFault;
        }

        public void setWord(int offset, short data)
        {
            fill();
            throw pageFault;
        }

        public void setDoubleWord(int offset, int data)
        {
            fill();
            throw pageFault;
        }

        public void setQuadWord(int offset, long data)
        {
            fill();
            throw pageFault;
        }

        public void setLowerDoubleQuadWord(int offset, long data)
        {
            fill();
            throw pageFault;
        }

        public void setUpperDoubleQuadWord(int offset, long data)
        {
            fill();
            throw pageFault;
        }

	public int execute(Processor cpu, int offset)
	{
	    fill();
	    throw pageFault;
	}
	
	public CodeBlock decodeCodeBlockAt(Processor cpu, int offset)
	{
	    fill();
	    throw pageFault;
	}
    }

    public void reset()
    {
	flush();

        baseAddress = 0;
        lastAddress = 0;
        pagingDisabled = true;
        globalPagesEnabled = false;
        writeProtectUserPages = false;
        pageSizeExtensions = false;

	readUserIndex = null;
	writeUserIndex = null;
	readSupervisorIndex = null;
	writeSupervisorIndex = null;
    }

    public boolean updated()
    {
        return target.updated();
    }

    public void updateComponent(HardwareComponent component)
    { }
    
    public boolean initialised()
    {
        return (target != null);
    }

    public void acceptComponent(HardwareComponent component)
    {
	if (component instanceof PhysicalAddressSpace)
	    target = (AddressSpace) component;
    }

    public void timerCallback() {}

    public String toString()
    {
        return "Linear Address Space";
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -