📄 fpa_download.c
字号:
} if(verbose) (void)putchar('\n');#endif DEBUG if(verbose) { int i; for (i = 0; i < ulines ; ++i) { int j; int found = 0; for (j = 0;(found == 0) && (j < uline_size); ++j) { /* (void)fprintf(stderr,"%8d * %8d + %8d= %8d\n", i, uline_size, j, i*uline_size+j);*/ if(ucode[i*uline_size + j] != v_ucode[i*uline_size +j]) found = 1; } if (found != 0) { (void)fprintf(stderr,"%d\t", i); for (j = 0; j < uline_size; ++j) (void)fprintf(stderr," %8x", ucode[i*uline_size + j]); (void)putchar('\n'); (void)fprintf(stderr,"up:\t", i); for (j = 0; j < uline_size; ++j) (void)fprintf(stderr," %8x",v_ucode[i*uline_size + j]); errors++; (void)putchar('\n'); } } } } if(verbose) (void)fprintf(stderr," done.\n"); my_ioctl("fpa_uload", FPA_LOAD_OFF, (char *)NULL); return(errors);}voidgot_buserr(){ (void)fprintf(stderr,"Got Bus error (SIGBUS) while trying to access FPA\n"); fpa_shutdown(IOCTL_FAILED);}u_int map[MAP_RAM_LINES];u_int v_map[MAP_RAM_LINES];/* Download The Mapping RAM/* filename is of the following format:/* an integer specifying number of lines, followed by/* nlines long's containing 24 mapping ram bits in lower order/* a checksum will be inserted at address MAP_CKSUM_ADDR */fpa_mload(filename) char *filename;{FILE *fp;u_int nlines;register u_int *ptr;u_int map_add; (void)signal(SIGBUS, got_buserr); if((fp=fopen(filename,"r"))==NULL) { error("can't open map file %s\n", filename); } my_ioctl("fpa_mload", FPA_ACCESS_OFF, (char *)NULL); my_ioctl("fpa_mload", FPA_LOAD_ON, (char *)NULL); nlines = 4 * 1024; if(fread((char *)map, sizeof(long), (int) nlines, fp) != nlines) { error("FPA mapping ram download file has bad format\n"); } map[MAP_CKSUM_ADDR] = MAP_MASK & (CHECKSUM ^ cksum(nlines, map, 1) ^ cksum(1, &map[MAP_CKSUM_ADDR], 1)); /* calculate the checksum of all locations BUT this one */ if(verbose) (void)fprintf(stderr,"Downloading map ram, checksum: 0x%x ", map[MAP_CKSUM_ADDR]); for (ptr = map, map_add = 0; nlines > 0; nlines--, map_add += 4) { fpa->fp_load_ptr = map_add | FPA_BIT_23_0; fpa->fp_ld_ram = *ptr++; } (void)fclose(fp); if(verbose) (void)fprintf(stderr,"..."); for (ptr = v_map, map_add = 0, nlines = MAP_RAM_LINES; nlines > 0; nlines--, map_add += 4) { fpa->fp_load_ptr = map_add | FPA_BIT_23_0; *ptr++ = fpa->fp_ld_ram & MAP_MASK; /* take only lower 3 bytes */ } /* compare */ for (nlines = 0; nlines < MAP_RAM_LINES; ++ nlines) { if(map[nlines] != v_map[nlines]) { (void)fprintf(stderr,"\nERROR: map line %d down: %x up: %x\n",nlines, map[nlines], v_map[nlines]); errors ++; } } if(verbose) (void)fprintf(stderr," done.\n"); my_ioctl("fpa_mload", FPA_LOAD_OFF, (char *)NULL); return(errors);}u_int const[CONST_RAM_LINES][2]; /* this initializes data to 0; maybe NaN is better */u_int v_const[CONST_RAM_LINES][2]; /* this initializes data to 0; maybe NaN is better *//* Download The Constants/* filename is of the following format:/* all lines start with a name which starts with s, d, c_s, or c_d./* following the name is a tab/* if the name starts with s or c_s then the tab is followed by a/* hex, eight-digit number/* if the name starts with d or c_d then the tab is followed by a/* hex sixteen-digit number/* a checksum will be inserted at address REG_CKSUM_ADDR */fpa_cload(filename) char *filename;{FILE *fp;u_int const_add;u_int constant1, constant2;int count = 0;int offset;char string[100];char name[100]; (void)signal(SIGBUS, got_buserr); if((fp=fopen(filename,"r"))==NULL) { error("can't open const file %s\n", filename); } my_ioctl("fpa_cload", FPA_ACCESS_ON, (char *)NULL); my_ioctl("fpa_cload", FPA_LOAD_OFF, (char *)NULL); while(fgets(string, 100, fp) != NULL) { if((sscanf(string, "%s%x%8x%8x", name, &const_add, &constant1, &constant2)) <=2) continue; switch(*name) { case 's': offset = 0x400; ck_loc(name, const_add+offset); const[const_add+offset][0] = constant1; const[const_add+offset][1] = FILLER; break; case 'd': offset = 0x600; ck_loc(name, const_add+offset); const[const_add+offset][0] = constant1; const[const_add+offset][1] = constant2; break; case 'c': if(name[2] == 's') { offset = 0x500; ck_loc(name, const_add+offset); const[const_add+offset][0] = constant1; const[const_add+offset][1] = FILLER; break; } else if(name[2] == 'd') { offset = 0x700; ck_loc(name, const_add+offset); const[const_add+offset][0] = constant1; const[const_add+offset][1] = constant2; break; } default: error("FPA constant file has bad format\n"); } count++; } if(verbose) (void)fprintf(stderr,"constants: %d\n", count); const[REG_CKSUM_ADDR][0] = CHECKSUM ^ cksum(REG_CKSUM_MAX - 0x400 +1, &const[0x400][0], 2); const[REG_CKSUM_ADDR][1] = CHECKSUM ^ cksum(REG_CKSUM_MAX - 0x400 +1, &const[0x400][1], 2); if(verbose) (void)fprintf(stderr,"Downloading constants, checksum: 0x%x 0x%x ", const[REG_CKSUM_ADDR][0], const[REG_CKSUM_ADDR][1]); for (const_add = 1024; const_add < CONST_RAM_LINES; const_add++) { fpa->fp_load_ptr = (long)(const_add << 2); *(long *)((long)fpa + REG_WRM_LP) = const[const_add][0]; *(long *)((long)fpa + REG_WRL_LP) = const[const_add][1]; } if(verbose) (void)fprintf(stderr,"..."); for (const_add = 1024; const_add < CONST_RAM_LINES; const_add++) { fpa->fp_load_ptr = (long)(const_add << 2); v_const[const_add][0] = *(long *)((long)fpa + REG_WRM_LP) ; v_const[const_add][1] = *(long *)((long)fpa + REG_WRL_LP) ; } for (const_add = 1024; const_add < CONST_RAM_LINES; const_add++) { if((v_const[const_add][0] != const[const_add][0]) ||(v_const[const_add][1] != const[const_add][1])) { (void)fprintf(stderr,"ERROR constant ram download/upload mismatch.\n"); (void)fprintf(stderr,"%d %8x %8x\n",const_add,const[const_add][0], const[const_add][1]); (void)fprintf(stderr,"up: %8x %8x\n",v_const[const_add][0], v_const[const_add][1]); errors++; } } if(verbose) (void)fprintf(stderr," done.\n"); if(errors) return(errors); /* don't finish if errors found */ fpa->fp_initialize = 0; fpa->fp_restore_mode3_0 = 0x2; my_ioctl("fpa_cload", FPA_ACCESS_OFF, (char *)NULL); my_ioctl("fpa_cload", FPA_INIT_DONE, (char *)NULL); (void)fclose(fp); return(0);}ck_loc(name, index)char *name;u_int index;{ if(const[index][0] || const[index][1]) (void)fprintf(stderr, "Warning! FPA Reloading constant: %12s at address %3x\n", name, index);}fpa_rev(){ (void)printf("%s installed.\n", fpa_type==FPA_PLUS ? "FPA+":"FPA");#ifndef COMMENT fpa->fp_load_ptr = 0x7f0 << 2; (void)printf("Microcode = level: %lx, date: %06lx\n", *(long *)LDP_MS, *(long *)LDP_LS); fpa->fp_load_ptr = 0x7f1 << 2; (void)printf("Constants = level: %lx, date: %06lx\n", *(long *)LDP_MS, *(long *)LDP_LS); #else COMMENT *(long *)REG_CPY_DP = 0xfc00; (void)printf("Microcode = level: %lx, date: %06lx\n", *(long *)REG_RD_MSW, *(long *)REG_RD_LSW); *(long *)REG_CPY_DP = 0xfc40; (void)printf("Constants = level: %lx, date: %06lx\n", *(long *)REG_RD_MSW, *(long *)REG_RD_LSW); */#endif COMMENT/* XXX*/}u_int cksum(nlines, ptr, inc)u_int nlines;u_int *ptr;u_int inc;{ u_int sum = 0; while(nlines--) { sum ^= *ptr; ptr += inc; } return(sum);}voidgot_fpeerr(){ (void)signal(SIGFPE, got_fpeerr); (void)fprintf(stderr, "Got a fpe error\n"); (void)fprintf(stderr, "The FPA IERR is: %xl\n", fpa->fp_ierr); if(errno == EPIPE) { fpa_shutdown(BUS_ERROR); } exit(-1);}voidgot_segverr(){ (void)signal(SIGSEGV, got_segverr); (void)fprintf(stderr, "Got a segmentation error\n"); exit(-1);}char *time_of_day(){ long temptime; (void)time(&temptime); return(ctime(&temptime));}char msg[FPA_LINESIZE] = "FPA Download Failed - ";fpa_shutdown(val) int val;{ (void)strcat(msg, error_message[val]); (void)strcat(msg, " - "); (void)strcat(msg, time_of_day()); broadcast_msg(msg); log_msg(msg); /* disable the fpa */ my_ioctl("fpa_shutdown", FPA_FAIL, msg); exit(-1);}log_msg(msg) char *msg;{ FILE *tmp_fp, *fopen(); if ((tmp_fp = fopen("/var/adm/diaglog","a")) == NULL) { perror("could not open /var/adm/diaglog"); } else { fputs(msg,tmp_fp); (void)fclose(tmp_fp); }}char tmp_file[L_tmpnam];char wall_str[100] = "/bin/wall -a \0";voidbroadcast_msg(msg)char *msg;{ FILE *tmp_fp, *fopen(); /* create temp file with error message */ (void)tmpnam(tmp_file); tmp_fp = fopen(tmp_file,"w"); if (tmp_fp == NULL) return; fputs(msg, tmp_fp); (void)fclose(tmp_fp); (void)strcpy(&wall_str[13], tmp_file); (void)strcat(wall_str, " 2> /dev/console"); if(system(wall_str) != 0) { (void)fprintf(stderr,"%s: %s FAILED\n",progname,wall_str); return; } (void)unlink(tmp_file);}char *a[] = { "FPA_ACCESS_ON", "FPA_ACCESS_OFF", "FPA_LOAD_ON", "FPA_LOAD_OFF", "FPA_INIT_DONE", "FPA_FAIL", "UNKNOWN IOCTL"};char *io_string(io_num)int io_num;{ switch(io_num) { case FPA_ACCESS_ON: return( a[0] ); case FPA_ACCESS_OFF: return( a[1] ); case FPA_LOAD_ON: return( a[2] ); case FPA_LOAD_OFF: return( a[3] ); case FPA_INIT_DONE: return( a[4] ); case FPA_FAIL: return( a[5] ); default: return( a[6] ); }}my_ioctl(func_str, io_call, data)char* func_str;int io_call;char* data;{ char *io_str; io_str = io_string(io_call); if(ioctl(fpa_fd, io_call, data) == -1) { if(errno == EPIPE) { (void)fprintf(stderr, "%s: %s - pipe not clear.\n", func_str, io_str); if(io_call != FPA_FAIL) fpa_shutdown(IOCTL_FAILED); } else { (void)fprintf(stderr,"%s: ioctl(%s) ", progname, io_str); perror(""); } exit(-1); }#ifdef DEBUG if(verbose) (void)fprintf(stderr,"%s: %s worked.\n",func_str, io_str);#endif DEBUG}/* print error string and exit *//*VARARGS*/voiderror(ctl, a1, a2, a3)char* ctl;{ (void)fprintf(stderr,"%s: ", progname); (void)fprintf(stderr, ctl, a1, a2, a3); exit(-1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -