Module Name:    src
Committed By:   jmmv
Date:           Sat Nov 12 01:18:41 UTC 2011

Modified Files:
        src/share/examples: Makefile
Added Files:
        src/share/examples/asm: Makefile Makefile.inc.inst README
        src/share/examples/asm/hello: Makefile Makefile.inst powerpc.s

Log Message:
Add assembly language examples in a new 'asm' subdirectory.

At the moment this only provides an example for a "Hello world" program
for powerpc.  (Bear with me: this is my very first assembly program in
powerpc; if you find anything stupid in the code, please fix it!)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/share/examples/Makefile
cvs rdiff -u -r0 -r1.1 src/share/examples/asm/Makefile \
    src/share/examples/asm/Makefile.inc.inst src/share/examples/asm/README
cvs rdiff -u -r0 -r1.1 src/share/examples/asm/hello/Makefile \
    src/share/examples/asm/hello/Makefile.inst \
    src/share/examples/asm/hello/powerpc.s

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/Makefile
diff -u src/share/examples/Makefile:1.19 src/share/examples/Makefile:1.20
--- src/share/examples/Makefile:1.19	Sat Oct 15 13:01:00 2011
+++ src/share/examples/Makefile	Sat Nov 12 01:18:40 2011
@@ -1,6 +1,6 @@
-#	$NetBSD: Makefile,v 1.19 2011/10/15 13:01:00 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.20 2011/11/12 01:18:40 jmmv Exp $
 
-SUBDIR= amd apm disktab emul fstab ftpd getdate hostapd isdn lua pppd racoon \
-	supfiles syslogd wsmoused
+SUBDIR= amd apm asm disktab emul fstab ftpd getdate hostapd isdn lua pppd \
+	racoon supfiles syslogd wsmoused
 
 .include <bsd.subdir.mk>

Added files:

Index: src/share/examples/asm/Makefile
diff -u /dev/null src/share/examples/asm/Makefile:1.1
--- /dev/null	Sat Nov 12 01:18:41 2011
+++ src/share/examples/asm/Makefile	Sat Nov 12 01:18:41 2011
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2011/11/12 01:18:41 jmmv Exp $
+
+.include <bsd.own.mk>
+
+SUBDIR= 	hello
+
+.if ${MKSHARE} != "no"
+FILES=		Makefile.inc.inst README
+FILESDIR=	/usr/share/examples/asm
+FILESNAME_Makefile.inc.inst=	Makefile.inc
+.endif
+
+.include <bsd.files.mk>
+.include <bsd.subdir.mk>
Index: src/share/examples/asm/Makefile.inc.inst
diff -u /dev/null src/share/examples/asm/Makefile.inc.inst:1.1
--- /dev/null	Sat Nov 12 01:18:41 2011
+++ src/share/examples/asm/Makefile.inc.inst	Sat Nov 12 01:18:41 2011
@@ -0,0 +1,17 @@
+# $NetBSD: Makefile.inc.inst,v 1.1 2011/11/12 01:18:41 jmmv Exp $
+
+# This common Makefile includes logic shared among all the assembly language
+# sample programs.  The code in here is completely optional: i.e. each of the
+# Makefiles inside a particular sample must not depend on this file at all.
+# This is to allow the user to copy the sample directory anywhere else and
+# build the code without having to care about other dependencies.
+
+# The check-implemented target is used by the tests in /usr/tests to determine
+# whether a particular example should be built and tested on a platform.
+.PHONY: check-implemented
+check-implemented:
+.if defined(PROG) && !empty(PROG)
+	@echo yes
+.else
+	@echo no
+.endif
Index: src/share/examples/asm/README
diff -u /dev/null src/share/examples/asm/README:1.1
--- /dev/null	Sat Nov 12 01:18:41 2011
+++ src/share/examples/asm/README	Sat Nov 12 01:18:41 2011
@@ -0,0 +1,11 @@
+$NetBSD: README,v 1.1 2011/11/12 01:18:41 jmmv Exp $
+
+This directory contains example programs written in assembly language
+for a variety of platforms.  They are intended to illustrate the
+specific details of how to write assembly code on a given platform;
+they are not supposed to teach assembly (althogh they might have this
+side-effect).
+
+If you want to build one of these example programs, you can "cp -rf"
+the corresponding directory anywhere else where you have write
+permissions and then issue a "make" within the directory.

Index: src/share/examples/asm/hello/Makefile
diff -u /dev/null src/share/examples/asm/hello/Makefile:1.1
--- /dev/null	Sat Nov 12 01:18:41 2011
+++ src/share/examples/asm/hello/Makefile	Sat Nov 12 01:18:41 2011
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1 2011/11/12 01:18:41 jmmv Exp $
+
+.include <bsd.own.mk>
+
+.if ${MKSHARE} != "no"
+FILES=		Makefile.inst powerpc.s
+FILESDIR=	/usr/share/examples/asm/hello
+FILESNAME_Makefile.inst=	Makefile
+.endif
+
+.include <bsd.prog.mk>
Index: src/share/examples/asm/hello/Makefile.inst
diff -u /dev/null src/share/examples/asm/hello/Makefile.inst:1.1
--- /dev/null	Sat Nov 12 01:18:41 2011
+++ src/share/examples/asm/hello/Makefile.inst	Sat Nov 12 01:18:41 2011
@@ -0,0 +1,12 @@
+# $NetBSD: Makefile.inst,v 1.1 2011/11/12 01:18:41 jmmv Exp $
+
+.include <bsd.own.mk>
+
+.if exists(${MACHINE_ARCH}.s)
+PROG=		hello
+MAN=		# empty
+LDFLAGS=	-nostdlib
+SRCS=		${MACHINE_ARCH}.s
+.endif
+
+.include <bsd.prog.mk>
Index: src/share/examples/asm/hello/powerpc.s
diff -u /dev/null src/share/examples/asm/hello/powerpc.s:1.1
--- /dev/null	Sat Nov 12 01:18:41 2011
+++ src/share/examples/asm/hello/powerpc.s	Sat Nov 12 01:18:41 2011
@@ -0,0 +1,74 @@
+# $NetBSD: powerpc.s,v 1.1 2011/11/12 01:18:41 jmmv Exp $
+#
+# Copyright (c) 2011 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+# ------------------------------------------------------------------------
+
+.section ".note.netbsd.ident", "a"
+	# This ELF section is used by the kernel to determine, among other
+	# things, the system call interface used by the binary.
+	#
+	# See http://www.netbsd.org/docs/kernel/elf-notes.html for more
+	# details.
+
+	.int 7			# Length of the OS name field below.
+	.int 4			# Length of the description field below.
+	.int 0x01		# The type of the note: NetBSD OS Version.
+	.ascii	"NetBSD\0\0"	# The OS name, padded to 8 bytes.
+	.int 0x23b419a0		# The description value; 5.99.56.
+
+# ------------------------------------------------------------------------
+
+.section ".data"
+
+message:
+	.ascii "Hello, world!\n"
+	.set MESSAGE_SIZE, . - message
+
+# ------------------------------------------------------------------------
+
+.section ".text"
+
+	.balign 4
+
+	.globl _start
+	.type _start, @function
+_start:
+	# write(STDOUT_FILENO, message, MESSAGE_SIZE)
+	li	%r0, 4			# r0: write(2) syscall number.
+	li	%r3, 1			# r3: first argument.
+	addis	%r4, %r0, message@h	# r4: second argument.
+	ori	%r4, %r4, message@l
+	li	%r5, MESSAGE_SIZE	# r5: third argument.
+	sc
+
+	# exit(EXIT_SUCCESS)
+	li	%r0, 1			# r0: exit(2) syscall number.
+	li	%r3, 0			# r3: first argument.
+	sc
+
+    .size _start, . - _start

Reply via email to