📄 physicaladdressspace.java
字号:
public byte getByte(int offset) { offset = baseAddress | offset; return memory.getByte(offset); } public short getWord(int offset) { offset = baseAddress | offset; return memory.getWord(offset); } public int getDoubleWord(int offset) { offset = baseAddress | offset; return memory.getDoubleWord(offset); } public long getQuadWord(int offset) { offset = baseAddress | offset; return memory.getQuadWord(offset); } public long getLowerDoubleQuadWord(int offset) { offset = baseAddress | offset; return memory.getQuadWord(offset); } public long getUpperDoubleQuadWord(int offset) { offset += 8; offset = baseAddress | offset; return memory.getQuadWord(offset); } public void setByte(int offset, byte data) { offset = baseAddress | offset; memory.setByte(offset, data); } public void setWord(int offset, short data) { offset = baseAddress | offset; memory.setWord(offset, data); } public void setDoubleWord(int offset, int data) { offset = baseAddress | offset; memory.setDoubleWord(offset, data); } public void setQuadWord(int offset, long data) { offset = baseAddress | offset; memory.setQuadWord(offset, data); } public void setLowerDoubleQuadWord(int offset, long data) { offset = baseAddress | offset; memory.setQuadWord(offset, data); } public void setUpperDoubleQuadWord(int offset, long data) { offset += 8; offset = baseAddress | offset; memory.setQuadWord(offset, data); } public int execute(Processor cpu, int offset) { offset = baseAddress | offset; return memory.execute(cpu, offset); } public CodeBlock decodeCodeBlockAt(Processor cpu, int offset) { offset = baseAddress | offset; CodeBlock block= memory.decodeCodeBlockAt(cpu, offset); if(block!=null) System.out.println(getClass().getName()+":1"); else System.out.println(getClass().getName()+":0"); return block; } } public void clear() { for (int i=0; i<quickNonA20MaskedIndex.length; i++) quickNonA20MaskedIndex[i].clear(); for (int i = 0; i < nonA20MaskedIndex.length; i++) { Memory[] subArray = nonA20MaskedIndex[i]; try { for (int j = 0; j < subArray.length; j++) { try { subArray[j].clear(); } catch (NullPointerException e) {} } } catch (NullPointerException e) {} } } public void unmap(int start, int length) { if ((start % BLOCK_SIZE) != 0) throw new IllegalStateException("Cannot deallocate memory starting at "+Integer.toHexString(start)+"; this is not block aligned at "+BLOCK_SIZE+" boundaries"); if ((length % BLOCK_SIZE) != 0) throw new IllegalStateException("Cannot deallocate memory in partial blocks. "+length+" is not a multiple of "+BLOCK_SIZE); for (int i=start; i<start+length; i+=BLOCK_SIZE) { if (getMemoryBlockAt(i) != UNCONNECTED) mappedRegionCount--; setMemoryBlockAt(i, UNCONNECTED); } } public void mapMemoryRegion(Memory underlying, int start, int length) { if (underlying.getSize() < length) throw new IllegalStateException("Underlying memory (length="+underlying.getSize()+") is too short for mapping into region "+length+" bytes long"); if ((start % BLOCK_SIZE) != 0) throw new IllegalStateException("Cannot map memory starting at "+Integer.toHexString(start)+"; this is not aligned to "+BLOCK_SIZE+" blocks"); if ((length % BLOCK_SIZE) != 0) throw new IllegalStateException("Cannot map memory in partial blocks: "+length+" is not a multiple of "+BLOCK_SIZE); unmap(start, length); long s = 0xFFFFFFFFl & start; for (long i=s; i<s+length; i += BLOCK_SIZE) { Memory w = new MapWrapper(underlying, (int)(i-s)); setMemoryBlockAt((int)i, w); mappedRegionCount++; } } public void allocateMemory(int start, Memory block) { if ((start % BLOCK_SIZE) != 0) throw new IllegalStateException("Cannot allocate memory starting at "+Integer.toHexString(start)+"; this is not aligned to "+BLOCK_SIZE+" blocks"); if (block.getSize() != BLOCK_SIZE) throw new IllegalStateException("Can only allocate memory in blocks of "+BLOCK_SIZE); unmap(start, BLOCK_SIZE); long s = 0xFFFFFFFFl & start; setMemoryBlockAt((int)s, block); mappedRegionCount++; } public static final class UnconnectedMemoryBlock extends Memory { public void clear() {} public void clear(int start, int length) {} public void copyContentsInto(int address, byte[] buffer, int off, int len) {} public void copyContentsFrom(int address, byte[] buffer, int off, int len) { len = Math.min(BLOCK_SIZE - address, Math.min(buffer.length - off, len)); for (int i=off; i<len; i++) buffer[i] = getByte(0); } public long getSize() { return BLOCK_SIZE; } public byte getByte(int offset) { return (byte) 0xFF; } public short getWord(int offset) { return (short) 0xFFFF; } public int getDoubleWord(int offset) { return 0xFFFFFFFF; } public long getQuadWord(int offset) { return -1l; } public long getLowerDoubleQuadWord(int offset) { return -1l; } public long getUpperDoubleQuadWord(int offset) { return -1l; } public void setByte(int offset, byte data) {} public void setWord(int offset, short data) {} public void setDoubleWord(int offset, int data) {} public void setQuadWord(int offset, long data) {} public void setLowerDoubleQuadWord(int offset, long data) {} public void setUpperDoubleQuadWord(int offset, long data) {} public int execute(Processor cpu, int offset) { throw new IllegalStateException("Trying to execute in Unconnected Block @ 0x" + Integer.toHexString(offset)); } public CodeBlock decodeCodeBlockAt(Processor cpu, int offset) { throw new IllegalStateException("Trying to execute in Unconnected Block @ 0x" + Integer.toHexString(offset)); } } public void reset() { clear(); setGateA20State(false); linearAddr = null; } public boolean updated() { return true; } public void updateComponent(HardwareComponent component) { } public boolean initialised() { return (linearAddr != null); } public void acceptComponent(HardwareComponent component) { if (component instanceof LinearAddressSpace) linearAddr = (LinearAddressSpace) component; } public String toString() { return "Physical Address Bus"; } private Memory getMemoryBlockAt(int i) { try { return quickIndex[i >>> INDEX_SHIFT]; } catch (ArrayIndexOutOfBoundsException e) { try { return index[i >>> TOP_INDEX_SHIFT][(i >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK]; } catch (NullPointerException n) { return UNCONNECTED; } } } private void setMemoryBlockAt(int i, Memory b) { try { int idx = i >>> INDEX_SHIFT; quickNonA20MaskedIndex[idx] = b; if ((idx & (GATEA20_MASK >>> INDEX_SHIFT)) == idx) { quickA20MaskedIndex[idx] = b; quickA20MaskedIndex[idx | ((~GATEA20_MASK) >>> INDEX_SHIFT)] = b; } } catch (ArrayIndexOutOfBoundsException e) { try { nonA20MaskedIndex[i >>> TOP_INDEX_SHIFT][(i >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK] = b; } catch (NullPointerException n) { nonA20MaskedIndex[i >>> TOP_INDEX_SHIFT] = new Memory[BOTTOM_INDEX_SIZE]; nonA20MaskedIndex[i >>> TOP_INDEX_SHIFT][(i >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK] = b; } if ((i & GATEA20_MASK) == i) { try { a20MaskedIndex[i >>> TOP_INDEX_SHIFT][(i >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK] = b; } catch (NullPointerException n) { a20MaskedIndex[i >>> TOP_INDEX_SHIFT] = new Memory[BOTTOM_INDEX_SIZE]; a20MaskedIndex[i >>> TOP_INDEX_SHIFT][(i >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK] = b; } int modi = i | ~GATEA20_MASK; try { a20MaskedIndex[modi >>> TOP_INDEX_SHIFT][(modi >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK] = b; } catch (NullPointerException n) { a20MaskedIndex[modi >>> TOP_INDEX_SHIFT] = new Memory[BOTTOM_INDEX_SIZE]; a20MaskedIndex[modi >>> TOP_INDEX_SHIFT][(modi >>> BOTTOM_INDEX_SHIFT) & BOTTOM_INDEX_MASK] = b; } } } } public void timerCallback() {}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -