Example #1
0
int mem_write(uint32_t addr, uint32_t val, unsigned int bytes,
              struct amiga_state *s)
{
    struct memory *m = find_memory(s, addr, bytes);

    if (m == NULL) {
        log_warn("Write %u bytes non-RAM", bytes);
        return M68KEMUL_UNHANDLEABLE;
        return M68KEMUL_OKAY;
    }

    addr -= m->start;
    switch (bytes) {
    case 1:
        *(uint8_t *)&m->dat[addr] = val;
        break;
    case 2:
        *(uint16_t *)&m->dat[addr] = htobe16(val);
        break;
    case 4:
        *(uint32_t *)&m->dat[addr] = htobe32(val);
        break;
    default:
        return M68KEMUL_UNHANDLEABLE;
    }

    return M68KEMUL_OKAY;
}
Example #2
0
void mem_free(struct amiga_state *s, uint32_t addr, uint32_t bytes)
{
    struct memory *m = find_memory(s, addr, bytes);
    struct region *r, *prev, **pprev;

    ASSERT(m != NULL);

    regions_dump(m->free);

    pprev = &m->free;
    while (((r = *pprev) != NULL) && (r->end < addr))
        pprev = &r->next;

    if ((r != NULL) && (r->start == (addr + bytes))) {
        r->start -= bytes;
    } else {
        r = memalloc(sizeof(*r));
        r->start = addr;
        r->end = addr + bytes - 1;
        r->next = *pprev;
        *pprev = r;
    }

    prev = container_of(pprev, struct region, next);
    if ((pprev != &m->free) && (prev->end >= (addr-1))) {
        ASSERT(prev->end == (addr-1));
        prev->end = r->end;
        prev->next = r->next;
        memfree(r);
    }

    memset(&m->dat[addr - m->start], 0xaa, bytes);

    regions_dump(m->free);
}
Example #3
0
int mem_read(uint32_t addr, uint32_t *val, unsigned int bytes,
             struct amiga_state *s)
{
    struct memory *m = find_memory(s, addr, bytes);

    if (m == NULL) {
        log_warn("Read %u bytes non-RAM", bytes);
        return M68KEMUL_UNHANDLEABLE;
        *val = bytes == 1 ? 0xff : bytes == 2 ? 0xffff : 0xffffffff;
        return M68KEMUL_OKAY;
    }

    addr -= m->start;
    switch (bytes) {
    case 1:
        *val = *(uint8_t *)&m->dat[addr];
        break;
    case 2:
        *val = be16toh(*(uint16_t *)&m->dat[addr]);
        break;
    case 4:
        *val = be32toh(*(uint32_t *)&m->dat[addr]);
        break;
    default:
        return M68KEMUL_UNHANDLEABLE;
    }

    return M68KEMUL_OKAY;
}
Example #4
0
void *buddy_allocation(info_p handle, long n_bytes){
  if(n_bytes > handle->n_bytes){
    printf("Buddy Alloc Error: Request Size too large\n");
    return NULL;
  }
  long size = find_smallest_block(n_bytes);
  if(size < (long)power(2,handle->parm1)){
    size = (long)power(2,handle->parm1);
  }
  printf("Looking for block size: %lu\n", size);

  int bitmap[handle->overhead * 8];
  encode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap);

  int indx = find_bit(bitmap, 1, handle->n_bytes, size, (long)power(2,handle->parm1));
  indx -= 50; //Decode the encoded index
  if(indx < 0){
    printf("Bitmap: Could not find free space\n");
    return NULL;
  }
  printf("Bitmap: Index Found: %d\n", indx);
  void *returnptr = find_memory(indx, handle);

  decode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap);

  printf("Buddy Alloc: Allocated Space at %p\n", returnptr);

  return returnptr;
}
Example #5
0
void mem_reserve(struct amiga_state *s, uint32_t start, uint32_t bytes)
{
    struct memory *m = find_memory(s, start, bytes);
    struct region *r, *n, **pprev;
    uint32_t end = start + bytes - 1;

    ASSERT(m != NULL);

    regions_dump(m->free);

    pprev = &m->free;
    while (((r = *pprev) != NULL) && (r->end < start))
        pprev = &r->next;

    ASSERT((r != NULL) && (r->start <= start) && (r->end >= end));
    if (r->start == start) {
        r->start = end + 1;
    } else if (r->end == end) {
        r->end = start - 1;
    } else {
        n = memalloc(sizeof(*n));
        n->start = end + 1;
        n->end = r->end;
        n->next = r->next;
        r->end = start - 1;
        r->next = n;
    }

    if (r->start > r->end) {
        ASSERT(r->start == (r->end + 1));
        *pprev = r->next;
        memfree(r);
    }

    regions_dump(m->free);
}
Example #6
0
void __init
setup_arch (char **cmdline_p)
{
	unw_init();

	ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist);

	*cmdline_p = __va(ia64_boot_param->command_line);
	strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);

	efi_init();
	io_port_init();

#ifdef CONFIG_IA64_GENERIC
	machvec_init(acpi_get_sysname());
#endif

	if (early_console_setup(*cmdline_p) == 0)
		mark_bsp_online();

#ifdef CONFIG_ACPI_BOOT
	/* Initialize the ACPI boot-time table parser */
	acpi_table_init();
# ifdef CONFIG_ACPI_NUMA
	acpi_numa_init();
# endif
#else
# ifdef CONFIG_SMP
	smp_build_cpu_map();	/* happens, e.g., with the Ski simulator */
# endif
#endif /* CONFIG_APCI_BOOT */

	find_memory();

	/* process SAL system table: */
	ia64_sal_init(efi.sal_systab);

#ifdef CONFIG_SMP
	cpu_physical_id(0) = hard_smp_processor_id();
#endif

	cpu_init();	/* initialize the bootstrap CPU */

#ifdef CONFIG_ACPI_BOOT
	acpi_boot_init();
#endif

#ifdef CONFIG_VT
	if (!conswitchp) {
# if defined(CONFIG_DUMMY_CONSOLE)
		conswitchp = &dummy_con;
# endif
# if defined(CONFIG_VGA_CONSOLE)
		/*
		 * Non-legacy systems may route legacy VGA MMIO range to system
		 * memory.  vga_con probes the MMIO hole, so memory looks like
		 * a VGA device to it.  The EFI memory map can tell us if it's
		 * memory so we can avoid this problem.
		 */
		if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
			conswitchp = &vga_con;
# endif
	}
#endif

	/* enable IA-64 Machine Check Abort Handling unless disabled */
	if (!strstr(saved_command_line, "nomca"))
		ia64_mca_init();
	
	platform_setup(cmdline_p);
	paging_init();
}
Example #7
0
void __init
setup_arch (char **cmdline_p)
{
	unw_init();

	ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist);

	*cmdline_p = __va(ia64_boot_param->command_line);
	strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);

	efi_init();
	io_port_init();

	parse_early_param();

#ifdef CONFIG_IA64_GENERIC
	machvec_init(NULL);
#endif

	if (early_console_setup(*cmdline_p) == 0)
		mark_bsp_online();

#ifdef CONFIG_ACPI
	/* Initialize the ACPI boot-time table parser */
	acpi_table_init();
# ifdef CONFIG_ACPI_NUMA
	acpi_numa_init();
# endif
#else
# ifdef CONFIG_SMP
	smp_build_cpu_map();	/* happens, e.g., with the Ski simulator */
# endif
#endif /* CONFIG_APCI_BOOT */

	find_memory();

	/* process SAL system table: */
	ia64_sal_init(__va(efi.sal_systab));

	ia64_setup_printk_clock();

#ifdef CONFIG_SMP
	cpu_physical_id(0) = hard_smp_processor_id();

	cpu_set(0, cpu_sibling_map[0]);
	cpu_set(0, cpu_core_map[0]);

	check_for_logical_procs();
	if (smp_num_cpucores > 1)
		printk(KERN_INFO
		       "cpu package is Multi-Core capable: number of cores=%d\n",
		       smp_num_cpucores);
	if (smp_num_siblings > 1)
		printk(KERN_INFO
		       "cpu package is Multi-Threading capable: number of siblings=%d\n",
		       smp_num_siblings);
#endif

	cpu_init();	/* initialize the bootstrap CPU */
	mmu_context_init();	/* initialize context_id bitmap */

#ifdef CONFIG_ACPI
	acpi_boot_init();
#endif

#ifdef CONFIG_VT
	if (!conswitchp) {
# if defined(CONFIG_DUMMY_CONSOLE)
		conswitchp = &dummy_con;
# endif
# if defined(CONFIG_VGA_CONSOLE)
		/*
		 * Non-legacy systems may route legacy VGA MMIO range to system
		 * memory.  vga_con probes the MMIO hole, so memory looks like
		 * a VGA device to it.  The EFI memory map can tell us if it's
		 * memory so we can avoid this problem.
		 */
		if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
			conswitchp = &vga_con;
# endif
	}
#endif

	/* enable IA-64 Machine Check Abort Handling unless disabled */
	if (!nomca)
		ia64_mca_init();

	platform_setup(cmdline_p);
	paging_init();
}
Example #8
0
void __init
setup_arch (char **cmdline_p)
{
	extern unsigned long ia64_iobase;
	unsigned long phys_iobase;

	unw_init();

	ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist);

	*cmdline_p = __va(ia64_boot_param->command_line);
	strlcpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));

	efi_init();

#ifdef CONFIG_ACPI_BOOT
	/* Initialize the ACPI boot-time table parser */
	acpi_table_init();
# ifdef CONFIG_ACPI_NUMA
	acpi_numa_init();
# endif
#else
# ifdef CONFIG_SMP
	smp_build_cpu_map();	/* happens, e.g., with the Ski simulator */
# endif
#endif /* CONFIG_APCI_BOOT */

	find_memory();

	/* process SAL system table: */
	ia64_sal_init(efi.sal_systab);

#ifdef CONFIG_IA64_GENERIC
	machvec_init(acpi_get_sysname());
#endif

	/*
	 *  Set `iobase' to the appropriate address in region 6 (uncached access range).
	 *
	 *  The EFI memory map is the "preferred" location to get the I/O port space base,
	 *  rather the relying on AR.KR0. This should become more clear in future SAL
	 *  specs. We'll fall back to getting it out of AR.KR0 if no appropriate entry is
	 *  found in the memory map.
	 */
	phys_iobase = efi_get_iobase();
	if (phys_iobase)
		/* set AR.KR0 since this is all we use it for anyway */
		ia64_set_kr(IA64_KR_IO_BASE, phys_iobase);
	else {
		phys_iobase = ia64_get_kr(IA64_KR_IO_BASE);
		printk(KERN_INFO "No I/O port range found in EFI memory map, falling back "
		       "to AR.KR0\n");
		printk(KERN_INFO "I/O port base = 0x%lx\n", phys_iobase);
	}
	ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);

	/* setup legacy IO port space */
	io_space[0].mmio_base = ia64_iobase;
	io_space[0].sparse = 1;
	num_io_spaces = 1;

#ifdef CONFIG_SMP
	cpu_physical_id(0) = hard_smp_processor_id();
#endif

	cpu_init();	/* initialize the bootstrap CPU */

#ifdef CONFIG_ACPI_BOOT
	acpi_boot_init();
#endif
#ifdef CONFIG_SERIAL_8250_HCDP
	if (efi.hcdp) {
		void setup_serial_hcdp(void *);
		setup_serial_hcdp(efi.hcdp);
	}
#endif
#ifdef CONFIG_SERIAL_8250_CONSOLE
	/*
	 * Without HCDP, we won't discover any serial ports until the serial driver looks
	 * in the ACPI namespace.  If ACPI claims there are some legacy devices, register
	 * the legacy COM ports so serial console works earlier.  This is slightly dangerous
	 * because we don't *really* know whether there's anything there, but we hope that
	 * all new boxes will implement HCDP.
	 */
	{
		extern unsigned char acpi_legacy_devices;
		if (!efi.hcdp && acpi_legacy_devices)
			setup_serial_legacy();
	}
#endif

#ifdef CONFIG_VT
# if defined(CONFIG_DUMMY_CONSOLE)
	conswitchp = &dummy_con;
# endif
# if defined(CONFIG_VGA_CONSOLE)
	/*
	 * Non-legacy systems may route legacy VGA MMIO range to system
	 * memory.  vga_con probes the MMIO hole, so memory looks like
	 * a VGA device to it.  The EFI memory map can tell us if it's
	 * memory so we can avoid this problem.
	 */
	if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
		conswitchp = &vga_con;
# endif
#endif

#ifdef CONFIG_IA64_MCA
	/* enable IA-64 Machine Check Abort Handling */
	ia64_mca_init();
#endif

	platform_setup(cmdline_p);
	paging_init();
}
void memory_pool_test(_P& memPool) {

  ASSERT_NE(FALSE, memPool.isValid());
  TRACE("Total Size = %u", memPool.total_size());
  TRACE("Free Size = %u", memPool.free_size());

  void* arrMem[2048] = {NULL};
  uint32_t alloc_count = 0;
  {
    void* arrMemCheck[2048] = {NULL};
    for (uint32_t idx = 0; idx < 512; ++idx) {

      void* mem = NULL;
      mem = memPool.get(64);
      if (NULL == mem) {
        TRACE("Total Size = %u", memPool.total_size());
        TRACE("Free Size = %u", memPool.free_size());
        continue;
      }

      arrMem[alloc_count] = mem;
      arrMemCheck[alloc_count] = mem;
      alloc_count++;
    }

    uint32_t reuse_count = 0;
    uint32_t release_count = 0;
    // clear
    for (uint32_t idx = 0; idx < alloc_count; ++idx) {

      void* mem = arrMem[idx];
      ASSERT_NE(NULL, mem);
      memPool.release(mem);
      arrMem[idx] = NULL;

      ++idx;
      ++release_count;
    }
    
    // again
    for (uint32_t idx = 0; idx < 512; ++idx) {

      void* mem = NULL;
      mem = memPool.get(64);
      if (NULL == mem) { continue; }
      if (RC_S_OK == find_memory((const void**)(&arrMemCheck), sizeof(arrMemCheck), mem)) {
        ++reuse_count;
      }

      arrMem[alloc_count] = mem;
      alloc_count++;
    }

    ASSERT_EQ(release_count, reuse_count);
    TRACE("reuse count = %u", reuse_count);
  }

  {
    void* mem = NULL;
    memPool.release(mem);
    mem = NULL;
  }

  {
    void* mem = NULL;
    mem = memPool.get(65*1024);
    //ASSERT_EQ(NULL, mem);
    arrMem[alloc_count] = mem;
    alloc_count++;
  }

  // release all
  {
    for (uint32_t idx = 0; idx < alloc_count; ++idx) {

      void* mem = arrMem[idx];
      if (mem) {
        memPool.release(mem);
      }
    }
  }
}