Use the correct names for the __ARM_NR_* syscalls.

This lets us move all the ARM syscall stubs over to the kernel <asm/unistd.h>.
Our generated <sys/linux-syscalls.h> is now unused, but I'll remove that in a
later change.

Change-Id: Ie5ff2cc4abce1938576af7cbaef615a79c7f310d
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 26cf3a5..2e87e03 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -76,9 +76,9 @@
 #
 
 arm_header = """/* autogenerated by gensyscalls.py */
+#include <asm/unistd.h>
 #include <linux/err.h>
 #include <machine/asm.h>
-#include <sys/linux-syscalls.h>
 
 ENTRY(%(fname)s)
 """
@@ -191,6 +191,14 @@
             count += 1
     return count
 
+# This lets us support regular system calls like __NR_write and also weird
+# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
+def make__NR_name(name):
+    if name.startswith("__"):
+        return name
+    else:
+        return "__NR_%s" % (name)
+
 class State:
     def __init__(self):
         self.old_stubs = []
@@ -286,25 +294,25 @@
 
             if t["common"] >= 0 or t["armid"] >= 0:
                 num_regs = count_arm_param_registers(syscall_params)
-                t["asm-arm"] = self.arm_eabi_genstub(syscall_func,num_regs,"__NR_"+syscall_name)
+                t["asm-arm"] = self.arm_eabi_genstub(syscall_func, num_regs, make__NR_name(syscall_name))
 
             if t["common"] >= 0 or t["x86id"] >= 0:
                 num_regs = count_generic_param_registers(syscall_params)
                 if t["cid"] >= 0:
-                    t["asm-x86"] = self.x86_genstub_cid(syscall_func, num_regs, "__NR_"+syscall_name, t["cid"])
+                    t["asm-x86"] = self.x86_genstub_cid(syscall_func, num_regs, make__NR_name(syscall_name), t["cid"])
                 else:
-                    t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, "__NR_"+syscall_name)
+                    t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, make__NR_name(syscall_name))
             elif t["cid"] >= 0:
                 E("cid for dispatch syscalls is only supported for x86 in "
                   "'%s'" % syscall_name)
                 return
 
             if t["common"] >= 0 or t["mipsid"] >= 0:
-                t["asm-mips"] = self.mips_genstub(syscall_func,"__NR_"+syscall_name)
+                t["asm-mips"] = self.mips_genstub(syscall_func, make__NR_name(syscall_name))
 
 
     def gen_NR_syscall(self, linux_fp, name, id):
-        linux_fp.write("#define __NR_%-25s    (__NR_SYSCALL_BASE + %d)\n" % (name,id))
+        linux_fp.write("#define %-30s    (__NR_SYSCALL_BASE + %d)\n" % (make__NR_name(name),id))
 
 
     def scan_linux_unistd_h(self, fp, path):
@@ -315,10 +323,11 @@
             if m:
                 syscalls.add(m.group(1))
         for syscall in sorted(syscalls):
-            fp.write("#define SYS_%s __NR_%s\n" % (syscall, syscall))
+            fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
 
 
     def gen_linux_syscalls_h(self):
+        # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
         glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
         glibc_fp = create_file(glibc_syscalls_h_path)
         glibc_fp.write("/* Auto-generated by gensyscalls.py; do not edit. */\n")
@@ -337,6 +346,7 @@
         glibc_fp.close()
         self.other_files.append(glibc_syscalls_h_path)
 
+        # TODO: stop generating this. it's useless.
         linux_syscalls_h_path = "include/sys/linux-syscalls.h"
         D("generating " + linux_syscalls_h_path)
         fp = create_file(linux_syscalls_h_path)
@@ -344,9 +354,8 @@
         fp.write( "#ifndef _BIONIC_LINUX_SYSCALLS_H_\n" )
         fp.write( "#define _BIONIC_LINUX_SYSCALLS_H_\n\n" )
         fp.write( "#if !defined __ASM_ARM_UNISTD_H && !defined __ASM_I386_UNISTD_H && !defined __ASM_MIPS_UNISTD_H\n" )
-        fp.write( "#if defined __arm__ && !defined __ARM_EABI__ && !defined __thumb__\n" )
-        fp.write( "  #  define __NR_SYSCALL_BASE 0x900000\n" )
-        fp.write( "#elif defined(__mips__)\n" )
+
+        fp.write( "#if defined(__mips__)\n" )
         fp.write( "  #  define __NR_SYSCALL_BASE 4000\n" )
         fp.write( "#else\n" )
         fp.write( "  #  define __NR_SYSCALL_BASE 0\n" )