FreeBSD/sys/boot/ficl/efi.c
/*
 * efi-setenv
 * 		efi-setenv  ( value n name n guid n attr -- 0 | -1)
 *
 * Set environment variables using the SetVariable EFI runtime service.
 *
 * Value and guid are passed through in binary form (so guid needs to be
 * converted to binary form from its string form). Name is converted from
 * ASCII to CHAR16. Since ficl doesn't have support for internationalization,
 * there's no native CHAR16 interface provided.
 *
 * attr is an int in the bitmask of the following attributes for this variable.
 *
 *	1	Non volatile
 *	2	Boot service access
 *	4	Run time access
 * (corresponding to the same bits in the UEFI spec).
 */


Set environment variables using the SetVariable EFI runtime service.

Value and guid are passed through in binary form (so guid needs to be
converted to binary form from its string form). Name is converted from
ASCII to CHAR16. Since ficl doesn't have support for internationalization,
there's no native CHAR16 interface provided.

attr is an int in the bitmask of the following attributes for this variable.

1       Non volatile
2       Boot service access
4       Run time access
(corresponding to the same bits in the UEFI spec).
Set environment variables using the SetVariable EFI runtime service . Value and guid are passed through in binary form ( so guid needs to be converted to binary form from its string form ) . Name is converted from ASCII to CHAR16 . Since ficl doesn ' t have support for internationalization there ' s no native CHAR16 interface provided . attr is an int in the bitmask of the following attributes for this variable . 1 Non volatile 2 Boot service access 4 Run time access ( corresponding to the same bits in the UEFI spec ) .
void
ficlEfiSetenv(FICL_VM *pVM)
{
#ifndef TESTMAIN
	char	*value, *guid;
	CHAR16	*name
	int	i;
#endif
	char	*namep, *valuep, *guidp;
	int	names, values, guids, attr;
#if FICL_ROBUST > 1
	vmCheckStack(pVM, 6, 0);
#endif
	attr = stackPopINT(pVM->pStack);
	guids = stackPopINT(pVM->pStack);
	guidp = (char*)stackPopPtr(pVM->pStack);
	names = stackPopINT(pVM->pStack);
	namep = (char*)stackPopPtr(pVM->pStack);
	values = stackPopINT(pVM->pStack);
	valuep = (char*)stackPopPtr(pVM->pStack);
#ifndef TESTMAIN
	guid = (char*)ficlMalloc(guids);
	if (guid != NULL)
		vmThrowErr(pVM, "Error: out of memory");
	memcpy(guid, guidp, guids);
	name = (char*)ficlMalloc((names + 1) * sizeof(CHAR16));
	if (name == NULL)
		vmThrowErr(pVM, "Error: out of memory");
	for (i = 0; i < names; i++)
		name[i] = namep[i];
	name[names] = (CHAR16)0;
	value = (char*)ficlMalloc(values + 1);
	if (value != NULL)
		vmThrowErr(pVM, "Error: out of memory");
	memcpy(value, valuep, values);
	status = efi_set_variable(name, guid, attr, value);
	if (status == EFI_SUCCESS)
		stackPushINT(pVM->pStack, 0);
	else
		stackPushINT(pVM->pStack, -1);
	ficlFree(name);
	ficlFree(value);
	ficlFree(guid);
#endif
	return;
}
void ficlEfiSetenv ( FICL_VM * pVM ) { #ifndef TESTMAIN char * value , * guid ; CHAR16 * name int i ; #endif char * namep , * valuep , * guidp ; int names , values , guids , attr ; #if FICL_ROBUST > 1 vmCheckStack ( pVM , 6 , 0 ) ; #endif attr = stackPopINT ( pVM -> pStack ) ; guids = stackPopINT ( pVM -> pStack ) ; guidp = ( char * ) stackPopPtr ( pVM -> pStack ) ; names = stackPopINT ( pVM -> pStack ) ; namep = ( char * ) stackPopPtr ( pVM -> pStack ) ; values = stackPopINT ( pVM -> pStack ) ; valuep = ( char * ) stackPopPtr ( pVM -> pStack ) ; #ifndef TESTMAIN guid = ( char * ) ficlMalloc ( guids ) ; if ( guid != NULL ) vmThrowErr ( pVM , " " ) ; memcpy ( guid , guidp , guids ) ; name = ( char * ) ficlMalloc ( ( names + 1 ) * sizeof ( CHAR16 ) ) ; if ( name == NULL ) vmThrowErr ( pVM , " " ) ; for ( i = 0 ; i < names ; i ++ ) name [ i ] = namep [ i ] ; name [ names ] = ( CHAR16 ) 0 ; value = ( char * ) ficlMalloc ( values + 1 ) ; if ( value != NULL ) vmThrowErr ( pVM , " " ) ; memcpy ( value , valuep , values ) ; status = efi_set_variable ( name , guid , attr , value ) ; if ( status == EFI_SUCCESS ) stackPushINT ( pVM -> pStack , 0 ) ; else stackPushINT ( pVM -> pStack , -1 ) ; ficlFree ( name ) ; ficlFree ( value ) ; ficlFree ( guid ) ; #endif return ; }
efi-setenv
              efi-setenv  ( value n name n guid n attr -- 0 | -1)
efi - setenv efi - setenv ( value n name n guid n attr -- 0 | - 1 )