kern

diff src/vm.c @ 45:b8f02479e3f4

mainly additions to the VM to support processes etc. not complete
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 26 Jul 2011 02:41:33 +0300
parents 5f6c5751ae05
children f65b348780e3
line diff
     1.1 --- a/src/vm.c	Mon Jul 25 11:29:57 2011 +0300
     1.2 +++ b/src/vm.c	Tue Jul 26 02:41:33 2011 +0300
     1.3 @@ -250,6 +250,7 @@
     1.4  {
     1.5  	int intr_state, ret = -1;
     1.6  	struct page_range *node, *prev, dummy;
     1.7 +	unsigned int attr = 0;	/* TODO */
     1.8  
     1.9  	intr_state = get_intr_state();
    1.10  	disable_intr();
    1.11 @@ -281,7 +282,60 @@
    1.12  
    1.13  	if(ret >= 0) {
    1.14  		/* allocate physical storage and map */
    1.15 -		if(map_page_range(ret, num, -1, 0) == -1) {
    1.16 +		if(map_page_range(ret, num, -1, attr) == -1) {
    1.17 +			ret = -1;
    1.18 +		}
    1.19 +	}
    1.20 +
    1.21 +	set_intr_state(intr_state);
    1.22 +	return ret;
    1.23 +}
    1.24 +
    1.25 +int pgalloc_vrange(int start, int num)
    1.26 +{
    1.27 +	struct page_range *node, *prev, dummy;
    1.28 +	int area, intr_state, ret = -1;
    1.29 +	unsigned int attr = 0;	/* TODO */
    1.30 +
    1.31 +	area = (start >= ADDR_TO_PAGE(KMEM_START)) ? MEM_KERNEL : MEM_USER;
    1.32 +	if(area == KMEM_USER && start + num > ADDR_TO_PAGE(KMEM_START)) {
    1.33 +		printf("pgalloc_vrange: invalid range request crossing user/kernel split\n");
    1.34 +		return -1;
    1.35 +	}
    1.36 +
    1.37 +	intr_state = get_intr_state();
    1.38 +	disable_intr();
    1.39 +
    1.40 +	dummy.next = pglist[area];
    1.41 +	node = pglist[area];
    1.42 +	prev = &dummy;
    1.43 +
    1.44 +	/* check to see if the requested VM range is available */
    1.45 +	node = pglist[area];
    1.46 +	while(node) {
    1.47 +		if(start >= node->start && start + num <= node->end) {
    1.48 +			ret = node->start;
    1.49 +			node->start += num;
    1.50 +
    1.51 +			if(node->start == node->end) {
    1.52 +				prev->next = node->next;
    1.53 +				node->next = 0;
    1.54 +
    1.55 +				if(node == pglist[area]) {
    1.56 +					pglist[area] = 0;
    1.57 +				}
    1.58 +				free_node(node);
    1.59 +			}
    1.60 +			break;
    1.61 +		}
    1.62 +
    1.63 +		prev = node;
    1.64 +		node = node->next;
    1.65 +	}
    1.66 +
    1.67 +	if(ret >= 0) {
    1.68 +		/* allocate physical storage and map */
    1.69 +		if(map_page_range(ret, num, -1, attr) == -1) {
    1.70  			ret = -1;
    1.71  		}
    1.72  	}