bool_t BusController::signal_update(int blockNum, int j){ getExec(blockNum, j); printf("signal_update!\n"); int i; for(i=0;i<shared_count;++i){ if(i==j) continue; mem_map[i]->ca->invalidate(blockNum*cB); } lockRecs(blockNum); for(i=0;i<shared_count;++i){ if(i==j) recs[i][blockNum] |= REC_WRITE; else recs[i][blockNum] = REC_NONE; } unlockRecs(blockNum); return TRUE; }
bool_t BusController::signal_allocate(int blockNum, int j){ getExec(blockNum, j); printf("signal allocate\n"); int id; for(id=shared_count-1;id>=0;--id){ if(recs[id][blockNum] & REC_WRITE) break; } if(id>=0){ // dirty cache int i = mem_map[id]->ca->findLine(blockNum*cB); mem_map[id]->ca->commit(i); syncBlock(blockNum, id); recs[id][blockNum] = REC_READ; } recs[j][blockNum] |= REC_READ; return TRUE; }
int load_list_menu(const char* path) { int flags = 0; int bootfd; ExecId id; int ret; //int boot_id; char fat_path[100]; char fat_device_path[10]; char *pDeviceStart = NULL; char *pDeviceEnd = NULL; unsigned int DevNameLength; //ext2 file system default bootfd = OpenLoadConfig(path); //printf("load_list_menu bootfd %d\n",bootfd); if (bootfd == -1) { //Second chance to try FAT32 file system //do the path tranform,for example //(usb0,0)/boot.cfg -> /dev/fat/disk@usb0/boot.cfg //(usb0,1)/boot.cfg -> /dev/fat/disk@usb0b/boot.cfg //(usb0,2)/boot.cfg -> /dev/fat/disk@usb0c/boot.cfg //(wd0,0)/boot.cfg -> /dev/fat/disk@wd0/boot.cfg //(wd0,1)/boot.cfg -> /dev/fat/disk@wd0b/boot.cfg //(wd0,2)/boot.cfg -> /dev/fat/disk@wd0c/boot.cfg pDeviceStart = strchr(path,'('); if (pDeviceStart==NULL) return -1; pDeviceEnd = strchr(path,','); if (pDeviceEnd==NULL) return -1; DevNameLength = (unsigned int)pDeviceEnd -(unsigned int)pDeviceStart -1; memset(fat_device_path, 0, 10); memcpy(fat_device_path, path+1, DevNameLength); fat_device_path[DevNameLength] =*(++pDeviceEnd)+0x31; fat_device_path[DevNameLength+1] = '\0'; pDeviceStart = strchr(path,'/'); if (pDeviceStart==NULL) return -1; pDeviceStart++; memset(fat_path, 0, 100); sprintf(fat_path, "/dev/fat/disk@%s/%s",fat_device_path,pDeviceStart); bootfd = OpenLoadConfig(fat_path); //printf("load_list_menu second bootfd %d\n",bootfd); if (bootfd == -1) return -1; } id = getExec("txt"); if (id != NULL) { ret = menu_list_read(id, bootfd, flags); if (ret != 0) { //printf("\nCannot found and boot item in boot configure file."); //printf("\nPress any key to continue ...\n"); getchar(); close(bootfd); return -2; } }else{ //printf("[error] this pmon can't read file!"); close(bootfd); return -3; } close(bootfd); return 0; }
int cmd_cat (int ac, char *av[]) { char path[256] = {0}; // char s[LINE_MAX+1] = {0}; char* s = NULL; char* buf = NULL; int flags = 0; int bootfd; int n = LINE_MAX; ExecId id; int siz = 0; int ln = 0; int i, j; int m; if (ac != 2) return -1; flags |= RFLAG; strcpy(path, av[1]); if ((bootfd = open (path, O_RDONLY | O_NONBLOCK)) < 0) { perror (path); return EXIT_FAILURE; } s = malloc(LINE_MAX + 1); if (s == NULL) { perror("malloc"); return EXIT_FAILURE; } memset(s, 0, LINE_MAX + 1); siz = moresz; ioctl(STDIN, CBREAK, NULL); ln = siz; i = 0; j = 0; buf = malloc(LINESZ + 8); if (buf == NULL) { perror("malloc"); free(s); return EXIT_FAILURE; } id = getExec("txt"); if (id != NULL) { do { n = LINE_MAX; exec(id, bootfd, s, &n, flags); if (n <= 0) { break; } s[n] = '\0'; j += sprintf(buf + j, "%s", s); if ((i % 2) != 0) { if (more(buf, &ln, siz)) { free(buf); free(s); close(bootfd); return 0; } j = 0; } i++; } while (n > 0); if (i % 2 != 0) { printf("%s", buf); } #if 0 do { exec(id, bootfd, s, &n, flags); s[n]='\0'; j += sprintf(buf + j, "%s", s); if (s[0] == '\n') { if ((i % 2) != 0) { more(buf, &ln, siz); j = 0; } /* else { j += sprintf(buf + j, "\n"); } */ i++; } }while(n>0 ); #endif }else{ printf("[error] this pmon can't read file!"); free(s); free(buf); close(bootfd); return -2; } close(bootfd); free(buf); free(s); return 0; }
int cmd_boot(int argc, char **argv) { char path[256]; char buf[DLREC+1]; extern char clientcmd[]; /* in go.c */ extern char *clientav[]; /* in go.c */ extern int clientac; /* in go.c */ extern int optind; extern char *optarg; int c, err; long ep; int n; int flags; unsigned long offset = 0; unsigned long entry = 0; flags = 0; optind = err = 0; offset = 0; while ((c = getopt (argc, argv, "sbke:ro:")) != EOF) { switch (c) { case 's': flags |= SFLAG; break; case 'b': flags |= BFLAG; break; case 'k': flags |= KFLAG; break; case 'r': flags |= RFLAG; break; case 'e': if (!get_rsa ((u_int32_t *)&entry, optarg)) { err++; } break; case 'o': if (!get_rsa ((u_int32_t *)&offset, optarg)) { err++; } break; default: err++; break; } } if (err) { return EXIT_FAILURE; } if (optind < argc) { strcpy(path, argv[optind++]); } else if (getenv("bootfile")) { strcpy(path, getenv("bootfile")); } else { printf("boot what?\n"); return EXIT_FAILURE; } if ((bootfd = open (path, O_RDONLY | O_NONBLOCK)) < 0) { perror (path); return EXIT_FAILURE; } dl_initialise (offset, flags); fprintf (stderr, "Loading file: %s ", path); errno = 0; n = 0; if (flags & RFLAG) { ExecId id; id = getExec("bin"); if (id != NULL) { ep = exec (id, bootfd, buf, &n, flags); } else { perror ("Can't find binary loader"); return EXIT_FAILURE; } } else { ep = exec (NULL, bootfd, buf, &n, flags); } close (bootfd); putc ('\n', stderr); if (ep == -1) { fprintf (stderr, "%s: boot failed\n", path); return EXIT_FAILURE; } if (ep == -2) { fprintf (stderr, "%s: invalid file format\n", path); return EXIT_FAILURE; } if (entry) dl_entry = entry; else dl_entry = ep; sprintf(clientcmd, "boot %s ", path); while (optind < argc) { strcat(clientcmd, argv[optind++]); strcat(clientcmd, " "); } md_setentry(NULL, (register_t)(int)dl_entry); /* set start address */ clientac = argvize (clientav, clientcmd); initstack (clientac, clientav, 1); clrhndlrs (); closelst (2); /* Init client terminal state */ md_setsr(NULL, initial_sr); tgt_enable(tgt_getmachtype ()); /* set up i/u hardware */ #ifdef __powerpc__ if(getenv("vxWorks")) { strcpy ((void *)0x4200, getenv ("vxWorks")); } #endif /* Flush caches if they are enabled */ if (md_cachestat()) flush_cache (DCACHE | ICACHE, NULL); if (setjmp (go_return_jump) == 0) { goclient (); } console_state(1); return 0; }