💾 Archived View for mirrors.apple2.org.za › archive › apple.cabi.net › Languages.Programming › OMF ›… captured on 2023-03-20 at 23:24:36.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Subject: v001SRC066: coff (OMF Disassembler) 01/09 Newsgroups: comp.sources.apple2 Approved: jac@paul.rutgers.edu Submitted-by: Albert Chin-A-Young (26285659t@servax.fiu.edu) Posting-number: Volume 1, Source:66 Archive-name: utility/gs/disassem/coff/part01 Architecture: ONLY_2gs Version-number: 1.1 Coff is an OMF disassembler designed for OMF 1.0 and 2.0 files. Output is similar to the Orca and APW utility 'dumpobj', although OMF and 65816 disassemblies are much cleaner and more readable. This is the first of 9 parts. Enjoy. =Read.Me -* UNIX coff utility -* README file -* -* 1990-1992, tao Developer Project -* -* albert chin-a-young ... 26285659t@servax.fiu.edu - -Coff is an OMF disassembler designed for OMF 1.0 and 2.0 files. Output is -similar to the Orca and APW utility 'dumpobj', although OMF and 65816 -disassemblies are much cleaner and more readable. - -v1.1 marks the first update to coff. - -The attached manual, coff.tex, describes all available options to the coff -utility in addition to a thorough description of the OMF file format. The -manual is formatted with the TeX text processing system. If you would like -a printed copy of this manual, contact me at the address below. - -The 'Apple IIgs GS/OS Reference, Volume 1' describes the OMF file format. -The manual also contains a description of the OMF file format. - -To assemble coff, you must have the Merlin 16+ assembler. Modifications to the -link file must occur if you have older versions of Merlin. Versions of coff -for the following environments are available: Merlin, Orca, and GNO. Edit the -env.h file for the environment you are compiling for. - -To compile coff, invoke the following command from the Merlin command-line: - link make[.orca|.gno] -To compile the resource fork: - compile coff.r keep=[pathname of coff] rez=(-d [MERLIN|ORCA|GNO]) -Make sure to change any absolute pathnames in the Merlin link script. - - -Merlin and Orca: - While coff is executing, pressing any key will pause the output. - Press any other key to resume output. CTRL-C will end coff. -GNO: - Coff supports the GNO signal SIGINT. Thus, CTRL-C will end coff. - CTRL-S will pause output and CTRL-Q resumes output as usual. - - -Coff is free software. Source code is available. If you have any comments, -bug reports, or suggestions on this utility, please contact me at the -following: - e-mail: 26285659t@servax.fiu.edu - post: Albert Chin-A-Young [ preferred ] - PO Box 4133 - Miramar, FL 33083-4133 - - -Below is a short description of the options available in coff. - ----------------------------------------------------------------------- - -calling parameters: -coff [-OPTIONS] filename [segments..] [loadsegments..] - -OPTIONS DESCRIPTION --v [+version] display coff's version number --d [+asm] dump segment body in 65816-format disassembly --T [+tool] interpret Toolbox, GS/OS, ProDOS, ROM calls --x [+hex] dump segment body in hex (can be used with '+asm') --l [+label] print expressions using labels (default is offsets) --t [+infix] display expressions in infix form --p [+postfix] display expressions in postfix form (default) --m [+merlin] format of '+asm' to use merlin opcodes (default) --o [+orca] format of '+asm' to use orca/m opcodes --a [+shorta] 8-bit accumulator --i [+shorti] 8-bit index registers --s [+header] dump segment headers only --n [+noheader] do not print segment headers --f [+nooffset] do not print offset into file --h [+help] print this information, then quit --D [+nodefault] disable default options --c [+compress] print short form of CONST, LCONST records --e [+exact] match segment, loadsegment names exactly - [+thanks] those who helped in the development of coff - -filename name of file to dump -[segments] names of segments in file to dump -[loadsegments] names of load segments in file to dump - - -Source files for coff v1.1. - ----------------------------------------------------------------------- - -(Place these files in your Merlin PFX4 directory): - - datatype.mac.s HLL data type macros - env.h.s environment defines - env.mac.s environment macros - getopt.h.s GNU getopt defines - getopt.mac.s GNU getopt macros - signal.h.s GNO signal defines - signal.mac.s GNU signal macros - -(Place these files in a 'coff' directory): - - asm.s 65816 OMF disassembler - coff.h.s coff defines - coff.mac.s coff macros - coff.r resource definitions - coff.s main coff source - coff.tex TeX coff manual - data.s coff variables - general.s general purpose routines - gsos.s GS/OS calls - make.gno.s link file for GNO environment - make.orca.s link file for Orca environment - make.rez make file for resource fork - make.s link file for Merlin environment - omf.s OMF disassembler - output.s output routines - structure.s data structure routines - tool.s toolbox call parser - x.* external routine files - -(Place this file in a 'getopt' directory): - - getopt.s GNU getopt utility (not fully functional yet) - - -albert chin-a-young -26285659t@servax.fiu.edu -Version 1.1 -October 1992 - =Manifest - -HISTORY -Read.Me -asm.s -coff.h.s -coff.mac.s -coff.r -coff.s -coff.tex -data.s -datatype.mac.s -env.h.s -env.mac.s -general.s -getopt.h.s -getopt.mac.s -getopt.s -make.gno.s -make.orca.s -make.rez -make.s -omf.s -output.s -structure.s -tool.s -x.asm.s -x.data.s -x.general.s -x.gsos.s -x.omf.s -x.output.s -x.structure.s -x.tool.s - =HISTORY -* UNIX coff utility -* HISTORY file -* -* 1990-1992, tao Developer Project -* -* albert chin-a-young ... 26285659t@servax.fiu.edu - -v1.1 28 September 1992 - added '+compress' option - made relative branch offsets 2 bytes (i.e. BPL, BMI, etc.) - fixed pos/neg bug in relative branch output - fixed parsing of SUPER records - added support for cINTERSEG and INTERSEG records - fixed offset values in SUPER, cRELOC, RELOC records - added length of CONST, LCONST records to output - redirection under Orca now works if filename is last on command-line - (thanks to Jerry Penner for above) - added '+exact' option - a list of all segment/loadsegment names not matched is displayed at - the end of a coff run - changed '+default' option to '+nodefault' - a message is now displayed if coff is unable to parse an OMF record - (which is the case if a test file could not be generated - for the OMF record) - when +hex is added to +header, headers are printed in hex - added a few more error messages - manual rewritten in TeX - -v1.0 16 june 1992 - converted to assembly - parse_kind_1() and parse_kind_2() work - unary expressions printed correctly - MEM disassembly works - xEXPR disassembly more intelligent - extended floating values recognized - moved GS/OS, ROM, Toolbox defines to data fork - support for System 6.0 Toolbox calls - added '+thanks' option - support for pause and cancel options in Merlin and Orca versions - support for CTRL-C GNO cancel signal in GNO version - (thanks to jawaid bazyar) - -v1.0g 30 june 1991 - changed defaults to +label, +infix, +tool - +orca option only enables Orca/M disassembly - +merlin option only enables Merlin disassembly - fixed bug in parse_relexpr() - fixed bug in recognize_record() - meaning of +default reversed - reorganized code - fixed prototype of parse_opcode_1() - -v1.0f 11 june 1991 - added record types: RELOC, cRELOC, SUPER - -v1.0e 5 june 1991 - jsr (addr,x) and jmp (addr,x) where addr is a number are - handled correctly - (thanks to jerry brenne) - mvn opcode now parsed correctly - +hex with dangling asm opcodes at end of OMF segment print in - correct position - exit status changed to 0 from 1 - library file are properly handled - support for verbose kind description fields - -v1.0d 2 may 1991 - +longa, +longi removed and replaced by +shorta, +shorti - fixed bug if OMF file looked like - pea {body}lt;num> - jsl ><name> - (thanks to tim meekins) - fixed bug for dangling asm opcodes at end of OMF segment - (thanks to tim meekins) - -v1.0c 30 april 1991 - new implementation of hex mode - (thanks to tim meekins) - +tool option recognizes toolbox, GS/OS, ProDOS calls, ROM addresses - (thanks to morgan davis, dave lyons) - removed all global variables except flags - removed inline asm bug fix (my fault) - cleaned up code - minimal speed improvement - program name changed to 'coff' to match UNIX coff utility - minor bug fixes - bug fix to 65816 expression at end of CONST record. parsing the - syntax of this opcode was dead wrong. - minimize parentheses routine for disassembly - (thanks to tim meekins) - -v1.0b 22 january 1991 - fix pause, oa-period - (thanks to jawaid bazyar, tim meekins) - fix to disassembly routines - set reload bit - -v0.9b 12 january 1991 - fix to disasm routines - fix to displacement, code counter - +infix option working - +nooffset option working - +postfix option added - +label option added - all file i/o converted to GS/OS calls - added record tyep: BEXPR - -v0.8b 21 december 1990 - support for OMF v2.0 headers - added record type: LCONST - -v0.7b 19 december 1990 - added record types: GEQU, MEM, EQU - -v0.6b 18 december 1990 - initial release of beta - =coff.h.s -* UNIX coff utility -* defines -* -* 1990-1992, The UNIX Consortium Developer Project -* -* albert chin-a-young ... 26285659t@servax.fiu.edu - - -NULL equ 0 -EOF equ $ffff -FALSE equ 0 ;boolean false value -TRUE equ 1 ;boolean true value - -CTRL_C equ $03 ;ctrl-c keypress (cancel) - -MERLIN_16 equ %00000001 ;output code for Merlin 16 -ORCA_M equ %00000010 ;output code for Orca/M - -;error messages -ERROR_STRING equ %00000001_00000000 ;parameter to error is C-String -ERROR_LHEX_VALUE equ %00000010_00000000 ;parameter to error is long hex value -ERROR_DEC_VALUE equ %00000100_00000000 ;parameter to error is decimal value -NO_FILENAME equ ERROR_STRING+$00 ;no OMF filename given -INVALID_FILENAME equ ERROR_STRING+$02 ;filename given is incorrect -PREMATURE_END equ ERROR_STRING+$04 ;premature end of file -OMF_VERSION equ ERROR_DEC_VALUE+$06 ;invalid OMF version -INVALID_LENGTH equ ERROR_LHEX_VALUE+$08 ;invalid length of OMF file -MORE_DATA equ ERROR_STRING+$0a ;not enough data in file to make sense of - -MERLIN equ %00000001 ;merlin assembler -ORCA equ %00000010 ;orca assembler - -ERROR equ $ffff -LOADNAME_LEN equ 10 ;length of loadname in OMF header -KIND_LEN equ 40 ;length of kind descriptor -DC equ $0100 -HEADER_LEN equ $38 ;approximate length of OMF header - -HEADER_EDGE equ 15 -ADDRESS_EDGE equ 36 -CHAR_EDGE equ 40 -CONST_EDGE equ 10 -DOUBLE_EDGE equ 36 -EXTENDED_EDGE equ 36 -FLOAT_EDGE equ 36 -HEX_EDGE equ 20 -INT_EDGE equ 36 -INFIX_EDGE equ 32 -POSTFIX_EDGE equ 30 -SOFT_REFERENCE_EDGE equ 36 -SUPER_EDGE equ 11 -INVALID_NAME_EDGE equ 65 - -TRUE_OFFSET equ $80 -FALSE_OFFSET equ $81 -LIBRARY equ $b2 ;library file - -USAGE equ $0001 ;short usage parameters -USAGE_VERBOSE equ $0002 ;verbose usage parameters -VERSION equ $0003 ;coff version number -THANKS equ $0004 ;those who helped in development of coff -DEFAULT equ $0005 ;default options - -GSOS_INLINE equ $e100a8 ;GS/OS inline entry -GSOS_STACK equ $e100b0 ;GS/OS stack entry -PRODOS_MLI equ $bf00 ;ProDOS 8 MLI entry -TOOL_STACK equ $e10000 ;ToolBox stack entry -TOOL_STACK_ALT equ $e10004 ;alt ToolBox stack entry - -KBD equ $e0c000 ;read keyboard -KBDSTRB equ $e0c010 ;clear keyboard - -* segment type subfield -* -CODE equ $0000 -DATA equ $0001 -JUMP_TABLE equ $0002 -PATHNAME equ $0004 -LIBRARY_DICTIONARY equ $0008 -INITIALIZATION equ $0010 -ABSOLUTE_BANK_SEG equ $0011 -DIRECT_PAGE equ $0012 - -* segment attributes bits -* -BANK_RELATIVE equ $0100 -SKIP equ $0200 -RELOAD equ $0400 -ABSOLUTE_BANK equ $0800 -POSITION_INDEPENDENT equ $2000 -PRIVATE equ $4000 -DYNAMIC equ $8000 - -* segment-body record types -* -END equ $00 -ALIGN equ $e0 -ORG equ $e1 -RELOC equ $e2 -INTERSEG equ $e3 -USING equ $e4 -STRONG equ $e5 -GLOBAL equ $e6 -GEQU equ $e7 -MEM equ $e8 -EXPR equ $eb -ZEXPR equ $ec -BEXPR equ $ed -RELEXPR equ $ee -LOCAL equ $ef -EQU equ $f0 -DS equ $f1 -LCONST equ $f2 -LEXPR equ $f3 -ENTRY equ $f4 -cRELOC equ $f5 -cINTERSEG equ $f6 -SUPER equ $f7 -GENERAL equ $fb - -SUPER_RELOC2 equ 0 -SUPER_RELOC3 equ 1 - -* expressions -* -ADD equ $01 -SUB equ $02 -MUL equ $03 -DIV equ $04 -MOD equ $05 -NEGATION equ $06 -BIT_SHIFT equ $07 -AND equ $08 -OR equ $09 -EOR equ $0a -NOT equ $0b -LESS_EQUAL equ $0c -GREATER_EQUAL equ $0d -NOT_EQUAL equ $0e -LESS equ $0f -GREATER equ $10 -EQUAL equ $11 -LOGICAL_AND equ $12 -INCLUSIVE_OR equ $13 -EXCLUSIVE_OR equ $14 -COMPLEMENT equ $15 - -LEFT equ 0 -RIGHT equ 1 -LEFT_RIGHT equ 2 - -LOCATION_COUNTER equ $80 -CONSTANT_OPERAND equ $81 -LABEL_WEAK equ $82 -LABEL_VALUE equ $83 -LABEL_LENGTH equ $84 -LABEL_TYPE equ $85 -LABEL_COUNT equ $86 -RELATIVE_OFFSET equ $87 - -LONGI equ $10 -LONGA equ $20 - -ASL equ $0a -INC equ $1a -ROL equ $2a -DEC equ $3a -LSR equ $4a -ROR equ $6a - -JSR equ $20 -JSL equ $22 -LDX equ $a2 -PEA equ $f4 - -BPL equ $10 -BMI equ $30 -BVC equ $50 -BVS equ $70 -BRA equ $80 -BCC equ $90 -BCS equ $b0 -REP equ $c2 -BNE equ $d0 -SEP equ $e2 -BEQ equ $f0 - -* addressing modes -* -ABSOLUTE equ $01 -ABSOLUTE_INDEX_X equ $02 -ABSOLUTE_INDEX_Y equ $03 -ABSOLUTE_INDEX_INDIRECT equ $04 -ABSOLUTE_INDIRECT equ $05 -ABSOLUTE_INDIRECT_LONG equ $06 -ABSOLUTE_LONG equ $07 -ABSOLUTE_LONG_INDEX_X equ $08 -ACCUMULATOR equ $09 -BLOCK_MOVE equ $0a -DP equ $0b -DP_INDEX_X equ $0c -DP_INDEX_Y equ $0d -DP_INDEX_INDIRECT_X equ $0e -DP_INDIRECT equ $0f -DP_INDIRECT_LONG equ $10 -DP_INDIRECT_INDEX_Y equ $11 -DP_INDIRECT_LONG_INDEX_Y equ $12 -IMMEDIATE equ $13 -IMPLIED equ $14 -PC_RELATIVE equ $15 -PC_RELATIVE_LONG equ $16 -STACK_ABSOLUTE equ $17 -STACK_DP_INDIRECT equ $18 -STACK_INTERRUPT equ $19 -STACK_PC_RELATIVE equ $1a -STACK_PULL equ $1b -STACK_PUSH equ $1c -STACK_RTI equ $1d -STACK_RTL equ $1e -STACK_RTS equ $1f -STACK_RELATIVE equ $20 -SR_INDIRECT_INDEX_Y equ $21 -WDM equ $22 - -;@label structure references -`label_name equ $00 ;name of label -`expr_name equ `label_name+4 ;expression label evaluates to -`type equ `expr_name+4 ;GLOBAL or LOCAL label -`next equ `type+2 ;next label reference -`prev equ `next+4 ;previous label reference -`last equ `prev+4 - -;@stack structure references -stack`str equ $00 ;handle to expression name (string) -stack`oper equ stack`str+4 ;if expression is an operator - -;@label data structure offsets -`lo equ $00 ;handle to array of labels -`hi equ `lo+4 - -;offsets to elements in binary tree -`str equ $00 -`oper equ `str+4 -`left equ `oper+2 ;left tree -`right equ `left+2 ;right tree - - ;@btree data structure offsets -`ptr equ $00 ;pointer to array of binary trees - -;~operator data structure offsets -`prec equ $00 ;operator precedence -`assoc equ `prec+2 ;operator associativity - -;~opcodes data structure offsets -`num_bytes equ $00 ;number of bytes the opcode takes -`m equ `num_bytes+2 ;if 16-bit mode accumulator -`i equ `m+2 ;if 16-bit mode index registers -`mode equ `i+2 ;addressing mode -`syntax equ `mode+2 ;how to format opcode - -;@omf data structure offsets -`offset equ $00 ;offset from beginning of file for this segment -`bytecnt equ `offset+4 ;number of bytes in file that segment requires -`resspc equ `bytecnt+4 ;number of bytes of zeros to add to end of segment -`length equ `resspc+4 ;memory size of segment -`kind equ `length+4 ;type and attributes of segment -`lablen equ `kind+2 ;length of each name or label record in segment -`numlen equ `lablen+2 ;length of each number field in segment body -`version equ `numlen+2 ;version number of OMF segment is compatible with -`revision equ `version+2 ;revision number of OMF v2.0 segment is compatible with -`banksize equ `revision+2 ;maximum memory-bank size for segment -`org equ `banksize+4 ;absolute address at which to load segment -`align equ `org+4 ;boundary on which to align segment -`numsex equ `align+4 ;order of bytes in a number field -`lcbank equ `numsex+2 ;load segment into language card -`segnum equ `lcbank+2 ;segment number -`entry equ `segnum+2 ;offset into segment that corresponds to entry point -`dispname equ `entry+4 ;displacement of the loadname field within segment header -`dispdata equ `dispname+2 ;displacement from start of segment header to start of segment body -`temporg equ `dispdata+2 ;temporary origin of object segment for OMF v2.0 -`loadname equ `temporg+4 ;name of load segment -`segname equ `loadname+LOADNAME_LEN ;name of segment -`displacement equ `segname+4 -`counter equ `displacement+4 -`library equ `counter+4 ;if file is a library -`refNum equ `library+2 ;reference number associated with file - -;global/local data parsing structure -`on equ $00 ;test if parsing on -`data_type equ `on+2 ;type of data to parse -`count equ `data_type+2 ;number of records to parse -`edge equ `count+2 ;right margin for output of data - -;@stack data structure offsets -`lo equ $00 ;array of handles containing stack -`hi equ `lo+4 ;elements -`size equ `hi+4 ;number of elements in stack - -;@expr_list data structure offsets -`lo equ $00 ;array of handles containing stack -`hi equ `lo+4 ;elements -`size equ `hi+4 ;number of elements in stack - -;offset for @Close data structure -Close`pCount equ $00 -Close`refNum equ Close`pCount+2 - -;offset for @Open data structure -Open`pCount equ $00 -Open`refNum equ Open`pCount+2 -Open`pathname equ Open`refNum+2 -Open`requestAccess equ $08 -Open`resourceNumber equ $0a -Open`access equ $0c -Open`fileType equ $0e -Open`auxType equ $10 -Open`storageType equ $14 -Open`createDateTime equ $16 -Open`modDateTime equ $1e -Open`optionList equ $26 -Open`eof equ $2a -Open`blocksUsed equ $2e -Open`resourceEOF equ $32 -Open`resourceBlocks equ $36 - -;offset for @SetMark data structure -SetMark`pCount equ $00 -SetMark`refNum equ SetMark`pCount+2 -SetMark`base equ SetMark`refNum+2 -SetMark`displacement equ SetMark`base+2 - -;offset for @GetMark data structure -GetMark`pCount equ $00 -GetMark`refNum equ $02 -GetMark`position equ $04 - -;offset for @Quit data structure -Quit`pCount equ $00 -Quit`pathname equ $02 -Quit`flags equ $06 - -;offset for @Read data structure -Read`pCount equ $00 -Read`refNum equ $02 -Read`dataBuffer equ $04 -Read`requestCount equ $08 -Read`transferCount equ $0c -Read`cachePriority equ $10 - -GSOSstack equ $e100b0 ;gs/os stack entry point - -Open equ $2010 ;Open call number -Read equ $2012 ;Read call number -Close equ $2014 ;Close call number -SetMark equ $2016 ;SetMark call number -GetMark equ $2017 ;GetMark call number -Quit equ $2029 ;Quit call number =coff.mac.s -* UNIX coff utility -* macros -* -* 1990-1992, tao Developer Project - - -cstr mac - asc ' ' ;space between opcode and operand - asc ]1 - db 0 - eom -absolute mac - dw 3,0,0 - dw ABSOLUTE - asc ]1 - cstr '$%4' - eom -absolute_index_x mac - dw 3,0,0 - dw ABSOLUTE_INDEX_X - asc ]1 - cstr '$%4,x' - eom -absolute_index_y mac - dw 3,0,0 - dw ABSOLUTE_INDEX_Y - asc ]1 - cstr '$%4,y' - eom -absolute_index_indirect mac - dw 3,0,0 - dw ABSOLUTE_INDEX_INDIRECT - asc ]1 - cstr '($%4,x)' - eom -absolute_indirect mac - dw 3,0,0 - dw ABSOLUTE_INDIRECT - asc ]1 - cstr '($%4)' - eom -absolute_indirect_long mac - dw 3,0,0 - dw ABSOLUTE_INDIRECT_LONG - asc ]1 - cstr '[$%4]' - eom -absolute_long mac - dw 4,0,0 - dw ABSOLUTE_LONG - asc ]1 - cstr '%c$%6' - eom -absolute_long_index_x mac - dw 4,0,0 - dw ABSOLUTE_LONG_INDEX_X - asc ]1 - cstr '%c$%6,x' - eom -accumulator macm - dw 1,0,0 - dw ACCUMULATOR - asc ]1 - asc ' ',00 - eom -block_move mac - dw 3,0,0 - dw BLOCK_MOVE - asc ]1 - asc '