Coder Social home page Coder Social logo

nativeos / homebrew-i386-elf-toolchain Goto Github PK

View Code? Open in Web Editor NEW
87.0 87.0 18.0 174 KB

Homebrew formulas for buildling a valid GCC toolchain for the i386-elf target.

Ruby 100.00%
cross-compiler gcc gcc-cross-compiler homebrew homebrew-tap i386 i386-elf i386-elf-gcc kernel linuxbrew linuxbrew-tap macos osdev toolchain

homebrew-i386-elf-toolchain's Introduction

NativeOS

NativeOS is a hobbyist kernel and operating system for the x86 platform. It is designed as a project to learn more about how the x86 processor work and how operating systems work. My intention is purely educational. The source code is open in the hope that it helps other people too.

Roadmap and contributing to the project

This project has no public roadmap. This means that I'm not disclosing what I'm working on when I'm working on this project. This is intended at this moment for this project because the project is not mature or stable enough and is still under development.

My issue and pull request policy is clarified on CONTRIBUTING.md. I'm not accepting pull requests at this moment. See the document to read why. Issues are still open and covered by the Code of Conduct. See CODE_OF_CONDUCT.md for details.

Building the NativeOS Kernel

To build the kernel image (in other words, the program that will run when the computer starts up), you will need to install the LLVM compiler if you don't have it already. NativeOS switched to LLVM because it has support for foreign ABIs (such as i386-elf in an x86-64 macOS) out of the box without requiring to setup a cross-compiler.

GNU Make is also required to run the Makefile file.

Python 3 is also required to run the kcons tool, which is used to generate the Makefiles.

Windows NT is not a supported platform and there may be bugs. Users of Windows NT are encouraged to setup a POSIX system such as MSYS or Cygwin, or use the Windows Subsystem for Linux if available.

Picking a profile

Profiles are kernel compilation settings. A profile causes a specific subset of source code files to be compiled into the kernel image, and some specific optional settings to be enabled.

At the moment, the repository provides the I386 profile, to build a basic 32 bit kernel image for the i386 architecture. The settings file for this profile is at conf/I386.

Building a profile

To build a profile, you can use the kcons script. kcons will parse the profile and the associated files and generate a Makefile that can be used to build the kernel. Call tools/kcons providing the path to a profile file as a parameter.

$ tools/kcons conf/I386

This will generate a subdirectory named after the profile name inside the compile/ directory. In this directory, a Makefile will be present. Use it to build the kernel image:

$ cd compile/I386

Generating a depfile is recommended in order to have the object files recompiled whenever the imported source code changes:

$ make .depend

Then, proceed to build the kernel.

$ make kernel

Or, to make things faster,

$ make -C compile/I386 .depend kernel

The NativeOS kernel file is a binary in the ELF format. It supports the Multiboot specification, so it can be deployed in any machine using a bootloader capable of loading Multiboot binaries, such as GNU GRUB, SYSLINUX or Limine.

Running the profile in QEMU

For the i386 platform, QEMU supports a special flag called -kernel, where the path to a Multiboot executable file can be given. QEMU will treat the given file as if it was booted via a CD-ROM. This allows to quickly test the executable file without having to build CD-ROMs:

$ make -C compile/I386 qemu
qemu-system-i386 -kernel kernel -serial stdio

Debugging the profile in QEMU

QEMU also supports using the gdbserver protocol, so it is possible to connect QEMU with GDB in order to debug the running processor. There is a gdbinit file in the conf directory to help with the process.

$ make -C compile/I386 qemu-gdb

(In another terminal:)

$ gdb -x conf/gdbinit.I386
> continue

Shortcut

It is also possible to configure and build a kernel image profile using the root Makefile. Provide the profile name as the PROFILE parameter and it will run all the commands above.

$ make build-kernel PROFILE=I386

Creating a CD image

You can use some of the GRUB Command Line Tools to generate ISO files. There is already a rule in the Makefile file to generate a CD-ROM using GRUB.

You need the GRUB Command Line Tools installed with support for the i386-elf platform. If you are using GNU/Linux, you probably already have support for that platform, but otherwise you might have to install it to your system. Take protections to prevent GRUB to running on your host system if that is not practical for you. The grub-mkrescue program should be able to run in your command line.

GNU xorriso is additionally required to generate the ISO file.

To create a NativeOS ISO image, run the following command, specifying the name of a previously built profile as the PROFILE variable:

$ make cdrom PROFILE=I386

Windows NT, macOS and BSD users can install the GRUB Command Line tools by following the instructions given in the following address: http://wiki.osdev.org/GRUB_2#Installing_GRUB2_on_Mac_OS_X. (Instructions are the same for Windows).

NOTE: You'll be getting the GRUB Command Line Tools here. This is definitely NOT the same as installing the GRUB Bootloader on your host PC, although the command line tools allow you to do that, so care must be taken in order to avoid running any dangerous command.

Running NativeOS

A virtual machine is the safest way for running and testing NativeOS. I don't recommend running this on your host PC unless you know what you are doing and you have inspected the source code. Also, take a look at the disclaimer below before attempting to run anything that you could regret later.

The Makefile already has some rules to run the NativeOS ISO file with QEMU. It is even possible to run QEMU in debug mode and to remotely attach GDB in order to debug the kernel image.

Run the following commands:

$ make qemu PROFILE=I386      # Run qemu-system-i386
$ make qemu-gdb PROFILE=I386  # Run qemu-system-i386 in debug mode

For more information on GDB debugging with QEMU, see the QEMU manual or the following article: http://wiki.osdev.org/QEMU.

License and disclaimer

Copyright (C) 2015-2021 Dani Rodríguez

NativeOS is licensed under the terms of the GNU General Public License v3. See the COPYING file for more information. Old NativeOS files will probably not have the GPL header on it. I'm working on that.

NativeOS is provided AS IS with no extra support. Working with kernels and OS and bootloaders is fun, but I'm not resposible for anything wrong you do with it. If you break your hard drive or your computer because of using the wrong command, that is not my fault.

homebrew-i386-elf-toolchain's People

Contributors

danirod avatar guilleiguaran avatar itztravelintime avatar rustin-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

homebrew-i386-elf-toolchain's Issues

[BUG] Doesn't compile on M1

Last 15 lines from /Users/user/Library/Logs/Homebrew/i386-elf-gcc/02.make:
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [lto1] Error 1
make[1]: *** Waiting for unfinished jobs....
Undefined symbols for architecture arm64:
  "_host_hooks", referenced from:
      c_common_no_more_pch() in c-pch.o
      toplev::main(int, char**) in libbackend.a(toplev.o)
      gt_pch_save(__sFILE*) in libbackend.a(ggc-common.o)
      gt_pch_restore(__sFILE*) in libbackend.a(ggc-common.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cc1plus] Error 1
rm gcc.pod
make: *** [all-gcc] Error 2

Do not report this issue to Homebrew/brew or Homebrew/core!

Failed to brew install i386-elf-gcc on M1 Mac

I just tried to install the i386-elf-toolchain. Installing binutils seemed to proceed normally, however I ran into a link failure when trying to install i386-elf-gcc

I'm running this on a Mac M1 and just installed XCode 13.2.1
This is what I did and got.

-> % brew install nativeos/i386-elf-toolchain/i386-elf-gcc
==> Downloading https://ghcr.io/v2/homebrew/core/libmpc/manifests/1.2.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libmpc/blobs/sha256:658a1d260b6
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
######################################################################## 100.0%
==> Installing i386-elf-gcc from nativeos/i386-elf-toolchain
==> Installing dependencies for nativeos/i386-elf-toolchain/i386-elf-gcc: libmpc
==> Installing nativeos/i386-elf-toolchain/i386-elf-gcc dependency: libmpc
==> Pouring libmpc--1.2.1.arm64_monterey.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libmpc/1.2.1: 12 files, 415.7KB
==> Installing nativeos/i386-elf-toolchain/i386-elf-gcc
==> ../configure --prefix=/opt/homebrew/Cellar/i386-elf-gcc/11.2.0_1 --target=i3
==> make all-gcc
Last 15 lines from /Users/kartikaiyer/Library/Logs/Homebrew/i386-elf-gcc/02.make:
      gt_pch_save(__sFILE*) in libbackend.a(ggc-common.o)
      gt_pch_restore(__sFILE*) in libbackend.a(ggc-common.o)
      gt_pch_save(__sFILE*) in libbackend.a(ggc-common.o)
      gt_pch_restore(__sFILE*) in libbackend.a(ggc-common.o)
      toplev::main(int, char**) in libbackend.a(toplev.o)
      toplev::main(int, char**) in libbackend.a(toplev.o)
ld: symbol(s) not found for architecture arm64
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [lto-dump] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [lto1] Error 1
rm gcc.pod
make: *** [all-gcc] Error 2

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
  https://github.com/nativeos/homebrew-i386-elf-toolchain/issues

Reports that Command Line Tools are too outdated

Hello , I'm running Mac OS Monterey 12.2.1 with Xcode 13.2.1 installed.
I added the tap and when I try to install binutils I get the following

> brew install nativeos/i386-elf-toolchain/i386-elf-binutils                   ~/[email protected]

Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.

==> Downloading https://sourceware.org/pub/binutils/releases/binutils-2.37.tar.xz
Already downloaded: /Users/kartikaiyer/Library/Caches/Homebrew/downloads/09934f6bacd23b0cc6993db80c80c0fe399ce47eb78f39600eda4c04d2cf41b4--binutils-2.37.tar.xz
==> Installing i386-elf-binutils from nativeos/i386-elf-toolchain
Error: Your Command Line Tools are too outdated.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 13.2.1.

I have installed the Command Line Tools and running xcode-select just says to run softwareupdate

> sudo xcode-select --install                                                  ~/[email protected]
Password:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

In XCode it confirmst that I have Command Line Tools for 13.2.1
Screen Shot 2022-02-12 at 1 39 57 PM

I'd appreciate any pointers or suggestions about this.

Thanks

Conflict with homebrew/core

Description

Since homebrew treat "i386-elf-binutils" as an old and deprecated name for "x86_64-elf-binutils", there is some confusion for homebrew if we install both x86_64-elf-binutils and nativeos/i386-elf-toolchain/i386-elf-binutils

How to reproduce

At first I do the following, and everything is OK.

brew install x86_64-elf-binutils
brew install x86_64-elf-gcc
brew tap nativeos/i386-elf-toolchain
brew install nativeos/i386-elf-toolchain/i386-elf-binutils
brew install nativeos/i386-elf-toolchain/i386-elf-gcc

Then when I try to do brew install nativeos/i386-elf-toolchain/i386-elf-gdb, it gives me the following error

Error: x86_64-elf-binutils from homebrew/core is given, but old name i386-elf-binutils was installed from nativeos/i386-elf-toolchain.
Please try to use fully-qualified nativeos/i386-elf-toolchain/i386-elf-binutils to refer to the formula.
To force migration, run:
  brew migrate --force i386-elf-binutils
Error: undefined method `core_tap?' for nil:NilClass

Full log

Though homebrew gives error about it, I can still successfully install gdb.

➜  Linux-0.11 git:(master) ✗ brew install nativeos/i386-elf-toolchain/i386-elf-gdb
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.
Error: x86_64-elf-binutils from homebrew/core is given, but old name i386-elf-binutils was installed from nativeos/i386-elf-toolchain.
Please try to use fully-qualified nativeos/i386-elf-toolchain/i386-elf-binutils to refer to the formula.
To force migration, run:
  brew migrate --force i386-elf-binutils
Error: undefined method `core_tap?' for nil:NilClass

==> Downloading https://ftp.gnu.org/gnu/gdb/gdb-10.2.tar.xz
######################################################################## 100.0%
==> Installing i386-elf-gdb from nativeos/i386-elf-toolchain
==> ./configure --prefix=/opt/homebrew/Cellar/i386-elf-gdb/10.2_2 --target=i386-elf --pro
==> make
==> make install
🍺  /opt/homebrew/Cellar/i386-elf-gdb/10.2_2: 31 files, 7.7MB, built in 2 minutes 34 seconds
==> Running `brew cleanup i386-elf-gdb`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

How to include c standard library?

Thanks for making this formula. I have successfully installed i386-elf-gcc and i386-elf-binutils, but when I use i386-elf-gcc to compile a test c file, I got the following errors:

JayWong Test $ i386-elf-gcc --sysroot=usr/includes test.c
test.c:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.

Do you happen to know how to add c standard library for compiling?

brew install error on macOS 14.4.1

❯ brew install nativeos/i386-elf-toolchain/i386-elf-gcc
==> Fetching nativeos/i386-elf-toolchain/i386-elf-gcc
==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz
Already downloaded: /Users/Rain/Library/Caches/Homebrew/downloads/9caf98c99bc119654de91583a325f293ed9186c1cc664ca548b1a3554d948cb9--gcc-12.2.0.tar.xz
==> Installing i386-elf-gcc from nativeos/i386-elf-toolchain
==> ../configure --prefix=/opt/homebrew/Cellar/i386-elf-gcc/12.2.0_2 --target=i386-elf --disable-multilib --disable-nls --disable-werror --without-hea
==> make all-gcc
Last 15 lines from /Users/Rain/Library/Logs/Homebrew/i386-elf-gcc/02.make:
In file included from ../../gcc/system.h:233:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/vector:321:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_integral.h:32:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/locale:202:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__locale:813:5: error: expected expression
return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[1]: *** [cp/mapper-resolver.o] Error 1
20 errors generated.
make[1]: *** [cp/module.o] Error 1
rm gcc.pod
make: *** [all-gcc] Error 2

Error installing on macOS 14.5

The last 15 lines of the log were not useful so I had to go a few lines back:

In file included from ../../grub-core/disk/luks2.c:30:
../../grub-core/disk/luks2.c: In function 'luks2_verify_key':
../../grub-core/disk/luks2.c:397:75: error: passing argument 5 of 'base64_decode_ctx' from incompatible pointer type [-Wincompatible-pointer-types]
  397 |   if (!base64_decode (d->digest, grub_strlen (d->digest), (char *)digest, &digestlen))
      |                                                                           ^~~~~~~~~~
      |                                                                           |
      |                                                                           grub_size_t * {aka unsigned int *}
../../grub-core/lib/gnulib/base64.h:65:50: note: in definition of macro 'base64_decode'
   65 |         base64_decode_ctx (NULL, in, inlen, out, outlen)
      |                                                  ^~~~~~
../../grub-core/lib/gnulib/base64.h:58:60: note: expected 'size_t *' {aka 'long unsigned int *'} but argument is of type 'grub_size_t *' {aka 'unsigned int *'}
   58 |                                char *restrict out, size_t *outlen);
      |                                                    ~~~~~~~~^~~~~~
../../grub-core/disk/luks2.c:399:69: error: passing argument 5 of 'base64_decode_ctx' from incompatible pointer type [-Wincompatible-pointer-types]
  399 |   if (!base64_decode (d->salt, grub_strlen (d->salt), (char *)salt, &saltlen))
      |                                                                     ^~~~~~~~
      |                                                                     |
      |                                                                     grub_size_t * {aka unsigned int *}
../../grub-core/lib/gnulib/base64.h:65:50: note: in definition of macro 'base64_decode'
   65 |         base64_decode_ctx (NULL, in, inlen, out, outlen)
      |                                                  ^~~~~~
../../grub-core/lib/gnulib/base64.h:58:60: note: expected 'size_t *' {aka 'long unsigned int *'} but argument is of type 'grub_size_t *' {aka 'unsigned int *'}
   58 |                                char *restrict out, size_t *outlen);
      |                                                    ~~~~~~~~^~~~~~
../../grub-core/disk/luks2.c: In function 'luks2_decrypt_key':
../../grub-core/disk/luks2.c:438:36: error: passing argument 5 of 'base64_decode_ctx' from incompatible pointer type [-Wincompatible-pointer-types]
  438 |                      (char *)salt, &saltlen))
      |                                    ^~~~~~~~
      |                                    |
      |                                    grub_size_t * {aka unsigned int *}
../../grub-core/lib/gnulib/base64.h:65:50: note: in definition of macro 'base64_decode'
   65 |         base64_decode_ctx (NULL, in, inlen, out, outlen)
      |                                                  ^~~~~~
../../grub-core/lib/gnulib/base64.h:58:60: note: expected 'size_t *' {aka 'long unsigned int *'} but argument is of type 'grub_size_t *' {aka 'unsigned int *'}
   58 |                                char *restrict out, size_t *outlen);
      |                                                    ~~~~~~~~^~~~~~
make[3]: *** [disk/luks2_module-luks2.o] Error 1
make[3]: *** Waiting for unfinished jobs....
mv -f disk/.deps-core/afsplitter_module-AFSplitter.Tpo disk/.deps-core/afsplitter_module-AFSplitter.Po
mv -f disk/.deps-core/mdraid09_module-mdraid_linux.Tpo disk/.deps-core/mdraid09_module-mdraid_linux.Po
mv -f disk/.deps-core/mdraid09_be_module-mdraid_linux_be.Tpo disk/.deps-core/mdraid09_be_module-mdraid_linux_be.Po
mv -f disk/.deps-core/mdraid1x_module-mdraid1x_linux.Tpo disk/.deps-core/mdraid1x_module-mdraid1x_linux.Po
mv -f disk/.deps-core/luks_module-luks.Tpo disk/.deps-core/luks_module-luks.Po
mv -f lib/json/.deps-core/json_module-json.Tpo lib/json/.deps-core/json_module-json.Po
mv -f disk/.deps-core/geli_module-geli.Tpo disk/.deps-core/geli_module-geli.Po
mv -f disk/.deps-core/ldm_module-ldm.Tpo disk/.deps-core/ldm_module-ldm.Po
mv -f disk/.deps-core/lvm_module-lvm.Tpo disk/.deps-core/lvm_module-lvm.Po
mv -f disk/.deps-core/cryptodisk_module-cryptodisk.Tpo disk/.deps-core/cryptodisk_module-cryptodisk.Po
mv -f lib/gnulib/.deps-core/regexp_module-regex.Tpo lib/gnulib/.deps-core/regexp_module-regex.Po
make[2]: *** [install] Error 2
make[1]: *** [install-recursive] Error 1
make: *** [install] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.