diff --git a/lib/asm/arm/generator_label.rb b/lib/asm/arm/generator_label.rb index c5f9634d..47d23d88 100644 --- a/lib/asm/arm/generator_label.rb +++ b/lib/asm/arm/generator_label.rb @@ -4,6 +4,12 @@ class Asm::Arm::GeneratorLabel < Asm::LabelObject def initialize(asm) @asm = asm end + def at pos + @position = pos + end + def length + 0 + end def set! @asm.add_object self end diff --git a/lib/asm/arm/instruction.rb b/lib/asm/arm/instruction.rb index cb9b1e71..5affab7a 100644 --- a/lib/asm/arm/instruction.rb +++ b/lib/asm/arm/instruction.rb @@ -141,8 +141,8 @@ module Asm io << packed[0,3] elsif (arg.is_a?(Asm::LabelObject) or arg.is_a?(Asm::LabelRefNode)) #not yet tested/supported - arg = @ast_asm.object_for_label(arg.label, self) if arg.is_a?(Asm::LabelRefNode) - as.add_relocation(io.tell, arg, Asm::Arm::R_ARM_PC24, RelocHandler) +# arg = @ast_asm.object_for_label(arg.label, self) if arg.is_a?(Asm::LabelRefNode) +# as.add_relocation(io.tell, arg, Asm::Arm::R_ARM_PC24, RelocHandler) #write 0 "for now" and let relocation happen io << "\x00\x00\x00" else diff --git a/lib/asm/assembler.rb b/lib/asm/assembler.rb index ac5f975c..bcbaff37 100644 --- a/lib/asm/assembler.rb +++ b/lib/asm/assembler.rb @@ -1,4 +1,3 @@ -require_relative "relocation" module Asm ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand' @@ -7,11 +6,11 @@ module Asm class Assembler def initialize @objects = [] - @position = 0 + @position = -1 # marks not set @label_objects = [] @relocations = [] end - attr_reader :relocations, :objects + attr_reader :relocations, :objects , :position def add_object(obj) obj.at(@position) @@ -19,28 +18,45 @@ module Asm @objects << obj end - def add_relocation(*args) - reloc = Asm::Relocation.new(*args) - #raise "reloc #{reloc.inspect}" - @relocations << reloc - end def assemble(io) @objects.each do |obj| obj.assemble io, self end - - @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 - reloc.handler.call(io, reloc.label.address, reloc.type) - end - not reloc.label.extern? - end end end + +# class Relocation +# def initialize(pos, label, type, handler) +# @position = pos +# @label = label +# @type = type +# @handler = handler +# end +# attr_reader :position, :label, :type, :handler +# end + +#old assemble function +#def assemble(io) +# @objects.each do |obj| +# obj.assemble io, self +# end +# @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 +# reloc.handler.call(io, reloc.label.address, reloc.type) +# end +# not reloc.label.extern? + #end +#end +#def add_relocation(*args) +# reloc = Asm::Relocation.new(*args) +# #raise "reloc #{reloc.inspect}" +# @relocations << reloc +#end + end diff --git a/lib/asm/object_writer.rb b/lib/asm/object_writer.rb index 7cfd4df9..04793d5b 100644 --- a/lib/asm/object_writer.rb +++ b/lib/asm/object_writer.rb @@ -18,8 +18,8 @@ module Asm @text = Elf::TextSection.new(".text") @object.add_section @text - @reloc_table = Elf::RelocationTableSection.new(".text.rel", @symbol_table, @text) - @object.add_section @reloc_table +# @reloc_table = Elf::RelocationTableSection.new(".text.rel", @symbol_table, @text) +# @object.add_section @reloc_table end def set_text(text) @@ -31,22 +31,19 @@ module Asm @symbol_table.add_func_symbol name, offset, @text, linkage end - def add_reloc_symbol(name) - @symbol_table.add_func_symbol name, 0, nil, Elf::Constants::STB_GLOBAL - end +# def add_reloc_symbol(name) +# @symbol_table.add_func_symbol name, 0, nil, Elf::Constants::STB_GLOBAL +# end - def add_reloc(offset, label, type) - @reloc_table.add_reloc offset, label, type - end +# def add_reloc(offset, label, type) +# @reloc_table.add_reloc offset, label, type +# end def save(filename) - File.open(filename, 'wb') { |fp| - write fp - } + to = File.open(filename, 'wb') + @object.write to + to.close end - def write(io) - @object.write io - end end end \ No newline at end of file diff --git a/lib/asm/relocation.rb b/lib/asm/relocation.rb deleted file mode 100644 index a0383c9c..00000000 --- a/lib/asm/relocation.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Asm - class Relocation - def initialize(pos, label, type, handler) - @position = pos - @label = label - @type = type - @handler = handler - end - attr_reader :position, :label, :type, :handler - end - -end \ No newline at end of file