Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

32-bit MSDOS (Announce)

posted by kerravon E-mail, Ligao, Free World North, 03.07.2021, 15:39

> > I decided to take a look at the assembler that
> > was being generated by Free Pascal. I couldn't
> > stop the assemble & link from happening, but
> > I was able to keep the assembler which meant
> > that I could simply redo the process.
>
> Compile with -a -s. It will keep the assembler, and generate a script to
> assemble and link it (ppas.sh or ppas.bat)

Thanks. That worked, just had to clean up stuff.

> > When I saw the generated assembler, ie
> > fpc_write_text_shortstr etc, I had another
> > thought. I don't know what the license is of
> > the code that is currently being linked in to
> > my world.exe,
>
> LGPL+ static linking exception, roughly the same as gcc's libgcc. Nearly
> all linkable code has that license, only the compiler and the IDEs are GPL
> (again, much like gcc)

Ok, so I'd like to produce a public domain
replacement, even if it isn't, for now, as
capable as the copyrighted version.

I've already done that for libgcc (subset).
Only took 27 years.

> > I can produce my own executable
> > consisting of nothing but public domain code,
> > just like my C90-based executables.
>
> C90 is a source standard. Calling binaries "C90" has no meaning.

C90-derived I meant. ie binaries produced
from C90 source code.

> > Unfortunately I don't know how to get my C
> > code to selectively generate "pascal" calling
> > convention, or whether Free Pascal's convention
> > is even that. I tried __pascal and __Pascal.
> > __stdcall does something different.
>
> The calling convention is called "register", used by Delphi and Free
> Pascal, and is somewhat related to stdcall in philosophy. Probably the only
> C(actually C++) compilers that do it are Borland's BCB.
>
> > Is this approach likely to work, or am I
> > missing something?
>
> Yes. Register calling convention support in the gcc compiler.

Ok, thanks.

> Let the Pascal code call C.

I don't know how to do that, and I don't have
control of that anyway, so I just created
some assembler code that will push the registers
onto the stack when I figure out how to get it
to even link.

> > void fpc_initializeunits(void)
> > {
> > return;
> > }
>
> This is an identifier that calls what is equivalent to CTORs (table with
> initialization code of varying units). Without it, initialization code in
> units (including the system unit) wont work.

I don't understand any of that, but I can tell
from the generated code that my "hello world"
won't care.

> > int fpc_get_output(void)
> > {
> > return ((int)stdout);
> > }
>
> Ok. Is afaik a function for thread variable (TLS) reasons.

I don't wish to support threads.

> > void fpc_write_text_shortstr(int handle, char *str)
> > {
> > fputs(str, (FILE*)handle);
> > return;
> > }
>
> This signature doesn't match. shortstrings are complicated beasts. Only
> replace the final call to the OS (in rtl/win/sysfile).

Ok, I sort of fixed that for now.

> > void fpc_iocheck(void)
> > {
> > return;
> > }
>
> Would disables all I/O checking, and among others checking for the
> existence of a file relies on that, so wouldn't work.

Ok. Will need to fix that eventually then.

> If you want any measure of compatibility, replace _only_ the user32 DLL
> calls to msvcrt DLL calls,

Compatibility with what? I want it to be
compatible with PDOS/386 as it is now.

> and let the msvcrt initializing be done using
> normal ways (dll_initialize), and don't go rearranging.

I checked PDPCLIB and there is no such function.

> You didn't link FPC libraries or startup code.

I don't wish to use other people's copyrighted
code in my executable if there is any way around
it. Even if it takes me 27 years.

> I wouldn't go this route, at
> least not for first steps, let Free Pascal generate the linking. You can
> tell it to link .o and .a's by doing {$L myobject.o} in the main program.

I don't wish to change the main program. It is
standard Pascal. It's everything else that has
to change.

> Use the earlier parameters to look at how it calls the linker, and then
> manipulate the source again till it works.

Here's what I have now. I don't know how to
resolve the link errors. It both complains
that the symbols are duplicate and complains
that they are missing.

BFN. Paul.



C:\devel\pascal>type pascals.s
# Public Domain by Paul Edwards

.section .text
.balign 16,0x90

.globl fpc_initializeunits
fpc_initializeunits:
call _fpc_initializeunits
ret

.globl fpc_get_output
fpc_get_output:
call _fpc_get_output
ret

.globl fpc_write_text_shortstr
fpc_write_text_shortstr:
call _fpc_write_text_shortstr
ret

.globl fpc_iocheck
fpc_iocheck:
call _fpc_iocheck
ret

.globl fpc_writeln_end
fpc_writeln_end:
call _fpc_writeln_end
ret

.globl fpc_do_exit
fpc_do_exit:
call _fpc_do_exit
ret

.section .data

.globl FPC_RESOURCESTRINGTABLES
FPC_RESOURCESTRINGTABLES:

.globl FPC_RESSTRINITTABLES
FPC_RESSTRINITTABLES:

.globl FPC_THREADVARTABLES
FPC_THREADVARTABLES:

.globl FPC_WIDEINITTABLES
FPC_WIDEINITTABLES:

.globl INITFINAL
INITFINAL:

.globl PASCALMAIN
PASCALMAIN:

.globl INIT$_$SYSTEM
INIT$_$SYSTEM:

.globl INIT$_$FPINTRES
INIT$_$FPINTRES:

.globl THREADVARLIST_$SYSTEM$indirect
THREADVARLIST_$SYSTEM$indirect:

C:\devel\pascal>



C:\devel\pascal>type pascalc.c
/* public domain by Paul Edwards */

#include <stdio.h>
#include <stdlib.h>

void fpc_initializeunits(void)
{
return;
}

int fpc_get_output(void)
{
return ((int)stdout);
}

void fpc_write_text_shortstr(int handle, char *str)
{
/* fputs(str, (FILE*)handle); */
fputs("fix the registers", stdout);
return;
}

void fpc_iocheck(void)
{
return;
}

void fpc_writeln_end(void)
{
printf("\n");
}

void fpc_do_exit(int x)
{
exit(x);
}

C:\devel\pascal>



C:\devel\pascal>type makefile.w32
# Produce Windows executables
# links with PDPCLIB created by makefile.msv

CC=gccwin
CFLAGS=-O2
LD=ldwin
LDFLAGS=
AS=aswin
AR=arwin
COPTS=-S $(CFLAGS) -fno-common -ansi -I. -I../pdos/pdpclib -D__WIN32__

all: clean worldpas.exe

worldpas.exe: worldpas.o pascalc.o pascals.o
$(LD) $(LDFLAGS) -s -o worldpas.exe ../pdos/pdpclib/w32start.o worldpas.o pascalc.o pascals.o ../pdos/pdpclib/msvcrt.a


# Without "-s", this produces an executable (but can be ignored)
# With "-s" this produces crap (which can be deleted)
# I choose to delete crap
.pas.o:
fpc -a -s $<
rm -fr link*.res
rm -fr ppas.bat
$(AS) -o $@ $*.s
rm -f $*.s

.c.o:
$(CC) $(COPTS) -o $*.s $<
$(AS) -o $@ $*.s
rm -f $*.s

.s.o:
$(AS) -o $@ $*.s

clean:
rm -f *.o worldpas.exe

C:\devel\pascal>



C:\devel\pascal>pdmake -f makefile.w32
rm -f *.o worldpas.exe
fpc -a -s worldpas.pas
Free Pascal Compiler version 3.2.2 [2021/05/15] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Note: Switching assembler to default source writing assembler
Target OS: Win32 for i386
Compiling worldpas.pas
Closing script ppas.bat
5 lines compiled, 0.2 sec
1 note(s) issued
rm -fr link*.res
rm -fr ppas.bat
aswin -o worldpas.o worldpas.s
rm -f worldpas.s
gccwin -S -O2 -fno-common -ansi -I. -I../pdos/pdpclib -D__WIN32__ -o pascalc.s pascalc.c
aswin -o pascalc.o pascalc.s
rm -f pascalc.s
aswin -o pascals.o pascals.s
ldwin -s -o worldpas.exe ../pdos/pdpclib/w32start.o worldpas.o pascalc.o pascals.o ../pdos/pdpclib/msvcrt.a
pascals.o(.data+0x0):fake: multiple definition of `FPC_RESOURCESTRINGTABLES'
worldpas.o(.rodata.n_FPC_RESOURCESTRINGTABLES+0x0):worldpas.pas: first defined here
pascals.o(.data+0x0):fake: multiple definition of `FPC_RESSTRINITTABLES'
worldpas.o(.data.n_FPC_RESSTRINITTABLES+0x0):worldpas.pas: first defined here
pascals.o(.data+0x0):fake: multiple definition of `FPC_THREADVARTABLES'
worldpas.o(.data.n_FPC_THREADVARTABLES+0x0):worldpas.pas: first defined here
pascals.o(.data+0x0):fake: multiple definition of `FPC_WIDEINITTABLES'
worldpas.o(.data.n_FPC_WIDEINITTABLES+0x0):worldpas.pas: first defined here
pascals.o(.data+0x0):fake: multiple definition of `INITFINAL'
worldpas.o(.data.n_INITFINAL+0x0):worldpas.pas: first defined here
pascals.o(.data+0x0):fake: multiple definition of `PASCALMAIN'
worldpas.o(.text.n__main+0x0):worldpas.pas: first defined here
Cannot export FPC_RESOURCESTRINGTABLES: symbol not found
Cannot export FPC_RESSTRINITTABLES: symbol not found
Cannot export FPC_THREADVARTABLES: symbol not found
Cannot export FPC_WIDEINITTABLES: symbol not found
Cannot export INIT$_$FPINTRES: symbol not found
Cannot export INIT$_$SYSTEM: symbol not found
Cannot export INITFINAL: symbol not found
Cannot export PASCALMAIN: symbol not found
Cannot export THREADVARLIST_$SYSTEM$indirect: symbol not found
[worldpas.exe] Error 1

C:\devel\pascal>

 

Complete thread:

Back to the forum
Board view  Mix view
22632 Postings in 2109 Threads, 402 registered users, 393 users online (1 registered, 392 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum