-
Notifications
You must be signed in to change notification settings - Fork 108
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
C compiler #1443
Comments
Hello @stevexyz, Thanks for your interest in ELKS. A few years back, the project switched from using bcc to ia16-elf-gcc to build the kernel and all the applications. One of the big reasons was the lack of support for 8086 segmented architecture linker and compiler options that are not present in bcc (or tcc). Unfortunately, gcc is way too large to be able to be included in ELKS runtime, so there isn't a way for ELKS to be self-compiled, but this has been viewed as a reasonable tradeoff, all things considered. I'm a fan of tcc, but the question is, given the limitations of segmented-mode 8086, what purpose would it serve, doing the work to get a self-hosted compiler running, when none available contain the features required to build the current kernel and all of the applications? Thank you! |
To me a C compiler is the base of a complete Linux (Unix) system... |
Hi @stevexyz -
Here's the the thing: ELKS is not a complete Linux or Unix system. Like the name says, it's intended for embedded systems. Embedded systems have limited resources and are rarely if ever selfcompiling. Of course our vintage PCs aren't embedded systems, but they have very limited resources. And - as @ghaerr also alluded to - it just doesn't make sense to have that ambition. Possibly fun, but not useful. Think about it - what we have today is a cross development environment with I have Venix running on one of my machines, a 286/12. It's a complete Unix system. It can compile itself if I had full sources, and I've done a lot of development on it. In the mid 80s and recently. It has
Yes, the compilers you're referring to RUN on the segmented architecture, but they support only parts of it – the small, maybe medium memory model, that's all. They have very limited options and support-tools (like
ELKS has come a long way, the last few years in particular. Your contributions would be very welcome. Even a native C-compiler. It's your time and your choice - and you'll get plenty support from the group regardless of whether the target tool/application is for the few or the many. --M |
Not for self-compiling but to make small debug program, it is nice to have a small compiler on ELKS. I now uses the basic to peek memory or read ports on the real PC from the background but sometimes wants to do a little more complicated. |
As already mentioned by @tyama501 it was not to be used to self compiling, even if it would have been a nice thing. And especially for starting, if there is something that is ready to be used, doesn't really matter if it is supporting just a limited memory model, but at least you can compile and run some programs on the system without always access another computer. For now I've other (unfortunately too many) projects going on and I'll stay on the window looking the ways ELKS will grow up, but in the future if it will still be not developed maybe I'll give it a try! In the meantime keep up the good work and happy hacking! |
I thought more deeply about exactly what is entailed when someone says "I'd like a C compiler" to run native on ELKS. As @tyama501 and @stevexyz mentioned, it would be nice to be able to at least just compile some programs from within ELKS. In order to do that, we'd need the following:
After all this, there are all the issues that @Mellvik brings up, which include problems associated with having no All in all - I have agree with @Mellvik that such a project is not really what people think of "having a C compiler" for ELKS. On another note, I was thinking about some C interpreters that might be able to provide fast execution of simple C programs, such as the C in 4 functions compiler. It is very cool with a small code size, and allows for calling out of various functions like Thank you! |
Hello @stevexyz, @ghaerr, @tyama501, I suspect that the Amsterdam Compiler Kit might be a good candidate for an ELKS-hosted C compiler, though I have not really got around to working on such a thing, and it probably needs a fair amount of effort. I believe ACK used to be the standard toolchain for Minix — including Minix/8086 — and besides, it is written to be able to run on small systems. Thank you! |
Seems to me that https://github.com/alexfru/SmallerC would be a very good start: seems easy enough and producing already 16 bit x86 code in various models, and with self compilation the ported compiler if it will produce the binary elk file. Maybe the author itself would adapt it if requested and specification of the binary file are given: if it is considered good we can try to ask. PS: @ghaerr I had a look at c in 4 functions, and while being an amazing exercise of minimization, seems really not easy to port to minimal memory systems for the way it has been designed |
just as comment, I tried to play with old "ACK for Minix" from https://web.archive.org/web/20070910201015/http://www.laurasia.com.au/ack/index.html#download on Minix i86 (not i386) qemu VM. Well, it ran out of memory :) trying to compile itself under existing 'cc' compiler there. |
Also, Portable C Compiler website seems to be down (and web archive does not have latest copy) so here I found slightly updated (2021) copy of code https://github.com/matijaskala/pcc There seems to be some code related by i86 generation by Alan Cox. Also, someone (Eric J. Korpela) looked at lcc-8086 but not get very far |
Hello @Randrianasulu and @tkchia, Thank you @Randrianasulu for the links to PCC, I'll take a look at it. Same for LCC-8086, that work looks extremely old but could be worthwhile. Of course, it would probably be a good idea to consider only using ANSI-capable (vs K&R) compilers, given where most C code is at today.
It's probably not needed that the compiler be able to compile itself under ELKS (or MINIX), so that's OK. I am not familiar to what degree ACK has been updated to any ANSI standards, and/or long/long log/float support etc. In the case of running on ELKS, we now have the issue that some portions of the C library may be using some @tkchia, you had mentioned you're possibly somewhat familiar with ACK, would that be a version similar to that used for MINIX as described above, or has there been more work done updating it, to your knowledge? Thank you! |
@ghaerr I found little something supposed to help with backtranslating ANSI C to older dialect: Also, may be Xenix (286) a.out variant can be used to get some idea how multiple segments were supported. https://ibcs-us.sourceforge.io/ |
Hello @ghaerr,
I have not yet done a comparison of the "laurasia" copy of ACK, and David Given's current ACK tree — I hope to do that soon. At the moment I am more familiar with Mr. Given's source tree (since I have been working on it a bit). Some impressions:
Thank you! |
slightly newer ackpack for minix (1.1.2) weirdly it comes as tar.tar. I only get file by downloading it via browser, not via wget. Same source should still be in Minix3 git, but a bit obscured because it was deleted years ago ... info from |
so, there was another compiler (c86 ?) but license prohibit commercial use. https://github.com/plusk01/8086-toolchain/tree/master/compiler |
https://web.archive.org/web/20150908032106/http://homepage.ntlworld.com/itimpi/compsrc.htm - so it was named c68, too ... |
ah, it was not complete compiler, just c to asm (nasm in this version) compiler. It needed cc (main driver), ld86 (linker), c preprocessor (it seems for Psion 3 they tried Decus cpp, available in X11R3 distribution - not tried to build it yet). So, some sources are newer in C68 (for QDOS - mk68k/ Sinchlair QL system) but part of older EPOC sources still live at older site: http://web.archive.org/web/20010414060410/http://www.itimpi.freeserve.co.uk/cpocdown.htm#SOURCE |
Seems has already a lot of options, among them the ones for 8086 specific:
|
so, I have something horribly broken, but it makes .o files! https://github.com/Randrianasulu/c86 make on linux/termux should give you some binaries. |
@Randrianasulu : it is almost certainly still not GPL-compatible though. |
seems to be very detailed document about c68 by author (I tried to send email to him, but no idea if old email address still works) |
https://qlforum.co.uk/viewtopic.php?t=2112 - may be he has new email, forwarded to it too |
just at the beginning of the C68 QL manual it says that it is Public Domain (even with capitals): INTRODUCTION |
Hello @stevexyz, I mentioned this because @Randrianasulu stated that the source files themselves seem to prohibit commercial use. And I see that Thank you! |
little aside (feel free to hide) but MAME got Psion 3 emulation inmore working state lately https://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=121869&page=3 |
also faucc (286 & 386 codegen only?) https://gitlab.cs.fau.de/faumachine/faucc/-/commits/master EDIT: sadly it does not compile faumachine's new bios :( also, no FP. so, not very useful? |
Just a sidenote, but I think NASM does support ELKS a.out format. LCC port might use NASM too. Anyways, last time I looked into ELKS binary format it had some limits on DATA and CODE segment sizes similar to Minix 1. Is that still the same? What are the limits? Is it now possible to make something like large memory model executables in MS-DOS with GCC-iA16? |
I'm not sure about whether NASM supports a 16-bit MINIX a.out format or not. Does NASM support ELF output? If so, the binary could likely be converted to ELKS a.out format using our own The ELKS toolchain and kernel currently offer the ability to create and run small (64K code, 64K data) and medium (128K code, 64k data) model programs. Access to a larger data segment is possible through C |
I took a peek at NASM. It doesn't support Minix/ELKS directly. It supports as86 obj files though. They could be then linked with ld86 into elks binary, I think. My memory is a bit murky on this. Thanx for the info on memory model support ghaerr. Much appreciated. |
Oh, you've got c86 running? That's great! How big is the executable? Can you run size and list the code and data sizes separately? This will give a first estimate of what we're looking at to port. I wonder if I can get it running on macOS.
It looks quite complete (and large). The ASM output looks super. Having a C compiler that outputs ASM could help by expanding the choices for assembler and linker. |
c86 executable for Linux ELF 64-bit (running on my debian) is 215744 bytes. Considering we can wipe out all the 386 code generation, it seems there is hope. edit: stripped size is 188376 bytes
|
@rafael2k, I just cloned your 8086-toolchain repo. I'm on macOS. Went to compiler/ and typed "make", and bin/c86 was built without modifications, only a few warnings, and runs! Very nice. I then noticed that assembler/ is missing, I assume renamed nasm/. Typed "make" and I see its now using OWCC for the cross compile. It might be nice to keep an assembler/ directory so that a host version of it can be built. I will have to go back to @hintron's version to play around with the complete system for the time being. On my system c86 is 180k text and exactly 32k data, interesting if not a coincidence. I'll pull down the other repo and see if I can get the entire system running on macOS to play with and learn more about it. Since it seems the upstream 8086-toolchain distribution was put together for a CS class, it might be interesting to check out those class files and see what the C programs look like, as well as which linker is being used. |
It just compiled on ELKS. |
It seems the executable is made to be loaded in an emulator for the class. |
You mean that there is no link phase, the NASM output relocatable modules are loaded by the emulator? I'm wondering what format NASM is outputting for that use. It is possible that the emulator loader code could be used as a linker.
That's great! It seems the compiler is very straightforward C. I was able to get it running on macOS by deleting the -m32 flags, but I'm having problem getting it to accept much C input without complaining heavily. I also don't know where its looking for header files during compilation. I pulled down the upstream repo and got NASM in assembler/ to compile and link by discarding -m32 as well. The emulator/ is in C++ and won't compiler without errors using -m32, and macOS doesn't support 32-bit executables anymore. |
The the class it is used bin output: https://web.archive.org/web/20210508035736/http://ece425web.groups.et.byu.net/stable/labs/BuildProcess.html And the is a simple clib for the class (prolly the clib was homework), for DOS I think: |
Thanks @rafael2k. This is very exciting, having a C compiler running on ELKS. It will be interesting to see what it can do!!! I notice that you're getting signal handler kernel error messages from C86 and NASM. I'll look into getting that fixed. |
There is an issue - there is no C preprocessor. In the class course it just mentions "use cpp before using c86". |
Well, that's kinda huge. It likely means we'll need a CPP/C/ASM compiler wrapper, just like UNIX v6, etc. The good news is that I have one that should work as part of my NCC project. There are a number of C preprocessors out there, many of which I would think we could get working on ELKS, except now that's another big item on the list. The important part will be selecting one that is conformant. In the meantime, I think it's still very interesting to continue seeing what the 8086-toolchain C compiler will and won't do with regards to running out of memory, etc. It would be good to allow your tree to compile both ELKS and host versions, perhaps by using seperate Makefiles and usage of My NCC project also has a C preprocessor but it's not standalone. However, I suppose it might be possible to remove the x86_64 code generation and have it run in cc -E form only. It's not yet worth chasing down a CPP until it is determined how well the C compiler runs on ELKS with pre-preprocessed files though, I would think. |
from memory c68 used "Decus cpp" still living in X11R3 archive ... and that compiler was running on x86-ish Psion handheld with segmented model so 64kb segments were very much target constrain ... But I guess thread grow so large it all scrolled away. nice to see progress anyway.. |
I'm using dev86 cpp. It seems be working ok. I added to the 8086-toolchain repo: |
Nice, good news about using dev86 cpp! I'm running a host version of c86 for now, and giving it preprocessed input using |
More information on CC386 v4.2.0: https://ladsoft.tripod.com/cc386_compiler.html Looks like it was maintained for quite a while into 2017 and then replaced by Orange C. There are apparently Win32 and DOS 16-bit versions. |
No idea. But now I'm running it with "-m16". |
What about dev86 linker? Is that of any use? I think I successfully cross-compiled it (or at least one of its earlier versions) using dev86/bcc a decade or so ago and it ran on ELKS without any problems. I think assembler cross-compiled easily, too. This, of course, doesn't work with ELF. Only with a classic Minix format (I mean older than V3). |
Hi Bocke. Indeed, I thought about ld86, but the problem is that I don't think it can link any of the nasm output formats. If ld86 is useful, then I think it would be relatively easy to port. |
Just double checked - nasm has indeed as86 output. |
I have opened a new issue #2112 for all comments regarding getting @rafael2k's 8086-toolchain (C86, NASM, CPP, LD) running on ELKS. Please post there for details on that specific port, as this issue is getting quite long and should pertain to discussions about general C compilers and their feasibility for running on ELKS. |
Fuzix C compiler does not generate code for 8086 (but it does for 8080 and 8085), and seems also an interesting option if it gets a 8086 backend. |
It's got most of an 8086 backend written but not tested out. Need to finish the assembler first |
That is really good news @EtchedPixels ! Yay! |
For the reference, another interesting compiler which can generate 8086: |
Native ELKS C tool chain starting to work! |
Maybe I'm wrong (I just tried to install elks on an original PC IBM XT), but seems to me that no C compiler is included inside elks (I've found the basic language interpreter though), while I think that's one of the basic thing of every Linux system.
If that's the case, I understand that a mammoth GCC might not really fit the project, but maybe the small and powerful tcc might be an option!
The text was updated successfully, but these errors were encountered: