uint64_t get_check_value(uint8_t track[], int length, CRC_INFO *crc_info, CHECK_TYPE check_type) { uint64_t value; if (check_type == CHECK_CRC) { value = crc64(track, length, crc_info); } else if (check_type == CHECK_CHKSUM) { value = checksum64(track, length, crc_info); if (crc_info->length == 16) { value = value & 0xff; } else if (crc_info->length == 32) { value = value & 0xffff; } else { msg(MSG_FATAL, "Unsupported checksum length %d\n",crc_info->length); exit(1); } } else if (check_type == CHECK_PARITY) { value = parity64(track, length, crc_info); } else { msg(MSG_FATAL, "Unknown check_type %d\n",check_type); exit(1); } return value; }
int main(int argc, char *argv[]) { int nn,qq; static char fname[500]; char *p; ofp = stdout; nn = processOptions(argc, argv); if (nn > argc-1) { displayHelp(); return 0; } strcpy(fname, argv[nn]); mfndx = 0; start_address = 0; code_address = 0; bss_address = 0; for (qq = 0; qq < 12; qq++) sections[qq].Clear(); nmTable.Clear(); memset(masterFile,0,sizeof(masterFile)); if (verbose) printf("Pass 1 - collect all input files.\r\n"); processFile(fname,0); // Pass 1, collect all include files if (debug) { FILE *fp; fp = fopen("a64-master.asm", "w"); if (fp) { fwrite(masterFile, 1, strlen(masterFile), fp); fclose(fp); } } if (verbose) printf("Pass 2 - group and reorder segments\r\n"); processSegments(); // Pass 2, group and order segments pass = 3; if (verbose) printf("Pass 3 - get all symbols, set initial values.\r\n"); processMaster(); pass = 4; phasing_errors = 0; if (verbose) printf("Pass 4 - assemble code.\r\n"); processMaster(); if (verbose) printf("Pass 4: phase errors: %d\r\n", phasing_errors); pass = 5; while (phasing_errors && pass < 10) { phasing_errors = 0; processMaster(); if (verbose) printf("Pass %d: phase errors: %d\r\n", pass, phasing_errors); pass++; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Output listing file. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ofp = (FILE *)NULL; if (listing) { if (verbose) printf("Generating listing file.\r\n"); strcpy(fname, argv[nn]); p = strrchr(fname,'.'); if (p) { *p = '\0'; } strcat(fname, ".lst"); ofp = fopen(fname,"w"); if (!ofp) printf("Can't open output file <%s>\r\n", fname); bGen = 1; } processMaster(); DumpSymbols(); if (listing) fclose(ofp); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Output binary file. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if (binary_out) { if (verbose) printf("Generating binary file.\r\n"); strcpy(fname, argv[nn]); p = strrchr(fname,'.'); if (p) { *p = '\0'; } strcat(fname, ".bin"); ofp = fopen(fname,"wb"); if (ofp) { fwrite((void*)sections[0].bytes,sections[0].index,1,ofp); fwrite((void*)sections[1].bytes,sections[1].index,1,ofp); fwrite((void*)sections[2].bytes,sections[2].index,1,ofp); //fwrite(binfile,binndx,1,ofp); fclose(ofp); } else printf("Can't create .bin file.\r\n"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Output ELF file. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if (elf_out) { if (verbose) printf("Generating ELF file.\r\n"); strcpy(fname, argv[nn]); p = strrchr(fname,'.'); if (p) { *p = '\0'; } if (rel_out) strcat(fname, ".rel"); else strcat(fname, ".elf"); ofp = fopen(fname,"wb"); if (ofp) { WriteELFFile(ofp); fclose(ofp); } else printf("Can't create .elf file.\r\n"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Output Verilog memory declaration // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if (verilog_out) { if (verbose) printf("Generating Verilog file.\r\n"); strcpy(fname, argv[nn]); p = strrchr(fname,'.'); if (p) { *p = '\0'; } strcat(fname, ".ver"); vfp = fopen(fname, "w"); if (vfp) { if (gCpu==64) { for (nn = 0; nn < binndx; nn+=8) { fprintf(vfp, "\trommem[%d] = 65'h%01d%02X%02X%02X%02X%02X%02X%02X%02X;\n", (((start_address+nn)/8)%8192), checksum64((int64_t *)&binfile[nn]), binfile[nn+7], binfile[nn+6], binfile[nn+5], binfile[nn+4], binfile[nn+3], binfile[nn+2], binfile[nn+1], binfile[nn]); } } else { for (nn = 0; nn < binndx; nn+=4) { fprintf(vfp, "\trommem[%d] = 33'h%01d%02X%02X%02X%02X;\n", (((start_address+nn)/4)%8192), checksum((int32_t *)&binfile[nn]), binfile[nn+3], binfile[nn+2], binfile[nn+1], binfile[nn]); } } fclose(vfp); } else printf("Can't create .ver file.\r\n"); } return 0; }