1/* 2 * Convert a data file into a .S file suitable for assembly. 3 * This reads from stdin and writes to stdout and takes a single 4 * argument for the name of the symbol in the assembly file. 5 */ 6 7#include <stdio.h> 8 9int main(int argc, char *argv[]) { 10 unsigned char buf[4096]; 11 size_t amt; 12 size_t i; 13 int col = 0; 14 char *name = argv[1]; 15 16 printf("\ 17#ifdef __APPLE_CC__\n\ 18/*\n\ 19 * The mid-2007 version of gcc that ships with Macs requires a\n\ 20 * comma on the .section line, but the rest of the world thinks\n\ 21 * that's a syntax error. It also wants globals to be explicitly\n\ 22 * prefixed with \"_\" as opposed to modern gccs that do the\n\ 23 * prefixing for you.\n\ 24 */\n\ 25.globl _%s\n\ 26 .section .rodata,\n\ 27 .align 8\n\ 28_%s:\n\ 29#else\n\ 30.globl %s\n\ 31 .section .rodata\n\ 32 .align 8\n\ 33%s:\n\ 34#endif\n\ 35", name, name, name, name); 36 37 while (! feof(stdin)) { 38 amt = fread(buf, 1, sizeof(buf), stdin); 39 for (i = 0; i < amt; i++) { 40 printf((col == 0) ? ".byte %3d" : ",%3d", buf[i]); 41 col++; 42 if (col == 16) { 43 printf("\n"); 44 col = 0; 45 } 46 } 47 } 48 49 if (col != 0) { 50 printf("\n"); 51 } 52} 53