1*aef5eb5fSryo/* $NetBSD: arm.s,v 1.1 2022/10/14 19:41:18 ryo Exp $ */ 2*aef5eb5fSryo 3*aef5eb5fSryo/*- 4*aef5eb5fSryo * Copyright (c) 2022 The NetBSD Foundation, Inc. 5*aef5eb5fSryo * All rights reserved. 6*aef5eb5fSryo * 7*aef5eb5fSryo * Redistribution and use in source and binary forms, with or without 8*aef5eb5fSryo * modification, are permitted provided that the following conditions 9*aef5eb5fSryo * are met: 10*aef5eb5fSryo * 1. Redistributions of source code must retain the above copyright 11*aef5eb5fSryo * notice, this list of conditions and the following disclaimer. 12*aef5eb5fSryo * 2. Redistributions in binary form must reproduce the above copyright 13*aef5eb5fSryo * notice, this list of conditions and the following disclaimer in the 14*aef5eb5fSryo * documentation and/or other materials provided with the distribution. 15*aef5eb5fSryo * 16*aef5eb5fSryo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17*aef5eb5fSryo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18*aef5eb5fSryo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19*aef5eb5fSryo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20*aef5eb5fSryo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*aef5eb5fSryo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*aef5eb5fSryo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23*aef5eb5fSryo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24*aef5eb5fSryo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25*aef5eb5fSryo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26*aef5eb5fSryo * POSSIBILITY OF SUCH DAMAGE. 27*aef5eb5fSryo */ 28*aef5eb5fSryo 29*aef5eb5fSryo/* 30*aef5eb5fSryo * assemble & link: 31*aef5eb5fSryo * as -o arm.o arm.s 32*aef5eb5fSryo * ld -o hello -e _start arm.o 33*aef5eb5fSryo */ 34*aef5eb5fSryo 35*aef5eb5fSryo /* ------------------------------------------------------------------ */ 36*aef5eb5fSryo 37*aef5eb5fSryo /* 38*aef5eb5fSryo * This ELF section is used by the kernel to determine, among other 39*aef5eb5fSryo * things, the system call interface used by the binary. 40*aef5eb5fSryo * 41*aef5eb5fSryo * Normally, /usr/lib/crti.o is linked, but here it is written manually. 42*aef5eb5fSryo * 43*aef5eb5fSryo * SEE ALSO: 44*aef5eb5fSryo * - http://www.netbsd.org/docs/kernel/elf-notes.html 45*aef5eb5fSryo * - src/sys/sys/exec_elf.h 46*aef5eb5fSryo * - src/lib/csu/common/sysident.S 47*aef5eb5fSryo * - src/lib/csu/arch/arm/crti.S 48*aef5eb5fSryo */ 49*aef5eb5fSryo .section ".note.netbsd.ident", "a" 50*aef5eb5fSryo .p2align 2 51*aef5eb5fSryo .long 7 /* ELF_NOTE_NETBSD_NAMESZ */ 52*aef5eb5fSryo .long 4 /* ELF_NOTE_NETBSD_DESCSZ */ 53*aef5eb5fSryo .long 1 /* ELF_NOTE_TYPE_NETBSD_TAG */ 54*aef5eb5fSryo .ascii "NetBSD\0\0" /* ELF_NOTE_NETBSD_NAME */ 55*aef5eb5fSryo .long 999010000 /* __NetBSD_Version__ (sys/sys/param.h) */ 56*aef5eb5fSryo 57*aef5eb5fSryo 58*aef5eb5fSryo /* ------------------------------------------------------------------ */ 59*aef5eb5fSryo 60*aef5eb5fSryo .section ".rodata" 61*aef5eb5fSryomessage: 62*aef5eb5fSryo .ascii "Hello, world!\n" 63*aef5eb5fSryo .set MESSAGE_SIZE, . - message 64*aef5eb5fSryo 65*aef5eb5fSryo 66*aef5eb5fSryo /* ------------------------------------------------------------------ */ 67*aef5eb5fSryo 68*aef5eb5fSryo .section ".text" 69*aef5eb5fSryo .p2align 2 70*aef5eb5fSryo 71*aef5eb5fSryo .global _start 72*aef5eb5fSryo .type _start, %function 73*aef5eb5fSryo_start: 74*aef5eb5fSryo /* write(STDOUT_FILENO, message, MESSAGE_SIZE) */ 75*aef5eb5fSryo mov r0, #1 /* r0: fd = STDOUT_FILENO */ 76*aef5eb5fSryo ldr r1, .Lmessage /* r1: buf = message */ 77*aef5eb5fSryo mov r2, #MESSAGE_SIZE /* r2: nbytes = MESSAGE_SIZE */ 78*aef5eb5fSryo svc #(0xa00000 | 4) /* SYS_write */ 79*aef5eb5fSryo 80*aef5eb5fSryo /* exit(0) */ 81*aef5eb5fSryo mov r0, #0 /* r0: status = 0 */ 82*aef5eb5fSryo svc #(0xa00000 | 1) /* SYS_exit */ 83*aef5eb5fSryo 84*aef5eb5fSryo .p2align 2 85*aef5eb5fSryo.Lmessage: 86*aef5eb5fSryo .word message 87*aef5eb5fSryo 88*aef5eb5fSryo .size _start, . - _start 89