Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ POSIX networking calls, and the build system aligned on Infrabase.
when AVZ took it. A Raspberry Pi 5 (BCM2712) platform skeleton is
added; it builds but has not been validated on a board yet.

• Kernel: the ARM timer reload is computed from the counter frequency (the
Raspberry Pi 4 tick was 2.9 % too long); a futex is freed by its waker,
• Kernel: on arm64 the FP/SIMD registers belong to the thread and to the
domain, saved and loaded at each switch, and the kernel no longer uses
them (they were shared by all, so that a preempted thread could get
another's values back, and one formatting a floating-point number be
killed in a loop without end); the ARM timer reload is computed from the
counter frequency (the Raspberry Pi 4 tick was 2.9 % too long); a futex is freed by its waker,
not by the waiters it woke; the VFS lock is no longer held across an
ioctl handler; malloc aligns on 8 bytes; a misaligned spinlock names its
caller; the device tree accepts status = "okay". Networking gained poll,
Expand Down
5 changes: 5 additions & 0 deletions so3/so3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ endif

ifeq ($(CONFIG_ARCH_ARM64),y)
KBUILD_CFLAGS += -mlittle-endian -DBITS_PER_LONG=64 -fno-allow-store-data-races

# The kernel leaves the FP/SIMD registers to the user space: they hold the
# state of the thread which entered the kernel, saved at a context switch only.

KBUILD_CFLAGS += -mgeneral-regs-only
KBUILD_AFLAGS += -mlittle-endian
endif

Expand Down
2 changes: 1 addition & 1 deletion so3/so3/arch/arm64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ obj-y += head.o exception.o traps.o

obj-y += fault.o backtrace.o
obj-y += backtrace.o backtrace_asm.o
obj-y += cache_v8.o cache.o context.o
obj-y += cache_v8.o cache.o context.o fpsimd.o
obj-y += semihosting.o semicall.o

obj-$(CONFIG_AVZ) += domain.o mmio.o
Expand Down
3 changes: 3 additions & 0 deletions so3/so3/arch/arm64/asm-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ int main(void)
BLANK();

DEFINE(OFFSET_TCB_CPU_REGS, offsetof(tcb_t, cpu_regs));

DEFINE(OFFSET_FPSIMD_FPSR, offsetof(struct fpsimd_state, fpsr));
DEFINE(OFFSET_FPSIMD_FPCR, offsetof(struct fpsimd_state, fpcr));
DEFINE(OFFSET_SP_USR, offsetof(cpu_regs_t, sp_usr));

BLANK();
Expand Down
80 changes: 80 additions & 0 deletions so3/so3/arch/arm64/fpsimd.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2026 Daniel Rossier <daniel.rossier@heig-vd.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

// The FP/SIMD state of a thread or of a domain: v0 to v31, FPSR and FPCR.
// The layout is struct fpsimd_state of asm/processor.h.

#include <linkage.h>

#include <generated/asm-offsets.h>

// Store the FP/SIMD registers.
// x0: the struct fpsimd_state to fill

ENTRY(fpsimd_save)
stp q0, q1, [x0, #(16 * 0)]
stp q2, q3, [x0, #(16 * 2)]
stp q4, q5, [x0, #(16 * 4)]
stp q6, q7, [x0, #(16 * 6)]
stp q8, q9, [x0, #(16 * 8)]
stp q10, q11, [x0, #(16 * 10)]
stp q12, q13, [x0, #(16 * 12)]
stp q14, q15, [x0, #(16 * 14)]
stp q16, q17, [x0, #(16 * 16)]
stp q18, q19, [x0, #(16 * 18)]
stp q20, q21, [x0, #(16 * 20)]
stp q22, q23, [x0, #(16 * 22)]
stp q24, q25, [x0, #(16 * 24)]
stp q26, q27, [x0, #(16 * 26)]
stp q28, q29, [x0, #(16 * 28)]
stp q30, q31, [x0, #(16 * 30)]

mrs x1, fpsr
str w1, [x0, #OFFSET_FPSIMD_FPSR]
mrs x1, fpcr
str w1, [x0, #OFFSET_FPSIMD_FPCR]

ret

// Load the FP/SIMD registers.
// x0: the struct fpsimd_state to load

ENTRY(fpsimd_restore)
ldp q0, q1, [x0, #(16 * 0)]
ldp q2, q3, [x0, #(16 * 2)]
ldp q4, q5, [x0, #(16 * 4)]
ldp q6, q7, [x0, #(16 * 6)]
ldp q8, q9, [x0, #(16 * 8)]
ldp q10, q11, [x0, #(16 * 10)]
ldp q12, q13, [x0, #(16 * 12)]
ldp q14, q15, [x0, #(16 * 14)]
ldp q16, q17, [x0, #(16 * 16)]
ldp q18, q19, [x0, #(16 * 18)]
ldp q20, q21, [x0, #(16 * 20)]
ldp q22, q23, [x0, #(16 * 22)]
ldp q24, q25, [x0, #(16 * 24)]
ldp q26, q27, [x0, #(16 * 26)]
ldp q28, q29, [x0, #(16 * 28)]
ldp q30, q31, [x0, #(16 * 30)]

ldr w1, [x0, #OFFSET_FPSIMD_FPSR]
msr fpsr, x1
ldr w1, [x0, #OFFSET_FPSIMD_FPCR]
msr fpcr, x1

ret
16 changes: 16 additions & 0 deletions so3/so3/arch/arm64/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,20 @@ enum trap_return {
#define GIC_PRIO_IRQOFF (GIC_PRIO_IRQON & ~0x80)
#define GIC_PRIO_PSR_I_SET (1 << 4)

/*
* The FP/SIMD state of a thread or of a domain. The kernel does not use these
* registers: they stay those of the context which entered it until a switch
* saves them here and loads those of the next one.
*/
struct fpsimd_state {
__uint128_t v[32];
u32 fpsr;
u32 fpcr;
};

void fpsimd_save(struct fpsimd_state *state);
void fpsimd_restore(struct fpsimd_state *state);

/* The structure is packed since we may refer as a linear space
* addressed by index
*/
Expand Down Expand Up @@ -1161,6 +1175,8 @@ typedef struct vcpu {
u64 tcr_el1;
u64 mair_el1;

/* FP/SIMD registers of the guest, its kernel and its user space alike */
struct fpsimd_state fpsimd;
} vcpu_t;

void resume_to_guest(void);
Expand Down
4 changes: 4 additions & 0 deletions so3/so3/avz/kernel/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ void vcpu_save_context(struct domain *d)
d->vcpu.ttbr1_el1 = read_sysreg(ttbr1_el1);
d->vcpu.tcr_el1 = read_sysreg(tcr_el1);
d->vcpu.mair_el1 = read_sysreg(mair_el1);

fpsimd_save(&d->vcpu.fpsimd);
}

/**
Expand All @@ -230,6 +232,8 @@ void vcpu_restore_context(struct domain *d)
write_sysreg(d->vcpu.tcr_el1, tcr_el1);
write_sysreg(d->vcpu.mair_el1, mair_el1);

fpsimd_restore(&d->vcpu.fpsimd);

gic_clear_pending_irqs();

/* Check for pending vIRQs for this domain */
Expand Down
4 changes: 4 additions & 0 deletions so3/so3/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ struct tcb {
struct list_head joinQueue;

cpu_regs_t cpu_regs;

#ifdef CONFIG_ARCH_ARM64
struct fpsimd_state fpsimd;
#endif
};
typedef struct tcb tcb_t;

Expand Down
7 changes: 7 additions & 0 deletions so3/so3/kernel/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ void schedule(void)
__in_interrupt = false;
__in_scheduling = false;

#ifdef CONFIG_ARCH_ARM64
if (prev)
fpsimd_save(&prev->fpsimd);

fpsimd_restore(&next->fpsimd);
#endif

__switch_to(prev, next);
}
__in_scheduling = false;
Expand Down
5 changes: 5 additions & 0 deletions so3/so3/kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ tcb_t *thread_create(clone_args_t *args)
kernel_panic();
}

#ifdef CONFIG_ARCH_ARM64
/* A new thread starts with the FP/SIMD state of its creator, as fork() requires. */
fpsimd_save(&tcb->fpsimd);
#endif

tcb->tid = tid_next++;

/* We append the tid to the thread name */
Expand Down
5 changes: 5 additions & 0 deletions so3/so3/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ lib-y += ctype.o
lib-y += vsprintf.o printk.o
ifneq ($(CONFIG_ARCH_X86_64),y)
lib-y += strtod.o

# strtod() computes in doubles; libroxml's XPath is its only caller.

CFLAGS_REMOVE_strtod.o = -mgeneral-regs-only
endif

lib-y += list_sort.o
lib-y += hashmap.o

6 changes: 6 additions & 0 deletions so3/so3/lib/libroxml/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ lib-y += roxml_buff.o roxml_commit.o roxml_content.o
lib-y += roxml_core.o roxml_edit.o roxml_mem.o roxml_nav.o
lib-y += roxml_parser.o roxml_xpath.o roxml_file.o


# The XPath evaluation computes in doubles.

ifeq ($(CONFIG_ARCH_ARM64),y)
CFLAGS_REMOVE_roxml_xpath.o = -mgeneral-regs-only
endif
Loading