/ Resources / Design / Class Definitions / CPU

RCOS.java Home PageContext

CPU

Class:

CPU

Name:

CPU

Comment:

Simulates P-Code CPU, normally executes in a simple loop.

fetchInstruction

  • address translation
  • check valid instruction
executeInstruction
if interruptsEnabled then
handleInterrupts
  • check InterruptQ to see if any are due at this point in time
  • any due are handled in a loop and usually result in calling a kernel method,
  • possibly a differnet method for each interrupt OR same method but pass the Interrupt class as a parameter.
oneTick
  • increment CPU clock
  • if time for a TimerInterrupt than add to the InterruptQ so that the interrupt is handled at the end of the next instruction execution cycle
  • should include a simple method to change when TimerInterrupts occur

Collaborators:

Interrupt - store information about type, source etc
Instruction - store opcode, parameter etc
Address - possibly used for translation mechanisms
PriorityQueue - used to store interrupts that are scheduled to happen

Responsibilities: