wip: going to try heuristic patching
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
635a9a2d48
commit
00fe7d0cdb
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1536
memtest/mem.init
1536
memtest/mem.init
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -11,7 +11,7 @@ module memtest (
|
||||
input clki
|
||||
);
|
||||
|
||||
reg [31:0] mem[0:511];
|
||||
reg [31:0] mem[0:2047];
|
||||
reg [10:0] memadr;
|
||||
assign random_rom_dat_r = mem[memadr];
|
||||
|
||||
|
1482
memtest/top.rpt
1482
memtest/top.rpt
File diff suppressed because it is too large
Load Diff
1922
output.txt
1922
output.txt
File diff suppressed because it is too large
Load Diff
BIN
rewrite-rom
BIN
rewrite-rom
Binary file not shown.
@ -182,8 +182,8 @@ int ice40_parse(struct irw_file *f)
|
||||
// try_4[i] = try_4[i + 1];
|
||||
// try_4[i + 1] = t;
|
||||
// }
|
||||
// printf("try 2:\n");
|
||||
// print_hex(try_2, sizeof(try_2), 0);
|
||||
printf("try 1:\n");
|
||||
print_hex(try_1, sizeof(try_1), (!!bs.current_offset) * (bs.current_width * bs.current_height) / 8);
|
||||
// printf("try 3:\n");
|
||||
// print_hex(try_3, sizeof(try_3), 0);
|
||||
// printf("try 4:\n");
|
||||
@ -371,7 +371,7 @@ uint32_t swap_u32(uint32_t word) {
|
||||
|
||||
// 1. Read ROM file into `input`
|
||||
// 2. For each pair of bytes of input,
|
||||
uint16_t mappings[65536];
|
||||
// uint16_t mappings[65536];
|
||||
int ice40_patch(struct irw_file *f, struct irw_file *rom, struct irw_file *o)
|
||||
{
|
||||
uint32_t preamble = 0;
|
||||
@ -384,10 +384,12 @@ int ice40_patch(struct irw_file *f, struct irw_file *rom, struct irw_file *o)
|
||||
uint8_t *i8 = (uint8_t *)input_rom;
|
||||
uint16_t *ora16 = (uint16_t *)output_rand;
|
||||
uint16_t *oro16 = (uint16_t *)output_rom;
|
||||
unsigned int ora_ptr;
|
||||
unsigned int ora_matches;
|
||||
int b;
|
||||
struct mapping mapping;
|
||||
// struct mapping mapping;
|
||||
|
||||
memset(&mapping, 0, sizeof(mapping));
|
||||
// memset(&mapping, 0, sizeof(mapping));
|
||||
memset(&bs, 0, sizeof(bs));
|
||||
|
||||
int input_ptr;
|
||||
@ -424,23 +426,23 @@ int ice40_patch(struct irw_file *f, struct irw_file *rom, struct irw_file *o)
|
||||
clear_bit(output_rom, input_ptr);
|
||||
}
|
||||
|
||||
// Finally, build a mapping from the random data to the replacement rom data.
|
||||
uint32_t collisions = 0;
|
||||
for (input_ptr = 0; input_ptr < 4096; input_ptr += 1) {
|
||||
// uint32_t ra1 = (output_rand[input_ptr + 0] & 0xffff0000)
|
||||
// | ((output_rand[input_ptr + 1] >> 16) & 0x0000ffff);
|
||||
// uint32_t ra2 = (output_rand[input_ptr + 1] & 0xffff0000)
|
||||
// | ((output_rand[input_ptr + 0] >> 16) & 0x0000ffff);
|
||||
// add_mapping(&mapping, ra1, output_rom[input_ptr + 0]);
|
||||
// add_mapping(&mapping, ra2, output_rom[input_ptr + 1]);
|
||||
if (mappings[ora16[input_ptr]]) {
|
||||
collisions++;
|
||||
printf("mapping position %d not empty\n", input_ptr);
|
||||
}
|
||||
mappings[ora16[input_ptr]] = oro16[input_ptr];
|
||||
}
|
||||
if (collisions)
|
||||
printf("had %d collisions\n", collisions);
|
||||
// // Finally, build a mapping from the random data to the replacement rom data.
|
||||
// uint32_t collisions = 0;
|
||||
// for (input_ptr = 0; input_ptr < 4096; input_ptr += 1) {
|
||||
// // uint32_t ra1 = (output_rand[input_ptr + 0] & 0xffff0000)
|
||||
// // | ((output_rand[input_ptr + 1] >> 16) & 0x0000ffff);
|
||||
// // uint32_t ra2 = (output_rand[input_ptr + 1] & 0xffff0000)
|
||||
// // | ((output_rand[input_ptr + 0] >> 16) & 0x0000ffff);
|
||||
// // add_mapping(&mapping, ra1, output_rom[input_ptr + 0]);
|
||||
// // add_mapping(&mapping, ra2, output_rom[input_ptr + 1]);
|
||||
// if (mappings[ora16[input_ptr]]) {
|
||||
// collisions++;
|
||||
// printf("mapping position %d not empty\n", input_ptr);
|
||||
// }
|
||||
// mappings[ora16[input_ptr]] = oro16[input_ptr];
|
||||
// }
|
||||
// if (collisions)
|
||||
// printf("had %d collisions\n", collisions);
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -522,7 +524,7 @@ int ice40_patch(struct irw_file *f, struct irw_file *rom, struct irw_file *o)
|
||||
bs.bram_height = MAX(bs.bram_height, bs.current_height);
|
||||
for (i = 0; i < ((bs.current_width * bs.current_height) / 8); i += 2)
|
||||
{
|
||||
uint32_t word =
|
||||
uint16_t word =
|
||||
// ((irw_readb(f) << 24) & 0xff000000)
|
||||
// |
|
||||
// ((irw_readb(f) << 16) & 0x00ff0000)
|
||||
@ -531,11 +533,36 @@ int ice40_patch(struct irw_file *f, struct irw_file *rom, struct irw_file *o)
|
||||
|
|
||||
((irw_readb(f) << 0) & 0x000000ff)
|
||||
;
|
||||
int words_per_block = 0;
|
||||
if (bs.current_width == 160)
|
||||
words_per_block = 5;
|
||||
else if (bs.current_width == 80)
|
||||
words_per_block = 3;
|
||||
else
|
||||
printf("unrecognized width: %d\n", bs.current_width);
|
||||
if (ora_matches >= words_per_block) {
|
||||
ora_matches = 0;
|
||||
ora_ptr = ora_ptr + 10;
|
||||
}
|
||||
int i;
|
||||
int found = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (ora16[i + ora_ptr] == word) {
|
||||
found = 1;
|
||||
printf("found %04x @ %d\n", word, i + ora_ptr);
|
||||
word = oro16[i + ora_ptr];
|
||||
ora_matches++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
printf("couldn't find word %04x\n", word);
|
||||
}
|
||||
// printf("%04x -> %04x\n", word, mapping[word]);
|
||||
// word = get_mapping(&mapping, word);
|
||||
// irw_writeb(o, word >> 24);
|
||||
// irw_writeb(o, word >> 16);
|
||||
word = mappings[word];
|
||||
// word = mappings[word];
|
||||
irw_writeb(o, word >> 8);
|
||||
irw_writeb(o, word);
|
||||
}
|
||||
@ -569,6 +596,8 @@ int ice40_patch(struct irw_file *f, struct irw_file *rom, struct irw_file *o)
|
||||
// Set current bank
|
||||
case 1:
|
||||
bs.current_bank = payload;
|
||||
ora_ptr = 0;
|
||||
ora_matches = 0;
|
||||
// printf("setting bank number to %d\n", bs.current_bank);
|
||||
break;
|
||||
|
||||
@ -674,6 +703,8 @@ int main(int argc, char **argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
// struct irw_file *mem = irw_open("memtest/memtest.bin", "r");
|
||||
// ice40_parse(mem);
|
||||
ice40_patch(input, rom, output);
|
||||
return 0;
|
||||
}
|
4
xform.c
4
xform.c
@ -129,8 +129,8 @@ int main(int argc, char **argv)
|
||||
// printf("test_4: bit %d set\n", i);
|
||||
// }
|
||||
|
||||
uint32_t input[512] = {};
|
||||
uint32_t output[512] = {};
|
||||
uint32_t input[2048] = {};
|
||||
uint32_t output[2048] = {};
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
printf("bit %d: %d\n", i, get_bit_offset(i, sizeof(input)*8));
|
||||
|
Loading…
Reference in New Issue
Block a user