summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-06-17 15:54:57 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-06-17 15:54:57 (GMT)
commit6cd83eb2dd7dea65db9a5431159b787af61a869f (patch)
treee03c19297b1704f79bc7bb43ae21faecfe0cb098
parent994496f3d5e26658448242c5c80c499593112577 (diff)
Added a small file to play with syscalls.
-rw-r--r--ARM/syscalls/Makefile8
-rw-r--r--ARM/syscalls/syscalls.asm73
2 files changed, 81 insertions, 0 deletions
diff --git a/ARM/syscalls/Makefile b/ARM/syscalls/Makefile
new file mode 100644
index 0000000..17a84e7
--- /dev/null
+++ b/ARM/syscalls/Makefile
@@ -0,0 +1,8 @@
+
+all: syscalls
+
+syscalls: syscalls.asm
+ grep .global syscalls.asm | cut -d ' ' -f 2 > keep.lst
+ arm-linux-gnueabi-as -o syscalls.o syscalls.asm
+ arm-linux-gnueabi-ld -s --retain-symbols-file=keep.lst -o syscalls syscalls.o
+ rm -f keep.lst
diff --git a/ARM/syscalls/syscalls.asm b/ARM/syscalls/syscalls.asm
new file mode 100644
index 0000000..1812e3b
--- /dev/null
+++ b/ARM/syscalls/syscalls.asm
@@ -0,0 +1,73 @@
+
+.data
+
+msg:
+ .ascii "Hello, ARM!\n"
+
+len = . - msg
+
+no_arg_msg:
+ .ascii "No command line argument...\n"
+
+no_arg_len = . - no_arg_msg
+
+got_arg_msg:
+ .ascii "Got command line argument(s)...\n"
+
+got_arg_len = . - got_arg_msg
+
+.text
+
+.global do_syscalls
+
+do_syscalls:
+
+ /**
+ * syscall write(int fd, const void *buf, size_t count)
+ */
+
+ mov %r0, $1 /* fd -> stdout */
+ ldr %r1, =msg /* buf -> msg */
+ ldr %r2, =len /* count -> len(msg) */
+ mov %r7, $4 /* write is syscall #4 */
+ swi $0 /* invoke syscall */
+
+ /**
+ * syscall write(int fd, const void *buf, size_t count)
+ */
+
+ mov %r0, $2 /* fd -> stderr */
+ mov %r7, $4 /* write is syscall #4 */
+
+ ldr %r3, [sp] /* argc */
+ cmp %r3, $1
+
+ beq no_arg
+
+ ldr %r1, =got_arg_msg /* buf -> msg */
+ ldr %r2, =got_arg_len /* count -> len(msg) */
+
+ b process_arg
+
+no_arg:
+
+ ldr %r1, =no_arg_msg /* buf -> msg */
+ ldr %r2, =no_arg_len /* count -> len(msg) */
+
+process_arg:
+
+ swi $0 /* invoke syscall */
+
+ /**
+ * syscall exit(int status)
+ */
+
+ mov %r0, $123 /* status -> 0 */
+ mov %r7, $1 /* exit is syscall #1 */
+ swi $0 /* invoke syscall */
+
+.global _start
+
+_start:
+
+ bl do_syscalls