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

Porting CM3 to Haiku x86 32 bits #16

Open
DKnoto opened this issue Apr 2, 2017 · 38 comments
Open

Porting CM3 to Haiku x86 32 bits #16

DKnoto opened this issue Apr 2, 2017 · 38 comments

Comments

@DKnoto
Copy link

DKnoto commented Apr 2, 2017

Hi,

I have been using Haiku for a long time and decided to port CM3 to this system.
In the first step I reduced the number of packages from the pkginfo.txt file to the
minimum necessary. So make-dist.py script makes CM3 distribution seamlessly.
The whole thing I prepared on Linux Fedora 25 on AMD64.
I read carefully the file doc/notses/porting.txt and performed the following steps:
a) I added the new target I386_HAIKU to Target.i3;
b) I added a buffer size to Jumpbuf_size, 32 bytes as 8 x address size;
c) I rebuilt CM3 with the make-dist.py script;
d) I have installed the reworked CM3-min distribution on the host system;
CM3 --version:

Critical Mass Modula-3 version d5.10.0
last updated: 2016-10-05
compiled: 2017-04-01 14:38:59
configuration: /opt/cm3-devel-5.10.0-dkk/bin/cm3.cfg
host: AMD64_LINUX
target: AMD64_LINUX

e) I added the entry "I386_HAIKIU": "i586-pc-haiku" to the file m3-sys/m3cc/src/platforms.quake;
f) I added the entry "I386_HAIKU" : "-with-gnu-as -with-gnu-ld" and added "I386_HIAKU" in line 475 in the file m3makefile in the same directory;
g) I tried to run the command: cm3 -DM3CC_TARGET=I386_HAIKU.

After that I have got the following message:

checking for clock_t... yes
checking if mkdir takes one argument... no
*** Configuration i586-pc-haiku not supported
Makefile:3413: recipe for target 'configure-gcc' failed
make: *** [configure-gcc] Error 1
"/run/media/dknoto/ARCHIWUM/Oprogramowanie/Critical.Mass.Modula-3/cm3-d5.10.0-20161121/m3-sys/m3cc/src/m3makefile", line 332: quake runtime error: exit 2: cd ../AMD64_LINUX-I386_HAIKU && make MAKE="make -j4 " AUTOCONF=: AUTOMAKE=: LEX='touch lex.yy.c' MAKEINFO=: configure-host
`--procedure-- -line- -file---` `exec -- <builtin>` `m3cc_Run 332 /run/media/dknoto/ARCHIWUM/Oprogramowanie/Critical.Mass.Modula-3/cm3-d5.10.0-20161121/m3-sys/m3cc/src/m3makefile` `include_dir 543 /run/media/dknoto/ARCHIWUM/Oprogramowanie/Critical.Mass.Modula-3/cm3-d5.10.0-20161121/m3-sys/m3cc/src/m3makefile` ` 5 /run/media/dknoto/ARCHIWUM/Oprogramowanie/Critical.Mass.Modula-3/cm3-d5.10.0-20161121/m3-sys/m3cc/AMD64_LINUX/m3make.args`
Fatal Error: package build failed

I tried manually to run gcc47 compiling commands but I did not go much further.

@darko20
Copy link
Contributor

darko20 commented Apr 2, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 2, 2017

I think that gcc47 is the default backend in CM3.

@darko20
Copy link
Contributor

darko20 commented Apr 2, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 2, 2017

Ok. I use gcc-5.4 from Fedora 25. The AMD64_LINUX version compiles correctly with this compiler.

@DKnoto
Copy link
Author

DKnoto commented Apr 2, 2017

Sorry, now I have gcc-6.3.1.

@DKnoto
Copy link
Author

DKnoto commented Apr 2, 2017

I checked again. The command "cm3 -DM3CC_TARGET=AMD64_LINUX" executes correctly.

@jaykrell
Copy link
Contributor

jaykrell commented Apr 2, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 2, 2017

I have a fog in my head :(

@jaykrell
Copy link
Contributor

jaykrell commented Apr 3, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 3, 2017

Using C backend we have a Modula-3 translator but not a compiler?

I would like to learn how to prepare gcc to cm3 but I need time for it :(

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

Do you think the "level" is key?

Generally yes. If the Modula-3 is to be a system language then it must allow gnerating the machine code to the raw machine without the help of the C compiler.

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

In addition, redundant levels in the compilation process are unnecessary load.

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

Jay understands your arguments and in this particular case I guess.
Unfortunately, this approach makes it impossible to build an operating system in pure Modula-3.

@olaf-wagner
Copy link
Contributor

olaf-wagner commented Apr 4, 2017 via email

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@RodneyBates
Copy link
Contributor

RodneyBates commented Apr 4, 2017 via email

@RodneyBates
Copy link
Contributor

RodneyBates commented Apr 4, 2017 via email

@RodneyBates
Copy link
Contributor

RodneyBates commented Apr 4, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

@olaf

As far as I know that has already been done once.
I'm not aware if it is still available anywhere though.

I remeber, it was SPIN OS.

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

Thanks a lot for the comments. Next weekend I will try to find the cause of this error. The ./configure script works fine when I run it manually.

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

BTW. Why did not you try a development path like FPC + Lazarus?

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 4, 2017

HOST=AMD64, Linux, gcc-6.3.1
TARGET=i586-pc-haiku
This gcc47 support Haiku, properly from 2.95 to 5.4.

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@jaykrell
Copy link
Contributor

jaykrell commented Apr 4, 2017 via email

@DKnoto
Copy link
Author

DKnoto commented Apr 9, 2017

Hi Jay,

I did what you advised. Gcc-4.7 with CM3 has the i586-pc-haiku target but unfortunately this setup does not work:
$ ../gcc-4.7/configure --host=amd64-linux --target=i586-pc-haiku
...
$ make
...
*** Configuration i586-pc-haiku not supported

Haiku uses gcc-5.4.0, can you approximate how much work to do to build CM3 based on this backend?

@jaykrell
Copy link
Contributor

jaykrell commented Jul 4, 2017 via email

@jaykrell
Copy link
Contributor

I know that people feel somehow unsatisfied with the C backend.
It does not mean that Modula-3 is somehow not a real programming language.
You can write a backend in Modula-3. There is one in the system. The NT386 backend writes out .obj files.
But then we still depend on the system linker. And debugger. And kernel.

And the other backend so often discussed, based on GCC, also doesn't really do codegen in Modula-3 either.
It is the GCC backend, written in C/C++, and a custom frontend, also in C/C++, that reads the Modula-3 IR from files.
The Modula-3 in this system "stops" at writing IR to files.
It still does a lot. It still does all the source parsing and type checking.
So there is still a ton of C/C++ code involved.

Whether or not there is an extra intermediate represenation hop as textual C code, does not matter.

The C backend has successfully run on a number of systems and imho proven its value.
The gcc-based backend has some advantages, but it is much more work to maintain, and not worthwhile imho.
It was last updated to gcc 4.7.

It is true we could write our own smaller faster backend, producing moderately decent code.
Again, we have one such. We should port it. But for great breadth of target support and speed of bringup, C is good.
Sorry to belabor this point so many times through the years.
Now I need to update the C backend slightly and bring up some new targets rapidly. :)

@jaykrell
Copy link
Contributor

And yeah, someone should try the C backend on Haiku.

@mikanystrom
Copy link
Contributor

mikanystrom commented Feb 24, 2021 via email

@jaykrell
Copy link
Contributor

I have a feeling, though I don't know, that the C compiles
about the same as m3cc.

I think they both have problems because of garbage collection.

I have a few ideas to speed it up.

  • Do not always include setjmp.h. Only if the file has a try.

  • Run:
    gcc -c foo.c bar.c
    instead of:
    gcc -c foo.c
    gcc -c bar.c

This is really the easy thing to do and will help.

  • Possibly being really clever wrt incrementality and
    whichever files need recompile, concat them to one:

touch foo.m3 bar.m3 abc.m3
gcc -c foobarabc.c
touch foo.m3 bar.c
gcc -c foobar.c

but I don't see how that'd really work, when you link.

Unless, well, um.
Every function name at the C layer has a version number at the end.
Every time you incrementally compile, you increment that version.
Every call goes through a pointer. Ouch.
Every time you compile, incrementally or not, you generate a file
with all the function pointers, w/o versions on the pointer names,
pointing to a carefully chosen versioned name.

And then you link foobar.o foobarabc.o all-the-function-pointers.o

For the data also. Kinda complicated, but it'd by running the C compiler
only once (or twice) for each (incremental) compile of a library.

The gcc still works, yes, for older targets.
But now I want ARM64_{NT,LINUX,DARWIN} and RISCV64_LINUX. :)
And the C backend gave us AMD64_NT and I believe ARM32_LINUX.
It also works well to cross/bootstrap from NT. I don't have to build gcc there. :)

@RodneyBates
Copy link
Contributor

RodneyBates commented Feb 24, 2021 via email

@jaykrell
Copy link
Contributor

Unfortunately, this approach makes it impossible to build an operating system in pure Modula-3.

No it does not.
It does not matter what the compiler is written in.
Unless you consider the compiler to be part of the operating system.
But then, how about the BIOS and the boot loader?
Or the hypervisor if you are using a virtual machine?
Or the router your network traffic is going through.
You are always going to be running C and C++ somehow.
That doesn't mean you cannot use other languages or detract from their use.

As well, it should be noted, it doesn't translate to idiomatic C.
Yet another hit on ease of debugging.

No it does not. There are line directives. You step through the Modula-3.
The ugly C does not matter. Just like the ugly assembly does not matter.

@jaykrell
Copy link
Contributor

The answer is to use the C backend.
It is now to the point where the output is the same across many targets.
I mean, run boot1.py I386_LINUX and copy the result to Haiku and see if it builds and runs. It quite likely will.
Someday maybe I will try.
I guess keep this open until then.

@VictorMiasnikov
Copy link
Contributor

I see in #833 comment #833 (reply in thread)

I ( DKnoto) have full version of CM3 on Haiku! Warnings still exists.

I.e. we can can close this issue?

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

No branches or pull requests

7 participants