xref: /netbsd-src/lib/libc/arch/riscv/sys/cerror.S (revision 35c3446182b5d2ae37a831f3e9c1597901314cac)
1*35c34461Smatt/*	$NetBSD: cerror.S,v 1.3 2015/03/27 23:23:14 matt Exp $	*/
26cf6fe02Smatt
36cf6fe02Smatt/*-
46cf6fe02Smatt * Copyright (c) 1991, 1993
56cf6fe02Smatt *	The Regents of the University of California.  All rights reserved.
66cf6fe02Smatt *
76cf6fe02Smatt * This code is derived from software contributed to Berkeley by
86cf6fe02Smatt * Ralph Campbell.
96cf6fe02Smatt *
106cf6fe02Smatt * Redistribution and use in source and binary forms, with or without
116cf6fe02Smatt * modification, are permitted provided that the following conditions
126cf6fe02Smatt * are met:
136cf6fe02Smatt * 1. Redistributions of source code must retain the above copyright
146cf6fe02Smatt *    notice, this list of conditions and the following disclaimer.
156cf6fe02Smatt * 2. Redistributions in binary form must reproduce the above copyright
166cf6fe02Smatt *    notice, this list of conditions and the following disclaimer in the
176cf6fe02Smatt *    documentation and/or other materials provided with the distribution.
186cf6fe02Smatt * 3. Neither the name of the University nor the names of its contributors
196cf6fe02Smatt *    may be used to endorse or promote products derived from this software
206cf6fe02Smatt *    without specific prior written permission.
216cf6fe02Smatt *
226cf6fe02Smatt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
236cf6fe02Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
246cf6fe02Smatt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
256cf6fe02Smatt * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
266cf6fe02Smatt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
276cf6fe02Smatt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
286cf6fe02Smatt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
296cf6fe02Smatt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
306cf6fe02Smatt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
316cf6fe02Smatt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
326cf6fe02Smatt * SUCH DAMAGE.
336cf6fe02Smatt */
346cf6fe02Smatt
356cf6fe02Smatt#include "SYS.h"
366cf6fe02Smatt
376cf6fe02Smatt#if defined(LIBC_SCCS) && !defined(lint)
38*35c34461Smatt	RCSID("$NetBSD: cerror.S,v 1.3 2015/03/27 23:23:14 matt Exp $")
396cf6fe02Smatt#endif /* LIBC_SCCS and not lint */
406cf6fe02Smatt
416cf6fe02Smatt	.protected	_C_LABEL(__cerror)
426cf6fe02Smatt
436cf6fe02Smatt	.globl	_C_LABEL(__errno)
446cf6fe02SmattENTRY_NP(__cerror)
456cf6fe02Smatt#ifdef _REENTRANT
466cf6fe02Smatt	addi		sp, sp, -CALLFRAME_SIZ
476cf6fe02Smatt	REG_S		ra, CALLFRAME_RA(sp)	# save return address
488a3081d2Smatt	INT_S		a0, CALLFRAME_S0(sp)	# save errno value
496cf6fe02Smatt
506cf6fe02Smatt	call		PLT(_C_LABEL(__errno))	# locate address of errno
516cf6fe02Smatt
528a3081d2Smatt	INT_L		t0, CALLFRAME_S0(sp)	# retrieve errno value
536cf6fe02Smatt	REG_L		ra, CALLFRAME_RA(sp)	# retrieve return address
548a3081d2Smatt	INT_S		t0, 0(a0)		# update errno value
556cf6fe02Smatt	addi		sp, sp, CALLFRAME_SIZ
566cf6fe02Smatt#else
578a3081d2Smatt	aiupc		a1, %hi(_C_LABEL(errno))
58*35c34461Smatt	INT_S		a0, %lo(_C_LABEL(errno))(a1)
596cf6fe02Smatt#endif /* _REENTRANT */
608a3081d2Smatt	li		a0, -1
618a3081d2Smatt	li		a1, -1
626cf6fe02Smatt	ret
636cf6fe02SmattEND(__cerror)
64