void main(u32int ax, u32int bx) { vlong hz; memset(edata, 0, end - edata); /* * ilock via i8250enable via i8250console * needs m->machno, sys->machptr[] set, and * also 'up' set to nil. */ cgapost(sizeof(uintptr)*8); memset(m, 0, sizeof(Mach)); m->machno = 0; m->online = 1; m->nixtype = NIXTC; sys->machptr[m->machno] = &sys->mach; m->stack = PTR2UINT(sys->machstk); m->vsvm = sys->vsvmpage; up = nil; active.nonline = 1; active.exiting = 0; active.nbooting = 0; asminit(); multiboot(ax, bx, 0); options(oargc, oargv); crapoptions(); /* * Need something for initial delays * until a timebase is worked out. */ m->cpuhz = 2000000000ll; m->cpumhz = 2000; cgainit(); i8250console("0"); consputs = cgaconsputs; vsvminit(MACHSTKSZ, NIXTC); conf.nmach = 1; fmtinit(); print("\nNIX\n"); if(vflag){ print("&ax = %#p, ax = %#ux, bx = %#ux\n", &ax, ax, bx); multiboot(ax, bx, vflag); } m->perf.period = 1; if((hz = archhz()) != 0ll){ m->cpuhz = hz; m->cyclefreq = hz; m->cpumhz = hz/1000000ll; } /* * Mmuinit before meminit because it * flushes the TLB via m->pml4->pa. */ mmuinit(); ioinit(); kbdinit(); meminit(); confinit(); archinit(); mallocinit(); /* * Acpiinit will cause the first malloc * call to happen. * If the system dies here it's probably due * to malloc not being initialised * correctly, or the data segment is misaligned * (it's amazing how far you can get with * things like that completely broken). */ acpiinit(); umeminit(); trapinit(); printinit(); /* * This is necessary with GRUB and QEMU. * Without it an interrupt can occur at a weird vector, * because the vector base is likely different, causing * havoc. Do it before any APIC initialisation. */ i8259init(32); procinit0(); mpsinit(maxcores); apiconline(); sipi(); timersinit(); kbdenable(); fpuinit(); psinit(conf.nproc); initimage(); links(); devtabreset(); pageinit(); swapinit(); userinit(); nixsquids(); testiccs(); print("schedinit...\n"); schedinit(); }
////////////////////////////////////////////////////////////////////////////////////////////////// // MAIN FUNCTION ////////////////////////////////////////////////////////////////////////////////////////////////// int main(int argc, char **argv) { int i=0,j=0,k=0; // int headstored=0, imagestored=0, stored; if(argc != 5) { printf("Usage: %s <image-file> <kernel-file> <result-file> <partitions>\n", argv[0]); printf("\n\nError, Missing parameters:\n"); printf("format: ./serialconvolution image_file kernel_file result_file\n"); printf("- image_file : source image path (*.ppm)\n"); printf("- kernel_file: kernel path (text file with 1D kernel matrix)\n"); printf("- result_file: result image path (*.ppm)\n"); printf("- partitions : Image partitions\n\n"); return -1; } ////////////////////////////////////////////////////////////////////////////////////////////////// // READING IMAGE HEADERS, KERNEL Matrix, DUPLICATE IMAGE DATA, OPEN RESULTING IMAGE FILE ////////////////////////////////////////////////////////////////////////////////////////////////// int imagesize, partitions, partsize, chunksize, halo, halosize; long position=0; double start, tstart=0, tend=0, tread=0, tcopy=0, tconv=0, tstore=0, treadk=0; struct timeval tim; FILE *fpsrc=NULL,*fpdst=NULL; ImagenData source=NULL, output=NULL; // Store number of partitions partitions = atoi(argv[4]); //////////////////////////////////////// //Reading kernel matrix gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); tstart = start; kernelData kern=NULL; if ( (kern = leerKernel(argv[2]))==NULL) { // free(source); // free(output); return -1; } //The matrix kernel define the halo size to use with the image. The halo is zero when the image is not partitioned. if (partitions==1) halo=0; else halo = (kern->kernelY/2)*2; gettimeofday(&tim, NULL); treadk = treadk + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); //////////////////////////////////////// //Reading Image Header. Image properties: Magical number, comment, size and color resolution. gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); //Memory allocation based on number of partitions and halo size. if ( (source = initimage(argv[1], &fpsrc, partitions, halo)) == NULL) { return -1; } gettimeofday(&tim, NULL); tread = tread + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); //Duplicate the image struct. gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); if ( (output = duplicateImageData(source, partitions, halo)) == NULL) { return -1; } gettimeofday(&tim, NULL); tcopy = tcopy + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); //////////////////////////////////////// //Initialize Image Storing file. Open the file and store the image header. gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); if (initfilestore(output, &fpdst, argv[3], &position)!=0) { perror("Error: "); // free(source); // free(output); return -1; } gettimeofday(&tim, NULL); tstore = tstore + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); ////////////////////////////////////////////////////////////////////////////////////////////////// // CHUNK READING ////////////////////////////////////////////////////////////////////////////////////////////////// int c=0, offset=0; imagesize = source->altura*source->ancho; partsize = (source->altura*source->ancho)/partitions; // printf("%s ocupa %dx%d=%d pixels. Partitions=%d, halo=%d, partsize=%d pixels\n", argv[1], source->altura, source->ancho, imagesize, partitions, halo, partsize); while (c < partitions) { //////////////////////////////////////////////////////////////////////////////// //Reading Next chunk. gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); if (c==0) { halosize = halo/2; chunksize = partsize + (source->ancho*halosize); offset = 0; } else if(c<partitions-1) { halosize = halo; chunksize = partsize + (source->ancho*halosize); offset = (source->ancho*halo/2); } else { halosize = halo/2; chunksize = partsize + (source->ancho*halosize); offset = (source->ancho*halo/2); } //DEBUG // printf("\nRound = %d, position = %ld, partsize= %d, chunksize=%d pixels\n", c, position, partsize, chunksize); if (readImage(source, &fpsrc, chunksize, halo/2, &position)) { return -1; } gettimeofday(&tim, NULL); tread = tread + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); //Duplicate the image chunk gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); if ( duplicateImageChunk(source, output, chunksize) ) { return -1; } //DEBUG // for (i=0;i<chunksize;i++) // if (source->R[i]!=output->R[i] || source->G[i]!=output->G[i] || source->B[i]!=output->B[i]) printf("At position i=%d %d!=%d,%d!=%d,%d!=%d\n",i,source->R[i],output->R[i], source->G[i],output->G[i],source->B[i],output->B[i]); gettimeofday(&tim, NULL); tcopy = tcopy + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); ////////////////////////////////////////////////////////////////////////////////////////////////// // CHUNK CONVOLUTION ////////////////////////////////////////////////////////////////////////////////////////////////// gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); #pragma omp parallel { #pragma omp sections { #pragma omp section convolve2D(source->R, output->R, source->ancho, (source->altura/partitions)+halosize, kern->vkern, kern->kernelX, kern->kernelY); #pragma omp section convolve2D(source->G, output->G, source->ancho, (source->altura/partitions)+halosize, kern->vkern, kern->kernelX, kern->kernelY); #pragma omp section convolve2D(source->B, output->B, source->ancho, (source->altura/partitions)+halosize, kern->vkern, kern->kernelX, kern->kernelY); } } gettimeofday(&tim, NULL); tconv = tconv + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); ////////////////////////////////////////////////////////////////////////////////////////////////// // CHUNK SAVING ////////////////////////////////////////////////////////////////////////////////////////////////// //Storing resulting image partition. gettimeofday(&tim, NULL); start = tim.tv_sec+(tim.tv_usec/1000000.0); if (savingChunk(output, &fpdst, partsize, offset)) { perror("Error: "); // free(source); // free(output); return -1; } gettimeofday(&tim, NULL); tstore = tstore + (tim.tv_sec+(tim.tv_usec/1000000.0) - start); //Next partition c++; } fclose(fpsrc); fclose(fpdst); freeImagestructure(&source); freeImagestructure(&output); gettimeofday(&tim, NULL); tend = tim.tv_sec+(tim.tv_usec/1000000.0); printf("Imatge: %s\n", argv[1]); printf("ISizeX : %d\n", source->ancho); printf("ISizeY : %d\n", source->altura); printf("kSizeX : %d\n", kern->kernelX); printf("kSizeY : %d\n", kern->kernelY); printf("%.6lf seconds elapsed for Reading image file.\n", tread); printf("%.6lf seconds elapsed for copying image structure.\n", tcopy); printf("%.6lf seconds elapsed for Reading kernel matrix.\n", treadk); printf("%.6lf seconds elapsed for make the convolution.\n", tconv); printf("%.6lf seconds elapsed for writing the resulting image.\n", tstore); printf("%.6lf seconds elapsed\n", tend-tstart); return 0; }
void main(uint32_t mbmagic, uint32_t mbaddress) { Mach *m = entrym; /* when we get here, entrym is set to core0 mach. */ sys->machptr[m->machno] = m; // Very special case for BSP only. Too many things // assume this is set. wrmsr(GSbase, PTR2UINT(&sys->machptr[m->machno])); if (machp() != m) panic("m and machp() are different!!\n"); assert(sizeof(Mach) <= PGSZ); /* * Check that our data is on the right boundaries. * This works because the immediate value is in code. */ if (x != 0x123456) panic("Data is not set up correctly\n"); memset(edata, 0, end - edata); m = (void *) (KZERO + 1048576 + 11*4096); sys = (void *) (KZERO + 1048576); /* * ilock via i8250enable via i8250console * needs m->machno, sys->machptr[] set, and * also 'up' set to nil. */ cgapost(sizeof(uintptr_t)*8); memset(m, 0, sizeof(Mach)); m->machno = 0; m->online = 1; m->nixtype = NIXTC; sys->machptr[m->machno] = &sys->mach; m->stack = PTR2UINT(sys->machstk); *(uintptr_t*)m->stack = STACKGUARD; m->vsvm = sys->vsvmpage; m->externup = (void *)0; active.nonline = 1; active.exiting = 0; active.nbooting = 0; asminit(); multiboot(mbmagic, mbaddress, 0); options(oargc, oargv); /* * Need something for initial delays * until a timebase is worked out. */ m->cpuhz = 2000000000ll; m->cpumhz = 2000; cgainit(); i8250console("0"); consputs = cgaconsputs; /* It all ends here. */ vsvminit(MACHSTKSZ, NIXTC, m); if (machp() != m) panic("After vsvminit, m and machp() are different"); sys->nmach = 1; fmtinit(); print("\nHarvey\n"); if(vflag){ multiboot(mbmagic, mbaddress, vflag); } m->perf.period = 1; if((hz = archhz()) != 0ll){ m->cpuhz = hz; m->cyclefreq = hz; m->cpumhz = hz/1000000ll; } //iprint("archhz returns 0x%lld\n", hz); //iprint("NOTE: if cpuidhz runs too fast, we get die early with a NULL pointer\n"); //iprint("So, until that's fixed, we bring up AP cores slowly. Sorry!\n"); /* * Mmuinit before meminit because it * flushes the TLB via m->pml4->pa. */ mmuinit(); ioinit(); meminit(); confinit(); archinit(); mallocinit(); /* test malloc. It's easier to find out it's broken here, * not deep in some call chain. * See next note. * void *v = malloc(1234); hi("v "); put64((uint64_t)v); hi("\n"); free(v); hi("free ok\n"); */ /* * Acpiinit will cause the first malloc * call to happen. * If the system dies here it's probably due * to malloc not being initialised * correctly, or the data segment is misaligned * (it's amazing how far you can get with * things like that completely broken). */ if (0){ acpiinit(); hi(" acpiinit();\n");} umeminit(); trapinit(); /* * This is necessary with GRUB and QEMU. * Without it an interrupt can occur at a weird vector, * because the vector base is likely different, causing * havoc. Do it before any APIC initialisation. */ i8259init(32); procinit0(); mpsinit(maxcores); apiconline(); /* Forcing to single core if desired */ if(!nosmp) { sipi(); } teardownidmap(m); timersinit(); fpuinit(); psinit(conf.nproc); initimage(); links(); keybinit(); keybenable(); mouseenable(); devtabreset(); pageinit(); swapinit(); userinit(); /* Forcing to single core if desired */ if(!nosmp) { nixsquids(); testiccs(); } print("CPU Freq. %dMHz\n", m->cpumhz); print("schedinit...\n"); schedinit(); }
int main(int argc, char **argv) { int c; /* Check commandline */ if (argc < 3) { printf("Usage: maked64 <diskimage> <commandfile> [diskname] [interleave]\n" " Commandfile contains <DOS-name> <C64-name>-pairs. Use _ to represent\n" " space in C64-names and in the diskname.\n"); return 1; } /* Make diskname */ for (c = 0; c < 23; c++) { unsigned char ch; if ((argc > 3) && (c < strlen(argv[3]))) { ch = argv[3][c]; if (ch == '_') ch = 0x20; } else ch = 0x20; diskname[c] = ch; } if (argc > 4) sscanf(argv[4], "%d", &interleave); /* Init image */ makesectortable(); initimage(); /* Open command file */ in = fopen(argv[2], "rt"); if (!in) { printf("Couldn't open command file!\n"); return 255; } /* Write files to image one by one */ while(fgets(commandbuf, 80, in)) { sscanf(commandbuf, "%s %s", &dosname[0], &c64name[0]); if (!writefile(dosname, c64name)) { printf("Error writing file %s\n", c64name); } else { printf("File %s written at track %d sector %d, last block %d bytes\n", c64name,starttrack,startsector,lastblocksize); } } fclose(in); /* Write image & exit */ out = fopen(argv[1], "wb"); if (!out) { printf("Couldn't open diskimage for writing!\n"); return 255; } fwrite(image, 174848, 1, out); fclose(out); printf("Diskimage written.\n"); return 0; }
/*----------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { int loop, test = 0, error = 0, command = COMMAND_NONE; int gray = 0, view = 1, help = 0; char *psave = 0x0, *pname = 0x0, *pdata = 0x0; my1Image currimage, tempimage, *pimage; my1IFrame currframe, tempframe; /* print tool info */ printf("\n%s - %s (%s)\n",MY1APP_PROGNAME,MY1APP_PROGINFO,MY1APP_PROGVERS); printf(" => by [email protected]\n\n"); /* check program arguments */ if(argc>1) { for(loop=1;loop<argc;loop++) { if(argv[loop][0]=='-') /* options! */ { if(!strcmp(argv[loop],"--save")) { loop++; if(loop<argc) psave = argv[loop]; else printf("Cannot get save file name - NOT saving!\n"); } else if(!strcmp(argv[loop],"--cdata")) { loop++; if(loop<argc) pdata = argv[loop]; else printf("Cannot get C data file name - NOT writing!\n"); } else if(!strcmp(argv[loop],"--gray")) { gray = 1; } else if(!strcmp(argv[loop],"--hide")) { view = 0; } else if(!strcmp(argv[loop],"--help")) { help = 1; } else { printf("Unknown option '%s'!\n",argv[loop]); } } else /* not an option? */ { /* first non-option must be file name! */ if(!pname) { pname = argv[loop]; continue; } /* then check for command! */ if(!strcmp(argv[loop],"laplace1")) { command = COMMAND_LAPLACE1; gray = 1; } else if(!strcmp(argv[loop],"sobelx")) { command = COMMAND_SOBELX; gray = 1; } else if(!strcmp(argv[loop],"sobely")) { command = COMMAND_SOBELY; gray = 1; } else if(!strcmp(argv[loop],"sobelall")) { command = COMMAND_SOBELALL; gray = 1; } else if(!strcmp(argv[loop],"laplace2")) { command = COMMAND_LAPLACE2; gray = 1; } else if(!strcmp(argv[loop],"gauss")) { command = COMMAND_GAUSS; gray = 1; } else { printf("Unknown parameter %s!\n",argv[loop]); continue; } /* warn if overriding previous command! */ if(command) { printf("Warning! Command '%s' overrides '%s'!\n", argv[loop],argv[test]); } test = loop; } } } /* check if user requested help */ if(help) { about(); return 0; } /** check input filename */ if(!pname) { printf("No filename given! Aborting!\n"); return ERROR_GENERAL; } /* initialize image & frame*/ initimage(&currimage); initimage(&tempimage); initframe(&currframe); initframe(&tempframe); /* try to open file */ if((error=load_image(&currimage,pname))<0) { return error; } /* display basic info */ printf("Input image: %s\n",pname); print_image_info(&currimage); /* convert grayscale if requested/required */ if(gray) grayscale_image(&currimage); /* process command */ switch(command) { case COMMAND_LAPLACE1: { createimage(&tempimage,currimage.height,currimage.width); laplace_image(&currimage,&tempimage); break; } case COMMAND_SOBELX: { createimage(&tempimage,currimage.height,currimage.width); sobel_x_image(&currimage,&tempimage); break; } case COMMAND_SOBELY: { createimage(&tempimage,currimage.height,currimage.width); sobel_y_image(&currimage,&tempimage); break; } case COMMAND_SOBELALL: { createimage(&tempimage,currimage.height,currimage.width); sobel_image(&currimage,&tempimage,0x0); break; } case COMMAND_LAPLACE2: { createimage(&tempimage,currimage.height,currimage.width); createframe(&currframe,currimage.height,currimage.width); createframe(&tempframe,currimage.height,currimage.width); image2frame(&currimage,&currframe,0); laplace_frame(&currframe,&tempframe); frame2image(&tempframe,&tempimage,1); break; } case COMMAND_GAUSS: { createimage(&tempimage,currimage.height,currimage.width); createframe(&currframe,currimage.height,currimage.width); createframe(&tempframe,currimage.height,currimage.width); image2frame(&currimage,&currframe,0); gauss_frame(&currframe,&tempframe,1.0,0x0); frame2image(&tempframe,&tempimage,1); break; } } if(!tempimage.length) pimage = &currimage; else pimage = &tempimage; printf("Check image:\n"); print_image_info(pimage); /** save results if requested */ if(psave) { printf("Saving image data to %s...\n",psave); error=save_image(pimage,psave); view = 0; } if(pdata) { printf("Saving C data to %s...\n",pdata); error=cdata_image(pimage,pdata); } /* view image if no request to hide! .. and NOT saving! */ if(view) view_image(pimage); /* cleanup */ freeframe(&currframe); freeframe(&tempframe); freeimage(&currimage); freeimage(&tempimage); return error; }