示例#1
0
void test_gc_build_structure(MM *mm, Obj handle_start) {
	Obj handle_prev = handle_start;
	Obj hdl;
	uint64 suma;
	int i;
	for (i = 1; i <= 1000; i++) {
		Obj handle_current = mm_alloc(mm, 2);
		mm_set(handle_current, 0, MK_IMMEDIATE(i));
		mm_set(handle_prev, 1, handle_current);
		handle_prev = handle_current;
	}
	mm_set(handle_prev, 1, MK_IMMEDIATE(9999));

	{
		suma = 0;
		hdl = handle_start;
		while (hdl & OBJ_FLAG_HANDLE) {
			suma += OBJ_HANDLE_TO_PTR(hdl)[0];
			hdl = OBJ_HANDLE_TO_PTR(hdl)[1];
		}
		assert(IMM_VALUE(suma) == 500544);
	}

	hdl = handle_start;
	for (i = 1; i <= 10; i++) {
		hdl = OBJ_HANDLE_TO_PTR(hdl)[1];
	}
	mm_set(handle_prev, 1, OBJ_HANDLE_TO_PTR(hdl)[1]);
	mm_set(hdl, 1, MK_IMMEDIATE(18));
}
示例#2
0
void bd_set_transitions(BDPhyloHmm *bdphmm) {
  int state;
  HMM *hmm = bdphmm->phmm->hmm;
  TreeNode *tree = bdphmm->phmm->mods[0]->tree;

  /* set transition probs based on mu, nu, and phi */
  for (state = 1; state < hmm->nstates; state++) {
    if (state == tree->nnodes)
      mm_set(hmm->transition_matrix, 0, state, bdphmm->nu * (1-bdphmm->phi));
    else 
      mm_set(hmm->transition_matrix, 0, state, bdphmm->nu * bdphmm->phi / 
             (hmm->nstates-2));
    mm_set(hmm->transition_matrix, state, 0, bdphmm->mu);
    mm_set(hmm->transition_matrix, state, state, 1-bdphmm->mu);
  }
  mm_set(hmm->transition_matrix, 0, 0, 1-bdphmm->nu);

  /* begin transitions */
  vec_set(hmm->begin_transitions, 0, 
          bdphmm->mu/(bdphmm->mu + bdphmm->nu));
  for (state = 1; state < hmm->nstates; state++) {
    if (state == tree->nnodes)
      vec_set(hmm->begin_transitions, state, bdphmm->nu * (1-bdphmm->phi)/
              (bdphmm->mu + bdphmm->nu));
    else 
      vec_set(hmm->begin_transitions, state, bdphmm->nu * bdphmm->phi /
              ((bdphmm->mu + bdphmm->nu) * (hmm->nstates-2)));
  }

  hmm_reset(hmm);
}
示例#3
0
// QUESTION: Why are we not calculating the string length automatically?
void ns_wipe(chr_t *s, size_t len) {

#ifdef MAGMA_PEDANTIC
	if (!s) log_pedantic("Attempting to wipe a NULL string pointer.");
#endif

	if (s && len) mm_set(s, 0, len);
}
示例#4
0
/**
 * @brief	Zero out a block of memory.
 * @note Uses the 'optimize (0)' and 'noinline' function attributes to prevent compiler optimization from removing logic it might consider unnecessary.
 * @param	block	the block of memory to be zeroed.
 * @param	len		the number of zero bytes to write to memory.
 * @see	http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Function-Attributes.html
 */
void *mm_wipe(void *block, size_t len) {

#ifdef MAGMA_PEDANTIC
	if (!block) {
		log_pedantic("Attempting to wipe a NULL block pointer.");
	}
#endif

	if (block && len) {
		mm_set(block, 0, len);
	}

	return block;
}
示例#5
0
/**
 *
 * @brief	Allocate a chunk of memory with the system allocator and zero-wipe it.
 * @note	Uses the 'malloc' function attribute to indicate any non-NULL return value is not an alias for any other valid pointer.
 * @note	The buffer length must be non-zero.
 * @see		http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Function-Attributes.html
 * @param	len	the amount of memory to allocate.
 * @return	a valid pointer to the allocated memory on success, or NULL on error.
 */
void *mm_alloc(size_t len) {

	void *result;

	if (!len) {
		log_pedantic("Attempted to allocate a zero length string.");
		return NULL;
	} else if ((result = malloc(len))) {
		mm_set(result, 0, len);
	} else {
		log_pedantic("Unable to allocate a block of %zu bytes.", len);
	}

	return result;
}
示例#6
0
bool_t check_string_print(void) {

	uint64_t total;
	bool_t result = true;
	stringer_t *strings[14];

	mm_set(strings, 0, sizeof(strings));

	strings[0] = st_print(NULLER_T | CONTIGUOUS | HEAP, "%.*s", st_length_int(constant), st_char_get(constant));
	strings[1] = st_print(NULLER_T | JOINTED | HEAP, "%.*s", st_length_int(strings[0]), st_char_get(strings[0]));
	strings[2] = st_print(BLOCK_T | CONTIGUOUS | HEAP, "%.*s", st_length_int(strings[1]), st_char_get(strings[1]));
	strings[3] = st_print(BLOCK_T | JOINTED | HEAP, "%.*s", st_length_int(strings[2]), st_char_get(strings[2]));
	strings[4] = st_print(MANAGED_T | CONTIGUOUS | HEAP, "%.*s", st_length_int(strings[3]), st_char_get(strings[3]));
	strings[5] = st_print(MANAGED_T | JOINTED | HEAP, "%.*s", st_length_int(strings[4]), st_char_get(strings[4]));
	strings[6] = st_print(MAPPED_T | JOINTED | HEAP, "%.*s", st_length_int(strings[5]), st_char_get(strings[5]));

	strings[7] = st_print(NULLER_T | CONTIGUOUS | SECURE, "%.*s", st_length_int(strings[6]), st_char_get(strings[6]));
	strings[8] = st_print(NULLER_T | JOINTED | SECURE, "%.*s", st_length_int(strings[7]), st_char_get(strings[7]));
	strings[9] = st_print(BLOCK_T | CONTIGUOUS | SECURE, "%.*s", st_length_int(strings[8]), st_char_get(strings[8]));
	strings[10] = st_print(BLOCK_T | JOINTED | SECURE, "%.*s", st_length_int(strings[9]), st_char_get(strings[9]));
	strings[11] = st_print(MANAGED_T | CONTIGUOUS | SECURE, "%.*s", st_length_int(strings[10]), st_char_get(strings[10]));
	strings[12] = st_print(MANAGED_T | JOINTED | SECURE, "%.*s", st_length_int(strings[11]), st_char_get(strings[11]));
	strings[13] = st_print(MAPPED_T | JOINTED | SECURE, "%.*s", st_length_int(strings[12]), st_char_get(strings[12]));

	for (int i = 0; i < 14 && strings[i]; i++) {
		for (unsigned int j = total = 0; strings[i] && j < st_length_get(strings[i]); j++) {
			total += *(st_char_get(strings[i]) + j);
		}

		if (total != 5366) {
			result = false;
		}
	}

	log_print("%28.28s = %s", "print", result ? "passed" : "failed");

	for (int i = 0; i < 14; i++) {
		if (strings[i])
			st_free(strings[i]);
	}

	return result;

}
示例#7
0
void test_gc(void) {
	printf("-- test mm_gc\n");

	MM _mm;
	MM *mm = &_mm;
	mm_init(mm, mm_stack_pointer_orig());

	Obj handle_start = mm_alloc(mm, 2);
	mm_set(handle_start, 0, MK_IMMEDIATE(44));

	test_gc_build_structure(mm, handle_start);

	mm_gc(mm);

	{
		uint64 suma = 0;
		Obj hdl = handle_start;
		while (hdl & OBJ_FLAG_HANDLE) {
			suma += OBJ_HANDLE_TO_PTR(hdl)[0];
			hdl = OBJ_HANDLE_TO_PTR(hdl)[1];
		}
		assert(IMM_VALUE(suma) == 99);
	}

	test_gc_build_structure(mm, handle_start);
	mm_gc(mm);

	{
		uint64 suma = 0;
		Obj hdl = handle_start;
		while (hdl & OBJ_FLAG_HANDLE) {
			suma += OBJ_HANDLE_TO_PTR(hdl)[0];
			hdl = OBJ_HANDLE_TO_PTR(hdl)[1];
		}
		assert(IMM_VALUE(suma) == 99);
	}

	mm_free_blocks(mm);
}
示例#8
0
文件: main.c 项目: gautamkmr/SBUnix
void start(uint32_t* modulep, void* physbase, void* physfree)
{       
  int i;
    struct smap_t {
                uint64_t base, length;
                uint32_t type;
        }__attribute__((packed)) *smap;
      
  
        // initially Mark all pages used  
        mm_set(freePage,MEM_SIZE); 
 
        while(modulep[0] != 0x9001) modulep += modulep[1]+2;
        for(smap = (struct smap_t*)(modulep+2); smap < (struct smap_t*)((char*)modulep+modulep[1]+2*4); ++smap) {
            if (smap->type == 1 /* memory */ && smap->length != 0) {
                        // Mark the memory available in the free list 
                        pmmngr_init_region(smap->base, smap->length);      
                  }
        }

      /* we need to mark the kernel memory as used kernel starts from 200000 and end at 220000 */ 
      /* so we will mark the memory till 400000 as used however we can keep it till 220000 as well */ 
      pmmngr_uninit_region((uint64_t)0,(uint64_t)0x400000);  // mark all kernel memory as used 
      
      /* we need to map the kernel memory to the page table */
      
      // initialize the page table
      set_page_table(&Page_Table);

     uint64_t *addr = (uint64_t*)physbase; 
    /* we need to map the kernel memory to the page table */ 
    for(addr = (uint64_t*)physbase; addr<=(uint64_t*)physfree; addr++)  
      {
       vmmngr_map_page(addr,(uint64_t *)((uint64_t)addr + KERNEL_VIRTUAL_BASE),&Page_Table);            
      }
   
 
      /* Map the Video memory This will map to single page 80*25*2 < 1 page */
      vmmngr_map_page((uint64_t *)0xb8000,(uint64_t*)VIDEO_VIRTUAL_MEMORY,&Page_Table);  
    //  printf("Video Memory has been marked in virtual address space\n"); 

      /* pass the pml4e value to cr3 register */
      kernel_pml4e = (uint64_t *)ALIGN_DOWN((uint64_t)Page_Table.root);
      write_cr3(&Page_Table);
      init_video();

/********************************* KERNEL CREATION ********************************/
 struct task_struct *pcb0 = (struct task_struct *)kmalloc(sizeof(struct task_struct));  //kernel 
 pcb0->pml4e =(uint64_t)kernel_pml4e;  // kernel's page table   
 pcb0->pid = 0;  // I'm kernel init process  so pid 0  
 pcb0->iswait = 0; //not waiting for any one
 pcb0->stack =(uint64_t *)stack; //my stack is already created by prof :)  
 process_count = 0; //at this point we don't have any other process in ready_queue so go ahead and create one and update this 
 sleeping_process_count = 0; // at this point no body is sleeping 
 // initialize processes queue  
 for(i=0;i<100;i++)  {   
  zombie_queue[i] = 0;    // no process is zombie 
 }
 foreground_process = 3; // process with this pid will be foreground process  
 
  // put them in the ready queue
  ready_queue[0] =(uint64_t ) pcb0;  //kernel 

/*
char fname[] = "bin/hello";
malloc_pcb(fname);

char fname1[] = "bin/world";
malloc_pcb(fname1);

char fname2[] = "bin/proc3";
malloc_pcb(fname2);

char fname3[] = "bin/proc4";
malloc_pcb(fname3);    
*/
/*************************************** Please change here fname ******************/
char fname4[] = "bin/printf";
malloc_pcb(fname4); 

  idt_install();
  __asm__("sti");

  //init_context_switch();    
  asm volatile("mov $0x2b,%ax");
  asm volatile("ltr %ax");
  tarfs_init();    
  while(1);      
}
示例#9
0
bool_t check_string_merge(void) {

	uint64_t total;
	bool_t result = true;
	stringer_t *strings[16];

	mm_set(strings, 0, sizeof(strings));

	strings[0] = st_alloc_opts(PLACER_T | JOINTED | HEAP | FOREIGNDATA, 0);
	st_data_set(strings[0], st_data_get(string_check_constant));
	st_length_set(strings[0], st_length_get(string_check_constant));

	strings[1] = st_merge_opts(NULLER_T | CONTIGUOUS | HEAP, "s", strings[0]);
	strings[2] = st_merge_opts(NULLER_T | JOINTED | HEAP, "s", strings[1]);
	strings[3] = st_merge_opts(BLOCK_T | CONTIGUOUS | HEAP, "s", strings[2]);
	strings[4] = st_merge_opts(BLOCK_T | JOINTED | HEAP, "s", strings[3]);
	strings[5] = st_merge_opts(MANAGED_T | CONTIGUOUS | HEAP, "s", strings[4]);
	strings[6] = st_merge_opts(MANAGED_T | JOINTED | HEAP, "s", strings[5]);
	strings[7] = st_merge_opts(MAPPED_T | JOINTED | HEAP, "s", strings[6]);

	strings[8] = st_merge_opts(NULLER_T | CONTIGUOUS | SECURE, "s", strings[7]);
	strings[9] = st_merge_opts(NULLER_T | JOINTED | SECURE, "s", strings[8]);
	strings[10] = st_merge_opts(BLOCK_T | CONTIGUOUS | SECURE, "s", strings[9]);
	strings[11] = st_merge_opts(BLOCK_T | JOINTED | SECURE, "s", strings[10]);
	strings[12] = st_merge_opts(MANAGED_T | CONTIGUOUS | SECURE, "s", strings[11]);
	strings[13] = st_merge_opts(MANAGED_T | JOINTED | SECURE, "s", strings[12]);
	strings[14] = st_merge_opts(MAPPED_T | JOINTED | SECURE, "s", strings[13]);

	for (int i = 0; i < 15 && strings[i]; i++) {
		for (unsigned int j = total = 0; strings[i] && j < st_length_get(strings[i]); j++) {
			total += *(st_char_get(strings[i]) + j);
		}

		if (total != 5366) {
			result = false;
		}
	}

	if (result) {

		strings[15] = st_merge_opts(MANAGED_T | JOINTED | HEAP, "snsnsnsnsnsnsnsnsnsnsnsnsnsnsnsn", string_check_constant, "\n", strings[0], "\n", strings[1], "\n", strings[2], "\n",
				strings[3], "\n", strings[4], "\n", strings[5], "\n", strings[6], "\n", strings[7], "\n", strings[8], "\n", strings[9], "\n", strings[10], "\n", strings[11],
				"\n", strings[12], "\n", strings[13], "\n", strings[14], "\n");

		for (unsigned int i = total = 0; strings[15] && i < st_length_get(strings[15]); i++) {
			total += *(st_char_get(strings[15]) + i);
		}

		if (total != (5376UL * 16)) {
			result = false;
		}

	}

	for (int i = 0; i < 16; i++) {
		st_cleanup(strings[i]);
	}

	return result;

}
示例#10
0
bool_t check_string_merge(void) {

	uint64_t total;
	bool_t result = true;
	stringer_t *strings[16];

	mm_set(strings, 0, sizeof(strings));

	strings[0] = st_alloc(PLACER_T | JOINTED | HEAP, 0);
	st_placer_set(strings[0], st_data_get(constant), st_length_get(constant));

	strings[1] = st_merge(NULLER_T | CONTIGUOUS | HEAP, "s", strings[0]);
	strings[2] = st_merge(NULLER_T | JOINTED | HEAP, "s", strings[1]);
	strings[3] = st_merge(BLOCK_T | CONTIGUOUS | HEAP, "s", strings[2]);
	strings[4] = st_merge(BLOCK_T | JOINTED | HEAP, "s", strings[3]);
	strings[5] = st_merge(MANAGED_T | CONTIGUOUS | HEAP, "s", strings[4]);
	strings[6] = st_merge(MANAGED_T | JOINTED | HEAP, "s", strings[5]);
	strings[7] = st_merge(MAPPED_T | JOINTED | HEAP, "s", strings[6]);

	strings[8] = st_merge(NULLER_T | CONTIGUOUS | SECURE, "s", strings[7]);
	strings[9] = st_merge(NULLER_T | JOINTED | SECURE, "s", strings[8]);
	strings[10] = st_merge(BLOCK_T | CONTIGUOUS | SECURE, "s", strings[9]);
	strings[11] = st_merge(BLOCK_T | JOINTED | SECURE, "s", strings[10]);
	strings[12] = st_merge(MANAGED_T | CONTIGUOUS | SECURE, "s", strings[11]);
	strings[13] = st_merge(MANAGED_T | JOINTED | SECURE, "s", strings[12]);
	strings[14] = st_merge(MAPPED_T | JOINTED | SECURE, "s", strings[13]);

	for (int i = 0; i < 15 && strings[i]; i++) {
		for (unsigned int j = total = 0; strings[i] && j < st_length_get(strings[i]); j++) {
			total += *(st_char_get(strings[i]) + j);
		}

		if (total != 5366) {
			result = false;
		}
	}

	if (result) {

		strings[15] = st_merge(MANAGED_T | JOINTED | HEAP, "snsnsnsnsnsnsnsnsnsnsnsnsnsnsnsn", constant, "\n", strings[0], "\n", strings[1], "\n", strings[2], "\n",
				strings[3], "\n", strings[4], "\n", strings[5], "\n", strings[6], "\n", strings[7], "\n", strings[8], "\n", strings[9], "\n", strings[10], "\n", strings[11],
				"\n", strings[12], "\n", strings[13], "\n", strings[14], "\n");

		for (unsigned int i = total = 0; strings[15] && i < st_length_get(strings[15]); i++) {
			total += *(st_char_get(strings[15]) + i);
		}

		if (total != (5376lu * 16lu)) {
			result = false;
		}

	}

	log_print("%28.28s = %s", "merged", result ? "passed" : "failed");

	for (int i = 0; i < 16; i++) {
		if (strings[i])
			st_free(strings[i]);
	}

	return result;

}