-- -------------------------------------------------------------------- -- -- Copyright 1995 by IEEE. All rights reserved. -- -- This source file is considered by the IEEE to be an essential part of the use -- of the standard 1076.3 and as such may be distributed without change, except -- as permitted by the standard. This source file may not be sold or distributed -- for profit. This package may be modified to include additional data required -- by tools, but must in no way change the external interfaces or simulation -- behaviour of the description. It is permissible to add comments and/or -- attributes to the package declarations, but not to change or delete any -- original lines of the approved package declaration. The package body may be -- changed only in accordance with the terms of clauses 7.1 and 7.2 of the -- standard. -- -- Title : Standard VHDL Synthesis Package (1076.3, NUMERIC_STD) -- -- Library : This package shall be compiled into a library symbolically -- : named IEEE. -- -- Developers : IEEE DASC Synthesis Working Group, PAR 1076.3 -- -- Purpose : This package defines numeric types and arithmetic functions -- : for use with synthesis tools. Two numeric types are defined: -- : -- > UNSIGNED: represents UNSIGNED number in vector form -- : -- > SIGNED: represents a SIGNED number in vector form -- : The base element type is type STD_LOGIC. -- : The leftmost bit is treated as the most significant bit. -- : Signed vectors are represented in two's complement form. -- : This package contains overloaded arithmetic operators on -- : the SIGNED and UNSIGNED types. The package also contains -- : useful type conversions functions. -- : -- : If any argument to a function is a null array, a null array is -- : returned (exceptions, if any, are noted individually). -- -- Limitation : -- -- Note : No declarations or definitions shall be included in, -- : or excluded from this package. The "package declaration" -- : defines the types, subtypes and declarations of -- : NUMERIC_STD. The NUMERIC_STD package body shall be -- : considered the formal definition of the semantics of -- : this package. Tool developers may choose to implement -- : the package body in the most efficient manner available -- : to them. -- -- -------------------------------------------------------------------- -- modification history : -- -------------------------------------------------------------------- -- Version: 2.4 -- Date : 12 April 1995 -- ----------------------------------------------------------------------------- --============================================================================== --============================= Package Body =================================== --============================================================================== package body NUMERIC_STD is -- null range array constants constant NAU: UNSIGNED(0 downto 1) := (others => '0'); constant NAS: SIGNED(0 downto 1) := (others => '0'); -- implementation controls constant NO_WARNING: BOOLEAN := FALSE; -- default to emit warnings --=========================Local Subprograms ================================= function MAX (LEFT, RIGHT: INTEGER) return INTEGER is begin if LEFT > RIGHT then return LEFT; else return RIGHT; end if; end MAX; function MIN (LEFT, RIGHT: INTEGER) return INTEGER is begin if LEFT < RIGHT then return LEFT; else return RIGHT; end if; end MIN; function SIGNED_NUM_BITS (ARG: INTEGER) return NATURAL is variable NBITS: NATURAL; variable N: NATURAL; begin if ARG >= 0 then N := ARG; else N := -(ARG+1); end if; NBITS := 1; while N > 0 loop NBITS := NBITS+1; N := N / 2; end loop; return NBITS; end SIGNED_NUM_BITS; function UNSIGNED_NUM_BITS (ARG: NATURAL) return NATURAL is variable NBITS: NATURAL; variable N: NATURAL; begin N := ARG; NBITS := 1; while N > 1 loop NBITS := NBITS+1; N := N / 2; end loop; return NBITS; end UNSIGNED_NUM_BITS; ------------------------------------------------------------------------ -- this internal function computes the addition of two UNSIGNED -- with input CARRY -- * the two arguments are of the same length function ADD_UNSIGNED (L, R: UNSIGNED; C: STD_LOGIC) return UNSIGNED is constant L_LEFT: INTEGER := L'LENGTH-1; alias XL: UNSIGNED(L_LEFT downto 0) is L; alias XR: UNSIGNED(L_LEFT downto 0) is R; variable RESULT: UNSIGNED(L_LEFT downto 0); variable CBIT: STD_LOGIC := C; begin for I in 0 to L_LEFT loop RESULT(I) := CBIT xor XL(I) xor XR(I); CBIT := (CBIT and XL(I)) or (CBIT and XR(I)) or (XL(I) and XR(I)); end loop; return RESULT; end ADD_UNSIGNED; -- this internal function computes the addition of two SIGNED -- with input CARRY -- * the two arguments are of the same length function ADD_SIGNED (L, R: SIGNED; C: STD_LOGIC) return SIGNED is constant L_LEFT: INTEGER := L'LENGTH-1; alias XL: SIGNED(L_LEFT downto 0) is L; alias XR: SIGNED(L_LEFT downto 0) is R; variable RESULT: SIGNED(L_LEFT downto 0);
/*
* This file is part of the flashrom project.
*
* Copyright (C) 2022 The Chromium OS Authors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "libflashrom.h"
void log_rust(enum flashrom_log_level level, const char *format);
// LOG_LEVEL = 0 (ERROR) means no messages are printed.
enum flashrom_log_level current_level = 0;
static int log_c(enum flashrom_log_level level, const char *format, va_list ap)
{
static char *buf = NULL;
static int len = 0;
if (level >= current_level) {
return 0;
}
va_list ap2;
va_copy(ap2, ap);
// when buf is NULL, len is zero and this will not write to buf
int req_len = vsnprintf(buf, len, format, ap2);
va_end(ap2);
if (req_len > len) {
char *new_buf = realloc(buf, req_len + 1);
if (!new_buf) {
return 0;
}
buf = new_buf;
len = req_len + 1;
req_len = vsnprintf(buf, len, format, ap);
}
if (req_len > 0) {
log_rust(level, buf);
}
return req_len;
}
void set_log_callback()
{
flashrom_set_log_callback(log_c);
}