cerror.S revision 1.17
11.17Suwe/* $NetBSD: cerror.S,v 1.17 2025/05/07 15:17:34 uwe Exp $ */ 21.1Sbjh21 31.1Sbjh21/*- 41.1Sbjh21 * Copyright (c) 1990 The Regents of the University of California. 51.1Sbjh21 * All rights reserved. 61.1Sbjh21 * 71.1Sbjh21 * Redistribution and use in source and binary forms, with or without 81.1Sbjh21 * modification, are permitted provided that the following conditions 91.1Sbjh21 * are met: 101.1Sbjh21 * 1. Redistributions of source code must retain the above copyright 111.1Sbjh21 * notice, this list of conditions and the following disclaimer. 121.1Sbjh21 * 2. Redistributions in binary form must reproduce the above copyright 131.1Sbjh21 * notice, this list of conditions and the following disclaimer in the 141.1Sbjh21 * documentation and/or other materials provided with the distribution. 151.5Sagc * 3. Neither the name of the University nor the names of its contributors 161.1Sbjh21 * may be used to endorse or promote products derived from this software 171.1Sbjh21 * without specific prior written permission. 181.1Sbjh21 * 191.1Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201.1Sbjh21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211.1Sbjh21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221.1Sbjh21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231.1Sbjh21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241.1Sbjh21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251.1Sbjh21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261.1Sbjh21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271.1Sbjh21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281.1Sbjh21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291.1Sbjh21 * SUCH DAMAGE. 301.1Sbjh21 * 311.1Sbjh21 * from: @(#)cerror.s 5.1 (Berkeley) 4/23/90 321.1Sbjh21 */ 331.1Sbjh21 341.1Sbjh21#include "SYS.h" 351.1Sbjh21 361.16Suwe/* { r0, r1 } := -1LL */ 371.16Suwe#ifdef __thumb__ 381.16Suwe#define MOV_RETVAL_MINUS_1 \ 391.16Suwe movs r0, #0 ; \ 401.16Suwe mvns r0, r0 ; \ 411.16Suwe movs r1, r0 421.16Suwe 431.16Suwe#else // !__thumb__ 441.16Suwe#define MOV_RETVAL_MINUS_1 \ 451.16Suwe mvn r0, #0 ; \ 461.16Suwe mov r1, r0 471.16Suwe#endif 481.16Suwe 491.16Suwe 501.16Suwe/* 511.16Suwe * Set `errno` and return -1. See SYS.h for syscall stubs that call this. 521.16Suwe */ 531.10SmattENTRY_NP(CERROR) 541.1Sbjh21#ifdef _REENTRANT 551.17Suwe /* __errno() returns the address of a thread local variable */ 561.17Suwe .globl _C_LABEL(__errno) 571.11Smatt#if defined(__ARM_EABI__) && defined(__UNWIND_TABLES__) 581.10Smatt .fnstart 591.10Smatt .cfi_startproc 601.10Smatt#endif 611.10Smatt push {r4, lr} 621.11Smatt#if defined(__ARM_EABI__) && defined(__UNWIND_TABLES__) 631.10Smatt .save {r4, lr} 641.10Smatt .cfi_def_cfa_offset 8 651.10Smatt .cfi_offset 14, -4 661.10Smatt .cfi_offset 4, -8 671.10Smatt#endif 681.16Suwe movs r4, r0 691.13Sjoerg bl PLT_SYM(_C_LABEL(__errno)) 701.1Sbjh21 str r4, [r0] 711.16Suwe MOV_RETVAL_MINUS_1 721.10Smatt pop {r4, pc} 731.11Smatt#if defined(__ARM_EABI__) && defined(__UNWIND_TABLES__) 741.10Smatt .cfi_endproc 751.10Smatt .fnend 761.10Smatt#endif 771.17Suwe 781.10Smatt#else /* !_REENTRANT */ 791.17Suwe /* errno is a global variable */ 801.17Suwe .globl _C_LABEL(errno) 811.11Smatt#if defined(__ARM_EABI__) && defined(__UNWIND_TABLES__) 821.10Smatt .fnstart 831.10Smatt .cfi_startproc 841.10Smatt#endif 851.15Suwe#ifdef __PIC__ 861.15Suwe /* Setup the GOT */ 871.15Suwe ldr r3, .Lgot 881.15Suwe add r3, r3, pc /* pc = &.LPIC0 */ 891.15Suwe ldr r1, .Lerrno 901.15Suwe.LPIC0: ldr r1, [r3, r1] 911.15Suwe#else 921.15Suwe ldr r1, .Lerrno 931.15Suwe#endif /* __PIC__ */ 941.1Sbjh21 str r0, [r1] 951.16Suwe MOV_RETVAL_MINUS_1 961.6Srearnsha RET 971.11Smatt#if defined(__ARM_EABI__) && defined(__UNWIND_TABLES__) 981.10Smatt .cfi_endproc 991.10Smatt .fnend 1001.10Smatt#endif 1011.1Sbjh21 1021.15Suwe#ifdef __PIC__ 1031.15Suwe .align 0 1041.15Suwe.Lgot: 1051.15Suwe .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - .LPIC0 1061.15Suwe#endif /* __PIC__ */ 1071.3Sthorpej.Lerrno: 1081.17Suwe .word GOT_SYM(_C_LABEL(errno)) 1091.1Sbjh21#endif /* _REENTRANT */ 1101.10SmattEND(CERROR) 111