1/*	$NetBSD: sh3.s,v 1.1 2022/10/14 19:41:18 ryo Exp $	*/
2
3/*-
4 * Copyright (c) 2022 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/*
30 * assemble & link:
31 *  as -o sh3.o sh3.s
32 *  ld -o hello -e __start sh3.o
33 */
34
35	/* ------------------------------------------------------------------ */
36
37	/*
38	 * This ELF section is used by the kernel to determine, among other
39	 * things, the system call interface used by the binary.
40	 *
41	 * Normally, /usr/lib/crti.o is linked, but here it is written manually.
42	 *
43	 * SEE ALSO:
44	 * - http://www.netbsd.org/docs/kernel/elf-notes.html
45	 * - src/sys/sys/exec_elf.h
46	 * - src/lib/csu/common/sysident.S
47	 * - src/lib/csu/arch/sh3/crti.S
48	 */
49	.section ".note.netbsd.ident", "a"
50	.p2align 2
51	.long	7		/* ELF_NOTE_NETBSD_NAMESZ */
52	.long	4		/* ELF_NOTE_NETBSD_DESCSZ */
53	.long	1		/* ELF_NOTE_TYPE_NETBSD_TAG */
54	.ascii	"NetBSD\0\0"	/* ELF_NOTE_NETBSD_NAME */
55	.long	999010000	/* __NetBSD_Version__ (sys/sys/param.h) */
56
57
58	/* ------------------------------------------------------------------ */
59
60	.section ".rodata"
61message:
62	.ascii "Hello, world!\n"
63	.set MESSAGE_SIZE, . - message
64
65
66	/* ------------------------------------------------------------------ */
67
68	.section ".text"
69	.p2align 2
70
71	.global __start
72	.type _start, %function
73__start:
74	/* write(STDOUT_FILENO, message, MESSAGE_SIZE) */
75	mov	#1, r4			/* r4: fd = STDOUT_FILENO */
76	mov.l	.Lmessage, r5		/* r5: buf = message */
77	mov	#MESSAGE_SIZE, r6	/* r6: nbytes = MESSAGE_SIZE */
78	mov	#4, r0			/* SYS_write */
79	trapa	#0x80
80
81	/* exit(0) */
82	mov	#0, r4			/* r4: status = 0 */
83	mov	#1, r0			/* SYS_exit */
84	trapa	#0x80
85
86	.p2align 2
87.Lmessage:
88	.long	message
89
90	.size __start, . - __start
91