Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Restructured some tests involving ihex records and bitwise operations. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | 19c2dad8e4d9486478933e771f7a4ff16f07ad96 |
User & Date: | jos 2015-08-13 13:00:44 |
Context
2015-08-14
| ||
10:12 | Corrected ihex checksum calculation, investigated on bit_op redundant ranges. check-in: d1e029084f user: jos tags: trunk | |
2015-08-13
| ||
13:00 | Restructured some tests involving ihex records and bitwise operations. check-in: 19c2dad8e4 user: jos tags: trunk | |
12:07 | DRYed up most io.write(string.format(...)) things, and some other cleanup. check-in: a639fc9186 user: jos tags: trunk | |
Changes
Changes to ihex.lua.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
-- Input : string or an array of byte-values and an optional length -- If the first parameter is a table, then it gets 2 additional method-fields -- that type 'string' already has by itself. -- -- Outputs a ihex-format record and updates global ihex_address -- function ihex_datarecord(buf,len) if( type(buf) == 'table' ) then buf.byte = table.byte; buf.len = table.len; end local ourLen = len or buf:len(); local ourSum = ihex_chksum(buf,ourLen); io.write( string.format(':%02X%04X00',ourLen,ihex_address) ); for i=1,ourLen do io.write( string.format('%02X',buf:byte(i)) ); end |
| |
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
-- Input : string or an array of byte-values and an optional length
-- If the first parameter is a table, then it gets 2 additional method-fields
-- that type 'string' already has by itself.
--
-- Outputs a ihex-format record and updates global ihex_address
--
function ihex_datarecord(buf,len)
if( type(buf) == 'table' ) then -- Add 'string' methods that 'table' misses.
buf.byte = table.byte; buf.len = table.len;
end
local ourLen = len or buf:len();
local ourSum = ihex_chksum(buf,ourLen);
io.write( string.format(':%02X%04X00',ourLen,ihex_address) );
for i=1,ourLen do io.write( string.format('%02X',buf:byte(i)) ); end
|
Deleted intelhex.lua.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
#!/usr/bin/env lua local to_byte = function (x) return string.char( bit32.band(x,0xff) ); end --returns a 1-byte string local as_byte = string.byte; -- [first] begin dump at 16 byte-aligned offset containing 'first' byte -- [last] end dump at 16 byte-aligned offset containing 'last' byte function hex_dump(buf,first,last) local function align(n) return math.ceil(n/16) * 16 end for i=(align((first or 1)-16)+1),align(math.min(last or #buf,#buf)) do if (i-1) % 16 == 0 then io.write(string.format('%08X ', i-1)) end io.write( i > #buf and ' ' or string.format('%02X ', buf:byte(i)) ) if i % 8 == 0 then io.write(' ') end if i % 16 == 0 then io.write( buf:sub(i-16+1, i):gsub('%c','.'), '\n' ) end end end local ihex_address = 0x0000; function ihex_reset() ihex_address = 0x0000; end function ihex_chksum( buf,startVal ) local ourSum = startVal or 0; for i=1,#buf,1 do ourSum = ourSum + buf:byte(i); end--for ourSum = ourSum + bit32.band(ihex_address,0xff); ourSum = ourSum + bit32.band( bit32.rshift(ihex_address,8),0xff); ourSum = bit32.bnot(ourSum) + 1; ourSum = bit32.band(ourSum,0xff); return( ourSum ); end function ihex_datarecord(buf,len) local ourLen = len or 16; local ourSum = ihex_chksum(buf,ourLen); io.write( string.format(':%02X%04X00',ourLen,ihex_address) ); for i=1,ourLen do io.write( string.format('%02X',buf:byte(i)) ); end ihex_address = ihex_address + ourLen; io.write( string.format('%02X', ourSum ) ); io.write( '\n' ); end function ihex_endrecord() io.write(':00000001FF\n'); end function ByteBuf( array ) local ourBuf = {}; for i,v in ipairs(array) do ourBuf[i] = to_byte(v); end return( table.concat(ourBuf) ); end --[[ disassembly Test 1 -- Spew out a series of Intel Hex records where every value from 0x00 to 0xff -- occurs 6 times in (sub)sequence. -- This way, each byte-value can be covered by the dissassembler of the -- MegaProcessor simulator. -- Instructions of lenght 1 will be disassembled 6 times, length 2 shows up 3 times, and -- length 3 shows up 2 times. -- --]] --[[ -- insert a space between the - and the [ to activate the enclosed section ihex_reset(); for i=0,255,1 do local data = {}; for j=1,6,1 do data[j] = i end local buf = ByteBuf(data); ihex_datarecord( buf,#buf ); end ihex_endrecord(); --]] --[[ disassembly Test 2: -- Spew out a series of IntelHex records for each of the instructions 0xd8..0xdf -- and every possible value of their postbytes. -- --]] -- [[ -- insert a space between the - and the [ to activate the enclosed section ihex_reset(); for i=0xd8,0xdf,1 do for j=0,15,1 do local data = {}; for k=0,15,1 do table.insert(data,i); table.insert(data,j*16+k) end local buf = ByteBuf(data); ihex_datarecord(buf,#buf); end end--for ihex_endrecord(); --]] |
< < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added test/test1.lua.
> > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#!/usr/bin/env lua package.path = '../?.lua;'..package.path; require('ihex'); --[[ disassembly Test 1 -- Spew out a series of Intel Hex records where every value from 0x00 to 0xff -- occurs 6 times in (sub)sequence. -- This way, each byte-value can be covered by the dissassembler of the -- MegaProcessor simulator. -- Instructions of lenght 1 will be disassembled 6 times, length 2 shows up 3 times, and -- length 3 shows up 2 times. -- --]] ihex_reset(); for i=0,255,1 do local data = {}; for j=1,6,1 do data[j] = i end ihex_datarecord( data,#data); end ihex_endrecord(); |
Added test/test2.lua.
> > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/usr/bin/env lua package.path = '../?.lua;'..package.path; require('ihex'); --[[ disassembly Test 2: -- Spew out a series of IntelHex records for each of the instructions 0xd8..0xdf -- and every possible value (0x00..0xff) of their postbytes. -- --]] ihex_reset(); for i=0xd8,0xdf,1 do for j=0,15,1 do local data = {}; for k=0,15,1 do table.insert(data,i); table.insert(data,j*16+k) end ihex_datarecord(data,#data); end end--for ihex_endrecord(); |