📄 processor.java
字号:
if (eflagsID) result |= 0x200000; return result; } public void setEFlags(int eflags) { // TODO: check that there aren't flags which can't be set this way! setCarryFlag((eflags & 1 ) != 0); setParityFlag((eflags & (1 << 2)) != 0); setAuxiliaryCarryFlag((eflags & (1 << 4)) != 0); setZeroFlag((eflags & (1 << 6)) != 0); setSignFlag((eflags & (1 << 7)) != 0); eflagsTrap = ((eflags & (1 << 8)) != 0); eflagsInterruptEnableSoon = eflagsInterruptEnable = ((eflags & (1 << 9)) != 0); eflagsDirection = ((eflags & (1 << 10)) != 0); setOverflowFlag((eflags & (1 << 11)) != 0); eflagsIOPrivilegeLevel = ((eflags >> 12) & 3); eflagsNestedTask = ((eflags & (1 << 14)) != 0); eflagsResume = ((eflags & (1 << 16)) != 0); eflagsVirtualInterrupt = ((eflags & (1 << 19)) != 0); eflagsVirtualInterruptPending = ((eflags & (1 << 20)) != 0); eflagsID = ((eflags & (1 << 21)) != 0); if (eflagsAlignmentCheck != ((eflags & (1 << 18)) != 0)) { eflagsAlignmentCheck = ((eflags & (1 << 18)) != 0); checkAlignmentChecking(); } if (eflagsVirtual8086Mode != ((eflags & (1 << 17)) != 0)) { eflagsVirtual8086Mode = ((eflags & (1 << 17)) != 0); if (eflagsVirtual8086Mode) { throw ModeSwitchException.VIRTUAL8086_MODE_EXCEPTION; } else { throw ModeSwitchException.PROTECTED_MODE_EXCEPTION; } } } public void processClock() { virtualClock.process(); } public void setCPL(int value) { currentPrivilegeLevel = value; linearMemory.setSupervisor(currentPrivilegeLevel == 0); checkAlignmentChecking(); } public int getCPL() { return currentPrivilegeLevel; } public void reportFPUException() { if ((cr0 & CR0_NUMERIC_ERROR) == 0) { System.err.println("Reporting FPU Error Via IRQ#13"); interruptController.setIRQ(13, 1); } else { System.err.println("Reporting FPU Error Via Exception 0x10"); throw new ProcessorException(Processor.PROC_EXCEPTION_MF_10, true); } } public void raiseInterrupt() { synchronized (this) { interruptFlags |= IFLAGS_HARDWARE_INTERRUPT; this.notifyAll(); } } public void clearInterrupt() { interruptFlags &= ~IFLAGS_HARDWARE_INTERRUPT; } public boolean waitForInterrupt(long time) { synchronized(this) { if ((interruptFlags & IFLAGS_HARDWARE_INTERRUPT) != 0) return true; try { this.wait(time); } catch (InterruptedException e) {}; return ((interruptFlags & IFLAGS_HARDWARE_INTERRUPT) != 0); } } public void requestReset() { interruptFlags |= IFLAGS_RESET_REQUEST; } public int getInterruptFlags() { return interruptFlags; } public boolean isProtectedMode() { return (cr0 & CR0_PROTECTION_ENABLE) == 1; } public boolean isVirtual8086Mode() { return eflagsVirtual8086Mode; } // Need to think about the TS flag for when we have an FPU - Section 2.5 Vol 3 public void setCR0(int value) { value |= 0x10; int changedBits = value ^ cr0; if (changedBits == 0) return; //actually set the value! cr0 = value; boolean pagingChanged = (changedBits & CR0_PAGING) != 0; boolean cachingChanged = (changedBits & CR0_CACHE_DISABLE) != 0; boolean modeSwitch = (changedBits & CR0_PROTECTION_ENABLE) != 0; boolean wpUserPagesChanged = (changedBits & CR0_WRITE_PROTECT) != 0; boolean alignmentChanged = (changedBits & CR0_ALIGNMENT_MASK) != 0; if ((changedBits & CR0_NOT_WRITETHROUGH)!= 0) System.err.println("INFO: Unimplemented CR0 flags changed ("+Integer.toHexString(changedBits)+"). Now is "+Integer.toHexString(value)); if (pagingChanged) { if (((value & CR0_PROTECTION_ENABLE) == 0) && ((value & CR0_PAGING) != 0)) throw new ProcessorException(PROC_EXCEPTION_GP, 0, true); } if (alignmentChanged) checkAlignmentChecking(); if (pagingChanged || cachingChanged) { linearMemory.setPagingEnabled((value & CR0_PAGING) != 0); linearMemory.setPageCacheEnabled((value & CR0_CACHE_DISABLE) == 0); } if (wpUserPagesChanged) linearMemory.setWriteProtectUserPages((value & CR0_WRITE_PROTECT) != 0); if (modeSwitch) { if ((value & CR0_PROTECTION_ENABLE) != 0) { convertSegmentsToProtectedMode(); throw ModeSwitchException.PROTECTED_MODE_EXCEPTION; } else {// linearMemory.flush(); setCPL(0); convertSegmentsToRealMode(); throw ModeSwitchException.REAL_MODE_EXCEPTION; } } } public int getCR0() { return cr0; } public void setCR3(int value) { cr3 = value; linearMemory.setPageWriteThroughEnabled((value & CR3_PAGE_WRITES_TRANSPARENT) != 0); linearMemory.setPageCacheEnabled((value & CR3_PAGE_CACHE_DISABLE) == 0); linearMemory.setPageDirectoryBaseAddress(value); } public int getCR3() { return cr3; } public int getCR2() { return cr2; } public void setCR2(int value) { cr2 = value; } public void setCR4(int value) { if (cr4 == value) return; cr4 = value; if ((cr4 & CR4_VIRTUAL8086_MODE_EXTENSIONS) != 0) System.err.println("WARNING: Virtual 8086 Mode Extensions enabled in the processor"); if ((cr4 & CR4_PROTECTED_MODE_VIRTUAL_INTERRUPTS) != 0) System.err.println("WARNING: Protected Mode Virtual Interrupts enabled in the processor"); if ((cr4 & CR4_OS_SUPPORT_UNMASKED_SIMD_EXCEPTIONS) != 0) System.err.println("WARNING: SIMD instruction support modified in the processor"); if ((cr4 & CR4_OS_SUPPORT_FXSAVE_FXSTORE) != 0) System.err.println("WARNING: FXSave and FXRStore flag enabled in the processor"); if ((cr4 & CR4_DEBUGGING_EXTENSIONS) != 0) System.err.println("WARNING: debugging extensions enabled"); if ((cr4 & CR4_TIME_STAMP_DISABLE) != 0) System.err.println("WARNING: timestamp restricted to CPL0"); if ((cr4 & CR4_PHYSICAL_ADDRESS_EXTENSION) != 0) throw new IllegalStateException("36 Bit Addressing enabled"); linearMemory.setGlobalPagesEnabled((value & CR4_PAGE_GLOBAL_ENABLE) != 0); linearMemory.setPageSizeExtensionsEnabled((cr4 & CR4_PAGE_SIZE_EXTENSIONS) != 0); } public int getCR4() { return cr4; } public void setDR0(int value) { dr0 = value; } public void setDR1(int value) { dr1 = value; } public void setDR2(int value) { dr2 = value; } public void setDR3(int value) { dr3 = value; } public void setDR6(int value) { dr6 = value; } public void setDR7(int value) { dr7 = value; } public int getDR0() { return dr0; } public int getDR1() { return dr1; } public int getDR2() { return dr2; } public int getDR3() { return dr3; } public int getDR6() { return dr6; } public int getDR7() { return dr7; } public long getMSR(int index) { try { return ((Long)modelSpecificRegisters.get(new Integer(index))).longValue(); } catch (NullPointerException e) { System.err.println("Reading unset MSR " + index + " : Returning 0"); return 0l; } } public void setMSR(int index, long value) { modelSpecificRegisters.put(new Integer(index), new Long(value)); } private void convertSegmentsToRealMode() { try { cs = createRealModeSegment(cs.translateAddressRead(0) >>> 4); } catch (ProcessorException e) { cs = createRealModeSegment(0); } try { ds = createRealModeSegment(ds.translateAddressRead(0) >>> 4); } catch (ProcessorException e) { ds = createRealModeSegment(0); } try { ss = createRealModeSegment(ss.translateAddressRead(0) >>> 4); } catch (ProcessorException e) { ss = createRealModeSegment(0); } try { es = createRealModeSegment(es.translateAddressRead(0) >>> 4); } catch (ProcessorException e) { es = createRealModeSegment(0); } try { fs = createRealModeSegment(fs.translateAddressRead(0) >>> 4); } catch (ProcessorException e) { fs = createRealModeSegment(0); } try { gs = createRealModeSegment(gs.translateAddressRead(0) >>> 4); } catch (ProcessorException e) { gs = createRealModeSegment(0); } } private void convertSegmentsToProtectedMode() { cs.setAddressSpace(linearMemory); ds.setAddressSpace(linearMemory); ss.setAddressSpace(linearMemory); es.setAddressSpace(linearMemory); fs.setAddressSpace(linearMemory); gs.setAddressSpace(linearMemory); } private void updateAlignmentCheckingInDataSegments() { if (alignmentChecking) { ds.setAddressSpace(alignmentCheckedMemory); ss.setAddressSpace(alignmentCheckedMemory); es.setAddressSpace(alignmentCheckedMemory); fs.setAddressSpace(alignmentCheckedMemory); gs.setAddressSpace(alignmentCheckedMemory); } else { ds.setAddressSpace(linearMemory); ss.setAddressSpace(linearMemory); es.setAddressSpace(linearMemory); fs.setAddressSpace(linearMemory); gs.setAddressSpace(linearMemory); } } public Segment createRealModeSegment(int selector) { return SegmentFactory.createRealModeSegment(physicalMemory, selector); } public Segment createDescriptorTableSegment(int base, int limit) { return SegmentFactory.createDescriptorTableSegment(linearMemory, base, limit); } public void correctAlignmentChecking(Segment segment) { if (alignmentChecking) { if ((segment.getType() & 0x18) == 0x10) // Should make this a data segment segment.setAddressSpace(alignmentCheckedMemory); } } public Segment getSegment(int segmentSelector) { boolean isSup = linearMemory.isSupervisor(); try { long segmentDescriptor = 0; linearMemory.setSupervisor(true); if ((segmentSelector & 0x4) != 0) segmentDescriptor = ldtr.getQuadWord(segmentSelector & 0xfff8); else { if (segmentSelector < 0x4) return SegmentFactory.NULL_SEGMENT; segmentDescriptor = gdtr.getQuadWord(segmentSelector & 0xfff8); } Segment result = SegmentFactory.createProtectedModeSegment(linearMemory, segmentSelector, segmentDescriptor);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -