[fpc-pascal]Porting to Free pascal this little Turbo Pascal code

Nelson M. Sicuro nelson at desktopsistemas.com.br
Fri Jul 30 15:31:46 CEST 2004

I think that you'll need to get rid of the "seg" and "ofs" functions,  
these are meaningless in 32 bit environment. You only need to store a full  
32 bit pointer from ebp/esp on a longint (32 bit integer) variable.
But you'll need to rethink some concepts there! The segment register from  
stack (SS) is defined by the operating system/dos extender as a segment  
*selector*, and this is *not* a memory reference. You can alloc some  
memory to place the task's stack and only redefine the esp. But do this  
with *caution*! this can have nasty effects if you don't know exactly what  
you're doing...
Just an example: if you switch the stack pointer, the next "return"  
doesn't returns to the caller, but to anywhere that is pointed by the new  
stack top!

Good luck!

Best regards,

> Thanks for you reply full of wisdom. Truth is, I *have* *to* make a  
> program
> that emulates multitasking that way.
> I adapted the code (after several trials since I have no assembler  
> experience)
> and it seems to work fine now :-)
> Here is the tip :
>   asm
>         movl bp_load, %ebp
>         movl ss_load, %esp
>   end;
> => loads the stack segment and base pointer
>   asm
>         movl %ebp, bp_save
>         movl %esp, ss_save
>   end;
> => saves the stack segment and base pointer
> I enclosed the revised TASKER.PAS as zip document, in case it could help
> someone else (thanks to Mr Warot).
> En réponse à "Nelson M. Sicuro" <nelson at desktopsistemas.com.br>:
>> In my humble experience with FreePascal, I know that you cannot mess
>> with
>> segment registers as you do in 16 bits mode. This code of yours need to
>> be
>> rewrited from scratch to be in 32 bits mode, without using the segment
>> registers and the inline functions (replaced with asm statements).
>> Anyway, this code seems unsafe to run in 32 bits anyway.
>> Most 32 bits environments are indeed capable of multitask programming,
>> take a look at the DOS 32 bit extenders that FreePascal uses.
>> Best regards,
>> Nelson
>> > Anybody capable of providing me an answer on how to get this working
>> > with Free
>> > Pascal (under DOS) ?
>> >
>> > The trick is that the Base Pointer and Segment Stack are saved and
>> > restored.
>> > That is what I am trying to do . Note FreePascal only accepts ASM
>> blocks.
>> >
>> > And also I do not know what instruction $89/$2e $8c/$16 $8b/$2e
>> $8e/$16
>> > $90/$90/
>> > $90 refer to.
>> > Regards.
>> >
>> >
> __________________
> Jérémie Lefrançois
> 06 73 27 35 97
> Consultant
> Altran Technologies

More information about the fpc-pascal mailing list