示例#1
0
文件: hboot.c 项目: czechop/2ndboot
void build_l1_table(uint32_t *table) {
    printk("PHYS OFFSET[0x%4X], PAGE_OFFSET[0x%4X], normal mapping[0x%4X]\n", (int)PHYS_OFFSET, (int)PAGE_OFFSET, (int)L1_NORMAL_MAPPING);
	memset(table, 0, 4*4096);
        l1_map(table, PHYS_OFFSET, PHYS_OFFSET, 512-12, L1_NORMAL_MAPPING);
        l1_map(table, PHYS_OFFSET, PAGE_OFFSET, 512-12, L1_NORMAL_MAPPING);
        l1_map(table, 0x48000000, 0xFA000000, 1, L1_NORMAL_MAPPING);
        l1_map(table, 0x49000000, 0xFB000000, 1, L1_NORMAL_MAPPING);
}
示例#2
0
int
vmm_map_xfer(PROCESS *actprp, PROCESS *prp, IOV **piov, int *pparts, int *poff, IOV *niov, int *pnparts, unsigned flags)
{
	struct xfer_slot	*slot = &xfer_slots[RUNCPU];
	IOV					*iov = *piov;
	int					parts = *pparts;
	unsigned			bound = prp->boundry_addr;
	unsigned			diff0 = 0;
	unsigned			diff1 = 0;
	unsigned			lo0 = 0;
	unsigned			lo1 = 0;
	unsigned			hi0 = 0;
	unsigned			hi1 = 0;
	int					l1_mapped = 0;
	unsigned			addr;
	unsigned			last;
	unsigned			off;
	unsigned			size;
	int					nbytes;
	int					nparts;
	int					nparts_max;

#ifndef	NDEBUG
	if (actprp->memory == 0) {
		crash();
	}
	if (prp->memory == 0) {
		crash();
	}
#endif

	slot->prp = prp;
	slot->diff0 = 0;
	slot->size0 = 0;
	slot->diff1 = 0;
	slot->size1 = 0;

	/*
	 * Map IOV addresses if necessary
	 */
	if ((flags & MAPADDR_FLAGS_IOVKERNEL) == 0) {
		last = (uintptr_t)iov + parts * sizeof(IOV) - 1;
		if ((uintptr_t)iov > last || (!(flags & MAPADDR_FLAGS_SYSPRP) && !WITHIN_BOUNDRY((uintptr_t)iov, last, bound))) {
			return -1;
		}
		if (V6_USER_SPACE(iov)) {
			/*
			 * Map the iov list
			 */
			if (l1_mapped == 0) {
				l1_map(prp->memory);
				l1_mapped = 1;
			}
			lo0 = (unsigned)iov & ~ARM_SCMASK;
			hi0 = map_slot0(lo0, last);
			slot->diff0 = diff0 = ARM_V6_XFER_BASE - lo0;
			slot->size0 = hi0 - lo0;

			iov = (IOV *)((unsigned)iov + diff0);
		}
	}

	/*
	 * Check whole IOV list is valid
	 */
	addr = ((uintptr_t)iov) & ~PGMASK;
	last = ((uintptr_t)(iov + (uint32_t)parts) - 1) & ~PGMASK;
	if (addr > last) {
		nbytes = -1;
		goto out;
	}
	while (addr <= last) {
		if (xfer_memprobe((void *)addr) != 0) {
			nbytes = -1;
			goto out;
		}
		addr += __PAGESIZE;
	}

	/*
	 * Skip to supplied offset
	 */
	off = *poff;
	while (off >= (size = GETIOVLEN(iov))) {
		off -= size;
		if (--parts == 0) {
			nbytes = 0;		// no more parts
			goto out;
		}
		iov++;
	}
	addr = (unsigned)GETIOVBASE(iov) + off;
	size = (unsigned)GETIOVLEN(iov)  - off;
	off = 0;

	/*
	 * Loop over remaining IOVs and adjust to mapped addresses
	 */
	nbytes = 0;
	nparts = 0;
	nparts_max = *pnparts;
	while (nparts < nparts_max) {
		unsigned	map_size;
		unsigned	map_addr;
		unsigned	len;

		if (size) {
			/*
			 * Check addresses are valid
			 */
			last = addr + size - 1;
			if (addr > last || (!(flags & MAPADDR_FLAGS_SYSPRP) && !WITHIN_BOUNDRY(addr, last, bound))) {
				nbytes = -1;
				goto out;
			}
			if (!V6_USER_SPACE(addr)) {
				/*
				 * Kernel address - no mapping required
				 */
				map_size = size;
				map_addr = addr;
			}
			else if (addr >= lo0 && addr < hi0) {
				/*
				 * Contained in first mapping
				 */
				map_addr = addr + diff0;
				map_size = hi0 - addr;
			}
			else if (addr >= lo1 && addr < hi1) {
				/*
				 * Contained in second mapping
				 */
				map_addr = addr + diff1;
				map_size = hi1 - addr;
			}
			else if (hi1 == 0) {
				/*
				 * Create second set of mappings
				 */
				if (l1_mapped == 0) {
					l1_map(prp->memory);
					l1_mapped = 1;
				}
				lo1 = addr & ~ARM_SCMASK;
				hi1 = map_slot1(lo1, slot->size0);
				slot->diff1 = diff1 = ARM_V6_XFER_BASE + slot->size0 - lo1;
				slot->size1 = ARM_V6_XFER_SIZE - slot->size0;

				map_addr = addr + diff1;
				map_size = hi1 - addr;
			}
			else {
				/*
				 * Can't map the iov data
				 */
				break;
			}

			len = min(size, map_size);
			SETIOV(niov, map_addr, len);
			niov++;
			nparts++;
			nbytes += len;
			if (size > map_size) {
				/*
				 * Could only map part of the iov
				 */
				off = (addr - (unsigned)GETIOVBASE(iov)) + len;
				break;
			}
		}
		if (--parts == 0) {
			break;
		}
		iov++;
		addr = (unsigned)GETIOVBASE(iov);
		size = GETIOVLEN(iov);
	}

	/*
	 * Adjust caller's iov list to the end of the area we just mapped
	 */
	*piov = (IOV *)((unsigned)iov - diff0);
	*pparts = parts;
	*poff = off;
	*pnparts = nparts;

out:
	if (l1_mapped) {
		l1_unmap();
	}
	return nbytes;
}
示例#3
0
int main()
{
  std::cout << std::endl
            << "TESTING LABYRINTH_MAP.CPP IMPLEMENTATION" << std::endl
            << "________________________________________________" << std::endl
            << std::endl;


  const unsigned int l1_xsize = 3;
  const unsigned int l1_ysize = 2;

  std::cout << "Creating a basic, empty Labyrinth with:" << std::endl
            << "  x size = " << l1_xsize << std::endl
            << "  y size = " << l1_ysize << std::endl;

  Labyrinth l1( l1_xsize, l1_ysize );
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;

  std::cout << "________________________________________________"
            << std::endl
            << std::endl;

  std::cout << "Creating and displaying a Map from the Labyrinth:" << std::endl;
  LabyrinthMap l1_map( &l1, l1_xsize, l1_ysize );
  std::cout << "Creation completed." << std::endl << std::endl;
  try
  {
    l1_map.Display();
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Display completed." << std::endl;
  std::cout << std::endl;

  std::cout << "________________________________________________"
            << std::endl
            << std::endl;

  std::cout << "Setting the Labyrinth to be a snake from the top left "
            << "to the bottom right." << std::endl;
  Coordinate c1(0, 0);
  Coordinate c2(0, 1);
  Coordinate c3(1, 1);
  Coordinate c4(1, 0);
  Coordinate c5(2, 0);
  Coordinate c6(2, 1);
  try
  {
    l1.ConnectRooms( c1, c2 );
    l1.ConnectRooms( c2, c3 );
    l1.ConnectRooms( c3, c4 );
    l1.ConnectRooms( c4, c5 );
    l1.ConnectRooms( c5, c6 );
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;


  std::cout << "Displaying the Map of the Labyrinth:" << std::endl << std::endl;
  try
  {
    l1_map.Display();
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;


  std::cout << "________________________________________________"
            << std::endl
            << std::endl;

  std::cout << "Setting the following items and inhabitants:" << std::endl;
  std::cout << "  Top left Coordinate has a Minotaur (live) and a bullet"
            << std::endl
            << "  Bottom left Coordinate has a Minotaur (dead)"
            << std::endl
            << "  Bottom center Coordinate has a Treasure"
            << std::endl
            << "  Top right Coordinate has a mirror (intact)"
            << std::endl
            << "  Bottom right Coordinate has a mirror (cracked)"
            << std::endl;

  try
  {
    l1.SetInhabitant( c1, Inhabitant::kMinotaur );
    l1.SetInhabitant( c2, Inhabitant::kMinotaurDead );
    l1.SetInhabitant( c5, Inhabitant::kMirror );
    l1.SetInhabitant( c6, Inhabitant::kMirrorCracked );

    l1.SetItem( c1, Item::kBullet );
    l1.SetItem( c3, Item::kTreasure );
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;

  std::cout << "Displaying the Map of the Labyrinth:" << std::endl << std::endl;
  try
  {
    l1_map.Display();
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;



  std::cout << "________________________________________________" << std::endl;
  std::cout << std::endl;
  std::cout << "All tests completed." << std::endl;
  std::cout << std::endl;
  std::cout << "Press enter to exit.";
  getchar();
  std::cout << std::endl;

  return 0;
}