most the relocation stuff is going
This commit is contained in:
parent
f724883691
commit
40a6437893
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
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
|
||||
|
||||
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user