Recent

Author Topic: FPC32 (with db66/db67) in DOS  (Read 5019 times)

microxa

  • Newbie
  • Posts: 6
FPC32 (with db66/db67) in DOS
« on: October 09, 2020, 02:29:21 pm »
Hi! for me FPC is more 'asm' than 'hll', but for fun:
I got an excellent result, using just the patched 32-bit FPC code generator (for Win32 target).
Then just post-processing Win32-PE to normalize in DOS exe. Of course, the minimal/dummy RTL (system/sysinit/fpintres)  is used.

Funny, but incredibly wild, x86_16 machine code (for 386+) works very well!
tested under dosbox(real mode)/ntvdm(v86).

despite some restrictions, are obtained rather complicated program:
http://imgsharing.ru/94576286.png

Thanks for the powerful supercompiler!

it was needed for a long time.. I'm happy again, sometimes doing programming!

p.s.
may be interesing:
common changes (aasmcpu.pas) for functions taicpu.calcsize/taicpu.GenCode

Code: Pascal  [Select][+][-]
  1.     function taicpu.calcsize(p:PInsEntry):shortint;
  2.       var
  3.         i,data:longint;
  4.         codes : pchar;
  5.       ...
  6.         exists_prefix_F2 := false;
  7.         exists_prefix_F3 := false;
  8.  
  9.     { ...  }
  10.         data:=pInteger(codes)^ and $FFFFFF;
  11.         {fix  call [procedure call mem??] }
  12.         if data = $FF01D5 then inc(len,2) else begin
  13.         data:=0;
  14.         for i:=0 to ops-1 do data:=data or oper[i]^.ot;
  15.         data := data and $0E000004; //mem&reg32
  16.  
  17.         if data = $00000004 then inc(len) else
  18.         if data = $0E000000 then inc(len) else
  19.         if data = $0E000004 then inc(len,2) else
  20.         begin
  21.            c:=ord(codes[1]);data:=pInteger(codes)^ and $FFFFFF;
  22.            case data of
  23.             $00C301, //retn
  24.             $00C901, //leave
  25.             $6001D5, //pushad
  26.             $6101D5, //popad
  27.             $CF01D5: //iretd
  28.                 inc(len);
  29.            end;
  30.         end;
  31.  
  32. { original code }
  33.         repeat
  34.           c:=ord(codes^);
  35.           inc(codes);
  36.  

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: FPC32 (with db66/db67) in DOS
« Reply #1 on: October 09, 2020, 03:46:37 pm »
I got an excellent result, using just the patched 32-bit FPC code generator (for Win32 target).
Then just post-processing Win32-PE to normalize in DOS exe. Of course, the minimal/dummy RTL (system/sysinit/fpintres)  is used.

Funny, but incredibly wild, x86_16 machine code (for 386+) works very well!
tested under dosbox(real mode)/ntvdm(v86).

While that is an interesting experiment, you are aware that FPC fully supports 16-bit x86 through the i8086 target? ;)

microxa

  • Newbie
  • Posts: 6
Re: FPC32 (with db66/db67) in DOS
« Reply #2 on: October 11, 2020, 12:13:18 am »
Hello PascalDragon.
yes, I know that ..
but there isn't exactly a 32 bit code generator.

By the way, version 3.2.0 has been successfully implemented for 16-bit mode, but version 3.3.1 unfortunately falls from memory burnout. But nevertheless, it was possible to transfer part of the optimizer modules (aoptx86, etc.) from version 3.3.1 to 3.2

I like this quest ..

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: FPC32 (with db66/db67) in DOS
« Reply #3 on: October 11, 2020, 01:00:44 am »
Maybe I'm being dense (probably :-[ )  but I'll ask: what's the point? I mean, FPC by itself already does generate 32 bits, protected-mode apps in DOS, and there is already a 16-bit generator so ... what's is "special" about what you're doing?

I'm really interested: we have a few apps working on DOS, both FP 32 bits and TP 16 bits (which we'll convert to 16 bit FP as soon as we can and the 16 bits compiler becomes fully stable and tested). It would be nice to know whatever alternatives there are out there.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

microxa

  • Newbie
  • Posts: 6
Re: FPC32 (with db66/db67) in DOS
« Reply #4 on: October 11, 2020, 02:27:41 am »
This is just an instrumental feature, implemented simply as
helloworld. The only alternative - is manual assembly.

microxa

  • Newbie
  • Posts: 6
Re: FPC32 (with db66/db67) in DOS
« Reply #5 on: October 12, 2020, 06:25:55 am »
В v331, a strange leak occurs when compiling files of medium/big size and if the optimization is -Op80386-OpPENTIUM. (i was not attentive to fpc.cfg) So this is not very critical. Optimization has very improved.
And yes, 16bitted matrix has me...
Ok!
>>what's is "special" about what you're doing?
dear, lucamar
too many "special & somspecial" for the x86 architecture. What can be done from the moment of launching in dos, iterating 32-bit code in real mode? This remains to be analyzed.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: FPC32 (with db66/db67) in DOS
« Reply #6 on: October 12, 2020, 07:56:27 am »
Doesn't the i8086 backend use 386 instructions for longint when properly instructed ?

It seems more straightforward to work towards more 32-bit usage with i8086 than within the i386 backend, since that has the correct memory model.

If it is not about the memory model, one could simply use go32v2 target.
« Last Edit: October 12, 2020, 08:01:43 am by marcov »

microxa

  • Newbie
  • Posts: 6
Re: FPC32 (with db66/db67) in DOS
« Reply #7 on: October 12, 2020, 05:24:42 pm »
Ок..
I am in no way detracting from the merits of other instruments.

Conceptually, i8086 codegen engine use traditional/canonical, segment-oriented model code & data distribution. This, may be, good for i8086-i80286.

Go32 highly advanced DPMI framework.

but..
of course, in my case, the Win32/flat model programming approach is more used  (more skills, experience, habits)..

And, perhaps "WDOSX" was the reason that made me think about "db66 / db67 powered code". At one time, under this mini-win32 environment, it was possible to successfully run FPC (2.2), but the main, small kernel, it was executed in a 16-bit code selector.
The same can be said about the HX-DOS extender.

Due to the increased complexity, many things remained abandoned and not implemented -
since it took a lot of assembler art, and constant delving into unnecessary details.

And only Pascal always came to the rescue!
And as we can see, even where it is not accepted, in no mainstream HLL - "Intel opcode powered db.. " .. oh you know :-D

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: FPC32 (with db66/db67) in DOS
« Reply #8 on: October 12, 2020, 06:27:12 pm »
I guess you were one of those using "unreal" mode and 4Gb segments, huh? ;D :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

microxa

  • Newbie
  • Posts: 6
Re: FPC32 (with db66/db67) in DOS
« Reply #9 on: October 12, 2020, 10:17:45 pm »
un(big)real, exec above 1mb boundary, multithreading..
Yes, it's not that hard, it was harder to figure out what to do next)..
but, something was used, then in the win32(under kernel mode).
DOS has a legacy of unique examples that still serve as sources of inspiration.
Which is very precious!

It's amazing that your project still supports this..

It will not be more surprising if "holy sweet real mode x86" does not remain in the new generations of x86 , But there is (ex)VEX, x64, and FPC, which understands this better than an assembler guru)))
(I still do not understand where the code generator is hidden there,
and it is very valuable, to me, that post processing was stacking in GenCode)

 

TinyPortal © 2005-2018