Beispiel #1
0
void scheduleVM(struct guestVM_s *guest)
{
	printh("Scheduling vm %d %d ", allocatedVMs, guest);
	virtualMachines[allocatedVMs] = guest;
	printh("%d\r\n", virtualMachines[allocatedVMs]);
	allocatedVMs++;
}
Beispiel #2
0
/* Level 1 Block, 1GB, entry in LPAE Descriptor format for the given physical address */
lpaed_t hvmm_mm_lpaed_l1_block( uint64_t pa, uint8_t attr_idx )
{
    /* lpae.c */
	lpaed_t lpaed;

	printh( "[mm] hvmm_mm_lpaed_l1_block:\n\r" );
	printh( " pa:"); uart_print_hex64(pa); printh("\n\r");
	printh( " attr_idx:"); uart_print_hex32((uint32_t) attr_idx); printh("\n\r");

	// Valid Block Entry
	lpaed.pt.valid = 1;
	lpaed.pt.table = 0;

	lpaed.bits &= ~TTBL_L1_OUTADDR_MASK;
	lpaed.bits |= pa & TTBL_L1_OUTADDR_MASK;
	lpaed.pt.sbz = 0;

	// Lower block attributes
	lpaed.pt.ai = attr_idx;
	lpaed.pt.ns = 1;	// Allow Non-secure access
	lpaed.pt.user = 1;
	lpaed.pt.ro = 0;
	lpaed.pt.sh = 2;	// Outher Shareable
	lpaed.pt.af = 1;	// Access Flag set to 1?
	lpaed.pt.ng = 1;

	// Upper block attributes
	lpaed.pt.hint = 0;
	lpaed.pt.pxn = 0;
	lpaed.pt.xn = 0;	// eXecute Never = 0
	return lpaed;
}
Beispiel #3
0
int test_enc_dec(int iface1, int iface2)
{
	unsigned long err;
	unsigned char pt[48] = "the quick brown fox jumps over a lazy dog";
	unsigned char key[16] = {0x0f,0x65,0xd1,0x3a,0xfe,0xcb,0xc4,0xb9,
				0x52,0xb1,0x60,0xcf,0xe8,0x55,0x6a,0xdd};
	unsigned char ct[64];
	unsigned char re[48];

	printf("%d -> %d\n", iface1, iface2);
	printh(pt);
	printh(key);
	if (select_crypto_if(iface1)) return 1;
	memset(ct, 0xfe, sizeof(ct));
	if ((err = encrypt(key, sizeof(key), pt, ct, sizeof(pt)))) {
		printf("encrypt error: %s\n", crypto_errstr(err));
		return 1;
	}
	printh(ct);
	if (select_crypto_if(iface2)) return 1;
	memset(re, 0xab, sizeof(re));
	if ((err = decrypt(key, sizeof(key), ct, re, sizeof(re)))) {
		printf("decrypt error: %s\n", crypto_errstr(err));
		return 1;
	}
	printh(re);
	if (memcmp(pt, re, sizeof(pt))) {
		printf("fail\n");
		return 1;
	}
	return 0;
}
Beispiel #4
0
void virqmap_vgicd_changed_istatus_callback_handler( vmid_t vmid, uint32_t istatus, uint8_t word_offset )
{
    uint32_t cstatus;                          // changed bits only
    uint32_t minirq;
    int bit;

    minirq = word_offset * 32;                 /* irq range: 0~31 + word_offset * size_of_istatus_in_bits */
    cstatus = old_vgicd_status[vmid][word_offset] ^ istatus;   // find changed bits

    while(cstatus) {
        uint32_t virq;
        uint32_t pirq;
        bit = firstbit32(cstatus);

        virq = minirq + bit;
        pirq = virqmap_pirq(vmid, virq);

        if ( pirq != PIRQ_INVALID ) {
            /* changed bit */
            if ( istatus & (1 << bit) ) {
                printh("[%s : %d] enabled irq num is %d\n", __FUNCTION__, __LINE__, bit + minirq);
                gic_test_configure_irq(pirq, GIC_INT_POLARITY_LEVEL, gic_cpumask_current(), GIC_INT_PRIORITY_DEFAULT );
            } else {
                printh("[%s : %d] disabled irq num is %d\n",__FUNCTION__, __LINE__, bit + minirq);
                gic_disable_irq(pirq);
            }
        } else {
            printh( "WARNING: Ignoring virq %d for guest %d has no mapped pirq\n", virq, vmid );
        }
        cstatus &= ~(1<< bit);
    }
    old_vgicd_status[vmid][word_offset] = istatus;
}
Beispiel #5
0
hvmm_status_t vdev_reg_device(vdev_info_t *new_vdev)
{
    hvmm_status_t result = HVMM_STATUS_BUSY;
    int i = 0;

    HVMM_TRACE_ENTER();
    for (i = 0; i < MAX_VDEV; i++) {
        if (vdev_list[i].handler == 0x0 ) {
            vdev_list[i].name = new_vdev->name;
            vdev_list[i].base = new_vdev->base;
            vdev_list[i].size = new_vdev->size;
            vdev_list[i].handler = new_vdev->handler;
            printh("vdev:Registered vdev '%s' at index %d\n", vdev_list[i].name, i);

            result = HVMM_STATUS_SUCCESS;
            break;
        }
    }

    if ( result != HVMM_STATUS_SUCCESS ) {
        printh("vdev:Failed registering vdev '%s', max %d full \n", new_vdev->name, MAX_VDEV);
    }

    HVMM_TRACE_EXIT();
    return result;
}
/**
* print_error - This function prints an error message to the user
* @addr - where data failed
* @access - BYTE,HWORD or WORD
* @data - the current read
* @expected - expected data
*/
void print_error(uint32_t addr, enum access_type access,
		uint32_t data, uint32_t expected)
{
	int bit, byte;
	if (bit_byte_check) {
		for (bit = 0; bit < 32; bit++) {
			if ((data & (1 << bit)) != (expected & (1 << bit)))
				bit_err_sta[bit % 32]++;
		}
		for (byte = 0; byte < 4; byte++) {
			if ((data & (0xFF << (byte * 8))) !=
					(expected & (0xFF << (byte * 8))))
				byte_err_sta[byte % 4]++;
		}
	}
	if (logout_mode == FULL_MODE) {
		printf("\nERROR: Expecting ");
		switch (access) {
		case ACCESS_TYPE_BYTE:
			printb((uint8_t)expected & 0xFF);
			break;
		case ACCESS_TYPE_HWORD:
			printh((uint16_t)expected & 0xFFFF);
			break;
		case ACCESS_TYPE_WORD:
			printw(expected);
			break;
		default:
			break;
		}
		printf(" at address ");
		printw(addr);
		printf(". Actual = ");
		switch (access) {
		case ACCESS_TYPE_BYTE:
			printb((uint8_t)data & 0xFF);
			break;
		case ACCESS_TYPE_HWORD:
			printh((uint16_t)data & 0xFFFF);
			break;
		case ACCESS_TYPE_WORD:
			printw(data);
			break;
		default:
			break;
		}
		printf("\n");
	}
}
Beispiel #7
0
int
check_option (int argc, char *argv[])
{
    int n = 0, ind = 0;
    const char optstr[] = "+:hv";
    struct option lopt[] = \
    {
        { "help", no_argument, NULL, 'h' },
        { "version", no_argument, NULL, 'v' },
        { 0, 0, 0, 0 }
    };

    opterr = optind = 0;
    while ((n = getopt_long (argc, argv, optstr, lopt, &ind)) != -1)
    {
        switch (n)
        {
        case 'h':
            printh ();
            exit (0);

        case 'v':
            printf ("%s is part of djbdns version %s\n", prog, VERSION);
            exit (0);

        default:
            errx (-1, "unknown option `%c', see: --help", optopt);
        }
    }

    return optind;
}
Beispiel #8
0
int
check_option (int argc, char *argv[])
{
    int n = 0, ind = 0;
    const char optstr[] = "+:c:d:Dl:p:P:hv";
    struct option lopt[] = \
    {
        { "help", no_argument, NULL, 'h' },
        { "version", no_argument, NULL, 'v' },
        { 0, 0, 0, 0 }
    };

    opterr = optind = mode = 0;
    while ((n = getopt_long (argc, argv, optstr, lopt, &ind)) != -1)
    {
        switch (n)
        {
        case 'c':
            cfgfile = strdup (optarg);
            break;

        case 'd':
            mode |= DEBUG;
            debug_level = atoi (optarg);
            break;

        case 'D':
            mode |= DAEMON;
            break;

        case 'l':
            logfile = strdup (optarg);
            break;

        case 'p':
            pidfile = strdup (optarg);
            break;

        case 'P':
            server_port = atoi (optarg);
            break;

        case 'h':
            printh ();
            exit (0);

        case 'v':
            printf ("%s version %s\n", prog, VERSION);
            exit (0);

        case ':':
            errx (-1, "option `%c' takes an argument, see: --help", optopt);

        default:
            errx (-1, "unknown option `%c', see: --help", optopt);
        }
    }

    return optind;
}
Beispiel #9
0
void vtimerHandler(unsigned int hsr, unsigned int hpfar, unsigned int hdfar, 
		struct cpuRegs_s *regs)
{
	unsigned int regInUse;
	unsigned int *ptrToReg = (unsigned int *)hpfar;
	unsigned int iss = (hsr & 0x01FFFFFF);
//	printh("vtimerHandler\r\n");
	if (iss & (1 << 24)) {
		/* valid instruction syndrome */
		regInUse = (iss & (0xF << 16)) >> 16;
		switch (regInUse) {
		default:
			printh("Invalid register\r\n");
			while(1);
			break;
		case 0 ... 12:
			ptrToReg = ((&regs->r0) + regInUse);
			break;
		case 14:
			ptrToReg = &regs->lr_svc;
			break;
		}

		if (iss & (1 << 6)) {
			/* write */
			vtimerHandlerWrite(hdfar, hpfar, ptrToReg);
		} else {
			/* read */
			vtimerHandlerRead(hdfar, hpfar, ptrToReg);
		}
	} else {
Beispiel #10
0
void qmail_button(char *modu, char *command, char *user, char *dom, time_t mytime, char *png)    
{
  printf ("<td align=center>");
  printh ("<a href=\"%s&modu=%C\">", cgiurl(command), modu);
  printf ("<img src=\"%s/%s\" border=0></a>", IMAGEURL, png);
  printf ("</td>\n");
}
Beispiel #11
0
int test_hmac(int iface)
{
	unsigned char hmac1[20];
	unsigned long err;
	int hmaclen;
	unsigned char hpt[28] = "what do ya want for nothing?";
	unsigned char hkey[4] = "Jefe";
	unsigned char hstd[20] = {0xef,0xfc,0xdf,0x6a,0xe5,0xeb,0x2f,0xa2,
		0xd2,0x74,0x16,0xd5,0xf1,0x84,0xdf,0x9c,0x25,0x9a,0x7c,0x79};

	if (select_crypto_if(iface)) return 1;
	memset(hmac1, 0, sizeof(hmac1));
	hmaclen = sizeof(hmac1);
	if ((err = hmac(hkey, sizeof(hkey), hpt, sizeof(hpt),
						hmac1, &hmaclen))) {
		printf("hash error: %s\n", crypto_errstr(err));
		return 1;
	}
	printf("%d: len=%d ", iface, hmaclen);
	printh(hmac1);
	if (memcmp(hmac1, hstd, sizeof(hstd))) {
		printf("fail\n");
		return 1;
	}
	return 0;
}
Beispiel #12
0
void va_arg_test(const char *fmt, ...)
{
	int fails = 0;
        va_list arg;
        va_list tmp;
	printh("Test: va_arg_test ");
        va_start(arg, fmt);

        tmp = arg;
        if (va_arg(arg, int) != 0x0a0a0a0a) {
		fails++;
                print_str("Error with va_arg initial value\r\n");
	}
        if (arg <= tmp) {
		fails++;
                print_str("va_arg does not modify arg correctly\r\n");
	}
        if (va_arg(arg, int) != (int)0xa0a0a0a0) {
		fails++;
                print_str("Error with va_arg sequential value\r\n");
	}

        va_end(arg);
        if (arg != 0x0) {
		fails++;
                print_str("Error with va_end, arg still valid\r\n");
	}
	if (fails > 0)
		print_str(" [FAIL]\r\n");
	else
		print_str(" [PASS]\r\n");
}
Beispiel #13
0
void registerVirtDeviceHandler(unsigned int address, virtDeviceHandler_t handler)
{
	struct virtDeviceTuple_s *tuple = malloc(sizeof(struct virtDeviceTuple_s));
	tuple->address = address;
	tuple->handler = handler;
	orderedListInsertItem(virtDevices, tuple);
	printh("Device handler item %d\r\n", orderedListGetItem(virtDevices, 0));
}
Beispiel #14
0
void init_irqs()
{
	install_hyp_vectors();

	init_gic();

	printh("HCR %d\r\n", getHCR());
	setHCR(0x00000038);
}
Beispiel #15
0
void callVirtDeviceHandler(unsigned int address, struct cpuRegs_s *regs)
{
	struct virtDeviceTuple_s tmp = { .address = address };
	struct virtDeviceTuple_s *handler = orderedListFindItem(virtDevices, &tmp);
	if (handler != NULL)
		handler->handler(regs);
	else {
		printh("No registered handler for %d %d\r\n", address, handler);
		while(1);
	}
}
Beispiel #16
0
void main()
{
		//	freopen("input.txt","r", stdin);
		//	freopen("output.txt","w", stdout);
		struct student *head_m = NULL, *end_m = NULL;
		creat();
		head_m = head;
		end_m = end;
		printh(head_m);
		printf("\n");
		printe(end_m);
		
}
Beispiel #17
0
void callback_timer(void *pdata)
{
    vmid_t vmid;
    HVMM_TRACE_ENTER();
    vmid = context_current_vmid();

    printh( "Injecting IRQ 30 to Guest:%d\n", vmid);
    //vgic_inject_virq_sw( 30, VIRQ_STATE_PENDING, GIC_INT_PRIORITY_DEFAULT, smp_processor_id(), 1);
    /* SW VIRQ, No PIRQ */

    if ( _timer_status[vmid] == 0 )
        virq_inject(vmid, 30, 0, 0);
    HVMM_TRACE_EXIT();
}
Beispiel #18
0
hvmm_status_t vdev_emulate(uint32_t fipa, uint32_t wnr, vdev_access_size_t access_size, uint32_t srt, struct arch_regs *regs) 
{
    hvmm_status_t result = HVMM_STATUS_NOT_FOUND;
    int i = 0;
    uint32_t offset;
    uint8_t isize = 4;

    HVMM_TRACE_ENTER();
    if ( regs->cpsr & 0x20 ) {
        /* Thumb */
        isize = 2;
    }

    for (i = 0; i < MAX_VDEV; i++){
        if ( vdev_list[i].base == 0 ) break;

        offset = fipa - vdev_list[i].base;
        if ( fipa >= vdev_list[i].base && offset < vdev_list[i].size && vdev_list[i].handler != 0) {
            /* fipa is in the rage: base ~ base + size */
            printh("vdev: found %s for fipa %x srt:%x gpr[srt]:%x write:%d vmid:%d\n", vdev_list[i].name, fipa, srt, regs->gpr[srt], wnr, context_current_vmid() );
            result = vdev_list[i].handler(wnr, offset, &(regs->gpr[srt]), access_size);
            if ( wnr == 0 ) {
                printh("vdev: result:%x\n", regs->gpr[srt] );
            }

            /* Update PC regardless handling result */
            regs->pc += isize;
            break;
        } else {
            printh("vdev: fipa %x base %x not matched\n", fipa, vdev_list[i].base );
        }
    }
    HVMM_TRACE_EXIT();

    return result;
}
Beispiel #19
0
int main(void)
{
	char c;
	int wl;                         /* word length counter */
	int wlen[MAXLEN] = { 0 };       /* word lengths from 1 .. MAXLEN */

	wl = 0;
	/* words' lengths are stored to the wlen array using their length as index */
	while ((c = getchar()) != EOF) {
		/* a word is defined as any group of alphabetic chars */
		if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
			wl++;
		} else if (wl) {
			if (wl < MAXLEN)
				wlen[wl]++;
			wl = 0;
		}
	}
	printh(wlen, MAXLEN);
	return 0;
}
Beispiel #20
0
/* baseAddr is the base address of RAM to be assigned to VM. 
 * Kernel must be placed 32KiB into this section of RAM.  */
struct guestVM_s *createVM(unsigned int baseAddr, unsigned int memorySize)
{
	struct guestVM_s *guest = malloc(sizeof(struct guestVM_s));

	guest->stageOneTable = createPageTable();
	mapMemoryToVM(guest, baseAddr, 0x40000000, memorySize, 0x1FF); /* base memory map */
	mapMemoryToVM(guest, 0x01c28000, 0x01c28000,  0x1000, 0x1B1);   /* UART0 */
	mapMemoryToVM(guest, 0x01c00000, 0x01c00000,  0x1000, 0x1B1);   /* SRAM config regs */
	mapMemoryToVM(guest, 0x01c01000, 0x01c01000,  0x1000, 0x1B1);   /* DRAM config regs */
	mapMemoryToVM(guest, 0x01c02000, 0x01c02000,  0x1000, 0x1B1);   /* DMA config regs */
	mapMemoryToVM(guest, 0x01c0a000, 0x01c0a000,  0x1000, 0x1B1);   /* TVE0 config regs */
	mapMemoryToVM(guest, 0x01c0C000, 0x01c0C000,  0x2000, 0x1B1);   /* LCD config regs */
	mapMemoryToVM(guest, 0x01c0F000, 0x01c0F000,  0x4000, 0x1B1);   /* MMC device regs */
	mapMemoryToVM(guest, 0x01c13000, 0x01c13000,  0x1000, 0x1B1);   /* USB config regs */
	mapMemoryToVM(guest, 0x01c14000, 0x01c14000,  0x1000, 0x1B1);   /* USB config regs */
	mapMemoryToVM(guest, 0x01c16000, 0x01c16000,  0x1000, 0x1B1);   /* USB config regs */
	mapMemoryToVM(guest, 0x01c1B000, 0x01c1B000,  0x1000, 0x1B1);   /* USB config regs */
	mapMemoryToVM(guest, 0x01c1C000, 0x01c1C000,  0x1000, 0x1B1);   /* USB config regs */
	mapMemoryToVM(guest, 0x01c18000, 0x01c18000,  0x1000, 0x1B1);   /* SATA config regs */
	mapMemoryToVM(guest, 0x01c22000, 0x01c22000,  0x1000, 0x1B1);   /* PS2 config regs */
	mapMemoryToVM(guest, 0x01c25000, 0x01c25000,  0x1000, 0x1B1);   /* PS2 config regs */
	mapMemoryToVM(guest, 0x01c2a000, 0x01c2a000,  0x2000, 0x1B1);   /* PS2 config regs */
	mapMemoryToVM(guest, 0x01c2c000, 0x01c2c000,  0x1000, 0x1B1);   /* PS2 config regs */
	mapMemoryToVM(guest, 0x01e00000, 0x01e00000, 0x40000, 0x1B1);   /* DEFE config regs */
	mapMemoryToVM(guest, 0x01e40000, 0x01e40000, 0x40000, 0x1B1);   /* DEBE config regs */
	mapMemoryToVM(guest, (unsigned int)GICV(0), (unsigned int)GICC, 
		0x1000, 0x1B1);   /* VGIC mappings */

	guest->regs.pc = (0x40008000);
	guest->regs.cpsr = 0x00000013;
	guest->regs.r0 = 0;
	guest->regs.r1 = 0x000010bb;
	guest->regs.r2 = 0x40000000;
	guest->regs.r3 = 0;
	guest->vgic.ctlr = 0;

	printh("New Guest Regs:\r\n");
	print_regs(&(guest->regs));
	return guest;
}
Beispiel #21
0
int test_sha(int iface)
{
	unsigned char sha1[20];
	unsigned long err;
	int shalen;
	unsigned char spt[3] = "abc";
	unsigned char sstd[20] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,
		0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};

	if (select_crypto_if(iface)) return 1;
	memset(sha1, 0, sizeof(sha1));
	shalen = sizeof(sha1);
	if ((err = hash(spt, sizeof(spt), sha1, &shalen))) {
		printf("hash error: %s\n", crypto_errstr(err));
		return 1;
	}
	printf("%d: len=%d ", iface, shalen);
	printh(sha1);
	if (memcmp(sha1, sstd, sizeof(sstd))) {
		printf("fail\n");
		return 1;
	}
	return 0;
}
Beispiel #22
0
/* contextual wrapper for mapping memory to a VM guest */
void mapMemoryToVM(struct guestVM_s *guest, unsigned int baseAddr, 
		unsigned int targetAddr, unsigned int size, unsigned int attrs)
{
	printh("Mapping %d to %d (size %d) for VM\r\n", baseAddr, targetAddr, size);
	mapVirtToPhys(guest->stageOneTable, targetAddr, baseAddr, size, attrs);
}
Beispiel #23
0
void test_hypervisor()
{
	printh("\r\n\r\nAuto-testing hypervisor\r\n"); 
	test_va_arg();
	test_malloc();
}
Beispiel #24
0
void test_va_arg() 
{
	printh("test_va_arg\r\n");
	va_arg_test("test format %d %d\r\n", 0x0a0a0a0a, 0xa0a0a0a0);
}