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

Freestanding/Baremetal #38

Closed
Immortalin opened this issue Jul 26, 2016 · 5 comments
Closed

Freestanding/Baremetal #38

Immortalin opened this issue Jul 26, 2016 · 5 comments

Comments

@Immortalin
Copy link

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

@norayr
Copy link
Member

norayr commented Jul 26, 2016

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
Copy link
Author

@norayr just standard x86/64

@norayr
Copy link
Member

norayr commented Jul 26, 2016

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
Copy link
Author

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

@dcwbrown
Copy link
Contributor

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] #38 (comment)
[4]
https://github.com/notifications/unsubscribe-auth/ADChoMMdXvB_8gJYj9bRzfsBxrvPauPSks5qZhUbgaJpZM4JVJbz

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

3 participants