22 January 2006, 20:31 | #1 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
Hunks
What are they?
What are the different types of hunk? (I've seen Code, Data and BSS) what do they do? are there any more (besides the 3 I listed)? |
23 January 2006, 00:13 | #2 |
Workbitch 1.3
Join Date: Oct 2001
Location: Melbourne, Australia
Age: 47
Posts: 2,084
|
What? Like Tom Cruise, George Clooney and Brad Pitt???
/me hides |
23 January 2006, 01:15 | #3 |
Tik Gora :D
Join Date: Oct 2001
Location: Round yo momma's
Posts: 1,273
|
Hunks are like definitions in a file as to what the next load of data is and where it should load into memory.
If i recall rightly CODE means the next `n` of data is executable code, DATA is for blocks of data (like graphics, music, etc) and BSS is also for blocks of data but only the pointer for the size of the data is stored. (BSS says a `n` sized block of freshly zero'ed memory is made available to the loaded program) Them three can be either declared for use in any, chip or fast memory. And theres lots more like hunk_debug, hunk_name, hunk_symbol, etc.. Last edited by mr_0rga5m; 23 January 2006 at 01:32. |
23 January 2006, 02:15 | #4 |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,187
|
A good book to get for detailed info on hunks is the AmigaDos manual: http://www.devili.iki.fi/library/publication/1.en.html
It explains all the hunk types (there are around 20-30 from memory) as lots of the hunks have 32 bit versions as well as 16-bit and even some 8-bits. They're kind of like IFF files really, a header saying it's a valid file, then a hunk ID and usually the length followed by lots of data. A standard Amiga executable for example starts with $000003f3, then the number of hunks in the file. Then the first hunk number (I've only ever seen this set to 0), then the last hunk number (starting from 0, so if there are 2 hunks it'd be 1), then a table of the lengths of the hunks followed by the hunks themselves. |
23 January 2006, 03:59 | #5 |
Registered User
Join Date: Jan 2004
Location: Toronto / Canada
Posts: 65
|
After the AmigaDOS manual, you might enjoy reading Linkers & Loaders by John Levine for a general account of object file formats, relocation, etc. If there is an equivalent of the GNU "objdump" util for the Amiga, then I would recommend experimenting with that, but I don't know whether such a thing exists.
|
23 January 2006, 10:19 | #6 |
move.w #$4489,$dff07e
Join Date: Sep 2005
Location: Norfolk, UK
Age: 43
Posts: 2,351
|
The Amiga Guru Book has some nice hunk-info as well
|
23 January 2006, 12:58 | #7 | |
Tik Gora :D
Join Date: Oct 2001
Location: Round yo momma's
Posts: 1,273
|
Quote:
What does this GNU "objdump" show then ? .. gissa link mate |
|
23 January 2006, 20:34 | #8 |
Registered User
Join Date: Jan 2004
Location: Toronto / Canada
Posts: 65
|
objdump is part of the GNU binutils (link not working at time of writing though):
http://www.gnu.org/software/binutils/ You'll find it on most Linux systems with any development tools. You can also get it for Windows as part of MinGW or Cygwin. Once you have it, you can look at the "sections" (presumably the same as "hunks") in an executable or object file library. $ objdump --all-headers /bin/bash /bin/bash: file format elf32-i386 /bin/bash architecture: i386, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x08058d40 ... Sections: Idx Name Size VMA LMA File off Algn 0 .interp 00000013 080480f4 080480f4 000000f4 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .note.ABI-tag 00000020 08048108 08048108 00000108 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 2 .hash 0000290c 08048128 08048128 00000128 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .dynsym 000063a0 0804aa34 0804aa34 00002a34 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 4 .dynstr 000064fd 08050dd4 08050dd4 00008dd4 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .gnu.version 00000c74 080572d2 080572d2 0000f2d2 2**1 CONTENTS, ALLOC, LOAD, READONLY, DATA 6 .gnu.version_r 00000080 08057f48 08057f48 0000ff48 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 7 .rel.got 00000008 08057fc8 08057fc8 0000ffc8 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 8 .rel.bss 00000050 08057fd0 08057fd0 0000ffd0 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 9 .rel.plt 00000450 08058020 08058020 00010020 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 10 .init 00000018 08058470 08058470 00010470 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 11 .plt 000008b0 08058488 08058488 00010488 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 12 .text 00051fdc 08058d40 08058d40 00010d40 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE 13 .fini 0000001e 080aad1c 080aad1c 00062d1c 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 14 .rodata 0001493f 080aad40 080aad40 00062d40 2**5 CONTENTS, ALLOC, LOAD, READONLY, DATA 15 .data 00005458 080c0680 080c0680 00077680 2**5 CONTENTS, ALLOC, LOAD, DATA 16 .eh_frame 00000004 080c5ad8 080c5ad8 0007cad8 2**2 CONTENTS, ALLOC, LOAD, DATA 17 .ctors 00000008 080c5adc 080c5adc 0007cadc 2**2 CONTENTS, ALLOC, LOAD, DATA 18 .dtors 00000008 080c5ae4 080c5ae4 0007cae4 2**2 CONTENTS, ALLOC, LOAD, DATA 19 .got 00000238 080c5aec 080c5aec 0007caec 2**2 CONTENTS, ALLOC, LOAD, DATA 20 .dynamic 000000b0 080c5d24 080c5d24 0007cd24 2**2 CONTENTS, ALLOC, LOAD, DATA 21 .sbss 00000000 080c5dd4 080c5dd4 0007cde0 2**0 CONTENTS 22 .bss 00004290 080c5de0 080c5de0 0007cde0 2**5 ALLOC And you can disassemble code in code sections too. $ objdump --disassemble bash bash: file format elf32-i386 Disassembly of section .init: 08058470 <.init>: 8058470: 55 push %ebp 8058471: 89 e5 mov %esp,%ebp 8058473: 83 ec 08 sub $0x8,%esp 8058476: e8 e9 08 00 00 call 0x8058d64 805847b: 90 nop 805847c: e8 7f 09 00 00 call 0x8058e00 8058481: e8 5a 28 05 00 call 0x80aace0 8058486: c9 leave 8058487: c3 ret ... Disassembly of section .text: 08058d40 <.text>: 8058d40: 31 ed xor %ebp,%ebp 8058d42: 5e pop %esi 8058d43: 89 e1 mov %esp,%ecx 8058d45: 83 e4 f0 and $0xfffffff0,%esp 8058d48: 50 push %eax 8058d49: 54 push %esp 8058d4a: 52 push %edx 8058d4b: 68 1c ad 0a 08 push $0x80aad1c 8058d50: 68 70 84 05 08 push $0x8058470 8058d55: 51 push %ecx 8058d56: 56 push %esi 8058d57: 68 40 8e 05 08 push $0x8058e40 8058d5c: e8 37 fc ff ff call 0x8058998 8058d61: f4 hlt 8058d62: 90 nop ... |
23 January 2006, 21:33 | #9 |
Tik Gora :D
Join Date: Oct 2001
Location: Round yo momma's
Posts: 1,273
|
Hrm .. Well being an Anti-linux peep an all i dont think i'll bother :P (tnx anyway mate)
Lets examine them Amiga hunks on a real (or emulate'd) Amiga eh: Quite simply paste the code below into a txt file, rename to `dalf.rexx` and then to use (@ a dos prompt) type `rx dalf.rexx <.exe filename>` Code:
/************************************************\ * dalf.rexx - Dumps Amiga Load Files. * * C 1990 Mikael Karlsson (m...@slaka.sirius.se) * \************************************************/ parse arg file /* File to examine */ signal on break_c /* We want a nice clean break */ pl. = "s" /* This is how to handle plurals the ince way */ pl.1 = "" temp = '00'x flagtext.temp = "" temp = '40'x /* Bit 30 means 'Load to CHIPMEM' */ flagtext.temp = " (CHIP)" bits. = '00'x type. = "Unknown" /* These are the hunk types we know about (so far) */ Hunk_unit = '03E7'x; type.Hunk_unit = "Hunk_unit " Hunk_name = '03E8'x; type.Hunk_name = "Hunk_name " Hunk_code = '03E9'x; type.Hunk_code = "Hunk_code " Hunk_data = '03EA'x; type.Hunk_data = "Hunk_data " Hunk_bss = '03EB'x; type.Hunk_bss = "Hunk_bss " Hunk_reloc32 = '03EC'x; type.Hunk_reloc32 = "Hunk_reloc32 " Hunk_reloc16 = '03ED'x; type.Hunk_reloc16 = "Hunk_reloc16 " Hunk_reloc8 = '03EE'x; type.Hunk_reloc8 = "Hunk_reloc8 " Hunk_ext = '03EF'x; type.Hunk_ext = "Hunk_ext " Hunk_symbol = '03F0'x; type.Hunk_symbol = "Hunk_symbol " Hunk_debug = '03F1'x; type.Hunk_debug = "Hunk_debug " Hunk_end = '03F2'x; type.Hunk_end = "Hunk_end " Hunk_header = '03F3'x; type.Hunk_header = "Hunk_header " Hunk_overlay = '03F5'x; type.Hunk_overlay = "Hunk_overlay " Hunk_break = '03F6'x; type.Hunk_break = "Hunk_break " Hunk_drel32 = '03F7'x; type.Hunk_drel32 = "Hunk_drel32 " Hunk_drel16 = '03F8'x; type.Hunk_drel16 = "Hunk_drel16 " Hunk_drel8 = '03F9'x; type.Hunk_drel8 = "Hunk_drel8 " Hunk_libhunk = '03FA'x; type.Hunk_libhunk = "Hunk_libhunk " Hunk_libindx = '03FB'x; type.Hunk_libindx = "Hunk_libindx " /* These are subtypes in Hunk_ext */ Hunk_def = '01'x; type.Hunk_def = "Hunk_def " Hunk_abs = '02'x; type.Hunk_abs = "Hunk_abs " Hunk_res = '03'x; type.Hunk_res = "Hunk_res " Hunk_ext32 = '81'x; type.Hunk_ext32 = "Hunk_ext32 " Hunk_ext16 = '83'x; type.Hunk_ext16 = "Hunk_ext16 " Hunk_ext8 = '84'x; type.Hunk_ext8 = "Hunk_ext8 " Hunk_dext32 = '85'x; type.Hunk_dext32 = "Hunk_dext32 " Hunk_dext16 = '86'x; type.Hunk_dext16 = "Hunk_dext16 " Hunk_dext8 = '87'x; type.Hunk_dext8 = "Hunk_dext8 " if ~open(lf, file, 'R') then do /* Open load file */ say "Can't open" file exit 10 end index = 0 size. = 0 loop: type = readch(lf, 4) /* Read hunk type */ if type == "" then do /* End of file */ signal done end bits.index = bitor(bits.index, left(type, 1)) /* Check flag bits */ type = right(type, 2) /* Remove flag bits */ if type.type = "Unknown" then do say "Unknown hunk type ("c2x(type)")" exit 10 end id = type.type "("c2x(type)")" signal value trim(type.type) /* Jump to hunk display routine */ |
23 January 2006, 21:36 | #10 |
Tik Gora :D
Join Date: Oct 2001
Location: Round yo momma's
Posts: 1,273
|
Code:
Hunk_header: say id dummy = c2d(readch(lf, 4)) /* What's this? */ count = c2d(readch(lf, 4)) low = c2d(readch(lf, 4)) high = c2d(readch(lf, 4)) say " "count "hunk"pl.count "("low "to" high")" do i=low to high size = readch(lf, 4) bits.i = left(size, 1) size.i = c2d(right(size, 3))*4 bits = bits.i say " Size hunk" i":" size.i "bytes" flagtext.bits end index = low signal loop Hunk_end: say " "id signal loop Hunk_code: size = readch(lf, 4) bits = bitor(bits.index, left(size, 1)) size = c2d(right(size, 3))*4 temp = right(index, 2) temp = temp":" id temp = temp "("size "bytes)"flagtext.bits say temp do while size>32768 data = readch(lf, 32768) size = size-32768 end data = readch(lf, size) index = index+1 signal loop Hunk_reloc32: Hunk_reloc16: Hunk_reloc8: say " "id count = c2d(readch(lf, 4)) do while count~=0 ref = c2d(readch(lf, 4)) say " "count "item"pl.count "for hunk" ref refs = readch(lf, count*4) count = c2d(readch(lf, 4)) end signal loop Hunk_ext: say " "id sym_type = readch(lf, 1) sym_length = c2d(readch(lf, 3))*4 do until sym_type == "00"x symbol = strip(readch(lf, sym_length), 'T', '00'x) select when sym_type == hunk_def |, sym_type == hunk_abs |, sym_type == hunk_res then do offset = strip(c2x(readch(lf, 4)), 'T', '00'x) temp = " " type.sym_type temp = temp left(symbol, 32)":" "0x"offset say temp end when sym_type == hunk_ext32 |, sym_type == hunk_ext16 |, sym_type == hunk_ext8 |, sym_type == hunk_dext32 |, sym_type == hunk_dext16 |, sym_type == hunk_dext8 then do count = c2d(readch(lf, 4)) refs = readch(lf, count*4) temp = " " type.sym_type temp = temp left(symbol, 32)":" temp = temp right(count, 2) "item"pl.count say temp end otherwise do say " Unknown definition" end end sym_type = readch(lf, 1) sym_length = c2d(readch(lf, 3))*4 end signal loop Hunk_drel32: Hunk_drel16: Hunk_drel8: say " "id count = c2d(readch(lf, 4)) do while count~=0 ref = c2d(readch(lf, 4)) say " "count "item"pl.count "for hunk" ref refs = readch(lf, count*4) count = c2d(readch(lf, 4)) end signal loop Hunk_data: size = readch(lf, 4) bits = bitor(bits.index, left(size, 1)) size = c2d(right(size, 3))*4 temp = right(index, 2) temp = temp":" id temp = temp "("size "bytes" if size.index-size>0 then do temp = temp"," size.index-size "BSS" end temp = temp")"flagtext.bits say temp data = readch(lf, size) index = index+1 signal loop Hunk_bss: size = readch(lf, 4) bits = bitor(bits.index, left(size, 1)) size = c2d(right(size, 3))*4 temp = right(index, 2) temp = temp":" id temp = temp "("size "bytes)"flagtext.bits say temp index = index+1 signal loop Hunk_unit: Hunk_name: say right(index, 2)":"id size = c2d(readch(lf, 4))*4 data = readch(lf, size) say " " type.type":" data index = index+1 signal loop Hunk_symbol: say right(index, 2)":"id size = c2d(readch(lf, 4))*4 do while size~=0 data = strip(readch(lf, size), 'T', '00'x) say " " left(data, 32)":" c2x(readch(lf, 4)) size = c2d(readch(lf, 4))*4 end signal loop Hunk_libhunk: size = readch(lf, 4) bits = bitor(bits.index, left(size, 1)) size = c2d(right(size, 3))*4 say " "id "("size "bytes)"flagtext.bits signal loop Hunk_libindx: size = c2d(readch(lf, 4))*4 say " "id "("size "bytes)" count = c2d(readch(lf, 2)) say " " count "bytes in string block" string = readch(lf, count) do forever nameoffset = c2d(readch(lf, 2)) if nameoffset=0 then leave parse value substr(string, nameoffset+1) with name "00"x . say " PUNIT '"name"'" unitoffset = c2d(readch(lf, 2)) say " offset" unitoffset "longword"pl.unitoffset hunkcount = c2d(readch(lf, 2)) say " " hunkcount "hunk"pl.hunkcount do for hunkcount nameoffset = c2d(readch(lf, 2)) parse value substr(string, nameoffset+1) with name "00"x . hunksize = c2d(readch(lf, 2)) hunktype = readch(lf, 2) say " " type.hunktype "'"name"' of" hunksize "longword"pl.hunksize refcount = c2d(readch(lf, 2)) say " " refcount "ref"pl.refcount":" do for refcount nameoffset = c2d(readch(lf, 2)) if substr(string, nameoffset+1, 1)="00"x then do nameoffset = nameoffset+1 temp = "16" end else do temp = "32" end parse value substr(string, nameoffset+1) with name "00"x . say " " temp"-bit ref '"name"'" end defcount = c2d(readch(lf, 2)) say " " defcount "def"pl.defcount":" do for defcount nameoffset = c2d(readch(lf, 2)) parse value substr(string, nameoffset+1) with name "00"x . defoffset = readch(lf, 2) defdata = readch(lf, 2) deftype = c2d(right(defdata, 2)) defdata = left(defdata, 2) select when deftype=1 then do say " Define def '"name"' at" c2d(defoffset) end when deftype=2 then do defoffset = defdata || defoffset say " Define abs '"name"' at" c2d(defoffset) end when deftype=3 then do say " Define res '"name"' at" c2d(defoffset) end when deftype=66 then do defoffset = "FF"x || defdata || defoffset say " Define abs '"name"' at" c2d(defoffset) end otherwise do say "Error in object file" exit 10 end end end end end signal loop Hunk_debug: size = c2d(readch(lf, 4))*4 say " "id "("size "bytes)" say " Offset:" c2d(readch(lf, 4)) say " Type: " readch(lf, 4) data = readch(lf, size-8) signal loop Hunk_break: size = c2d(readch(lf, 4))*4 say " "id "("size "bytes)" data = readch(lf, size) index = index+1 signal loop Hunk_overlay: size = c2d(readch(lf, 4))*4 say " "id "("size "bytes) - Not supported" data = readch(lf, size) index = index+1 signal loop break_c: done: exit 0 |
10 February 2006, 22:56 | #11 |
Registered User
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
|
If you want to know about hunks, I coded an Arexx "compiler" once that takes Arexx script and packs it up in it's own executable. This was really useful to the Arexx community back in the day, as they could issue programs without the fear of people stealing their script routines. The code shows how to create all the various hunks from scratch, to build an EXE file with BSS, data and code hunks. The program also optimised the original source, so various string handling routines are included.
There are also routines for reversing the whole affair, as well as lots of system freindly functions for opening files, packing and unpacking data (I think I used the imploder algorhythm), as well as using the reqtools library for dialogs etc. Some great code for writing WB / CLI apps in there, all 100% asm code. It was a shareware product, but I stopped getting money from it a long time ago If anyone is interested, I will upload the project to the zone. |
10 February 2006, 22:58 | #12 | |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,658
|
Quote:
|
|
10 February 2006, 23:05 | #13 | |
Registered User
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
|
Quote:
|
|
11 February 2006, 12:44 | #14 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 9,017
|
Intel code is also backwards, at least from a coders point of view, 68k is logically written.
|
11 February 2006, 15:14 | #15 |
Zone Friend
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 424
|
Yes, it is ugly and backwards
(for all non asm-guys) cool 68k: move.l a1,d4 what wherefrom where intel: MOV DL,02 what where wherefrom ..It´s not poossible to both understand and appreciate Intel CPUs... ..MOV MOV (maybe a barking dog) |
11 February 2006, 15:28 | #16 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
In english
68k: move source, dest intel: move dest, source |
11 February 2006, 15:57 | #17 | |
Zone Friend
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 424
|
Quote:
But, there is no e in Intel´s MOV .. |
|
11 February 2006, 15:59 | #18 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
yes you are correct (not that I know anything about intel asm) I'm just saying what the instruction does lol
|
11 February 2006, 16:10 | #19 | |
Zone Friend
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 424
|
Quote:
(maybe a bit Offtopic) Yoy can see the advantage of 68k asm also in comparing the registers. The 68000 has 7 data and 7 adressregisters + SP and SR register.(the 68000 is from 1979!!!!) Now compare it with a Pentium...see scan... limited regiters..+ limited access.. not to mention the Segment Offset adressing-mode... 12AF:3302 <---- Last edited by NOB; 23 January 2007 at 21:02. |
|
12 February 2006, 16:07 | #20 |
In deep Trouble
Join Date: Sep 2004
Location: Manchester, Made in Norway
Age: 51
Posts: 841
|
Pentium.....has 4 data regs.... AX BX CX DX..... and so on.... it's almost funny to see how simpleminded it is.... totally spaghetti, IMHO...... but then, that spaghettti is incredibly fast, nowadays
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Amiga Exe Hunks | heavy | Coders. General | 4 | 16 August 2007 00:20 |
AmigaDOS hunks documentation & HUNK_OVERLAY | AmiGer | Coders. General | 2 | 06 February 2004 08:00 |
|
|