vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

Freestanding/Baremetal #38

Closed Immortalin closed 5 years ago

Immortalin commented 7 years ago

Is it possible to add a compiler option for freestanding/bare metal compilation? (Equivalent GCC flag -ffreestanding )

norayr commented 7 years ago

Hey. I was using it for AVR micros, as well as for nmos6502 computer. In the former case avr-libc provided enough options, in the latter - cc65 had already implemented standard library to work on bare metal computer. Which platform do you need it for?

or may be i did not understand the question good enough.

Immortalin commented 7 years ago

@norayr just standard x86/64

norayr commented 7 years ago

Short search did not unveil for me some answers yet.

Does gcc when used with -ffreestanding produce code that can be booted on a standard x86?

Then, which options do you have for further development? I guess you cannot access filesystems? How does standard output work? When you use write(), the code gcc generates already implements the write system call? Can you use stdio with printf() let's say?

Short answer is yes, it is fairly possible to use voc on a bare metal, moreover, that gcc supports it. I just never tried using gcc with that flag, didn't even know about it's existence, and need to experiment. Also, I need to understand better the new build system, which @dcwbrown recently implemented.

Immortalin commented 7 years ago

@norayr this page will give you more information: http://wiki.osdev.org/Bare_Bones

dcwbrown commented 7 years ago

Hi.

As Norayr says, this should be possible. OS access is from a fairly limited range of places:

All operating system requests from user programs and from the run time system should go through either Platformunix.Mod or Platformwindows.Mod. I believe memcpy and strcmp are the only two functions that SYSTEM.h calls directly, and most C compilers should be treating them as built-ins/intrinsics (i.e. they generate inline code rather than calls to library code).

Fundamentally you will need to update configure.c and vishap.make in src/tools/make to add a 'barebones' platform type, and implement Platformbarebones.Mod. These contain things like memory allocation and file access. Some of these are referenced in SYSTEM.h or SYSTEM.c and you will need to provide your own versions (e.g. OSAllocate). Others are used by standard modules like Files.Mod (e.g. OpenRO and OpenRW).

The startup code is generated by the compiler when you pass -m: it generates an 'int main(int argc, char **argv)' that calls all the Oberon run time system initialisation code (mainly type setup) ahead of the actual code of the main module. One approach woul be to provide your own C startup code that calls main.

When voc calls gcc, it looks for an environment variable called CFLAGS and includes its value in the parameters passed to gcc, so it is possible to set and/or override compiler and linker options this way.

I'm sure there will be things we haven't though of, but does that sound roughly like what you would be looking for?

-- Dave.

On 2016-07-26 15:09, Immortalin wrote:

@norayr [1] this page will give you more information: http://wiki.osdev.org/Bare_Bones [2]

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [3], or mute the thread [4].

Links:

[1] https://github.com/norayr [2] http://wiki.osdev.org/Bare_Bones [3] https://github.com/vishaps/voc/issues/38#issuecomment-235279035 [4] https://github.com/notifications/unsubscribe-auth/ADChoMMdXvB_8gJYj9bRzfsBxrvPauPSks5qZhUbgaJpZM4JVJbz