Hi Ralf,
the tests I did showed that FreePascal is perfectly capable of producing
reasonably small binaries fitting the small memory model, if you do not
require the full language feature set (stay away from ObjFpc / Delphi
modes). SysUtils and exception handling pulls in a significant amount of
code, so you either stick with plain FPC or TP modes or have to live
with large memory model.
I am not that interested in Turbo Pascal compatibility, so I can not say
anything about it. For me, FreePascal provides some benefits over Turbo
Pascal, taking my specific use case into account: e.g. 64-bit arithmetic
in 8086 real mode.
To the specific problem: I have to provide a FAR pointer to the BIOS as
a member of an INT13 device access packet. That pointer shall point to a
512 byte array, for which I get a near pointer via the @ address
operator. This near pointer has to be converted to a far pointer.
Because this operation is clearly defined for the small memory model, I
asked if someone knows that a built-in solution exists. But perhaps this
question is better addressed to the FreePascal community. In the
meantime, I will use the function from my last mail.
Greetings, Bernd
On 08.11.2023 20:57, Ralf Quint via Freedos-devel wrote:
On 11/8/2023 11:40 AM, Bernd Böckmann via Freedos-devel wrote:
Hi all,
has anyone recently played around with the FreePascal 8086 cross
compiler to generate DOS executables? I try to convert a near pointer
to a far pointer while working under the small memory model, but that
is not as trivial as it should be, because I have not found a
language / library feature for it. For example, a cast operation does
not work. But the semantics should be well defined (for the small
memory model): set the segment part of the far pointer to DS.
I came up with the following solution, but I am wondering if I have
overlooked something built-in?
function ToFarPointer(nearP: NearPointer) : FarPointer;
var p: packed record ofs: NearPointer; segm: Word; end;
begin
p.ofs := nearP;
asm
mov ax, seg @data
mov [p.segm], ax
end;
ToFarPointer := FarPointer(p);
end;
(the above of course only works with the small / tiny / compact
memory models)
Greetings, Bernd
How are you even working in the "small" memory model in FreePascal?
One of the problems that I noticed when trying to use the 8086 version
of FreePascal long time ago was that while someone went through the
length of generating 8086 code, there was little compatibility with
Turbo/Borland Pascal and actually DOS.
"small" memory model means that you have a fixed code AND data
segment, and all pointers are just offsets within those segments. Not
having the definitions of NearPointer and FarPointer from the above
snippet, one thing to consider is that when changing either CS or DS
segments in a small memory model program, you need to make sure that
you ALWAYS save and restore those segments when changing them
temporarily...
I am pretty sure that the actual compatibility with the DOS
environment has not significantly improved since I tried. And as in
Pascal, by default you should not be messing with any pointers
directly, any such feature to do so would be a very specific
implementation/library issue...
Ralf
_______________________________________________
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel
_______________________________________________
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel