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 #187

Open
Immortalin opened this issue Jul 3, 2016 · 7 comments
Open

Freestanding/Baremetal #187

Immortalin opened this issue Jul 3, 2016 · 7 comments

Comments

@Immortalin
Copy link

Hi, since terra supports pointer arithmetic, can it be compiled freestanding? I am curious if it can be used for OS development .

@0joshuaolson1
Copy link
Contributor

Maybe try the mailing list? Cross-compilation should be possible, and the Lua(JIT) and LLVM runtime dependencies are optional.

@zdevito
Copy link
Collaborator

zdevito commented Jul 15, 2016

The terralib.saveobj function should do what you want. See
http://terralang.org/api.html#saving-terra-code for the details. It allows
you to save Terra code as freestanding C ABI compatible code in various
formats(.so, .o, llvm bitcode, etc.)

On Thu, Jul 14, 2016 at 8:51 PM, Joshua Olson notifications@github.com
wrote:

Maybe try the mailing list? Cross-compilation should be possible, and the
Lua(JIT) and LLVM runtime dependencies are optional.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#187 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAWmGi6pPipTgKl_LYV14DZ2jZy_qVorks5qVwO-gaJpZM4JD4xj
.

@Immortalin
Copy link
Author

@zdevito thanks, I will try it out

@Immortalin
Copy link
Author

@zdevito I tried the following code but encounter some errors:

local intel_x86_target = terralib.newtarget {
  Triple = "i686-pc-none-elf";
  -- CPU = ;
  -- Features = "-ffreestanding ";
  Ffreestanding = true;
}

terralib.saveobj("hello", {target = intel_x86_target})

Errors:

src/terralib.lua:4296: expected terra globals or functions but found table
stack traceback:
    [C]: in function 'error'
    src/terralib.lua:4296: in function 'saveobj'
    .../Development/Lua/hello.terra:8: in main chunk

Also, can you pass arbitrary flags to the llvm from the terralib.newtarget() function?

@xspager
Copy link

xspager commented Jul 28, 2016

I'm doing an experiment with Terra code running of the (U)EFI environment and this works if I link with C and the GNU-EFI lib so, this works:

terralib.includepath = terralib.includepath..";/usr/include/efi;/usr/include/efi/x86_64" 

local C = terralib.includecstring [[
    #include <efi.h>
    #include <efilib.h>
]]

terra terra_main(str: &uint16)
    C.Print(str)
end

terralib.saveobj('foo.o', {
    terra_main=terra_main,
    terra_add=add
}, {"-c", "-fno-stack-protector", "-fpic", "-fshort-wchar", "-mno-red-zone"})`

https://github.com/xspager/hello_efi_from_terra/blob/master/foo.t#L19

I'm looking into rewriting all code in Terra and doing something useful.

@xspager
Copy link

xspager commented Aug 11, 2016

@Immortalin, try:

local intel_x86_target = terralib.newtarget {
  Triple = "i686-pc-none-elf";
  -- CPU = ;
  -- Features = "-ffreestanding ";
  Ffreestanding = true;
}

terralib.saveobj("hello", "", {}, {}, intel_x86_target)

You (may) need to pass the target to includecstring and includec, check: http://terralang.org/api.html#c-backwards-compatibility

@elliottslaughter
Copy link
Member

@xspager Are you still interested in this? If so you could try again on master? I'm trying to figure out which of the older issues are still relevant.

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

5 participants