/// /// _UNMEMTRACK // remove a node from the memory tracking lists void _UNMEMTRACK(const char *file, const int line, const char *func, const void *ptr) { if(isFlagSet(debug_classes, DBC_MTRACK) && ptr != NULL) { BOOL success = FALSE; struct DbgMallocNode *dmn; ObtainSemaphore(&DbgMallocListSema); if((dmn = findDbgMallocNode(ptr)) != NULL) { Remove((struct Node *)dmn); if(matchAllocFunc(dmn->func, func) == FALSE) { _DPRINTF(DBC_WARNING, DBF_ALWAYS, file, line, "free of tracked memory area 0x%08lx with unsuitable function (allocated with %s, freed with %s counterpart)", ptr, dmn->func, func); DbgUnsuitableFreeCount++; } FreeVec(dmn); DbgMallocCount--; success = TRUE; } if(success == FALSE) _DPRINTF(DBC_WARNING, DBF_ALWAYS, file, line, "free of untracked memory area 0x%08lx attempted", ptr); ReleaseSemaphore(&DbgMallocListSema); } }
int __check_dram(paddr_t start, paddr_t end) { u_int8_t *page; int i, x; _DPRINTF(" checking..."); for (; start < end; start += NBPG) { page = (u_int8_t *)SH3_PHYS_TO_P2SEG (start); x = random(); for (i = 0; i < NBPG; i += 4) *(volatile int *)(page + i) = (x ^ i); for (i = 0; i < NBPG; i += 4) if (*(volatile int *)(page + i) != (x ^ i)) goto bad; x = random(); for (i = 0; i < NBPG; i += 4) *(volatile int *)(page + i) = (x ^ i); for (i = 0; i < NBPG; i += 4) if (*(volatile int *)(page + i) != (x ^ i)) goto bad; } _DPRINTF("success.\n"); return (0); bad: _DPRINTF("failed.\n"); return (1); }
/// /// DumpDbgMalloc // output all current allocations void DumpDbgMalloc(void) { ENTER(); if(isFlagSet(debug_classes, DBC_MTRACK)) { ULONG i; ObtainSemaphore(&DbgMallocListSema); D(DBF_ALWAYS, "%ld memory areas tracked", DbgMallocCount); for(i = 0; i < ARRAY_SIZE(DbgMallocList); i++) { struct Node *curNode; for(curNode = GetHead((struct List *)&DbgMallocList[i]); curNode != NULL; curNode = GetSucc(curNode)) { struct DbgMallocNode *dmn = (struct DbgMallocNode *)curNode; _DPRINTF(DBC_MTRACK, DBF_ALWAYS, dmn->file, dmn->line, "memarea 0x%08lx, size/type %ld, func (%s)", dmn->memory, dmn->size, dmn->func); } } ReleaseSemaphore(&DbgMallocListSema); } LEAVE(); }
/// /// _MEMTRACK // add a new node to the memory tracking lists void _MEMTRACK(const char *file, const int line, const char *func, void *ptr, size_t size) { if(isFlagSet(debug_classes, DBC_MTRACK)) { if(ptr != NULL && size != 0) { struct DbgMallocNode *dmn; if((dmn = AllocVec(sizeof(*dmn), MEMF_ANY)) != NULL) { dmn->memory = ptr; dmn->size = size; dmn->file = file; dmn->line = line; dmn->func = func; ObtainSemaphore(&DbgMallocListSema); AddTail((struct List *)&DbgMallocList[ptr2hash(ptr)], (struct Node *)&dmn->node); DbgMallocCount++; ReleaseSemaphore(&DbgMallocListSema); } } else _DPRINTF(DBC_WARNING, DBF_ALWAYS, file, line, "potential invalid %s call with return (0x%08lx, 0x%08lx)", func, ptr, size); } }
void __find_dram_shadow(paddr_t start, paddr_t end) { vaddr_t page, startaddr, endaddr; int x; _DPRINTF("search D-RAM from 0x%08lx for 0x%08lx\n", start, end); startaddr = SH3_PHYS_TO_P2SEG(start); endaddr = SH3_PHYS_TO_P2SEG(end); page = startaddr; x = random(); *(volatile int *)(page + 0) = x; *(volatile int *)(page + 4) = ~x; if (*(volatile int *)(page + 0) != x || *(volatile int *)(page + 4) != ~x) return; for (page += NBPG; page < endaddr; page += NBPG) { if (*(volatile int *)(page + 0) == x && *(volatile int *)(page + 4) == ~x) { goto memend_found; } } page -= NBPG; *(volatile int *)(page + 0) = x; *(volatile int *)(page + 4) = ~x; if (*(volatile int *)(page + 0) != x || *(volatile int *)(page + 4) != ~x) return; /* no memory in this bank */ memend_found: KASSERT(mem_cluster_cnt < VM_PHYSSEG_MAX); mem_clusters[mem_cluster_cnt].start = start; mem_clusters[mem_cluster_cnt].size = page - startaddr; /* skip kernel area */ if (mem_cluster_cnt == 1) mem_clusters[1].size -= mem_clusters[0].size; mem_cluster_cnt++; }
/// /// CleanupDbgMalloc // cleanup the memory tracking framework and output possibly pending allocations static void CleanupDbgMalloc(void) { ENTER(); if(isFlagSet(debug_classes, DBC_MTRACK)) { _DBPRINTF("** Cleaning up memory tracking *************************************\n"); ObtainSemaphore(&DbgMallocListSema); if(DbgMallocCount != 0 || DbgUnsuitableFreeCount != 0) { if(DbgMallocCount != 0) { ULONG i; E(DBF_ALWAYS, "there are still %ld unfreed memory trackings", DbgMallocCount); for(i = 0; i < ARRAY_SIZE(DbgMallocList); i++) { struct DbgMallocNode *dmn; while((dmn = (struct DbgMallocNode *)RemHead((struct List *)&DbgMallocList[i])) != NULL) { _DPRINTF(DBC_ERROR, DBF_ALWAYS, dmn->file, dmn->line, "unfreed memory tracking: 0x%08lx, size/type %ld, func (%s)", dmn->memory, dmn->size, dmn->func); // We only free the node structure here but not dmn->memory itself. // First of all, this is because the allocation could have been done // by other functions than malloc() and calling free() for these will // cause havoc. And second the c-library's startup code will/should // free all further pending allocations upon program termination. FreeVec(dmn); } } } if(DbgUnsuitableFreeCount != 0) { E(DBF_ALWAYS, "there were %ld unsuitable freeing calls", DbgUnsuitableFreeCount); } } else D(DBF_ALWAYS, "all memory trackings have been free()'d correctly"); ReleaseSemaphore(&DbgMallocListSema); } LEAVE(); }
void mem_cluster_load() { paddr_t start, end; psize_t size; int i; /* Cluster 0 is always the kernel, which doesn't get loaded. */ sh_dcache_wbinv_all(); for (i = 1; i < mem_cluster_cnt; i++) { start = (paddr_t)mem_clusters[i].start; size = (psize_t)mem_clusters[i].size; _DPRINTF("loading 0x%lx,0x%lx\n", start, size); memset((void *)SH3_PHYS_TO_P1SEG(start), 0, size); end = atop(start + size); start = atop(start); uvm_page_physload(start, end, start, end, VM_FREELIST_DEFAULT); } sh_dcache_wbinv_all(); }
//=============================================================================== // Static functions //=============================================================================== BOOL DetectionModule_touchLib::FingerResultCallBack(int frameID, FingerDetectionResultPckage *package, int argc, void* argv[]) { { DetectionModule_touchLib* myDM=static_cast<DetectionModule_touchLib*>(argv[0]); CAutoLock lck(&myDM->m_csFingerResults); SimpleDetectionResult *simpleDR = new SimpleDetectionResult(); simpleDR->Init(package->fingerNum); simpleDR->SetFrameID(frameID); simpleDR->SetFingers(package->pFingerResults); myDM->m_arrDetectionResults.push_back(simpleDR); _DPRINTF((L"---- %d (%d)\n",frameID,simpleDR->GetFingerNum())); } return TRUE; }
int cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen, struct proc *p) { /* all sysctl names at this level are terminal */ if (namelen != 1) return (ENOTDIR); /* overloaded */ switch (name[0]) { case CPU_CONSDEV: return (sysctl_rdstruct(oldp, oldlenp, newp, &cn_tab->cn_dev, sizeof cn_tab->cn_dev)); default: } return (EOPNOTSUPP); } void cpu_reboot(int howto, char *bootstr) { /* take a snap shot before clobbering any registers */ if (curproc) savectx(curpcb); /* If system is cold, just halt. */ if (cold) { howto |= RB_HALT; goto haltsys; } /* If "always halt" was specified as a boot flag, obey. */ if ((boothowto & RB_HALT) != 0) { howto |= RB_HALT; } #ifdef KLOADER_KERNEL_PATH if ((howto & RB_HALT) == 0) kloader_reboot_setup(KLOADER_KERNEL_PATH); #endif boothowto = howto; if ((howto & RB_NOSYNC) == 0) { /* * Synchronize the disks.... */ vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } /* Disable interrupts. */ splhigh(); /* If rebooting and a dump is requested do it. */ #if notyet if (howto & RB_DUMP) dumpsys(); #endif haltsys: /* run any shutdown hooks */ doshutdownhooks(); /* Finally, halt/reboot the system. */ if (howto & RB_HALT) { printf("halted.\n"); } else { #ifdef KLOADER_KERNEL_PATH kloader_reboot(); /* NOTREACHED */ #endif } #if NHD64465IF > 0 hd64465_shutdown(); #endif cpu_reset(); /*NOTREACHED*/ while(1) ; } /* return # of physical pages. */ int mem_cluster_init(paddr_t addr) { phys_ram_seg_t *seg; int npages, i; /* cluster 0 is always kernel myself. */ mem_clusters[0].start = SH_CS3_START; mem_clusters[0].size = addr - SH_CS3_START; mem_cluster_cnt = 1; /* search CS3 */ #ifdef SH3 /* SH7709A's CS3 is splited to 2 banks. */ if (CPU_IS_SH3) { __find_dram_shadow(addr, SH7709_CS3_BANK0_END); __find_dram_shadow(SH7709_CS3_BANK1_START, SH7709_CS3_BANK1_END); } #endif #ifdef SH4 /* contig CS3 */ if (CPU_IS_SH4) { __find_dram_shadow(addr, SH_CS3_END); } #endif _DPRINTF("mem_cluster_cnt = %d\n", mem_cluster_cnt); npages = 0; for (i = 0, seg = mem_clusters; i < mem_cluster_cnt; i++, seg++) { _DPRINTF("mem_clusters[%d] = {0x%lx+0x%lx <0x%lx}", i, (paddr_t)seg->start, (paddr_t)seg->size, (paddr_t)seg->start + (paddr_t)seg->size); npages += sh3_btop(seg->size); #ifdef NARLY_MEMORY_PROBE if (i == 0) { _DPRINTF(" don't check.\n"); continue; } if (__check_dram((paddr_t)seg->start, (paddr_t)seg->start + (paddr_t)seg->size) != 0) panic("D-RAM check failed."); #else _DPRINTF("\n"); #endif /* NARLY_MEMORY_PROBE */ } return (npages); }
void machine_startup(int argc, char *argv[], struct bootinfo *bi) { extern char edata[], end[]; vaddr_t kernend; size_t symbolsize; int i; char *p; /* * this routines stack is never polluted since stack pointer * is lower than kernel text segment, and at exiting, stack pointer * is changed to proc0. */ struct kloader_bootinfo kbi; /* Symbol table size */ symbolsize = 0; if (memcmp(&end, ELFMAG, SELFMAG) == 0) { Elf_Ehdr *eh = (void *)end; Elf_Shdr *sh = (void *)(end + eh->e_shoff); for(i = 0; i < eh->e_shnum; i++, sh++) if (sh->sh_offset > 0 && (sh->sh_offset + sh->sh_size) > symbolsize) symbolsize = sh->sh_offset + sh->sh_size; } /* Clear BSS */ memset(edata, 0, end - edata); /* Setup bootinfo */ bootinfo = &kbi.bootinfo; memcpy(bootinfo, bi, sizeof(struct bootinfo)); if (bootinfo->magic == BOOTINFO_MAGIC) { platid.dw.dw0 = bootinfo->platid_cpu; platid.dw.dw1 = bootinfo->platid_machine; } /* CPU initialize */ if (platid_match(&platid, &platid_mask_CPU_SH_3)) sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709A); else if (platid_match(&platid, &platid_mask_CPU_SH_4)) sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); /* Start to determine heap area */ kernend = (vaddr_t)sh3_round_page(end + symbolsize); /* Setup bootstrap options */ makebootdev("wd0"); /* default boot device */ boothowto = 0; for (i = 1; i < argc; i++) { /* skip 1st arg (kernel name). */ char *cp = argv[i]; switch (*cp) { case 'b': /* boot device: -b=sd0 etc. */ p = cp + 2; #ifdef NFS if (strcmp(p, "nfs") == 0) mountroot = nfs_mountroot; else makebootdev(p); #else /* NFS */ makebootdev(p); #endif /* NFS */ break; default: BOOT_FLAG(*cp, boothowto); break; } } #ifdef MFS /* * Check to see if a mini-root was loaded into memory. It resides * at the start of the next page just after the end of BSS. */ if (boothowto & RB_MINIROOT) { size_t fssz; fssz = sh3_round_page(mfs_initminiroot((void *)kernend)); #ifdef MEMORY_DISK_DYNAMIC md_root_setconf((caddr_t)kernend, fssz); #endif kernend += fssz; } #endif /* MFS */ /* Console */ consinit(); #ifdef HPC_DEBUG_LCD dbg_lcd_test(); #endif /* copy boot parameter for kloader */ kloader_bootinfo_set(&kbi, argc, argv, bi, TRUE); /* Find memory cluster. and load to UVM */ physmem = mem_cluster_init(SH3_P1SEG_TO_PHYS(kernend)); _DPRINTF("total memory = %dMbyte\n", (int)(sh3_ptob(physmem) >> 20)); mem_cluster_load(); /* Initialize proc0 u-area */ sh_proc0_init(); /* Initialize pmap and start to address translation */ pmap_bootstrap(); /* Debugger. */ #ifdef DDB if (symbolsize) { ddb_init(symbolsize, &end, end + symbolsize); _DPRINTF("symbol size = %d byte\n", symbolsize); } if (boothowto & RB_KDB) Debugger(); #endif /* DDB */ #ifdef KGDB if (boothowto & RB_KDB) { if (kgdb_dev == NODEV) { printf("no kgdb console.\n"); } else { kgdb_debug_init = 1; kgdb_connect(1); } } #endif /* KGDB */ /* Jump to main */ __asm__ __volatile__( "jmp @%0;" "mov %1, sp" :: "r"(main),"r"(proc0.p_md.md_pcb->pcb_sf.sf_r7_bank)); /* NOTREACHED */ while (1) ; }
void _CRTestMakePixelDataAndPMatrixWithProjectionSetting(float pMatrix[4][4], unsigned char **output_pixel, int width, int height, CRHomogeneousVec3* projected_corners, float focal, float xdeg, float ydeg, float zdeg, float xt, float yt, float zt) { float corners[4][4]; corners[0][0] = -0.5; corners[0][1] = -0.5; corners[0][2] = 0; corners[0][3] = 1; corners[1][0] = -0.5; corners[1][1] = 0.5; corners[1][2] = 0; corners[1][3] = 1; corners[2][0] = 0.5; corners[2][1] = 0.5; corners[2][2] = 0; corners[2][3] = 1; corners[3][0] = 0.5; corners[3][1] = -0.5; corners[3][2] = 0; corners[3][3] = 1; unsigned char *pixel = (unsigned char*)malloc(sizeof(unsigned char)*width*height); float corners_projected[12]; float mat[4][4]; for (int i = 0; i < 4; i++) { float *p = corners_projected + i * 3; _CRTestSetIdentityMatrix(pMatrix); _CRTestProjectPoint(pMatrix, corners[i], p, focal, xdeg, ydeg, zdeg, xt, yt, zt); //printf("%f,%f,%f,%f,%f,%f,%f\n", focal, xdeg, ydeg, zdeg, xt, yt, zt); //printf("%d,%d\n", width, height); // printf("--->\n"); // printf("%f\n", corners[i][0]); // printf("%f\n", corners[i][1]); // printf("<---\n"); // printf("%f\n", p[0]); // printf("%f\n", p[1]); p[0] += width / 2; p[1] += height / 2; projected_corners[i].x = p[0]; projected_corners[i].y = p[1]; projected_corners[i].w = p[2]; } int precision = 200; _DPRINTF("--------------------------------------------------------------------->\n"); float step = 1.0f / (precision - 1); for (int i = 0; i < precision; i++) { for (int j = 0; j < precision; j++) { float x_temp[4]; float x_temp_projected[4]; x_temp[0] = -0.5 + step * i; x_temp[1] = -0.5 + step * j; x_temp[2] = 0; x_temp[3] = 1; _CRTestSetIdentityMatrix(mat); _CRTestProjectPoint(mat, x_temp, x_temp_projected, focal, xdeg, ydeg, zdeg, xt, yt, zt); //printf("%f,%f,%f,%f,%f,%f,%f\n", focal, xdeg, ydeg, zdeg, xt, yt, zt); //printf("%d,%d\n", width, height); // printf("--->\n"); // printf("%f\n", x_temp[0]); // printf("%f\n", x_temp[1]); // printf("<---\n"); // printf("%f\n", x_temp_projected[0]); // printf("%f\n", x_temp_projected[1]); x_temp_projected[0] += width / 2; x_temp_projected[1] += height / 2; _CRTestSetPixel(pixel, width, height, x_temp_projected[0], x_temp_projected[1], 0x01); } } *output_pixel = pixel; }