|
|
1.1 root 1: /* Copyright 1989 by AT&T Bell Laboratories */
2: /* slinkdata.c -- group files into text segment of a .s file */
3:
4: #ifndef MIPS
5: #define DATALIST "_datalist"
6: #define END_SYMBOL "_endmo"
7: #define WORD ".long"
8: #else
9: #define DATALIST "datalist"
10: #define END_SYMBOL "endmo"
11: #define WORD ".word"
12: #endif
13:
14: #include "tags.h"
15: #include <sys/types.h>
16: #include <sys/stat.h>
17: #include <stdio.h>
18:
19: void die(s)
20: char *s;
21: {
22: perror(s);
23: exit(1);
24: }
25:
26:
27: #define WORDS_PER_LINE 6
28: main(argc, argv)
29: int argc;
30: char *argv[];
31: {
32: int i, sz, n;
33: struct stat st;
34: FILE *in;
35: int buf[WORDS_PER_LINE];
36:
37: if (argc <= 1) die("Not enough arguments");
38:
39: printf(".text\n.globl %s\n", DATALIST);
40:
41:
42: for (i=1; i<argc; i++) {
43: printf(".align 2\n");
44: printf("1: %s 0x31\n",WORD); /* descriptor */
45: if (i==1) printf("%s: ",DATALIST);
46: printf("%s 2f+4\n",WORD); /* filename */
47: printf("%s 3f+4\n",WORD); /* contents */
48: printf("%s %s\n",WORD,i==argc-1 ? "1" : "1f+4"); /* next entry */
49: printf("2: %s %d\n",WORD,mak_desc(strlen(argv[i]),tag_string));
50: printf(".ascii \"%s\"\n",argv[i]);
51: printf(".align 2\n");
52: if (stat(argv[i], &st) == -1)
53: die("stat");
54: sz = st.st_size;
55: if (sz % 4 != 0) die ("file size not a multiple of 4");
56: printf("3:%s %d\n",WORD,mak_desc(sz,tag_string));
57: if ((in=fopen(argv[i],"r"))==NULL) die ("open");
58: while(n=fread(buf,sizeof(int),WORDS_PER_LINE,in)) {
59: int j=0;
60: printf("%s 0x%x",WORD,buf[0]);
61: for(j=1;j<n;j++) printf(", 0x%x",buf[j]);
62: printf("\n");
63: }
64: fclose(in);
65: }
66: }
67:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.