Пример #1
0
void setupWeb(){
	// initialize the Ethernet adapter
	if (DEBUG_MEMORY) printMem("SW1 ");
	Ethernet.begin(mac, ip );
	if (DEBUG_MEMORY) printMem("SW2 ");
	server.begin();
	if (DEBUG_WEB) dbg.print("Coop server is at ");
	if (DEBUG_WEB) dbg.println(Ethernet.localIP());
}
Пример #2
0
void postMessage(const byte deviceIdx) {

	if (DEBUG_MEMORY) printMem("Post ");

	if (client_send.connect(vlosite, 80)) {
		if (DEBUG_WEB) dbg.println("NewC");

		int len = 0;
		printP(COMMAND_IO_SEND, TXTPOST);
		len = printResponse(COMMAND_IO_SEND, deviceIdx, true);
		client_send.println(len);
		if (DEBUG_WEB) dbg.println(len);
		client_send.println();
		if (DEBUG_WEB) dbg.println();
		printResponse(COMMAND_IO_SEND, deviceIdx, false);
		client_send.println();

		delay (3);
		while (client_send.available()) {
			char c = client_send.read();
			if (DEBUG_WEB) dbg.print(c);
		}

	} else {
		if (DEBUG_WEB) dbg.println("Fail");
		showStatus(NET_ERROR, 0);
		Reset_AVR();
	}

	delay(1);
	if (DEBUG_WEB) dbg.println("Disc");
	client_send.stop();
}
Пример #3
0
void printExpression(FILE* file, IR_myExp exp, int spaceNum)
{
    newline(file), indentSpace(file, spaceNum);
    if (exp == NULL)
        return printNull(file);
    
    switch (exp->kind)
    {
        case IR_BinOperation:
            return printBinOperation(file, exp, spaceNum);
        case IR_Call:
            return printCall(file, exp, spaceNum);
        case IR_Const:
            return printConst(file, exp, spaceNum);
        case IR_ESeq:
            return printESeq(file, exp, spaceNum);
        case IR_Mem:
            return printMem(file, exp, spaceNum);
        case IR_Name:
            return printName(file, exp, spaceNum);
        case IR_Temp:
            return printTemp(file, exp, spaceNum);
        default:    assert (false);
    }
}
Пример #4
0
/* Prints out our memory structure (debugging feature mostly) */
void Sys_PrintMem() {
    
    /* Flush existing writes first */
    Flush_Batched_Write();
    printMem();
    SysStatus = SUCCEEDED;
    
}
Пример #5
0
void *fpl_try_alloc(int fpl)
{
    int result;
    void *addr = (void*)-1;

    result = sceKernelTryAllocateFpl(fpl, &addr);
    printf("sceKernelTryAllocateFpl result=%08x addr=%p\n", result, addr);
    printMem();

    if (result != 0)
        addr = 0;

    return addr;
}
Пример #6
0
void *fpl_wait_alloc(const char *threadname, int fpl)
{
    int result;
    void *addr = (void*)-1;

    printf("[%s] sceKernelAllocateFpl wait alloc...\n", threadname);
    result = sceKernelAllocateFpl(fpl, &addr, 0x0);
    printf("[%s] sceKernelAllocateFpl result=%08x addr=%p\n", threadname, result, addr);
    printMem();

    if (result != 0)
        addr = 0;

    return addr;
}
Пример #7
0
void *fpl_alloc(int fpl)
{
    int result;
    unsigned int timeout = 1000000;
    void *addr = (void*)-1;

    result = sceKernelAllocateFpl(fpl, &addr, &timeout);
    printf("sceKernelAllocateFpl result=%08x addr=%p timeout=%d\n", result, addr, timeout);
    printMem();

    if (result != 0)
        addr = 0;

    return addr;
}
Пример #8
0
Файл: test.c Проект: crazzru/BS
int main() {
	int sa = 128;
	unsigned char* a = (unsigned char*)malloc(sa);
	for (int i = 0; i < sa; i++) {
		a[i] = 0xAA;
	}
	printMem();

	int sb = 256;
	unsigned char* b = (unsigned char*)malloc(sb);
	for (int i = 0; i < sb; i++) {
		b[i] = 0xBB;
	}
	printMem();

	free(a);
	printMem();

	int sc = 64;
	unsigned char* c = (unsigned char*)malloc(sc);
	for (int i = 0; i < sc; i++) {
		c[i] = 0xCC;
	}
	printMem();

	int sd = 128;
	unsigned char* d = (unsigned char*)malloc(sd);
	for (int i = 0; i < sd; i++) {
		d[i] = 0xDD;
	}
	printMem();

	free(c);
	printMem();

	free(d);
	printMem();
	
	int se = 32, sec = 2;
	unsigned char* e = (unsigned char*)calloc(sec, se);
	for (int i = 0; i < sec*se; i++) {
		e[i] = 0xEE;
	}
	printMem();
}
Пример #9
0
//only add function called from SRT or RR.  Determines which memory algorithm to use
bool Memory::add_memory(char proc, int proc_size, int time){

    if(algo == "First-Fit"){
        first_fit(proc, proc_size, time);   
    }

    else if(algo == "Next-Fit"){
        next_fit(proc, proc_size, time);   
    }

    else if(algo == "Best-Fit"){
        best_fit(proc, proc_size, time);   
    }
    else{
        return false;
    }

    printMem(time);

    return true;
}
Пример #10
0
int main(int argc, char *argv[])
{
  //int ret;
  int c;
  unsigned short i=0, ac;
  unsigned short rom_adr, startAdr=i8086_BEGINADR;  /* Mem-Viewer Startadresse  */
  char str[6];
  char cfgStr[i8086_CFG_MAX_VALUE_LEN];
  unsigned short adr;
  codeView cv;                             /* Code-Viewer Data */

  if (argc<2)
  {
                    printf("i8086emu "VERSION_NUMBER);
                    printf("\nUsage: %s [OPTIONS] FILENAME\n", argv[0]);
                    printf("\nOptions:");
                    printf("\n -c\t\t\tCodeViewer deaktivieren");
                    printf("\n -o XXXXh\t\tStartadresse");
                    printf("\n -r XXXXh\t\tStartadresse ROM-File");
                    printf("\n -d file\t\tDUMP-File");
                    printf("\n --version\t\tshow version information");
                    printf("\n --help\t\t\tthis help information");
                    printf("\n");

    exit(1);
  }
  
  
  signal(SIGTERM, resetAll);
  signal(SIGINT, resetAll);
  signal(SIGQUIT, resetAll);
  signal(SIGSEGV, resetAll);
  
  i8086clearLog(); /* Log-File leeren. */
  i8086init(); /* Prozessor initialisieren. */
  oldPortHandler = i8086SetMsgFunc(i8086_SIG_PORT_OUT, portSignalHandler);

  /* Config-File laden */
  if (i8086ReadStrConfig(cfgStr, CONFIG_FILE, "ROMFILE")!=0)
  {
    rom_adr = i8086ReadHexConfig(CONFIG_FILE, "ROMSTARTADR", 0xc000);
    LoadRomFile(cfgStr, rom_adr);
  }
  else /* Wenn ROM -> kein Core-Dump */
    if (i8086ReadStrConfig(cfgStr, CONFIG_FILE, "COREDUMP")!=0)
      LoadCoreDumpFile(cfgStr);
  startAdr = i8086ReadHexConfig(CONFIG_FILE, "PROGSTARTADR", 0x0100);
    
  for (ac=1; ac<argc; ac++) /* Programmargumente auswerten und speichern */
  {
    char *str;
    
    if(strcmp(argv[ac],"--version")==0)
    {
                    printf("i8086emu "VERSION_NUMBER"\n"
                    "Copyright (C) 2004 JMH, RD, FB, CST\n"
                    "i8086emu comes with NO WARRANTY,\n"
                    "to the extent permitted by law.\n"
                    "You may redistribute copies of i8086emu\n"
                    "under the terms of the GNU General Public License.\n");
                    exit(1);
    }
    if(strcmp(argv[ac],"--help")==0)
    {
                    printf("i8086emu "VERSION_NUMBER);
                    printf("\nUsage: %s [OPTIONS] FILENAME\n", argv[0]);
                    printf("\nOptions:");
                    printf("\n -c\t\t\tCodeViewer deaktivieren");
                    printf("\n -o XXXXh\t\tStartadresse");
                    printf("\n -r XXXXh\t\tStartadresse ROM-File");
                    printf("\n -d file\t\tDUMP-File");
                    printf("\n --version\t\tshow version information");
                    printf("\n --help\t\t\tthis help information");
                    printf("\n");

    exit(1);
    }          
    if (strcmp(argv[ac], "-c")==0)          /* CodeViewer deaktivieren */
      args |= HIDE_CODE_VIEWER;
    if ((str=strstr(argv[ac], "-o"))!=NULL) /* Startadresse des Programmes setzen */
    {
      str = strtok(str, "-o");
      if (str!=NULL)
        startAdr = strtoul(str, NULL, 16);
    }
    if ((str=strstr(argv[ac], "-r"))!=NULL) /* ROM laden */
    {
      //int adr;
      if (argc<ac+2)
      {
        printf("\n -r XXXXh file -> Startadresse ROM-File");
        exit(1);
      }
      rom_adr = strtoul(argv[ac+1], NULL, 16);
      LoadRomFile(argv[ac+2], rom_adr);
    }
    if ((str=strstr(argv[ac], "-d"))!=NULL) /* Core-Dump laden */
    {
      if (argc<ac+1)
      {
        printf("\n -d file -> DUMP-File");
        exit(1);
      }       
      LoadCoreDumpFile(argv[ac+1]);
    }
  }

  if (i8086loadBinFile(core, argv[argc-1], startAdr)!=i8086_SUC_FILELOAD)
  {
    i8086error(argv[argc-1], i8086_ERR_STR_FILENF);    
  }
  if (args & LOAD_ROM) /* ROM verarbeiten */
    startAdr = rom_adr;
  core->pc = startAdr;
    
  initscr();
  clear();
  refresh();
  createWin();

  printReg();
  printFlags();
  printLeds(0);
  printSwitches();
  printDisplay();
  printMem(startAdr);
  cv.startAdr = 0;//i8086_BEGINADR;
  cv.endAdr = 0;

  printCode(core, commands, &cv);
  //i8086PushMsg(1, 1);

  noecho();     /* getch echo aus */
  curs_set(0);  /* Cursor ausschalten */

  keypad(stdscr,1);
  //while (/*c=='g' ||*/ (c=getch/*ar*/())!='q')

  //sendepuffer ist leer
  //core->ports.x[0xD2]=3;

  while ((c==ERR && i%50000!=0) || (c=getch/*ar*/())!='q') //automode nur aller 50000 takte abbrechbar, reicht aber aus, sonst wars zu langsam
  {
    i++;
    if (c==KEY_F(9))
      nodelay(stdscr,TRUE);
    else if (c=='n')
      nodelay(stdscr,FALSE);
    else if (c==KEY_F(8))
    {
    	adr=i8086GetSegRegister_fast(core,i8086_REG_CS, 1)+core->pc;
    	stepover=adr+commands[core->mem[adr]]->size;
	if (commands[core->mem[adr]]->hasMod!=0)
		stepover+=getAdditionalCmdLength(core, core->mem[adr], core->mem[adr+1]);
    	nodelay(stdscr,TRUE);
    }

    if (c==ERR||c=='n') /* next Opcode */
      if (i8086execCommand(core, commands)==i8086_ERR_ILGOPCODE)
      {
        sprintf(str, "%hd", core->mem[core->pc + i8086GetSegRegister_fast(core, i8086_REG_CS, 1)]);
        i8086error(i8086_ERR_STR_ILGOPCODE, str);
        //resetAll(0);
      }

    if (i8086GetSegRegister_fast(core,i8086_REG_CS, 1)+core->pc==breakpoint || i8086GetSegRegister_fast(core,i8086_REG_CS, 1)+core->pc==stepover)
    {
    	i=0;
    	nodelay(stdscr,FALSE);
	    c=0;
    }

    if (c=='r') /* set Registervalue */
      setReg();
    else if (c==KEY_F(1)) /* Print Help */
      printHelp();
    else if (c==KEY_F(2)) //Breakpoint setzen
      {
      	setBreakpoint();
	c=0;
      }
    else if (c=='m') /* Anfangsadresse von Speicherviewer setzen */
      startAdr=readMem();
    else if (c=='w') /* Wert von Speicherzelle setzen */
      setMem();
    else if (c==KEY_F(3)) /* CoreDump */
      coreDump();
    else if ((c>='0')&&(c<='7')) /* Schalter An/Aus */
    {
      unsigned char dual[] = {1,2,4,8,16,32,64,128};
      core->ports.x[0] = core->ports.x[0] ^ dual[atoi((char*)&c)];
    }
    else if (c==KEY_F(12))	//Reset Taste
    {
    	i=0;
    	core->pc=0x0c000;
	i8086SetSegRegister(core,i8086_REG_CS,0xc00);
	i8086SetRegister(core,i8086_REG_AX,1,0);
	//i8086SetRegister(core,i8086_REG_BX,1,0);
	//i8086SetRegister(core,i8086_REG_CX,1,0);
	//i8086SetRegister(core,i8086_REG_DX,1,0);
	//nodelay(stdscr,TRUE);
    }

    handleKeyboard(core,c);

    if (c!=ERR)
    {
      printReg();
      printFlags();
      printSwitches();
      printDisplay();
      printMem(startAdr);
      printCode(core, commands, &cv);
    //printLeds();
    }
  }

  resetAll(0);

  return EXIT_SUCCESS;
}
Пример #11
0
void updateWeb(){
//if (DEBUG_MEMORY) printMem(" Web 1 ");

	client_recv = server.available();
	byte cptr;
	const char *slash = "/";
	const char *space = " ";

	if (client_recv) {
		while (client_recv.connected()) {
			if (client_recv.available()) {
				char c = client_recv.read();
				
				//read char by char HTTP request
				if (cptr < MAX_STRING_LEN-1) {
					temp[cptr++] = c;
				} else {
					cptr = 0;
				}
				temp[cptr] = '\0';

				//if HTTP request has ended
				if (c == '\n') {
					if (DEBUG_WEB) dbg.println(temp); //print to serial monitor for debuging

					if (strstr(temp,"GET / ")) { 		// Root requested, then give page, else try to parse post parameters
						if (DEBUG_MEMORY) printMem("WebG ");
	    	     		printP(COMMAND_IO_RECV, HEADER_OK);
						client_recv.println();
	    	     		printP(COMMAND_IO_RECV, HEADERPG2);
	    	     		printP(COMMAND_IO_RECV, HEADERPG3);

						for (byte deviceIdx = 0 ; deviceIdx < DEVICE_COUNT ;  deviceIdx++ ) {
							mdevices[deviceIdx].readInput();
		    	     		printP(COMMAND_IO_RECV, AOPEN);
		    	     		printP(COMMAND_IO_RECV, H3);					// <H3>
		    	     		printP(COMMAND_IO_RECV, ACLOSE);
							switch (deviceIdx) {
							case 0:
								printP(COMMAND_IO_RECV, DEV_0);
								break;
							case 1:
								printP(COMMAND_IO_RECV, DEV_1);
								break;
							case 2:
								printP(COMMAND_IO_RECV, DEV_2);
								break;
							case 3:
								printP(COMMAND_IO_RECV, DEV_3);
								break;
							case 4:
								printP(COMMAND_IO_RECV, DEV_4);
								break;
							case 5:
								printP(COMMAND_IO_RECV, DEV_5);
								break;
							case 6:
								printP(COMMAND_IO_RECV, DEV_6);
								break;
							case 7:
								printP(COMMAND_IO_RECV, DEV_7);
								break;
							case 8:
								printP(COMMAND_IO_RECV, DEV_8);
								break;
							case 9:
								printP(COMMAND_IO_RECV, DEV_9);
								break;
							}
		    	     		printP(COMMAND_IO_RECV, AOPEN);
		    	     		printP(COMMAND_IO_RECV, SLASH);
		    	     		printP(COMMAND_IO_RECV, H3);					// </H3>
		    	     		printP(COMMAND_IO_RECV, ACLOSE);
		    	     		printP(COMMAND_IO_RECV, AOPEN);
		    	     		printP(COMMAND_IO_RECV, SPAN);					// <SPAN>
		    	     		printP(COMMAND_IO_RECV, ACLOSE);

							printPage(COMMAND_IO_RECV, deviceIdx);

		    	     		printP(COMMAND_IO_RECV, AOPEN);
		    	     		printP(COMMAND_IO_RECV, BR);
		    	     		printP(COMMAND_IO_RECV, SLASH);
		    	     		printP(COMMAND_IO_RECV, ACLOSE);
		    	     		printP(COMMAND_IO_RECV, AOPEN);
		    	     		printP(COMMAND_IO_RECV, SLASH);
		    	     		printP(COMMAND_IO_RECV, SPAN);					// </SPAN>
		    	     		printP(COMMAND_IO_RECV, ACLOSE);
						}
						printP(COMMAND_IO_RECV, HEADERPGEND);
					} else {												// parse

						// parse url POST /d/203/c/23/v/12 HTTP/1.1
						if (DEBUG_MEMORY) printMem("WebP ");
						int deviceID = 0;
						int commandID = 0;
						int commandValue = 0;
						//temp = strtok(temp, " "); // POST /d/203/c/23/v/12 HTTP/1.1
						char * token = strtok(temp, space); // POST /d/203/c/23/v/12 HTTP/1.1
						byte deviceIdx = ERROR;
						byte result = ERROR;
						if (strcmp(token,"POST") == 0) {
							token = strtok(NULL, space); // Second part
							token = strtok(token, slash); // d
							token = strtok(NULL, slash); // deviceID
							deviceID = atoi(token);
							token = strtok(NULL, slash); // c
							token = strtok(NULL, slash); // commandID
							commandID = atoi(token);
							token = strtok(NULL, slash); // v
							if (token != NULL) {
								token = strtok(NULL, slash); // value ?
								commandValue = atoi(token);
							}
							deviceIdx = findDeviceIndex(deviceID);
							if (DEBUG_WEB) dbg.print("Idx ");
							if (DEBUG_WEB) dbg.println(deviceIdx);

							if (deviceIdx != ERROR) {
								result = deviceCommandHandler(deviceIdx, commandID, false, commandValue);
							} // return error?
						}

						if ( deviceIdx == ERROR || result == ERROR) {
							printP(COMMAND_IO_RECV, HEADER_ERR);
							client_recv.println();
							printP(COMMAND_IO_RECV, HEADER_ERR_MESS);
						} else {
							printP(COMMAND_IO_RECV, HEADER_OK);
							client_recv.println();
							if ( result == HNDLR_WRITE_RESULT) printResponse(COMMAND_IO_RECV, deviceIdx, false);
						}
					}
					delay(1);
					//stopping client
					client_recv.stop();
					//clearing string for next read
					cptr = 0;
					temp[cptr] = '\0';
				}
			}
		}
	}
}
Пример #12
0
void fpl_test()
{
    int result;
    int fpl;
    int attr = 0x4000;

    //fpl = sceKernelCreateFpl("FPL", 2, attr, 0x1000, 1, 0x0);
    fpl = sceKernelCreateFpl("FPL", 2, attr, 0x1, 2, 0x0);
    //fpl = sceKernelCreateFpl("FPL", 2, attr, 0x4000000, 1, 0x0); // not enough free mem
    printf("sceKernelCreateFpl(attr=%08x) %08x\n", attr, fpl);
    if (fpl <= 0)
        return;

    printMem(); // 256-byte aligned consumption (may be enforced by pspsysmem, not threadman/fpl)
    fpl_refer(fpl);

    void *addr;
    void *addr2;

    addr = fpl_alloc(fpl);

    if (0)
    {
        // test multiple wait
        int thid = sceKernelCreateThread("fpl_thread", fpl_thread, 0x20, 0x4000, 0, 0);
        if (thid >= 0)
        {
            sceKernelStartThread(thid, 4, &fpl);
        }

        addr2 = fpl_wait_alloc("user_main", fpl);
    }
    else
    {
        addr2 = fpl_alloc(fpl); // 32-bit aligned
        fpl_try_alloc(fpl);
        //fpl_try_alloc(fpl);
    }
    fpl_refer(fpl);

    if (addr)
    {
        result = sceKernelFreeFpl(fpl, addr); // ok
        printf("sceKernelFreeFpl(addr) result=%08x\n", result);
        printMem();

        //result = sceKernelFreeFpl(fpl, addr); // illegal mem block
        //printf("sceKernelFreeFpl(addr) result=%08x\n", result);
        //printMem();
    }

    if (addr2)
    {
        result = sceKernelFreeFpl(fpl, addr2); // ok
        printf("sceKernelFreeFpl(addr2) result=%08x\n", result);
        printMem();
    }

    //result = sceKernelFreeFpl(fpl, (void*)0x08A00000); // illegal mem block
    //printf("sceKernelFreeFpl(0x08A00000) result=%08x\n", result);
    //printMem();

    result = sceKernelDeleteFpl(fpl); // ok
    printf("sceKernelDeleteFpl %08x\n", result);
    printMem();

    result = sceKernelDeleteFpl(fpl); // not found fpl
    printf("sceKernelDeleteFpl %08x\n", result);
    printMem();

    fpl_refer(fpl); // not found fpl
}
Пример #13
0
void
BoardInfoInit(void)
{
    short   len;
    ushort  crc;
    struct  boardinfo *bip;
    int     maxpromptsize, erased;
    struct  boardinfoverify *bipv;
    uchar   buf[BOARDINFO_BUFMAX];
    char    c, snum[8], prfmt[16], *prefill;

    sprintf(snum,"%d",BOARDINFO_SECTOR);

    /* Step through each bip entry and see if the data area is either
     * empty or the crc16 passed.  If either is true, then allow
     * If every entry in the board-information area is either empty
     * or the crc test passes, we can just return...
     */
    erased = 0;
    maxpromptsize = 0;
    boardinfo_error = 0;
    bip = boardinfotbl;
    while((bip->array) && (!boardinfo_error)) {
        BINFOPRINT(("Boardinfo item: %s (%s)",bip->varname,bip->prompt));
        if(bip->array[0] != 0xff) {
            BINFOPRINT((" not"));
            bipv = (struct boardinfoverify *)&bip->array[bip->size-BIVSIZE];

            /* If len and crc are set, then use those fields to sanity
             * check the data...
             */
            if((bipv->len != 0xffff) && (bipv->crc16 != 0xffff)) {
                if((bipv->len > bip->size) ||
                        (xcrc16(bip->array,bipv->len) != bipv->crc16)) {
                    boardinfo_error = 1;
                }
            }
        } else {
            erased++;
        }
        BINFOPRINT((" erased\n"));

        /* Gather data to determine the largest prompt... */
        len = strlen(bip->prompt);
        if(len > maxpromptsize) {
            maxpromptsize = len;
        }
        bip++;
    }

    /* If there was no error, and the board info area is not erased,
     * we return here assuming the data is valid.
     */
    if((boardinfo_error == 0) && (erased == 0)) {
        sectorProtect(snum,1);
        return;
    }

    /* If there was some kind of error reading any of the fields in the
     * board-info area, then either return or clear the error and interact
     * with the user to re-load the data...
     */
    if(boardinfo_error != 0) {
#ifdef BOARDINFO_REENTER_ON_ERROR
        printf("\nError reading board-info data, re-enter data...");
        boardinfo_error = 0;
#else
        printf("\nError reading board-info data in sector %d.\n",
               BOARDINFO_SECTOR);
        return;
#endif
    }

    sprintf(prfmt,"%%%ds : ",maxpromptsize);

    printf("%s: board information field initialization...\n",PLATFORM_NAME);

    /* Un-protect the sector used for board information...
     */
    sectorProtect(snum,0);

    do {
        /* Erase the sector used for board information...
         */
        if(AppFlashErase(BOARDINFO_SECTOR) < 0) {
            boardinfo_error = 1;
            break;
        }

        /* Step through each entry in the boardinfo table and query
         * the user for input to be stored...
         */
        bip = boardinfotbl;
        while(bip->array) {
            bipv = (struct boardinfoverify *)&bip->array[bip->size-BIVSIZE];

            if(bip->def) {
                prefill = bip->def;
            } else {
                prefill = 0;
            }

            printf(prfmt,bip->prompt);
            len = 0;
            if(getline_p((char *)buf,bip->size-BIVSIZE,0,prefill) != 0) {
                len = strlen(buf)+1;
                if(AppFlashWrite(bip->array,buf,len) < 0) {
                    boardinfo_error = 1;
                    break;
                }
                crc = xcrc16(buf,len);
            }
            if(len) {
                if(AppFlashWrite((uchar *)(&bipv->len),
                                 (uchar *)&len,sizeof(len)) < 0) {
                    boardinfo_error = 1;
                    break;
                }
                if(AppFlashWrite((uchar *)(&bipv->crc16),
                                 (uchar *)&crc,sizeof(crc)) < 0) {
                    boardinfo_error = 1;
                    break;
                }
            }
            bip++;
        }
        if(boardinfo_error) {
            break;
        }

        bip = boardinfotbl;
        printf("\nNew system settings:\n\n");
        while(bip->array) {
#ifdef BOARDINFO_SHOW_RAW
            printMem(bip->array,bip->size,1);
#else
            printf("%24s: %s\n",bip->prompt,
                   bip->array[0] == 0xff ? "" : (char *)bip->array);
#endif
            bip++;
        }
        putstr("\nHit ENTER to accept, any other key to re-enter...");
        c = getchar();
        putchar('\n');

    } while((c != '\r') && (c != '\n'));

    sectorProtect(snum,1);
}
Пример #14
0
int main(void){


	char op_code[100];
	uint16_t instAddr;
	uint16_t topAddr;
	uint16_t baseAddr;
	uint16_t mem;
	int run = 1;
	char fileName[100];
	char in[100];

	puts("Initializing memory");
	puts("Usage:\n ~pm lower upper : prints memor from lower to upper, <mem> = 1 for secondary");
	puts("~rm : resets memory");
	puts("~in : import file into memory");
	puts("~wr : writes current MEM to the RAM chip");
	puts("~rr <mem> : reads current RAM into MEM, reads into secondary mem if <mem> = 1");
	puts("~cm : checks secondary memory to main memory");
	puts("~q : quit");

	//setup
	setup_io();
	initGPIOs();
	initMem();

	GPIO_SET = 1 << WE;

	//UNCOMMENT FOR PI AS RAM
	//pthread_t tid;
	//pthread_create(&tid, NULL, memThread, NULL);



	while(run){

		printf("Input: ");
		fgets(in, 99, stdin);
		sscanf(in, "%s %hu %hu %hu", op_code, &instAddr, &topAddr, &mem);

		//Process input
		if(!strcmp(op_code, "~q")){
			printf("Shuting down memory...\n");
			run = 0;
		}
		else if(!strcmp(op_code, "~pm")){
			printMem(instAddr, topAddr, mem);
			printf("Current Address: %hu\n", readAddress());
		}
		else if(!strcmp(op_code, "~rm")){
			freeMem();
			initMem();
		}
		else if(!strcmp(op_code, "~in")){
			printf("Enter file name, followed by an address to load at: ");
        	        scanf("%s %hu", fileName, &baseAddr);
			puts("WARNING, make sure the base address is set correctly when assembling file");
			while(getchar()!= '\n');
			if(readBin(fileName, baseAddr) == -1){
                        	puts("Could not open file");
			}
		}
		else if(!strcmp(op_code, "~wr")){
			printf("Writing current MEM to RAM...\n");
			writeRAMChip();
		}
		else if(!strcmp(op_code, "~rr")){
			printf("Reading RAM into Memory\n");
			readRAMChip(instAddr);
		}
		else if(!strcmp(op_code, "~off")){
			initGPIOs();
		}
		else if(!strcmp(op_code, "~cm")){
			checkMEM(instAddr);
		}


	}

}
Пример #15
0
void chainNet(char *chainFile, char *tSizes, char *qSizes, 
	char *tNet, char *qNet)
/* chainNet - Make alignment nets out of chains. */
{
struct lineFile *lf = lineFileOpen(chainFile, TRUE);
struct hash *qHash, *tHash;
struct chrom *qChromList, *tChromList, *tChrom, *qChrom;
struct chain *chain;
double lastScore = -1;
struct lm *lm = lmInit(0);
struct rbTreeNode **rbStack;
FILE *tNetFile = mustOpen(tNet, "w");
FILE *qNetFile = mustOpen(qNet, "w");


lmAllocArray(lm, rbStack, 256);
makeChroms(qSizes, lm, rbStack, &qHash, &qChromList);
makeChroms(tSizes, lm, rbStack, &tHash, &tChromList);
verbose(1, "Got %d chroms in %s, %d in %s\n", slCount(tChromList), tSizes,
       slCount(qChromList), qSizes);
lineFileSetMetaDataOutput(lf, tNetFile);
lineFileSetMetaDataOutput(lf, qNetFile);

/* Loop through chain file building up net. */
while ((chain = chainRead(lf)) != NULL)
    {
    /* Make sure that input is really sorted. */
    if (lastScore >= 0 && chain->score > lastScore)
        errAbort("%s must be sorted in order of score", chainFile);
    lastScore = chain->score;

    if (chain->score < minScore) 
	{
    	break;
	}
    verbose(2, "chain %f (%d els) %s %d-%d %c %s %d-%d\n", 
	    chain->score, slCount(chain->blockList), 
	    chain->tName, chain->tStart, chain->tEnd, 
	    chain->qStrand, chain->qName, chain->qStart, chain->qEnd);
    qChrom = hashMustFindVal(qHash, chain->qName);
    if (qChrom->size != chain->qSize)
        errAbort("%s is %d in %s but %d in %s", chain->qName, 
		chain->qSize, chainFile,
		qChrom->size, qSizes);
    tChrom = hashMustFindVal(tHash, chain->tName);
    if (tChrom->size != chain->tSize)
        errAbort("%s is %d in %s but %d in %s", chain->tName, 
		chain->tSize, chainFile,
		tChrom->size, tSizes);
    if (!inclQuery(chain))
        verbose(2, "skipping chain on query %s\n", chain->qName);
    else
        {
        addChain(qChrom, tChrom, chain);
        verbose(2, "%s has %d inserts, %s has %d\n", tChrom->name, 
                tChrom->spaces->n, qChrom->name, qChrom->spaces->n);
        }
    }
/* Build up other side of fills.  It's just for historical 
 * reasons this is not done during the main build up.   
 * It's a little less efficient this way, but to change it
 * some hard reverse strand issues would have to be juggled. */
verbose(1, "Finishing nets\n");
finishNet(qChromList, TRUE);
finishNet(tChromList, FALSE);

/* Write out basic net files. */
verbose(1, "writing %s\n", tNet);
outputNetSide(tChromList, tNetFile, FALSE);
verbose(1, "writing %s\n", qNet);
outputNetSide(qChromList, qNetFile, TRUE);

/* prevent SIGPIPE in preceding process if input is a pipe, consume remainder
 * of input file since we stop before EOF. */
if (isPipe(lf->fd))
    {
    char *line;
    while(lineFileNext(lf, &line, NULL))
        continue;
    }
lineFileClose(&lf);

if (verboseLevel() > 1)
    printMem(stderr);
}
Пример #16
0
// this is called after a memory block has been allocated and needs to be registered
void Mem::addMem ( void *mem , size_t size , const char *note , char isnew ) {
	if(!s_lock.working) return;

	ScopedLock sl(s_lock);

	logTrace( g_conf.m_logTraceMem, "mem=%p size=%zu note='%s' is_new=%d", mem, size, note, isnew );

	//validate();

	  // 4G/x = 600*1024 -> x = 4000000000.0/(600*1024) = 6510
	// crap, g_hostdb.init() is called inmain.cpp before
	// g_conf.init() which is needed to set g_conf.m_maxMem...
	if ( ! s_initialized ) {
		//m_memtablesize = m_maxMem / 6510;
		// support 1.2M ptrs for now. good for about 8GB
		// raise from 3000 to 8194 to fix host #1
		m_memtablesize = 8194*1024;//m_maxMem / 6510;
		//if ( m_maxMem < 8000000000 ) gbshutdownLogicError();
	}

	if ( (int32_t)m_numAllocated + 100 >= (int32_t)m_memtablesize ) { 
		static bool s_printed = false;
		if ( ! s_printed ) {
			log(LOG_WARN, "mem: using too many slots");
			printMem();
			s_printed = true;
		}
	}

	logDebug( g_conf.m_logDebugMem, "mem: add %08" PTRFMT" %zu bytes (%" PRId64") (%s)", (PTRTYPE)mem, size, m_used, note );

	// check for breech after every call to alloc or free in order to
	// more easily isolate breeching code.. this slows things down a lot
	// though.
	if ( g_conf.m_logDebugMem ) printBreeches_unlocked();

	// copy the magic character, iff not a new() call
	if ( size == 0 ) {
		sl.unlock();
		gbshutdownLogicError();
	}

	// sanity check -- for machines with > 4GB ram?
	if ( (PTRTYPE)mem + (PTRTYPE)size < (PTRTYPE)mem ) {
		log(LOG_LOGIC,"mem: Kernel returned mem at "
		    "%08" PTRFMT" of size %" PRId32" "
		    "which would wrap. Bad kernel.",
		    (PTRTYPE)mem,(int32_t)size);
		sl.unlock();
		gbshutdownLogicError();
	}

	// umsg00
//	bool useElectricFence = false;
//	if ( ! isnew && ! useElectricFence ) {
	if ( ! isnew ) {
		for ( int32_t i = 0 ; i < UNDERPAD ; i++ )
			((char *)mem)[0-i-1] = MAGICCHAR;
		for ( int32_t i = 0 ; i < OVERPAD ; i++ )
			((char *)mem)[0+size+i] = MAGICCHAR;
	}

	// if no label!
	if ( ! note[0] ) log(LOG_LOGIC,"mem: addmem: NO note.");

	// clear mem ptrs if this is our first call
	if ( ! s_initialized ) {

		s_mptrs  = (void **)sysmalloc ( m_memtablesize*sizeof(void *));
		s_sizes = (size_t *)sysmalloc(m_memtablesize * sizeof(size_t));
		s_labels = (char  *)sysmalloc ( m_memtablesize*16            );
		s_isnew  = (char  *)sysmalloc ( m_memtablesize               );
		if ( ! s_mptrs || ! s_sizes || ! s_labels || ! s_isnew ) {
			if ( s_mptrs  ) sysfree ( s_mptrs  );
			if ( s_sizes  ) sysfree ( s_sizes  );
			if ( s_labels ) sysfree ( s_labels );
			if ( s_isnew  ) sysfree ( s_isnew );
			log(LOG_WARN, "mem: addMem: Init failed. Disabling checks.");
			g_conf.m_detectMemLeaks = false;
			return;
		}
		s_initialized = true;
		memset ( s_mptrs , 0 , sizeof(char *) * m_memtablesize );
	}
	// try to add ptr/size/note to leak-detecting table
	if ( (int32_t)s_n > (int32_t)m_memtablesize ) {
		log( LOG_WARN, "mem: addMem: No room in table for %s size=%zu.", note,size);
		return;
	}
	// hash into table
	uint32_t u = (PTRTYPE)mem * (PTRTYPE)0x4bf60ade;
	uint32_t h = u % (uint32_t)m_memtablesize;
	// chain to an empty bucket
	int32_t count = (int32_t)m_memtablesize;
	while ( s_mptrs[h] ) {
		// if an occupied bucket as our same ptr then chances are
		// we freed without calling rmMem() and a new addMem() got it
		if ( s_mptrs[h] == mem ) {
			// if we are being called from addnew(), the 
			// overloaded "operator new" function above should
			// have stored a temp ptr in here... allow that, it
			// is used in case an engineer forgets to call 
			// mnew() after calling new() so gigablast would never
			// realize that the memory was allocated.
			if ( s_sizes[h] == size &&
			     s_labels[h*16+0] == 'T' &&
			     s_labels[h*16+1] == 'M' &&
			     s_labels[h*16+2] == 'P' &&
			     s_labels[h*16+3] == 'M' &&
			     s_labels[h*16+4] == 'E' &&
			     s_labels[h*16+5] == 'M'  ) {
				goto skipMe;
			}
			log( LOG_ERROR, "mem: addMem: Mem already added. rmMem not called? label=%c%c%c%c%c%c",
			     s_labels[h*16+0],
			     s_labels[h*16+1],
			     s_labels[h*16+2],
			     s_labels[h*16+3],
			     s_labels[h*16+4],
			     s_labels[h*16+5] );
			sl.unlock();
			gbshutdownAbort(true);
		}
		h++;
		if ( h == m_memtablesize ) h = 0;
		if ( --count == 0 ) {
			log( LOG_ERROR, "mem: addMem: Mem table is full.");
			printMem();
			sl.unlock();
			gbshutdownResourceError();
		}
	}
	// add to debug table
	s_mptrs  [ h ] = mem;
	s_sizes  [ h ] = size;
	s_isnew  [ h ] = isnew;
	//log("adding %" PRId32" size=%" PRId32" to [%" PRId32"] #%" PRId32" (%s)",
	//(int32_t)mem,size,h,s_n,note);
	s_n++;
	// debug
	if ( (size > MINMEM && g_conf.m_logDebugMemUsage) || size>=100000000 )
		log(LOG_INFO,"mem: addMem(%zu): %s. ptr=0x%" PTRFMT" "
		    "used=%" PRId64,
		    size,note,(PTRTYPE)mem,m_used);
	// now update used mem
	// we do this here now since we always call addMem() now
	m_used += size;
	m_numAllocated++;
	m_numTotalAllocated++;
	if ( size > m_maxAlloc ) { m_maxAlloc = size; m_maxAllocBy = note; }
	if ( m_used > m_maxAllocated ) m_maxAllocated = m_used;


 skipMe:
	int32_t len = strlen(note);
	if ( len > 15 ) len = 15;
	char *here = &s_labels [ h * 16 ];
	memcpy ( here , note , len );
	// make sure NULL terminated
	here[len] = '\0';
	//validate();
}
Пример #17
0
/*
* Main loop used to continuously ask for user input
*/
int mainloop(){

	//Local variables
	int mode = 0;
	char op_code[100];
	uint16_t instAddr;
	uint16_t topAddr;
	uint16_t baseAddr;
	char fileName[100];
	char run = 1;
	char in[100];
	regA.data = 0;
	regSTAT.data = 0;
	nibble currentInst;
	int tempAddress = 0;
	int instrRun = 0;
	struct timespec gettime_now;
	struct timespec newTime = {0, 0};
	long totalFirstTime;
	long totalSecondTime;
	long firstTime;
	long secondTime;
	long period = 200000;
	char step = 0;




	while(run){

		if(mode == USERMODE)
			printf("Input: ");
		fgets(in, 99, stdin);
		sscanf(in, "%s %hu %hu", op_code, &instAddr, &topAddr);

		//Process input
		if(!strcmp(op_code, "~q")){
			printf("Halting\n");
			run = 0;
		}
		else if(!strcmp(op_code, "~pm")){
			printMem(instAddr, topAddr);
		}
		else if(!strcmp(op_code, "~pr")){
			printReg();
		}
		else if(!strcmp(op_code, "~in")){
			printf("Enter file name, followed by an address to load at: ");
        	        scanf("%s %hu", fileName, &baseAddr);
			puts("WARNING, make sure the base address is set correctly when assembling file");
			while(getchar()!= '\n');
			if(readBin(fileName, baseAddr) == -1){
                        	printf("Entering User Input Mode");
   				mode = USERMODE;
			}
		}
		else if(!strcmp(op_code, "~run")){
			regPC = instAddr;
			instrRun = 0;
			regSTAT.data &= 0xD;
			mode = FILEMODE;
			step = 0;
		}
		else if(!strcmp(op_code, "~step")){
			if(instAddr != NULL)
			{
				regPC = instAddr;
				regSTAT.data &= 0xD;
			}
			instrRun = 0;
			mode = FILEMODE;
			step = 1;
		}
		else if(!strcmp(op_code, "~cp")){
                        printf("Enter period: ");
                        scanf("%li", &period);
                        while(getchar()!= '\n');
		}
		else if(!strcmp(op_code, "~rm")){
			freeMem();
			initMem();
		}
		else {
			if(mode == USERMODE)
				decode(op_code, instAddr);
		}

		if(mode == FILEMODE){
			if(step == 0)
			{
				puts("Program started...");
			}
			else if (step == 1)
			{
				puts("Stepping forward...");
			}

			//Runs while HLT is off
			while(!(regSTAT.data & 0x2)){

				//Start of file code

				//EXECUTE FIRST 4 BITS
				currentInst = readMem(regPC);

                                clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
                                waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_CLR = 1<<CLKPIN;
								#endif
				
				clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_SET = 1<<CLKPIN;
								#endif
				
				//EXECUTE SECOND 4 BITS
				instAddr = 0;
				tempAddress = 0;
				tempAddress = readMem(++regPC).data;
				instAddr |= (tempAddress << 12);

                                clock_gettime(CLOCK_REALTIME, &gettime_now);
				firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2);
								#ifdef RPI
                                GPIO_CLR = 1 <<CLKPIN;
								#endif
								
				clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_SET = 1<<CLKPIN;
								#endif

				//EXECUTE THIRD 4 BITS
	                        tempAddress = readMem(++regPC).data;
       		                instAddr |= (tempAddress << 8);


                                clock_gettime(CLOCK_REALTIME, &gettime_now);
				firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_CLR = 1<<CLKPIN;
								#endif
								
				clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_SET = 1<<CLKPIN;
								#endif
				//EXECUTE FOURTH 4 BITS
                        	tempAddress = readMem(++regPC).data;
                        	instAddr |= (tempAddress << 4);

                                clock_gettime(CLOCK_REALTIME, &gettime_now);
				firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
				#ifdef RPI
				GPIO_CLR = 1 <<CLKPIN;
				#endif

				clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_SET = 1<<CLKPIN;
								#endif
								
				//EXECUTE FIFTH 4 BITS
                      		tempAddress = readMem(++regPC).data;
	                        instAddr |= (tempAddress);
				regPC++;

                                clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_CLR = 1<<CLKPIN;
								#endif
								
				clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_SET = 1<<CLKPIN;
								#endif	
								
	                        if(currentInst.data == HLT)
        	                        decode("HLT", instAddr);
                	        else if(currentInst.data == LOD)
                        	        decode("LOD", instAddr);
	                        else if(currentInst.data == STR)
        	                       	decode("STR", instAddr);
                	        else if(currentInst.data == ADD)
                        	        decode("ADD", instAddr);
	                        else if(currentInst.data == NOP)
        	                        decode("NOP", instAddr);
                	        else if(currentInst.data == NND)
                        	        decode("NND", instAddr);
	                        else if(currentInst.data == CXA)
        	                       	decode("CXA", instAddr);
                	        else if(currentInst.data == JMP)
                        	        decode("JMP", instAddr);
	                        else
									#ifndef __MINGW32__
        	                        shutdown(UNKNOWNINSTRUCTIONERROR);
									#endif
									#ifdef __MINGW32__
									shutdown_vm4(UNKNOWNINSTRUCTIONERROR);
									#endif

                                clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
                                waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_CLR = 1 <<CLKPIN;
								#endif
								
				clock_gettime(CLOCK_REALTIME, &gettime_now);
                                firstTime = gettime_now.tv_nsec;
				waitForPeriod(firstTime,gettime_now,period/2 );
								#ifdef RPI
                                GPIO_SET = 1<<CLKPIN;
								#endif

				if(step == 1)
				{
					break;
				}

			}
		if((regSTAT.data & 0x2) && step)
		{
			puts("Computer halted");
		}
		mode = USERMODE;
		if(step == 0)
		{
			puts("Program finished");
			printf("Instructions run %d\n", instrRun);
			#ifdef RPI
			GPIO_CLR = 1 << CLKPIN;
			#endif
		}
		}

	}

	return 1;
}