def __init__(self, ram, os, num=0): threading.Thread.__init__(self) self._num = num # unique ID of this cpu self.clear_registers() self._ram = ram self._os = os self._debug = False self._intr_raised = False self._intr_addrs = set() self._intr_lock = threading.Lock() self._intr_vector = [self._timer_isr] # Create device controller threads. # This is done here so that when the CPU is done running a program, # the screen and kbd threads can be killed. Then if it is told # to start up again, it will create new threads (since you cannot # restart stopped threads). # TODO: revisit the above decision? CPU thread is not stopped anymore... # Also, not using the Keyboard and Screen devices... # And, it seems weird for the CPU to start up the other device controllers... import devices self._timer = devices.TimerController(self, TIMER_DEV_ID, self._debug) self._os.set_timer_controller(self._timer) # Start up the thread, though its countdown will be -1, so it won't do anything # until that is set. self._timer.start()
def __init__(self, ram, os, num=0): # TODO: the CPU should know nothing about the OS. The CPU should # just execute instructions and handle the interrupts. We should # not pass the OS object in, but instead should make an API which # the OS code could call to register a callback to be called for # the various interrupts -- the software trap, timer expiration, # etc. self._num = num # unique ID of this cpu self._registers = { 'reg0' : 0, 'reg1' : 0, 'reg2' : 0, 'pc': 0 } self._ram = ram self._os = os self._mmu = MMU(self._ram) self._debug = False # Set _stop to True to "power down" the CPU. self._stop = False self._intr_raised = False self._intr_addrs = set() self._intr_lock = threading.Lock() self._intr_vector = [self._trap_isr, self._timer_isr] # Create device controller threads. # This is done here so that when the CPU is done running a program, # the screen and kbd threads can be killed. Then if it is told # to start up again, it will create new threads (since you cannot # restart stopped threads). # TODO: revisit the above decision? CPU thread is not stopped anymore... # Also, not using the Keyboard and Screen devices... # And, it seems weird for the CPU to start up the other device controllers... import devices self._timer = devices.TimerController(self, TIMER_DEV_ID, self._debug) # Start up the thread, though its countdown will be -1, so it won't do # anything until that is set. self._timer.start()