Hello,

On Fri, Nov 6, 2026 at 5:11 PM Gianluca Cannata <[email protected]> wrote:
> and it reaches a point where it tries to reach a variable named
> percpu_array that is not mapped correctly, maybe
> Breakpoint 1, 0x0000000000000200 in ?? ()
>    0x40000000: ldr x0, 0x40000018
>    0x40000004: mov x1, xzr
>    0x40000008: mov x2, xzr
>    0x4000000c: mov x3, xzr
>    0x40000010: ldr x4, 0x40000020
>    0x40000014: br x4
>    0x40000018: stxrh w0, w0, [x0]
>    0x4000001c: udf #0
>    0x40000020: .inst 0x40200000 ; undefined
>    0x40000024: udf #0
> $1 = (struct percpu (*)[1]) 0xbb0c0 <percpu_array>
> 0xbb0c0 <percpu_array>: Cannot access memory at address 0xbb0c0

I don't immediately recognize this code (perhaps this is QEMU's boot
stub, the first few instructions it runs before jumping to gnumach?),
and it's not clear to me why you think percpu_array has to do with it.

> Trying to get an answer from this dilemma, I have produced this commit
> https://github.com/aculnaig/gnumach/commit/e02cce5c5a02a1aa63799421b7e2a2619c760238
> but I am not entirely sure I have followed the right approach.

That patch does not make sense to me either, it's unclear what's going
on, and why. OTOH it's been long since I've seriously worked on
AArch64 Mach, so don't take that as an indication that the patch is
necessarily wrong.

> start example: Hello from Mach bare-metal example!

Great!

> static void mach_print(const char *msg)
> {
> register long x0 asm ("x0") = (long)msg;
> register long x8 asm ("x8") = MACH_TRAP_PRINT;
> asm volatile ("svc 0"
> : "+r"(x0)
> : "r"(x8)
> : "memory");
> }

Yes, something like that. Although it also clobbers x0, as all traps
do, and you should let the compiler know about that.

> And this commit [0] fixes the pl011 console output; I hope.
> [0]: 
> https://github.com/aculnaig/gnumach/commit/53f5f66fde895f09f0102ff74ed05b1d2878d49a

I was trying to avoid hard-coding 0x9000000 (or indeed PL011 at all),
instead we should read it from DTB, as different machines have it
mapped at different virtual addresses. And we should have already been
doing that in early_dtb_walk_visit_node.

> I am trying to understand the roles of the GICv2 and Generic Timer
> from aarch64 perspective now and I am reading the source code because
> at this point [0] I don't understand how to proceed.

GIC is an *interrupt controller*. Various peripherals / devices are
wired up to it on one side, and your CPU core(s?) on another side. GIC
sort of multiplexes interrupts that the devices raise into a single
"irq" line of the CPU (there's a second one, "fiq", which goes
unused). Or in other words: the devices indicate when they need
attention, and GIC turns that into CPU interrupts. I don't remember
the details, but I would guess that you can ask GIC whether an
interrupt from a particular source is pending, to clear/set it, etc.

The timer is exactly what it says on the tin: it's a simple (built-in)
device that you configure with a frequency, and it sends you
interrupts at that frequency. Your can then run some periodic tasks in
response, notably:
- context-switch between runnable threads, so everyone gets a fair
share of the time while running "simultaneously",
- increment the stored idea of the current time (which is later
returned from various APIs including time(3)).

> As the previous thread, I can run a simple bare-metal example but I
> wonder what is the next stage of the development.
> If you can point me in any direction.

Mach has some tests (small userland programs) of its own, see tests/
in my branch. You should be able to compile and run those.

> I am trying to cross compile the Hurd with [0] but I need a non-linux
> version of GCC.

Indeed, you need a cross-toolchain targeting aarch64-gnu, not aarch64-linux-gnu.

> I remember you worked on some patches to add support for the Hurd in GCC.
> Do you also remember if they were merged upstream ?

Yes, aarch64-gnu support should be upstream in gcc and binutils, IIRC.
But you need to do the usual back-and-forth "dance" to bootstrap it,
including glibc and all. Perhaps indeed using something like Flavio's
scripts; alternatively, I posted a "simpler" guide back in 2023 [0].

[0]: https://lists.gnu.org/archive/html/bug-hurd/2023-01/msg00132.html

Sergey

Reply via email to