News for hackers. Stuff that matters.
Re:Apple M1 Assembly Language Hello World by marcan_42 on Thursday January 14, 2021 @10:47PM (#25786775)
I see your userland M1 assembly language hello world and raise you a bare-metal M1 kernel assembly language hello world :-)

https://github.com/AsahiLinux/m1n1/blob/main/src/start.S

The first few lines of that will print 'm1n1' to the serial port as it initializes other things and eventually jumps to C code.

Re:Apple M1 Assembly Language Hello World by cshift on Friday January 15, 2021 @07:47AM (#25790307)
> I see your userland M1 assembly language hello world and raise you a bare-metal M1 kernel assembly language hello world :-)

The most on-brand HN thing I've read so far today.

Re:Apple M1 Assembly Language Hello World by nneonneo on Thursday January 14, 2021 @10:50PM (#25786795)
This looks basically like assembly code for practically any embedded system - reading/writing hardware registers to interact with UARTs. Nice job (& best of luck with the Asahi Linux project - very exciting!)
Re:Apple M1 Assembly Language Hello World by marcan_42 on Thursday January 14, 2021 @11:49PM (#25787130)
Well, the Apple M1 is an embedded SoC after all :)

Thank you!

Re:Apple M1 Assembly Language Hello World by yitchelle on Friday January 15, 2021 @03:34AM (#25788407)
That is the most exciting part of the M1 for me. What do you think will be the first embedded application for the M1, assuming Apple allows it to be purchased by 3rd parties? Autonomous driving, or robotics, or other..??
Re:Apple M1 Assembly Language Hello World by saagarjha on Friday January 15, 2021 @05:17AM (#25789091)
Apple won't allow it to be purchased by third parties.
Re:Apple M1 Assembly Language Hello World by magnusmundus on Friday January 15, 2021 @05:35AM (#25789202)
Not quite as exciting as your examples, but I guess an evolution of Apple CarPlay might be likely.
Re:Apple M1 Assembly Language Hello World by WanderPanda on Friday January 15, 2021 @08:05AM (#25790481)
Yes they need to capture the car UI part as legacy automakers will not be able to build an ecosystem for that.
Re:Apple M1 Assembly Language Hello World by SulfurHexaFluri on Friday January 15, 2021 @12:04AM (#25787201)
How do you actually load / run this code without an OS? I'm guessing its the same way something like grub gets run?
Re:Apple M1 Assembly Language Hello World by garaetjjte on Friday January 15, 2021 @08:10AM (#25790526)
It's linked into Mach-O binary that is loaded by iBoot bootloader. It is explained in detail there: https://www.youtube.com/watch?v=d5s9fYfvzmY&t=12260
Re:Apple M1 Assembly Language Hello World by moonchild on Friday January 15, 2021 @03:19AM (#25788310)
I don't know how it works on apple hardware—though I heard they used a UEFI variant with HFS+ at one point—but in general, on PCs, there are two ways to get bootcode to run.

The first is legacy BIOS: the BIOS will load the first 512 bytes of the boot sector, called the Master Boot Record (MBR) into memory location 0x7C00; they are then responsible for bootstrapping the rest of the system. Usually by doing the bare minimum to load a second-stage bootloader off the disc, and letting the second-stage bootloader do the rest of the work, since 512 bytes (actually only ~440) is really not very much.

The second is UEFI. The firmware will load a PE-formatted executable from a .efi-suffixed file on a FAT32 partition which has the EFI System Partition (ESP) flag set. Since this PE file can be any size, a second-stage bootloader is not generally necessary (but may be interesting for aesthetic reasons e.g. if you don't like PE).

Re:Apple M1 Assembly Language Hello World by alexjm on Friday January 15, 2021 @11:28AM (#25792612)
The process for Apple hardware to find and start EFI is described in the "Booting from an Apple File System Partition" section on page 22 of this document. Basically, the EFI image is read from a special block on disk.

https://developer.apple.com/support/downloads/Apple-File-Sys...

The boot process for HFS+ is more involved, because you have to actually read the HFS+ file system to locate the EFI image, since it's stored in a regular file.

I'm not sure what happens after jumping into the EFI code.

(Disclaimer: I worked on the linked document.)

Re:Apple M1 Assembly Language Hello World by CameronNemo on Friday January 15, 2021 @04:34AM (#25788799)
On Rockchip boards, there is a bootrom that looks for data at a specific offset on a few storage devices, then calls the first one it finds. From there open source / flashable firmware initializes RAM, scales up CPU frequencies, and starts looking for a kernel or whatever.

TL;DR likely read only firmware, possibly more low level than a BIOS, UEFI, or Coreboot implementation would be.

Edit: then again, they could be shipping a full EFI implementation like they do on their x86 offerings.

Re:Apple M1 Assembly Language Hello World by user-the-name on Friday January 15, 2021 @03:32AM (#25788390)
Where is the UART on that thing?
Re:Apple M1 Assembly Language Hello World by terramex on Friday January 15, 2021 @04:04AM (#25788596)
UART can be enabled on M1 Mini on "the leftmost port (closest to the power input)". It first needs to be enabled by sending special USB-PD message.

More information: https://github.com/AsahiLinux/docs/wiki/HW%3AUSB-PD

Re:Apple M1 Assembly Language Hello World by user-the-name on Friday January 15, 2021 @04:56AM (#25788944)
Interesting!
Re:Apple M1 Assembly Language Hello World by deaddodo on Friday January 15, 2021 @04:09AM (#25788625)
He talks about it here:

https://www.youtube.com/watch?v=d5s9fYfvzmY

(In addition to the docs, as outlined by terramex)

Re:Apple M1 Assembly Language Hello World by CyberRabbi on Thursday January 14, 2021 @11:32PM (#25787037)
What baud rate does it run at?
Re:Apple M1 Assembly Language Hello World by marcan_42 on Thursday January 14, 2021 @11:48PM (#25787125)
115200 by default (it's what iBoot initializes it at), but I spent a chunk of yesterday's live development stream yak-shaving a way to smoothly switch to 1.5Mbaud in a way that lets my Glasgow-based auto-baud-sensing serial interface resync cleanly (turns out: it seems to be impossible using any single byte repeating with 1 stopbit and no pauses due to ambiguous framing; I had to use a multiple-byte pattern).
Re:Apple M1 Assembly Language Hello World by reaperducer on Friday January 15, 2021 @12:21PM (#25793345)
115200 by default

This made me laugh because I spent a good chunk of last weekend trying to debug a problem with some of my old computer hardware and the problem turned out to be a link that couldn't handle anything over 150 baud.

Now we're squirting 115,200 straight out of a chip. It's like the future!

Re:Apple M1 Assembly Language Hello World by CyberRabbi on Friday January 15, 2021 @10:38PM (#25799805)
The crazy part is that 115200 is actually slow by today’s standards!
Re:Apple M1 Assembly Language Hello World by RantyDave on Saturday January 16, 2021 @04:59AM (#25801273)
LOL. Zephyr?
Re:Apple M1 Assembly Language Hello World by sneak on Thursday January 14, 2021 @11:38PM (#25787072)
String bet! :)

(Raises are not accepted after you've already called.)