def DirFA(): """ Set the device's family. If this is not used in a program a warning is given and the assembler defaults to the XMega family, which can do everything. As of version 3.02.00 of this cross overlay an extra family tree has been added to reflect the families found on Wikipedia. This allows for a much finer distinction between the capabilities of the processors. The old family tree still exists though for backward compatibility. - Boundary Sync. """ global Asm target.BoundarySync() families = [ 'TINY', 'AVR', 'MEGA', 'XMEGA', 'REDUCED', 'MINIMAL', 'CLASSIC8K' ] families += ['CLASSIC128K', 'ENHANCED8K', 'ENHANCED128K', 'ENHANCED4M'] if dec.Asm.Parse_Pointer == 0: # No parameter given errors.DoError('missoper', False) return family = assem.GetWord().upper() if family not in families: errors.DoError('badoper', False) return dec.Asm.AVR_Family = families.index(family) + 1 NoMore()
def CrossMnemonic(): """ Instructions have to start on an even byte location, so we'll do a boundary sync first. Then we'll check if the given directive is known to us. Depending on the chosen family some directives may not be valid. Parse the mnemonic if it is valid. """ global Asm target.BoundarySync() if dec.Asm.AVR_Family == 0: # AVR Family not specified, assume XMega family errors.DoWarning(dec.Cross.Name + 'nofamily', False) dec.Asm.AVR_Family = 4 if dec.Asm.Mnemonic in dec.Asm.Instructions: if not (FamilyCheck(dec.Asm.Instructions[dec.Asm.Mnemonic][1], dec.Asm.Instructions[dec.Asm.Mnemonic][2])): # Opcode not supported by this family errors.DoError('badopco', False) else: # Opcode is supported by this family, do it dec.Asm.Timing = dec.Asm.Instructions[dec.Asm.Mnemonic][4] func = dec.Asm.Instructions[dec.Asm.Mnemonic][0] func() else: errors.DoError('badopco', False)
def DirMS(): """ Set the maximum ROM memory size. Jumps beyond that size will result in a range error. Code can not be saved to a target address which is > maximum size. Forward reference values are not allowed. Thus for a 64k word device, .MS must be set to $10000. Note: Any size can be set between 0 and $400000, even silly sizes! - Boundary Sync """ global Asm target.BoundarySync() if dec.Asm.Parse_Pointer == 0: # No parameter given errors.DoError('missoper', False) return value = assem.EvalExpr() if value[1]: # Forward referenced labels are not allowed errors.DoError('forwref', False) return else: # It's not a forward referenced label if value[0] < 1 or value[0] > ((1 << 22)): # Value not within legal range errors.DoError('range', False) return dec.Asm.Max_Address = value[0] - 1 NoMore()
def CrossCleanUp(): """ Ensure that the Code Memory ends on a word boundary. """ global Asm dec.Asm.Memory = 0 target.BoundarySync()
def CrossMnemonic(): """ Entry point for parsing the mnemonics for this cross overlay. """ global Asm target.BoundarySync() if dec.Asm.Mnemonic in dec.Asm.Instructions: func = dec.Asm.Instructions[dec.Asm.Mnemonic][0] func() else: errors.DoError('badopco', False)
def DirES(): """ Change to EEPROM segment. Equivalent to .SM EERPOM - Boundary Sync """ global Asm target.BoundarySync() dec.Asm.Memory = 2 dec.Asm.BOL_Address = dec.Asm.EM_Address dec.Asm.List_Address = dec.Asm.EM_Address
def DirDS(): """ Change to RAM segment. Equivalent to .SM RAM - Boundary Sync """ global Asm target.BoundarySync() dec.Asm.Memory = 1 dec.Asm.BOL_Address = dec.Asm.RM_Address dec.Asm.List_Address = dec.Asm.RM_Address
def DirCS(): """ Change to Code segment. Equivalent to .SM CODE - Boundary Sync """ global Asm target.BoundarySync() dec.Asm.Memory = 0 dec.Asm.BOL_Address = dec.Asm.PH_Address dec.Asm.List_Address = dec.Asm.PH_Address
def ParseLine(): """ We've got our source line. Now it's time to parse it all. However if we're defining a macro, we take a detour. First we look if it's an empty line or a comment line Then we extract the label field, if any. Then the mnemonic field, and act on its contents. It can be one of three things: A directive, a macro call or a mnemonic. Before executing the lot we also prepare the operand field. """ global Asm, Flags, Label dec.Asm.Parse_Pointer = 0 dec.Asm.New_Label = "" dec.Asm.Mnemonic = "" dec.Asm.List_Line = "" dec.Asm.Timing = "" dec.Asm.List_Byte_Cnt = 0 macrolevel = dec.Asm.Local_Index if dec.Asm.Parse_Line == chr(26) + " ": # Ctrl-Z, end mark for DOS files, ignore it return if dec.Asm.Macro_Def != '': # Defining a Macro, add this line to macro macros.DefineMacro() return if dec.Asm.Cond_False == 0: # Conditional assembly is true. Have to assemble this line # Select memory mode # May have changed by previous line if dec.Asm.Memory == 0: dec.Asm.BOL_Address = dec.Asm.PH_Address dec.Asm.List_Address = dec.Asm.PH_Address elif dec.Asm.Memory == 1: dec.Asm.BOL_Address = dec.Asm.RM_Address dec.Asm.List_Address = dec.Asm.RM_Address else: dec.Asm.BOL_Address = dec.Asm.EM_Address dec.Asm.List_Address = dec.Asm.EM_Address if IsComment(): # Do nothing if this line is empty or a comment line return newlabel = GetLabelName() globlab = string.ascii_uppercase + '_' # Legal begin chars of label if len(newlabel) > 0 and (newlabel[0] in globlab): # New global label defined newglobal = True else: # No new global lable defined newglobal = False if NowChar() == ":": # It's a macro label IncParsePointer() if NowChar() != " ": # Can't be a bare : errors.DoError('illlabel', False) return # Dont' bother to continue dec.Asm.New_Label = newlabel if len(newlabel) > 0: # Do a boundary sync if a label is given target.BoundarySync() dec.Asm.Mnemonic = GetMnemonic() if dec.Asm.Mnemonic == "": # No mnemonic means no operand either dec.Asm.Parse_Pointer = 0 else: # Parse the operand field dec.Asm.Parse_Pointer = FindOperandField() if newglobal and dec.Asm.Mnemonic[:3] != '.SE': # Set last assigned global label name, only when not .SE directive dec.Asm.Last_Global = newlabel # Reset macro indexes dec.Asm.Macro_Number = 0 dec.Asm.Local_Index = 0 DoAssemble() # Got all the ingredients, now put them all together if dec.Asm.New_Label != "": AssignLabel(dec.Asm.New_Label, macrolevel) else: # Conditional assembly is false, accept only .DO, .EL and # .FI directives if IsComment(): # Nothing to do in this line, it's a comment return if NowChar() != " ": # A label is declared here, get it but don't bother about syntax dec.Asm.New_Label = GetWord("", "", " ") dec.Asm.Mnemonic = GetMnemonic() if dec.Asm.Mnemonic != "": if dec.Asm.Mnemonic[:3] in (".DO", ".EL", ".FI"): # These are the only directives of interest now dec.Asm.Parse_Pointer = FindOperandField() DoAssemble()
def DirEV(): """ Force a Boundary Sync. """ target.BoundarySync()
def ParseLine(): """ We've got our source line. Now it's time to parse it all. However if we're defining a macro, we take a detour. First we look if it's an empty line or a comment line Then we extract the label field, if any. Then the mnemonic field, and act on its contents. It can be one of three things: A directive, a macro call or a mnemonic. Before executing the lot we also prepare the operand field. """ global Asm, Flags, Label global current_aid_pointer global array_aid, ending_address # JKL dec.Asm.Parse_Pointer = 0 dec.Asm.New_Label = "" dec.Asm.Mnemonic = "" dec.Asm.List_Line = "" dec.Asm.Timing = "" dec.Asm.List_Byte_Cnt = 0 macrolevel = dec.Asm.Local_Index if dec.Asm.Parse_Line == chr(26) + " ": # Ctrl-Z, end mark for DOS files, ignore it return if dec.Asm.Macro_Def != '': # Defining a Macro macros.DefineMacro() return if dec.Asm.Cond_False == 0: # Conditional assembly is ture. Have to assemble this line # Select memory mode # May have changed by previous line if dec.Asm.Memory == 0: dec.Asm.BOL_Address = dec.Asm.PH_Address dec.Asm.List_Address = dec.Asm.PH_Address elif dec.Asm.Memory == 1: dec.Asm.BOL_Address = dec.Asm.RM_Address dec.Asm.List_Address = dec.Asm.RM_Address else: dec.Asm.BOL_Address = dec.Asm.EM_Address dec.Asm.List_Address = dec.Asm.EM_Address if IsComment(): # Do nothing if this line is empty or a comment line return newlabel = GetLabelName() globlab = string.ascii_uppercase + '_' if len(newlabel) > 0 and (newlabel[0] in globlab): # Clear these in case we have to expand a macro on this line dec.Asm.Macro_Number = 0 dec.Asm.Local_Index = 0 dec.Asm.Last_Global = newlabel if NowChar() == ":": IncParsePointer() if NowChar() != " ": errors.DoError('illlabel', False) return # Dont' bother to continue dec.Asm.New_Label = newlabel if len(newlabel) > 0: # Do a boundary sync if a label is given target.BoundarySync() dec.Asm.Mnemonic = GetMnemonic() if dec.Asm.Mnemonic == "": dec.Asm.Parse_Pointer = 0 # No mnemonic means no operand either else: dec.Asm.Parse_Pointer = FindOperandField() DoAssemble() # Got all the ingredients, now put them all together if dec.Asm.New_Label != "": AssignLabel(dec.Asm.New_Label, macrolevel) else: # Conditional assembly is false, accept only .DO, .EL and .FI directives if IsComment(): # Nothing to do in this line, it's a comment return if NowChar() != " ": # A label is declared here, get it but don't bother about syntax dec.Asm.New_Label = GetWord("", "", " ") dec.Asm.Mnemonic = GetMnemonic() #jkl #sys.stdout = sys.__stdout__ if dec.Asm.Mnemonic != "": if dec.Asm.Mnemonic[:3] in (".DO", ".EL", ".FI"): # These are the only directives of interest now dec.Asm.Parse_Pointer = FindOperandField() DoAssemble() #JKL NOX if (len(dec.Asm.List_Line) > 0): #print(str(hex(dec.Asm.BOL_Address)) + " " +dec.Asm.Mnemonic + " " + dec.Asm.List_Line[8:14] + " " + str(dec.Asm.List_Byte_Cnt) + " ") # TODO ADD LABEL HERE, LINK BACK IN TO NEW ADDITIONAL SYMBOL TABLE array_aid[dec.Asm.BOL_Address] = { 'address': dec.Asm.BOL_Address, 'operator': dec.Asm.Mnemonic, 'operand': dec.Asm.List_Line[8:14], 'byte_cnt': dec.Asm.List_Byte_Cnt } print((array_aid[dec.Asm.BOL_Address])) ending_address = dec.Asm.BOL_Address