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
# TODO add check that the value fits into 24 bits
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
def handle_swi(io)
@ -75,7 +75,7 @@ module Arm
raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric))
packed = [arg].pack('L')[0,3]
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
def to_s

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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