Closed LowLevelMahn closed 3 years ago
I am not sure if it is good idea.
OW C code relate to C run-time library (for some support routines as minimum).
The references to C run-time library depend on code if it call something what need it.
Generaly it relates to C run-time initial code, you can remove such references by -zl
and -zls
compiler options.
Below is sample how you can declare variables in code.
extern unsigned __based( __segname("_CODE") ) __OVLFILEPREV__;
Or you can define it by
unsigned __based( __segname("_CODE") ) __OVLFILEPREV__;
If you need something on begining of code than you can use something as following as first in source file.
const char __based( __segname( "_CODE" ) ) Signature[4] = "DIP";
You can link it as binary file which start on offset 0.
Thanks for the tips - the Variables in CODE-Segment is perfect, and i don't need anything from the Standardlibs so skipping is ok
Got working - thanks for your help - now i've got a small asm stub for the jump table and a little bit C/C++ with "based( segname( "_CODE" ) )" - perfect solution, your watcom tools are just briliant for reverse engineering/porting old stuff
You are lucky, probably you use only int/unsigned int types or narrow types that you don't need wider 32/64-bit arithmetic. Anyway you could be able define jump tables in C. You need to put it in some module and ensure that linker put it on the beginning of binary image. It can be achieved by order of linked modules or by using multiple segments and their order. OW linker can group segment together even if they use different segment name. There are -n... compilers options which can define segment names for each module. OW linker can also organized segments by their explicit offset in output image.
You are lucky, probably you use only int/unsigned int types or narrow types that you don't need wider 32/64-bit arithmetic.
im reversing 186 code - so years away from 32bit and eons away from 64bit
Anyway you could be able define jump tables in C.
im going with the asm stub because the jump-table needs to contain near jumps of 3 bytes size per entry - that could be hard to archive with C
you can use array of jmp near structures with instruction byte and relative offset. You can simplify it by some macro.
i've got some sort of loadable driver/plugin that is used by an old 16Bit DOS program
i disassembled the plugin and im able to build a 100% binary equal version of the driver based on my assembler code
now i want to port that thing over to C code - but i have no idea how to fullfill the exact code location constraints
contraints: -jump table needs to be at offset 0 -each table entry needs to be far callable and at a descent offset -all variables needs to adressed by cs-Register
problems: -how to locate the jump table -how to get my vars cs-register addresseable -how to prevent runtime linking
thanks for any ideas