| 1 |
#!/usr/bin/env nickle |
| 2 |
|
| 3 |
autoimport Process; |
| 4 |
|
| 5 |
int byteflip(int x) { |
| 6 |
return ((x >> 24) & 0xff) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | ((x << 24) & 0xff000000); |
| 7 |
} |
| 8 |
|
| 9 |
void main () { |
| 10 |
file input = popen(popen_direction.read, true, "objdump", |
| 11 |
"objdump", "-j", ".text", |
| 12 |
"--start-address=0", |
| 13 |
"--stop-address=0x20", |
| 14 |
"-s", argv[1]); |
| 15 |
int sum = 0; |
| 16 |
|
| 17 |
void add_in(int addr, int value) { |
| 18 |
if (addr < 0x1c) { |
| 19 |
sum += value; |
| 20 |
} else if (addr == 0x1c) { |
| 21 |
printf ("-DCKSUM=0x%08x\n", -sum & 0xffffffff); |
| 22 |
exit(0); |
| 23 |
} |
| 24 |
} |
| 25 |
while (!File::end(input)) { |
| 26 |
string line = File::fgets(input); |
| 27 |
string[] words = String::wordsplit(line, " "); |
| 28 |
|
| 29 |
if (dim(words) < 5) |
| 30 |
continue; |
| 31 |
if (words[0] == "0000" || words[0] == "0010") { |
| 32 |
int addr = string_to_integer(words[0], 16); |
| 33 |
for (int i = 0; i < 4; i++) |
| 34 |
add_in(addr + i * 4, byteflip(string_to_integer(words[i+1], 16))); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
main(); |