From 887d66d537bf63a768ed08aad980b1af3696ff07 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 12 Jan 2020 18:54:07 -0600 Subject: [PATCH] Implement aligned_alloc function (C11). This allocates memory with a specified alignment. Currently, the only allowed alignment value is 1. --- stdlib.asm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/stdlib.asm b/stdlib.asm index 91f94ba..d3a5e26 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -70,6 +70,42 @@ lb1 tay return A rtl end +**************************************************************** +* +* void *aligned_alloc(size_t alignment, size_t size) +* +* Allocate memory with specified alignment. +* +* Inputs: +* alignment - alignment to use (only value allowed is 1) +* size - bytes of memory to allocate +* +* Outputs: +* Returns pointer to allocated memory, or NULL on error. +* +**************************************************************** +* +aligned_alloc start + csubroutine (4:alignment,4:size),0 + + lda alignment check that alignment==1 + dec a + ora alignment+2 + beq good + stz size return NULL on error + stz size+2 + lda #EINVAL + sta >errno + bra ret + +good ph4