#include #include #include #include const char *yaml_def = "#schemaversion 3.0.0\n" "root:\n" " class: MemDev\n" " size: 32\n" " children:\n" " mmio:\n" " at: { nelms: 1 }\n" " class: MMIODev\n" " size: 32\n" " children:\n" " GitHash:\n" " class: GmpZField\n" " at: { offset: 0 }\n" " sizeBits: 160\n" " RawMem:\n" " class: IntField\n" " sizeBits: 8\n" " at: { offset: 0, nelms: 20 }\n" ; int main() { Path r = IPath::loadYamlStream(yaml_def); ScalVal raw = IScalVal::create( r->findByName("mmio/RawMem") ); GmpZVal gitHash = IGmpZVal::create( r->findByName("mmio/GitHash") ); MPZ mpz; unsigned git_hash_len = raw->getNelms(); uint8_t hash_img[git_hash_len]; size_t written; // read large integer from string defined on commandline mpz_set_str( mpz.m_, GIT_HASH_LONG, 16 ); // export as little-endian, long number into 'hash_img' memory area if ( (mpz_sizeinbase( mpz.m_, 2 ) + 7) / 8 > git_hash_len ) { fprintf(stderr,"FATAL ERROR - memory image too small\n"); exit(1); } mpz_export( hash_img, &written, -1 /* Little_endian */, sizeof(uint8_t), 0, 0, mpz.m_ ); /* mpz_export only exports 'necessary' number of words */ memset( hash_img + written, 0, git_hash_len - written ); // Write into memory backed device; byte - by - byte raw->setVal( hash_img, git_hash_len ); // Test the CPSW-GMP interface gitHash->getVal( &mpz.m_, 1 ); printf("Git hash from CPSW: "); mpz_out_str(stdout, 16, mpz.m_ ); printf("\n"); return 0; }