summaryrefslogtreecommitdiffstats
path: root/tools/bin2asm
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commitb6c1cf6de79035f58b512f4400db458c8401379a (patch)
tree68979db37c85b499bc384e4ac337ed1424baab51 /tools/bin2asm
downloadbuild-b6c1cf6de79035f58b512f4400db458c8401379a.zip
build-b6c1cf6de79035f58b512f4400db458c8401379a.tar.gz
build-b6c1cf6de79035f58b512f4400db458c8401379a.tar.bz2
Initial Contribution
Diffstat (limited to 'tools/bin2asm')
-rw-r--r--tools/bin2asm/Android.mk24
-rw-r--r--tools/bin2asm/data52
-rw-r--r--tools/bin2asm/icudata.c72
3 files changed, 148 insertions, 0 deletions
diff --git a/tools/bin2asm/Android.mk b/tools/bin2asm/Android.mk
new file mode 100644
index 0000000..4522a20
--- /dev/null
+++ b/tools/bin2asm/Android.mk
@@ -0,0 +1,24 @@
+# Copyright (C) 2008 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ icudata.c
+
+LOCAL_MODULE := icudata
+
+include $(BUILD_HOST_EXECUTABLE)
+
diff --git a/tools/bin2asm/data b/tools/bin2asm/data
new file mode 100644
index 0000000..3be865f
--- /dev/null
+++ b/tools/bin2asm/data
@@ -0,0 +1,52 @@
+/*
+ * Convert a data file into a .S file suitable for assembly.
+ * This reads from stdin and writes to stdout and takes a single
+ * argument for the name of the symbol in the assembly file.
+ */
+
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+ unsigned char buf[4096];
+ size_t amt;
+ size_t i;
+ int col = 0;
+ char *name = argv[1];
+
+ printf("\
+#ifdef __APPLE_CC__\n\
+/*\n\
+ * The mid-2007 version of gcc that ships with Macs requires a\n\
+ * comma on the .section line, but the rest of the world thinks\n\
+ * that's a syntax error. It also wants globals to be explicitly\n\
+ * prefixed with \"_\" as opposed to modern gccs that do the\n\
+ * prefixing for you.\n\
+ */\n\
+.globl _%s\n\
+ .section .rodata,\n\
+ .align 8\n\
+_%s:\n\
+#else\n\
+.globl %s\n\
+ .section .rodata\n\
+ .align 8\n\
+%s:\n\
+#endif\n\
+", name, name, name, name);
+
+ while (! feof(stdin)) {
+ amt = fread(buf, 1, sizeof(buf), stdin);
+ for (i = 0; i < amt; i++) {
+ printf((col == 0) ? ".byte %3d" : ",%3d", buf[i]);
+ col++;
+ if (col == 16) {
+ printf("\n");
+ col = 0;
+ }
+ }
+ }
+
+ if (col != 0) {
+ printf("\n");
+ }
+}
diff --git a/tools/bin2asm/icudata.c b/tools/bin2asm/icudata.c
new file mode 100644
index 0000000..ecd1b4b
--- /dev/null
+++ b/tools/bin2asm/icudata.c
@@ -0,0 +1,72 @@
+/*
+ * Convert a data file into a .S file suitable for assembly.
+ * This reads from stdin and writes to stdout and takes a single
+ * argument for the name of the symbol in the assembly file.
+ */
+
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+ unsigned char buf[4096];
+ size_t amt;
+ size_t i;
+ int col = 0;
+ char *name;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s NAME < DAT_FILE > ASM_FILE\n", argv[0]);
+ for (i=0; i<argc; i++) {
+ fprintf(stderr, " '%s'", argv[i]);
+ }
+ fprintf(stderr, "\n");
+ return 1;
+ }
+
+ name = argv[1];
+
+ printf("\
+#ifdef __APPLE_CC__\n\
+/*\n\
+ * The mid-2007 version of gcc that ships with Macs requires a\n\
+ * comma on the .section line, but the rest of the world thinks\n\
+ * that's a syntax error. It also wants globals to be explicitly\n\
+ * prefixed with \"_\" as opposed to modern gccs that do the\n\
+ * prefixing for you.\n\
+ */\n\
+.globl _%s\n\
+ .section .rodata,\n\
+ .align 8\n\
+_%s:\n\
+#else\n\
+.globl %s\n\
+ .section .rodata\n\
+ .align 8\n\
+%s:\n\
+#endif\n\
+", name, name, name, name);
+
+ while (! feof(stdin)) {
+ amt = fread(buf, 1, sizeof(buf), stdin);
+ for (i = 0; i < amt; i++) {
+ if (col == 0) {
+ printf(".byte ");
+ }
+ printf("0x%02x", buf[i]);
+ col++;
+ if (col == 16) {
+ printf("\n");
+ col = 0;
+ } else if (col % 4 == 0) {
+ printf(", ");
+ } else {
+ printf(",");
+ }
+ }
+ }
+
+ if (col != 0) {
+ printf("\n");
+ }
+
+ return 0;
+}