Example #1
0
static void ddr3_write(hwaddr_t addr, void *data, uint8_t *mask) {
	Assert(addr < HW_MEM_SIZE, "physical address %x is outside of the physical memory!", addr);
	dram_addr temp;
	temp.addr = addr & ~BURST_MASK;
	uint32_t rank = temp.rank;
	uint32_t bank = temp.bank;
	uint32_t row = temp.row;
	uint32_t col = temp.col;

	if(!(rowbufs[rank][bank].valid && rowbufs[rank][bank].row_idx == row) ) {
		/* read a row into row buffer */
		memcpy(rowbufs[rank][bank].buf, dram[rank][bank][row], NR_COL);
		rowbufs[rank][bank].row_idx = row;
		rowbufs[rank][bank].valid = true;
	}

	/* burst write */
	memcpy_with_mask(rowbufs[rank][bank].buf + col, data, BURST_LEN, mask);

	/* write back to dram */
	memcpy(dram[rank][bank][row], rowbufs[rank][bank].buf, NR_COL);
}
Example #2
0
void netman_static_line(NetmanIfConfig *config, int lineno, char *line)
{
	char *cmd = strtok(line, SPACES);
	if (cmd == NULL)
	{
		return;
	};
	
	if (strcmp(cmd, "address") == 0)
	{
		_glidix_ifaddr6 addr;

		char *cidr = strtok(NULL, SPACES);
		if (cidr == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected address in CIDR notation, not EOL\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		char *slashpos = strchr(cidr, '/');
		if (slashpos == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected address in CIDR notation, not '%s'\n",
					lineno, cidr);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		*slashpos = 0;
		unsigned int netsize;
		if (sscanf(slashpos+1, "%u", &netsize) != 1)
		{
			fprintf(stderr, "static: if.conf line %d error: invalid subnet size '%s'\n", lineno, slashpos+1);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (!inet_pton(AF_INET6, cidr, &addr.addr))
		{
			fprintf(stderr, "static: if.conf line %d error: invalid address '%s'\n", lineno, cidr);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (netsize > 128)
		{
			fprintf(stderr, "static: if.conf line %d error: maximum subnet size is 128, got %u\n", lineno, netsize);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		writeMask((uint8_t*)&addr.mask, netsize);
		addr.domain = _GLIDIX_DOM_GLOBAL;
		
		char *domname = strtok(NULL, SPACES);
		if (domname != NULL)
		{
			int domain = getDomainByName(domname);
			if (domain == -1)
			{
				fprintf(stderr, "static: if.conf line %d: invalid address domain '%s'\n", lineno, domname);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			addr.domain = domain;
		};
		
		StaticConfig *statconf = (StaticConfig*) config->data;
		statconf->addrs = realloc(statconf->addrs, sizeof(_glidix_ifaddr6)*(statconf->addrcount+1));
		memcpy(&statconf->addrs[statconf->addrcount], &addr, sizeof(_glidix_ifaddr6));
		statconf->addrcount++;
		
		statconf->routes = realloc(statconf->routes, sizeof(_glidix_gen_route)*(statconf->routecount+1));
		memset(&statconf->routes[statconf->routecount], 0, sizeof(_glidix_gen_route));
		_glidix_in6_route *inroute = (_glidix_in6_route*) &statconf->routes[statconf->routecount];
		statconf->routecount++;
		
		strcpy(inroute->ifname, config->ifname);
		memcpy_with_mask(&inroute->dest, &addr.addr, &addr.mask, 16);
		memcpy(&inroute->mask, &addr.mask, 16);
		memset(&inroute->gateway, 0, 16);
		inroute->domain = addr.domain;
		inroute->flags = 0;
	}
	else if (strcmp(cmd, "route") == 0)
	{
		StaticConfig *statconf = (StaticConfig*) config->data;
		
		statconf->routes = realloc(statconf->routes, sizeof(_glidix_gen_route)*(statconf->routecount+1));
		memset(&statconf->routes[statconf->routecount], 0, sizeof(_glidix_gen_route));
		_glidix_in6_route *inroute = (_glidix_in6_route*) &statconf->routes[statconf->routecount];
		statconf->routecount++;
		
		strcpy(inroute->ifname, config->ifname);
		memset(&inroute->gateway, 0, 16);
		inroute->domain = _GLIDIX_DOM_GLOBAL;
		inroute->flags = 0;
		
		char *cidr = strtok(NULL, SPACES);
		if (cidr == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected CIDR route destination, not EOL\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (strcmp(cidr, "default") == 0)
		{
			memset(&inroute->dest, 0, 16);
			memset(&inroute->mask, 0, 16);
		}
		else
		{
			char *slashpos = strchr(cidr, '/');
			if (slashpos == NULL)
			{
				fprintf(stderr, "static: if.conf line %d error: expected prefix in CIDR notation, not '%s'\n",
						lineno, cidr);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			*slashpos = 0;
			unsigned int netsize;
			if (sscanf(slashpos+1, "%u", &netsize) != 1)
			{
				fprintf(stderr, "static: if.conf line %d error: invalid subnet size '%s'\n", lineno, slashpos+1);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			if (!inet_pton(AF_INET6, cidr, &inroute->dest))
			{
				fprintf(stderr, "static: if.conf line %d error: invalid address '%s'\n", lineno, cidr);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			if (netsize > 128)
			{
				fprintf(stderr, "static: if.conf line %d error: maximum subnet size is 128, got %u\n",
					lineno, netsize);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			writeMask((uint8_t*)&inroute->mask, netsize);
		};
		
		char *nextKeyword = strtok(NULL, SPACES);
		if (nextKeyword != NULL)
		{
			if (strcmp(nextKeyword, "via") == 0)
			{
				char *gateway = strtok(NULL, SPACES);
				if (gateway == NULL)
				{
					fprintf(stderr, "static: if.conf line %d error: expected gateway IP after 'via'"
							" keyword\n", lineno);
					config->status = NETMAN_STATUS_ERROR;
					return;
				};
				
				if (!inet_pton(AF_INET6, gateway, &inroute->gateway))
				{
					fprintf(stderr, "static: if.conf line %d error: invalid gateway address '%s'\n",
							lineno, gateway);
					config->status = NETMAN_STATUS_ERROR;
					return;
				};
				
				nextKeyword = strtok(NULL, SPACES);
			};
		};
		
		if (nextKeyword != NULL)
		{
			if (strcmp(nextKeyword, "domain") != 0)
			{
				fprintf(stderr, "static: if.conf line %d error: expected 'via' or 'domain', not '%s'\n",
						lineno, nextKeyword);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			char *domname = strtok(NULL, SPACES);
			if (domname == NULL)
			{
				fprintf(stderr, "static: if.conf line %d error: expected domain name, not EOL\n", lineno);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			int domain = getDomainByName(domname);
			if (domain == -1)
			{
				fprintf(stderr, "static: if.conf line %d error: invalid route domain '%s'\n", lineno, domname);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			inroute->domain = domain;
		};
	}
	else if (strcmp(cmd, "nameserver") == 0)
	{
		StaticConfig *statconf = (StaticConfig*) config->data;
		
		char *nameserver = strtok(NULL, SPACES);
		if (nameserver == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected name server\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		statconf->dns = realloc(statconf->dns, 16*(++statconf->dnscount));
		if (!inet_pton(AF_INET6, nameserver, &statconf->dns[statconf->dnscount-1]))
		{
			fprintf(stderr, "static: if.conf line %d error: invalid name server address '%s'\n", lineno, nameserver);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
	}
	else
	{
		fprintf(stderr, "static: if.conf line %d error: unknown command '%s'\n", lineno, cmd);
		config->status = NETMAN_STATUS_ERROR;
		return;
	};
};