Last active
December 20, 2015 07:59
-
-
Save satokjp/6097437 to your computer and use it in GitHub Desktop.
PDP-11 a.out binary C
Mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| cc header.c -o header | |
| */ | |
| #include <stdio.h> | |
| #include <stdint.h> | |
| uint8_t mem[0x10000]; | |
| /**************************************************/ | |
| // Little Endian | |
| /**************************************************/ | |
| uint16_t w_l_uint16(int i){ | |
| return mem[i] | (mem[i + 1] << 8); | |
| } | |
| /**************************************************/ | |
| // Big Endian | |
| /**************************************************/ | |
| uint16_t w_s_uint16(int i){ | |
| return ( mem[i] << 8 ) | mem[i + 1] ; | |
| } | |
| /**************************************************/ | |
| /**************************************************/ | |
| int ana_text(int tsize) | |
| { | |
| uint16_t w0, w1; | |
| for (int i = 0; i < tsize; i += 2) { | |
| w0 = w_l_uint16(i) ; | |
| switch (w0){ | |
| case 0x15c0 : | |
| w1 = w_l_uint16(i+2) ; | |
| printf("%2x: 15c0 %04x \t mov $%d, r0 \n",i,w1,w1); | |
| i += 2; | |
| break; | |
| case 0x8904 : | |
| // write | |
| printf("%2x: %04x \t sys 4\n",i,w0); | |
| i += 2; | |
| w1 = w_l_uint16(i) ; | |
| // word | |
| printf("%2x: %04x \t word %o \n",i,w1,w1); | |
| i += 2; | |
| w1 = w_l_uint16(i) ; | |
| // rtt | |
| printf("%2x: %04x \t rtt \n",i,w1); | |
| break; | |
| case 0x8901 : | |
| printf("%2x: %04x \t sys 1\n",i,w0); | |
| break; | |
| default: | |
| printf("%2x: error %04x \n",i,w0); | |
| break; | |
| } | |
| } | |
| return 0 ; | |
| } | |
| /**************************************************/ | |
| /**************************************************/ | |
| int main(int argc, char *argv[]) { | |
| FILE *f; | |
| uint8_t header[16]; | |
| uint16_t w ; | |
| int tsize, dsize; | |
| // command line | |
| if (argc != 2) { | |
| printf("Command Line Error !\n"); | |
| return 1; | |
| } | |
| // file open | |
| f = fopen(argv[1], "rb"); | |
| if (!f) { | |
| printf("file not fund!\n"); | |
| return 1; | |
| } | |
| // read header area | |
| fread(header, sizeof(header), 1, f); | |
| // text size | |
| w = header[2] | (header[3] << 8); | |
| tsize = w ; | |
| // data size | |
| w = header[4] | (header[5] << 8); | |
| dsize = w ; | |
| printf("tsize = 0x%04x, dsize = 0x%04x\n", tsize, dsize); | |
| // read text & data area | |
| fread(mem, tsize + dsize, 1, f); | |
| fclose(f); | |
| // .text | |
| printf("session: .text \n"); | |
| ana_text(tsize); | |
| // .data | |
| printf("session: .data\n"); | |
| for (int i = tsize; i < tsize + dsize; i += 2) { | |
| w = w_s_uint16(i); | |
| printf("%04x: %04x\n", i, w); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment