Пример #1
0
    def run(self):
        ''' move data from kernel memory to HD '''

        # get task data
        if self.used_resources.get_by_class(TaskDataAtSM) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(TaskDataAtSM), self,
                TaskDataAtSM)
            return

        # get external memory
        if self.used_resources.get_by_class(ExternalMemory) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(ExternalMemory), self,
                ExternalMemory)
            return

        # get channel3
        if self.used_resources.get_by_class(Channel3) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(Channel3), self, Channel3)
            return

        # move data
        write_data = real.channel_device.sm_hd(True)

        kernel.create_resource(TaskAtHD, self, {'write_info': write_data})
        kernel.delete_resource(self.used_resources.get_by_class(TaskDataAtSM))
        kernel.free_resource(self.used_resources.get_by_class(Channel3), self,
                             True)
        return
Пример #2
0
    def run(self):
        ''' create virtual machine '''

        # get load task
        if self.used_resources.get_by_class(TaskLoaded) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(TaskLoaded), self, TaskLoaded)
            return
        
        in_data = True 
        ds_length = 0
        cs_length = 0

        # manual ugly counting
        for address in self.used_resources.get_by_class(TaskLoaded).addresses:
            if user_memory.fetch(address) == "CODE":
                in_data = False
                cs_length -= 1

            if in_data:
                ds_length += 1
            else:
                cs_length += 1

        kernel.create_process(VirtualMachine, self, { 'ds_length' : ds_length, 'cs_length' : cs_length, 'addresses' : self.used_resources.get_by_class(TaskLoaded).addresses })
        kernel.delete_resource(self.used_resources.get_by_class(TaskLoaded))
Пример #3
0
    def run(self):
        ''' move task from HD to User memory '''

        # get task loaded
        if self.used_resources.get_by_class(TaskAtHD) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(TaskAtHD), self, TaskAtHD)
            return

        # TODO - interaction with TaskAtHD for asking space
        # Enough-space is single resource that when asked checks if there is enough space on user memory
        # and reserves it
        # get enough space
        #if self.used_resources.get_by_class(EnoughSpace) is None:
        #    kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(EnoughSpace), self, EnoughSpace)
        #    return

        # get channel3
        if self.used_resources.get_by_class(Channel3) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(Channel3), self, Channel3)
            return

        addresses = channel_device.hd_to_um(
            self.used_resources.get_by_class(TaskAtHD).write_info)

        if addresses is not None:
            kernel.create_resource(TaskLoaded, self, {'addresses': addresses})
            kernel.delete_resource(self.used_resources.get_by_class(TaskAtHD))

        #kernel.free_resource(self.used_resources.get_by_class(EnoughSpace), self)
        #return
        kernel.free_resource(self.used_resources.get_by_class(Channel3), self,
                             True)
        return
Пример #4
0
    def run(self):
        ''' create virtual machine '''

        # get load task
        if self.used_resources.get_by_class(TaskLoaded) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(TaskLoaded), self,
                TaskLoaded)
            return

        in_data = True
        ds_length = 0
        cs_length = 0

        # manual ugly counting
        for address in self.used_resources.get_by_class(TaskLoaded).addresses:
            if user_memory.fetch(address) == "CODE":
                in_data = False
                cs_length -= 1

            if in_data:
                ds_length += 1
            else:
                cs_length += 1

        kernel.create_process(
            VirtualMachine, self, {
                'ds_length': ds_length,
                'cs_length': cs_length,
                'addresses':
                self.used_resources.get_by_class(TaskLoaded).addresses
            })
        kernel.delete_resource(self.used_resources.get_by_class(TaskLoaded))
Пример #5
0
    def run(self):
        ''' move data from kernel memory to HD '''

        # get task data
        if self.used_resources.get_by_class(TaskDataAtSM) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(TaskDataAtSM), self, TaskDataAtSM)
            return

        # get external memory
        if self.used_resources.get_by_class(ExternalMemory) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(ExternalMemory), self, ExternalMemory)
            return

        # get channel3 
        if self.used_resources.get_by_class(Channel3) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(Channel3), self, Channel3)
            return

        # move data
        write_data = real.channel_device.sm_hd(True)

        kernel.create_resource(TaskAtHD, self, {'write_info' : write_data})
        kernel.delete_resource(self.used_resources.get_by_class(TaskDataAtSM))
        kernel.free_resource(self.used_resources.get_by_class(Channel3), self, True)
        return
Пример #6
0
    def run(self):
        ''' move task from HD to User memory '''

        # get task loaded
        if self.used_resources.get_by_class(TaskAtHD) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(TaskAtHD), self, TaskAtHD)
            return

        # TODO - interaction with TaskAtHD for asking space
        # Enough-space is single resource that when asked checks if there is enough space on user memory
        # and reserves it
        # get enough space
        #if self.used_resources.get_by_class(EnoughSpace) is None:
        #    kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(EnoughSpace), self, EnoughSpace)
        #    return

        # get channel3 
        if self.used_resources.get_by_class(Channel3) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(Channel3), self, Channel3)
            return

        addresses =  channel_device.hd_to_um(self.used_resources.get_by_class(TaskAtHD).write_info)

        if addresses is not None:
            kernel.create_resource(TaskLoaded, self, {'addresses' : addresses })
            kernel.delete_resource(self.used_resources.get_by_class(TaskAtHD))

        #kernel.free_resource(self.used_resources.get_by_class(EnoughSpace), self)
        #return 
        kernel.free_resource(self.used_resources.get_by_class(Channel3), self, True)
        return
Пример #7
0
    def run(self):
        while True:
            if self.used_resources.get_by_class(LineToPrint) is None:
                kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(LineToPrint), self, LineToPrint)
                return

            output_device.write(self.used_resources.get_by_class(LineToPrint).data_to_print)

            kernel.delete_resource(self.used_resources.get_by_class(LineToPrint))
Пример #8
0
    def run(self):
        while True:
            if self.used_resources.get_by_class(LineToPrint) is None:
                kernel.ask_for_resource(
                    kernel_data.RESOURCES.get_by_class(LineToPrint), self,
                    LineToPrint)
                return

            output_device.write(
                self.used_resources.get_by_class(LineToPrint).data_to_print)

            kernel.delete_resource(
                self.used_resources.get_by_class(LineToPrint))
Пример #9
0
    def run(self):
        ''' interprets loaded task '''

        # get task
        if self.used_resources.get_by_class(TaskAtSM) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(TaskAtSM), self, TaskAtSM)
            return
        
        if data.SM[-1][:3] != "END" or data.SM[0][:4] != "DATA" or not data.SM.__contains__("CODE"):
            kernel.create_resource(LineToPrint, self, {'data' : "PARSING TASK FAILED: task name: " + self.used_resources.get_by_class(TaskAtSM).name + 'at: ' + str(data.SM[0][:3]) + '\n' })
            kernel.delete_resource(self.used_resources.get_by_class(TaskAtSM))
            return

        kernel.create_resource(TaskDataAtSM, self)
        kernel.delete_resource(self.used_resources.get_by_class(TaskAtSM))
Пример #10
0
    def run(self):
        ''' 
          Reads task from input device to kernel memory and creates
            resource task_at_sm
        '''
        while True:
            # get task
            if self.used_resources.get_by_class(TaskAtInput) is None:
                kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(TaskAtInput), self, TaskAtInput)
                return

            # get input device
            if self.used_resources.get_by_class(InputDevice) is None:
                kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(InputDevice), self, InputDevice)
                return

            # get kernel memory
            if self.used_resources.get_by_class(KernelMemory) is None:
                kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(KernelMemory), self, KernelMemory)
                return

            # get channel device
            if self.used_resources.get_by_class(Channel1) is None:
                kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(Channel1), self, Channel1)
                return
            
            # read data
            data.input_file = self.used_resources.get_by_class(TaskAtInput).file_path
            channel_device.read_from_in(True) 

            # create resource at_sm
            kernel.create_resource(TaskAtSM, self)

            # reverse order because after freeing resource it would be caught again
            # delete resource
            kernel.delete_resource(self.used_resources.get_by_class(TaskAtInput))
            #free resource
            kernel.free_resource(self.used_resources.get_by_class(KernelMemory), self, True)
            return

            kernel.free_resource(self.used_resources.get_by_class(Channel1), self, True)
            return 
Пример #11
0
    def run(self):
        ''' Waits for InterruptEvent resource, identifies it and deals with it  '''

        # get interrupt event 
        if self.used_resources.get_by_class(InterruptEvent) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(InterruptEvent), self, InterruptEvent)
            return

        interrupt_event = self.used_resources.get_by_class(InterruptEvent)

        if processor.pi != 0:
            rOpts = {}
            
            '''
                    Don't forget to change messages into less lame ones.
                    Also need to think of what to do with the offending processes.
            '''
            
            if processor.pi == 1: #Some bad memory thingie
                rOpts['data'] = 'Bad memory thingie message: '  
            elif processor.pi == 2: #Illegal operation
                rOpts['data'] = 'Illegal operation: '
            elif processor.pi == 3: #Critical system error
                rOpts['data'] = 'Critical system error: '
            
            rOpts['data'] += interrupt_event.message
            kernel.create_resource(LineToPrint, self, rOpts)
            kernel.create_resource(TaskCompleted, self)
            kernel.terminate_process(self.used_resources.get_by_class(InterruptEvent).process) 
            processor.pi = 0
        
        elif processor.si != 0:
                
            if processor.si == 1: #GD
                    #???
                    pass
            elif processor.si == 2: #PD
                    #???
                    pass
            elif processor. si == 3: #END statement found
                    kernel.terminate_process(self.used_resources.get_by_class(InterruptEvent).process) 
                    kernel.create_resource(TaskCompleted, self)

            processor.si = 0
        
        # this actually wrong : ioi interrupts don't work this way. See docs
        #elif processor.ioi != 0:
        #    print "IOI"
        #    rOpts = {}
        #    rOpts['data'] = '' #find out where to get data
        #    kernel.create_resource(LineToPrint, self, rOpts)
        #    processor.ioi = 0
        
        elif processor.ti != 0: #blocks process when time runs out 
            processor.ti = 0
            processor.time = 0
            # this is not needed: process was already blocked at this time
            #self.used_resources.get_by_class(InterruptEvent).process.make_blocked()

        # if VM was terminated, the resource it created will no longer exist
        if not self.used_resources.get_by_class(InterruptEvent) is None: 
            kernel.delete_resource(self.used_resources.get_by_class(InterruptEvent))
Пример #12
0
    def run(self):
        ''' Waits for InterruptEvent resource, identifies it and deals with it  '''

        # get interrupt event
        if self.used_resources.get_by_class(InterruptEvent) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(InterruptEvent), self,
                InterruptEvent)
            return

        interrupt_event = self.used_resources.get_by_class(InterruptEvent)

        if processor.pi != 0:
            rOpts = {}
            '''
                    Don't forget to change messages into less lame ones.
                    Also need to think of what to do with the offending processes.
            '''

            if processor.pi == 1:  #Some bad memory thingie
                rOpts['data'] = 'Bad memory thingie message: '
            elif processor.pi == 2:  #Illegal operation
                rOpts['data'] = 'Illegal operation: '
            elif processor.pi == 3:  #Critical system error
                rOpts['data'] = 'Critical system error: '

            rOpts['data'] += interrupt_event.message
            kernel.create_resource(LineToPrint, self, rOpts)
            kernel.create_resource(TaskCompleted, self)
            kernel.terminate_process(
                self.used_resources.get_by_class(InterruptEvent).process)
            processor.pi = 0

        elif processor.si != 0:

            if processor.si == 1:  #GD
                #???
                pass
            elif processor.si == 2:  #PD
                #???
                pass
            elif processor.si == 3:  #END statement found
                kernel.terminate_process(
                    self.used_resources.get_by_class(InterruptEvent).process)
                kernel.create_resource(TaskCompleted, self)

            processor.si = 0

        # this actually wrong : ioi interrupts don't work this way. See docs
        #elif processor.ioi != 0:
        #    print "IOI"
        #    rOpts = {}
        #    rOpts['data'] = '' #find out where to get data
        #    kernel.create_resource(LineToPrint, self, rOpts)
        #    processor.ioi = 0

        elif processor.ti != 0:  #blocks process when time runs out
            processor.ti = 0
            processor.time = 0
            # this is not needed: process was already blocked at this time
            #self.used_resources.get_by_class(InterruptEvent).process.make_blocked()

        # if VM was terminated, the resource it created will no longer exist
        if not self.used_resources.get_by_class(InterruptEvent) is None:
            kernel.delete_resource(
                self.used_resources.get_by_class(InterruptEvent))