clean and work on labels
This commit is contained in:
@ -1,34 +1,39 @@
|
||||
class Asm::Arm::AddrTableObject
|
||||
def initialize
|
||||
@table = []
|
||||
@const = []
|
||||
end
|
||||
module Asm
|
||||
module Arm
|
||||
|
||||
class AddrTableObject
|
||||
def initialize
|
||||
@table = []
|
||||
@const = []
|
||||
end
|
||||
|
||||
# TODO don't create new entry if there's already an entry for the same label/const
|
||||
def add_label(label)
|
||||
d = [label, Asm::LabelObject.new]
|
||||
@table << d
|
||||
d[1]
|
||||
end
|
||||
# TODO don't create new entry if there's already an entry for the same label/const
|
||||
def add_label(label)
|
||||
d = [label, Asm::LabelObject.new]
|
||||
@table << d
|
||||
d[1]
|
||||
end
|
||||
|
||||
def add_const(const)
|
||||
d = [const, Asm::LabelObject.new]
|
||||
@const << d
|
||||
d[1]
|
||||
end
|
||||
def add_const(const)
|
||||
d = [const, Asm::LabelObject.new]
|
||||
@const << d
|
||||
d[1]
|
||||
end
|
||||
|
||||
def assemble(io, as)
|
||||
@table.each do |pair|
|
||||
target_label, here_label = *pair
|
||||
here_label.assemble io, as
|
||||
as.add_relocation io.tell, target_label, Asm::Arm::R_ARM_ABS32,
|
||||
Asm::Arm::Instruction::RelocHandler
|
||||
io.write_uint32 0
|
||||
end
|
||||
@const.each do |pair|
|
||||
const, here_label = *pair
|
||||
here_label.assemble io, as
|
||||
io.write_uint32 const
|
||||
def assemble(io, as)
|
||||
@table.each do |pair|
|
||||
target_label, here_label = *pair
|
||||
here_label.assemble io, as
|
||||
as.add_relocation io.tell, target_label, Asm::Arm::R_ARM_ABS32,
|
||||
Asm::Arm::Instruction::RelocHandler
|
||||
io.write_uint32 0
|
||||
end
|
||||
@const.each do |pair|
|
||||
const, here_label = *pair
|
||||
here_label.assemble io, as
|
||||
io.write_uint32 const
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
require 'asm/assembler'
|
||||
|
||||
require "asm/arm/addr_table_object"
|
||||
module Asm
|
||||
module Arm
|
||||
|
||||
|
@ -29,12 +29,12 @@ module Asm
|
||||
# Build representation for target address
|
||||
def build_operand(arg)
|
||||
#str / ldr are _seruous instructions. With BIG possibilities no half are implemented
|
||||
@i = 0
|
||||
@pre_post_index = 0
|
||||
@w = 0
|
||||
@operand = 0
|
||||
if (arg.is_a?(Asm::RegisterArgNode))
|
||||
@i = 0
|
||||
@pre_post_index = 0
|
||||
@w = 0
|
||||
@rn = reg_ref(arg)
|
||||
@operand = 0
|
||||
|
||||
if (false ) #argr.op and argr.right.is_a?(Asm::NumLiteralArgNode))
|
||||
|
||||
@ -55,17 +55,13 @@ module Asm
|
||||
else
|
||||
# raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg)
|
||||
end
|
||||
elsif (arg.is_a?(Asm::LabelEquivAddrArgNode) or arg.is_a?(Asm::NumEquivAddrArgNode))
|
||||
@i = 0
|
||||
elsif (arg.is_a?(Asm::LabelRefArgNode) or arg.is_a?(Asm::NumEquivAddrArgNode))
|
||||
@pre_post_index = 1
|
||||
@w = 0
|
||||
@rn = 15 # pc
|
||||
@operand = 0
|
||||
@use_addrtable_reloc = true
|
||||
@addrtable_reloc_target = arg
|
||||
else
|
||||
puts "Invalid #{arg.inspect}"
|
||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg.inspect)
|
||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect, arg.inspect)
|
||||
end
|
||||
end
|
||||
|
||||
@ -81,7 +77,7 @@ module Asm
|
||||
(pre_post_index << 12+4+4+1+1+1+1) | (i << 12+4+4+1+1+1+1+1) |
|
||||
(inst_class << 12+4+4+1+1+1+1+1+1) | (cond << 12+4+4+1+1+1+1+1+1+2)
|
||||
if (@use_addrtable_reloc)
|
||||
closest_addrtable = Asm::Arm.closest_addrtable(as)
|
||||
# closest_addrtable = Asm::Arm.closest_addrtable(as)
|
||||
if (@addrtable_reloc_target.is_a?(Asm::LabelEquivAddrArgNode))
|
||||
obj = ast_asm.object_for_label(@addrtable_reloc_target.label, inst)
|
||||
ref_label = closest_addrtable.add_label(obj)
|
||||
|
@ -17,7 +17,9 @@ module Asm
|
||||
end
|
||||
|
||||
def add_relocation(*args)
|
||||
@relocations << Asm::Relocation.new(*args)
|
||||
reloc = Asm::Relocation.new(*args)
|
||||
raise "reloc #{reloc.inspect}"
|
||||
@relocations << reloc
|
||||
end
|
||||
|
||||
def assemble(io)
|
||||
@ -27,6 +29,7 @@ module Asm
|
||||
|
||||
@relocations.delete_if do |reloc|
|
||||
io.seek reloc.position
|
||||
puts "reloc #{reloc.inspect}"
|
||||
if (reloc.label.extern?)
|
||||
reloc.handler.call(io, io.tell, reloc.type)
|
||||
else
|
||||
|
Reference in New Issue
Block a user