Unhardcoded codeSegmentOffset and the hardware offset.

Changed Interrupt(int hw, int offset, boolean retry)
to	interrupt(boolean hw, int offset).
Removed no operand overload of int.
Added org_hwIVoddset to config.properties
This commit is contained in:
Brent O'Neil 2017-12-31 13:19:04 +11:00
parent 3db05478c1
commit ab5810c585
4 changed files with 17 additions and 14 deletions

View File

@ -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)));
}
}

View File

@ -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);
return status;
}
public Status execute(Status status) {
cpu.Interrupt(0,0, false);
cpu.interrupt(false, src);
return status;
}
}

View File

@ -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;
}

View File

@ -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