예제 #1
0
파일: mm.c 프로젝트: domoritz/nupkux
static void *heap_realloc(void *ptr, UINT size, heap *aheap)
{
	mm_header *header, *tmpheader;
	mm_footer *footer, *tmpfooter;

	if ((!ptr) || (!aheap)) return 0;
	if (!size) {
		heap_free(ptr, aheap);
		return 0;
	}
	header = (mm_header*) ((UINT)ptr - sizeof(mm_header));
	footer = (mm_footer*) ((UINT)header + header->size - sizeof(mm_footer));
	if ((header->magic != MM_MAGIC) || (footer->magic != MM_MAGIC)) return 0;
	if (size == header->size - sizeof(mm_header) - sizeof(mm_footer)) return ptr;
	else if (size < header->size - sizeof(mm_header) - sizeof(mm_footer)) {
		if (header->size - size - 2 * (sizeof(mm_header) - sizeof(mm_footer)) < 0) return ptr;
		tmpheader = (mm_header*) ((UINT)ptr + size + sizeof(mm_footer));
		tmpfooter = (mm_footer*) ((UINT)ptr + size);
		footer->header = tmpheader;
		tmpfooter->header = header;
		tmpheader->magic = tmpfooter->magic = MM_MAGIC;
		tmpheader->flag = MM_FLAG_BLOCK;
		tmpheader->size = (UINT)footer - (UINT)tmpheader + sizeof(mm_footer);
		header->size = sizeof(mm_header) + size + sizeof(mm_footer);
		heap_free((void *)((UINT)tmpheader + sizeof(mm_header)), aheap);
		return ptr;
	} else {
		void *res = heap_malloc(size, 0, aheap);

		if (!res) return 0;
		memcpy(res, ptr, size);
		heap_free(ptr, aheap);
		return res;
	}
}
예제 #2
0
파일: heap.c 프로젝트: mtarek/BeRTOS
void *heap_calloc(struct Heap* h, size_t size)
{
    void *mem;

    if ((mem = heap_malloc(h, size)))
        memset(mem, 0, size);

    return mem;
}
예제 #3
0
파일: table.c 프로젝트: def44/mate
struct table_entry * table_entry_create(int k, int v, int h) {
	struct table_entry *r;

	if ((r = (struct table_entry *)heap_malloc(heap, sizeof(struct table_entry))) == NULL)
		mvm_halt();

	r->key = k;
	r->value = v;
	r->hash = h;

	return r;
}
예제 #4
0
void stack_name_add(names_stack *stack, const char *name)
{
	names_list *names_lists;
	const char **old_names;
	const char **names;
	char *new_buffer;
	unsigned int size;
	unsigned int i;

	names_lists = stack->names_lists[stack->names_lists_c - 1];
	old_names = names_lists->names;

	size = sizeof(const char *) * (names_lists->names_c + 1);
	names = (const char **)heap_malloc(size);
	if (!names) {
		err_msg("malloc char**\n");
		die();
	}

	for (i = 0; i < names_lists->names_c; i++) {
		names[i] = old_names[i];
	}
	if (old_names) {
		heap_free(old_names);
	}

	size = sizeof(char) * str_nlen(name, 100) + 1;
	new_buffer = (char *)heap_malloc(size);
	if (!new_buffer) {
		err_msg("malloc char*\n");
		die();
	}

	names[names_lists->names_c] = new_buffer;
	str_ncpy(new_buffer, name, size);

	names_lists->names = names;
	names_lists->names_c++;
}
예제 #5
0
파일: table.c 프로젝트: def44/mate
struct table * table_create(int c, struct object *o) {
	struct table *t;

	if ((t = (struct table *)heap_malloc(heap, sizeof(struct table))) == NULL)
		mvm_halt();

	t->object = o;

	t->num_entries = 0;
	t->current_capacity = c;
	t->load_factor = TABLE_DEFAULT_LOAD_FACTOR;

	t->iterator_is_running = 0;
	t->iterator_bucket = 0;
	t->iterator_entry = NULL;

	if ((t->buckets = (struct table_entry **)heap_malloc(heap, sizeof(struct table_entry *)*c)) == NULL)
		mvm_halt();

	memset(t->buckets, 0, sizeof(struct table_entry *)*c);

#ifdef TABLE_USE_RWLOCK
	if (pthread_rwlock_init(&t->rwlock, NULL) != 0) {
		perror("mvm: pthread_rwlock_init");
		mvm_halt();
	}
#endif

#ifdef DMP
	if (dmp == NULL)
		t->dmp = NULL;
	else
		t->dmp = dmp_create_table_dmp(dmp, t, object_get_dmp(o));
#endif

	return t;
}
예제 #6
0
names_stack *stack_new(void)
{
	unsigned int size;
	names_stack *stack;

	size = sizeof(names_stack);
	stack = (names_stack *)heap_malloc(size);
	if (!stack) {
		err_msg("malloc names_stack\n");
		die();
	}
	stack->names_lists = 0;
	stack->names_lists_c = 0;

	return stack;
}
예제 #7
0
파일: mm.c 프로젝트: domoritz/nupkux
static UINT _kmalloc_base(UINT sz, UINT *phys, UCHAR align)
{
	UINT res;

	if (kheap) {
		res = (UINT)heap_malloc(sz, align, kheap);
		if (phys) {
			page *apage = get_page(res, 0, kernel_directory);
			*phys = (apage->frame * FRAME_SIZE) + (res & 0xFFF);
		}
	} else {
		if (align) ASSERT_ALIGN(kmalloc_pos);
		if (phys) *phys = kmalloc_pos;
		res = kmalloc_pos;
		kmalloc_pos += sz;
	}
	return res;
}
예제 #8
0
파일: thread.c 프로젝트: def44/mate
struct thread * thread_create() {
	struct thread *t;

	pthread_once(&key_once, thread_make_key);

	if ((t = (struct thread *)heap_malloc(heap, sizeof(struct thread))) == NULL)
		mvm_halt();

	t->ref = 0;
	t->state = new_state;
	t->pc = 0;

	if ((t->ref_buckets = (struct heap_ref *)
	     calloc(HEAP_NUM_BUCKETS, sizeof(struct heap_ref))) == NULL) {
		perror("mvm: malloc");
		mvm_halt();
	}

	if ((t->free_buckets = (struct free_bucket *)
	     calloc(THREAD_NUM_FREE_BUCKETS, sizeof(struct free_bucket))) == NULL) {
		perror("mvm: malloc");
		mvm_halt();
	}

	if ((t->vm_stack = vm_stack_create()) == NULL)
		mvm_halt();

	if ((t->excluded_set = ref_set_create(0)) == NULL)
		mvm_halt();

#ifdef DMP	
	if (dmp == NULL)
		t->dmp = NULL;
	else
		t->dmp = dmp_create_thread_dmp(dmp, t);
#endif

	return t;
}
예제 #9
0
void *vmm_dma_malloc(virtual_size_t size)
{
	return heap_malloc(&dma_heap, size);
}
예제 #10
0
void *vmm_malloc(virtual_size_t size)
{
	return heap_malloc(&normal_heap, size);
}
void main ( void )
{
	ADI_ETHER_HANDLE   hEthernet;
	ADI_ETHER_RESULT   etherResult;
	ADI_ETHER_DEV_INIT EtherInitData[MAX_NETWORK_IF] = { { true, &memtable[0] }, { true, &memtable[1] }}; // data-cache,driver memory
	uint32_t reg_data;
	int i, nEtherDevUsed;
	char *ether_stack_block;

	ADI_GPIO_RESULT gpio_result;
	uint32_t gpioMaxCallbacks;
	int nRet;


	/**
	 * Initialize managed drivers and/or services that have been added to
	 * the project.
	 * @return zero on success
	 */
	adi_initComponents();
	
	/**
	 * The default startup code does not include any functionality to allow
	 * core 0 to enable core 1. A convenient way to enable core 1 is to use the
	 * 'adi_core_1_enable' function.
	 */
	adi_core_1_enable();
	
	/* Begin adding your custom code here */
	g_AuxiTMIsFirstUpdated = 1;
	
	/* init CGU first time */
	CGU_Init ( MULTIPLIER_SEL, CCLK_SEL, DDRCLK_SEL );				/* CCLK=16.384*iMultiplier /1 Mhz, 16.384*iMultiplier/iDDCLKSel Mhz DDR2 CLK */
	
#if defined(__DEBUG_FILE__)
    /* open the debug file */
    pDebugFile = fopen(__DEBUG_FILE_NAME__, "w");
    if (pDebugFile == 0)
    {
    	fclose(pDebugFile);
    	return;
    }
#elif defined(__DEBUG_UART__)
    Init_UART();
#endif

    Init_PTPAuxin();

	/* configures the switches */
#if BF609_EZ_BRD
	
	DEBUG_STATEMENT ( "Configuring switches for the ethernet operation \n\n" );
	ConfigSoftSwitches();
	
#endif
	
	/* open ethernet device */
	nEtherDevUsed = ( user_net_num_ifces > MAX_NETWORK_IF ) ? MAX_NETWORK_IF : user_net_num_ifces;

#if BF609_EZ_BRD
	nEtherDevUsed = 1;
#endif

	DEBUG_STATEMENT ( " init EMAC\n\n" );

	for ( i = 0; i < nEtherDevUsed; i++ )
	{
		etherResult = adi_ether_Open ( g_pDevEntry[i], &EtherInitData[i], g_pEthCallBack[i], &hEthernet );
		if ( etherResult != ADI_ETHER_RESULT_SUCCESS )
		{
			DEBUG_STATEMENT ( "adi_ether_Open: failed to open ethernet driver\n\n" );
			return ;
		}
		
		g_hDev[i] = hEthernet;
		
		/* get the mac address */
		memcpy ( ( ( ADI_EMAC_DEVICE * ) hEthernet )->MacAddress, user_net_config_info[i].hwaddr, 6 );

		/* allocate memory  */
		ether_stack_block = heap_malloc ( i+1, g_contEthHeapSize[i] );
		if ( ether_stack_block == NULL )
		{
			DEBUG_PRINT ( " heap_malloc: in heap %d, failed to allocate memory to the stack \n\n" , i+1);
			return ;
		}
		
		/* init buf mem */
		nRet = InitBuff ( g_contEthHeapSize[i],
				ether_stack_block, hEthernet,
				&user_net_config_info[i] );
		if( nRet<0 )
		{
			DEBUG_STATEMENT ( " InitBuff: failed to enable Init Buffs\n\n" );
			return ;
		}

		/* Enable the MAC */
		etherResult = adi_ether_EnableMAC ( hEthernet );
		if ( etherResult != ADI_ETHER_RESULT_SUCCESS )
		{
			DEBUG_STATEMENT ( " adi_ether_EnableMAC: failed to enable EMAC\n\n" );
			return ;
		}
	}
	
	//enable EMAC INT
	adi_int_EnableInt ( ( (ADI_EMAC_DEVICE *)g_hDev[0])->Interrupt, true);
	adi_int_EnableInt ( ( (ADI_EMAC_DEVICE *)g_hDev[1])->Interrupt, true);

	/* activate rx channel DMA */
	enable_rx ( g_hDev[0] );
	enable_rx ( g_hDev[1] );
	/* activate tx channel DMA */
	enable_tx ( g_hDev[0] );
	enable_tx ( g_hDev[1] );

	//enable emac0 tx,rx
	enable_emac_tx_rx (  g_hDev[0] );

	//enable emac1 tx,rx
	enable_emac_tx_rx (  g_hDev[1] );

	//enable
	Enable_Time_Stamp_Auxin_Interrupt();

	//
	HandleLoop();

	return ;

}//main
예제 #12
0
파일: mm.c 프로젝트: domoritz/nupkux
void *malloc(UINT size)
{
	if (!kheap) return (void *)_kmalloc(size);
	else return heap_malloc(size, 0, kheap);
}
예제 #13
0
파일: mm.c 프로젝트: domoritz/nupkux
static void *heap_malloc(UINT size, UCHAR page_align, heap *aheap)
{
	UINT newsize = size + sizeof(mm_header) + sizeof(mm_footer);
	UINT hole_pos = find_smallest_hole(newsize, page_align, aheap), oldsize, oldpos, newpos, oldend;
	mm_header *header, *newheader;
	mm_footer *newfooter;

	if ((!size) || (!aheap)) return 0;
	if (hole_pos == MM_NO_HOLE) {
		oldsize = aheap->end - aheap->start;
		oldend = aheap->end;
		expand_heap(oldsize + newsize, aheap);
		newsize = aheap->end - aheap->start;
		UINT idx = MM_NO_HOLE;
		UINT value = 0;
		for (hole_pos = 0; hole_pos < aheap->entrycount; hole_pos++) {
			UINT tmp = (UINT) aheap->entries[hole_pos];
			if (tmp > value) {
				value = tmp;
				idx = hole_pos;
			}
		}
		if (idx == MM_NO_HOLE) {
			header = (mm_header *)oldend;
			header->size = newsize - oldsize;
			header->flag = MM_FLAG_HOLE;
			newfooter = (mm_footer *) (oldend + header->size - sizeof(mm_footer));
			header->magic = newfooter->magic = MM_MAGIC;
			newfooter->header = header;
			heap_add_entry(header, aheap);
		} else  {
			header = aheap->entries[idx];
			header->size += newsize - oldsize;
			newfooter = (mm_footer *) ((UINT)header + header->size - sizeof(mm_footer));
			newfooter->header = header;
			newfooter->magic = MM_MAGIC;
		}
		return heap_malloc(size, page_align, aheap);
	}
	header = aheap->entries[hole_pos];
	if (header->size - sizeof(mm_header) - sizeof(mm_footer) < newsize) {
		size += header->size - newsize;
		newsize = header->size;
	}
	oldpos = (UINT)header;
	oldsize = header->size;
	if (page_align && (oldpos & 0xFFFFF000)) {
		newpos = oldpos + FRAME_SIZE - (oldpos & 0xFFF) - sizeof(mm_header);
		newheader = (mm_header *) oldpos;
		newfooter = (mm_footer *) ((UINT)newpos - sizeof(mm_footer));
		newheader->size = newpos - oldpos;
		newheader->flag = MM_FLAG_HOLE;
		newheader->magic = newfooter->magic = MM_MAGIC;
		newfooter->header = newheader;
		oldpos = newpos;
		oldsize = oldsize - newheader->size;
	} else  {
		heap_del_entry(hole_pos, aheap);
	}
	header = (mm_header *) oldpos;
	newfooter = (mm_footer *) (oldpos + sizeof(mm_header) + size);
	header->flag = MM_FLAG_BLOCK;
	header->size = newsize;
	header->magic = newfooter->magic = MM_MAGIC;
	newfooter->header = header;
	if (oldsize - newsize > 0) {
		newheader = (mm_header *) (oldpos + newsize);
		newheader->magic = MM_MAGIC;
		newheader->flag = MM_FLAG_HOLE;
		newheader->size = oldsize - newsize;
		newfooter = (mm_footer *) ((UINT)newheader + newheader->size - sizeof(mm_footer));
		if ((UINT)newfooter < aheap->end)  {
			newfooter->magic = MM_MAGIC;
			newfooter->header = newheader;
		}
		heap_add_entry(newheader, aheap);
	}
	return (void *) ((UINT)header + sizeof(mm_header));
}
예제 #14
0
void stack_enter_or_leave(names_stack *stack, unsigned int enter)
{
	names_list **names_lists;
	names_list **old_names_lists;
	names_list *new_names_list;
	names_list *old_names_list;
	unsigned int old_names_lists_c;
	unsigned int new_names_lists_c;
	unsigned int size;
	unsigned int i;

	old_names_lists = stack->names_lists;
	old_names_lists_c = stack->names_lists_c;
	new_names_lists_c = old_names_lists_c;
	if (enter) {
		new_names_lists_c += 1;
	} else {
		if (old_names_lists_c) {
			new_names_lists_c -= 1;
		} else {
			new_names_lists_c = 0;
		}
	}

	size = sizeof(names_list *) * new_names_lists_c;
	if (size > 0) {
		names_lists = (names_list **) heap_malloc(size);
		if (!names_lists) {
			err_msg("malloc names_list array\n");
			die();
		}
	}

	for (i = 0; i < old_names_lists_c && i < new_names_lists_c; i++) {
		names_lists[i] = old_names_lists[i];
	}

	if (enter == 0 && old_names_lists_c != 0) {
		old_names_list = old_names_lists[old_names_lists_c - 1];
		for (i = 0; i < old_names_list->names_c; i++) {
			heap_free((void *)old_names_list->names[i]);
		}
		heap_free((void *)old_names_list->names);
		heap_free((void *)old_names_list);
	}
	if (old_names_lists) {
		heap_free(old_names_lists);
	}

	stack->names_lists = names_lists;
	stack->names_lists_c = new_names_lists_c;

	if (enter) {
		size = sizeof(names_list);
		new_names_list = (names_list *) heap_malloc(size);
		if (!new_names_list) {
			err_msg("malloc names_list\n");
			die();
		}
		new_names_list->names = 0;
		new_names_list->names_c = 0;

		names_lists[new_names_lists_c - 1] = new_names_list;
	}
}