Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] First pass at compiling most all of C library with OpenWatcom #1911

Merged
merged 5 commits into from
May 31, 2024

Conversation

ghaerr
Copy link
Owner

@ghaerr ghaerr commented May 31, 2024

Compiles almost all the ELKS C library using the OpenWatcom C compiler for compact model. Large, medium and small mode are easily built by editing libc/watcom.inc.

This first version is mostly for OpenWatcom compatibility testing, getting the Makefiles adjusted, and further application linking testing. Discussed a bit in #1443 and #1786.

To use, the OpenWatcom C Toolchain needs to be cloned and built, and then the WATCOM and WATDIR environment variables need to be setup by sourcing a script like the following with the full path to the OpenWatcom binary directory (WATCOM) and top-level directory (WATDIR):

#!/usr/bin/env bash

# Set up Watcom build environment

export WATCOM=/Users/greg/net/open-watcom-v2/rel/bino64 # for macOS
export WATCOM=/Users/greg/net/open-watcom-v2/rel/binl   # for Linux
export WATDIR=/Users/greg/net/open-watcom-v2

add_path () {
    if [[ ":$PATH:" != *":$1:"* ]]; then
        export PATH="$1:$PATH"
    fi
}

add_path "$WATCOM"

echo PATH set to $PATH

After that, to build the C library libc.lib:

cd $TOPDIR            # ELKS top-level directory
cd libc
make -f watcom.mk     # creates libc.lib

@ghaerr ghaerr merged commit 8bbe910 into master May 31, 2024
2 checks passed
@ghaerr ghaerr deleted the watclib branch May 31, 2024 16:15
@tyama501
Copy link
Contributor

tyama501 commented May 31, 2024

Hello @ghaerr ,

Fantastic. Does this also need gcc-ia16?
Since I only have OpenWatcom in Ubuntu on qemu and I don't have gcc-ia16 on that yet.

Thank you.

@ghaerr
Copy link
Owner Author

ghaerr commented Jun 1, 2024

Hello @tyama501,

Does this also need gcc-ia16?

No. Except that it does build the ELKS C library within the $TOPDIR/libc directory of the ELKS repo, so the repo must be cloned at present. In addition, the tool os2toelks will be required, which is normally built during the ELKS tree tools build. This can be done manually however using:

cd $TOPDIR/elks/tools/objtools
cc -W -Wall -O3 -o os2toelks os2toelks.c

and then copying os2toelks to somewhere in your path.

I only have OpenWatcom in Ubuntu on qemu and I don't have gcc-ia16 on that yet.

The idea will be that one can compile ELKS programs without requiring ia16-elf-gcc at all. Full replacement! Some other tools like the above os2toelks may continue to be necessary though. Building the C library in the ELKS repo will produce a $TOPDIR/libc/libc.lib file that may also have to be copied out. I hope to build some compiler scripts that will automatically run the Watcom C compiler/linker with the correct option along with finding the libc.lib C library so that this can be automated. When that's done I'll have it build the required extra tools (like os2toelks) as well.

Thank you!

@toncho11
Copy link
Contributor

toncho11 commented Jun 1, 2024

Would having this compiler help a bit with porting Doom8088 :) ? Maybe the memory requirements will now be easier: medium, large model, far pointers, etc?

@ghaerr
Copy link
Owner Author

ghaerr commented Jun 1, 2024

Yes @toncho11. The OpenWatcom C compiler is an incredible piece of software technology. It has everything we could need as far as supporting small, medium, compact, large and huge models, near/far pointers, fast/specialized register-calling sequences, and the likely ability to run on ELKS itself at some point. It comes with complete source to all tools and its very complete runtime libraries for DOS, OS/2, and 32-bit Linux. I'm quite impressed with it.

That said, there's still quite a bit of work getting the large data model working, and the ASM format is Intel rather than AT&T (ia16-elf-as) compatible. I'm currently in a deep dive trying to get our C library compiled and working in large and compact models. Things are almost working, but the ELKS a.out format isn't suitable for > 64K data or 128K code and will have to be enhanced in order to fully support large data/code. There's also some big issues with floating point, which is that soft floating point emulation will be hard to support. The math library is currently being compiled assuming an 8087 coprocessor. For now, this only affects the basic interpreter and floating point number display.

@tyama501
Copy link
Contributor

tyama501 commented Jun 1, 2024

Hello @ghaerr ,

I needed to source the following script that is included in the linux build watcom,
but I could build libc.
(install dir is binl64 for linux 64 and INCLUDE is also needed)

image

Cool!
image

Thank you.

@tyama501
Copy link
Contributor

tyama501 commented Jun 1, 2024

Oh, should not the header in /usr/bin/watcom/lh be used?
It says stddef.h is missing if I don't set that INCLUDE.

@toncho11
Copy link
Contributor

toncho11 commented Jun 1, 2024

Yes @toncho11. The OpenWatcom C compiler is an incredible piece of software technology. It has everything we could need as far as supporting small, medium, compact, large and huge models, near/far pointers, fast/specialized register-calling sequences, and the likely ability to run on ELKS itself at some point. It comes with complete source to all tools and its very complete runtime libraries for DOS, OS/2, and 32-bit Linux. I'm quite impressed with it.

That said, there's still quite a bit of work getting the large data model working, and the ASM format is Intel rather than AT&T (ia16-elf-as) compatible. I'm currently in a deep dive trying to get our C library compiled and working in large and compact models. Things are almost working, but the ELKS a.out format isn't suitable for > 64K data or 128K code and will have to be enhanced in order to fully support large data/code. There's also some big issues with floating point, which is that soft floating point emulation will be hard to support. The math library is currently being compiled assuming an 8087 coprocessor. For now, this only affects the basic interpreter and floating point number display.

Yes at the end of the https://github.com/FrenkelS/Doom8088 readme it says:

It's also possible to build a 16-bit version with Watcom: Run setenvwc.bat followed by compwc16.bat.

@toncho11
Copy link
Contributor

toncho11 commented Jun 1, 2024

Excellent work @ghaerr !!!

@ghaerr
Copy link
Owner Author

ghaerr commented Jun 1, 2024

Hello @tyama501,

It says stddef.h is missing if I don't set that INCLUDE.

Sorry, I'm fixing that right now - long story short it is getting complicated mixing header files between IA16 and Watcom compilers. I should have a PR posted shortly. The WATDIR= environment variable does need to be set though to the base of the OpenWatcom repo (not the bin installation locations).

Oh, should not the header in /usr/bin/watcom/lh be used?

No, the "lh" headers are for Linux, but they can't be properly used for ELKS because all the Watcom headers for Linux assume 32-bit integer (and other) sizes and so are incorrect. We have to use the DOS headers but the application programs will always use the ELKS headers, with a few exceptions noted below. The INCLUDE variable is set in libc/watcom.inc should not be /usr/bin/watcom/lh, but rather $WATDIR/bld/hdr/dos/h.

That said, some applications will need "standard" headers that are not provided by ELKS C library. These include stddefs.h, stdarg.h, and a few others. The stdint.h header is usable but is redirected by the ELKS stdint.h. I will clarify more on this after I have it all sorted out.

We also cannot use any of the system call wrappers OpenWatcom has already built for DOS, OS/2 or Linux, as none of these will work correctly for ELKS. I'm also working on that now.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants