Can FreePascal generate flat binary files? 
Author Message
 Can FreePascal generate flat binary files?

Hi!

I want to write my own OS and because of that i searched the net and i
finally found something: http://www.*-*-*.com/ ;Someone
wrote an OS using FreePascal and NASM. The compiled version works, but
I cannot recompile it. The included BAT files do not work although i
think i did not make any mistake. Can someone help me? I did not find
any eMail adress on the page to ask the author....

How can I get flat binaries with FreePascal + NASM?

HELP?

MrSaint



Sun, 13 Nov 2005 21:15:22 GMT  
 Can FreePascal generate flat binary files?

Quote:

> I want to write my own OS and because of that i searched the net and i
> finally found something: http://www.thegaineys.fsnet.co.uk/  Someone
> wrote an OS using FreePascal and NASM. The compiled version works, but
> I cannot recompile it. The included BAT files do not work although i
> think i did not make any mistake. Can someone help me? I did not find
> any eMail adress on the page to ask the author....
> How can I get flat binaries with FreePascal + NASM?

Define flat binary :-)

FPC generates pure protected mode assembler files. (for use with AS, TASM,
NASM). The way how the assembler-file is translated to binary depends on
the assembler and the linker.

If you normally compiler FPC code to a binary, FPC calls the assembler (by
default AS (*)) and linker (by default GNU ld or derivative, except on
Mac OS X, where it will call the default Mac linker)

So you'll have to make FPC generate the nasm assembler files, and the
rest is the scope of the "os" project. (iow the batchfiles which should
call a assembler and a linker with the appropiate parameters). So I don't
have that information (check the batchfiles, and see if you have the correct
assembler and (cross?) linker installed, and if all options match)

If you have more specific information about what you use, and where exactly
it goes wrong (parameters, error messages), and I can try to guess what goes
wrong exactly.

(FPC generates NASM files if you specify "the right" -A options and the -a
option (for the precise -A options run fpc without parameters. Probably
-Anasm or so))

(*) FPC also has an assembler internally for most common targets, but
this is more a speed optimization.



Sun, 13 Nov 2005 21:24:24 GMT  
 Can FreePascal generate flat binary files?

Quote:

> > I want to write my own OS and because of that i searched the net and i
> > finally found something: http://www.thegaineys.fsnet.co.uk/  Someone
> > wrote an OS using FreePascal and NASM. The compiled version works, but
> > I cannot recompile it. The included BAT files do not work although i
> > think i did not make any mistake. Can someone help me? I did not find
> > any eMail adress on the page to ask the author....

> > How can I get flat binaries with FreePascal + NASM?

> Define flat binary :-)

> FPC generates pure protected mode assembler files. (for use with AS, TASM,
> NASM). The way how the assembler-file is translated to binary depends on
> the assembler and the linker.

> If you normally compiler FPC code to a binary, FPC calls the assembler (by
> default AS (*)) and linker (by default GNU ld or derivative, except on
> Mac OS X, where it will call the default Mac linker)

> So you'll have to make FPC generate the nasm assembler files, and the
> rest is the scope of the "os" project. (iow the batchfiles which should
> call a assembler and a linker with the appropiate parameters). So I don't
> have that information (check the batchfiles, and see if you have the correct
> assembler and (cross?) linker installed, and if all options match)

> If you have more specific information about what you use, and where exactly
> it goes wrong (parameters, error messages), and I can try to guess what goes
> wrong exactly.

> (FPC generates NASM files if you specify "the right" -A options and the -a
> option (for the precise -A options run fpc without parameters. Probably
> -Anasm or so))

> (*) FPC also has an assembler internally for most common targets, but
> this is more a speed optimization.

I need to have a plain binary file, which can be read by the BIOS (on a
floppy at, i think, sector 0). I have everything installed, but it
doesn't work.

It is not so important, that this OS at
http://www.thegaineys.fsnet.co.uk/ works, but that I can generate just
such binary files with FreePascal (or TurboPascal... but I think that
doesn't work...).
I can get FP to generate the NASM code, but in this code there are
"EXTERN" calls, which i don't want to have there :) With these calls it
is not possible to generate an own OS code (i thinks these "EXTERNALS"
refer to DOS-procedures and DOS should not be running).

Help?

MrSaint



Mon, 14 Nov 2005 01:55:51 GMT  
 Can FreePascal generate flat binary files?

Quote:

... snip ...

> I need to have a plain binary file, which can be read by the
> BIOS (on a floppy at, i think, sector 0). I have everything
> installed, but it doesn't work.

The obvious is the correct way to create a binary file in Pascal.
Don't know about FPC, which I believe is not ISO 7185 compliant.
How to put that image on the floppy is another (system specific)
matter.

   CONST
     MAXSECT  = 511;

   TYPE
     asector  = ARRAY[0..MAXSECT] OF char;

     binfile  = FILE OF char;    (* assuming char fits in a byte
*)
     sectfile = FILE OF asector; (* another possibility *)

   VAR
     i        : 0..MAXSECT;
     sector   : asector;
     f        : sectfile;
     fc       : binfile;

....

   rewrite(f);
   FOR i := 0 TO MAXSECT DO BEGIN
     sector[i] := chr(get_value_of_next_byte_to_store);
     END;
   f^ := sector; put(f);

or

   rewrite(fc);
   FOR i := 0 TO MAXSECT DO BEGIN
     fc^ := chr(get_value_of_next_byte_to_store);
     put(fc);
     END;

which assumes that get_value_of_next_byte_to_store returns an
integer in the range 0..255.

There may well be some murkiness in the system implementation of
FILE OF char, but the FILE OF asector should have no problems.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Mon, 14 Nov 2005 04:55:40 GMT  
 Can FreePascal generate flat binary files?

Quote:


> .... snip ...

> > I need to have a plain binary file, which can be read by the
> > BIOS (on a floppy at, i think, sector 0). I have everything
> > installed, but it doesn't work.

> The obvious is the correct way to create a binary file in Pascal.
> Don't know about FPC, which I believe is not ISO 7185 compliant.
> How to put that image on the floppy is another (system specific)
> matter.

>    CONST
>      MAXSECT  = 511;

>    TYPE
>      asector  = ARRAY[0..MAXSECT] OF char;

>      binfile  = FILE OF char;    (* assuming char fits in a byte
> *)
>      sectfile = FILE OF asector; (* another possibility *)

>    VAR
>      i        : 0..MAXSECT;
>      sector   : asector;
>      f        : sectfile;
>      fc       : binfile;

> .....

>    rewrite(f);
>    FOR i := 0 TO MAXSECT DO BEGIN
>      sector[i] := chr(get_value_of_next_byte_to_store);
>      END;
>    f^ := sector; put(f);

> or

>    rewrite(fc);
>    FOR i := 0 TO MAXSECT DO BEGIN
>      fc^ := chr(get_value_of_next_byte_to_store);
>      put(fc);
>      END;

> which assumes that get_value_of_next_byte_to_store returns an
> integer in the range 0..255.

> There may well be some murkiness in the system implementation of
> FILE OF char, but the FILE OF asector should have no problems.

Okay.... it's no problem to write the file to the disk, but to compile
the file! Does nobody know how to compile it???

MrSaint



Wed, 16 Nov 2005 18:38:35 GMT  
 Can FreePascal generate flat binary files?

Quote:

>> FILE OF char, but the FILE OF asector should have no problems.

> Okay.... it's no problem to write the file to the disk, but to compile
> the file! Does nobody know how to compile it???

You will have to debug this one of a time. Basically the package is
discarding the prepackaged RTL, and compiles a customized RTL of its own.

Problem is that there are some connections between RTL and compiler that
are version dependant, and the RTL on which this package is based on is
quite outdated.

I can't really test under Dos/Windows at the moment, but during a quick test
in a vmware box I saw that e.g. the objpas.inc code does some pretty ugly
things, which are nowadays illegal. (because they were loopholes that are
dangerous and Delphi incompatible), like accessing SELF in class methods.

One would have to check all code, preferably with the current RTL sources as
a reference, and try to build the code again, debug the batchfiles etc.

This requires some knowledge, and is not easily explained here.



Wed, 16 Nov 2005 18:58:55 GMT  
 Can FreePascal generate flat binary files?

Quote:


> ... snip ...

>> I need to have a plain binary file, which can be read by the
>> BIOS (on a floppy at, i think, sector 0). I have everything
>> installed, but it doesn't work.

> The obvious is the correct way to create a binary file in Pascal.
> Don't know about FPC, which I believe is not ISO 7185 compliant.
> How to put that image on the floppy is another (system specific)
> matter.

It's not that. It's about generating a binary that is in fact an operating
system with FPC. Which requites special link options etc.

However the problem is that therefore the package must have an own
customized RTL that doesn't depend on any operating system (in fact be
somewhat of an embedded kernel.

The problem with the advocated package is that the customized RTL is from
a quite old FPC version.

You know GPC don't you?

It would probably be comparable to taking GPC's 2.0 RTS, customize it so
that it would run without any operating system (would require a 16-bit stub
and some pretty hefty assembler to enter protected mode), and try to compile
those sources using a gcc 3 based modern GPC.

It wouldn't probably work because RTS and compiler mismatch.



Wed, 16 Nov 2005 19:03:31 GMT  
 Can FreePascal generate flat binary files?

Quote:

> >> FILE OF char, but the FILE OF asector should have no problems.

> > Okay.... it's no problem to write the file to the disk, but to compile
> > the file! Does nobody know how to compile it???

> You will have to debug this one of a time. Basically the package is
> discarding the prepackaged RTL, and compiles a customized RTL of its own.

> Problem is that there are some connections between RTL and compiler that
> are version dependant, and the RTL on which this package is based on is
> quite outdated.

> I can't really test under Dos/Windows at the moment, but during a quick test
> in a vmware box I saw that e.g. the objpas.inc code does some pretty ugly
> things, which are nowadays illegal. (because they were loopholes that are
> dangerous and Delphi incompatible), like accessing SELF in class methods.

> One would have to check all code, preferably with the current RTL sources as
> a reference, and try to build the code again, debug the batchfiles etc.

> This requires some knowledge, and is not easily explained here.

hmmm.. is it really so complicated to achive this? This guy from the
page mentioned above did it, too, and he doesn't say anything about such
"problems" anywhere on his page/in the sources/etc. ...

MrSaint



Wed, 16 Nov 2005 20:46:25 GMT  
 Can FreePascal generate flat binary files?

Quote:



>> >> FILE OF char, but the FILE OF asector should have no problems.

> hmmm.. is it really so complicated to achive this? This guy from the
> page mentioned above did it, too, and he doesn't say anything about such
> "problems" anywhere on his page/in the sources/etc. ...

If you obtain the same version compiler as him, it will probably work
out of the box. The newer version compiler is the problem, and the creator
probably never tested a newer compiler.


Wed, 16 Nov 2005 22:20:09 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Converting binary (text file) to compress binary file

2. Reading Pascal-generated PACKED binary w/ C program

3. reading binary with freepascal

4. flat-file datasets

5. Midas flat-file indexes, help

6. Flat-file database w/out BDE?

7. I can't use my paradox database(flat-file) for multiuser

8. TDataSet flat file implementation

9. It's not bad canned meat...

10. Converting ASCII Text file to compress binary file format

11. reading a Unix Generated text file

12. generate .COM Files with TP 7.0?

 

 
Powered by phpBB® Forum Software