1/*	$NetBSD: arm.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 arm.o arm.s
32 *  ld -o hello -e _start arm.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/arm/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	r0, #1			/* r0: fd = STDOUT_FILENO */
76	ldr	r1, .Lmessage		/* r1: buf = message */
77	mov	r2, #MESSAGE_SIZE	/* r2: nbytes = MESSAGE_SIZE */
78	svc	#(0xa00000 | 4)		/* SYS_write */
79
80	/* exit(0) */
81	mov	r0, #0			/* r0: status = 0 */
82	svc	#(0xa00000 | 1)		/* SYS_exit */
83
84	.p2align 2
85.Lmessage:
86	.word	message
87
88	.size _start, . - _start
89