コード例 #1
0
ファイル: ustack.hpp プロジェクト: BOuissem/openhyperflow2d
T& UStack<T>::Pop(T* pt) {
    if (pt==NULL) {
        memcpy(&TopElement,UArray<T>::GetElementPtr(GetStackSize()-1),sizeof(T));
        UArray<T>::DelElement(GetStackSize()-1);
        return TopElement;
    } else {
        memcpy(pt,UArray<T>::GetElementPtr(GetStackSize()-1),sizeof(T));
        UArray<T>::DelElement(GetStackSize()-1);
        return  *pt;
    }
}
コード例 #2
0
ファイル: isapi.cpp プロジェクト: rickerliang/OpenNT
int CHttpServer::CallMemberFunc(CHttpServerContext* pCtxt,
	const AFX_PARSEMAP_ENTRY* pEntry,
	AFX_PARSEMAP_ENTRY* pParams, LPTSTR pszParams)
{
	ISAPIASSERT(NULL != pEntry);
	AFX_PISAPICMD pFunc = pEntry->pfn;
	ISAPIASSERT(NULL != pFunc);
	int nRet = callOK;

	// get default function and parameters
	BYTE bNoParams = 0;
	const BYTE* pbParams = (const BYTE*)pEntry->pszArgs;
	if (NULL == pbParams)
		pbParams = &bNoParams;
	UINT nParams = lstrlenA((LPCSTR)pbParams);

	AFX_PARSEMAP_ENTRY_PARAMS *pDefaultParams = NULL;
	if (pParams != NULL)
	{
		::EnterCriticalSection(m_pCritSec);
		if (pParams->pszFnName == NULL)
			nRet = ParseDefaultParams(pParams, nParams, pDefaultParams, pbParams);
		else
			pDefaultParams = (AFX_PARSEMAP_ENTRY_PARAMS*) pParams->pszFnName;
		::LeaveCriticalSection(m_pCritSec);
	}

	if (nRet == callOK)
	{
		// get default function and return value information
		AFX_PISAPICMD pfn = pEntry->pfn;

		// determine size of arguments and allocate stack space
		// include space for our context pointer
		UINT nSizeArgs = GetStackSize(pbParams) + sizeof(_STACK_PTR);
		ISAPIASSERT(nSizeArgs != 0);

		if (nSizeArgs < _STACK_MIN)
			nSizeArgs = _STACK_MIN;
		BYTE* pStack = (BYTE*)_alloca(nSizeArgs + _SCRATCH_SIZE);
		if (pStack == NULL)
		{
			ISAPITRACE0("Error: stack overflow in CHttpServer::CallMemberFunc()!\n");
			return callNoStackSpace;
		}

		if (pDefaultParams != NULL)
#ifndef _SHADOW_DOUBLES
			nRet = PushDefaultStackArgs(pStack, pCtxt, pbParams, pszParams,
				pDefaultParams);
#else
			nRet = PushDefaultStackArgs(pStack, pCtxt, pbParams, pszParams,
				pDefaultParams, nSizeArgs);
#endif
		else
コード例 #3
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
void AItem::TakeFrom(AItem* otherItem) {
	// Get the amount of items needed to add
	int amountToAdd = otherItem->GetAmount();

	// Can we just add to this item
	if (GetRemainingSpace() >= amountToAdd) {
		SetAmount(GetAmount() + otherItem->GetAmount());
		otherItem->SetAmount(0);
	}
	else {
		// If we're greater than stack size just set the amount to max size
		otherItem->SetAmount(otherItem->GetAmount() - GetRemainingSpace());
		SetAmount(GetStackSize());
	}
}
コード例 #4
0
ファイル: Lua.cpp プロジェクト: asraniel/rocket
int lua_setmetatable(lua_State* L, int index)
{

    luai_apicheck(L, GetStackSize(L) >= 1);

    Value* object    = GetValueForIndex(L, index);
    Value* metatable = GetValueForIndex(L, -1);

    Table* table = NULL;
    if (!Value_GetIsNil(metatable))
    {
        luai_apicheck(L, Value_GetIsTable(metatable) );
        table = metatable->table;
    }

    Value_SetMetatable( L, object, table );

    Pop(L, 1);
    return 1;

}
コード例 #5
0
ファイル: oledisp1.cpp プロジェクト: anyue100/winscp
// invoke standard method given IDispatch parameters/return value, etc.
SCODE CCmdTarget::CallMemberFunc(const AFX_DISPMAP_ENTRY* pEntry, WORD wFlags,
	VARIANT* pvarResult, DISPPARAMS* pDispParams, UINT* puArgErr)
{
	AFX_MANAGE_STATE(m_pModuleState);

	ASSERT(pEntry != NULL);
	ASSERT(pEntry->pfn != NULL);

	// special union used only to hold largest return value possible
	union AFX_RESULT
	{
		VARIANT vaVal;
		CY cyVal;
		float fltVal;
		double dblVal;
		DWORD nVal;
	};

	// get default function and parameters
	BYTE bNoParams = 0;
	const BYTE* pbParams = (const BYTE*)pEntry->lpszParams;
	if (pbParams == NULL)
		pbParams = &bNoParams;
	UINT nParams = lstrlenA((LPCSTR)pbParams);

	// get default function and return value information
	AFX_PMSG pfn = pEntry->pfn;
	VARTYPE vtResult = pEntry->vt;

	// make DISPATCH_PROPERTYPUT look like call with one extra parameter
	if (wFlags & (DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF))
	{
		BYTE* pbPropSetParams = (BYTE*)_alloca(nParams+3);
		ASSERT(pbPropSetParams != NULL);    // stack overflow?

		ASSERT(!(pEntry->vt & VT_BYREF));
		memcpy(pbPropSetParams, pbParams, nParams);
		pbParams = pbPropSetParams;

		VARTYPE vtProp = pEntry->vt;
#if !defined(_UNICODE) && !defined(OLE2ANSI)
		if (vtProp == VT_BSTR)
			vtProp = VT_BSTRA;
#endif
		// VT_MFCVALUE serves serves as marker denoting start of named params
		pbPropSetParams[nParams++] = (BYTE)VT_MFCMARKER;
		pbPropSetParams[nParams++] = (BYTE)vtProp;
		pbPropSetParams[nParams] = 0;

		// call "set" function instead of "get"
		ASSERT(pEntry->pfnSet != NULL);
		pfn = pEntry->pfnSet;
		vtResult = VT_EMPTY;
	}

	// allocate temporary space for VARIANT temps created by VariantChangeType
	VARIANT* rgTempVars =
		(VARIANT*)_alloca(pDispParams->cArgs * sizeof(VARIANT));
	if (rgTempVars == NULL)
	{
		TRACE0("Error: stack overflow in IDispatch::Invoke!\n");
		return E_OUTOFMEMORY;
	}
	memset(rgTempVars, 0, pDispParams->cArgs * sizeof(VARIANT));

	// determine size of arguments and allocate stack space
	UINT nSizeArgs = GetStackSize(pbParams, vtResult);
	ASSERT(nSizeArgs != 0);
	if (nSizeArgs < _STACK_MIN)
		nSizeArgs = _STACK_MIN;
	BYTE* pStack = (BYTE*)_alloca(nSizeArgs + _SCRATCH_SIZE);
	if (pStack == NULL)
	{
		TRACE0("Error: stack overflow in IDispatch::Invoke!\n");
		return E_OUTOFMEMORY;
	}

	// push all the args on to the stack allocated memory
	AFX_RESULT result;
#ifndef _SHADOW_DOUBLES
	SCODE sc = PushStackArgs(pStack, pbParams, &result, vtResult,
		pDispParams, puArgErr, rgTempVars);
#else
	SCODE sc = PushStackArgs(pStack, pbParams, &result, vtResult,
		pDispParams, puArgErr, rgTempVars, nSizeArgs);
#endif
	pStack += _STACK_OFFSET;

	DWORD dwResult = 0;
	if (sc == S_OK)
	{
		TRY
		{
			// PushStackArgs will fail on argument mismatches
			DWORD (AFXAPI *pfnDispatch)(AFX_PMSG, void*, UINT) =
				&_AfxDispatchCall;

			// floating point return values are a special case
			switch (vtResult)
			{
			case VT_R4:
				result.fltVal = ((float (AFXAPI*)(AFX_PMSG, void*, UINT))
					pfnDispatch)(pfn, pStack, nSizeArgs);
				break;
			case VT_R8:
				result.dblVal = ((double (AFXAPI*)(AFX_PMSG, void*, UINT))
					pfnDispatch)(pfn, pStack, nSizeArgs);
				break;
			case VT_DATE:
				result.dblVal = ((DATE (AFXAPI*)(AFX_PMSG, void*, UINT))
					pfnDispatch)(pfn, pStack, nSizeArgs);
				break;

			default:
				dwResult = pfnDispatch(pfn, pStack, nSizeArgs);
				break;
			}
		}
		CATCH_ALL(e)
		{
			// free temporaries created by VariantChangeType
			for (UINT iArg = 0; iArg < pDispParams->cArgs; ++iArg)
				VariantClear(&rgTempVars[iArg]);

			THROW_LAST();
		}
		END_CATCH_ALL
	}
コード例 #6
0
ファイル: oledisp1.cpp プロジェクト: rickerliang/OpenNT
// invoke standard method given IDispatch parameters/return value, etc.
SCODE CCmdTarget::CallMemberFunc(const AFX_DISPMAP_ENTRY* pEntry, WORD wFlags,
	VARIANT* pvarResult, DISPPARAMS* pDispParams, UINT* puArgErr)
{
	ASSERT(pEntry != NULL);
	ASSERT(pEntry->pfn != NULL);

	// special union used only to hold largest return value possible
	union AFX_RESULT
	{
		VARIANT vaVal;
		CY cyVal;
		float fltVal;
		double dblVal;
		DWORD nVal;
	};

	// get default function and parameters
	BYTE bNoParams = 0;
	const BYTE* pbParams = (const BYTE*)pEntry->lpszParams;
	if (pbParams == NULL)
		pbParams = &bNoParams;
	UINT nParams = lstrlenA((LPCSTR)pbParams);

	// get default function and return value information
	AFX_PMSG pfn = pEntry->pfn;
	VARTYPE vtResult = pEntry->vt;

	// make DISPATCH_PROPERTYPUT look like call with one extra parameter
	if (wFlags & (DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF))
	{
		BYTE* pbPropSetParams = (BYTE*)_alloca(nParams+3);
		ASSERT(pbPropSetParams != NULL);    // stack overflow?

		ASSERT(!(pEntry->vt & VT_BYREF));
		memcpy(pbPropSetParams, pbParams, nParams);
		pbParams = pbPropSetParams;

		// VT_MFCVALUE serves serves as marker denoting start of named params
		pbPropSetParams[nParams++] = (BYTE)VT_MFCMARKER;
		pbPropSetParams[nParams++] = (BYTE)pEntry->vt;
		pbPropSetParams[nParams] = 0;

		if (pEntry->pfnSet != NULL)
		{
			pfn = pEntry->pfnSet;   // call "set" function instead of "get"
			vtResult = VT_EMPTY;
		}
	}

	// allocate temporary space for VARIANT temps created by VariantChangeType
	VARIANT* rgTempVars =
		(VARIANT*)_alloca(pDispParams->cArgs * sizeof(VARIANT));
	if (rgTempVars == NULL)
	{
		TRACE0("Error: stack overflow in IDispatch::Invoke!\n");
		return E_OUTOFMEMORY;
	}
	memset(rgTempVars, 0, pDispParams->cArgs * sizeof(VARIANT));

	// determine size of arguments and allocate stack space
	UINT nSizeArgs = GetStackSize(pbParams, vtResult);
	ASSERT(nSizeArgs != 0);
	if (nSizeArgs < _STACK_MIN)
		nSizeArgs = _STACK_MIN;
	BYTE* pStack = (BYTE*)_alloca(nSizeArgs + _SCRATCH_SIZE);
	if (pStack == NULL)
	{
		TRACE0("Error: stack overflow in IDispatch::Invoke!\n");
		return E_OUTOFMEMORY;
	}

	// push all the args on to the stack allocated memory
	AFX_RESULT result;
#ifndef _SHADOW_DOUBLES
	SCODE sc = PushStackArgs(pStack, pbParams, &result, vtResult,
		pDispParams, puArgErr, rgTempVars);
#else
	SCODE sc = PushStackArgs(pStack, pbParams, &result, vtResult,
		pDispParams, puArgErr, rgTempVars, nSizeArgs);
#endif

	// PushStackArgs will fail on argument mismatches
	DWORD dwResult;
	if (sc == S_OK)
	{
		DWORD (AFXAPI *pfnDispatch)(AFX_PMSG, void*, UINT) = &_AfxDispatchCall;

		// floating point return values are a special case
		switch (vtResult)
		{
		case VT_R4:
			result.fltVal = ((float (AFXAPI*)(AFX_PMSG, void*, UINT))
				pfnDispatch)(pfn, pStack, nSizeArgs);
			break;
		case VT_R8:
			result.dblVal = ((double (AFXAPI*)(AFX_PMSG, void*, UINT))
				pfnDispatch)(pfn, pStack, nSizeArgs);
			break;
		case VT_DATE:
			result.dblVal = ((DATE (AFXAPI*)(AFX_PMSG, void*, UINT))
				pfnDispatch)(pfn, pStack, nSizeArgs);
			break;

		default:
			dwResult = pfnDispatch(pfn, pStack, nSizeArgs);
			break;
		}
	}

	// free temporaries created by VariantChangeType
	for (UINT iArg = 0; iArg < pDispParams->cArgs; ++iArg)
		VariantClear(&rgTempVars[iArg]);

	// handle error during PushStackParams
	if (sc != S_OK)
		return sc;

	// property puts don't touch the return value
	if (pvarResult != NULL)
	{
		// clear pvarResult just in case
		VariantClear(pvarResult);
		pvarResult->vt = vtResult;

		// build return value VARIANT from result union
		switch (vtResult)
		{
		case VT_I2:
			pvarResult->iVal = (short)dwResult;
			break;
		case VT_I4:
			pvarResult->lVal = (long)dwResult;
			break;
		case VT_R4:
			pvarResult->fltVal = result.fltVal;
			break;
		case VT_R8:
			pvarResult->dblVal = result.dblVal;
			break;
		case VT_CY:
			pvarResult->cyVal = result.cyVal;
			break;
		case VT_DATE:
			pvarResult->date = result.dblVal;
			break;
		case VT_BSTR:
			pvarResult->bstrVal = (BSTR)dwResult;
			break;
		case VT_ERROR:
			pvarResult->scode = (SCODE)dwResult;
			break;
		case VT_BOOL:
			pvarResult->boolVal = (VARIANT_BOOL)((BOOL)dwResult != 0 ? -1 : 0);
			break;
		case VT_VARIANT:
			*pvarResult = result.vaVal;
			break;
		case VT_DISPATCH:
		case VT_UNKNOWN:
			pvarResult->punkVal = (LPUNKNOWN)dwResult; // already AddRef
			break;
		}
	}
	else
	{
		// free unused return value
		switch (vtResult)
		{
		case VT_BSTR:
			if ((BSTR)dwResult != NULL)
				SysFreeString((BSTR)dwResult);
			break;
		case VT_DISPATCH:
		case VT_UNKNOWN:
			if ((LPUNKNOWN)dwResult != 0)
				((LPUNKNOWN)dwResult)->Release();
			break;
		case VT_VARIANT:
			VariantClear(&result.vaVal);
			break;
		}
	}

	return S_OK;    // success!
}
コード例 #7
0
CGUIDialogBoxeeWizardBase* CBoxeeOTAConfigurationManager::HandleNextAction(CGUIDialogBoxeeWizardBase* pDialog, bool& addCurrentDlgToStack)
{
  if (!pDialog)
  {
    CLog::Log(LOGERROR,"CBoxeeOTAConfigurationManager::HandleNextAction - Enter function with a NULL pointer (digwiz)");
    return NULL;
  }

  int id = pDialog->GetID();

  CLog::Log(LOGDEBUG,"CBoxeeOTAConfigurationManager::HandleNextAction - Enter function with [id=%d] (digwiz)",id);

  CGUIDialogBoxeeWizardBase* pNextDialog = NULL;

  switch(id)
  {
  case WINDOW_OTA_WELCOME_CONFIGURATION:
  {
    m_data.ClearData();
    m_data.DetectLocation();

    // If we know the country, ask the user to confirm, otherwise let the user select the location
    BOXEE::BXCurrentLocation& location = BOXEE::BXCurrentLocation::GetInstance();
    if (location.IsLocationDetected())
      pNextDialog = (CGUIDialogBoxeeOTAConfirmLocation*)g_windowManager.GetWindow(WINDOW_OTA_LOCATION_CONFIRMATION);
    else
      pNextDialog = (CGUIDialogBoxeeOTACountriesLocationConfiguration*)g_windowManager.GetWindow(WINDOW_OTA_COUNTRIES_CONFIGURATION);

    if (pNextDialog)
      addCurrentDlgToStack = true;
  }
  break;

  case WINDOW_OTA_LOCATION_CONFIRMATION:
  {
    CGUIDialogBoxeeOTAConfirmLocation* pLocationDialog = (CGUIDialogBoxeeOTAConfirmLocation*)g_windowManager.GetWindow(WINDOW_OTA_LOCATION_CONFIRMATION);
    if (!pLocationDialog)
      break;

    if (pLocationDialog->GetYesButtonPressed() && m_data.IsInNorthAmerica())
      pNextDialog = (CGUIDialogBoxeeOTAZipcodeLocationConfiguration*)g_windowManager.GetWindow(WINDOW_OTA_ZIPCODE_CONFIGURATION);
    else if (pLocationDialog->GetYesButtonPressed() && !m_data.IsInNorthAmerica() && !m_isConnectedToFacebook)
      pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_OTA_FACEBOOK_CONNECT);
    else if (pLocationDialog->GetYesButtonPressed() && !m_data.IsInNorthAmerica() && m_isConnectedToFacebook)
      SetWizardComplete(true);
    else
      pNextDialog = (CGUIDialogBoxeeOTACountriesLocationConfiguration*)g_windowManager.GetWindow(WINDOW_OTA_COUNTRIES_CONFIGURATION);

    if (pNextDialog)
      addCurrentDlgToStack = true;
  }
  break;

  case WINDOW_OTA_COUNTRIES_CONFIGURATION:
  {
    if (m_data.IsInNorthAmerica())
      pNextDialog = (CGUIDialogBoxeeOTAZipcodeLocationConfiguration*)g_windowManager.GetWindow(WINDOW_OTA_ZIPCODE_CONFIGURATION);
    else if (!m_isConnectedToFacebook)
      pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_OTA_FACEBOOK_CONNECT);
    else
      SetWizardComplete(true);

    if (pNextDialog)
      addCurrentDlgToStack = true;
  }
  break;

  case WINDOW_OTA_ZIPCODE_CONFIGURATION:
  {
    pNextDialog = (CGUIDialogBoxeeOTAConnectionConfiguration*)g_windowManager.GetWindow(WINDOW_OTA_CONNECTION_CONFIGURATION);
    if (pNextDialog)
    {
      addCurrentDlgToStack = true;
    }
  }
  break;

  case WINDOW_OTA_CONNECTION_CONFIGURATION:
  {
    if (!m_isConnectedToFacebook)
       pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_OTA_FACEBOOK_CONNECT);
    else
       SetWizardComplete(true);

    if (pNextDialog)
    {
      addCurrentDlgToStack = true;
    }
  }
  break;

  case WINDOW_OTA_FACEBOOK_CONNECT:
  {
    SetWizardComplete(true);
  }
  break;

  default:
  {
    CLog::Log(LOGERROR,"CBoxeeOTAConfigurationManager::HandleNextAction - FAILED to handle WindowId [%d] (digwiz)",id);
  }
  break;
  }

  if (addCurrentDlgToStack)
  {
    AddToStack(id);
  }
  else
  {
    CLog::Log(LOGDEBUG,"CBoxeeOTAConfigurationManager::HandleNextAction - Not adding [id=%d] to stack. [addCurrentDlgToStack=%d][DialogStackSize=%d] (digwiz)",id,addCurrentDlgToStack,GetStackSize());
  }

  CLog::Log(LOGDEBUG,"CBoxeeOTAConfigurationManager::HandleNextAction - Exit function and return [NextDialog=%p] for [id=%d] (digwiz)",pNextDialog,id);

  return pNextDialog;
}
コード例 #8
0
ファイル: uefientry.cpp プロジェクト: ChaiSoft/ChaiOS
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
	InitializeLib(ImageHandle, SystemTable);
	CallConstructors();

	EFI_STATUS Status;

	const char16_t* searchdir = u"\\EFI\\ChaiOS\\";
	if (Status = SetWorkingDirectory(searchdir))
		printf(u"Error setting working directory: %s\r\n", getError(Status));

	CHAIOS_BOOT_FILES* bootfile = nullptr;
	while (bootfile = iterateBootFiles(bootfile))
	{
		if (bootfile->loadLocation != nullptr)
			continue;		//Support in-memory images

		EFI_FILE* file = OpenFile(bootfile->fileName, "r");
		if (!file)
		{
			printf(u"Error: could not open %s: %s\r\n", bootfile->fileName, getError(getErrno()));
		}
		UINT64 fileSize = GetFileSize(file);
		VOID* bootfilebuf = kmalloc(fileSize+1);
		UINTN read = ReadFile(bootfilebuf, 1, fileSize, file);
		if (read < fileSize)
			printf(u"Read %d bytes, failed\r\n", read);
		else
			printf(u"Successfully read %d bytes\r\n", read);
		//Boot file is now loaded into memory
		CloseFile(file);
		bootfile->loadLocation = bootfilebuf;
		bootfile->fileSize = fileSize;
		if (bootfile->bootType == CHAIOS_BOOT_CONFIGURATION)
		{
			//We need to parse this now. INI format
			((char*)bootfilebuf)[fileSize] = '\0';
			ini_parse_string((const char*)bootfilebuf, &bootini_handler, nullptr);
		}
	}

	//size_t value = GetIntegerInput(u"Enter scrolling lines configuration: ");
	//set_scrolllines(value);

	UINT32 AutoMode = IterateGraphicsMode(&match_config_resoultion);
	EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* info; UINTN SizeOfInfo;
	if (AutoMode == UINT32_MAX)
	{
		if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo)))
		{
			IterateGraphicsMode(&print_graphics_mode);
			size_t value = GetIntegerInput(u"Enter boot graphics mode: ");
			SetGraphicsMode(value);
			AutoMode = value;
		}
	}
	else
	{
		SetGraphicsMode(AutoMode);
	}
	if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo)))
	{
		printf(u"Graphics mode %d: %dx%d\r\n", AutoMode, info->HorizontalResolution, info->VerticalResolution);
	}

	puts(u"ChaiOS 0.09 UEFI Loader\r\n");
	int majorver = SystemTable->Hdr.Revision / (1 << 16);
	int minorver = SystemTable->Hdr.Revision % (1 << 16);
	printf(u"Firmware Vendor: %s, version: %d (UEFI:%d.%d)\r\n", SystemTable->FirmwareVendor, SystemTable->FirmwareRevision, majorver, minorver);
	//Read ACPI configuration tables
	//startup_acpi(SystemTable);
	//startup_multiprocessor();

	const size_t EARLY_PAGE_STACK_SIZE = 1024*1024;
	EFI_PHYSICAL_ADDRESS earlyPhypageStack = 0;
	if (EFI_ERROR(SystemTable->BootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, EARLY_PAGE_STACK_SIZE / EFI_PAGE_SIZE, &earlyPhypageStack)))
	{
		puts(u"Could not allocate page stack\r\n");
		return EFI_OUT_OF_RESOURCES;
	}

	SystemTable->BootServices->SetWatchdogTimer(0, 0, 0, nullptr);

	PrepareExitBootServices();

	EfiMemoryMap map;
	map.MemMapSize = map.MapKey = map.DescriptorSize = map.DescriptorVersion = 0;

	SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, nullptr, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion);
	//Give a nice bit of room to spare (memory map can change)
	map.MemMapSize += 16 * map.DescriptorSize;
	map.memmap = (EFI_MEMORY_DESCRIPTOR*)kmalloc(map.MemMapSize);	//Allocate a nice buffer

	SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, map.memmap, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion);
	printf(u"EFI Memory Map: Descriptor size %d\n", map.DescriptorSize);
#if 0
	//Dump the UEFI memory map to a file for testing
	EFI_FILE* file = OpenFile(u"efimap.dat", "w");
	if (!file)
	{
		printf(u"Error: could not open %s: %s\r\n", u"efimap.dat", getError(getErrno()));
	}
	WriteFile(map.memmap, 1, map.MemMapSize, file);
	CloseFile(file);
#endif
	if (EFI_ERROR(Status = SystemTable->BootServices->ExitBootServices(ImageHandle, map.MapKey)))
	{
		printf(u"Failed to exit boot services: %s\r\n", getError(Status));
		UINTN index;
		SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &index);
		return EFI_SUCCESS;
	}
	//We need to take control of the hardware now. Setup basic memory management
	setLiballocAllocator(nullptr, nullptr);

	InitializePmmngr(map, (void*)earlyPhypageStack, EARLY_PAGE_STACK_SIZE);
	puts(u"Physical memory manager intialized\n");
	arch_initialize_paging();
	puts(u"Paging initialized\n");
	setLiballocAllocator(&arch_allocate_pages, &arch_free_pages);
	//Now load the OS!
	bootfile = nullptr;
	kimage_entry kentry = nullptr;
	KLOAD_HANDLE kernel = NULL;
	while (bootfile = iterateBootFiles(bootfile))
	{
		printf(u"Boot file: %s @ %x, length %d, type %d\n", bootfile->fileName, bootfile->loadLocation, bootfile->fileSize, bootfile->bootType);
		if (!bootfile->loadLocation)
			continue;
		if (bootfile->bootType == CHAIOS_DLL)
		{
			KLOAD_HANDLE dll = LoadImage(bootfile->loadLocation, bootfile->fileName);
			if (GetProcAddress(dll, "memcpy"))
			{
				set_memcpy((memcpy_proc)GetProcAddress(dll, "memcpy"));
			}
		}
		else if (bootfile->bootType == CHAIOS_KERNEL)
		{
			kernel = LoadImage(bootfile->loadLocation, bootfile->fileName);
			kentry = GetEntryPoint(kernel);
		}
	}

	size_t kstacksize = GetStackSize(kernel);

	if (!paging_map(stackaddr, PADDR_T_MAX, kstacksize, PAGE_ATTRIBUTE_WRITABLE))
	{
		puts(u"Error: could not allocate kernel stack\n");
		while (1);
	}

	KERNEL_BOOT_INFO bootinfo;
	fill_pmmngr_info(bootinfo.pmmngr_info);
	fill_arch_paging_info(bootinfo.paging_info);
	fill_modloader_info(bootinfo.modloader_info);
	get_framebuffer_info(bootinfo.fbinfo);
	populate_kterm_info(bootinfo.kterm_status);
	bootinfo.efi_system_table = SystemTable;
	bootinfo.memory_map = &map;
	bootinfo.loaded_files = &bootfiles;
	bootinfo.boottype = CHAIOS_BOOT_TYPE_UEFI;
	bootinfo.printf_proc = &printf;
	bootinfo.puts_proc = &puts;

	printf(u"Success: Kernel entry point at %x, stack at %x, length %x\n", kentry, stackaddr, kstacksize);
	call_kernel(&bootinfo, kentry, stackaddr, kstacksize);
	puts(u"Kernel returned");
	while (1);
}
コード例 #9
0
ファイル: SPUThread.cpp プロジェクト: hminth/rpcs3
u64 SPUThread::GetFreeStackSize() const
{
	return (GetStackAddr() + GetStackSize()) - GPR[1]._u32[3];
}
コード例 #10
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
int32 AItem::GetRemainingSpace() {
	return GetStackSize() - GetAmount();
}
コード例 #11
0
ファイル: ustack.hpp プロジェクト: BOuissem/openhyperflow2d
T& UStack<T>::Top() {
    return(*this)[GetStackSize()-1];
}
コード例 #12
0
ファイル: ustack.hpp プロジェクト: BOuissem/openhyperflow2d
unsigned int UStack<T>::Push(T* pt)
{
    UArray<T>::AddElement(pt);
    return GetStackSize();
}
コード例 #13
0
ファイル: main.c プロジェクト: apkbox/lpc_testbed
int main()
{
    UART_CFG_Type uart_config;
    UART_FIFO_CFG_Type uart_fifo_config;
    TIM_TIMERCFG_Type timer_config;
    TIM_MATCHCFG_Type timer_match;
    OS_TID uart_task_id = 0;
    OS_TID activity_task_id = 0;
    uint32_t reset_flags = 0;

    reset_flags = LPC_SYSCON->SYSRSTSTAT;

    SEQ_Initialize();
    PROTO_Reset();
    PROTO_SetHandlers(g_protocol_handlers);

    SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);

    // Reset pin
    IOCON_SetPinFunc(IOCON_PIO0_0, PIO0_0_FUN_RESET);

    // Status LED pin
    ACTIVITY_SET_PIN();
    GPIO_SetDir(ACTIVITY_PORT, ACTIVITY_PIN, 1);
    GPIO_ResetBits(ACTIVITY_PORT, ACTIVITY_PIN);

    // Timer activity LED pin
    TIMER_ACTIVITY_SET_PIN();
    GPIO_SetDir(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN, 1);
    GPIO_ResetBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN);

    // RGB control
    RED_SET_PIN();
    GREEN_SET_PIN();
    BLUE_SET_PIN();
    GPIO_SetDir(RED_PORT, RED_PIN, 1);
    GPIO_SetDir(GREEN_PORT, GREEN_PIN, 1);
    GPIO_SetDir(BLUE_PORT, BLUE_PIN, 1);
    GPIO_ResetBits(RED_PORT, RED_PIN);
    GPIO_ResetBits(GREEN_PORT, GREEN_PIN);
    GPIO_ResetBits(BLUE_PORT, BLUE_PIN);

    timer_config.PrescaleOption = TIM_PRESCALE_TICKVAL;
    timer_config.PrescaleValue = 1;
    TIM_Init(LPC_TMR32B0, TIM_TIMER_MODE, &timer_config);

    timer_match.MatchChannel = 0;
    timer_match.IntOnMatch = ENABLE;
    timer_match.StopOnMatch = DISABLE;
    timer_match.ResetOnMatch = ENABLE;
    timer_match.ExtMatchOutputType = 0;
    timer_match.MatchValue = SystemCoreClock / (TICKS_PER_SECOND * 256);
    TIM_ConfigMatch(LPC_TMR32B0, &timer_match);

    TIM_Cmd(LPC_TMR32B0, ENABLE);
    NVIC_EnableIRQ(TIMER_32_0_IRQn);

    // UART
    IOCON_SetPinFunc(IOCON_PIO1_6, PIO1_6_FUN_RXD);   /* UART RXD - PIO1_6 */
    IOCON_SetPinFunc(IOCON_PIO1_7, PIO1_7_FUN_TXD);   /* UART RXD - PIO1_7 */

    uart_config.Baud_rate = 115200;
    uart_config.Databits = UART_DATABIT_8;
    uart_config.Parity = UART_PARITY_NONE;
    uart_config.Stopbits = UART_STOPBIT_1;

    UART_Init(LPC_UART, &uart_config);

    uart_fifo_config.FIFO_Level = UART_FIFO_TRGLEV0;
    uart_fifo_config.FIFO_ResetRxBuf = ENABLE;
    uart_fifo_config.FIFO_ResetTxBuf = ENABLE;
    UART_FIFOConfig(LPC_UART, &uart_fifo_config);

    UART_TxCmd(LPC_UART, ENABLE);

    // SPI
    CL632_Init();
    // Select page 0 and no paging access
    CL632_SpiWriteByte(0x00, 0x00);
    CL632_SpiWriteByte(0x00, 0x00);

    // LCD
    // LCD backlite control
    LCD_BACKLITE_SET_PIN();
    GPIO_SetDir(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN, 1);
    GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN);

    // LCD Data bus
    LCD_DATA_SET_PINS();
    GPIO_SetDir(LCD_DATA_PORT, LCD_DATA_BUS, 1);
    GPIO_ResetBits(LCD_DATA_PORT, LCD_DATA_BUS);

    LCD_RS_SET_PIN();
    GPIO_SetDir(LCD_RS_PORT, LCD_RS_PIN, 1);
    GPIO_ResetBits(LCD_RS_PORT, LCD_RS_PIN);

    LCD_RW_SET_PIN();
    GPIO_SetDir(LCD_RW_PORT, LCD_RW_PIN, 1);
    GPIO_ResetBits(LCD_RW_PORT, LCD_RW_PIN);

    LCD_E_SET_PIN();
    GPIO_SetDir(LCD_E_PORT, LCD_E_PIN, 1);
    GPIO_ResetBits(LCD_E_PORT, LCD_E_PIN);

    KS0066_PowerUpDelay();
    KS0066_FunctionSet();
    KS0066_WaitForIdle();
    KS0066_DisplayOnOffControl(KS0066_DISPCTL_DISPLAY_ON);
    KS0066_WaitForIdle();
    KS0066_ClearDisplay();
    KS0066_WaitForIdle();

    CoInitOS();
    GPIO_SetBits(ACTIVITY_PORT, ACTIVITY_PIN);

    uart_task_id = CoCreateTask(uartTask, NULL, UART_TASK_PRIORITY,
            GetStackTop(uartTaskStack), GetStackSize(uartTaskStack));

    activity_task_id = CoCreateTask(activityTask, NULL, ACTIVITY_TASK_PRIORITY,
            GetStackTop(activityTaskStack), GetStackSize(activityTaskStack));

    if (uart_task_id == E_CREATE_FAIL || activity_task_id == E_CREATE_FAIL) {
        UART_PrintString("INIT ERROR");
        UART_PrintString(kNewLine);
    }

    if (reset_flags & 0x01)
        UART_PrintString("RST:PU");
    else if (reset_flags & 0x02)
        UART_PrintString("RST:RST");
    else if (reset_flags & 0x04)
        UART_PrintString("RST:WDT");
    else if (reset_flags & 0x08)
        UART_PrintString("RST:BOD");
    else if (reset_flags & 0x10)
        UART_PrintString("RST:SOFT");
    else
        UART_PrintString("RST");

    UART_PrintString(kNewLine);

    PrintVersionString(UART_WriteChar);
    UART_PrintString(kNewLine);
    func_printf_nofloat(UART_WriteChar, "COOS:%d\r\n", CoGetOSVersion());

    KS0066_WriteString("V:" __DATE__ " " __TIME__, KS0066_WRAP_FLAG);

    CoStartOS();

    //while (1) {
    //}

    return 0;
}
コード例 #14
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
bool AItem::HasSpace() {
	return GetAmount() < GetStackSize();
}
コード例 #15
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
AItem* AItem::Copy() {
	return CreateItem(GetWorld(), GetItemOwner(), GetName(), GetAmount(), GetGrade(), GetQuality(), GetStackSize());
}
コード例 #16
0
ファイル: tclUnixInit.c プロジェクト: nzavagli/UnrealPy
int
TclpGetCStackParams(
    int **stackBoundPtr)
{
    int result = TCL_OK;
    size_t stackSize = 0;	/* The size of the current stack. */
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
				/* Most variables are actually in a
				 * thread-specific data block to minimise the
				 * impact on the stack. */
#ifdef TCL_CROSS_COMPILE
    if (stackGrowsDown == -1) {
	/*
	 * Not initialised!
	 */

	stackGrowsDown = StackGrowsDown(&result);
    }
#endif
    
    /*
     * The first time through in a thread: record the "outermost" stack
     * frame and inquire with the OS about the stack size.
     */

    if (tsdPtr->outerVarPtr == NULL) {
	tsdPtr->outerVarPtr = &result;
	result = GetStackSize(&stackSize);
	if (result != TCL_OK) {
	    /* Can't check, assume it always succeeds */
#ifdef TCL_CROSS_COMPILE
	    stackGrowsDown = 1;
#endif
	    tsdPtr->stackBound = NULL;
	    goto done;
	}
    }

    if (stackSize || (tsdPtr->stackBound &&
	    ((stackGrowsDown && (&result < tsdPtr->stackBound)) ||
	    (!stackGrowsDown && (&result > tsdPtr->stackBound))))) {
	/*
	 * Either the thread's first pass or stack failure: set the params
	 */

	if (!stackSize) {
	    /*
	     * Stack failure: if we didn't already blow up, we are within the
	     * safety area. Recheck with the OS in case the stack was grown. 
	     */
	    result = GetStackSize(&stackSize);
	    if (result != TCL_OK) {
		/* Can't check, assume it always succeeds */
#ifdef TCL_CROSS_COMPILE
		stackGrowsDown = 1;
#endif
		tsdPtr->stackBound = NULL;
		goto done;
	    }
	}

	if (stackGrowsDown) {
	    tsdPtr->stackBound = (int *) ((char *)tsdPtr->outerVarPtr -
		    stackSize);
	} else {
	    tsdPtr->stackBound = (int *) ((char *)tsdPtr->outerVarPtr +
		    stackSize);
	}
    }

    done:
    *stackBoundPtr = tsdPtr->stackBound;
    return stackGrowsDown;
}
コード例 #17
0
ファイル: PPUThread.cpp プロジェクト: ItzWarty/rpcs3
u64 PPUThread::GetFreeStackSize() const
{
	return (GetStackAddr() + GetStackSize()) - GPR[1];
}
コード例 #18
0
CGUIDialogBoxeeWizardBase* CBoxeeLoginWizardManager::HandleNextAction(CGUIDialogBoxeeWizardBase* pDialog, bool& addCurrentDlgToStack)
{
  if (!pDialog)
  {
    CLog::Log(LOGERROR,"CBoxeeLoginWizardManager::HandleNextAction - Enter function with a NULL pointer (blw)(digwiz)");
    return NULL;
  }

  int id = pDialog->GetID();

  CLog::Log(LOGDEBUG,"CBoxeeLoginWizardManager::HandleNextAction - Enter function with [id=%d] (blw)(digwiz)",id);

  CGUIDialogBoxeeWizardBase* pNextDialog = NULL;

  switch(id)
  {
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_CHOOSE_USER_TO_ADD:
  {
    CGUIDialogBoxeeLoginWizardChooseUserToAddType* pAddUserDlg = (CGUIDialogBoxeeLoginWizardChooseUserToAddType*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_CHOOSE_USER_TO_ADD);
    if (!pAddUserDlg)
    {
      CLog::Log(LOGERROR,"CBoxeeLoginWizardManager::HandleNextAction - FAILED to get DialogBoxeeLoginWizardAddUser (blw)(digwiz)");
      break;
    }

    if (pAddUserDlg->IsAddingNewUser())
    {
      pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_ADD_NEW_USER);
      CLog::Log(LOGDEBUG,"CBoxeeLoginWizardManager::HandleNextAction - IsAddingNewUser returned TRUE (blw)(digwiz)");
    }
    else
    {
      CLog::Log(LOGDEBUG,"CBoxeeLoginWizardManager::HandleNextAction - IsAddingNewUser returned FALSE. Set next dialog to ADD_EXISTING_USER (blw)(digwiz)");
      pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_ADD_EXISTING_USER);
    }

    IsAddingDialogToStack(pNextDialog,addCurrentDlgToStack);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_ADD_EXISTING_USER:
  {
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_MENU_CUST);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_ADD_NEW_USER:
  {
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_NEW_USER_DETAILS);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_NEW_USER_DETAILS:
  {
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_TOU);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_TOU:
  {
#ifdef HAS_EMBEDDED
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_CONNECT_SOCIAL_SERVICES);
#else
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_MENU_CUST);
#endif
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_CONNECT_SOCIAL_SERVICES:
  {
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_MENU_CUST);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_MENU_CUST:
  {
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_CONFIRMATION);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_CONFIRMATION:
  {
#ifdef HAS_EMBEDDED
    if (strcmpi(BoxeeUtils::GetPlatformStr(),"dlink.dsm380") == 0)
    {
      CLog::Log(LOGDEBUG,"CBoxeeLoginWizardManager::HandleNextAction - [platform=%s] -> show RemoteQuickTip (blw)(digwiz)",BoxeeUtils::GetPlatformStr());
      pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_QUICK_TIP);
    }
    else
    {
      pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_QUICK_TIP_AIRPLAY);
    }
#else
    //pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_QUICK_TIP_AIRPLAY);
    SetWizardComplete(true);
#endif
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_QUICK_TIP:
  {
    pNextDialog = (CGUIDialogBoxeeWizardBase*)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_QUICK_TIP_AIRPLAY);
  }
  break;
  case WINDOW_DIALOG_BOXEE_LOGIN_WIZARD_QUICK_TIP_AIRPLAY:
  {
    SetWizardComplete(true);
  }
  break;
  default:
  {
    CLog::Log(LOGERROR,"CBoxeeLoginWizardManager::HandleNextAction - FAILED to handle WindowId [%d] (blw)(digwiz)",id);
  }
  break;
  }

  if (addCurrentDlgToStack)
  {
    AddToStack(id);
  }
  else
  {
    CLog::Log(LOGDEBUG,"CBoxeeLoginWizardManager::HandleNextAction - Not adding [id=%d] to stack. [addCurrentDlgToStack=%d][DialogStackSize=%d] (blw)(digwiz)",id,addCurrentDlgToStack,GetStackSize());
  }

  CLog::Log(LOGDEBUG,"CBoxeeLoginWizardManager::HandleNextAction - Exit function and return [NextDialog=%p] for [id=%d] (blw)(digwiz)",pNextDialog,id);

  return pNextDialog;
}