Home | History | Annotate | Line # | Download | only in sh3
      1 /*	$NetBSD: h_execregs.S,v 1.1 2025/04/27 02:24:07 uwe Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2025 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #define	_LOCORE
     30 #include <machine/asm.h>
     31 #include <machine/mcontext.h>
     32 #include <sys/syscall.h>
     33 
     34 
     35 // ELF entry point
     36 ENTRY(execregs_start)
     37 	// __gregset_t r;	// mcontext (but general regs only)
     38 	mov.l	sp, @-sp
     39 	mov.l	r0, @-sp
     40 	mov.l	r1, @-sp
     41 	mov.l	r2, @-sp
     42 	mov.l	r3, @-sp
     43 	mov.l	r4, @-sp
     44 	mov.l	r5, @-sp
     45 	mov.l	r6, @-sp
     46 	mov.l	r7, @-sp
     47 	mov.l	r8, @-sp
     48 	mov.l	r9, @-sp
     49 	mov.l	r10, @-sp
     50 	mov.l	r11, @-sp
     51 	mov.l	r12, @-sp
     52 	mov.l	r13, @-sp
     53 	mov.l	r14, @-sp
     54 	sts.l	pr, @-sp
     55 	sts.l	mach, @-sp
     56 	sts.l	macl, @-sp
     57 	mov	#0, r0
     58 	mov.l	r0, @-sp	// _REG_SR is privileged
     59 	mova	.Lend, r0	// _REG_PC
     60 	mov.l	@r0, r1
     61 	sub	r1, r0
     62 	mov.l	r0, @-sp
     63 	stc.l	gbr, @-sp
     64 
     65 	// write(STDOUT_FILENO, &r, sizeof(__gregset_t))
     66 	mov	#1, r4
     67 	mov	sp, r5
     68 	mov	#(_NGREG * 4), r6
     69 	mov	#SYS_write, r0
     70 	trapa	#0x80
     71 
     72 	// _exit(0)
     73 	mov	#0, r4
     74 	mov	#SYS_exit, r0
     75 	trapa	#0x80
     76 
     77 	.p2align 2
     78 .Lend:	.long	.Lend - execregs_start
     79 	SET_ENTRY_SIZE(execregs_start)
     80 
     81 
     82 // main stub to simplify linking
     83 ENTRY(main)
     84 	rts
     85 	 mov	#0, r0
     86 	SET_ENTRY_SIZE(main)
     87