Discussion:
Disassembly of old Turbo Pascal (V3) code - how to create data
(too old to reply)
Robert Prins
2021-04-17 13:48:02 UTC
Permalink
Hi all,

I would like to disassemble the final version of a self-written Turbo Pascal V3
program, i.e. a simple .COM file, and to that effect I've dug out my old (AD
2004) registered copy of IDA Pro (V4.7.0.831). Not having used it for more than
10 years, and no longer having access to their forum, I'm now stuck. The .COM
file loads, IDA happily disassembles it, but it just creates one single segment,
and I have no (longer) a clue on how to create the data segment. There's a bit
of info in the TP3 Manual, and using David Lindauer's GRDB in DOXBox-X allows me
to single-step through the RTL initialisation code and that shows me it sets up
up DS and SS, but it doesn't help me in setting up these segments in IDA.

I've tried the "Create Segment" option, but I'm lost entering the required
values for start address, end address and base, "class" is probably "DATA", the
once for the single "seg000" that IDA creates are CODE, start @ 0x0100, end @
0xD623, which leads me to assume that a to-be-created "seg001" should start at
0x0000, end at 0xffff, and have a base of 0xd63 (paragraphs), but that results
in a "Bad segment base: segment would have bytes with a negative offset" pop-up.

Trying start @ 0xd630, end @ 0x1d630, with a base 0x0000 creates a segment, but
it looks like

seg000:D622
seg001:C8C00 ;
---------------------------------------------------------------------------
seg001:C8C00
seg001:C8C00 ; Segment type: Regular
seg001:C8C00 seg001 segment byte public '' use16
seg001:C8C00 assume cs:seg001
seg001:C8C00 ;org 0C8C00h
seg001:C8C00 assume es:nothing, ss:nothing, ds:nothing,
fs:nothing, gs:nothing

Which may be correct, but the "org 0c8c00" makes absolutely no sense to me.

If you can help me I would be grateful, and to help you, I've uploaded a RAR
archive with the full sources, the resulting "lift.com" executable and the input
file to my Google drive @
<https://drive.google.com/drive/folders/0B0oygbfs7DsVVWNBZWpqaHRHX3c?usp=sharing>,
look for lift16bit.rar Please note that the code will not compile with anything
more advanced than Turbo Pascal 3, and in my case it was compiled with TP 3.01a.

Thanks,

Robert
--
Robert AH Prins
robert(a)prino(d)org
The hitchhiking grandfather - https://prino.neocities.org/indez.html
Some REXX code for use on z/OS - https://prino.neocities.org/zOS/zOS-Tools.html
Sjouke Burry
2021-04-17 18:32:10 UTC
Permalink
Post by Robert Prins
Hi all,
I would like to disassemble the final version of a self-written Turbo Pascal V3
program, i.e. a simple .COM file, and to that effect I've dug out my old (AD
2004) registered copy of IDA Pro (V4.7.0.831). Not having used it for more than
10 years, and no longer having access to their forum, I'm now stuck. The .COM
file loads, IDA happily disassembles it, but it just creates one single segment,
and I have no (longer) a clue on how to create the data segment. There's a bit
of info in the TP3 Manual, and using David Lindauer's GRDB in DOXBox-X allows me
to single-step through the RTL initialisation code and that shows me it sets up
up DS and SS, but it doesn't help me in setting up these segments in IDA.
I've tried the "Create Segment" option, but I'm lost entering the required
values for start address, end address and base, "class" is probably "DATA", the
0xD623, which leads me to assume that a to-be-created "seg001" should start at
0x0000, end at 0xffff, and have a base of 0xd63 (paragraphs), but that results
in a "Bad segment base: segment would have bytes with a negative offset" pop-up.
it looks like
seg000:D622
seg001:C8C00 ;
---------------------------------------------------------------------------
seg001:C8C00
seg001:C8C00 ; Segment type: Regular
seg001:C8C00 seg001 segment byte public '' use16
seg001:C8C00 assume cs:seg001
seg001:C8C00 ;org 0C8C00h
seg001:C8C00 assume es:nothing, ss:nothing, ds:nothing,
fs:nothing, gs:nothing
Which may be correct, but the "org 0c8c00" makes absolutely no sense to me.
If you can help me I would be grateful, and to help you, I've uploaded a RAR
archive with the full sources, the resulting "lift.com" executable and the input
<https://drive.google.com/drive/folders/0B0oygbfs7DsVVWNBZWpqaHRHX3c?usp=sharing>,
look for lift16bit.rar Please note that the code will not compile with anything
more advanced than Turbo Pascal 3, and in my case it was compiled with TP 3.01a.
Thanks,
Robert
A com file is a simplyfied exe, without a lot of exe things.
Just a solid block of code and data.
And not to much of that either.
wolfgang kern
2021-04-17 19:30:24 UTC
Permalink
Post by Robert Prins
Hi all,
Hello,
Post by Robert Prins
I would like to disassemble the final version of a self-written Turbo
Pascal V3 program, i.e. a simple .COM file,
...

.com files haven't any segment-info.
you can try DOS-debug (if you have one) or the NASM disassembler.

DOS.COM-files are usually organized to start at cs:0x0100.
If you post a hex-dump of your code I could disassemble it.
__
wolfgang
Robert Prins
2021-04-17 22:07:15 UTC
Permalink
Post by wolfgang kern
Post by Robert Prins
Hi all,
Hello,
Post by Robert Prins
I would like to disassemble the final version of a self-written Turbo Pascal
V3 program, i.e. a simple .COM file,
...
.com files haven't any segment-info.
you can try DOS-debug (if you have one) or the NASM disassembler.
DOS.COM-files are usually organized to start at cs:0x0100.
If you post a hex-dump of your code I could disassemble it.
To you, Wolfgang, and Sjouke Berry,

Turbo Pascal V3 (and probably versions 1 & 2 too) created .COM files are not
run-of-the-mill .COM files. The startup-code actually sets up DS to point to a
separate data segment, and SS to a separate stack. For what it's worth, I've put
'LIFT.COM' temporarily on my website
<https://prino.neocities.com/temp/lift.com>, so feel free to have a go at it.
The code that sets up the environment starts at 0x2d7c (assuming the program is
loaded at 0x100)

And as I wrote, IDA Pro happily disassembles it, but my problem is, not having
ever disassembled a TP3 generated .COM file, how to create a second (= data)
segment. I see it being created running the program in GRDB, but GRDB <> IDA Pro.

Getting a new version of IDA Pro (to again get access to their forum) is a
no-no, the Pro version costs USD 1879 (or more than 10% of my annual income),
the Home version costs USD 365, but no longer has a perpetual license and can
only disassemble selected instruction sets...

Robert

PS: Maybe I should give this NSA thing, Ghidra, a try?
--
Robert AH Prins
robert(a)prino(d)org
The hitchhiking grandfather - https://prino.neocities.org/indez.html
Some REXX code for use on z/OS - https://prino.neocities.org/zOS/zOS-Tools.html
Frank Kotler
2021-04-17 21:50:15 UTC
Permalink
On 04/17/2021 06:07 PM, Robert Prins wrote:

...
Post by Robert Prins
Turbo Pascal V3 (and probably versions 1 & 2 too) created .COM files are
not run-of-the-mill .COM files.
As I recall, DOS doesn't care what the file is named. If the first two
bytes are "MZ", it's an exe. Perhaps we should not call it .COM?

Best,
Frank
Robert Prins
2021-04-18 09:09:25 UTC
Permalink
...
Post by Robert Prins
Turbo Pascal V3 (and probably versions 1 & 2 too) created .COM files are not
run-of-the-mill .COM files.
As I recall, DOS doesn't care what the file is named. If the first two bytes are
"MZ", it's an exe. Perhaps we should not call it .COM?
They are not MZ files, they are real COM files, be it that they do strange
things once loaded.

Not that strange, given that "turbo.com", the original "IDE" did also handle
multiple segments (itself, and the image of the compiled program, when set to
run from memory) Anders Hejlsberg, who originally wrote it, was (and still is)
pretty brilliant guy.

Robert
--
Robert AH Prins
robert(a)prino(d)org
The hitchhiking grandfather - https://prino.neocities.org/indez.html
Some REXX code for use on z/OS - https://prino.neocities.org/zOS/zOS-Tools.html
wolfgang kern
2021-04-18 09:29:37 UTC
Permalink
This post might be inappropriate. Click to display it.
Robert Prins
2021-04-19 01:26:54 UTC
Permalink
Post by wolfgang kern
Post by Robert Prins
...
Post by Robert Prins
Turbo Pascal V3 (and probably versions 1 & 2 too) created .COM files are not
run-of-the-mill .COM files.
As I recall, DOS doesn't care what the file is named. If the first two bytes
are "MZ", it's an exe. Perhaps we should not call it .COM?
They are not MZ files, they are real COM files, be it that they do strange
things once loaded.
Not that strange, given that "turbo.com", the original "IDE" did also handle
multiple segments (itself, and the image of the compiled program, when set to
run from memory) Anders Hejlsberg, who originally wrote it, was (and still is)
pretty brilliant guy.
if they are real COM files then the segment info is found in the code.
org 0100h       ;to override DOS default segment setting
push CS        ;the COM-loader grant a few bytes stack
pop  SS
mov  SP.xxxx   ;wherever it's wanted to be
push CS
pop  DS
push  0
pop  ES
....
The info is there, but it's not as trivial as what you show. I'm sure that I
will be able to get at it at some stage to automagically create an skeleton IDC
file to generate the segments, after all I also got this bit of REXX,

=== CUT ===
data = charin(file, 1, chars(file))

data = overlay(reverse(x2c(d2x(date('T', now, 'I') + 12 * 3600, 8))), data,
pos('PE' || x2c(00 00), data) + 8)

call charout file, data, 1
=== CUT ===

that sets the timestamp in the PE files coming out of Virtual Pascal to 12:00
with "now" being the date of the newest source file.

Robert
--
Robert AH Prins
robert(a)prino(d)org
The hitchhiking grandfather - https://prino.neocities.org/indez.html
Some REXX code for use on z/OS - https://prino.neocities.org/zOS/zOS-Tools.html
Terje Mathisen
2021-04-18 12:39:10 UTC
Permalink
Post by Robert Prins
Post by Frank Kotler
...
Post by Robert Prins
Turbo Pascal V3 (and probably versions 1 & 2 too) created .COM files
are not run-of-the-mill .COM files.
As I recall, DOS doesn't care what the file is named. If the first two
bytes are "MZ", it's an exe. Perhaps we should not call it .COM?
They are not MZ files, they are real COM files, be it that they do
strange things once loaded.
Not that strange, given that "turbo.com", the original "IDE" did also
handle multiple segments (itself, and the image of the compiled program,
when set to run from memory) Anders Hejlsberg, who originally wrote it,
was (and still is) pretty brilliant guy.
I agree 100%.

The 35-37 kB needed for Turbo.com is one of the all-time great hacks:

A compiler (non-optimizing but still), editor, debugger and RTL in that
space?

Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Loading...