diff --git a/Server/src/main/java/net/simon987/server/assembly/CPU.java b/Server/src/main/java/net/simon987/server/assembly/CPU.java index e445436..52cc0be 100755 --- a/Server/src/main/java/net/simon987/server/assembly/CPU.java +++ b/Server/src/main/java/net/simon987/server/assembly/CPU.java @@ -47,6 +47,11 @@ public class CPU implements JSONSerialisable { * executed at this address each tick. Defaults to org_offset@config.properties */ private int codeSegmentOffset; + /** + * Offset of the code segment. The code starts to get + * executed at this address each tick. Defaults to org_hwIVoffset@config.properties + */ + private int hardwareInterruptVectorOffset; /** * Instruction pointer, always points to the next instruction @@ -74,6 +79,7 @@ public class CPU implements JSONSerialisable { registerSet = new DefaultRegisterSet(); attachedHardware = new HashMap<>(); codeSegmentOffset = config.getInt("org_offset"); + hardwareInterruptVectorOffset = config.getInt("org_hwIVoffset"); instructionSet.add(new JmpInstruction(this)); instructionSet.add(new JnzInstruction(this)); @@ -469,13 +475,13 @@ public class CPU implements JSONSerialisable { } /** - * Sets the IP to 0x0200 + Offset and pushes flags then the old IP + * Sets the IP to codeSegmentOffset + Offset and pushes flags then the old IP * */ - public void Interrupt(int hw, int offset, boolean retry) { - Instruction push = instructionSet.get("push"); + public void interrupt(boolean hw, int offset) { + Instruction push = instructionSet.get(PushInstruction.OPCODE); push.execute(status.toByte(), status); push.execute(ip, status); - this.setIp((char)(0x0200 + offset*2 + 0x0080*hw)); + this.setIp((char)(codeSegmentOffset + offset*2 + (hw ? hardwareInterruptVectorOffset : 0))); } } diff --git a/Server/src/main/java/net/simon987/server/assembly/instruction/IntInstruction.java b/Server/src/main/java/net/simon987/server/assembly/instruction/IntInstruction.java index bad1b64..ff3eda9 100644 --- a/Server/src/main/java/net/simon987/server/assembly/instruction/IntInstruction.java +++ b/Server/src/main/java/net/simon987/server/assembly/instruction/IntInstruction.java @@ -6,7 +6,7 @@ import net.simon987.server.assembly.Status; /** * Software Interrupt * Pushes the flags register and the IP to the stack then - * Sets the IP to 0x0200 + 2*src. + * Sets the IP to the CPU codeSegmentOffset + 2*src. * (x2 is to align with jmp instructions) * * No reserved interrupt vectors yet @@ -23,12 +23,7 @@ public class IntInstruction extends Instruction{ @Override public Status execute(int src, Status status) { - cpu.Interrupt(0, src, false); + cpu.interrupt(false, src); return status; } - - public Status execute(Status status) { - cpu.Interrupt(0,0, false); - return status; - } } diff --git a/Server/src/main/java/net/simon987/server/assembly/instruction/IretInstruction.java b/Server/src/main/java/net/simon987/server/assembly/instruction/IretInstruction.java index 6caec63..e15b59b 100644 --- a/Server/src/main/java/net/simon987/server/assembly/instruction/IretInstruction.java +++ b/Server/src/main/java/net/simon987/server/assembly/instruction/IretInstruction.java @@ -16,13 +16,13 @@ public class IretInstruction extends Instruction{ private CPU cpu; public IretInstruction(CPU cpu) { - super("intr", OPCODE); + super("iret", OPCODE); this.cpu = cpu; } public Status execute(Status status) { - cpu.setIp((char)cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue())); //IP (SP + 0) - status.fromByte((char) cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue() + 1)); //Status (SP + 1) + cpu.setIp((char)cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue())); //IP = (SP + 0) + status.fromByte((char) cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue() + 1)); //Status = (SP + 1) cpu.getRegisterSet().getRegister("SP").setValue(cpu.getRegisterSet().getRegister("SP").getValue() + 2); //Increment SP (stack grows towards smaller) return status; } diff --git a/config.properties b/config.properties index 87bc1c8..78209cf 100644 --- a/config.properties +++ b/config.properties @@ -20,6 +20,8 @@ cert_path=certificates tick_length=1000 # Default offset of the origin (starting point of code execution) in words org_offset=512 +# Default offset of interrupts from hardware (from starting execution point) +org_hwIVoffset=126 # Address of the stack bottom stack_bottom=65536 # Size of the memory in words