AsahiLinux / docs

Hardware and software docs / wiki
Other
1.76k stars 49 forks source link

Bare Metal Homebrew on Apple Silicon #78

Closed 7ombie closed 11 months ago

7ombie commented 12 months ago

This is not an issue with Asahi Linux. Sorry. I'm hoping you wont mind me asking for advice here (once), as this is the only community that could help.

I'd like to use M1 MacBooks for homebrew, basically like bare metal programming on the RaspberryPi. I'm hoping I could piggyback off the work of this project to create ROMs that can be installed so the user can select them during boot, just like an OS.

Honestly, my main concern is simply being completely out of my depth. My basic assumption is that I can communicate with the hardware, just like any other computer, so it's just a matter of doing what the hardware expects; there's generally no black magic required. Is this true?

In short, is there any obvious reason why a committed hobbyist shouldn't try to make simple games that run directly on the MacBook's hardware?

wodin commented 12 months ago

Unless you want to write device drivers, a TCP/IP stack, etc., etc., yourself, it seems better to use a Linux kernel and just have a minimal userspace containing your game. But I am not a game dev or OS kernel dev 🤷‍♂️

7ombie commented 11 months ago

Unless you want to write device drivers, a TCP/IP stack, etc., etc., yourself, it seems better to use a Linux kernel and just have a minimal userspace containing your game. But I am not a game dev or OS kernel dev 🤷‍♂️

Thanks for getting back to me - much appreciated.

I'm fine with nothing working out the box. This would be all about practicing low-level programming. Building a game was just hypothetical (I'm more interested in generating music personally).

I just wondered if this is comparable to doing the same on a RPi, and I can't see any reason why not, but feel like there's probably a few reasons why not. I just don't know what they are yet.

I'm thinking it might be possible to use QEMU and M1 virtualization to efficiently emulate the hardware, with the option of buying a second M1 Mac down the road (when I can afford another one, frankly), and linking them up (with debugging etc). It could be a lot of fun (if it was as simple as it seems).

Again, all the best, buddy. Cheers.

wodin commented 11 months ago

I am no expert in any of this stuff. Just a random person on the Internet who happened to see your question. But it seems to me tbat a Raspberry Pi is a deliberately simple device, designed for people to tinker with, whereas a Mac is a highly proprietary and complex device with no official public documentation on a lot of the pieces. So my guess is that it would be a lot more work than you expect.

But if you can use qemu to emulate most of the hardware and then maybe write custom drivers for one piece of hardware at a time, then maybe that would work. But as I say, I'm just a random person on the Internet, so I don't really know how much effort this would be.

DavidBuchanan314 commented 11 months ago

m1n1 is an example of an application that runs on bare metal (or at least, as bare as one can get) on apple silicon https://github.com/AsahiLinux/m1n1, https://github.com/AsahiLinux/docs/wiki/m1n1%3AUser-Guide

Note that it supports chainloading kernel images, which might be useful to you. This, iiuc, represents the unofficial standard that is the linux kernel image format, which you can find documented here https://www.kernel.org/doc/Documentation/arm64/booting.txt

In terms of driving the hardware, you can look at m1n1 itself, or the various linux device drivers that have been written as part of the asahi project.

You may be able to achieve your goals by editing m1n1 itself.

7ombie commented 11 months ago

@wodin - I understand you're not taking an authoritative position, but I still appreciate the time you took you offer your thoughts. Thanks.

@DavidBuchanan314 - I was looking at m1n1, and hoped I could exploit stuff like that. I understand I'll need some parts of the project, but would like to avoid an entire OS kernel. To be fair, I'm really just toying with the idea, and wanted to see if anyone more knowledgable could foresee it was a non-starter.

I appreciate your advice (and the links). I'll close the issue, and look into it some more. Thanks again. Much appreciated.