fix names and requires to get some elf out again (still crashes though)

This commit is contained in:
Torsten Ruger 2014-04-19 23:25:46 +03:00
parent a89bc3d628
commit 091a93f368
10 changed files with 39 additions and 27 deletions

View File

@ -3,7 +3,7 @@ Assembler in Ruby
Supporting arm, but aimed quite specifically at raspberry pi, arm v7, floating point included
Outputs ELF object files, with relocation support.
Outputs Elf object files, with relocation support.
Constant table support exists but isn't very good. Some addressing modes
are not supported or only partially supported.

View File

@ -1,3 +1,5 @@
require_relative "relocation"
module Asm
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
ERRSTR_INVALID_ARG = 'invalid operand argument'

View File

@ -1,20 +1,24 @@
require_relative 'elfobject'
require 'elf/object_file'
require 'elf/symbol_table_section'
require 'elf/text_section'
require 'elf/string_table_section'
require 'elf/relocation_table_section'
module Asm
class ObjectWriter
def initialize(target)
@object = ELF::ObjectFile.new(target)
@object = Elf::ObjectFile.new(target)
sym_strtab = ELF::StringTableSection.new(".strtab")
sym_strtab = Elf::StringTableSection.new(".strtab")
@object.add_section sym_strtab
@symbol_table = ELF::SymbolTableSection.new(".symtab", sym_strtab)
@symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab)
@object.add_section @symbol_table
@text = ELF::TextSection.new(".text")
@text = Elf::TextSection.new(".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
end

View File

@ -1,5 +0,0 @@
class Numeric
def fits_u8?
self >= 0 and self <= 255
end
end

View File

@ -1,4 +1,4 @@
module ELF
module Elf
module Constants
ET_NONE = 0
ET_REL = 1
@ -23,9 +23,9 @@ module ELF
ELFCLASS32 = 1
ELFCLASS64 = 2
ELFDATANONE = 0
ELFDATA2LSB = 1
ELFDATA2MSB = 2
Elf::DATANONE = 0
Elf::DATA2LSB = 1
Elf::DATA2MSB = 2
SHT_NULL = 0
SHT_PROGBITS = 1
@ -53,7 +53,7 @@ module ELF
ARM_INFLOOP = "\x08\xf0\x4f\xe2"
TARGET_ARM = [ELFCLASS32, ELFDATA2LSB, ABI_ARM, EM_ARM]
TARGET_X86 = [ELFCLASS32, ELFDATA2LSB, ABI_SYSTEMV, EM_386]
TARGET_ARM = [ELFCLASS32, Elf::DATA2LSB, ABI_ARM, EM_ARM]
TARGET_X86 = [ELFCLASS32, Elf::DATA2LSB, ABI_SYSTEMV, EM_386]
end
end

View File

@ -1,3 +1,5 @@
require_relative "section"
module Elf
class NullSection < Section
def initialize

View File

@ -1,6 +1,9 @@
require_relative "constants"
require_relative "null_section"
module Elf
class ObjectFile
include ELF
include Constants
def initialize(target)
@target = target

View File

@ -1,3 +1,9 @@
class Numeric
def fits_u8?
self >= 0 and self <= 255
end
end
module StreamReader
def read_binary(size, count, type)
d = __sr_read(size*count)

View File

@ -1,6 +1,7 @@
require "asm/arm/code_generator"
if (__FILE__ == $0)
gen = Asm::ArmCodeGenerator.new
gen = Asm::Arm::CodeGenerator.new
gen.instance_eval {
mov r0, 5
@ -11,8 +12,7 @@ if (__FILE__ == $0)
bx lr
}
require 'objectwriter'
require 'tempfile'
require 'asm/object_writer'
writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM)
writer.set_text gen.assemble

View File

@ -1,15 +1,15 @@
if (__FILE__ == $0)
obj = ELF::ObjectFile.new ELF::TARGET_ARM
obj = Elf::ObjectFile.new Elf::TARGET_ARM
sym_strtab = ELF::StringTableSection.new(".strtab")
sym_strtab = Elf::StringTableSection.new(".strtab")
obj.add_section sym_strtab
symtab = ELF::SymbolTableSection.new(".symtab", sym_strtab)
symtab = Elf::SymbolTableSection.new(".symtab", sym_strtab)
obj.add_section symtab
text_section = ELF::TextSection.new(".text")
text_section = Elf::TextSection.new(".text")
obj.add_section text_section
symtab.add_func_symbol "_start", 0, text_section, ELF::STB_GLOBAL
symtab.add_func_symbol "_start", 0, text_section, Elf::STB_GLOBAL
fp = File.open("test.o", "wb")
obj.write fp