Example #1
0
    def getResultingDataAddress(self, offset):
        if len(self.segments) == 0:
            return offset
        else:
            #check if segment descriptor exists
            if len(self.segments) < self.DS:
                raise CPUSegmentViolationException(SEGMENT_DATA, offset)

            #check type of segment
            if self.segments[self.DS].type != SEGMENT_DATA:
                raise CPUSegmentViolationException(SEGMENT_DATA, offset)

            #check boundaries of segment
            if offset < self.segments[self.DS].start or offset > self.segments[
                    self.DS].limit:
                raise CPUSegmentViolationException(SEGMENT_DATA, offset)

            return offset
Example #2
0
    def setRegister(self, reg, value):
        if reg < 0 or reg > 30:
            raise CPUStateError(
                "Can't access register smaller than 0 or bigger than 30")

        if len(self.segments) == 0:
            self.memory.writeWord(0x2000 + reg, value)
        else:
            #check if segment descriptor exists
            if len(self.segments) < self.RS:
                raise CPUSegmentViolationException(SEGMENT_REGISTER, reg)

            #check type of segment
            if self.segments[self.RS].type != SEGMENT_REGISTER:
                raise CPUSegmentViolationException(SEGMENT_REGISTER, reg)

            #write register to memory
            self.memory.writeWord(self.segments[self.RS].start + reg, value)
Example #3
0
    def getResultingInstructionAddress(self):
        #TODO: check if privLvl is not violated

        if len(self.segments) == 0:
            return self.IP
        else:
            #check if segment descriptor exists
            if len(self.segments) < self.CS:
                raise CPUSegmentViolationException(SEGMENT_CODE, self.IP)

            #check type of segment
            if self.segments[self.CS].type != SEGMENT_CODE:
                raise CPUSegmentViolationException(SEGMENT_CODE, self.IP)

            #check boundaries of segment
            if self.IP < self.segments[
                    self.CS].start or self.IP > self.segments[self.CS].limit:
                raise CPUSegmentViolationException(SEGMENT_CODE, self.IP)

            return self.IP
Example #4
0
    def getResultingStackAddress(self):
        if len(self.segments) == 0:
            return self.getRegister(30)
        else:
            sp = self.getRegister(30)

            #check if segment descriptor exists
            if len(self.segments) < self.SS:
                raise CPUSegmentViolationException(SEGMENT_STACK, sp)

            #check type of segment
            if self.segments[self.SS].type != SEGMENT_STACK:
                raise CPUSegmentViolationException(SEGMENT_STACK, sp)

            #check boundaries of segment
            if sp < self.segments[self.SS].start or sp > self.segments[
                    self.SS].limit:
                raise CPUSegmentViolationException(SEGMENT_STACK, sp)

            return sp