Exemplo n.º 1
0
void MainWindow::jumpToSelectedAddress() {
    if (auto address = cxxView_->getIntegerUnderCursor()) {
        if (jumpToAddress(*address)) {
            instructionsView_->show();
        }
    }
}
Exemplo n.º 2
0
void MainWindow::jumpToSymbolAddress() {
    if (auto symbol = symbolsView_->selectedSymbol()) {
        if (symbol->value()) {
            if (jumpToAddress(*symbol->value())) {
                instructionsView_->show();
            }
        }
    }
}
Exemplo n.º 3
0
void Cpu::processInstruction() {
    switch (_ir) {
    case 1: // load value
        _ac = fetchInstruction();
        break;
    case 2: // load value at the address into the AC
        _ac = readFromMemory(fetchInstruction());
        break;
    case 3: // Use the AC value as an address to a another value.
        // this new value is also used as an address to the final value.
        _ac = readFromMemory(readFromMemory(fetchInstruction()));
        break;
    case 4: // load the value at address + X into the AC
        _ac = readFromMemory(fetchInstruction() + _x);
        break;
    case 5: // load the value at the address + Y into the AC
        _ac = readFromMemory(fetchInstruction() + _y);
        break;
    case 6: // from from sp + X into the AC
        _ac = readFromMemory(_sp + _x);
        break;
    case 7: // store the AC value into the following address
        writeToMemory(fetchInstruction(), _ac);
        break;
    case 8: // Get a random integer from interval [1, 100]
        putRandInAC();
        break;
    case 9: // write the AC to the screen as an integer if following value is 1
        // or as an char if the following value is 2
        putPort();
        break;
    case 10: // add the value in X to the AC
        _ac = _ac + _x;
        break;
    case 11: // add the value in Y to the AC
        _ac = _ac + _y;
        break;
    case 12: // subtract the value in X from the AC
        _ac = _ac - _x;
        break;
    case 13: // subtract the value in Y from the AC
        _ac = _ac - _y;
        break;
    case 14: // Copy AC to X
        _x = _ac;
        break;
    case 15: // Copy X to AC
        _ac = _x;
        break;
    case 16: // Copy AC to Y
        _y = _ac;
        break;
    case 17: // Copy Y to AC
        _ac = _y;
        break;
    case 18: // Copy AC to SP
        _sp = _ac;
        break;
    case 19: // Copy SP to AC
        _ac = _sp;
        break;
    case 20: // Jump to following address
        jumpToAddress(fetchInstruction());
        break;
    case 21: // jump to address if AC == 0
        if (_ac == 0)
            jumpToAddress(fetchInstruction());
        else
            _pc++;
        break;
    case 22: // jump to address if AC != 0
        if (_ac != 0)
            jumpToAddress(fetchInstruction());
        else
            _pc++;
        break;
    case 23: // push return address onto the stack and jump to the following address
        callAddress();
        break;
    case 24: // return from stack
        jumpToAddress(pop());
        break;
    case 25:
        _x++;
        break;
    case 26:
        _x--;
        break;
    case 27:
        push(_ac);
        break;
    case 28:
        _ac = pop();
        break;
    case 29: // Set system mode, switch stack, push SP and PC, set new SP and PC
        if (_interruptEnabled)
            interrupt(INTERRUPT_HANDLER_ADDRESS);
        break;
    case 30: // restore registers and set to user mode
        if (_inSystemMode)
            returnFromInterrupt();
        break;
    }
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
	int speed = B115200;
	const char *device = "/dev/ttyUSB0";
	unsigned char x;
	int fd, n;
	unsigned char buf[32768];

	unsigned do_erase = 0;
	unsigned do_write = 0;
	unsigned do_exec = 0;
	unsigned addr = 0;

	if (argc < 2)
		return usage();

	if (!strcmp(argv[1],"erase")) {
		do_erase = 1;
	} else if (!strcmp(argv[1],"flash")) {
		do_erase = 1;
		do_write = 1;
		addr = 0x08000000;
	} else if (!strcmp(argv[1],"exec")) {
		do_write = 1;
		do_exec = 1;
		addr = 0x20001000;
	} else {
		return usage();
	}

	if (do_write && argc != 3)
		return usage();

	fd = openserial(device, speed);
	if (fd < 0) {
		fprintf(stderr, "stderr open '%s'\n", device);
		return -1;
	}

	n = TIOCM_DTR;
	ioctl(fd, TIOCMBIS, &n);
	usleep(2500);
	ioctl(fd, TIOCMBIC, &n);
	usleep(2500);

	/* If the board just powered up, we need to send an ACK
	 * to auto-baud and will get an ACK back.  If the board
	 * is already up, two ACKs will get a NAK (invalid cmd).
	 * Either way, we're talking!
	 */
	for (n = 0; n < 5; n++) {
		unsigned char SYNC = 0x7F;
		if (write(fd, &SYNC, 1)) { /* do nothing */ }
		if (read(fd, &x, 1) != 1)
			continue;
		if ((x == 0x79) || (x == 0x1f))
			break;
	}
	if (n == 5) {
		fprintf(stderr,"sync failure\n");
		return -1;
	}

#if 0
	readMemory(fd, 0x1FFFF000, buf, 4096);
	for (n = 0; n < 1024; n++) 
		fprintf(stderr,"%02x ", buf[n]);
	return 0;
#endif
	if (do_write) {
		int fd2 = open(argv[2], O_RDONLY);
		n = read(fd2, buf, sizeof(buf));
		close(fd2);
		if ((fd2 < 0) || (n <= 0)) {
			fprintf(stderr,"cannot read '%s'\n", argv[2]);
			return -1;
		}
		n += (n % 4);


		if (do_erase) {
			fprintf(stderr,"erasing flash...\n");
			if (eraseFlash(fd)) {
				fprintf(stderr,"erase failed\n");
				return -1;
			}
		}

		fprintf(stderr,"sending %d bytes...\n", n);
		if (writeMemory(fd, addr, buf, n)) {
			fprintf(stderr,"write failed\n");
			return -1;
		}
		fprintf(stderr,"done\n");

		if (do_exec) {
			jumpToAddress(fd, addr);
		} else {
			return 0;
		}
	} else if (do_erase) {
		if (eraseFlash(fd)) {
			fprintf(stderr,"erase failed\n");
			return -1;
		}
		fprintf(stderr,"flash erased\n");
		return 0;
	}
	
	for (;;) {
		if (read(fd, &x, 1) == 1) {
			if (x == 27) break;
			if ((x < 0x20) || (x > 0x7f))
				if ((x != 10) && (x != 13))
					x = '.';
			fprintf(stderr,"%c", x);
		}
	}
	
	return 0;
}
Exemplo n.º 5
0
void Cpu::callAddress() {
    const int address = fetchInstruction();
    push(_pc);
    jumpToAddress(address);
}