From 746c5aaf4b2d325d7f0bfb457ec0b3e1789d175c Mon Sep 17 00:00:00 2001 From: Aiden Gall Date: Tue, 14 Oct 2025 20:06:30 +0100 Subject: add support for indirect branch tracking --- config.inc | 3 +++ tco.asm | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/config.inc b/config.inc index ae7ee48..b499536 100644 --- a/config.inc +++ b/config.inc @@ -7,3 +7,6 @@ STACK_CAPACITY = 64*4096 ; - aligned_alloc (C11) ; - mmap (linux) MALLOC equ aligned_alloc + +; enable indirect branch tracking support +IBT_ENABLE = 1 diff --git a/tco.asm b/tco.asm index a26de62..4b3f268 100644 --- a/tco.asm +++ b/tco.asm @@ -15,15 +15,20 @@ format ELF64 -public tco_go -public tco_args -public tco_yield - ; assembly-time configuration options include 'config.inc' assert (STACK_CAPACITY mod 16) = 0 assert MALLOC in +macro fn lbl { + label lbl + public lbl + + if IBT_ENABLE + endbr64 + end if +} + ; circular singly-linked list containing callee-saved registers and instruction ; pointer to resume execution of coroutine when yielded to struc ctx_node next { @@ -60,7 +65,7 @@ end if section '.text' executable ; int tco_go(void (*f)(...)) ; spawns a coroutine -tco_go: +fn tco_go call stash ; pushing rdi also aligns stack to 16 byte boundary for function call @@ -154,7 +159,7 @@ end if ; void tco_args(...) ; sets the arguments of the next coroutine -tco_args: +fn tco_args irps reg, rax rdi rsi rdx r10 r8 r9 { mov [coroutine_args.#reg], reg } @@ -170,7 +175,7 @@ tco_args: ; void tco_yield(void) ; yield to next coroutine -tco_yield: +fn tco_yield call stash xor eax, eax jmp switch -- cgit v1.2.3