mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
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:
parent
3db05478c1
commit
ab5810c585
@ -47,6 +47,11 @@ public class CPU implements JSONSerialisable {
|
|||||||
* executed at this address each tick. Defaults to org_offset@config.properties
|
* executed at this address each tick. Defaults to org_offset@config.properties
|
||||||
*/
|
*/
|
||||||
private int codeSegmentOffset;
|
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
|
* Instruction pointer, always points to the next instruction
|
||||||
@ -74,6 +79,7 @@ public class CPU implements JSONSerialisable {
|
|||||||
registerSet = new DefaultRegisterSet();
|
registerSet = new DefaultRegisterSet();
|
||||||
attachedHardware = new HashMap<>();
|
attachedHardware = new HashMap<>();
|
||||||
codeSegmentOffset = config.getInt("org_offset");
|
codeSegmentOffset = config.getInt("org_offset");
|
||||||
|
hardwareInterruptVectorOffset = config.getInt("org_hwIVoffset");
|
||||||
|
|
||||||
instructionSet.add(new JmpInstruction(this));
|
instructionSet.add(new JmpInstruction(this));
|
||||||
instructionSet.add(new JnzInstruction(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) {
|
public void interrupt(boolean hw, int offset) {
|
||||||
Instruction push = instructionSet.get("push");
|
Instruction push = instructionSet.get(PushInstruction.OPCODE);
|
||||||
push.execute(status.toByte(), status);
|
push.execute(status.toByte(), status);
|
||||||
push.execute(ip, status);
|
push.execute(ip, status);
|
||||||
this.setIp((char)(0x0200 + offset*2 + 0x0080*hw));
|
this.setIp((char)(codeSegmentOffset + offset*2 + (hw ? hardwareInterruptVectorOffset : 0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import net.simon987.server.assembly.Status;
|
|||||||
/**
|
/**
|
||||||
* Software Interrupt
|
* Software Interrupt
|
||||||
* Pushes the flags register and the IP to the stack then
|
* 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)
|
* (x2 is to align with jmp instructions)
|
||||||
*
|
*
|
||||||
* No reserved interrupt vectors yet
|
* No reserved interrupt vectors yet
|
||||||
@ -23,12 +23,7 @@ public class IntInstruction extends Instruction{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Status execute(int src, Status status) {
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,13 @@ public class IretInstruction extends Instruction{
|
|||||||
private CPU cpu;
|
private CPU cpu;
|
||||||
|
|
||||||
public IretInstruction(CPU cpu) {
|
public IretInstruction(CPU cpu) {
|
||||||
super("intr", OPCODE);
|
super("iret", OPCODE);
|
||||||
this.cpu = cpu;
|
this.cpu = cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Status execute(Status status) {
|
public Status execute(Status status) {
|
||||||
cpu.setIp((char)cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue())); //IP (SP + 0)
|
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)
|
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)
|
cpu.getRegisterSet().getRegister("SP").setValue(cpu.getRegisterSet().getRegister("SP").getValue() + 2); //Increment SP (stack grows towards smaller)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ cert_path=certificates
|
|||||||
tick_length=1000
|
tick_length=1000
|
||||||
# Default offset of the origin (starting point of code execution) in words
|
# Default offset of the origin (starting point of code execution) in words
|
||||||
org_offset=512
|
org_offset=512
|
||||||
|
# Default offset of interrupts from hardware (from starting execution point)
|
||||||
|
org_hwIVoffset=126
|
||||||
# Address of the stack bottom
|
# Address of the stack bottom
|
||||||
stack_bottom=65536
|
stack_bottom=65536
|
||||||
# Size of the memory in words
|
# Size of the memory in words
|
||||||
|
Loading…
x
Reference in New Issue
Block a user