summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAiden Gall <aiden@aidengall.xyz>2025-10-14 20:06:30 +0100
committerAiden Gall <aiden@aidengall.xyz>2025-10-14 20:06:30 +0100
commit746c5aaf4b2d325d7f0bfb457ec0b3e1789d175c (patch)
treee7b09521f68097e56f39b94c41d1603673831735
parent201b2fc4bed967ea04dbda857cdb364363c12343 (diff)
add support for indirect branch trackingHEADmaster
-rw-r--r--config.inc3
-rw-r--r--tco.asm19
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 <posix_memalign,aligned_alloc,mmap>
+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