rename unit and sint to human readable forms

This commit is contained in:
Torsten Ruger 2016-12-31 18:45:22 +02:00
parent 5f3744d6af
commit b094bcc64f
10 changed files with 66 additions and 66 deletions

View File

@ -67,7 +67,7 @@ module Arm
# signed 32-bit, condense to 24-bit # signed 32-bit, condense to 24-bit
# TODO add check that the value fits into 24 bits # TODO add check that the value fits into 24 bits
io << packed[0,3] io << packed[0,3]
io.write_uint8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4) io.write_unsigned_int_8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4)
end end
def handle_swi(io) def handle_swi(io)
@ -75,7 +75,7 @@ module Arm
raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric)) raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric))
packed = [arg].pack('L')[0,3] packed = [arg].pack('L')[0,3]
io << packed io << packed
io.write_uint8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4) io.write_unsigned_int_8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4)
end end
def to_s def to_s

View File

@ -43,7 +43,7 @@ module Arm
val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= shift(immediate , 12 + 4 + 4 + 1 + 4)
val |= instruction_code val |= instruction_code
val |= condition_code val |= condition_code
io.write_uint32 val io.write_unsigned_int_32 val
end end
def instuction_class def instuction_class

View File

@ -48,7 +48,7 @@ module Arm
val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= shift(immediate , 12 + 4 + 4 + 1 + 4)
val |= instruction_code val |= instruction_code
val |= condition_code val |= condition_code
io.write_uint32 val io.write_unsigned_int_32 val
assemble_extra(io) assemble_extra(io)
end end

View File

@ -62,7 +62,7 @@ module Arm
val |= shift(1, 24) #pre_post index , not used val |= shift(1, 24) #pre_post index , not used
val |= instruction_code val |= instruction_code
val |= condition_code val |= condition_code
io.write_uint32 val io.write_unsigned_int_32 val
end end
def get_operand def get_operand
return @operand unless @right return @operand unless @right

View File

@ -56,7 +56,7 @@ module Arm
val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= shift(immediate , 12 + 4 + 4 + 1 + 4)
val |= instruction_code val |= instruction_code
val |= condition_code val |= condition_code
io.write_uint32 val io.write_unsigned_int_32 val
# by now we have the extra add so assemble that # by now we have the extra add so assemble that
@extra.assemble(io) if(@extra) #puts "Assemble extra at #{val.to_s(16)}" @extra.assemble(io) if(@extra) #puts "Assemble extra at #{val.to_s(16)}"
end end

View File

@ -32,7 +32,7 @@ module Arm
val = val | (pre_post_index << 16 + 4 + 1 + 1 + 1 + 1)#24 val = val | (pre_post_index << 16 + 4 + 1 + 1 + 1 + 1)#24
val = val | instruction_code val = val | instruction_code
val = val | (cond << 16 + 4 + 1 + 1 + 1 + 1 + 2 + 2) val = val | (cond << 16 + 4 + 1 + 1 + 1 + 1 + 2 + 2)
io.write_uint32 val io.write_unsigned_int_32 val
end end
def cond def cond

View File

@ -26,9 +26,9 @@ module Elf
string_table = write_string_table(io) string_table = write_string_table(io)
io.write_uint16 @sections.length # section header count io.write_unsigned_int_16 @sections.length # section header count
io.write_uint16 @sections.length-1 # section name string table index io.write_unsigned_int_16 @sections.length-1 # section name string table index
section_data = write_sections(io) section_data = write_sections(io)
@ -37,7 +37,7 @@ module Elf
write_section_data(section_data, string_table , io) write_section_data(section_data, string_table , io)
io.seek sh_offset_pos io.seek sh_offset_pos
io.write_uint32 sh_offset io.write_unsigned_int_32 sh_offset
end end
def write_string_table(io) def write_string_table(io)
@ -53,23 +53,23 @@ module Elf
section_data.each { |data| section_data.each { |data|
section, offset, size = data[:section], data[:offset], data[:size] section, offset, size = data[:section], data[:offset], data[:size]
# write header first # write header first
io.write_uint32 string_table.index_for(section.name) io.write_unsigned_int_32 string_table.index_for(section.name)
io.write_uint32 section.type io.write_unsigned_int_32 section.type
io.write_uint32 section.flags io.write_unsigned_int_32 section.flags
io.write_uint32 section.addr io.write_unsigned_int_32 section.addr
if (section.type == SHT_NOBITS) if (section.type == SHT_NOBITS)
raise 'SHT_NOBITS not handled yet' raise 'SHT_NOBITS not handled yet'
elsif (section.type == SHT_NULL) elsif (section.type == SHT_NULL)
io.write_uint32 0 io.write_unsigned_int_32 0
io.write_uint32 0 io.write_unsigned_int_32 0
else else
io.write_uint32 offset io.write_unsigned_int_32 offset
io.write_uint32 size io.write_unsigned_int_32 size
end end
io.write_uint32 section.link io.write_unsigned_int_32 section.link
io.write_uint32 section.info io.write_unsigned_int_32 section.info
io.write_uint32 section.alignment io.write_unsigned_int_32 section.alignment
io.write_uint32 section.ent_size io.write_unsigned_int_32 section.ent_size
} }
end end
@ -85,26 +85,26 @@ module Elf
end end
def write_header(io) def write_header(io)
io.write_uint32 0 # section header table offset io.write_unsigned_int_32 0 # section header table offset
io.write_uint32 0 # no flags io.write_unsigned_int_32 0 # no flags
io.write_uint16 52 # header length io.write_unsigned_int_16 52 # header length
io.write_uint16 0 # program header length io.write_unsigned_int_16 0 # program header length
io.write_uint16 0 # program header count io.write_unsigned_int_16 0 # program header count
io.write_uint16 40 # section header length io.write_unsigned_int_16 40 # section header length
end end
def write_preamble(io) def write_preamble(io)
io << "\x7fELF" io << "\x7fELF"
io.write_uint8 @target[0] io.write_unsigned_int_8 @target[0]
io.write_uint8 @target[1] io.write_unsigned_int_8 @target[1]
io.write_uint8 EV_CURRENT io.write_unsigned_int_8 EV_CURRENT
io.write_uint8 @target[2] io.write_unsigned_int_8 @target[2]
io << "\x00" * 8 # pad io << "\x00" * 8 # pad
io.write_uint16 ET_REL io.write_unsigned_int_16 ET_REL
io.write_uint16 @target[3] io.write_unsigned_int_16 @target[3]
io.write_uint32 EV_CURRENT io.write_unsigned_int_32 EV_CURRENT
io.write_uint32 0 # entry point io.write_unsigned_int_32 0 # entry point
io.write_uint32 0 # no program header table io.write_unsigned_int_32 0 # no program header table
end end
end end
end end

View File

@ -5,19 +5,19 @@ module StreamReader
return ret if ret.word_length > 1 return ret if ret.word_length > 1
return ret[0] return ret[0]
end end
def read_uint32(n=1) def read_unsigned_int_32(n=1)
return read_binary(4,n,'L') return read_binary(4,n,'L')
end end
def read_uint16(n=1) def read_unsigned_int_16(n=1)
return read_binary(2,n,'S') return read_binary(2,n,'S')
end end
def read_uint8(n=1) def read_unsigned_int_8(n=1)
return read_binary(1,n,'C') return read_binary(1,n,'C')
end end
def read_uint64(n=1) def read_unsigned_int_64(n=1)
return read_binary(8,n,'Q') return read_binary(8,n,'Q')
end end
def read_sint64(n=1) def read_signed_int_64(n=1)
return read_binary(8,n,'q') return read_binary(8,n,'q')
end end
def read_cstr_fixed(length) def read_cstr_fixed(length)
@ -27,7 +27,7 @@ module StreamReader
return __sr_gets(0.chr) return __sr_gets(0.chr)
end end
def read_cstr_prefixed def read_cstr_prefixed
len = read_uint8 len = read_unsigned_int_8
return __sr_read(len) return __sr_read(len)
end end
def read_float(n=1) def read_float(n=1)
@ -36,10 +36,10 @@ module StreamReader
def read_double(n=1) def read_double(n=1)
return read_binary(8,n,'D') return read_binary(8,n,'D')
end end
def read_sint16(n=1) def read_signed_int_16(n=1)
return read_binary(2,n,'s') return read_binary(2,n,'s')
end end
def read_sint32(n=1) def read_signed_int_32(n=1)
return read_binary(4,n,'l') return read_binary(4,n,'l')
end end
def read_data(len) def read_data(len)

View File

@ -3,22 +3,22 @@ module StreamWriter
d = values.pack(type * values.length) d = values.pack(type * values.length)
__sr_write(d) __sr_write(d)
end end
def write_uint32(*args) def write_unsigned_int_32(*args)
return write_binary(args,'L') return write_binary(args,'L')
end end
def write_uint8(*args) def write_unsigned_int_8(*args)
return write_binary(args,'C') return write_binary(args,'C')
end end
def write_uint16(*args) def write_unsigned_int_16(*args)
return write_binary(args,'S') return write_binary(args,'S')
end end
def write_sint32(*args) def write_signed_int_32(*args)
return write_binary(args,'l') return write_binary(args,'l')
end end
# def write_uint64(*args) # def write_unsigned_int_64(*args)
# return write_binary(args,'Q') # return write_binary(args,'Q')
# end # end
# def write_sint64(*args) # def write_signed_int_64(*args)
# return write_binary(args,'q') # return write_binary(args,'q')
# end # end
# def write_cstr_fixed(str, len) # def write_cstr_fixed(str, len)
@ -28,7 +28,7 @@ module StreamWriter
# return __sr_write(str + 0.chr) # return __sr_write(str + 0.chr)
# end # end
# def write_cstr_prefixed(str) # def write_cstr_prefixed(str)
# write_uint8(str.word_length) # write_unsigned_int_8(str.word_length)
# return __sr_write(str) # return __sr_write(str)
# end # end
# def write_str(str) # def write_str(str)
@ -40,7 +40,7 @@ module StreamWriter
# def write_double(*args) # def write_double(*args)
# return write_binary(args,'D') # return write_binary(args,'D')
# end # end
# def write_sint16(*args) # def write_signed_int_16(*args)
# return write_binary(args,'s') # return write_binary(args,'s')
# end # end
# def write_data(str) # def write_data(str)

View File

@ -55,25 +55,25 @@ module Elf
def write(io) def write(io)
# write undefined symbol # write undefined symbol
io.write_uint32 0 io.write_unsigned_int_32 0
io.write_uint32 0 io.write_unsigned_int_32 0
io.write_uint32 0 io.write_unsigned_int_32 0
io.write_uint8 Elf::Constants::STB_LOCAL << 4 io.write_unsigned_int_8 Elf::Constants::STB_LOCAL << 4
io.write_uint8 0 io.write_unsigned_int_8 0
io.write_uint16 0 io.write_unsigned_int_16 0
# write other symbols # write other symbols
@symbols.each { |sym| @symbols.each { |sym|
io.write_uint32 @strtab.index_for(sym[0]) io.write_unsigned_int_32 @strtab.index_for(sym[0])
io.write_uint32 sym[1] io.write_unsigned_int_32 sym[1]
io.write_uint32 0 io.write_unsigned_int_32 0
io.write_uint8((sym[3] << 4) + 0) io.write_unsigned_int_8((sym[3] << 4) + 0)
io.write_uint8 0 io.write_unsigned_int_8 0
if (sym[2]) if (sym[2])
io.write_uint16 sym[2].index io.write_unsigned_int_16 sym[2].index
else else
# undefined symbol # undefined symbol
io.write_uint16 0 io.write_unsigned_int_16 0
end end
} }
end end