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)
|
def initialize(asm)
|
||||||
@asm = asm
|
@asm = asm
|
||||||
end
|
end
|
||||||
|
def at pos
|
||||||
|
@position = pos
|
||||||
|
end
|
||||||
|
def length
|
||||||
|
0
|
||||||
|
end
|
||||||
def set!
|
def set!
|
||||||
@asm.add_object self
|
@asm.add_object self
|
||||||
end
|
end
|
||||||
|
@ -141,8 +141,8 @@ module Asm
|
|||||||
io << packed[0,3]
|
io << packed[0,3]
|
||||||
elsif (arg.is_a?(Asm::LabelObject) or arg.is_a?(Asm::LabelRefNode))
|
elsif (arg.is_a?(Asm::LabelObject) or arg.is_a?(Asm::LabelRefNode))
|
||||||
#not yet tested/supported
|
#not yet tested/supported
|
||||||
arg = @ast_asm.object_for_label(arg.label, self) if arg.is_a?(Asm::LabelRefNode)
|
# 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)
|
# as.add_relocation(io.tell, arg, Asm::Arm::R_ARM_PC24, RelocHandler)
|
||||||
#write 0 "for now" and let relocation happen
|
#write 0 "for now" and let relocation happen
|
||||||
io << "\x00\x00\x00"
|
io << "\x00\x00\x00"
|
||||||
else
|
else
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
require_relative "relocation"
|
|
||||||
|
|
||||||
module Asm
|
module Asm
|
||||||
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
|
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
|
||||||
@ -7,11 +6,11 @@ module Asm
|
|||||||
class Assembler
|
class Assembler
|
||||||
def initialize
|
def initialize
|
||||||
@objects = []
|
@objects = []
|
||||||
@position = 0
|
@position = -1 # marks not set
|
||||||
@label_objects = []
|
@label_objects = []
|
||||||
@relocations = []
|
@relocations = []
|
||||||
end
|
end
|
||||||
attr_reader :relocations, :objects
|
attr_reader :relocations, :objects , :position
|
||||||
|
|
||||||
def add_object(obj)
|
def add_object(obj)
|
||||||
obj.at(@position)
|
obj.at(@position)
|
||||||
@ -19,28 +18,45 @@ module Asm
|
|||||||
@objects << obj
|
@objects << obj
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_relocation(*args)
|
|
||||||
reloc = Asm::Relocation.new(*args)
|
|
||||||
#raise "reloc #{reloc.inspect}"
|
|
||||||
@relocations << reloc
|
|
||||||
end
|
|
||||||
|
|
||||||
def assemble(io)
|
def assemble(io)
|
||||||
@objects.each do |obj|
|
@objects.each do |obj|
|
||||||
obj.assemble io, self
|
obj.assemble io, self
|
||||||
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
|
||||||
|
|
||||||
@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
|
end
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ module Asm
|
|||||||
@text = Elf::TextSection.new(".text")
|
@text = Elf::TextSection.new(".text")
|
||||||
@object.add_section @text
|
@object.add_section @text
|
||||||
|
|
||||||
@reloc_table = Elf::RelocationTableSection.new(".text.rel", @symbol_table, @text)
|
# @reloc_table = Elf::RelocationTableSection.new(".text.rel", @symbol_table, @text)
|
||||||
@object.add_section @reloc_table
|
# @object.add_section @reloc_table
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_text(text)
|
def set_text(text)
|
||||||
@ -31,22 +31,19 @@ module Asm
|
|||||||
@symbol_table.add_func_symbol name, offset, @text, linkage
|
@symbol_table.add_func_symbol name, offset, @text, linkage
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_reloc_symbol(name)
|
# def add_reloc_symbol(name)
|
||||||
@symbol_table.add_func_symbol name, 0, nil, Elf::Constants::STB_GLOBAL
|
# @symbol_table.add_func_symbol name, 0, nil, Elf::Constants::STB_GLOBAL
|
||||||
end
|
# end
|
||||||
|
|
||||||
def add_reloc(offset, label, type)
|
# def add_reloc(offset, label, type)
|
||||||
@reloc_table.add_reloc offset, label, type
|
# @reloc_table.add_reloc offset, label, type
|
||||||
end
|
# end
|
||||||
|
|
||||||
def save(filename)
|
def save(filename)
|
||||||
File.open(filename, 'wb') { |fp|
|
to = File.open(filename, 'wb')
|
||||||
write fp
|
@object.write to
|
||||||
}
|
to.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(io)
|
|
||||||
@object.write io
|
|
||||||
end
|
|
||||||
end
|
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