figuring relocations
This commit is contained in:
parent
4e075e3a81
commit
6226521abb
@ -25,6 +25,9 @@ module Asm
|
|||||||
case type
|
case type
|
||||||
when R_ARM_PC24
|
when R_ARM_PC24
|
||||||
diff = addr - io.tell - 8
|
diff = addr - io.tell - 8
|
||||||
|
if (diff.abs > (1 << 25))
|
||||||
|
raise Asm::AssemblyError.new('offset too large for R_ARM_PC24 relocation', nil)
|
||||||
|
end
|
||||||
packed = [diff >> 2].pack('l')
|
packed = [diff >> 2].pack('l')
|
||||||
io << packed[0,3]
|
io << packed[0,3]
|
||||||
when R_ARM_ABS32
|
when R_ARM_ABS32
|
||||||
@ -33,8 +36,7 @@ module Asm
|
|||||||
when R_ARM_PC12
|
when R_ARM_PC12
|
||||||
diff = addr - io.tell - 8
|
diff = addr - io.tell - 8
|
||||||
if (diff.abs > 2047)
|
if (diff.abs > 2047)
|
||||||
raise Asm::AssemblyError.new('offset too large for R_ARM_PC12 relocation',
|
raise Asm::AssemblyError.new('offset too large for R_ARM_PC12 relocation', nil)
|
||||||
nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
val = diff.abs
|
val = diff.abs
|
||||||
|
@ -4,7 +4,7 @@ require_relative 'generator_label'
|
|||||||
require 'asm/nodes'
|
require 'asm/nodes'
|
||||||
require 'stream_reader'
|
require 'stream_reader'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
require "asm/data_object"
|
||||||
|
|
||||||
class Asm::Arm::CodeGenerator
|
class Asm::Arm::CodeGenerator
|
||||||
def initialize
|
def initialize
|
||||||
@ -82,7 +82,7 @@ class Asm::Arm::CodeGenerator
|
|||||||
if (lbl = @externs.find { |extern| extern.name == sym })
|
if (lbl = @externs.find { |extern| extern.name == sym })
|
||||||
lbl
|
lbl
|
||||||
else
|
else
|
||||||
@externs << lbl = GeneratorExternLabel.new(sym)
|
@externs << lbl = Asm::Arm::GeneratorExternLabel.new(sym)
|
||||||
@asm.add_object lbl
|
@asm.add_object lbl
|
||||||
lbl
|
lbl
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,6 @@ module Asm
|
|||||||
def initialize
|
def initialize
|
||||||
@objects = []
|
@objects = []
|
||||||
@label_objects = []
|
@label_objects = []
|
||||||
@label_callbacks = []
|
|
||||||
@relocations = []
|
@relocations = []
|
||||||
end
|
end
|
||||||
attr_reader :relocations, :objects
|
attr_reader :relocations, :objects
|
||||||
@ -21,10 +20,6 @@ module Asm
|
|||||||
@relocations << Asm::Relocation.new(*args)
|
@relocations << Asm::Relocation.new(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_label_callback(label, io_pos, &block)
|
|
||||||
@label_callbacks << [label, io_pos, block]
|
|
||||||
end
|
|
||||||
|
|
||||||
def assemble(io)
|
def assemble(io)
|
||||||
@objects.each do |obj|
|
@objects.each do |obj|
|
||||||
obj.assemble io, self
|
obj.assemble io, self
|
||||||
|
Loading…
Reference in New Issue
Block a user