Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/share/examples Add assembly language examples in a new 'asm'...



details:   https://anonhg.NetBSD.org/src/rev/5d147c05699c
branches:  trunk
changeset: 771139:5d147c05699c
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Sat Nov 12 01:18:40 2011 +0000

description:
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!)

diffstat:

 share/examples/Makefile                |   6 +-
 share/examples/asm/Makefile            |  14 ++++++
 share/examples/asm/Makefile.inc.inst   |  17 +++++++
 share/examples/asm/README              |  11 +++++
 share/examples/asm/hello/Makefile      |  11 +++++
 share/examples/asm/hello/Makefile.inst |  12 +++++
 share/examples/asm/hello/powerpc.s     |  74 ++++++++++++++++++++++++++++++++++
 7 files changed, 142 insertions(+), 3 deletions(-)

diffs (176 lines):

diff -r 8c893a3836f4 -r 5d147c05699c share/examples/Makefile
--- a/share/examples/Makefile   Fri Nov 11 23:01:59 2011 +0000
+++ b/share/examples/Makefile   Sat Nov 12 01:18:40 2011 +0000
@@ -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>
diff -r 8c893a3836f4 -r 5d147c05699c share/examples/asm/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/asm/Makefile       Sat Nov 12 01:18:40 2011 +0000
@@ -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>
diff -r 8c893a3836f4 -r 5d147c05699c share/examples/asm/Makefile.inc.inst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/asm/Makefile.inc.inst      Sat Nov 12 01:18:40 2011 +0000
@@ -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
diff -r 8c893a3836f4 -r 5d147c05699c share/examples/asm/README
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/asm/README Sat Nov 12 01:18:40 2011 +0000
@@ -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.
diff -r 8c893a3836f4 -r 5d147c05699c share/examples/asm/hello/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/asm/hello/Makefile Sat Nov 12 01:18:40 2011 +0000
@@ -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>
diff -r 8c893a3836f4 -r 5d147c05699c share/examples/asm/hello/Makefile.inst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/asm/hello/Makefile.inst    Sat Nov 12 01:18:40 2011 +0000
@@ -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>
diff -r 8c893a3836f4 -r 5d147c05699c share/examples/asm/hello/powerpc.s
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/asm/hello/powerpc.s        Sat Nov 12 01:18:40 2011 +0000
@@ -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



Home | Main Index | Thread Index | Old Index