ucell load_dictionary(const char *data, ucell len) { u32 checksum=0; const char *checksum_walk; ucell *walk, *reloc_table; dictionary_header_t *header=(dictionary_header_t *)data; /* assertions */ if (len <= (sizeof(dictionary_header_t)) || strncmp(DICTID, data, 8)) return 0; #ifdef CONFIG_DEBUG_DICTIONARY dump_header(header); #endif checksum_walk=data; while (checksum_walk<data+len) { checksum+=read_long(checksum_walk); checksum_walk+=sizeof(u32); } if(checksum) { printk("Checksum invalid (%08x)!\n", checksum); return 0; } data += sizeof(dictionary_header_t); dicthead = target_long(header->length); memcpy(dict, data, dicthead); reloc_table=(ucell *)(data+dicthead); #ifdef CONFIG_DEBUG_DICTIONARY printk("\nmoving dictionary (%x bytes) to %x\n", (ucell)dicthead, (ucell)dict); printk("\ndynamic relocation..."); #endif for (walk = (ucell *) dict; walk < (ucell *) (dict + dicthead); walk++) { int pos, bit, l; l=(walk-(ucell *)dict); pos=l/BITS; bit=l&~(-BITS); if (reloc_table[pos] & target_ucell((ucell)1ULL << bit)) { // printk("%lx, pos %x, bit %d\n",*walk, pos, bit); write_ucell(walk, read_ucell(walk)+pointer2cell(dict)); } } #ifdef CONFIG_DEBUG_DICTIONARY printk(" done.\n"); #endif last = (ucell *)(dict + target_ucell(header->last)); return -1; }
static void store(void) { const ucell *aaddr = (ucell *)cell2pointer(POP()); const ucell x = POP(); #ifdef CONFIG_DEBUG_INTERNAL printk("!: %lx : %lx -> %lx\n", aaddr, read_ucell(aaddr), x); #endif write_ucell(aaddr,x); }