blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 4
721
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 5
91
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringclasses 321
values | visit_date
timestamp[ns]date 2016-08-12 09:31:09
2023-09-06 10:45:07
| revision_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| github_id
int64 426
681M
| star_events_count
int64 101
243k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 23
values | gha_event_created_at
timestamp[ns]date 2012-06-28 18:51:49
2023-09-14 21:59:16
⌀ | gha_created_at
timestamp[ns]date 2008-02-11 22:55:26
2023-08-10 11:14:58
⌀ | gha_language
stringclasses 147
values | src_encoding
stringclasses 26
values | language
stringclasses 2
values | is_vendor
bool 2
classes | is_generated
bool 2
classes | length_bytes
int64 6
10.2M
| extension
stringclasses 115
values | filename
stringlengths 3
113
| content
stringlengths 6
10.2M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
591b2bdf24439db798397bb4ed6dd9afcfad2202
|
dcbef06d5a00f07756339b9e62c684dec2fee425
|
/nuitka/build/static_src/MetaPathBasedLoaderResourceReaderFiles.c
|
282fe2831be081386bfa17181a1e4d028105f1e9
|
[
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
Nuitka/Nuitka
|
f9543d8d95bfa0b81d4e60af0dfad99fb72893a4
|
d87faf2f7e1d6ed9bfe4cf8c1d648f34307e33f2
|
refs/heads/develop
| 2023-08-28T14:00:32.861328
| 2023-08-27T09:16:45
| 2023-08-27T09:16:45
| 9,626,741
| 8,573
| 599
|
Apache-2.0
| 2023-09-13T02:49:41
| 2013-04-23T15:40:33
|
Python
|
UTF-8
|
C
| false
| false
| 19,752
|
c
|
MetaPathBasedLoaderResourceReaderFiles.c
|
// Copyright 2023, Kay Hayen, mailto:kay.hayen@gmail.com
//
// Part of "Nuitka", an optimizing Python compiler that is compatible and
// integrates with CPython, but also works on its own.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// This implements the resource reader for of C compiled modules and
// shared library extension modules bundled for standalone mode with
// newer Python.
// This file is included from another C file, help IDEs to still parse it on
// its own.
#ifdef __IDE_ONLY__
#include "nuitka/prelude.h"
#include "nuitka/unfreezing.h"
#endif
struct Nuitka_ResourceReaderFilesObject {
/* Python object folklore: */
PyObject_HEAD
// The loader entry, to know this is for one package exactly.
struct Nuitka_MetaPathBasedLoaderEntry const *m_loader_entry;
// The path relative to the entry, if e.g. joinpath is used
PyObject *m_path;
};
static PyObject *Nuitka_ResourceReaderFiles_New(PyThreadState *tstate,
struct Nuitka_MetaPathBasedLoaderEntry const *entry, PyObject *path);
static PyObject *_Nuitka_ResourceReaderFiles_GetPath(PyThreadState *tstate,
struct Nuitka_ResourceReaderFilesObject const *files) {
// Allow for absolute paths, TODO: Too lazy to have OS_PATH_JOIN at this
// time also not clearly how early JOIN2 is used, i.e. do we have importing
// available for it.
PyObject *is_abs = OS_PATH_ISABS(tstate, files->m_path);
PyObject *result;
if (is_abs == Py_True) {
#if 0
PRINT_STRING("Getting path from absolute: ");
PRINT_ITEM(files->m_path);
PRINT_NEW_LINE();
#endif
result = files->m_path;
Py_INCREF(result);
} else {
result = getModuleDirectory(tstate, files->m_loader_entry);
#if 0
PRINT_STRING("Getting path from relative: ");
PRINT_ITEM(result);
PRINT_STRING(" ");
PRINT_ITEM(files->m_path);
PRINT_NEW_LINE();
#endif
if (files->m_path != const_str_empty) {
PyObject *old = result;
result = JOIN_PATH2(result, files->m_path);
Py_DECREF(old);
}
}
Py_DECREF(is_abs);
return result;
}
static void Nuitka_ResourceReaderFiles_tp_dealloc(struct Nuitka_ResourceReaderFilesObject *files) {
Nuitka_GC_UnTrack(files);
Py_DECREF(files->m_path);
PyObject_GC_Del(files);
}
static PyObject *Nuitka_ResourceReaderFiles_tp_repr(struct Nuitka_ResourceReaderFilesObject *files) {
return PyUnicode_FromFormat("<nuitka_resource_reader_files for package '%s' file %R>", files->m_loader_entry->name,
files->m_path);
}
static PyObject *Nuitka_ResourceReaderFiles_tp_str(struct Nuitka_ResourceReaderFilesObject *files) {
PyThreadState *tstate = PyThreadState_GET();
return _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
}
// Obligatory, even if we have nothing to own
static int Nuitka_ResourceReaderFiles_tp_traverse(struct Nuitka_ResourceReaderFilesObject *files, visitproc visit,
void *arg) {
return 0;
}
// Methods that need to be implemented.
//
//
// def iterdir(self):
// """
// Yield Traversable objects from self
// """
//
static PyObject *Nuitka_ResourceReaderFiles_iterdir(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_path = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
PyObject *file_names = OS_LISTDIR(tstate, file_path);
Py_DECREF(file_path);
// TODO: Actually we ought to behave like a generator and delay this error,
// but we currently spare us the effort and raise this immediately.
if (unlikely(file_names == NULL)) {
return NULL;
}
PyObject *files_objects = MAKE_LIST_EMPTY(0);
Py_ssize_t n = PyList_GET_SIZE(file_names);
for (Py_ssize_t i = 0; i < n; i++) {
PyObject *file_name = PyList_GET_ITEM(file_names, i);
CHECK_OBJECT(file_name);
PyObject *joined = JOIN_PATH2(files->m_path, file_name);
CHECK_OBJECT(joined);
PyObject *files_object = Nuitka_ResourceReaderFiles_New(tstate, files->m_loader_entry, joined);
bool res = LIST_APPEND1(files_objects, files_object);
assert(res);
CHECK_OBJECT(files_object);
Py_DECREF(joined);
}
PyObject *result = MAKE_ITERATOR_INFALLIBLE(files_objects);
Py_DECREF(files_objects);
return result;
}
// def read_bytes(self):
// """
// Read contents of self as bytes
// """
// with self.open('rb') as strm:
// return strm.read()
//
static PyObject *Nuitka_ResourceReaderFiles_read_bytes(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_name = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
if (unlikely(file_name == NULL)) {
return NULL;
}
return GET_FILE_BYTES(tstate, file_name);
}
// def read_text(self, encoding=None):
// """
// Read contents of self as text
// """
// with self.open(encoding=encoding) as strm:
// return strm.read()
static char const *_kw_list_encoding[] = {"encoding", NULL};
static PyObject *Nuitka_ResourceReaderFiles_read_text(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyObject *encoding = NULL;
int res = PyArg_ParseTupleAndKeywords(args, kwds, "|O:read_text", (char **)_kw_list_encoding, &encoding);
if (unlikely(res == 0)) {
return NULL;
}
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_name = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
if (unlikely(file_name == NULL)) {
return NULL;
}
PyObject *file_object = BUILTIN_OPEN_SIMPLE(tstate, file_name, "r", true, encoding);
Py_DECREF(file_name);
if (unlikely(file_object == NULL)) {
return NULL;
}
PyObject *read_method = LOOKUP_ATTRIBUTE(tstate, file_object, const_str_plain_read);
Py_DECREF(file_object);
if (unlikely(read_method == NULL)) {
return NULL;
}
PyObject *result = CALL_FUNCTION_NO_ARGS(PyThreadState_GET(), read_method);
Py_DECREF(read_method);
return result;
}
// @abc.abstractmethod
// def is_dir(self) -> bool:
// """
// Return True if self is a dir
// """
//
static PyObject *Nuitka_ResourceReaderFiles_is_dir(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_name = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
PyObject *result = OS_PATH_FILE_ISDIR(tstate, file_name);
Py_DECREF(file_name);
return result;
}
// @abc.abstractmethod
// def is_file(self) -> bool:
// """
// Return True if self is a file
// """
static PyObject *Nuitka_ResourceReaderFiles_is_file(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_name = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
PyObject *result = OS_PATH_FILE_ISFILE(tstate, file_name);
Py_DECREF(file_name);
return result;
}
static char const *_kw_list_joinpath[] = {"child", NULL};
// @abc.abstractmethod
// def joinpath(self, child):
// """
// Return Traversable child in self
// """
//
// Functions out there, some accept "child", and accept varargs, lets be compatible with both.
static PyObject *Nuitka_ResourceReaderFiles_joinpath(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyObject *joined = files->m_path;
if (kwds != NULL) {
PyObject *child;
int res = PyArg_ParseTupleAndKeywords(args, kwds, "O:joinpath", (char **)_kw_list_joinpath, &child);
if (unlikely(res == 0)) {
return NULL;
}
joined = JOIN_PATH2(joined, child);
if (unlikely(joined == NULL)) {
return NULL;
}
} else {
Py_INCREF(joined);
Py_ssize_t n = PyTuple_GET_SIZE(args);
for (Py_ssize_t i = 0; i < n; ++i) {
PyObject *child = PyTuple_GET_ITEM(args, i);
PyObject *old = joined;
if (old == const_str_empty) {
joined = child;
Py_INCREF(child);
} else {
joined = JOIN_PATH2(joined, child);
}
Py_DECREF(old);
if (unlikely(joined == NULL)) {
return NULL;
}
}
}
PyThreadState *tstate = PyThreadState_GET();
PyObject *result = Nuitka_ResourceReaderFiles_New(tstate, files->m_loader_entry, joined);
Py_DECREF(joined);
return result;
}
PyObject *Nuitka_ResourceReaderFiles_nb_truediv(struct Nuitka_ResourceReaderFilesObject *files, PyObject *arg) {
PyObject *joined;
if (files->m_path == const_str_empty) {
joined = arg;
Py_INCREF(arg);
} else {
joined = JOIN_PATH2(files->m_path, arg);
}
if (unlikely(joined == NULL)) {
return NULL;
}
PyThreadState *tstate = PyThreadState_GET();
PyObject *result = Nuitka_ResourceReaderFiles_New(tstate, files->m_loader_entry, joined);
return result;
}
// @abc.abstractmethod
// def open(self, mode='r', *args, **kwargs):
// """
// mode may be 'r' or 'rb' to open as text or binary. Return a handle
// suitable for reading (same as pathlib.Path.open).
//
// When opening as text, accepts encoding parameters such as those
// accepted by io.TextIOWrapper.
// """
//
static char const *_kw_list_open[] = {"mode", "buffering", "encoding", "errors", "newline", NULL};
static PyObject *Nuitka_ResourceReaderFiles_open(struct Nuitka_ResourceReaderFilesObject *files, PyObject *args,
PyObject *kwds) {
PyObject *mode = NULL;
PyObject *buffering = NULL;
PyObject *encoding = NULL;
PyObject *errors = NULL;
PyObject *newline = NULL;
int res = PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO:open", (char **)_kw_list_open, &mode, &buffering,
&encoding, &errors, &newline);
if (unlikely(res == 0)) {
return NULL;
}
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_name = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
return BUILTIN_OPEN(tstate, file_name, mode, buffering, encoding, errors, newline, NULL, NULL);
}
static PyObject *Nuitka_ResourceReaderFiles_as_file(struct Nuitka_ResourceReaderFilesObject *files) {
CHECK_OBJECT(files);
Py_INCREF(files);
return (PyObject *)files;
}
static PyObject *Nuitka_ResourceReaderFiles_enter(struct Nuitka_ResourceReaderFilesObject *files) {
CHECK_OBJECT(files);
Py_INCREF(files);
return (PyObject *)files;
}
static PyObject *Nuitka_ResourceReaderFiles_exit(struct Nuitka_ResourceReaderFilesObject *files) {
CHECK_OBJECT(files);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *Nuitka_ResourceReaderFiles_fspath(struct Nuitka_ResourceReaderFilesObject *files) {
PyThreadState *tstate = PyThreadState_GET();
return _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
}
static PyObject *Nuitka_ResourceReaderFiles_absolute(struct Nuitka_ResourceReaderFilesObject *files) {
PyThreadState *tstate = PyThreadState_GET();
PyObject *path = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
PyObject *abspath = OS_PATH_ABSPATH(tstate, path);
if (unlikely(abspath == NULL)) {
return NULL;
}
return Nuitka_ResourceReaderFiles_New(tstate, files->m_loader_entry, abspath);
}
static PyMethodDef Nuitka_ResourceReaderFiles_methods[] = {
{"iterdir", (PyCFunction)Nuitka_ResourceReaderFiles_iterdir, METH_NOARGS, NULL},
{"read_bytes", (PyCFunction)Nuitka_ResourceReaderFiles_read_bytes, METH_NOARGS, NULL},
{"read_text", (PyCFunction)Nuitka_ResourceReaderFiles_read_text, METH_VARARGS | METH_KEYWORDS, NULL},
{"is_dir", (PyCFunction)Nuitka_ResourceReaderFiles_is_dir, METH_NOARGS, NULL},
{"is_file", (PyCFunction)Nuitka_ResourceReaderFiles_is_file, METH_NOARGS, NULL},
{"joinpath", (PyCFunction)Nuitka_ResourceReaderFiles_joinpath, METH_VARARGS | METH_KEYWORDS, NULL},
{"open", (PyCFunction)Nuitka_ResourceReaderFiles_open, METH_VARARGS | METH_KEYWORDS, NULL},
{"__enter__", (PyCFunction)Nuitka_ResourceReaderFiles_enter, METH_NOARGS, NULL},
{"__exit__", (PyCFunction)Nuitka_ResourceReaderFiles_exit, METH_VARARGS, NULL},
{"__fspath__", (PyCFunction)Nuitka_ResourceReaderFiles_fspath, METH_NOARGS, NULL},
{"absolute", (PyCFunction)Nuitka_ResourceReaderFiles_absolute, METH_NOARGS, NULL},
// Nuitka specific, for "importlib.resource.as_file" overload.
{"as_file", (PyCFunction)Nuitka_ResourceReaderFiles_as_file, METH_NOARGS, NULL},
{NULL}};
// @abc.abstractproperty
// def name(self) -> str:
// """
// The base name of this object without any parent references.
// """
static PyObject *Nuitka_ResourceReaderFiles_get_name(struct Nuitka_ResourceReaderFilesObject *files) {
PyThreadState *tstate = PyThreadState_GET();
PyObject *file_name = _Nuitka_ResourceReaderFiles_GetPath(tstate, files);
PyObject *result = OS_PATH_BASENAME(tstate, file_name);
Py_DECREF(file_name);
return result;
}
static int Nuitka_ResourceReaderFiles_set_name(struct Nuitka_FunctionObject *files, PyObject *value) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_AttributeError, "readonly attribute");
return -1;
}
static PyGetSetDef Nuitka_ResourceReaderFiles_getset[] = {
{(char *)"name", (getter)Nuitka_ResourceReaderFiles_get_name, (setter)Nuitka_ResourceReaderFiles_set_name, NULL},
{NULL}};
// Initialized during readying the type for nb_truediv
static PyNumberMethods Nuitka_resource_reader_as_number = {0};
static PyTypeObject Nuitka_ResourceReaderFiles_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "nuitka_resource_reader_files",
sizeof(struct Nuitka_ResourceReaderFilesObject), // tp_basicsize
0, // tp_itemsize
(destructor)Nuitka_ResourceReaderFiles_tp_dealloc, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_reserved
(reprfunc)Nuitka_ResourceReaderFiles_tp_repr, // tp_repr
&Nuitka_resource_reader_as_number, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
(reprfunc)Nuitka_ResourceReaderFiles_tp_str, // tp_str
0, // tp_getattro (PyObject_GenericGetAttr)
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
0, // tp_doc
(traverseproc)Nuitka_ResourceReaderFiles_tp_traverse, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter (PyObject_SelfIter)
0, // tp_iternext
Nuitka_ResourceReaderFiles_methods, // tp_methods
0, // tp_members
Nuitka_ResourceReaderFiles_getset, // tp_getset
};
#if PYTHON_VERSION >= 0x390
static void registerResourceReaderFiles(PyThreadState *tstate, PyObject *resources_module) {
PyObject *as_file = LOOKUP_ATTRIBUTE(tstate, resources_module, const_str_plain_as_file);
if (likely(as_file != NULL)) {
PyObject *our_as_file =
LOOKUP_ATTRIBUTE(tstate, (PyObject *)&Nuitka_ResourceReaderFiles_Type, const_str_plain_as_file);
CHECK_OBJECT(our_as_file);
PyObject *args[2] = {(PyObject *)&Nuitka_ResourceReaderFiles_Type, our_as_file};
PyObject *register_result = CALL_METHOD_WITH_ARGS2(tstate, as_file, const_str_plain_register, args);
if (unlikely(register_result == NULL)) {
CLEAR_ERROR_OCCURRED_TSTATE(tstate);
}
Py_DECREF(as_file);
Py_DECREF(our_as_file);
} else {
CLEAR_ERROR_OCCURRED_TSTATE(tstate);
}
}
#endif
static PyObject *Nuitka_ResourceReaderFiles_New(PyThreadState *tstate,
struct Nuitka_MetaPathBasedLoaderEntry const *entry, PyObject *path) {
struct Nuitka_ResourceReaderFilesObject *result;
static bool init_done = false;
if (init_done == false) {
// We do not really want to write a lot of NULLs just to do this, and
// for as long as we do not have C11 everywhere, that is how we have
// to do it.
Nuitka_ResourceReaderFiles_Type.tp_as_number->nb_true_divide =
(binaryfunc)Nuitka_ResourceReaderFiles_nb_truediv;
Nuitka_PyType_Ready(&Nuitka_ResourceReaderFiles_Type, NULL, true, false, true, false, false);
#if PYTHON_VERSION >= 0x390
// Also register our open, which can avoid a temporary file being created.
PyObject *importlib_resources_module = IMPORT_HARD_IMPORTLIB__RESOURCES();
registerResourceReaderFiles(tstate, importlib_resources_module);
PyObject *importlib_resources_backport_module = IMPORT_HARD_IMPORTLIB_RESOURCES();
if (importlib_resources_backport_module != NULL) {
registerResourceReaderFiles(tstate, importlib_resources_backport_module);
} else {
DROP_ERROR_OCCURRED_TSTATE(tstate);
}
#endif
init_done = true;
}
result = (struct Nuitka_ResourceReaderFilesObject *)Nuitka_GC_New(&Nuitka_ResourceReaderFiles_Type);
Nuitka_GC_Track(result);
result->m_loader_entry = entry;
result->m_path = path;
Py_INCREF(path);
return (PyObject *)result;
}
|
6b04d6317a879a2c656827b51b521bd432028e17
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/os/mm/mm_gran/mm_graninit.c
|
03248065b1060f4ef1e4a28c9ae82c9cba676372
|
[
"Apache-2.0",
"GPL-1.0-or-later",
"BSD-3-Clause",
"ISC",
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 9,255
|
c
|
mm_graninit.c
|
/****************************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/****************************************************************************
* mm/mm_gran/mm_graninit.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <tinyara/config.h>
#include <assert.h>
#include <errno.h>
#include <tinyara/mm/gran.h>
#include <tinyara/kmalloc.h>
#include "mm_gran/mm_gran.h"
#ifdef CONFIG_GRAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/* State of the single GRAN allocator */
#ifdef CONFIG_GRAN_SINGLE
FAR struct gran_s *g_graninfo;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: gran_common_initialize
*
* Description:
* Perform common GRAN initialization.
*
* Input Parameters:
* heapstart - Start of the granule allocation heap
* heapsize - Size of heap in bytes
* log2gran - Log base 2 of the size of one granule. 0->1 byte,
* 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc.
* log2align - Log base 2 of required alignment. 0->1 byte,
* 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. Note that
* log2gran must be greater than or equal to log2align
* so that all contiguous granules in memory will meet
* the minimum alignment requirement. A value of zero
* would mean that no alignment is required.
*
* Returned Value:
* On success, a non-NULL info structure is returned that may be used with
* other granule allocator interfaces.
*
****************************************************************************/
static inline FAR struct gran_s *gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, uint8_t log2align)
{
FAR struct gran_s *priv;
uintptr_t heapend;
uintptr_t alignedstart;
unsigned int mask;
unsigned int alignedsize;
unsigned int ngranules;
/* Check parameters if debug is on. Note the size of a granule is
* limited to 2**31 bytes and that the size of the granule must be greater
* than or equal to the alignment size.
*/
DEBUGASSERT(heapstart && heapsize > 0 && log2gran > 0 && log2gran < 32 && log2gran >= log2align);
/* Get the aligned start of the heap */
mask = (1 << log2align) - 1;
alignedstart = ((uintptr_t)heapstart + mask) & ~mask;
/* Determine the number of granules */
mask = (1 << log2gran) - 1;
heapend = (uintptr_t)heapstart + heapsize;
alignedsize = (heapend - alignedstart) & ~mask;
ngranules = alignedsize >> log2gran;
/* Allocate the information structure with a granule table of the
* correct size.
*/
priv = (FAR struct gran_s *)kmm_zalloc(SIZEOF_GRAN_S(ngranules));
if (priv) {
/* Initialize non-zero elements of the granules heap info structure */
priv->log2gran = log2gran;
priv->ngranules = ngranules;
priv->heapstart = alignedstart;
/* Initialize mutual exclusion support */
#ifndef CONFIG_GRAN_INTR
sem_init(&priv->exclsem, 0, 1);
#endif
}
return priv;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: gran_initialize
*
* Description:
* Set up one granule allocator instance. Allocations will be aligned to
* the alignment size (log2align; allocations will be in units of the
* granule size (log2gran). Larger granules will give better performance
* and less overhead but more losses of memory due to quantization waste.
* Additional memory waste can occur from alignment; log2align should be
* set to 0 unless you are using the granule allocator to manage DMA
* or page-aligned memory and your hardware has specific memory alignment
* requirements.
*
* General Usage Summary. This is an example using the GCC section
* attribute to position a DMA heap in memory (logic in the linker script
* would assign the section .dmaheap to the DMA memory.
*
* FAR uint32_t g_dmaheap[DMAHEAP_SIZE] __attribute__((section(.dmaheap)));
*
* The heap is created by calling gran_initialize(). Here the granule size
* is set to 64 bytes (2**6) and the alignment to 16 bytes (2**4):
*
* GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4);
*
* Then the GRAN_HANDLE can be used to allocate memory (There is no
* GRAN_HANDLE if CONFIG_GRAN_SINGLE=y):
*
* FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47);
*
* The actual memory allocates will be 64 byte (wasting 17 bytes) and
* will be aligned at least to (1 << log2align).
*
* NOTE: The current implementation also restricts the maximum allocation
* size to 32 granules. That restriction could be eliminated with some
* additional coding effort.
*
* Input Parameters:
* heapstart - Start of the granule allocation heap
* heapsize - Size of heap in bytes
* log2gran - Log base 2 of the size of one granule. 0->1 byte,
* 1->2 bytes, 2->4 bytes, 3->8 bytes, etc.
* log2align - Log base 2 of required alignment. 0->1 byte,
* 1->2 bytes, 2->4 bytes, 3->8 bytes, etc. Note that
* log2gran must be greater than or equal to log2align
* so that all contiguous granules in memory will meet
* the minimum alignment requirement. A value of zero
* would mean that no alignment is required.
*
* Returned Value:
* On success, a non-NULL handle is returned that may be used with other
* granule allocator interfaces.
*
****************************************************************************/
#ifdef CONFIG_GRAN_SINGLE
int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, uint8_t log2align)
{
g_graninfo = gran_common_initialize(heapstart, heapsize, log2gran, log2align);
if (!g_graninfo) {
return -ENOMEM;
}
return OK;
}
#else
GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, uint8_t log2align)
{
return (GRAN_HANDLE)gran_common_initialize(heapstart, heapsize, log2gran, log2align);
}
#endif
#endif /* CONFIG_GRAN */
|
2383eeead47c9c25b9af684143fa8d559790621d
|
f4056b1d5cb2d222f315c7f790ccf14d01436834
|
/hw/xquartz/xpr/xpr.h
|
fc614ebc3da04df0c1e775935a4ddfd26c8dc9e2
|
[
"SGI-B-2.0",
"ISC",
"LicenseRef-scancode-mit-old-style",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-x11-adobe",
"LicenseRef-scancode-xfree86-1.0",
"HPND-sell-variant",
"ICU",
"MIT-open-group",
"BSD-3-Clause",
"HPND",
"X11-distribute-modifications-variant",
"MIT",
"LicenseRef-scancode-other-permissive",
"X11"
] |
permissive
|
XQuartz/xorg-server
|
cd677ecd115213f5534cc1b06aff6a8c9a3ea733
|
0ea9b595891f2f31915538192961f3404d9ca699
|
refs/heads/master
| 2023-09-05T12:04:27.866042
| 2023-01-18T18:38:41
| 2023-01-26T17:51:16
| 44,375,619
| 287
| 60
|
NOASSERTION
| 2022-12-14T15:56:16
| 2015-10-16T09:29:57
|
C
|
UTF-8
|
C
| false
| false
| 2,598
|
h
|
xpr.h
|
/*
* Xplugin rootless implementation
*
* Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
* Copyright (c) 2002-2012 Apple Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name(s) of the above copyright
* holders shall not be used in advertising or otherwise to promote the sale,
* use or other dealings in this Software without prior written authorization.
*/
#ifndef XPR_H
#define XPR_H
#include "windowstr.h"
#include "screenint.h"
#include <Xplugin.h>
#include "darwin.h"
#undef DEBUG_LOG
#define DEBUG_LOG(msg, args ...) ASL_LOG(ASL_LEVEL_DEBUG, "xpr", msg, ## args)
Bool
QuartzModeBundleInit(void);
void
AppleDRIExtensionInit(void);
void
xprAppleWMInit(void);
Bool
xprInit(ScreenPtr pScreen);
Bool
xprIsX11Window(int windowNumber);
WindowPtr
xprGetXWindow(xp_window_id wid);
void
xprHideWindows(Bool hide);
Bool
QuartzInitCursor(ScreenPtr pScreen);
void
QuartzSuspendXCursor(ScreenPtr pScreen);
void
QuartzResumeXCursor(ScreenPtr pScreen);
/* If we are rooted, we need the root window and desktop levels to be below
* the menubar (24) but above native windows. Normal window level is 0.
* Floating window level is 3. The rest are filled in as appropriate.
* See CGWindowLevel.h
*/
#include <X11/extensions/applewmconst.h>
static const int normal_window_levels[AppleWMNumWindowLevels + 1] = {
0, 3, 4, 5, INT_MIN + 30, INT_MIN + 29,
};
static const int rooted_window_levels[AppleWMNumWindowLevels + 1] = {
20, 21, 22, 23, 19, 18,
};
#endif /* XPR_H */
|
02fed80cf938ea804f3a0e9b9d8c6475aa845789
|
24acbcc7b5ad20d2cea61b2b2b8190befe7f5bce
|
/Code/Sorting/PointerBased/bucketArraySortPtr.c
|
65d0d4dd86d28ccaf679885f18e82100abd169a4
|
[
"MIT"
] |
permissive
|
heineman/algorithms-nutshell-2ed
|
a08e2136fb3f9199e119a8aebca1be09a02b86f4
|
6bdaf7ee2878f69a2df00ae7a3274f5d43d24605
|
refs/heads/master
| 2022-09-04T20:53:52.422824
| 2021-12-29T02:34:44
| 2021-12-29T02:34:44
| 43,086,309
| 577
| 226
| null | null | null | null |
UTF-8
|
C
| false
| false
| 3,385
|
c
|
bucketArraySortPtr.c
|
/**
* @file bucketArraySortPtr.c Define core driver for Bucket Sort, pending the proper hash() and numBuckets() implementations, using arrays.
* @brief
* To employ Bucket Sort you only need to (a) provide a meaningful hash ()
* method to return an integer given an element; and (b) provide a method
* to compute the number of buckets to use. This code acts as the driver
* and relies on external code to provide the domain-specific coding.
*
*
* @author George Heineman
* @date 6/15/08
*/
#include <stdlib.h>
#include <stdio.h>
#include "report.h"
#include "bucketArraySortPtr.h"
/** Allocation of buckets and the number of buckets allocated */
static BUCKET *buckets = 0;
/** Number of buckets. */
static int num = 0;
/**
* Insert into bucket and extend as needed by doubling the size of the bucket
* array storage.
*/
static void insert (BUCKET *bucket, void *elt) {
if (bucket->size == 0) {
bucket->size = BUCKETSIZE;
bucket->ar = (void **) calloc (BUCKETSIZE, sizeof (void *));
}
/* extend by doubling the size of the array each time.*/
if (bucket->count == bucket->size) {
bucket->ar = (void **) realloc (bucket->ar, sizeof (void *) * (bucket->count*2));
bucket->size *= 2;
}
bucket->ar[bucket->count++] = elt;
}
/** Use Insertion Sort to sort the pointers in the bucket array. */
static void insertionSortPointers (void **ar, int n,
int(*cmp)(const void *,const void *)) {
int j;
for (j = 1; j < n; j++) {
int i = j-1;
void *value = ar[j];
while (i >= 0 && cmp(ar[i], value)> 0) {
#ifdef COUNT /* TIMING */
ADD_SWAP; /* TIMING */
#endif /*COUNT*/ /* TIMING */
ar[i+1] = ar[i];
i--;
}
ar[i+1] = value;
}
}
/** One by one remove and overwrite ar with proper values. */
void extract (BUCKET buckets[], int(*cmp)(const void *,const void *),
void **ar) {
int i, j;
int idx = 0;
for (i = 0; i < num; i++) {
if (buckets[i].count == 0) continue; /* empty bucket */
if (buckets[i].count == 1) {
ar[idx++] = buckets[i].ar[0];
buckets[i].ar[0] = 0;
free (buckets[i].ar);
buckets[i].ar = 0;
continue;
}
/* insertion sort within each bucket and then extract */
insertionSortPointers (buckets[i].ar, buckets[i].count, cmp);
for (j = 0; j < buckets[i].count; j++) {
ar[idx++] = buckets[i].ar[j];
buckets[i].ar[j] = 0;
}
free (buckets[i].ar);
buckets[i].ar = 0;
}
}
/**
* Invoke BucketSort on the given array.
*/
void sortPointers (void **ar, int n,
int(*cmp)(const void *,const void *)) {
int i;
num = numBuckets(n);
buckets = (BUCKET *) calloc (num, sizeof (BUCKET));
for (i = 0; i < n; i++) {
int bucket = hash(ar[i]);
insert (&buckets[bucket], ar[i]);
}
/* now read out and overwrite */
extract (buckets, cmp, ar);
free (buckets);
}
/**
* Debug routine. Output useful information.
*/
void debugBucket() {
int i;
int numEmpty = 0;
int numOne = 0;
int total = 0;
float avg = 0.0;
int numNonEmpty = 0;
for (i = 0; i < num; i++) {
if (buckets[i].count == 0) { numEmpty++; continue; }
if (buckets[i].count == 1) { numOne++; }
total += buckets[i].count;
numNonEmpty++;
}
avg += total;
avg /= numNonEmpty;
printf ("%d buckets, %d empty , %d with 1, Average: %f \n",
num, numEmpty, numOne, avg);
}
|
e04e4de115080713435c4eb0b8dafbba9454b9b1
|
d9ea45dbc964799991b9191ae620d2f150652a3d
|
/Sources/kinc/graphics5/commandlist.h
|
010f900ba5969fe001016814abef87cccf391927
|
[
"Zlib"
] |
permissive
|
Kode/Kinc
|
6ebb1cfa11c6e9ed0e153c486f573f1d7dca5664
|
d90b7478b192c8270e0ee32c0c3ee18977becd7a
|
refs/heads/main
| 2023-08-08T16:50:01.534587
| 2023-08-07T20:22:46
| 2023-08-07T20:22:46
| 10,254,751
| 283
| 249
|
Zlib
| 2023-08-26T12:27:36
| 2013-05-23T22:22:58
|
C
|
UTF-8
|
C
| false
| false
| 16,893
|
h
|
commandlist.h
|
#pragma once
#include <kinc/global.h>
#include "rendertarget.h"
#include "sampler.h"
#include "texture.h"
#include "textureunit.h"
#include <kinc/backend/graphics5/commandlist.h>
#include <stddef.h>
/*! \file commandlist.h
\brief Contains functions for building command-lists to send commands to the GPU.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define KINC_G5_CLEAR_COLOR 1
#define KINC_G5_CLEAR_DEPTH 2
#define KINC_G5_CLEAR_STENCIL 4
struct kinc_g5_constant_buffer;
struct kinc_g5_index_buffer;
struct kinc_g5_pipeline;
struct kinc_g5_render_target;
struct kinc_g5_texture;
struct kinc_g5_vertex_buffer;
struct kinc_g5_render_target;
/*typedef enum kinc_g5_render_target_format {
KINC_G5_RENDER_TARGET_FORMAT_32BIT,
KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT,
KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT,
KINC_G5_RENDER_TARGET_FORMAT_128BIT_FLOAT,
KINC_G5_RENDER_TARGET_FORMAT_16BIT_DEPTH,
KINC_G5_RENDER_TARGET_FORMAT_8BIT_RED
} kinc_g5_render_target_format_t;*/
// typedef kinc_g4_render_target_format_t kinc_g5_render_target_format_t;
typedef struct kinc_g5_command_list {
CommandList5Impl impl;
} kinc_g5_command_list_t;
/// <summary>
/// Initializes a command-list.
/// </summary>
/// <param name="list">The command-list to initialize</param>
KINC_FUNC void kinc_g5_command_list_init(kinc_g5_command_list_t *list);
/// <summary>
/// Destroys a command-list.
/// </summary>
/// <param name="list">The command-list to destroy</param>
KINC_FUNC void kinc_g5_command_list_destroy(kinc_g5_command_list_t *list);
/// <summary>
/// Starts recording commands in a command-list.
/// </summary>
/// <param name="list">The list to use</param>
KINC_FUNC void kinc_g5_command_list_begin(kinc_g5_command_list_t *list);
/// <summary>
/// Ends recording commands for the list. Has to be called after kinc_g5_command_list_begin and before kinc_g5_command_list_execute.
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
KINC_FUNC void kinc_g5_command_list_end(kinc_g5_command_list_t *list);
/// <summary>
/// Records a command to clear the color, depth and/or stencil-components of a render-target.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="render_target">The render-target to clear</param>
/// <param name="flags">Defines what components to clear</param>
/// <param name="color">The color-value to clear to</param>
/// <param name="depth">The depth-value to clear to</param>
/// <param name="stencil">The stencil-value to clear to</param>
KINC_FUNC void kinc_g5_command_list_clear(kinc_g5_command_list_t *list, struct kinc_g5_render_target *render_target, unsigned flags, unsigned color,
float depth, int stencil);
/// <summary>
/// Records a command that prepares a render-target to be used as the current framebuffer.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="renderTarget">The render-target to use as the current framebuffer</param>
KINC_FUNC void kinc_g5_command_list_render_target_to_framebuffer_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget);
/// <summary>
/// Records a command that prepares a render-target for regular render-target-usage after being used as the current framebuffer.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="renderTarget">The render-target to use in regular render-target-mode</param>
KINC_FUNC void kinc_g5_command_list_framebuffer_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget);
/// <summary>
/// Writes a command that prepares a render-target to be rendered to.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="renderTarget">The render-target to render to</param>
KINC_FUNC void kinc_g5_command_list_texture_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget);
/// <summary>
/// Writes a command that prepares a render-target to be used for sampling/reading like a texture.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="renderTarget">The render-target to be used like a texture</param>
KINC_FUNC void kinc_g5_command_list_render_target_to_texture_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget);
/// <summary>
/// Writes a command that draws the entire content of the currently set index-buffer and vertex-buffer. G4 can only draw triangle-lists using vertex-indices as
/// this is what GPUs tend to be optimized for.
/// </summary>
/// <param name="list">The list to write the command to</param>
KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices(kinc_g5_command_list_t *list);
/// <summary>
/// Writes a command that draws a part of the content of the currently set index-buffer and vertex-buffer. G4 can only draw triangle-lists using vertex-indices
/// as this is what GPUs tend to be optimized for.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="start">The offset into the index-buffer</param>
/// <param name="count">The number of indices to use</param>
KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_from_to(kinc_g5_command_list_t *list, int start, int count);
/// <summary>
/// Writes a command that draws a part of the content of the currently set index-buffer and vertex-buffer and additionally applies a general offset into the
/// vertex-buffer. G4 can only draw triangle-lists using vertex-indices as this is what GPUs tend to be optimized for.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="start">The offset into the index-buffer</param>
/// <param name="count">The number of indices to use</param>
/// <param name="vertex_offset">The offset into the vertex-buffer which is added to each index read from the index-buffer</param>
KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_from_to_from(kinc_g5_command_list_t *list, int start, int count, int vertex_offset);
KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_instanced(kinc_g5_command_list_t *list, int instanceCount);
KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(kinc_g5_command_list_t *list, int instanceCount, int start, int count);
/// <summary>
/// Writes a command that sets the viewport which defines the portion of the framebuffer or render-target things are rendered into. By default the viewport is
/// equivalent to the full size of the current render-target or framebuffer.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="x">The x-offset of the viewport from the left of the screen in pixels</param>
/// <param name="y">The y-offset of the viewport from the top of the screen in pixels</param>
/// <param name="width">The width of the viewport in pixels</param>
/// <param name="height">The height of the viewport in pixels</param>
KINC_FUNC void kinc_g5_command_list_viewport(kinc_g5_command_list_t *list, int x, int y, int width, int height);
/// <summary>
/// Writes a command that enables and defines the scissor-rect. When the scissor-rect is enabled, anything that's rendered outside of the scissor-rect will be
/// ignored.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="x">The x-offset of the scissor-rect from the left of the screen in pixels</param>
/// <param name="y">The y-offset of the scissor-rect from the top of the screen in pixels</param>
/// <param name="width">The width of the scissor-rect in pixels</param>
/// <param name="height">The height of the scissor-rect in pixels</param>
KINC_FUNC void kinc_g5_command_list_scissor(kinc_g5_command_list_t *list, int x, int y, int width, int height);
/// <summary>
/// Writes a command to disable the scissor-rect.
/// </summary>
/// <param name="list">The list to write the command to</param>
KINC_FUNC void kinc_g5_command_list_disable_scissor(kinc_g5_command_list_t *list);
/// <summary>
/// Writes a command to set the pipeline for the next draw-call. The pipeline defines most rendering-state including the shaders to be used.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="pipeline">The pipeline to set</param>
KINC_FUNC void kinc_g5_command_list_set_pipeline(kinc_g5_command_list_t *list, struct kinc_g5_pipeline *pipeline);
/// <summary>
/// Sets the blend constant used for `KINC_G5_BLEND_CONSTANT` or `KINC_G5_INV_BLEND_CONSTANT`
/// </summary>
KINC_FUNC void kinc_g5_command_list_set_blend_constant(kinc_g5_command_list_t *list, float r, float g, float b, float a);
/// <summary>
/// Writes a command which sets vertex-buffers for the next draw-call.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffers">The buffers to set</param>
/// <param name="offsets">The offset to use for every buffer in number of vertices</param>
/// <param name="count">The number of buffers to set</param>
KINC_FUNC void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer **buffers, int *offsets, int count);
/// <summary>
/// Writes a command to set an index-buffer to be used for the next draw-command.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffer">The buffer to use</param>
KINC_FUNC void kinc_g5_command_list_set_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer);
/// <summary>
/// Writes a command that sets the render-targets to draw into in following draw-calls.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="targets">The render-targets to use for following-draw calls</param>
/// <param name="count">The number of render-targets to use</param>
KINC_FUNC void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count);
/// <summary>
/// Writes a command to upload an index-buffer that's in main-memory to gpu-memory. Does nothing on unified-memory-systems.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffer">The buffer to upload</param>
KINC_FUNC void kinc_g5_command_list_upload_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer);
/// <summary>
/// Writes a command to upload a vertex-buffer that's in main-memory to gpu-memory. Does nothing on unified-memory-systems.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffer">The buffer to upload</param>
KINC_FUNC void kinc_g5_command_list_upload_vertex_buffer(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer *buffer);
/// <summary>
/// Writes a command to upload a texture that's in main-memory to gpu-memory. Does nothing on unified-memory-systems.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffer">The texture to upload</param>
KINC_FUNC void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, struct kinc_g5_texture *texture);
/// <summary>
/// Writes a command that sets a constant-buffer for the vertex-shader-stage.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffer">The buffer to set</param>
/// <param name="offset">The offset into the buffer in bytes to use as the start</param>
/// <param name="size">The size of the buffer to use in bytes starting at the offset</param>
KINC_FUNC void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size);
/// <summary>
/// Writes a command that sets a constant-buffer for the fragment-shader-stage.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="buffer">The buffer to set</param>
/// <param name="offset">The offset into the buffer in bytes to use as the start</param>
/// <param name="size">The size of the buffer to use in bytes starting at the offset</param>
KINC_FUNC void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size);
/// <summary>
/// Kicks off execution of the commands which have been recorded in the command-list. kinc_g5_command_list_end has to be called beforehand.
/// </summary>
/// <param name="list">The command-list to execute</param>
KINC_FUNC void kinc_g5_command_list_execute(kinc_g5_command_list_t *list);
/// <summary>
/// Waits for execution of the command_list to finish. Make sure the command-list is executing before you wait for it.
/// Also take note that waiting for a command-list to finish executing completely is a very expensive operation.
/// </summary>
/// <param name="list">The command-list to execute</param>
KINC_FUNC void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *list);
/// <summary>
/// Writes a command that copies the contents of a render-target into a cpu-side buffer. Beware: This is enormously slow.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="render_target">The render-target to copy the data from</param>
/// <param name="data">The buffer to copy the data into</param>
KINC_FUNC void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, struct kinc_g5_render_target *render_target, uint8_t *data);
/// <summary>
/// Records a command that fires off a compute-run on x * y * z elements.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="x">The x-size for the compute-run</param>
/// <param name="y">The y-size for the compute-run</param>
/// <param name="z">The z-size for the compute-run</param>
KINC_FUNC void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z);
/// <summary>
/// Assigns a texture to a texture-unit for sampled access.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="unit">The unit to assign this texture to</param>
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture);
/// <summary>
/// Assigns a texture to a texture-unit for direct access.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="unit">The unit to assign this texture to</param>
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture);
/// <summary>
/// Uses the color-component of a render-target as a texture.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="unit">The texture-unit to assign the render-target to</param>
/// <param name="target">The render-target to use</param>
KINC_FUNC void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *target);
/// <summary>
/// Uses the depth-component of a render-target as a texture.
/// </summary>
/// <param name="list">The list to write the command to</param>
/// <param name="unit">The texture-unit to assign the render-target to</param>
/// <param name="target">The render-target to use</param>
KINC_FUNC void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit,
kinc_g5_render_target_t *target);
KINC_FUNC void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face);
KINC_FUNC void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler);
// Occlusion Query
KINC_FUNC bool kinc_g5_command_list_init_occlusion_query(kinc_g5_command_list_t *list, unsigned *occlusionQuery);
KINC_FUNC void kinc_g5_command_list_delete_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery);
KINC_FUNC void kinc_g5_command_list_render_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery, int triangles);
KINC_FUNC bool kinc_g5_command_list_are_query_results_available(kinc_g5_command_list_t *list, unsigned occlusionQuery);
KINC_FUNC void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigned occlusionQuery, unsigned *pixelCount);
#ifdef __cplusplus
}
#endif
|
b9a601149a77a4581ba4b6182a1a82155b26af01
|
add160f872dccc7f326dc00196fd418c748a89b1
|
/openmmapi/include/OpenMM.h
|
7af6fddab569143731f7c395b997eb9ec6d58731
|
[] |
no_license
|
openmm/openmm
|
22f3d6ae2747f54acfaa92a5a6a5869049019dee
|
d2593f386a627d069b5ec17a3a2f4ecd40d85dd1
|
refs/heads/master
| 2023-08-22T18:29:54.807240
| 2023-08-18T19:09:05
| 2023-08-18T19:09:05
| 10,178,188
| 875
| 324
| null | 2023-09-12T23:40:17
| 2013-05-20T17:42:52
|
C++
|
UTF-8
|
C
| false
| false
| 4,318
|
h
|
OpenMM.h
|
#ifndef OPENMM_H_
#define OPENMM_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2009-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/AndersenThermostat.h"
#include "openmm/BrownianIntegrator.h"
#include "openmm/CMAPTorsionForce.h"
#include "openmm/CMMotionRemover.h"
#include "openmm/CompoundIntegrator.h"
#include "openmm/CustomBondForce.h"
#include "openmm/CustomCentroidBondForce.h"
#include "openmm/CustomCompoundBondForce.h"
#include "openmm/CustomAngleForce.h"
#include "openmm/CustomTorsionForce.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/CustomCVForce.h"
#include "openmm/CustomGBForce.h"
#include "openmm/CustomHbondForce.h"
#include "openmm/CustomIntegrator.h"
#include "openmm/CustomManyParticleForce.h"
#include "openmm/CustomNonbondedForce.h"
#include "openmm/Force.h"
#include "openmm/GayBerneForce.h"
#include "openmm/GBSAOBCForce.h"
#include "openmm/HarmonicAngleForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/Integrator.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/LangevinMiddleIntegrator.h"
#include "openmm/LocalEnergyMinimizer.h"
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/MonteCarloFlexibleBarostat.h"
#include "openmm/MonteCarloMembraneBarostat.h"
#include "openmm/NonbondedForce.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/PeriodicTorsionForce.h"
#include "openmm/RBTorsionForce.h"
#include "openmm/RMSDForce.h"
#include "openmm/State.h"
#include "openmm/System.h"
#include "openmm/TabulatedFunction.h"
#include "openmm/Units.h"
#include "openmm/VariableLangevinIntegrator.h"
#include "openmm/VariableVerletIntegrator.h"
#include "openmm/Vec3.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/NoseHooverIntegrator.h"
#include "openmm/NoseHooverChain.h"
#include "openmm/VirtualSite.h"
#include "openmm/Platform.h"
#include "openmm/serialization/XmlSerializer.h"
#include "openmm/ATMForce.h"
#endif /*OPENMM_H_*/
|
4a6a1888101a36c6c426c60b9c535adb4c4b9339
|
55540f3e86f1d5d86ef6b5d295a63518e274efe3
|
/components/platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/regs/iso11898_reg.h
|
b549ba5cd4d4e8633941b1346e86c17c4876f0ac
|
[
"Apache-2.0"
] |
permissive
|
bouffalolab/bl_iot_sdk
|
bc5eaf036b70f8c65dd389439062b169f8d09daa
|
b90664de0bd4c1897a9f1f5d9e360a9631d38b34
|
refs/heads/master
| 2023-08-31T03:38:03.369853
| 2023-08-16T08:50:33
| 2023-08-18T09:13:27
| 307,347,250
| 244
| 101
|
Apache-2.0
| 2023-08-28T06:29:02
| 2020-10-26T11:16:30
|
C
|
UTF-8
|
C
| false
| false
| 42,987
|
h
|
iso11898_reg.h
|
/*
* Copyright (c) 2016-2023 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ISO11898_REG_H__
#define __ISO11898_REG_H__
#include "bl808.h"
/* 0x0 : op mode:rw reset mode:rw */
#define ISO11898_MODE_OFFSET (0x0)
#define ISO11898_RESET_REQUEST ISO11898_RESET_REQUEST
#define ISO11898_RESET_REQUEST_POS (0U)
#define ISO11898_RESET_REQUEST_LEN (1U)
#define ISO11898_RESET_REQUEST_MSK (((1U << ISO11898_RESET_REQUEST_LEN) - 1) << ISO11898_RESET_REQUEST_POS)
#define ISO11898_RESET_REQUEST_UMSK (~(((1U << ISO11898_RESET_REQUEST_LEN) - 1) << ISO11898_RESET_REQUEST_POS))
#define ISO11898_LISTEN_ONLY ISO11898_LISTEN_ONLY
#define ISO11898_LISTEN_ONLY_POS (1U)
#define ISO11898_LISTEN_ONLY_LEN (1U)
#define ISO11898_LISTEN_ONLY_MSK (((1U << ISO11898_LISTEN_ONLY_LEN) - 1) << ISO11898_LISTEN_ONLY_POS)
#define ISO11898_LISTEN_ONLY_UMSK (~(((1U << ISO11898_LISTEN_ONLY_LEN) - 1) << ISO11898_LISTEN_ONLY_POS))
#define ISO11898_SELT_TEST ISO11898_SELT_TEST
#define ISO11898_SELT_TEST_POS (2U)
#define ISO11898_SELT_TEST_LEN (1U)
#define ISO11898_SELT_TEST_MSK (((1U << ISO11898_SELT_TEST_LEN) - 1) << ISO11898_SELT_TEST_POS)
#define ISO11898_SELT_TEST_UMSK (~(((1U << ISO11898_SELT_TEST_LEN) - 1) << ISO11898_SELT_TEST_POS))
#define ISO11898_ACCEPTANCE_FILTER ISO11898_ACCEPTANCE_FILTER
#define ISO11898_ACCEPTANCE_FILTER_POS (3U)
#define ISO11898_ACCEPTANCE_FILTER_LEN (1U)
#define ISO11898_ACCEPTANCE_FILTER_MSK (((1U << ISO11898_ACCEPTANCE_FILTER_LEN) - 1) << ISO11898_ACCEPTANCE_FILTER_POS)
#define ISO11898_ACCEPTANCE_FILTER_UMSK (~(((1U << ISO11898_ACCEPTANCE_FILTER_LEN) - 1) << ISO11898_ACCEPTANCE_FILTER_POS))
/* 0x4 : op mode:w r -> 8'h00
reset mode:w r -> 8'h00 */
#define ISO11898_COMMAND_OFFSET (0x4)
#define ISO11898_TRANSMIT_REQUEST ISO11898_TRANSMIT_REQUEST
#define ISO11898_TRANSMIT_REQUEST_POS (0U)
#define ISO11898_TRANSMIT_REQUEST_LEN (1U)
#define ISO11898_TRANSMIT_REQUEST_MSK (((1U << ISO11898_TRANSMIT_REQUEST_LEN) - 1) << ISO11898_TRANSMIT_REQUEST_POS)
#define ISO11898_TRANSMIT_REQUEST_UMSK (~(((1U << ISO11898_TRANSMIT_REQUEST_LEN) - 1) << ISO11898_TRANSMIT_REQUEST_POS))
#define ISO11898_ABORT_TRANSMISSION ISO11898_ABORT_TRANSMISSION
#define ISO11898_ABORT_TRANSMISSION_POS (1U)
#define ISO11898_ABORT_TRANSMISSION_LEN (1U)
#define ISO11898_ABORT_TRANSMISSION_MSK (((1U << ISO11898_ABORT_TRANSMISSION_LEN) - 1) << ISO11898_ABORT_TRANSMISSION_POS)
#define ISO11898_ABORT_TRANSMISSION_UMSK (~(((1U << ISO11898_ABORT_TRANSMISSION_LEN) - 1) << ISO11898_ABORT_TRANSMISSION_POS))
#define ISO11898_RELEASE_RECEIVE_BUFFER ISO11898_RELEASE_RECEIVE_BUFFER
#define ISO11898_RELEASE_RECEIVE_BUFFER_POS (2U)
#define ISO11898_RELEASE_RECEIVE_BUFFER_LEN (1U)
#define ISO11898_RELEASE_RECEIVE_BUFFER_MSK (((1U << ISO11898_RELEASE_RECEIVE_BUFFER_LEN) - 1) << ISO11898_RELEASE_RECEIVE_BUFFER_POS)
#define ISO11898_RELEASE_RECEIVE_BUFFER_UMSK (~(((1U << ISO11898_RELEASE_RECEIVE_BUFFER_LEN) - 1) << ISO11898_RELEASE_RECEIVE_BUFFER_POS))
#define ISO11898_CLEAR_DATA_OVERRUN ISO11898_CLEAR_DATA_OVERRUN
#define ISO11898_CLEAR_DATA_OVERRUN_POS (3U)
#define ISO11898_CLEAR_DATA_OVERRUN_LEN (1U)
#define ISO11898_CLEAR_DATA_OVERRUN_MSK (((1U << ISO11898_CLEAR_DATA_OVERRUN_LEN) - 1) << ISO11898_CLEAR_DATA_OVERRUN_POS)
#define ISO11898_CLEAR_DATA_OVERRUN_UMSK (~(((1U << ISO11898_CLEAR_DATA_OVERRUN_LEN) - 1) << ISO11898_CLEAR_DATA_OVERRUN_POS))
#define ISO11898_SELF_REQUEST ISO11898_SELF_REQUEST
#define ISO11898_SELF_REQUEST_POS (4U)
#define ISO11898_SELF_REQUEST_LEN (1U)
#define ISO11898_SELF_REQUEST_MSK (((1U << ISO11898_SELF_REQUEST_LEN) - 1) << ISO11898_SELF_REQUEST_POS)
#define ISO11898_SELF_REQUEST_UMSK (~(((1U << ISO11898_SELF_REQUEST_LEN) - 1) << ISO11898_SELF_REQUEST_POS))
/* 0x8 : op mode:r reset mode:r */
#define ISO11898_STATUS_OFFSET (0x8)
#define ISO11898_RECEIVE_BUFFER_STS ISO11898_RECEIVE_BUFFER_STS
#define ISO11898_RECEIVE_BUFFER_STS_POS (0U)
#define ISO11898_RECEIVE_BUFFER_STS_LEN (1U)
#define ISO11898_RECEIVE_BUFFER_STS_MSK (((1U << ISO11898_RECEIVE_BUFFER_STS_LEN) - 1) << ISO11898_RECEIVE_BUFFER_STS_POS)
#define ISO11898_RECEIVE_BUFFER_STS_UMSK (~(((1U << ISO11898_RECEIVE_BUFFER_STS_LEN) - 1) << ISO11898_RECEIVE_BUFFER_STS_POS))
#define ISO11898_DATA_OVERRUN_STS ISO11898_DATA_OVERRUN_STS
#define ISO11898_DATA_OVERRUN_STS_POS (1U)
#define ISO11898_DATA_OVERRUN_STS_LEN (1U)
#define ISO11898_DATA_OVERRUN_STS_MSK (((1U << ISO11898_DATA_OVERRUN_STS_LEN) - 1) << ISO11898_DATA_OVERRUN_STS_POS)
#define ISO11898_DATA_OVERRUN_STS_UMSK (~(((1U << ISO11898_DATA_OVERRUN_STS_LEN) - 1) << ISO11898_DATA_OVERRUN_STS_POS))
#define ISO11898_TRANSMIT_BUFFER_STS ISO11898_TRANSMIT_BUFFER_STS
#define ISO11898_TRANSMIT_BUFFER_STS_POS (2U)
#define ISO11898_TRANSMIT_BUFFER_STS_LEN (1U)
#define ISO11898_TRANSMIT_BUFFER_STS_MSK (((1U << ISO11898_TRANSMIT_BUFFER_STS_LEN) - 1) << ISO11898_TRANSMIT_BUFFER_STS_POS)
#define ISO11898_TRANSMIT_BUFFER_STS_UMSK (~(((1U << ISO11898_TRANSMIT_BUFFER_STS_LEN) - 1) << ISO11898_TRANSMIT_BUFFER_STS_POS))
#define ISO11898_TRANSMIT_COMPLETE_STS ISO11898_TRANSMIT_COMPLETE_STS
#define ISO11898_TRANSMIT_COMPLETE_STS_POS (3U)
#define ISO11898_TRANSMIT_COMPLETE_STS_LEN (1U)
#define ISO11898_TRANSMIT_COMPLETE_STS_MSK (((1U << ISO11898_TRANSMIT_COMPLETE_STS_LEN) - 1) << ISO11898_TRANSMIT_COMPLETE_STS_POS)
#define ISO11898_TRANSMIT_COMPLETE_STS_UMSK (~(((1U << ISO11898_TRANSMIT_COMPLETE_STS_LEN) - 1) << ISO11898_TRANSMIT_COMPLETE_STS_POS))
#define ISO11898_RECEIVE_STS ISO11898_RECEIVE_STS
#define ISO11898_RECEIVE_STS_POS (4U)
#define ISO11898_RECEIVE_STS_LEN (1U)
#define ISO11898_RECEIVE_STS_MSK (((1U << ISO11898_RECEIVE_STS_LEN) - 1) << ISO11898_RECEIVE_STS_POS)
#define ISO11898_RECEIVE_STS_UMSK (~(((1U << ISO11898_RECEIVE_STS_LEN) - 1) << ISO11898_RECEIVE_STS_POS))
#define ISO11898_TRANSMIT_STS ISO11898_TRANSMIT_STS
#define ISO11898_TRANSMIT_STS_POS (5U)
#define ISO11898_TRANSMIT_STS_LEN (1U)
#define ISO11898_TRANSMIT_STS_MSK (((1U << ISO11898_TRANSMIT_STS_LEN) - 1) << ISO11898_TRANSMIT_STS_POS)
#define ISO11898_TRANSMIT_STS_UMSK (~(((1U << ISO11898_TRANSMIT_STS_LEN) - 1) << ISO11898_TRANSMIT_STS_POS))
#define ISO11898_ERROR_STS ISO11898_ERROR_STS
#define ISO11898_ERROR_STS_POS (6U)
#define ISO11898_ERROR_STS_LEN (1U)
#define ISO11898_ERROR_STS_MSK (((1U << ISO11898_ERROR_STS_LEN) - 1) << ISO11898_ERROR_STS_POS)
#define ISO11898_ERROR_STS_UMSK (~(((1U << ISO11898_ERROR_STS_LEN) - 1) << ISO11898_ERROR_STS_POS))
#define ISO11898_BUS_STS ISO11898_BUS_STS
#define ISO11898_BUS_STS_POS (7U)
#define ISO11898_BUS_STS_LEN (1U)
#define ISO11898_BUS_STS_MSK (((1U << ISO11898_BUS_STS_LEN) - 1) << ISO11898_BUS_STS_POS)
#define ISO11898_BUS_STS_UMSK (~(((1U << ISO11898_BUS_STS_LEN) - 1) << ISO11898_BUS_STS_POS))
/* 0xc : op mode:r reset mode:r when be read,all bits are reseted and iso11898_int disappear */
#define ISO11898_INTERRUPT_OFFSET (0xc)
#define ISO11898_RECEIVE_INT ISO11898_RECEIVE_INT
#define ISO11898_RECEIVE_INT_POS (0U)
#define ISO11898_RECEIVE_INT_LEN (1U)
#define ISO11898_RECEIVE_INT_MSK (((1U << ISO11898_RECEIVE_INT_LEN) - 1) << ISO11898_RECEIVE_INT_POS)
#define ISO11898_RECEIVE_INT_UMSK (~(((1U << ISO11898_RECEIVE_INT_LEN) - 1) << ISO11898_RECEIVE_INT_POS))
#define ISO11898_TRANSMIT_INT ISO11898_TRANSMIT_INT
#define ISO11898_TRANSMIT_INT_POS (1U)
#define ISO11898_TRANSMIT_INT_LEN (1U)
#define ISO11898_TRANSMIT_INT_MSK (((1U << ISO11898_TRANSMIT_INT_LEN) - 1) << ISO11898_TRANSMIT_INT_POS)
#define ISO11898_TRANSMIT_INT_UMSK (~(((1U << ISO11898_TRANSMIT_INT_LEN) - 1) << ISO11898_TRANSMIT_INT_POS))
#define ISO11898_ERROR_INT ISO11898_ERROR_INT
#define ISO11898_ERROR_INT_POS (2U)
#define ISO11898_ERROR_INT_LEN (1U)
#define ISO11898_ERROR_INT_MSK (((1U << ISO11898_ERROR_INT_LEN) - 1) << ISO11898_ERROR_INT_POS)
#define ISO11898_ERROR_INT_UMSK (~(((1U << ISO11898_ERROR_INT_LEN) - 1) << ISO11898_ERROR_INT_POS))
#define ISO11898_DATA_OVERRUN_INT ISO11898_DATA_OVERRUN_INT
#define ISO11898_DATA_OVERRUN_INT_POS (3U)
#define ISO11898_DATA_OVERRUN_INT_LEN (1U)
#define ISO11898_DATA_OVERRUN_INT_MSK (((1U << ISO11898_DATA_OVERRUN_INT_LEN) - 1) << ISO11898_DATA_OVERRUN_INT_POS)
#define ISO11898_DATA_OVERRUN_INT_UMSK (~(((1U << ISO11898_DATA_OVERRUN_INT_LEN) - 1) << ISO11898_DATA_OVERRUN_INT_POS))
#define ISO11898_ERROR_PASSIVE_INT ISO11898_ERROR_PASSIVE_INT
#define ISO11898_ERROR_PASSIVE_INT_POS (5U)
#define ISO11898_ERROR_PASSIVE_INT_LEN (1U)
#define ISO11898_ERROR_PASSIVE_INT_MSK (((1U << ISO11898_ERROR_PASSIVE_INT_LEN) - 1) << ISO11898_ERROR_PASSIVE_INT_POS)
#define ISO11898_ERROR_PASSIVE_INT_UMSK (~(((1U << ISO11898_ERROR_PASSIVE_INT_LEN) - 1) << ISO11898_ERROR_PASSIVE_INT_POS))
#define ISO11898_ARB_LOST_INT ISO11898_ARB_LOST_INT
#define ISO11898_ARB_LOST_INT_POS (6U)
#define ISO11898_ARB_LOST_INT_LEN (1U)
#define ISO11898_ARB_LOST_INT_MSK (((1U << ISO11898_ARB_LOST_INT_LEN) - 1) << ISO11898_ARB_LOST_INT_POS)
#define ISO11898_ARB_LOST_INT_UMSK (~(((1U << ISO11898_ARB_LOST_INT_LEN) - 1) << ISO11898_ARB_LOST_INT_POS))
#define ISO11898_BUS_ERROR_INT ISO11898_BUS_ERROR_INT
#define ISO11898_BUS_ERROR_INT_POS (7U)
#define ISO11898_BUS_ERROR_INT_LEN (1U)
#define ISO11898_BUS_ERROR_INT_MSK (((1U << ISO11898_BUS_ERROR_INT_LEN) - 1) << ISO11898_BUS_ERROR_INT_POS)
#define ISO11898_BUS_ERROR_INT_UMSK (~(((1U << ISO11898_BUS_ERROR_INT_LEN) - 1) << ISO11898_BUS_ERROR_INT_POS))
/* 0x10 : op mode:rw reset mode:rw when be read,all bits are reseted and iso11898_int disappear */
#define ISO11898_INTERRUPT_ENABLE_OFFSET (0x10)
#define ISO11898_RECEIVE_INT_EN ISO11898_RECEIVE_INT_EN
#define ISO11898_RECEIVE_INT_EN_POS (0U)
#define ISO11898_RECEIVE_INT_EN_LEN (1U)
#define ISO11898_RECEIVE_INT_EN_MSK (((1U << ISO11898_RECEIVE_INT_EN_LEN) - 1) << ISO11898_RECEIVE_INT_EN_POS)
#define ISO11898_RECEIVE_INT_EN_UMSK (~(((1U << ISO11898_RECEIVE_INT_EN_LEN) - 1) << ISO11898_RECEIVE_INT_EN_POS))
#define ISO11898_TRANSMIT_INT_EN ISO11898_TRANSMIT_INT_EN
#define ISO11898_TRANSMIT_INT_EN_POS (1U)
#define ISO11898_TRANSMIT_INT_EN_LEN (1U)
#define ISO11898_TRANSMIT_INT_EN_MSK (((1U << ISO11898_TRANSMIT_INT_EN_LEN) - 1) << ISO11898_TRANSMIT_INT_EN_POS)
#define ISO11898_TRANSMIT_INT_EN_UMSK (~(((1U << ISO11898_TRANSMIT_INT_EN_LEN) - 1) << ISO11898_TRANSMIT_INT_EN_POS))
#define ISO11898_ERROR_INT_EN ISO11898_ERROR_INT_EN
#define ISO11898_ERROR_INT_EN_POS (2U)
#define ISO11898_ERROR_INT_EN_LEN (1U)
#define ISO11898_ERROR_INT_EN_MSK (((1U << ISO11898_ERROR_INT_EN_LEN) - 1) << ISO11898_ERROR_INT_EN_POS)
#define ISO11898_ERROR_INT_EN_UMSK (~(((1U << ISO11898_ERROR_INT_EN_LEN) - 1) << ISO11898_ERROR_INT_EN_POS))
#define ISO11898_DATA_OVERRUN_INT_EN ISO11898_DATA_OVERRUN_INT_EN
#define ISO11898_DATA_OVERRUN_INT_EN_POS (3U)
#define ISO11898_DATA_OVERRUN_INT_EN_LEN (1U)
#define ISO11898_DATA_OVERRUN_INT_EN_MSK (((1U << ISO11898_DATA_OVERRUN_INT_EN_LEN) - 1) << ISO11898_DATA_OVERRUN_INT_EN_POS)
#define ISO11898_DATA_OVERRUN_INT_EN_UMSK (~(((1U << ISO11898_DATA_OVERRUN_INT_EN_LEN) - 1) << ISO11898_DATA_OVERRUN_INT_EN_POS))
#define ISO11898_ERROR_PASSIVE_INT_EN ISO11898_ERROR_PASSIVE_INT_EN
#define ISO11898_ERROR_PASSIVE_INT_EN_POS (5U)
#define ISO11898_ERROR_PASSIVE_INT_EN_LEN (1U)
#define ISO11898_ERROR_PASSIVE_INT_EN_MSK (((1U << ISO11898_ERROR_PASSIVE_INT_EN_LEN) - 1) << ISO11898_ERROR_PASSIVE_INT_EN_POS)
#define ISO11898_ERROR_PASSIVE_INT_EN_UMSK (~(((1U << ISO11898_ERROR_PASSIVE_INT_EN_LEN) - 1) << ISO11898_ERROR_PASSIVE_INT_EN_POS))
#define ISO11898_ARB_LOST_INT_EN ISO11898_ARB_LOST_INT_EN
#define ISO11898_ARB_LOST_INT_EN_POS (6U)
#define ISO11898_ARB_LOST_INT_EN_LEN (1U)
#define ISO11898_ARB_LOST_INT_EN_MSK (((1U << ISO11898_ARB_LOST_INT_EN_LEN) - 1) << ISO11898_ARB_LOST_INT_EN_POS)
#define ISO11898_ARB_LOST_INT_EN_UMSK (~(((1U << ISO11898_ARB_LOST_INT_EN_LEN) - 1) << ISO11898_ARB_LOST_INT_EN_POS))
#define ISO11898_BUS_ERROR_INT_EN ISO11898_BUS_ERROR_INT_EN
#define ISO11898_BUS_ERROR_INT_EN_POS (7U)
#define ISO11898_BUS_ERROR_INT_EN_LEN (1U)
#define ISO11898_BUS_ERROR_INT_EN_MSK (((1U << ISO11898_BUS_ERROR_INT_EN_LEN) - 1) << ISO11898_BUS_ERROR_INT_EN_POS)
#define ISO11898_BUS_ERROR_INT_EN_UMSK (~(((1U << ISO11898_BUS_ERROR_INT_EN_LEN) - 1) << ISO11898_BUS_ERROR_INT_EN_POS))
/* 0x18 : op mode:r reset mode:rw */
#define ISO11898_BUS_TIMING_0_OFFSET (0x18)
#define ISO11898_BAUD_RATE_PRESCALER ISO11898_BAUD_RATE_PRESCALER
#define ISO11898_BAUD_RATE_PRESCALER_POS (0U)
#define ISO11898_BAUD_RATE_PRESCALER_LEN (6U)
#define ISO11898_BAUD_RATE_PRESCALER_MSK (((1U << ISO11898_BAUD_RATE_PRESCALER_LEN) - 1) << ISO11898_BAUD_RATE_PRESCALER_POS)
#define ISO11898_BAUD_RATE_PRESCALER_UMSK (~(((1U << ISO11898_BAUD_RATE_PRESCALER_LEN) - 1) << ISO11898_BAUD_RATE_PRESCALER_POS))
#define ISO11898_SYNC_JUMP_WIDTH ISO11898_SYNC_JUMP_WIDTH
#define ISO11898_SYNC_JUMP_WIDTH_POS (6U)
#define ISO11898_SYNC_JUMP_WIDTH_LEN (2U)
#define ISO11898_SYNC_JUMP_WIDTH_MSK (((1U << ISO11898_SYNC_JUMP_WIDTH_LEN) - 1) << ISO11898_SYNC_JUMP_WIDTH_POS)
#define ISO11898_SYNC_JUMP_WIDTH_UMSK (~(((1U << ISO11898_SYNC_JUMP_WIDTH_LEN) - 1) << ISO11898_SYNC_JUMP_WIDTH_POS))
/* 0x1c : op mode:r reset mode:rw */
#define ISO11898_BUS_TIMING_1_OFFSET (0x1c)
#define ISO11898_TIME_SEGMENT_1 ISO11898_TIME_SEGMENT_1
#define ISO11898_TIME_SEGMENT_1_POS (0U)
#define ISO11898_TIME_SEGMENT_1_LEN (4U)
#define ISO11898_TIME_SEGMENT_1_MSK (((1U << ISO11898_TIME_SEGMENT_1_LEN) - 1) << ISO11898_TIME_SEGMENT_1_POS)
#define ISO11898_TIME_SEGMENT_1_UMSK (~(((1U << ISO11898_TIME_SEGMENT_1_LEN) - 1) << ISO11898_TIME_SEGMENT_1_POS))
#define ISO11898_TIME_SEGMENT_2 ISO11898_TIME_SEGMENT_2
#define ISO11898_TIME_SEGMENT_2_POS (4U)
#define ISO11898_TIME_SEGMENT_2_LEN (3U)
#define ISO11898_TIME_SEGMENT_2_MSK (((1U << ISO11898_TIME_SEGMENT_2_LEN) - 1) << ISO11898_TIME_SEGMENT_2_POS)
#define ISO11898_TIME_SEGMENT_2_UMSK (~(((1U << ISO11898_TIME_SEGMENT_2_LEN) - 1) << ISO11898_TIME_SEGMENT_2_POS))
#define ISO11898_SAMPLING ISO11898_SAMPLING
#define ISO11898_SAMPLING_POS (7U)
#define ISO11898_SAMPLING_LEN (1U)
#define ISO11898_SAMPLING_MSK (((1U << ISO11898_SAMPLING_LEN) - 1) << ISO11898_SAMPLING_POS)
#define ISO11898_SAMPLING_UMSK (~(((1U << ISO11898_SAMPLING_LEN) - 1) << ISO11898_SAMPLING_POS))
/* 0x2c : op mode:r reset mode:r */
#define ISO11898_ARB_LOST_CAPTURE_OFFSET (0x2c)
#define ISO11898_ALC4_0 ISO11898_ALC4_0
#define ISO11898_ALC4_0_POS (0U)
#define ISO11898_ALC4_0_LEN (5U)
#define ISO11898_ALC4_0_MSK (((1U << ISO11898_ALC4_0_LEN) - 1) << ISO11898_ALC4_0_POS)
#define ISO11898_ALC4_0_UMSK (~(((1U << ISO11898_ALC4_0_LEN) - 1) << ISO11898_ALC4_0_POS))
/* 0x30 : op mode:r reset mode:r */
#define ISO11898_ERROR_CODE_CAPTURE_OFFSET (0x30)
#define ISO11898_SEGMENT4_0 ISO11898_SEGMENT4_0
#define ISO11898_SEGMENT4_0_POS (0U)
#define ISO11898_SEGMENT4_0_LEN (5U)
#define ISO11898_SEGMENT4_0_MSK (((1U << ISO11898_SEGMENT4_0_LEN) - 1) << ISO11898_SEGMENT4_0_POS)
#define ISO11898_SEGMENT4_0_UMSK (~(((1U << ISO11898_SEGMENT4_0_LEN) - 1) << ISO11898_SEGMENT4_0_POS))
#define ISO11898_DIR ISO11898_DIR
#define ISO11898_DIR_POS (5U)
#define ISO11898_DIR_LEN (1U)
#define ISO11898_DIR_MSK (((1U << ISO11898_DIR_LEN) - 1) << ISO11898_DIR_POS)
#define ISO11898_DIR_UMSK (~(((1U << ISO11898_DIR_LEN) - 1) << ISO11898_DIR_POS))
#define ISO11898_ERR_CODE ISO11898_ERR_CODE
#define ISO11898_ERR_CODE_POS (6U)
#define ISO11898_ERR_CODE_LEN (2U)
#define ISO11898_ERR_CODE_MSK (((1U << ISO11898_ERR_CODE_LEN) - 1) << ISO11898_ERR_CODE_POS)
#define ISO11898_ERR_CODE_UMSK (~(((1U << ISO11898_ERR_CODE_LEN) - 1) << ISO11898_ERR_CODE_POS))
/* 0x34 : op mode:r reset mode:rw */
#define ISO11898_ERROR_WARNING_LIMIT_OFFSET (0x34)
#define ISO11898_ERR_WARNING_LIMIT ISO11898_ERR_WARNING_LIMIT
#define ISO11898_ERR_WARNING_LIMIT_POS (0U)
#define ISO11898_ERR_WARNING_LIMIT_LEN (8U)
#define ISO11898_ERR_WARNING_LIMIT_MSK (((1U << ISO11898_ERR_WARNING_LIMIT_LEN) - 1) << ISO11898_ERR_WARNING_LIMIT_POS)
#define ISO11898_ERR_WARNING_LIMIT_UMSK (~(((1U << ISO11898_ERR_WARNING_LIMIT_LEN) - 1) << ISO11898_ERR_WARNING_LIMIT_POS))
/* 0x38 : op mode:r reset mode:rw */
#define ISO11898_RX_ERR_COUNT_OFFSET (0x38)
#define ISO11898_RX_ERR_CNT ISO11898_RX_ERR_CNT
#define ISO11898_RX_ERR_CNT_POS (0U)
#define ISO11898_RX_ERR_CNT_LEN (8U)
#define ISO11898_RX_ERR_CNT_MSK (((1U << ISO11898_RX_ERR_CNT_LEN) - 1) << ISO11898_RX_ERR_CNT_POS)
#define ISO11898_RX_ERR_CNT_UMSK (~(((1U << ISO11898_RX_ERR_CNT_LEN) - 1) << ISO11898_RX_ERR_CNT_POS))
/* 0x3c : op mode:r reset mode:rw */
#define ISO11898_TX_ERR_COUNT_OFFSET (0x3c)
#define ISO11898_TX_ERR_CNT ISO11898_TX_ERR_CNT
#define ISO11898_TX_ERR_CNT_POS (0U)
#define ISO11898_TX_ERR_CNT_LEN (8U)
#define ISO11898_TX_ERR_CNT_MSK (((1U << ISO11898_TX_ERR_CNT_LEN) - 1) << ISO11898_TX_ERR_CNT_POS)
#define ISO11898_TX_ERR_CNT_UMSK (~(((1U << ISO11898_TX_ERR_CNT_LEN) - 1) << ISO11898_TX_ERR_CNT_POS))
/* 0x40 : op mode: w -> tx_frm_info
r -> rx_frm_info
reset mode:rw -> acceptance_code0 */
#define ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_OFFSET (0x40)
#define ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0 ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0
#define ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_POS (0U)
#define ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_LEN (8U)
#define ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_MSK (((1U << ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_LEN) - 1) << ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_POS)
#define ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_UMSK (~(((1U << ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_LEN) - 1) << ISO11898_TXRX_FRM_INFO_OR_ACCEPTANCE_CODE0_POS))
/* 0x44 : op mode:w -> tx_id1
r -> rx_id1
reset mode:rw -> acceptance_code1 */
#define ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_OFFSET (0x44)
#define ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1 ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1
#define ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_POS (0U)
#define ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_LEN (8U)
#define ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_MSK (((1U << ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_LEN) - 1) << ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_POS)
#define ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_UMSK (~(((1U << ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_LEN) - 1) << ISO11898_TXRX_ID1_OR_ACCEPTANCE_CODE1_POS))
/* 0x48 : op mode:w -> tx_id2
r -> rx_id2
reset mode:rw -> acceptance_code2 */
#define ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_OFFSET (0x48)
#define ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2 ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2
#define ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_POS (0U)
#define ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_LEN (8U)
#define ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_MSK (((1U << ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_LEN) - 1) << ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_POS)
#define ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_UMSK (~(((1U << ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_LEN) - 1) << ISO11898_TXRX_ID2_OR_ACCEPTANCE_CODE2_POS))
/* 0x74 : op mode:r reset mode:r */
#define ISO11898_RX_MESSAGE_COUNT_OFFSET (0x74)
#define ISO11898_RX_MESSAGE_CNT ISO11898_RX_MESSAGE_CNT
#define ISO11898_RX_MESSAGE_CNT_POS (0U)
#define ISO11898_RX_MESSAGE_CNT_LEN (5U)
#define ISO11898_RX_MESSAGE_CNT_MSK (((1U << ISO11898_RX_MESSAGE_CNT_LEN) - 1) << ISO11898_RX_MESSAGE_CNT_POS)
#define ISO11898_RX_MESSAGE_CNT_UMSK (~(((1U << ISO11898_RX_MESSAGE_CNT_LEN) - 1) << ISO11898_RX_MESSAGE_CNT_POS))
/* 0x7c : op mode:rw reset mode:rw iso11898_mode and cbp can be write in reset mode only */
#define ISO11898_CLOCK_DIVIDER_OFFSET (0x7c)
#define ISO11898_CD ISO11898_CD
#define ISO11898_CD_POS (0U)
#define ISO11898_CD_LEN (3U)
#define ISO11898_CD_MSK (((1U << ISO11898_CD_LEN) - 1) << ISO11898_CD_POS)
#define ISO11898_CD_UMSK (~(((1U << ISO11898_CD_LEN) - 1) << ISO11898_CD_POS))
#define ISO11898_CLOCKOFF ISO11898_CLOCKOFF
#define ISO11898_CLOCKOFF_POS (3U)
#define ISO11898_CLOCKOFF_LEN (1U)
#define ISO11898_CLOCKOFF_MSK (((1U << ISO11898_CLOCKOFF_LEN) - 1) << ISO11898_CLOCKOFF_POS)
#define ISO11898_CLOCKOFF_UMSK (~(((1U << ISO11898_CLOCKOFF_LEN) - 1) << ISO11898_CLOCKOFF_POS))
#define ISO11898_READONLY ISO11898_READONLY
#define ISO11898_READONLY_POS (4U)
#define ISO11898_READONLY_LEN (1U)
#define ISO11898_READONLY_MSK (((1U << ISO11898_READONLY_LEN) - 1) << ISO11898_READONLY_POS)
#define ISO11898_READONLY_UMSK (~(((1U << ISO11898_READONLY_LEN) - 1) << ISO11898_READONLY_POS))
#define ISO11898_RXINTEN ISO11898_RXINTEN
#define ISO11898_RXINTEN_POS (5U)
#define ISO11898_RXINTEN_LEN (1U)
#define ISO11898_RXINTEN_MSK (((1U << ISO11898_RXINTEN_LEN) - 1) << ISO11898_RXINTEN_POS)
#define ISO11898_RXINTEN_UMSK (~(((1U << ISO11898_RXINTEN_LEN) - 1) << ISO11898_RXINTEN_POS))
#define ISO11898_CBP ISO11898_CBP
#define ISO11898_CBP_POS (6U)
#define ISO11898_CBP_LEN (1U)
#define ISO11898_CBP_MSK (((1U << ISO11898_CBP_LEN) - 1) << ISO11898_CBP_POS)
#define ISO11898_CBP_UMSK (~(((1U << ISO11898_CBP_LEN) - 1) << ISO11898_CBP_POS))
#define ISO11898_MODE ISO11898_MODE
#define ISO11898_MODE_POS (7U)
#define ISO11898_MODE_LEN (1U)
#define ISO11898_MODE_MSK (((1U << ISO11898_MODE_LEN) - 1) << ISO11898_MODE_POS)
#define ISO11898_MODE_UMSK (~(((1U << ISO11898_MODE_LEN) - 1) << ISO11898_MODE_POS))
/* 0x40 : Frame information */
#define ISO11898_INFORMATION_OFFSET (0x40)
#define ISO11898_INF_DLC ISO11898_INF_DLC
#define ISO11898_INF_DLC_POS (0U)
#define ISO11898_INF_DLC_LEN (4U)
#define ISO11898_INF_DLC_MSK (((1U << ISO11898_INF_DLC_LEN) - 1) << ISO11898_INF_DLC_POS)
#define ISO11898_INF_DLC_UMSK (~(((1U << ISO11898_INF_DLC_LEN) - 1) << ISO11898_INF_DLC_POS))
#define ISO11898_INF_RTR ISO11898_INF_RTR
#define ISO11898_INF_RTR_POS (6U)
#define ISO11898_INF_RTR_LEN (1U)
#define ISO11898_INF_RTR_MSK (((1U << ISO11898_INF_RTR_LEN) - 1) << ISO11898_INF_RTR_POS)
#define ISO11898_INF_RTR_UMSK (~(((1U << ISO11898_INF_RTR_LEN) - 1) << ISO11898_INF_RTR_POS))
#define ISO11898_INF_FF ISO11898_INF_FF
#define ISO11898_INF_FF_POS (7U)
#define ISO11898_INF_FF_LEN (1U)
#define ISO11898_INF_FF_MSK (((1U << ISO11898_INF_FF_LEN) - 1) << ISO11898_INF_FF_POS)
#define ISO11898_INF_FF_UMSK (~(((1U << ISO11898_INF_FF_LEN) - 1) << ISO11898_INF_FF_POS))
/* 0x44 : Identifier 1, ID28~21 */
#define ISO11898_IDENTIFIER_1_OFFSET (0x44)
/* 0x48 : Identifier 2, ID20~13, SFF Only use ID20~18 */
#define ISO11898_IDENTIFIER_2_OFFSET (0x48)
/* 0x4C : Identifier 3, ID12~5, only for EFF */
#define ISO11898_IDENTIFIER_3_OFFSET (0x4C)
/* 0x50 : Identifier 4, ID4~0, only for EFF */
#define ISO11898_IDENTIFIER_4_OFFSET (0x50)
/* 0x4C : Standard Format Data 1 buffer */
#define ISO11898_SFF_DATA_1_OFFSET (0x4C)
/* 0x50 : Standard Format Data 2 buffer */
#define ISO11898_SFF_DATA_2_OFFSET (0x50)
/* 0x54 : Standard Format Data 3 buffer */
#define ISO11898_SFF_DATA_3_OFFSET (0x54)
/* 0x58 : Standard Format Data 4 buffer */
#define ISO11898_SFF_DATA_4_OFFSET (0x58)
/* 0x5C : Standard Format Data 5 buffer */
#define ISO11898_SFF_DATA_5_OFFSET (0x5C)
/* 0x60 : Standard Format Data 6 buffer */
#define ISO11898_SFF_DATA_6_OFFSET (0x60)
/* 0x64 : Standard Format Data 7 buffer */
#define ISO11898_SFF_DATA_7_OFFSET (0x64)
/* 0x68 : Standard Format Data 8 buffer */
#define ISO11898_SFF_DATA_8_OFFSET (0x68)
/* 0x54 : Extended Format Data 1 buffer */
#define ISO11898_EFF_DATA_1_OFFSET (0x54)
/* 0x58 : Extended Format Data 2 buffer */
#define ISO11898_EFF_DATA_2_OFFSET (0x58)
/* 0x5C : Extended Format Data 3 buffer */
#define ISO11898_EFF_DATA_3_OFFSET (0x5C)
/* 0x60 : Extended Format Data 4 buffer */
#define ISO11898_EFF_DATA_4_OFFSET (0x60)
/* 0x64 : Extended Format Data 5 buffer */
#define ISO11898_EFF_DATA_5_OFFSET (0x64)
/* 0x68 : Extended Format Data 6 buffer */
#define ISO11898_EFF_DATA_6_OFFSET (0x68)
/* 0x6C : Extended Format Data 7 buffer */
#define ISO11898_EFF_DATA_7_OFFSET (0x6C)
/* 0x70 : Extended Format Data 8 buffer */
#define ISO11898_EFF_DATA_8_OFFSET (0x70)
/* 0x70 : Extended Format Data 8 buffer */
#define ISO11898_EFF_DATA_8_OFFSET (0x70)
/* 0x40 : Filter Acceptance 0 */
#define ISO11898_FILTER_ACCEPTANCE_0_OFFSET (0x40)
/* 0x44 : Filter Acceptance 1 */
#define ISO11898_FILTER_ACCEPTANCE_1_OFFSET (0x44)
/* 0x48 : Filter Acceptance 2 */
#define ISO11898_FILTER_ACCEPTANCE_2_OFFSET (0x48)
/* 0x4C : Filter Acceptance 3 */
#define ISO11898_FILTER_ACCEPTANCE_3_OFFSET (0x4C)
/* 0x50 : Filter Mask 0 */
#define ISO11898_FILTER_Mask_0_OFFSET (0x50)
/* 0x54 : Filter Mask 1 */
#define ISO11898_FILTER_Mask_1_OFFSET (0x54)
/* 0x58 : Filter Mask 2 */
#define ISO11898_FILTER_Mask_2_OFFSET (0x58)
/* 0x5C : Filter Mask 3 */
#define ISO11898_FILTER_Mask_3_OFFSET (0x5C)
/* 0x4C : Extended Format, Tx information 5, ID4~0 */
#define ISO11898_IDENTIFIER_4_OFFSET (0x50)
struct iso11898_reg {
/* 0x0 : op mode:rw reset mode:rw */
union {
struct {
uint32_t reset_request : 1; /* [ 0], w1c, 0x0 */
uint32_t listen_only : 1; /* [ 1], w1c, 0x0 */
uint32_t selt_test : 1; /* [ 2], w1c, 0x0 */
uint32_t acceptance_filter : 1; /* [ 3], w1c, 0x0 */
uint32_t rsvd_7_4 : 4; /* [ 7: 4], rsvd, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} mode;
/* 0x4 : op mode:w r -> 8'h00
reset mode:w r -> 8'h00 */
union {
struct {
uint32_t transmit_request : 1; /* [ 0], w1c, 0x0 */
uint32_t abort_transmission : 1; /* [ 1], w1c, 0x0 */
uint32_t release_receive_buffer : 1; /* [ 2], w1c, 0x0 */
uint32_t clear_data_overrun : 1; /* [ 3], w1c, 0x0 */
uint32_t self_request : 1; /* [ 4], w1c, 0x0 */
uint32_t rsvd_7_5 : 3; /* [ 7: 5], rsvd, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} command;
/* 0x8 : op mode:r reset mode:r */
union {
struct {
uint32_t receive_buffer_sts : 1; /* [ 0], r, 0x0 */
uint32_t data_overrun_sts : 1; /* [ 1], r, 0x0 */
uint32_t transmit_buffer_sts : 1; /* [ 2], r, 0x0 */
uint32_t transmit_complete_sts : 1; /* [ 3], r, 0x0 */
uint32_t receive_sts : 1; /* [ 4], r, 0x0 */
uint32_t transmit_sts : 1; /* [ 5], r, 0x0 */
uint32_t error_sts : 1; /* [ 6], r, 0x0 */
uint32_t bus_sts : 1; /* [ 7], r, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} status;
/* 0xc : op mode:r reset mode:r when be read,all bits are reseted and iso11898_int disappear */
union {
struct {
uint32_t receive_int : 1; /* [ 0], r, 0x0 */
uint32_t transmit_int : 1; /* [ 1], r, 0x0 */
uint32_t error_int : 1; /* [ 2], r, 0x0 */
uint32_t data_overrun_int : 1; /* [ 3], r, 0x0 */
uint32_t rsvd_4 : 1; /* [ 4], rsvd, 0x0 */
uint32_t error_passive_int : 1; /* [ 5], r, 0x0 */
uint32_t arb_lost_int : 1; /* [ 6], r, 0x0 */
uint32_t bus_error_int : 1; /* [ 7], r, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} interrupt;
/* 0x10 : op mode:rw reset mode:rw when be read,all bits are reseted and iso11898_int disappear */
union {
struct {
uint32_t receive_int_en : 1; /* [ 0], r/w, 0x0 */
uint32_t transmit_int_en : 1; /* [ 1], r/w, 0x0 */
uint32_t error_int_en : 1; /* [ 2], r/w, 0x0 */
uint32_t data_overrun_int_en : 1; /* [ 3], r/w, 0x0 */
uint32_t rsvd_4 : 1; /* [ 4], rsvd, 0x0 */
uint32_t error_passive_int_en : 1; /* [ 5], r/w, 0x0 */
uint32_t arb_lost_int_en : 1; /* [ 6], r/w, 0x0 */
uint32_t bus_error_int_en : 1; /* [ 7], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} interrupt_enable;
/* 0x14 reserved */
uint8_t RESERVED0x14[4];
/* 0x18 : op mode:r reset mode:rw */
union {
struct {
uint32_t baud_rate_prescaler_0 : 1; /* [ 0], r/w, 0x0 */
uint32_t baud_rate_prescaler_1 : 1; /* [ 1], r/w, 0x0 */
uint32_t baud_rate_prescaler_2 : 1; /* [ 2], r/w, 0x0 */
uint32_t baud_rate_prescaler_3 : 1; /* [ 3], r/w, 0x0 */
uint32_t baud_rate_prescaler_4 : 1; /* [ 4], r/w, 0x0 */
uint32_t baud_rate_prescaler_5 : 1; /* [ 5], r/w, 0x0 */
uint32_t sync_jump_width_0 : 1; /* [ 6], r/w, 0x0 */
uint32_t sync_jump_width_1 : 1; /* [ 7], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} bus_timing_0;
/* 0x1c : op mode:r reset mode:rw */
union {
struct {
uint32_t time_segment_1_0 : 1; /* [ 0], r/w, 0x0 */
uint32_t time_segment_1_1 : 1; /* [ 1], r/w, 0x0 */
uint32_t time_segment_1_2 : 1; /* [ 2], r/w, 0x0 */
uint32_t time_segment_1_3 : 1; /* [ 3], r/w, 0x0 */
uint32_t time_segment_2_0 : 1; /* [ 4], r/w, 0x0 */
uint32_t time_segment_2_1 : 1; /* [ 5], r/w, 0x0 */
uint32_t time_segment_2_2 : 1; /* [ 6], r/w, 0x0 */
uint32_t sampling : 1; /* [ 7], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} bus_timing_1;
/* 0x20 reserved */
uint8_t RESERVED0x20[12];
/* 0x2c : op mode:r reset mode:r */
union {
struct {
uint32_t ALC4_0 : 5; /* [ 4: 0], r, 0x0 */
uint32_t rsvd_7_5 : 3; /* [ 7: 5], rsvd, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} arb_lost_capture;
/* 0x30 : op mode:r reset mode:r */
union {
struct {
uint32_t segment4_0 : 5; /* [ 4: 0], r, 0x0 */
uint32_t dir : 1; /* [ 5], r, 0x0 */
uint32_t err_code : 2; /* [ 7: 6], r, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} error_code_capture;
/* 0x34 : op mode:r reset mode:rw */
union {
struct {
uint32_t err_warning_limit : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} error_warning_limit;
/* 0x38 : op mode:r reset mode:rw */
union {
struct {
uint32_t rx_err_cnt : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} rx_err_count;
/* 0x3c : op mode:r reset mode:rw */
union {
struct {
uint32_t tx_err_cnt : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} tx_err_count;
/* 0x40 : op mode: w -> tx_frm_info
r -> rx_frm_info
reset mode:rw -> acceptance_code0 */
union {
struct {
uint32_t txrx_frm_info_or_acceptance_code0 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_frm_info_or_acceptance_code0;
/* 0x44 : op mode:w -> tx_id1
r -> rx_id1
reset mode:rw -> acceptance_code1 */
union {
struct {
uint32_t txrx_id1_or_acceptance_code1 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_id1_or_acceptance_code1;
/* 0x48 : op mode:w -> tx_id2
r -> rx_id2
reset mode:rw -> acceptance_code2 */
union {
struct {
uint32_t txrx_id2_or_acceptance_code2 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_id2_or_acceptance_code2;
/* 0x4c : op mode:w -> tx_data1_s or tx_id3
r -> rx_data1_s or rx_id3
reset mode:rw -> acceptance_code3 */
union {
struct {
uint32_t txrx_data1_s_or_txrx_id3_e_or_acceptance_code3 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data1_s_or_txrx_id3_e_or_acceptance_code3;
/* 0x50 : op mode:w -> tx_data2_s or tx_id4
r -> rx_data2_s or rx_id4
reset mode:rw -> acceptance_mask0 */
union {
struct {
uint32_t txrx_data2_s_or_txrx_id4_e_or_acceptance_mask0 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data2_s_or_txrx_id4_e_or_acceptance_mask0;
/* 0x54 : op mode:w -> tx_data3_s or tx_data1_e
r -> rx_data3_s or rx_data1_e
reset mode:rw -> acceptance_mask1 */
union {
struct {
uint32_t txrx_data3_s_or_txrx_data1_e_or_acceptance_mask1 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data3_s_or_txrx_data1_e_or_acceptance_mask1;
/* 0x58 : op mode:w -> tx_data4_s or tx_data2_e
r -> rx_data4_s or rx_data2_e
reset mode:rw -> acceptance_mask2 */
union {
struct {
uint32_t txrx_data4_s_or_txrx_data2_e_or_acceptance_mask2 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data4_s_or_txrx_data2_e_or_acceptance_mask2;
/* 0x5c : op mode:w -> tx_data5_s or tx_data3_e
r -> rx_data5_s or rx_data3_e
reset mode:rw -> acceptance_mask3 */
union {
struct {
uint32_t txrx_data5_s_or_txrx_data3_e_or_acceptance_mask3 : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data5_s_or_txrx_data3_e_or_acceptance_mask3;
/* 0x60 : op mode:w -> tx_data6_s or tx_data4_e
r -> rx_data6_s or rx_data4_e
reset mode:r -> 8'H00 */
union {
struct {
uint32_t txrx_data6_s_or_txrx_data4_e : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data6_s_or_txrx_data4_e;
/* 0x64 : op mode:w -> tx_data7_s or tx_data5_e
r -> rx_data7_s or rx_data5_e
reset mode:r -> 8'H00 */
union {
struct {
uint32_t txrx_data7_s_or_txrx_data5_e : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data7_s_or_txrx_data5_e;
/* 0x68 : op mode:w -> tx_data8_s or tx_data6_e
r -> rx_data8_s or rx_data6_e
reset mode:r -> 8'H00 */
union {
struct {
uint32_t txrx_data8_s_or_txrx_data6_e : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data8_s_or_txrx_data6_e;
/* 0x6c : op mode:w -> tx_data7_e
r -> rx_data7_e
reset mode:r -> 8'H00 */
union {
struct {
uint32_t txrx_data7_e : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data7_e;
/* 0x70 : op mode:w -> tx_data8_e
r -> rx_data8_e
reset mode:r -> 8'H00 */
union {
struct {
uint32_t txrx_data8_e : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} txrx_data8_e;
/* 0x74 : op mode:r reset mode:r */
union {
struct {
uint32_t rx_message_cnt : 8; /* [ 7: 0], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} rx_message_count;
/* 0x78 reserved */
uint8_t RESERVED0x78[4];
/* 0x7c : op mode:rw reset mode:rw iso11898_mode and cbp can be write in reset mode only */
union {
struct {
uint32_t cd : 3; /* [ 2: 0], r/w, 0x0 */
uint32_t clockoff : 1; /* [ 3], r/w, 0x0 */
uint32_t readonly : 1; /* [ 4], r, 0x0 */
uint32_t rxinten : 1; /* [ 5], r/w, 0x0 */
uint32_t cbp : 1; /* [ 6], r/w, 0x0 */
uint32_t iso11898_mode : 1; /* [ 7], r/w, 0x0 */
uint32_t reserved_8_31 : 24; /* [31: 8], rsvd, 0x0 */
} BF;
uint32_t WORD;
} clock_divider;
};
typedef volatile struct iso11898_reg iso11898_reg_t;
#endif /* __ISO11898_REG_H__ */
|
42147106558524b03d0152b02fdcf1e87101b59b
|
f9e7d65cb784c01a0200145ba8d289afe41d4a56
|
/driver/retimer/nb7v904m.c
|
2defda52a27d9c823c4b17c9a43f14d287ddeb4c
|
[
"BSD-3-Clause"
] |
permissive
|
FrameworkComputer/EmbeddedController
|
ad7086769e87d0a4179eae96a7c9ff5e383ff54e
|
f6d6b927eed71550d3475411cfc3e59abe5cef2a
|
refs/heads/hx20-hx30
| 2023-08-08T20:45:10.621169
| 2023-05-26T07:03:59
| 2023-05-26T07:03:59
| 447,021,040
| 846
| 48
|
BSD-3-Clause
| 2023-05-26T07:04:59
| 2022-01-12T00:11:14
|
C
|
UTF-8
|
C
| false
| false
| 3,539
|
c
|
nb7v904m.c
|
/* Copyright 2020 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* ON Semiconductor NB7V904M USB Type-C DisplayPort Alt Mode Redriver
*/
#include <stdbool.h>
#include "common.h"
#include "console.h"
#include "ec_commands.h"
#include "i2c.h"
#include "nb7v904m.h"
#include "usb_mux.h"
#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
static int nb7v904m_write(const struct usb_mux *me, int offset, int data)
{
return i2c_write8(me->i2c_port,
me->i2c_addr_flags,
offset, data);
}
static int nb7v904m_read(const struct usb_mux *me, int offset, int *regval)
{
return i2c_read8(me->i2c_port,
me->i2c_addr_flags,
offset, regval);
}
static int set_low_power_mode(const struct usb_mux *me, bool enable)
{
int regval;
int rv;
rv = nb7v904m_read(me, NB7V904M_REG_GEN_DEV_SETTINGS, ®val);
if (rv)
return rv;
if (enable)
regval &= ~NB7V904M_CHIP_EN;
else
regval |= NB7V904M_CHIP_EN;
return nb7v904m_write(me, NB7V904M_REG_GEN_DEV_SETTINGS, regval);
}
static int nb7v904m_enter_low_power_mode(const struct usb_mux *me)
{
int rv = set_low_power_mode(me, 1);
if (rv)
CPRINTS("C%d: NB7V904M: Failed to enter low power mode!",
me->usb_port);
return rv;
}
static int nb7v904m_init(const struct usb_mux *me)
{
int rv = set_low_power_mode(me, 0);
if (rv)
CPRINTS("C%d: NB7V904M: init failed!", me->usb_port);
return rv;
}
static int nb7v904m_set_mux(const struct usb_mux *me, mux_state_t mux_state)
{
int rv = EC_SUCCESS;
int regval;
int flipped = !!(mux_state & USB_PD_MUX_POLARITY_INVERTED);
/* Turn off redriver if it's not needed at all. */
if (mux_state == USB_PD_MUX_NONE)
return nb7v904m_enter_low_power_mode(me);
rv = nb7v904m_init(me);
if (rv)
return rv;
/* Clear operation mode field */
rv = nb7v904m_read(me, NB7V904M_REG_GEN_DEV_SETTINGS, ®val);
if (rv) {
CPRINTS("C%d %s: Failed to obtain dev settings!",
me->usb_port, __func__);
return rv;
}
regval &= ~NB7V904M_OP_MODE_MASK;
if (mux_state & USB_PD_MUX_USB_ENABLED) {
/* USB with DP */
if (mux_state & USB_PD_MUX_DP_ENABLED) {
if (flipped)
regval |= NB7V904M_USB_DP_FLIPPED;
else
regval |= NB7V904M_USB_DP_NORMAL;
} else {
/* USB only */
regval |= NB7V904M_USB_ONLY;
}
} else if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* 4 lanes DP */
regval |= NB7V904M_DP_ONLY;
}
if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* Connect AUX */
rv = nb7v904m_write(me, NB7V904M_REG_AUX_CH_CTRL, flipped ?
NB7V904M_AUX_CH_FLIPPED :
NB7V904M_AUX_CH_NORMAL);
/* Enable all channels for DP */
regval |= NB7V904M_CH_EN_MASK;
} else {
/* Disconnect AUX since it's not being used. */
rv = nb7v904m_write(me, NB7V904M_REG_AUX_CH_CTRL,
NB7V904M_AUX_CH_HI_Z);
/* Disable the unused channels to save power */
regval &= ~NB7V904M_CH_EN_MASK;
if (flipped) {
/* Only enable channels A & B */
regval |= NB7V904M_CH_A_EN | NB7V904M_CH_B_EN;
} else {
/* Only enable channels C & D */
regval |= NB7V904M_CH_C_EN | NB7V904M_CH_D_EN;
}
}
rv |= nb7v904m_write(me, NB7V904M_REG_GEN_DEV_SETTINGS, regval);
if (rv)
CPRINTS("C%d: %s failed!", me->usb_port, __func__);
return rv;
}
const struct usb_mux_driver nb7v904m_usb_redriver_drv = {
.enter_low_power_mode = &nb7v904m_enter_low_power_mode,
.init = &nb7v904m_init,
.set = &nb7v904m_set_mux,
};
|
3ccc972609b323a503764983f8bc15a4d6f6e096
|
6ff85b80c6fe1b3ad5416a304b93551a5e80de10
|
/C/Syntax/Pragma.c
|
bacdfc0f5c250be6ebf46ce1bab08aae6005d424
|
[
"MIT"
] |
permissive
|
maniero/SOpt
|
c600cc2333e0a47ce013be3516bbb8080502ff2a
|
5d17e1a9cbf115eaea6d30af2079d0c92ffff7a3
|
refs/heads/master
| 2023-08-10T16:48:46.058739
| 2023-08-10T13:42:17
| 2023-08-10T13:42:17
| 78,631,930
| 1,002
| 136
|
MIT
| 2023-01-28T12:10:01
| 2017-01-11T11:19:24
|
C#
|
UTF-8
|
C
| false
| false
| 123
|
c
|
Pragma.c
|
#pragma comment(lib, "nomeDaBiblioteca")
#pragma comment(user, "texto aqui")
//https://pt.stackoverflow.com/q/155564/101
|
d7bb2787d7e9ae653cd7e6952717be5e683213e1
|
95fee909ed97348eaf50d8cff1b67b77b7b4e267
|
/tb/data/config.h
|
2833503caddba0829b7ce4db6fc0a65c6ea228c5
|
[
"BSD-3-Clause"
] |
permissive
|
Xilinx/finn-hlslib
|
46a39a0c4425a55aea6f4d2bbaf19b8e01ee7a7c
|
27fd7a2b50a031cbb97142e8c2d1f234671de579
|
refs/heads/master
| 2023-08-03T11:10:46.391064
| 2023-05-24T15:28:05
| 2023-05-24T15:28:05
| 209,122,537
| 152
| 63
|
BSD-3-Clause
| 2023-07-25T20:53:42
| 2019-09-17T17:57:58
|
C++
|
UTF-8
|
C
| false
| false
| 273
|
h
|
config.h
|
#define KERNEL_DIM 3
#define SIMD1 2
#define PE1 2
#define MMV1 1
#define WIDTH 1
#define IFM_Channels1 4
#define OFM_Channels1 16
#define IFMDim1 3
#define OFMDim1 1
#define STRIDE 1
#define INPUT_PRECISION 8
#define TILE1 144
#define ACTIVATION_PRECISION 16
|
6d533c4b5b87dfa62fc19f93ea9a2a7d91fa7e0a
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/os/board/rtl8730e/src/component/soc/amebad2/atf/include/bl31/interrupt_mgmt.h
|
935bf776655e56b509cb2a5119f52d051f9ef810
|
[
"Apache-2.0",
"GPL-1.0-or-later",
"BSD-3-Clause",
"ISC",
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 5,571
|
h
|
interrupt_mgmt.h
|
/*
* Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef INTERRUPT_MGMT_H
#define INTERRUPT_MGMT_H
#include <arch.h>
#include <lib/utils_def.h>
/*******************************************************************************
* Constants for the types of interrupts recognised by the IM framework
******************************************************************************/
#define INTR_TYPE_S_EL1 U(0)
#define INTR_TYPE_EL3 U(1)
#define INTR_TYPE_NS U(2)
#define MAX_INTR_TYPES U(3)
#define INTR_TYPE_INVAL MAX_INTR_TYPES
/* Interrupt routing modes */
#define INTR_ROUTING_MODE_PE 0
#define INTR_ROUTING_MODE_ANY 1
/*
* Constant passed to the interrupt handler in the 'id' field when the
* framework does not read the gic registers to determine the interrupt id.
*/
#define INTR_ID_UNAVAILABLE U(0xFFFFFFFF)
/*******************************************************************************
* Mask for _both_ the routing model bits in the 'flags' parameter and
* constants to define the valid routing models for each supported interrupt
* type
******************************************************************************/
#define INTR_RM_FLAGS_SHIFT U(0x0)
#define INTR_RM_FLAGS_MASK U(0x3)
/* Routed to EL3 from NS. Taken to S-EL1 from Secure */
#define INTR_SEL1_VALID_RM0 U(0x2)
/* Routed to EL3 from NS and Secure */
#define INTR_SEL1_VALID_RM1 U(0x3)
/* Routed to EL1/EL2 from NS and to S-EL1 from Secure */
#define INTR_NS_VALID_RM0 U(0x0)
/* Routed to EL1/EL2 from NS and to EL3 from Secure */
#define INTR_NS_VALID_RM1 U(0x1)
/* Routed to EL3 from NS. Taken to S-EL1 from Secure and handed over to EL3 */
#define INTR_EL3_VALID_RM0 U(0x2)
/* Routed to EL3 from NS and Secure */
#define INTR_EL3_VALID_RM1 U(0x3)
/* This is the default routing model */
#define INTR_DEFAULT_RM U(0x0)
/*******************************************************************************
* Constants for the _individual_ routing model bits in the 'flags' field for
* each interrupt type and mask to validate the 'flags' parameter while
* registering an interrupt handler
******************************************************************************/
#define INTR_TYPE_FLAGS_MASK U(0xFFFFFFFC)
#define INTR_RM_FROM_SEC_SHIFT SECURE /* BIT[0] */
#define INTR_RM_FROM_NS_SHIFT NON_SECURE /* BIT[1] */
#define INTR_RM_FROM_FLAG_MASK U(1)
#define get_interrupt_rm_flag(flag, ss) \
((((flag) >> INTR_RM_FLAGS_SHIFT) >> (ss)) & INTR_RM_FROM_FLAG_MASK)
#define set_interrupt_rm_flag(flag, ss) ((flag) |= U(1) << (ss))
#define clr_interrupt_rm_flag(flag, ss) ((flag) &= ~(U(1) << (ss)))
/*******************************************************************************
* Macros to set the 'flags' parameter passed to an interrupt type handler. Only
* the flag to indicate the security state when the exception was generated is
* supported.
******************************************************************************/
#define INTR_SRC_SS_FLAG_SHIFT U(0) /* BIT[0] */
#define INTR_SRC_SS_FLAG_MASK U(1)
#define set_interrupt_src_ss(flag, val) ((flag) |= (val) << INTR_SRC_SS_FLAG_SHIFT)
#define clr_interrupt_src_ss(flag) ((flag) &= ~(U(1) << INTR_SRC_SS_FLAG_SHIFT))
#define get_interrupt_src_ss(flag) (((flag) >> INTR_SRC_SS_FLAG_SHIFT) & \
INTR_SRC_SS_FLAG_MASK)
#ifndef __ASSEMBLER__
#include <errno.h>
#include <stdint.h>
/*******************************************************************************
* Helpers to validate the routing model bits in the 'flags' for a type
* of interrupt. If the model does not match one of the valid masks
* -EINVAL is returned.
******************************************************************************/
static inline int32_t validate_sel1_interrupt_rm(uint32_t x)
{
if ((x == INTR_SEL1_VALID_RM0) || (x == INTR_SEL1_VALID_RM1))
return 0;
return -EINVAL;
}
static inline int32_t validate_ns_interrupt_rm(uint32_t x)
{
if ((x == INTR_NS_VALID_RM0) || (x == INTR_NS_VALID_RM1))
return 0;
return -EINVAL;
}
static inline int32_t validate_el3_interrupt_rm(uint32_t x)
{
#if EL3_EXCEPTION_HANDLING
/*
* With EL3 exception handling, EL3 interrupts are always routed to EL3
* from both Secure and Non-secure, and therefore INTR_EL3_VALID_RM1 is
* the only valid routing model.
*/
if (x == INTR_EL3_VALID_RM1)
return 0;
#else
if ((x == INTR_EL3_VALID_RM0) || (x == INTR_EL3_VALID_RM1))
return 0;
#endif
return -EINVAL;
}
/*******************************************************************************
* Prototype for defining a handler for an interrupt type
******************************************************************************/
typedef uint64_t (*interrupt_type_handler_t)(uint32_t id,
uint32_t flags,
void *handle,
void *cookie);
/*******************************************************************************
* Function & variable prototypes
******************************************************************************/
u_register_t get_scr_el3_from_routing_model(uint32_t security_state);
int32_t set_routing_model(uint32_t type, uint32_t flags);
int32_t register_interrupt_type_handler(uint32_t type,
interrupt_type_handler_t handler,
uint32_t flags);
interrupt_type_handler_t get_interrupt_type_handler(uint32_t type);
int disable_intr_rm_local(uint32_t type, uint32_t security_state);
int enable_intr_rm_local(uint32_t type, uint32_t security_state);
#endif /*__ASSEMBLER__*/
#endif /* INTERRUPT_MGMT_H */
|
9478f54dd5b0b084f6ab419256ce6a34f94684fa
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/hpmicro/libraries/hpm_sdk/soc/HPM6360/hpm_gpiom_soc_drv.h
|
1377f27d619f021f534962281bb28744a09a59c2
|
[
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 391
|
h
|
hpm_gpiom_soc_drv.h
|
/*
* Copyright (c) 2021 HPMicro
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef HPM_GPIOM_SOC_DRV_H
#define HPM_GPIOM_SOC_DRV_H
/**
* @addtogroup gpiom_interface GPIOM driver APIs
* @{
*/
/* @brief gpiom control module */
typedef enum hpm6300_gpiom_gpio {
gpiom_soc_gpio0 = 0,
gpiom_core0_fast = 1,
} gpiom_gpio_t;
/**
* @}
*/
#endif /* HPM_GPIOM_SOC_DRV_H */
|
a914653594ff93ca0af12820b22c9c3e233cdace
|
bed3ac926beac0f4e0293303d7b2a6031ee476c9
|
/Modules/ThirdParty/OpenJPEG/src/openjpeg/opj_includes.h
|
ed1a06a0db923fa6bd04970a2da2b6f8acce75dd
|
[
"IJG",
"Zlib",
"LicenseRef-scancode-proprietary-license",
"SMLNJ",
"BSD-3-Clause",
"BSD-4.3TAHOE",
"LicenseRef-scancode-free-unknown",
"Spencer-86",
"LicenseRef-scancode-llnl",
"FSFUL",
"Libpng",
"libtiff",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-hdf5",
"MIT",
"NTP",
"LicenseRef-scancode-mit-old-style",
"GPL-1.0-or-later",
"LicenseRef-scancode-unknown-license-reference",
"MPL-2.0",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] |
permissive
|
InsightSoftwareConsortium/ITK
|
ed9dbbc5b8b3f7511f007c0fc0eebb3ad37b88eb
|
3eb8fd7cdfbc5ac2d0c2e5e776848a4cbab3d7e1
|
refs/heads/master
| 2023-08-31T17:21:47.754304
| 2023-08-31T00:58:51
| 2023-08-31T14:12:21
| 800,928
| 1,229
| 656
|
Apache-2.0
| 2023-09-14T17:54:00
| 2010-07-27T15:48:04
|
C++
|
UTF-8
|
C
| false
| false
| 3,434
|
h
|
opj_includes.h
|
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPJ_INCLUDES_H
#define OPJ_INCLUDES_H
/*
==========================================================
Standard includes used by the library
==========================================================
*/
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
/*
==========================================================
OpenJPEG interface
==========================================================
*/
/*
==========================================================
OpenJPEG modules
==========================================================
*/
/* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__
#define __attribute__(x) /* __attribute__(x) */
#endif
/*
The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ...
*/
#ifndef INLINE
#if defined(_MSC_VER)
#define INLINE __inline
#elif defined(__GNUC__)
#define INLINE __inline__
#elif defined(__MWERKS__)
#define INLINE inline
#else
/* add other compilers here ... */
#define INLINE
#endif /* defined(<Compiler>) */
#endif /* INLINE */
/* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L)
/* Not a C99 compiler */
#ifdef __GNUC__
#define restrict __restrict__
#else
#define restrict /* restrict */
#endif
#endif
/* MSVC and Borland C do not have lrintf */
#if defined(_MSC_VER) || defined(__BORLANDC__)
/* MSVC 64bits doesn't support _asm */
#if !defined(_WIN64)
static INLINE long opj_lrintf(float f){
int i;
_asm{
fld f
fistp i
};
return i;
}
#else
static INLINE long opj_lrintf(float x){
long r;
if (x>=0.f)
{
x+=0.5f;
}
else
{
x-=0.5f;
}
r = (long)(x);
if ( x != (float)(r) ) return r;
return 2*(r/2);
}
#endif
#endif
#endif /* OPJ_INCLUDES_H */
|
d0d803f435397d37a8cf8d67cc59d00333bd1902
|
7f6c235b0598353549959c18f69eefd20b766907
|
/libsrc/_DEVELOPMENT/EXAMPLES/sms/AstroForce/src/main.c
|
0321434d1553c3bbfba36fde89de9f4dc113321d
|
[
"ClArtistic"
] |
permissive
|
z88dk/z88dk
|
46dfd4905f36d99333173cadd0a660839befc9f0
|
8b07f37cc43c5d9ffe69b563c80763491d8faff7
|
refs/heads/master
| 2023-09-04T19:29:49.254958
| 2023-09-03T20:51:24
| 2023-09-03T20:51:24
| 54,035,569
| 820
| 263
|
NOASSERTION
| 2023-09-05T11:09:04
| 2016-03-16T13:48:16
|
Assembly
|
UTF-8
|
C
| false
| false
| 3,264
|
c
|
main.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include <arch/sms/SMSlib.h>
#include <arch/sms/PSGlib.h>
#include "fixedbank.h"
#include "vars.h"
#include "funcs.h"
#include "timeredlabel.h"
#include "map.h"
#include "scroller.h"
#include "barrom.h"
#include "explosion.h"
#include "warning.h"
#include "introovni.h"
#include "introsideplayer.h"
#include "introstar.h"
#include "intro3object.h"
#include "waveship.h"
#include "rectship.h"
#include "bombship.h"
#include "spreadship.h"
#include "stage4middleboss.h"
#include "stage4endboss.h"
#include "stage4endbossb.h"
#include "stage4object.h"
#include "stage2object.h"
#include "ww2plane.h"
#include "ww2planeb.h"
#include "ww2zeppelin.h"
#include "ww2ship.h"
#include "stage5missile.h"
#include "stage5endboss.h"
#include "fortressphantom.h"
#include "fortresssearcher.h"
#include "fortresswave.h"
#include "fortresscannon.h"
#include "fortressdoor.h"
#include "stage1middlebossc.h"
#include "stage1middlebossb.h"
#include "stage1middleboss.h"
#include "stage1endboss.h"
#include "monsterblob.h"
#include "monstermissil.h"
#include "monsterhead.h"
#include "stage7middleboss.h"
#include "stage7endboss.h"
#include "stage7object.h"
#include "vulcanstation.h"
#include "vulcantank.h"
#include "vulcanvulcan.h"
#include "vulcanlava.h"
#include "vulcanbird.h"
#include "vulcanlaser.h"
#include "stage2endboss.h"
#include "spacestation.h"
#include "spaceasteroid.h"
#include "spaceshooter.h"
#include "stage3laser.h"
#include "stage3endboss.h"
#include "stage3star.h"
#include "stage6endboss.h"
#include "stage6endbossb.h"
#include "stage6object.h"
#include "skullbone.h"
#include "turnship.h"
#include "stage8lateral.h"
#include "stage8bossa.h"
#include "stage8bossb.h"
#include "stage8bossc.h"
#include "rsgthing.h"
#include "enemy.h"
#include "scripter.h"
#include "mikgamesstage.h"
#include "logostage.h"
#include "jukeboxstage.h"
#include "intro1stage.h"
#include "intro2stage.h"
#include "intro3stage.h"
#include "intro4stage.h"
#include "finishstage.h"
#include "introstage.h"
#include "selectorstage.h"
#include "gameoverstage.h"
#include "stage1.h"
#include "stage2.h"
#include "stage3.h"
#include "stage4.h"
#include "stage5.h"
#include "stage6.h"
#include "stage7.h"
#include "stage8.h"
#include "enemyshoot.h"
#include "playershoot.h"
#include "powerup.h"
#include "player.h"
#include "playstage.h"
// Inicio del juego
void main()
{
// Iniciamos la consola
InitConsole();
// Lo ponemos solo aquí
gamelevel=0;
gamestock=3;
// Forever bucle
while(1)
{
// Testing
/*
stagenum=8;
numplayers=6;
InitPlayerConstants();
InitPlayer();
InitPlayStage();
*/
// Mikgames
InitMikGamesStage();
// Game intro
InitIntroStage(1);
InitIntroStage(4);
InitIntroStage(2);
// Logo
InitLogoStage();
// If we have jukebox before play
if(dojukebox==1)
InitJukeboxStage();
// Selector
InitSelectorStage();
// Init stage and players
stagenum=1;
numplayers=gamestock;
// Stage looping
while(stagenum<10)
{
if(stagenum==0)
InitGameoverStage();
else if(stagenum==9)
{
InitIntroStage(5);
InitIntroStage(3);
}
else InitPlayStage();
}
}
}
// SMS_EMBED_SEGA_ROM_HEADER(57300,0); //;)
|
eac3fb1cd681b43fe19bfef9feb7afaee4485f19
|
d6cdbe2e256f2a3c81e239f98727d44f4f54564e
|
/src/asm.c
|
5cb8dd4a3576ec8726c43d708bfd35326a9fa3f2
|
[
"MIT"
] |
permissive
|
zakirullin/tiny-compiler
|
22e848b0cd4020e1863543813e66a51170142f8a
|
94ed7a983d13dc5d9111e0c2c28a8d363dfc499e
|
refs/heads/master
| 2023-04-08T16:55:59.572844
| 2023-02-06T18:30:03
| 2023-02-06T18:30:03
| 88,029,459
| 583
| 56
|
MIT
| 2023-03-16T11:05:24
| 2017-04-12T08:40:25
|
C
|
UTF-8
|
C
| false
| false
| 729
|
c
|
asm.c
|
#include <stdio.h>
#include "asm.h"
#include "sym.h"
#include "codes.h"
#include "gen.h"
void print_asm(byte *code)
{
byte cur_byte;
int i = 0;
while ((cur_byte = code[i++]) != RET) {
switch (cur_byte) {
case PUSH: printf("PUSH %i\n", code[i++]); break;
case READ: cur_byte = code[i++]; printf("READ %s\n",get_sym(cur_byte)->name); break;
case WRITE: cur_byte = code[i++]; printf("WRITE %s\n", get_sym(cur_byte)->name); break;
case ADD: puts("ADD POP, POP"); break;
case SUB: puts("SUB POP, POP"); break;
case MUL: puts("MUL POP, POP"); break;
case DIV: puts("DIV POP, POP"); break;
}
}
puts("RET");
}
|
a8ef4ae5af06372f7c8ff127e3b1487a42697753
|
07327b5e8b2831b12352bf7c6426bfda60129da7
|
/Include/10.0.14393.0/um/dshowasf.h
|
c99f3887a7aa381485e71fb085a2481ededcc596
|
[] |
no_license
|
tpn/winsdk-10
|
ca279df0fce03f92036e90fb04196d6282a264b7
|
9b69fd26ac0c7d0b83d378dba01080e93349c2ed
|
refs/heads/master
| 2021-01-10T01:56:18.586459
| 2018-02-19T21:26:31
| 2018-02-19T21:29:50
| 44,352,845
| 218
| 432
| null | null | null | null |
UTF-8
|
C
| false
| false
| 20,585
|
h
|
dshowasf.h
|
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 8.01.0618 */
/* @@MIDL_FILE_HEADING( ) */
/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 500
#endif
/* verify that the <rpcsal.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCSAL_H_VERSION__
#define __REQUIRED_RPCSAL_H_VERSION__ 100
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif /* __RPCNDR_H_VERSION__ */
#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/
#ifndef __dshowasf_h__
#define __dshowasf_h__
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/* Forward Declarations */
#ifndef __IAMWMBufferPass_FWD_DEFINED__
#define __IAMWMBufferPass_FWD_DEFINED__
typedef interface IAMWMBufferPass IAMWMBufferPass;
#endif /* __IAMWMBufferPass_FWD_DEFINED__ */
#ifndef __IAMWMBufferPassCallback_FWD_DEFINED__
#define __IAMWMBufferPassCallback_FWD_DEFINED__
typedef interface IAMWMBufferPassCallback IAMWMBufferPassCallback;
#endif /* __IAMWMBufferPassCallback_FWD_DEFINED__ */
#ifndef __IConfigAsfWriter_FWD_DEFINED__
#define __IConfigAsfWriter_FWD_DEFINED__
typedef interface IConfigAsfWriter IConfigAsfWriter;
#endif /* __IConfigAsfWriter_FWD_DEFINED__ */
#ifndef __IConfigAsfWriter2_FWD_DEFINED__
#define __IConfigAsfWriter2_FWD_DEFINED__
typedef interface IConfigAsfWriter2 IConfigAsfWriter2;
#endif /* __IConfigAsfWriter2_FWD_DEFINED__ */
/* header files for imported files */
#include "unknwn.h"
#include "objidl.h"
#include "strmif.h"
#include "wmsdkidl.h"
#ifdef __cplusplus
extern "C"{
#endif
/* interface __MIDL_itf_dshowasf_0000_0000 */
/* [local] */
//=========================================================================
//
// Microsoft Windows Media Technologies
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//=========================================================================
#include <winapifamily.h>
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
EXTERN_GUID( IID_IConfigAsfWriter2,0x7989ccaa, 0x53f0, 0x44f0, 0x88, 0x4a, 0xf3, 0xb0, 0x3f, 0x6a, 0xe0, 0x66 );
EXTERN_GUID( IID_IConfigAsfWriter,0x45086030,0xF7E4,0x486a,0xB5,0x04,0x82,0x6B,0xB5,0x79,0x2A,0x3B );
EXTERN_GUID( IID_IAMWMBufferPass,0x6dd816d7, 0xe740, 0x4123, 0x9e, 0x24, 0x24, 0x44, 0x41, 0x26, 0x44, 0xd8 );
EXTERN_GUID( IID_IAMWMBufferPassCallback,0xb25b8372, 0xd2d2, 0x44b2, 0x86, 0x53, 0x1b, 0x8d, 0xae, 0x33, 0x24, 0x89 );
#ifndef EC_PREPROCESS_COMPLETE
#define EC_PREPROCESS_COMPLETE 0x56
#endif
extern RPC_IF_HANDLE __MIDL_itf_dshowasf_0000_0000_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_dshowasf_0000_0000_v0_0_s_ifspec;
#ifndef __IAMWMBufferPass_INTERFACE_DEFINED__
#define __IAMWMBufferPass_INTERFACE_DEFINED__
/* interface IAMWMBufferPass */
/* [unique][uuid][object] */
EXTERN_C const IID IID_IAMWMBufferPass;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("6DD816D7-E740-4123-9E24-2444412644D8")
IAMWMBufferPass : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE SetNotify(
/* [in] */ __RPC__in_opt IAMWMBufferPassCallback *pCallback) = 0;
};
#else /* C style interface */
typedef struct IAMWMBufferPassVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
__RPC__in IAMWMBufferPass * This,
/* [in] */ __RPC__in REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
__RPC__in IAMWMBufferPass * This);
ULONG ( STDMETHODCALLTYPE *Release )(
__RPC__in IAMWMBufferPass * This);
HRESULT ( STDMETHODCALLTYPE *SetNotify )(
__RPC__in IAMWMBufferPass * This,
/* [in] */ __RPC__in_opt IAMWMBufferPassCallback *pCallback);
END_INTERFACE
} IAMWMBufferPassVtbl;
interface IAMWMBufferPass
{
CONST_VTBL struct IAMWMBufferPassVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IAMWMBufferPass_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IAMWMBufferPass_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IAMWMBufferPass_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IAMWMBufferPass_SetNotify(This,pCallback) \
( (This)->lpVtbl -> SetNotify(This,pCallback) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IAMWMBufferPass_INTERFACE_DEFINED__ */
#ifndef __IAMWMBufferPassCallback_INTERFACE_DEFINED__
#define __IAMWMBufferPassCallback_INTERFACE_DEFINED__
/* interface IAMWMBufferPassCallback */
/* [unique][uuid][object] */
EXTERN_C const IID IID_IAMWMBufferPassCallback;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("B25B8372-D2D2-44b2-8653-1B8DAE332489")
IAMWMBufferPassCallback : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Notify(
/* [in] */ __RPC__in_opt INSSBuffer3 *pNSSBuffer3,
/* [in] */ __RPC__in_opt IPin *pPin,
/* [in] */ __RPC__in REFERENCE_TIME *prtStart,
/* [in] */ __RPC__in REFERENCE_TIME *prtEnd) = 0;
};
#else /* C style interface */
typedef struct IAMWMBufferPassCallbackVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
__RPC__in IAMWMBufferPassCallback * This,
/* [in] */ __RPC__in REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
__RPC__in IAMWMBufferPassCallback * This);
ULONG ( STDMETHODCALLTYPE *Release )(
__RPC__in IAMWMBufferPassCallback * This);
HRESULT ( STDMETHODCALLTYPE *Notify )(
__RPC__in IAMWMBufferPassCallback * This,
/* [in] */ __RPC__in_opt INSSBuffer3 *pNSSBuffer3,
/* [in] */ __RPC__in_opt IPin *pPin,
/* [in] */ __RPC__in REFERENCE_TIME *prtStart,
/* [in] */ __RPC__in REFERENCE_TIME *prtEnd);
END_INTERFACE
} IAMWMBufferPassCallbackVtbl;
interface IAMWMBufferPassCallback
{
CONST_VTBL struct IAMWMBufferPassCallbackVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IAMWMBufferPassCallback_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IAMWMBufferPassCallback_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IAMWMBufferPassCallback_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IAMWMBufferPassCallback_Notify(This,pNSSBuffer3,pPin,prtStart,prtEnd) \
( (This)->lpVtbl -> Notify(This,pNSSBuffer3,pPin,prtStart,prtEnd) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IAMWMBufferPassCallback_INTERFACE_DEFINED__ */
/* interface __MIDL_itf_dshowasf_0000_0002 */
/* [local] */
enum _AM_ASFWRITERCONFIG_PARAM
{
AM_CONFIGASFWRITER_PARAM_AUTOINDEX = 1,
AM_CONFIGASFWRITER_PARAM_MULTIPASS = ( AM_CONFIGASFWRITER_PARAM_AUTOINDEX + 1 ) ,
AM_CONFIGASFWRITER_PARAM_DONTCOMPRESS = ( AM_CONFIGASFWRITER_PARAM_MULTIPASS + 1 )
} ;
extern RPC_IF_HANDLE __MIDL_itf_dshowasf_0000_0002_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_dshowasf_0000_0002_v0_0_s_ifspec;
#ifndef __IConfigAsfWriter_INTERFACE_DEFINED__
#define __IConfigAsfWriter_INTERFACE_DEFINED__
/* interface IConfigAsfWriter */
/* [unique][uuid][object] */
EXTERN_C const IID IID_IConfigAsfWriter;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("45086030-F7E4-486a-B504-826BB5792A3B")
IConfigAsfWriter : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE ConfigureFilterUsingProfileId(
/* [in] */ DWORD dwProfileId) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentProfileId(
/* [out] */ __RPC__out DWORD *pdwProfileId) = 0;
virtual HRESULT STDMETHODCALLTYPE ConfigureFilterUsingProfileGuid(
/* [in] */ __RPC__in REFGUID guidProfile) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentProfileGuid(
/* [out] */ __RPC__out GUID *pProfileGuid) = 0;
virtual HRESULT STDMETHODCALLTYPE ConfigureFilterUsingProfile(
/* [in] */ __RPC__in_opt IWMProfile *pProfile) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentProfile(
/* [out] */ __RPC__deref_out_opt IWMProfile **ppProfile) = 0;
virtual HRESULT STDMETHODCALLTYPE SetIndexMode(
/* [in] */ BOOL bIndexFile) = 0;
virtual HRESULT STDMETHODCALLTYPE GetIndexMode(
/* [out] */ __RPC__out BOOL *pbIndexFile) = 0;
};
#else /* C style interface */
typedef struct IConfigAsfWriterVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
__RPC__in IConfigAsfWriter * This,
/* [in] */ __RPC__in REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
__RPC__in IConfigAsfWriter * This);
ULONG ( STDMETHODCALLTYPE *Release )(
__RPC__in IConfigAsfWriter * This);
HRESULT ( STDMETHODCALLTYPE *ConfigureFilterUsingProfileId )(
__RPC__in IConfigAsfWriter * This,
/* [in] */ DWORD dwProfileId);
HRESULT ( STDMETHODCALLTYPE *GetCurrentProfileId )(
__RPC__in IConfigAsfWriter * This,
/* [out] */ __RPC__out DWORD *pdwProfileId);
HRESULT ( STDMETHODCALLTYPE *ConfigureFilterUsingProfileGuid )(
__RPC__in IConfigAsfWriter * This,
/* [in] */ __RPC__in REFGUID guidProfile);
HRESULT ( STDMETHODCALLTYPE *GetCurrentProfileGuid )(
__RPC__in IConfigAsfWriter * This,
/* [out] */ __RPC__out GUID *pProfileGuid);
HRESULT ( STDMETHODCALLTYPE *ConfigureFilterUsingProfile )(
__RPC__in IConfigAsfWriter * This,
/* [in] */ __RPC__in_opt IWMProfile *pProfile);
HRESULT ( STDMETHODCALLTYPE *GetCurrentProfile )(
__RPC__in IConfigAsfWriter * This,
/* [out] */ __RPC__deref_out_opt IWMProfile **ppProfile);
HRESULT ( STDMETHODCALLTYPE *SetIndexMode )(
__RPC__in IConfigAsfWriter * This,
/* [in] */ BOOL bIndexFile);
HRESULT ( STDMETHODCALLTYPE *GetIndexMode )(
__RPC__in IConfigAsfWriter * This,
/* [out] */ __RPC__out BOOL *pbIndexFile);
END_INTERFACE
} IConfigAsfWriterVtbl;
interface IConfigAsfWriter
{
CONST_VTBL struct IConfigAsfWriterVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IConfigAsfWriter_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IConfigAsfWriter_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IConfigAsfWriter_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IConfigAsfWriter_ConfigureFilterUsingProfileId(This,dwProfileId) \
( (This)->lpVtbl -> ConfigureFilterUsingProfileId(This,dwProfileId) )
#define IConfigAsfWriter_GetCurrentProfileId(This,pdwProfileId) \
( (This)->lpVtbl -> GetCurrentProfileId(This,pdwProfileId) )
#define IConfigAsfWriter_ConfigureFilterUsingProfileGuid(This,guidProfile) \
( (This)->lpVtbl -> ConfigureFilterUsingProfileGuid(This,guidProfile) )
#define IConfigAsfWriter_GetCurrentProfileGuid(This,pProfileGuid) \
( (This)->lpVtbl -> GetCurrentProfileGuid(This,pProfileGuid) )
#define IConfigAsfWriter_ConfigureFilterUsingProfile(This,pProfile) \
( (This)->lpVtbl -> ConfigureFilterUsingProfile(This,pProfile) )
#define IConfigAsfWriter_GetCurrentProfile(This,ppProfile) \
( (This)->lpVtbl -> GetCurrentProfile(This,ppProfile) )
#define IConfigAsfWriter_SetIndexMode(This,bIndexFile) \
( (This)->lpVtbl -> SetIndexMode(This,bIndexFile) )
#define IConfigAsfWriter_GetIndexMode(This,pbIndexFile) \
( (This)->lpVtbl -> GetIndexMode(This,pbIndexFile) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IConfigAsfWriter_INTERFACE_DEFINED__ */
#ifndef __IConfigAsfWriter2_INTERFACE_DEFINED__
#define __IConfigAsfWriter2_INTERFACE_DEFINED__
/* interface IConfigAsfWriter2 */
/* [unique][uuid][object] */
EXTERN_C const IID IID_IConfigAsfWriter2;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("7989CCAA-53F0-44f0-884A-F3B03F6AE066")
IConfigAsfWriter2 : public IConfigAsfWriter
{
public:
virtual HRESULT STDMETHODCALLTYPE StreamNumFromPin(
/* [in] */ __RPC__in_opt IPin *pPin,
/* [out] */ __RPC__out WORD *pwStreamNum) = 0;
virtual HRESULT STDMETHODCALLTYPE SetParam(
/* [in] */ DWORD dwParam,
/* [in] */ DWORD dwParam1,
/* [in] */ DWORD dwParam2) = 0;
virtual HRESULT STDMETHODCALLTYPE GetParam(
/* [in] */ DWORD dwParam,
/* [out] */ __RPC__out DWORD *pdwParam1,
/* [out] */ __RPC__out DWORD *pdwParam2) = 0;
virtual HRESULT STDMETHODCALLTYPE ResetMultiPassState( void) = 0;
};
#else /* C style interface */
typedef struct IConfigAsfWriter2Vtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ __RPC__in REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
__RPC__in IConfigAsfWriter2 * This);
ULONG ( STDMETHODCALLTYPE *Release )(
__RPC__in IConfigAsfWriter2 * This);
HRESULT ( STDMETHODCALLTYPE *ConfigureFilterUsingProfileId )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ DWORD dwProfileId);
HRESULT ( STDMETHODCALLTYPE *GetCurrentProfileId )(
__RPC__in IConfigAsfWriter2 * This,
/* [out] */ __RPC__out DWORD *pdwProfileId);
HRESULT ( STDMETHODCALLTYPE *ConfigureFilterUsingProfileGuid )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ __RPC__in REFGUID guidProfile);
HRESULT ( STDMETHODCALLTYPE *GetCurrentProfileGuid )(
__RPC__in IConfigAsfWriter2 * This,
/* [out] */ __RPC__out GUID *pProfileGuid);
HRESULT ( STDMETHODCALLTYPE *ConfigureFilterUsingProfile )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ __RPC__in_opt IWMProfile *pProfile);
HRESULT ( STDMETHODCALLTYPE *GetCurrentProfile )(
__RPC__in IConfigAsfWriter2 * This,
/* [out] */ __RPC__deref_out_opt IWMProfile **ppProfile);
HRESULT ( STDMETHODCALLTYPE *SetIndexMode )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ BOOL bIndexFile);
HRESULT ( STDMETHODCALLTYPE *GetIndexMode )(
__RPC__in IConfigAsfWriter2 * This,
/* [out] */ __RPC__out BOOL *pbIndexFile);
HRESULT ( STDMETHODCALLTYPE *StreamNumFromPin )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ __RPC__in_opt IPin *pPin,
/* [out] */ __RPC__out WORD *pwStreamNum);
HRESULT ( STDMETHODCALLTYPE *SetParam )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ DWORD dwParam,
/* [in] */ DWORD dwParam1,
/* [in] */ DWORD dwParam2);
HRESULT ( STDMETHODCALLTYPE *GetParam )(
__RPC__in IConfigAsfWriter2 * This,
/* [in] */ DWORD dwParam,
/* [out] */ __RPC__out DWORD *pdwParam1,
/* [out] */ __RPC__out DWORD *pdwParam2);
HRESULT ( STDMETHODCALLTYPE *ResetMultiPassState )(
__RPC__in IConfigAsfWriter2 * This);
END_INTERFACE
} IConfigAsfWriter2Vtbl;
interface IConfigAsfWriter2
{
CONST_VTBL struct IConfigAsfWriter2Vtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IConfigAsfWriter2_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IConfigAsfWriter2_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IConfigAsfWriter2_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IConfigAsfWriter2_ConfigureFilterUsingProfileId(This,dwProfileId) \
( (This)->lpVtbl -> ConfigureFilterUsingProfileId(This,dwProfileId) )
#define IConfigAsfWriter2_GetCurrentProfileId(This,pdwProfileId) \
( (This)->lpVtbl -> GetCurrentProfileId(This,pdwProfileId) )
#define IConfigAsfWriter2_ConfigureFilterUsingProfileGuid(This,guidProfile) \
( (This)->lpVtbl -> ConfigureFilterUsingProfileGuid(This,guidProfile) )
#define IConfigAsfWriter2_GetCurrentProfileGuid(This,pProfileGuid) \
( (This)->lpVtbl -> GetCurrentProfileGuid(This,pProfileGuid) )
#define IConfigAsfWriter2_ConfigureFilterUsingProfile(This,pProfile) \
( (This)->lpVtbl -> ConfigureFilterUsingProfile(This,pProfile) )
#define IConfigAsfWriter2_GetCurrentProfile(This,ppProfile) \
( (This)->lpVtbl -> GetCurrentProfile(This,ppProfile) )
#define IConfigAsfWriter2_SetIndexMode(This,bIndexFile) \
( (This)->lpVtbl -> SetIndexMode(This,bIndexFile) )
#define IConfigAsfWriter2_GetIndexMode(This,pbIndexFile) \
( (This)->lpVtbl -> GetIndexMode(This,pbIndexFile) )
#define IConfigAsfWriter2_StreamNumFromPin(This,pPin,pwStreamNum) \
( (This)->lpVtbl -> StreamNumFromPin(This,pPin,pwStreamNum) )
#define IConfigAsfWriter2_SetParam(This,dwParam,dwParam1,dwParam2) \
( (This)->lpVtbl -> SetParam(This,dwParam,dwParam1,dwParam2) )
#define IConfigAsfWriter2_GetParam(This,dwParam,pdwParam1,pdwParam2) \
( (This)->lpVtbl -> GetParam(This,dwParam,pdwParam1,pdwParam2) )
#define IConfigAsfWriter2_ResetMultiPassState(This) \
( (This)->lpVtbl -> ResetMultiPassState(This) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IConfigAsfWriter2_INTERFACE_DEFINED__ */
/* interface __MIDL_itf_dshowasf_0000_0004 */
/* [local] */
////////////////////////////////////////////////////////////////
//
// Windows Media Filters compatibility option flags
//
static DWORD EXCLUDE_SCRIPT_STREAM_DELIVERY_SYNCHRONIZATION = 0x00000001;
////////////////////////////////////////////////////////////////
//
// ATOM strings to match compatibility option flags above for certain applications that don't want to (or not allowed to) update registry entries
// These need to be setup by the application using the WM filters to enable the particular functionality
//
static const WCHAR* g_wszExcludeScriptStreamDeliverySynchronization = L"ExcludeScriptStreamDeliverySynchronization";
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
#pragma endregion
extern RPC_IF_HANDLE __MIDL_itf_dshowasf_0000_0004_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_dshowasf_0000_0004_v0_0_s_ifspec;
/* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */
#ifdef __cplusplus
}
#endif
#endif
|
1d04c6132df4c20c57bf086e1a946cbcb6c566c9
|
26ed9786d3d99134ccbf7a167533e58c2fbb422f
|
/firmware/code/tx_v2/Inc/helpers.h
|
ba8c2de35d005135afd1fc46c58d74bacebc4e05
|
[
"MIT"
] |
permissive
|
dekuNukem/daytripper
|
2e3bd20fa7439419f85ce694e37e391de9623181
|
bfe78c6e6b2a8a09745f00a98955ddafcc408639
|
refs/heads/master
| 2022-10-30T14:42:29.341151
| 2022-10-03T15:05:09
| 2022-10-03T15:05:09
| 144,575,169
| 3,641
| 176
|
MIT
| 2020-04-09T11:27:41
| 2018-08-13T12:13:37
|
C
|
UTF-8
|
C
| false
| false
| 587
|
h
|
helpers.h
|
#ifndef __HELPERS_H
#define __HELPERS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32l0xx_hal.h"
#include "shared.h"
#define DTPR_CMD_TEST 0xa1
#define DTPR_CMD_TRIG 0xb2
#define DTPR_CMD_STAT 0xc3
#define NRF_PAYLOAD_SIZE 6
#define NRF_CHANNEL 115
void build_packet_trig(uint8_t* data_array, uint16_t base, uint16_t this);
uint8_t send_packet(uint8_t* data);
void build_packet_stat(uint8_t* data, uint16_t vbat_mV, uint16_t pot);
void kick_dog(void);
uint32_t get_battery_adc_reading(void);
uint8_t EEPROM_ReadByte(uint16_t addr);
#ifdef __cplusplus
}
#endif
#endif
|
0657b60e5efd4cc2b55f8e6498e75d2d2e525c28
|
b7d4fc29e02e1379b0d44a756b4697dc19f8a792
|
/deps/icu4c/source/layout/AttachmentPosnSubtables.h
|
18bb2799916a164d9a79aaf99045c22ed9f03fb2
|
[
"GPL-1.0-or-later",
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"ICU",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"NAIST-2003",
"BSD-3-Clause",
"LicenseRef-scancode-unicode",
"GPL-3.0-or-later",
"NTP",
"LicenseRef-scancode-unicode-icu-58",
"LicenseRef-scancode-autoconf-simple-exception"
] |
permissive
|
vslavik/poedit
|
45140ca86a853db58ddcbe65ab588da3873c4431
|
1b0940b026b429a10f310d98eeeaadfab271d556
|
refs/heads/master
| 2023-08-29T06:24:16.088676
| 2023-08-14T15:48:18
| 2023-08-14T15:48:18
| 477,156
| 1,424
| 275
|
MIT
| 2023-09-01T16:57:47
| 2010-01-18T08:23:13
|
C++
|
UTF-8
|
C
| false
| false
| 979
|
h
|
AttachmentPosnSubtables.h
|
/*
*
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
*
*/
#ifndef __ATTACHMENTPOSITIONINGSUBTABLES_H
#define __ATTACHMENTPOSITIONINGSUBTABLES_H
/**
* \file
* \internal
*/
#include "LETypes.h"
#include "OpenTypeTables.h"
#include "GlyphPositioningTables.h"
#include "ValueRecords.h"
#include "GlyphIterator.h"
U_NAMESPACE_BEGIN
struct AttachmentPositioningSubtable : GlyphPositioningSubtable
{
Offset baseCoverageTableOffset;
le_uint16 classCount;
Offset markArrayOffset;
Offset baseArrayOffset;
inline le_int32 getBaseCoverage(const LETableReference &base, LEGlyphID baseGlyphId, LEErrorCode &success) const;
le_uint32 process(GlyphIterator *glyphIterator) const;
};
inline le_int32 AttachmentPositioningSubtable::getBaseCoverage(const LETableReference &base, LEGlyphID baseGlyphID, LEErrorCode &success) const
{
return getGlyphCoverage(base, baseCoverageTableOffset, baseGlyphID, success);
}
U_NAMESPACE_END
#endif
|
2d94fe9053bb4f0e0361e4502cb8424daf006144
|
58fe7cb3949dd1930e709696659a0296500b64a6
|
/crypto/s2n_tls13_keys.h
|
5bd7455dc2ce69cfb0a119439c79383603478edb
|
[
"Apache-2.0",
"MIT"
] |
permissive
|
aws/s2n-tls
|
3344638a6a69c6f20665cf6847e1bc4b85f2e558
|
62dc7a6d4876e5eee0dea3690d528a4c7080a1d5
|
refs/heads/main
| 2023-08-31T23:26:33.780048
| 2023-08-31T05:17:33
| 2023-08-31T05:17:33
| 21,287,076
| 513
| 213
|
Apache-2.0
| 2023-09-13T23:52:29
| 2014-06-27T19:37:59
|
C
|
UTF-8
|
C
| false
| false
| 3,721
|
h
|
s2n_tls13_keys.h
|
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#pragma once
#include <stdint.h>
#include "crypto/s2n_hkdf.h"
#include "crypto/s2n_hmac.h"
#include "stuffer/s2n_stuffer.h"
#include "tls/s2n_psk.h"
#include "tls/s2n_tls_parameters.h"
#include "utils/s2n_blob.h"
#include "utils/s2n_mem.h"
#include "utils/s2n_safety.h"
/* Unlike TLS1.2 secrets, TLS1.3 secret lengths vary depending
* on the hash algorithm used to calculate them.
* We allocate enough space for the largest possible secret.
* At the moment, that is 48 bytes for S2N_HASH_SHA384 and
* matches the TLS1.2 secret length.
*/
#define S2N_TLS13_SECRET_MAX_LEN SHA384_DIGEST_LENGTH
struct s2n_tls13_keys {
s2n_hmac_algorithm hmac_algorithm;
s2n_hash_algorithm hash_algorithm;
uint8_t size;
/* we only need to keep these 2 rolling secrets at any point,
* since other secrets to be used can be generated from these
*/
struct s2n_blob extract_secret;
struct s2n_blob derive_secret;
uint8_t extract_secret_bytes[S2N_TLS13_SECRET_MAX_LEN];
uint8_t derive_secret_bytes[S2N_TLS13_SECRET_MAX_LEN];
struct s2n_hmac_state hmac;
};
/* Defines TLS 1.3 HKDF Labels */
extern const struct s2n_blob s2n_tls13_label_derived_secret;
extern const struct s2n_blob s2n_tls13_label_external_psk_binder_key;
extern const struct s2n_blob s2n_tls13_label_resumption_psk_binder_key;
extern const struct s2n_blob s2n_tls13_label_client_early_traffic_secret;
extern const struct s2n_blob s2n_tls13_label_early_exporter_master_secret;
extern const struct s2n_blob s2n_tls13_label_client_handshake_traffic_secret;
extern const struct s2n_blob s2n_tls13_label_server_handshake_traffic_secret;
extern const struct s2n_blob s2n_tls13_label_client_application_traffic_secret;
extern const struct s2n_blob s2n_tls13_label_server_application_traffic_secret;
extern const struct s2n_blob s2n_tls13_label_exporter_master_secret;
extern const struct s2n_blob s2n_tls13_label_resumption_master_secret;
extern const struct s2n_blob s2n_tls13_label_finished;
/* Traffic secret labels */
extern const struct s2n_blob s2n_tls13_label_traffic_secret_key;
extern const struct s2n_blob s2n_tls13_label_traffic_secret_iv;
#define s2n_tls13_key_blob(name, bytes) \
s2n_stack_blob(name, bytes, S2N_TLS13_SECRET_MAX_LEN)
int s2n_tls13_keys_init(struct s2n_tls13_keys *handshake, s2n_hmac_algorithm alg);
int s2n_tls13_keys_free(struct s2n_tls13_keys *keys);
int s2n_tls13_derive_traffic_keys(struct s2n_tls13_keys *handshake, struct s2n_blob *secret, struct s2n_blob *key, struct s2n_blob *iv);
int s2n_tls13_derive_finished_key(struct s2n_tls13_keys *keys, struct s2n_blob *secret_key, struct s2n_blob *output_finish_key);
int s2n_tls13_calculate_finished_mac(struct s2n_tls13_keys *keys, struct s2n_blob *finished_key, struct s2n_hash_state *hash_state, struct s2n_blob *finished_verify);
int s2n_tls13_update_application_traffic_secret(struct s2n_tls13_keys *keys, struct s2n_blob *old_secret, struct s2n_blob *new_secret);
S2N_RESULT s2n_tls13_derive_session_ticket_secret(struct s2n_tls13_keys *keys, struct s2n_blob *resumption_secret,
struct s2n_blob *ticket_nonce, struct s2n_blob *secret_blob);
|
d9657f4c9cf15cf10e6e6e7762d49306cad2a108
|
f79dec3c4033ca3cbb55d8a51a748cc7b8b6fbab
|
/net/kopete/patches/patch-libkopete_avdevice_videodevice.h
|
738f90134c0d0a3a675d2e8a37ae346f3c98936c
|
[] |
no_license
|
jsonn/pkgsrc
|
fb34c4a6a2d350e8e415f3c4955d4989fcd86881
|
c1514b5f4a3726d90e30aa16b0c209adbc276d17
|
refs/heads/trunk
| 2021-01-24T09:10:01.038867
| 2017-07-07T15:49:43
| 2017-07-07T15:49:43
| 2,095,004
| 106
| 47
| null | 2016-09-19T09:26:01
| 2011-07-23T23:49:04
|
Makefile
|
UTF-8
|
C
| false
| false
| 510
|
h
|
patch-libkopete_avdevice_videodevice.h
|
$NetBSD: patch-libkopete_avdevice_videodevice.h,v 1.1 2013/11/07 13:03:07 markd Exp $
--- libkopete/avdevice/videodevice.h.orig 2011-04-01 10:59:27.000000000 +0000
+++ libkopete/avdevice/videodevice.h
@@ -75,6 +75,13 @@
#endif // HAVE_V4L2
#endif // __linux__ __FreeBSD__ ENABLE_AV
+#if (defined(__NetBSD__) || defined(__DragonFly__)) && defined(ENABLE_AV)
+
+#ifdef HAVE_LIBV4L2
+#include <libv4l2.h>
+#endif // HAVE_V4L2
+
+#endif // __NetBSD__ __DragonFly__
#include <qstring.h>
#include <qfile.h>
|
6930e7d748664d27f3e58e017ff057477968c5dc
|
d3c958632858e84bedcce26d6245f93328fdbced
|
/tests/kvm-unit-tests/x86/vmx_tests.c
|
0ccc7e77ca876bcf132e108943c654e4352695c1
|
[
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference",
"GPL-2.0-only",
"LGPL-2.0-only"
] |
permissive
|
copy/v86
|
0cf989542ca0634dc40927da9b0d3c0932c0e361
|
b8a39b11dd2076870699e6cac053556271b9bfab
|
refs/heads/master
| 2023-08-17T02:32:24.107665
| 2023-08-06T20:54:51
| 2023-08-06T20:54:51
| 14,158,237
| 17,313
| 1,555
|
BSD-2-Clause
| 2023-09-14T19:35:47
| 2013-11-06T00:12:12
|
Rust
|
UTF-8
|
C
| false
| false
| 92,645
|
c
|
vmx_tests.c
|
/*
* All test cases of nested virtualization should be in this file
*
* Author : Arthur Chunqi Li <yzt356@gmail.com>
*/
#include "vmx.h"
#include "msr.h"
#include "processor.h"
#include "vm.h"
#include "fwcfg.h"
#include "isr.h"
#include "desc.h"
#include "apic.h"
#include "types.h"
#define NONCANONICAL 0xaaaaaaaaaaaaaaaaull
#define VPID_CAP_INVVPID_TYPES_SHIFT 40
u64 ia32_pat;
u64 ia32_efer;
void *io_bitmap_a, *io_bitmap_b;
u16 ioport;
unsigned long *pml4;
u64 eptp;
void *data_page1, *data_page2;
void *pml_log;
#define PML_INDEX 512
static inline unsigned ffs(unsigned x)
{
int pos = -1;
__asm__ __volatile__("bsf %1, %%eax; cmovnz %%eax, %0"
: "+r"(pos) : "rm"(x) : "eax");
return pos + 1;
}
static inline void vmcall()
{
asm volatile("vmcall");
}
void basic_guest_main()
{
report("Basic VMX test", 1);
}
int basic_exit_handler()
{
report("Basic VMX test", 0);
print_vmexit_info();
return VMX_TEST_EXIT;
}
void vmenter_main()
{
u64 rax;
u64 rsp, resume_rsp;
report("test vmlaunch", 1);
asm volatile(
"mov %%rsp, %0\n\t"
"mov %3, %%rax\n\t"
"vmcall\n\t"
"mov %%rax, %1\n\t"
"mov %%rsp, %2\n\t"
: "=r"(rsp), "=r"(rax), "=r"(resume_rsp)
: "g"(0xABCD));
report("test vmresume", (rax == 0xFFFF) && (rsp == resume_rsp));
}
int vmenter_exit_handler()
{
u64 guest_rip;
ulong reason;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
switch (reason) {
case VMX_VMCALL:
if (regs.rax != 0xABCD) {
report("test vmresume", 0);
return VMX_TEST_VMEXIT;
}
regs.rax = 0xFFFF;
vmcs_write(GUEST_RIP, guest_rip + 3);
return VMX_TEST_RESUME;
default:
report("test vmresume", 0);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
u32 preempt_scale;
volatile unsigned long long tsc_val;
volatile u32 preempt_val;
u64 saved_rip;
int preemption_timer_init()
{
if (!(ctrl_pin_rev.clr & PIN_PREEMPT)) {
printf("\tPreemption timer is not supported\n");
return VMX_TEST_EXIT;
}
vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) | PIN_PREEMPT);
preempt_val = 10000000;
vmcs_write(PREEMPT_TIMER_VALUE, preempt_val);
preempt_scale = rdmsr(MSR_IA32_VMX_MISC) & 0x1F;
if (!(ctrl_exit_rev.clr & EXI_SAVE_PREEMPT))
printf("\tSave preemption value is not supported\n");
return VMX_TEST_START;
}
void preemption_timer_main()
{
tsc_val = rdtsc();
if (ctrl_exit_rev.clr & EXI_SAVE_PREEMPT) {
vmx_set_test_stage(0);
vmcall();
if (vmx_get_test_stage() == 1)
vmcall();
}
vmx_set_test_stage(1);
while (vmx_get_test_stage() == 1) {
if (((rdtsc() - tsc_val) >> preempt_scale)
> 10 * preempt_val) {
vmx_set_test_stage(2);
vmcall();
}
}
tsc_val = rdtsc();
asm volatile ("hlt");
vmcall();
vmx_set_test_stage(5);
vmcall();
}
int preemption_timer_exit_handler()
{
bool guest_halted;
u64 guest_rip;
ulong reason;
u32 insn_len;
u32 ctrl_exit;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
insn_len = vmcs_read(EXI_INST_LEN);
switch (reason) {
case VMX_PREEMPT:
switch (vmx_get_test_stage()) {
case 1:
case 2:
report("busy-wait for preemption timer",
((rdtsc() - tsc_val) >> preempt_scale) >=
preempt_val);
vmx_set_test_stage(3);
vmcs_write(PREEMPT_TIMER_VALUE, preempt_val);
return VMX_TEST_RESUME;
case 3:
guest_halted =
(vmcs_read(GUEST_ACTV_STATE) == ACTV_HLT);
report("preemption timer during hlt",
((rdtsc() - tsc_val) >> preempt_scale) >=
preempt_val && guest_halted);
vmx_set_test_stage(4);
vmcs_write(PIN_CONTROLS,
vmcs_read(PIN_CONTROLS) & ~PIN_PREEMPT);
vmcs_write(GUEST_ACTV_STATE, ACTV_ACTIVE);
return VMX_TEST_RESUME;
case 4:
report("preemption timer with 0 value",
saved_rip == guest_rip);
break;
default:
report("Invalid stage.", false);
print_vmexit_info();
break;
}
break;
case VMX_VMCALL:
vmcs_write(GUEST_RIP, guest_rip + insn_len);
switch (vmx_get_test_stage()) {
case 0:
report("Keep preemption value",
vmcs_read(PREEMPT_TIMER_VALUE) == preempt_val);
vmx_set_test_stage(1);
vmcs_write(PREEMPT_TIMER_VALUE, preempt_val);
ctrl_exit = (vmcs_read(EXI_CONTROLS) |
EXI_SAVE_PREEMPT) & ctrl_exit_rev.clr;
vmcs_write(EXI_CONTROLS, ctrl_exit);
return VMX_TEST_RESUME;
case 1:
report("Save preemption value",
vmcs_read(PREEMPT_TIMER_VALUE) < preempt_val);
return VMX_TEST_RESUME;
case 2:
report("busy-wait for preemption timer", 0);
vmx_set_test_stage(3);
vmcs_write(PREEMPT_TIMER_VALUE, preempt_val);
return VMX_TEST_RESUME;
case 3:
report("preemption timer during hlt", 0);
vmx_set_test_stage(4);
/* fall through */
case 4:
vmcs_write(PIN_CONTROLS,
vmcs_read(PIN_CONTROLS) | PIN_PREEMPT);
vmcs_write(PREEMPT_TIMER_VALUE, 0);
saved_rip = guest_rip + insn_len;
return VMX_TEST_RESUME;
case 5:
report("preemption timer with 0 value (vmcall stage 5)", 0);
break;
default:
// Should not reach here
report("unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
break;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) & ~PIN_PREEMPT);
return VMX_TEST_VMEXIT;
}
void msr_bmp_init()
{
void *msr_bitmap;
u32 ctrl_cpu0;
msr_bitmap = alloc_page();
memset(msr_bitmap, 0x0, PAGE_SIZE);
ctrl_cpu0 = vmcs_read(CPU_EXEC_CTRL0);
ctrl_cpu0 |= CPU_MSR_BITMAP;
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu0);
vmcs_write(MSR_BITMAP, (u64)msr_bitmap);
}
static int test_ctrl_pat_init()
{
u64 ctrl_ent;
u64 ctrl_exi;
msr_bmp_init();
if (!(ctrl_exit_rev.clr & EXI_SAVE_PAT) &&
!(ctrl_exit_rev.clr & EXI_LOAD_PAT) &&
!(ctrl_enter_rev.clr & ENT_LOAD_PAT)) {
printf("\tSave/load PAT is not supported\n");
return 1;
}
ctrl_ent = vmcs_read(ENT_CONTROLS);
ctrl_exi = vmcs_read(EXI_CONTROLS);
ctrl_ent |= ctrl_enter_rev.clr & ENT_LOAD_PAT;
ctrl_exi |= ctrl_exit_rev.clr & (EXI_SAVE_PAT | EXI_LOAD_PAT);
vmcs_write(ENT_CONTROLS, ctrl_ent);
vmcs_write(EXI_CONTROLS, ctrl_exi);
ia32_pat = rdmsr(MSR_IA32_CR_PAT);
vmcs_write(GUEST_PAT, 0x0);
vmcs_write(HOST_PAT, ia32_pat);
return VMX_TEST_START;
}
static void test_ctrl_pat_main()
{
u64 guest_ia32_pat;
guest_ia32_pat = rdmsr(MSR_IA32_CR_PAT);
if (!(ctrl_enter_rev.clr & ENT_LOAD_PAT))
printf("\tENT_LOAD_PAT is not supported.\n");
else {
if (guest_ia32_pat != 0) {
report("Entry load PAT", 0);
return;
}
}
wrmsr(MSR_IA32_CR_PAT, 0x6);
vmcall();
guest_ia32_pat = rdmsr(MSR_IA32_CR_PAT);
if (ctrl_enter_rev.clr & ENT_LOAD_PAT)
report("Entry load PAT", guest_ia32_pat == ia32_pat);
}
static int test_ctrl_pat_exit_handler()
{
u64 guest_rip;
ulong reason;
u64 guest_pat;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
switch (reason) {
case VMX_VMCALL:
guest_pat = vmcs_read(GUEST_PAT);
if (!(ctrl_exit_rev.clr & EXI_SAVE_PAT)) {
printf("\tEXI_SAVE_PAT is not supported\n");
vmcs_write(GUEST_PAT, 0x6);
} else {
report("Exit save PAT", guest_pat == 0x6);
}
if (!(ctrl_exit_rev.clr & EXI_LOAD_PAT))
printf("\tEXI_LOAD_PAT is not supported\n");
else
report("Exit load PAT", rdmsr(MSR_IA32_CR_PAT) == ia32_pat);
vmcs_write(GUEST_PAT, ia32_pat);
vmcs_write(GUEST_RIP, guest_rip + 3);
return VMX_TEST_RESUME;
default:
printf("ERROR : Undefined exit reason, reason = %ld.\n", reason);
break;
}
return VMX_TEST_VMEXIT;
}
static int test_ctrl_efer_init()
{
u64 ctrl_ent;
u64 ctrl_exi;
msr_bmp_init();
ctrl_ent = vmcs_read(ENT_CONTROLS) | ENT_LOAD_EFER;
ctrl_exi = vmcs_read(EXI_CONTROLS) | EXI_SAVE_EFER | EXI_LOAD_EFER;
vmcs_write(ENT_CONTROLS, ctrl_ent & ctrl_enter_rev.clr);
vmcs_write(EXI_CONTROLS, ctrl_exi & ctrl_exit_rev.clr);
ia32_efer = rdmsr(MSR_EFER);
vmcs_write(GUEST_EFER, ia32_efer ^ EFER_NX);
vmcs_write(HOST_EFER, ia32_efer ^ EFER_NX);
return VMX_TEST_START;
}
static void test_ctrl_efer_main()
{
u64 guest_ia32_efer;
guest_ia32_efer = rdmsr(MSR_EFER);
if (!(ctrl_enter_rev.clr & ENT_LOAD_EFER))
printf("\tENT_LOAD_EFER is not supported.\n");
else {
if (guest_ia32_efer != (ia32_efer ^ EFER_NX)) {
report("Entry load EFER", 0);
return;
}
}
wrmsr(MSR_EFER, ia32_efer);
vmcall();
guest_ia32_efer = rdmsr(MSR_EFER);
if (ctrl_enter_rev.clr & ENT_LOAD_EFER)
report("Entry load EFER", guest_ia32_efer == ia32_efer);
}
static int test_ctrl_efer_exit_handler()
{
u64 guest_rip;
ulong reason;
u64 guest_efer;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
switch (reason) {
case VMX_VMCALL:
guest_efer = vmcs_read(GUEST_EFER);
if (!(ctrl_exit_rev.clr & EXI_SAVE_EFER)) {
printf("\tEXI_SAVE_EFER is not supported\n");
vmcs_write(GUEST_EFER, ia32_efer);
} else {
report("Exit save EFER", guest_efer == ia32_efer);
}
if (!(ctrl_exit_rev.clr & EXI_LOAD_EFER)) {
printf("\tEXI_LOAD_EFER is not supported\n");
wrmsr(MSR_EFER, ia32_efer ^ EFER_NX);
} else {
report("Exit load EFER", rdmsr(MSR_EFER) == (ia32_efer ^ EFER_NX));
}
vmcs_write(GUEST_PAT, ia32_efer);
vmcs_write(GUEST_RIP, guest_rip + 3);
return VMX_TEST_RESUME;
default:
printf("ERROR : Undefined exit reason, reason = %ld.\n", reason);
break;
}
return VMX_TEST_VMEXIT;
}
u32 guest_cr0, guest_cr4;
static void cr_shadowing_main()
{
u32 cr0, cr4, tmp;
// Test read through
vmx_set_test_stage(0);
guest_cr0 = read_cr0();
if (vmx_get_test_stage() == 1)
report("Read through CR0", 0);
else
vmcall();
vmx_set_test_stage(1);
guest_cr4 = read_cr4();
if (vmx_get_test_stage() == 2)
report("Read through CR4", 0);
else
vmcall();
// Test write through
guest_cr0 = guest_cr0 ^ (X86_CR0_TS | X86_CR0_MP);
guest_cr4 = guest_cr4 ^ (X86_CR4_TSD | X86_CR4_DE);
vmx_set_test_stage(2);
write_cr0(guest_cr0);
if (vmx_get_test_stage() == 3)
report("Write throuth CR0", 0);
else
vmcall();
vmx_set_test_stage(3);
write_cr4(guest_cr4);
if (vmx_get_test_stage() == 4)
report("Write through CR4", 0);
else
vmcall();
// Test read shadow
vmx_set_test_stage(4);
vmcall();
cr0 = read_cr0();
if (vmx_get_test_stage() != 5)
report("Read shadowing CR0", cr0 == guest_cr0);
vmx_set_test_stage(5);
cr4 = read_cr4();
if (vmx_get_test_stage() != 6)
report("Read shadowing CR4", cr4 == guest_cr4);
// Test write shadow (same value with shadow)
vmx_set_test_stage(6);
write_cr0(guest_cr0);
if (vmx_get_test_stage() == 7)
report("Write shadowing CR0 (same value with shadow)", 0);
else
vmcall();
vmx_set_test_stage(7);
write_cr4(guest_cr4);
if (vmx_get_test_stage() == 8)
report("Write shadowing CR4 (same value with shadow)", 0);
else
vmcall();
// Test write shadow (different value)
vmx_set_test_stage(8);
tmp = guest_cr0 ^ X86_CR0_TS;
asm volatile("mov %0, %%rsi\n\t"
"mov %%rsi, %%cr0\n\t"
::"m"(tmp)
:"rsi", "memory", "cc");
report("Write shadowing different X86_CR0_TS", vmx_get_test_stage() == 9);
vmx_set_test_stage(9);
tmp = guest_cr0 ^ X86_CR0_MP;
asm volatile("mov %0, %%rsi\n\t"
"mov %%rsi, %%cr0\n\t"
::"m"(tmp)
:"rsi", "memory", "cc");
report("Write shadowing different X86_CR0_MP", vmx_get_test_stage() == 10);
vmx_set_test_stage(10);
tmp = guest_cr4 ^ X86_CR4_TSD;
asm volatile("mov %0, %%rsi\n\t"
"mov %%rsi, %%cr4\n\t"
::"m"(tmp)
:"rsi", "memory", "cc");
report("Write shadowing different X86_CR4_TSD", vmx_get_test_stage() == 11);
vmx_set_test_stage(11);
tmp = guest_cr4 ^ X86_CR4_DE;
asm volatile("mov %0, %%rsi\n\t"
"mov %%rsi, %%cr4\n\t"
::"m"(tmp)
:"rsi", "memory", "cc");
report("Write shadowing different X86_CR4_DE", vmx_get_test_stage() == 12);
}
static int cr_shadowing_exit_handler()
{
u64 guest_rip;
ulong reason;
u32 insn_len;
u32 exit_qual;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
insn_len = vmcs_read(EXI_INST_LEN);
exit_qual = vmcs_read(EXI_QUALIFICATION);
switch (reason) {
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 0:
report("Read through CR0", guest_cr0 == vmcs_read(GUEST_CR0));
break;
case 1:
report("Read through CR4", guest_cr4 == vmcs_read(GUEST_CR4));
break;
case 2:
report("Write through CR0", guest_cr0 == vmcs_read(GUEST_CR0));
break;
case 3:
report("Write through CR4", guest_cr4 == vmcs_read(GUEST_CR4));
break;
case 4:
guest_cr0 = vmcs_read(GUEST_CR0) ^ (X86_CR0_TS | X86_CR0_MP);
guest_cr4 = vmcs_read(GUEST_CR4) ^ (X86_CR4_TSD | X86_CR4_DE);
vmcs_write(CR0_MASK, X86_CR0_TS | X86_CR0_MP);
vmcs_write(CR0_READ_SHADOW, guest_cr0 & (X86_CR0_TS | X86_CR0_MP));
vmcs_write(CR4_MASK, X86_CR4_TSD | X86_CR4_DE);
vmcs_write(CR4_READ_SHADOW, guest_cr4 & (X86_CR4_TSD | X86_CR4_DE));
break;
case 6:
report("Write shadowing CR0 (same value)",
guest_cr0 == (vmcs_read(GUEST_CR0) ^ (X86_CR0_TS | X86_CR0_MP)));
break;
case 7:
report("Write shadowing CR4 (same value)",
guest_cr4 == (vmcs_read(GUEST_CR4) ^ (X86_CR4_TSD | X86_CR4_DE)));
break;
default:
// Should not reach here
report("unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
case VMX_CR:
switch (vmx_get_test_stage()) {
case 4:
report("Read shadowing CR0", 0);
vmx_inc_test_stage();
break;
case 5:
report("Read shadowing CR4", 0);
vmx_inc_test_stage();
break;
case 6:
report("Write shadowing CR0 (same value)", 0);
vmx_inc_test_stage();
break;
case 7:
report("Write shadowing CR4 (same value)", 0);
vmx_inc_test_stage();
break;
case 8:
case 9:
// 0x600 encodes "mov %esi, %cr0"
if (exit_qual == 0x600)
vmx_inc_test_stage();
break;
case 10:
case 11:
// 0x604 encodes "mov %esi, %cr4"
if (exit_qual == 0x604)
vmx_inc_test_stage();
break;
default:
// Should not reach here
report("unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
static int iobmp_init()
{
u32 ctrl_cpu0;
io_bitmap_a = alloc_page();
io_bitmap_b = alloc_page();
memset(io_bitmap_a, 0x0, PAGE_SIZE);
memset(io_bitmap_b, 0x0, PAGE_SIZE);
ctrl_cpu0 = vmcs_read(CPU_EXEC_CTRL0);
ctrl_cpu0 |= CPU_IO_BITMAP;
ctrl_cpu0 &= (~CPU_IO);
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu0);
vmcs_write(IO_BITMAP_A, (u64)io_bitmap_a);
vmcs_write(IO_BITMAP_B, (u64)io_bitmap_b);
return VMX_TEST_START;
}
static void iobmp_main()
{
// stage 0, test IO pass
vmx_set_test_stage(0);
inb(0x5000);
outb(0x0, 0x5000);
report("I/O bitmap - I/O pass", vmx_get_test_stage() == 0);
// test IO width, in/out
((u8 *)io_bitmap_a)[0] = 0xFF;
vmx_set_test_stage(2);
inb(0x0);
report("I/O bitmap - trap in", vmx_get_test_stage() == 3);
vmx_set_test_stage(3);
outw(0x0, 0x0);
report("I/O bitmap - trap out", vmx_get_test_stage() == 4);
vmx_set_test_stage(4);
inl(0x0);
report("I/O bitmap - I/O width, long", vmx_get_test_stage() == 5);
// test low/high IO port
vmx_set_test_stage(5);
((u8 *)io_bitmap_a)[0x5000 / 8] = (1 << (0x5000 % 8));
inb(0x5000);
report("I/O bitmap - I/O port, low part", vmx_get_test_stage() == 6);
vmx_set_test_stage(6);
((u8 *)io_bitmap_b)[0x1000 / 8] = (1 << (0x1000 % 8));
inb(0x9000);
report("I/O bitmap - I/O port, high part", vmx_get_test_stage() == 7);
// test partial pass
vmx_set_test_stage(7);
inl(0x4FFF);
report("I/O bitmap - partial pass", vmx_get_test_stage() == 8);
// test overrun
vmx_set_test_stage(8);
memset(io_bitmap_a, 0x0, PAGE_SIZE);
memset(io_bitmap_b, 0x0, PAGE_SIZE);
inl(0xFFFF);
report("I/O bitmap - overrun", vmx_get_test_stage() == 9);
vmx_set_test_stage(9);
vmcall();
outb(0x0, 0x0);
report("I/O bitmap - ignore unconditional exiting",
vmx_get_test_stage() == 9);
vmx_set_test_stage(10);
vmcall();
outb(0x0, 0x0);
report("I/O bitmap - unconditional exiting",
vmx_get_test_stage() == 11);
}
static int iobmp_exit_handler()
{
u64 guest_rip;
ulong reason, exit_qual;
u32 insn_len, ctrl_cpu0;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
exit_qual = vmcs_read(EXI_QUALIFICATION);
insn_len = vmcs_read(EXI_INST_LEN);
switch (reason) {
case VMX_IO:
switch (vmx_get_test_stage()) {
case 0:
case 1:
vmx_inc_test_stage();
break;
case 2:
report("I/O bitmap - I/O width, byte",
(exit_qual & VMX_IO_SIZE_MASK) == _VMX_IO_BYTE);
report("I/O bitmap - I/O direction, in", exit_qual & VMX_IO_IN);
vmx_inc_test_stage();
break;
case 3:
report("I/O bitmap - I/O width, word",
(exit_qual & VMX_IO_SIZE_MASK) == _VMX_IO_WORD);
report("I/O bitmap - I/O direction, out",
!(exit_qual & VMX_IO_IN));
vmx_inc_test_stage();
break;
case 4:
report("I/O bitmap - I/O width, long",
(exit_qual & VMX_IO_SIZE_MASK) == _VMX_IO_LONG);
vmx_inc_test_stage();
break;
case 5:
if (((exit_qual & VMX_IO_PORT_MASK) >> VMX_IO_PORT_SHIFT) == 0x5000)
vmx_inc_test_stage();
break;
case 6:
if (((exit_qual & VMX_IO_PORT_MASK) >> VMX_IO_PORT_SHIFT) == 0x9000)
vmx_inc_test_stage();
break;
case 7:
if (((exit_qual & VMX_IO_PORT_MASK) >> VMX_IO_PORT_SHIFT) == 0x4FFF)
vmx_inc_test_stage();
break;
case 8:
if (((exit_qual & VMX_IO_PORT_MASK) >> VMX_IO_PORT_SHIFT) == 0xFFFF)
vmx_inc_test_stage();
break;
case 9:
case 10:
ctrl_cpu0 = vmcs_read(CPU_EXEC_CTRL0);
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu0 & ~CPU_IO);
vmx_inc_test_stage();
break;
default:
// Should not reach here
report("unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 9:
ctrl_cpu0 = vmcs_read(CPU_EXEC_CTRL0);
ctrl_cpu0 |= CPU_IO | CPU_IO_BITMAP;
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu0);
break;
case 10:
ctrl_cpu0 = vmcs_read(CPU_EXEC_CTRL0);
ctrl_cpu0 = (ctrl_cpu0 & ~CPU_IO_BITMAP) | CPU_IO;
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu0);
break;
default:
// Should not reach here
report("unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
default:
printf("guest_rip = %#lx\n", guest_rip);
printf("\tERROR : Undefined exit reason, reason = %ld.\n", reason);
break;
}
return VMX_TEST_VMEXIT;
}
#define INSN_CPU0 0
#define INSN_CPU1 1
#define INSN_ALWAYS_TRAP 2
#define FIELD_EXIT_QUAL (1 << 0)
#define FIELD_INSN_INFO (1 << 1)
asm(
"insn_hlt: hlt;ret\n\t"
"insn_invlpg: invlpg 0x12345678;ret\n\t"
"insn_mwait: xor %eax, %eax; xor %ecx, %ecx; mwait;ret\n\t"
"insn_rdpmc: xor %ecx, %ecx; rdpmc;ret\n\t"
"insn_rdtsc: rdtsc;ret\n\t"
"insn_cr3_load: mov cr3,%rax; mov %rax,%cr3;ret\n\t"
"insn_cr3_store: mov %cr3,%rax;ret\n\t"
#ifdef __x86_64__
"insn_cr8_load: mov %rax,%cr8;ret\n\t"
"insn_cr8_store: mov %cr8,%rax;ret\n\t"
#endif
"insn_monitor: xor %eax, %eax; xor %ecx, %ecx; xor %edx, %edx; monitor;ret\n\t"
"insn_pause: pause;ret\n\t"
"insn_wbinvd: wbinvd;ret\n\t"
"insn_cpuid: mov $10, %eax; cpuid;ret\n\t"
"insn_invd: invd;ret\n\t"
"insn_sgdt: sgdt gdt64_desc;ret\n\t"
"insn_lgdt: lgdt gdt64_desc;ret\n\t"
"insn_sidt: sidt idt_descr;ret\n\t"
"insn_lidt: lidt idt_descr;ret\n\t"
"insn_sldt: sldt %ax;ret\n\t"
"insn_lldt: xor %eax, %eax; lldt %ax;ret\n\t"
"insn_str: str %ax;ret\n\t"
);
extern void insn_hlt();
extern void insn_invlpg();
extern void insn_mwait();
extern void insn_rdpmc();
extern void insn_rdtsc();
extern void insn_cr3_load();
extern void insn_cr3_store();
#ifdef __x86_64__
extern void insn_cr8_load();
extern void insn_cr8_store();
#endif
extern void insn_monitor();
extern void insn_pause();
extern void insn_wbinvd();
extern void insn_sgdt();
extern void insn_lgdt();
extern void insn_sidt();
extern void insn_lidt();
extern void insn_sldt();
extern void insn_lldt();
extern void insn_str();
extern void insn_cpuid();
extern void insn_invd();
u32 cur_insn;
u64 cr3;
struct insn_table {
const char *name;
u32 flag;
void (*insn_func)();
u32 type;
u32 reason;
ulong exit_qual;
u32 insn_info;
// Use FIELD_EXIT_QUAL and FIELD_INSN_INFO to define
// which field need to be tested, reason is always tested
u32 test_field;
};
/*
* Add more test cases of instruction intercept here. Elements in this
* table is:
* name/control flag/insn function/type/exit reason/exit qulification/
* instruction info/field to test
* The last field defines which fields (exit_qual and insn_info) need to be
* tested in exit handler. If set to 0, only "reason" is checked.
*/
static struct insn_table insn_table[] = {
// Flags for Primary Processor-Based VM-Execution Controls
{"HLT", CPU_HLT, insn_hlt, INSN_CPU0, 12, 0, 0, 0},
{"INVLPG", CPU_INVLPG, insn_invlpg, INSN_CPU0, 14,
0x12345678, 0, FIELD_EXIT_QUAL},
{"MWAIT", CPU_MWAIT, insn_mwait, INSN_CPU0, 36, 0, 0, 0},
{"RDPMC", CPU_RDPMC, insn_rdpmc, INSN_CPU0, 15, 0, 0, 0},
{"RDTSC", CPU_RDTSC, insn_rdtsc, INSN_CPU0, 16, 0, 0, 0},
{"CR3 load", CPU_CR3_LOAD, insn_cr3_load, INSN_CPU0, 28, 0x3, 0,
FIELD_EXIT_QUAL},
{"CR3 store", CPU_CR3_STORE, insn_cr3_store, INSN_CPU0, 28, 0x13, 0,
FIELD_EXIT_QUAL},
#ifdef __x86_64__
{"CR8 load", CPU_CR8_LOAD, insn_cr8_load, INSN_CPU0, 28, 0x8, 0,
FIELD_EXIT_QUAL},
{"CR8 store", CPU_CR8_STORE, insn_cr8_store, INSN_CPU0, 28, 0x18, 0,
FIELD_EXIT_QUAL},
#endif
{"MONITOR", CPU_MONITOR, insn_monitor, INSN_CPU0, 39, 0, 0, 0},
{"PAUSE", CPU_PAUSE, insn_pause, INSN_CPU0, 40, 0, 0, 0},
// Flags for Secondary Processor-Based VM-Execution Controls
{"WBINVD", CPU_WBINVD, insn_wbinvd, INSN_CPU1, 54, 0, 0, 0},
{"DESC_TABLE (SGDT)", CPU_DESC_TABLE, insn_sgdt, INSN_CPU1, 46, 0, 0, 0},
{"DESC_TABLE (LGDT)", CPU_DESC_TABLE, insn_lgdt, INSN_CPU1, 46, 0, 0, 0},
{"DESC_TABLE (SIDT)", CPU_DESC_TABLE, insn_sidt, INSN_CPU1, 46, 0, 0, 0},
{"DESC_TABLE (LIDT)", CPU_DESC_TABLE, insn_lidt, INSN_CPU1, 46, 0, 0, 0},
{"DESC_TABLE (SLDT)", CPU_DESC_TABLE, insn_sldt, INSN_CPU1, 47, 0, 0, 0},
{"DESC_TABLE (LLDT)", CPU_DESC_TABLE, insn_lldt, INSN_CPU1, 47, 0, 0, 0},
{"DESC_TABLE (STR)", CPU_DESC_TABLE, insn_str, INSN_CPU1, 47, 0, 0, 0},
/* LTR causes a #GP if done with a busy selector, so it is not tested. */
// Instructions always trap
{"CPUID", 0, insn_cpuid, INSN_ALWAYS_TRAP, 10, 0, 0, 0},
{"INVD", 0, insn_invd, INSN_ALWAYS_TRAP, 13, 0, 0, 0},
// Instructions never trap
{NULL},
};
static int insn_intercept_init()
{
u32 ctrl_cpu;
ctrl_cpu = ctrl_cpu_rev[0].set | CPU_SECONDARY;
ctrl_cpu &= ctrl_cpu_rev[0].clr;
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu);
vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu_rev[1].set);
cr3 = read_cr3();
return VMX_TEST_START;
}
static void insn_intercept_main()
{
for (cur_insn = 0; insn_table[cur_insn].name != NULL; cur_insn++) {
vmx_set_test_stage(cur_insn * 2);
if ((insn_table[cur_insn].type == INSN_CPU0 &&
!(ctrl_cpu_rev[0].clr & insn_table[cur_insn].flag)) ||
(insn_table[cur_insn].type == INSN_CPU1 &&
!(ctrl_cpu_rev[1].clr & insn_table[cur_insn].flag))) {
printf("\tCPU_CTRL%d.CPU_%s is not supported.\n",
insn_table[cur_insn].type - INSN_CPU0,
insn_table[cur_insn].name);
continue;
}
if ((insn_table[cur_insn].type == INSN_CPU0 &&
!(ctrl_cpu_rev[0].set & insn_table[cur_insn].flag)) ||
(insn_table[cur_insn].type == INSN_CPU1 &&
!(ctrl_cpu_rev[1].set & insn_table[cur_insn].flag))) {
/* skip hlt, it stalls the guest and is tested below */
if (insn_table[cur_insn].insn_func != insn_hlt)
insn_table[cur_insn].insn_func();
report("execute %s", vmx_get_test_stage() == cur_insn * 2,
insn_table[cur_insn].name);
} else if (insn_table[cur_insn].type != INSN_ALWAYS_TRAP)
printf("\tCPU_CTRL%d.CPU_%s always traps.\n",
insn_table[cur_insn].type - INSN_CPU0,
insn_table[cur_insn].name);
vmcall();
insn_table[cur_insn].insn_func();
report("intercept %s", vmx_get_test_stage() == cur_insn * 2 + 1,
insn_table[cur_insn].name);
vmx_set_test_stage(cur_insn * 2 + 1);
vmcall();
}
}
static int insn_intercept_exit_handler()
{
u64 guest_rip;
u32 reason;
ulong exit_qual;
u32 insn_len;
u32 insn_info;
bool pass;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
exit_qual = vmcs_read(EXI_QUALIFICATION);
insn_len = vmcs_read(EXI_INST_LEN);
insn_info = vmcs_read(EXI_INST_INFO);
if (reason == VMX_VMCALL) {
u32 val = 0;
if (insn_table[cur_insn].type == INSN_CPU0)
val = vmcs_read(CPU_EXEC_CTRL0);
else if (insn_table[cur_insn].type == INSN_CPU1)
val = vmcs_read(CPU_EXEC_CTRL1);
if (vmx_get_test_stage() & 1)
val &= ~insn_table[cur_insn].flag;
else
val |= insn_table[cur_insn].flag;
if (insn_table[cur_insn].type == INSN_CPU0)
vmcs_write(CPU_EXEC_CTRL0, val | ctrl_cpu_rev[0].set);
else if (insn_table[cur_insn].type == INSN_CPU1)
vmcs_write(CPU_EXEC_CTRL1, val | ctrl_cpu_rev[1].set);
} else {
pass = (cur_insn * 2 == vmx_get_test_stage()) &&
insn_table[cur_insn].reason == reason;
if (insn_table[cur_insn].test_field & FIELD_EXIT_QUAL &&
insn_table[cur_insn].exit_qual != exit_qual)
pass = false;
if (insn_table[cur_insn].test_field & FIELD_INSN_INFO &&
insn_table[cur_insn].insn_info != insn_info)
pass = false;
if (pass)
vmx_inc_test_stage();
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
}
/* Enables EPT and sets up the identity map. */
static int setup_ept(bool enable_ad)
{
unsigned long end_of_memory;
u32 ctrl_cpu[2];
if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
!(ctrl_cpu_rev[1].clr & CPU_EPT)) {
printf("\tEPT is not supported");
return 1;
}
if (!(ept_vpid.val & EPT_CAP_UC) &&
!(ept_vpid.val & EPT_CAP_WB)) {
printf("\tEPT paging-structure memory type "
"UC&WB are not supported\n");
return 1;
}
if (ept_vpid.val & EPT_CAP_UC)
eptp = EPT_MEM_TYPE_UC;
else
eptp = EPT_MEM_TYPE_WB;
if (!(ept_vpid.val & EPT_CAP_PWL4)) {
printf("\tPWL4 is not supported\n");
return 1;
}
ctrl_cpu[0] = vmcs_read(CPU_EXEC_CTRL0);
ctrl_cpu[1] = vmcs_read(CPU_EXEC_CTRL1);
ctrl_cpu[0] = (ctrl_cpu[0] | CPU_SECONDARY)
& ctrl_cpu_rev[0].clr;
ctrl_cpu[1] = (ctrl_cpu[1] | CPU_EPT)
& ctrl_cpu_rev[1].clr;
vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu[0]);
vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu[1]);
eptp |= (3 << EPTP_PG_WALK_LEN_SHIFT);
pml4 = alloc_page();
memset(pml4, 0, PAGE_SIZE);
eptp |= virt_to_phys(pml4);
if (enable_ad)
eptp |= EPTP_AD_FLAG;
vmcs_write(EPTP, eptp);
end_of_memory = fwcfg_get_u64(FW_CFG_RAM_SIZE);
if (end_of_memory < (1ul << 32))
end_of_memory = (1ul << 32);
/* Cannot use large EPT pages if we need to track EPT
* accessed/dirty bits at 4K granularity.
*/
setup_ept_range(pml4, 0, end_of_memory, 0,
!enable_ad && ept_2m_supported(),
EPT_WA | EPT_RA | EPT_EA);
return 0;
}
static void ept_enable_ad_bits(void)
{
eptp |= EPTP_AD_FLAG;
vmcs_write(EPTP, eptp);
}
static void ept_disable_ad_bits(void)
{
eptp &= ~EPTP_AD_FLAG;
vmcs_write(EPTP, eptp);
}
static void ept_enable_ad_bits_or_skip_test(void)
{
if (!ept_ad_bits_supported())
test_skip("EPT AD bits not supported.");
ept_enable_ad_bits();
}
static int apic_version;
static int ept_init_common(bool have_ad)
{
if (setup_ept(have_ad))
return VMX_TEST_EXIT;
data_page1 = alloc_page();
data_page2 = alloc_page();
memset(data_page1, 0x0, PAGE_SIZE);
memset(data_page2, 0x0, PAGE_SIZE);
*((u32 *)data_page1) = MAGIC_VAL_1;
*((u32 *)data_page2) = MAGIC_VAL_2;
install_ept(pml4, (unsigned long)data_page1, (unsigned long)data_page2,
EPT_RA | EPT_WA | EPT_EA);
apic_version = apic_read(APIC_LVR);
return VMX_TEST_START;
}
static int ept_init()
{
return ept_init_common(false);
}
static void ept_common()
{
vmx_set_test_stage(0);
if (*((u32 *)data_page2) != MAGIC_VAL_1 ||
*((u32 *)data_page1) != MAGIC_VAL_1)
report("EPT basic framework - read", 0);
else {
*((u32 *)data_page2) = MAGIC_VAL_3;
vmcall();
if (vmx_get_test_stage() == 1) {
if (*((u32 *)data_page1) == MAGIC_VAL_3 &&
*((u32 *)data_page2) == MAGIC_VAL_2)
report("EPT basic framework", 1);
else
report("EPT basic framework - remap", 1);
}
}
// Test EPT Misconfigurations
vmx_set_test_stage(1);
vmcall();
*((u32 *)data_page1) = MAGIC_VAL_1;
if (vmx_get_test_stage() != 2) {
report("EPT misconfigurations", 0);
goto t1;
}
vmx_set_test_stage(2);
vmcall();
*((u32 *)data_page1) = MAGIC_VAL_1;
report("EPT misconfigurations", vmx_get_test_stage() == 3);
t1:
// Test EPT violation
vmx_set_test_stage(3);
vmcall();
*((u32 *)data_page1) = MAGIC_VAL_1;
report("EPT violation - page permission", vmx_get_test_stage() == 4);
// Violation caused by EPT paging structure
vmx_set_test_stage(4);
vmcall();
*((u32 *)data_page1) = MAGIC_VAL_2;
report("EPT violation - paging structure", vmx_get_test_stage() == 5);
}
static void ept_main()
{
ept_common();
// Test EPT access to L1 MMIO
vmx_set_test_stage(6);
report("EPT - MMIO access", *((u32 *)0xfee00030UL) == apic_version);
// Test invalid operand for INVEPT
vmcall();
report("EPT - unsupported INVEPT", vmx_get_test_stage() == 7);
}
bool invept_test(int type, u64 eptp)
{
bool ret, supported;
supported = ept_vpid.val & (EPT_CAP_INVEPT_SINGLE >> INVEPT_SINGLE << type);
ret = invept(type, eptp);
if (ret == !supported)
return false;
if (!supported)
printf("WARNING: unsupported invept passed!\n");
else
printf("WARNING: invept failed!\n");
return true;
}
static int pml_exit_handler(void)
{
u16 index, count;
ulong reason = vmcs_read(EXI_REASON) & 0xff;
u64 *pmlbuf = pml_log;
u64 guest_rip = vmcs_read(GUEST_RIP);;
u64 guest_cr3 = vmcs_read(GUEST_CR3);
u32 insn_len = vmcs_read(EXI_INST_LEN);
switch (reason) {
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 0:
index = vmcs_read(GUEST_PML_INDEX);
for (count = index + 1; count < PML_INDEX; count++) {
if (pmlbuf[count] == (u64)data_page2) {
vmx_inc_test_stage();
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page2);
break;
}
}
break;
case 1:
index = vmcs_read(GUEST_PML_INDEX);
/* Keep clearing the dirty bit till a overflow */
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page2);
break;
default:
report("unexpected stage, %d.", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
case VMX_PML_FULL:
vmx_inc_test_stage();
vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
return VMX_TEST_RESUME;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
static int ept_exit_handler_common(bool have_ad)
{
u64 guest_rip;
u64 guest_cr3;
ulong reason;
u32 insn_len;
u32 exit_qual;
static unsigned long data_page1_pte, data_page1_pte_pte;
guest_rip = vmcs_read(GUEST_RIP);
guest_cr3 = vmcs_read(GUEST_CR3);
reason = vmcs_read(EXI_REASON) & 0xff;
insn_len = vmcs_read(EXI_INST_LEN);
exit_qual = vmcs_read(EXI_QUALIFICATION);
switch (reason) {
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 0:
check_ept_ad(pml4, guest_cr3,
(unsigned long)data_page1,
have_ad ? EPT_ACCESS_FLAG : 0,
have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
check_ept_ad(pml4, guest_cr3,
(unsigned long)data_page2,
have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0,
have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page2);
if (have_ad)
ept_sync(INVEPT_SINGLE, eptp);;
if (*((u32 *)data_page1) == MAGIC_VAL_3 &&
*((u32 *)data_page2) == MAGIC_VAL_2) {
vmx_inc_test_stage();
install_ept(pml4, (unsigned long)data_page2,
(unsigned long)data_page2,
EPT_RA | EPT_WA | EPT_EA);
} else
report("EPT basic framework - write", 0);
break;
case 1:
install_ept(pml4, (unsigned long)data_page1,
(unsigned long)data_page1, EPT_WA);
ept_sync(INVEPT_SINGLE, eptp);
break;
case 2:
install_ept(pml4, (unsigned long)data_page1,
(unsigned long)data_page1,
EPT_RA | EPT_WA | EPT_EA |
(2 << EPT_MEM_TYPE_SHIFT));
ept_sync(INVEPT_SINGLE, eptp);
break;
case 3:
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
TEST_ASSERT(get_ept_pte(pml4, (unsigned long)data_page1,
1, &data_page1_pte));
set_ept_pte(pml4, (unsigned long)data_page1,
1, data_page1_pte & ~EPT_PRESENT);
ept_sync(INVEPT_SINGLE, eptp);
break;
case 4:
TEST_ASSERT(get_ept_pte(pml4, (unsigned long)data_page1,
2, &data_page1_pte));
data_page1_pte &= PAGE_MASK;
TEST_ASSERT(get_ept_pte(pml4, data_page1_pte,
2, &data_page1_pte_pte));
set_ept_pte(pml4, data_page1_pte, 2,
data_page1_pte_pte & ~EPT_PRESENT);
ept_sync(INVEPT_SINGLE, eptp);
break;
case 6:
if (!invept_test(0, eptp))
vmx_inc_test_stage();
break;
// Should not reach here
default:
report("ERROR - unexpected stage, %d.", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
case VMX_EPT_MISCONFIG:
switch (vmx_get_test_stage()) {
case 1:
case 2:
vmx_inc_test_stage();
install_ept(pml4, (unsigned long)data_page1,
(unsigned long)data_page1,
EPT_RA | EPT_WA | EPT_EA);
ept_sync(INVEPT_SINGLE, eptp);
break;
// Should not reach here
default:
report("ERROR - unexpected stage, %d.", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
return VMX_TEST_RESUME;
case VMX_EPT_VIOLATION:
switch(vmx_get_test_stage()) {
case 3:
check_ept_ad(pml4, guest_cr3, (unsigned long)data_page1, 0,
have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
if (exit_qual == (EPT_VLT_WR | EPT_VLT_LADDR_VLD |
EPT_VLT_PADDR))
vmx_inc_test_stage();
set_ept_pte(pml4, (unsigned long)data_page1,
1, data_page1_pte | (EPT_PRESENT));
ept_sync(INVEPT_SINGLE, eptp);
break;
case 4:
check_ept_ad(pml4, guest_cr3, (unsigned long)data_page1, 0,
have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
if (exit_qual == (EPT_VLT_RD |
(have_ad ? EPT_VLT_WR : 0) |
EPT_VLT_LADDR_VLD))
vmx_inc_test_stage();
set_ept_pte(pml4, data_page1_pte, 2,
data_page1_pte_pte | (EPT_PRESENT));
ept_sync(INVEPT_SINGLE, eptp);
break;
default:
// Should not reach here
report("ERROR : unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
return VMX_TEST_RESUME;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
static int ept_exit_handler()
{
return ept_exit_handler_common(false);
}
static int eptad_init()
{
int r = ept_init_common(true);
if (r == VMX_TEST_EXIT)
return r;
if ((rdmsr(MSR_IA32_VMX_EPT_VPID_CAP) & EPT_CAP_AD_FLAG) == 0) {
printf("\tEPT A/D bits are not supported");
return VMX_TEST_EXIT;
}
return r;
}
static int pml_init()
{
u32 ctrl_cpu;
int r = eptad_init();
if (r == VMX_TEST_EXIT)
return r;
if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
!(ctrl_cpu_rev[1].clr & CPU_PML)) {
printf("\tPML is not supported");
return VMX_TEST_EXIT;
}
pml_log = alloc_page();
memset(pml_log, 0x0, PAGE_SIZE);
vmcs_write(PMLADDR, (u64)pml_log);
vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) | CPU_PML;
vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu);
return VMX_TEST_START;
}
static void pml_main()
{
int count = 0;
vmx_set_test_stage(0);
*((u32 *)data_page2) = 0x1;
vmcall();
report("PML - Dirty GPA Logging", vmx_get_test_stage() == 1);
while (vmx_get_test_stage() == 1) {
vmcall();
*((u32 *)data_page2) = 0x1;
if (count++ > PML_INDEX)
break;
}
report("PML Full Event", vmx_get_test_stage() == 2);
}
static void eptad_main()
{
ept_common();
}
static int eptad_exit_handler()
{
return ept_exit_handler_common(true);
}
bool invvpid_test(int type, u16 vpid)
{
bool ret, supported;
supported = ept_vpid.val &
(VPID_CAP_INVVPID_ADDR >> INVVPID_ADDR << type);
ret = invvpid(type, vpid, 0);
if (ret == !supported)
return false;
if (!supported)
printf("WARNING: unsupported invvpid passed!\n");
else
printf("WARNING: invvpid failed!\n");
return true;
}
static int vpid_init()
{
u32 ctrl_cpu1;
if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
!(ctrl_cpu_rev[1].clr & CPU_VPID)) {
printf("\tVPID is not supported");
return VMX_TEST_EXIT;
}
ctrl_cpu1 = vmcs_read(CPU_EXEC_CTRL1);
ctrl_cpu1 |= CPU_VPID;
vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu1);
return VMX_TEST_START;
}
static void vpid_main()
{
vmx_set_test_stage(0);
vmcall();
report("INVVPID SINGLE ADDRESS", vmx_get_test_stage() == 1);
vmx_set_test_stage(2);
vmcall();
report("INVVPID SINGLE", vmx_get_test_stage() == 3);
vmx_set_test_stage(4);
vmcall();
report("INVVPID ALL", vmx_get_test_stage() == 5);
}
static int vpid_exit_handler()
{
u64 guest_rip;
ulong reason;
u32 insn_len;
guest_rip = vmcs_read(GUEST_RIP);
reason = vmcs_read(EXI_REASON) & 0xff;
insn_len = vmcs_read(EXI_INST_LEN);
switch (reason) {
case VMX_VMCALL:
switch(vmx_get_test_stage()) {
case 0:
if (!invvpid_test(INVVPID_ADDR, 1))
vmx_inc_test_stage();
break;
case 2:
if (!invvpid_test(INVVPID_CONTEXT_GLOBAL, 1))
vmx_inc_test_stage();
break;
case 4:
if (!invvpid_test(INVVPID_ALL, 1))
vmx_inc_test_stage();
break;
default:
report("ERROR: unexpected stage, %d", false,
vmx_get_test_stage());
print_vmexit_info();
return VMX_TEST_VMEXIT;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
#define TIMER_VECTOR 222
static volatile bool timer_fired;
static void timer_isr(isr_regs_t *regs)
{
timer_fired = true;
apic_write(APIC_EOI, 0);
}
static int interrupt_init(struct vmcs *vmcs)
{
msr_bmp_init();
vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) & ~PIN_EXTINT);
handle_irq(TIMER_VECTOR, timer_isr);
return VMX_TEST_START;
}
static void interrupt_main(void)
{
long long start, loops;
vmx_set_test_stage(0);
apic_write(APIC_LVTT, TIMER_VECTOR);
irq_enable();
apic_write(APIC_TMICT, 1);
for (loops = 0; loops < 10000000 && !timer_fired; loops++)
asm volatile ("nop");
report("direct interrupt while running guest", timer_fired);
apic_write(APIC_TMICT, 0);
irq_disable();
vmcall();
timer_fired = false;
apic_write(APIC_TMICT, 1);
for (loops = 0; loops < 10000000 && !timer_fired; loops++)
asm volatile ("nop");
report("intercepted interrupt while running guest", timer_fired);
irq_enable();
apic_write(APIC_TMICT, 0);
irq_disable();
vmcall();
timer_fired = false;
start = rdtsc();
apic_write(APIC_TMICT, 1000000);
asm volatile ("sti; hlt");
report("direct interrupt + hlt",
rdtsc() - start > 1000000 && timer_fired);
apic_write(APIC_TMICT, 0);
irq_disable();
vmcall();
timer_fired = false;
start = rdtsc();
apic_write(APIC_TMICT, 1000000);
asm volatile ("sti; hlt");
report("intercepted interrupt + hlt",
rdtsc() - start > 10000 && timer_fired);
apic_write(APIC_TMICT, 0);
irq_disable();
vmcall();
timer_fired = false;
start = rdtsc();
apic_write(APIC_TMICT, 1000000);
irq_enable();
asm volatile ("nop");
vmcall();
report("direct interrupt + activity state hlt",
rdtsc() - start > 10000 && timer_fired);
apic_write(APIC_TMICT, 0);
irq_disable();
vmcall();
timer_fired = false;
start = rdtsc();
apic_write(APIC_TMICT, 1000000);
irq_enable();
asm volatile ("nop");
vmcall();
report("intercepted interrupt + activity state hlt",
rdtsc() - start > 10000 && timer_fired);
apic_write(APIC_TMICT, 0);
irq_disable();
vmx_set_test_stage(7);
vmcall();
timer_fired = false;
apic_write(APIC_TMICT, 1);
for (loops = 0; loops < 10000000 && !timer_fired; loops++)
asm volatile ("nop");
report("running a guest with interrupt acknowledgement set", timer_fired);
}
static int interrupt_exit_handler(void)
{
u64 guest_rip = vmcs_read(GUEST_RIP);
ulong reason = vmcs_read(EXI_REASON) & 0xff;
u32 insn_len = vmcs_read(EXI_INST_LEN);
switch (reason) {
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 0:
case 2:
case 5:
vmcs_write(PIN_CONTROLS,
vmcs_read(PIN_CONTROLS) | PIN_EXTINT);
break;
case 7:
vmcs_write(EXI_CONTROLS, vmcs_read(EXI_CONTROLS) | EXI_INTA);
vmcs_write(PIN_CONTROLS,
vmcs_read(PIN_CONTROLS) | PIN_EXTINT);
break;
case 1:
case 3:
vmcs_write(PIN_CONTROLS,
vmcs_read(PIN_CONTROLS) & ~PIN_EXTINT);
break;
case 4:
case 6:
vmcs_write(GUEST_ACTV_STATE, ACTV_HLT);
break;
}
vmx_inc_test_stage();
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
case VMX_EXTINT:
if (vmcs_read(EXI_CONTROLS) & EXI_INTA) {
int vector = vmcs_read(EXI_INTR_INFO) & 0xff;
handle_external_interrupt(vector);
} else {
irq_enable();
asm volatile ("nop");
irq_disable();
}
if (vmx_get_test_stage() >= 2)
vmcs_write(GUEST_ACTV_STATE, ACTV_ACTIVE);
return VMX_TEST_RESUME;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
static int dbgctls_init(struct vmcs *vmcs)
{
u64 dr7 = 0x402;
u64 zero = 0;
msr_bmp_init();
asm volatile(
"mov %0,%%dr0\n\t"
"mov %0,%%dr1\n\t"
"mov %0,%%dr2\n\t"
"mov %1,%%dr7\n\t"
: : "r" (zero), "r" (dr7));
wrmsr(MSR_IA32_DEBUGCTLMSR, 0x1);
vmcs_write(GUEST_DR7, 0x404);
vmcs_write(GUEST_DEBUGCTL, 0x2);
vmcs_write(ENT_CONTROLS, vmcs_read(ENT_CONTROLS) | ENT_LOAD_DBGCTLS);
vmcs_write(EXI_CONTROLS, vmcs_read(EXI_CONTROLS) | EXI_SAVE_DBGCTLS);
return VMX_TEST_START;
}
static void dbgctls_main(void)
{
u64 dr7, debugctl;
asm volatile("mov %%dr7,%0" : "=r" (dr7));
debugctl = rdmsr(MSR_IA32_DEBUGCTLMSR);
/* Commented out: KVM does not support DEBUGCTL so far */
(void)debugctl;
report("Load debug controls", dr7 == 0x404 /* && debugctl == 0x2 */);
dr7 = 0x408;
asm volatile("mov %0,%%dr7" : : "r" (dr7));
wrmsr(MSR_IA32_DEBUGCTLMSR, 0x3);
vmx_set_test_stage(0);
vmcall();
report("Save debug controls", vmx_get_test_stage() == 1);
if (ctrl_enter_rev.set & ENT_LOAD_DBGCTLS ||
ctrl_exit_rev.set & EXI_SAVE_DBGCTLS) {
printf("\tDebug controls are always loaded/saved\n");
return;
}
vmx_set_test_stage(2);
vmcall();
asm volatile("mov %%dr7,%0" : "=r" (dr7));
debugctl = rdmsr(MSR_IA32_DEBUGCTLMSR);
/* Commented out: KVM does not support DEBUGCTL so far */
(void)debugctl;
report("Guest=host debug controls", dr7 == 0x402 /* && debugctl == 0x1 */);
dr7 = 0x408;
asm volatile("mov %0,%%dr7" : : "r" (dr7));
wrmsr(MSR_IA32_DEBUGCTLMSR, 0x3);
vmx_set_test_stage(3);
vmcall();
report("Don't save debug controls", vmx_get_test_stage() == 4);
}
static int dbgctls_exit_handler(void)
{
unsigned int reason = vmcs_read(EXI_REASON) & 0xff;
u32 insn_len = vmcs_read(EXI_INST_LEN);
u64 guest_rip = vmcs_read(GUEST_RIP);
u64 dr7, debugctl;
asm volatile("mov %%dr7,%0" : "=r" (dr7));
debugctl = rdmsr(MSR_IA32_DEBUGCTLMSR);
switch (reason) {
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 0:
if (dr7 == 0x400 && debugctl == 0 &&
vmcs_read(GUEST_DR7) == 0x408 /* &&
Commented out: KVM does not support DEBUGCTL so far
vmcs_read(GUEST_DEBUGCTL) == 0x3 */)
vmx_inc_test_stage();
break;
case 2:
dr7 = 0x402;
asm volatile("mov %0,%%dr7" : : "r" (dr7));
wrmsr(MSR_IA32_DEBUGCTLMSR, 0x1);
vmcs_write(GUEST_DR7, 0x404);
vmcs_write(GUEST_DEBUGCTL, 0x2);
vmcs_write(ENT_CONTROLS,
vmcs_read(ENT_CONTROLS) & ~ENT_LOAD_DBGCTLS);
vmcs_write(EXI_CONTROLS,
vmcs_read(EXI_CONTROLS) & ~EXI_SAVE_DBGCTLS);
break;
case 3:
if (dr7 == 0x400 && debugctl == 0 &&
vmcs_read(GUEST_DR7) == 0x404 /* &&
Commented out: KVM does not support DEBUGCTL so far
vmcs_read(GUEST_DEBUGCTL) == 0x2 */)
vmx_inc_test_stage();
break;
}
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
default:
report("Unknown exit reason, %d", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
struct vmx_msr_entry {
u32 index;
u32 reserved;
u64 value;
} __attribute__((packed));
#define MSR_MAGIC 0x31415926
struct vmx_msr_entry *exit_msr_store, *entry_msr_load, *exit_msr_load;
static int msr_switch_init(struct vmcs *vmcs)
{
msr_bmp_init();
exit_msr_store = alloc_page();
exit_msr_load = alloc_page();
entry_msr_load = alloc_page();
memset(exit_msr_store, 0, PAGE_SIZE);
memset(exit_msr_load, 0, PAGE_SIZE);
memset(entry_msr_load, 0, PAGE_SIZE);
entry_msr_load[0].index = MSR_KERNEL_GS_BASE;
entry_msr_load[0].value = MSR_MAGIC;
vmx_set_test_stage(1);
vmcs_write(ENT_MSR_LD_CNT, 1);
vmcs_write(ENTER_MSR_LD_ADDR, (u64)entry_msr_load);
vmcs_write(EXI_MSR_ST_CNT, 1);
vmcs_write(EXIT_MSR_ST_ADDR, (u64)exit_msr_store);
vmcs_write(EXI_MSR_LD_CNT, 1);
vmcs_write(EXIT_MSR_LD_ADDR, (u64)exit_msr_load);
return VMX_TEST_START;
}
static void msr_switch_main()
{
if (vmx_get_test_stage() == 1) {
report("VM entry MSR load",
rdmsr(MSR_KERNEL_GS_BASE) == MSR_MAGIC);
vmx_set_test_stage(2);
wrmsr(MSR_KERNEL_GS_BASE, MSR_MAGIC + 1);
exit_msr_store[0].index = MSR_KERNEL_GS_BASE;
exit_msr_load[0].index = MSR_KERNEL_GS_BASE;
exit_msr_load[0].value = MSR_MAGIC + 2;
}
vmcall();
}
static int msr_switch_exit_handler()
{
ulong reason;
reason = vmcs_read(EXI_REASON);
if (reason == VMX_VMCALL && vmx_get_test_stage() == 2) {
report("VM exit MSR store",
exit_msr_store[0].value == MSR_MAGIC + 1);
report("VM exit MSR load",
rdmsr(MSR_KERNEL_GS_BASE) == MSR_MAGIC + 2);
vmx_set_test_stage(3);
entry_msr_load[0].index = MSR_FS_BASE;
return VMX_TEST_RESUME;
}
printf("ERROR %s: unexpected stage=%u or reason=%lu\n",
__func__, vmx_get_test_stage(), reason);
return VMX_TEST_EXIT;
}
static int msr_switch_entry_failure(struct vmentry_failure *failure)
{
ulong reason;
if (failure->early) {
printf("ERROR %s: early exit\n", __func__);
return VMX_TEST_EXIT;
}
reason = vmcs_read(EXI_REASON);
if (reason == (VMX_ENTRY_FAILURE | VMX_FAIL_MSR) &&
vmx_get_test_stage() == 3) {
report("VM entry MSR load: try to load FS_BASE",
vmcs_read(EXI_QUALIFICATION) == 1);
return VMX_TEST_VMEXIT;
}
printf("ERROR %s: unexpected stage=%u or reason=%lu\n",
__func__, vmx_get_test_stage(), reason);
return VMX_TEST_EXIT;
}
static int vmmcall_init(struct vmcs *vmcs )
{
vmcs_write(EXC_BITMAP, 1 << UD_VECTOR);
return VMX_TEST_START;
}
static void vmmcall_main(void)
{
asm volatile(
"mov $0xABCD, %%rax\n\t"
"vmmcall\n\t"
::: "rax");
report("VMMCALL", 0);
}
static int vmmcall_exit_handler()
{
ulong reason;
reason = vmcs_read(EXI_REASON);
switch (reason) {
case VMX_VMCALL:
printf("here\n");
report("VMMCALL triggers #UD", 0);
break;
case VMX_EXC_NMI:
report("VMMCALL triggers #UD",
(vmcs_read(EXI_INTR_INFO) & 0xff) == UD_VECTOR);
break;
default:
report("Unknown exit reason, %ld", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
static int disable_rdtscp_init(struct vmcs *vmcs)
{
u32 ctrl_cpu1;
if (ctrl_cpu_rev[0].clr & CPU_SECONDARY) {
ctrl_cpu1 = vmcs_read(CPU_EXEC_CTRL1);
ctrl_cpu1 &= ~CPU_RDTSCP;
vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu1);
}
return VMX_TEST_START;
}
static void disable_rdtscp_ud_handler(struct ex_regs *regs)
{
switch (vmx_get_test_stage()) {
case 0:
report("RDTSCP triggers #UD", true);
vmx_inc_test_stage();
regs->rip += 3;
break;
case 2:
report("RDPID triggers #UD", true);
vmx_inc_test_stage();
regs->rip += 4;
break;
}
return;
}
static void disable_rdtscp_main(void)
{
/* Test that #UD is properly injected in L2. */
handle_exception(UD_VECTOR, disable_rdtscp_ud_handler);
vmx_set_test_stage(0);
asm volatile("rdtscp" : : : "eax", "ecx", "edx");
vmcall();
asm volatile(".byte 0xf3, 0x0f, 0xc7, 0xf8" : : : "eax");
vmcall();
}
static int disable_rdtscp_exit_handler(void)
{
unsigned int reason = vmcs_read(EXI_REASON) & 0xff;
switch (reason) {
case VMX_VMCALL:
switch (vmx_get_test_stage()) {
case 0:
report("RDTSCP triggers #UD", false);
vmx_inc_test_stage();
/* fallthrough */
case 1:
vmx_inc_test_stage();
vmcs_write(GUEST_RIP, vmcs_read(GUEST_RIP) + 3);
return VMX_TEST_RESUME;
case 2:
report("RDPID triggers #UD", false);
break;
}
break;
default:
report("Unknown exit reason, %d", false, reason);
print_vmexit_info();
}
return VMX_TEST_VMEXIT;
}
int int3_init()
{
vmcs_write(EXC_BITMAP, ~0u);
return VMX_TEST_START;
}
void int3_guest_main()
{
asm volatile ("int3");
}
int int3_exit_handler()
{
u32 reason = vmcs_read(EXI_REASON);
u32 intr_info = vmcs_read(EXI_INTR_INFO);
report("L1 intercepts #BP", reason == VMX_EXC_NMI &&
(intr_info & INTR_INFO_VALID_MASK) &&
(intr_info & INTR_INFO_VECTOR_MASK) == BP_VECTOR &&
((intr_info & INTR_INFO_INTR_TYPE_MASK) >>
INTR_INFO_INTR_TYPE_SHIFT) == VMX_INTR_TYPE_SOFT_EXCEPTION);
return VMX_TEST_VMEXIT;
}
int into_init()
{
vmcs_write(EXC_BITMAP, ~0u);
return VMX_TEST_START;
}
void into_guest_main()
{
struct far_pointer32 fp = {
.offset = (uintptr_t)&&into,
.selector = KERNEL_CS32,
};
register uintptr_t rsp asm("rsp");
if (fp.offset != (uintptr_t)&&into) {
printf("Code address too high.\n");
return;
}
if ((u32)rsp != rsp) {
printf("Stack address too high.\n");
return;
}
asm goto ("lcall *%0" : : "m" (fp) : "rax" : into);
return;
into:
asm volatile (".code32;"
"movl $0x7fffffff, %eax;"
"addl %eax, %eax;"
"into;"
"lret;"
".code64");
__builtin_unreachable();
}
int into_exit_handler()
{
u32 reason = vmcs_read(EXI_REASON);
u32 intr_info = vmcs_read(EXI_INTR_INFO);
report("L1 intercepts #OF", reason == VMX_EXC_NMI &&
(intr_info & INTR_INFO_VALID_MASK) &&
(intr_info & INTR_INFO_VECTOR_MASK) == OF_VECTOR &&
((intr_info & INTR_INFO_INTR_TYPE_MASK) >>
INTR_INFO_INTR_TYPE_SHIFT) == VMX_INTR_TYPE_SOFT_EXCEPTION);
return VMX_TEST_VMEXIT;
}
static void exit_monitor_from_l2_main(void)
{
printf("Calling exit(0) from l2...\n");
exit(0);
}
static int exit_monitor_from_l2_handler(void)
{
report("The guest should have killed the VMM", false);
return VMX_TEST_EXIT;
}
static void assert_exit_reason(u64 expected)
{
u64 actual = vmcs_read(EXI_REASON);
TEST_ASSERT_EQ_MSG(expected, actual, "Expected %s, got %s.",
exit_reason_description(expected),
exit_reason_description(actual));
}
static void skip_exit_vmcall()
{
u64 guest_rip = vmcs_read(GUEST_RIP);
u32 insn_len = vmcs_read(EXI_INST_LEN);
assert_exit_reason(VMX_VMCALL);
vmcs_write(GUEST_RIP, guest_rip + insn_len);
}
static void v2_null_test_guest(void)
{
}
static void v2_null_test(void)
{
test_set_guest(v2_null_test_guest);
enter_guest();
report(__func__, 1);
}
static void v2_multiple_entries_test_guest(void)
{
vmx_set_test_stage(1);
vmcall();
vmx_set_test_stage(2);
}
static void v2_multiple_entries_test(void)
{
test_set_guest(v2_multiple_entries_test_guest);
enter_guest();
TEST_ASSERT_EQ(vmx_get_test_stage(), 1);
skip_exit_vmcall();
enter_guest();
TEST_ASSERT_EQ(vmx_get_test_stage(), 2);
report(__func__, 1);
}
static int fixture_test_data = 1;
static void fixture_test_teardown(void *data)
{
*((int *) data) = 1;
}
static void fixture_test_guest(void)
{
fixture_test_data++;
}
static void fixture_test_setup(void)
{
TEST_ASSERT_EQ_MSG(1, fixture_test_data,
"fixture_test_teardown didn't run?!");
fixture_test_data = 2;
test_add_teardown(fixture_test_teardown, &fixture_test_data);
test_set_guest(fixture_test_guest);
}
static void fixture_test_case1(void)
{
fixture_test_setup();
TEST_ASSERT_EQ(2, fixture_test_data);
enter_guest();
TEST_ASSERT_EQ(3, fixture_test_data);
report(__func__, 1);
}
static void fixture_test_case2(void)
{
fixture_test_setup();
TEST_ASSERT_EQ(2, fixture_test_data);
enter_guest();
TEST_ASSERT_EQ(3, fixture_test_data);
report(__func__, 1);
}
enum ept_access_op {
OP_READ,
OP_WRITE,
OP_EXEC,
OP_FLUSH_TLB,
OP_EXIT,
};
static struct ept_access_test_data {
unsigned long gpa;
unsigned long *gva;
unsigned long hpa;
unsigned long *hva;
enum ept_access_op op;
} ept_access_test_data;
extern unsigned char ret42_start;
extern unsigned char ret42_end;
/* Returns 42. */
asm(
".align 64\n"
"ret42_start:\n"
"mov $42, %eax\n"
"ret\n"
"ret42_end:\n"
);
static void
diagnose_ept_violation_qual(u64 expected, u64 actual)
{
#define DIAGNOSE(flag) \
do { \
if ((expected & flag) != (actual & flag)) \
printf(#flag " %sexpected\n", \
(expected & flag) ? "" : "un"); \
} while (0)
DIAGNOSE(EPT_VLT_RD);
DIAGNOSE(EPT_VLT_WR);
DIAGNOSE(EPT_VLT_FETCH);
DIAGNOSE(EPT_VLT_PERM_RD);
DIAGNOSE(EPT_VLT_PERM_WR);
DIAGNOSE(EPT_VLT_PERM_EX);
DIAGNOSE(EPT_VLT_LADDR_VLD);
DIAGNOSE(EPT_VLT_PADDR);
#undef DIAGNOSE
}
static void do_ept_access_op(enum ept_access_op op)
{
ept_access_test_data.op = op;
enter_guest();
}
/*
* Force the guest to flush its TLB (i.e., flush gva -> gpa mappings). Only
* needed by tests that modify guest PTEs.
*/
static void ept_access_test_guest_flush_tlb(void)
{
do_ept_access_op(OP_FLUSH_TLB);
skip_exit_vmcall();
}
/*
* Modifies the EPT entry at @level in the mapping of @gpa. First clears the
* bits in @clear then sets the bits in @set. @mkhuge transforms the entry into
* a huge page.
*/
static unsigned long ept_twiddle(unsigned long gpa, bool mkhuge, int level,
unsigned long clear, unsigned long set)
{
struct ept_access_test_data *data = &ept_access_test_data;
unsigned long orig_pte;
unsigned long pte;
/* Screw with the mapping at the requested level. */
TEST_ASSERT(get_ept_pte(pml4, gpa, level, &orig_pte));
pte = orig_pte;
if (mkhuge)
pte = (orig_pte & ~EPT_ADDR_MASK) | data->hpa | EPT_LARGE_PAGE;
else
pte = orig_pte;
pte = (pte & ~clear) | set;
set_ept_pte(pml4, gpa, level, pte);
ept_sync(INVEPT_SINGLE, eptp);
return orig_pte;
}
static void ept_untwiddle(unsigned long gpa, int level, unsigned long orig_pte)
{
set_ept_pte(pml4, gpa, level, orig_pte);
}
static void do_ept_violation(bool leaf, enum ept_access_op op,
u64 expected_qual, u64 expected_paddr)
{
u64 qual;
/* Try the access and observe the violation. */
do_ept_access_op(op);
assert_exit_reason(VMX_EPT_VIOLATION);
qual = vmcs_read(EXI_QUALIFICATION);
diagnose_ept_violation_qual(expected_qual, qual);
TEST_EXPECT_EQ(expected_qual, qual);
#if 0
/* Disable for now otherwise every test will fail */
TEST_EXPECT_EQ(vmcs_read(GUEST_LINEAR_ADDRESS),
(unsigned long) (
op == OP_EXEC ? data->gva + 1 : data->gva));
#endif
/*
* TODO: tests that probe expected_paddr in pages other than the one at
* the beginning of the 1g region.
*/
TEST_EXPECT_EQ(vmcs_read(INFO_PHYS_ADDR), expected_paddr);
}
static void
ept_violation_at_level_mkhuge(bool mkhuge, int level, unsigned long clear,
unsigned long set, enum ept_access_op op,
u64 expected_qual)
{
struct ept_access_test_data *data = &ept_access_test_data;
unsigned long orig_pte;
orig_pte = ept_twiddle(data->gpa, mkhuge, level, clear, set);
do_ept_violation(level == 1 || mkhuge, op, expected_qual,
op == OP_EXEC ? data->gpa + sizeof(unsigned long) :
data->gpa);
/* Fix the violation and resume the op loop. */
ept_untwiddle(data->gpa, level, orig_pte);
enter_guest();
skip_exit_vmcall();
}
static void
ept_violation_at_level(int level, unsigned long clear, unsigned long set,
enum ept_access_op op, u64 expected_qual)
{
ept_violation_at_level_mkhuge(false, level, clear, set, op,
expected_qual);
if (ept_huge_pages_supported(level))
ept_violation_at_level_mkhuge(true, level, clear, set, op,
expected_qual);
}
static void ept_violation(unsigned long clear, unsigned long set,
enum ept_access_op op, u64 expected_qual)
{
ept_violation_at_level(1, clear, set, op, expected_qual);
ept_violation_at_level(2, clear, set, op, expected_qual);
ept_violation_at_level(3, clear, set, op, expected_qual);
ept_violation_at_level(4, clear, set, op, expected_qual);
}
static void ept_access_violation(unsigned long access, enum ept_access_op op,
u64 expected_qual)
{
ept_violation(EPT_PRESENT, access, op,
expected_qual | EPT_VLT_LADDR_VLD | EPT_VLT_PADDR);
}
/*
* For translations that don't involve a GVA, that is physical address (paddr)
* accesses, EPT violations don't set the flag EPT_VLT_PADDR. For a typical
* guest memory access, the hardware does GVA -> GPA -> HPA. However, certain
* translations don't involve GVAs, such as when the hardware does the guest
* page table walk. For example, in translating GVA_1 -> GPA_1, the guest MMU
* might try to set an A bit on a guest PTE. If the GPA_2 that the PTE resides
* on isn't present in the EPT, then the EPT violation will be for GPA_2 and
* the EPT_VLT_PADDR bit will be clear in the exit qualification.
*
* Note that paddr violations can also be triggered by loading PAE page tables
* with wonky addresses. We don't test that yet.
*
* This function modifies the EPT entry that maps the GPA that the guest page
* table entry mapping ept_access_data.gva resides on.
*
* @ept_access EPT permissions to set. Other permissions are cleared.
*
* @pte_ad Set the A/D bits on the guest PTE accordingly.
*
* @op Guest operation to perform with ept_access_data.gva.
*
* @expect_violation
* Is a violation expected during the paddr access?
*
* @expected_qual Expected qualification for the EPT violation.
* EPT_VLT_PADDR should be clear.
*/
static void ept_access_paddr(unsigned long ept_access, unsigned long pte_ad,
enum ept_access_op op, bool expect_violation,
u64 expected_qual)
{
struct ept_access_test_data *data = &ept_access_test_data;
unsigned long *ptep;
unsigned long gpa;
unsigned long orig_epte;
/* Modify the guest PTE mapping data->gva according to @pte_ad. */
ptep = get_pte_level(current_page_table(), data->gva, /*level=*/1);
TEST_ASSERT(ptep);
TEST_ASSERT_EQ(*ptep & PT_ADDR_MASK, data->gpa);
*ptep = (*ptep & ~PT_AD_MASK) | pte_ad;
ept_access_test_guest_flush_tlb();
/*
* Now modify the access bits on the EPT entry for the GPA that the
* guest PTE resides on. Note that by modifying a single EPT entry,
* we're potentially affecting 512 guest PTEs. However, we've carefully
* constructed our test such that those other 511 PTEs aren't used by
* the guest: data->gva is at the beginning of a 1G huge page, thus the
* PTE we're modifying is at the beginning of a 4K page and the
* following 511 entires are also under our control (and not touched by
* the guest).
*/
gpa = virt_to_phys(ptep);
TEST_ASSERT_EQ(gpa & ~PAGE_MASK, 0);
/*
* Make sure the guest page table page is mapped with a 4K EPT entry,
* otherwise our level=1 twiddling below will fail. We use the
* identity map (gpa = gpa) since page tables are shared with the host.
*/
install_ept(pml4, gpa, gpa, EPT_PRESENT);
orig_epte = ept_twiddle(gpa, /*mkhuge=*/0, /*level=*/1,
/*clear=*/EPT_PRESENT, /*set=*/ept_access);
if (expect_violation) {
do_ept_violation(/*leaf=*/true, op,
expected_qual | EPT_VLT_LADDR_VLD, gpa);
ept_untwiddle(gpa, /*level=*/1, orig_epte);
do_ept_access_op(op);
} else {
do_ept_access_op(op);
ept_untwiddle(gpa, /*level=*/1, orig_epte);
}
TEST_ASSERT(*ptep & PT_ACCESSED_MASK);
if ((pte_ad & PT_DIRTY_MASK) || op == OP_WRITE)
TEST_ASSERT(*ptep & PT_DIRTY_MASK);
skip_exit_vmcall();
}
static void ept_access_allowed_paddr(unsigned long ept_access,
unsigned long pte_ad,
enum ept_access_op op)
{
ept_access_paddr(ept_access, pte_ad, op, /*expect_violation=*/false,
/*expected_qual=*/-1);
}
static void ept_access_violation_paddr(unsigned long ept_access,
unsigned long pte_ad,
enum ept_access_op op,
u64 expected_qual)
{
ept_access_paddr(ept_access, pte_ad, op, /*expect_violation=*/true,
expected_qual);
}
static void ept_allowed_at_level_mkhuge(bool mkhuge, int level,
unsigned long clear,
unsigned long set,
enum ept_access_op op)
{
struct ept_access_test_data *data = &ept_access_test_data;
unsigned long orig_pte;
orig_pte = ept_twiddle(data->gpa, mkhuge, level, clear, set);
/* No violation. Should proceed to vmcall. */
do_ept_access_op(op);
skip_exit_vmcall();
ept_untwiddle(data->gpa, level, orig_pte);
}
static void ept_allowed_at_level(int level, unsigned long clear,
unsigned long set, enum ept_access_op op)
{
ept_allowed_at_level_mkhuge(false, level, clear, set, op);
if (ept_huge_pages_supported(level))
ept_allowed_at_level_mkhuge(true, level, clear, set, op);
}
static void ept_allowed(unsigned long clear, unsigned long set,
enum ept_access_op op)
{
ept_allowed_at_level(1, clear, set, op);
ept_allowed_at_level(2, clear, set, op);
ept_allowed_at_level(3, clear, set, op);
ept_allowed_at_level(4, clear, set, op);
}
static void ept_ignored_bit(int bit)
{
/* Set the bit. */
ept_allowed(0, 1ul << bit, OP_READ);
ept_allowed(0, 1ul << bit, OP_WRITE);
ept_allowed(0, 1ul << bit, OP_EXEC);
/* Clear the bit. */
ept_allowed(1ul << bit, 0, OP_READ);
ept_allowed(1ul << bit, 0, OP_WRITE);
ept_allowed(1ul << bit, 0, OP_EXEC);
}
static void ept_access_allowed(unsigned long access, enum ept_access_op op)
{
ept_allowed(EPT_PRESENT, access, op);
}
static void ept_misconfig_at_level_mkhuge_op(bool mkhuge, int level,
unsigned long clear,
unsigned long set,
enum ept_access_op op)
{
struct ept_access_test_data *data = &ept_access_test_data;
unsigned long orig_pte;
orig_pte = ept_twiddle(data->gpa, mkhuge, level, clear, set);
do_ept_access_op(op);
assert_exit_reason(VMX_EPT_MISCONFIG);
/* Intel 27.2.1, "For all other VM exits, this field is cleared." */
#if 0
/* broken: */
TEST_EXPECT_EQ_MSG(vmcs_read(EXI_QUALIFICATION), 0);
#endif
#if 0
/*
* broken:
* According to description of exit qual for EPT violation,
* EPT_VLT_LADDR_VLD indicates if GUEST_LINEAR_ADDRESS is valid.
* However, I can't find anything that says GUEST_LINEAR_ADDRESS ought
* to be set for msiconfig.
*/
TEST_EXPECT_EQ(vmcs_read(GUEST_LINEAR_ADDRESS),
(unsigned long) (
op == OP_EXEC ? data->gva + 1 : data->gva));
#endif
/* Fix the violation and resume the op loop. */
ept_untwiddle(data->gpa, level, orig_pte);
enter_guest();
skip_exit_vmcall();
}
static void ept_misconfig_at_level_mkhuge(bool mkhuge, int level,
unsigned long clear,
unsigned long set)
{
/* The op shouldn't matter (read, write, exec), so try them all! */
ept_misconfig_at_level_mkhuge_op(mkhuge, level, clear, set, OP_READ);
ept_misconfig_at_level_mkhuge_op(mkhuge, level, clear, set, OP_WRITE);
ept_misconfig_at_level_mkhuge_op(mkhuge, level, clear, set, OP_EXEC);
}
static void ept_misconfig_at_level(int level, unsigned long clear,
unsigned long set)
{
ept_misconfig_at_level_mkhuge(false, level, clear, set);
if (ept_huge_pages_supported(level))
ept_misconfig_at_level_mkhuge(true, level, clear, set);
}
static void ept_misconfig(unsigned long clear, unsigned long set)
{
ept_misconfig_at_level(1, clear, set);
ept_misconfig_at_level(2, clear, set);
ept_misconfig_at_level(3, clear, set);
ept_misconfig_at_level(4, clear, set);
}
static void ept_access_misconfig(unsigned long access)
{
ept_misconfig(EPT_PRESENT, access);
}
static void ept_reserved_bit_at_level_nohuge(int level, int bit)
{
/* Setting the bit causes a misconfig. */
ept_misconfig_at_level_mkhuge(false, level, 0, 1ul << bit);
/* Making the entry non-present turns reserved bits into ignored. */
ept_violation_at_level(level, EPT_PRESENT, 1ul << bit, OP_READ,
EPT_VLT_RD | EPT_VLT_LADDR_VLD | EPT_VLT_PADDR);
}
static void ept_reserved_bit_at_level_huge(int level, int bit)
{
/* Setting the bit causes a misconfig. */
ept_misconfig_at_level_mkhuge(true, level, 0, 1ul << bit);
/* Making the entry non-present turns reserved bits into ignored. */
ept_violation_at_level(level, EPT_PRESENT, 1ul << bit, OP_READ,
EPT_VLT_RD | EPT_VLT_LADDR_VLD | EPT_VLT_PADDR);
}
static void ept_reserved_bit_at_level(int level, int bit)
{
/* Setting the bit causes a misconfig. */
ept_misconfig_at_level(level, 0, 1ul << bit);
/* Making the entry non-present turns reserved bits into ignored. */
ept_violation_at_level(level, EPT_PRESENT, 1ul << bit, OP_READ,
EPT_VLT_RD | EPT_VLT_LADDR_VLD | EPT_VLT_PADDR);
}
static void ept_reserved_bit(int bit)
{
ept_reserved_bit_at_level(1, bit);
ept_reserved_bit_at_level(2, bit);
ept_reserved_bit_at_level(3, bit);
ept_reserved_bit_at_level(4, bit);
}
#define PAGE_2M_ORDER 9
#define PAGE_1G_ORDER 18
static void *get_1g_page(void)
{
static void *alloc;
if (!alloc)
alloc = alloc_pages(PAGE_1G_ORDER);
return alloc;
}
static void ept_access_test_teardown(void *unused)
{
/* Exit the guest cleanly. */
do_ept_access_op(OP_EXIT);
}
static void ept_access_test_guest(void)
{
struct ept_access_test_data *data = &ept_access_test_data;
int (*code)(void) = (int (*)(void)) &data->gva[1];
while (true) {
switch (data->op) {
case OP_READ:
TEST_ASSERT_EQ(*data->gva, MAGIC_VAL_1);
break;
case OP_WRITE:
*data->gva = MAGIC_VAL_2;
TEST_ASSERT_EQ(*data->gva, MAGIC_VAL_2);
*data->gva = MAGIC_VAL_1;
break;
case OP_EXEC:
TEST_ASSERT_EQ(42, code());
break;
case OP_FLUSH_TLB:
write_cr3(read_cr3());
break;
case OP_EXIT:
return;
default:
TEST_ASSERT_MSG(false, "Unknown op %d", data->op);
}
vmcall();
}
}
static void ept_access_test_setup(void)
{
struct ept_access_test_data *data = &ept_access_test_data;
unsigned long npages = 1ul << PAGE_1G_ORDER;
unsigned long size = npages * PAGE_SIZE;
unsigned long *page_table = current_page_table();
unsigned long pte;
if (setup_ept(false))
test_skip("EPT not supported");
test_set_guest(ept_access_test_guest);
test_add_teardown(ept_access_test_teardown, NULL);
data->hva = get_1g_page();
TEST_ASSERT(data->hva);
data->hpa = virt_to_phys(data->hva);
data->gpa = 1ul << 40;
data->gva = (void *) ALIGN((unsigned long) alloc_vpages(npages * 2),
size);
TEST_ASSERT(!any_present_pages(page_table, data->gva, size));
install_pages(page_table, data->gpa, size, data->gva);
/*
* Make sure nothing's mapped here so the tests that screw with the
* pml4 entry don't inadvertently break something.
*/
TEST_ASSERT(get_ept_pte(pml4, data->gpa, 4, &pte) && pte == 0);
TEST_ASSERT(get_ept_pte(pml4, data->gpa + size - 1, 4, &pte) && pte == 0);
install_ept(pml4, data->hpa, data->gpa, EPT_PRESENT);
data->hva[0] = MAGIC_VAL_1;
memcpy(&data->hva[1], &ret42_start, &ret42_end - &ret42_start);
}
static void ept_access_test_not_present(void)
{
ept_access_test_setup();
/* --- */
ept_access_violation(0, OP_READ, EPT_VLT_RD);
ept_access_violation(0, OP_WRITE, EPT_VLT_WR);
ept_access_violation(0, OP_EXEC, EPT_VLT_FETCH);
}
static void ept_access_test_read_only(void)
{
ept_access_test_setup();
/* r-- */
ept_access_allowed(EPT_RA, OP_READ);
ept_access_violation(EPT_RA, OP_WRITE, EPT_VLT_WR | EPT_VLT_PERM_RD);
ept_access_violation(EPT_RA, OP_EXEC, EPT_VLT_FETCH | EPT_VLT_PERM_RD);
}
static void ept_access_test_write_only(void)
{
ept_access_test_setup();
/* -w- */
ept_access_misconfig(EPT_WA);
}
static void ept_access_test_read_write(void)
{
ept_access_test_setup();
/* rw- */
ept_access_allowed(EPT_RA | EPT_WA, OP_READ);
ept_access_allowed(EPT_RA | EPT_WA, OP_WRITE);
ept_access_violation(EPT_RA | EPT_WA, OP_EXEC,
EPT_VLT_FETCH | EPT_VLT_PERM_RD | EPT_VLT_PERM_WR);
}
static void ept_access_test_execute_only(void)
{
ept_access_test_setup();
/* --x */
if (ept_execute_only_supported()) {
ept_access_violation(EPT_EA, OP_READ,
EPT_VLT_RD | EPT_VLT_PERM_EX);
ept_access_violation(EPT_EA, OP_WRITE,
EPT_VLT_WR | EPT_VLT_PERM_EX);
ept_access_allowed(EPT_EA, OP_EXEC);
} else {
ept_access_misconfig(EPT_EA);
}
}
static void ept_access_test_read_execute(void)
{
ept_access_test_setup();
/* r-x */
ept_access_allowed(EPT_RA | EPT_EA, OP_READ);
ept_access_violation(EPT_RA | EPT_EA, OP_WRITE,
EPT_VLT_WR | EPT_VLT_PERM_RD | EPT_VLT_PERM_EX);
ept_access_allowed(EPT_RA | EPT_EA, OP_EXEC);
}
static void ept_access_test_write_execute(void)
{
ept_access_test_setup();
/* -wx */
ept_access_misconfig(EPT_WA | EPT_EA);
}
static void ept_access_test_read_write_execute(void)
{
ept_access_test_setup();
/* rwx */
ept_access_allowed(EPT_RA | EPT_WA | EPT_EA, OP_READ);
ept_access_allowed(EPT_RA | EPT_WA | EPT_EA, OP_WRITE);
ept_access_allowed(EPT_RA | EPT_WA | EPT_EA, OP_EXEC);
}
static void ept_access_test_reserved_bits(void)
{
int i;
int maxphyaddr;
ept_access_test_setup();
/* Reserved bits above maxphyaddr. */
maxphyaddr = cpuid_maxphyaddr();
for (i = maxphyaddr; i <= 51; i++) {
report_prefix_pushf("reserved_bit=%d", i);
ept_reserved_bit(i);
report_prefix_pop();
}
/* Level-specific reserved bits. */
ept_reserved_bit_at_level_nohuge(2, 3);
ept_reserved_bit_at_level_nohuge(2, 4);
ept_reserved_bit_at_level_nohuge(2, 5);
ept_reserved_bit_at_level_nohuge(2, 6);
/* 2M alignment. */
for (i = 12; i < 20; i++) {
report_prefix_pushf("reserved_bit=%d", i);
ept_reserved_bit_at_level_huge(2, i);
report_prefix_pop();
}
ept_reserved_bit_at_level_nohuge(3, 3);
ept_reserved_bit_at_level_nohuge(3, 4);
ept_reserved_bit_at_level_nohuge(3, 5);
ept_reserved_bit_at_level_nohuge(3, 6);
/* 1G alignment. */
for (i = 12; i < 29; i++) {
report_prefix_pushf("reserved_bit=%d", i);
ept_reserved_bit_at_level_huge(3, i);
report_prefix_pop();
}
ept_reserved_bit_at_level(4, 3);
ept_reserved_bit_at_level(4, 4);
ept_reserved_bit_at_level(4, 5);
ept_reserved_bit_at_level(4, 6);
ept_reserved_bit_at_level(4, 7);
}
static void ept_access_test_ignored_bits(void)
{
ept_access_test_setup();
/*
* Bits ignored at every level. Bits 8 and 9 (A and D) are ignored as
* far as translation is concerned even if AD bits are enabled in the
* EPTP. Bit 63 is ignored because "EPT-violation #VE" VM-execution
* control is 0.
*/
ept_ignored_bit(8);
ept_ignored_bit(9);
ept_ignored_bit(10);
ept_ignored_bit(11);
ept_ignored_bit(52);
ept_ignored_bit(53);
ept_ignored_bit(54);
ept_ignored_bit(55);
ept_ignored_bit(56);
ept_ignored_bit(57);
ept_ignored_bit(58);
ept_ignored_bit(59);
ept_ignored_bit(60);
ept_ignored_bit(61);
ept_ignored_bit(62);
ept_ignored_bit(63);
}
static void ept_access_test_paddr_not_present_ad_disabled(void)
{
ept_access_test_setup();
ept_disable_ad_bits();
ept_access_violation_paddr(0, PT_AD_MASK, OP_READ, EPT_VLT_RD);
ept_access_violation_paddr(0, PT_AD_MASK, OP_WRITE, EPT_VLT_RD);
ept_access_violation_paddr(0, PT_AD_MASK, OP_EXEC, EPT_VLT_RD);
}
static void ept_access_test_paddr_not_present_ad_enabled(void)
{
u64 qual = EPT_VLT_RD | EPT_VLT_WR;
ept_access_test_setup();
ept_enable_ad_bits_or_skip_test();
ept_access_violation_paddr(0, PT_AD_MASK, OP_READ, qual);
ept_access_violation_paddr(0, PT_AD_MASK, OP_WRITE, qual);
ept_access_violation_paddr(0, PT_AD_MASK, OP_EXEC, qual);
}
static void ept_access_test_paddr_read_only_ad_disabled(void)
{
/*
* When EPT AD bits are disabled, all accesses to guest paging
* structures are reported separately as a read and (after
* translation of the GPA to host physical address) a read+write
* if the A/D bits have to be set.
*/
u64 qual = EPT_VLT_WR | EPT_VLT_RD | EPT_VLT_PERM_RD;
ept_access_test_setup();
ept_disable_ad_bits();
/* Can't update A bit, so all accesses fail. */
ept_access_violation_paddr(EPT_RA, 0, OP_READ, qual);
ept_access_violation_paddr(EPT_RA, 0, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA, 0, OP_EXEC, qual);
/* AD bits disabled, so only writes try to update the D bit. */
ept_access_allowed_paddr(EPT_RA, PT_ACCESSED_MASK, OP_READ);
ept_access_violation_paddr(EPT_RA, PT_ACCESSED_MASK, OP_WRITE, qual);
ept_access_allowed_paddr(EPT_RA, PT_ACCESSED_MASK, OP_EXEC);
/* Both A and D already set, so read-only is OK. */
ept_access_allowed_paddr(EPT_RA, PT_AD_MASK, OP_READ);
ept_access_allowed_paddr(EPT_RA, PT_AD_MASK, OP_WRITE);
ept_access_allowed_paddr(EPT_RA, PT_AD_MASK, OP_EXEC);
}
static void ept_access_test_paddr_read_only_ad_enabled(void)
{
/*
* When EPT AD bits are enabled, all accesses to guest paging
* structures are considered writes as far as EPT translation
* is concerned.
*/
u64 qual = EPT_VLT_WR | EPT_VLT_RD | EPT_VLT_PERM_RD;
ept_access_test_setup();
ept_enable_ad_bits_or_skip_test();
ept_access_violation_paddr(EPT_RA, 0, OP_READ, qual);
ept_access_violation_paddr(EPT_RA, 0, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA, 0, OP_EXEC, qual);
ept_access_violation_paddr(EPT_RA, PT_ACCESSED_MASK, OP_READ, qual);
ept_access_violation_paddr(EPT_RA, PT_ACCESSED_MASK, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA, PT_ACCESSED_MASK, OP_EXEC, qual);
ept_access_violation_paddr(EPT_RA, PT_AD_MASK, OP_READ, qual);
ept_access_violation_paddr(EPT_RA, PT_AD_MASK, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA, PT_AD_MASK, OP_EXEC, qual);
}
static void ept_access_test_paddr_read_write(void)
{
ept_access_test_setup();
/* Read-write access to paging structure. */
ept_access_allowed_paddr(EPT_RA | EPT_WA, 0, OP_READ);
ept_access_allowed_paddr(EPT_RA | EPT_WA, 0, OP_WRITE);
ept_access_allowed_paddr(EPT_RA | EPT_WA, 0, OP_EXEC);
}
static void ept_access_test_paddr_read_write_execute(void)
{
ept_access_test_setup();
/* RWX access to paging structure. */
ept_access_allowed_paddr(EPT_PRESENT, 0, OP_READ);
ept_access_allowed_paddr(EPT_PRESENT, 0, OP_WRITE);
ept_access_allowed_paddr(EPT_PRESENT, 0, OP_EXEC);
}
static void ept_access_test_paddr_read_execute_ad_disabled(void)
{
/*
* When EPT AD bits are disabled, all accesses to guest paging
* structures are reported separately as a read and (after
* translation of the GPA to host physical address) a read+write
* if the A/D bits have to be set.
*/
u64 qual = EPT_VLT_WR | EPT_VLT_RD | EPT_VLT_PERM_RD | EPT_VLT_PERM_EX;
ept_access_test_setup();
ept_disable_ad_bits();
/* Can't update A bit, so all accesses fail. */
ept_access_violation_paddr(EPT_RA | EPT_EA, 0, OP_READ, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, 0, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, 0, OP_EXEC, qual);
/* AD bits disabled, so only writes try to update the D bit. */
ept_access_allowed_paddr(EPT_RA | EPT_EA, PT_ACCESSED_MASK, OP_READ);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_ACCESSED_MASK, OP_WRITE, qual);
ept_access_allowed_paddr(EPT_RA | EPT_EA, PT_ACCESSED_MASK, OP_EXEC);
/* Both A and D already set, so read-only is OK. */
ept_access_allowed_paddr(EPT_RA | EPT_EA, PT_AD_MASK, OP_READ);
ept_access_allowed_paddr(EPT_RA | EPT_EA, PT_AD_MASK, OP_WRITE);
ept_access_allowed_paddr(EPT_RA | EPT_EA, PT_AD_MASK, OP_EXEC);
}
static void ept_access_test_paddr_read_execute_ad_enabled(void)
{
/*
* When EPT AD bits are enabled, all accesses to guest paging
* structures are considered writes as far as EPT translation
* is concerned.
*/
u64 qual = EPT_VLT_WR | EPT_VLT_RD | EPT_VLT_PERM_RD | EPT_VLT_PERM_EX;
ept_access_test_setup();
ept_enable_ad_bits_or_skip_test();
ept_access_violation_paddr(EPT_RA | EPT_EA, 0, OP_READ, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, 0, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, 0, OP_EXEC, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_ACCESSED_MASK, OP_READ, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_ACCESSED_MASK, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_ACCESSED_MASK, OP_EXEC, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_AD_MASK, OP_READ, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_AD_MASK, OP_WRITE, qual);
ept_access_violation_paddr(EPT_RA | EPT_EA, PT_AD_MASK, OP_EXEC, qual);
}
static void ept_access_test_paddr_not_present_page_fault(void)
{
ept_access_test_setup();
/*
* TODO: test no EPT violation as long as guest PF occurs. e.g., GPA is
* page is read-only in EPT but GVA is also mapped read only in PT.
* Thus guest page fault before host takes EPT violation for trying to
* update A bit.
*/
}
static void ept_access_test_force_2m_page(void)
{
ept_access_test_setup();
TEST_ASSERT_EQ(ept_2m_supported(), true);
ept_allowed_at_level_mkhuge(true, 2, 0, 0, OP_READ);
ept_violation_at_level_mkhuge(true, 2, EPT_PRESENT, EPT_RA, OP_WRITE,
EPT_VLT_WR | EPT_VLT_PERM_RD |
EPT_VLT_LADDR_VLD | EPT_VLT_PADDR);
ept_misconfig_at_level_mkhuge(true, 2, EPT_PRESENT, EPT_WA);
}
static bool invvpid_valid(u64 type, u64 vpid, u64 gla)
{
u64 msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
TEST_ASSERT(msr & VPID_CAP_INVVPID);
if (type < INVVPID_ADDR || type > INVVPID_CONTEXT_LOCAL)
return false;
if (!(msr & (1ull << (type + VPID_CAP_INVVPID_TYPES_SHIFT))))
return false;
if (vpid >> 16)
return false;
if (type != INVVPID_ALL && !vpid)
return false;
if (type == INVVPID_ADDR && !is_canonical(gla))
return false;
return true;
}
static void try_invvpid(u64 type, u64 vpid, u64 gla)
{
int rc;
bool valid = invvpid_valid(type, vpid, gla);
u64 expected = valid ? VMXERR_UNSUPPORTED_VMCS_COMPONENT
: VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID;
/*
* Set VMX_INST_ERROR to VMXERR_UNVALID_VMCS_COMPONENT, so
* that we can tell if it is updated by INVVPID.
*/
vmcs_read(~0);
rc = invvpid(type, vpid, gla);
report("INVVPID type %ld VPID %lx GLA %lx %s",
!rc == valid, type, vpid, gla,
valid ? "passes" : "fails");
report("After %s INVVPID, VMX_INST_ERR is %ld (actual %ld)",
vmcs_read(VMX_INST_ERROR) == expected,
rc ? "failed" : "successful",
expected, vmcs_read(VMX_INST_ERROR));
}
static void ds_invvpid(void *data)
{
u64 msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
u64 type = ffs(msr >> VPID_CAP_INVVPID_TYPES_SHIFT) - 1;
TEST_ASSERT(type >= INVVPID_ADDR && type <= INVVPID_CONTEXT_LOCAL);
asm volatile("invvpid %0, %1"
:
: "m"(*(struct invvpid_operand *)data),
"r"(type));
}
/*
* The SS override is ignored in 64-bit mode, so we use an addressing
* mode with %rsp as the base register to generate an implicit SS
* reference.
*/
static void ss_invvpid(void *data)
{
u64 msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
u64 type = ffs(msr >> VPID_CAP_INVVPID_TYPES_SHIFT) - 1;
TEST_ASSERT(type >= INVVPID_ADDR && type <= INVVPID_CONTEXT_LOCAL);
asm volatile("sub %%rsp,%0; invvpid (%%rsp,%0,1), %1"
: "+r"(data)
: "r"(type));
}
static void invvpid_test_gp(void)
{
bool fault;
fault = test_for_exception(GP_VECTOR, &ds_invvpid,
(void *)NONCANONICAL);
report("INVVPID with non-canonical DS operand raises #GP", fault);
}
static void invvpid_test_ss(void)
{
bool fault;
fault = test_for_exception(SS_VECTOR, &ss_invvpid,
(void *)NONCANONICAL);
report("INVVPID with non-canonical SS operand raises #SS", fault);
}
static void invvpid_test_pf(void)
{
void *vpage = alloc_vpage();
bool fault;
fault = test_for_exception(PF_VECTOR, &ds_invvpid, vpage);
report("INVVPID with unmapped operand raises #PF", fault);
}
static void try_compat_invvpid(void *unused)
{
struct far_pointer32 fp = {
.offset = (uintptr_t)&&invvpid,
.selector = KERNEL_CS32,
};
register uintptr_t rsp asm("rsp");
TEST_ASSERT_MSG(fp.offset == (uintptr_t)&&invvpid,
"Code address too high.");
TEST_ASSERT_MSG(rsp == (u32)rsp, "Stack address too high.");
asm goto ("lcall *%0" : : "m" (fp) : "rax" : invvpid);
return;
invvpid:
asm volatile (".code32;"
"invvpid (%eax), %eax;"
"lret;"
".code64");
__builtin_unreachable();
}
static void invvpid_test_compatibility_mode(void)
{
bool fault;
fault = test_for_exception(UD_VECTOR, &try_compat_invvpid, NULL);
report("Compatibility mode INVVPID raises #UD", fault);
}
static void invvpid_test_not_in_vmx_operation(void)
{
bool fault;
TEST_ASSERT(!vmx_off());
fault = test_for_exception(UD_VECTOR, &ds_invvpid, NULL);
report("INVVPID outside of VMX operation raises #UD", fault);
TEST_ASSERT(!vmx_on());
}
/*
* This does not test real-address mode, virtual-8086 mode, protected mode,
* or CPL > 0.
*/
static void invvpid_test_v2(void)
{
u64 msr;
int i;
unsigned types = 0;
unsigned type;
if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
!(ctrl_cpu_rev[1].clr & CPU_VPID))
test_skip("VPID not supported");
msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
if (!(msr & VPID_CAP_INVVPID))
test_skip("INVVPID not supported.\n");
if (msr & VPID_CAP_INVVPID_ADDR)
types |= 1u << INVVPID_ADDR;
if (msr & VPID_CAP_INVVPID_CXTGLB)
types |= 1u << INVVPID_CONTEXT_GLOBAL;
if (msr & VPID_CAP_INVVPID_ALL)
types |= 1u << INVVPID_ALL;
if (msr & VPID_CAP_INVVPID_CXTLOC)
types |= 1u << INVVPID_CONTEXT_LOCAL;
if (!types)
test_skip("No INVVPID types supported.\n");
for (i = -127; i < 128; i++)
try_invvpid(i, 0xffff, 0);
/*
* VPID must not be more than 16 bits.
*/
for (i = 0; i < 64; i++)
for (type = 0; type < 4; type++)
if (types & (1u << type))
try_invvpid(type, 1ul << i, 0);
/*
* VPID must not be zero, except for "all contexts."
*/
for (type = 0; type < 4; type++)
if (types & (1u << type))
try_invvpid(type, 0, 0);
/*
* The gla operand is only validated for single-address INVVPID.
*/
if (types & (1u << INVVPID_ADDR))
try_invvpid(INVVPID_ADDR, 0xffff, NONCANONICAL);
invvpid_test_gp();
invvpid_test_ss();
invvpid_test_pf();
invvpid_test_compatibility_mode();
invvpid_test_not_in_vmx_operation();
}
/*
* Test for early VMLAUNCH failure. Returns true if VMLAUNCH makes it
* at least as far as the guest-state checks. Returns false if the
* VMLAUNCH fails early and execution falls through to the next
* instruction.
*/
static bool vmlaunch_succeeds(void)
{
/*
* Indirectly set VMX_INST_ERR to 12 ("VMREAD/VMWRITE from/to
* unsupported VMCS component"). The caller can then check
* to see if a failed VM-entry sets VMX_INST_ERR as expected.
*/
vmcs_write(~0u, 0);
vmcs_write(HOST_RIP, (uintptr_t)&&success);
__asm__ __volatile__ goto ("vmwrite %%rsp, %0; vmlaunch"
:
: "r" ((u64)HOST_RSP)
: "cc", "memory"
: success);
return false;
success:
TEST_ASSERT(vmcs_read(EXI_REASON) ==
(VMX_FAIL_STATE | VMX_ENTRY_FAILURE));
return true;
}
/*
* Try to launch the current VMCS.
*/
static void test_vmx_controls(bool controls_valid)
{
bool success = vmlaunch_succeeds();
u32 vmx_inst_err;
report("vmlaunch %s", success == controls_valid,
controls_valid ? "succeeds" : "fails");
if (!controls_valid) {
vmx_inst_err = vmcs_read(VMX_INST_ERROR);
report("VMX inst error is %d (actual %d)",
vmx_inst_err == VMXERR_ENTRY_INVALID_CONTROL_FIELD,
VMXERR_ENTRY_INVALID_CONTROL_FIELD, vmx_inst_err);
}
}
/*
* Test a particular address setting for a physical page reference in
* the VMCS.
*/
static void test_vmcs_page_addr(const char *name,
enum Encoding encoding,
bool ignored,
u64 addr)
{
report_prefix_pushf("%s = %lx", name, addr);
vmcs_write(encoding, addr);
test_vmx_controls(ignored || (IS_ALIGNED(addr, PAGE_SIZE) &&
addr < (1ul << cpuid_maxphyaddr())));
report_prefix_pop();
}
/*
* Test interesting values for a physical page reference in the VMCS.
*/
static void test_vmcs_page_values(const char *name,
enum Encoding encoding,
bool ignored)
{
unsigned i;
u64 orig_val = vmcs_read(encoding);
for (i = 0; i < 64; i++)
test_vmcs_page_addr(name, encoding, ignored, 1ul << i);
test_vmcs_page_addr(name, encoding, ignored, PAGE_SIZE - 1);
test_vmcs_page_addr(name, encoding, ignored, PAGE_SIZE);
test_vmcs_page_addr(name, encoding, ignored,
(1ul << cpuid_maxphyaddr()) - PAGE_SIZE);
test_vmcs_page_addr(name, encoding, ignored, -1ul);
vmcs_write(encoding, orig_val);
}
/*
* Test a physical page reference in the VMCS, when the corresponding
* feature is enabled and when the corresponding feature is disabled.
*/
static void test_vmcs_page_reference(u32 control_bit, enum Encoding field,
const char *field_name,
const char *control_name)
{
u32 primary = vmcs_read(CPU_EXEC_CTRL0);
u64 page_addr;
if (!(ctrl_cpu_rev[0].clr & control_bit))
return;
page_addr = vmcs_read(field);
report_prefix_pushf("%s enabled", control_name);
vmcs_write(CPU_EXEC_CTRL0, primary | control_bit);
test_vmcs_page_values(field_name, field, false);
report_prefix_pop();
report_prefix_pushf("%s disabled", control_name);
vmcs_write(CPU_EXEC_CTRL0, primary & ~control_bit);
test_vmcs_page_values(field_name, field, true);
report_prefix_pop();
vmcs_write(field, page_addr);
vmcs_write(CPU_EXEC_CTRL0, primary);
}
/*
* If the "use I/O bitmaps" VM-execution control is 1, bits 11:0 of
* each I/O-bitmap address must be 0. Neither address should set any
* bits beyond the processor's physical-address width.
* [Intel SDM]
*/
static void test_io_bitmaps(void)
{
test_vmcs_page_reference(CPU_IO_BITMAP, IO_BITMAP_A,
"I/O bitmap A", "Use I/O bitmaps");
test_vmcs_page_reference(CPU_IO_BITMAP, IO_BITMAP_B,
"I/O bitmap B", "Use I/O bitmaps");
}
/*
* If the "use MSR bitmaps" VM-execution control is 1, bits 11:0 of
* the MSR-bitmap address must be 0. The address should not set any
* bits beyond the processor's physical-address width.
* [Intel SDM]
*/
static void test_msr_bitmap(void)
{
test_vmcs_page_reference(CPU_MSR_BITMAP, MSR_BITMAP,
"MSR bitmap", "Use MSR bitmaps");
}
static void vmx_controls_test(void)
{
/*
* Bit 1 of the guest's RFLAGS must be 1, or VM-entry will
* fail due to invalid guest state, should we make it that
* far.
*/
vmcs_write(GUEST_RFLAGS, 0);
test_io_bitmaps();
test_msr_bitmap();
}
static bool valid_vmcs_for_vmentry(void)
{
struct vmcs *current_vmcs = NULL;
if (vmcs_save(¤t_vmcs))
return false;
return current_vmcs && !(current_vmcs->revision_id >> 31);
}
static void try_vmentry_in_movss_shadow(void)
{
u32 vm_inst_err;
u32 flags;
bool early_failure = false;
u32 expected_flags = X86_EFLAGS_FIXED;
bool valid_vmcs = valid_vmcs_for_vmentry();
expected_flags |= valid_vmcs ? X86_EFLAGS_ZF : X86_EFLAGS_CF;
/*
* Indirectly set VM_INST_ERR to 12 ("VMREAD/VMWRITE from/to
* unsupported VMCS component").
*/
vmcs_write(~0u, 0);
__asm__ __volatile__ ("mov %[host_rsp], %%edx;"
"vmwrite %%rsp, %%rdx;"
"mov 0f, %%rax;"
"mov %[host_rip], %%edx;"
"vmwrite %%rax, %%rdx;"
"mov $-1, %%ah;"
"sahf;"
"mov %%ss, %%ax;"
"mov %%ax, %%ss;"
"vmlaunch;"
"mov $1, %[early_failure];"
"0: lahf;"
"movzbl %%ah, %[flags]"
: [early_failure] "+r" (early_failure),
[flags] "=&a" (flags)
: [host_rsp] "i" (HOST_RSP),
[host_rip] "i" (HOST_RIP)
: "rdx", "cc", "memory");
vm_inst_err = vmcs_read(VMX_INST_ERROR);
report("Early VM-entry failure", early_failure);
report("RFLAGS[8:0] is %x (actual %x)", flags == expected_flags,
expected_flags, flags);
if (valid_vmcs)
report("VM-instruction error is %d (actual %d)",
vm_inst_err == VMXERR_ENTRY_EVENTS_BLOCKED_BY_MOV_SS,
VMXERR_ENTRY_EVENTS_BLOCKED_BY_MOV_SS, vm_inst_err);
}
static void vmentry_movss_shadow_test(void)
{
struct vmcs *orig_vmcs;
TEST_ASSERT(!vmcs_save(&orig_vmcs));
/*
* Set the launched flag on the current VMCS to verify the correct
* error priority, below.
*/
test_set_guest(v2_null_test_guest);
enter_guest();
/*
* With bit 1 of the guest's RFLAGS clear, VM-entry should
* fail due to invalid guest state (if we make it that far).
*/
vmcs_write(GUEST_RFLAGS, 0);
/*
* "VM entry with events blocked by MOV SS" takes precedence over
* "VMLAUNCH with non-clear VMCS."
*/
report_prefix_push("valid current-VMCS");
try_vmentry_in_movss_shadow();
report_prefix_pop();
/*
* VMfailInvalid takes precedence over "VM entry with events
* blocked by MOV SS."
*/
TEST_ASSERT(!vmcs_clear(orig_vmcs));
report_prefix_push("no current-VMCS");
try_vmentry_in_movss_shadow();
report_prefix_pop();
TEST_ASSERT(!make_vmcs_current(orig_vmcs));
vmcs_write(GUEST_RFLAGS, X86_EFLAGS_FIXED);
}
#define TEST(name) { #name, .v2 = name }
/* name/init/guest_main/exit_handler/syscall_handler/guest_regs */
struct vmx_test vmx_tests[] = {
{ "null", NULL, basic_guest_main, basic_exit_handler, NULL, {0} },
{ "vmenter", NULL, vmenter_main, vmenter_exit_handler, NULL, {0} },
{ "preemption timer", preemption_timer_init, preemption_timer_main,
preemption_timer_exit_handler, NULL, {0} },
{ "control field PAT", test_ctrl_pat_init, test_ctrl_pat_main,
test_ctrl_pat_exit_handler, NULL, {0} },
{ "control field EFER", test_ctrl_efer_init, test_ctrl_efer_main,
test_ctrl_efer_exit_handler, NULL, {0} },
{ "CR shadowing", NULL, cr_shadowing_main,
cr_shadowing_exit_handler, NULL, {0} },
{ "I/O bitmap", iobmp_init, iobmp_main, iobmp_exit_handler,
NULL, {0} },
{ "instruction intercept", insn_intercept_init, insn_intercept_main,
insn_intercept_exit_handler, NULL, {0} },
{ "EPT A/D disabled", ept_init, ept_main, ept_exit_handler, NULL, {0} },
{ "EPT A/D enabled", eptad_init, eptad_main, eptad_exit_handler, NULL, {0} },
{ "PML", pml_init, pml_main, pml_exit_handler, NULL, {0} },
{ "VPID", vpid_init, vpid_main, vpid_exit_handler, NULL, {0} },
{ "interrupt", interrupt_init, interrupt_main,
interrupt_exit_handler, NULL, {0} },
{ "debug controls", dbgctls_init, dbgctls_main, dbgctls_exit_handler,
NULL, {0} },
{ "MSR switch", msr_switch_init, msr_switch_main,
msr_switch_exit_handler, NULL, {0}, msr_switch_entry_failure },
{ "vmmcall", vmmcall_init, vmmcall_main, vmmcall_exit_handler, NULL, {0} },
{ "disable RDTSCP", disable_rdtscp_init, disable_rdtscp_main,
disable_rdtscp_exit_handler, NULL, {0} },
{ "int3", int3_init, int3_guest_main, int3_exit_handler, NULL, {0} },
{ "into", into_init, into_guest_main, into_exit_handler, NULL, {0} },
{ "exit_monitor_from_l2_test", NULL, exit_monitor_from_l2_main,
exit_monitor_from_l2_handler, NULL, {0} },
/* Basic V2 tests. */
TEST(v2_null_test),
TEST(v2_multiple_entries_test),
TEST(fixture_test_case1),
TEST(fixture_test_case2),
/* EPT access tests. */
TEST(ept_access_test_not_present),
TEST(ept_access_test_read_only),
TEST(ept_access_test_write_only),
TEST(ept_access_test_read_write),
TEST(ept_access_test_execute_only),
TEST(ept_access_test_read_execute),
TEST(ept_access_test_write_execute),
TEST(ept_access_test_read_write_execute),
TEST(ept_access_test_reserved_bits),
TEST(ept_access_test_ignored_bits),
TEST(ept_access_test_paddr_not_present_ad_disabled),
TEST(ept_access_test_paddr_not_present_ad_enabled),
TEST(ept_access_test_paddr_read_only_ad_disabled),
TEST(ept_access_test_paddr_read_only_ad_enabled),
TEST(ept_access_test_paddr_read_write),
TEST(ept_access_test_paddr_read_write_execute),
TEST(ept_access_test_paddr_read_execute_ad_disabled),
TEST(ept_access_test_paddr_read_execute_ad_enabled),
TEST(ept_access_test_paddr_not_present_page_fault),
TEST(ept_access_test_force_2m_page),
/* Opcode tests. */
TEST(invvpid_test_v2),
/* VM-entry tests */
TEST(vmx_controls_test),
TEST(vmentry_movss_shadow_test),
{ NULL, NULL, NULL, NULL, NULL, {0} },
};
|
8ff0a1a331f92be8cae876918b0e6b614a241c2c
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/arch/arm/src/tiva/hardware/cc13x0/cc13x0_uart.h
|
9cc681b4d467433ec0b830b410c79de7c355931a
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 15,603
|
h
|
cc13x0_uart.h
|
/****************************************************************************
* arch/arm/src/tiva/hardware/cc13x0/cc13x0_uart.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Technical content derives from a TI header file that has a compatible
* BSD license:
*
* Copyright (c) 2015-2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_TIVA_HARDWARE_CC13X0_CC13X0_UART_H
#define __ARCH_ARM_SRC_TIVA_HARDWARE_CC13X0_CC13X0_UART_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <arch/chip/chip.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* UART register offsets ****************************************************/
#define TIVA_UART_DR_OFFSET 0x0000 /* UART Data */
#define TIVA_UART_RSR_OFFSET 0x0004 /* UART Receive Status */
#define TIVA_UART_ECR_OFFSET 0x0004 /* UART Error Clear */
#define TIVA_UART_FR_OFFSET 0x0018 /* UART Flag */
#define TIVA_UART_IBRD_OFFSET 0x0024 /* UART Integer Baud-Rate Divisor*/
#define TIVA_UART_FBRD_OFFSET 0x0028 /* UART Fractional Baud-Rate Divisor */
#define TIVA_UART_LCRH_OFFSET 0x002c /* UART Line Control */
#define TIVA_UART_CTL_OFFSET 0x0030 /* UART Control */
#define TIVA_UART_IFLS_OFFSET 0x0034 /* UART Interrupt FIFO Level Select */
#define TIVA_UART_IM_OFFSET 0x0038 /* UART Interrupt Mask */
#define TIVA_UART_RIS_OFFSET 0x003c /* UART Raw Interrupt Status */
#define TIVA_UART_MIS_OFFSET 0x0040 /* UART Masked Interrupt Status */
#define TIVA_UART_ICR_OFFSET 0x0044 /* UART Interrupt Clear */
#define TIVA_UART_DMACTL_OFFSET 0x0048 /* UART DMA Control */
#define TIVA_UART_PERIPHID4_OFFSET 0x0fd0 /* UART Peripheral Identification 4 */
#define TIVA_UART_PERIPHID5_OFFSET 0x0fd4 /* UART Peripheral Identification 5 */
#define TIVA_UART_PERIPHID6_OFFSET 0x0fd8 /* UART Peripheral Identification 6 */
#define TIVA_UART_PERIPHID7_OFFSET 0x0fdc /* UART Peripheral Identification 7 */
#define TIVA_UART_PERIPHID0_OFFSET 0x0fe0 /* UART Peripheral Identification 0 */
#define TIVA_UART_PERIPHID1_OFFSET 0x0fe4 /* UART Peripheral Identification 1 */
#define TIVA_UART_PERIPHID2_OFFSET 0x0fe8 /* UART Peripheral Identification 2 */
#define TIVA_UART_PERIPHID3_OFFSET 0x0fec /* UART Peripheral Identification 3 */
#define TIVA_UART_PCELLID0_OFFSET 0x0ff0 /* UART PrimeCell Identification 0 */
#define TIVA_UART_PCELLID1_OFFSET 0x0ff4 /* UART PrimeCell Identification 1 */
#define TIVA_UART_PCELLID2_OFFSET 0x0ff8 /* UART PrimeCell Identification 2 */
#define TIVA_UART_PCELLID3_OFFSET 0x0ffc /* UART PrimeCell Identification 3 */
/* UART register addresses **************************************************/
#define TIVA_UART_BASE(n) (TIVA_UART0_BASE + (n)*0x01000)
#define TIVA_UART_DR(n) (TIVA_UART_BASE(n) + TIVA_UART_DR_OFFSET)
#define TIVA_UART_RSR(n) (TIVA_UART_BASE(n) + TIVA_UART_RSR_OFFSET)
#define TIVA_UART_ECR(n) (TIVA_UART_BASE(n) + TIVA_UART_ECR_OFFSET)
#define TIVA_UART_FR(n) (TIVA_UART_BASE(n) + TIVA_UART_FR_OFFSET)
#define TIVA_UART_IBRD(n) (TIVA_UART_BASE(n) + TIVA_UART_IBRD_OFFSET)
#define TIVA_UART_FBRD(n) (TIVA_UART_BASE(n) + TIVA_UART_FBRD_OFFSET)
#define TIVA_UART_LCRH(n) (TIVA_UART_BASE(n) + TIVA_UART_LCRH_OFFSET)
#define TIVA_UART_CTL(n) (TIVA_UART_BASE(n) + TIVA_UART_CTL_OFFSET)
#define TIVA_UART_IFLS(n) (TIVA_UART_BASE(n) + TIVA_UART_IFLS_OFFSET)
#define TIVA_UART_IM(n) (TIVA_UART_BASE(n) + TIVA_UART_IM_OFFSET)
#define TIVA_UART_RIS(n) (TIVA_UART_BASE(n) + TIVA_UART_RIS_OFFSET)
#define TIVA_UART_MIS(n) (TIVA_UART_BASE(n) + TIVA_UART_MIS_OFFSET)
#define TIVA_UART_ICR(n) (TIVA_UART_BASE(n) + TIVA_UART_ICR_OFFSET)
#define TIVA_UART_DMACTL(n) (TIVA_UART_BASE(n) + TIVA_UART_DMACTL_OFFSET)
#if TIVA_NUARTS > 0
# define TIVA_UART0_DR (TIVA_UART0_BASE + TIVA_UART_DR_OFFSET)
# define TIVA_UART0_RSR (TIVA_UART0_BASE + TIVA_UART_RSR_OFFSET)
# define TIVA_UART0_ECR (TIVA_UART0_BASE + TIVA_UART_ECR_OFFSET)
# define TIVA_UART0_FR (TIVA_UART0_BASE + TIVA_UART_FR_OFFSET)
# define TIVA_UART0_IBRD (TIVA_UART0_BASE + TIVA_UART_IBRD_OFFSET)
# define TIVA_UART0_FBRD (TIVA_UART0_BASE + TIVA_UART_FBRD_OFFSET)
# define TIVA_UART0_LCRH (TIVA_UART0_BASE + TIVA_UART_LCRH_OFFSET)
# define TIVA_UART0_CTL (TIVA_UART0_BASE + TIVA_UART_CTL_OFFSET)
# define TIVA_UART0_IFLS (TIVA_UART0_BASE + TIVA_UART_IFLS_OFFSET)
# define TIVA_UART0_IM (TIVA_UART0_BASE + TIVA_UART_IM_OFFSET)
# define TIVA_UART0_RIS (TIVA_UART0_BASE + TIVA_UART_RIS_OFFSET)
# define TIVA_UART0_MIS (TIVA_UART0_BASE + TIVA_UART_MIS_OFFSET)
# define TIVA_UART0_ICR (TIVA_UART0_BASE + TIVA_UART_ICR_OFFSET)
# define TIVA_UART0_DMACTL (TIVA_UART0_BASE + TIVA_UART_DMACTL_OFFSET)
#endif
/* UART register bit settings ***********************************************/
/* UART Data (DR) */
#define UART_DR_DATA_SHIFT 0 /* Bits 7-0: Data Transmitted or Received */
#define UART_DR_DATA_MASK (0xff << UART_DR_DATA_SHIFT)
#define UART_DR_FE (1 << 8) /* Bit 8: UART Framing Error */
#define UART_DR_PE (1 << 9) /* Bit 9: UART Parity Error */
#define UART_DR_BE (1 << 10) /* Bit 10: UART Break Error */
#define UART_DR_OE (1 << 11) /* Bit 11: UART Overrun Error */
/* UART Receive Status (RSR) */
#define UART_RSR_FE (1 << 0) /* Bit 0: UART Framing Error */
#define UART_RSR_PE (1 << 1) /* Bit 1: UART Parity Error */
#define UART_RSR_BE (1 << 2) /* Bit 2: UART Break Error */
#define UART_RSR_OE (1 << 3) /* Bit 3: UART Overrun Error */
/* UART Error Clear (ECR) */
#define UART_ECR_FE (1 << 0) /* Bit 0: UART Clear Framing Error */
#define UART_ECR_PE (1 << 1) /* Bit 1: UART Clear Parity Error */
#define UART_ECR_BE (1 << 2) /* Bit 2: UART Clear Break Error */
#define UART_ECR_OE (1 << 3) /* Bit 3: UART Clear Overrun Error */
/* UART Flag (FR) */
#define UART_FR_CTS (1 << 0) /* Bit 0: Clear to Send */
#define UART_FR_BUSY (1 << 3) /* Bit 3: UART Busy */
#define UART_FR_RXFE (1 << 4) /* Bit 4: UART Receive FIFO Empty */
#define UART_FR_TXFF (1 << 5) /* Bit 5: UART Transmit FIFO Full */
#define UART_FR_RXFF (1 << 6) /* Bit 6: UART Receive FIFO Full */
#define UART_FR_TXFE (1 << 7) /* Bit 7: UART Transmit FIFO Empty */
/* UART Integer Baud-Rate Divisor (IBRD) */
#define UART_IBRD_DIVINT_MASK (0xffff) /* Bits 15-0: Integer Baud-Rate Divisor */
/* UART Fractional Baud-Rate Divisor (UARTFBRD) */
#define UART_FBRD_DIVFRAC_MASK (0x3f) /* Bits 5-0: Fractional Baud-Rate Divisor */
/* Register 7: UART Line Control (LCRH) */
#define UART_LCRH_BRK (1 << 0) /* Bit 0: UART Send Break */
#define UART_LCRH_PEN (1 << 1) /* Bit 1: UART Parity Enable */
#define UART_LCRH_EPS (1 << 2) /* Bit 2: UART Even Parity Select */
#define UART_LCRH_STP2 (1 << 3) /* Bit 3: UART Two Stop Bits Select */
#define UART_LCRH_FEN (1 << 4) /* Bit 4: UART Enable FIFOs */
#define UART_LCRH_WLEN_SHIFT 5 /* Bits 6-5: UART Word Length */
#define UART_LCRH_WLEN_MASK (3 << UART_LCRH_WLEN_SHIFT)
# define UART_LCRH_WLEN_5BITS (0 << UART_LCRH_WLEN_SHIFT) /* 5-bits (reset) */
# define UART_LCRH_WLEN_6BITS (1 << UART_LCRH_WLEN_SHIFT) /* 6-bits */
# define UART_LCRH_WLEN_7BITS (2 << UART_LCRH_WLEN_SHIFT) /* 7-bits */
# define UART_LCRH_WLEN_8BITS (3 << UART_LCRH_WLEN_SHIFT) /* 8-bits */
#define UART_LCRH_SPS (1 << 7) /* Bit 7: UART Stick Parity Select */
/* UART Control (CTL) */
#define UART_CTL_UARTEN (1 << 0) /* Bit 0: UART Enable */
#define UART_CTL_LBE (1 << 7) /* Bit 7: UART Loop Back Enable */
#define UART_CTL_TXE (1 << 8) /* Bit 8: UART Transmit Enable */
#define UART_CTL_RXE (1 << 9) /* Bit 9: UART Receive Enable */
#define UART_CTL_RTS (1 << 11) /* Bit 11: Request to Send */
#define UART_CTL_RTSEN (1 << 14) /* Bit 14: Enable Request to Send */
#define UART_CTL_CTSEN (1 << 15) /* Bit 15: Enable Clear To Send */
/* UART Interrupt FIFO Level Select (IFLS) */
#define UART_IFLS_TXIFLSEL_SHIFT 0 /* Bits 0-2: UART Transmit Interrupt FIFO Level Select */
#define UART_IFLS_TXIFLSEL_MASK (7 << UART_IFLS_TXIFLSEL_SHIFT)
# define UART_IFLS_TXIFLSEL_18TH (0 << UART_IFLS_TXIFLSEL_SHIFT) /* 1/8th full */
# define UART_IFLS_TXIFLSEL_14TH (1 << UART_IFLS_TXIFLSEL_SHIFT) /* 1/4th full */
# define UART_IFLS_TXIFLSEL_HALF (2 << UART_IFLS_TXIFLSEL_SHIFT) /* half full */
# define UART_IFLS_TXIFLSEL_34TH (3 << UART_IFLS_TXIFLSEL_SHIFT) /* 3/4th full */
# define UART_IFLS_TXIFLSEL_78TH (4 << UART_IFLS_TXIFLSEL_SHIFT) /* 7/8th full */
#define UART_IFLS_RXIFLSEL_SHIFT 3 /* Bits 3-5: UART Receive Interrupt FIFO Level Select */
#define UART_IFLS_RXIFLSEL_MASK (7 << UART_IFLS_RXIFLSEL_SHIFT)
# define UART_IFLS_RXIFLSEL_18TH (0 << UART_IFLS_RXIFLSEL_SHIFT) /* 1/8th full */
# define UART_IFLS_RXIFLSEL_14TH (1 << UART_IFLS_RXIFLSEL_SHIFT) /* 1/4th full */
# define UART_IFLS_RXIFLSEL_HALF (2 << UART_IFLS_RXIFLSEL_SHIFT) /* half full */
# define UART_IFLS_RXIFLSEL_34TH (3 << UART_IFLS_RXIFLSEL_SHIFT) /* 3/4th full */
# define UART_IFLS_RXIFLSEL_78TH (4 << UART_IFLS_RXIFLSEL_SHIFT) /* 7/8th full */
/* UART Interrupt Mask (IM) */
#define UART_IM_CTSIM (1 << 1) /* Bit 1: UART Clear to Send Modem Interrupt Mask */
#define UART_IM_RXIM (1 << 4) /* Bit 4: UART Receive Interrupt Mask */
#define UART_IM_TXIM (1 << 5) /* Bit 5: UART Transmit Interrupt Mask */
#define UART_IM_RTIM (1 << 6) /* Bit 6: UART Receive Time-Out Interrupt Mask */
#define UART_IM_FEIM (1 << 7) /* Bit 7: UART Framing Error Interrupt Mask */
#define UART_IM_PEIM (1 << 8) /* Bit 8: UART Parity Error Interrupt Mask */
#define UART_IM_BEIM (1 << 9) /* Bit 9: UART Break Error Interrupt Mask */
#define UART_IM_OEIM (1 << 10) /* Bit 10: UART Overrun Error Interrupt Mask */
/* UART Raw Interrupt Status (RIS) */
#define UART_RIS_CTSIS (1 << 1) /* Bit 1: UART Clear to Send Modem Raw Interrupt Status */
#define UART_RIS_RXRIS (1 << 4) /* Bit 4: UART Receive Raw Interrupt Status */
#define UART_RIS_TXRIS (1 << 5) /* Bit 5: UART Transmit Raw Interrupt Status */
#define UART_RIS_RTRIS (1 << 6) /* Bit 6: UART Receive Time-Out Raw Interrupt Status */
#define UART_RIS_FERIS (1 << 7) /* Bit 7: UART Framing Error Raw Interrupt Status */
#define UART_RIS_PERIS (1 << 8) /* Bit 8: UART Parity Error Raw Interrupt Status */
#define UART_RIS_BERIS (1 << 9) /* Bit 9: UART Break Error Raw Interrupt Status */
#define UART_RIS_OERIS (1 << 10) /* Bit 10: UART Overrun Error Raw Interrupt Status */
/* UART Masked Interrupt Status (MIS) */
#define UART_MIS_CTSIS (1 << 1) /* Bit 1: UART Clear to Send Modem Masked Interrupt Status */
#define UART_MIS_RXMIS (1 << 4) /* Bit 4: UART Receive Masked Interrupt Status */
#define UART_MIS_TXMIS (1 << 5) /* Bit 5: UART Transmit Masked Interrupt Status */
#define UART_MIS_RTMIS (1 << 6) /* Bit 6: UART Receive Time-Out Masked Interrupt Status */
#define UART_MIS_FEMIS (1 << 7) /* Bit 7: UART Framing Error Masked Interrupt Status */
#define UART_MIS_PEMIS (1 << 8) /* Bit 8: UART Parity Error Masked Interrupt Status */
#define UART_MIS_BEMIS (1 << 9) /* Bit 9: UART Break Error Masked Interrupt Status */
#define UART_MIS_OEMIS (1 << 10) /* Bit 10: UART Overrun Error Masked Interrupt Status */
/* UART Interrupt Clear (ICR) */
#define UART_ICR_CTSIC (1 << 1) /* Bit 1: UART Clear to Send Modem Interrupt Clear */
#define UART_ICR_RXIC (1 << 4) /* Bit 4: Receive Interrupt Clear */
#define UART_ICR_TXIC (1 << 5) /* Bit 5: Transmit Interrupt Clear */
#define UART_ICR_RTIC (1 << 6) /* Bit 6: Receive Time-Out Interrupt Clear */
#define UART_ICR_FEIC (1 << 7) /* Bit 7: Framing Error Interrupt Clear */
#define UART_ICR_PEIC (1 << 8) /* Bit 8: Parity Error Interrupt Clear */
#define UART_ICR_BEIC (1 << 9) /* Bit 9: Break Error Interrupt Clear */
#define UART_ICR_OEIC (1 << 10) /* Bit 10: Overrun Error Interrupt Clear */
/* UART DMA Control (DMACTL) */
#define UART_DMACTL_RXDMAE (1 << 0) /* Bit 0: Receive DMA Enable */
#define UART_DMACTL_TXDMAE (1 << 1) /* Bit 1: Transmit DMA Enable */
#define UART_DMACTL_DMAERR (1 << 2) /* Bit 2: DMA on Error */
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#endif /* __ARCH_ARM_SRC_TIVA_HARDWARE_CC13X0_CC13X0_UART_H */
|
482599343c1a8d99ebb3283aaa71b39ef48c322a
|
dfffb511642ed71d82fe35206789a767b876da3a
|
/VGA/kernel_c/Bitmap_Text/bitmap.c
|
d75bee90872c1c37f1573f69ff0479beb1629af5
|
[] |
no_license
|
pritamzope/OS
|
13953a44ad38d212d0792b1d2f70c6f90e9c366c
|
a58470ed14a942904fa5b2127c423d4860cf543c
|
refs/heads/master
| 2023-03-07T15:32:08.891080
| 2023-01-21T16:21:20
| 2023-01-21T16:21:20
| 153,988,174
| 639
| 129
| null | 2023-02-26T18:17:33
| 2018-10-21T08:34:25
|
C
|
UTF-8
|
C
| false
| false
| 5,393
|
c
|
bitmap.c
|
#include "bitmap.h"
#include "types.h"
#include "vga.h"
// 0 = no-pixel, 1 = pixel
uint8 bitmaps_0_9[10][BITMAP_SIZE] = {
// 0
{0b01111110, 0b11000011, 0b11000111, 0b11001111,
0b11011011, 0b11110011, 0b11100011, 0b01111110},
// 1
{0b00011000, 0b00111000, 0b00111000, 0b00011000,
0b00011000, 0b00011000, 0b01111110, 0b01111110},
// 2
{0b00111100, 0b11100111, 0b00000111, 0b00000110,
0b00011110, 0b01111000, 0b11100011, 0b11111111},
// 3
{0b00111100, 0b11100111, 0b00000111, 0b00011100,
0b00000111, 0b00000111, 0b11100110, 0b00111100},
// 4
{0b00011100, 0b00111100, 0b01101100, 0b11001100,
0b11001100, 0b11111110, 0b00001100, 0b00011110},
// 5
{0b11111111, 0b11000000, 0b11111110, 0b00000111,
0b00000111, 0b00000111, 0b11000110, 0b01111110},
// 6
{0b00011100, 0b00110000, 0b01100000, 0b11000000,
0b11111110, 0b11000011, 0b11000011, 0b01111110},
// 7
{0b11111111, 0b11111111, 0b11000111, 0b00000111,
0b00001110, 0b00111000, 0b00111000, 0b00111000},
// 8
{0b01111110, 0b01111110, 0b11000011, 0b11000011,
0b01111110, 0b11000011, 0b11000011, 0b01111110},
// 9
{0b01111110, 0b11000011, 0b11000011, 0b01111111,
0b00000011, 0b00000111, 0b00001110, 0b01111100},
};
uint8 bitmaps_A_Z[26][BITMAP_SIZE] = {
// A
{0b00011000, 0b00111100, 0b01100110, 0b11000011,
0b11000011, 0b11111111, 0b11000011, 0b11000011},
// B
{0b11111100, 0b01100110, 0b01100110, 0b01111100,
0b01111100, 0b01100110, 0b01100110, 0b11111100},
// C
{0b00111110, 0b01100011, 0b11000000, 0b11000000,
0b11000000, 0b11000000, 0b01100011, 0b00111110},
// D
{0b11111100, 0b01100110, 0b01100011, 0b01100011,
0b01100011, 0b01100011, 0b01100110, 0b11111100},
// E
{0b11111111, 0b01100001, 0b01100000, 0b01100100,
0b01111100, 0b01100100, 0b01100001, 0b11111111},
// F
{0b11111111, 0b01100001, 0b01100000, 0b01100100,
0b01111100, 0b01100100, 0b01100000, 0b11110000},
// G
{0b00111110, 0b01100011, 0b11000000, 0b11000000,
0b11000111, 0b11100011, 0b01100011, 0b00111111},
// H
{0b11000011, 0b11000011, 0b11000011, 0b11000011,
0b11111111, 0b11000011, 0b11000011, 0b11000011},
// I
{0b01111110, 0b00011000, 0b00011000, 0b00011000,
0b00011000, 0b00011000, 0b00011000, 0b01111110},
// J
{0b00001111, 0b00000110, 0b00000110, 0b00000110,
0b00000110, 0b11000110, 0b11000110, 0b01111100},
// K
{0b11100011, 0b01100011, 0b01100110, 0b01101100,
0b01111000, 0b01101100, 0b01100110, 0b11100011},
// L
{0b11110000, 0b01100000, 0b01100000, 0b01100000,
0b01100000, 0b01100001, 0b01100011, 0b11111111},
// M
{0b11000011, 0b11100111, 0b11111111, 0b11111111,
0b11011011, 0b11000011, 0b11000011, 0b11000011},
// N
{0b11000011, 0b11100011, 0b11110011, 0b11011011,
0b11001111, 0b11000111, 0b11000011, 0b11000011},
// O
{0b00111100, 0b01100110, 0b11000011, 0b11000011,
0b11000011, 0b11000011, 0b01100110, 0b00111100},
// P
{0b11111110, 0b01100011, 0b01100011, 0b01100011,
0b01111110, 0b01100000, 0b01100000, 0b11110000},
// Q
{0b01111110, 0b11000011, 0b11000011, 0b11000011,
0b11000011, 0b11001111, 0b01111110, 0b00001111},
// R
{0b11111110, 0b01100011, 0b01100011, 0b01111110,
0b01101110, 0b01100110, 0b01100011, 0b11100011},
// S
{0b01111110, 0b11000011, 0b11100000, 0b01110000,
0b00011111, 0b00000011, 0b11000110, 0b01111100},
// T
{0b11111111, 0b10011001, 0b00011000, 0b00011000,
0b00011000, 0b00011000, 0b00011000, 0b00111100},
// U
{0b11000011, 0b11000011, 0b11000011, 0b11000011,
0b11000011, 0b11000011, 0b11000011, 0b11111111},
// V
{0b11000011, 0b11000011, 0b11000011, 0b11000011,
0b11000011, 0b11000011, 0b00111100, 0b00011000},
// W
{0b11000011, 0b11000011, 0b11000011, 0b11000011,
0b11011011, 0b11111111, 0b11100111, 0b11000011},
// X
{0b11000011, 0b11000011, 0b01100110, 0b01100110,
0b00111100, 0b00111100, 0b01100111, 0b11000011},
// Y
{0b11000011, 0b11000011, 0b11000011, 0b11000011,
0b01111110, 0b000011000, 0b00011000, 0b00111100},
// Z
{0b11111111, 0b11000011, 0b10000110, 0b00001100,
0b00011000, 0b00110001, 0b01100011, 0b11111111}
};
// putpixels of 0-9 bits from right-to-left
void draw_num_bitmaps(uint16 index, uint16 x, uint16 y, uint8 color)
{
uint16 temp = 0, pix = 0;
for(uint8 i = 0; i < BITMAP_SIZE; i++){
temp = x;
x += BITMAP_SIZE;
pix = bitmaps_0_9[index][i];
while(pix > 0){
if(pix & 1){
putpixel(x, y, color);
}
pix >>= 1;
x--;
}
x = temp;
y++;
}
}
// putpixels of A-Z bits from right-to-left
void draw_alpha_bitmaps(uint16 index, uint16 x, uint16 y, uint8 color)
{
uint16 temp = 0, pix = 0;
for(uint8 i = 0; i < BITMAP_SIZE; i++){
temp = x;
x += BITMAP_SIZE;
pix = bitmaps_A_Z[index][i];
while(pix > 0){
if(pix & 1){
putpixel(x, y, color);
}
pix >>= 1;
x--;
}
x = temp;
y++;
}
}
void draw_char(uint16 x, uint16 y, uint8 color, char ch)
{
if(ch >= '0' && ch <= '9'){
draw_num_bitmaps(ch - '0', x, y, color);
}else if(ch >= 'A' && ch <= 'Z'){
draw_alpha_bitmaps((ch - '0') - 17, x, y, color);
}
}
void draw_string(uint16 x, uint16 y, uint8 color, char *str)
{
uint32 index = 0;
while(str[index]){
draw_char(x, y, color, str[index]);
x += BITMAP_SIZE + 1;
index++;
}
}
|
fb1fbc0c5f8485dde752d686043777bce01718ea
|
cb80ffbfe6b12be3f42322537aff3552fd9239f2
|
/examples/models/models_billboard.c
|
9b02a8af1f5fae295106c474fe84bc6f077f2d7b
|
[
"Zlib",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
raysan5/raylib
|
afe80387401361d6f35f9831978b0b379d2d9971
|
a86c93ebc0095f6c2ffc14656bfc9e1e37070f72
|
refs/heads/master
| 2023-08-16T20:49:02.921768
| 2023-08-14T22:09:27
| 2023-08-14T22:09:27
| 13,836,499
| 15,971
| 2,825
|
Zlib
| 2023-09-14T21:19:02
| 2013-10-24T15:46:04
|
C
|
UTF-8
|
C
| false
| false
| 4,751
|
c
|
models_billboard.c
|
/*******************************************************************************************
*
* raylib [models] example - Drawing billboards
*
* Example originally created with raylib 1.3, last time updated with raylib 3.5
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include "raymath.h"
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
// Define the camera to look into our 3d world
Camera camera = { 0 };
camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Texture2D bill = LoadTexture("resources/billboard.png"); // Our billboard texture
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
// Entire billboard texture, source is used to take a segment from a larger texture.
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
// NOTE: Billboard locked on axis-Y
Vector3 billUp = { 0.0f, 1.0f, 0.0f };
// Rotate around origin
// Here we choose to rotate around the image center
// NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture
Vector2 rotateOrigin = { 0.0f };
// Distance is needed for the correct billboard draw order
// Larger distance (further away from the camera) should be drawn prior to smaller distance.
float distanceStatic;
float distanceRotating;
float rotation = 0.0f;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_ORBITAL);
rotation += 0.4f;
distanceStatic = Vector3Distance(camera.position, billPositionStatic);
distanceRotating = Vector3Distance(camera.position, billPositionRotating);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
DrawGrid(10, 1.0f); // Draw a grid
// Draw order matters!
if (distanceStatic > distanceRotating)
{
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, (Vector2) {1.0f, 1.0f}, rotateOrigin, rotation, WHITE);
}
else
{
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, (Vector2) {1.0f, 1.0f}, rotateOrigin, rotation, WHITE);
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
}
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(bill); // Unload texture
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
|
69fe516324fa2a6695f6ea63ac588eae989accf8
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/os/include/tinyara/binary_manager.h
|
a848889579bc920b8c6bdda2117f290a75cb492e
|
[
"Apache-2.0",
"GPL-1.0-or-later",
"BSD-3-Clause",
"ISC",
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 8,971
|
h
|
binary_manager.h
|
/****************************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef __INCLUDE_TINYARA_BINARY_MANAGER_H
#define __INCLUDE_TINYARA_BINARY_MANAGER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <tinyara/config.h>
#include <stdint.h>
#include <limits.h>
#include <stdbool.h>
#ifdef CONFIG_BINARY_MANAGER
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define BINMGR_REQUEST_MQ "bin_req_mq"
#define BINMGR_RESPONSE_MQ_PREFIX "bin_res_mq"
/* Binary manager Callback Message Queue */
#define BINMGR_CBMSG_MQ "binmgr_cb"
/* Maximum number of messages on queue */
#define BINMGR_MAX_MSG 32
/* Message priority for request type */
#define BINMGR_FAULT_PRIO 100
#define BINMGR_NORMAL_PRIO 50
/* Message queue name Length */
#define BIN_PRIVMQ_LEN 16
/* The maximum length of binary name */
#define BIN_NAME_MAX 16
/* The number of User binaries */
#ifdef CONFIG_NUM_APPS
#define USER_BIN_COUNT CONFIG_NUM_APPS
#else
#define USER_BIN_COUNT 2
#endif
#define KERNEL_BIN_COUNT 2
#define BINARY_COUNT (USER_BIN_COUNT + KERNEL_BIN_COUNT)
/* Kernel version has "YYMMDD" format */
#define KERNEL_BIN_VER_MIN 101 /* YYMMDD : 000101 */
#define KERNEL_BIN_VER_MAX 991231 /* YYMMDD : 991231 */
/* The lenght of user or kernel partition path */
#define BINARY_PATH_LEN 16
/* Binary Type : Kernel, Common, User app */
enum binary_type_e {
BINARY_KERNEL = 0,
BINARY_COMMON = 1,
BINARY_USERAPP = 2,
BINARY_TYPE_MAX = 3,
};
/* Macros for binary grouping used for request to set bootparam */
#define BM_SET_GROUP(type, x) ((type) |= (1 << (x)))
#define BM_CLR_GROUP(type, x) ((type) &= ~(1 << (x)))
#define BM_CHECK_GROUP(type, x) ((type) & (1 << (x)))
/* Binary states used in state callback */
enum binary_statecb_state_e {
BINARY_STARTED = 0, /* Binary is started */
BINARY_UNLOADED = 1, /* Binary is unloaded */
BINARY_READYTOUNLOAD = 2, /* Binary will be unloaded */
};
/* States for user binary */
enum binary_state {
BINARY_UNREGISTERED = 0, /* File is not existing */
BINARY_INACTIVE = 1, /* File is existing but binary is not loaded yet */
BINARY_LOADED = 2, /* Loading binary is done */
BINARY_RUNNING = 3, /* Loaded binary gets scheduling */
BINARY_UNLOADING = 4, /* Loaded binary would be unloaded */
BINARY_FAULT = 5, /* Binary is excluded from scheduling and would be reloaded */
BINARY_STATE_MAX,
};
typedef enum binary_state binary_state_e;
/* Message type for binary manager */
enum binmgr_request_msg_type {
BINMGR_GET_INFO,
BINMGR_GET_INFO_ALL,
#ifdef CONFIG_USE_BP
BINMGR_SETBP,
#endif
BINMGR_UPDATE,
BINMGR_GET_STATE,
BINMGR_GET_DOWNLOAD_PATH,
BINMGR_GET_CURRENT_PATH,
BINMGR_NOTIFY_STARTED,
BINMGR_REGISTER_STATECB,
BINMGR_UNREGISTER_STATECB,
#ifdef CONFIG_BINMGR_RECOVERY
BINMGR_FAULT,
#endif
};
/* Result values of returned from binary manager. */
enum binmgr_result_type {
BINMGR_OK = 0,
BINMGR_COMMUNICATION_FAIL = -1,
BINMGR_OPERATION_FAIL = -2,
BINMGR_OUT_OF_MEMORY = -3,
BINMGR_INVALID_PARAM = -4,
BINMGR_NOT_FOUND = -5,
BINMGR_ALREADY_REGISTERED = -6,
BINMGR_ALREADY_UPDATED = -7,
BINMGR_INVALID_SIGNATURE = -8,
};
typedef enum binmgr_result_type binmgr_result_type_e;
/****************************************************************************
* Public Data
****************************************************************************/
/* Binary header data */
struct user_binary_header_s {
uint32_t crc_hash;
uint16_t header_size;
uint8_t bin_type;
uint8_t bin_priority;
uint8_t loading_priority;
uint32_t bin_size;
char bin_name[BIN_NAME_MAX];
uint32_t bin_ver;
uint32_t bin_ramsize;
uint32_t bin_stacksize;
uint32_t kernel_ver;
} __attribute__((__packed__));
typedef struct user_binary_header_s user_binary_header_t;
struct kernel_binary_header_s {
uint32_t crc_hash;
uint16_t header_size;
uint32_t version;
uint32_t binary_size;
uint16_t secure_header_size;
} __attribute__((__packed__));
typedef struct kernel_binary_header_s kernel_binary_header_t;
struct common_binary_header_s {
uint32_t crc_hash;
uint16_t header_size;
uint32_t version;
uint32_t bin_size;
} __attribute__((__packed__));
typedef struct common_binary_header_s common_binary_header_t;
/* The structure of binary update information for kernel or user binaries */
struct binary_setbp_result_s {
int result[BINARY_TYPE_MAX];
};
typedef struct binary_setbp_result_s binary_setbp_result_t;
/* The structure of binary update information for kernel or user binaries */
struct binary_update_info_s {
int available_size;
char name[BIN_NAME_MAX];
uint32_t version;
};
typedef struct binary_update_info_s binary_update_info_t;
/* The structure of load attr configuration */
struct load_attr_s {
char bin_name[BIN_NAME_MAX];
uint32_t bin_size; /* The size of ELF binary to be loaded */
uint32_t ram_size; /* The size of RAM partition required by binary */
uint32_t stack_size; /* Size of the stack allocated for binary */
uint16_t offset; /* The offset from which ELF binary has to be read in MTD partition */
uint8_t priority; /* Priority of the binary */
uint32_t bin_ver; /* version of binary */
#ifdef CONFIG_OPTIMIZE_APP_RELOAD_TIME
void *binp; /* Binary info pointer */
#endif
};
typedef struct load_attr_s load_attr_t;
/* The structure of binaries' information list */
struct binary_update_info_list_s {
uint32_t bin_count;
binary_update_info_t bin_info[BINARY_COUNT];
};
typedef struct binary_update_info_list_s binary_update_info_list_t;
typedef void (*binmgr_statecb_t)(char *bin_name, int state, void *cb_data);
struct binmgr_cb_s {
binmgr_statecb_t func;
void *data;
};
typedef struct binmgr_cb_s binmgr_cb_t;
struct binmgr_cb_msg_s {
binmgr_cb_t *callback;
bool need_response;
int state;
char bin_name[BIN_NAME_MAX];
};
typedef struct binmgr_cb_msg_s binmgr_cb_msg_t;
struct binmgr_request_s {
int cmd;
int requester_pid;
union {
uint8_t type;
char bin_name[BIN_NAME_MAX];
binmgr_cb_t *cb_info;
} data;
};
typedef struct binmgr_request_s binmgr_request_t;
struct binmgr_setbp_response_s {
binmgr_result_type_e result;
binary_setbp_result_t data;
};
typedef struct binmgr_setbp_response_s binmgr_setbp_response_t;
struct binmgr_getpath_response_s {
int result;
char binpath[BINARY_PATH_LEN];
};
typedef struct binmgr_getpath_response_s binmgr_getpath_response_t;
struct binmgr_getstate_response_s {
binmgr_result_type_e result;
binary_state_e state;
};
typedef struct binmgr_getstate_response_s binmgr_getstate_response_t;
struct binmgr_statecb_response_s {
binmgr_result_type_e result;
binmgr_cb_t *cb_info;
};
typedef struct binmgr_statecb_response_s binmgr_statecb_response_t;
struct binmgr_getinfo_response_s {
binmgr_result_type_e result;
binary_update_info_t data;
};
typedef struct binmgr_getinfo_response_s binmgr_getinfo_response_t;
struct binmgr_getinfo_all_response_s {
binmgr_result_type_e result;
binary_update_info_list_t data;
};
typedef struct binmgr_getinfo_all_response_s binmgr_getinfo_all_response_t;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
void binary_manager_register_kpart(int part_num, int part_size, int part_offset);
void binary_manager_register_bppart(int part_num, int part_size);
void binary_manager_register_upart(char *name, int part_num, int part_size, int part_offset);
void binary_manager_deinit_modules(void);
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_BINARY_MANAGER */
#endif /* __INCLUDE_TINYARA_BINARY_MANAGER_H */
|
dfb066dc4c2b5259edd2d61603df4b30b06669d2
|
d61b532db0d3e08818338cfaac530a1ced1ffe3b
|
/util/ceg/assemble/obj_assemble/const.h
|
fc24538a5e09bd98c1f8d151b3f5689b15a591b1
|
[
"LicenseRef-scancode-other-permissive"
] |
permissive
|
davidgiven/ack
|
61049c7a8e95ff61a77b1edd3c22bb290720e276
|
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
|
refs/heads/default
| 2023-08-29T07:33:12.771205
| 2023-07-08T20:17:27
| 2023-07-08T20:17:27
| 37,686,316
| 376
| 74
|
NOASSERTION
| 2023-07-08T20:17:28
| 2015-06-18T21:33:42
|
C
|
UTF-8
|
C
| false
| false
| 100
|
h
|
const.h
|
#define Bool int
#define TRUE 1
#define FALSE 0
#define MAX_OPERANDS 4
#define MAX_MNEMONICS 100
|
cecbf0a90fc285f2017b8028ff25bcd783d8cf6c
|
01bcef56ade123623725ca78d233ac8653a91ece
|
/public/wintab/wntab32x/mgropen.c
|
d9c704fbc236d0f50cab1b8164b81d77ad2dca86
|
[
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
SwagSoftware/Kisak-Strike
|
1085ba3c6003e622dac5ebc0c9424cb16ef58467
|
4c2fdc31432b4f5b911546c8c0d499a9cff68a85
|
refs/heads/master
| 2023-09-01T02:06:59.187775
| 2022-09-05T00:51:46
| 2022-09-05T00:51:46
| 266,676,410
| 921
| 123
| null | 2022-10-01T16:26:41
| 2020-05-25T03:41:35
|
C++
|
UTF-8
|
C
| false
| false
| 104
|
c
|
mgropen.c
|
#include <proc.h>
#include <xlib.h>
#include <xlibproc.h>
PROC_TEMPLATE( WTMgrOpen, Wintab, -, 100)
|
4f0cf995a537d623450d8ce221d66547f8546068
|
66df4873f0599b86e6baf66bb3a0c87329a71e61
|
/linked-lists/standard-recursive-traversal/main.c
|
ab315cce9ff2d5f1d21ba62f1faeba34fb8f0982
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
bartobri/data-structures-c
|
1aaaa0f9f36b173b2df6049d9677c70a0d2afbde
|
02d8e6b0aec7d38af5f5d5cab3383bdbc2288a61
|
refs/heads/master
| 2023-02-21T23:00:18.553695
| 2023-02-17T16:58:37
| 2023-02-17T16:58:37
| 82,822,619
| 102
| 48
|
MIT
| 2020-10-01T12:04:34
| 2017-02-22T15:48:12
|
C
|
UTF-8
|
C
| false
| false
| 354
|
c
|
main.c
|
#include <stdio.h>
#include "list.h"
#define N 10
void visit(link);
int main(void) {
int i;
link head, x;
// Population
head = new_link(0);
x = head;
for (i = 1; i < N; ++i) {
x = insert_after(x, new_link(i));
}
// Recursive Traversal
traverse(head, visit);
return 0;
}
void visit(link x) {
printf("Visited link %i\n", x->item);
}
|
372deb45feb8995bf64fb5b90e8c5c9d23929d74
|
7547d54f6f5f231fdd23a235b3c06bf80a6365df
|
/ext/polyphony/event.c
|
971cb5c4e1769dcc5264118f9af1574b91061590
|
[
"MIT"
] |
permissive
|
digital-fabric/polyphony
|
fed42f534dc4e72ec3b4de60c998fa4ec904795c
|
77b4e264344ef82ab5a31ebaa832a25489b26cda
|
refs/heads/master
| 2023-08-09T06:58:33.581327
| 2023-08-06T07:19:49
| 2023-08-06T07:19:49
| 145,374,867
| 624
| 18
|
MIT
| 2023-08-06T08:07:26
| 2018-08-20T06:22:07
|
C
|
UTF-8
|
C
| false
| false
| 2,299
|
c
|
event.c
|
#include "polyphony.h"
#include "ring_buffer.h"
typedef struct event {
VALUE waiting_fiber;
int signaled;
VALUE result;
} Event_t;
VALUE cEvent = Qnil;
static void Event_mark(void *ptr) {
Event_t *event = ptr;
rb_gc_mark(event->waiting_fiber);
rb_gc_mark(event->result);
}
static void Event_free(void *ptr) {
xfree(ptr);
}
static size_t Event_size(const void *ptr) {
return sizeof(Event_t);
}
static const rb_data_type_t Event_type = {
"Event",
{Event_mark, Event_free, Event_size,},
0, 0, 0
};
static VALUE Event_allocate(VALUE klass) {
Event_t *event;
event = ALLOC(Event_t);
return TypedData_Wrap_Struct(klass, &Event_type, event);
}
static VALUE Event_initialize(VALUE self) {
Event_t *event = RTYPEDDATA_DATA(self);
event->waiting_fiber = Qnil;
event->signaled = 0;
event->result = Qnil;
return self;
}
VALUE Event_signal(int argc, VALUE *argv, VALUE self) {
VALUE value = argc > 0 ? argv[0] : Qnil;
Event_t *event = RTYPEDDATA_DATA(self);
if (event->signaled) goto done;
event->signaled = 1;
event->result = value;
if (event->waiting_fiber != Qnil) {
Fiber_make_runnable(event->waiting_fiber, value);
event->waiting_fiber = Qnil;
}
done:
return self;
}
VALUE Event_await(VALUE self) {
Event_t *event = RTYPEDDATA_DATA(self);
VALUE switchpoint_result;
VALUE backend;
if (event->waiting_fiber != Qnil)
rb_raise(rb_eRuntimeError, "Event is already awaited by another fiber");
if (event->signaled) {
VALUE result = event->result;
event->signaled = 0;
event->result = Qnil;
return result;
}
backend = rb_ivar_get(rb_thread_current(), ID_ivar_backend);
event->waiting_fiber = rb_fiber_current();
switchpoint_result = Backend_wait_event(backend, Qnil);
event->waiting_fiber = Qnil;
event->signaled = 0;
event->result = Qnil;
RAISE_IF_EXCEPTION(switchpoint_result);
RB_GC_GUARD(backend);
RB_GC_GUARD(switchpoint_result);
return switchpoint_result;
}
void Init_Event(void) {
cEvent = rb_define_class_under(mPolyphony, "Event", rb_cObject);
rb_define_alloc_func(cEvent, Event_allocate);
rb_define_method(cEvent, "initialize", Event_initialize, 0);
rb_define_method(cEvent, "await", Event_await, 0);
rb_define_method(cEvent, "signal", Event_signal, -1);
}
|
1065bef7fa176dfea5d1f83591d619d9895318cd
|
7f6c235b0598353549959c18f69eefd20b766907
|
/examples/embedded/sine.c
|
bd9eeaaf0db903c91a9b60ba4dc1368cfdbf3171
|
[
"ClArtistic"
] |
permissive
|
z88dk/z88dk
|
46dfd4905f36d99333173cadd0a660839befc9f0
|
8b07f37cc43c5d9ffe69b563c80763491d8faff7
|
refs/heads/master
| 2023-09-04T19:29:49.254958
| 2023-09-03T20:51:24
| 2023-09-03T20:51:24
| 54,035,569
| 820
| 263
|
NOASSERTION
| 2023-09-05T11:09:04
| 2016-03-16T13:48:16
|
Assembly
|
UTF-8
|
C
| false
| false
| 445
|
c
|
sine.c
|
/*
* Z80 test
*
* Print stars in sine pattern
*
*/
#include <stdio.h>
#include <math.h>
#include "ns16450.h"
int main(void)
{
float spunk;
char res;
char p;
#if defined(__EMBEDDED)
init_uart(0,1);
#endif
while (1)
{
for (spunk = 0.0; spunk < 6.283; spunk = spunk + 0.1)
{
res = 30.0 * sin(spunk) + 40.0;
for (p = 0; p < res; ++p)
{
putchar(' ');
}
putchar('*');
putchar(0x0d);
putchar(0x0a);
}
}
}
|
7e3fa1e5082811fdb94e6b01468385784e407ab7
|
526b17ad25eec622b8f266034df3506ca1580ce6
|
/scheduler/cert.c
|
2a28b568f89f9fe95318ab517875ebcaa39bcc7d
|
[
"LLVM-exception",
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer",
"EPL-1.0",
"GPL-2.0-only",
"LGPL-2.0-only"
] |
permissive
|
apple/cups
|
906903c936f9ec702e50dcd9971ec71af90a56fb
|
ec055da6794984133d48cc376f04e10af62b64dc
|
refs/heads/master
| 2023-08-24T17:53:09.249969
| 2022-06-27T16:22:46
| 2022-06-27T16:22:46
| 44,137,852
| 1,875
| 570
|
Apache-2.0
| 2023-01-19T21:23:20
| 2015-10-12T22:33:18
|
C
|
UTF-8
|
C
| false
| false
| 9,994
|
c
|
cert.c
|
/*
* Authentication certificate routines for the CUPS scheduler.
*
* Copyright 2007-2016 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*/
/*
* Include necessary headers...
*/
#include "cupsd.h"
#ifdef HAVE_ACL_INIT
# include <sys/acl.h>
# ifdef HAVE_MEMBERSHIP_H
# include <membership.h>
# endif /* HAVE_MEMBERSHIP_H */
#endif /* HAVE_ACL_INIT */
/*
* Local functions...
*/
static int ctcompare(const char *a, const char *b);
/*
* 'cupsdAddCert()' - Add a certificate.
*/
void
cupsdAddCert(int pid, /* I - Process ID */
const char *username, /* I - Username */
int type) /* I - AuthType for username */
{
int i; /* Looping var */
cupsd_cert_t *cert; /* Current certificate */
int fd; /* Certificate file */
char filename[1024]; /* Certificate filename */
static const char hex[] = "0123456789ABCDEF";
/* Hex constants... */
cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAddCert: Adding certificate for PID %d", pid);
/*
* Allocate memory for the certificate...
*/
if ((cert = calloc(sizeof(cupsd_cert_t), 1)) == NULL)
return;
/*
* Fill in the certificate information...
*/
cert->pid = pid;
cert->type = type;
strlcpy(cert->username, username, sizeof(cert->username));
for (i = 0; i < 32; i ++)
cert->certificate[i] = hex[CUPS_RAND() & 15];
/*
* Save the certificate to a file readable only by the User and Group
* (or root and SystemGroup for PID == 0)...
*/
snprintf(filename, sizeof(filename), "%s/certs/%d", StateDir, pid);
unlink(filename);
if ((fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0400)) < 0)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to create certificate file %s - %s",
filename, strerror(errno));
free(cert);
return;
}
if (pid == 0)
{
#ifdef HAVE_ACL_INIT
acl_t acl; /* ACL information */
acl_entry_t entry; /* ACL entry */
acl_permset_t permset; /* Permissions */
# ifdef HAVE_MBR_UID_TO_UUID
uuid_t group; /* Group ID */
# endif /* HAVE_MBR_UID_TO_UUID */
static int acls_not_supported = 0;
/* Only warn once */
#endif /* HAVE_ACL_INIT */
/*
* Root certificate...
*/
fchmod(fd, 0440);
fchown(fd, RunUser, SystemGroupIDs[0]);
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddCert: NumSystemGroups=%d", NumSystemGroups);
#ifdef HAVE_ACL_INIT
if (NumSystemGroups > 1)
{
/*
* Set POSIX ACLs for the root certificate so that all system
* groups can access it...
*/
int j; /* Looping var */
# ifdef HAVE_MBR_UID_TO_UUID
/*
* On macOS, ACLs use UUIDs instead of GIDs...
*/
acl = acl_init(NumSystemGroups - 1);
for (i = 1; i < NumSystemGroups; i ++)
{
/*
* Add each group ID to the ACL...
*/
for (j = 0; j < i; j ++)
if (SystemGroupIDs[j] == SystemGroupIDs[i])
break;
if (j < i)
continue; /* Skip duplicate groups */
acl_create_entry(&acl, &entry);
acl_get_permset(entry, &permset);
acl_add_perm(permset, ACL_READ_DATA);
acl_set_tag_type(entry, ACL_EXTENDED_ALLOW);
mbr_gid_to_uuid((gid_t)SystemGroupIDs[i], group);
acl_set_qualifier(entry, &group);
acl_set_permset(entry, permset);
}
# else
/*
* POSIX ACLs need permissions for owner, group, other, and mask
* in addition to the rest of the system groups...
*/
acl = acl_init(NumSystemGroups + 3);
/* Owner */
acl_create_entry(&acl, &entry);
acl_get_permset(entry, &permset);
acl_add_perm(permset, ACL_READ);
acl_set_tag_type(entry, ACL_USER_OBJ);
acl_set_permset(entry, permset);
/* Group */
acl_create_entry(&acl, &entry);
acl_get_permset(entry, &permset);
acl_add_perm(permset, ACL_READ);
acl_set_tag_type(entry, ACL_GROUP_OBJ);
acl_set_permset(entry, permset);
/* Others */
acl_create_entry(&acl, &entry);
acl_get_permset(entry, &permset);
acl_add_perm(permset, 0);
acl_set_tag_type(entry, ACL_OTHER);
acl_set_permset(entry, permset);
/* Mask */
acl_create_entry(&acl, &entry);
acl_get_permset(entry, &permset);
acl_add_perm(permset, ACL_READ);
acl_set_tag_type(entry, ACL_MASK);
acl_set_permset(entry, permset);
for (i = 1; i < NumSystemGroups; i ++)
{
/*
* Add each group ID to the ACL...
*/
for (j = 0; j < i; j ++)
if (SystemGroupIDs[j] == SystemGroupIDs[i])
break;
if (j < i)
continue; /* Skip duplicate groups */
acl_create_entry(&acl, &entry);
acl_get_permset(entry, &permset);
acl_add_perm(permset, ACL_READ);
acl_set_tag_type(entry, ACL_GROUP);
acl_set_qualifier(entry, SystemGroupIDs + i);
acl_set_permset(entry, permset);
}
if (acl_valid(acl))
{
char *text, *textptr; /* Temporary string */
cupsdLogMessage(CUPSD_LOG_ERROR, "ACL did not validate: %s",
strerror(errno));
text = acl_to_text(acl, NULL);
for (textptr = strchr(text, '\n');
textptr;
textptr = strchr(textptr + 1, '\n'))
*textptr = ',';
cupsdLogMessage(CUPSD_LOG_ERROR, "ACL: %s", text);
acl_free(text);
}
# endif /* HAVE_MBR_UID_TO_UUID */
if (acl_set_fd(fd, acl))
{
if (errno != EOPNOTSUPP || !acls_not_supported)
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to set ACLs on root certificate \"%s\" - %s",
filename, strerror(errno));
if (errno == EOPNOTSUPP)
acls_not_supported = 1;
}
acl_free(acl);
}
#endif /* HAVE_ACL_INIT */
RootCertTime = time(NULL);
}
else
{
/*
* CGI certificate...
*/
fchmod(fd, 0400);
fchown(fd, User, Group);
}
write(fd, cert->certificate, strlen(cert->certificate));
close(fd);
/*
* Insert the certificate at the front of the list...
*/
cert->next = Certs;
Certs = cert;
}
/*
* 'cupsdDeleteCert()' - Delete a single certificate.
*/
void
cupsdDeleteCert(int pid) /* I - Process ID */
{
cupsd_cert_t *cert, /* Current certificate */
*prev; /* Previous certificate */
char filename[1024]; /* Certificate file */
for (prev = NULL, cert = Certs; cert != NULL; prev = cert, cert = cert->next)
if (cert->pid == pid)
{
/*
* Remove this certificate from the list...
*/
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeleteCert: Removing certificate for PID %d.", pid);
if (prev == NULL)
Certs = cert->next;
else
prev->next = cert->next;
free(cert);
/*
* Delete the file and return...
*/
snprintf(filename, sizeof(filename), "%s/certs/%d", StateDir, pid);
if (unlink(filename))
cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to remove %s!", filename);
return;
}
}
/*
* 'cupsdDeleteAllCerts()' - Delete all certificates...
*/
void
cupsdDeleteAllCerts(void)
{
cupsd_cert_t *cert, /* Current certificate */
*next; /* Next certificate */
char filename[1024]; /* Certificate file */
/*
* Loop through each certificate, deleting them...
*/
for (cert = Certs; cert != NULL; cert = next)
{
/*
* Delete the file...
*/
snprintf(filename, sizeof(filename), "%s/certs/%d", StateDir, cert->pid);
if (unlink(filename))
cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to remove %s!", filename);
/*
* Free memory...
*/
next = cert->next;
free(cert);
}
Certs = NULL;
RootCertTime = 0;
}
/*
* 'cupsdFindCert()' - Find a certificate.
*/
cupsd_cert_t * /* O - Matching certificate or NULL */
cupsdFindCert(const char *certificate) /* I - Certificate */
{
cupsd_cert_t *cert; /* Current certificate */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdFindCert(certificate=%s)", certificate);
for (cert = Certs; cert != NULL; cert = cert->next)
if (!ctcompare(certificate, cert->certificate))
{
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdFindCert: Returning \"%s\".", cert->username);
return (cert);
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdFindCert: Certificate not found.");
return (NULL);
}
/*
* 'cupsdInitCerts()' - Initialize the certificate "system" and root
* certificate.
*/
void
cupsdInitCerts(void)
{
#ifndef HAVE_ARC4RANDOM
cups_file_t *fp; /* /dev/random file */
/*
* Initialize the random number generator using the random device or
* the current time, as available...
*/
if ((fp = cupsFileOpen("/dev/urandom", "rb")) == NULL)
{
struct timeval tod; /* Time of day */
/*
* Get the time in usecs and use it as the initial seed...
*/
gettimeofday(&tod, NULL);
CUPS_SRAND((unsigned)(tod.tv_sec + tod.tv_usec));
}
else
{
unsigned seed; /* Seed for random number generator */
/*
* Read 4 random characters from the random device and use
* them as the seed...
*/
seed = (unsigned)cupsFileGetChar(fp);
seed = (seed << 8) | (unsigned)cupsFileGetChar(fp);
seed = (seed << 8) | (unsigned)cupsFileGetChar(fp);
CUPS_SRAND((seed << 8) | (unsigned)cupsFileGetChar(fp));
cupsFileClose(fp);
}
#endif /* !HAVE_ARC4RANDOM */
/*
* Create a root certificate and return...
*/
if (!RunUser)
cupsdAddCert(0, "root", cupsdDefaultAuthType());
}
/*
* 'ctcompare()' - Compare two strings in constant time.
*/
static int /* O - 0 on match, non-zero on non-match */
ctcompare(const char *a, /* I - First string */
const char *b) /* I - Second string */
{
int result = 0; /* Result */
while (*a && *b)
{
result |= *a ^ *b;
a ++;
b ++;
}
// either both *a and *b == '\0', or one points inside a string,
// so factor that in.
result |= (*a ^ *b);
return (result);
}
|
5d75121a10efe1ed2679e6b81cd16c8b65b257ab
|
c9bc99866cfab223c777cfb741083be3e9439d81
|
/product/tc1/scp_romfw/config_sds.c
|
b0754f37677972840927051809d0ee1e93ea0b63
|
[
"BSD-3-Clause"
] |
permissive
|
ARM-software/SCP-firmware
|
4738ca86ce42d82588ddafc2226a1f353ff2c797
|
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
|
refs/heads/master
| 2023-09-01T16:13:36.962036
| 2023-08-17T13:00:20
| 2023-08-31T07:43:37
| 134,399,880
| 211
| 165
|
NOASSERTION
| 2023-09-13T14:27:10
| 2018-05-22T10:35:56
|
C
|
UTF-8
|
C
| false
| false
| 2,768
|
c
|
config_sds.c
|
/*
* Arm SCP/MCP Software
* Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "clock_soc.h"
#include "scp_mmap.h"
#include "scp_pik.h"
#include "tc1_sds.h"
#include <mod_sds.h>
#include <fwk_assert.h>
#include <fwk_element.h>
#include <fwk_id.h>
#include <fwk_macros.h>
#include <fwk_module.h>
#include <fwk_module_idx.h>
#include <stdbool.h>
#include <stdint.h>
static const uint32_t feature_flags = 0x00000000;
static const struct mod_sds_region_desc sds_module_regions[1] = {
[TC1_SDS_REGION_SECURE] =
{
.base = (void *)SCP_SDS_MEM_BASE,
.size = SCP_SDS_MEM_SIZE,
},
};
static_assert(
FWK_ARRAY_SIZE(sds_module_regions) == TC1_SDS_REGION_COUNT,
"Mismatch between number of SDS regions and number of regions "
"provided by the SDS configuration.");
const struct mod_sds_config sds_module_config = {
.regions = sds_module_regions,
.region_count = TC1_SDS_REGION_COUNT,
.clock_id = FWK_ID_ELEMENT_INIT(
FWK_MODULE_IDX_CLOCK,
CLOCK_IDX_CPU_GROUP_CORTEX_A510)
};
static struct fwk_element sds_element_table[4] = {
{
.name = "CPU Info",
.data = &((struct mod_sds_structure_desc){
.id = TC1_SDS_CPU_INFO,
.size = TC1_SDS_CPU_INFO_SIZE,
.region_id = TC1_SDS_REGION_SECURE,
.finalize = true,
}),
},
{
.name = "Feature Availability",
.data = &((struct mod_sds_structure_desc){
.id = TC1_SDS_FEATURE_AVAILABILITY,
.size = TC1_SDS_FEATURE_AVAILABILITY_SIZE,
.payload = &feature_flags,
.region_id = TC1_SDS_REGION_SECURE,
.finalize = true,
}),
},
{
.name = "Bootloader",
.data = &((struct mod_sds_structure_desc){
.id = TC1_SDS_BOOTLOADER,
.size = TC1_SDS_BOOTLOADER_SIZE,
.region_id = TC1_SDS_REGION_SECURE,
.finalize = true,
}),
},
{ 0 }, /* Termination description. */
};
static_assert(
SCP_SDS_MEM_SIZE > TC1_SDS_CPU_INFO_SIZE +
TC1_SDS_FEATURE_AVAILABILITY_SIZE + TC1_SDS_BOOTLOADER_SIZE,
"SDS structures too large for SDS SRAM.\n");
static const struct fwk_element *sds_get_element_table(fwk_id_t module_id)
{
static_assert(BUILD_VERSION_MAJOR < UINT8_MAX, "Invalid version size");
static_assert(BUILD_VERSION_MINOR < UINT8_MAX, "Invalid version size");
static_assert(BUILD_VERSION_PATCH < UINT16_MAX, "Invalid version size");
return sds_element_table;
}
struct fwk_module_config config_sds = {
.elements = FWK_MODULE_DYNAMIC_ELEMENTS(sds_get_element_table),
.data = &sds_module_config,
};
|
64e294101f56ad1345e684c6eee787f576af900b
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/dev/fdt/mvrtc.c
|
d98f814bd3b0fce571f7766a136f108019ee3326
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 4,325
|
c
|
mvrtc.c
|
/* $OpenBSD: mvrtc.c,v 1.3 2022/10/17 19:09:46 kettenis Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/intr.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/fdt.h>
#include <dev/clock_subr.h>
/* Registers. */
#define RTC_STATUS 0x0000
#define RTC_TIME 0x000c
#define RTC_TIMING_CTL0 0x0000
#define RTC_TIMING_CTL0_WRCLK_PERIOD_MASK (0xffff << 0)
#define RTC_TIMING_CTL0_WRCLK_PERIOD_SHIFT 0
#define RTC_TIMING_CTL0_WRCLK_SETUP_MASK (0xffff << 16)
#define RTC_TIMING_CTL0_WRCLK_SETUP_SHIFT 16
#define RTC_TIMING_CTL1 0x0004
#define RTC_TIMING_CTL1_READ_DELAY_MASK (0xffff << 0)
#define RTC_TIMING_CTL1_READ_DELAY_SHIFT 0
#define HREAD4(sc, reg) \
(bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg)))
#define HWRITE4(sc, reg, val) \
bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
struct mvrtc_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
bus_space_handle_t sc_soc_ioh;
struct todr_chip_handle sc_todr;
};
int mvrtc_match(struct device *, void *, void *);
void mvrtc_attach(struct device *, struct device *, void *);
const struct cfattach mvrtc_ca = {
sizeof (struct mvrtc_softc), mvrtc_match, mvrtc_attach
};
struct cfdriver mvrtc_cd = {
NULL, "mvrtc", DV_DULL
};
int mvrtc_gettime(struct todr_chip_handle *, struct timeval *);
int mvrtc_settime(struct todr_chip_handle *, struct timeval *);
int
mvrtc_match(struct device *parent, void *match, void *aux)
{
struct fdt_attach_args *faa = aux;
return OF_is_compatible(faa->fa_node, "marvell,armada-8k-rtc");
}
void
mvrtc_attach(struct device *parent, struct device *self, void *aux)
{
struct mvrtc_softc *sc = (struct mvrtc_softc *)self;
struct fdt_attach_args *faa = aux;
uint32_t reg;
if (faa->fa_nreg < 2) {
printf(": no registers\n");
return;
}
sc->sc_iot = faa->fa_iot;
if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr,
faa->fa_reg[0].size, 0, &sc->sc_ioh)) {
printf(": can't map registers\n");
return;
}
if (bus_space_map(sc->sc_iot, faa->fa_reg[1].addr,
faa->fa_reg[1].size, 0, &sc->sc_soc_ioh)) {
bus_space_unmap(sc->sc_iot, sc->sc_ioh, faa->fa_reg[0].size);
printf(": can't map soc registers\n");
return;
}
/* Magic to make bus access actually work. */
reg = bus_space_read_4(sc->sc_iot, sc->sc_soc_ioh, RTC_TIMING_CTL0);
reg &= ~RTC_TIMING_CTL0_WRCLK_PERIOD_MASK;
reg |= (0x3ff << RTC_TIMING_CTL0_WRCLK_PERIOD_SHIFT);
reg &= ~RTC_TIMING_CTL0_WRCLK_SETUP_MASK;
reg |= (0x29 << RTC_TIMING_CTL0_WRCLK_SETUP_SHIFT);
bus_space_write_4(sc->sc_iot, sc->sc_soc_ioh, RTC_TIMING_CTL0, reg);
reg = bus_space_read_4(sc->sc_iot, sc->sc_soc_ioh, RTC_TIMING_CTL1);
reg &= ~RTC_TIMING_CTL1_READ_DELAY_MASK;
reg |= (0x3f << RTC_TIMING_CTL1_READ_DELAY_SHIFT);
bus_space_write_4(sc->sc_iot, sc->sc_soc_ioh, RTC_TIMING_CTL1, reg);
printf("\n");
sc->sc_todr.cookie = sc;
sc->sc_todr.todr_gettime = mvrtc_gettime;
sc->sc_todr.todr_settime = mvrtc_settime;
sc->sc_todr.todr_quality = 0;
todr_attach(&sc->sc_todr);
}
int
mvrtc_gettime(struct todr_chip_handle *handle, struct timeval *tv)
{
struct mvrtc_softc *sc = handle->cookie;
tv->tv_sec = HREAD4(sc, RTC_TIME);
tv->tv_usec = 0;
return 0;
}
int
mvrtc_settime(struct todr_chip_handle *handle, struct timeval *tv)
{
struct mvrtc_softc *sc = handle->cookie;
HWRITE4(sc, RTC_STATUS, 0);
HWRITE4(sc, RTC_STATUS, 0);
HWRITE4(sc, RTC_TIME, tv->tv_sec);
delay(10);
return 0;
}
|
129b0f9a6f62a6e3d9de5a7f51beb8b6acecb11a
|
0ab34cafb4fce823bdb64588375a5e0320c4d5da
|
/src/spesh/threshold.h
|
3337b92cb23b0a850f636d9c463cab8ae29c461d
|
[
"Artistic-2.0",
"MIT",
"BSD-3-Clause",
"LicenseRef-scancode-public-domain"
] |
permissive
|
MoarVM/MoarVM
|
00eb8de04ef3eb43d8dd108a016a5fbd644f7cb7
|
2f8234c222dea886da28a9e369e34f3cff18ad8a
|
refs/heads/main
| 2023-08-24T03:30:58.906341
| 2023-08-23T03:28:20
| 2023-08-23T03:28:20
| 10,411,154
| 616
| 228
|
NOASSERTION
| 2023-08-23T03:28:33
| 2013-05-31T19:02:30
|
C
|
UTF-8
|
C
| false
| false
| 183
|
h
|
threshold.h
|
/* The maximum size of bytecode we'll ever attempt to optimize. */
#define MVM_SPESH_MAX_BYTECODE_SIZE 65536
MVMuint32 MVM_spesh_threshold(MVMThreadContext *tc, MVMStaticFrame *sf);
|
95a133efb438d714717d335bc1f5c28d4270f852
|
1661c43eaf9e44dfe7cce269cfaae62e336036f1
|
/blink/memory.c
|
1119aa53e86248f12203e75aa9be9f7bc42f40cc
|
[] |
permissive
|
jart/blink
|
3354eaf084e3e85a50372f1a93fc75ff2b9488b1
|
312a027d0908c1b1f9d1e9ebba837da569606b82
|
refs/heads/master
| 2023-08-31T21:30:40.551686
| 2023-08-22T15:42:44
| 2023-08-22T15:42:44
| 561,183,031
| 6,089
| 192
|
ISC
| 2023-08-22T15:42:46
| 2022-11-03T06:07:09
|
C
|
UTF-8
|
C
| false
| false
| 19,890
|
c
|
memory.c
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include "blink/assert.h"
#include "blink/biosrom.h"
#include "blink/bus.h"
#include "blink/checked.h"
#include "blink/debug.h"
#include "blink/endian.h"
#include "blink/errno.h"
#include "blink/linux.h"
#include "blink/log.h"
#include "blink/machine.h"
#include "blink/macros.h"
#include "blink/pml4t.h"
#include "blink/stats.h"
#include "blink/thread.h"
#include "blink/util.h"
#include "blink/x86.h"
void SetReadAddr(struct Machine *m, i64 addr, u32 size) {
if (size) {
m->readaddr = addr;
m->readsize = size;
}
}
void SetWriteAddr(struct Machine *m, i64 addr, u32 size) {
if (size) {
m->writeaddr = addr;
m->writesize = size;
}
}
u8 *GetPageAddress(struct System *s, u64 entry, bool is_cr3) {
unassert(is_cr3 || (entry & PAGE_V));
unassert(~entry & PAGE_RSRV);
if (entry & PAGE_HOST) {
return (u8 *)(uintptr_t)(entry & PAGE_TA);
} else {
unassert(s->real);
if ((entry & PAGE_TA) + 4096 <= kRealSize) {
return s->real + (entry & PAGE_TA);
} else {
return 0;
}
}
}
u64 HandlePageFault(struct Machine *m, u8 *pslot, u64 entry) {
u64 x, page;
unassert(entry & PAGE_RSRV);
unassert(!HasLinearMapping());
if (m->nofault) {
m->segvcode = SEGV_MAPERR_LINUX;
errno = ENOBUFS;
return 0;
}
do {
if (entry & (PAGE_HOST | PAGE_MAP | PAGE_MUG)) {
// a file-mapped page is being accessed for the first time
unassert((entry & (PAGE_HOST | PAGE_MAP)) == (PAGE_HOST | PAGE_MAP));
x = entry & ~PAGE_RSRV;
if (CasPte(pslot, entry, x)) {
m->system->memstat.committed += 1;
m->system->memstat.reserved -= 1;
m->system->rss += 1;
entry = x;
} else {
entry = LoadPte(pslot);
}
} else {
// an anonymous page is being accessed for the first time
if ((page = AllocateAnonymousPage(m->system)) == -1) {
m->segvcode = SEGV_MAPERR_LINUX;
entry = 0;
break;
}
x = (page & (PAGE_TA | PAGE_HOST)) | (entry & ~(PAGE_TA | PAGE_RSRV));
if (CasPte(pslot, entry, x)) {
m->system->memstat.committed += 1;
m->system->memstat.reserved -= 1;
entry = x;
} else {
FreeAnonymousPage(m->system, (u8 *)(uintptr_t)(page & PAGE_TA));
entry = LoadPte(pslot);
m->system->rss -= 1;
}
}
} while (entry & PAGE_RSRV);
return entry;
}
bool HasPageLock(const struct Machine *m, i64 page) {
int i;
unassert(!(page & 4095));
for (i = m->pagelocks.i; i--;) {
if (m->pagelocks.p[i].page == page) {
return true;
}
}
return false;
}
static bool RecordPageLock(struct Machine *m, i64 page, u8 *pslot) {
unassert(m->sysdepth > 0);
unassert(!m->pagelocks.i ||
m->pagelocks.p[m->pagelocks.i - 1].sysdepth <= m->sysdepth);
if (m->pagelocks.i == m->pagelocks.n) {
int n2;
struct PageLock *p2;
p2 = m->pagelocks.p;
n2 = m->pagelocks.n;
n2 += 3;
n2 += n2 >> 1;
if ((p2 = (struct PageLock *)realloc(p2, n2 * sizeof(*p2)))) {
m->pagelocks.p = p2;
m->pagelocks.n = n2;
} else {
return false;
}
}
m->pagelocks.p[m->pagelocks.i].page = page;
m->pagelocks.p[m->pagelocks.i].pslot = pslot;
m->pagelocks.p[m->pagelocks.i].sysdepth = m->sysdepth;
++m->pagelocks.i;
STATISTIC(++page_locks);
return true;
}
static void ReleasePageLock(u8 *pslot) {
u64 entry;
do {
entry = LoadPte(pslot);
unassert(entry & PAGE_V);
unassert(entry & PAGE_LOCKS);
} while (!CasPte(pslot, entry, entry - PAGE_LOCK));
}
static bool HasOutdatedPageLocks(struct Machine *m) {
return m->pagelocks.i &&
m->pagelocks.p[m->pagelocks.i - 1].sysdepth > m->sysdepth;
}
void CollectPageLocks(struct Machine *m) {
if (HasOutdatedPageLocks(m)) {
LOCK(&m->system->pagelocks_lock);
do ReleasePageLock(m->pagelocks.p[--m->pagelocks.i].pslot);
while (HasOutdatedPageLocks(m));
unassert(!pthread_cond_broadcast(&m->system->pagelocks_cond));
UNLOCK(&m->system->pagelocks_lock);
}
}
// returns page directory entry associated with virtual address
// @return raw page directory entry contents, or zero w/ errno
// @raise EFAULT if a valid 4096 page didn't exist at address
// @raise ENOMEM if memory couldn't be allocated internally
// @raise EAGAIN if too many locks are held on a page
u64 FindPageTableEntry(struct Machine *m, u64 page) {
u8 *pslot;
i64 table;
u64 entry;
long tlbkey;
unsigned level, index;
if (UNLIKELY(atomic_load_explicit(&m->invalidated, memory_order_acquire))) {
ResetTlb(m);
atomic_store_explicit(&m->invalidated, false, memory_order_relaxed);
}
tlbkey = (page >> 12) & (ARRAYLEN(m->tlb) - 1);
if (LIKELY(m->tlb[tlbkey].page == page &&
((entry = m->tlb[tlbkey].entry) & PAGE_V))) {
STATISTIC(++tlb_hits);
return entry;
}
STATISTIC(++tlb_misses);
unassert(!(page & 4095));
if (!(-0x800000000000 <= (i64)page && (i64)page < 0x800000000000)) {
m->segvcode = SEGV_MAPERR_LINUX;
return (u64)(uintptr_t)efault0();
}
TryAgain:
unassert((entry = m->system->cr3));
level = 39;
do {
table = entry;
index = (page >> level) & 511;
pslot = GetPageAddress(m->system, table, level == 39) + index * 8;
if (!pslot) goto MapError;
entry = LoadPte(pslot);
if (!(entry & PAGE_V)) goto MapError;
if (m->metal) {
entry &= ~(u64)(PAGE_RSRV | PAGE_HOST | PAGE_MAP | PAGE_GROW | PAGE_MUG |
PAGE_FILE);
}
if ((entry & PAGE_PS) && level > 12) {
// huge (1 GiB or 2 MiB) page; "rewrite" the TLB copy of the page table
// entry, to point to the 4 KiB subpage being accessed
// TODO: if partial TLB flushes are implemented in the future, we will
// also need to somehow record the original huge page size in the TLB,
// so we can correctly invalidate all TLB entries for the huge page
u64 submask = ((u64)1 << level) - 4096;
entry &= ~submask;
entry |= page & submask;
break;
}
} while ((level -= 9) >= 12);
if ((entry & PAGE_RSRV) && !(entry = HandlePageFault(m, pslot, entry))) {
return 0;
}
// system calls lock the pages they access
// this prevents race conditions w/ munmap
if (m->insyscall && !m->nofault && !HasPageLock(m, page)) {
if ((entry & PAGE_LOCKS) < PAGE_LOCKS) {
if (CasPte(pslot, entry, entry + PAGE_LOCK)) {
unassert(LoadPte(pslot) & PAGE_LOCKS);
if (RecordPageLock(m, page, pslot)) {
entry += PAGE_LOCK;
} else {
ReleasePageLock(pslot);
m->segvcode = SEGV_MAPERR_LINUX;
return 0;
}
} else {
goto TryAgain;
}
} else {
LOGF("too many threads locked page %#" PRIx64, page);
m->segvcode = SEGV_MAPERR_LINUX;
errno = EAGAIN;
return 0;
}
}
m->tlb[tlbkey].page = page;
m->tlb[tlbkey].entry = entry;
return entry;
MapError:
m->segvcode = SEGV_MAPERR_LINUX;
return (uintptr_t)efault0();
}
u8 *LookupAddress2(struct Machine *m, i64 virt, u64 mask, u64 need) {
u8 *host;
u64 entry;
if (!m->metal || m->mode.omode == XED_MODE_LONG ||
(m->mode.genmode != XED_GEN_MODE_REAL && (m->system->cr0 & CR0_PG))) {
if (!(entry = FindPageTableEntry(m, virt & -4096))) {
return 0;
}
} else if (virt >= 0 && virt <= 0xffffffff &&
(virt & 0xffffffff) + 4095 < kRealSize) {
unassert(m->system->real);
return m->system->real + virt;
} else {
m->segvcode = SEGV_MAPERR_LINUX;
return (u8 *)efault0();
}
if ((entry & mask) != need) {
m->segvcode = SEGV_ACCERR_LINUX;
return (u8 *)efault0();
}
#ifndef DISABLE_JIT
if ((need & PAGE_RW) &&
(entry & (PAGE_U | PAGE_RW | PAGE_XD)) == (PAGE_U | PAGE_RW) &&
!IsJitDisabled(&m->system->jit) && !IsPageInSmcQueue(m, virt)) {
AddPageToSmcQueue(m, virt);
}
#endif
if ((host = GetPageAddress(m->system, entry, false))) {
return host + (virt & 4095);
} else {
m->segvcode = SEGV_MAPERR_LINUX;
return (u8 *)efault0();
}
}
u8 *LookupAddress(struct Machine *m, i64 virt) {
u64 need = 0;
if (Cpl(m) == 3) need = PAGE_U;
return LookupAddress2(m, virt, need, need);
}
flattencalls u8 *GetAddress(struct Machine *m, i64 v) {
if (HasLinearMapping()) return ToHost(v);
return LookupAddress(m, v);
}
/**
* Translates virtual address into pointer.
*
* This function bypasses memory protection, since it's used to display
* memory in the debugger tui. That's useful, for example, if debugging
* programs that specify an eXecute-only program header.
*
* It's recommended that the caller use:
*
* BEGIN_NO_PAGE_FAULTS;
* i64 address = ...;
* u8 *pointer = SpyAddress(m, address);
* END_NO_PAGE_FAULTS;
*
* When calling this function.
*/
u8 *SpyAddress(struct Machine *m, i64 virt) {
return LookupAddress2(m, virt, 0, 0);
}
u8 *ResolveAddress(struct Machine *m, i64 v) {
u8 *r;
if ((r = GetAddress(m, v))) return r;
ThrowSegmentationFault(m, v);
}
bool IsValidMemory(struct Machine *m, i64 virt, i64 size, int prot) {
i64 p, pe;
u64 pte, mask, need;
size += virt & 4095;
virt &= -4096;
unassert(m->mode.omode == XED_MODE_LONG);
unassert(prot && !(prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)));
need = mask = 0;
if (prot & PROT_READ) {
mask |= PAGE_U;
need |= PAGE_U;
}
if (prot & PROT_WRITE) {
mask |= PAGE_RW;
need |= PAGE_RW;
}
if (prot & PROT_EXEC) {
mask |= PAGE_XD;
}
if (ckd_add(&pe, virt, size)) {
eoverflow();
return false;
}
for (p = virt; p < pe; p += 4096) {
if (!(pte = FindPageTableEntry(m, p))) {
return false;
}
if ((pte & mask) != need) {
errno = EFAULT;
return false;
}
}
return true;
}
int VirtualCopy(struct Machine *m, i64 v, char *r, u64 n, bool d) {
u8 *p;
u64 k;
k = 4096 - (v & 4095);
while (n) {
k = MIN(k, n);
if (!(p = LookupAddress(m, v))) return -1;
if (d) {
memcpy(r, p, k);
} else if (!IsRomAddress(m, p)) {
memcpy(p, r, k);
}
n -= k;
r += k;
v += k;
k = 4096;
}
return 0;
}
int CopyFromUser(struct Machine *m, void *dst, i64 src, u64 n) {
return VirtualCopy(m, src, (char *)dst, n, true);
}
int CopyFromUserRead(struct Machine *m, void *dst, i64 addr, u64 n) {
if (CopyFromUser(m, dst, addr, n) == -1) return -1;
SetReadAddr(m, addr, n);
return 0;
}
int CopyToUser(struct Machine *m, i64 dst, void *src, u64 n) {
return VirtualCopy(m, dst, (char *)src, n, false);
}
int CopyToUserWrite(struct Machine *m, i64 addr, void *src, u64 n) {
if (CopyToUser(m, addr, src, n) == -1) return -1;
SetWriteAddr(m, addr, n);
return 0;
}
void CommitStash(struct Machine *m) {
unassert(m->stashaddr);
if (m->opcache->writable) {
CopyToUser(m, m->stashaddr, m->opcache->stash, m->opcache->stashsize);
}
m->stashaddr = 0;
}
u8 *ReserveAddress(struct Machine *m, i64 v, size_t n, bool writable) {
long k;
u64 mask, need;
u8 *res, *p1, *p2;
if (writable) {
SetWriteAddr(m, v, n);
} else {
SetReadAddr(m, v, n);
}
if (HasLinearMapping()) {
return ToHost(v);
}
m->reserving = true;
if (Cpl(m) == 3) {
if (!writable) {
mask = PAGE_U;
need = PAGE_U;
} else {
mask = PAGE_U | PAGE_RW;
need = PAGE_U | PAGE_RW;
}
} else {
mask = 0;
need = 0;
}
if ((v & 4095) + n <= 4096) {
if ((res = LookupAddress2(m, v, mask, need))) {
if (!IsRomAddress(m, res)) return res;
p1 = res;
m->stashaddr = v;
m->opcache->stashsize = n;
m->opcache->writable = writable;
res = m->opcache->stash;
IGNORE_RACES_START();
memcpy(res, p1, n);
IGNORE_RACES_END();
return res;
} else {
ThrowSegmentationFault(m, v);
}
}
STATISTIC(++page_overlaps);
unassert(n <= 4096);
m->stashaddr = v;
m->opcache->stashsize = n;
m->opcache->writable = writable;
res = m->opcache->stash;
k = 4096 - (v & 4095);
if ((p1 = LookupAddress2(m, v, mask, need))) {
if ((p2 = LookupAddress2(m, v + k, mask, need))) {
IGNORE_RACES_START();
memcpy(res, p1, k);
memcpy(res + k, p2, n - k);
IGNORE_RACES_END();
return res;
} else {
ThrowSegmentationFault(m, v + k);
}
} else {
ThrowSegmentationFault(m, v);
}
}
static u8 *AccessRam2(struct Machine *m, i64 v, size_t n, void *p[2], u8 *tmp,
bool copy, bool protect_rom) {
u8 *a, *b;
unsigned k;
unassert(n <= 4096);
if ((v & 4095) + n <= 4096) {
a = ResolveAddress(m, v);
if (!protect_rom || !IsRomAddress(m, a)) return a;
if (copy) memcpy(tmp, a, n);
return tmp;
}
STATISTIC(++page_overlaps);
k = 4096;
k -= v & 4095;
unassert(k <= 4096);
a = ResolveAddress(m, v);
b = ResolveAddress(m, v + k);
if (copy) {
memcpy(tmp, a, k);
memcpy(tmp + k, b, n - k);
}
if (protect_rom) {
if (IsRomAddress(m, a)) a = NULL;
if (IsRomAddress(m, b)) b = NULL;
}
p[0] = a;
p[1] = b;
return tmp;
}
u8 *AccessRam(struct Machine *m, i64 v, size_t n, void *p[2], u8 *tmp, bool d) {
return AccessRam2(m, v, n, p, tmp, d, !d);
}
u8 *Load(struct Machine *m, i64 v, size_t n, u8 *b) {
void *p[2];
SetReadAddr(m, v, n);
return AccessRam(m, v, n, p, b, true);
}
u8 *BeginStore(struct Machine *m, i64 v, size_t n, void *p[2], u8 *b) {
SetWriteAddr(m, v, n);
return AccessRam(m, v, n, p, b, false);
}
u8 *BeginStoreNp(struct Machine *m, i64 v, size_t n, void *p[2], u8 *b) {
if (!v) return NULL;
return BeginStore(m, v, n, p, b);
}
#if 0
u8 *BeginLoadStore(struct Machine *m, i64 v, size_t n, void *p[2], u8 *b) {
SetWriteAddr(m, v, n);
return AccessRam2(m, v, n, p, b, true, true);
}
#endif
void EndStore(struct Machine *m, i64 v, size_t n, void *p[2], u8 *b) {
unsigned k;
unassert(n <= 4096);
if ((v & 4095) + n <= 4096) return;
k = 4096;
k -= v & 4095;
unassert(n > k);
#ifdef DISABLE_ROM
unassert(p[0]);
unassert(p[1]);
memcpy(p[0], b, k);
memcpy(p[1], b + k, n - k);
#else
if (p[0]) memcpy(p[0], b, k);
if (p[1]) memcpy(p[1], b + k, n - k);
#endif
}
void EndStoreNp(struct Machine *m, i64 v, size_t n, void *p[2], u8 *b) {
if (v) EndStore(m, v, n, p, b);
}
void *AddToFreeList(struct Machine *m, void *mem) {
int n;
void *p;
p = m->freelist.p;
n = m->freelist.n + 1;
if ((p = realloc(p, n * sizeof(*m->freelist.p)))) {
STATISTIC(++freelisted);
m->freelist.p = (void **)p;
m->freelist.n = n;
m->freelist.p[n - 1] = mem;
return mem;
} else {
free(mem);
return 0;
}
}
// Returns pointer to memory in guest memory. If the memory overlaps a
// page boundary, then it's copied, and the temporary memory is pushed
// to the free list. Returns NULL w/ EFAULT or ENOMEM on error.
void *Schlep(struct Machine *m, i64 addr, size_t size, u64 mask, u64 need) {
char *copy;
size_t have;
void *res, *page;
if (!size) return 0;
if (!(page = LookupAddress2(m, addr, mask, need))) return 0;
have = 4096 - (addr & 4095);
if (size <= have) {
res = page;
} else {
if (!(copy = (char *)malloc(size))) return 0;
memcpy(copy, page, have);
for (; have < size; have += 4096) {
if (!(page = LookupAddress2(m, addr + have, mask, need))) {
free(copy);
return 0;
}
memcpy(copy + have, page, MIN(4096, size - have));
}
res = AddToFreeList(m, copy);
}
return res;
}
void *SchlepR(struct Machine *m, i64 addr, size_t size) {
SetReadAddr(m, addr, size);
return Schlep(m, addr, size, PAGE_U, PAGE_U);
}
void *SchlepW(struct Machine *m, i64 addr, size_t size) {
SetWriteAddr(m, addr, size);
return Schlep(m, addr, size, PAGE_RW, PAGE_RW);
}
void *SchlepRW(struct Machine *m, i64 addr, size_t size) {
SetReadAddr(m, addr, size);
SetWriteAddr(m, addr, size);
return Schlep(m, addr, size, PAGE_U | PAGE_RW, PAGE_U | PAGE_RW);
}
// Returns pointer to string in guest memory. If the string overlaps a
// page boundary, then it's copied, and the temporary memory is pushed
// to the free list. Returns NULL w/ EFAULT or ENOMEM on error.
char *LoadStr(struct Machine *m, i64 addr) {
size_t have;
char *copy, *page, *p;
have = 4096 - (addr & 4095);
if (!addr) return 0;
if (!(page = (char *)LookupAddress2(m, addr, PAGE_U, PAGE_U))) return 0;
if ((p = (char *)memchr(page, '\0', have))) {
SetReadAddr(m, addr, p - page + 1);
return page;
}
if (!(copy = (char *)malloc(have + 4096))) return 0;
memcpy(copy, page, have);
for (;;) {
if (!(page = (char *)LookupAddress2(m, addr + have, PAGE_U, PAGE_U))) break;
if ((p = (char *)memccpy(copy + have, page, '\0', 4096))) {
SetReadAddr(m, addr, have + (p - (copy + have)) + 1);
return (char *)AddToFreeList(m, copy);
}
have += 4096;
if (!(p = (char *)realloc(copy, have + 4096))) break;
copy = p;
}
free(copy);
return 0;
}
// Copies string from guest memory. The returned memory is pushed to the
// machine free list. NULL w/ ENOMEM is returned if we're out of memory.
char *CopyStr(struct Machine *m, i64 addr) {
char *s;
if (!(s = LoadStr(m, addr))) return 0;
return (char *)AddToFreeList(m, strdup(s));
}
// Returns fully copied NULL-terminated NUL-terminated string list. All
// memory allocated by this routine is pushed to the machine free list.
char **CopyStrList(struct Machine *m, i64 addr) {
int n;
u8 b[8];
char *s;
void *mem;
char **list;
for (list = 0, n = 0;;) {
if ((mem = realloc(list, ++n * sizeof(*list)))) {
list = (char **)mem;
} else {
free(list);
return 0;
}
CopyFromUserRead(m, b, addr + n * 8 - 8, 8);
if (Read64(b)) {
if ((s = CopyStr(m, Read64(b)))) {
list[n - 1] = s;
} else {
free(list);
return 0;
}
} else {
list[n - 1] = 0;
return (char **)AddToFreeList(m, list);
}
}
}
|
a56fd319b978c0094020b444c3f876d89f4cd114
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/ata/pata_palmld.c
|
df2bb7504fc8e073650c271dd147d4d75cbf26a5
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 3,180
|
c
|
pata_palmld.c
|
/*
* drivers/ata/pata_palmld.c
*
* Driver for IDE channel in Palm LifeDrive
*
* Based on research of:
* Alex Osborne <ato@meshy.org>
*
* Rewrite for mainline:
* Marek Vasut <marek.vasut@gmail.com>
*
* Rewritten version based on pata_ixp4xx_cf.c:
* ixp4xx PATA/Compact Flash driver
* Copyright (C) 2006-07 Tower Technologies
* Author: Alessandro Zummo <a.zummo@towertech.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/libata.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <scsi/scsi_host.h>
#include <mach/palmld.h>
#define DRV_NAME "pata_palmld"
static struct gpio palmld_hdd_gpios[] = {
{ GPIO_NR_PALMLD_IDE_PWEN, GPIOF_INIT_HIGH, "HDD Power" },
{ GPIO_NR_PALMLD_IDE_RESET, GPIOF_INIT_LOW, "HDD Reset" },
};
static struct scsi_host_template palmld_sht = {
ATA_PIO_SHT(DRV_NAME),
};
static struct ata_port_operations palmld_port_ops = {
.inherits = &ata_sff_port_ops,
.sff_data_xfer = ata_sff_data_xfer_noirq,
.cable_detect = ata_cable_40wire,
};
static int palmld_pata_probe(struct platform_device *pdev)
{
struct ata_host *host;
struct ata_port *ap;
void __iomem *mem;
int ret;
/* allocate host */
host = ata_host_alloc(&pdev->dev, 1);
if (!host) {
ret = -ENOMEM;
goto err1;
}
/* remap drive's physical memory address */
mem = devm_ioremap(&pdev->dev, PALMLD_IDE_PHYS, 0x1000);
if (!mem) {
ret = -ENOMEM;
goto err1;
}
/* request and activate power GPIO, IRQ GPIO */
ret = gpio_request_array(palmld_hdd_gpios,
ARRAY_SIZE(palmld_hdd_gpios));
if (ret)
goto err1;
/* reset the drive */
gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 0);
msleep(30);
gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 1);
msleep(30);
/* setup the ata port */
ap = host->ports[0];
ap->ops = &palmld_port_ops;
ap->pio_mask = ATA_PIO4;
ap->flags |= ATA_FLAG_PIO_POLLING;
/* memory mapping voodoo */
ap->ioaddr.cmd_addr = mem + 0x10;
ap->ioaddr.altstatus_addr = mem + 0xe;
ap->ioaddr.ctl_addr = mem + 0xe;
/* start the port */
ata_sff_std_ports(&ap->ioaddr);
/* activate host */
ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING,
&palmld_sht);
if (ret)
goto err2;
return ret;
err2:
gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
err1:
return ret;
}
static int palmld_pata_remove(struct platform_device *dev)
{
ata_platform_remove_one(dev);
/* power down the HDD */
gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0);
gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
return 0;
}
static struct platform_driver palmld_pata_platform_driver = {
.driver = {
.name = DRV_NAME,
.owner = THIS_MODULE,
},
.probe = palmld_pata_probe,
.remove = palmld_pata_remove,
};
module_platform_driver(palmld_pata_platform_driver);
MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
MODULE_DESCRIPTION("PalmLD PATA driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRV_NAME);
|
a3a517413eec4d5979ab810c741667aa05fed1e2
|
d7b655c9887f508466dd8080a7836318343db57f
|
/FG_MPI/PIC-static/pic.c
|
44cd205fe17da4df9063db28e91b907c5bc4af00
|
[
"BSD-3-Clause",
"LicenseRef-scancode-stream-benchmark"
] |
permissive
|
ParRes/Kernels
|
7b2cbbeea726674e819025462169b48592d12244
|
f2c1e1e82bd21973884665b0102c90a6758b45c9
|
refs/heads/default
| 2023-08-19T08:35:36.579984
| 2023-08-16T11:57:55
| 2023-08-16T11:59:12
| 13,330,867
| 393
| 110
|
NOASSERTION
| 2023-08-16T11:59:14
| 2013-10-04T18:00:10
|
C
|
UTF-8
|
C
| false
| false
| 40,633
|
c
|
pic.c
|
/*
Copyright (c) 2016, Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*******************************************************************
NAME: PIC
PURPOSE: This program tests the efficiency with which a cloud of
charged particles can be moved through a spatially fixed
collection of charges located at the vertices of a square
equi-spaced grid. It is a proxy for a component of a
particle-in-cell method
USAGE: <progname> <#simulation steps> <grid size> <#particles> \
<horizontal velocity> <vertical velocity> \
<init mode> <init parameters>
The output consists of diagnostics to make sure the
algorithm worked, and of timing statistics.
FUNCTIONS CALLED:
Other than standard C functions, the following functions are used in
this program:
initializeGrid()
initializeGeometric()
initializeSinusoidal()
initializeLinear()
initializePatch()
finishParticlesInitialization()
find_owner()
computeCoulomb()
computeTotalForce()
verifyParticle()
add_particle_to_buffer()
attach_particles()
attach_received_particles()
resize_buffer()
bad_patch()
contain()
wtime()
random_draw()
HISTORY: - Written by Evangelos Georganas, August 2015.
- RvdW: Refactored to make the code PRK conforming, March 2016
**********************************************************************************/
#include <par-res-kern_general.h>
#include <par-res-kern_fg-mpi.h>
#include <random_draw.h>
/* M_PI is not defined in strict C99 */
#ifdef M_PI
#define PRK_M_PI M_PI
#else
#define PRK_M_PI 3.14159265358979323846264338327950288419716939937510
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
#define MASS_INV 1.0
#define Q 1.0
#define epsilon 0.000001
#define DT 1.0
#define MEMORYSLACK 10
#define REL_X 0.5
#define REL_Y 0.5
#define GEOMETRIC 10
#define SINUSOIDAL 11
#define LINEAR 12
#define PATCH 13
#define UNDEFINED 14
typedef struct {
uint64_t left;
uint64_t right;
uint64_t bottom;
uint64_t top;
} bbox_t;
/* Particle data structure */
typedef struct particle_t {
double x; // x coordinate of particle
double y; // y coordinate of particle
double v_x; // component of velocity in x direction
double v_y; // component of velocity in y direction
double q; // charge of the particle
/* The following variables are used only for verification/debug purposes */
double x0; // initial position in x
double y0; // initial position in y
double k;
double m;
double ID; // ID of particle; use double to create homogeneous type
} particle_t;
int bad_patch(bbox_t *patch, bbox_t *patch_contain) {
if (patch->left>=patch->right || patch->bottom>=patch->top) return(1);
if (patch_contain) {
if (patch->left <patch_contain->left || patch->right>=patch_contain->right) return(2);
if (patch->bottom<patch_contain->bottom || patch->top >=patch_contain->top) return(3);
}
return(0);
}
int contain(uint64_t x, uint64_t y, bbox_t patch) {
if (x<patch.left || x>patch.right || y<patch.bottom || y>patch.top) return 0;
return 1;
}
/* Initializes the grid of charges */
double *initializeGrid(bbox_t tile) {
double *grid;
uint64_t x, y, n_columns, n_rows;
int error=0, my_ID;
n_columns = tile.right-tile.left+1;
n_rows = tile.top-tile.bottom+1;
grid = (double*) prk_malloc(n_columns*n_rows*sizeof(double));
if (grid == NULL) {
MPI_Comm_rank(MPI_COMM_WORLD, &my_ID);
printf("ERROR: Process %d could not allocate space for grid\n", my_ID);
error = 1;
}
bail_out(error);
/* So far supporting only initialization with dipoles */
for (y=tile.bottom; y<=tile.top; y++) {
for (x=tile.left; x<=tile.right; x++) {
grid[y-tile.bottom+(x-tile.left)*n_rows] = (x%2 == 0) ? Q : -Q;
}
}
return grid;
}
/* Completes particle distribution */
void finishParticlesInitialization(uint64_t n, particle_t *p) {
double x_coord, y_coord, rel_x, rel_y, cos_theta, cos_phi, r1_sq, r2_sq, base_charge, ID;
uint64_t x, pi, cumulative_count;
MPI_Scan(&n, &cumulative_count, 1, MPI_UINT64_T, MPI_SUM, MPI_COMM_WORLD);
ID = (double) (cumulative_count - n + 1);
int my_ID;
MPI_Comm_rank(MPI_COMM_WORLD, &my_ID);
for (pi=0; pi<n; pi++) {
x_coord = p[pi].x;
y_coord = p[pi].y;
rel_x = fmod(x_coord,1.0);
rel_y = fmod(y_coord,1.0);
x = (uint64_t) x_coord;
r1_sq = rel_y * rel_y + rel_x * rel_x;
r2_sq = rel_y * rel_y + (1.0-rel_x) * (1.0-rel_x);
cos_theta = rel_x/sqrt(r1_sq);
cos_phi = (1.0-rel_x)/sqrt(r2_sq);
base_charge = 1.0 / ((DT*DT) * Q * (cos_theta/r1_sq + cos_phi/r2_sq));
p[pi].v_x = 0.0;
p[pi].v_y = ((double) p[pi].m) / DT;
/* this particle charge assures movement in positive x-direction */
p[pi].q = (x%2 == 0) ? (2*p[pi].k+1)*base_charge : -1.0 * (2*p[pi].k+1)*base_charge ;
p[pi].x0 = x_coord;
p[pi].y0 = y_coord;
p[pi].ID = ID;
ID += 1.0;
}
}
/* Initializes the particles following the geometric distribution as described in the spec */
particle_t *initializeGeometric(uint64_t n_input, uint64_t L, double rho,
bbox_t tile, double k, double m,
uint64_t *n_placed, uint64_t *n_size,
random_draw_t *parm) {
particle_t *particles;
double A;
uint64_t x, y, p, pi, actual_particles, start_index;
/* initialize random number generator */
LCG_init(parm);
/* first determine total number of particles, then allocate and place them */
/* Each cell in the i-th column of cells contains p(i) = A * rho^i particles */
A = n_input * ((1.0-rho) / (1.0-pow(rho, L))) / (double) L;
for (*n_placed=0,x=tile.left; x<tile.right; x++) {
/* at start of each grid column we jump into sequence of random numbers */
start_index = tile.bottom+x*L;
LCG_jump(2*start_index, 0, parm);
for (y=tile.bottom; y<tile.top; y++) {
(*n_placed) += random_draw(A * pow(rho, x), parm);
}
}
/* use some slack in allocating memory to avoid fine-grain memory management */
(*n_size) = ((*n_placed)*(1+MEMORYSLACK))/MEMORYSLACK;
particles = (particle_t*) prk_malloc((*n_size) * sizeof(particle_t));
if (particles == NULL) return(particles);
for (pi=0,x=tile.left; x<tile.right; x++) {
/* at start of each grid column we jump into sequence of random numbers */
start_index = tile.bottom+x*L;
LCG_jump(2*start_index, 0, parm);
for (y=tile.bottom; y<tile.top; y++) {
actual_particles = random_draw(A * pow(rho, x), parm);
for (p=0; p<actual_particles; p++) {
particles[pi].x = x + REL_X;
particles[pi].y = y + REL_Y;
particles[pi].k = k;
particles[pi].m = m;
pi++;
}
}
}
finishParticlesInitialization((*n_placed), particles);
return particles;
}
/* Initialize with a sinusodial particle distribution */
particle_t *initializeSinusoidal(uint64_t n_input, uint64_t L,
bbox_t tile, double k, double m,
uint64_t *n_placed, uint64_t *n_size,
random_draw_t *parm) {
particle_t *particles;
double step;
uint64_t x, y, pi, p, actual_particles, start_index;
/* initialize random number generator */
LCG_init(parm);
step = PRK_M_PI/L;
/* Place number of particles to each cell to form distribution decribed in spec. */
for ((*n_placed)=0,x=tile.left; x<tile.right; x++) {
/* at start of each grid column we jump into sequence of random numbers */
start_index = tile.bottom+x*L;
LCG_jump(2*start_index, 0, parm);
for (y=tile.bottom; y<tile.top; y++) {
(*n_placed) += random_draw(2.0*cos(x*step)*cos(x*step)*n_input/(L*L), parm);
}
}
/* use some slack in allocating memory to avoid fine-grain memory management */
(*n_size) = ((*n_placed)*(1+MEMORYSLACK))/MEMORYSLACK;
particles = (particle_t*) prk_malloc((*n_size) * sizeof(particle_t));
if (particles == NULL) return(particles);
for (pi=0,x=tile.left; x<tile.right; x++) {
/* at start of each grid column we jump into sequence of random numbers */
start_index = tile.bottom+x*L;
LCG_jump(2*start_index, 0, parm);
for (y=tile.bottom; y<tile.top; y++) {
actual_particles = random_draw(2.0*cos(x*step)*cos(x*step)*n_input/(L*L), parm);
for (p=0; p<actual_particles; p++) {
particles[pi].x = x + REL_X;
particles[pi].y = y + REL_Y;
particles[pi].k = k;
particles[pi].m = m;
pi++;
}
}
}
finishParticlesInitialization((*n_placed), particles);
return particles;
}
/* Initialize particles with "linearly-decreasing" distribution */
/* The linear function is f(x) = -alpha * x + beta , x in [0,1]*/
particle_t *initializeLinear(uint64_t n_input, uint64_t L, double alpha, double beta,
bbox_t tile, double k, double m,
uint64_t *n_placed, uint64_t *n_size,
random_draw_t *parm) {
particle_t *particles;
double total_weight, step, current_weight;
uint64_t x, y, p, pi, actual_particles, start_index;
/* initialize random number generator */
LCG_init(parm);
/* First, find sum of all weights in order to normalize the number of particles */
step = 1.0/(L-1);
total_weight = beta*L-alpha*0.5*step*L*(L-1);
/* Loop over columns of cells and assign number of particles proportional linear weight */
for (*n_placed=0,x=tile.left; x<tile.right; x++) {
current_weight = (beta - alpha * step * ((double) x));
start_index = tile.bottom+x*L;
LCG_jump(2*start_index, 0, parm);
for (y=tile.bottom; y<tile.top; y++) {
(*n_placed) += random_draw(n_input*(current_weight/total_weight)/L, parm);
}
}
/* use some slack in allocating memory to avoid fine-grain memory management */
(*n_size) = ((*n_placed)*(1+MEMORYSLACK))/MEMORYSLACK;
particles = (particle_t*) prk_malloc((*n_size) * sizeof(particle_t));
if (particles == NULL) return(particles);
for (pi=0,x=tile.left; x<tile.right; x++) {
current_weight = (beta - alpha * step * ((double) x));
start_index = tile.bottom+x*L;
LCG_jump(2*start_index,0, parm);
for (y=tile.bottom; y<tile.top; y++) {
actual_particles = random_draw(n_input*(current_weight/total_weight)/L, parm);
for (p=0; p<actual_particles; p++) {
particles[pi].x = x + REL_X;
particles[pi].y = y + REL_Y;
particles[pi].k = k;
particles[pi].m = m;
pi++;
}
}
}
finishParticlesInitialization((*n_placed), particles);
return particles;
}
/* Initialize uniformly particles within a "patch" */
particle_t *initializePatch(uint64_t n_input, uint64_t L, bbox_t patch,
bbox_t tile, double k, double m,
uint64_t *n_placed, uint64_t *n_size,
random_draw_t *parm) {
particle_t *particles;
uint64_t x, y, total_cells, pi, p, actual_particles, start_index;
double particles_per_cell;
/* initialize random number generator */
LCG_init(parm);
total_cells = (patch.right - patch.left+1)*(patch.top - patch.bottom+1);
particles_per_cell = (double) n_input/total_cells;
/* Loop over columns of cells and assign number of particles if inside patch */
for (*n_placed=0,x=tile.left; x<tile.right; x++) {
start_index = tile.bottom+x*L;
LCG_jump(2*start_index, 0, parm);
for (y=tile.bottom; y<tile.top; y++) {
if (contain(x,y,patch)) (*n_placed) += random_draw(particles_per_cell, parm);
else (*n_placed) += random_draw(0.0, parm);
}
}
/* use some slack in allocating memory to avoid fine-grain memory management */
(*n_size) = ((*n_placed)*(1+MEMORYSLACK))/MEMORYSLACK;
particles = (particle_t*) prk_malloc((*n_size) * sizeof(particle_t));
if (particles == NULL) return(particles);
for (pi=0,x=tile.left; x<tile.right; x++) {
start_index = tile.bottom+x*L;
LCG_jump(2*start_index,0, parm);
for (y=tile.bottom; y<tile.top; y++) {
actual_particles = random_draw(particles_per_cell, parm);
if (!contain(x,y,patch)) actual_particles = 0;
for (p=0; p<actual_particles; p++) {
particles[pi].x = x + REL_X;
particles[pi].y = y + REL_Y;
particles[pi].k = k;
particles[pi].m = m;
pi++;
}
}
}
finishParticlesInitialization((*n_placed), particles);
return particles;
}
/* introduce function pointer type to be able to switch between search functions */
typedef int (*find_owner_type)(particle_t p, int width, int height, int icrit, int jcrit,
int ileftover, int jleftover, int Num_procsx);
/* Finds the owner of particle (2D decomposition of grid to ranks) */
int find_owner_general(particle_t p, int width, int height, int Num_procsx,
int icrit, int jcrit, int ileftover, int jleftover) {
int IDx, IDy, x, y;
x = (int) floor(p.x);
y = (int) floor(p.y);
if (x<icrit) IDx = x/(width+1);
else IDx = ileftover + (x-icrit)/width;
if (y<jcrit) IDy = y/(height+1);
else IDy = jleftover + (y-jcrit)/height;
int proc_id = IDy * Num_procsx + IDx;
return proc_id;
}
/* Finds the owner of particle (2D decomposition of grid to ranks) */
int find_owner_simple(particle_t p, int width, int height, int Num_procsx,
int icrit, int jcrit, int ileftover, int jleftover) {
int IDx, IDy, x, y;
x = (int) floor(p.x);
y = (int) floor(p.y);
IDx = x/width;
IDy = y/height;
int proc_id = IDy * Num_procsx + IDx;
return proc_id;
}
/* Computes the Coulomb force among two charges q1 and q2 */
int computeCoulomb(double x_dist, double y_dist, double q1, double q2, double *fx, double *fy)
{
double r, r2, f_coulomb;
r2 = x_dist * x_dist + y_dist * y_dist;
r = sqrt(r2);
f_coulomb = q1 * q2 / r2;
(*fx) = f_coulomb * x_dist/r; // f_coulomb * cos_theta
(*fy) = f_coulomb * y_dist/r; // f_coulomb * sin_theta
return 0;
}
/* Computes the total Coulomb force on a particle exerted from the charges of the corresponding cell */
void computeTotalForce(particle_t p, bbox_t tile, double *grid, double *fx, double *fy)
{
uint64_t x, y, n_rows;
double tmp_fx, tmp_fy, rel_y, rel_x, tmp_res_x, tmp_res_y;
n_rows = tile.top-tile.bottom+1;
/* Coordinates of the cell containing the particle */
y = (uint64_t) floor(p.y);
x = (uint64_t) floor(p.x);
rel_x = p.x - x;
rel_y = p.y - y;
x = x - tile.left;
y = y - tile.bottom;
computeCoulomb(rel_x, rel_y, p.q, grid[y+x*n_rows], &tmp_fx, &tmp_fy);
tmp_res_x = tmp_fx;
tmp_res_y = tmp_fy;
/* Coulomb force from bottom-left charge */
computeCoulomb(rel_x, 1.0-rel_y, p.q, grid[(y+1)+x*n_rows], &tmp_fx, &tmp_fy);
tmp_res_x += tmp_fx;
tmp_res_y -= tmp_fy;
/* Coulomb force from top-right charge */
computeCoulomb(1.0-rel_x, rel_y, p.q, grid[y+(x+1)*n_rows], &tmp_fx, &tmp_fy);
tmp_res_x -= tmp_fx;
tmp_res_y += tmp_fy;
/* Coulomb force from bottom-right charge */
computeCoulomb(1.0-rel_x, 1.0-rel_y, p.q, grid[(y+1)+(x+1)*n_rows], &tmp_fx, &tmp_fy);
tmp_res_x -= tmp_fx;
tmp_res_y -= tmp_fy;
(*fx) = tmp_res_x;
(*fy) = tmp_res_y;
}
/* Verifies the final position of a particle */
int verifyParticle(particle_t p, double L, uint64_t iterations)
{
double x_final, y_final, x_periodic, y_periodic;
x_final = p.x0 + (double) (iterations+1) * (2.0*p.k+1);
y_final = p.y0 + (double) (iterations+1) * p.m;
x_periodic = (x_final >= 0.0) ? fmod(x_final, L) : L + fmod(x_final, L);
y_periodic = (y_final >= 0.0) ? fmod(y_final, L) : L + fmod(y_final, L);
if ( fabs(p.x - x_periodic) > epsilon || fabs(p.y - y_periodic) > epsilon) {
return(0);
}
return(1);
}
/* Adds a particle to a buffer. Resizes buffer if need be. */
void add_particle_to_buffer(particle_t p, particle_t **buffer, uint64_t *position, uint64_t *buffer_size)
{
uint64_t cur_pos = (*position);
uint64_t cur_buf_size = (*buffer_size);
particle_t *cur_buffer = (*buffer);
particle_t *temp_buf;
if (cur_pos == cur_buf_size) {
/* Have to resize buffer */
temp_buf = (particle_t*) prk_malloc(2 * cur_buf_size * sizeof(particle_t));
if (!temp_buf) {
printf("Could not increase particle buffer size\n");
/* do not attempt graceful exit; just allow code to abort */
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
memcpy(temp_buf, cur_buffer, cur_buf_size*sizeof(particle_t));
prk_free(cur_buffer);
cur_buffer = temp_buf;
(*buffer) = temp_buf;
(*buffer_size) = cur_buf_size * 2;
}
cur_buffer[cur_pos] = p;
(*position)++;
}
/* Attaches src buffer of particles to destination buffer. Resizes destination buffer if need be. */
void attach_particles(particle_t **dst_buffer, uint64_t *position, uint64_t *buffer_size,
particle_t *src_buffer, uint64_t n_src_particles) {
uint64_t cur_pos = (*position);
uint64_t cur_buf_size = (*buffer_size);
particle_t *cur_buffer = (*dst_buffer);
particle_t *temp_buf;
if ((cur_pos + n_src_particles) > cur_buf_size) {
/* Have to resize buffer */
temp_buf = (particle_t*) prk_malloc(2 *(cur_buf_size + n_src_particles) * sizeof(particle_t));
if (!temp_buf) {
printf("Could not increase particle buffer size\n");
/* do not attempt graceful exit; just allow code to abort */
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
memcpy(temp_buf, cur_buffer, cur_pos*sizeof(particle_t));
prk_free(cur_buffer);
cur_buffer = temp_buf;
(*dst_buffer) = temp_buf;
(*buffer_size) = 2*(cur_buf_size + n_src_particles);
}
memcpy(&cur_buffer[cur_pos], src_buffer, n_src_particles * sizeof(particle_t));
(*position) += n_src_particles;
}
void attach_received_particles(particle_t **dst_buffer, uint64_t *position, uint64_t *buffer_size, particle_t *src_buffer,
uint64_t n_src_particles, particle_t *src_buffer2, uint64_t n_src_particles2)
{
uint64_t cur_pos = (*position);
uint64_t cur_buf_size = (*buffer_size);
particle_t *cur_buffer = (*dst_buffer);
particle_t *temp_buf;
if ((cur_pos + n_src_particles + n_src_particles2 ) > cur_buf_size) {
/* Have to resize buffer */
temp_buf = (particle_t*) prk_malloc((cur_buf_size + 2*(n_src_particles + n_src_particles2)) * sizeof(particle_t));
if (!temp_buf) {
printf("Could not increase particle buffer size\n");
/* do not attempt graceful exit; just allow code to abort */
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
memcpy(temp_buf, cur_buffer, cur_pos*sizeof(particle_t));
prk_free(cur_buffer);
cur_buffer = temp_buf;
(*dst_buffer) = temp_buf;
(*buffer_size) = cur_buf_size + 2*(n_src_particles + n_src_particles2);
}
memcpy(&cur_buffer[cur_pos], src_buffer, n_src_particles * sizeof(particle_t));
(*position) += n_src_particles;
memcpy(&cur_buffer[*position], src_buffer2, n_src_particles2 * sizeof(particle_t));
(*position) += n_src_particles2;
}
/* Resizes a buffer if need be */
void resize_buffer(particle_t **buffer, uint64_t *size, uint64_t new_size)
{
uint64_t cur_size = (*size);
if (new_size > cur_size) {
prk_free(*buffer);
(*buffer) = (particle_t*) prk_malloc(2*new_size*sizeof(particle_t));
if (!(*buffer)) {
printf("Could not increase particle buffer size\n");
/* do not attempt graceful exit; just allow code to abort */
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
(*size) = 2*new_size;
}
}
int main(int argc, char ** argv) {
int Num_procs; // number of ranks
int Num_procsx,
Num_procsy; // number of ranks in each coord direction
int args_used = 1; // keeps track of # consumed arguments
int my_ID; // MPI rank
int my_IDx, my_IDy; // coordinates of rank in rank grid
int root = 0; // master rank
uint64_t L; // dimension of grid in cells
uint64_t iterations ; // total number of simulation steps
uint64_t n; // total number of particles requested in the simulation
uint64_t actual_particles, // actual number of particles owned by my rank
total_particles; // total number of generated particles
char *init_mode; // particle initialization mode (char)
double rho ; // attenuation factor for geometric particle distribution
uint64_t k, m; // determine initial horizontal and vertical velocity of
// particles-- (2*k)+1 cells per time step
double *grid; // the grid is represented as an array of charges
uint64_t iter, i; // dummies
double fx, fy, ax, ay; // particle forces and accelerations
int error=0; // used for graceful exit after error
uint64_t correctness=0; // boolean indicating correct particle displacements
uint64_t istart, jstart, iend, jend, particles_size, particles_count;
bbox_t grid_patch, // whole grid
init_patch, // subset of grid used for localized initialization
my_tile; // subset of grid owner by my rank
particle_t *particles, *p; // array of particles owned by my rank
uint64_t sendbuf_size[8], recvbuf_size[8];
particle_t *sendbuf[8], *recvbuf[8]; // particle communication buffers
uint64_t ptr_my; //
uint64_t owner; // owner (rank) of a particular particle
double pic_time, local_pic_time, avg_time;
uint64_t my_checksum = 0, tot_checksum = 0, correctness_checksum = 0;
uint64_t width, height; // minimum dimensions of grid tile owned by my rank
int particle_mode; // type of initialization
double alpha, beta; // negative slope and offset for linear initialization
int nbr[8]; // topological neighbor ranks
int icrit, jcrit; // global grid indices where tile size drops to minimum
find_owner_type find_owner;
int ileftover, jleftover;// excess grid points divided among "fat" tiles
uint64_t to_send[8], to_recv[8];//
MPI_Request requests[16];
int procsize; // number of ranks per OS process
random_draw_t dice;
/* Initialize the MPI environment */
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_ID);
MPI_Comm_size(MPI_COMM_WORLD, &Num_procs);
/* FIXME: This can be further improved */
/* Create MPI data type for particle_t */
MPI_Datatype PARTICLE;
MPI_Type_contiguous(sizeof(particle_t)/sizeof(double), MPI_DOUBLE, &PARTICLE);
MPI_Type_commit( &PARTICLE );
if (my_ID==root) {
printf("Parallel Research Kernels version %s\n", PRKVERSION);
printf("FG_MPI Particle-in-Cell execution on 2D grid\n");
if (argc<6) {
printf("Usage: %s <#simulation steps> <grid size> <#particles> <k (particle charge semi-increment)> ", argv[0]);
printf("<m (vertical particle velocity)>\n");
printf(" <init mode> <init parameters>]\n");
printf(" init mode \"GEOMETRIC\" parameters: <attenuation factor>\n");
printf(" \"SINUSOIDAL\" parameters: none\n");
printf(" \"LINEAR\" parameters: <negative slope> <constant offset>\n");
printf(" \"PATCH\" parameters: <xleft> <xright> <ybottom> <ytop>\n");
error = 1;
goto ENDOFTESTS;
}
iterations = atol(*++argv); args_used++;
if (iterations<1) {
printf("ERROR: Number of time steps must be positive: %llu\n", iterations);
error = 1;
goto ENDOFTESTS;
}
L = atol(*++argv); args_used++;
if (L<1 || L%2) {
printf("ERROR: Number of grid cells must be positive and even: %llu\n", L);
error = 1;
goto ENDOFTESTS;
}
n = atol(*++argv); args_used++;
if (n<1) {
printf("ERROR: Number of particles must be positive: %llu\n", n);
error = 1;
goto ENDOFTESTS;
}
particle_mode = UNDEFINED;
k = atoi(*++argv); args_used++;
m = atoi(*++argv); args_used++;
init_mode = *++argv; args_used++;
ENDOFTESTS:;
} // done with standard initialization parameters
bail_out(error);
MPI_Bcast(&iterations, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&L, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&n, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&k, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&m, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
grid_patch = (bbox_t){0, L+1, 0, L+1};
if (my_ID==root) { // process initialization parameters
/* Initialize particles with geometric distribution */
if (strcmp(init_mode, "GEOMETRIC") == 0) {
if (argc<args_used+1) {
printf("ERROR: Not enough arguments for GEOMETRIC\n");
error = 1;
goto ENDOFTESTS2;
}
particle_mode = GEOMETRIC;
rho = atof(*++argv); args_used++;
}
/* Initialize with a sinusoidal particle distribution (single period) */
if (strcmp(init_mode, "SINUSOIDAL") == 0) {
particle_mode = SINUSOIDAL;
}
/* Initialize particles with linear distribution */
/* The linear function is f(x) = -alpha * x + beta , x in [0,1]*/
if (strcmp(init_mode, "LINEAR") == 0) {
if (argc<args_used+2) {
printf("ERROR: Not enough arguments for LINEAR initialization\n");
error = 1;
goto ENDOFTESTS2;
exit(EXIT_FAILURE);
}
particle_mode = LINEAR;
alpha = atof(*++argv); args_used++;
beta = atof(*++argv); args_used++;
if (beta <0 || beta<alpha) {
printf("ERROR: linear profile gives negative particle density\n");
error = 1;
goto ENDOFTESTS2;
}
}
/* Initialize particles uniformly within a "patch" */
if (strcmp(init_mode, "PATCH") == 0) {
if (argc<args_used+4) {
printf("ERROR: Not enough arguments for PATCH initialization\n");
error = 1;
goto ENDOFTESTS2;
}
particle_mode = PATCH;
init_patch.left = atoi(*++argv); args_used++;
init_patch.right = atoi(*++argv); args_used++;
init_patch.bottom = atoi(*++argv); args_used++;
init_patch.top = atoi(*++argv); args_used++;
if (bad_patch(&init_patch, &grid_patch)) {
printf("ERROR: inconsistent initial patch\n");
error = 1;
goto ENDOFTESTS2;
}
}
ENDOFTESTS2:;
} //done with processing initializaton parameters, now broadcast
bail_out(error);
MPI_Bcast(&particle_mode, 1, MPI_INT, root, MPI_COMM_WORLD);
switch (particle_mode) {
case GEOMETRIC: MPI_Bcast(&rho, 1, MPI_DOUBLE, root, MPI_COMM_WORLD);
break;
case SINUSOIDAL: break;
case LINEAR: MPI_Bcast(&alpha, 1, MPI_DOUBLE, root, MPI_COMM_WORLD);
MPI_Bcast(&beta, 1, MPI_DOUBLE, root, MPI_COMM_WORLD);
break;
case PATCH: MPI_Bcast(&init_patch.left, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&init_patch.right, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&init_patch.bottom, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
MPI_Bcast(&init_patch.top, 1, MPI_UINT64_T, root, MPI_COMM_WORLD);
break;
}
/* determine best way to create a 2D grid of ranks (closest to square, for
best surface/volume ratio); we do this brute force for now */
for (Num_procsx=(int) (sqrt(Num_procs+1)); Num_procsx>0; Num_procsx--) {
if (!(Num_procs%Num_procsx)) {
Num_procsy = Num_procs/Num_procsx;
break;
}
}
my_IDx = my_ID%Num_procsx;
my_IDy = my_ID/Num_procsx;
if (my_ID == root) {
MPIX_Get_collocated_size(&procsize);
printf("Number of ranks = %d\n", Num_procs);
printf("Number of ranks/process = %d\n", procsize);
printf("Load balancing = None\n");
printf("Grid size = %llu\n", L);
printf("Tiles in x/y-direction = %d/%d\n", Num_procsx, Num_procsy);
printf("Number of particles requested = %llu\n", n);
printf("Number of time steps = %llu\n", iterations);
printf("Initialization mode = %s\n", init_mode);
switch(particle_mode) {
case GEOMETRIC: printf(" Attenuation factor = %lf\n", rho); break;
case SINUSOIDAL: break;
case LINEAR: printf(" Negative slope = %lf\n", alpha);
printf(" Offset = %lf\n", beta); break;
case PATCH: printf(" Bounding box = %llu, %llu, %llu, %llu\n",
init_patch.left, init_patch.right,
init_patch.bottom, init_patch.top); break;
default: printf("ERROR: Unsupported particle initializating mode\n");
error = 1;
}
printf("Particle charge semi-increment (k) = %llu\n", k);
printf("Vertical velocity (m) = %llu\n", m);
}
bail_out(error);
/* The processes collectively create the underlying grid following a 2D block decomposition;
unlike in the stencil code, successive blocks share an overlap vertex */
width = L/Num_procsx;
if (width < 2*k) {
if (my_ID==0) printf("k-value too large: %llu, must be no greater than %llu\n", k, width/2);
bail_out(1);
}
ileftover = L%Num_procsx;
if (my_IDx<ileftover) {
istart = (width+1) * my_IDx;
iend = istart + width + 1;
}
else {
istart = (width+1) * ileftover + width * (my_IDx-ileftover);
iend = istart + width;
}
icrit = (width+1) * ileftover;
height = L/Num_procsy;
if (height < m) {
if (my_ID==0) printf("m-value too large: %llu, must be no greater than %llu\n", m, height);
bail_out(1);
}
jleftover = L%Num_procsy;
if (my_IDy<jleftover) {
jstart = (height+1) * my_IDy;
jend = jstart + height + 1;
}
else {
jstart = (height+1) * jleftover + height * (my_IDy-jleftover);
jend = jstart + height;
}
jcrit = (height+1) * jleftover;
/* if the problem can be divided evenly among ranks, use the simple owner finding function */
if (icrit==0 && jcrit==0) {
find_owner = find_owner_simple;
if (my_ID==root) printf("Rank search mode used = simple\n");
}
else {
find_owner = find_owner_general;
if (my_ID==root) printf("Rank search mode used = general\n");
}
/* define bounding box for tile owned by my rank for convenience */
my_tile = (bbox_t){istart,iend,jstart,jend};
/* Find neighbors. Indexing: left=0, right=1, bottom=2, top=3,
bottom-left=4, bottom-right=5, top-left=6, top-right=7 */
/* These are IDs in the global communicator */
nbr[0] = (my_IDx == 0 ) ? my_ID + Num_procsx - 1 : my_ID - 1;
nbr[1] = (my_IDx == Num_procsx-1) ? my_ID - Num_procsx + 1 : my_ID + 1;
nbr[2] = (my_IDy == Num_procsy-1) ? my_ID + Num_procsx - Num_procs : my_ID + Num_procsx;
nbr[3] = (my_IDy == 0 ) ? my_ID - Num_procsx + Num_procs : my_ID - Num_procsx;
nbr[4] = (my_IDy == Num_procsy-1) ? nbr[0] + Num_procsx - Num_procs : nbr[0] + Num_procsx;
nbr[5] = (my_IDy == Num_procsy-1) ? nbr[1] + Num_procsx - Num_procs : nbr[1] + Num_procsx;
nbr[6] = (my_IDy == 0 ) ? nbr[0] - Num_procsx + Num_procs : nbr[0] - Num_procsx;
nbr[7] = (my_IDy == 0 ) ? nbr[1] - Num_procsx + Num_procs : nbr[1] - Num_procsx;
grid = initializeGrid(my_tile);
LCG_init(&dice);
switch(particle_mode){
case GEOMETRIC:
particles = initializeGeometric(n, L, rho, my_tile, k, m,
&particles_count, &particles_size, &dice);
break;
case LINEAR:
particles = initializeLinear(n, L, alpha, beta, my_tile, k, m,
&particles_count, &particles_size, &dice);
break;
case SINUSOIDAL:
particles = initializeSinusoidal(n, L, my_tile, k, m,
&particles_count, &particles_size, &dice);
break;
case PATCH:
particles = initializePatch(n, L, init_patch, my_tile, k, m,
&particles_count, &particles_size, &dice);
}
if (!particles) {
printf("ERROR: Rank %d could not allocate space for %llu particles\n", my_ID, particles_size);
error=1;
}
bail_out(error);
#if VERBOSE
for (i=0; i<Num_procs; i++) {
MPI_Barrier(MPI_COMM_WORLD);
if (i == my_ID) printf("Rank %d has %llu particles\n", my_ID, particles_count);
}
#endif
if (my_ID==root) {
MPI_Reduce(&particles_count, &total_particles, 1, MPI_UINT64_T, MPI_SUM, root, MPI_COMM_WORLD);
printf("Number of particles placed = %llu\n", total_particles);
}
else {
MPI_Reduce(&particles_count, &total_particles, 1, MPI_UINT64_T, MPI_SUM, root, MPI_COMM_WORLD);
}
/* Allocate space for communication buffers. Adjust appropriately as the simulation proceeds */
error=0;
for (i=0; i<8; i++) {
sendbuf_size[i] = MAX(1,n/(MEMORYSLACK*Num_procs));
recvbuf_size[i] = MAX(1,n/(MEMORYSLACK*Num_procs));
sendbuf[i] = (particle_t*) prk_malloc(sendbuf_size[i] * sizeof(particle_t));
recvbuf[i] = (particle_t*) prk_malloc(recvbuf_size[i] * sizeof(particle_t));
if (!sendbuf[i] || !recvbuf[i]) error++;
}
if (error) printf("Rank %d could not allocate communication buffers\n", my_ID);
bail_out(error);
/* Run the simulation */
for (iter=0; iter<=iterations; iter++) {
/* start timer after a warmup iteration */
if (iter == 1) {
MPI_Barrier(MPI_COMM_WORLD);
local_pic_time = wtime();
}
ptr_my = 0;
for (i=0; i<8; i++) to_send[i]=0;
/* Process own particles */
p = particles;
for (i=0; i < particles_count; i++) {
fx = 0.0;
fy = 0.0;
computeTotalForce(p[i], my_tile, grid, &fx, &fy);
ax = fx * MASS_INV;
ay = fy * MASS_INV;
/* Update particle positions, taking into account periodic boundaries */
p[i].x = fmod(p[i].x + p[i].v_x*DT + 0.5*ax*DT*DT + L, L);
p[i].y = fmod(p[i].y + p[i].v_y*DT + 0.5*ay*DT*DT + L, L);
/* Update velocities */
p[i].v_x += ax * DT;
p[i].v_y += ay * DT;
/* Check if particle stayed in same subdomain or moved to another */
owner = find_owner(p[i], width, height, Num_procsx, icrit, jcrit, ileftover, jleftover);
if (owner==my_ID) {
add_particle_to_buffer(p[i], &p, &ptr_my, &particles_size);
/* Add particle to the appropriate communication buffer */
} else if (owner == nbr[0]) {
add_particle_to_buffer(p[i], &sendbuf[0], &to_send[0], &sendbuf_size[0]);
} else if (owner == nbr[1]) {
add_particle_to_buffer(p[i], &sendbuf[1], &to_send[1], &sendbuf_size[1]);
} else if (owner == nbr[2]) {
add_particle_to_buffer(p[i], &sendbuf[2], &to_send[2], &sendbuf_size[2]);
} else if (owner == nbr[3]) {
add_particle_to_buffer(p[i], &sendbuf[3], &to_send[3], &sendbuf_size[3]);
} else if (owner == nbr[4]) {
add_particle_to_buffer(p[i], &sendbuf[4], &to_send[4], &sendbuf_size[4]);
} else if (owner == nbr[5]) {
add_particle_to_buffer(p[i], &sendbuf[5], &to_send[5], &sendbuf_size[5]);
} else if (owner == nbr[6]) {
add_particle_to_buffer(p[i], &sendbuf[6], &to_send[6], &sendbuf_size[6]);
} else if (owner == nbr[7]) {
add_particle_to_buffer(p[i], &sendbuf[7], &to_send[7], &sendbuf_size[7]);
} else {
printf("Could not find neighbor owner of particle %llu in tile %llu\n",
i, owner);
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
}
/* Communicate the number of particles to be sent/received */
for (i=0; i<8; i++) {
MPI_Isend(&to_send[i], 1, MPI_UINT64_T, nbr[i], 0, MPI_COMM_WORLD, &requests[i]);
MPI_Irecv(&to_recv[i], 1, MPI_UINT64_T, nbr[i], 0, MPI_COMM_WORLD, &requests[8+i]);
}
MPI_Waitall(16, requests, MPI_STATUSES_IGNORE);
/* Resize receive buffers if need be */
for (i=0; i<8; i++) {
resize_buffer(&recvbuf[i], &recvbuf_size[i], to_recv[i]);
}
/* Communicate the particles */
for (i=0; i<8; i++) {
MPI_Isend(sendbuf[i], to_send[i], PARTICLE, nbr[i], 0, MPI_COMM_WORLD, &requests[i]);
MPI_Irecv(recvbuf[i], to_recv[i], PARTICLE, nbr[i], 0, MPI_COMM_WORLD, &requests[8+i]);
}
MPI_Waitall(16, requests, MPI_STATUSES_IGNORE);
/* Attach received particles to particles buffer */
for (i=0; i<4; i++) {
attach_received_particles(&particles, &ptr_my, &particles_size, recvbuf[2*i], to_recv[2*i],
recvbuf[2*i+1], to_recv[2*i+1]);
}
particles_count = ptr_my;
} // end of iterations
local_pic_time = wtime() - local_pic_time;
MPI_Reduce(&local_pic_time, &pic_time, 1, MPI_DOUBLE, MPI_MAX, root,
MPI_COMM_WORLD);
/* Run the verification test */
/* First verify own particles */
for (i=0; i < particles_count; i++) {
correctness += verifyParticle(particles[i], (double)L, iterations);
my_checksum += (uint64_t)particles[i].ID;
}
/* Gather total checksum of particles */
MPI_Reduce(&my_checksum, &tot_checksum, 1, MPI_UINT64_T, MPI_SUM, root, MPI_COMM_WORLD);
/* Gather total checksum of correctness flags */
MPI_Reduce(&correctness, &correctness_checksum, 1, MPI_UINT64_T, MPI_SUM, root, MPI_COMM_WORLD);
if ( my_ID == root) {
if (correctness_checksum != total_particles ) {
printf("ERROR: there are %llu miscalculated locations\n", total_particles-correctness_checksum);
}
else {
if (tot_checksum != (total_particles*(total_particles+1))/2) {
printf("ERROR: Particle checksum incorrect\n");
}
else {
avg_time = total_particles*iterations/pic_time;
printf("Solution validates\n");
printf("Rate (Mparticles_moved/s): %lf\n", 1.0e-6*avg_time);
}
}
}
#if VERBOSE
for (i=0; i<Num_procs; i++) {
MPI_Barrier(MPI_COMM_WORLD);
if (i == my_ID) printf("Rank %d has %llu particles\n", my_ID, particles_count);
}
#endif
MPI_Finalize();
return 0;
}
|
d1436cd9d4eb2470d358c53f33def02b2baa27c2
|
ce99bd11ca505967277f4689c621479c1987698e
|
/src/libultra/io/piacs.c
|
69938b2c010115fd2e4938e1fb7a48c426b3eaf0
|
[] |
no_license
|
n64decomp/007
|
5951258890f15431f273e1503674c5e0402c66e0
|
c46751089ddc18b12ef7a45b6a3e03de2054c422
|
refs/heads/master
| 2022-11-08T23:34:54.021033
| 2022-10-29T14:41:01
| 2022-10-29T14:41:01
| 241,212,109
| 359
| 48
| null | 2020-11-21T23:30:31
| 2020-02-17T21:31:00
|
C
|
UTF-8
|
C
| false
| false
| 607
|
c
|
piacs.c
|
#include <os_internal.h>
#define PI_Q_BUF_LEN 1
u32 __osPiAccessQueueEnabled = 0;
static OSMesg piAccessBuf[PI_Q_BUF_LEN];
OSMesgQueue __osPiAccessQueue;
void __osPiCreateAccessQueue(void)
{
__osPiAccessQueueEnabled = 1;
osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN);
osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK);
}
void __osPiGetAccess(void)
{
OSMesg dummyMesg;
if (!__osPiAccessQueueEnabled)
__osPiCreateAccessQueue();
osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK);
}
void __osPiRelAccess(void)
{
osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK);
}
|
1dfbe9157b715626ad3f47358aa511ae31ba3c54
|
f42190636add23ead6a5022d706a124032d66f92
|
/src/Microsoft.DotNet.Wpf/src/WpfGfx/shared/util/UtilLib/Registry.h
|
06882503b0a102b3f1f3db7b7380e0494cd159d1
|
[
"MIT"
] |
permissive
|
dotnet/wpf
|
b8f73a99e03f87b4dee5db643e38e2c0704f707a
|
2ff355a607d79eef5fea7796de1f29cf9ea4fbed
|
refs/heads/main
| 2023-09-04T09:35:19.355384
| 2023-09-03T02:30:37
| 2023-09-03T02:30:37
| 153,711,945
| 6,927
| 1,397
|
MIT
| 2023-09-14T17:22:06
| 2018-10-19T01:55:23
|
C#
|
UTF-8
|
C
| false
| false
| 969
|
h
|
Registry.h
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//+-----------------------------------------------------------------------
//
//
// Description: Simple registry utilities
//
//------------------------------------------------------------------------
#pragma once
bool RegGetDword(
const HKEY hKey,
const LPCTSTR pszValueName,
__out_ecount(1) LPDWORD pdwValue
);
bool RegGetHKLMDword(
const LPCTSTR pszKeyName,
const LPCTSTR pszValueName,
__out_ecount(1) LPDWORD pdwValue
);
bool RegGetString(
const HKEY hKey,
const LPCTSTR pszValueName,
__out_bcount(cbValue) LPTSTR pszValue,
DWORD cbValue
);
bool RegGetHKLMString(
const LPCTSTR pszKeyName,
const LPCTSTR pszValueName,
__out_bcount(cbValue) LPTSTR pszValue,
DWORD cbValue
);
|
007ffda81f57fdbec08380e17cc22a8146c1dfc2
|
da1500e0d3040497614d5327d2461a22e934b4d8
|
/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_main.c
|
9e4a3ea42adda336f6be89d20d93e32b0e82d06c
|
[
"NCSA",
"MIT",
"LLVM-exception",
"Apache-2.0",
"BSD-3-Clause",
"GPL-1.0-or-later",
"LGPL-2.0-or-later"
] |
permissive
|
youtube/cobalt
|
34085fc93972ebe05b988b15410e99845efd1968
|
acefdaaadd3ef46f10f63d1acae2259e4024d383
|
refs/heads/main
| 2023-09-01T13:09:47.225174
| 2023-09-01T08:54:54
| 2023-09-01T08:54:54
| 50,049,789
| 169
| 80
|
BSD-3-Clause
| 2023-09-14T21:50:50
| 2016-01-20T18:11:34
| null |
UTF-8
|
C
| false
| false
| 765
|
c
|
dispatch_main.c
|
// Check that we don't crash when dispatch_main calls pthread_exit which
// quits the main thread.
// RUN: %clang_tsan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
#include <dispatch/dispatch.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
fprintf(stderr,"Hello world");
dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
dispatch_async(q, ^{
fprintf(stderr,"1");
});
dispatch_async(q, ^{
fprintf(stderr,"2");
});
dispatch_async(q, ^{
fprintf(stderr,"3");
dispatch_async(dispatch_get_main_queue(), ^{
fprintf(stderr,"Done.");
sleep(1);
exit(0);
});
});
dispatch_main();
}
// CHECK: Hello world
// CHECK: 123
// CHECK: Done.
|
68607aebd97b64d97143ae9ca38881be89e79f59
|
f367e4b66a1ee42e85830b31df88f63723c36a47
|
/plugins/filter_geoip2/libmaxminddb/src/data-pool.h
|
25d09923e0cc2c301576037e4ba65548ce42b4fb
|
[
"Apache-2.0"
] |
permissive
|
fluent/fluent-bit
|
06873e441162b92941024e9a7e9e8fc934150bf7
|
1a41f49dc2f3ae31a780caa9ffd6137b1d703065
|
refs/heads/master
| 2023-09-05T13:44:55.347372
| 2023-09-05T10:14:33
| 2023-09-05T10:14:33
| 29,933,948
| 4,907
| 1,565
|
Apache-2.0
| 2023-09-14T10:17:02
| 2015-01-27T20:41:52
|
C
|
UTF-8
|
C
| false
| false
| 1,788
|
h
|
data-pool.h
|
#ifndef DATA_POOL_H
#define DATA_POOL_H
#include "maxminddb.h"
#include <stdbool.h>
#include <stddef.h>
// This should be large enough that we never need to grow the array of pointers
// to blocks. 32 is enough. Even starting out of with size 1 (1 struct), the
// 32nd element alone will provide 2**32 structs as we exponentially increase
// the number in each block. Being confident that we do not have to grow the
// array lets us avoid writing code to do that. That code would be risky as it
// would rarely be hit and likely not be well tested.
#define DATA_POOL_NUM_BLOCKS 32
// A pool of memory for MMDB_entry_data_list_s structs. This is so we can
// allocate multiple up front rather than one at a time for performance
// reasons.
//
// The order you add elements to it (by calling data_pool_alloc()) ends up as
// the order of the list.
//
// The memory only grows. There is no support for releasing an element you take
// back to the pool.
typedef struct MMDB_data_pool_s {
// Index of the current block we're allocating out of.
size_t index;
// The size of the current block, counting by structs.
size_t size;
// How many used in the current block, counting by structs.
size_t used;
// The current block we're allocating out of.
MMDB_entry_data_list_s *block;
// The size of each block.
size_t sizes[DATA_POOL_NUM_BLOCKS];
// An array of pointers to blocks of memory holding space for list
// elements.
MMDB_entry_data_list_s *blocks[DATA_POOL_NUM_BLOCKS];
} MMDB_data_pool_s;
MMDB_data_pool_s *data_pool_new(size_t const);
void data_pool_destroy(MMDB_data_pool_s *const);
MMDB_entry_data_list_s *data_pool_alloc(MMDB_data_pool_s *const);
MMDB_entry_data_list_s *data_pool_to_list(MMDB_data_pool_s *const);
#endif
|
85fb3e72693af5af9efb2cdfa24789746f83f7e8
|
10a8580aa44d33b7458429023c00de8c01ceda98
|
/axiom/tests/test_datastore_instance.c
|
6bc670922fdc75b710e0128ed51c137538b81690
|
[
"BSD-4-Clause-UC",
"Apache-2.0"
] |
permissive
|
newrelic/newrelic-php-agent
|
87ad20e0a5abf0d2855e7d27a25c36454ae4389a
|
dfb359f0dbb53e4cbc5106b52c8f3807c7fc8d42
|
refs/heads/main
| 2023-08-15T10:28:24.372352
| 2023-08-14T17:29:31
| 2023-08-14T17:29:31
| 302,112,572
| 116
| 67
|
Apache-2.0
| 2023-09-13T18:33:47
| 2020-10-07T17:35:01
|
C
|
UTF-8
|
C
| false
| false
| 6,451
|
c
|
test_datastore_instance.c
|
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "nr_axiom.h"
#include <stddef.h>
#include "nr_datastore_instance.h"
#include "util_memory.h"
#include "util_strings.h"
#include "util_system.h"
#include "tlib_main.h"
static void test_is_localhost(void) {
int outcome;
outcome = nr_datastore_instance_is_localhost(NULL);
tlib_pass_if_int_equal("null host", 0, outcome);
outcome = nr_datastore_instance_is_localhost("");
tlib_pass_if_int_equal("empty string", 0, outcome);
outcome = nr_datastore_instance_is_localhost("127.0.0.2");
tlib_pass_if_int_equal("not quite local address", 0, outcome);
outcome = nr_datastore_instance_is_localhost("localhost");
tlib_pass_if_int_equal("local address", 1, outcome);
outcome = nr_datastore_instance_is_localhost("127.0.0.1");
tlib_pass_if_int_equal("local address", 1, outcome);
outcome = nr_datastore_instance_is_localhost("0.0.0.0");
tlib_pass_if_int_equal("local address", 1, outcome);
outcome = nr_datastore_instance_is_localhost("0:0:0:0:0:0:0:1");
tlib_pass_if_int_equal("local address", 1, outcome);
outcome = nr_datastore_instance_is_localhost("::1");
tlib_pass_if_int_equal("local address", 1, outcome);
outcome = nr_datastore_instance_is_localhost("0:0:0:0:0:0:0:0");
tlib_pass_if_int_equal("local address", 1, outcome);
outcome = nr_datastore_instance_is_localhost("::");
tlib_pass_if_int_equal("local address", 1, outcome);
}
static void test_destroy(void) {
nr_datastore_instance_t* instance = NULL;
nr_datastore_instance_t stack
= {.host = NULL, .port_path_or_id = NULL, .database_name = NULL};
/* Don't explode! */
nr_datastore_instance_destroy(NULL);
nr_datastore_instance_destroy(&instance);
nr_datastore_instance_destroy_fields(NULL);
instance = nr_datastore_instance_create("a", "b", "c");
nr_datastore_instance_destroy(&instance);
tlib_pass_if_null("it's dead, Jim", instance);
nr_datastore_instance_destroy_fields(&stack);
stack.host = nr_strdup("host");
stack.port_path_or_id = nr_strdup("port path or id");
stack.database_name = nr_strdup("database name");
nr_datastore_instance_destroy_fields(&stack);
tlib_pass_if_null("host", stack.host);
tlib_pass_if_null("port path or id", stack.port_path_or_id);
tlib_pass_if_null("database name", stack.database_name);
}
static void test_getters(void) {
nr_datastore_instance_t* instance = NULL;
const char* host = NULL;
const char* port_path_or_id = NULL;
const char* database_name = NULL;
char* system_host = NULL;
host = nr_datastore_instance_get_host(NULL);
port_path_or_id = nr_datastore_instance_get_port_path_or_id(NULL);
database_name = nr_datastore_instance_get_database_name(NULL);
tlib_pass_if_null("null host if instance is null", host);
tlib_pass_if_null("null port_path_or_id if instance is null",
port_path_or_id);
tlib_pass_if_null("null database_name if instance is null", database_name);
instance
= nr_datastore_instance_create("bluestar", "1234", "lemon_poppyseed");
host = nr_datastore_instance_get_host(instance);
port_path_or_id = nr_datastore_instance_get_port_path_or_id(instance);
database_name = nr_datastore_instance_get_database_name(instance);
tlib_pass_if_str_equal("host in matches host out", "bluestar", host);
tlib_pass_if_str_equal("port_path_or_id in matches port_path_or_id out",
"1234", port_path_or_id);
tlib_pass_if_str_equal("database_name in matches database_name out",
"lemon_poppyseed", database_name);
nr_datastore_instance_set_host(instance, "localhost");
host = nr_datastore_instance_get_host(instance);
system_host = nr_system_get_hostname();
tlib_pass_if_str_equal("localhost appropriately transformed", system_host,
host);
nr_free(system_host);
nr_datastore_instance_destroy(&instance);
}
static void test_setters(void) {
nr_datastore_instance_t* instance = NULL;
nr_datastore_instance_set_host(NULL, NULL);
nr_datastore_instance_set_port_path_or_id(NULL, NULL);
nr_datastore_instance_set_database_name(NULL, NULL);
tlib_pass_if_null("null instance is unaffected by null input", instance);
instance
= nr_datastore_instance_create("bluestar", "1234", "lemon_poppyseed");
nr_datastore_instance_set_host(instance, NULL);
nr_datastore_instance_set_port_path_or_id(instance, NULL);
nr_datastore_instance_set_database_name(instance, NULL);
tlib_fail_if_null("non-null instance is unaffected by null input", instance);
tlib_pass_if_str_equal("null host results in unknown", "unknown",
instance->host);
tlib_pass_if_str_equal("null port_path_or_id results in unknown", "unknown",
instance->port_path_or_id);
tlib_pass_if_str_equal("null database_name results in unknown", "unknown",
instance->database_name);
nr_datastore_instance_set_host(instance, "");
nr_datastore_instance_set_port_path_or_id(instance, "");
nr_datastore_instance_set_database_name(instance, "");
tlib_fail_if_null("non-null instance is unaffected by empty input", instance);
tlib_pass_if_str_equal("empty host results in unknown", "unknown",
instance->host);
tlib_pass_if_str_equal("empty port_path_or_id results in unknown", "unknown",
instance->port_path_or_id);
tlib_pass_if_str_equal("empty database_name results in unknown", "unknown",
instance->database_name);
nr_datastore_instance_set_host(instance, "voodoo");
nr_datastore_instance_set_port_path_or_id(instance, "4321");
nr_datastore_instance_set_database_name(instance, "chocolate");
tlib_fail_if_null("non-null instance is unaffected by valid input", instance);
tlib_pass_if_str_equal("host in matches host out", "voodoo", instance->host);
tlib_pass_if_str_equal("port_path_or_id in matches host out", "4321",
instance->port_path_or_id);
tlib_pass_if_str_equal("database_name in matches host out", "chocolate",
instance->database_name);
nr_datastore_instance_destroy(&instance);
}
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 2, .state_size = 0};
void test_main(void* p NRUNUSED) {
test_is_localhost();
test_destroy();
test_getters();
test_setters();
}
|
8802f7313bd8af6ee9249b9d40bc6bbe8717a31a
|
83e7dc1281874779c46dfadcc15b2bb66d8e599c
|
/demos/music/assets/img_lv_demo_music_icon_2_large.c
|
05a9ac870d6d3b44379e3ad8cf8ceef78c8a359f
|
[
"MIT"
] |
permissive
|
lvgl/lvgl
|
7d51d6774d6ac71df7101fc7ded56fea4b70be01
|
5c984b4a5364b6455966eb3a860153806c51626f
|
refs/heads/master
| 2023-08-30T22:39:20.283922
| 2023-08-30T19:55:29
| 2023-08-30T19:55:29
| 60,667,730
| 9,296
| 2,218
|
MIT
| 2023-09-14T17:59:34
| 2016-06-08T04:14:34
|
C
|
UTF-8
|
C
| false
| false
| 53,294
|
c
|
img_lv_demo_music_icon_2_large.c
|
#include "../lv_demo_music.h"
#if LV_USE_DEMO_MUSIC && LV_DEMO_MUSIC_LARGE
#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
#ifndef LV_ATTRIBUTE_IMG_IMG_LV_DEMO_MUSIC_ICN_CHAT
#define LV_ATTRIBUTE_IMG_IMG_LV_DEMO_MUSIC_ICN_CHAT
#endif
const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_IMG_LV_DEMO_MUSIC_ICN_CHAT uint8_t
img_lv_demo_music_icon_2_map[] = {
#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8
/*Pixel format: Blue: 2 bit, Green: 3 bit, Red: 3 bit, Alpha 8 bit */
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x18, 0x21, 0x63, 0x21, 0x97, 0x21, 0xbf, 0x21, 0xdc, 0x21, 0xeb, 0x21, 0xe7, 0x21, 0xcc, 0x21, 0xa8, 0x21, 0x7b, 0x21, 0x38, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x37, 0x21, 0xa7, 0x21, 0xfc, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xcc, 0x21, 0x67, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x0b, 0x21, 0x9b, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xdf, 0x21, 0xa3, 0x21, 0x70, 0x21, 0x4c, 0x21, 0x3f, 0x21, 0x43, 0x21, 0x60, 0x21, 0x8c, 0x21, 0xc3, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xd3, 0x21, 0x43, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x30, 0x21, 0xe0, 0x21, 0xff, 0x21, 0xff, 0x21, 0xbb, 0x21, 0x50, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x28, 0x21, 0x8b, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0x7c, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x3c, 0x21, 0xff, 0x21, 0xff, 0x21, 0xf3, 0x21, 0x58, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x23, 0x21, 0xb4, 0x21, 0xff, 0x21, 0xff, 0x21, 0x97, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x27, 0x21, 0xff, 0x21, 0xff, 0x21, 0xd7, 0x21, 0x1c, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x84, 0x21, 0xff, 0x21, 0xff, 0x21, 0x8b, 0x21, 0x00, 0x25, 0x00, 0x25, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xe7, 0x21, 0xff, 0x21, 0xdb, 0x21, 0x08, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x7c, 0x21, 0xff, 0x21, 0xff, 0x21, 0x53, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x98, 0x21, 0xff, 0x21, 0xfb, 0x21, 0x17, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0xa7, 0x21, 0xff, 0x21, 0xfb, 0x21, 0x0b, 0x21, 0x00,
0x21, 0x00, 0x21, 0x23, 0x21, 0xff, 0x21, 0xff, 0x21, 0x58, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xec, 0x21, 0xff, 0x21, 0x94, 0x21, 0x00,
0x21, 0x00, 0x21, 0xa7, 0x21, 0xff, 0x21, 0xcf, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x58, 0x21, 0xff, 0x21, 0xff, 0x21, 0x13,
0x21, 0x0f, 0x21, 0xfc, 0x21, 0xff, 0x21, 0x48, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xe4, 0x21, 0xff, 0x21, 0x70,
0x21, 0x5f, 0x21, 0xff, 0x21, 0xe8, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x84, 0x21, 0xff, 0x21, 0xc3,
0x21, 0x97, 0x21, 0xff, 0x21, 0xa4, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x37, 0x21, 0xff, 0x21, 0xff,
0x21, 0xc0, 0x21, 0xff, 0x21, 0x6f, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x0c, 0x21, 0xff, 0x21, 0xff,
0x21, 0xe0, 0x21, 0xff, 0x21, 0x48, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x25, 0x00, 0x21, 0x5c, 0x21, 0xa3, 0x21, 0x47, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x0b, 0x21, 0x94, 0x21, 0x9c, 0x21, 0x13, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x34, 0x21, 0xa3, 0x21, 0x6c, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xf3, 0x21, 0xff,
0x21, 0xf0, 0x21, 0xff, 0x21, 0x38, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x33, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0x1c, 0x21, 0x00, 0x21, 0x00, 0x21, 0x98, 0x21, 0xff, 0x21, 0xff, 0x21, 0xb7, 0x21, 0x00, 0x21, 0x00, 0x21, 0x10, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0x4f, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xe4, 0x21, 0xff,
0x21, 0xeb, 0x21, 0xff, 0x21, 0x3f, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x34, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0x1f, 0x21, 0x00, 0x21, 0x00, 0x21, 0x9f, 0x21, 0xff, 0x21, 0xff, 0x21, 0xbc, 0x21, 0x00, 0x21, 0x00, 0x21, 0x10, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0x54, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xeb, 0x21, 0xff,
0x21, 0xcc, 0x21, 0xff, 0x21, 0x5f, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x6b, 0x21, 0xaf, 0x21, 0x53, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x0f, 0x21, 0xa4, 0x21, 0xab, 0x21, 0x18, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x40, 0x21, 0xaf, 0x21, 0x7b, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x03, 0x21, 0xfc, 0x21, 0xff,
0x21, 0xa7, 0x21, 0xff, 0x21, 0x90, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x1c, 0x21, 0xff, 0x21, 0xff,
0x21, 0x74, 0x21, 0xff, 0x21, 0xd4, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x58, 0x21, 0xff, 0x21, 0xe7,
0x21, 0x24, 0x21, 0xff, 0x21, 0xff, 0x21, 0x27, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xb4, 0x21, 0xff, 0x21, 0x9f,
0x21, 0x00, 0x21, 0xcf, 0x21, 0xff, 0x21, 0x9c, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x14, 0x21, 0xff, 0x21, 0xff, 0x21, 0x44,
0x21, 0x00, 0x21, 0x50, 0x21, 0xff, 0x21, 0xff, 0x21, 0x24, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0xa8, 0x21, 0xff, 0x21, 0xdf, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0xd8, 0x21, 0xff, 0x21, 0x73, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x25, 0x00, 0x21, 0x44, 0x21, 0xff, 0x21, 0xff, 0x21, 0x48, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0xe4, 0x21, 0xff, 0x21, 0x57, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x1f, 0x21, 0xf8, 0x21, 0xff, 0x21, 0xb4, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x43, 0x21, 0xff, 0x21, 0xfc, 0x21, 0x0b, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x27, 0x21, 0xeb, 0x21, 0xff, 0x21, 0xe7, 0x21, 0x07, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x9b, 0x21, 0xff, 0x21, 0x8c, 0x21, 0x00, 0x21, 0x1b, 0x21, 0x54, 0x21, 0x50, 0x21, 0x04, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x57, 0x21, 0xf8, 0x21, 0xff, 0x21, 0xf0, 0x21, 0x20, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0xe3, 0x21, 0xff, 0x21, 0xaf, 0x21, 0xa8, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xdf, 0x21, 0x63, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x33, 0x21, 0xab, 0x21, 0xff, 0x21, 0xff, 0x21, 0xd8, 0x21, 0x20, 0x21, 0x00, 0x25, 0x00, 0x25, 0x00, 0x25, 0x00,
0x21, 0x00, 0x21, 0xcf, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xe3, 0x21, 0xf0, 0x21, 0xff, 0x21, 0xff, 0x21, 0xdb, 0x21, 0x88, 0x21, 0x3f, 0x21, 0x14, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x0b, 0x21, 0x2b, 0x21, 0x68, 0x21, 0xb8, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0x9f, 0x21, 0x07, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x24, 0x21, 0xbb, 0x21, 0xc7, 0x21, 0x88, 0x21, 0x3c, 0x21, 0x00, 0x21, 0x0f, 0x21, 0x93, 0x21, 0xfb, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xf3, 0x21, 0xe8, 0x21, 0xec, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xbf, 0x21, 0x44, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x1b, 0x21, 0x73, 0x21, 0xbb, 0x21, 0xf4, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xff, 0x21, 0xfc, 0x21, 0xd4, 0x21, 0x8f, 0x21, 0x3c, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00,
#endif
#if LV_COLOR_DEPTH == 16
/*Pixel format: Blue: 5 bit, Green: 6 bit, Red: 5 bit, Alpha 8 bit*/
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x18, 0x66, 0x20, 0x63, 0x66, 0x20, 0x97, 0x66, 0x20, 0xbf, 0x66, 0x20, 0xdc, 0x66, 0x20, 0xeb, 0x66, 0x20, 0xe7, 0x66, 0x20, 0xcc, 0x66, 0x20, 0xa8, 0x66, 0x20, 0x7b, 0x66, 0x20, 0x38, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x37, 0x66, 0x20, 0xa7, 0x66, 0x20, 0xfc, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xcc, 0x66, 0x20, 0x67, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x0b, 0x66, 0x20, 0x9b, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xdf, 0x66, 0x20, 0xa3, 0x66, 0x20, 0x70, 0x66, 0x20, 0x4c, 0x66, 0x20, 0x3f, 0x66, 0x20, 0x43, 0x66, 0x20, 0x60, 0x66, 0x20, 0x8c, 0x66, 0x20, 0xc3, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xd3, 0x66, 0x20, 0x43, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x30, 0x66, 0x20, 0xe0, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xbb, 0x66, 0x20, 0x50, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x28, 0x66, 0x20, 0x8b, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x7c, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x3c, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xf3, 0x66, 0x20, 0x58, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x23, 0x66, 0x20, 0xb4, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x97, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x27, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xd7, 0x66, 0x20, 0x1c, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x84, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x8b, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0xe7, 0x66, 0x20, 0xff, 0x86, 0x20, 0xdb, 0x66, 0x20, 0x08, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x7c, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x53, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x98, 0x66, 0x20, 0xff, 0x66, 0x20, 0xfb, 0x86, 0x20, 0x17, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0xa7, 0x66, 0x20, 0xff, 0x66, 0x20, 0xfb, 0x66, 0x20, 0x0b, 0x66, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0x23, 0x66, 0x20, 0xff, 0x86, 0x20, 0xff, 0x46, 0x20, 0x58, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0xec, 0x66, 0x20, 0xff, 0x86, 0x20, 0x94, 0x86, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0xa7, 0x66, 0x20, 0xff, 0x66, 0x20, 0xcf, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x58, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x86, 0x20, 0x13,
0x66, 0x20, 0x0f, 0x66, 0x20, 0xfc, 0x66, 0x20, 0xff, 0x66, 0x20, 0x48, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0xe4, 0x66, 0x20, 0xff, 0x66, 0x20, 0x70,
0x66, 0x20, 0x5f, 0x66, 0x20, 0xff, 0x66, 0x20, 0xe8, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x84, 0x66, 0x20, 0xff, 0x66, 0x20, 0xc3,
0x66, 0x20, 0x97, 0x66, 0x20, 0xff, 0x66, 0x20, 0xa4, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x37, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff,
0x66, 0x20, 0xc0, 0x66, 0x20, 0xff, 0x66, 0x20, 0x6f, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x0c, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff,
0x66, 0x20, 0xe0, 0x66, 0x20, 0xff, 0x66, 0x20, 0x48, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x5c, 0x66, 0x20, 0xa3, 0x66, 0x20, 0x47, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x0b, 0x66, 0x20, 0x94, 0x66, 0x20, 0x9c, 0x66, 0x20, 0x13, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x34, 0x66, 0x20, 0xa3, 0x66, 0x20, 0x6c, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0xf3, 0x66, 0x20, 0xff,
0x66, 0x20, 0xf0, 0x66, 0x20, 0xff, 0x66, 0x20, 0x38, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x33, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x86, 0x20, 0x1c, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x98, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xb7, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x10, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x4f, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0xe4, 0x66, 0x20, 0xff,
0x66, 0x20, 0xeb, 0x66, 0x20, 0xff, 0x66, 0x20, 0x3f, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x34, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x1f, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x9f, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xbc, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x10, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x54, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0xeb, 0x66, 0x20, 0xff,
0x66, 0x20, 0xcc, 0x66, 0x20, 0xff, 0x66, 0x20, 0x5f, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x6b, 0x66, 0x20, 0xaf, 0x66, 0x20, 0x53, 0x26, 0x20, 0x00, 0x46, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x0f, 0x66, 0x20, 0xa4, 0x86, 0x20, 0xab, 0x46, 0x20, 0x18, 0x26, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x40, 0x66, 0x20, 0xaf, 0x66, 0x20, 0x7b, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x03, 0x66, 0x20, 0xfc, 0x66, 0x20, 0xff,
0x66, 0x20, 0xa7, 0x66, 0x20, 0xff, 0x66, 0x20, 0x90, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x26, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x26, 0x20, 0x00, 0x46, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x1c, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff,
0x86, 0x20, 0x74, 0x66, 0x20, 0xff, 0x66, 0x20, 0xd4, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x26, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x58, 0x66, 0x20, 0xff, 0x66, 0x20, 0xe7,
0x66, 0x20, 0x24, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x27, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x26, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0xb4, 0x86, 0x20, 0xff, 0x66, 0x20, 0x9f,
0x66, 0x20, 0x00, 0x66, 0x20, 0xcf, 0x66, 0x20, 0xff, 0x66, 0x20, 0x9c, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x26, 0x20, 0x00, 0x46, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x26, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x14, 0x66, 0x20, 0xff, 0x86, 0x20, 0xff, 0x66, 0x20, 0x44,
0x66, 0x20, 0x00, 0x66, 0x20, 0x50, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x86, 0x20, 0x24, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x46, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0xa8, 0x66, 0x20, 0xff, 0x66, 0x20, 0xdf, 0x46, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0xd8, 0x66, 0x20, 0xff, 0x66, 0x20, 0x73, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x44, 0x66, 0x20, 0xff, 0x86, 0x20, 0xff, 0x66, 0x20, 0x48, 0x46, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0xe4, 0x66, 0x20, 0xff, 0x66, 0x20, 0x57, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x1f, 0x66, 0x20, 0xf8, 0x66, 0x20, 0xff, 0x66, 0x20, 0xb4, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0x43, 0x66, 0x20, 0xff, 0x66, 0x20, 0xfc, 0x66, 0x20, 0x0b, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x27, 0x66, 0x20, 0xeb, 0x66, 0x20, 0xff, 0x66, 0x20, 0xe7, 0x46, 0x20, 0x07, 0x46, 0x20, 0x00, 0x46, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0x9b, 0x66, 0x20, 0xff, 0x66, 0x20, 0x8c, 0x66, 0x20, 0x00, 0x66, 0x20, 0x1b, 0x66, 0x20, 0x54, 0x66, 0x20, 0x50, 0x66, 0x20, 0x04, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x57, 0x66, 0x20, 0xf8, 0x66, 0x20, 0xff, 0x66, 0x20, 0xf0, 0x66, 0x20, 0x20, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0xe3, 0x66, 0x20, 0xff, 0x66, 0x20, 0xaf, 0x66, 0x20, 0xa8, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xdf, 0x66, 0x20, 0x63, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x33, 0x66, 0x20, 0xab, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xd8, 0x66, 0x20, 0x20, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x66, 0x20, 0x00, 0x66, 0x20, 0xcf, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xe3, 0x66, 0x20, 0xf0, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xdb, 0x66, 0x20, 0x88, 0x66, 0x20, 0x3f, 0x66, 0x20, 0x14, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x0b, 0x66, 0x20, 0x2b, 0x66, 0x20, 0x68, 0x66, 0x20, 0xb8, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0x9f, 0x66, 0x20, 0x07, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x24, 0x66, 0x20, 0xbb, 0x66, 0x20, 0xc7, 0x66, 0x20, 0x88, 0x66, 0x20, 0x3c, 0x66, 0x20, 0x00, 0x66, 0x20, 0x0f, 0x66, 0x20, 0x93, 0x66, 0x20, 0xfb, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xf3, 0x66, 0x20, 0xe8, 0x66, 0x20, 0xec, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xbf, 0x66, 0x20, 0x44, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x1b, 0x66, 0x20, 0x73, 0x66, 0x20, 0xbb, 0x66, 0x20, 0xf4, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xff, 0x66, 0x20, 0xfc, 0x66, 0x20, 0xd4, 0x66, 0x20, 0x8f, 0x66, 0x20, 0x3c, 0x86, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x66, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00, 0x86, 0x20, 0x00,
#endif
#if LV_COLOR_DEPTH == 32
/*Pixel format: Blue: 8 bit, Green: 8 bit, Red: 8 bit, Alpha: 8 bit*/
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x18, 0x32, 0x0e, 0x20, 0x63, 0x32, 0x0e, 0x20, 0x97, 0x32, 0x0e, 0x20, 0xbf, 0x32, 0x0e, 0x20, 0xdc, 0x32, 0x0e, 0x20, 0xeb, 0x32, 0x0e, 0x20, 0xe7, 0x32, 0x0e, 0x20, 0xcc, 0x32, 0x0e, 0x20, 0xa8, 0x32, 0x0e, 0x20, 0x7b, 0x31, 0x0d, 0x20, 0x38, 0x31, 0x0c, 0x20, 0x00, 0x32, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0b, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x37, 0x32, 0x0e, 0x20, 0xa7, 0x32, 0x0e, 0x20, 0xfc, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xcc, 0x32, 0x0e, 0x20, 0x67, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0b, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x0b, 0x32, 0x0e, 0x20, 0x9b, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xdf, 0x32, 0x0e, 0x20, 0xa3, 0x31, 0x0d, 0x20, 0x70, 0x31, 0x0d, 0x20, 0x4c, 0x31, 0x0d, 0x20, 0x3f, 0x31, 0x0d, 0x20, 0x43, 0x31, 0x0e, 0x20, 0x60, 0x31, 0x0e, 0x20, 0x8c, 0x32, 0x0e, 0x20, 0xc3, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0d, 0x20, 0xd3, 0x32, 0x0c, 0x20, 0x43, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x30, 0x32, 0x0e, 0x20, 0xe0, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xbb, 0x31, 0x0e, 0x20, 0x50, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x28, 0x32, 0x0e, 0x20, 0x8b, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0d, 0x20, 0x7c, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x3c, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xf3, 0x31, 0x0d, 0x20, 0x58, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x23, 0x32, 0x0e, 0x20, 0xb4, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x97, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x27, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0d, 0x20, 0xd7, 0x31, 0x0c, 0x20, 0x1c, 0x30, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x84, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x8b, 0x30, 0x10, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xe7, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0f, 0x20, 0xdb, 0x31, 0x0e, 0x20, 0x08, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x7c, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x53, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00,
0x30, 0x0f, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x98, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xfb, 0x30, 0x0f, 0x20, 0x17, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x31, 0x0f, 0x20, 0xa7, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xfb, 0x30, 0x0d, 0x20, 0x0b, 0x30, 0x0c, 0x20, 0x00,
0x32, 0x0d, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x23, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0f, 0x20, 0xff, 0x31, 0x0a, 0x20, 0x58, 0x30, 0x07, 0x20, 0x00, 0x30, 0x09, 0x20, 0x00, 0x30, 0x08, 0x20, 0x00, 0x30, 0x09, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xec, 0x33, 0x0e, 0x20, 0xff, 0x31, 0x0f, 0x20, 0x94, 0x30, 0x10, 0x20, 0x00,
0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xa7, 0x33, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xcf, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x32, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x58, 0x33, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x30, 0x0f, 0x20, 0x13,
0x31, 0x0e, 0x20, 0x0f, 0x32, 0x0e, 0x20, 0xfc, 0x32, 0x0e, 0x20, 0xff, 0x30, 0x0c, 0x20, 0x48, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x32, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x10, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xe4, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x70,
0x31, 0x0e, 0x20, 0x5f, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xe8, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x32, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x10, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x84, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xc3,
0x32, 0x0e, 0x20, 0x97, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0xa4, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x32, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x10, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x37, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff,
0x32, 0x0e, 0x20, 0xc0, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x6f, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x32, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x12, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x10, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x0c, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff,
0x32, 0x0e, 0x20, 0xe0, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x48, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x5c, 0x32, 0x0d, 0x20, 0xa3, 0x31, 0x0d, 0x20, 0x47, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x10, 0x20, 0x0b, 0x32, 0x0d, 0x20, 0x94, 0x32, 0x0d, 0x20, 0x9c, 0x30, 0x0e, 0x20, 0x13, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x34, 0x32, 0x0d, 0x20, 0xa3, 0x31, 0x0d, 0x20, 0x6c, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xf3, 0x32, 0x0e, 0x20, 0xff,
0x32, 0x0e, 0x20, 0xf0, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x38, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x33, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0f, 0x20, 0x1c, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x98, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xb7, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x10, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x4f, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xe4, 0x32, 0x0e, 0x20, 0xff,
0x32, 0x0e, 0x20, 0xeb, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x3f, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x34, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0b, 0x20, 0x1f, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x9f, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xbc, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x10, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x54, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xeb, 0x32, 0x0e, 0x20, 0xff,
0x32, 0x0e, 0x20, 0xcc, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x5f, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x6b, 0x32, 0x0e, 0x20, 0xaf, 0x31, 0x0c, 0x20, 0x53, 0x30, 0x05, 0x20, 0x00, 0x30, 0x09, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x0f, 0x32, 0x0e, 0x20, 0xa4, 0x32, 0x0f, 0x20, 0xab, 0x30, 0x0a, 0x20, 0x18, 0x30, 0x05, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x12, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x40, 0x32, 0x0e, 0x20, 0xaf, 0x32, 0x0d, 0x20, 0x7b, 0x30, 0x08, 0x20, 0x00, 0x2f, 0x07, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x03, 0x32, 0x0e, 0x20, 0xfc, 0x32, 0x0e, 0x20, 0xff,
0x32, 0x0e, 0x20, 0xa7, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0d, 0x20, 0x90, 0x31, 0x0b, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x07, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x06, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x12, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x06, 0x20, 0x00, 0x30, 0x08, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x1c, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff,
0x31, 0x0f, 0x20, 0x74, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xd4, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x07, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x06, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x12, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x08, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x32, 0x0d, 0x20, 0x58, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xe7,
0x30, 0x0e, 0x20, 0x24, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x27, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x07, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x06, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x12, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0f, 0x20, 0xb4, 0x32, 0x0f, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x9f,
0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xcf, 0x33, 0x0e, 0x20, 0xff, 0x31, 0x0e, 0x20, 0x9c, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x30, 0x06, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x30, 0x05, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x30, 0x12, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x14, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0f, 0x20, 0xff, 0x31, 0x0c, 0x20, 0x44,
0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x50, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x30, 0x0f, 0x20, 0x24, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0b, 0x20, 0x00, 0x32, 0x0c, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x0b, 0x20, 0x00, 0x31, 0x0a, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xa8, 0x33, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xdf, 0x30, 0x0a, 0x20, 0x00,
0x30, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xd8, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0x73, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x44, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0f, 0x20, 0xff, 0x31, 0x0b, 0x20, 0x48, 0x30, 0x08, 0x20, 0x00,
0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xe4, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x57, 0x30, 0x0b, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x00, 0x31, 0x0f, 0x20, 0x00, 0x30, 0x10, 0x20, 0x1f, 0x32, 0x0e, 0x20, 0xf8, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0c, 0x20, 0xb4, 0x30, 0x09, 0x20, 0x00, 0x30, 0x09, 0x20, 0x00,
0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x43, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xfc, 0x30, 0x0c, 0x20, 0x0b, 0x30, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x27, 0x32, 0x0e, 0x20, 0xeb, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xe7, 0x30, 0x09, 0x20, 0x07, 0x30, 0x08, 0x20, 0x00, 0x30, 0x09, 0x20, 0x00,
0x30, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0x9b, 0x32, 0x0e, 0x20, 0xff, 0x31, 0x0d, 0x20, 0x8c, 0x30, 0x0c, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x1b, 0x31, 0x0e, 0x20, 0x54, 0x31, 0x0d, 0x20, 0x50, 0x31, 0x0c, 0x20, 0x04, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x57, 0x32, 0x0e, 0x20, 0xf8, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xf0, 0x31, 0x0e, 0x20, 0x20, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x32, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xe3, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xaf, 0x32, 0x0e, 0x20, 0xa8, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xdf, 0x31, 0x0d, 0x20, 0x63, 0x31, 0x0c, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x33, 0x32, 0x0e, 0x20, 0xab, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xd8, 0x32, 0x0d, 0x20, 0x20, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00, 0x30, 0x11, 0x20, 0x00,
0x31, 0x0e, 0x20, 0x00, 0x32, 0x0e, 0x20, 0xcf, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xe3, 0x32, 0x0e, 0x20, 0xf0, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xdb, 0x32, 0x0e, 0x20, 0x88, 0x31, 0x0d, 0x20, 0x3f, 0x31, 0x0e, 0x20, 0x14, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x0b, 0x31, 0x0d, 0x20, 0x2b, 0x31, 0x0d, 0x20, 0x68, 0x32, 0x0e, 0x20, 0xb8, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0x9f, 0x31, 0x0c, 0x20, 0x07, 0x32, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x0f, 0x20, 0x24, 0x32, 0x0e, 0x20, 0xbb, 0x32, 0x0e, 0x20, 0xc7, 0x32, 0x0e, 0x20, 0x88, 0x31, 0x0d, 0x20, 0x3c, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x0f, 0x31, 0x0e, 0x20, 0x93, 0x32, 0x0e, 0x20, 0xfb, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xf3, 0x32, 0x0e, 0x20, 0xe8, 0x32, 0x0e, 0x20, 0xec, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xbf, 0x31, 0x0d, 0x20, 0x44, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x32, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x30, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x1b, 0x31, 0x0e, 0x20, 0x73, 0x32, 0x0e, 0x20, 0xbb, 0x32, 0x0e, 0x20, 0xf4, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xff, 0x32, 0x0e, 0x20, 0xfc, 0x32, 0x0e, 0x20, 0xd4, 0x31, 0x0e, 0x20, 0x8f, 0x31, 0x0e, 0x20, 0x3c, 0x31, 0x0f, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x31, 0x0d, 0x20, 0x00, 0x32, 0x0d, 0x20, 0x00, 0x31, 0x0e, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00, 0x30, 0x10, 0x20, 0x00,
#endif
};
const lv_img_dsc_t img_lv_demo_music_icon_2 = {
.header.always_zero = 0,
.header.w = 31,
.header.h = 31,
.data_size = 961 * LV_COLOR_FORMAT_NATIVE_ALPHA_SIZE,
.header.cf = LV_COLOR_FORMAT_NATIVE_ALPHA,
.data = img_lv_demo_music_icon_2_map,
};
#endif
|
9dd044a42e3ab0ed0086478001c85115202e62eb
|
10a8580aa44d33b7458429023c00de8c01ceda98
|
/axiom/nr_errors.c
|
627cc321037b7881696b1ba71a2f0aa00c745cbb
|
[
"BSD-4-Clause-UC",
"Apache-2.0"
] |
permissive
|
newrelic/newrelic-php-agent
|
87ad20e0a5abf0d2855e7d27a25c36454ae4389a
|
dfb359f0dbb53e4cbc5106b52c8f3807c7fc8d42
|
refs/heads/main
| 2023-08-15T10:28:24.372352
| 2023-08-14T17:29:31
| 2023-08-14T17:29:31
| 302,112,572
| 116
| 67
|
Apache-2.0
| 2023-09-13T18:33:47
| 2020-10-07T17:35:01
|
C
|
UTF-8
|
C
| false
| false
| 4,205
|
c
|
nr_errors.c
|
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "nr_axiom.h"
#include <stddef.h>
#include "nr_errors.h"
#include "nr_errors_private.h"
#include "util_memory.h"
#include "util_object.h"
#include "util_time.h"
nr_error_t* nr_error_create(int priority,
const char* message,
const char* klass,
const char* stacktrace_json,
const char* span_id,
nrtime_t when) {
nr_error_t* error;
if (0 == message) {
return 0;
}
if (0 == klass) {
return 0;
}
if (0 == stacktrace_json) {
return 0;
}
error = (nr_error_t*)nr_zalloc(sizeof(nr_error_t));
error->priority = priority;
error->when = when;
error->message = nr_strdup(message);
error->klass = nr_strdup(klass);
error->stacktrace_json = nr_strdup(stacktrace_json);
if (NULL != span_id) {
error->span_id = nr_strdup(span_id);
}
return error;
}
const char* nr_error_get_message(const nr_error_t* error) {
if (NULL == error) {
return NULL;
}
return error->message;
}
const char* nr_error_get_klass(const nr_error_t* error) {
if (NULL == error) {
return NULL;
}
return error->klass;
}
nrtime_t nr_error_get_time(const nr_error_t* error) {
if (NULL == error) {
return 0;
}
return error->when;
}
int nr_error_priority(const nr_error_t* error) {
if (0 == error) {
return 0;
}
return error->priority;
}
const char* nr_error_get_span_id(const nr_error_t* error) {
if (NULL == error) {
return NULL;
}
return error->span_id;
}
void nr_error_destroy(nr_error_t** error_ptr) {
nr_error_t* error;
if (0 == error_ptr) {
return;
}
error = *error_ptr;
if (0 == error) {
return;
}
nr_free(error->message);
nr_free(error->klass);
nr_free(error->span_id);
nr_free(error->stacktrace_json);
nr_realfree((void**)error_ptr);
}
static nrobj_t* nr_error_params_to_object(const char* stacktrace_json,
const nrobj_t* agent_attributes,
const nrobj_t* user_attributes,
const nrobj_t* intrinsics,
const char* request_uri) {
nrobj_t* hash;
char* json;
hash = nro_new_hash();
nro_set_hash_jstring(hash, "stack_trace", stacktrace_json);
if (agent_attributes) {
json = nro_to_json(agent_attributes);
nro_set_hash_jstring(hash, "agentAttributes", json);
nr_free(json);
}
if (user_attributes) {
json = nro_to_json(user_attributes);
nro_set_hash_jstring(hash, "userAttributes", json);
nr_free(json);
}
if (intrinsics) {
json = nro_to_json(intrinsics);
nro_set_hash_jstring(hash, "intrinsics", json);
nr_free(json);
}
if (request_uri) {
nro_set_hash_string(hash, "request_uri", request_uri);
}
return hash;
}
char* nr_error_to_daemon_json(const nr_error_t* error,
const char* txn_name,
const nrobj_t* agent_attributes,
const nrobj_t* user_attributes,
const nrobj_t* intrinsics,
const char* request_uri) {
nrobj_t* outer;
nrobj_t* params;
char* json;
if (NULL == error) {
return NULL;
}
/*
* Since errors are not aggregated together in the daemon, we create the JSON
* expected by the collector here, and send it to the daemon along with the
* priority (so that the daemon can keep the highest priority errors).
*/
params = nr_error_params_to_object(error->stacktrace_json, agent_attributes,
user_attributes, intrinsics, request_uri);
outer = nro_new_array();
nro_set_array_long(outer, 1, error->when / NR_TIME_DIVISOR_MS);
nro_set_array_string(outer, 2, txn_name);
nro_set_array_string(outer, 3, error->message);
nro_set_array_string(outer, 4, error->klass);
nro_set_array(outer, 5, params);
nro_delete(params);
json = nro_to_json(outer);
nro_delete(outer);
return json;
}
|
8392ba09e7b1cd265ebcc49c1cdb38ee52fd9d1d
|
d2e0fb3fdad7fc2cb70894591d358f40d8db13d2
|
/libc/include/sys/resource.h
|
ba93893b4ff31e342daaed2f81ea6e8f4b9b26b8
|
[
"ISC",
"MIT"
] |
permissive
|
dennis95/dennix
|
54c568485862a0799664033eb0717abb028d3924
|
f898bb2d27346f6257df1650a002ee929e66e7fa
|
refs/heads/master
| 2023-08-17T06:54:17.274650
| 2023-07-10T16:06:35
| 2023-07-10T16:06:35
| 55,073,371
| 168
| 15
| null | null | null | null |
UTF-8
|
C
| false
| false
| 1,810
|
h
|
resource.h
|
/* Copyright (c) 2020 Dennis Wölfing
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* libc/include/sys/resource.h
* Resource operations.
*/
#ifndef _SYS_RESOURCE_H
#define _SYS_RESOURCE_H
#include <sys/cdefs.h>
#define __need_id_t
#define __need_suseconds_t
#define __need_time_t
#include <bits/types.h>
#include <bits/timeval.h>
#include <dennix/resource.h>
#if __USE_DENNIX
# include <dennix/rusagens.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define RLIM_INFINITY __UINTMAX_MAX__
#define RLIM_SAVED_MAX RLIM_INFINITY
#define RLIM_SAVED_CUR RLIM_INFINITY
#define RLIMIT_CORE 0
#define RLIMIT_CPU 1
#define RLIMIT_DATA 2
#define RLIMIT_FSIZE 3
#define RLIMIT_NOFILE 4
#define RLIMIT_STACK 5
#define RLIMIT_AS 6
typedef __UINTMAX_TYPE__ rlim_t;
struct rlimit {
rlim_t rlim_cur;
rlim_t rlim_max;
};
struct rusage {
struct timeval ru_utime;
struct timeval ru_stime;
};
int getrlimit(int, struct rlimit*);
int getrusage(int, struct rusage*);
int setrlimit(int, const struct rlimit*);
#if __USE_DENNIX
int getrusagens(int, struct rusagens*);
#endif
#ifdef __cplusplus
}
#endif
#endif
|
0080d58002f03ea2326d28215b58e6ffcff8bb8c
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/area_kkj/kkj_00/kkj_00_5_npc_ending.c
|
7a6312b2b189c603e865a62c4661b07b4c3541c3
|
[] |
no_license
|
pmret/papermario
|
8b514b19653cef8d6145e47499b3636b8c474a37
|
9774b26d93f1045dd2a67e502b6efc9599fb6c31
|
refs/heads/main
| 2023-08-31T07:09:48.951514
| 2023-08-21T18:07:08
| 2023-08-21T18:07:08
| 287,151,133
| 904
| 139
| null | 2023-09-14T02:44:23
| 2020-08-13T01:22:57
|
C
|
UTF-8
|
C
| false
| false
| 46,788
|
c
|
kkj_00_5_npc_ending.c
|
#include "kkj_00.h"
#include "sprite/player.h"
#include "world/common/npc/Toad_Stationary.inc.c"
#include "world/common/npc/Peach.inc.c"
#include "world/common/npc/Dummy.inc.c"
EvtScript N(EVS_NpcInit_RussT) = {
EVT_CALL(SetNpcPos, NPC_SELF, -300, 0, 295)
EVT_CALL(SetNpcYaw, NPC_SELF, 90)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_ShiverToad_02) = {
EVT_CALL(SetNpcPos, NPC_SELF, -175, 0, -75)
EVT_CALL(SetNpcYaw, NPC_SELF, 90)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Unused) = {
EVT_CALL(SetNpcPos, NPC_SELF, -440, 0, 220)
EVT_CALL(SetNpcYaw, NPC_SELF, 90)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Toadette_03) = {
EVT_CALL(SetNpcPos, NPC_SELF, 295, 0, -15)
EVT_CALL(SetNpcYaw, NPC_SELF, 270)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Toadette_04) = {
EVT_CALL(SetNpcPos, NPC_SELF, 325, 0, -10)
EVT_CALL(SetNpcYaw, NPC_SELF, 270)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_ToadGuard_03) = {
EVT_CALL(SetNpcPos, NPC_SELF, 50, 100, -365)
EVT_CALL(SetNpcYaw, NPC_SELF, 270)
EVT_RETURN
EVT_END
};
AnimID N(ExtraAnims_Peach)[] = {
ANIM_Peach1_Still,
ANIM_Peach1_Idle,
ANIM_Peach2_TalkIdle,
ANIM_Peach2_RaiseArms,
ANIM_Peach2_Talk,
ANIM_Peach2_LowerArms,
ANIM_Peach1_Walk,
ANIM_Peach2_SpreadArms,
ANIM_Peach3_Pray,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Minister)[] = {
ANIM_ToadMinister_Still,
ANIM_ToadMinister_Idle,
ANIM_ToadMinister_Walk,
ANIM_ToadMinister_Talk,
ANIM_LIST_END
};
AnimID N(ExtraAnims_TayceT)[] = {
ANIM_TayceT_Still,
ANIM_TayceT_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_RussT)[] = {
ANIM_RussT_Still,
ANIM_RussT_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_ShiverToad)[] = {
ANIM_ShiverToad_Red_Still,
ANIM_ShiverToad_Red_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Toad)[] = {
ANIM_Toad_Red_Still,
ANIM_Toad_Red_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Toadette)[] = {
ANIM_Toadette_Orange_Still,
ANIM_Toadette_Orange_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_ToadGuard)[] = {
ANIM_ToadGuard_Red_Still,
ANIM_ToadGuard_Red_Idle,
ANIM_ToadGuard_Red_Talk,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Goombario)[] = {
ANIM_WorldGoombario_Still,
ANIM_WorldGoombario_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Kooper)[] = {
ANIM_WorldKooper_Still,
ANIM_WorldKooper_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Bombette)[] = {
ANIM_WorldBombette_Still,
ANIM_WorldBombette_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Parakarry)[] = {
ANIM_WorldParakarry_Still,
ANIM_WorldParakarry_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Bow)[] = {
ANIM_WorldBow_Still,
ANIM_WorldBow_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Watt)[] = {
ANIM_WorldWatt_Still,
ANIM_WorldWatt_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Sushie)[] = {
ANIM_WorldSushie_Still,
ANIM_WorldSushie_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Lakilester)[] = {
ANIM_WorldLakilester_Still,
ANIM_WorldLakilester_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Merlon)[] = {
ANIM_Merlon_Still,
ANIM_Merlon_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Merluvlee)[] = {
ANIM_Merluvlee_Still,
ANIM_Merluvlee_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Merlow)[] = {
ANIM_Merlow_Still,
ANIM_Merlow_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Merlee)[] = {
ANIM_WorldMerlee_Still,
ANIM_WorldMerlee_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Merle)[] = {
ANIM_Merle_Still,
ANIM_Merle_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Lakilulu)[] = {
ANIM_Lakilulu_Still,
ANIM_Lakilulu_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Bootler)[] = {
ANIM_Bootler_Still,
ANIM_Bootler_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Goompa)[] = {
ANIM_Goompa_Still,
ANIM_Goompa_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Goombaria)[] = {
ANIM_Goombaria_Still,
ANIM_Goombaria_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Yoshi)[] = {
ANIM_Yoshi_Green_Still,
ANIM_Yoshi_Green_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Penguin)[] = {
ANIM_Penguin_Still,
ANIM_Penguin_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Dryite)[] = {
ANIM_Dryite_Green_Still,
ANIM_Dryite_Green_Idle,
ANIM_LIST_END
};
AnimID N(ExtraAnims_Ninji)[] = {
ANIM_Ninji_Still,
ANIM_Ninji_Idle,
ANIM_LIST_END
};
NpcData N(NpcData_Peach) = {
.id = NPC_Peach,
.pos = { 0.0f, 100.0f, -440.0f },
.yaw = 270,
.settings = &N(NpcSettings_Peach),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_USE_PLAYER_SPRITE,
.drops = NO_DROPS,
.animations = PEACH_ANIMS,
.extraAnimations = N(ExtraAnims_Peach),
};
NpcData N(NpcData_SpecialToads)[] = {
{
.id = NPC_ToadMinister,
.pos = { 100.0f, 0.0f, 250.0f },
.yaw = 270,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_MINISTER_ANIMS,
.extraAnimations = N(ExtraAnims_Minister),
},
{
.id = NPC_TayceT,
.pos = { -200.0f, 0.0f, 260.0f },
.yaw = 90,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_TayceT_Idle,
},
.extraAnimations = N(ExtraAnims_TayceT),
},
{
.id = NPC_RussT_02,
.pos = { 300.0f, 0.0f, 150.0f },
.yaw = 90,
.init = &N(EVS_NpcInit_RussT),
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_RussT_Idle,
.walk = ANIM_RussT_Idle,
.run = ANIM_RussT_Idle,
.chase = ANIM_RussT_Idle,
.anim_4 = ANIM_RussT_Idle,
.anim_5 = ANIM_RussT_Idle,
.death = ANIM_RussT_Idle,
.hit = ANIM_RussT_Idle,
.anim_8 = ANIM_RussT_Idle,
.anim_9 = ANIM_RussT_Idle,
.anim_A = ANIM_RussT_Idle,
.anim_B = ANIM_RussT_Idle,
.anim_C = ANIM_RussT_Idle,
.anim_D = ANIM_RussT_Idle,
.anim_E = ANIM_RussT_Idle,
.anim_F = ANIM_RussT_Idle,
},
.extraAnimations = N(ExtraAnims_RussT),
},
{
.id = NPC_ShiverToad_02,
.pos = { 330.0f, 0.0f, 135.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_ShiverToad_02),
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_ShiverToad_Green_Idle,
.walk = ANIM_ShiverToad_Green_Walk,
.run = ANIM_ShiverToad_Green_Idle,
.chase = ANIM_ShiverToad_Green_Idle,
.anim_4 = ANIM_ShiverToad_Green_Idle,
.anim_5 = ANIM_ShiverToad_Green_Idle,
.death = ANIM_ShiverToad_Green_Idle,
.hit = ANIM_ShiverToad_Green_Idle,
.anim_8 = ANIM_ShiverToad_Green_Idle,
.anim_9 = ANIM_ShiverToad_Green_Idle,
.anim_A = ANIM_ShiverToad_Green_Idle,
.anim_B = ANIM_ShiverToad_Green_Idle,
.anim_C = ANIM_ShiverToad_Green_Idle,
.anim_D = ANIM_ShiverToad_Green_Idle,
.anim_E = ANIM_ShiverToad_Green_Idle,
.anim_F = ANIM_ShiverToad_Green_Idle,
},
.extraAnimations = N(ExtraAnims_ShiverToad),
},
};
NpcData N(NpcData_Party)[] = {
{
.id = NPC_Goombario,
.pos = { 180.0f, 0.0f, 80.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldGoombario_Idle,
.walk = ANIM_WorldGoombario_Walk,
.run = ANIM_WorldGoombario_Run,
.chase = ANIM_WorldGoombario_Run,
.anim_4 = ANIM_WorldGoombario_Idle,
.anim_5 = ANIM_WorldGoombario_Idle,
.death = ANIM_WorldGoombario_Still,
.hit = ANIM_WorldGoombario_Still,
.anim_8 = ANIM_WorldGoombario_Run,
.anim_9 = ANIM_WorldGoombario_Run,
.anim_A = ANIM_WorldGoombario_Run,
.anim_B = ANIM_WorldGoombario_Run,
.anim_C = ANIM_WorldGoombario_Run,
.anim_D = ANIM_WorldGoombario_Run,
.anim_E = ANIM_WorldGoombario_Run,
.anim_F = ANIM_WorldGoombario_Run,
},
.extraAnimations = N(ExtraAnims_Goombario),
},
{
.id = NPC_Kooper,
.pos = { 225.0f, 0.0f, 225.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldKooper_Idle,
.walk = ANIM_WorldKooper_Walk,
.run = ANIM_WorldKooper_Walk,
.chase = ANIM_WorldKooper_Walk,
.anim_4 = ANIM_WorldKooper_Walk,
.anim_5 = ANIM_WorldKooper_Walk,
.death = ANIM_WorldKooper_Still,
.hit = ANIM_WorldKooper_Still,
.anim_8 = ANIM_WorldKooper_Still,
.anim_9 = ANIM_WorldKooper_Still,
.anim_A = ANIM_WorldKooper_Still,
.anim_B = ANIM_WorldKooper_Still,
.anim_C = ANIM_WorldKooper_Still,
.anim_D = ANIM_WorldKooper_Still,
.anim_E = ANIM_WorldKooper_Still,
.anim_F = ANIM_WorldKooper_Still,
},
.extraAnimations = N(ExtraAnims_Kooper),
},
{
.id = NPC_Bombette,
.pos = { 270.0f, 0.0f, 115.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldBombette_Idle,
.walk = ANIM_WorldBombette_Walk,
.run = ANIM_WorldBombette_Walk,
.chase = ANIM_WorldBombette_Walk,
.anim_4 = ANIM_WorldBombette_Walk,
.anim_5 = ANIM_WorldBombette_Walk,
.death = ANIM_WorldBombette_Still,
.hit = ANIM_WorldBombette_Still,
.anim_8 = ANIM_WorldBombette_Still,
.anim_9 = ANIM_WorldBombette_Still,
.anim_A = ANIM_WorldBombette_Still,
.anim_B = ANIM_WorldBombette_Still,
.anim_C = ANIM_WorldBombette_Still,
.anim_D = ANIM_WorldBombette_Still,
.anim_E = ANIM_WorldBombette_Still,
.anim_F = ANIM_WorldBombette_Still,
},
.extraAnimations = N(ExtraAnims_Bombette),
},
{
.id = NPC_Parakarry,
.pos = { 325.0f, 10.0f, 175.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldParakarry_Idle,
.walk = ANIM_WorldParakarry_Walk,
.run = ANIM_WorldParakarry_Run,
.chase = ANIM_WorldParakarry_Run,
.anim_4 = ANIM_WorldParakarry_Idle,
.anim_5 = ANIM_WorldParakarry_Idle,
.death = ANIM_WorldParakarry_Still,
.hit = ANIM_WorldParakarry_Still,
.anim_8 = ANIM_WorldParakarry_Idle,
.anim_9 = ANIM_WorldParakarry_Idle,
.anim_A = ANIM_WorldParakarry_Idle,
.anim_B = ANIM_WorldParakarry_Idle,
.anim_C = ANIM_WorldParakarry_Idle,
.anim_D = ANIM_WorldParakarry_Idle,
.anim_E = ANIM_WorldParakarry_Idle,
.anim_F = ANIM_WorldParakarry_Idle,
},
.extraAnimations = N(ExtraAnims_Parakarry),
},
{
.id = NPC_Bow,
.pos = { -270.0f, 0.0f, 145.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldBow_Idle,
.walk = ANIM_WorldBow_Walk,
.run = ANIM_WorldBow_Run,
.chase = ANIM_WorldBow_Run,
.anim_4 = ANIM_WorldBow_Idle,
.anim_5 = ANIM_WorldBow_Idle,
.death = ANIM_WorldBow_Still,
.hit = ANIM_WorldBow_Still,
.anim_8 = ANIM_WorldBow_Run,
.anim_9 = ANIM_WorldBow_Run,
.anim_A = ANIM_WorldBow_Run,
.anim_B = ANIM_WorldBow_Run,
.anim_C = ANIM_WorldBow_Run,
.anim_D = ANIM_WorldBow_Run,
.anim_E = ANIM_WorldBow_Run,
.anim_F = ANIM_WorldBow_Run,
},
.extraAnimations = N(ExtraAnims_Bow),
},
{
.id = NPC_Watt,
.pos = { -235.0f, 0.0f, 85.0f },
.yaw = 90,
.initVarCount = 1,
.initVar = { .value = 0 },
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldWatt_Idle,
.walk = ANIM_WorldWatt_Idle,
.run = ANIM_WorldWatt_Idle,
.chase = ANIM_WorldWatt_Idle,
.anim_4 = ANIM_WorldWatt_Idle,
.anim_5 = ANIM_WorldWatt_Idle,
.death = ANIM_WorldWatt_Idle,
.hit = ANIM_WorldWatt_Idle,
.anim_8 = ANIM_WorldWatt_Idle,
.anim_9 = ANIM_WorldWatt_Idle,
.anim_A = ANIM_WorldWatt_Idle,
.anim_B = ANIM_WorldWatt_Idle,
.anim_C = ANIM_WorldWatt_Idle,
.anim_D = ANIM_WorldWatt_Idle,
.anim_E = ANIM_WorldWatt_Idle,
.anim_F = ANIM_WorldWatt_Idle,
},
.extraAnimations = N(ExtraAnims_Watt),
},
{
.id = NPC_Sushie,
.pos = { -190.0f, 0.0f, 50.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldSushie_Idle,
.walk = ANIM_WorldSushie_Idle,
.run = ANIM_WorldSushie_Idle,
.chase = ANIM_WorldSushie_Idle,
.anim_4 = ANIM_WorldSushie_Idle,
.anim_5 = ANIM_WorldSushie_Idle,
.death = ANIM_WorldSushie_Idle,
.hit = ANIM_WorldSushie_Idle,
.anim_8 = ANIM_WorldSushie_Idle,
.anim_9 = ANIM_WorldSushie_Idle,
.anim_A = ANIM_WorldSushie_Idle,
.anim_B = ANIM_WorldSushie_Idle,
.anim_C = ANIM_WorldSushie_Idle,
.anim_D = ANIM_WorldSushie_Idle,
.anim_E = ANIM_WorldSushie_Idle,
.anim_F = ANIM_WorldSushie_Idle,
},
.extraAnimations = N(ExtraAnims_Sushie),
},
{
.id = NPC_Lakilester,
.pos = { -320.0f, 0.0f, -60.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldLakilester_Idle,
.walk = ANIM_WorldLakilester_Idle,
.run = ANIM_WorldLakilester_Idle,
.chase = ANIM_WorldLakilester_Idle,
.anim_4 = ANIM_WorldLakilester_Idle,
.anim_5 = ANIM_WorldLakilester_Idle,
.death = ANIM_WorldLakilester_Idle,
.hit = ANIM_WorldLakilester_Idle,
.anim_8 = ANIM_WorldLakilester_Idle,
.anim_9 = ANIM_WorldLakilester_Idle,
.anim_A = ANIM_WorldLakilester_Idle,
.anim_B = ANIM_WorldLakilester_Idle,
.anim_C = ANIM_WorldLakilester_Idle,
.anim_D = ANIM_WorldLakilester_Idle,
.anim_E = ANIM_WorldLakilester_Idle,
.anim_F = ANIM_WorldLakilester_Idle,
},
.extraAnimations = N(ExtraAnims_Lakilester),
},
};
NpcData N(NpcData_Wizards)[] = {
{
.id = NPC_Merlon,
.pos = { -145.0f, 0.0f, 415.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Merlon_Idle,
},
.extraAnimations = N(ExtraAnims_Merlon),
},
{
.id = NPC_Merluvlee,
.pos = { -225.0f, 0.0f, 380.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Merluvlee_Idle,
},
.extraAnimations = N(ExtraAnims_Merluvlee),
},
{
.id = NPC_Merlow,
.pos = { -175.0f, 0.0f, 330.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Merlow_Idle,
},
.extraAnimations = N(ExtraAnims_Merlow),
},
{
.id = NPC_Merlee,
.pos = { -250.0f, 0.0f, 350.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_WorldMerlee_Idle,
.walk = ANIM_WorldMerlee_Walk,
.run = ANIM_WorldMerlee_Run,
.chase = ANIM_WorldMerlee_Run,
.anim_4 = ANIM_WorldMerlee_Idle,
.anim_5 = ANIM_WorldMerlee_Idle,
.death = ANIM_WorldMerlee_Idle,
.hit = ANIM_WorldMerlee_Idle,
.anim_8 = ANIM_WorldMerlee_Idle,
.anim_9 = ANIM_WorldMerlee_Idle,
.anim_A = ANIM_WorldMerlee_Idle,
.anim_B = ANIM_WorldMerlee_Idle,
.anim_C = ANIM_WorldMerlee_Idle,
.anim_D = ANIM_WorldMerlee_Idle,
.anim_E = ANIM_WorldMerlee_Idle,
.anim_F = ANIM_WorldMerlee_Idle,
},
.extraAnimations = N(ExtraAnims_Merlee),
},
{
.id = NPC_Merle,
.pos = { -220.0f, 0.0f, 450.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Merle_Idle,
.walk = ANIM_Merle_Idle,
.run = ANIM_Merle_Idle,
.chase = ANIM_Merle_Idle,
.anim_4 = ANIM_Merle_Idle,
.anim_5 = ANIM_Merle_Idle,
.death = ANIM_Merle_Idle,
.hit = ANIM_Merle_Idle,
.anim_8 = ANIM_Merle_Idle,
.anim_9 = ANIM_Merle_Idle,
.anim_A = ANIM_Merle_Idle,
.anim_B = ANIM_Merle_Idle,
.anim_C = ANIM_Merle_Idle,
.anim_D = ANIM_Merle_Idle,
.anim_E = ANIM_Merle_Idle,
.anim_F = ANIM_Merle_Idle,
},
.extraAnimations = N(ExtraAnims_Merle),
},
};
NpcData N(NpcData_PartyFamily)[] = {
{
.id = NPC_Lakilulu,
.pos = { -365.0f, 0.0f, -60.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Lakilulu_Idle,
.walk = ANIM_Lakilulu_Idle,
.run = ANIM_Lakilulu_Idle,
.chase = ANIM_Lakilulu_Idle,
.anim_4 = ANIM_Lakilulu_Idle,
.anim_5 = ANIM_Lakilulu_Idle,
.death = ANIM_Lakilulu_Idle,
.hit = ANIM_Lakilulu_Idle,
.anim_8 = ANIM_Lakilulu_Idle,
.anim_9 = ANIM_Lakilulu_Idle,
.anim_A = ANIM_Lakilulu_Idle,
.anim_B = ANIM_Lakilulu_Idle,
.anim_C = ANIM_Lakilulu_Idle,
.anim_D = ANIM_Lakilulu_Idle,
.anim_E = ANIM_Lakilulu_Idle,
.anim_F = ANIM_Lakilulu_Idle,
},
.extraAnimations = N(ExtraAnims_Lakilulu),
},
{
.id = NPC_Bootler,
.pos = { -340.0f, 0.0f, 100.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Bootler_Idle,
.walk = ANIM_Bootler_Walk,
.run = ANIM_Bootler_Run,
.chase = ANIM_Bootler_Run,
.anim_4 = ANIM_Bootler_Idle,
.anim_5 = ANIM_Bootler_Idle,
.death = ANIM_Bootler_Still,
.hit = ANIM_Bootler_Still,
.anim_8 = ANIM_Bootler_Shock,
.anim_9 = ANIM_Bootler_Panic,
.anim_A = ANIM_Bootler_Dejected,
.anim_B = ANIM_Bootler_Quaver,
.anim_C = ANIM_Bootler_Shock,
.anim_D = ANIM_Bootler_Panic,
.anim_E = ANIM_Bootler_Dejected,
.anim_F = ANIM_Bootler_Quaver,
},
.extraAnimations = N(ExtraAnims_Bootler),
},
{
.id = NPC_Goompa,
.pos = { 170.0f, 0.0f, 0.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Goompa_Idle,
.walk = ANIM_Goompa_Walk,
.run = ANIM_Goompa_Run,
.chase = ANIM_Goompa_Run,
.anim_4 = ANIM_Goompa_Idle,
.anim_5 = ANIM_Goompa_Idle,
.death = ANIM_Goompa_Still,
.hit = ANIM_Goompa_Still,
.anim_8 = ANIM_Goompa_Run,
.anim_9 = ANIM_Goompa_Run,
.anim_A = ANIM_Goompa_Run,
.anim_B = ANIM_Goompa_Run,
.anim_C = ANIM_Goompa_Run,
.anim_D = ANIM_Goompa_Run,
.anim_E = ANIM_Goompa_Run,
.anim_F = ANIM_Goompa_Run,
},
.extraAnimations = N(ExtraAnims_Goompa),
},
{
.id = NPC_Goombaria,
.pos = { 140.0f, 0.0f, 50.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Goombaria_Idle,
.walk = ANIM_Goombaria_Walk,
.run = ANIM_Goombaria_Run,
.chase = ANIM_Goombaria_Run,
.anim_4 = ANIM_Goombaria_Idle,
.anim_5 = ANIM_Goombaria_Idle,
.death = ANIM_Goombaria_Still,
.hit = ANIM_Goombaria_Still,
.anim_8 = ANIM_Goombaria_Run,
.anim_9 = ANIM_Goombaria_Run,
.anim_A = ANIM_Goombaria_Run,
.anim_B = ANIM_Goombaria_Run,
.anim_C = ANIM_Goombaria_Run,
.anim_D = ANIM_Goombaria_Run,
.anim_E = ANIM_Goombaria_Run,
.anim_F = ANIM_Goombaria_Run,
},
.extraAnimations = N(ExtraAnims_Goombaria),
},
};
NpcData N(NpcData_Visitors)[] = {
{
.id = NPC_Yoshi,
.pos = { -340.0f, 0.0f, 310.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Yoshi_Blue_Idle,
.walk = ANIM_Yoshi_Blue_Walk,
.run = ANIM_Yoshi_Blue_Idle,
.chase = ANIM_Yoshi_Blue_Idle,
.anim_4 = ANIM_Yoshi_Blue_Idle,
.anim_5 = ANIM_Yoshi_Blue_Idle,
.death = ANIM_Yoshi_Blue_Idle,
.hit = ANIM_Yoshi_Blue_Idle,
.anim_8 = ANIM_Yoshi_Blue_Idle,
.anim_9 = ANIM_Yoshi_Blue_Idle,
.anim_A = ANIM_Yoshi_Blue_Idle,
.anim_B = ANIM_Yoshi_Blue_Idle,
.anim_C = ANIM_Yoshi_Blue_Idle,
.anim_D = ANIM_Yoshi_Blue_Idle,
.anim_E = ANIM_Yoshi_Blue_Idle,
.anim_F = ANIM_Yoshi_Blue_Idle,
},
.extraAnimations = N(ExtraAnims_Yoshi),
},
{
.id = NPC_Penguin_02,
.pos = { 225.0f, 0.0f, -80.0f },
.yaw = 270,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Penguin_Idle,
.walk = ANIM_Penguin_Walk,
.run = ANIM_Penguin_Run,
.chase = ANIM_Penguin_Run,
.anim_4 = ANIM_Penguin_Idle,
.anim_5 = ANIM_Penguin_Idle,
.death = ANIM_Penguin_Idle,
.hit = ANIM_Penguin_Idle,
.anim_8 = ANIM_Penguin_Idle,
.anim_9 = ANIM_Penguin_Idle,
.anim_A = ANIM_Penguin_Idle,
.anim_B = ANIM_Penguin_Idle,
.anim_C = ANIM_Penguin_Idle,
.anim_D = ANIM_Penguin_Idle,
.anim_E = ANIM_Penguin_Idle,
.anim_F = ANIM_Penguin_Idle,
},
.extraAnimations = N(ExtraAnims_Penguin),
},
{
.id = NPC_Penguin_03,
.pos = { -250.0f, 0.0f, -150.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Penguin_Idle,
.walk = ANIM_Penguin_Walk,
.run = ANIM_Penguin_Run,
.chase = ANIM_Penguin_Run,
.anim_4 = ANIM_Penguin_Idle,
.anim_5 = ANIM_Penguin_Idle,
.death = ANIM_Penguin_Idle,
.hit = ANIM_Penguin_Idle,
.anim_8 = ANIM_Penguin_Idle,
.anim_9 = ANIM_Penguin_Idle,
.anim_A = ANIM_Penguin_Idle,
.anim_B = ANIM_Penguin_Idle,
.anim_C = ANIM_Penguin_Idle,
.anim_D = ANIM_Penguin_Idle,
.anim_E = ANIM_Penguin_Idle,
.anim_F = ANIM_Penguin_Idle,
},
.extraAnimations = N(ExtraAnims_Penguin),
},
{
.id = NPC_Dryite,
.pos = { -320.0f, 0.0f, 245.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Dryite_Yellow_Idle,
.walk = ANIM_Dryite_Yellow_Walk,
.run = ANIM_Dryite_Yellow_Run,
.chase = ANIM_Dryite_Yellow_Run,
.anim_4 = ANIM_Dryite_Yellow_Idle,
.anim_5 = ANIM_Dryite_Yellow_Idle,
.death = ANIM_Dryite_Yellow_Still,
.hit = ANIM_Dryite_Yellow_Still,
.anim_8 = ANIM_Dryite_Yellow_Idle,
.anim_9 = ANIM_Dryite_Yellow_Idle,
.anim_A = ANIM_Dryite_Yellow_Idle,
.anim_B = ANIM_Dryite_Yellow_Idle,
.anim_C = ANIM_Dryite_Yellow_Idle,
.anim_D = ANIM_Dryite_Yellow_Idle,
.anim_E = ANIM_Dryite_Yellow_Idle,
.anim_F = ANIM_Dryite_Yellow_Idle,
},
.extraAnimations = N(ExtraAnims_Dryite),
},
{
.id = NPC_Ninji,
.pos = { -395.0f, 68.0f, 50.0f },
.yaw = 90,
.settings = &N(NpcSettings_Dummy),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = {
.idle = ANIM_Ninji_Idle,
.walk = ANIM_Ninji_Walk,
.run = ANIM_Ninji_Idle,
.chase = ANIM_Ninji_Idle,
.anim_4 = ANIM_Ninji_Idle,
.anim_5 = ANIM_Ninji_Idle,
.death = ANIM_Ninji_Idle,
.hit = ANIM_Ninji_Idle,
.anim_8 = ANIM_Ninji_Idle,
.anim_9 = ANIM_Ninji_Idle,
.anim_A = ANIM_Ninji_Idle,
.anim_B = ANIM_Ninji_Idle,
.anim_C = ANIM_Ninji_Idle,
.anim_D = ANIM_Ninji_Idle,
.anim_E = ANIM_Ninji_Idle,
.anim_F = ANIM_Ninji_Idle,
},
.extraAnimations = N(ExtraAnims_Ninji),
},
};
NpcData N(NpcData_Toads)[] = {
{
.id = NPC_Toad_04,
.pos = { 200.0f, 0.0f, 420.0f },
.yaw = 270,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_RED_ANIMS,
.extraAnimations = N(ExtraAnims_Toad),
},
{
.id = NPC_Toad_05,
.pos = { -120.0f, 0.0f, 205.0f },
.yaw = 90,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_YELLOW_ANIMS,
.extraAnimations = N(ExtraAnims_Toad),
},
{
.id = NPC_Toad_06,
.pos = { -440.0f, 0.0f, 220.0f },
.yaw = 90,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_GREEN_ANIMS,
.extraAnimations = N(ExtraAnims_Toad),
},
{
.id = NPC_Toad_07,
.pos = { 285.0f, 0.0f, 290.0f },
.yaw = 270,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_BLUE_ANIMS,
.extraAnimations = N(ExtraAnims_Toad),
},
};
NpcData N(NpcData_Toadettes)[] = {
{
.id = NPC_Toadette_03,
.pos = { -300.0f, 0.0f, 100.0f },
.yaw = 90,
.init = &N(EVS_NpcInit_Toadette_03),
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOADETTE_PINK_ANIMS,
.extraAnimations = N(ExtraAnims_Toadette),
},
{
.id = NPC_Toadette_04,
.pos = { -270.0f, 0.0f, 85.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_Toadette_04),
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOADETTE_GREEN_ANIMS,
.extraAnimations = N(ExtraAnims_Toadette),
},
{
.id = NPC_Toadette_05,
.pos = { -190.0f, 0.0f, 160.0f },
.yaw = 90,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOADETTE_ORANGE_ANIMS,
.extraAnimations = N(ExtraAnims_Toadette),
},
{
.id = NPC_Toadette_06,
.pos = { 190.0f, 0.0f, 300.0f },
.yaw = 270,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOADETTE_PURPLE_ANIMS,
.extraAnimations = N(ExtraAnims_Toadette),
},
};
NpcData N(NpcData_ToadGuards)[] = {
{
.id = NPC_ToadGuard_03,
.pos = { 100.0f, 0.0f, 150.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_ToadGuard_03),
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_GUARD_RED_ANIMS,
.extraAnimations = N(ExtraAnims_ToadGuard),
},
{
.id = NPC_ToadGuard_04,
.pos = { -50.0f, 100.0f, -365.0f },
.yaw = 270,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_GUARD_BLUE_ANIMS,
.extraAnimations = N(ExtraAnims_ToadGuard),
},
{
.id = NPC_ToadGuard_05,
.pos = { 225.0f, 0.0f, 125.0f },
.yaw = 270,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_GUARD_RED_ANIMS,
.extraAnimations = N(ExtraAnims_ToadGuard),
},
{
.id = NPC_ToadGuard_06,
.pos = { -392.0f, 40.0f, -230.0f },
.yaw = 90,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_GUARD_GREEN_ANIMS,
.extraAnimations = N(ExtraAnims_ToadGuard),
},
{
.id = NPC_ToadGuard_07,
.pos = { -392.0f, 40.0f, -230.0f },
.yaw = 90,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_4 | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_PLAYER_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_SHADOW_RAYCAST | ENEMY_FLAG_IGNORE_TOUCH | ENEMY_FLAG_IGNORE_JUMP | ENEMY_FLAG_IGNORE_HAMMER | ENEMY_FLAG_CANT_INTERACT | ENEMY_FLAG_IGNORE_PARTNER | ENEMY_FLAG_IGNORE_SPIN,
.drops = NO_DROPS,
.animations = TOAD_GUARD_YELLOW_ANIMS,
.extraAnimations = N(ExtraAnims_ToadGuard),
},
};
NpcGroupList N(EndingNPCs) = {
NPC_GROUP(N(NpcData_Peach)),
NPC_GROUP(N(NpcData_SpecialToads)),
NPC_GROUP(N(NpcData_Party)),
NPC_GROUP(N(NpcData_Wizards)),
NPC_GROUP(N(NpcData_PartyFamily)),
NPC_GROUP(N(NpcData_Visitors)),
NPC_GROUP(N(NpcData_Toads)),
NPC_GROUP(N(NpcData_Toadettes)),
NPC_GROUP(N(NpcData_ToadGuards)),
{}
};
|
3cacbe1eebfa4e0fb330e31864921f3783b76f04
|
50e95229b9a1161ac294137120aaba94c9eb06bc
|
/sources/ippcp/pcpbnu_getoctstr.c
|
201cb58900feafdbe37cba2b8bc615b4514d3ecf
|
[
"Apache-2.0",
"Intel"
] |
permissive
|
intel/ipp-crypto
|
f0f05b87203705e82603db67bed5f8def13a5ee8
|
36e76e2388f3dd10cc440e213dfcf6ef59a0dfb8
|
refs/heads/develop
| 2023-09-04T08:15:06.851373
| 2023-07-27T12:47:12
| 2023-07-27T12:47:12
| 140,034,345
| 304
| 81
|
Apache-2.0
| 2023-08-30T17:18:36
| 2018-07-06T22:16:28
|
C
|
UTF-8
|
C
| false
| false
| 2,654
|
c
|
pcpbnu_getoctstr.c
|
/*******************************************************************************
* Copyright (C) 2002 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*******************************************************************************/
/*
// Purpose:
// Intel(R) Integrated Performance Primitives. Cryptography Primitives.
// Internal Unsigned BNU misc functionality
//
// Contents:
// cpToOctStr_BNU()
//
*/
#include "owncp.h"
#include "pcpbnumisc.h"
/*
// Convert BNU into HexString representation
//
// Returns length of the string or 0 if no success
*/
/*F*
// Name: cpToOctStr_BNU
//
// Purpose: Convert BNU into HexString representation.
//
// Returns:
// length of the string or 0 if no success
//
// Parameters:
// pA pointer to the source BN A
// nsA size of A
// pStr pointer to the target octet string
// strLen octet string length
*F*/
IPP_OWN_DEFN (cpSize, cpToOctStr_BNU, (Ipp8u* pStr, cpSize strLen, const BNU_CHUNK_T* pA, cpSize nsA))
{
FIX_BNU(pA, nsA);
{
cpSize bnuBitSize = BITSIZE_BNU(pA, nsA);
if(bnuBitSize <= strLen*BYTESIZE) {
int cnvLen = 0;
BNU_CHUNK_T x = pA[nsA-1];
ZEXPAND_BNU(pStr, 0, strLen);
pStr += strLen - BITS2WORD8_SIZE(bnuBitSize);
if(x) {
//int nb;
cpSize nb;
for(nb=cpNLZ_BNU(x)/BYTESIZE; nb<(cpSize)(sizeof(BNU_CHUNK_T)); cnvLen++, nb++)
*pStr++ = EBYTE(x, (Ipp32s)sizeof(BNU_CHUNK_T)-1-nb);
for(--nsA; nsA>0; cnvLen+=(Ipp32s)sizeof(BNU_CHUNK_T), nsA--) {
x = pA[nsA-1];
#if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT)
*pStr++ = EBYTE(x,7);
*pStr++ = EBYTE(x,6);
*pStr++ = EBYTE(x,5);
*pStr++ = EBYTE(x,4);
#endif
*pStr++ = EBYTE(x,3);
*pStr++ = EBYTE(x,2);
*pStr++ = EBYTE(x,1);
*pStr++ = EBYTE(x,0);
}
}
IPP_UNREFERENCED_PARAMETER(cnvLen);
return strLen;
}
else
return 0;
}
}
|
96cb1332dbba81a3a6ac175bad367d87da870219
|
5c72e3dec37038e313beab6250acaa54b4b03b93
|
/fwcfg64/driver.c
|
cfbdfb5c4a98c200b4d5d97bed64a8e2662439e5
|
[
"BSD-3-Clause",
"GPL-1.0-or-later"
] |
permissive
|
virtio-win/kvm-guest-drivers-windows
|
eb29c92b6949d6bfb0ee8c70004e359180ee2398
|
19a79901f36aa552b85f8b4c3c9645ebe90d9ec5
|
refs/heads/master
| 2023-09-06T00:50:32.529282
| 2023-08-25T10:21:53
| 2023-08-31T07:30:16
| 2,524,933
| 1,424
| 294
|
BSD-3-Clause
| 2023-08-26T16:02:39
| 2011-10-06T09:06:41
|
C
|
UTF-8
|
C
| false
| false
| 6,819
|
c
|
driver.c
|
/*
* This file contains driver routines
*
* Copyright (C) 2018 Virtuozzo International GmbH
*
*/
#include "driver.h"
#include "fwcfg.h"
#include "trace.h"
#include "driver.tmh"
#ifdef ALLOC_PRAGMA
#pragma alloc_text(INIT, DriverEntry)
#pragma alloc_text(PAGE, FwCfgEvtDeviceAdd)
#pragma alloc_text(PAGE, FwCfgEvtDriverCleanup)
#endif
NTSTATUS VMCoreInfoFill(PDEVICE_CONTEXT ctx)
{
NTSTATUS status;
PUCHAR hdr_buf;
ULONG bufSizeNeeded;
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL, "Obtaining header");
hdr_buf = (PUCHAR)ctx->vmci_data.pNote + FIELD_OFFSET(VMCI_ELF64_NOTE, n_desc);
status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, hdr_buf,
DUMP_HDR_SIZE, &bufSizeNeeded);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_ALL, "Failed to obtain header");
return status;
}
/*
* Original KDBG pointer was saved in header by system.
* BugcheckParameter1 field is unused in live system and will be filled by QEMU.
* So the pointer to decoded KDBG can be stored in this field.
*/
#ifdef _AMD64_
*(PULONG64)(hdr_buf + DUMP_HDR_OFFSET_BUGCHECK_PARAM1) = (ULONG64)ctx->kdbg;
#else
*(PULONG32)(hdr_buf + DUMP_HDR_OFFSET_BUGCHECK_PARAM1) = (ULONG32)ctx->kdbg;
#endif
return status;
}
NTSTATUS VMCoreInfoSend(PDEVICE_CONTEXT ctx)
{
NTSTATUS status;
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL, "Sending header");
status = FWCfgDmaSend(ctx->ioBase, ctx->vmci_data.vmci_pa, ctx->index,
sizeof(VMCOREINFO), ctx->dma_access, ctx->dma_access_pa);
return status;
}
VOID FwCfgEvtDriverCleanup(IN WDFOBJECT DriverObject)
{
UNREFERENCED_PARAMETER(DriverObject);
PAGED_CODE();
WPP_CLEANUP(WdfDriverWdmGetDriverObject((WDFDRIVER)DriverObject));
}
NTSTATUS GetKdbg(PDEVICE_CONTEXT ctx)
{
PUCHAR minidump;
ULONG32 kdbg_offset;
ULONG32 kdbg_size;
CONTEXT context = { 0 };
NTSTATUS status = STATUS_SUCCESS;
minidump = ExAllocatePoolUninitialized(NonPagedPoolNx, MINIDUMP_BUFFER_SIZE, 'pmdm');
if (!minidump)
{
return STATUS_MEMORY_NOT_ALLOCATED;
}
memset(minidump, 0, MINIDUMP_BUFFER_SIZE);
KeCapturePersistentThreadState(&context, NULL, 0, 0, 0, 0, 0, minidump);
kdbg_offset = *(PULONG32)(minidump + MINIDUMP_OFFSET_KDBG_OFFSET);
kdbg_size = *(PULONG32)(minidump + MINIDUMP_OFFSET_KDBG_SIZE);
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT,
"KdDebuggerDataBlock size = %lx, offset = 0x%lx",
kdbg_size, kdbg_offset);
/*
* KeCapturePersistentThreadState is supposed to save Small Memory Dump to the buffer.
* But since it is undocumented function, the driver should check actual output data.
*/
if (kdbg_size == 0 || (kdbg_offset + kdbg_size) > MINIDUMP_BUFFER_SIZE)
{
status = STATUS_INVALID_BUFFER_SIZE;
goto out_free_minidump;
}
ctx->kdbg = ExAllocatePoolUninitialized(NonPagedPoolNx, kdbg_size, 'gbdk');
if (!ctx->kdbg)
{
status = STATUS_MEMORY_NOT_ALLOCATED;
goto out_free_minidump;
}
memcpy(ctx->kdbg, minidump + kdbg_offset, kdbg_size);
out_free_minidump:
ExFreePool(minidump);
return status;
}
static VOID FwCfgContextInit(PDEVICE_CONTEXT ctx)
{
PCBUF_DATA pcbuf_data;
LONGLONG pcbuf_data_pa;
pcbuf_data = WdfCommonBufferGetAlignedVirtualAddress(ctx->cbuf);
pcbuf_data_pa = WdfCommonBufferGetAlignedLogicalAddress(ctx->cbuf).QuadPart;
ctx->vmci_data.pNote = &pcbuf_data->note;
ctx->vmci_data.note_pa = pcbuf_data_pa + FIELD_OFFSET(CBUF_DATA, note);
ctx->vmci_data.pVmci = &pcbuf_data->vmci;
ctx->vmci_data.vmci_pa = pcbuf_data_pa + FIELD_OFFSET(CBUF_DATA, vmci);
ctx->dma_access = &pcbuf_data->fwcfg_da;
ctx->dma_access_pa = pcbuf_data_pa + FIELD_OFFSET(CBUF_DATA, fwcfg_da);
}
NTSTATUS FwCfgEvtDeviceAdd(IN WDFDRIVER Driver, IN PWDFDEVICE_INIT DeviceInit)
{
NTSTATUS status;
WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
WDF_OBJECT_ATTRIBUTES attributes;
WDFDEVICE device;
PDEVICE_CONTEXT ctx;
WDF_DMA_ENABLER_CONFIG dmaEnablerConfig;
WDF_DEVICE_STATE devState;
UNREFERENCED_PARAMETER(Driver);
PAGED_CODE();
WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
pnpPowerCallbacks.EvtDevicePrepareHardware = FwCfgEvtDevicePrepareHardware;
pnpPowerCallbacks.EvtDeviceReleaseHardware = FwCfgEvtDeviceReleaseHardware;
pnpPowerCallbacks.EvtDeviceD0Entry = FwCfgEvtDeviceD0Entry;
pnpPowerCallbacks.EvtDeviceD0Exit = FwCfgEvtDeviceD0Exit;
WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, DEVICE_CONTEXT);
status = WdfDeviceCreate(&DeviceInit, &attributes, &device);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"WdfDeviceCreate failed: %!STATUS!", status);
return status;
}
ctx = GetDeviceContext(device);
memset(ctx, 0, sizeof(*ctx));
WDF_DMA_ENABLER_CONFIG_INIT(&dmaEnablerConfig, WdfDmaProfilePacket64,
sizeof(CBUF_DATA));
status = WdfDmaEnablerCreate(device, &dmaEnablerConfig,
WDF_NO_OBJECT_ATTRIBUTES, &ctx->dmaEnabler);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"Failed to create DMA enabler");
return status;
}
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT,
"DMA enabler created");
status = WdfCommonBufferCreate(ctx->dmaEnabler, sizeof(CBUF_DATA),
WDF_NO_OBJECT_ATTRIBUTES, &ctx->cbuf);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"Failed to create common buffer");
return status;
}
FwCfgContextInit(ctx);
WDF_DEVICE_STATE_INIT(&devState);
devState.NotDisableable = WdfFalse;
WdfDeviceSetDeviceState(device, &devState);
return STATUS_SUCCESS;
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
WDF_DRIVER_CONFIG config;
WDF_OBJECT_ATTRIBUTES attributes;
WPP_INIT_TRACING(DriverObject, RegistryPath);
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.EvtCleanupCallback = FwCfgEvtDriverCleanup;
WDF_DRIVER_CONFIG_INIT(&config, FwCfgEvtDeviceAdd);
status = WdfDriverCreate(DriverObject, RegistryPath, &attributes,
&config, WDF_NO_HANDLE);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"WdfDriverCreate failed: %!STATUS!", status);
WPP_CLEANUP(DriverObject);
}
return status;
}
|
e1c674ba3dbf0123daf015ff2486631afa0998e9
|
8447eb38a4fc71b32b6b82a99f7828a2c50621aa
|
/ppu/sprx/libsysfs/config.h
|
a0e016c08f72907766d897a4927231834a69c264
|
[
"MIT"
] |
permissive
|
ps3dev/PSL1GHT
|
9ecc1f0a2996b39d35cc98303c58c79966b9388b
|
5bc0961c66a3615c74f15e0c29bbeaa33f867ab3
|
refs/heads/master
| 2023-08-04T06:50:55.256801
| 2023-07-30T13:34:19
| 2023-07-30T13:34:19
| 1,541,223
| 159
| 357
|
MIT
| 2023-07-23T07:26:09
| 2011-03-29T12:34:15
|
C
|
UTF-8
|
C
| false
| false
| 131
|
h
|
config.h
|
#define LIBRARY_NAME "sys_fs"
#define LIBRARY_SYMBOL sys_fs
#define LIBRARY_HEADER_1 0x2c000001
#define LIBRARY_HEADER_2 0x0009
|
94bdff862a7ef36b1d774ce491cc23db4d9828eb
|
f2a90800f53ec5cf37a0f2317260b8bc6e0c7963
|
/drivers/gpu/drm/i915/gem/i915_gemfs.h
|
3bfeb98f06a5c3f66ddba2834ebbaf5f80b080e2
|
[] |
no_license
|
freebsd/drm-kmod
|
d53a2ca53ac1f8f2cd0b23652e1aec1167f49afb
|
b7ad04844fd8c1195b4c2f8d867499b4356000a5
|
refs/heads/master
| 2023-09-03T15:23:22.568180
| 2023-06-13T12:50:16
| 2023-06-13T12:50:56
| 261,718,139
| 129
| 87
| null | 2023-06-05T04:52:51
| 2020-05-06T09:54:12
|
C
|
UTF-8
|
C
| false
| false
| 490
|
h
|
i915_gemfs.h
|
/*
* SPDX-License-Identifier: MIT
*
* Copyright © 2017 Intel Corporation
*/
#ifndef __I915_GEMFS_H__
#define __I915_GEMFS_H__
struct drm_i915_private;
#ifdef __linux__
int i915_gemfs_init(struct drm_i915_private *i915);
void i915_gemfs_fini(struct drm_i915_private *i915);
#elif defined(__FreeBSD__)
static inline int
i915_gemfs_init(struct drm_i915_private *i915)
{
return -ENODEV;
}
static inline void
i915_gemfs_fini(struct drm_i915_private *i915)
{
return;
}
#endif
#endif
|
50e322735110bad73c8d1e5b1d75dcd8a2ea9b37
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/emulators/simh/files/patch-PDP18B_pdp18b__mt.c
|
d8163597fcc5ab9ec4b123b08cef52e4c2dadb4b
|
[
"BSD-2-Clause"
] |
permissive
|
freebsd/freebsd-ports
|
86f2e89d43913412c4f6b2be3e255bc0945eac12
|
605a2983f245ac63f5420e023e7dce56898ad801
|
refs/heads/main
| 2023-08-30T21:46:28.720924
| 2023-08-30T19:33:44
| 2023-08-30T19:33:44
| 1,803,961
| 916
| 918
|
NOASSERTION
| 2023-09-08T04:06:26
| 2011-05-26T11:15:35
| null |
UTF-8
|
C
| false
| false
| 2,052
|
c
|
patch-PDP18B_pdp18b__mt.c
|
--- PDP18B/pdp18b_mt.c.orig 2016-12-01 22:43:42 UTC
+++ PDP18B/pdp18b_mt.c
@@ -353,7 +353,7 @@ switch (f) {
mtxb[p++] = M[xma] & 0377;
}
} /* end for */
- if (st = sim_tape_wrrecf (uptr, mtxb, tbc)) /* write rec, err? */
+ if ((st = sim_tape_wrrecf (uptr, mtxb, tbc))) /* write rec, err? */
r = mt_map_err (uptr, st); /* map error */
else {
M[MT_CA] = (M[MT_CA] + wc) & DMASK; /* advance mem addr */
@@ -363,7 +363,7 @@ switch (f) {
break;
case FN_WREOF:
- if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */
+ if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */
r = mt_map_err (uptr, st); /* map error */
else uptr->USTAT = STA_EOF;
mt_cu = mt_cu & ~CU_ERASE; /* clear erase flag */
@@ -372,7 +372,7 @@ switch (f) {
case FN_SPACEF: /* space forward */
do {
M[MT_WC] = (M[MT_WC] + 1) & DMASK; /* inc WC */
- if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */
+ if ((st = sim_tape_sprecf (uptr, &tbc))) { /* space rec fwd, err? */
r = mt_map_err (uptr, st); /* map error */
break;
}
@@ -382,7 +382,7 @@ switch (f) {
case FN_SPACER: /* space reverse */
do {
M[MT_WC] = (M[MT_WC] + 1) & DMASK; /* inc WC */
- if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */
+ if ((st = sim_tape_sprecr (uptr, &tbc))) { /* space rec rev, err? */
r = mt_map_err (uptr, st); /* map error */
break;
}
|
7a3560875bdc4393f9bc527fff637627e573a935
|
9b886f22aabb00ecbaaba8b87f988119e0300b3f
|
/src/testsystem.c
|
a03b04af2cc2c5f7d63b3d138c6e02a53f2ea97b
|
[
"LicenseRef-scancode-public-domain",
"Apache-2.0"
] |
permissive
|
spotify/sparkey
|
db0409dec26c6e96537ecbd8d40c5b2b033678da
|
d694f20f35caa1cb514c84f3f02e94f71248f857
|
refs/heads/master
| 2023-09-03T03:10:01.123186
| 2023-08-17T09:06:05
| 2023-08-17T09:06:05
| 12,488,811
| 505
| 57
|
Apache-2.0
| 2023-08-17T09:06:07
| 2013-08-30T14:52:09
|
C
|
UTF-8
|
C
| false
| false
| 10,384
|
c
|
testsystem.c
|
/*
* Copyright (c) 2012-2013 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "sparkey.h"
static int max(int a, int b) {
return a > b ? a : b;
}
static void _assert_equals(const char *file, int line, int expected, int actual) {
if (expected != actual) {
printf("%s:%d: Expected %d but got %d\n", file, line, expected, actual);
exit(1);
}
}
#define assert_equals(expected, actual) _assert_equals(__FILE__, __LINE__, expected, actual)
static void _assert_str_equals(const char *file, int line, const char *expected, const char *actual) {
if (expected == NULL && actual != NULL) {
printf("%s:%d: Expected NULL but got '%s'\n", file, line, actual);
exit(1);
}
if (expected != NULL && actual == NULL) {
printf("%s:%d: Expected '%s' but got NULL\n", file, line, expected);
exit(1);
}
if (expected != NULL && actual != NULL && strcmp(expected, actual)) {
printf("%s:%d: Expected '%s' but got '%s'\n", file, line, expected, actual);
exit(1);
}
}
#define assert_str_equals(expected, actual) _assert_str_equals(__FILE__, __LINE__, expected, actual)
void verify(sparkey_compression_type compression, int blocksize, int hashsize, int num_puts, int num_deletes, int num_puts2) {
int expected_puts = max(0, num_puts - max(num_deletes, num_puts2));
int expected_total = expected_puts + num_puts2;
// write some data to the log
sparkey_logwriter *mywriter;
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_create(&mywriter, "test.spl", compression, blocksize));
for (int i = 0; i < num_puts; i++) {
char key[100];
char value[100];
sprintf(key, "key_%d", i);
sprintf(value, "value_%d", i);
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_put(mywriter, strlen(key), (uint8_t*) key, strlen(value), (uint8_t*) value));
}
for (int i = 0; i < num_deletes; i++) {
char key[100];
sprintf(key, "key_%d", i);
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_delete(mywriter, strlen(key), (uint8_t*) key));
}
for (int i = 0; i < num_puts2; i++) {
char key[100];
char value[100];
sprintf(key, "key_%d", i);
sprintf(value, "newvalue_%d", i);
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_put(mywriter, strlen(key), (uint8_t*) key, strlen(value), (uint8_t*) value));
}
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_close(&mywriter));
// verify correct log iteration
sparkey_logreader *myreader;
assert_equals(SPARKEY_SUCCESS, sparkey_logreader_open(&myreader, "test.spl"));
sparkey_logiter *myiter;
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_create(&myiter, myreader));
int visited = 0;
while (1) {
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_next(myiter, myreader));
if (sparkey_logiter_state(myiter) != SPARKEY_ITER_ACTIVE) {
break;
}
visited++;
uint64_t wanted_keylen = sparkey_logiter_keylen(myiter);
// one extra byte to account for the extra \0 at the end, as we're going to compare it as a string.
// By using calloc we also ensure that it initializes to 0 directly.
uint8_t *keybuf = calloc(1 + wanted_keylen, 1);
uint64_t actual_keylen;
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_fill_key(myiter, myreader, wanted_keylen, keybuf, &actual_keylen));
assert_equals(wanted_keylen, actual_keylen);
uint64_t wanted_valuelen = sparkey_logiter_valuelen(myiter);
uint8_t *valuebuf = calloc(1 + wanted_valuelen, 1);
uint64_t actual_valuelen;
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_fill_value(myiter, myreader, wanted_valuelen, valuebuf, &actual_valuelen));
assert_equals(wanted_valuelen, actual_valuelen);
sparkey_entry_type expected_type;
int expected_id;
const char *expected_value_prefix;
if (visited <= num_puts) {
expected_type = SPARKEY_ENTRY_PUT;
expected_id = visited - 1;
expected_value_prefix = "value";
} else if (visited <= num_puts + num_deletes) {
expected_type = SPARKEY_ENTRY_DELETE;
expected_id = visited - num_puts - 1;
expected_value_prefix = "UNUSED";
} else {
expected_type = SPARKEY_ENTRY_PUT;
expected_id = visited - num_puts - num_deletes - 1;
expected_value_prefix = "newvalue";
}
assert_equals(expected_type, sparkey_logiter_type(myiter));
char expected_key[100];
char expected_value[100];
sprintf(expected_key, "key_%d", expected_id);
sprintf(expected_value, "%s_%d", expected_value_prefix, expected_id);
assert_str_equals(expected_key, (char*) keybuf);
if (expected_type == SPARKEY_ENTRY_PUT) {
assert_str_equals(expected_value, (char*) valuebuf);
}
free(keybuf);
free(valuebuf);
}
assert_equals(num_puts + num_deletes + num_puts2, visited);
sparkey_logreader_close(&myreader);
sparkey_logiter_close(&myiter);
// create the hash
assert_equals(SPARKEY_SUCCESS, sparkey_hash_write("test.spi", "test.spl", hashsize));
// verify hash iteration
sparkey_hashreader *myhashreader;
assert_equals(SPARKEY_SUCCESS, sparkey_hash_open(&myhashreader, "test.spi", "test.spl"));
myreader = sparkey_hash_getreader(myhashreader);
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_create(&myiter, myreader));
visited = 0;
while (1) {
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_hashnext(myiter, myhashreader));
if (sparkey_logiter_state(myiter) != SPARKEY_ITER_ACTIVE) {
break;
}
visited++;
uint64_t wanted_keylen = sparkey_logiter_keylen(myiter);
uint8_t *keybuf = calloc(1 + wanted_keylen, 1);
uint64_t actual_keylen;
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_fill_key(myiter, myreader, wanted_keylen, keybuf, &actual_keylen));
assert_equals(wanted_keylen, actual_keylen);
uint64_t wanted_valuelen = sparkey_logiter_valuelen(myiter);
uint8_t *valuebuf = calloc(1 + wanted_valuelen, 1);
uint64_t actual_valuelen;
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_fill_value(myiter, myreader, wanted_valuelen, valuebuf, &actual_valuelen));
assert_equals(wanted_valuelen, actual_valuelen);
assert_equals(SPARKEY_ENTRY_PUT, sparkey_logiter_type(myiter));
int expected_id;
const char *expected_value_prefix;
if (visited <= expected_puts) {
expected_id = max(num_deletes, num_puts2) + visited - 1;
expected_value_prefix = "value";
} else {
expected_id = visited - expected_puts - 1;
expected_value_prefix = "newvalue";
}
char expected_key[100];
char expected_value[100];
sprintf(expected_key, "key_%d", expected_id);
sprintf(expected_value, "%s_%d", expected_value_prefix, expected_id);
assert_str_equals(expected_key, (char*) keybuf);
assert_str_equals(expected_value, (char*) valuebuf);
free(keybuf);
free(valuebuf);
}
assert_equals(expected_total, visited);
// verify random access
for (int i = 0; i < max(num_puts, num_puts2) + 100; i++) {
char key[100];
char expected_value[100];
sprintf(key, "key_%d", i);
assert_equals(SPARKEY_SUCCESS, sparkey_hash_get(myhashreader, (uint8_t*) key, strlen(key), myiter));
if (i < num_puts2) {
assert_equals(SPARKEY_ITER_ACTIVE, sparkey_logiter_state(myiter));
sprintf(expected_value, "newvalue_%d", i);
} else if (i >= num_deletes && i < num_puts) {
assert_equals(SPARKEY_ITER_ACTIVE, sparkey_logiter_state(myiter));
sprintf(expected_value, "value_%d", i);
} else {
assert_equals(SPARKEY_ITER_INVALID, sparkey_logiter_state(myiter));
}
if (sparkey_logiter_state(myiter) == SPARKEY_ITER_ACTIVE) {
uint64_t wanted_valuelen = sparkey_logiter_valuelen(myiter);
uint8_t *valuebuf = calloc(1 + wanted_valuelen, 1);
uint64_t actual_valuelen;
assert_equals(SPARKEY_SUCCESS, sparkey_logiter_fill_value(myiter, myreader, wanted_valuelen, valuebuf, &actual_valuelen));
assert_equals(wanted_valuelen, actual_valuelen);
assert_str_equals(expected_value, (char*) valuebuf);
free(valuebuf);
}
}
sparkey_hash_close(&myhashreader);
sparkey_logiter_close(&myiter);
}
void verify_files_closed() {
// Verify that SPARKEY_FILE_IDENTIFIER_MISMATCH is returned appropriately.
sparkey_logwriter *writer;
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_create(&writer, "test1.spl",
SPARKEY_COMPRESSION_NONE, 4096));
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_close(&writer));
assert_equals(1, writer == NULL);
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_create(&writer, "test2.spl",
SPARKEY_COMPRESSION_NONE, 4096));
assert_equals(SPARKEY_SUCCESS, sparkey_logwriter_close(&writer));
assert_equals(1, writer == NULL);
// Now create a hash for test1.
assert_equals(SPARKEY_SUCCESS, sparkey_hash_write("test1.spi", "test1.spl", 0));
// and try to open the wrong files:
sparkey_hashreader* reader;
sparkey_returncode rc = sparkey_hash_open(
&reader,
"test1.spi",
"test2.spl"
);
assert_equals(SPARKEY_FILE_IDENTIFIER_MISMATCH, rc);
}
int main() {
verify(SPARKEY_COMPRESSION_NONE, 0, 0, 0, 0, 0);
verify(SPARKEY_COMPRESSION_NONE, 0, 0, 1, 0, 0);
verify(SPARKEY_COMPRESSION_NONE, 0, 0, 100, 0, 0);
verify(SPARKEY_COMPRESSION_NONE, 0, 0, 0, 100, 0);
verify(SPARKEY_COMPRESSION_NONE, 0, 0, 0, 0, 100);
verify(SPARKEY_COMPRESSION_NONE, 0, 0, 100, 10, 5);
for (sparkey_compression_type t = SPARKEY_COMPRESSION_SNAPPY; t <= SPARKEY_COMPRESSION_ZSTD; t++) {
verify(t, 10, 0, 100, 0, 0);
verify(t, 20, 0, 100, 0, 0);
verify(t, 100, 0, 100, 0, 0);
verify(t, 100, 0, 1000, 0, 0);
verify(t, 1000, 0, 1000, 0, 0);
verify(t, 100, 0, 1000, 100, 0);
verify(t, 100, 0, 1000, 100, 50);
verify(t, 100, 4, 1000, 0, 0);
verify(t, 100, 8, 1000, 0, 0);
}
verify_files_closed();
printf("Success!\n");
}
|
9075b674873c1c3e8e2e84a3bf69336cf3fb966d
|
9ab1b8920650fc77976c495f9554ba4dcb483e38
|
/src/runtime/testdata/testwinlibthrow/veh.c
|
08c1f9edf03ba9c915881cc17b9cc9c258017e96
|
[
"BSD-3-Clause",
"CC-BY-4.0",
"LicenseRef-scancode-google-patent-license-golang"
] |
permissive
|
cloudflare/go
|
6ea74badb90f65a457bae123d77ee37ff5fe9c32
|
c6d8c70b1759cba3f5a2181fdd3e845f5bec94f6
|
refs/heads/cf
| 2023-09-04T08:21:43.730902
| 2023-08-14T11:56:04
| 2023-08-14T11:56:04
| 15,983,484
| 290
| 59
|
BSD-3-Clause
| 2023-09-06T22:18:57
| 2014-01-16T22:50:12
|
Go
|
UTF-8
|
C
| false
| false
| 470
|
c
|
veh.c
|
//go:build ignore
#include <windows.h>
__declspec(dllexport)
void RaiseNoExcept(void)
{
RaiseException(42, 0, 0, 0);
}
static DWORD WINAPI ThreadRaiser(void* Context)
{
RaiseNoExcept();
return 0;
}
__declspec(dllexport)
void ThreadRaiseNoExcept(void)
{
HANDLE thread = CreateThread(0, 0, ThreadRaiser, 0, 0, 0);
if (0 != thread)
{
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
}
|
5352ad532c51be3e3e11247e0038b48f904ddd01
|
b75aed5b06c00bd1435239da8bd72696829631b0
|
/qpdf/qpdf-ctest.c
|
ba177444994449639248c558ff2ff524751db6c3
|
[
"Artistic-1.0",
"Artistic-2.0",
"Apache-2.0",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-public-domain",
"MIT",
"AGPL-3.0-or-later"
] |
permissive
|
qpdf/qpdf
|
e233c2d09b4fc4586a6af44ea8350873d5ff95e7
|
3372615e5bc22ed3d4f0f5990ce2e6e41dc06c4f
|
refs/heads/main
| 2023-09-03T17:54:14.006027
| 2023-09-03T14:13:02
| 2023-09-03T14:13:17
| 4,539,167
| 2,583
| 261
|
Apache-2.0
| 2023-09-05T17:37:12
| 2012-06-03T17:40:19
|
C++
|
UTF-8
|
C
| false
| false
| 51,504
|
c
|
qpdf-ctest.c
|
#include <qpdf/assert_test.h>
#include <qpdf/qpdf-c.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char* whoami = 0;
static qpdf_data qpdf = 0;
static FILE*
safe_fopen(char const* filename, char const* mode)
{
// This function is basically a "C" port of QUtil::safe_fopen.
FILE* f = 0;
#ifdef _MSC_VER
errno_t err = fopen_s(&f, filename, mode);
if (err != 0) {
char buf[94];
strerror_s(buf, sizeof(buf), errno);
fprintf(stderr, "%s: unable to open %s: %s\n", whoami, filename, buf);
exit(2);
}
#else
f = fopen(filename, mode);
if (f == NULL) {
fprintf(stderr, "%s: unable to open %s: %s\n", whoami, filename, strerror(errno));
exit(2);
}
#endif
return f;
}
static void
print_error(char const* label, qpdf_data q, qpdf_error e)
{
printf("%s: %s\n", label, qpdf_get_error_full_text(q, e));
printf(" code: %d\n", qpdf_get_error_code(q, e));
printf(" file: %s\n", qpdf_get_error_filename(q, e));
printf(" pos: %lld\n", qpdf_get_error_file_position(q, e));
printf(" text: %s\n", qpdf_get_error_message_detail(q, e));
}
static void
report_errors()
{
qpdf_error e = 0;
while (qpdf_more_warnings(qpdf)) {
e = qpdf_next_warning(qpdf);
print_error("warning", qpdf, e);
}
if (qpdf_has_error(qpdf)) {
e = qpdf_get_error(qpdf);
assert(qpdf_has_error(qpdf) == QPDF_FALSE);
print_error("error", qpdf, e);
} else {
e = qpdf_get_error(qpdf);
assert(e == 0);
assert(qpdf_get_error_code(qpdf, e) == qpdf_e_success);
// Call these to ensure that they can be called on a null
// error pointer.
(void)qpdf_get_error_full_text(qpdf, e);
(void)qpdf_get_error_filename(qpdf, e);
(void)qpdf_get_error_file_position(qpdf, e);
(void)qpdf_get_error_message_detail(qpdf, e);
}
}
static void
handle_oh_error(qpdf_data q, char const* label)
{
if (qpdf_has_error(q)) {
print_error(label, q, qpdf_get_error(q));
}
}
static void
read_file_into_memory(char const* filename, char** buf, unsigned long* size)
{
char* buf_p = 0;
FILE* f = NULL;
size_t bytes_read = 0;
size_t len = 0;
f = safe_fopen(filename, "rb");
fseek(f, 0, SEEK_END);
*size = (unsigned long)ftell(f);
fseek(f, 0, SEEK_SET);
*buf = malloc(*size);
if (*buf == NULL) {
fprintf(stderr, "%s: unable to allocate %lu bytes\n", whoami, *size);
exit(2);
}
buf_p = *buf;
bytes_read = 0;
len = 0;
while ((len = fread(buf_p + bytes_read, 1, *size - bytes_read, f)) > 0) {
bytes_read += len;
}
if (bytes_read != *size) {
if (ferror(f)) {
fprintf(stderr, "%s: failure reading file %s into memory:", whoami, filename);
} else {
fprintf(stderr, "%s: premature EOF reading file %s:", whoami, filename);
}
fprintf(stderr, " read %lu, wanted %lu\n", (unsigned long)bytes_read, (unsigned long)*size);
exit(2);
}
fclose(f);
}
static void
count_progress(int percent, void* data)
{
++(*(int*)data);
}
static int
write_to_file(char const* data, size_t size, void* udata)
{
FILE* f = (FILE*)udata;
return fwrite(data, 1, size, f) != size;
}
static int
custom_log(char const* data, size_t size, void* udata)
{
fprintf(stderr, "|custom|");
fwrite(data, 1, size, stderr);
fflush(stderr);
return 0;
}
static void
test01(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
printf("version: %s\n", qpdf_get_pdf_version(qpdf));
if (qpdf_get_pdf_extension_level(qpdf) > 0) {
printf("extension level: %d\n", qpdf_get_pdf_extension_level(qpdf));
}
printf("linearized: %d\n", qpdf_is_linearized(qpdf));
printf("encrypted: %d\n", qpdf_is_encrypted(qpdf));
if (qpdf_is_encrypted(qpdf)) {
printf("user password: %s\n", qpdf_get_user_password(qpdf));
printf("extract for accessibility: %d\n", qpdf_allow_accessibility(qpdf));
printf("extract for any purpose: %d\n", qpdf_allow_extract_all(qpdf));
printf("print low resolution: %d\n", qpdf_allow_print_low_res(qpdf));
printf("print high resolution: %d\n", qpdf_allow_print_high_res(qpdf));
printf("modify document assembly: %d\n", qpdf_allow_modify_assembly(qpdf));
printf("modify forms: %d\n", qpdf_allow_modify_form(qpdf));
printf("modify annotations: %d\n", qpdf_allow_modify_annotation(qpdf));
printf("modify other: %d\n", qpdf_allow_modify_other(qpdf));
printf("modify anything: %d\n", qpdf_allow_modify_all(qpdf));
}
report_errors();
}
static void
test02(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_set_suppress_warnings(qpdf, QPDF_TRUE);
if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) {
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
}
report_errors();
}
static void
test03(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_content_normalization(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test04(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_set_ignore_xref_streams(qpdf, QPDF_TRUE);
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test05(char const* infile, char const* password, char const* outfile, char const* xarg)
{
int count = 0;
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_register_progress_reporter(qpdf, count_progress, (void*)&count);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_linearization(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
/* make sure progress reporter was called */
assert(count > 0);
report_errors();
}
static void
test06(char const* infile, char const* password, char const* outfile, char const* xarg)
{
char* buf = NULL;
unsigned long size = 0;
read_file_into_memory(infile, &buf, &size);
qpdf_read_memory(qpdf, infile, buf, size, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_object_stream_mode(qpdf, qpdf_o_generate);
qpdf_write(qpdf);
report_errors();
free(buf);
}
static void
test07(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test08(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test09(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_stream_data_mode(qpdf, qpdf_s_uncompress);
qpdf_write(qpdf);
report_errors();
}
static void
test10(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_set_attempt_recovery(qpdf, QPDF_FALSE);
qpdf_read(qpdf, infile, password);
report_errors();
}
static void
test11(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_r2_encryption_parameters_insecure(
qpdf, "user1", "owner1", QPDF_FALSE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test12(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_r3_encryption_parameters_insecure(
qpdf,
"user2",
"owner2",
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
qpdf_r3p_low);
qpdf_write(qpdf);
report_errors();
}
static void
test13(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
printf("user password: %s\n", qpdf_get_user_password(qpdf));
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_preserve_encryption(qpdf, QPDF_FALSE);
qpdf_write(qpdf);
report_errors();
}
static void
test14(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_minimum_pdf_version_and_extension(qpdf, "1.7", 8);
qpdf_write(qpdf);
qpdf_init_write(qpdf, xarg);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_force_pdf_version(qpdf, "1.4");
qpdf_write(qpdf);
report_errors();
}
static void
test15(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_r4_encryption_parameters_insecure(
qpdf,
"user2",
"owner2",
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
qpdf_r3p_low,
QPDF_TRUE,
QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
print_info(char const* key)
{
char const* value = qpdf_get_info_key(qpdf, key);
printf("Info key %s: %s\n", key, (value ? value : "(null)"));
}
static void
test16(char const* infile, char const* password, char const* outfile, char const* xarg)
{
unsigned long buflen = 0L;
unsigned char const* buf = 0;
FILE* f = 0;
qpdf_read(qpdf, infile, password);
print_info("/Author");
print_info("/Producer");
print_info("/Creator");
qpdf_set_info_key(qpdf, "/Author", "Mr. Potato Head");
qpdf_set_info_key(qpdf, "/Producer", "QPDF library");
qpdf_set_info_key(qpdf, "/Creator", 0);
print_info("/Author");
print_info("/Producer");
print_info("/Creator");
qpdf_init_write_memory(qpdf);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_stream_data_mode(qpdf, qpdf_s_uncompress);
qpdf_write(qpdf);
f = safe_fopen(outfile, "wb");
buflen = (unsigned long)(qpdf_get_buffer_length(qpdf));
buf = qpdf_get_buffer(qpdf);
fwrite(buf, 1, buflen, f);
fclose(f);
report_errors();
}
static void
test17(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_r5_encryption_parameters2(
qpdf,
"user3",
"owner3",
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
qpdf_r3p_low,
QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test18(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_r6_encryption_parameters2(
qpdf,
"user4",
"owner4",
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
QPDF_TRUE,
qpdf_r3p_low,
QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test19(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_deterministic_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test20(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_compress_streams(qpdf, QPDF_FALSE);
qpdf_set_decode_level(qpdf, qpdf_dl_specialized);
qpdf_write(qpdf);
report_errors();
}
static void
test21(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_preserve_unreferenced_objects(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test22(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
qpdf_set_compress_streams(qpdf, QPDF_FALSE);
qpdf_set_newline_before_endstream(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test23(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Test check and also exercise custom logger */
qpdflogger_handle l1 = qpdf_get_logger(qpdf);
qpdflogger_handle l2 = qpdflogger_default_logger();
assert(qpdflogger_equal(l1, l2));
qpdflogger_cleanup(&l1);
qpdflogger_cleanup(&l2);
qpdflogger_handle l = qpdflogger_create();
qpdflogger_set_warn(l, qpdf_log_dest_custom, custom_log, NULL);
qpdf_set_logger(qpdf, l);
qpdflogger_handle l3 = qpdf_get_logger(qpdf);
assert(qpdflogger_equal(l, l3));
qpdflogger_cleanup(&l);
qpdflogger_cleanup(&l3);
QPDF_ERROR_CODE status = 0;
qpdf_read(qpdf, infile, password);
status = qpdf_check_pdf(qpdf);
printf("status: %d\n", status);
report_errors();
}
static void
test24(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. Pull objects out of
* minimal.pdf to make sure all our accessors work as expected.
*/
qpdf_read(qpdf, infile, password);
qpdf_oh trailer = qpdf_get_trailer(qpdf);
/* The library never returns 0 */
assert(trailer == 1);
/* Get root two different ways */
qpdf_oh root = qpdf_get_root(qpdf);
assert(qpdf_oh_get_generation(qpdf, root) == 0);
qpdf_oh root_from_trailer = qpdf_oh_get_key(qpdf, trailer, "/Root");
assert(qpdf_oh_get_object_id(qpdf, root) == qpdf_oh_get_object_id(qpdf, root_from_trailer));
/* Go to the first page and look at all the keys */
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
assert(qpdf_oh_is_dictionary(qpdf, pages));
assert(qpdf_oh_get_type_code(qpdf, pages) == ot_dictionary);
assert(strcmp(qpdf_oh_get_type_name(qpdf, pages), "dictionary") == 0);
assert(qpdf_oh_is_initialized(qpdf, pages));
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
assert(qpdf_oh_is_array(qpdf, kids));
assert(qpdf_oh_get_type_code(qpdf, kids) == ot_array);
assert(strcmp(qpdf_oh_get_type_name(qpdf, kids), "array") == 0);
assert(qpdf_oh_get_array_n_items(qpdf, kids) == 1);
qpdf_oh page1 = qpdf_oh_get_array_item(qpdf, kids, 0);
qpdf_oh_begin_dict_key_iter(qpdf, page1);
while (qpdf_oh_dict_more_keys(qpdf)) {
printf("page dictionary key: %s\n", qpdf_oh_dict_next_key(qpdf));
}
/* Inspect the first page */
qpdf_oh type = qpdf_oh_get_key(qpdf, page1, "/Type");
assert(qpdf_oh_is_name(qpdf, type));
assert(qpdf_oh_get_type_code(qpdf, type) == ot_name);
assert(strcmp(qpdf_oh_get_type_name(qpdf, type), "name") == 0);
assert(strcmp(qpdf_oh_get_name(qpdf, type), "/Page") == 0);
qpdf_oh parent = qpdf_oh_get_key(qpdf, page1, "/Parent");
assert(qpdf_oh_is_indirect(qpdf, parent));
qpdf_oh mediabox = qpdf_oh_get_key(qpdf, page1, "/MediaBox");
assert(!qpdf_oh_is_scalar(qpdf, mediabox));
assert(qpdf_oh_is_array(qpdf, mediabox));
assert(qpdf_oh_get_array_n_items(qpdf, mediabox) == 4);
for (int i = 0; i < 4; ++i) {
qpdf_oh item = qpdf_oh_get_array_item(qpdf, mediabox, i);
printf(
"item %d: %d %.2f\n",
i,
qpdf_oh_get_int_value_as_int(qpdf, item),
qpdf_oh_get_numeric_value(qpdf, item));
}
/* Exercise different ways of looking at integers */
qpdf_oh i2 = qpdf_oh_get_array_item(qpdf, mediabox, 2);
assert(qpdf_oh_get_int_value_as_int(qpdf, i2) == 612);
assert(qpdf_oh_get_int_value(qpdf, i2) == 612ll);
assert(qpdf_oh_get_uint_value_as_uint(qpdf, i2) == 612u);
assert(qpdf_oh_get_uint_value(qpdf, i2) == 612ull);
/* Exercise accessors of other object types */
assert(!qpdf_oh_is_operator(qpdf, i2));
assert(!qpdf_oh_is_inline_image(qpdf, i2));
/* Chain calls. */
qpdf_oh encoding = qpdf_oh_get_key(
qpdf,
qpdf_oh_get_key(
qpdf,
qpdf_oh_get_key(qpdf, qpdf_oh_get_key(qpdf, page1, "/Resources"), "/Font"),
"/F1"),
"/Encoding");
assert(strcmp(qpdf_oh_get_name(qpdf, encoding), "/WinAnsiEncoding") == 0);
qpdf_oh res = qpdf_oh_get_key_if_dict(qpdf, page1, "/Resources");
assert(qpdf_oh_has_key(qpdf, res, "/Font"));
/* check no warning when called with null */
while (qpdf_more_warnings(qpdf)) {
qpdf_next_warning(qpdf);
}
res = qpdf_oh_get_key_if_dict(qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font");
assert(!qpdf_more_warnings(qpdf));
/* Look at page contents to exercise stream functions */
qpdf_oh contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
assert(qpdf_oh_is_stream(qpdf, contents));
assert(qpdf_oh_get_type_code(qpdf, contents) == ot_stream);
assert(strcmp(qpdf_oh_get_type_name(qpdf, contents), "stream") == 0);
qpdf_oh contents_dict = qpdf_oh_get_dict(qpdf, contents);
assert(!qpdf_oh_is_scalar(qpdf, contents));
assert(!qpdf_oh_is_scalar(qpdf, contents_dict));
qpdf_oh contents_length = qpdf_oh_get_key(qpdf, contents_dict, "/Length");
assert(qpdf_oh_is_integer(qpdf, contents_length));
assert(qpdf_oh_get_type_code(qpdf, contents_length) == ot_integer);
assert(strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0);
assert(qpdf_oh_is_scalar(qpdf, contents_length));
assert(qpdf_oh_is_number(qpdf, contents_length));
qpdf_oh contents_array = qpdf_oh_wrap_in_array(qpdf, contents);
assert(qpdf_oh_get_array_n_items(qpdf, contents_array) == 1);
assert(
qpdf_oh_get_object_id(qpdf, qpdf_oh_get_array_item(qpdf, contents_array, 0)) ==
qpdf_oh_get_object_id(qpdf, contents));
/* Wrap in array for a non-trivial case */
qpdf_oh wrapped_contents_array = qpdf_oh_wrap_in_array(qpdf, contents_array);
assert(qpdf_oh_get_array_n_items(qpdf, wrapped_contents_array) == 1);
assert(
qpdf_oh_get_object_id(qpdf, qpdf_oh_get_array_item(qpdf, wrapped_contents_array, 0)) ==
qpdf_oh_get_object_id(qpdf, contents));
/* Exercise functions that work with indirect objects */
qpdf_oh resources = qpdf_oh_get_key(qpdf, page1, "/Resources");
qpdf_oh procset = qpdf_oh_get_key(qpdf, resources, "/ProcSet");
assert(strcmp(qpdf_oh_unparse(qpdf, procset), "5 0 R") == 0);
assert(strcmp(qpdf_oh_unparse_resolved(qpdf, procset), "[ /PDF /Text ]") == 0);
qpdf_oh_make_direct(qpdf, procset);
assert(strcmp(qpdf_oh_unparse(qpdf, procset), "[ /PDF /Text ]") == 0);
/* The replaced /ProcSet can be seen to be a direct object in the
* expected output PDF.
*/
qpdf_oh_replace_key(qpdf, resources, "/ProcSet", procset);
/* Release and access to exercise handling of object handle errors
* and to show that write still works after releasing. This test
* uses the default oh error handler, so messages get written to
* stderr. The warning about using the default error handler only
* appears once.
*/
qpdf_oh_release(qpdf, page1);
contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
assert(qpdf_oh_is_null(qpdf, contents));
assert(qpdf_oh_get_type_code(qpdf, contents) == ot_null);
assert(strcmp(qpdf_oh_get_type_name(qpdf, contents), "null") == 0);
assert(qpdf_oh_is_array(qpdf, mediabox));
qpdf_oh_release_all(qpdf);
assert(!qpdf_oh_is_null(qpdf, mediabox));
assert(!qpdf_oh_is_array(qpdf, mediabox));
/* Make sure something is assigned when we exit so we check that
* it gets properly freed.
*/
qpdf_get_root(qpdf);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test25(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
qpdf_read(qpdf, infile, password);
qpdf_oh root = qpdf_get_root(qpdf);
/* Parse objects from a string */
qpdf_oh parsed =
qpdf_oh_parse(qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true false /Six]");
qpdf_oh p_int = qpdf_oh_get_array_item(qpdf, parsed, 0);
qpdf_oh p_real = qpdf_oh_get_array_item(qpdf, parsed, 1);
qpdf_oh p_string = qpdf_oh_get_array_item(qpdf, parsed, 2);
qpdf_oh p_dict = qpdf_oh_get_array_item(qpdf, parsed, 3);
qpdf_oh p_null = qpdf_oh_get_array_item(qpdf, parsed, 4);
qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5);
qpdf_oh p_bool_f = qpdf_oh_get_array_item(qpdf, parsed, 6);
qpdf_oh p_name = qpdf_oh_get_array_item(qpdf, parsed, 7);
assert(qpdf_oh_is_integer(qpdf, p_int) && qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1);
long long l = 0;
assert(qpdf_oh_get_value_as_longlong(qpdf, p_bool, &l) == QPDF_FALSE);
assert((qpdf_oh_get_value_as_longlong(qpdf, p_int, &l) == QPDF_TRUE) && (l == 1));
int i = 0;
assert(qpdf_oh_get_value_as_int(qpdf, p_bool, &i) == QPDF_FALSE);
assert((qpdf_oh_get_value_as_int(qpdf, p_int, &i) == QPDF_TRUE) && (i == 1));
unsigned long long ul = 0u;
assert(qpdf_oh_get_value_as_ulonglong(qpdf, p_bool, &ul) == QPDF_FALSE);
assert((qpdf_oh_get_value_as_ulonglong(qpdf, p_int, &ul) == QPDF_TRUE) && (ul == 1u));
unsigned int u = 0u;
assert(qpdf_oh_get_value_as_uint(qpdf, p_bool, &u) == QPDF_FALSE);
assert((qpdf_oh_get_value_as_uint(qpdf, p_int, &u) == QPDF_TRUE) && (u == 1u));
double d = 0.0;
assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE);
assert(
(qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) && ((d - 1.0) < 1e-6) &&
((d - 1.0) > -1e-6));
assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0);
assert(
qpdf_oh_is_real(qpdf, p_real) &&
(strcmp(qpdf_oh_get_real_value(qpdf, p_real), "2.0") == 0) &&
qpdf_oh_get_numeric_value(qpdf, p_real) == 2.0);
const char* r = "";
size_t length = 0;
assert(
(qpdf_oh_get_value_as_real(qpdf, p_name, &r, &length) == QPDF_FALSE) &&
(strcmp(r, "") == 0) && (length == 0));
assert(
(qpdf_oh_get_value_as_real(qpdf, p_real, &r, &length) == QPDF_TRUE) &&
(strcmp(r, "2.0") == 0) && (length == 3));
assert(qpdf_oh_get_type_code(qpdf, p_real) == ot_real);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_real), "real") == 0);
assert(
qpdf_oh_is_string(qpdf, p_string) &&
(strcmp(qpdf_oh_get_string_value(qpdf, p_string), "3\xf7") == 0) &&
(strcmp(qpdf_oh_get_utf8_value(qpdf, p_string), "3\xc3\xb7") == 0) &&
(strcmp(qpdf_oh_unparse_binary(qpdf, p_string), "<33f7>") == 0));
const char* str = "";
length = 0;
assert(
(qpdf_oh_get_value_as_string(qpdf, p_name, &str, &length) == QPDF_FALSE) &&
(strcmp(str, "") == 0) && (length == 0));
assert(
(qpdf_oh_get_value_as_string(qpdf, p_string, &str, &length) == QPDF_TRUE) &&
(strcmp(str, "3\xf7") == 0) && (length == 2));
const char* utf8 = "";
length = 0;
assert(
(qpdf_oh_get_value_as_utf8(qpdf, p_name, &utf8, &length) == QPDF_FALSE) &&
(strcmp(utf8, "") == 0) && (length == 0));
assert(
(qpdf_oh_get_value_as_utf8(qpdf, p_string, &utf8, &length) == QPDF_TRUE) &&
(strcmp(utf8, "3\xc3\xb7") == 0) && (length == 3));
assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string);
assert(!qpdf_oh_is_name_and_equals(qpdf, p_string, "3\xf7"));
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_string), "string") == 0);
assert(qpdf_oh_is_dictionary(qpdf, p_dict));
qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four");
assert(qpdf_oh_is_or_has_name(qpdf, p_five, "/Five"));
assert(!qpdf_oh_is_name_and_equals(qpdf, p_five, "/Five"));
assert(qpdf_oh_is_or_has_name(qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
assert(qpdf_oh_is_name_and_equals(qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
assert(qpdf_oh_is_null(qpdf, p_null));
assert(qpdf_oh_get_type_code(qpdf, p_null) == ot_null);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0);
assert(qpdf_oh_is_bool(qpdf, p_bool) && (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE));
QPDF_BOOL b = QPDF_FALSE;
assert((qpdf_oh_get_value_as_bool(qpdf, p_int, &b) == QPDF_FALSE) && b == QPDF_FALSE);
assert((qpdf_oh_get_value_as_bool(qpdf, p_bool, &b) == QPDF_TRUE) && b == QPDF_TRUE);
assert((qpdf_oh_get_value_as_bool(qpdf, p_bool_f, &b) == QPDF_TRUE) && b == QPDF_FALSE);
assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0);
const char* n = "";
length = 0;
assert(
(qpdf_oh_get_value_as_name(qpdf, p_string, &n, &length) == QPDF_FALSE) &&
(strcmp(n, "") == 0) && (length == 0));
assert(
(qpdf_oh_get_value_as_name(qpdf, p_name, &n, &length) == QPDF_TRUE) &&
(strcmp(n, "/Six") == 0) && (length == 4));
qpdf_oh_erase_item(qpdf, parsed, 4);
qpdf_oh_insert_item(
qpdf,
parsed,
2,
qpdf_oh_parse(qpdf, "<</A 1 /B 2 /C 3 /D 4 /Type /Test /Subtype /Marvin>>"));
qpdf_oh new_dict = qpdf_oh_get_array_item(qpdf, parsed, 2);
assert(qpdf_oh_has_key(qpdf, new_dict, "/A"));
assert(qpdf_oh_has_key(qpdf, new_dict, "/D"));
assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", ""));
assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", 0));
assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/Marvin"));
assert(!qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test2", ""));
assert(!qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/M"));
assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "", ""));
qpdf_oh new_array = qpdf_oh_new_array(qpdf);
qpdf_oh_replace_or_remove_key(qpdf, new_dict, "/A", qpdf_oh_new_null(qpdf));
qpdf_oh_replace_or_remove_key(qpdf, new_dict, "/B", new_array);
qpdf_oh_replace_key(qpdf, new_dict, "/C", qpdf_oh_new_dictionary(qpdf));
qpdf_oh_remove_key(qpdf, new_dict, "/D");
assert(!qpdf_oh_has_key(qpdf, new_dict, "/A"));
assert(!qpdf_oh_has_key(qpdf, new_dict, "/D"));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_string(qpdf, "potato"));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_unicode_string(qpdf, "qww\xc3\xb7\xcf\x80"));
qpdf_oh_append_item(
qpdf, new_array, qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 2 */
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 3 */
qpdf_oh_set_array_item(qpdf, new_array, 3, qpdf_oh_new_name(qpdf, "/Quack"));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_real_from_double(qpdf, 4.123, 2));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_real_from_string(qpdf, "5.0"));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_integer(qpdf, 6));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_bool(qpdf, QPDF_TRUE));
qpdf_oh_replace_key(qpdf, root, "/QTest", new_dict);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test26(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Make sure we detect uninitialized objects */
qpdf_data qpdf2 = qpdf_init();
qpdf_oh trailer = qpdf_get_trailer(qpdf2);
assert(!qpdf_oh_is_initialized(qpdf2, trailer));
assert(qpdf_oh_get_type_code(qpdf, trailer) == ot_uninitialized);
qpdf_cleanup(&qpdf2);
}
static void
test27(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Exercise a string with a null. Since the regular methods return
* char*, we can't see past the null character without looking
* explicitly at the length.
*/
qpdf_oh p_string_with_null = qpdf_oh_parse(qpdf, "<6f6e650074776f>");
assert(qpdf_oh_is_string(qpdf, p_string_with_null));
assert(strcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one") == 0);
assert(qpdf_get_last_string_length(qpdf) == 7);
/* memcmp adds a character to verify the trailing null */
assert(memcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one\000two", 8) == 0);
size_t length = 0;
p_string_with_null = qpdf_oh_new_binary_string(qpdf, "potato\000salad", 12);
/* memcmp adds a character to verify the trailing null */
assert(
memcmp(
qpdf_oh_get_binary_string_value(qpdf, p_string_with_null, &length),
"potato\000salad",
13) == 0);
assert(qpdf_get_last_string_length(qpdf) == 12);
assert(length == 12);
/* repeat for UTF8 string */
qpdf_oh p_utf8_string_with_null = qpdf_oh_parse(qpdf, "<feff007100770000007700f703c0>");
assert(qpdf_oh_is_string(qpdf, p_utf8_string_with_null));
assert(
strcmp(qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), "qw\x00w\xc3\xb7\xcf\x80") ==
0);
assert(qpdf_get_last_string_length(qpdf) == 8);
/* memcmp adds a character to verify the trailing null */
assert(
memcmp(
qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), "qw\x00w\xc3\xb7\xcf\x80", 8) ==
0);
p_utf8_string_with_null = qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8);
/* memcmp adds a character to verify the trailing null */
assert(
memcmp(
qpdf_oh_get_binary_utf8_value(qpdf, p_utf8_string_with_null, &length),
"qw\x00w\xc3\xb7\xcf\x80",
9) == 0);
assert(qpdf_get_last_string_length(qpdf) == 8);
assert(length == 8);
}
static void
test28(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
/* Look at the media box. The media box is in array. Trivially
* wrap it and also clone it and make sure we get different
* handles with the same contents.
*/
qpdf_read(qpdf, infile, password);
qpdf_oh root = qpdf_get_root(qpdf);
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
qpdf_oh page1 = qpdf_oh_get_array_item(qpdf, kids, 0);
qpdf_oh mediabox = qpdf_oh_get_key(qpdf, page1, "/MediaBox");
qpdf_oh wrapped_mediabox = qpdf_oh_wrap_in_array(qpdf, mediabox);
qpdf_oh cloned_mediabox = qpdf_oh_new_object(qpdf, mediabox);
assert(wrapped_mediabox != mediabox);
assert(cloned_mediabox != mediabox);
assert(qpdf_oh_get_array_n_items(qpdf, wrapped_mediabox) == 4);
for (int i = 0; i < 4; ++i) {
qpdf_oh item = qpdf_oh_get_array_item(qpdf, mediabox, i);
qpdf_oh item2 = qpdf_oh_get_array_item(qpdf, wrapped_mediabox, i);
qpdf_oh item3 = qpdf_oh_get_array_item(qpdf, cloned_mediabox, i);
assert(
qpdf_oh_get_int_value_as_int(qpdf, item) ==
(i == 0 ? 0
: i == 1 ? 0
: i == 2 ? 612
: i == 3 ? 792
: -1));
assert(
qpdf_oh_get_int_value_as_int(qpdf, item) == qpdf_oh_get_int_value_as_int(qpdf, item2));
assert(
qpdf_oh_get_int_value_as_int(qpdf, item) == qpdf_oh_get_int_value_as_int(qpdf, item3));
qpdf_oh_release(qpdf, item);
}
}
static void
test29(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Trap exceptions thrown by object accessors. Type mismatches are
* errors rather than warnings when they don't have an owning QPDF
* object.
*/
qpdf_silence_errors(qpdf);
/* get_root fails when we have no trailer */
qpdf_oh root = qpdf_get_root(qpdf);
handle_oh_error(qpdf, "get root");
assert(root != 0);
assert(!qpdf_oh_is_initialized(qpdf, root));
assert(!qpdf_oh_is_initialized(qpdf, qpdf_oh_parse(qpdf, "[oops")));
handle_oh_error(qpdf, "bad parse");
report_errors();
assert(qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_new_string(qpdf, "x")) == 0);
handle_oh_error(qpdf, "type mismatch (int operation on string)");
qpdf_oh int_oh = qpdf_oh_new_integer(qpdf, 12);
assert(strlen(qpdf_oh_get_string_value(qpdf, int_oh)) == 0);
handle_oh_error(qpdf, "type mismatch (string operation on int)");
// This doesn't test every possible error flow, but it tests each
// way of handling errors in the library code.
assert(qpdf_oh_get_array_n_items(qpdf, int_oh) == 0);
handle_oh_error(qpdf, "array type mismatch - n_items");
assert(qpdf_oh_is_null(qpdf, qpdf_oh_get_array_item(qpdf, int_oh, 3)));
handle_oh_error(qpdf, "array type mismatch - item");
qpdf_oh_append_item(qpdf, int_oh, qpdf_oh_new_null(qpdf));
handle_oh_error(qpdf, "append to non-array");
qpdf_oh array = qpdf_oh_new_array(qpdf);
assert(qpdf_oh_is_null(qpdf, qpdf_oh_get_array_item(qpdf, array, 3)));
handle_oh_error(qpdf, "array bounds");
qpdf_oh_begin_dict_key_iter(qpdf, int_oh);
assert(qpdf_oh_dict_more_keys(qpdf) == QPDF_FALSE);
handle_oh_error(qpdf, "dictionary iter type mismatch");
assert(qpdf_oh_is_null(qpdf, qpdf_oh_get_key(qpdf, int_oh, "potato")));
handle_oh_error(qpdf, "dictionary type mismatch");
assert(qpdf_oh_has_key(qpdf, int_oh, "potato") == QPDF_FALSE);
handle_oh_error(qpdf, "dictionary type mismatch");
report_errors();
}
static void
test30(char const* infile, char const* password, char const* outfile, char const* xarg)
{
assert(qpdf_read(qpdf, infile, password) & QPDF_ERRORS);
/* Fail to handle error */
}
static void
test31(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Make sure type warnings have a specific error code. This test
* case is designed for minimal.pdf.
*/
qpdf_read(qpdf, infile, password);
qpdf_oh trailer = qpdf_get_trailer(qpdf);
assert(qpdf_oh_get_int_value(qpdf, trailer) == 0LL);
assert(!qpdf_has_error(qpdf));
assert(qpdf_more_warnings(qpdf));
qpdf_error e = qpdf_next_warning(qpdf);
assert(qpdf_get_error_code(qpdf, e) == qpdf_e_object);
report_errors();
}
static void
test32(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_oh page = qpdf_get_object_by_id(qpdf, 3, 0);
assert(qpdf_oh_is_dictionary(qpdf, page));
assert(qpdf_oh_has_key(qpdf, page, "/MediaBox"));
report_errors();
}
static void
test33(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
/* Convert a direct object to an indirect object and replace it. */
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_oh root = qpdf_get_root(qpdf);
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
qpdf_oh page1 = qpdf_oh_get_array_item(qpdf, kids, 0);
qpdf_oh mediabox = qpdf_oh_get_key(qpdf, page1, "/MediaBox");
assert(!qpdf_oh_is_indirect(qpdf, mediabox));
qpdf_oh i_mediabox = qpdf_make_indirect_object(qpdf, mediabox);
assert(qpdf_oh_is_indirect(qpdf, i_mediabox));
qpdf_oh_replace_key(qpdf, page1, "/MediaBox", i_mediabox);
/* Replace a different indirect object */
qpdf_oh resources = qpdf_oh_get_key(qpdf, page1, "/Resources");
qpdf_oh procset = qpdf_oh_get_key(qpdf, resources, "/ProcSet");
assert(qpdf_oh_is_indirect(qpdf, procset));
qpdf_replace_object(
qpdf,
qpdf_oh_get_object_id(qpdf, procset),
qpdf_oh_get_generation(qpdf, procset),
qpdf_oh_parse(qpdf, "[/PDF]"));
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test34(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */
/* Non-error cases for page API */
qpdf_data qpdf2 = qpdf_init();
assert(qpdf_read(qpdf, infile, password) == 0);
assert(qpdf_read(qpdf2, xarg, "") == 0);
assert(qpdf_get_num_pages(qpdf) == 11);
assert(qpdf_get_num_pages(qpdf2) == 1);
/* At this time, there is no C API for accessing stream data, so
* we hard-code object IDs from a known input file.
*/
assert(qpdf_oh_get_object_id(qpdf, qpdf_get_page_n(qpdf, 0)) == 4);
assert(qpdf_oh_get_object_id(qpdf, qpdf_get_page_n(qpdf, 10)) == 14);
qpdf_oh page3 = qpdf_get_page_n(qpdf, 3);
assert(qpdf_find_page_by_oh(qpdf, page3) == 3);
assert(qpdf_find_page_by_id(qpdf, qpdf_oh_get_object_id(qpdf, page3), 0) == 3);
/* Add other page to the end */
qpdf_oh opage0 = qpdf_get_page_n(qpdf2, 0);
assert(qpdf_add_page(qpdf, qpdf2, opage0, QPDF_FALSE) == 0);
/* Add other page before page 3 */
assert(qpdf_add_page_at(qpdf, qpdf2, opage0, QPDF_TRUE, page3) == 0);
/* Remove page 3 */
assert(qpdf_remove_page(qpdf, page3) == 0);
/* At page 3 back at the beginning */
assert(qpdf_add_page(qpdf, qpdf, page3, QPDF_TRUE) == 0);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
qpdf_cleanup(&qpdf2);
}
static void
test35(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test uses 11-pages.pdf */
assert(qpdf_get_num_pages(qpdf) == -1);
assert(qpdf_has_error(qpdf));
qpdf_error e = qpdf_get_error(qpdf);
assert(qpdf_get_error_code(qpdf, e) != QPDF_SUCCESS);
assert(!qpdf_has_error(qpdf));
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_oh range = qpdf_get_page_n(qpdf, 11);
assert(!qpdf_oh_is_initialized(qpdf, range));
assert(qpdf_has_error(qpdf));
e = qpdf_get_error(qpdf);
assert(qpdf_get_error_code(qpdf, e) != QPDF_SUCCESS);
assert(!qpdf_has_error(qpdf));
assert(qpdf_find_page_by_id(qpdf, 100, 0) == -1);
assert(qpdf_has_error(qpdf));
e = qpdf_get_error(qpdf);
assert(qpdf_get_error_code(qpdf, e) != QPDF_SUCCESS);
assert(!qpdf_has_error(qpdf));
assert(qpdf_find_page_by_oh(qpdf, qpdf_get_root(qpdf)) == -1);
assert(qpdf_more_warnings(qpdf));
e = qpdf_next_warning(qpdf);
assert(qpdf_get_error_code(qpdf, e) != QPDF_SUCCESS);
assert(qpdf_has_error(qpdf));
e = qpdf_get_error(qpdf);
assert(qpdf_get_error_code(qpdf, e) != QPDF_SUCCESS);
assert(!qpdf_has_error(qpdf));
assert(qpdf_find_page_by_id(qpdf, 100, 0) == -1);
assert(qpdf_has_error(qpdf));
e = qpdf_get_error(qpdf);
assert(qpdf_get_error_code(qpdf, e) != QPDF_SUCCESS);
assert(!qpdf_has_error(qpdf));
assert(qpdf_add_page(qpdf, qpdf, 1000, QPDF_FALSE) != 0);
report_errors();
}
static void
test36(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test uses inherited-rotate.pdf */
assert(qpdf_read(qpdf, infile, password) == 0);
/* Non-trivially push inherited attributes */
qpdf_oh page0 = qpdf_get_object_by_id(qpdf, 3, 0);
assert(qpdf_oh_is_dictionary(qpdf, page0));
qpdf_oh r = qpdf_oh_get_key(qpdf, page0, "/Rotate");
assert(qpdf_oh_get_int_value(qpdf, r) == 90);
qpdf_oh_remove_key(qpdf, page0, "/Rotate");
assert(!qpdf_oh_has_key(qpdf, page0, "/Rotate"));
assert(qpdf_push_inherited_attributes_to_page(qpdf) == 0);
r = qpdf_oh_get_key(qpdf, page0, "/Rotate");
assert(qpdf_oh_get_int_value(qpdf, r) == 270);
assert(qpdf_add_page(qpdf, qpdf, page0, QPDF_TRUE) == 0);
}
static void
test37(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test uses 11-pages.pdf */
/* Manually manipulate pages tree */
assert(qpdf_read(qpdf, infile, password) == 0);
assert(qpdf_get_num_pages(qpdf) == 11);
qpdf_oh pages = qpdf_get_object_by_id(qpdf, 3, 0);
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
assert(qpdf_oh_get_array_n_items(qpdf, kids) == 11);
qpdf_oh_erase_item(qpdf, kids, 0);
assert(qpdf_get_num_pages(qpdf) == 11);
assert(qpdf_update_all_pages_cache(qpdf) == 0);
assert(qpdf_get_num_pages(qpdf) == 10);
}
static void
test38(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects 11-pages.pdf. */
/* Read stream data */
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_oh stream = qpdf_get_object_by_id(qpdf, 17, 0);
qpdf_oh dict = qpdf_oh_get_dict(qpdf, stream);
assert(qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_get_key(qpdf, dict, "/Length")) == 53);
/* Get raw data */
unsigned char* buf = 0;
size_t len = 0;
assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) == 0);
assert(len == 53);
assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234));
free(buf);
/* Test whether filterable */
QPDF_BOOL filtered = QPDF_FALSE;
assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, &filtered, 0, 0) == 0);
assert(filtered == QPDF_TRUE);
/* Get filtered data */
assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, 0, &buf, &len) == 0);
assert(len == 47);
assert(memcmp((char const*)buf, "BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET\n", len) == 0);
/* Get page data */
qpdf_oh page2 = qpdf_get_page_n(qpdf, 1); /* 0-based index */
unsigned char* buf2 = 0;
assert(qpdf_oh_get_page_content_data(qpdf, page2, &buf2, &len) == 0);
assert(len == 47);
assert(memcmp(buf, buf2, len) == 0);
free(buf);
free(buf2);
/* errors */
printf("page content on broken page\n");
qpdf_oh_replace_key(qpdf, page2, "/Contents", qpdf_oh_new_integer(qpdf, 3));
buf = 0;
qpdf_oh_get_page_content_data(qpdf, page2, &buf, &len);
assert(buf == 0);
report_errors();
printf("stream data for non stream\n");
qpdf_oh root = qpdf_get_root(qpdf);
assert(qpdf_oh_get_stream_data(qpdf, root, qpdf_dl_all, 0, 0, 0) != 0);
report_errors();
}
static void
test39(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */
/* Foreign object */
qpdf_data qpdf2 = qpdf_init();
assert(qpdf_read(qpdf, infile, password) == 0);
assert(qpdf_read(qpdf2, xarg, "") == 0);
qpdf_oh resources = qpdf_get_object_by_id(qpdf2, 3, 0);
qpdf_oh copy = qpdf_oh_copy_foreign_object(qpdf, qpdf2, resources);
qpdf_oh root = qpdf_get_root(qpdf);
qpdf_oh_replace_key(qpdf, root, "/Copy", copy);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
qpdf_cleanup(&qpdf2);
}
static void
test40(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects minimal.pdf. */
/* New stream */
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_oh stream = qpdf_oh_new_stream(qpdf);
qpdf_oh_replace_stream_data(
qpdf,
stream,
(unsigned char*)"12345\000abcde",
11, /* embedded null */
qpdf_oh_new_null(qpdf),
qpdf_oh_new_null(qpdf));
qpdf_oh root = qpdf_get_root(qpdf);
qpdf_oh_replace_key(qpdf, root, "/Potato", stream);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test41(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Empty PDF -- infile is ignored */
assert(qpdf_empty_pdf(qpdf) == 0);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test42(char const* infile, char const* password, char const* outfile, char const* xarg)
{
assert(qpdf_create_from_json_file(qpdf, infile) == QPDF_SUCCESS);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test43(char const* infile, char const* password, char const* outfile, char const* xarg)
{
char* buf = NULL;
unsigned long size = 0;
read_file_into_memory(infile, &buf, &size);
assert(qpdf_create_from_json_data(qpdf, buf, size) == QPDF_SUCCESS);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
free(buf);
}
static void
test44(char const* infile, char const* password, char const* outfile, char const* xarg)
{
assert(qpdf_read(qpdf, infile, password) == 0);
assert(qpdf_update_from_json_file(qpdf, xarg) == QPDF_SUCCESS);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void
test45(char const* infile, char const* password, char const* outfile, char const* xarg)
{
char* buf = NULL;
unsigned long size = 0;
read_file_into_memory(xarg, &buf, &size);
assert(qpdf_read(qpdf, infile, password) == 0);
assert(qpdf_update_from_json_data(qpdf, buf, size) == QPDF_SUCCESS);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
free(buf);
}
static void
test46(char const* infile, char const* password, char const* outfile, char const* xarg)
{
FILE* f = safe_fopen(outfile, "wb");
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_write_json(qpdf, 2, write_to_file, f, qpdf_dl_none, qpdf_sj_inline, "", NULL);
fclose(f);
report_errors();
}
static void
test47(char const* infile, char const* password, char const* outfile, char const* xarg)
{
FILE* f = safe_fopen(outfile, "wb");
assert(qpdf_read(qpdf, infile, password) == 0);
char const* wanted_objects[] = {"obj:4 0 R", "trailer", NULL};
qpdf_write_json(
qpdf, 2, write_to_file, f, qpdf_dl_specialized, qpdf_sj_file, xarg, wanted_objects);
fclose(f);
report_errors();
}
int
main(int argc, char* argv[])
{
char* p = 0;
int n = 0;
char const* infile = 0;
char const* password = 0;
char const* outfile = 0;
char const* xarg = 0;
void (*fn)(char const*, char const*, char const*, char const*) = 0;
if ((p = strrchr(argv[0], '/')) != NULL) {
whoami = p + 1;
} else if ((p = strrchr(argv[0], '\\')) != NULL) {
whoami = p + 1;
} else {
whoami = argv[0];
}
if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
printf("qpdf-ctest version %s\n", qpdf_get_qpdf_version());
return 0;
}
if (argc < 5) {
fprintf(stderr, "usage: %s n infile password outfile\n", whoami);
exit(2);
}
n = atoi(argv[1]);
infile = argv[2];
password = argv[3];
outfile = argv[4];
xarg = (argc > 5 ? argv[5] : 0);
fn =
((n == 1) ? test01
: (n == 2) ? test02
: (n == 3) ? test03
: (n == 4) ? test04
: (n == 5) ? test05
: (n == 6) ? test06
: (n == 7) ? test07
: (n == 8) ? test08
: (n == 9) ? test09
: (n == 10) ? test10
: (n == 11) ? test11
: (n == 12) ? test12
: (n == 13) ? test13
: (n == 14) ? test14
: (n == 15) ? test15
: (n == 16) ? test16
: (n == 17) ? test17
: (n == 18) ? test18
: (n == 19) ? test19
: (n == 20) ? test20
: (n == 21) ? test21
: (n == 22) ? test22
: (n == 23) ? test23
: (n == 24) ? test24
: (n == 25) ? test25
: (n == 26) ? test26
: (n == 27) ? test27
: (n == 28) ? test28
: (n == 29) ? test29
: (n == 30) ? test30
: (n == 31) ? test31
: (n == 32) ? test32
: (n == 33) ? test33
: (n == 34) ? test34
: (n == 35) ? test35
: (n == 36) ? test36
: (n == 37) ? test37
: (n == 38) ? test38
: (n == 39) ? test39
: (n == 40) ? test40
: (n == 41) ? test41
: (n == 42) ? test42
: (n == 43) ? test43
: (n == 44) ? test44
: (n == 45) ? test45
: (n == 46) ? test46
: (n == 47) ? test47
: 0);
if (fn == 0) {
fprintf(stderr, "%s: invalid test number %d\n", whoami, n);
exit(2);
}
qpdf = qpdf_init();
fn(infile, password, outfile, xarg);
qpdf_cleanup(&qpdf);
assert(qpdf == 0);
printf("C test %d done\n", n);
return 0;
}
|
cf6a5d77a669b2b24381af82ca41ac5f49be94ec
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/media/dvb-frontends/au8522_decoder.c
|
2099f21e374d6cdf4388d66e8adbc2da43460271
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 26,427
|
c
|
au8522_decoder.c
|
/*
* Auvitek AU8522 QAM/8VSB demodulator driver and video decoder
*
* Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
* Copyright (C) 2005-2008 Auvitek International, Ltd.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/* Developer notes:
*
* VBI support is not yet working
* Enough is implemented here for CVBS and S-Video inputs, but the actual
* analog demodulator code isn't implemented (not needed for xc5000 since it
* has its own demodulator and outputs CVBS)
*
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <media/v4l2-common.h>
#include <media/v4l2-chip-ident.h>
#include <media/v4l2-device.h>
#include "au8522.h"
#include "au8522_priv.h"
MODULE_AUTHOR("Devin Heitmueller");
MODULE_LICENSE("GPL");
static int au8522_analog_debug;
module_param_named(analog_debug, au8522_analog_debug, int, 0644);
MODULE_PARM_DESC(analog_debug,
"Analog debugging messages [0=Off (default) 1=On]");
struct au8522_register_config {
u16 reg_name;
u8 reg_val[8];
};
/* Video Decoder Filter Coefficients
The values are as follows from left to right
0="ATV RF" 1="ATV RF13" 2="CVBS" 3="S-Video" 4="PAL" 5=CVBS13" 6="SVideo13"
*/
static const struct au8522_register_config filter_coef[] = {
{AU8522_FILTER_COEF_R410, {0x25, 0x00, 0x25, 0x25, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R411, {0x20, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R412, {0x03, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R413, {0xe6, 0x00, 0xe6, 0xe6, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R414, {0x40, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R415, {0x1b, 0x00, 0x1b, 0x1b, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R416, {0xc0, 0x00, 0xc0, 0x04, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R417, {0x04, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R418, {0x8c, 0x00, 0x8c, 0x8c, 0x00, 0x00, 0x00} },
{AU8522_FILTER_COEF_R419, {0xa0, 0x40, 0xa0, 0xa0, 0x40, 0x40, 0x40} },
{AU8522_FILTER_COEF_R41A, {0x21, 0x09, 0x21, 0x21, 0x09, 0x09, 0x09} },
{AU8522_FILTER_COEF_R41B, {0x6c, 0x38, 0x6c, 0x6c, 0x38, 0x38, 0x38} },
{AU8522_FILTER_COEF_R41C, {0x03, 0xff, 0x03, 0x03, 0xff, 0xff, 0xff} },
{AU8522_FILTER_COEF_R41D, {0xbf, 0xc7, 0xbf, 0xbf, 0xc7, 0xc7, 0xc7} },
{AU8522_FILTER_COEF_R41E, {0xa0, 0xdf, 0xa0, 0xa0, 0xdf, 0xdf, 0xdf} },
{AU8522_FILTER_COEF_R41F, {0x10, 0x06, 0x10, 0x10, 0x06, 0x06, 0x06} },
{AU8522_FILTER_COEF_R420, {0xae, 0x30, 0xae, 0xae, 0x30, 0x30, 0x30} },
{AU8522_FILTER_COEF_R421, {0xc4, 0x01, 0xc4, 0xc4, 0x01, 0x01, 0x01} },
{AU8522_FILTER_COEF_R422, {0x54, 0xdd, 0x54, 0x54, 0xdd, 0xdd, 0xdd} },
{AU8522_FILTER_COEF_R423, {0xd0, 0xaf, 0xd0, 0xd0, 0xaf, 0xaf, 0xaf} },
{AU8522_FILTER_COEF_R424, {0x1c, 0xf7, 0x1c, 0x1c, 0xf7, 0xf7, 0xf7} },
{AU8522_FILTER_COEF_R425, {0x76, 0xdb, 0x76, 0x76, 0xdb, 0xdb, 0xdb} },
{AU8522_FILTER_COEF_R426, {0x61, 0xc0, 0x61, 0x61, 0xc0, 0xc0, 0xc0} },
{AU8522_FILTER_COEF_R427, {0xd1, 0x2f, 0xd1, 0xd1, 0x2f, 0x2f, 0x2f} },
{AU8522_FILTER_COEF_R428, {0x84, 0xd8, 0x84, 0x84, 0xd8, 0xd8, 0xd8} },
{AU8522_FILTER_COEF_R429, {0x06, 0xfb, 0x06, 0x06, 0xfb, 0xfb, 0xfb} },
{AU8522_FILTER_COEF_R42A, {0x21, 0xd5, 0x21, 0x21, 0xd5, 0xd5, 0xd5} },
{AU8522_FILTER_COEF_R42B, {0x0a, 0x3e, 0x0a, 0x0a, 0x3e, 0x3e, 0x3e} },
{AU8522_FILTER_COEF_R42C, {0xe6, 0x15, 0xe6, 0xe6, 0x15, 0x15, 0x15} },
{AU8522_FILTER_COEF_R42D, {0x01, 0x34, 0x01, 0x01, 0x34, 0x34, 0x34} },
};
#define NUM_FILTER_COEF (sizeof(filter_coef)\
/ sizeof(struct au8522_register_config))
/* Registers 0x060b through 0x0652 are the LP Filter coefficients
The values are as follows from left to right
0="SIF" 1="ATVRF/ATVRF13"
Note: the "ATVRF/ATVRF13" mode has never been tested
*/
static const struct au8522_register_config lpfilter_coef[] = {
{0x060b, {0x21, 0x0b} },
{0x060c, {0xad, 0xad} },
{0x060d, {0x70, 0xf0} },
{0x060e, {0xea, 0xe9} },
{0x060f, {0xdd, 0xdd} },
{0x0610, {0x08, 0x64} },
{0x0611, {0x60, 0x60} },
{0x0612, {0xf8, 0xb2} },
{0x0613, {0x01, 0x02} },
{0x0614, {0xe4, 0xb4} },
{0x0615, {0x19, 0x02} },
{0x0616, {0xae, 0x2e} },
{0x0617, {0xee, 0xc5} },
{0x0618, {0x56, 0x56} },
{0x0619, {0x30, 0x58} },
{0x061a, {0xf9, 0xf8} },
{0x061b, {0x24, 0x64} },
{0x061c, {0x07, 0x07} },
{0x061d, {0x30, 0x30} },
{0x061e, {0xa9, 0xed} },
{0x061f, {0x09, 0x0b} },
{0x0620, {0x42, 0xc2} },
{0x0621, {0x1d, 0x2a} },
{0x0622, {0xd6, 0x56} },
{0x0623, {0x95, 0x8b} },
{0x0624, {0x2b, 0x2b} },
{0x0625, {0x30, 0x24} },
{0x0626, {0x3e, 0x3e} },
{0x0627, {0x62, 0xe2} },
{0x0628, {0xe9, 0xf5} },
{0x0629, {0x99, 0x19} },
{0x062a, {0xd4, 0x11} },
{0x062b, {0x03, 0x04} },
{0x062c, {0xb5, 0x85} },
{0x062d, {0x1e, 0x20} },
{0x062e, {0x2a, 0xea} },
{0x062f, {0xd7, 0xd2} },
{0x0630, {0x15, 0x15} },
{0x0631, {0xa3, 0xa9} },
{0x0632, {0x1f, 0x1f} },
{0x0633, {0xf9, 0xd1} },
{0x0634, {0xc0, 0xc3} },
{0x0635, {0x4d, 0x8d} },
{0x0636, {0x21, 0x31} },
{0x0637, {0x83, 0x83} },
{0x0638, {0x08, 0x8c} },
{0x0639, {0x19, 0x19} },
{0x063a, {0x45, 0xa5} },
{0x063b, {0xef, 0xec} },
{0x063c, {0x8a, 0x8a} },
{0x063d, {0xf4, 0xf6} },
{0x063e, {0x8f, 0x8f} },
{0x063f, {0x44, 0x0c} },
{0x0640, {0xef, 0xf0} },
{0x0641, {0x66, 0x66} },
{0x0642, {0xcc, 0xd2} },
{0x0643, {0x41, 0x41} },
{0x0644, {0x63, 0x93} },
{0x0645, {0x8e, 0x8e} },
{0x0646, {0xa2, 0x42} },
{0x0647, {0x7b, 0x7b} },
{0x0648, {0x04, 0x04} },
{0x0649, {0x00, 0x00} },
{0x064a, {0x40, 0x40} },
{0x064b, {0x8c, 0x98} },
{0x064c, {0x00, 0x00} },
{0x064d, {0x63, 0xc3} },
{0x064e, {0x04, 0x04} },
{0x064f, {0x20, 0x20} },
{0x0650, {0x00, 0x00} },
{0x0651, {0x40, 0x40} },
{0x0652, {0x01, 0x01} },
};
#define NUM_LPFILTER_COEF (sizeof(lpfilter_coef)\
/ sizeof(struct au8522_register_config))
static inline struct au8522_state *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct au8522_state, sd);
}
static void setup_vbi(struct au8522_state *state, int aud_input)
{
int i;
/* These are set to zero regardless of what mode we're in */
au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_L_REG018H, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_THRESH1_REG01CH, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H, 0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H,
0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H,
0x00);
au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H,
0x00);
/* Setup the VBI registers */
for (i = 0x30; i < 0x60; i++)
au8522_writereg(state, i, 0x40);
/* For some reason, every register is 0x40 except register 0x44
(confirmed via the HVR-950q USB capture) */
au8522_writereg(state, 0x44, 0x60);
/* Enable VBI (we always do this regardless of whether the user is
viewing closed caption info) */
au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H,
AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON);
}
static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
{
int i;
int filter_coef_type;
/* Provide reasonable defaults for picture tuning values */
au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0x07);
au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0xed);
au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0x79);
au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0x80);
au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0x80);
au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0x00);
au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0x00);
/* Other decoder registers */
au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00);
if (input_mode == 0x23) {
/* S-Video input mapping */
au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x04);
} else {
/* All other modes (CVBS/ATVRF etc.) */
au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x00);
}
au8522_writereg(state, AU8522_TVDEC_PGA_REG012H,
AU8522_TVDEC_PGA_REG012H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_MODE_REG015H,
AU8522_TVDEC_COMB_MODE_REG015H_CVBS);
au8522_writereg(state, AU8522_TVDED_DBG_MODE_REG060H,
AU8522_TVDED_DBG_MODE_REG060H_CVBS);
au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN);
au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC);
au8522_writereg(state, AU8522_TVDEC_VCR_DET_LLIM_REG063H,
AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS);
au8522_writereg(state, AU8522_TVDEC_VCR_DET_HLIM_REG064H,
AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR1_REG065H,
AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR2_REG066H,
AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR3_REG067H,
AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_NOTCH_THR_REG068H,
AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR1_REG069H,
AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR2_REG06AH,
AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO);
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO);
} else {
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS);
}
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH,
AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS);
au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH,
AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H,
AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS);
au8522_writereg(state, AU8522_REG071H, AU8522_REG071H_CVBS);
au8522_writereg(state, AU8522_REG072H, AU8522_REG072H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H,
AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS);
au8522_writereg(state, AU8522_REG074H, AU8522_REG074H_CVBS);
au8522_writereg(state, AU8522_REG075H, AU8522_REG075H_CVBS);
au8522_writereg(state, AU8522_TVDEC_DCAGC_CTRL_REG077H,
AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS);
au8522_writereg(state, AU8522_TVDEC_PIC_START_ADJ_REG078H,
AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS);
au8522_writereg(state, AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H,
AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS);
au8522_writereg(state, AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH,
AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS);
au8522_writereg(state, AU8522_TVDEC_INTRP_CTRL_REG07BH,
AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS);
au8522_writereg(state, AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H,
AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS);
au8522_writereg(state, AU8522_TOREGAAGC_REG0E5H,
AU8522_TOREGAAGC_REG0E5H_CVBS);
au8522_writereg(state, AU8522_REG016H, AU8522_REG016H_CVBS);
setup_vbi(state, 0);
if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
/* Despite what the table says, for the HVR-950q we still need
to be in CVBS mode for the S-Video input (reason unknown). */
/* filter_coef_type = 3; */
filter_coef_type = 5;
} else {
filter_coef_type = 5;
}
/* Load the Video Decoder Filter Coefficients */
for (i = 0; i < NUM_FILTER_COEF; i++) {
au8522_writereg(state, filter_coef[i].reg_name,
filter_coef[i].reg_val[filter_coef_type]);
}
/* It's not clear what these registers are for, but they are always
set to the same value regardless of what mode we're in */
au8522_writereg(state, AU8522_REG42EH, 0x87);
au8522_writereg(state, AU8522_REG42FH, 0xa2);
au8522_writereg(state, AU8522_REG430H, 0xbf);
au8522_writereg(state, AU8522_REG431H, 0xcb);
au8522_writereg(state, AU8522_REG432H, 0xa1);
au8522_writereg(state, AU8522_REG433H, 0x41);
au8522_writereg(state, AU8522_REG434H, 0x88);
au8522_writereg(state, AU8522_REG435H, 0xc2);
au8522_writereg(state, AU8522_REG436H, 0x3c);
}
static void au8522_setup_cvbs_mode(struct au8522_state *state)
{
/* here we're going to try the pre-programmed route */
au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
/* PGA in automatic mode */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
/* Enable clamping control */
au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
setup_decoder_defaults(state, AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
}
static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state)
{
/* here we're going to try the pre-programmed route */
au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
/* It's not clear why we have to have the PGA in automatic mode while
enabling clamp control, but it's what Windows does */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
/* Enable clamping control */
au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e);
/* Disable automatic PGA (since the CVBS is coming from the tuner) */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
/* Set input mode to CVBS on channel 4 with SIF audio input enabled */
au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF);
setup_decoder_defaults(state,
AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
}
static void au8522_setup_svideo_mode(struct au8522_state *state)
{
au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO);
/* Set input to Y on Channe1, C on Channel 3 */
au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
/* PGA in automatic mode */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
/* Enable clamping control */
au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
setup_decoder_defaults(state,
AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
}
/* ----------------------------------------------------------------------- */
static void disable_audio_input(struct au8522_state *state)
{
au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04);
au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO);
}
/* 0=disable, 1=SIF */
static void set_audio_input(struct au8522_state *state, int aud_input)
{
int i;
/* Note that this function needs to be used in conjunction with setting
the input routing via register 0x81 */
if (aud_input == AU8522_AUDIO_NONE) {
disable_audio_input(state);
return;
}
if (aud_input != AU8522_AUDIO_SIF) {
/* The caller asked for a mode we don't currently support */
printk(KERN_ERR "Unsupported audio mode requested! mode=%d\n",
aud_input);
return;
}
/* Load the Audio Decoder Filter Coefficients */
for (i = 0; i < NUM_LPFILTER_COEF; i++) {
au8522_writereg(state, lpfilter_coef[i].reg_name,
lpfilter_coef[i].reg_val[0]);
}
/* Setup audio */
au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80);
au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84);
msleep(150);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x00);
msleep(1);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x9d);
msleep(50);
au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0xff);
msleep(80);
au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO);
au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x82);
msleep(70);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x09);
au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03);
au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0xc2);
}
/* ----------------------------------------------------------------------- */
static int au8522_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct au8522_state *state =
container_of(ctrl->handler, struct au8522_state, hdl);
switch (ctrl->id) {
case V4L2_CID_BRIGHTNESS:
au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH,
ctrl->val - 128);
break;
case V4L2_CID_CONTRAST:
au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH,
ctrl->val);
break;
case V4L2_CID_SATURATION:
au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH,
ctrl->val);
au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH,
ctrl->val);
break;
case V4L2_CID_HUE:
au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH,
ctrl->val >> 8);
au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH,
ctrl->val & 0xFF);
break;
default:
return -EINVAL;
}
return 0;
}
/* ----------------------------------------------------------------------- */
#ifdef CONFIG_VIDEO_ADV_DEBUG
static int au8522_g_register(struct v4l2_subdev *sd,
struct v4l2_dbg_register *reg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct au8522_state *state = to_state(sd);
if (!v4l2_chip_match_i2c_client(client, ®->match))
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
reg->val = au8522_readreg(state, reg->reg & 0xffff);
return 0;
}
static int au8522_s_register(struct v4l2_subdev *sd,
const struct v4l2_dbg_register *reg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct au8522_state *state = to_state(sd);
if (!v4l2_chip_match_i2c_client(client, ®->match))
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
au8522_writereg(state, reg->reg, reg->val & 0xff);
return 0;
}
#endif
static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
{
struct au8522_state *state = to_state(sd);
if (enable) {
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
0x01);
msleep(1);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
} else {
/* This does not completely power down the device
(it only reduces it from around 140ma to 80ma) */
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
1 << 5);
}
return 0;
}
static int au8522_reset(struct v4l2_subdev *sd, u32 val)
{
struct au8522_state *state = to_state(sd);
state->operational_mode = AU8522_ANALOG_MODE;
/* Clear out any state associated with the digital side of the
chip, so that when it gets powered back up it won't think
that it is already tuned */
state->current_frequency = 0;
au8522_writereg(state, 0xa4, 1 << 5);
return 0;
}
static int au8522_s_video_routing(struct v4l2_subdev *sd,
u32 input, u32 output, u32 config)
{
struct au8522_state *state = to_state(sd);
au8522_reset(sd, 0);
if (input == AU8522_COMPOSITE_CH1) {
au8522_setup_cvbs_mode(state);
} else if (input == AU8522_SVIDEO_CH13) {
au8522_setup_svideo_mode(state);
} else if (input == AU8522_COMPOSITE_CH4_SIF) {
au8522_setup_cvbs_tuner_mode(state);
} else {
printk(KERN_ERR "au8522 mode not currently supported\n");
return -EINVAL;
}
return 0;
}
static int au8522_s_audio_routing(struct v4l2_subdev *sd,
u32 input, u32 output, u32 config)
{
struct au8522_state *state = to_state(sd);
set_audio_input(state, input);
return 0;
}
static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
{
int val = 0;
struct au8522_state *state = to_state(sd);
u8 lock_status;
/* Interrogate the decoder to see if we are getting a real signal */
lock_status = au8522_readreg(state, 0x00);
if (lock_status == 0xa2)
vt->signal = 0xffff;
else
vt->signal = 0x00;
vt->capability |=
V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
val = V4L2_TUNER_SUB_MONO;
vt->rxsubchans = val;
vt->audmode = V4L2_TUNER_MODE_STEREO;
return 0;
}
static int au8522_g_chip_ident(struct v4l2_subdev *sd,
struct v4l2_dbg_chip_ident *chip)
{
struct au8522_state *state = to_state(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev);
}
/* ----------------------------------------------------------------------- */
static const struct v4l2_subdev_core_ops au8522_core_ops = {
.log_status = v4l2_ctrl_subdev_log_status,
.g_chip_ident = au8522_g_chip_ident,
.reset = au8522_reset,
#ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = au8522_g_register,
.s_register = au8522_s_register,
#endif
};
static const struct v4l2_subdev_tuner_ops au8522_tuner_ops = {
.g_tuner = au8522_g_tuner,
};
static const struct v4l2_subdev_audio_ops au8522_audio_ops = {
.s_routing = au8522_s_audio_routing,
};
static const struct v4l2_subdev_video_ops au8522_video_ops = {
.s_routing = au8522_s_video_routing,
.s_stream = au8522_s_stream,
};
static const struct v4l2_subdev_ops au8522_ops = {
.core = &au8522_core_ops,
.tuner = &au8522_tuner_ops,
.audio = &au8522_audio_ops,
.video = &au8522_video_ops,
};
static const struct v4l2_ctrl_ops au8522_ctrl_ops = {
.s_ctrl = au8522_s_ctrl,
};
/* ----------------------------------------------------------------------- */
static int au8522_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct au8522_state *state;
struct v4l2_ctrl_handler *hdl;
struct v4l2_subdev *sd;
int instance;
struct au8522_config *demod_config;
/* Check if the adapter supports the needed features */
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE_DATA)) {
return -EIO;
}
/* allocate memory for the internal state */
instance = au8522_get_state(&state, client->adapter, client->addr);
switch (instance) {
case 0:
printk(KERN_ERR "au8522_decoder allocation failed\n");
return -EIO;
case 1:
/* new demod instance */
printk(KERN_INFO "au8522_decoder creating new instance...\n");
break;
default:
/* existing demod instance */
printk(KERN_INFO "au8522_decoder attach existing instance.\n");
break;
}
demod_config = kzalloc(sizeof(struct au8522_config), GFP_KERNEL);
if (demod_config == NULL) {
if (instance == 1)
kfree(state);
return -ENOMEM;
}
demod_config->demod_address = 0x8e >> 1;
state->config = demod_config;
state->i2c = client->adapter;
sd = &state->sd;
v4l2_i2c_subdev_init(sd, client, &au8522_ops);
hdl = &state->hdl;
v4l2_ctrl_handler_init(hdl, 4);
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0, 255, 1, 109);
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_CONTRAST, 0, 255, 1,
AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_SATURATION, 0, 255, 1, 128);
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_HUE, -32768, 32767, 1, 0);
sd->ctrl_handler = hdl;
if (hdl->error) {
int err = hdl->error;
v4l2_ctrl_handler_free(hdl);
kfree(demod_config);
kfree(state);
return err;
}
state->c = client;
state->vid_input = AU8522_COMPOSITE_CH1;
state->aud_input = AU8522_AUDIO_NONE;
state->id = 8522;
state->rev = 0;
/* Jam open the i2c gate to the tuner */
au8522_writereg(state, 0x106, 1);
return 0;
}
static int au8522_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
v4l2_device_unregister_subdev(sd);
v4l2_ctrl_handler_free(sd->ctrl_handler);
au8522_release_state(to_state(sd));
return 0;
}
static const struct i2c_device_id au8522_id[] = {
{"au8522", 0},
{}
};
MODULE_DEVICE_TABLE(i2c, au8522_id);
static struct i2c_driver au8522_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "au8522",
},
.probe = au8522_probe,
.remove = au8522_remove,
.id_table = au8522_id,
};
module_i2c_driver(au8522_driver);
|
eed7d8cc5453bf058a2d559a6bac91f10d5cb23e
|
f8c0a188d1cf8ae5221c4cd11552c221a86e259a
|
/Firmware/Flux.AX3/include/Peripherals/ADC MCP3421.h
|
bc19bb1a1ed91bf745d45f937d293d15d5ab1888
|
[
"CC-BY-3.0",
"BSD-2-Clause"
] |
permissive
|
digitalinteraction/openmovement
|
6310abf35b379655073485e84719cc2521733c0e
|
9c2ee2eeb5eae457673e60699b2842c6df82abb1
|
refs/heads/master
| 2023-08-03T23:48:42.973605
| 2023-07-26T17:52:37
| 2023-07-26T17:52:37
| 27,082,024
| 135
| 86
| null | 2018-06-21T23:32:43
| 2014-11-24T15:38:43
|
C
|
UTF-8
|
C
| false
| false
| 1,131
|
h
|
ADC MCP3421.h
|
// Device driver for the MCP3421 18 bit I2C ADC
// KL 20-01-2012
#ifndef ADC_MCP3421_H
#define ADC_MCP3421_H
// Device defines for init function, use logical OR
#define MCP3421_START_SAMPLE 0x80
#define MCP3421_SAMPLE_nREADY 0x80
#define MCP3421_CONTINUOUS_CONVERSION 0x10
#define MCP3421_SAMPLE_12BIT_4MS 0x00
#define MCP3421_SAMPLE_14BIT_17MS 0x04
#define MCP3421_SAMPLE_16BIT_67MS 0x08
#define MCP3421_SAMPLE_18BIT_267MS 0x0C
#define MCP3421_GAIN_1 0x00
#define MCP3421_GAIN_2 0x01
#define MCP3421_GAIN_4 0x02
#define MCP3421_GAIN_8 0x03
// Default: Useful for thermocouple measurements
#define MCP3421_DEFAULT (MCP3421_SAMPLE_18BIT_267MS | MCP3421_GAIN_8)
// Initialise the device - call first with defined arguments
void MCP3421Init(unsigned char setup);
// Shut down the device
void MCP3421Off(void);
// Initiate conversion
void MCP3421Sample(void);
// Returns true is complete - better to just wait though for lowest power
unsigned char MCP3421CheckComplete(void);
// Note: ssumes the current conversion is over
signed long MCP3421Read(void);
#endif
//EOF
|
8a6bdaccaee8dab2dde5e8918f162053f3a57627
|
91971732033d69414cb6acdcf471c2862483679c
|
/hel/include/hel.h
|
ee1bb5ef2b6cc7f0ab5612d590208731c61d00b5
|
[
"MIT"
] |
permissive
|
managarm/managarm
|
d94e5bab607e36df458213984876fafc4575b184
|
f274d8d531f7f083284c0681ac065db1e467256f
|
refs/heads/master
| 2023-09-04T08:07:06.523632
| 2023-08-29T22:26:04
| 2023-08-29T22:26:04
| 63,081,862
| 1,261
| 87
|
MIT
| 2023-08-29T22:26:06
| 2016-07-11T15:57:53
|
C++
|
UTF-8
|
C
| false
| false
| 31,393
|
h
|
hel.h
|
//! @file hel.h
#ifndef HEL_H
#define HEL_H
#include <stddef.h>
#include <string.h>
#include <stdint.h>
#include "hel-types.h"
#ifdef __cplusplus
#define HEL_C_LINKAGE extern "C"
#else
#define HEL_C_LINKAGE
#endif
enum {
// largest system call number plus 1
kHelNumCalls = 103,
kHelCallLog = 1,
kHelCallPanic = 10,
kHelCallNop = 2,
kHelCallSubmitAsyncNop = 3,
kHelCallCreateUniverse = 62,
kHelCallTransferDescriptor = 66,
kHelCallDescriptorInfo = 32,
kHelCallGetCredentials = 84,
kHelCallCloseDescriptor = 21,
kHelCallCreateQueue = 89,
kHelCallCancelAsync = 92,
kHelCallAllocateMemory = 51,
kHelCallResizeMemory = 83,
kHelCallCreateManagedMemory = 64,
kHelCallCopyOnWrite = 39,
kHelCallAccessPhysical = 30,
kHelCallCreateSliceView = 88,
kHelCallForkMemory = 40,
kHelCallCreateSpace = 27,
kHelCallCreateIndirectMemory = 45,
kHelCallAlterMemoryIndirection = 52,
kHelCallMapMemory = 44,
kHelCallSubmitProtectMemory = 99,
kHelCallSubmitSynchronizeSpace = 53,
kHelCallUnmapMemory = 36,
kHelCallPointerPhysical = 43,
kHelCallSubmitReadMemory = 77,
kHelCallSubmitWriteMemory = 78,
kHelCallMemoryInfo = 26,
kHelCallSubmitManageMemory = 46,
kHelCallUpdateMemory = 47,
kHelCallSubmitLockMemoryView = 48,
kHelCallLoadahead = 49,
kHelCallCreateVirtualizedSpace = 50,
kHelCallCreateThread = 67,
kHelCallQueryThreadStats = 95,
kHelCallSetPriority = 85,
kHelCallYield = 34,
kHelCallSubmitObserve = 74,
kHelCallKillThread = 87,
kHelCallInterruptThread = 86,
kHelCallResume = 61,
kHelCallLoadRegisters = 75,
kHelCallStoreRegisters = 76,
kHelCallQueryRegisterInfo = 102,
kHelCallWriteFsBase = 41,
kHelCallGetClock = 42,
kHelCallSubmitAwaitClock = 80,
kHelCallCreateVirtualizedCpu = 37,
kHelCallRunVirtualizedCpu = 38,
kHelCallGetRandomBytes = 101,
kHelCallWriteGsBase = 54,
kHelCallReadFsBase = 55,
kHelCallReadGsBase = 56,
kHelCallCreateStream = 68,
kHelCallSubmitAsync = 79,
kHelCallShutdownLane = 91,
kHelCallFutexWait = 73,
kHelCallFutexWake = 71,
kHelCallCreateOneshotEvent = 96,
kHelCallCreateBitsetEvent = 97,
kHelCallRaiseEvent = 98,
kHelCallAccessIrq = 14,
kHelCallAcknowledgeIrq = 81,
kHelCallSubmitAwaitEvent = 82,
kHelCallAutomateIrq = 94,
kHelCallAccessIo = 11,
kHelCallEnableIo = 12,
kHelCallEnableFullIo = 35,
kHelCallBindKernlet = 93,
kHelCallSetAffinity = 100,
kHelCallSuper = 0x80000000
};
enum {
kHelErrNone = 0,
kHelErrIllegalSyscall = 5,
kHelErrIllegalArgs = 7,
kHelErrIllegalState = 15,
kHelErrUnsupportedOperation = 18,
kHelErrOutOfBounds = 19,
kHelErrQueueTooSmall = 14,
kHelErrCancelled = 12,
kHelErrNoDescriptor = 4,
kHelErrBadDescriptor = 2,
kHelErrThreadTerminated = 11,
kHelErrTransmissionMismatch = 13,
kHelErrLaneShutdown = 8,
kHelErrEndOfLane = 9,
kHelErrDismissed = 20,
kHelErrBufferTooSmall = 1,
kHelErrFault = 10,
kHelErrRemoteFault = 21,
kHelErrNoHardwareSupport = 16,
kHelErrNoMemory = 17,
kHelErrAlreadyExists = 22
};
struct HelX86SegmentRegister {
uint64_t base;
uint32_t limit;
uint16_t selector;
uint8_t type, present, dpl, db, s, l, g, avl;
};
struct HelX86DescriptorTable {
uint64_t base;
uint16_t limit;
};
struct HelX86VirtualizationRegs {
uint64_t rax;
uint64_t rbx;
uint64_t rcx;
uint64_t rdx;
uint64_t rsi;
uint64_t rdi;
uint64_t rbp;
uint64_t r8;
uint64_t r9;
uint64_t r10;
uint64_t r11;
uint64_t r12;
uint64_t r13;
uint64_t r14;
uint64_t r15;
uint64_t rsp;
uint64_t rip;
uint64_t rflags;
struct HelX86SegmentRegister cs, ds, es, fs, gs, ss;
struct HelX86SegmentRegister tr, ldt;
struct HelX86DescriptorTable gdt, idt;
uint64_t cr0, cr2, cr3, cr4, cr8;
uint64_t efer;
uint64_t apic_base;
};
enum {
kHelNullHandle = 0,
kHelThisUniverse = -1,
kHelThisThread = -2,
kHelZeroMemory = -3
};
enum {
kHelWaitInfinite = -1
};
enum {
kHelAbiSystemV = 1
};
enum {
kHelActionDismiss = 11,
kHelActionOffer = 5,
kHelActionAccept = 6,
kHelActionImbueCredentials = 8,
kHelActionExtractCredentials = 9,
kHelActionSendFromBuffer = 1,
kHelActionSendFromBufferSg = 10,
kHelActionRecvInline = 7,
kHelActionRecvToBuffer = 3,
kHelActionPushDescriptor = 2,
kHelActionPullDescriptor = 4
};
enum {
kHelItemChain = 1,
kHelItemAncillary = 2,
kHelItemWantLane = (1 << 16),
};
struct HelSgItem {
void *buffer;
size_t length;
};
struct HelAction {
int type;
uint32_t flags;
// TODO: the following fields could be put into unions
void *buffer;
size_t length;
HelHandle handle;
};
struct HelDescriptorInfo {
int type;
};
enum HelAllocFlags {
kHelAllocContinuous = 4,
kHelAllocOnDemand = 1,
};
struct HelAllocRestrictions {
int addressBits;
};
enum HelManagedFlags {
kHelManagedReadahead = 1
};
enum HelManageRequests {
kHelManageInitialize = 1,
kHelManageWriteback = 2
};
enum HelMapFlags {
// Additional flags that may be set.
kHelMapProtRead = 256,
kHelMapProtWrite = 512,
kHelMapProtExecute = 1024,
kHelMapDontRequireBacking = 128,
kHelMapFixed = 2048,
kHelMapFixedNoReplace = 4096
};
enum HelThreadFlags {
kHelThreadStopped = 1
};
enum HelObservation {
kHelObserveNull = 0,
kHelObserveInterrupt = 4,
kHelObservePanic = 3,
kHelObserveBreakpoint = 1,
kHelObservePageFault = 2,
kHelObserveGeneralFault = 5,
kHelObserveIllegalInstruction = 6,
kHelObserveSuperCall = 0x80000000
};
enum HelRegisterSets {
kHelRegsProgram = 1,
kHelRegsGeneral = 2,
kHelRegsThread = 3,
kHelRegsDebug = 4,
kHelRegsVirtualization = 5,
kHelRegsSimd = 6
};
//! Register-related information returned by helQueryRegisterInfo
struct HelRegisterInfo {
//! Size of the selected register set
int setSize;
};
#if defined(__x86_64__)
enum HelRegisterIndex {
kHelRegRax = 0,
kHelRegRbx = 1,
kHelRegRcx = 2,
kHelRegRdx = 3,
kHelRegRdi = 4,
kHelRegRsi = 5,
kHelRegR8 = 6,
kHelRegR9 = 7,
kHelRegR10 = 8,
kHelRegR11 = 9,
kHelRegR12 = 10,
kHelRegR13 = 11,
kHelRegR14 = 12,
kHelRegR15 = 13,
kHelRegRbp = 14,
kHelNumGprs = 15,
kHelRegIp = 0,
kHelRegSp = 1
};
enum HelSyscallArgs {
kHelRegNumber = kHelRegRdi,
kHelRegError = kHelRegRdi,
kHelRegArg0 = kHelRegRsi,
kHelRegArg1 = kHelRegRdx,
kHelRegArg2 = kHelRegRax,
kHelRegArg3 = kHelRegR8,
kHelRegArg4 = kHelRegR9,
kHelRegArg5 = kHelRegR10,
kHelRegArg6 = kHelRegR12,
kHelRegArg7 = kHelRegR13,
kHelRegArg8 = kHelRegR14,
kHelRegOut0 = kHelRegRsi,
kHelRegOut1 = kHelRegRdx
};
#elif defined(__aarch64__)
enum HelRegisterIndex {
kHelRegX0 = 0,
kHelRegX1,
kHelRegX2,
kHelRegX3,
kHelRegX4,
kHelRegX5,
kHelRegX6,
kHelRegX7,
kHelRegX8,
kHelRegX9,
kHelRegX10,
kHelRegX11,
kHelRegX12,
kHelRegX13,
kHelRegX14,
kHelRegX15,
kHelRegX16,
kHelRegX17,
kHelRegX18,
kHelRegX19,
kHelRegX20,
kHelRegX21,
kHelRegX22,
kHelRegX23,
kHelRegX24,
kHelRegX25,
kHelRegX26,
kHelRegX27,
kHelRegX28,
kHelRegX29,
kHelRegX30,
kHelNumGprs = 31,
kHelRegIp = 0,
kHelRegSp = 1
};
enum HelSyscallArgs {
kHelRegNumber = kHelRegX0,
kHelRegError = kHelRegX0,
kHelRegArg0 = kHelRegX1,
kHelRegArg1 = kHelRegX2,
kHelRegArg2 = kHelRegX3,
kHelRegArg3 = kHelRegX4,
kHelRegArg4 = kHelRegX5,
kHelRegArg5 = kHelRegX6,
kHelRegArg6 = kHelRegX7,
kHelRegArg7 = kHelRegX8,
kHelRegArg8 = kHelRegX9,
kHelRegOut0 = kHelRegX1,
kHelRegOut1 = kHelRegX2
};
#endif
struct HelQueueParameters {
uint32_t flags;
unsigned int ringShift;
unsigned int numChunks;
size_t chunkSize;
};
//! Mask to extract the current queue head.
static const int kHelHeadMask = 0xFFFFFF;
//! Can be set by the kernel to request a FutexWake on update
static const int kHelHeadWaiters = (1 << 24);
//! In-memory kernel/user-space queue.
struct HelQueue {
//! Futex for kernel/user-space head synchronization.
int headFutex;
//! Ensures that the buffer is 8-byte aligned.
char padding[4];
//! The actual queue.
int indexQueue[];
};
//! Mask to extract the number of valid bytes in the chunk.
static const int kHelProgressMask = 0xFFFFFF;
//! Can be set by userspace to request a FutexWake on update.
static const int kHelProgressWaiters = (1 << 24);
//! Set by the kernel once it retires the chunk.
static const int kHelProgressDone = (1 << 25);
struct HelChunk {
//! Futex for kernel/user-space progress synchronization.
int progressFutex;
//! Ensures that the buffer is 8-byte aligned.
char padding[4];
//! Actual contents of the chunk.
char buffer[];
};
//! A single element of a HelQueue.
struct HelElement {
//! Length of the element in bytes.
unsigned int length;
unsigned int reserved;
//! User-defined value.
void *context;
};
struct HelSimpleResult {
HelError error;
int reserved;
};
struct HelCredentialsResult {
HelError error;
int reserved;
char credentials[16];
};
struct HelManageResult {
HelError error;
int type;
uintptr_t offset;
size_t length;
};
struct HelObserveResult {
HelError error;
unsigned int observation;
uint64_t sequence;
};
struct HelInlineResult {
HelError error;
int reserved;
size_t length;
char data[];
};
struct HelInlineResultNoFlex {
HelError error;
int reserved;
size_t length;
};
struct HelLengthResult {
HelError error;
int reserved;
size_t length;
};
struct HelHandleResult {
HelError error;
int reserved;
HelHandle handle;
};
struct HelEventResult {
HelError error;
uint32_t bitset;
uint64_t sequence;
};
enum HelAckFlags {
kHelAckAcknowledge = 2,
kHelAckNack = 3,
kHelAckKick = 1,
kHelAckClear = 0x100,
};
union HelKernletData {
HelHandle handle;
};
struct HelThreadStats {
uint64_t userTime;
};
enum {
kHelVmexitHlt = 0,
kHelVmexitTranslationFault = 1,
kHelVmexitError = -1,
kHelVmexitUnknownPlatformSpecificExitCode = -2,
};
struct HelVmexitReason {
uint32_t exitReason;
uint32_t code;
size_t address;
size_t flags;
};
//! @name Logging
//! @{
//! Writes a text message (e.g., a line of text) to the kernel's log.
//! @param[in] string
//! Text to be written.
//! @param[in] length
//! Size of the text in bytes.
HEL_C_LINKAGE HelError helLog(const char *string, size_t length);
//! Kills the current thread and writes an error message to the kernel's log.
//! @param[in] string
//! Text to be written.
//! @param[in] length
//! Size of the text in bytes.
HEL_C_LINKAGE void helPanic(const char *string, size_t length)
__attribute__ (( noreturn ));
//! @}
//! @name Debugging
//! @{
//! Does nothing (useful only for profiling).
HEL_C_LINKAGE HelError helNop();
//! Does nothing, asynchronously (useful only for profiling).
//!
//! This is an asynchronous operation.
HEL_C_LINKAGE HelError helSubmitAsyncNop(HelHandle queueHandle, uintptr_t context);
//! @}
//! @name Management of Descriptors and Universes
//! @{
//! Creates a new universe descriptor.
//! @param[out] handle
//! Handle to the new universe descriptor.
HEL_C_LINKAGE HelError helCreateUniverse(HelHandle *handle);
//! Copies descriptors from the current universe to another universe.
//! @param[in] handle
//! Handle the descriptor to transfer.
//! @param[in] universeHandle
//! Handle to the destination universe.
//! @param[out] outHandle
//! Handle to the copied descriptor (valid in the universe specified by @p universeHandle).
HEL_C_LINKAGE HelError helTransferDescriptor(HelHandle handle, HelHandle universeHandle,
HelHandle *outHandle);
HEL_C_LINKAGE HelError helDescriptorInfo(HelHandle handle, struct HelDescriptorInfo *info);
//! Returns the credentials associated with a given descriptor.
//! @param[in] handle
//! Handle to the descriptor.
//! @param[out] credentials
//! Credentials, i.e., a 16-byte binary string.
HEL_C_LINKAGE HelError helGetCredentials(HelHandle handle, uint32_t flags,
char *credentials);
//! Closes a descriptor.
//! @param[in] universeHandle
//! Handle to the universe containing @p handle.
//! @param[in] handle
//! Handle to be closed.
HEL_C_LINKAGE HelError helCloseDescriptor(HelHandle universeHandle, HelHandle handle);
//! @}
//! @name Management of IPC Queues
//! @{
//! Creates an IPC queue.
HEL_C_LINKAGE HelError helCreateQueue(struct HelQueueParameters *params,
HelHandle *handle);
//! Cancels an ongoing asynchronous operation.
//! @param[in] queueHandle
//! Handle to the queue that the operation was submitted to.
//! @param[in] asyncId
//! ID identifying the operation.
HEL_C_LINKAGE HelError helCancelAsync(HelHandle queueHandle, uint64_t asyncId);
//! @}
//! @name Memory Management
//! @{
//! Creates a memory object consisting of unmanaged RAM.
//! @param[in] size
//! Size of the memory object in bytes.
//! Must be aligned to the system's page size.
//! @param[in] restrictions
//! Specifies restrictions for the kernel's memory allocator.
//! May be @p NULL if there are no restrictions.
//! @param[out] handle
//! Handle to the new memory object.
HEL_C_LINKAGE HelError helAllocateMemory(size_t size, uint32_t flags,
struct HelAllocRestrictions *restrictions, HelHandle *handle);
//! Resizes a memory object.
//! @param[in] handle
//! Handle to the memory object.
//! Must be aligned to the system's page size.
//! @param[in] newSize
//! New size in bytes.
HEL_C_LINKAGE HelError helResizeMemory(HelHandle handle, size_t newSize);
//! Creates a memory object that is managed by userspace.
//!
//! The @p backingHandle is used to manage the memory object, while
//! the @p frontalHandle provides a view on the memory object for consumers.
//! @param[in] size
//! Size of the memory object in bytes.
//! Must be aligned to the system's page size.
//! @param[out] backingHandle
//! Handle to the new memory object (for management)
//! @param[out] frontalHandle
//! Handle to the new memory object (for consumers).
HEL_C_LINKAGE HelError helCreateManagedMemory(size_t size, uint32_t flags,
HelHandle *backingHandle, HelHandle *frontalHandle);
//! Creates memory object that obtains its memory by copy-on-write from another memory object.
//! @param[in] memory
//! Handle to the source memory object.
//! @param[in] offset
//! Offset in byte relative to @p memory.
//! @param[in] size
//! Size of the memory object in bytes.
//! Must be aligned to the system's page size.
//! @param[out] handle
//! Handle to the new memory object.
HEL_C_LINKAGE HelError helCopyOnWrite(HelHandle memory,
uintptr_t offset, size_t size, HelHandle *handle);
HEL_C_LINKAGE HelError helAccessPhysical(uintptr_t physical,
size_t size, HelHandle *handle);
//! Creates a memory object that obtains its memory by delegating to other memory objects.
//! @param[in] numSlots
//! Number of slots, i.e., other memory objects that the indirect memory object refers to.
//! @param[out] handle
//! Handle to the new memory object.
HEL_C_LINKAGE HelError helCreateIndirectMemory(size_t numSlots, HelHandle *handle);
//! Modifies indirect memory objects.
//!
//! @param[in] indirectHandle
//! Handle to the indirect memory object to be modified.
//! Must refer to a memory object created by ::helCreateIndirectMemory.
//! @param[in] slotIndex
//! Index of the slot to be modified. Must be a non-negative integer smaller than
//! @p numSlots (see ::helCreateIndirectMemory).
//! @param[in] memoryHandle
//! Handle to the memory object that @p indirectHandle should delegate to.
//! @param[in] offset
//! Offset in bytes, relative to @p memoryHandle.
//! Must be aligned to the system's page size.
//! @param[in] size
//! Size of the indirection in bytes.
//! Must be aligned to the system's page size.
HEL_C_LINKAGE HelError helAlterMemoryIndirection(HelHandle indirectHandle, size_t slotIndex,
HelHandle memoryHandle, uintptr_t offset, size_t size);
HEL_C_LINKAGE HelError helCreateSliceView(HelHandle bundle, uintptr_t offset, size_t size,
uint32_t flags, HelHandle *handle);
//! Forks memory objects, i.e., copies them using copy-on-write.
//!
//! @param[in] indirectHandle
//! Handle to the memory object to be forked.
//! Must refer to a memory object created by ::helCopyOnWrite.
//! @param[out] handle
//! Handle to the new (i.e., forked) memory object.
HEL_C_LINKAGE HelError helForkMemory(HelHandle handle, HelHandle *forkedHandle);
//! Creates a virtual address space that threads can run in.
//! @param[out] handle
//! Handle to the new address space.
HEL_C_LINKAGE HelError helCreateSpace(HelHandle *handle);
//! Maps memory objects into an address space.
//! @param[in] memoryHandle
//! Handle to the memory object.
//! @param[in] spaceHandle
//! Handle to the address space (see ::helCreateSpace).
//! @param[in] pointer
//! Pointer to which the memory is mapped.
//! Can be specified as @p NULL to let the kernel pick a pointer.
//! @param[in] offset
//! Offset in bytes, relative to @p memoryHandle.
//! Must be aligned to the system's page size.
//! @param[in] size
//! Size of the mappping in bytes.
//! Must be aligned to the system's page size.
//! @param[out] actualPointer
//! Pointer to which the memory is mapped.
//! Differs from @p pointer only if @p pointer was specified as @p NULL.
HEL_C_LINKAGE HelError helMapMemory(HelHandle memoryHandle, HelHandle spaceHandle,
void *pointer, uintptr_t offset, size_t size, uint32_t flags, void **actualPointer);
//! Changes protection attributes of a memory mapping.
//!
//! This is an asynchronous operation.
//! @param[in] spaceHandle
//! Handle to the address space containing @p pointer.
//! @param[in] pointer
//! Pointer to the mapping that is modified.
//! Must be aligned to the system's page size.
//! @param[in] size
//! Size of the mapping that is modified.
//! Must be aligned to the system's page size.
HEL_C_LINKAGE HelError helSubmitProtectMemory(HelHandle spaceHandle,
void *pointer, size_t size, uint32_t flags,
HelHandle queueHandle, uintptr_t context);
//! Notifies the kernel of dirty pages in a memory mapping.
//!
//! This system call returns after the kernel has scanned all specified pages
//! and determined whether they are dirty
//! or not. It does *not* wait until the pages are clean again.
//!
//! This is an asynchronous operation.
//! @param[in] spaceHandle
//! Handle to the address space containing @p pointer.
//! @param[in] pointer
//! Pointer to the mapping that is synchronized.
//! Must be aligned to the system's page size.
//! @param[in] size
//! Size of the mapping that is synchronized.
//! Must be aligned to the system's page size.
HEL_C_LINKAGE HelError helSubmitSynchronizeSpace(HelHandle spaceHandle,
void *pointer, size_t size,
HelHandle queueHandle, uintptr_t context);
//! Unmaps memory from an address space.
//!
//! @param[in] spaceHandle
//! Handle to the address space containing @p pointer.
//! @param[in] pointer
//! Pointer to the mapping that is unmapped.
//! Must be aligned to the system's page size.
//! @param[in] size
//! Size of the mapping that is unmapped.
//! Must be aligned to the system's page size.
HEL_C_LINKAGE HelError helUnmapMemory(HelHandle spaceHandle, void *pointer, size_t size);
HEL_C_LINKAGE HelError helPointerPhysical(const void *pointer, uintptr_t *physical);
//! Load memory (i.e., bytes) from a descriptor.
//!
//! This is an asynchronous operation.
//! @param[in] handle
//! Handle to the descriptor. This system call supports
//! address spaces (see ::helCreateAddressSpace)
//! and virtualized spaces (see ::helCreateVirtualizedSpace).
//! @param[in] address
//! Address that is accessed, relative to @p handle.
//! @param[in] length
//! Length of the copied memory region.
HEL_C_LINKAGE HelError helSubmitReadMemory(HelHandle handle, uintptr_t address,
size_t length, void *buffer,
HelHandle queue, uintptr_t context);
//! Store memory (i.e., bytes) to a descriptor.
//!
//! This is an asynchronous operation.
//! @param[in] handle
//! Handle to the descriptor. This system call supports
//! address spaces (see ::helCreateAddressSpace)
//! and virtualized spaces (see ::helCreateVirtualizedSpace).
//! @param[in] address
//! Address that is accessed, relative to @p handle.
//! @param[in] length
//! Length of the copied memory region.
HEL_C_LINKAGE HelError helSubmitWriteMemory(HelHandle handle, uintptr_t address,
size_t length, const void *buffer,
HelHandle queue, uintptr_t context);
HEL_C_LINKAGE HelError helMemoryInfo(HelHandle handle,
size_t *size);
HEL_C_LINKAGE HelError helSubmitManageMemory(HelHandle handle,
HelHandle queue, uintptr_t context);
HEL_C_LINKAGE HelError helUpdateMemory(HelHandle handle, int type, uintptr_t offset, size_t length);
HEL_C_LINKAGE HelError helSubmitLockMemoryView(HelHandle handle, uintptr_t offset, size_t size,
HelHandle queue, uintptr_t context);
//! Notifies the kernel that a certain range of memory should be preloaded.
//!
//! This acts as a hint to the kernel and is meant purely as a performance optimization.
//! The kernel is free to ignore it.
//! @param[in] handle
//! Handle to the memory object.
//! @param[in] offset
//! Offset in bytes, relative to @p handle.
//! @param[in] length
//! Length of the memory range that is preloaded.
HEL_C_LINKAGE HelError helLoadahead(HelHandle handle, uintptr_t offset, size_t length);
HEL_C_LINKAGE HelError helCreateVirtualizedSpace(HelHandle *handle);
//! @}
//! @name Thread Management
//! @{
//! Create a new thread.
//! @param[in] universeHandle
//! Handle to universe of the new thread.
//! @param[in] spaceHandle
//! Handle to universe of the new thread.
//! @param[in] abi
//! ABI that the new thread should adhere to.
//! @param[in] ip
//! Instruction pointer of the new thread.
//! @param[in] sp
//! Stack pointer of the new thread.
//! @param[out] handle
//! Handle to the new thread.
HEL_C_LINKAGE HelError helCreateThread(HelHandle universe, HelHandle spaceHandle,
HelAbi abi, void *ip, void *sp, uint32_t flags, HelHandle *handle);
//! Query run-time statistics of a thread.
//! @param[in] handle
//! Handle to the thread.
//! @param[out] stats
//! Statistics related to the thread.
HEL_C_LINKAGE HelError helQueryThreadStats(HelHandle handle, struct HelThreadStats *stats);
//! Set the priority of a thread.
//!
//! Managarm always runs the runnable thread with highest priority.
//! The default priority of a thread is zero.
//! @param[in] handle
//! Handle to the thread.
//! @param[in] priority
//! New priority value of the thread.
HEL_C_LINKAGE HelError helSetPriority(HelHandle handle, int priority);
//! Yields the current thread.
HEL_C_LINKAGE HelError helYield();
//! Observe whether a thread changes its state.
//!
//! This is an asynchronous operation.
//! @param[in] handle
//! Handle to the thread.
//! @param[in] sequence
//! Previous sequence number.
HEL_C_LINKAGE HelError helSubmitObserve(HelHandle handle, uint64_t sequence,
HelHandle queue, uintptr_t context);
//! Kill (i.e., terminate) a thread.
//! @param[in] handle
//! Handle to the thread.
HEL_C_LINKAGE HelError helKillThread(HelHandle handle);
//! Interrupt a thread.
//!
//! This system call temporarily suspends a thread.
//! The thread can later be resumed through the use of ::helResume.
//! @param[in] handle
//! Handle to the thread.
HEL_C_LINKAGE HelError helInterruptThread(HelHandle handle);
//! Resume a suspended thread.
//!
//! Threads can explicitly be suspended through the use of ::helInterruptThread.
//! They are also suspended on faults and supercalls.
//! @param[in] handle
//! Handle to the thread.
HEL_C_LINKAGE HelError helResume(HelHandle handle);
//! Load a register image (e.g., from a thread).
//! @param[in] handle
//! Handle to the thread.
//! @param[in] set
//! Register set that will be accessed.
//! @param[out] image
//! Copy of the register image.
HEL_C_LINKAGE HelError helLoadRegisters(HelHandle handle, int set, void *image);
//! Store a register image (e.g., to a thread).
//! @param[in] handle
//! Handle to the thread.
//! @param[in] set
//! Register set that will be accessed.
//! @param[in] image
//! Copy of the register image.
HEL_C_LINKAGE HelError helStoreRegisters(HelHandle handle, int set, const void *image);
//! Query register-related information.
//! @param[in] set
// Register set to query information for.
//! @param[out] info
//! Returned information.
HEL_C_LINKAGE HelError helQueryRegisterInfo(int set, struct HelRegisterInfo *info);
HEL_C_LINKAGE HelError helWriteFsBase(void *pointer);
HEL_C_LINKAGE HelError helReadFsBase(void **pointer);
HEL_C_LINKAGE HelError helWriteGsBase(void *pointer);
HEL_C_LINKAGE HelError helReadGsBase(void **pointer);
//! Read the system-wide monotone clock.
//!
//! @param[out] counter
//! Current value of the system-wide clock in nanoseconds since boot.
HEL_C_LINKAGE HelError helGetClock(uint64_t *counter);
//! Wait until time passes.
//!
//! This is an asynchronous operation.
//! @param[in] counter
//! Deadline (absolute, see ::helGetClock).
//! @param[out] asyncId
//! ID to identify the asynchronous operation (absolute, see ::helCancelAsync).
HEL_C_LINKAGE HelError helSubmitAwaitClock(uint64_t counter,
HelHandle queue, uintptr_t context, uint64_t *asyncId);
HEL_C_LINKAGE HelError helCreateVirtualizedCpu(HelHandle handle, HelHandle *out_handle);
HEL_C_LINKAGE HelError helRunVirtualizedCpu(HelHandle handle, struct HelVmexitReason *reason);
HEL_C_LINKAGE HelError helGetRandomBytes(void *buffer, size_t wantedSize, size_t *actualSize);
//! Set a thread's CPU affinity mask.
//! @param[in] handle
//! Handle to the thread.
//! @param[in] mask
//! Pointer to a bit mask of CPUs to schedule on.
//! @param[in] size
//! Size of bit mask.
HEL_C_LINKAGE HelError helSetAffinity(HelHandle thread,
uint8_t *mask, size_t size);
//! @}
//! @name Message Passing
//! @{
//! Create a stream (which always consists of two lanes).
//! @param[out] lane1
//! Handle to the first lane of the new stream.
//! @param[out] lane2
//! Handle to the second lane of the new stream.
HEL_C_LINKAGE HelError helCreateStream(HelHandle *lane1, HelHandle *lane2);
//! Pass messages on a stream.
//! @param[in] handle
//! Handle to the lane that messages will be passed to.
//! @param[in] actions
//! Pointer to array of message items.
//! @param[in] count
//! Number of elements in @p actions.
HEL_C_LINKAGE HelError helSubmitAsync(HelHandle handle, const struct HelAction *actions,
size_t count, HelHandle queue, uintptr_t context, uint32_t flags);
HEL_C_LINKAGE HelError helShutdownLane(HelHandle handle);
//! @}
//! @name Inter-Thread Synchronization
//! @{
//! Waits on a futex.
//! @param[in] pointer
//! Pointer that identifies the futex.
//! @param[in] expected
//! Expected value of the futex. This function does nothing unless
//! the futex pointed to by @pointer matches this value.
//! @param[in] deadline
//! Timeout (in absolute monotone time, see ::helGetClock).
HEL_C_LINKAGE HelError helFutexWait(int *pointer, int expected, int64_t deadline);
//! Wakes up all waiters of a futex.
//! @param[in] pointer
//! Pointer that identifies the futex.
HEL_C_LINKAGE HelError helFutexWake(int *pointer);
//! @}
//! @name Event Handling
//! @{
//! Create an event that fires at most once.
//! @param[out] handle
//! Handle to the new event.
HEL_C_LINKAGE HelError helCreateOneshotEvent(HelHandle *handle);
//! Create an event consisting of multiple bits that can fire independently.
//! @param[out] handle
//! Handle to the new event.
HEL_C_LINKAGE HelError helCreateBitsetEvent(HelHandle *handle);
//! Raise an event.
//! @param[in] handle
//! Handle to the event that will be raised.
HEL_C_LINKAGE HelError helRaiseEvent(HelHandle handle);
HEL_C_LINKAGE HelError helAccessIrq(int number, HelHandle *handle);
HEL_C_LINKAGE HelError helAcknowledgeIrq(HelHandle handle, uint32_t flags, uint64_t sequence);
//! Wait for an event.
//!
//! This is an asynchronous operation.
//! @param[in] handle
//! Handle to the event that will be awaited.
//! @param[in] sequence
//! Previous sequence number.
HEL_C_LINKAGE HelError helSubmitAwaitEvent(HelHandle handle, uint64_t sequence,
HelHandle queue, uintptr_t context);
HEL_C_LINKAGE HelError helAutomateIrq(HelHandle handle, uint32_t flags, HelHandle kernlet);
//! @}
//! @name Input/Output
//! @{
HEL_C_LINKAGE HelError helAccessIo(uintptr_t *port_array, size_t num_ports,
HelHandle *handle);
//! Enable userspace access to hardware I/O resources.
//! @param[in] handle
//! Handle to the hardware I/O resource.
HEL_C_LINKAGE HelError helEnableIo(HelHandle handle);
HEL_C_LINKAGE HelError helEnableFullIo();
//! @}
//! @name Kernlet Management
//! @{
//! Bind parameters to a kernlet.
//! @param[in] handle
//! Handle to the unbound kernlet.
//! @param[in] data
//! Pointer to an array of binding parameters.
//! @param[in] numData
//! Number of binding parameters in @p data.
//! @param[out] boundHandle
//! Handle to the bound kernlet.
HEL_C_LINKAGE HelError helBindKernlet(HelHandle handle,
const union HelKernletData *data, size_t numData, HelHandle *boundHandle);
//! @}
extern inline __attribute__ (( always_inline )) const char *_helErrorString(HelError code) {
switch(code) {
case kHelErrNone:
return "Success";
case kHelErrIllegalSyscall:
return "Illegal syscall";
case kHelErrIllegalArgs:
return "Illegal arguments";
case kHelErrIllegalState:
return "Illegal state";
case kHelErrUnsupportedOperation:
return "Unsupported operation";
case kHelErrNoDescriptor:
return "No such descriptor";
case kHelErrBadDescriptor:
return "Illegal descriptor for this operation";
case kHelErrThreadTerminated:
return "Thread terminated already";
case kHelErrLaneShutdown:
return "Lane shutdown";
case kHelErrEndOfLane:
return "End of lane";
case kHelErrDismissed:
return "IPC item dismissed by remote";
case kHelErrBufferTooSmall:
return "Buffer too small";
case kHelErrQueueTooSmall:
return "Buffer too small";
case kHelErrFault:
return "Segfault";
case kHelErrNoHardwareSupport:
return "Missing hardware support for this feature";
case kHelErrNoMemory:
return "Out of memory";
case kHelErrTransmissionMismatch:
return "Transmission mismatch";
case kHelErrCancelled:
return "Cancelled";
case kHelErrOutOfBounds:
return "Out of bounds";
case kHelErrAlreadyExists:
return "Already exists";
default:
return 0;
}
}
extern inline __attribute__ (( always_inline )) void _helCheckFailed(HelError err_code,
const char *string, int fatal) {
helLog(string, strlen(string));
const char *err_string = _helErrorString(err_code);
if(err_string == 0)
err_string = "(Unexpected error code)";
helLog(err_string, strlen(err_string));
helLog("\n", 1);
if(fatal)
helPanic(0, 0);
}
#define HEL_STRINGIFY_AUX(x) #x
#define HEL_STRINGIFY(x) HEL_STRINGIFY_AUX(x)
#define HEL_CHECK(expr) do { HelError __error = expr; if(__error != kHelErrNone) \
_helCheckFailed(__error, "HEL_CHECK failed: " #expr "\n" \
" In file " __FILE__ " on line " HEL_STRINGIFY(__LINE__) "\n", 1); } while(0)
#define HEL_SOFT_CHECK(expr) do { HelError __error = expr; if(__error != kHelErrNone) \
_helCheckFailed(__error, "HEL_SOFT_CHECK failed: " #expr "\n" \
" In file " __FILE__ " on line " HEL_STRINGIFY(__LINE__) "\n", 0); } while(0)
#endif // HEL_H
|
3df92be5ba0d11b245055ce7657f63a2ccc82737
|
7e6afb4986a53c420d40a2039240f8c5ed3f9549
|
/3rdparty/xspublic/xstypes/xssyncsetting.h
|
a66e76baf49f8b43be91c2a0ff41467e33b390d9
|
[
"BSD-3-Clause"
] |
permissive
|
MRPT/mrpt
|
9ea3c39a76de78eacaca61a10e7e96646647a6da
|
34077ec74a90b593b587f2057d3280ea520a3609
|
refs/heads/develop
| 2023-08-17T23:37:29.722496
| 2023-08-17T15:39:54
| 2023-08-17T15:39:54
| 13,708,826
| 1,695
| 646
|
BSD-3-Clause
| 2023-09-12T22:02:53
| 2013-10-19T21:09:23
|
C++
|
UTF-8
|
C
| false
| false
| 5,933
|
h
|
xssyncsetting.h
|
// Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions, and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions, and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the names of the copyright holders nor the names of their contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
// SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
// OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
// ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
//
#ifndef XSSYNCSETTINGS_H
#define XSSYNCSETTINGS_H
#include <string.h>
#include "pstdint.h"
#include "xstypesconfig.h"
#include "xssyncline.h"
#include "xssyncfunction.h"
#include "xssyncpolarity.h"
struct XsSyncSetting;
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __cplusplus
#define XSSYNCSETTINGS_INITIALIZER { XSL_Invalid, XSF_Invalid, XSP_None, 1, 0, 0, 0, 0, 0, 0 }
#endif
XSTYPES_DLL_API int XsSyncSetting_isInput(const struct XsSyncSetting* thisPtr);
XSTYPES_DLL_API int XsSyncSetting_isOutput(const struct XsSyncSetting* thisPtr);
XSTYPES_DLL_API void XsSyncSetting_swap(struct XsSyncSetting* a, struct XsSyncSetting* b);
XSTYPES_DLL_API int XsSyncSetting_compare(const struct XsSyncSetting* a, const struct XsSyncSetting* b);
#ifdef __cplusplus
} // extern "C"
#endif
/*! \brief A structure for storing all xsens sync settings */
struct XsSyncSetting {
XsSyncLine m_line; /*!< The sync lines enabled. \see XsSyncLine. */
XsSyncFunction m_function; /*!< The action to be performed, when an input sync line changes \see XsSyncFunction. */
XsSyncPolarity m_polarity; /*!< The edge on which the action is performed, \see XsSyncPolarity. */
uint32_t m_pulseWidth; /*!< The time to keep the line polarity before toggling back, in microseconds. */
int32_t m_offset; /*!< The time between reception of a line change and the execution of the sync action, in microseconds. */
uint16_t m_skipFirst; /*!< The number of frames to skip before executing the action. */
uint16_t m_skipFactor; /*!< The number of frames to skip between 2 actions. */
uint16_t m_clockPeriod; /*!< The frequency of the external clock in milliseconds, only valid when function is XSF_ClockBiasEstimation. */
uint8_t m_triggerOnce; /*!< Whether the action is repeated for each frame. */
uint8_t m_padding; /*!< Padding to get at a 4 byte boundary so memcpy/memcmp works with sizeof(XsSyncSetting) */
#ifdef __cplusplus
//! \brief Default constructor, initializes to the given (default) settings
explicit XsSyncSetting(XsSyncLine line = XSL_Invalid
, XsSyncFunction function = XSF_Invalid
, XsSyncPolarity polarity = XSP_RisingEdge
, uint32_t pulseWidth = 1000
, int32_t offset = 0
, uint16_t skipFirst = 0
, uint16_t skipFactor = 0
, uint16_t clockPeriod = 0
, uint8_t triggerOnce = 0)
: m_line(line)
, m_function(function)
, m_polarity(polarity)
, m_pulseWidth(pulseWidth)
, m_offset(offset)
, m_skipFirst(skipFirst)
, m_skipFactor(skipFactor)
, m_clockPeriod(clockPeriod)
, m_triggerOnce(triggerOnce)
, m_padding(0)
{
}
//! \brief Construct a XsSyncSetting as a copy of \a other.
XsSyncSetting(const XsSyncSetting& other)
{
memcpy(this, &other, sizeof(XsSyncSetting));
}
//! \brief Copy values of \a other into this.
const XsSyncSetting& operator =(const XsSyncSetting& other)
{
if (this != &other)
memcpy(this, &other, sizeof(XsSyncSetting));
return *this;
}
//! \brief \copybrief XsSyncSetting_isInput
inline bool isInput() const
{
return 0 != XsSyncSetting_isInput(this);
}
//! \brief \copybrief XsSyncSetting_isOutput
inline bool isOutput() const
{
return 0 != XsSyncSetting_isOutput(this);
}
/*! \brief Swap the contents with \a other
*/
inline void swap(XsSyncSetting& other)
{
XsSyncSetting_swap(this, &other);
}
/*! \brief Return true if \a other is identical to this
*/
inline bool operator == (const XsSyncSetting& other) const
{
return (this == &other) || XsSyncSetting_compare(this, &other) == 0;
}
/*! \brief Return true if \a other is not identical to this
*/
inline bool operator != (const XsSyncSetting& other) const
{
return (this != &other) && XsSyncSetting_compare(this, &other) != 0;
}
/*! \brief Return true if \a other is less than this
*/
inline bool operator < (const XsSyncSetting& other) const
{
return (this != &other) && XsSyncSetting_compare(this, &other) < 0;
}
#endif
};
typedef struct XsSyncSetting XsSyncSetting;
#endif
|
1cdf494e7562d931d86cdebfcf231d1330c23c8f
|
fa1ad2e2ac7e376fc7cb3b3a6e1bb88eed3e80be
|
/govern/data-security/krb-1.2.1/src/windows/include/loadfuncs-com_err.h
|
05ef8698f138051acf7ab3e060bcd4cad85e42df
|
[
"Apache-2.0",
"BSD-3-Clause",
"MIT",
"BSD-4-Clause",
"LicenseRef-scancode-generic-export-compliance",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-mit-old-style",
"BSD-4-Clause-UC",
"LicenseRef-scancode-rsa-1990",
"MIT-CMU",
"LicenseRef-scancode-mit-no-advert-export-control",
"CC-BY-SA-3.0",
"LicenseRef-scancode-mit-modification-obligations",
"LicenseRef-scancode-proprietary-license",
"GPL-2.0-or-later",
"LicenseRef-scancode-michigan-disclaimer",
"ISC",
"LicenseRef-scancode-nrl-permission",
"FreeBSD-DOC",
"LicenseRef-scancode-rsa-md4",
"RSA-MD",
"OLDAP-2.8",
"FSFULLRWD",
"BSD-2-Clause",
"LicenseRef-scancode-brian-gladman"
] |
permissive
|
alldatacenter/alldata
|
7bc7713c9f1d56ad6b8e59ea03206d1073b7e047
|
8d5f9a2d49ab8f9e85ccf058cb02c2fda287afc6
|
refs/heads/master
| 2023-08-05T07:32:25.442740
| 2023-08-03T13:17:24
| 2023-08-03T13:17:24
| 213,321,771
| 774
| 250
|
Apache-2.0
| 2023-09-06T17:35:32
| 2019-10-07T07:36:18
| null |
UTF-8
|
C
| false
| false
| 896
|
h
|
loadfuncs-com_err.h
|
#ifndef __LOADFUNCS_COM_ERR_H__
#define __LOADFUNCS_COM_ERR_H__
#include "loadfuncs.h"
#include <com_err.h>
#if defined(_WIN64)
#define COMERR_DLL "comerr64.dll"
#else
#define COMERR_DLL "comerr32.dll"
#endif
TYPEDEF_FUNC(
void,
KRB5_CALLCONV_C,
com_err,
(const char FAR *, errcode_t, const char FAR *, ...)
);
TYPEDEF_FUNC(
void,
KRB5_CALLCONV,
com_err_va,
(const char FAR *whoami, errcode_t code, const char FAR *fmt, va_list ap)
);
TYPEDEF_FUNC(
const char FAR *,
KRB5_CALLCONV,
error_message,
(errcode_t)
);
TYPEDEF_FUNC(
errcode_t,
KRB5_CALLCONV,
add_error_table,
(const struct error_table FAR *)
);
TYPEDEF_FUNC(
errcode_t,
KRB5_CALLCONV,
remove_error_table,
(const struct error_table FAR *)
);
#endif /* __LOADFUNCS_COM_ERR_H__ */
|
cbd0b5771118fcaf672c3cb0254305837f0d9ae8
|
c31767d5d5d7f9267a2607bbddd261a72cc9a6f6
|
/runtime/test/page_swap.c
|
a2da15f296170ad3edf3fac67b194bbd5ddc65d3
|
[
"LicenseRef-scancode-bsd-3-clause-jtag",
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
keystone-enclave/keystone
|
39986d7d4d7f1f651a77ccf338ac0ebaf2744a55
|
9b9dd5a015cc77725b3576441f589c3ea2c7ced0
|
refs/heads/master
| 2023-09-03T15:18:31.943293
| 2023-08-30T02:28:55
| 2023-08-30T02:28:55
| 137,123,646
| 409
| 136
|
NOASSERTION
| 2023-09-09T00:28:40
| 2018-06-12T20:23:19
|
C
|
UTF-8
|
C
| false
| false
| 4,292
|
c
|
page_swap.c
|
#define _GNU_SOURCE
#include "../mm/page_swap.c"
#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/mman.h>
#include "mock.h"
void
sbi_exit_enclave(uintptr_t code) {
exit(code);
}
uintptr_t
sbi_random() {
uintptr_t out;
rt_util_getrandom(&out, sizeof out);
return out;
}
size_t
rt_util_getrandom(void* vaddr, size_t buflen) {
uint8_t* charbuf = (uint8_t*)vaddr;
for (size_t i = 0; i < buflen; i++) charbuf[i] = rand();
return buflen;
}
bool
paging_epm_inbounds(uintptr_t addr) {
(void)addr;
return true;
}
static void* backing_region;
#define BACKING_REGION_SIZE (2 * 1024 * 1024)
bool
paging_backpage_inbounds(uintptr_t addr) {
return (addr >= (uintptr_t)backing_region) &&
(addr < (uintptr_t)backing_region + BACKING_REGION_SIZE);
}
uintptr_t
paging_backing_region() {
if (!backing_region) {
backing_region = mmap(
NULL, BACKING_REGION_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
assert_int_not_equal(backing_region, MAP_FAILED);
}
return (uintptr_t)backing_region;
}
uintptr_t
paging_backing_region_size() {
return BACKING_REGION_SIZE;
}
static uintptr_t
palloc() {
void* out = mmap(
NULL, RISCV_PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
assert_int_not_equal(out, MAP_FAILED);
return (uintptr_t)out;
}
static void
pfree(uintptr_t page) {
int res = munmap((void*)page, RISCV_PAGE_SIZE);
assert_int_equal(res, 0);
}
typedef struct {
uint8_t dat[32];
} hash_s;
static hash_s
hash_page(uintptr_t page) {
hash_s out;
SHA256_CTX sha;
sha256_init(&sha);
sha256_update(&sha, (uint8_t*)page, RISCV_PAGE_SIZE);
sha256_final(&sha, out.dat);
return out;
}
static bool
hash_eq(hash_s* h1, hash_s* h2) {
return !memcmp(h1, h2, sizeof(hash_s));
}
static double
bit_similarity(uintptr_t page1, uintptr_t page2) {
double avg = 0;
size_t n = 0;
uint64_t* p1buf = (uint64_t*)page1;
uint64_t* p2buf = (uint64_t*)page2;
for (size_t i = 0; i < RISCV_PAGE_SIZE / 8; i++) {
double word_similarity =
(double)__builtin_popcountll(p1buf[i] ^ p2buf[i]) / 64.0;
avg += (word_similarity - avg) / ++n;
}
return avg;
}
static double
bit_similarity_sd() {
// For 2 IID pages, each bit is similar with probability 0.5.
// So the sum of all similarities follows a binomial distribution
// B(8*PAGE_SIZE, 0.5). The mean # of similar bits is 4*PAGE_SIZE, +/-
// sqrt(2*PAGE_SIZE) So the mean similarity is 0.5 +/- 1/sqrt(8*PAGE_SIZE)
// With PAGE_SIZE=4096, this is 0.5 */- 0.0028
return 1.0 / sqrt(8 * RISCV_PAGE_SIZE);
}
void
test_swapout_randomness() {
pswap_init();
uintptr_t back_page = paging_alloc_backing_page();
uintptr_t front_page = palloc();
rt_util_getrandom((void*)front_page, RISCV_PAGE_SIZE);
page_swap_epm(back_page, front_page, 0);
// Backing page should be essentially random.
double sim = bit_similarity(back_page, front_page);
assert_true(sim < 0.5 + 4 * bit_similarity_sd());
assert_true(sim > 0.5 - 4 * bit_similarity_sd());
pfree(front_page);
}
void
test_swap_out_in() {
pswap_init();
uintptr_t back_page = paging_alloc_backing_page();
uintptr_t front_page = palloc();
rt_util_getrandom((void*)front_page, RISCV_PAGE_SIZE);
hash_s back_hash = hash_page(back_page);
hash_s front_hash = hash_page(front_page);
page_swap_epm(back_page, front_page, 0);
hash_s back_swp_hash = hash_page(back_page);
hash_s front_swp_hash = hash_page(front_page);
assert_false(hash_eq(&back_hash, &back_swp_hash));
assert_true(hash_eq(&front_hash, &front_swp_hash));
// Randomize front_page and then swap back in our old front_page
rt_util_getrandom((void*)front_page, RISCV_PAGE_SIZE);
page_swap_epm(back_page, front_page, back_page);
hash_s back_swp_hash2 = hash_page(back_page);
hash_s front_swp_hash2 = hash_page(front_page);
assert_false(hash_eq(&back_hash, &back_swp_hash2));
assert_false(hash_eq(&back_swp_hash, &back_swp_hash2));
assert_true(hash_eq(&front_hash, &front_swp_hash2));
pfree(front_page);
}
int
main() {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_swapout_randomness),
cmocka_unit_test(test_swap_out_in),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
|
831b1f78c8a41bf63fcd102e3d66cd9e9b5d30b9
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/kernel/rtmutex.c
|
d9ca207cec0ceff1fe4b74fad22b3b0d19c02303
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 32,566
|
c
|
rtmutex.c
|
/*
* RT-Mutexes: simple blocking mutual exclusion locks with PI support
*
* started by Ingo Molnar and Thomas Gleixner.
*
* Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
* Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
* Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
* Copyright (C) 2006 Esben Nielsen
*
* See Documentation/rt-mutex-design.txt for details.
*/
#include <linux/spinlock.h>
#include <linux/export.h>
#include <linux/sched.h>
#include <linux/sched/rt.h>
#include <linux/timer.h>
#include "rtmutex_common.h"
/*
* lock->owner state tracking:
*
* lock->owner holds the task_struct pointer of the owner. Bit 0
* is used to keep track of the "lock has waiters" state.
*
* owner bit0
* NULL 0 lock is free (fast acquire possible)
* NULL 1 lock is free and has waiters and the top waiter
* is going to take the lock*
* taskpointer 0 lock is held (fast release possible)
* taskpointer 1 lock is held and has waiters**
*
* The fast atomic compare exchange based acquire and release is only
* possible when bit 0 of lock->owner is 0.
*
* (*) It also can be a transitional state when grabbing the lock
* with ->wait_lock is held. To prevent any fast path cmpxchg to the lock,
* we need to set the bit0 before looking at the lock, and the owner may be
* NULL in this small time, hence this can be a transitional state.
*
* (**) There is a small time when bit 0 is set but there are no
* waiters. This can happen when grabbing the lock in the slow path.
* To prevent a cmpxchg of the owner releasing the lock, we need to
* set this bit before looking at the lock.
*/
static void
rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner)
{
unsigned long val = (unsigned long)owner;
if (rt_mutex_has_waiters(lock))
val |= RT_MUTEX_HAS_WAITERS;
lock->owner = (struct task_struct *)val;
}
static inline void clear_rt_mutex_waiters(struct rt_mutex *lock)
{
lock->owner = (struct task_struct *)
((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS);
}
static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
{
if (!rt_mutex_has_waiters(lock))
clear_rt_mutex_waiters(lock);
}
/*
* We can speed up the acquire/release, if the architecture
* supports cmpxchg and if there's no debugging state to be set up
*/
#if defined(__HAVE_ARCH_CMPXCHG) && !defined(CONFIG_DEBUG_RT_MUTEXES)
# define rt_mutex_cmpxchg(l,c,n) (cmpxchg(&l->owner, c, n) == c)
static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
{
unsigned long owner, *p = (unsigned long *) &lock->owner;
do {
owner = *p;
} while (cmpxchg(p, owner, owner | RT_MUTEX_HAS_WAITERS) != owner);
}
/*
* Safe fastpath aware unlock:
* 1) Clear the waiters bit
* 2) Drop lock->wait_lock
* 3) Try to unlock the lock with cmpxchg
*/
static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock)
__releases(lock->wait_lock)
{
struct task_struct *owner = rt_mutex_owner(lock);
clear_rt_mutex_waiters(lock);
raw_spin_unlock(&lock->wait_lock);
/*
* If a new waiter comes in between the unlock and the cmpxchg
* we have two situations:
*
* unlock(wait_lock);
* lock(wait_lock);
* cmpxchg(p, owner, 0) == owner
* mark_rt_mutex_waiters(lock);
* acquire(lock);
* or:
*
* unlock(wait_lock);
* lock(wait_lock);
* mark_rt_mutex_waiters(lock);
*
* cmpxchg(p, owner, 0) != owner
* enqueue_waiter();
* unlock(wait_lock);
* lock(wait_lock);
* wake waiter();
* unlock(wait_lock);
* lock(wait_lock);
* acquire(lock);
*/
return rt_mutex_cmpxchg(lock, owner, NULL);
}
#else
# define rt_mutex_cmpxchg(l,c,n) (0)
static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
{
lock->owner = (struct task_struct *)
((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS);
}
/*
* Simple slow path only version: lock->owner is protected by lock->wait_lock.
*/
static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock)
__releases(lock->wait_lock)
{
lock->owner = NULL;
raw_spin_unlock(&lock->wait_lock);
return true;
}
#endif
/*
* Calculate task priority from the waiter list priority
*
* Return task->normal_prio when the waiter list is empty or when
* the waiter is not allowed to do priority boosting
*/
int rt_mutex_getprio(struct task_struct *task)
{
if (likely(!task_has_pi_waiters(task)))
return task->normal_prio;
return min(task_top_pi_waiter(task)->pi_list_entry.prio,
task->normal_prio);
}
/*
* Adjust the priority of a task, after its pi_waiters got modified.
*
* This can be both boosting and unboosting. task->pi_lock must be held.
*/
static void __rt_mutex_adjust_prio(struct task_struct *task)
{
int prio = rt_mutex_getprio(task);
if (task->prio != prio)
rt_mutex_setprio(task, prio);
}
/*
* Adjust task priority (undo boosting). Called from the exit path of
* rt_mutex_slowunlock() and rt_mutex_slowlock().
*
* (Note: We do this outside of the protection of lock->wait_lock to
* allow the lock to be taken while or before we readjust the priority
* of task. We do not use the spin_xx_mutex() variants here as we are
* outside of the debug path.)
*/
static void rt_mutex_adjust_prio(struct task_struct *task)
{
unsigned long flags;
raw_spin_lock_irqsave(&task->pi_lock, flags);
__rt_mutex_adjust_prio(task);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
}
/*
* Max number of times we'll walk the boosting chain:
*/
int max_lock_depth = 1024;
static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
{
return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
}
/*
* Adjust the priority chain. Also used for deadlock detection.
* Decreases task's usage by one - may thus free the task.
* Returns 0 or -EDEADLK.
*/
static int rt_mutex_adjust_prio_chain(struct task_struct *task,
int deadlock_detect,
struct rt_mutex *orig_lock,
struct rt_mutex *next_lock,
struct rt_mutex_waiter *orig_waiter,
struct task_struct *top_task)
{
struct rt_mutex *lock;
struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter;
int detect_deadlock, ret = 0, depth = 0;
unsigned long flags;
detect_deadlock = debug_rt_mutex_detect_deadlock(orig_waiter,
deadlock_detect);
/*
* The (de)boosting is a step by step approach with a lot of
* pitfalls. We want this to be preemptible and we want hold a
* maximum of two locks per step. So we have to check
* carefully whether things change under us.
*/
again:
if (++depth > max_lock_depth) {
static int prev_max;
/*
* Print this only once. If the admin changes the limit,
* print a new message when reaching the limit again.
*/
if (prev_max != max_lock_depth) {
prev_max = max_lock_depth;
printk(KERN_WARNING "Maximum lock depth %d reached "
"task: %s (%d)\n", max_lock_depth,
top_task->comm, task_pid_nr(top_task));
}
put_task_struct(task);
return -EDEADLK;
}
retry:
/*
* Task can not go away as we did a get_task() before !
*/
raw_spin_lock_irqsave(&task->pi_lock, flags);
waiter = task->pi_blocked_on;
/*
* Check whether the end of the boosting chain has been
* reached or the state of the chain has changed while we
* dropped the locks.
*/
if (!waiter)
goto out_unlock_pi;
/*
* Check the orig_waiter state. After we dropped the locks,
* the previous owner of the lock might have released the lock.
*/
if (orig_waiter && !rt_mutex_owner(orig_lock))
goto out_unlock_pi;
/*
* We dropped all locks after taking a refcount on @task, so
* the task might have moved on in the lock chain or even left
* the chain completely and blocks now on an unrelated lock or
* on @orig_lock.
*
* We stored the lock on which @task was blocked in @next_lock,
* so we can detect the chain change.
*/
if (next_lock != waiter->lock)
goto out_unlock_pi;
/*
* Drop out, when the task has no waiters. Note,
* top_waiter can be NULL, when we are in the deboosting
* mode!
*/
if (top_waiter) {
if (!task_has_pi_waiters(task))
goto out_unlock_pi;
/*
* If deadlock detection is off, we stop here if we
* are not the top pi waiter of the task.
*/
if (!detect_deadlock && top_waiter != task_top_pi_waiter(task))
goto out_unlock_pi;
}
/*
* When deadlock detection is off then we check, if further
* priority adjustment is necessary.
*/
if (!detect_deadlock && waiter->list_entry.prio == task->prio)
goto out_unlock_pi;
lock = waiter->lock;
if (!raw_spin_trylock(&lock->wait_lock)) {
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
cpu_relax();
goto retry;
}
/*
* Deadlock detection. If the lock is the same as the original
* lock which caused us to walk the lock chain or if the
* current lock is owned by the task which initiated the chain
* walk, we detected a deadlock.
*/
if (lock == orig_lock || rt_mutex_owner(lock) == top_task) {
debug_rt_mutex_deadlock(deadlock_detect, orig_waiter, lock);
raw_spin_unlock(&lock->wait_lock);
ret = -EDEADLK;
goto out_unlock_pi;
}
top_waiter = rt_mutex_top_waiter(lock);
/* Requeue the waiter */
plist_del(&waiter->list_entry, &lock->wait_list);
waiter->list_entry.prio = task->prio;
plist_add(&waiter->list_entry, &lock->wait_list);
/* Release the task */
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
if (!rt_mutex_owner(lock)) {
/*
* If the requeue above changed the top waiter, then we need
* to wake the new top waiter up to try to get the lock.
*/
if (top_waiter != rt_mutex_top_waiter(lock))
wake_up_process(rt_mutex_top_waiter(lock)->task);
raw_spin_unlock(&lock->wait_lock);
goto out_put_task;
}
put_task_struct(task);
/* Grab the next task */
task = rt_mutex_owner(lock);
get_task_struct(task);
raw_spin_lock_irqsave(&task->pi_lock, flags);
if (waiter == rt_mutex_top_waiter(lock)) {
/* Boost the owner */
plist_del(&top_waiter->pi_list_entry, &task->pi_waiters);
waiter->pi_list_entry.prio = waiter->list_entry.prio;
plist_add(&waiter->pi_list_entry, &task->pi_waiters);
__rt_mutex_adjust_prio(task);
} else if (top_waiter == waiter) {
/* Deboost the owner */
plist_del(&waiter->pi_list_entry, &task->pi_waiters);
waiter = rt_mutex_top_waiter(lock);
waiter->pi_list_entry.prio = waiter->list_entry.prio;
plist_add(&waiter->pi_list_entry, &task->pi_waiters);
__rt_mutex_adjust_prio(task);
}
/*
* Check whether the task which owns the current lock is pi
* blocked itself. If yes we store a pointer to the lock for
* the lock chain change detection above. After we dropped
* task->pi_lock next_lock cannot be dereferenced anymore.
*/
next_lock = task_blocked_on_lock(task);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
top_waiter = rt_mutex_top_waiter(lock);
raw_spin_unlock(&lock->wait_lock);
/*
* We reached the end of the lock chain. Stop right here. No
* point to go back just to figure that out.
*/
if (!next_lock)
goto out_put_task;
if (!detect_deadlock && waiter != top_waiter)
goto out_put_task;
goto again;
out_unlock_pi:
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
out_put_task:
put_task_struct(task);
return ret;
}
/*
* Try to take an rt-mutex
*
* Must be called with lock->wait_lock held.
*
* @lock: the lock to be acquired.
* @task: the task which wants to acquire the lock
* @waiter: the waiter that is queued to the lock's wait list. (could be NULL)
*/
static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
struct rt_mutex_waiter *waiter)
{
/*
* We have to be careful here if the atomic speedups are
* enabled, such that, when
* - no other waiter is on the lock
* - the lock has been released since we did the cmpxchg
* the lock can be released or taken while we are doing the
* checks and marking the lock with RT_MUTEX_HAS_WAITERS.
*
* The atomic acquire/release aware variant of
* mark_rt_mutex_waiters uses a cmpxchg loop. After setting
* the WAITERS bit, the atomic release / acquire can not
* happen anymore and lock->wait_lock protects us from the
* non-atomic case.
*
* Note, that this might set lock->owner =
* RT_MUTEX_HAS_WAITERS in the case the lock is not contended
* any more. This is fixed up when we take the ownership.
* This is the transitional state explained at the top of this file.
*/
mark_rt_mutex_waiters(lock);
if (rt_mutex_owner(lock))
return 0;
/*
* It will get the lock because of one of these conditions:
* 1) there is no waiter
* 2) higher priority than waiters
* 3) it is top waiter
*/
if (rt_mutex_has_waiters(lock)) {
if (task->prio >= rt_mutex_top_waiter(lock)->list_entry.prio) {
if (!waiter || waiter != rt_mutex_top_waiter(lock))
return 0;
}
}
if (waiter || rt_mutex_has_waiters(lock)) {
unsigned long flags;
struct rt_mutex_waiter *top;
raw_spin_lock_irqsave(&task->pi_lock, flags);
/* remove the queued waiter. */
if (waiter) {
plist_del(&waiter->list_entry, &lock->wait_list);
task->pi_blocked_on = NULL;
}
/*
* We have to enqueue the top waiter(if it exists) into
* task->pi_waiters list.
*/
if (rt_mutex_has_waiters(lock)) {
top = rt_mutex_top_waiter(lock);
top->pi_list_entry.prio = top->list_entry.prio;
plist_add(&top->pi_list_entry, &task->pi_waiters);
}
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
}
/* We got the lock. */
debug_rt_mutex_lock(lock);
rt_mutex_set_owner(lock, task);
rt_mutex_deadlock_account_lock(lock, task);
return 1;
}
/*
* Task blocks on lock.
*
* Prepare waiter and propagate pi chain
*
* This must be called with lock->wait_lock held.
*/
static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
struct rt_mutex_waiter *waiter,
struct task_struct *task,
int detect_deadlock)
{
struct task_struct *owner = rt_mutex_owner(lock);
struct rt_mutex_waiter *top_waiter = waiter;
struct rt_mutex *next_lock;
int chain_walk = 0, res;
unsigned long flags;
/*
* Early deadlock detection. We really don't want the task to
* enqueue on itself just to untangle the mess later. It's not
* only an optimization. We drop the locks, so another waiter
* can come in before the chain walk detects the deadlock. So
* the other will detect the deadlock and return -EDEADLOCK,
* which is wrong, as the other waiter is not in a deadlock
* situation.
*/
if (owner == task)
return -EDEADLK;
raw_spin_lock_irqsave(&task->pi_lock, flags);
__rt_mutex_adjust_prio(task);
waiter->task = task;
waiter->lock = lock;
plist_node_init(&waiter->list_entry, task->prio);
plist_node_init(&waiter->pi_list_entry, task->prio);
/* Get the top priority waiter on the lock */
if (rt_mutex_has_waiters(lock))
top_waiter = rt_mutex_top_waiter(lock);
plist_add(&waiter->list_entry, &lock->wait_list);
task->pi_blocked_on = waiter;
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
if (!owner)
return 0;
raw_spin_lock_irqsave(&owner->pi_lock, flags);
if (waiter == rt_mutex_top_waiter(lock)) {
plist_del(&top_waiter->pi_list_entry, &owner->pi_waiters);
plist_add(&waiter->pi_list_entry, &owner->pi_waiters);
__rt_mutex_adjust_prio(owner);
if (owner->pi_blocked_on)
chain_walk = 1;
} else if (debug_rt_mutex_detect_deadlock(waiter, detect_deadlock)) {
chain_walk = 1;
}
/* Store the lock on which owner is blocked or NULL */
next_lock = task_blocked_on_lock(owner);
raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
/*
* Even if full deadlock detection is on, if the owner is not
* blocked itself, we can avoid finding this out in the chain
* walk.
*/
if (!chain_walk || !next_lock)
return 0;
/*
* The owner can't disappear while holding a lock,
* so the owner struct is protected by wait_lock.
* Gets dropped in rt_mutex_adjust_prio_chain()!
*/
get_task_struct(owner);
raw_spin_unlock(&lock->wait_lock);
res = rt_mutex_adjust_prio_chain(owner, detect_deadlock, lock,
next_lock, waiter, task);
raw_spin_lock(&lock->wait_lock);
return res;
}
/*
* Wake up the next waiter on the lock.
*
* Remove the top waiter from the current tasks pi waiter list and
* wake it up.
*
* Called with lock->wait_lock held.
*/
static void wakeup_next_waiter(struct rt_mutex *lock)
{
struct rt_mutex_waiter *waiter;
unsigned long flags;
raw_spin_lock_irqsave(¤t->pi_lock, flags);
waiter = rt_mutex_top_waiter(lock);
/*
* Remove it from current->pi_waiters. We do not adjust a
* possible priority boost right now. We execute wakeup in the
* boosted mode and go back to normal after releasing
* lock->wait_lock.
*/
plist_del(&waiter->pi_list_entry, ¤t->pi_waiters);
/*
* As we are waking up the top waiter, and the waiter stays
* queued on the lock until it gets the lock, this lock
* obviously has waiters. Just set the bit here and this has
* the added benefit of forcing all new tasks into the
* slow path making sure no task of lower priority than
* the top waiter can steal this lock.
*/
lock->owner = (void *) RT_MUTEX_HAS_WAITERS;
raw_spin_unlock_irqrestore(¤t->pi_lock, flags);
/*
* It's safe to dereference waiter as it cannot go away as
* long as we hold lock->wait_lock. The waiter task needs to
* acquire it in order to dequeue the waiter.
*/
wake_up_process(waiter->task);
}
/*
* Remove a waiter from a lock and give up
*
* Must be called with lock->wait_lock held and
* have just failed to try_to_take_rt_mutex().
*/
static void remove_waiter(struct rt_mutex *lock,
struct rt_mutex_waiter *waiter)
{
int first = (waiter == rt_mutex_top_waiter(lock));
struct task_struct *owner = rt_mutex_owner(lock);
struct rt_mutex *next_lock = NULL;
unsigned long flags;
raw_spin_lock_irqsave(¤t->pi_lock, flags);
plist_del(&waiter->list_entry, &lock->wait_list);
current->pi_blocked_on = NULL;
raw_spin_unlock_irqrestore(¤t->pi_lock, flags);
if (!owner)
return;
if (first) {
raw_spin_lock_irqsave(&owner->pi_lock, flags);
plist_del(&waiter->pi_list_entry, &owner->pi_waiters);
if (rt_mutex_has_waiters(lock)) {
struct rt_mutex_waiter *next;
next = rt_mutex_top_waiter(lock);
plist_add(&next->pi_list_entry, &owner->pi_waiters);
}
__rt_mutex_adjust_prio(owner);
/* Store the lock on which owner is blocked or NULL */
next_lock = task_blocked_on_lock(owner);
raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
}
WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
if (!next_lock)
return;
/* gets dropped in rt_mutex_adjust_prio_chain()! */
get_task_struct(owner);
raw_spin_unlock(&lock->wait_lock);
rt_mutex_adjust_prio_chain(owner, 0, lock, next_lock, NULL, current);
raw_spin_lock(&lock->wait_lock);
}
/*
* Recheck the pi chain, in case we got a priority setting
*
* Called from sched_setscheduler
*/
void rt_mutex_adjust_pi(struct task_struct *task)
{
struct rt_mutex_waiter *waiter;
struct rt_mutex *next_lock;
unsigned long flags;
raw_spin_lock_irqsave(&task->pi_lock, flags);
waiter = task->pi_blocked_on;
if (!waiter || waiter->list_entry.prio == task->prio) {
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
return;
}
next_lock = waiter->lock;
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
/* gets dropped in rt_mutex_adjust_prio_chain()! */
get_task_struct(task);
rt_mutex_adjust_prio_chain(task, 0, NULL, next_lock, NULL, task);
}
/**
* __rt_mutex_slowlock() - Perform the wait-wake-try-to-take loop
* @lock: the rt_mutex to take
* @state: the state the task should block in (TASK_INTERRUPTIBLE
* or TASK_UNINTERRUPTIBLE)
* @timeout: the pre-initialized and started timer, or NULL for none
* @waiter: the pre-initialized rt_mutex_waiter
*
* lock->wait_lock must be held by the caller.
*/
static int __sched
__rt_mutex_slowlock(struct rt_mutex *lock, int state,
struct hrtimer_sleeper *timeout,
struct rt_mutex_waiter *waiter)
{
int ret = 0;
for (;;) {
/* Try to acquire the lock: */
if (try_to_take_rt_mutex(lock, current, waiter))
break;
/*
* TASK_INTERRUPTIBLE checks for signals and
* timeout. Ignored otherwise.
*/
if (unlikely(state == TASK_INTERRUPTIBLE)) {
/* Signal pending? */
if (signal_pending(current))
ret = -EINTR;
if (timeout && !timeout->task)
ret = -ETIMEDOUT;
if (ret)
break;
}
raw_spin_unlock(&lock->wait_lock);
debug_rt_mutex_print_deadlock(waiter);
schedule_rt_mutex(lock);
raw_spin_lock(&lock->wait_lock);
set_current_state(state);
}
return ret;
}
static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
struct rt_mutex_waiter *w)
{
/*
* If the result is not -EDEADLOCK or the caller requested
* deadlock detection, nothing to do here.
*/
if (res != -EDEADLOCK || detect_deadlock)
return;
/*
* Yell lowdly and stop the task right here.
*/
rt_mutex_print_deadlock(w);
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
schedule();
}
}
/*
* Slow path lock function:
*/
static int __sched
rt_mutex_slowlock(struct rt_mutex *lock, int state,
struct hrtimer_sleeper *timeout,
int detect_deadlock)
{
struct rt_mutex_waiter waiter;
int ret = 0;
debug_rt_mutex_init_waiter(&waiter);
raw_spin_lock(&lock->wait_lock);
/* Try to acquire the lock again: */
if (try_to_take_rt_mutex(lock, current, NULL)) {
raw_spin_unlock(&lock->wait_lock);
return 0;
}
set_current_state(state);
/* Setup the timer, when timeout != NULL */
if (unlikely(timeout)) {
hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS);
if (!hrtimer_active(&timeout->timer))
timeout->task = NULL;
}
ret = task_blocks_on_rt_mutex(lock, &waiter, current, detect_deadlock);
if (likely(!ret))
ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
set_current_state(TASK_RUNNING);
if (unlikely(ret)) {
remove_waiter(lock, &waiter);
rt_mutex_handle_deadlock(ret, detect_deadlock, &waiter);
}
/*
* try_to_take_rt_mutex() sets the waiter bit
* unconditionally. We might have to fix that up.
*/
fixup_rt_mutex_waiters(lock);
raw_spin_unlock(&lock->wait_lock);
/* Remove pending timer: */
if (unlikely(timeout))
hrtimer_cancel(&timeout->timer);
debug_rt_mutex_free_waiter(&waiter);
return ret;
}
/*
* Slow path try-lock function:
*/
static inline int
rt_mutex_slowtrylock(struct rt_mutex *lock)
{
int ret = 0;
raw_spin_lock(&lock->wait_lock);
if (likely(rt_mutex_owner(lock) != current)) {
ret = try_to_take_rt_mutex(lock, current, NULL);
/*
* try_to_take_rt_mutex() sets the lock waiters
* bit unconditionally. Clean this up.
*/
fixup_rt_mutex_waiters(lock);
}
raw_spin_unlock(&lock->wait_lock);
return ret;
}
/*
* Slow path to release a rt-mutex:
*/
static void __sched
rt_mutex_slowunlock(struct rt_mutex *lock)
{
raw_spin_lock(&lock->wait_lock);
debug_rt_mutex_unlock(lock);
rt_mutex_deadlock_account_unlock(current);
/*
* We must be careful here if the fast path is enabled. If we
* have no waiters queued we cannot set owner to NULL here
* because of:
*
* foo->lock->owner = NULL;
* rtmutex_lock(foo->lock); <- fast path
* free = atomic_dec_and_test(foo->refcnt);
* rtmutex_unlock(foo->lock); <- fast path
* if (free)
* kfree(foo);
* raw_spin_unlock(foo->lock->wait_lock);
*
* So for the fastpath enabled kernel:
*
* Nothing can set the waiters bit as long as we hold
* lock->wait_lock. So we do the following sequence:
*
* owner = rt_mutex_owner(lock);
* clear_rt_mutex_waiters(lock);
* raw_spin_unlock(&lock->wait_lock);
* if (cmpxchg(&lock->owner, owner, 0) == owner)
* return;
* goto retry;
*
* The fastpath disabled variant is simple as all access to
* lock->owner is serialized by lock->wait_lock:
*
* lock->owner = NULL;
* raw_spin_unlock(&lock->wait_lock);
*/
while (!rt_mutex_has_waiters(lock)) {
/* Drops lock->wait_lock ! */
if (unlock_rt_mutex_safe(lock) == true)
return;
/* Relock the rtmutex and try again */
raw_spin_lock(&lock->wait_lock);
}
/*
* The wakeup next waiter path does not suffer from the above
* race. See the comments there.
*/
wakeup_next_waiter(lock);
raw_spin_unlock(&lock->wait_lock);
/* Undo pi boosting if necessary: */
rt_mutex_adjust_prio(current);
}
/*
* debug aware fast / slowpath lock,trylock,unlock
*
* The atomic acquire/release ops are compiled away, when either the
* architecture does not support cmpxchg or when debugging is enabled.
*/
static inline int
rt_mutex_fastlock(struct rt_mutex *lock, int state,
int detect_deadlock,
int (*slowfn)(struct rt_mutex *lock, int state,
struct hrtimer_sleeper *timeout,
int detect_deadlock))
{
if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) {
rt_mutex_deadlock_account_lock(lock, current);
return 0;
} else
return slowfn(lock, state, NULL, detect_deadlock);
}
static inline int
rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
struct hrtimer_sleeper *timeout, int detect_deadlock,
int (*slowfn)(struct rt_mutex *lock, int state,
struct hrtimer_sleeper *timeout,
int detect_deadlock))
{
if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) {
rt_mutex_deadlock_account_lock(lock, current);
return 0;
} else
return slowfn(lock, state, timeout, detect_deadlock);
}
static inline int
rt_mutex_fasttrylock(struct rt_mutex *lock,
int (*slowfn)(struct rt_mutex *lock))
{
if (likely(rt_mutex_cmpxchg(lock, NULL, current))) {
rt_mutex_deadlock_account_lock(lock, current);
return 1;
}
return slowfn(lock);
}
static inline void
rt_mutex_fastunlock(struct rt_mutex *lock,
void (*slowfn)(struct rt_mutex *lock))
{
if (likely(rt_mutex_cmpxchg(lock, current, NULL)))
rt_mutex_deadlock_account_unlock(current);
else
slowfn(lock);
}
/**
* rt_mutex_lock - lock a rt_mutex
*
* @lock: the rt_mutex to be locked
*/
void __sched rt_mutex_lock(struct rt_mutex *lock)
{
might_sleep();
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, 0, rt_mutex_slowlock);
}
EXPORT_SYMBOL_GPL(rt_mutex_lock);
/**
* rt_mutex_lock_interruptible - lock a rt_mutex interruptible
*
* @lock: the rt_mutex to be locked
* @detect_deadlock: deadlock detection on/off
*
* Returns:
* 0 on success
* -EINTR when interrupted by a signal
* -EDEADLK when the lock would deadlock (when deadlock detection is on)
*/
int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock,
int detect_deadlock)
{
might_sleep();
return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE,
detect_deadlock, rt_mutex_slowlock);
}
EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
/**
* rt_mutex_timed_lock - lock a rt_mutex interruptible
* the timeout structure is provided
* by the caller
*
* @lock: the rt_mutex to be locked
* @timeout: timeout structure or NULL (no timeout)
* @detect_deadlock: deadlock detection on/off
*
* Returns:
* 0 on success
* -EINTR when interrupted by a signal
* -ETIMEDOUT when the timeout expired
* -EDEADLK when the lock would deadlock (when deadlock detection is on)
*/
int
rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout,
int detect_deadlock)
{
might_sleep();
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
detect_deadlock, rt_mutex_slowlock);
}
EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
/**
* rt_mutex_trylock - try to lock a rt_mutex
*
* @lock: the rt_mutex to be locked
*
* Returns 1 on success and 0 on contention
*/
int __sched rt_mutex_trylock(struct rt_mutex *lock)
{
return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
}
EXPORT_SYMBOL_GPL(rt_mutex_trylock);
/**
* rt_mutex_unlock - unlock a rt_mutex
*
* @lock: the rt_mutex to be unlocked
*/
void __sched rt_mutex_unlock(struct rt_mutex *lock)
{
rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
}
EXPORT_SYMBOL_GPL(rt_mutex_unlock);
/**
* rt_mutex_destroy - mark a mutex unusable
* @lock: the mutex to be destroyed
*
* This function marks the mutex uninitialized, and any subsequent
* use of the mutex is forbidden. The mutex must not be locked when
* this function is called.
*/
void rt_mutex_destroy(struct rt_mutex *lock)
{
WARN_ON(rt_mutex_is_locked(lock));
#ifdef CONFIG_DEBUG_RT_MUTEXES
lock->magic = NULL;
#endif
}
EXPORT_SYMBOL_GPL(rt_mutex_destroy);
/**
* __rt_mutex_init - initialize the rt lock
*
* @lock: the rt lock to be initialized
*
* Initialize the rt lock to unlocked state.
*
* Initializing of a locked rt lock is not allowed
*/
void __rt_mutex_init(struct rt_mutex *lock, const char *name)
{
lock->owner = NULL;
raw_spin_lock_init(&lock->wait_lock);
plist_head_init(&lock->wait_list);
debug_rt_mutex_init(lock, name);
}
EXPORT_SYMBOL_GPL(__rt_mutex_init);
/**
* rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
* proxy owner
*
* @lock: the rt_mutex to be locked
* @proxy_owner:the task to set as owner
*
* No locking. Caller has to do serializing itself
* Special API call for PI-futex support
*/
void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
struct task_struct *proxy_owner)
{
__rt_mutex_init(lock, NULL);
debug_rt_mutex_proxy_lock(lock, proxy_owner);
rt_mutex_set_owner(lock, proxy_owner);
rt_mutex_deadlock_account_lock(lock, proxy_owner);
}
/**
* rt_mutex_proxy_unlock - release a lock on behalf of owner
*
* @lock: the rt_mutex to be locked
*
* No locking. Caller has to do serializing itself
* Special API call for PI-futex support
*/
void rt_mutex_proxy_unlock(struct rt_mutex *lock,
struct task_struct *proxy_owner)
{
debug_rt_mutex_proxy_unlock(lock);
rt_mutex_set_owner(lock, NULL);
rt_mutex_deadlock_account_unlock(proxy_owner);
}
/**
* rt_mutex_start_proxy_lock() - Start lock acquisition for another task
* @lock: the rt_mutex to take
* @waiter: the pre-initialized rt_mutex_waiter
* @task: the task to prepare
* @detect_deadlock: perform deadlock detection (1) or not (0)
*
* Returns:
* 0 - task blocked on lock
* 1 - acquired the lock for task, caller should wake it up
* <0 - error
*
* Special API call for FUTEX_REQUEUE_PI support.
*/
int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
struct rt_mutex_waiter *waiter,
struct task_struct *task, int detect_deadlock)
{
int ret;
raw_spin_lock(&lock->wait_lock);
if (try_to_take_rt_mutex(lock, task, NULL)) {
raw_spin_unlock(&lock->wait_lock);
return 1;
}
/* We enforce deadlock detection for futexes */
ret = task_blocks_on_rt_mutex(lock, waiter, task, 1);
if (ret && !rt_mutex_owner(lock)) {
/*
* Reset the return value. We might have
* returned with -EDEADLK and the owner
* released the lock while we were walking the
* pi chain. Let the waiter sort it out.
*/
ret = 0;
}
if (unlikely(ret))
remove_waiter(lock, waiter);
raw_spin_unlock(&lock->wait_lock);
debug_rt_mutex_print_deadlock(waiter);
return ret;
}
/**
* rt_mutex_next_owner - return the next owner of the lock
*
* @lock: the rt lock query
*
* Returns the next owner of the lock or NULL
*
* Caller has to serialize against other accessors to the lock
* itself.
*
* Special API call for PI-futex support
*/
struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
{
if (!rt_mutex_has_waiters(lock))
return NULL;
return rt_mutex_top_waiter(lock)->task;
}
/**
* rt_mutex_finish_proxy_lock() - Complete lock acquisition
* @lock: the rt_mutex we were woken on
* @to: the timeout, null if none. hrtimer should already have
* been started.
* @waiter: the pre-initialized rt_mutex_waiter
* @detect_deadlock: perform deadlock detection (1) or not (0)
*
* Complete the lock acquisition started our behalf by another thread.
*
* Returns:
* 0 - success
* <0 - error, one of -EINTR, -ETIMEDOUT, or -EDEADLK
*
* Special API call for PI-futex requeue support
*/
int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
struct hrtimer_sleeper *to,
struct rt_mutex_waiter *waiter,
int detect_deadlock)
{
int ret;
raw_spin_lock(&lock->wait_lock);
set_current_state(TASK_INTERRUPTIBLE);
ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
set_current_state(TASK_RUNNING);
if (unlikely(ret))
remove_waiter(lock, waiter);
/*
* try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
* have to fix that up.
*/
fixup_rt_mutex_waiters(lock);
raw_spin_unlock(&lock->wait_lock);
return ret;
}
|
c6fbcfea2349e1929358970acf02892286cd6811
|
d38ed5f31d74a79a054ed55dd9123a8d615283b9
|
/third_party/libgit2/tests/index/names.c
|
369318b031ab99852ef640f76aa94d0b8aa150ba
|
[
"GPL-2.0-only",
"LicenseRef-scancode-public-domain",
"GCC-exception-2.0",
"LGPL-2.0-or-later",
"Zlib",
"LGPL-2.1-or-later",
"LGPL-2.1-only",
"ISC",
"MIT",
"Apache-2.0"
] |
permissive
|
chigraph/chigraph
|
8ff76a14337da29fa2b2a84d5c35f2eac4156c6e
|
6981bdd6763db54edfe284c1f7d223193584c69a
|
refs/heads/master
| 2022-12-21T13:46:57.273039
| 2022-12-17T18:41:19
| 2022-12-17T18:41:19
| 60,776,831
| 364
| 65
|
Apache-2.0
| 2019-12-13T14:46:43
| 2016-06-09T13:27:37
|
C++
|
UTF-8
|
C
| false
| false
| 5,834
|
c
|
names.c
|
#include "clar_libgit2.h"
#include "index.h"
#include "git2/sys/index.h"
#include "git2/repository.h"
#include "../reset/reset_helpers.h"
static git_repository *repo;
static git_index *repo_index;
#define TEST_REPO_PATH "mergedrepo"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
/* Fixture setup and teardown */
void test_index_names__initialize(void)
{
repo = cl_git_sandbox_init("mergedrepo");
git_repository_index(&repo_index, repo);
}
void test_index_names__cleanup(void)
{
git_index_free(repo_index);
repo_index = NULL;
cl_git_sandbox_cleanup();
}
static void index_add_conflicts(void)
{
git_index_entry entry = {{0}};
const char *paths[][3] = {
{ "ancestor", "ours", "theirs" },
{ "ancestor2", "ours2", "theirs2" },
{ "ancestor3", "ours3", "theirs3" } };
const char **conflict;
size_t i;
for (i = 0; i < ARRAY_SIZE(paths); i++) {
conflict = paths[i];
/* ancestor */
entry.path = conflict[0];
entry.mode = GIT_FILEMODE_BLOB;
GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_ANCESTOR);
git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
cl_git_pass(git_index_add(repo_index, &entry));
/* ours */
entry.path = conflict[1];
entry.mode = GIT_FILEMODE_BLOB;
GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_OURS);
git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
cl_git_pass(git_index_add(repo_index, &entry));
/* theirs */
entry.path = conflict[2];
entry.mode = GIT_FILEMODE_BLOB;
GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_THEIRS);
git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
cl_git_pass(git_index_add(repo_index, &entry));
}
}
void test_index_names__add(void)
{
const git_index_name_entry *conflict_name;
index_add_conflicts();
cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));
cl_assert(git_index_name_entrycount(repo_index) == 3);
conflict_name = git_index_name_get_byindex(repo_index, 0);
cl_assert(strcmp(conflict_name->ancestor, "ancestor") == 0);
cl_assert(strcmp(conflict_name->ours, "ours") == 0);
cl_assert(strcmp(conflict_name->theirs, "theirs") == 0);
conflict_name = git_index_name_get_byindex(repo_index, 1);
cl_assert(strcmp(conflict_name->ancestor, "ancestor2") == 0);
cl_assert(strcmp(conflict_name->ours, "ours2") == 0);
cl_assert(conflict_name->theirs == NULL);
conflict_name = git_index_name_get_byindex(repo_index, 2);
cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
cl_assert(conflict_name->ours == NULL);
cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
cl_git_pass(git_index_write(repo_index));
}
void test_index_names__roundtrip(void)
{
const git_index_name_entry *conflict_name;
cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));
cl_git_pass(git_index_write(repo_index));
git_index_clear(repo_index);
cl_assert(git_index_name_entrycount(repo_index) == 0);
cl_git_pass(git_index_read(repo_index, true));
cl_assert(git_index_name_entrycount(repo_index) == 3);
conflict_name = git_index_name_get_byindex(repo_index, 0);
cl_assert(strcmp(conflict_name->ancestor, "ancestor") == 0);
cl_assert(strcmp(conflict_name->ours, "ours") == 0);
cl_assert(strcmp(conflict_name->theirs, "theirs") == 0);
conflict_name = git_index_name_get_byindex(repo_index, 1);
cl_assert(strcmp(conflict_name->ancestor, "ancestor2") == 0);
cl_assert(strcmp(conflict_name->ours, "ours2") == 0);
cl_assert(conflict_name->theirs == NULL);
conflict_name = git_index_name_get_byindex(repo_index, 2);
cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
cl_assert(conflict_name->ours == NULL);
cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
}
void test_index_names__cleaned_on_reset_hard(void)
{
git_object *target;
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_names__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(target);
}
void test_index_names__cleaned_on_reset_mixed(void)
{
git_object *target;
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_names__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
cl_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(target);
}
void test_index_names__cleaned_on_checkout_tree(void)
{
git_oid oid;
git_object *obj;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_UPDATE_ONLY;
test_index_names__add();
cl_git_pass(git_reference_name_to_id(&oid, repo, "refs/heads/master"));
cl_git_pass(git_object_lookup(&obj, repo, &oid, GIT_OBJECT_ANY));
cl_git_pass(git_checkout_tree(repo, obj, &opts));
cl_assert_equal_sz(0, git_index_name_entrycount(repo_index));
git_object_free(obj);
}
void test_index_names__cleaned_on_checkout_head(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_UPDATE_ONLY;
test_index_names__add();
cl_git_pass(git_checkout_head(repo, &opts));
cl_assert_equal_sz(0, git_index_name_entrycount(repo_index));
}
void test_index_names__retained_on_checkout_index(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_UPDATE_ONLY;
test_index_names__add();
cl_git_pass(git_checkout_index(repo, repo_index, &opts));
cl_assert(git_index_name_entrycount(repo_index) > 0);
}
|
27e77075941177b59abcf0b4cab1cc29ca3bc55d
|
c8b39acfd4a857dc15ed3375e0d93e75fa3f1f64
|
/Engine/Source/Programs/UnrealVersionSelector/Private/PlatformInstallation.h
|
0240e2b4b2f30a59165a91b2a66b8b213b9991a2
|
[
"MIT",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
windystrife/UnrealEngine_NVIDIAGameWorks
|
c3c7863083653caf1bc67d3ef104fb4b9f302e2a
|
b50e6338a7c5b26374d66306ebc7807541ff815e
|
refs/heads/4.18-GameWorks
| 2023-03-11T02:50:08.471040
| 2022-01-13T20:50:29
| 2022-01-13T20:50:29
| 124,100,479
| 262
| 179
|
MIT
| 2022-12-16T05:36:38
| 2018-03-06T15:44:09
|
C++
|
UTF-8
|
C
| false
| false
| 340
|
h
|
PlatformInstallation.h
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#pragma once
#if PLATFORM_WINDOWS
#include "Windows/WindowsPlatformInstallation.h"
typedef FWindowsPlatformInstallation FPlatformInstallation;
#else
#include "GenericPlatform/GenericPlatformInstallation.h"
typedef FGenericPlatformInstallation FPlatformInstallation;
#endif
|
26485499fecc406a663ac46d99c3307669919cc2
|
ffdc77394c5b5532b243cf3c33bd584cbdc65cb7
|
/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/intrinsics/sse/DepthwiseFp32_Sse.c
|
777d626a6af9fad7afd8552ebf52eb2b51605e03
|
[
"Apache-2.0",
"LicenseRef-scancode-proprietary-license",
"MPL-1.0",
"OpenSSL",
"LGPL-3.0-only",
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause-Open-MPI",
"MIT",
"MPL-2.0-no-copyleft-exception",
"NTP",
"BSD-3-Clause",
"GPL-1.0-or-later",
"0BSD",
"MPL-2.0",
"LicenseRef-scancode-free-unknown",
"AGPL-3.0-only",
"Libpng",
"MPL-1.1",
"IJG",
"GPL-2.0-only",
"BSL-1.0",
"Zlib",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-python-cwi",
"BSD-2-Clause",
"LicenseRef-scancode-gary-s-brown",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"Python-2.0",
"LicenseRef-scancode-mit-nagy",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference",
"Unlicense"
] |
permissive
|
mindspore-ai/mindspore
|
ca7d5bb51a3451c2705ff2e583a740589d80393b
|
54acb15d435533c815ee1bd9f6dc0b56b4d4cf83
|
refs/heads/master
| 2023-07-29T09:17:11.051569
| 2023-07-17T13:14:15
| 2023-07-17T13:14:15
| 239,714,835
| 4,178
| 768
|
Apache-2.0
| 2023-07-26T22:31:11
| 2020-02-11T08:43:48
|
C++
|
UTF-8
|
C
| false
| false
| 12,834
|
c
|
DepthwiseFp32_Sse.c
|
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef ENABLE_SSE
#include "nnacl/intrinsics/ms_simd_instructions.h"
#include "nnacl/fp32/conv_depthwise_fp32.h"
#include "nnacl/intrinsics/sse/sse_common.h"
#ifndef ENABLE_AVX
void ConvDwFp32Border(float *dst, const float *src, const float *weight, const float *bias, size_t height, size_t width,
size_t in_kh_step, size_t in_kw_step, size_t kernel_w_step, size_t relu, size_t relu6) {
in_kh_step /= sizeof(float);
in_kw_step /= sizeof(float);
kernel_w_step /= sizeof(float);
const float *src_kh = src;
const float *weight_kh = weight;
__m128 dst_ma = _mm_setzero_ps();
for (int kh = 0; kh < height; kh++) {
const float *src_kw = src_kh;
const float *weight_kw = weight_kh;
int c1 = 0;
int c4 = DOWN_DIV(width, C4NUM) * C4NUM;
int c2 = DOWN_DIV(width, C2NUM) * C2NUM;
// c4 loop
for (; c1 < c4; c1 += C4NUM) {
__m128 src_ma1 = _mm_loadu_ps(src_kw);
__m128 src_ma2 = _mm_loadu_ps(src_kw + in_kw_step);
__m128 src_ma3 = _mm_loadu_ps(src_kw + 2 * in_kw_step);
__m128 src_ma4 = _mm_loadu_ps(src_kw + 3 * in_kw_step);
__m128 weight_ma1 = _mm_loadu_ps(weight_kw);
__m128 weight_ma2 = _mm_loadu_ps(weight_kw + C4NUM);
__m128 weight_ma3 = _mm_loadu_ps(weight_kw + 2 * C4NUM);
__m128 weight_ma4 = _mm_loadu_ps(weight_kw + 3 * C4NUM);
__m128 mul_ma1 = _mm_mul_ps(src_ma1, weight_ma1);
__m128 mul_ma2 = _mm_mul_ps(src_ma2, weight_ma2);
__m128 mul_ma3 = _mm_mul_ps(src_ma3, weight_ma3);
__m128 mul_ma4 = _mm_mul_ps(src_ma4, weight_ma4);
dst_ma = _mm_add_ps(dst_ma, mul_ma1);
dst_ma = _mm_add_ps(dst_ma, mul_ma2);
dst_ma = _mm_add_ps(dst_ma, mul_ma3);
dst_ma = _mm_add_ps(dst_ma, mul_ma4);
src_kw += in_kw_step * 4;
weight_kw += C4NUM * 4;
}
// c2 loop
for (; c1 < c2; c1 += C2NUM) {
__m128 src_ma1 = _mm_loadu_ps(src_kw);
__m128 src_ma2 = _mm_loadu_ps(src_kw + in_kw_step);
__m128 weight_ma1 = _mm_loadu_ps(weight_kw);
__m128 weight_ma2 = _mm_loadu_ps(weight_kw + C4NUM);
__m128 mul_ma1 = _mm_mul_ps(src_ma1, weight_ma1);
__m128 mul_ma2 = _mm_mul_ps(src_ma2, weight_ma2);
dst_ma = _mm_add_ps(dst_ma, mul_ma1);
dst_ma = _mm_add_ps(dst_ma, mul_ma2);
src_kw += in_kw_step * 2;
weight_kw += C4NUM * 2;
}
// remaining
for (; c1 < width; ++c1) {
__m128 src_ma1 = _mm_loadu_ps(src_kw);
__m128 weight_ma1 = _mm_loadu_ps(weight_kw);
__m128 mul_ma1 = _mm_mul_ps(src_ma1, weight_ma1);
dst_ma = _mm_add_ps(dst_ma, mul_ma1);
src_kw += in_kw_step;
weight_kw += C4NUM;
}
src_kh += in_kh_step;
weight_kh += kernel_w_step;
}
__m128 bias_ma = _mm_loadu_ps(bias);
dst_ma = _mm_add_ps(dst_ma, bias_ma);
__m128 zero_ma = _mm_setzero_ps();
if (relu || relu6) {
dst_ma = _mm_max_ps(zero_ma, dst_ma);
if (relu6) {
__m128 const_ma = _mm_set_ps(6.0f, 6.0f, 6.0f, 6.0f);
dst_ma = _mm_min_ps(const_ma, dst_ma);
}
}
_mm_storeu_ps(dst, dst_ma);
}
#endif
void ConvDwFp32Center(float *dst, const float *src, const float *weight, const float *bias, size_t height, size_t width,
size_t kernel_h, size_t kernel_w, size_t out_h_step, size_t block_channel, size_t in_sh_step,
size_t in_sw_step, size_t in_kh_step, size_t in_kw_step, size_t relu, size_t relu6) {
out_h_step /= sizeof(float);
block_channel /= sizeof(float);
in_sh_step /= sizeof(float);
in_sw_step /= sizeof(float);
in_kh_step /= sizeof(float);
in_kw_step /= sizeof(float);
float *dst_h = dst;
const float *src_h = src;
for (int oh = 0; oh < height; oh++) {
float *dst_w = dst_h;
const float *src_w = src_h;
int c4 = DOWN_DIV(width, C4NUM) * C4NUM;
int c2 = DOWN_DIV(width, C2NUM) * C2NUM;
int c1 = 0;
// c4 loop
for (; c1 < c4; c1 += C4NUM, dst_w += C4NUM * block_channel, src_w += C4NUM * in_sw_step) {
const float *src_kh = src_w, *weight_kh = weight;
__m128 dst_w_ma1 = _mm_setzero_ps();
__m128 dst_w_ma2 = _mm_setzero_ps();
__m128 dst_w_ma3 = _mm_setzero_ps();
__m128 dst_w_ma4 = _mm_setzero_ps();
for (int kh = 0; kh < kernel_h; kh++, src_kh += in_kh_step, weight_kh += kernel_w * C4NUM) {
const float *src_kw = src_kh, *weight_kw = weight_kh;
for (int kw = 0; kw < kernel_w; kw++, src_kw += in_kw_step, weight_kw += C4NUM) {
__m128 src_kw_ma1 = _mm_loadu_ps(src_kw);
__m128 weight_kw_ma1 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma1 = _mm_mul_ps(src_kw_ma1, weight_kw_ma1);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, tmp_ma1);
__m128 src_kw_ma2 = _mm_loadu_ps(src_kw + in_sw_step);
__m128 weight_kw_ma2 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma2 = _mm_mul_ps(src_kw_ma2, weight_kw_ma2);
dst_w_ma2 = _mm_add_ps(dst_w_ma2, tmp_ma2);
__m128 src_kw_ma3 = _mm_loadu_ps(src_kw + 2 * in_sw_step);
__m128 weight_kw_ma3 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma3 = _mm_mul_ps(src_kw_ma3, weight_kw_ma3);
dst_w_ma3 = _mm_add_ps(dst_w_ma3, tmp_ma3);
__m128 src_kw_ma4 = _mm_loadu_ps(src_kw + 3 * in_sw_step);
__m128 weight_kw_ma4 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma4 = _mm_mul_ps(src_kw_ma4, weight_kw_ma4);
dst_w_ma4 = _mm_add_ps(dst_w_ma4, tmp_ma4);
} // kernel_w loop
} // kernel_h loop
// add bias relu
__m128 bias_ma = _mm_loadu_ps(bias);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, bias_ma);
dst_w_ma2 = _mm_add_ps(dst_w_ma2, bias_ma);
dst_w_ma3 = _mm_add_ps(dst_w_ma3, bias_ma);
dst_w_ma4 = _mm_add_ps(dst_w_ma4, bias_ma);
ActBlock4(&dst_w_ma1, &dst_w_ma2, &dst_w_ma3, &dst_w_ma4, relu, relu6);
_mm_storeu_ps(dst_w, dst_w_ma1);
_mm_storeu_ps(dst_w + block_channel, dst_w_ma2);
_mm_storeu_ps(dst_w + 2 * block_channel, dst_w_ma3);
_mm_storeu_ps(dst_w + 3 * block_channel, dst_w_ma4);
} // dst_width loop
// c2 loop
for (; c1 < c2; c1 += C2NUM, dst_w += C2NUM * block_channel, src_w += C2NUM * in_sw_step) {
const float *src_kh = src_w, *weight_kh = weight;
__m128 dst_w_ma1 = _mm_setzero_ps();
__m128 dst_w_ma2 = _mm_setzero_ps();
for (int kh = 0; kh < kernel_h; kh++, src_kh += in_kh_step, weight_kh += kernel_w * C4NUM) {
const float *src_kw = src_kh, *weight_kw = weight_kh;
for (int kw = 0; kw < kernel_w; kw++, src_kw += in_kw_step, weight_kw += C4NUM) {
__m128 src_kw_ma1 = _mm_loadu_ps(src_kw);
__m128 weight_kw_ma1 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma1 = _mm_mul_ps(src_kw_ma1, weight_kw_ma1);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, tmp_ma1);
__m128 src_kw_ma2 = _mm_loadu_ps(src_kw + in_sw_step);
__m128 weight_kw_ma2 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma2 = _mm_mul_ps(src_kw_ma2, weight_kw_ma2);
dst_w_ma2 = _mm_add_ps(dst_w_ma2, tmp_ma2);
} // kernel_w loop
} // kernel_h loop
// add bias relu
__m128 bias_ma = _mm_loadu_ps(bias);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, bias_ma);
dst_w_ma2 = _mm_add_ps(dst_w_ma2, bias_ma);
ActBlock2(&dst_w_ma1, &dst_w_ma2, relu, relu6);
_mm_storeu_ps(dst_w, dst_w_ma1);
_mm_storeu_ps(dst_w + block_channel, dst_w_ma2);
}
// remaining
for (; c1 < width; c1++, dst_w += block_channel, src_w += in_sw_step) {
const float *src_kh = src_w, *weight_kh = weight;
__m128 dst_w_ma1 = _mm_setzero_ps();
for (int kh = 0; kh < kernel_h; kh++, src_kh += in_kh_step, weight_kh += kernel_w * C4NUM) {
const float *src_kw = src_kh, *weight_kw = weight_kh;
for (int kw = 0; kw < kernel_w; kw++, src_kw += in_kw_step, weight_kw += C4NUM) {
__m128 src_kw_ma1 = _mm_loadu_ps(src_kw);
__m128 weight_kw_ma1 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma1 = _mm_mul_ps(src_kw_ma1, weight_kw_ma1);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, tmp_ma1);
} // kernel_w loop
} // kernel_h loop
// add bias relu
__m128 bias_ma = _mm_loadu_ps(bias);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, bias_ma);
ActBlock1(&dst_w_ma1, relu, relu6);
_mm_storeu_ps(dst_w, dst_w_ma1);
}
dst_h += out_h_step;
src_h += in_sh_step;
} // dst_height loop
}
void DeconvDwFp32Center(float *dst, const float *src, const float *weight, size_t height, size_t width, size_t kernel_h,
size_t kernel_w, size_t out_h_step, size_t block_channel, size_t in_sh_step, size_t in_sw_step,
size_t in_kh_step, size_t in_kw_step) {
out_h_step /= sizeof(float);
block_channel /= sizeof(float);
in_sh_step /= sizeof(float);
in_sw_step /= sizeof(float);
in_kh_step /= sizeof(float);
in_kw_step /= sizeof(float);
float *dst_h = dst;
const float *src_h = src;
for (int oh = 0; oh < height; oh++) {
float *dst_w = dst_h;
const float *src_w = src_h;
for (int ow = 0; ow < width; ow++) {
float *dst_kh = dst_w;
const float *weight_kh = weight;
__m128 src_w_ma = _mm_loadu_ps(src_w);
for (int kh = 0; kh < kernel_h; kh++) {
float *dst_kw = dst_kh;
const float *weight_kw = weight_kh;
int c4 = DOWN_DIV(kernel_w, C4NUM) * C4NUM;
int c2 = DOWN_DIV(kernel_w, C2NUM) * C2NUM;
int c1 = 0;
// c4 loop
for (; c1 < c4; c1 += C4NUM) {
__m128 dst_w_ma1 = _mm_loadu_ps(dst_kw);
__m128 weight_kw_ma1 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma1 = _mm_mul_ps(src_w_ma, weight_kw_ma1);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, tmp_ma1);
_mm_storeu_ps(dst_kw, dst_w_ma1);
__m128 dst_w_ma2 = _mm_loadu_ps(dst_kw + in_kw_step);
__m128 weight_kw_ma2 = _mm_loadu_ps(weight_kw + C4NUM);
__m128 tmp_ma2 = _mm_mul_ps(src_w_ma, weight_kw_ma2);
dst_w_ma2 = _mm_add_ps(dst_w_ma2, tmp_ma2);
_mm_storeu_ps(dst_kw + in_kw_step, dst_w_ma2);
__m128 dst_w_ma3 = _mm_loadu_ps(dst_kw + 2 * in_kw_step);
__m128 weight_kw_ma3 = _mm_loadu_ps(weight_kw + 2 * C4NUM);
__m128 tmp_ma3 = _mm_mul_ps(src_w_ma, weight_kw_ma3);
dst_w_ma3 = _mm_add_ps(dst_w_ma3, tmp_ma3);
_mm_storeu_ps(dst_kw + 2 * in_kw_step, dst_w_ma3);
__m128 dst_w_ma4 = _mm_loadu_ps(dst_kw + 3 * in_kw_step);
__m128 weight_kw_ma4 = _mm_loadu_ps(weight_kw + 3 * C4NUM);
__m128 tmp_ma4 = _mm_mul_ps(src_w_ma, weight_kw_ma4);
dst_w_ma4 = _mm_add_ps(dst_w_ma4, tmp_ma4);
_mm_storeu_ps(dst_kw + 3 * in_kw_step, dst_w_ma4);
dst_kw += 4 * in_kw_step;
weight_kw += 4 * C4NUM;
}
// c2 loop
for (; c1 < c2; c1 += C2NUM) {
__m128 dst_w_ma1 = _mm_loadu_ps(dst_kw);
__m128 weight_kw_ma1 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma1 = _mm_mul_ps(src_w_ma, weight_kw_ma1);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, tmp_ma1);
_mm_storeu_ps(dst_kw, dst_w_ma1);
__m128 dst_w_ma2 = _mm_loadu_ps(dst_kw + in_kw_step);
__m128 weight_kw_ma2 = _mm_loadu_ps(weight_kw + C4NUM);
__m128 tmp_ma2 = _mm_mul_ps(src_w_ma, weight_kw_ma2);
dst_w_ma2 = _mm_add_ps(dst_w_ma2, tmp_ma2);
_mm_storeu_ps(dst_kw + in_kw_step, dst_w_ma2);
dst_kw += 2 * in_kw_step;
weight_kw += 2 * C4NUM;
}
// remaining
for (; c1 < kernel_w; ++c1) {
__m128 dst_w_ma1 = _mm_loadu_ps(dst_kw);
__m128 weight_kw_ma1 = _mm_loadu_ps(weight_kw);
__m128 tmp_ma1 = _mm_mul_ps(src_w_ma, weight_kw_ma1);
dst_w_ma1 = _mm_add_ps(dst_w_ma1, tmp_ma1);
_mm_storeu_ps(dst_kw, dst_w_ma1);
dst_kw += in_kw_step;
weight_kw += C4NUM;
} // kernel_w loop
dst_kh += in_kh_step;
weight_kh += kernel_w * C4NUM;
} // kernel_h loop
dst_w += in_sw_step;
src_w += block_channel;
} // dst_width loop
dst_h += in_sh_step;
src_h += out_h_step;
} // dst_height loop
}
#endif
|
f9aa8828e21ec8c8d00eb6ea9a21c065d7c6ffa8
|
c9bc99866cfab223c777cfb741083be3e9439d81
|
/product/juno/scp_ramfw/config_transport.c
|
64796ef329ebb38d74076cb58ed8b8df817fa73c
|
[
"BSD-3-Clause"
] |
permissive
|
ARM-software/SCP-firmware
|
4738ca86ce42d82588ddafc2226a1f353ff2c797
|
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
|
refs/heads/master
| 2023-09-01T16:13:36.962036
| 2023-08-17T13:00:20
| 2023-08-31T07:43:37
| 134,399,880
| 211
| 165
|
NOASSERTION
| 2023-09-13T14:27:10
| 2018-05-22T10:35:56
|
C
|
UTF-8
|
C
| false
| false
| 3,951
|
c
|
config_transport.c
|
/*
* Arm SCP/MCP Software
* Copyright (c) 2019-2022, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "config_power_domain.h"
#include "juno_mhu.h"
#include "juno_scmi.h"
#include "software_mmap.h"
#include <mod_transport.h>
#include <fwk_element.h>
#include <fwk_id.h>
#include <fwk_module.h>
#include <fwk_module_idx.h>
#include <stddef.h>
#include <stdint.h>
static const struct fwk_element element_table[] = {
/* JUNO_SCMI_SERVICE_IDX_PSCI_A2P */
{ .name = "",
.data =
&(struct mod_transport_channel_config){
.channel_type = MOD_TRANSPORT_CHANNEL_TYPE_COMPLETER,
.policies =
(MOD_TRANSPORT_POLICY_INIT_MAILBOX |
MOD_TRANSPORT_POLICY_SECURE),
.out_band_mailbox_address = (uintptr_t)SCMI_PAYLOAD_S_A2P_BASE,
.out_band_mailbox_size = SCMI_PAYLOAD_SIZE,
.driver_id = FWK_ID_SUB_ELEMENT_INIT(
FWK_MODULE_IDX_MHU,
JUNO_MHU_DEVICE_IDX_S,
0),
.driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MHU, 0),
.pd_source_id = FWK_ID_ELEMENT_INIT(
FWK_MODULE_IDX_POWER_DOMAIN,
POWER_DOMAIN_IDX_SYSTOP),
} },
/* JUNO_SCMI_SERVICE_IDX_OSPM_A2P_0 */
{ .name = "",
.data =
&(struct mod_transport_channel_config){
.channel_type = MOD_TRANSPORT_CHANNEL_TYPE_COMPLETER,
.policies = MOD_TRANSPORT_POLICY_INIT_MAILBOX,
.out_band_mailbox_address = (uintptr_t)SCMI_PAYLOAD_LOW_A2P_BASE,
.out_band_mailbox_size = SCMI_PAYLOAD_SIZE,
.driver_id = FWK_ID_SUB_ELEMENT_INIT(
FWK_MODULE_IDX_MHU,
JUNO_MHU_DEVICE_IDX_NS_L,
0),
.driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MHU, 0),
.pd_source_id = FWK_ID_ELEMENT_INIT(
FWK_MODULE_IDX_POWER_DOMAIN,
POWER_DOMAIN_IDX_SYSTOP),
} },
/* JUNO_SCMI_SERVICE_IDX_OSPM_A2P_1 */
{ .name = "",
.data =
&(struct mod_transport_channel_config){
.channel_type = MOD_TRANSPORT_CHANNEL_TYPE_COMPLETER,
.policies = MOD_TRANSPORT_POLICY_INIT_MAILBOX,
.out_band_mailbox_address = (uintptr_t)SCMI_PAYLOAD_HIGH_A2P_BASE,
.out_band_mailbox_size = SCMI_PAYLOAD_SIZE,
.driver_id = FWK_ID_SUB_ELEMENT_INIT(
FWK_MODULE_IDX_MHU,
JUNO_MHU_DEVICE_IDX_NS_H,
0),
.driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MHU, 0),
.pd_source_id = FWK_ID_ELEMENT_INIT(
FWK_MODULE_IDX_POWER_DOMAIN,
POWER_DOMAIN_IDX_SYSTOP),
} },
#ifdef BUILD_HAS_SCMI_NOTIFICATIONS
/* JUNO_SCMI_SERVICE_IDX_OSPM_P2A */
{ .name = "",
.data =
&(struct mod_transport_channel_config){
.channel_type = MOD_TRANSPORT_CHANNEL_TYPE_REQUESTER,
.policies = MOD_TRANSPORT_POLICY_INIT_MAILBOX,
.out_band_mailbox_address = (uintptr_t)SCMI_PAYLOAD_HIGH_P2A_BASE,
.out_band_mailbox_size = SCMI_PAYLOAD_SIZE,
.driver_id = FWK_ID_SUB_ELEMENT_INIT(
FWK_MODULE_IDX_MHU,
JUNO_MHU_DEVICE_IDX_NS_H,
1),
.driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MHU, 0),
.pd_source_id = FWK_ID_ELEMENT_INIT(
FWK_MODULE_IDX_POWER_DOMAIN,
POWER_DOMAIN_IDX_SYSTOP),
} },
#endif
[JUNO_SCMI_SERVICE_IDX_COUNT] = { 0 },
};
static const struct fwk_element *get_element_table(fwk_id_t module_id)
{
return element_table;
}
struct fwk_module_config config_transport = {
.elements = FWK_MODULE_DYNAMIC_ELEMENTS(get_element_table),
};
|
1e45d29ce0fb8da44104cb35103f8e4d19d24eaa
|
2dae12c0b60d0cdb69ea769035fa3bb60cc17814
|
/projects/miragesdk/src/dhcp-client/dhcp.c
|
5632274da3c4e580e64558e84b378b87b57ea495
|
[
"Apache-2.0"
] |
permissive
|
linuxkit/linuxkit
|
64c637614d884cd7658931f52dd9957ed84ad87f
|
959dce294c0a43b675f80419f7189393221613d4
|
refs/heads/master
| 2023-08-27T09:48:24.331778
| 2023-08-17T09:02:56
| 2023-08-17T09:02:56
| 46,932,243
| 8,488
| 1,221
|
Apache-2.0
| 2023-08-17T09:02:58
| 2015-11-26T14:48:52
|
Go
|
UTF-8
|
C
| false
| false
| 2,927
|
c
|
dhcp.c
|
/* dhcp_bpf_filter taken from bpf.c in dhcp-3.1.0
*
* Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Internet Systems Consortium, Inc.
* 950 Charter Street
* Redwood City, CA 94063
* <info@isc.org>
* http://www.isc.org/
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/ethernet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "caml/memory.h"
#include "caml/fail.h"
#include "caml/unixsupport.h"
#include "caml/signals.h"
#include "caml/alloc.h"
#include "caml/custom.h"
#include "caml/bigarray.h"
#ifdef __linux__
#include <linux/if_packet.h>
#include <linux/filter.h>
#include <net/if.h>
#include <arpa/inet.h>
#define BOOTPC 68
#define BPF_WHOLEPACKET 0x0fffffff
#ifndef BPF_ETHCOOK
# define BPF_ETHCOOK 0
#endif
static const struct sock_filter bootp_bpf_filter [] = {
/* Make sure this is an IP packet... */
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8),
/* Make sure it's a UDP packet... */
BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23 + BPF_ETHCOOK),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
/* Make sure this isn't a fragment... */
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20 + BPF_ETHCOOK),
BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
/* Get the IP header length... */
BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14 + BPF_ETHCOOK),
/* Make sure it's to the right port... */
BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16 + BPF_ETHCOOK),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTPC, 0, 1),
/* If we passed all the tests, ask for the whole packet. */
BPF_STMT(BPF_RET + BPF_K, BPF_WHOLEPACKET),
/* Otherwise, drop it. */
BPF_STMT(BPF_RET + BPF_K, 0),
};
#else
struct sock_filter {};
static const struct sock_filter bootp_bpf_filter [] = {};
#endif
/* Filters */
CAMLprim value bpf_filter(value vunit)
{
CAMLparam0();
CAMLlocal1(vfilter);
vfilter = caml_alloc_string(sizeof(bootp_bpf_filter));
memcpy(String_val(vfilter), bootp_bpf_filter, sizeof(bootp_bpf_filter));
CAMLreturn (vfilter);
}
|
6bc148226275b5bb4ac227cca91c0700266aa912
|
321d11eaee885ceb3a74db0a062f9bbdf282148c
|
/providers/implementations/ciphers/cipher_aes_siv.h
|
4a682b77c44055cb033eab1ad6be6a1e3eb9b579
|
[
"Apache-2.0",
"OpenSSL",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
openssl/openssl
|
75691ebaae957793f2ff0673f77545277dfb3988
|
5318c012885a5382eadbf95aa9c1d35664bca819
|
refs/heads/master
| 2023-09-03T15:22:52.727123
| 2023-09-01T07:10:49
| 2023-09-02T14:30:01
| 7,634,677
| 24,148
| 11,569
|
Apache-2.0
| 2023-09-14T19:48:11
| 2013-01-15T22:34:48
|
C
|
UTF-8
|
C
| false
| false
| 1,465
|
h
|
cipher_aes_siv.h
|
/*
* Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include "prov/ciphercommon.h"
#include "crypto/aes_platform.h"
#include "crypto/siv.h"
typedef struct prov_cipher_hw_aes_siv_st {
int (*initkey)(void *ctx, const uint8_t *key, size_t keylen);
int (*cipher)(void *ctx, unsigned char *out, const unsigned char *in,
size_t len);
void (*setspeed)(void *ctx, int speed);
int (*settag)(void *ctx, const unsigned char *tag, size_t tagl);
void (*cleanup)(void *ctx);
int (*dupctx)(void *src, void *dst);
} PROV_CIPHER_HW_AES_SIV;
typedef struct prov_siv_ctx_st {
unsigned int mode; /* The mode that we are using */
unsigned int enc : 1; /* Set to 1 if we are encrypting or 0 otherwise */
size_t keylen; /* The input keylength (twice the alg key length) */
size_t taglen; /* the taglen is the same as the sivlen */
SIV128_CONTEXT siv;
EVP_CIPHER *ctr; /* These are fetched - so we need to free them */
EVP_CIPHER *cbc;
const PROV_CIPHER_HW_AES_SIV *hw;
OSSL_LIB_CTX *libctx;
} PROV_AES_SIV_CTX;
const PROV_CIPHER_HW_AES_SIV *ossl_prov_cipher_hw_aes_siv(size_t keybits);
|
cefa10bd53207f14f39237e860f0a5376a007a96
|
676acab8ff535019faff7da3afb8eecc3fa127f5
|
/src/lib/mavlink/v2.0/common/mavlink_msg_terrain_request.h
|
70f75ebcef165603f71bffdc8a729551d1d32422
|
[
"Apache-2.0"
] |
permissive
|
Firmament-Autopilot/FMT-Firmware
|
f8c324577245bd7e91af436954b4ce9421acbb41
|
0212fe89820376bfbedaded519552f6b011a7b8a
|
refs/heads/master
| 2023-09-01T11:37:46.194145
| 2023-08-29T06:33:10
| 2023-08-29T06:33:10
| 402,557,689
| 351
| 143
|
Apache-2.0
| 2023-09-12T05:28:39
| 2021-09-02T20:42:56
|
C
|
UTF-8
|
C
| false
| false
| 13,813
|
h
|
mavlink_msg_terrain_request.h
|
#pragma once
// MESSAGE TERRAIN_REQUEST PACKING
#define MAVLINK_MSG_ID_TERRAIN_REQUEST 133
typedef struct __mavlink_terrain_request_t {
uint64_t mask; /*< Bitmask of requested 4x4 grids (row major 8x7 array of grids, 56 bits)*/
int32_t lat; /*< [degE7] Latitude of SW corner of first grid*/
int32_t lon; /*< [degE7] Longitude of SW corner of first grid*/
uint16_t grid_spacing; /*< [m] Grid spacing*/
} mavlink_terrain_request_t;
#define MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN 18
#define MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN 18
#define MAVLINK_MSG_ID_133_LEN 18
#define MAVLINK_MSG_ID_133_MIN_LEN 18
#define MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC 6
#define MAVLINK_MSG_ID_133_CRC 6
#if MAVLINK_COMMAND_24BIT
#define MAVLINK_MESSAGE_INFO_TERRAIN_REQUEST \
{ \
133, \
"TERRAIN_REQUEST", \
4, \
{ \
{ "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 8, offsetof(mavlink_terrain_request_t, lat) }, \
{ "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 12, offsetof(mavlink_terrain_request_t, lon) }, \
{ "grid_spacing", NULL, MAVLINK_TYPE_UINT16_T, 0, 16, offsetof(mavlink_terrain_request_t, grid_spacing) }, \
{ "mask", "0x%07x", MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_terrain_request_t, mask) }, \
} \
}
#else
#define MAVLINK_MESSAGE_INFO_TERRAIN_REQUEST \
{ \
"TERRAIN_REQUEST", \
4, \
{ \
{ "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 8, offsetof(mavlink_terrain_request_t, lat) }, \
{ "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 12, offsetof(mavlink_terrain_request_t, lon) }, \
{ "grid_spacing", NULL, MAVLINK_TYPE_UINT16_T, 0, 16, offsetof(mavlink_terrain_request_t, grid_spacing) }, \
{ "mask", "0x%07x", MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_terrain_request_t, mask) }, \
} \
}
#endif
/**
* @brief Pack a terrain_request message
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param msg The MAVLink message to compress the data into
*
* @param lat [degE7] Latitude of SW corner of first grid
* @param lon [degE7] Longitude of SW corner of first grid
* @param grid_spacing [m] Grid spacing
* @param mask Bitmask of requested 4x4 grids (row major 8x7 array of grids, 56 bits)
* @return length of the message in bytes (excluding serial stream start sign)
*/
static inline uint16_t mavlink_msg_terrain_request_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
int32_t lat, int32_t lon, uint16_t grid_spacing, uint64_t mask)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN];
_mav_put_uint64_t(buf, 0, mask);
_mav_put_int32_t(buf, 8, lat);
_mav_put_int32_t(buf, 12, lon);
_mav_put_uint16_t(buf, 16, grid_spacing);
memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN);
#else
mavlink_terrain_request_t packet;
packet.mask = mask;
packet.lat = lat;
packet.lon = lon;
packet.grid_spacing = grid_spacing;
memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN);
#endif
msg->msgid = MAVLINK_MSG_ID_TERRAIN_REQUEST;
return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
}
/**
* @brief Pack a terrain_request message on a channel
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param chan The MAVLink channel this message will be sent over
* @param msg The MAVLink message to compress the data into
* @param lat [degE7] Latitude of SW corner of first grid
* @param lon [degE7] Longitude of SW corner of first grid
* @param grid_spacing [m] Grid spacing
* @param mask Bitmask of requested 4x4 grids (row major 8x7 array of grids, 56 bits)
* @return length of the message in bytes (excluding serial stream start sign)
*/
static inline uint16_t mavlink_msg_terrain_request_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
mavlink_message_t* msg,
int32_t lat, int32_t lon, uint16_t grid_spacing, uint64_t mask)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN];
_mav_put_uint64_t(buf, 0, mask);
_mav_put_int32_t(buf, 8, lat);
_mav_put_int32_t(buf, 12, lon);
_mav_put_uint16_t(buf, 16, grid_spacing);
memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN);
#else
mavlink_terrain_request_t packet;
packet.mask = mask;
packet.lat = lat;
packet.lon = lon;
packet.grid_spacing = grid_spacing;
memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN);
#endif
msg->msgid = MAVLINK_MSG_ID_TERRAIN_REQUEST;
return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
}
/**
* @brief Encode a terrain_request struct
*
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param msg The MAVLink message to compress the data into
* @param terrain_request C-struct to read the message contents from
*/
static inline uint16_t mavlink_msg_terrain_request_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_terrain_request_t* terrain_request)
{
return mavlink_msg_terrain_request_pack(system_id, component_id, msg, terrain_request->lat, terrain_request->lon, terrain_request->grid_spacing, terrain_request->mask);
}
/**
* @brief Encode a terrain_request struct on a channel
*
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param chan The MAVLink channel this message will be sent over
* @param msg The MAVLink message to compress the data into
* @param terrain_request C-struct to read the message contents from
*/
static inline uint16_t mavlink_msg_terrain_request_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_terrain_request_t* terrain_request)
{
return mavlink_msg_terrain_request_pack_chan(system_id, component_id, chan, msg, terrain_request->lat, terrain_request->lon, terrain_request->grid_spacing, terrain_request->mask);
}
/**
* @brief Send a terrain_request message
* @param chan MAVLink channel to send the message
*
* @param lat [degE7] Latitude of SW corner of first grid
* @param lon [degE7] Longitude of SW corner of first grid
* @param grid_spacing [m] Grid spacing
* @param mask Bitmask of requested 4x4 grids (row major 8x7 array of grids, 56 bits)
*/
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
static inline void mavlink_msg_terrain_request_send(mavlink_channel_t chan, int32_t lat, int32_t lon, uint16_t grid_spacing, uint64_t mask)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN];
_mav_put_uint64_t(buf, 0, mask);
_mav_put_int32_t(buf, 8, lat);
_mav_put_int32_t(buf, 12, lon);
_mav_put_uint16_t(buf, 16, grid_spacing);
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_REQUEST, buf, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
#else
mavlink_terrain_request_t packet;
packet.mask = mask;
packet.lat = lat;
packet.lon = lon;
packet.grid_spacing = grid_spacing;
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_REQUEST, (const char*)&packet, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
#endif
}
/**
* @brief Send a terrain_request message
* @param chan MAVLink channel to send the message
* @param struct The MAVLink struct to serialize
*/
static inline void mavlink_msg_terrain_request_send_struct(mavlink_channel_t chan, const mavlink_terrain_request_t* terrain_request)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
mavlink_msg_terrain_request_send(chan, terrain_request->lat, terrain_request->lon, terrain_request->grid_spacing, terrain_request->mask);
#else
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_REQUEST, (const char*)terrain_request, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
#endif
}
#if MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN <= MAVLINK_MAX_PAYLOAD_LEN
/*
This varient of _send() can be used to save stack space by re-using
memory from the receive buffer. The caller provides a
mavlink_message_t which is the size of a full mavlink message. This
is usually the receive buffer for the channel, and allows a reply to an
incoming message with minimum stack space usage.
*/
static inline void mavlink_msg_terrain_request_send_buf(mavlink_message_t* msgbuf, mavlink_channel_t chan, int32_t lat, int32_t lon, uint16_t grid_spacing, uint64_t mask)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char* buf = (char*)msgbuf;
_mav_put_uint64_t(buf, 0, mask);
_mav_put_int32_t(buf, 8, lat);
_mav_put_int32_t(buf, 12, lon);
_mav_put_uint16_t(buf, 16, grid_spacing);
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_REQUEST, buf, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
#else
mavlink_terrain_request_t* packet = (mavlink_terrain_request_t*)msgbuf;
packet->mask = mask;
packet->lat = lat;
packet->lon = lon;
packet->grid_spacing = grid_spacing;
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_REQUEST, (const char*)packet, MAVLINK_MSG_ID_TERRAIN_REQUEST_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN, MAVLINK_MSG_ID_TERRAIN_REQUEST_CRC);
#endif
}
#endif
#endif
// MESSAGE TERRAIN_REQUEST UNPACKING
/**
* @brief Get field lat from terrain_request message
*
* @return [degE7] Latitude of SW corner of first grid
*/
static inline int32_t mavlink_msg_terrain_request_get_lat(const mavlink_message_t* msg)
{
return _MAV_RETURN_int32_t(msg, 8);
}
/**
* @brief Get field lon from terrain_request message
*
* @return [degE7] Longitude of SW corner of first grid
*/
static inline int32_t mavlink_msg_terrain_request_get_lon(const mavlink_message_t* msg)
{
return _MAV_RETURN_int32_t(msg, 12);
}
/**
* @brief Get field grid_spacing from terrain_request message
*
* @return [m] Grid spacing
*/
static inline uint16_t mavlink_msg_terrain_request_get_grid_spacing(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint16_t(msg, 16);
}
/**
* @brief Get field mask from terrain_request message
*
* @return Bitmask of requested 4x4 grids (row major 8x7 array of grids, 56 bits)
*/
static inline uint64_t mavlink_msg_terrain_request_get_mask(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint64_t(msg, 0);
}
/**
* @brief Decode a terrain_request message into a struct
*
* @param msg The message to decode
* @param terrain_request C-struct to decode the message contents into
*/
static inline void mavlink_msg_terrain_request_decode(const mavlink_message_t* msg, mavlink_terrain_request_t* terrain_request)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
terrain_request->mask = mavlink_msg_terrain_request_get_mask(msg);
terrain_request->lat = mavlink_msg_terrain_request_get_lat(msg);
terrain_request->lon = mavlink_msg_terrain_request_get_lon(msg);
terrain_request->grid_spacing = mavlink_msg_terrain_request_get_grid_spacing(msg);
#else
uint8_t len = msg->len < MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN ? msg->len : MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN;
memset(terrain_request, 0, MAVLINK_MSG_ID_TERRAIN_REQUEST_LEN);
memcpy(terrain_request, _MAV_PAYLOAD(msg), len);
#endif
}
|
30512ff22c48ad0a513b281994465df79f1a35ba
|
3b955b6c1122d6caea1175b24bea7b22aa5b9069
|
/libs/sc68/io68/paula_io.c
|
46e716bf8cd2b1ce1352725c7d7b7545c184d546
|
[] |
no_license
|
yoyofr/modizer
|
52930c995424c6243859008d1b5e84b5fcda1aa4
|
68457a14344208bf1ca1660b3952aa59dff3aaea
|
refs/heads/master
| 2023-04-30T00:43:18.365195
| 2023-04-17T08:47:41
| 2023-04-17T08:47:41
| 3,095,707
| 110
| 43
| null | 2021-03-20T17:29:09
| 2012-01-03T17:06:30
|
C
|
UTF-8
|
C
| false
| false
| 7,114
|
c
|
paula_io.c
|
/*
* sc68 - Paula IO plugin (AMIGA soundchip)
* Copyright (C) 1999 Benjamin Gerard <ben@sashipa.com>
*
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "paula_io.h"
#include "paulaemul.h"
#ifdef _DEBUG
# include "file68/debugmsg68.h"
#endif /*_DEBUG*/
static void reload(paulav_t *v , const u8 * p);
static unsigned int clearset(const unsigned int v, const unsigned int clrset)
{
if (clrset & 0x8000) {
return (v | clrset) & 0x7FFF;
} else {
return v & ~clrset;
}
}
static int DMACON(const int dmacon)
{
return (dmacon << (8*sizeof(int)-1-9) >> (8*sizeof(int)-1) )
& dmacon & 0xF;
}
static int INTREQ(const int intreq)
{
return intreq & (0xF<<7);
}
static int INTENA(const int intena)
{
return (intena << (8*sizeof(int)-1-14) >> (8*sizeof(int)-1))
& intena & (0xF<<7);
}
static u32 paula_readB(u32 addr, cycle68_t cycle)
{
addr &= 0xFF;
switch(addr) {
case PAULA_VHPOSR:
return paula[PAULA_VHPOSR]++;
default:
#ifdef _DEBUG
SC68os_pdebug("Read Byte in AMIGA HW (%02X)", addr);
#endif
/* Copy shadow registers. */
paula[PAULA_DMACONRH] = (paula_dmacon>>8)&0x7f;
paula[PAULA_DMACONRL] = paula_dmacon;
paula[PAULA_INTENARH] = (paula_intena>>8)&0x7f;
paula[PAULA_INTENARL] = paula_intena;
paula[PAULA_INTREQRH] = (paula_intreq>>8)&0x7f;
paula[PAULA_INTREQRL] = paula_intreq;
paula[PAULA_ADKCONRH] = (paula_adkcon>>8)&0x7f;
paula[PAULA_ADKCONRL] = paula_adkcon;
return paula[addr];
}
}
static u32 paula_readW(u32 addr, cycle68_t cycle)
{
addr &= 0xFF;
switch (addr) {
case PAULA_DMACONR:
return paula_dmacon & 0x7fff;
case PAULA_INTENAR:
return paula_intena & 0x7fff;
case PAULA_INTREQR:
return paula_intreq & 0x7fff;
case PAULA_ADKCON:
return paula_adkcon & 0x7fff;
default:
#ifdef _DEBUG
SC68os_pdebug("Read Word in AMIGA HW (%02X)", addr);
#endif
return (paula[addr]<<8) | paula[addr+1];
}
}
static u32 paula_readL(u32 addr, cycle68_t cycle)
{
return (paula_readW(addr,cycle)<<16) | paula_readW(addr+2,cycle+4);
}
/* start DMA on voice n ( DMA disable -> enable ) */
static void start_DMA(int bit)
{
int old,chg,cur;
old = DMACON(paula_dmacon);
paula_dmacon |= bit;
cur = DMACON(paula_dmacon);
chg = cur & ~old;
if(chg&1) reload(paulav+0, paula+0xA0);
if(chg&2) reload(paulav+1, paula+0xB0);
if(chg&4) reload(paulav+2, paula+0xC0);
if(chg&8) reload(paulav+3, paula+0xD0);
}
/* stop DMA bit to be stopped */
static void stop_DMA(int bit)
{
paula_dmacon &= ~bit;
// audio_int(0x8000 | ((bit^0xF)<<7));
/* printf("STOP(%X)\n",bit&0x20f);
*/
}
/* Reload paula internal register with current value */
static void reload(paulav_t * v, const u8 * p)
{
int len;
v->start = v->adr =
(((p[1]<<16)|(p[2]<<8)|p[3])&0x7FFFE) << PAULA_CT_FIX;
len = (p[4]<<8) | p[5];
len |= (!len) << 16;
len <<= (PAULA_CT_FIX+1);
v->end = v->start + len;
}
/* Write INTREQ :
*
* - If clearing bits just release the interrupt. Nothing more to do.
* - If setting bit checks wheter the interrupt is denied or not.
* When denied it seems that the internal pointer and length register
* are reloaded however its is not an official practice.
*/
static void write_intreq(const int intreq)
{
int intdenied;
if ( !(intreq & 0x8000) ) {
/* Clearing ... */
paula_intreq &= ~intreq;
return;
}
/* Master interrupt not set : DENIED */
intdenied = ~INTENA(paula_intena);
/* Already requested : DENIED */
intdenied |= paula_intreq;
/* Only interrested by requested bits */
intdenied &= intreq;
/* Reload for each denied channel */
/* $$$ May be should not reload if DMA is OFF $$$ */
if(intdenied & (1<< 7)) reload(paulav+0, paula+0xA0);
if(intdenied & (1<< 8)) reload(paulav+1, paula+0xB0);
if(intdenied & (1<< 9)) reload(paulav+2, paula+0xC0);
if(intdenied & (1<<10)) reload(paulav+3, paula+0xD0);
paula_intreq |= intreq;
}
static void paula_writeB(u32 addr, u32 v, cycle68_t cycle)
{
addr=addr; cycle=cycle;
addr &= 0xFF;
v &= 0xFF;
paula[addr] = v;
#if _DEBUG
SC68os_pdebug("Write Byte in AMIGA HW (%02X <= %02x)", addr, v);
#endif
}
static void paula_writeW(u32 addr, u32 v, cycle68_t cycle)
{
addr &= 0xFF;
v &= 0xFFFF;
/* Copy into hw-reg */
paula[addr] = v >> 8;
paula[(addr+1) & 0xFF] = v;
switch (addr) {
case PAULA_ADKCON:
{
int old_adkcon = paula_adkcon;
paula_adkcon = clearset(old_adkcon, v);
#ifdef _DEBUG
if (paula_adkcon & ~old_adkcon & 0xFF) {
SC68os_pdebug("Amiga Audio Modulation (%02X)\n", paula_adkcon & 0xFF);
}
#endif
} break;
case PAULA_DMACON:
{
int old_dmacon = paula_dmacon;
int old_dmaena = DMACON(old_dmacon);
int paula_dmaena;
int start;
paula_dmacon = clearset(old_dmacon, v);
paula_dmaena = DMACON(paula_dmacon);
start = paula_dmaena & ~old_dmaena;
if(start&1) reload(paulav+0, paula+0xA0);
if(start&2) reload(paulav+1, paula+0xB0);
if(start&4) reload(paulav+2, paula+0xC0);
if(start&8) reload(paulav+3, paula+0xD0);
} break;
case PAULA_INTENA:
{
int old_intena = INTENA(paula_intena), new_intena;
old_intena=old_intena;
paula_intena = clearset(paula_intena, v);
new_intena = INTENA(paula_intena);
#ifdef _DEBUG
if ( new_intena & ~old_intena ) {
SC68os_pdebug("Amiga Audio IRQ enabled (%X)\n",new_intena);
}
#endif
} break;
case PAULA_INTREQ:
write_intreq(v);
break;
default:
#if _DEBUG
if (addr < PAULA_VOICE(0) || addr >= PAULA_VOICE(4)) {
SC68os_pdebug("Write Word in AMIGA HW (%02X <= %04x)", addr, v);
}
#endif
break; /* to please vc7*/
}
}
static void paula_writeL(u32 addr, u32 v, cycle68_t cycle)
{
paula_writeW(addr, v>>16, cycle);
paula_writeW(addr+2, v, cycle);
}
static int68_t *paula_int(cycle68_t cycle)
{
cycle = cycle;
return 0;
}
static cycle68_t paula_nextint(cycle68_t cycle)
{
cycle = cycle;
return IO68_NO_INT;
}
static int paula_reset(void)
{
PL_reset();
return 0;
}
static void paula_subcycle(cycle68_t sub)
{
sub = sub;
}
io68_t paula_io = {
NULL,
"AMIGA Paula",
0xFFDFF000, 0xFFDFF0DF,
{paula_readB, paula_readW, paula_readL},
{paula_writeB, paula_writeW, paula_writeL},
paula_int, paula_nextint,
paula_subcycle,
paula_reset,
0,0
};
|
f23c08f98b6173f0fe533bf99b82b100a0a2a518
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/lpc55sxx/Libraries/drivers/drv_wdt.c
|
51f8f93ff930c4482947f89d2e5768efac43a4e7
|
[
"Apache-2.0",
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 6,154
|
c
|
drv_wdt.c
|
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-04-20 tyustli the first version.
* 2019-07-15 Magicoe The first version for LPC55S6x, timeout unit is S not mS
*
*/
#include <rtthread.h>
#ifdef BSP_USING_WDT
#if !defined(BSP_USING_WDT)
#error "Please define at least one BSP_USING_WDOGx"
#endif
#define LOG_TAG "drv.wdt"
#include <drv_log.h>
#include "drv_wdt.h"
#include <rthw.h>
#include "rtdevice.h"
#if defined(BSP_USING_WDT)
#include "fsl_wwdt.h"
struct lpc_wdt_obj
{
rt_watchdog_t watchdog;
rt_uint16_t is_start;
};
static struct lpc_wdt_obj lpc_wdt;
static wwdt_config_t WWDT1_config =
{
/* Enable the watch dog */
.enableWwdt = true,
/* Disable the watchdog timeout reset */
.enableWatchdogReset = false,
/* Disable the watchdog protection for updating the timeout value */
.enableWatchdogProtect = false,
/* Windowing is not in effect */
.windowValue = 0xFFFFFFU,
/* Set the timeout value to the max */
.timeoutValue = 0xFFFFFFU,
/* No warning is provided */
.warningValue = 0,
/* Set clock frequency. */
.clockFreq_Hz = 0U,
};
void WDT_BOD_IRQHandler(void)
{
uint32_t wdtStatus = WWDT_GetStatusFlags(WWDT);
/* The chip will reset before this happens */
if (wdtStatus & kWWDT_TimeoutFlag)
{
/* A watchdog feed didn't occur prior to window timeout */
/* Stop WDT */
WWDT_Disable(WWDT);
WWDT_ClearStatusFlags(WWDT, kWWDT_TimeoutFlag);
/* Needs restart */
WWDT_Enable(WWDT);
}
/* Handle warning interrupt */
if (wdtStatus & kWWDT_WarningFlag)
{
/* A watchdog feed didn't occur prior to warning timeout */
WWDT_ClearStatusFlags(WWDT, kWWDT_WarningFlag);
/* User code. User can do urgent case before timeout reset.
* IE. user can backup the ram data or ram log to flash.
* the period is set by config.warningValue, user need to
* check the period between warning interrupt and timeout.
*/
}
}
static rt_err_t lpc_wwdt_close(rt_watchdog_t *wdt)
{
rt_uint32_t level;
WWDT_Type *base;
base = (WWDT_Type *)wdt->parent.user_data;
level = rt_hw_interrupt_disable();
WWDT_Disable(base);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
static rt_err_t lpc_wwdt_open(rt_watchdog_t *wdt, rt_uint16_t oflag)
{
WWDT_Type *base;
base = (WWDT_Type *)wdt->parent.user_data;
rt_uint32_t level;
level = rt_hw_interrupt_disable();
WWDT_Enable(base);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
static rt_err_t lpc_wwdt_init(rt_watchdog_t *wdt)
{
WWDT_Type *base;
base = (WWDT_Type *)wdt->parent.user_data;
/* Enable FRO 1M clock for WWDT module. */
SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_FRO1MHZ_CLK_ENA_MASK;
/* Set clock divider for WWDT clock source. */
CLOCK_SetClkDiv(kCLOCK_DivWdtClk, 1U, true);
WWDT_GetDefaultConfig(&WWDT1_config);
/*
* Set watchdog feed time constant to approximately 4s
* Set watchdog warning time to 512 ticks after feed time constant
* Set watchdog window time to 1s
*/
/* The WDT divides the input frequency into it by 4 */
WWDT1_config.timeoutValue = (CLOCK_GetWdtClkFreq() / 4) * 4;
WWDT1_config.warningValue = 512;
WWDT1_config.windowValue = (CLOCK_GetWdtClkFreq() / 4) * 1;
/* Configure WWDT to reset on timeout */
WWDT1_config.enableWatchdogReset = true;
/* Setup watchdog clock frequency(Hz). */
WWDT1_config.clockFreq_Hz = CLOCK_GetWdtClkFreq();
WWDT_Init(base, &WWDT1_config);
lpc_wwdt_close(wdt);
return RT_EOK;
}
static rt_err_t lpc_wwdt_refresh(rt_watchdog_t *wdt)
{
WWDT_Type *base;
base = (WWDT_Type *)wdt->parent.user_data;
rt_uint32_t level;
level = rt_hw_interrupt_disable();
WWDT_Refresh(base);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
/**
* @function control wdog
*
* @param
* wdt whick wdog used
* cmd control wdog options
* args argument of conrtol
* @retval rt_err_t the status of control result
*
* @attention wdog1 is can not get left time(register not exist) and wdogs unit is seconds
*
*/
static rt_err_t lpc_wwdt_control(rt_watchdog_t *wdt, int cmd, void *args)
{
RT_ASSERT(wdt != NULL);
WWDT_Type *base;
base = (WWDT_Type *)wdt->parent.user_data;
switch(cmd)
{
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
{
*(uint16_t *)args = WWDT1_config.timeoutValue;
}
break;
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
{
RT_ASSERT(*(uint16_t *)args != 0);
WWDT1_config.timeoutValue = (CLOCK_GetWdtClkFreq() / 4) * (*(uint16_t *)args) * 2;
WWDT1_config.warningValue = 512;
WWDT1_config.windowValue = (CLOCK_GetWdtClkFreq() / 4) * (*(uint16_t *)args) * 2 / 4;
base->TC = WWDT_TC_COUNT(WWDT1_config.timeoutValue);
base->WINDOW = WWDT_WINDOW_WINDOW(WWDT1_config.windowValue);
base->WARNINT = WWDT_WARNINT_WARNINT(WWDT1_config.warningValue);
WWDT_Refresh(base);
lpc_wwdt_close(wdt);
}
break;
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
{
lpc_wwdt_refresh(wdt);
}
break;
case RT_DEVICE_CTRL_WDT_START:
{
lpc_wwdt_open(wdt, *(rt_uint32_t *)args);
}
break;
case RT_DEVICE_CTRL_WDT_STOP:
{
lpc_wwdt_close(wdt);
}
break;
default:
return -RT_EINVAL;
}
return RT_EOK;
}
static struct rt_watchdog_ops lpc_wwdt_ops =
{
.init = lpc_wwdt_init,
.control = lpc_wwdt_control,
};
#endif /* BSP_USING_WDT */
int rt_hw_wdt_init(void)
{
rt_err_t ret = RT_EOK;
#if defined (BSP_USING_WDT)
lpc_wdt.watchdog.ops = &lpc_wwdt_ops;
ret = rt_hw_watchdog_register(&lpc_wdt.watchdog, "wdt", RT_DEVICE_FLAG_RDWR, WWDT);
if (ret != RT_EOK)
{
LOG_E("rt device register failed %d\n", ret);
}
#endif /* BSP_USING_WDT */
return ret;
}
INIT_DEVICE_EXPORT(rt_hw_wdt_init);
#endif /* BSP_USING_WDT */
|
5d76650e63448f3966f7aecc7813c41cb1724b33
|
17227ad12bc0826771ac6ac2b95dddd9517d0117
|
/PVSupport/Sources/retro/libretro-common/string/stdstring.c
|
c114f1ed165f6f7a614a6447969943b59ee7e6c6
|
[
"BSD-2-Clause"
] |
permissive
|
Provenance-Emu/Provenance
|
e38f7c81e784455d4876f8a2ff999baca0135199
|
c6f49d7921ee27eb8c0c34ca95ec9dc7baf584c1
|
refs/heads/develop
| 2023-08-17T05:04:01.554294
| 2023-07-01T07:58:33
| 2023-07-01T07:58:33
| 12,416,862
| 2,367
| 364
|
NOASSERTION
| 2023-08-01T07:42:35
| 2013-08-27T20:34:36
|
C
|
UTF-8
|
C
| false
| false
| 4,282
|
c
|
stdstring.c
|
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (stdstring.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdint.h>
#include <ctype.h>
#include <string/stdstring.h>
bool string_is_empty(const char *data)
{
return data==NULL || *data=='\0';
}
bool string_is_equal(const char *a, const char *b)
{
if (!a || !b)
return false;
return (strcmp(a, b) == 0);
}
bool string_is_equal_noncase(const char *a, const char *b)
{
if (!a || !b)
return false;
return (strcasecmp(a, b) == 0);
}
char *string_to_upper(char *s)
{
char *cs = (char *)s;
for ( ; *cs != '\0'; cs++)
*cs = toupper(*cs);
return s;
}
char *string_to_lower(char *s)
{
char *cs = (char *)s;
for ( ; *cs != '\0'; cs++)
*cs = tolower(*cs);
return s;
}
char *string_ucwords(char *s)
{
char *cs = (char *)s;
for ( ; *cs != '\0'; cs++)
{
if (*cs == ' ')
{
*(cs+1) = toupper(*(cs+1));
}
}
s[0] = toupper(s[0]);
return s;
}
char *string_replace_substring(const char *in,
const char *pattern, const char *replacement)
{
size_t numhits, pattern_len, replacement_len, outlen;
const char *inat;
const char *inprev;
char *out, *outat;
/* if either pattern or replacement is NULL,
* duplicate in and let caller handle it. */
if (!pattern || !replacement)
return strdup(in);
pattern_len = strlen(pattern);
replacement_len = strlen(replacement);
numhits = 0;
inat = in;
while ((inat = strstr(inat, pattern)))
{
inat += pattern_len;
numhits++;
}
outlen = strlen(in) - pattern_len*numhits + replacement_len*numhits;
out = (char *)malloc(outlen+1);
outat = out;
inat = in;
inprev = in;
while ((inat = strstr(inat, pattern)))
{
memcpy(outat, inprev, inat-inprev);
outat += inat-inprev;
memcpy(outat, replacement, replacement_len);
outat += replacement_len;
inat += pattern_len;
inprev = inat;
}
strcpy(outat, inprev);
return out;
}
/* Non-GPL licensed versions of whitespace trimming:
* http://stackoverflow.com/questions/656542/trim-a-string-in-c
*/
/* Remove leading whitespaces */
char *string_trim_whitespace_left(char *const s)
{
if(s && *s)
{
size_t len = strlen(s);
char *cur = s;
while(*cur && isspace(*cur))
++cur, --len;
if(s != cur)
memmove(s, cur, len + 1);
}
return s;
}
/* Remove trailing whitespaces */
char *string_trim_whitespace_right(char *const s)
{
if(s && *s)
{
size_t len = strlen(s);
char *cur = s + len - 1;
while(cur != s && isspace(*cur))
--cur, --len;
cur[isspace(*cur) ? 0 : 1] = '\0';
}
return s;
}
/* Remove leading and trailing whitespaces */
char *string_trim_whitespace(char *const s)
{
string_trim_whitespace_right(s); /* order matters */
string_trim_whitespace_left(s);
return s;
}
|
15d2972c1730458c1f33e87069ad2d5990778def
|
2ae0b8d95d439ccfd55ea7933ad4a2994ad0f6c5
|
/samples/c/common/opencv_c_wrapper/src/bmp_reader.h
|
44b51941f28c9e64664b045a81c2326933c0b264
|
[
"Apache-2.0"
] |
permissive
|
openvinotoolkit/openvino
|
38ea745a247887a4e14580dbc9fc68005e2149f9
|
e4bed7a31c9f00d8afbfcabee3f64f55496ae56a
|
refs/heads/master
| 2023-08-18T03:47:44.572979
| 2023-08-17T21:24:59
| 2023-08-17T21:24:59
| 153,097,643
| 3,953
| 1,492
|
Apache-2.0
| 2023-09-14T21:42:24
| 2018-10-15T10:54:40
|
C++
|
UTF-8
|
C
| false
| false
| 1,201
|
h
|
bmp_reader.h
|
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
typedef struct BmpHeaderType {
unsigned short type; /* Magic identifier */
unsigned int size; /* File size in bytes */
unsigned int reserved;
unsigned int offset; /* Offset to image data, bytes */
} BmpHeader;
typedef struct BmpInfoHeaderType {
unsigned int size; /* Header size in bytes */
int width, height; /* Width and height of image */
unsigned short planes; /* Number of colour planes */
unsigned short bits; /* Bits per pixel */
unsigned int compression; /* Compression type */
unsigned int imagesize; /* Image size in bytes */
int xresolution, yresolution; /* Pixels per meter */
unsigned int ncolours; /* Number of colours */
unsigned int importantcolours; /* Important colours */
} BmpInfoHeader;
typedef struct BitMapType {
BmpHeader header;
BmpInfoHeader infoHeader;
int width, height;
unsigned char* data;
} BitMap;
int readBmpImage(const char* fileName, BitMap* image);
|
46618e8cbcfcfc60552e8128102441637984217a
|
52c8ed39b32ccc7c0673278c1adea3638797c9ff
|
/src/wboxtest/wboxtest.h
|
375d2dc67173292502b1ada06b0c2735e0547940
|
[
"MIT"
] |
permissive
|
xboot/xboot
|
0cab7b440b612aa0a4c366025598a53a7ec3adf1
|
6d6b93947b7fcb8c3924fedb0715c23877eedd5e
|
refs/heads/master
| 2023-08-20T05:56:25.149388
| 2023-07-12T07:38:29
| 2023-07-12T07:38:29
| 471,539
| 765
| 296
|
MIT
| 2023-05-25T09:39:01
| 2010-01-14T08:25:12
|
C
|
UTF-8
|
C
| false
| false
| 2,593
|
h
|
wboxtest.h
|
#ifndef __WBOXTEST_H__
#define __WBOXTEST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <xboot.h>
struct wboxtest_t
{
struct kobj_t * kobj;
struct hlist_node node;
const char * group;
const char * name;
void * (*setup)(struct wboxtest_t * wbt);
void (*clean)(struct wboxtest_t * wbt, void * data);
void (*run)(struct wboxtest_t * wbt, void * data);
};
struct wboxtest_t * search_wboxtest(const char * group, const char * name);
bool_t register_wboxtest(struct wboxtest_t * wbt);
bool_t unregister_wboxtest(struct wboxtest_t * wbt);
void wboxtest_run_group_name(const char * group, const char * name, int count);
void wboxtest_run_group(const char * group, int count);
void wboxtest_run_all(int count);
void wboxtest_list(void);
#define assert_null(x) do { wboxtest_assert(((x) == NULL), #x, __FILE__, __LINE__); } while(0);
#define assert_not_null(x) do { wboxtest_assert(((x) != NULL), #x, __FILE__, __LINE__); } while(0);
#define assert_true(x) do { wboxtest_assert((x), #x, __FILE__, __LINE__); } while(0);
#define assert_false(x) do { wboxtest_assert((!(x)), #x, __FILE__, __LINE__); } while(0);
#define assert_equal(a, b) do { wboxtest_assert(((a) == (b)), #a" == "#b, __FILE__, __LINE__); } while(0);
#define assert_not_equal(a, b) do { wboxtest_assert(((a) != (b)), #a" != "#b, __FILE__, __LINE__); } while(0);
#define assert_string_equal(a, b) do { wboxtest_assert((strcmp((a), (b)) == 0), "S["#a" == "#b"]", __FILE__, __LINE__); } while(0);
#define assert_string_not_equal(a, b) do { wboxtest_assert((strcmp((a), (b)) != 0), "S["#a" != "#b"]", __FILE__, __LINE__); } while(0);
#define assert_memory_equal(a, b, l) do { wboxtest_assert((memcmp((a), (b), (l)) == 0), "M["#a" == "#b"]", __FILE__, __LINE__); } while(0);
#define assert_memory_not_equal(a, b, l) do { wboxtest_assert((memcmp((a), (b), (l)) != 0), "M["#a" != "#b"]", __FILE__, __LINE__); } while(0);
#define assert_inrange(v, min, max) do { wboxtest_assert((((v) >= (min)) && ((v) <= (max))), #v"><["#min", "#max"]", __FILE__, __LINE__); } while(0);
#define assert_not_inrange(v, min, max) do { wboxtest_assert((((v) < (min)) && ((v) > (max))), #v"<>["#min", "#max"]", __FILE__, __LINE__); } while(0);
int wboxtest_random_int(int a, int b);
double wboxtest_random_float(double a, double b);
char * wboxtest_random_string(char * buf, int len);
char * wboxtest_random_buffer(char * buf, int len);
int wboxtest_print(const char * fmt, ...);
void wboxtest_assert(int cond, char * expr, const char * file, int line);
#ifdef __cplusplus
}
#endif
#endif /* __WBOXTEST_H__ */
|
e31139b14e19435af22f0e83771137a90ca5629a
|
1f399edf85d995443d01f66d77eca0723886d0ff
|
/hypervisor/common/ptdev.c
|
323067ded4b9c7165938d83730f890d896c94577
|
[
"BSD-3-Clause"
] |
permissive
|
projectacrn/acrn-hypervisor
|
f9c5864d54929a5d2fa36b5e78c08f19b46b8f98
|
390740aa1b1e9d62c51f8e3afa0c29e07e43fa23
|
refs/heads/master
| 2023-08-18T05:07:01.310327
| 2023-08-11T07:49:36
| 2023-08-16T13:20:27
| 123,983,554
| 1,059
| 686
|
BSD-3-Clause
| 2023-09-14T09:51:10
| 2018-03-05T21:52:25
|
C
|
UTF-8
|
C
| false
| false
| 8,507
|
c
|
ptdev.c
|
/*
* Copyright (C) 2018-2022 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <hash.h>
#include <asm/per_cpu.h>
#include <asm/guest/vm.h>
#include <softirq.h>
#include <ptdev.h>
#include <irq.h>
#include <logmsg.h>
#include <asm/vtd.h>
#include <ticks.h>
#define PTIRQ_ENTRY_HASHBITS 9U
#define PTIRQ_ENTRY_HASHSIZE (1U << PTIRQ_ENTRY_HASHBITS)
#define PTIRQ_BITMAP_ARRAY_SIZE INT_DIV_ROUNDUP(CONFIG_MAX_PT_IRQ_ENTRIES, 64U)
struct ptirq_remapping_info ptirq_entries[CONFIG_MAX_PT_IRQ_ENTRIES];
static uint64_t ptirq_entry_bitmaps[PTIRQ_BITMAP_ARRAY_SIZE];
spinlock_t ptdev_lock = { .head = 0U, .tail = 0U, };
/* lookup mapping info from phyical sid, hashing from sid + acrn_vm structure address (NULL) */
static struct hlist_head phys_sid_htable[PTIRQ_ENTRY_HASHSIZE];
/* lookup mapping info from virtual sid within a vm, hashing from sid + acrn_vm structure address */
static struct hlist_head virt_sid_htable[PTIRQ_ENTRY_HASHSIZE];
static inline uint16_t ptirq_alloc_entry_id(void)
{
uint16_t id = (uint16_t)ffz64_ex(ptirq_entry_bitmaps, CONFIG_MAX_PT_IRQ_ENTRIES);
while (id < CONFIG_MAX_PT_IRQ_ENTRIES) {
if (!bitmap_test_and_set_lock((id & 0x3FU), &ptirq_entry_bitmaps[id >> 6U])) {
break;
}
id = (uint16_t)ffz64_ex(ptirq_entry_bitmaps, CONFIG_MAX_PT_IRQ_ENTRIES);
}
return (id < CONFIG_MAX_PT_IRQ_ENTRIES) ? id: INVALID_PTDEV_ENTRY_ID;
}
/*
* get the hash key when looking up ptirq_remapping_info from virtual
* source id in a VM, or just physical source id (vm == NULL).
* Hashing from source id value and acrn_vm structure address can decrease
* the probability of hash collisions as different VMs may have equal
* virtual source ids.
*/
static inline uint64_t ptirq_hash_key(const struct acrn_vm *vm,
const union source_id *sid)
{
return hash64(sid->value + (uint64_t)vm, PTIRQ_ENTRY_HASHBITS);
}
/*
* to find ptirq_remapping_info from phyical source id (vm == NULL) or
* virtual source id in a vm.
*/
struct ptirq_remapping_info *find_ptirq_entry(uint32_t intr_type,
const union source_id *sid, const struct acrn_vm *vm)
{
struct hlist_node *p;
struct hlist_head *b;
struct ptirq_remapping_info *n, *entry = NULL;
uint64_t key = ptirq_hash_key(vm, sid);
if (vm == NULL) {
b = &(phys_sid_htable[key]);
hlist_for_each(p, b) {
n = hlist_entry(p, struct ptirq_remapping_info, phys_link);
if (is_entry_active(n)) {
if ((intr_type == n->intr_type) && (sid->value == n->phys_sid.value)) {
entry = n;
break;
}
}
}
} else {
b = &(virt_sid_htable[key]);
hlist_for_each(p, b) {
n = hlist_entry(p, struct ptirq_remapping_info, virt_link);
if (is_entry_active(n)) {
if ((intr_type == n->intr_type) && (sid->value == n->virt_sid.value) && (vm == n->vm)) {
entry = n;
break;
}
}
}
}
return entry;
}
static void ptirq_enqueue_softirq(struct ptirq_remapping_info *entry)
{
uint64_t rflags;
/* enqueue request in order, SOFTIRQ_PTDEV will pickup */
CPU_INT_ALL_DISABLE(&rflags);
/* avoid adding recursively */
list_del(&entry->softirq_node);
/* TODO: assert if entry already in list */
list_add_tail(&entry->softirq_node, &get_cpu_var(softirq_dev_entry_list));
CPU_INT_ALL_RESTORE(rflags);
fire_softirq(SOFTIRQ_PTDEV);
}
static void ptirq_intr_delay_callback(void *data)
{
struct ptirq_remapping_info *entry = (struct ptirq_remapping_info *) data;
ptirq_enqueue_softirq(entry);
}
struct ptirq_remapping_info *ptirq_dequeue_softirq(uint16_t pcpu_id)
{
uint64_t rflags;
struct ptirq_remapping_info *entry = NULL;
CPU_INT_ALL_DISABLE(&rflags);
while (!list_empty(&get_cpu_var(softirq_dev_entry_list))) {
entry = get_first_item(&per_cpu(softirq_dev_entry_list, pcpu_id), struct ptirq_remapping_info, softirq_node);
list_del_init(&entry->softirq_node);
/* if Service VM, just dequeue, if User VM, check delay timer */
if (is_service_vm(entry->vm) || timer_expired(&entry->intr_delay_timer, cpu_ticks(), NULL)) {
break;
} else {
/* add it into timer list; dequeue next one */
(void)add_timer(&entry->intr_delay_timer);
entry = NULL;
}
}
CPU_INT_ALL_RESTORE(rflags);
return entry;
}
struct ptirq_remapping_info *ptirq_alloc_entry(struct acrn_vm *vm, uint32_t intr_type)
{
struct ptirq_remapping_info *entry = NULL;
uint16_t ptirq_id = ptirq_alloc_entry_id();
if (ptirq_id < CONFIG_MAX_PT_IRQ_ENTRIES) {
entry = &ptirq_entries[ptirq_id];
(void)memset((void *)entry, 0U, sizeof(struct ptirq_remapping_info));
entry->ptdev_entry_id = ptirq_id;
entry->intr_type = intr_type;
entry->vm = vm;
entry->intr_count = 0UL;
entry->irte_idx = INVALID_IRTE_ID;
INIT_LIST_HEAD(&entry->softirq_node);
initialize_timer(&entry->intr_delay_timer, ptirq_intr_delay_callback, entry, 0UL, 0UL);
entry->active = false;
} else {
pr_err("Alloc ptdev irq entry failed");
}
return entry;
}
void ptirq_release_entry(struct ptirq_remapping_info *entry)
{
uint64_t rflags;
CPU_INT_ALL_DISABLE(&rflags);
list_del_init(&entry->softirq_node);
del_timer(&entry->intr_delay_timer);
CPU_INT_ALL_RESTORE(rflags);
bitmap_clear_lock((entry->ptdev_entry_id) & 0x3FU, &ptirq_entry_bitmaps[entry->ptdev_entry_id >> 6U]);
(void)memset((void *)entry, 0U, sizeof(struct ptirq_remapping_info));
}
/* interrupt context */
static void ptirq_interrupt_handler(__unused uint32_t irq, void *data)
{
struct ptirq_remapping_info *entry = (struct ptirq_remapping_info *) data;
bool to_enqueue = true;
/*
* "interrupt storm" detection & delay intr injection just for User VM
* pass-thru devices, collect its data and delay injection if needed
*/
if (!is_service_vm(entry->vm)) {
entry->intr_count++;
/* if delta > 0, set the delay TSC, dequeue to handle */
if (entry->vm->intr_inject_delay_delta > 0UL) {
/* if the timer started (entry is in timer-list), not need enqueue again */
if (timer_is_started(&entry->intr_delay_timer)) {
to_enqueue = false;
} else {
update_timer(&entry->intr_delay_timer,
cpu_ticks() + entry->vm->intr_inject_delay_delta, 0UL);
}
} else {
update_timer(&entry->intr_delay_timer, 0UL, 0UL);
}
}
if (to_enqueue) {
ptirq_enqueue_softirq(entry);
}
}
/* active intr with irq registering */
int32_t ptirq_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_irq)
{
int32_t ret = 0;
uint32_t irq = IRQ_INVALID;
uint64_t key;
if ((entry->intr_type == PTDEV_INTR_INTX) || !is_pi_capable(entry->vm)) {
/* register and allocate host vector/irq */
ret = request_irq(phys_irq, ptirq_interrupt_handler, (void *)entry, IRQF_PT);
if (ret >=0) {
irq = (uint32_t)ret;
} else {
pr_err("request irq failed, please check!, phys-irq=%d", phys_irq);
}
}
if (ret >=0) {
entry->allocated_pirq = irq;
entry->active = true;
key = ptirq_hash_key(NULL, &(entry->phys_sid));
hlist_add_head(&entry->phys_link, &(phys_sid_htable[key]));
key = ptirq_hash_key(entry->vm, &(entry->virt_sid));
hlist_add_head(&entry->virt_link, &(virt_sid_htable[key]));
}
return ret;
}
void ptirq_deactivate_entry(struct ptirq_remapping_info *entry)
{
hlist_del(&entry->phys_link);
hlist_del(&entry->virt_link);
entry->active = false;
if (entry->allocated_pirq != IRQ_INVALID) {
free_irq(entry->allocated_pirq);
}
}
void ptdev_init(void)
{
if (get_pcpu_id() == BSP_CPU_ID) {
register_softirq(SOFTIRQ_PTDEV, ptirq_softirq);
}
INIT_LIST_HEAD(&get_cpu_var(softirq_dev_entry_list));
}
void ptdev_release_all_entries(const struct acrn_vm *vm)
{
struct ptirq_remapping_info *entry;
uint16_t idx;
/* VM already down */
for (idx = 0U; idx < CONFIG_MAX_PT_IRQ_ENTRIES; idx++) {
entry = &ptirq_entries[idx];
if ((entry->vm == vm) && is_entry_active(entry)) {
spinlock_obtain(&ptdev_lock);
if (entry->release_cb != NULL) {
entry->release_cb(entry);
}
ptirq_deactivate_entry(entry);
ptirq_release_entry(entry);
spinlock_release(&ptdev_lock);
}
}
}
uint32_t ptirq_get_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, uint32_t buffer_cnt)
{
uint32_t index = 0U;
uint16_t i;
struct ptirq_remapping_info *entry;
for (i = 0U; i < CONFIG_MAX_PT_IRQ_ENTRIES; i++) {
entry = &ptirq_entries[i];
if (!is_entry_active(entry) || (entry->allocated_pirq == IRQ_INVALID)) {
continue;
}
if (entry->vm == target_vm) {
buffer[index] = entry->allocated_pirq;
buffer[index + 1U] = entry->intr_count;
index += 2U;
if (index > (buffer_cnt - 2U)) {
break;
}
}
}
return index;
}
|
f2a9dc2909bcddaec80903bd961ec2c296e5db6d
|
3f55217e912141e04815bc8bcb6fbd5638d0896e
|
/src/hd/rhd_odraw.h
|
ae4e0fa1c7f488272bc93e98565eedba820a486a
|
[
"BSD-2-Clause"
] |
permissive
|
NREL/Radiance
|
bfbb93c99d86368ad0f27052a2a5504aeced47f8
|
2fcca99ace2f2435f32a09525ad31f2b3be3c1bc
|
refs/heads/master
| 2021-12-26T12:42:04.586614
| 2021-12-18T00:43:56
| 2021-12-18T00:43:56
| 8,210,805
| 164
| 68
|
NOASSERTION
| 2019-06-06T19:57:11
| 2013-02-15T00:47:56
|
C
|
UTF-8
|
C
| false
| false
| 5,032
|
h
|
rhd_odraw.h
|
/* RCSid $Id: rhd_odraw.h,v 3.14 2011/05/20 02:06:39 greg Exp $ */
/*
* Header for OpenGL cone drawing routines with depth buffer checks.
*
* Include after "standard.h"
*/
#ifndef _RAD_RHD_ODRAW_H_
#define _RAD_RHD_ODRAW_H_
#include "color.h"
#include "tonemap.h"
#include "rhdriver.h"
#ifdef __cplusplus
extern "C" {
#endif
extern struct ODview {
int sfirst, snext; /* first sample and first in next view */
short hhi, vhi; /* screen image resolution */
short hlow, vlow; /* block resolution */
int n2redraw; /* approx. number of samples needing redraw */
struct ODblock {
short nsamp; /* number of samples in block */
short nused; /* number actually allocated */
int first; /* first sample in this block */
int free; /* index for block free list */
float pthresh; /* proximity threshold */
} *bmap; /* low resolution image map */
int32 *emap; /* low resolution edge presence map */
int32 *pmap; /* high resolution presence map */
GLfloat *dmap; /* high resolution depth map */
} *odView; /* our view list */
extern int odNViews; /* number of views in our list */
extern TMstruct *tmGlobal; /* global tone-mapping structure */
extern struct ODsamp {
union ODfunion {
float prox; /* viewpoint proximity */
int32 next; /* next in free list */
} *f; /* free list next or proximity */
short (*ip)[2]; /* image position array */
TMbright *brt; /* encoded brightness array */
uby8 (*chr)[3]; /* encoded chrominance array */
uby8 (*rgb)[3]; /* tone-mapped color array */
int32 *redraw; /* redraw flags */
int nsamp; /* total number of samples */
char *base; /* base of allocated memory */
} odS; /* sample values */
#ifndef FL4OP
#define FL4OP(f,i,op) ((f)[(i)>>5] op (1L<<((i)&0x1f)))
#define CHK4(f,i) FL4OP(f,i,&)
#define SET4(f,i) FL4OP(f,i,|=)
#define CLR4(f,i) FL4OP(f,i,&=~)
#define TGL4(f,i) FL4OP(f,i,^=)
#define FL4NELS(n) (((n)+0x1f)>>5)
#define CLR4ALL(f,n) memset((char *)(f),'\0',FL4NELS(n)*sizeof(int32))
#endif
#define OMAXDEPTH 32000 /* maximum depth value */
#define nextfree(i) f[i].next /* free pointers */
#define closeness(i) f[i].prox /* viewpoint proximity */
#define ENDFREE (-1) /* free list terminator */
#define odClean() odInit(odS.nsamp) /* clear samples */
#define odDone() odInit(0) /* free samples */
/*****************************************************************************
* Interface routines:
int
odInit(nsamps) : allocate and initialize memory
int nsamps; : number of samples to make available
If nsamps is zero, then this becomes a deallocation routine. If nsamps
is the same as last time, then this merely clears all data. The dev_auxview()
function may be called to determine the current view(s). The odAlloc()
function returns the number of samples actually allocated.
void
odSample(c, d, p) : register new sample value
COLR c; : pixel color (RGBE)
FVECT d; : ray direction vector
FVECT p; : world intersection point
If p is NULL, then the point is at infinity.
void
odDepthMap(vn, dm) : set depth map for the given view
int vn; : view number
GLfloat *dm; : depth map
Assign the depth map associated with view number vn. The map has
been preallocated, and won't be freed until it is no longer needed
(after an odAlloc() call). All depth values are the projected
distance along the view direction from the view origin. If dm
is NULL, then there is no depth map associated with this view.
void
odRedraw(vn, x0, y0, x1, y1) : region needs to be redrawn
int vn; : view number
int x0, y0, x1, y1; : rectangle to redraw
This call indicates that the given rectangular region in view vn
needs to be redrawn in the next call to odUpdate().
void
odRedrawAll() : everything needs to be redrawn
Redraw everything in all views on the next call to odUpdate().
Unless odRemap() is called, no new tone mapping will be done.
void
odUpdate(vn) : update the current view
int vn; : view number
Draw all new and undrawn sample values since last call for this view.
void
odRemap(newhist) : recompute tone mapping
int newhist; : flag whether to clear history
Recompute the tone mapping for all the samples in all the views
and redraw them on the next call(s) to odUpdate(). If newhist
is non-zero, then clear the previous sample history.
**********************************************************************/
/* rhd_geom.c */
void gmNewGeom( char *file);
extern void gmEndGeom(void);
extern int gmDrawGeom(void);
extern void gmDrawPortals(int r, int g, int b, int a);
extern void gmDepthLimit( double dl[2], FVECT vorg, FVECT vdir);
extern void gmNewPortal(char *pflist);
extern int gmEndPortal(void);
/* rhd_odraw.c */
extern int odInit(int n);
extern void odSample(COLR c, FVECT d, FVECT p);
extern void odRemap(int newhist);
extern void odRedrawAll(void);
extern void odRedraw(int vn, int hmin, int vmin, int hmax, int vmax);
extern void odDepthMap(int vn, GLfloat *dm);
extern void odUpdate(int vn);
#ifdef __cplusplus
}
#endif
#endif /* _RAD_RHD_ODRAW_H_ */
|
1468ded40f0d853e6def55c8c59787a28637f2b2
|
409d14156eb919757bf1c6ae8c94827520e98667
|
/HC-SR04/HC_SR04.c
|
f737d242fef3289b529f0b774ae7c57eb4de9813
|
[
"BSD-3-Clause"
] |
permissive
|
Mculover666/HAL_Driver_Lib
|
8fa69e7590802290b1ef8b33dee6585d1c8a51e0
|
2c09811e01fed3ec64c85be50a5565f55fee995d
|
refs/heads/master
| 2023-04-12T03:27:19.326842
| 2023-04-08T14:30:03
| 2023-04-08T14:30:03
| 196,137,750
| 189
| 78
|
BSD-3-Clause
| 2022-06-26T10:39:17
| 2019-07-10T05:33:30
|
C
|
UTF-8
|
C
| false
| false
| 2,524
|
c
|
HC_SR04.c
|
/**
* @Copyright (c) 2021,mculover666 All rights reserved
* @filename HC_SR04.c
* @breif Drive HC_SR04 based on stm32 tim peripheral
* @changelog v1.0 mculover666 2021/5/9
* v1.1 mculover666 2021/5/12 add object design
*/
#include "HC_SR04.h"
#include <stdio.h>
/**
* @brief pend the mutex to protect tim.
* @param none
* @return none
* @note it will be need if you use rtos
*/
static void HC_SRO4_Mutex_Pend()
{
//add your code here
}
/**
* @brief post the mutex to protect tim.
* @param none
* @return none
* @note it will be need if you use rtos
*/
static void HC_SRO4_Mutex_Post()
{
//add your code here
}
/**
* @brief hc_sr04_device object initialization.
* @param none
* @return none
*/
void HC_SR04_Init(hc_sr04_device_t *hc_sr04_device)
{
// the gpio and tim is initialized in main
}
/**
* @brief Send trig signal.
* @param none
* @return none
*/
static void HC_SR04_Start(hc_sr04_device_t *hc_sr04_device)
{
/* output high level */
HAL_GPIO_WritePin(hc_sr04_device->trig_port, hc_sr04_device->trig_pin, GPIO_PIN_SET);
/* maintain high level at least 10us */
CPU_TS_Tmr_Delay_US(10);
/* resume low level */
HAL_GPIO_WritePin(hc_sr04_device->trig_port, hc_sr04_device->trig_pin, GPIO_PIN_RESET);
}
/**
* @brief Measure the high level time of the echo signal.
* @param hc_sr04_device the pointer of the hc_sr04_device_t object
* @return errcode
* @retval 0 success
* @retval -1 fail
*/
int HC_SR04_Measure(hc_sr04_device_t *hc_sr04_device)
{
uint32_t tick_us;
HC_SRO4_Mutex_Pend();
HC_SR04_Start(hc_sr04_device);
__HAL_TIM_SetCounter(hc_sr04_device->tim, 0);
/* waitting for start of the high level through echo pin */
while (HAL_GPIO_ReadPin(hc_sr04_device->echo_port, hc_sr04_device->echo_pin) == GPIO_PIN_RESET);
/* start the tim and enable the interrupt */
HAL_TIM_Base_Start(hc_sr04_device->tim);
/* waitting for end of the high level through echo pin */
while (HAL_GPIO_ReadPin(hc_sr04_device->echo_port, hc_sr04_device->echo_pin) == GPIO_PIN_SET);
/* stop the tim */
HAL_TIM_Base_Stop(hc_sr04_device->tim);
/* get the time of high level */
tick_us = __HAL_TIM_GetCounter(hc_sr04_device->tim);
/* calc distance in unit cm */
hc_sr04_device->distance = (double)(tick_us/1000000.0) * 340.0 / 2.0 *100.0;
HC_SRO4_Mutex_Post();
return 0;
}
|
9eac6e1477cd3431c1ed87aa18381a21ba844aa9
|
676acab8ff535019faff7da3afb8eecc3fa127f5
|
/target/pixhawk/fmt-io/project/source/board_config.h
|
0929212f20a31db96e6c76157d2242ca974789a3
|
[
"Apache-2.0"
] |
permissive
|
Firmament-Autopilot/FMT-Firmware
|
f8c324577245bd7e91af436954b4ce9421acbb41
|
0212fe89820376bfbedaded519552f6b011a7b8a
|
refs/heads/master
| 2023-09-01T11:37:46.194145
| 2023-08-29T06:33:10
| 2023-08-29T06:33:10
| 402,557,689
| 351
| 143
|
Apache-2.0
| 2023-09-12T05:28:39
| 2021-09-02T20:42:56
|
C
|
UTF-8
|
C
| false
| false
| 102
|
h
|
board_config.h
|
#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__
#define USE_IMU_HEAT
#define CUBEPILOT
#endif
|
630b305804e77d84436647a9d19169eb842ae2ac
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/net/arp/arp_notify.c
|
73cc52fa7f7323d9f5c203efac2ada1fd7357e5e
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 6,133
|
c
|
arp_notify.c
|
/****************************************************************************
* net/arp/arp_notify.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include <netinet/in.h>
#include <nuttx/irq.h>
#include <nuttx/net/net.h>
#include "arp/arp.h"
#ifdef CONFIG_NET_ARP_SEND
/****************************************************************************
* Private Data
****************************************************************************/
/* List of tasks waiting for ARP events */
static FAR struct arp_notify_s *g_arp_waiters;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: arp_wait_setup
*
* Description:
* Called BEFORE an ARP request is sent. This function sets up the ARP
* response timeout before the ARP request is sent so that there is
* no race condition when arp_wait() is called.
*
* Assumptions:
* This function is called from ARP send and executes in the normal
* tasking environment.
*
****************************************************************************/
void arp_wait_setup(in_addr_t ipaddr, FAR struct arp_notify_s *notify)
{
irqstate_t flags;
/* Initialize the wait structure */
notify->nt_ipaddr = ipaddr;
notify->nt_result = -ETIMEDOUT;
nxsem_init(¬ify->nt_sem, 0, 0);
/* Add the wait structure to the list with interrupts disabled */
flags = enter_critical_section();
notify->nt_flink = g_arp_waiters;
g_arp_waiters = notify;
leave_critical_section(flags);
}
/****************************************************************************
* Name: arp_wait_cancel
*
* Description:
* Cancel any wait set after arp_wait_setup is called but before arp_wait()
* is called (arp_wait() will automatically cancel the wait).
*
* Assumptions:
* This function may execute with interrupts disabled when called from
* arp_wait().
*
****************************************************************************/
int arp_wait_cancel(FAR struct arp_notify_s *notify)
{
FAR struct arp_notify_s *curr;
FAR struct arp_notify_s *prev;
irqstate_t flags;
int ret = -ENOENT;
/* Remove our wait structure from the list (we may no longer be at the
* head of the list).
*/
flags = enter_critical_section();
for (prev = NULL, curr = g_arp_waiters;
curr && curr != notify;
prev = curr, curr = curr->nt_flink)
{
}
DEBUGASSERT(curr && curr == notify);
if (curr)
{
if (prev)
{
prev->nt_flink = notify->nt_flink;
}
else
{
g_arp_waiters = notify->nt_flink;
}
ret = OK;
}
leave_critical_section(flags);
nxsem_destroy(¬ify->nt_sem);
return ret;
}
/****************************************************************************
* Name: arp_wait
*
* Description:
* Called each time that a ARP request is sent. This function will sleep
* until either: (1) the matching ARP response is received, or (2) a
* timeout occurs.
*
* Assumptions:
* This function is called from ARP send must execute with the network
* locked.
*
****************************************************************************/
int arp_wait(FAR struct arp_notify_s *notify, unsigned int timeout)
{
int ret;
/* And wait for the ARP response (or a timeout). */
net_sem_timedwait_uninterruptible(¬ify->nt_sem, timeout);
/* Then get the real result of the transfer */
ret = notify->nt_result;
/* Remove our wait structure from the list (we may no longer be at the
* head of the list).
*/
arp_wait_cancel(notify);
return ret;
}
/****************************************************************************
* Name: arp_notify
*
* Description:
* Called each time that a ARP response is received in order to wake-up
* any threads that may be waiting for this particular ARP response.
*
* Assumptions:
* This function is called from the MAC device driver indirectly through
* arp_input() will execute with the network locked.
*
****************************************************************************/
void arp_notify(in_addr_t ipaddr)
{
FAR struct arp_notify_s *curr;
irqstate_t flags;
flags = enter_critical_section();
/* Find an entry with the matching IP address in the list of waiters */
for (curr = g_arp_waiters; curr; curr = curr->nt_flink)
{
/* Does this entry match? If the result is okay, then we have
* already notified this waiter and it has not yet taken the
* entry from the list.
*/
if (curr->nt_result != OK && curr->nt_ipaddr == ipaddr)
{
/* Yes.. Signal the waiting, returning success */
curr->nt_result = OK;
nxsem_post(&curr->nt_sem);
break;
}
}
leave_critical_section(flags);
}
#endif /* CONFIG_NET_ARP_SEND */
|
a5ca6fdec36245eac2bff46b55a66da068d8a4be
|
0cc343d927d5db6693006018986715c43acab961
|
/examples/shared_boxes/stack_hp/stack_hp.h
|
e1d6e3ec5deb906d2a5c4b7db4e0db9aaf958523
|
[
"MIT"
] |
permissive
|
verifast/verifast
|
ec0101fc4a69bd33c5f66be4444169c4e060ead8
|
d152da790c7ebf72ce616533a6c83082629adbdb
|
refs/heads/master
| 2023-08-25T00:13:51.464802
| 2023-08-13T10:00:00
| 2023-08-13T10:00:00
| 14,519,163
| 325
| 64
|
NOASSERTION
| 2023-08-10T21:16:08
| 2013-11-19T08:57:02
|
OCaml
|
UTF-8
|
C
| false
| false
| 7,700
|
h
|
stack_hp.h
|
#ifndef STACK_HP_H
#define STACK_HP_H
#include "atomics.h"
struct stack;
struct stack_client;
/*@
predicate stack(struct stack *stack; int allClientsId, list<void*> elems);
predicate stack_local(struct stack *stack; int allClientsId);
predicate stack_client_local(struct stack_client* client, struct stack *stack, int allClientsId);
predicate_family stack_sep(void *sep)(any info, struct stack *stack, int allClientsId, predicate() inv, stack_unsep *unsep);
predicate_family stack_unsep(void *unsep)(any info, struct stack *stack, int allClientsId, predicate() inv, stack_sep *sep, list<void*> elems);
typedef lemma void stack_sep();
requires stack_sep(this)(?info, ?stack, ?allClientsId, ?inv, ?unsep) &*& inv();
ensures stack_unsep(unsep)(info, stack, allClientsId, inv, this, ?elems) &*& stack(stack, allClientsId, elems);
typedef lemma void stack_unsep();
requires stack_unsep(this)(?info, ?stack, ?allClientsId, ?inv, ?sep, ?elems) &*& stack(stack, allClientsId, elems);
ensures stack_sep(sep)(info, stack, allClientsId, inv, this) &*& inv();
predicate stack_inv_info(any info, struct stack *stack, int allClientsId, predicate() inv, stack_sep* sep, stack_unsep* unsep);
@*/
// creating and disposing stacks
struct stack *create_stack();
//@ requires true;
//@ ensures stack(result, _, nil);
void dispose_stack(struct stack *stack);
//@ requires stack(stack, _, nil);
//@ ensures true;
// sequential operations on stacks
void stack_push_sequential(struct stack *stack, void *data);
//@ requires stack(stack, ?allClientsId, ?elems);
//@ ensures stack(stack, allClientsId, cons(data, elems));
bool stack_try_pop_sequential(struct stack *stack, void** resultRef);
//@ requires stack(stack, ?allClientsId, ?elems) &*& pointer(resultRef, _);
//@ ensures stack(stack, allClientsId, tail(elems)) &*& pointer(resultRef, head_or(elems, 0)) &*& result == (elems != nil);
// lemma's to share and unshare stacks
/*@
lemma void share_stack(struct stack *stack);
requires
stack(stack, ?allClientsId, ?elems) &*&
is_stack_sep(?sep) &*&
is_stack_unsep(?unsep) &*&
stack_unsep(unsep)(?info, stack, ?inv, sep, elems);
ensures atomic_space(inv) &*& stack_inv_info(info, stack, inv, sep, unsep);
lemma void unshare_stack(struct stack *stack);
requires atomic_space(?inv) &*& stack_inv_info(?info, stack, inv, ?sep, ?unsep);
ensures stack(stack, ?elems) &*&
is_stack_sep(sep) &*&
is_stack_unsep(unsep) &*&
stack_unsep(unsep)(info, stack, inv, sep, elems);
@*/
// concurrent operations to create and dispose stack clients
struct stack_client* stack_create_client(struct stack *stack);
/*@
requires
stack_inv_info(?args, stack, ?inv, ?sep, ?unsep) &*&
[?f] atomic_space(inv);
@*/
/*@
ensures
stack_inv_info(args, stack, inv, sep, unsep) &*&
[f] atomic_space(inv) &*&
stack_client(stack, result);
@*/
void stack_dispose_client(struct stack *stack, struct stack_client* client);
/*@
requires
stack_inv_info(?args, stack, ?inv, ?sep, ?unsep) &*&
[?f] atomic_space(inv) &*&
stack_client(stack, client);
@*/
/*@
ensures
stack_inv_info(args, stack, inv, sep, unsep) &*&
[f] atomic_space(inv);
@*/
// concurrent operations on stacks
/*@
predicate_family stack_push_operation_pre(void *op)(struct stack *stack, void *data);
predicate_family stack_push_operation_post(void *op)();
typedef lemma void stack_push_operation();
requires stack_push_operation_pre(this)(?stack, ?data) &*& stack(stack, ?allClientsId, ?elems);
ensures stack_push_operation_post(this)() &*& stack(stack, allClientsId, cons(data, elems));
predicate_family stack_push_context_pre(void *ctxt)(stack_unsep* unsep, struct stack *stack, int allClientsId, void *data, any args);
predicate_family stack_push_context_post(void *ctxt)(any args);
typedef lemma void stack_push_context(stack_push_operation *op);
requires
stack_push_context_pre(this)(?unsep, ?stack, ?allClientsId, ?data, ?args) &*&
stack(stack, allClientsId, ?elems) &*&
stack_unsep(unsep)(args, stack, allClientsId, ?inv, ?sep, elems) &*&
is_stack_push_operation(op) &*&
stack_push_operation_pre(op)(stack, data);
ensures
stack_push_operation_post(op)() &*&
stack(stack, allClientsId, cons(data, elems)) &*&
stack_unsep(unsep)(args, stack, allClientsId, inv, sep, cons(data, elems)) &*&
is_stack_push_operation(op) &*&
stack_push_context_post(this)(args);
@*/
void stack_push(struct stack *stack, struct stack_client *client, void *data);
/*@
requires
stack_inv_info(?args, stack, ?inv, ?sep, ?unsep) &*&
is_stack_push_context(?context) &*&
stack_push_context_pre(context)(unsep, stack, data, args) &*&
[?f] atomic_space(inv) &*&
stack_client(stack, client);
@*/
/*@
ensures
stack_inv_info(args, stack, inv, sep, unsep) &*&
is_stack_push_context(context) &*&
[f] atomic_space(inv) &*&
stack_push_context_post(context)(args) &*&
stack_client(stack, client);
@*/
/*@
predicate_family stack_try_pop_operation_pre(void *op)(struct stack *stack);
predicate_family stack_try_pop_operation_post(void *op)(bool succes, void* result);
fixpoint t head_or<t>(list<t> l, t def) {
switch(l) {
case nil: return def;
case cons(h, l0): return h;
}
}
typedef lemma void stack_try_pop_operation();
requires stack_try_pop_operation_pre(this)(?stack) &*& stack(stack, ?allClientsId, ?elems);
ensures stack_try_pop_operation_post(this)(elems != nil, head_or(elems, 0)) &*&
stack(stack, allClientsId, tail(elems));
predicate_family stack_try_pop_context_pre(void *ctxt)(stack_unsep* unsep, struct stack *stack, int allClientsId, any args);
predicate_family stack_try_pop_context_post(void *ctxt)(bool succes, void* result, any args);
typedef lemma void stack_try_pop_context(stack_try_pop_operation *op);
requires
stack_try_pop_context_pre(this)(?unsep, ?stack, ?allClientsId, ?args) &*&
stack(stack, allClientsId, ?elems) &*&
stack_unsep(unsep)(args, stack, allClientsId, ?inv, ?sep, elems) &*&
is_stack_try_pop_operation(op) &*&
stack_try_pop_operation_pre(op)(stack);
ensures
stack_try_pop_operation_post(op)(?success, ?result) &*&
stack(stack, allClientsId, tail(elems)) &*&
stack_unsep(unsep)(args, stack, allClientsId, inv, sep, tail(elems)) &*&
is_stack_try_pop_operation(op) &*&
stack_try_pop_context_post(this)(success, result, args);
@*/
bool stack_try_pop(struct stack *stack, struct stack_client *client, void** resultRef);
/*@
requires
stack_inv_info(?args, stack, ?inv, ?sep, ?unsep) &*&
is_stack_try_pop_context(?context) &*&
stack_try_pop_context_pre(context)(unsep, stack, args) &*&
[?f] atomic_space(inv) &*&
stack_client(stack, client)&*&
pointer(resultRef, _);
@*/
/*@
ensures
stack_inv_info(args, stack, inv, sep, unsep) &*&
is_stack_try_pop_context(context) &*&
stack_try_pop_context_post(context)(result, ?data, args) &*&
[f] atomic_space(inv) &*&
stack_client(stack, client) &*&
pointer(resultRef, data);
@*/
#endif
|
c9180f7ae32227e6782fc7c3ed118e4ee2b1c085
|
b835d39668f565f48e3486bc1ea710b543c364c6
|
/libswc/seat.c
|
028836904d23cfd6b1ba7e933c0e7be2ff666162
|
[
"MIT"
] |
permissive
|
michaelforney/swc
|
29591010ac06c551ba13ede5d277054f7e092226
|
19893a5ca3239082b904a04fdb9ac7c3a1fb62e2
|
refs/heads/master
| 2023-08-14T23:11:55.958336
| 2023-07-01T20:56:30
| 2023-07-01T20:56:30
| 10,686,699
| 542
| 69
|
MIT
| 2021-10-05T05:37:44
| 2013-06-14T10:21:36
|
C
|
UTF-8
|
C
| false
| false
| 13,969
|
c
|
seat.c
|
/* swc: libswc/seat.c
*
* Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "seat.h"
#include "compositor.h"
#include "data_device.h"
#include "event.h"
#include "internal.h"
#include "keyboard.h"
#include "launch.h"
#include "pointer.h"
#include "screen.h"
#include "surface.h"
#include "util.h"
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libinput.h>
#include <linux/input.h>
#ifdef ENABLE_LIBUDEV
# include <libudev.h>
#endif
#ifndef NETLINK_MASK
# define NETLINK_MASK 4
#endif
struct seat {
struct swc_seat base;
char *name;
uint32_t capabilities;
struct libinput *libinput;
struct wl_event_source *libinput_source;
#ifdef ENABLE_LIBUDEV
struct udev *udev;
#endif
struct wl_listener swc_listener;
struct wl_listener keyboard_focus_listener;
struct pointer pointer;
struct wl_listener data_device_listener;
struct wl_global *global;
struct wl_list resources;
};
static void
handle_keyboard_focus_event(struct wl_listener *listener, void *data)
{
struct seat *seat = wl_container_of(listener, seat, keyboard_focus_listener);
struct event *ev = data;
struct input_focus_event_data *event_data = ev->data;
if (ev->type != INPUT_FOCUS_EVENT_CHANGED)
return;
if (event_data->new) {
struct wl_client *client = wl_resource_get_client(event_data->new->surface->resource);
/* Offer the selection to the new focus. */
data_device_offer_selection(seat->base.data_device, client);
}
}
static void
handle_data_device_event(struct wl_listener *listener, void *data)
{
struct seat *seat = wl_container_of(listener, seat, data_device_listener);
struct event *ev = data;
if (ev->type != DATA_DEVICE_EVENT_SELECTION_CHANGED)
return;
if (seat->base.keyboard->focus.client)
data_device_offer_selection(seat->base.data_device, seat->base.keyboard->focus.client);
}
static void
handle_swc_event(struct wl_listener *listener, void *data)
{
struct seat *seat = wl_container_of(listener, seat, swc_listener);
struct event *ev = data;
switch (ev->type) {
case SWC_EVENT_DEACTIVATED:
libinput_suspend(seat->libinput);
keyboard_reset(seat->base.keyboard);
break;
case SWC_EVENT_ACTIVATED:
if (libinput_resume(seat->libinput) != 0)
WARNING("Failed to resume libinput context\n");
break;
}
}
/* Wayland Seat Interface */
static void
get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id)
{
struct seat *seat = wl_resource_get_user_data(resource);
if (!pointer_bind(&seat->pointer, client, wl_resource_get_version(resource), id))
wl_resource_post_no_memory(resource);
}
static void
get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id)
{
struct seat *seat = wl_resource_get_user_data(resource);
if (!keyboard_bind(seat->base.keyboard, client, wl_resource_get_version(resource), id))
wl_resource_post_no_memory(resource);
}
static void
get_touch(struct wl_client *client, struct wl_resource *resource, uint32_t id)
{
/* XXX: Implement */
}
static const struct wl_seat_interface seat_impl = {
.get_pointer = get_pointer,
.get_keyboard = get_keyboard,
.get_touch = get_touch,
};
static void
bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
struct seat *seat = data;
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_seat_interface, version, id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &seat_impl, seat, &remove_resource);
wl_list_insert(&seat->resources, wl_resource_get_link(resource));
if (version >= 2)
wl_seat_send_name(resource, seat->name);
wl_seat_send_capabilities(resource, seat->capabilities);
}
static void
update_capabilities(struct seat *seat, uint32_t capabilities)
{
struct wl_resource *resource;
if (!(~seat->capabilities & capabilities))
return;
seat->capabilities |= capabilities;
wl_list_for_each(resource, &seat->resources, link)
wl_seat_send_capabilities(resource, seat->capabilities);
}
static int
open_restricted(const char *path, int flags, void *user_data)
{
return launch_open_device(path, flags);
}
static void
close_restricted(int fd, void *user_data)
{
close(fd);
}
const struct libinput_interface libinput_interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
static uint32_t
device_capabilities(struct libinput_device *device)
{
uint32_t capabilities = 0;
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
capabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
capabilities |= WL_SEAT_CAPABILITY_POINTER;
/* TODO: Add touch device support
* if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
* capabilities |= WL_SEAT_CAPABILITY_TOUCH;
*/
return capabilities;
}
static int
handle_libinput_data(int fd, uint32_t mask, void *data)
{
struct seat *seat = data;
struct screen *screen;
struct swc_rectangle *rect;
struct libinput_event *generic_event;
struct libinput_device *device;
union {
struct libinput_event_keyboard *k;
struct libinput_event_pointer *p;
} event;
wl_fixed_t x, y, value;
uint32_t time, key, state;
enum wl_pointer_axis_source source;
int value120;
if (libinput_dispatch(seat->libinput) != 0) {
WARNING("libinput_dispatch failed: %s\n", strerror(errno));
return 0;
}
while ((generic_event = libinput_get_event(seat->libinput))) {
switch (libinput_event_get_type(generic_event)) {
case LIBINPUT_EVENT_DEVICE_ADDED:
device = libinput_event_get_device(generic_event);
update_capabilities(seat, device_capabilities(device));
if (swc.manager->new_device)
swc.manager->new_device(device);
break;
case LIBINPUT_EVENT_KEYBOARD_KEY:
event.k = libinput_event_get_keyboard_event(generic_event);
time = libinput_event_keyboard_get_time(event.k);
key = libinput_event_keyboard_get_key(event.k);
state = libinput_event_keyboard_get_key_state(event.k);
keyboard_handle_key(seat->base.keyboard, time, key, state);
break;
case LIBINPUT_EVENT_POINTER_MOTION:
event.p = libinput_event_get_pointer_event(generic_event);
time = libinput_event_pointer_get_time(event.p);
x = wl_fixed_from_double(libinput_event_pointer_get_dx(event.p));
y = wl_fixed_from_double(libinput_event_pointer_get_dy(event.p));
pointer_handle_relative_motion(&seat->pointer, time, x, y);
pointer_handle_frame(&seat->pointer);
break;
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
screen = wl_container_of(swc.screens.next, screen, link);
rect = &screen->base.geometry;
event.p = libinput_event_get_pointer_event(generic_event);
time = libinput_event_pointer_get_time(event.p);
x = wl_fixed_from_double(libinput_event_pointer_get_absolute_x_transformed(event.p, rect->width));
y = wl_fixed_from_double(libinput_event_pointer_get_absolute_y_transformed(event.p, rect->height));
pointer_handle_absolute_motion(&seat->pointer, time, x, y);
pointer_handle_frame(&seat->pointer);
break;
case LIBINPUT_EVENT_POINTER_BUTTON:
event.p = libinput_event_get_pointer_event(generic_event);
time = libinput_event_pointer_get_time(event.p);
key = libinput_event_pointer_get_button(event.p);
state = libinput_event_pointer_get_button_state(event.p);
pointer_handle_button(&seat->pointer, time, key, state);
if (state == LIBINPUT_BUTTON_STATE_PRESSED) {
/* qemu generates GEAR_UP/GEAR_DOWN events on scroll, so pass
* those through as axis events. */
source = WL_POINTER_AXIS_SOURCE_WHEEL;
switch (key) {
case BTN_GEAR_DOWN:
pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, source, wl_fixed_from_int(10), 120);
break;
case BTN_GEAR_UP:
pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, source, wl_fixed_from_int(-10), -120);
break;
}
}
pointer_handle_frame(&seat->pointer);
break;
case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
source = WL_POINTER_AXIS_SOURCE_WHEEL;
goto scroll;
case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
source = WL_POINTER_AXIS_SOURCE_FINGER;
goto scroll;
case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
source = WL_POINTER_AXIS_SOURCE_CONTINUOUS;
goto scroll;
scroll:
event.p = libinput_event_get_pointer_event(generic_event);
time = libinput_event_pointer_get_time(event.p);
value120 = 0;
if (libinput_event_pointer_has_axis(event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
value = wl_fixed_from_double(libinput_event_pointer_get_scroll_value(event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL));
if (source == WL_POINTER_AXIS_SOURCE_WHEEL)
value120 = libinput_event_pointer_get_scroll_value_v120(event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, source, value, value120);
}
if (libinput_event_pointer_has_axis(event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
value = wl_fixed_from_double(libinput_event_pointer_get_scroll_value(event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL));
if (source == WL_POINTER_AXIS_SOURCE_WHEEL)
value120 = libinput_event_pointer_get_scroll_value_v120(event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_HORIZONTAL_SCROLL, source, value, value120);
}
pointer_handle_frame(&seat->pointer);
break;
default:
break;
}
libinput_event_destroy(generic_event);
}
return 0;
}
bool
initialize_libinput(struct seat *seat)
{
#ifdef ENABLE_LIBUDEV
if (!(seat->udev = udev_new())) {
ERROR("Could not create udev context\n");
goto error0;
}
seat->libinput = libinput_udev_create_context(&libinput_interface, NULL, seat->udev);
#else
seat->libinput = libinput_netlink_create_context(&libinput_interface, NULL, NETLINK_MASK);
#endif
if (!seat->libinput) {
ERROR("Could not create libinput context\n");
goto error1;
}
#ifdef ENABLE_LIBUDEV
if (libinput_udev_assign_seat(seat->libinput, seat->name) != 0) {
ERROR("Failed to assign seat to libinput context\n");
goto error2;
}
#else
if (libinput_netlink_assign_seat(seat->libinput, seat->name) != 0) {
ERROR("Failed to assign seat to libinput context\n");
goto error2;
}
#endif
seat->libinput_source = wl_event_loop_add_fd(swc.event_loop, libinput_get_fd(seat->libinput), WL_EVENT_READABLE, &handle_libinput_data, seat);
if (!seat->libinput_source) {
ERROR("Could not create event source for libinput\n");
goto error2;
}
if (!swc.active)
libinput_suspend(seat->libinput);
return true;
error2:
libinput_unref(seat->libinput);
error1:
#ifdef ENABLE_LIBUDEV
udev_unref(seat->udev);
error0:
#endif
return false;
}
struct swc_seat *
seat_create(struct wl_display *display, const char *seat_name)
{
struct seat *seat;
seat = malloc(sizeof(*seat));
if (!seat)
goto error0;
seat->name = strdup(seat_name);
if (!seat->name) {
ERROR("Could not allocate seat name string\n");
goto error1;
}
seat->global = wl_global_create(display, &wl_seat_interface, 8, seat, &bind_seat);
if (!seat->global)
goto error2;
seat->capabilities = 0;
wl_list_init(&seat->resources);
seat->swc_listener.notify = &handle_swc_event;
wl_signal_add(&swc.event_signal, &seat->swc_listener);
seat->base.data_device = data_device_create();
if (!seat->base.data_device) {
ERROR("Could not initialize data device\n");
goto error3;
}
seat->data_device_listener.notify = &handle_data_device_event;
wl_signal_add(&seat->base.data_device->event_signal, &seat->data_device_listener);
seat->base.keyboard = keyboard_create(NULL);
if (!seat->base.keyboard) {
ERROR("Could not initialize keyboard\n");
goto error4;
}
seat->keyboard_focus_listener.notify = handle_keyboard_focus_event;
wl_signal_add(&seat->base.keyboard->focus.event_signal, &seat->keyboard_focus_listener);
if (!pointer_initialize(&seat->pointer)) {
ERROR("Could not initialize pointer\n");
goto error5;
}
seat->base.pointer = &seat->pointer;
if (!initialize_libinput(seat))
goto error6;
return &seat->base;
error6:
pointer_finalize(&seat->pointer);
error5:
keyboard_destroy(seat->base.keyboard);
error4:
data_device_destroy(seat->base.data_device);
error3:
wl_global_destroy(seat->global);
error2:
free(seat->name);
error1:
free(seat);
error0:
return NULL;
}
void
seat_destroy(struct swc_seat *seat_base)
{
struct seat *seat = wl_container_of(seat_base, seat, base);
wl_event_source_remove(seat->libinput_source);
libinput_unref(seat->libinput);
#ifdef ENABLE_LIBUDEV
udev_unref(seat->udev);
#endif
pointer_finalize(&seat->pointer);
keyboard_destroy(seat->base.keyboard);
data_device_destroy(seat->base.data_device);
wl_global_destroy(seat->global);
free(seat->name);
free(seat);
}
|
721263683733816b5db1e077920d0134a88c7621
|
4692f28f86ee84a76abfac8cc8a0dd41fcd402e4
|
/pkg/network/ebpf/c/protocols/kafka/maps.h
|
88268d3dfc49873cd83b4a82ac333ddd27f35975
|
[
"CC0-1.0",
"BSD-3-Clause",
"Apache-2.0",
"GPL-1.0-or-later",
"MIT",
"0BSD",
"Unlicense",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"BSD-2-Clause-Views",
"MPL-2.0",
"GPL-2.0-only"
] |
permissive
|
DataDog/datadog-agent
|
cc4b89839d6031903bf23aa12eccc2a3f3c7f213
|
d960cdb7de8fa5d1c7138cfe58e754af80cb796a
|
refs/heads/main
| 2023-09-04T10:45:08.138748
| 2023-09-04T09:13:43
| 2023-09-04T09:13:43
| 49,970,739
| 2,388
| 1,288
|
Apache-2.0
| 2023-09-14T20:06:34
| 2016-01-19T17:40:41
|
Go
|
UTF-8
|
C
| false
| false
| 1,541
|
h
|
maps.h
|
#ifndef KAFKA_MAPS_H
#define KAFKA_MAPS_H
#include "map-defs.h"
#include "protocols/kafka/defs.h"
#include "protocols/kafka/types.h"
// LINUX_VERSION_CODE doesn't work with co-re and is relevant to runtime compilation only
#ifdef COMPILE_RUNTIME
// Kernels before 4.7 do not know about per-cpu array maps.
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
// A per-cpu buffer used to read requests fragments during protocol
// classification and avoid allocating a buffer on the stack. Some protocols
// requires us to read at offset that are not aligned. Such reads are forbidden
// if done on the stack and will make the verifier complain about it, but they
// are allowed on map elements, hence the need for this map.
BPF_PERCPU_ARRAY_MAP(kafka_client_id, __u32, char [CLIENT_ID_SIZE_TO_VALIDATE], 1)
BPF_PERCPU_ARRAY_MAP(kafka_topic_name, __u32, char [TOPIC_NAME_MAX_STRING_SIZE_TO_VALIDATE], 1)
#else
// Kernels < 4.7.0 do not know about the per-cpu array map used
// in classification, preventing the program to load even though
// we won't use it. We change the type to a simple array map to
// circumvent that.
BPF_ARRAY_MAP(kafka_client_id, __u32, 1)
BPF_ARRAY_MAP(kafka_topic_name, __u32, 1)
#endif
#else
BPF_PERCPU_ARRAY_MAP(kafka_client_id, __u32, char [CLIENT_ID_SIZE_TO_VALIDATE], 1)
BPF_PERCPU_ARRAY_MAP(kafka_topic_name, __u32, char [TOPIC_NAME_MAX_STRING_SIZE_TO_VALIDATE], 1)
#endif
#endif
|
8d392d428c083ec53f8ac68ba9c190245ff9ac9b
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/crypto/chacha/arch/x86/chacha_sse2.c
|
8256b7d579241176cf8f00dd0b9333cfafcaf0b7
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 16,112
|
c
|
chacha_sse2.c
|
/* $NetBSD: chacha_sse2.c,v 1.3 2023/08/07 01:07:36 rin Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/endian.h>
#include <crypto/arch/x86/immintrin.h>
#include "chacha_sse2.h"
static inline __m128i
rol32(__m128i x, uint8_t n)
{
return _mm_slli_epi32(x, n) | _mm_srli_epi32(x, 32 - n);
}
static inline void
chacha_permute(__m128i *p0, __m128i *p1, __m128i *p2, __m128i *p3,
unsigned nr)
{
__m128i r0, r1, r2, r3;
__m128i c0, c1, c2, c3;
r0 = *p0;
r1 = *p1;
r2 = *p2;
r3 = *p3;
for (; nr > 0; nr -= 2) {
r0 = _mm_add_epi32(r0, r1); r3 ^= r0; r3 = rol32(r3, 16);
r2 = _mm_add_epi32(r2, r3); r1 ^= r2; r1 = rol32(r1, 12);
r0 = _mm_add_epi32(r0, r1); r3 ^= r0; r3 = rol32(r3, 8);
r2 = _mm_add_epi32(r2, r3); r1 ^= r2; r1 = rol32(r1, 7);
c0 = r0;
c1 = _mm_shuffle_epi32(r1, 0x39);
c2 = _mm_shuffle_epi32(r2, 0x4e);
c3 = _mm_shuffle_epi32(r3, 0x93);
c0 = _mm_add_epi32(c0, c1); c3 ^= c0; c3 = rol32(c3, 16);
c2 = _mm_add_epi32(c2, c3); c1 ^= c2; c1 = rol32(c1, 12);
c0 = _mm_add_epi32(c0, c1); c3 ^= c0; c3 = rol32(c3, 8);
c2 = _mm_add_epi32(c2, c3); c1 ^= c2; c1 = rol32(c1, 7);
r0 = c0;
r1 = _mm_shuffle_epi32(c1, 0x93);
r2 = _mm_shuffle_epi32(c2, 0x4e);
r3 = _mm_shuffle_epi32(c3, 0x39);
}
*p0 = r0;
*p1 = r1;
*p2 = r2;
*p3 = r3;
}
void
chacha_core_sse2(uint8_t out[restrict static 64],
const uint8_t in[static 16],
const uint8_t k[static 32],
const uint8_t c[static 16],
unsigned nr)
{
__m128i in0, in1, in2, in3;
__m128i r0, r1, r2, r3;
r0 = in0 = _mm_loadu_si128((const __m128i *)c);
r1 = in1 = _mm_loadu_si128((const __m128i *)k);
r2 = in2 = _mm_loadu_si128((const __m128i *)k + 1);
r3 = in3 = _mm_loadu_si128((const __m128i *)in);
chacha_permute(&r0, &r1, &r2, &r3, nr);
_mm_storeu_si128((__m128i *)out + 0, _mm_add_epi32(r0, in0));
_mm_storeu_si128((__m128i *)out + 1, _mm_add_epi32(r1, in1));
_mm_storeu_si128((__m128i *)out + 2, _mm_add_epi32(r2, in2));
_mm_storeu_si128((__m128i *)out + 3, _mm_add_epi32(r3, in3));
}
void
hchacha_sse2(uint8_t out[restrict static 32],
const uint8_t in[static 16],
const uint8_t k[static 32],
const uint8_t c[static 16],
unsigned nr)
{
__m128i r0, r1, r2, r3;
r0 = _mm_loadu_si128((const __m128i *)c);
r1 = _mm_loadu_si128((const __m128i *)k);
r2 = _mm_loadu_si128((const __m128i *)k + 1);
r3 = _mm_loadu_si128((const __m128i *)in);
chacha_permute(&r0, &r1, &r2, &r3, nr);
_mm_storeu_si128((__m128i *)out + 0, r0);
_mm_storeu_si128((__m128i *)out + 1, r3);
}
#define CHACHA_QUARTERROUND(a, b, c, d) do \
{ \
(a) = _mm_add_epi32((a), (b)); (d) ^= a; (d) = rol32((d), 16); \
(c) = _mm_add_epi32((c), (d)); (b) ^= c; (b) = rol32((b), 12); \
(a) = _mm_add_epi32((a), (b)); (d) ^= a; (d) = rol32((d), 8); \
(c) = _mm_add_epi32((c), (d)); (b) ^= c; (b) = rol32((b), 7); \
} while (/*CONSTCOND*/0)
static inline __m128i
load1_epi32(const void *p)
{
return (__m128i)_mm_load1_ps(p);
}
static inline __m128i
loadu_epi32(const void *p)
{
return _mm_loadu_si128(p);
}
static inline void
storeu_epi32(void *p, __m128i v)
{
return _mm_storeu_si128(p, v);
}
static inline __m128i
unpack0_epi32(__m128i a, __m128i b, __m128i c, __m128i d)
{
__m128 lo = (__m128)_mm_unpacklo_epi32(a, b); /* (a[0], b[0], ...) */
__m128 hi = (__m128)_mm_unpacklo_epi32(c, d); /* (c[0], d[0], ...) */
/* (lo[0]=a[0], lo[1]=b[0], hi[0]=c[0], hi[1]=d[0]) */
return (__m128i)_mm_movelh_ps(lo, hi);
}
static inline __m128i
unpack1_epi32(__m128i a, __m128i b, __m128i c, __m128i d)
{
__m128 lo = (__m128)_mm_unpacklo_epi32(a, b); /* (..., a[1], b[1]) */
__m128 hi = (__m128)_mm_unpacklo_epi32(c, d); /* (..., c[1], d[1]) */
/* (lo[2]=a[1], lo[3]=b[1], hi[2]=c[1], hi[3]=d[1]) */
return (__m128i)_mm_movehl_ps(hi, lo);
}
static inline __m128i
unpack2_epi32(__m128i a, __m128i b, __m128i c, __m128i d)
{
__m128 lo = (__m128)_mm_unpackhi_epi32(a, b); /* (a[2], b[2], ...) */
__m128 hi = (__m128)_mm_unpackhi_epi32(c, d); /* (c[2], d[2], ...) */
/* (lo[0]=a[2], lo[1]=b[2], hi[0]=c[2], hi[1]=d[2]) */
return (__m128i)_mm_movelh_ps(lo, hi);
}
static inline __m128i
unpack3_epi32(__m128i a, __m128i b, __m128i c, __m128i d)
{
__m128 lo = (__m128)_mm_unpackhi_epi32(a, b); /* (..., a[3], b[3]) */
__m128 hi = (__m128)_mm_unpackhi_epi32(c, d); /* (..., c[3], d[3]) */
/* (lo[2]=a[3], lo[3]=b[3], hi[2]=c[3], hi[3]=d[3]) */
return (__m128i)_mm_movehl_ps(hi, lo);
}
void
chacha_stream_sse2(uint8_t *restrict s, size_t n,
uint32_t blkno,
const uint8_t nonce[static 12],
const uint8_t k[static 32],
unsigned nr)
{
__m128i x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
__m128i y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15;
__m128i z0,z1,z2,z3,z4,z5,z6,z7,z8,z9,z10,z11,z12,z13,z14,z15;
unsigned r;
if (n < 256)
goto out;
x0 = load1_epi32(chacha_const32 + 0);
x1 = load1_epi32(chacha_const32 + 4);
x2 = load1_epi32(chacha_const32 + 8);
x3 = load1_epi32(chacha_const32 + 12);
x4 = load1_epi32(k + 0);
x5 = load1_epi32(k + 4);
x6 = load1_epi32(k + 8);
x7 = load1_epi32(k + 12);
x8 = load1_epi32(k + 16);
x9 = load1_epi32(k + 20);
x10 = load1_epi32(k + 24);
x11 = load1_epi32(k + 28);
/* x12 set in the loop */
x13 = load1_epi32(nonce + 0);
x14 = load1_epi32(nonce + 4);
x15 = load1_epi32(nonce + 8);
for (; n >= 256; s += 256, n -= 256, blkno += 4) {
x12 = _mm_add_epi32(_mm_set1_epi32(blkno),
_mm_set_epi32(3,2,1,0));
y0 = x0;
y1 = x1;
y2 = x2;
y3 = x3;
y4 = x4;
y5 = x5;
y6 = x6;
y7 = x7;
y8 = x8;
y9 = x9;
y10 = x10;
y11 = x11;
y12 = x12;
y13 = x13;
y14 = x14;
y15 = x15;
for (r = nr; r > 0; r -= 2) {
CHACHA_QUARTERROUND( y0, y4, y8,y12);
CHACHA_QUARTERROUND( y1, y5, y9,y13);
CHACHA_QUARTERROUND( y2, y6,y10,y14);
CHACHA_QUARTERROUND( y3, y7,y11,y15);
CHACHA_QUARTERROUND( y0, y5,y10,y15);
CHACHA_QUARTERROUND( y1, y6,y11,y12);
CHACHA_QUARTERROUND( y2, y7, y8,y13);
CHACHA_QUARTERROUND( y3, y4, y9,y14);
}
y0 = _mm_add_epi32(y0, x0);
y1 = _mm_add_epi32(y1, x1);
y2 = _mm_add_epi32(y2, x2);
y3 = _mm_add_epi32(y3, x3);
y4 = _mm_add_epi32(y4, x4);
y5 = _mm_add_epi32(y5, x5);
y6 = _mm_add_epi32(y6, x6);
y7 = _mm_add_epi32(y7, x7);
y8 = _mm_add_epi32(y8, x8);
y9 = _mm_add_epi32(y9, x9);
y10 = _mm_add_epi32(y10, x10);
y11 = _mm_add_epi32(y11, x11);
y12 = _mm_add_epi32(y12, x12);
y13 = _mm_add_epi32(y13, x13);
y14 = _mm_add_epi32(y14, x14);
y15 = _mm_add_epi32(y15, x15);
z0 = unpack0_epi32(y0, y1, y2, y3);
z1 = unpack0_epi32(y4, y5, y6, y7);
z2 = unpack0_epi32(y8, y9, y10, y11);
z3 = unpack0_epi32(y12, y13, y14, y15);
z4 = unpack1_epi32(y0, y1, y2, y3);
z5 = unpack1_epi32(y4, y5, y6, y7);
z6 = unpack1_epi32(y8, y9, y10, y11);
z7 = unpack1_epi32(y12, y13, y14, y15);
z8 = unpack2_epi32(y0, y1, y2, y3);
z9 = unpack2_epi32(y4, y5, y6, y7);
z10 = unpack2_epi32(y8, y9, y10, y11);
z11 = unpack2_epi32(y12, y13, y14, y15);
z12 = unpack3_epi32(y0, y1, y2, y3);
z13 = unpack3_epi32(y4, y5, y6, y7);
z14 = unpack3_epi32(y8, y9, y10, y11);
z15 = unpack3_epi32(y12, y13, y14, y15);
storeu_epi32(s + 16*0, z0);
storeu_epi32(s + 16*1, z1);
storeu_epi32(s + 16*2, z2);
storeu_epi32(s + 16*3, z3);
storeu_epi32(s + 16*4, z4);
storeu_epi32(s + 16*5, z5);
storeu_epi32(s + 16*6, z6);
storeu_epi32(s + 16*7, z7);
storeu_epi32(s + 16*8, z8);
storeu_epi32(s + 16*9, z9);
storeu_epi32(s + 16*10, z10);
storeu_epi32(s + 16*11, z11);
storeu_epi32(s + 16*12, z12);
storeu_epi32(s + 16*13, z13);
storeu_epi32(s + 16*14, z14);
storeu_epi32(s + 16*15, z15);
}
out: if (n) {
const __m128i blkno_inc = _mm_set_epi32(0,0,0,1);
__m128i in0, in1, in2, in3;
__m128i r0, r1, r2, r3;
in0 = _mm_loadu_si128((const __m128i *)chacha_const32);
in1 = _mm_loadu_si128((const __m128i *)k);
in2 = _mm_loadu_si128((const __m128i *)k + 1);
in3 = _mm_set_epi32(le32dec(nonce + 8), le32dec(nonce + 4),
le32dec(nonce), blkno);
for (; n; s += 64, n -= 64) {
r0 = in0;
r1 = in1;
r2 = in2;
r3 = in3;
chacha_permute(&r0, &r1, &r2, &r3, nr);
r0 = _mm_add_epi32(r0, in0);
r1 = _mm_add_epi32(r1, in1);
r2 = _mm_add_epi32(r2, in2);
r3 = _mm_add_epi32(r3, in3);
if (n < 64) {
uint8_t buf[64] __aligned(16);
_mm_storeu_si128((__m128i *)buf + 0, r0);
_mm_storeu_si128((__m128i *)buf + 1, r1);
_mm_storeu_si128((__m128i *)buf + 2, r2);
_mm_storeu_si128((__m128i *)buf + 3, r3);
memcpy(s, buf, n);
break;
}
_mm_storeu_si128((__m128i *)s + 0, r0);
_mm_storeu_si128((__m128i *)s + 1, r1);
_mm_storeu_si128((__m128i *)s + 2, r2);
_mm_storeu_si128((__m128i *)s + 3, r3);
in3 = _mm_add_epi32(in3, blkno_inc);
}
}
}
void
chacha_stream_xor_sse2(uint8_t *s, const uint8_t *p, size_t n,
uint32_t blkno,
const uint8_t nonce[static 12],
const uint8_t k[static 32],
unsigned nr)
{
__m128i x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
__m128i y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15;
__m128i z0,z1,z2,z3,z4,z5,z6,z7,z8,z9,z10,z11,z12,z13,z14,z15;
unsigned r;
if (n < 256)
goto out;
x0 = load1_epi32(chacha_const32 + 0);
x1 = load1_epi32(chacha_const32 + 4);
x2 = load1_epi32(chacha_const32 + 8);
x3 = load1_epi32(chacha_const32 + 12);
x4 = load1_epi32(k + 0);
x5 = load1_epi32(k + 4);
x6 = load1_epi32(k + 8);
x7 = load1_epi32(k + 12);
x8 = load1_epi32(k + 16);
x9 = load1_epi32(k + 20);
x10 = load1_epi32(k + 24);
x11 = load1_epi32(k + 28);
/* x12 set in the loop */
x13 = load1_epi32(nonce + 0);
x14 = load1_epi32(nonce + 4);
x15 = load1_epi32(nonce + 8);
for (; n >= 256; s += 256, p += 256, n -= 256, blkno += 4) {
x12 = _mm_add_epi32(_mm_set1_epi32(blkno),
_mm_set_epi32(3,2,1,0));
y0 = x0;
y1 = x1;
y2 = x2;
y3 = x3;
y4 = x4;
y5 = x5;
y6 = x6;
y7 = x7;
y8 = x8;
y9 = x9;
y10 = x10;
y11 = x11;
y12 = x12;
y13 = x13;
y14 = x14;
y15 = x15;
for (r = nr; r > 0; r -= 2) {
CHACHA_QUARTERROUND( y0, y4, y8,y12);
CHACHA_QUARTERROUND( y1, y5, y9,y13);
CHACHA_QUARTERROUND( y2, y6,y10,y14);
CHACHA_QUARTERROUND( y3, y7,y11,y15);
CHACHA_QUARTERROUND( y0, y5,y10,y15);
CHACHA_QUARTERROUND( y1, y6,y11,y12);
CHACHA_QUARTERROUND( y2, y7, y8,y13);
CHACHA_QUARTERROUND( y3, y4, y9,y14);
}
y0 = _mm_add_epi32(y0, x0);
y1 = _mm_add_epi32(y1, x1);
y2 = _mm_add_epi32(y2, x2);
y3 = _mm_add_epi32(y3, x3);
y4 = _mm_add_epi32(y4, x4);
y5 = _mm_add_epi32(y5, x5);
y6 = _mm_add_epi32(y6, x6);
y7 = _mm_add_epi32(y7, x7);
y8 = _mm_add_epi32(y8, x8);
y9 = _mm_add_epi32(y9, x9);
y10 = _mm_add_epi32(y10, x10);
y11 = _mm_add_epi32(y11, x11);
y12 = _mm_add_epi32(y12, x12);
y13 = _mm_add_epi32(y13, x13);
y14 = _mm_add_epi32(y14, x14);
y15 = _mm_add_epi32(y15, x15);
z0 = unpack0_epi32(y0, y1, y2, y3);
z1 = unpack0_epi32(y4, y5, y6, y7);
z2 = unpack0_epi32(y8, y9, y10, y11);
z3 = unpack0_epi32(y12, y13, y14, y15);
z4 = unpack1_epi32(y0, y1, y2, y3);
z5 = unpack1_epi32(y4, y5, y6, y7);
z6 = unpack1_epi32(y8, y9, y10, y11);
z7 = unpack1_epi32(y12, y13, y14, y15);
z8 = unpack2_epi32(y0, y1, y2, y3);
z9 = unpack2_epi32(y4, y5, y6, y7);
z10 = unpack2_epi32(y8, y9, y10, y11);
z11 = unpack2_epi32(y12, y13, y14, y15);
z12 = unpack3_epi32(y0, y1, y2, y3);
z13 = unpack3_epi32(y4, y5, y6, y7);
z14 = unpack3_epi32(y8, y9, y10, y11);
z15 = unpack3_epi32(y12, y13, y14, y15);
storeu_epi32(s + 16*0, loadu_epi32(p + 16*0) ^ z0);
storeu_epi32(s + 16*1, loadu_epi32(p + 16*1) ^ z1);
storeu_epi32(s + 16*2, loadu_epi32(p + 16*2) ^ z2);
storeu_epi32(s + 16*3, loadu_epi32(p + 16*3) ^ z3);
storeu_epi32(s + 16*4, loadu_epi32(p + 16*4) ^ z4);
storeu_epi32(s + 16*5, loadu_epi32(p + 16*5) ^ z5);
storeu_epi32(s + 16*6, loadu_epi32(p + 16*6) ^ z6);
storeu_epi32(s + 16*7, loadu_epi32(p + 16*7) ^ z7);
storeu_epi32(s + 16*8, loadu_epi32(p + 16*8) ^ z8);
storeu_epi32(s + 16*9, loadu_epi32(p + 16*9) ^ z9);
storeu_epi32(s + 16*10, loadu_epi32(p + 16*10) ^ z10);
storeu_epi32(s + 16*11, loadu_epi32(p + 16*11) ^ z11);
storeu_epi32(s + 16*12, loadu_epi32(p + 16*12) ^ z12);
storeu_epi32(s + 16*13, loadu_epi32(p + 16*13) ^ z13);
storeu_epi32(s + 16*14, loadu_epi32(p + 16*14) ^ z14);
storeu_epi32(s + 16*15, loadu_epi32(p + 16*15) ^ z15);
}
out: if (n) {
const __m128i blkno_inc = _mm_set_epi32(0,0,0,1);
__m128i in0, in1, in2, in3;
__m128i r0, r1, r2, r3;
in0 = _mm_loadu_si128((const __m128i *)chacha_const32);
in1 = _mm_loadu_si128((const __m128i *)k);
in2 = _mm_loadu_si128((const __m128i *)k + 1);
in3 = _mm_set_epi32(le32dec(nonce + 8), le32dec(nonce + 4),
le32dec(nonce), blkno);
for (; n; s += 64, p += 64, n -= 64) {
r0 = in0;
r1 = in1;
r2 = in2;
r3 = in3;
chacha_permute(&r0, &r1, &r2, &r3, nr);
r0 = _mm_add_epi32(r0, in0);
r1 = _mm_add_epi32(r1, in1);
r2 = _mm_add_epi32(r2, in2);
r3 = _mm_add_epi32(r3, in3);
if (n < 64) {
uint8_t buf[64] __aligned(16);
unsigned i;
_mm_storeu_si128((__m128i *)buf + 0, r0);
_mm_storeu_si128((__m128i *)buf + 1, r1);
_mm_storeu_si128((__m128i *)buf + 2, r2);
_mm_storeu_si128((__m128i *)buf + 3, r3);
for (i = 0; i < n - n%4; i += 4)
le32enc(s + i,
le32dec(p + i) ^ le32dec(buf + i));
for (; i < n; i++)
s[i] = p[i] ^ buf[i];
break;
}
r0 ^= _mm_loadu_si128((const __m128i *)p + 0);
r1 ^= _mm_loadu_si128((const __m128i *)p + 1);
r2 ^= _mm_loadu_si128((const __m128i *)p + 2);
r3 ^= _mm_loadu_si128((const __m128i *)p + 3);
_mm_storeu_si128((__m128i *)s + 0, r0);
_mm_storeu_si128((__m128i *)s + 1, r1);
_mm_storeu_si128((__m128i *)s + 2, r2);
_mm_storeu_si128((__m128i *)s + 3, r3);
in3 = _mm_add_epi32(in3, blkno_inc);
}
}
}
void
xchacha_stream_sse2(uint8_t *restrict s, size_t nbytes,
uint32_t blkno,
const uint8_t nonce[static 24],
const uint8_t k[static 32],
unsigned nr)
{
uint8_t subkey[32];
uint8_t subnonce[12];
hchacha_sse2(subkey, nonce/*[0:16)*/, k, chacha_const32, nr);
memset(subnonce, 0, 4);
memcpy(subnonce + 4, nonce + 16, 8);
chacha_stream_sse2(s, nbytes, blkno, subnonce, subkey, nr);
}
void
xchacha_stream_xor_sse2(uint8_t *restrict c, const uint8_t *p, size_t nbytes,
uint32_t blkno,
const uint8_t nonce[static 24],
const uint8_t k[static 32],
unsigned nr)
{
uint8_t subkey[32];
uint8_t subnonce[12];
hchacha_sse2(subkey, nonce/*[0:16)*/, k, chacha_const32, nr);
memset(subnonce, 0, 4);
memcpy(subnonce + 4, nonce + 16, 8);
chacha_stream_xor_sse2(c, p, nbytes, blkno, subnonce, subkey, nr);
}
|
e91cccae3f9e84c4050c24e3686e0e76c9d0ea68
|
1095cfe2e29ddf4e4c5e12d713bd12f45c9b6f7d
|
/ext/softfloat/f128M_div.c
|
a2c838df5332e87c304d9278bc848762e7365fbe
|
[
"BSD-3-Clause",
"LicenseRef-scancode-proprietary-license",
"LGPL-2.0-or-later",
"MIT"
] |
permissive
|
gem5/gem5
|
9ec715ae036c2e08807b5919f114e1d38d189bce
|
48a40cf2f5182a82de360b7efa497d82e06b1631
|
refs/heads/stable
| 2023-09-03T15:56:25.819189
| 2023-08-31T05:53:03
| 2023-08-31T05:53:03
| 27,425,638
| 1,185
| 1,177
|
BSD-3-Clause
| 2023-09-14T08:29:31
| 2014-12-02T09:46:00
|
C++
|
UTF-8
|
C
| false
| false
| 6,782
|
c
|
f128M_div.c
|
/*============================================================================
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
Package, Release 3d, by John R. Hauser.
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "specialize.h"
#include "softfloat.h"
#ifdef SOFTFLOAT_FAST_INT64
void
f128M_div( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr )
{
*zPtr = f128_div( *aPtr, *bPtr );
}
#else
void
f128M_div( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr )
{
const uint32_t *aWPtr, *bWPtr;
uint32_t *zWPtr, uiA96;
bool signA;
int32_t expA;
uint32_t uiB96;
bool signB;
int32_t expB;
bool signZ;
uint32_t y[5], sigB[4];
int32_t expZ;
uint32_t recip32;
int ix;
uint64_t q64;
uint32_t q, qs[3], uiZ96;
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
aWPtr = (const uint32_t *) aPtr;
bWPtr = (const uint32_t *) bPtr;
zWPtr = (uint32_t *) zPtr;
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
uiA96 = aWPtr[indexWordHi( 4 )];
signA = signF128UI96( uiA96 );
expA = expF128UI96( uiA96 );
uiB96 = bWPtr[indexWordHi( 4 )];
signB = signF128UI96( uiB96 );
expB = expF128UI96( uiB96 );
signZ = signA ^ signB;
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
if ( softfloat_tryPropagateNaNF128M( aWPtr, bWPtr, zWPtr ) ) return;
if ( expA == 0x7FFF ) {
if ( expB == 0x7FFF ) goto invalid;
goto infinity;
}
goto zero;
}
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
expA = softfloat_shiftNormSigF128M( aWPtr, 13, y );
expB = softfloat_shiftNormSigF128M( bWPtr, 13, sigB );
if ( expA == -128 ) {
if ( expB == -128 ) goto invalid;
goto zero;
}
if ( expB == -128 ) {
softfloat_raiseFlags( softfloat_flag_infinite );
goto infinity;
}
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
expZ = expA - expB + 0x3FFE;
if ( softfloat_compare128M( y, sigB ) < 0 ) {
--expZ;
softfloat_add128M( y, y, y );
}
recip32 =
softfloat_approxRecip32_1(
((uint64_t) sigB[indexWord( 4, 3 )]<<32 | sigB[indexWord( 4, 2 )])
>>30
);
ix = 3;
for (;;) {
q64 = (uint64_t) y[indexWordHi( 4 )] * recip32;
q = (q64 + 0x80000000)>>32;
--ix;
if ( ix < 0 ) break;
softfloat_remStep128MBy32( y, 29, sigB, q, y );
if ( y[indexWordHi( 4 )] & 0x80000000 ) {
--q;
softfloat_add128M( y, sigB, y );
}
qs[ix] = q;
}
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
if ( ((q + 1) & 7) < 2 ) {
softfloat_remStep128MBy32( y, 29, sigB, q, y );
if ( y[indexWordHi( 4 )] & 0x80000000 ) {
--q;
softfloat_add128M( y, sigB, y );
} else if ( softfloat_compare128M( sigB, y ) <= 0 ) {
++q;
softfloat_sub128M( y, sigB, y );
}
if (
y[indexWordLo( 4 )] || y[indexWord( 4, 1 )]
|| (y[indexWord( 4, 2 )] | y[indexWord( 4, 3 )])
) {
q |= 1;
}
}
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
q64 = (uint64_t) q<<28;
y[indexWord( 5, 0 )] = q64;
q64 = ((uint64_t) qs[0]<<25) + (q64>>32);
y[indexWord( 5, 1 )] = q64;
q64 = ((uint64_t) qs[1]<<22) + (q64>>32);
y[indexWord( 5, 2 )] = q64;
q64 = ((uint64_t) qs[2]<<19) + (q64>>32);
y[indexWord( 5, 3 )] = q64;
y[indexWord( 5, 4 )] = q64>>32;
softfloat_roundPackMToF128M( signZ, expZ, y, zWPtr );
return;
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
invalid:
softfloat_invalidF128M( zWPtr );
return;
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
infinity:
uiZ96 = packToF128UI96( signZ, 0x7FFF, 0 );
goto uiZ96;
zero:
uiZ96 = packToF128UI96( signZ, 0, 0 );
uiZ96:
zWPtr[indexWordHi( 4 )] = uiZ96;
zWPtr[indexWord( 4, 2 )] = 0;
zWPtr[indexWord( 4, 1 )] = 0;
zWPtr[indexWord( 4, 0 )] = 0;
}
#endif
|
6b43e83a293107fb3c652d75553ccc5dfd3a2dab
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/libc/fmt/formatflex64.c
|
728d98b05aa544acb478b2f4d6a98385b6448f6c
|
[
"ISC"
] |
permissive
|
jart/cosmopolitan
|
fb11b5658939023977060a7c6c71a74093d9cb44
|
0d748ad58e1063dd1f8560f18a0c75293b9415b7
|
refs/heads/master
| 2023-09-06T09:17:29.303607
| 2023-09-02T03:49:13
| 2023-09-02T03:50:18
| 272,457,606
| 11,887
| 435
|
ISC
| 2023-09-14T17:47:58
| 2020-06-15T14:16:13
|
C
|
UTF-8
|
C
| false
| false
| 2,359
|
c
|
formatflex64.c
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/fmt/itoa.h"
#include "libc/intrin/popcnt.h"
/**
* Formats integer using decimal or hexadecimal.
*
* This formats as int64 signed decimal. However it's a:
*
* 1. positive number
* 2. with population count of 1
* 3. and a magnitude of at least 256
*
* Then we switch to hex notation to make the number more readable.
*/
char *FormatFlex64(char p[hasatleast 24], int64_t x, char z) {
if (x >= 256 && popcnt(x) == 1) {
return FormatHex64(p, x, z);
} else {
return FormatInt64(p, x);
}
}
|
a2d75043081e8aa8936499c884bbf3d86d3a522d
|
c4a119311ac01bbe7d5ab81b1d3d663ad0900ab6
|
/python-modules/pybluez/bluez/bluetooth/mgmt.h
|
80b4de58d5cbcb9aae52c430246eb91ab09eba1b
|
[
"GPL-2.0-only",
"Apache-2.0"
] |
permissive
|
kuri65536/python-for-android
|
1d8d99e81e64bc87805c2c58ee0dcf43d413e72e
|
26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891
|
refs/heads/master
| 2021-06-02T01:17:29.685199
| 2018-05-05T00:12:13
| 2018-05-05T01:36:22
| 32,235,625
| 280
| 122
|
Apache-2.0
| 2020-05-15T06:47:36
| 2015-03-14T22:44:36
|
Python
|
UTF-8
|
C
| false
| false
| 2,504
|
h
|
mgmt.h
|
/*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2010 Nokia Corporation
* Copyright (C) 2010 Marcel Holtmann <marcel@holtmann.org>
*
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __packed
#define __packed __attribute__((packed))
#endif
struct mgmt_hdr {
uint16_t opcode;
uint16_t len;
} __packed;
#define MGMT_HDR_SIZE 4
#define MGMT_OP_READ_VERSION 0x0001
struct mgmt_rp_read_version {
uint8_t version;
uint16_t revision;
} __packed;
#define MGMT_OP_READ_FEATURES 0x0002
struct mgmt_rp_read_features {
uint8_t features[8];
} __packed;
#define MGMT_OP_READ_INDEX_LIST 0x0003
struct mgmt_rp_read_index_list {
uint16_t num_controllers;
uint16_t index[0];
} __packed;
#define MGMT_OP_READ_INFO 0x0004
struct mgmt_cp_read_info {
uint16_t index;
} __packed;
struct mgmt_rp_read_info {
uint8_t status;
uint16_t index;
uint8_t type;
bdaddr_t bdaddr;
uint8_t features[8];
uint16_t manufacturer;
uint8_t hci_ver;
uint16_t hci_rev;
} __packed;
#define MGMT_OP_READ_STATISTICS 0x0005
#define MGMT_OP_READ_MODE 0x0006
struct mgmt_cp_read_mode {
uint16_t index;
} __packed;
struct mgmt_rp_read_mode {
uint8_t status;
uint16_t index;
uint8_t enabled;
uint8_t mode;
} __packed;
#define MGMT_OP_WRITE_MODE 0x0007
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
uint16_t opcode;
uint8_t data[0];
} __packed;
#define MGMT_EV_CMD_STATUS 0x0002
struct mgmt_ev_cmd_status {
uint8_t status;
uint16_t opcode;
} __packed;
#define MGMT_EV_CONTROLLER_ERROR 0x0003
struct mgmt_ev_controller_error {
uint16_t index;
uint8_t error_code;
} __packed;
#define MGMT_EV_INDEX_ADDED 0x0004
struct mgmt_ev_index_added {
uint16_t index;
} __packed;
#define MGMT_EV_INDEX_REMOVED 0x0005
struct mgmt_ev_index_removed {
uint16_t index;
} __packed;
|
52080e23a5ef1b49795967fb2a74990aa40a0ade
|
76f7459a09acb9be2d52407132f5ff8955627da2
|
/sandbox/power10/p10_testsuite/performance.c
|
25f1c3ff2a98b1a98a6e5dfaf7d9e0055329ebfd
|
[
"BSD-3-Clause"
] |
permissive
|
flame/blis
|
448bc0ad139b726188129c5627c304274b41c3c1
|
6dcf7666eff14348e82fbc2750be4b199321e1b9
|
refs/heads/master
| 2023-09-01T14:56:11.920485
| 2023-08-27T19:18:57
| 2023-08-27T19:18:57
| 16,143,904
| 1,696
| 361
|
NOASSERTION
| 2023-08-27T19:18:58
| 2014-01-22T15:58:24
|
C
|
UTF-8
|
C
| false
| false
| 2,908
|
c
|
performance.c
|
/*
This program is designed to gather the performance data of the POWER10
GEMM kernels in `blis/sandbox/power10`.
By default, the performance of the kernels is gather over a set of square
matrices. The perfromance results are reported in GFLOPS, and outputted in
CSV format.
*/
#include "performance.h"
#include "blis.h"
#include "../bli_sandbox.h"
#include "common.h"
#include <stdio.h>
// print kernel name
const char* get_kernel_name(int kernel_id)
{
switch (kernel_id)
{
case FLOAT16 : return "bli_shgemm";
case BFLOAT16: return "bli_sbgemm";
case INT16 : return "bli_i16gemm";
case INT8 : return "bli_i8gemm";
case INT4 : return "bli_i4gemm";
default: printf("INCORRECT KERNEL ID\n"); exit(-1);
}
}
// create all the performance gathering functions for each kernel
GET_PERF_API_TEMP(sb, bli_sbgemm, bfloat16, float);
GET_PERF_API_TEMP(sh, bli_shgemm, float16, float);
GET_PERF_API_TEMP(i16, bli_i16gemm, int16_t, int);
GET_PERF_API_TEMP(i8, bli_i8gemm, int8_t, int);
GET_PERF_API_TEMP(i4, bli_i4gemm, nibbles, int);
// using the DATATYPE enum, gather the performance of the respective GEMM kernel
double run_kernel(int kernel_id, int nreps, int m, int n, int k)
{
switch (kernel_id)
{
case FLOAT16 : return test_shapi(nreps, m, n, k);
case BFLOAT16: return test_sbapi(nreps, m, n, k);
case INT16 : return test_i16api(nreps, m, n, k);
case INT8 : return test_i8api(nreps, m, n, k);
case INT4 : return test_i4api(nreps, m, n, k);
default: return -1.0;
}
}
// print the performance data in CSV format
// performance is measured in terms of GFLOPs
void print_perf_data(int m, int n, int k, double best_time)
{
double GFLOPS = (2.0 * m * n * k) / (1e9 * best_time);
printf("%d, %d, %d, %.2f\n", m, n, k, GFLOPS);
}
// get performance data
void get_perf(int kernel_id, int nreps, int start, int end, int inc)
{
// csv header
printf("%s performance\n", get_kernel_name(kernel_id));
printf("m, n, k, GFLOPS\n");
int m,n,k;
// run over all problem sizes
for (int p=start; p<=end; p+=inc)
{
// change here to adjust problem size
m = p,
n = p,
k = p;
double best_run_time = run_kernel(kernel_id, nreps, m, n, k);
print_perf_data(m, n, k, best_run_time);
}
}
int main(int argc, char *argv[])
{
// initialize a square problem set range
int start = 80;
int end = 4000;
int inc = 80;
// number of times the kernel will be run
int nreps = 5;
// run a respective kernel
get_perf( FLOAT16, nreps, start, end, inc);
get_perf(BFLOAT16, nreps, start, end, inc);
get_perf( INT16, nreps, start, end, inc);
get_perf( INT8, nreps, start, end, inc);
get_perf( INT4, nreps, start, end, inc);
return 0;
}
|
6ec60722fa8638ce4816117c891512b20e021d6b
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/databases/OpenEXR/avtOpenEXRFileFormat.C
|
f371d5ea1b7517d977e8722bf704dcf1cfad8754
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 11,630
|
c
|
avtOpenEXRFileFormat.C
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
// ************************************************************************* //
// avtOpenEXRFileFormat.C //
// ************************************************************************* //
#include <avtOpenEXRFileFormat.h>
#include <string>
#include <vtkFloatArray.h>
#include <vtkRectilinearGrid.h>
#include <avtDatabaseMetaData.h>
#include <InvalidVariableException.h>
#include <DebugStream.h>
#ifdef _WIN32
// We built OpenEXR as a DLL on Windows.
#define OPENEXR_DLL
#endif
#include <ImfInputFile.h>
#include <ImfChannelList.h>
#include <ImfFrameBuffer.h>
// ****************************************************************************
// Class: avtOpenEXRFileFormat::Internal
//
// Purpose:
// Reads OpenEXR files.
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 18:00:24 PDT 2017
//
// Modifications:
//
// ****************************************************************************
class avtOpenEXRFileFormat::Internal
{
public:
Internal() : file(NULL), filename()
{
}
~Internal()
{
FreeResources();
}
void FreeResources()
{
if(file != NULL)
{
delete file;
file = NULL;
}
}
void SetFileName(const std::string &fn)
{
if(fn != filename && file != NULL)
{
delete file;
file = NULL;
}
filename = fn;
}
Imf::InputFile *GetFile()
{
if(file == NULL)
{
try
{
file = new Imf::InputFile(filename.c_str());
}
catch(...)
{
file = NULL;
}
}
return file;
}
void GetSize(int &width, int &height)
{
// Read the channel names from the file. Get the image size.
if(GetFile() != NULL)
{
Imath::Box2i dw = GetFile()->header().dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
}
else
{
width = height = 0;
}
}
bool GetChannelNames(std::vector<std::string> &names)
{
names.clear();
if(GetFile() != NULL)
{
const Imf::ChannelList &channels = GetFile()->header().channels();
Imf::ChannelList::ConstIterator it = channels.begin();
for( ; it != channels.end(); ++it)
{
names.push_back(it.name());
}
}
return !names.empty();
}
vtkDataArray *ReadChannel(const std::string &name)
{
vtkDataArray *retval = NULL;
if(GetFile() != NULL)
{
int width, height;
GetSize(width, height);
debug5 << "OpenEXR: width=" << width << ", height=" << height << endl;
const Imf::ChannelList &channels = GetFile()->header().channels();
const Imf::Channel *channel = channels.findChannel(name);
if(channel != NULL)
{
Imf::FrameBuffer fb;
if(channel->type == Imf::HALF)
{
debug5 << "Reading half data for " << name << endl;
half *data = new half[width*height];
fb.insert(name,
Imf::Slice(Imf::HALF,
(char *)data,
sizeof(half),
sizeof(half) * width,
1, 1,
0.));
GetFile()->setFrameBuffer(fb);
Imath::Box2i dw = GetFile()->header().dataWindow();
GetFile()->readPixels(dw.min.y, dw.max.y);
// Convert to float.
vtkFloatArray *f = vtkFloatArray::New();
f->SetNumberOfTuples(width*height);
f->SetName(name.c_str());
float *dest = (float *)f->GetVoidPointer(0);
// Flip
for(int j = 0; j < height; ++j)
{
half *src = data + (height-j-1)*width; // flip
for(int i = 0; i < width; ++i)
*dest++ = float(*src++);
}
delete [] data;
retval = f;
}
else if(channel->type == Imf::FLOAT)
{
debug5 << "Reading float data for " << name << endl;
float *data = new float[width*height];
fb.insert(name,
Imf::Slice(Imf::FLOAT,
(char *)data,
sizeof(float),
sizeof(float) * width,
1, 1,
0.));
GetFile()->setFrameBuffer(fb);
Imath::Box2i dw = GetFile()->header().dataWindow();
GetFile()->readPixels(dw.min.y, dw.max.y);
// Flip
vtkFloatArray *f = vtkFloatArray::New();
f->SetNumberOfTuples(width*height);
f->SetName(name.c_str());
float *dest = (float *)f->GetVoidPointer(0);
for(int j = 0; j < height; ++j)
{
float *src = data + (height-j-1)*width; // flip
memcpy(dest, src, sizeof(float)*width);
dest += width;
}
delete [] data;
retval = f;
}
else
{
debug5 << "Unsupported data type." << endl;
}
}
}
return retval;
}
private:
Imf::InputFile *file;
std::string filename;
};
// ****************************************************************************
// Method: avtOpenEXRFileFormat constructor
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 17:24:29 PST 2017
//
// ****************************************************************************
avtOpenEXRFileFormat::avtOpenEXRFileFormat(const char *filename)
: avtSTSDFileFormat(filename)
{
d = new Internal;
d->SetFileName(filename);
}
avtOpenEXRFileFormat::~avtOpenEXRFileFormat()
{
delete d;
}
// ****************************************************************************
// Method: avtOpenEXRFileFormat::FreeUpResources
//
// Purpose:
// When VisIt is done focusing on a particular timestep, it asks that
// timestep to free up any resources (memory, file descriptors) that
// it has associated with it. This method is the mechanism for doing
// that.
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 17:24:29 PST 2017
//
// ****************************************************************************
void
avtOpenEXRFileFormat::FreeUpResources(void)
{
d->FreeResources();
}
// ****************************************************************************
// Method: avtOpenEXRFileFormat::PopulateDatabaseMetaData
//
// Purpose:
// This database meta-data object is like a table of contents for the
// file. By populating it, you are telling the rest of VisIt what
// information it can request from you.
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 17:24:29 PST 2017
//
// ****************************************************************************
void
avtOpenEXRFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
std::string meshname = "mesh";
avtMeshType mt = AVT_RECTILINEAR_MESH;
int nblocks = 1;
int block_origin = 0;
int spatial_dimension = 2;
int topological_dimension = 2;
double *extents = NULL;
AddMeshToMetaData(md, meshname, mt, extents, nblocks, block_origin,
spatial_dimension, topological_dimension);
std::vector<std::string> names;
d->GetChannelNames(names);
for(size_t i = 0; i < names.size(); ++i)
AddScalarVarToMetaData(md, names[i], "mesh", AVT_NODECENT);
}
// ****************************************************************************
// Method: avtOpenEXRFileFormat::GetMesh
//
// Purpose:
// Gets the mesh associated with this file. The mesh is returned as a
// derived type of vtkDataSet (ie vtkRectilinearGrid, vtkStructuredGrid,
// vtkUnstructuredGrid, etc).
//
// Arguments:
// meshname The name of the mesh of interest. This can be ignored if
// there is only one mesh.
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 17:24:29 PST 2017
//
// ****************************************************************************
vtkDataSet *
avtOpenEXRFileFormat::GetMesh(const char *meshname)
{
int ndims = 2;
int dims[3] = {1,1,1};
vtkFloatArray *coords[3] = {0,0,0};
if(d->GetFile() == NULL)
return NULL;
d->GetSize(dims[0], dims[1]);
coords[0] = vtkFloatArray::New();
coords[0]->SetNumberOfTuples(dims[0]);
float *xarray = (float *)coords[0]->GetVoidPointer(0);
for(int i = 0; i < dims[0]; ++i)
xarray[i] = i;
coords[1] = vtkFloatArray::New();
coords[1]->SetNumberOfTuples(dims[1]);
float *yarray = (float *)coords[1]->GetVoidPointer(0);
for(int i = 0; i < dims[1]; ++i)
yarray[i] = i;
coords[2] = vtkFloatArray::New();
coords[2]->SetNumberOfTuples(1);
coords[2]->SetComponent(0, 0, 0.);
//
// Create the vtkRectilinearGrid object and set its dimensions
// and coordinates.
//
vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
rgrid->SetDimensions(dims);
rgrid->SetXCoordinates(coords[0]);
coords[0]->Delete();
rgrid->SetYCoordinates(coords[1]);
coords[1]->Delete();
rgrid->SetZCoordinates(coords[2]);
coords[2]->Delete();
return rgrid;
}
// ****************************************************************************
// Method: avtOpenEXRFileFormat::GetVar
//
// Purpose:
// Gets a scalar variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// varname The name of the variable requested.
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 17:24:29 PST 2017
//
// ****************************************************************************
vtkDataArray *
avtOpenEXRFileFormat::GetVar(const char *varname)
{
return d->ReadChannel(varname);
}
// ****************************************************************************
// Method: avtOpenEXRFileFormat::GetVectorVar
//
// Purpose:
// Gets a vector variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// varname The name of the variable requested.
//
// Programmer: Brad Whitlock
// Creation: Wed Sep 27 17:24:29 PST 2017
//
// ****************************************************************************
vtkDataArray *
avtOpenEXRFileFormat::GetVectorVar(const char *varname)
{
return GetVar(varname);
}
|
1b550960942be8cd5068251cb61185c700c6f154
|
a2440dbe95b034784aa940ddc0ee0faae7869e76
|
/modules/lwjgl/opengl/src/generated/c/org_lwjgl_opengl_ARBSparseTexture.c
|
07498c5f070e7505509f78939bc2ae908b0ec32b
|
[
"LicenseRef-scancode-khronos",
"LGPL-2.0-or-later",
"BSD-3-Clause",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
LWJGL/lwjgl3
|
8972338303520c5880d4a705ddeef60472a3d8e5
|
67b64ad33bdeece7c09b0f533effffb278c3ecf7
|
refs/heads/master
| 2023-08-26T16:21:38.090410
| 2023-08-26T16:05:52
| 2023-08-26T16:05:52
| 7,296,244
| 4,835
| 1,004
|
BSD-3-Clause
| 2023-09-10T12:03:24
| 2012-12-23T15:40:04
|
Java
|
UTF-8
|
C
| false
| false
| 1,403
|
c
|
org_lwjgl_opengl_ARBSparseTexture.c
|
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include "opengl.h"
typedef void (APIENTRY *glTexPageCommitmentARBPROC) (jint, jint, jint, jint, jint, jint, jint, jint, jboolean);
typedef void (APIENTRY *glTexturePageCommitmentEXTPROC) (jint, jint, jint, jint, jint, jint, jint, jint, jboolean);
EXTERN_C_ENTER
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBSparseTexture_glTexPageCommitmentARB(JNIEnv *__env, jclass clazz, jint target, jint level, jint xoffset, jint yoffset, jint zoffset, jint width, jint height, jint depth, jboolean commit) {
glTexPageCommitmentARBPROC glTexPageCommitmentARB = (glTexPageCommitmentARBPROC)tlsGetFunction(1364);
UNUSED_PARAM(clazz)
glTexPageCommitmentARB(target, level, xoffset, yoffset, zoffset, width, height, depth, commit);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBSparseTexture_glTexturePageCommitmentEXT(JNIEnv *__env, jclass clazz, jint texture, jint level, jint xoffset, jint yoffset, jint zoffset, jint width, jint height, jint depth, jboolean commit) {
glTexturePageCommitmentEXTPROC glTexturePageCommitmentEXT = (glTexturePageCommitmentEXTPROC)tlsGetFunction(1365);
UNUSED_PARAM(clazz)
glTexturePageCommitmentEXT(texture, level, xoffset, yoffset, zoffset, width, height, depth, commit);
}
EXTERN_C_EXIT
|
25a97b7c500d7dce1aa74a6261733f376ed41bc3
|
e1d9c54e9925e30e388a255b53a93cccad0b94cb
|
/kubernetes/unit-test/test_v1_container_image.c
|
a5832498db2256fb7957bc4c6904bd4a28c01928
|
[
"Apache-2.0",
"curl"
] |
permissive
|
kubernetes-client/c
|
dd4fd8095485c083e0f40f2b48159b1609a6141b
|
5ac5ff25e9809a92a48111b1f77574b6d040b711
|
refs/heads/master
| 2023-08-13T10:51:03.702497
| 2023-08-07T19:18:32
| 2023-08-07T19:18:32
| 247,958,425
| 127
| 47
|
Apache-2.0
| 2023-09-07T20:07:00
| 2020-03-17T11:59:05
|
C
|
UTF-8
|
C
| false
| false
| 1,668
|
c
|
test_v1_container_image.c
|
#ifndef v1_container_image_TEST
#define v1_container_image_TEST
// the following is to include only the main from the first c file
#ifndef TEST_MAIN
#define TEST_MAIN
#define v1_container_image_MAIN
#endif // TEST_MAIN
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "../external/cJSON.h"
#include "../model/v1_container_image.h"
v1_container_image_t* instantiate_v1_container_image(int include_optional);
v1_container_image_t* instantiate_v1_container_image(int include_optional) {
v1_container_image_t* v1_container_image = NULL;
if (include_optional) {
v1_container_image = v1_container_image_create(
list_createList(),
56
);
} else {
v1_container_image = v1_container_image_create(
list_createList(),
56
);
}
return v1_container_image;
}
#ifdef v1_container_image_MAIN
void test_v1_container_image(int include_optional) {
v1_container_image_t* v1_container_image_1 = instantiate_v1_container_image(include_optional);
cJSON* jsonv1_container_image_1 = v1_container_image_convertToJSON(v1_container_image_1);
printf("v1_container_image :\n%s\n", cJSON_Print(jsonv1_container_image_1));
v1_container_image_t* v1_container_image_2 = v1_container_image_parseFromJSON(jsonv1_container_image_1);
cJSON* jsonv1_container_image_2 = v1_container_image_convertToJSON(v1_container_image_2);
printf("repeating v1_container_image:\n%s\n", cJSON_Print(jsonv1_container_image_2));
}
int main() {
test_v1_container_image(1);
test_v1_container_image(0);
printf("Hello world \n");
return 0;
}
#endif // v1_container_image_MAIN
#endif // v1_container_image_TEST
|
029cfa3bacf82c1cb15737dc416bb3251b4ecabe
|
a0c3679eda79919ebe06f490b799353081b2d233
|
/src/llist_ts.h
|
a4b6184637821c65eda250b0fb44f930190b6613
|
[
"BSD-2-Clause"
] |
permissive
|
lfos/calcurse
|
91309ac2e1cc30b83c24199d5e0242348b489b97
|
95bb55f68b446e4461f27ef3a74a7d2eda950289
|
refs/heads/pu
| 2023-08-22T11:19:07.177361
| 2023-06-03T17:30:37
| 2023-06-03T17:31:59
| 13,078,961
| 970
| 156
|
BSD-2-Clause
| 2023-08-12T15:33:48
| 2013-09-24T23:06:30
|
C
|
UTF-8
|
C
| false
| false
| 4,347
|
h
|
llist_ts.h
|
/*
* Calcurse - text-based organizer
*
* Copyright (c) 2004-2023 calcurse Development Team <misc@calcurse.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Send your feedback or comments to : misc@calcurse.org
* Calcurse home page : http://calcurse.org
*
*/
/* Thread-safe linked lists. */
typedef struct llist_ts llist_ts_t;
struct llist_ts {
llist_item_t *head;
llist_item_t *tail;
pthread_mutex_t mutex;
};
/* Initialization and deallocation. */
#define LLIST_TS_INIT(l_ts) do { \
llist_init ((llist_t *)l_ts); \
pthread_mutex_init (&(l_ts)->mutex, NULL); \
} while (0)
#define LLIST_TS_FREE(l_ts) do { \
llist_free ((llist_t *)l_ts); \
pthread_mutex_destroy (&(l_ts)->mutex); \
} while (0)
#define LLIST_TS_FREE_INNER(l_ts, fn_free) \
llist_free_inner ((llist_t *)l_ts, (llist_fn_free_t)fn_free)
/* Thread-safety operations. */
#define LLIST_TS_LOCK(l_ts) pthread_mutex_lock (&(l_ts)->mutex)
#define LLIST_TS_UNLOCK(l_ts) pthread_mutex_unlock (&(l_ts)->mutex)
/* Retrieving list items. */
#define LLIST_TS_FIRST(l_ts) llist_first ((llist_t *)l_ts)
#define LLIST_TS_NTH(l_ts, n) llist_nth ((llist_t *)l_ts, n)
#define LLIST_TS_NEXT(i) llist_next (i)
#define LLIST_TS_NEXT_FILTER(i, data, fn_match) \
llist_next_filter (i, data, (llist_fn_match_t)fn_match)
#define LLIST_TS_FIND_FIRST(l_ts, data, fn_match) \
llist_find_first ((llist_t *)l_ts, data, (llist_fn_match_t)fn_match)
#define LLIST_TS_FIND_NEXT(i, data, fn_match) \
llist_find_next (i, data, (llist_fn_match_t)fn_match)
#define LLIST_TS_FIND_NTH(l_ts, n, data, fn_match) \
llist_find_nth ((llist_t *)l_ts, n, data, (llist_fn_match_t)fn_match)
#define LLIST_TS_FOREACH(l_ts, i) \
for (i = LLIST_TS_FIRST (l_ts); i; i = LLIST_TS_NEXT (i))
#define LLIST_TS_FIND_FOREACH(l_ts, data, fn_match, i) \
for (i = LLIST_TS_FIND_FIRST (l_ts, data, fn_match); i; \
i = LLIST_TS_FIND_NEXT (i, data, fn_match))
#define LLIST_TS_FIND_FOREACH_CONT(l_ts, data, fn_match, i) \
for (i = LLIST_TS_FIND_FIRST (l_ts, data, fn_match); i; \
i = LLIST_TS_NEXT_FILTER (i, data, fn_match))
/* Accessing list item data. */
#define LLIST_TS_GET_DATA(i) llist_get_data (i)
/* List manipulation. */
#define LLIST_TS_ADD(l_ts, data) llist_add ((llist_t *)l_ts, data)
#define LLIST_TS_REMOVE(l_ts, i) llist_remove ((llist_t *)l_ts, i)
#define LLIST_TS_ADD_SORTED(l_ts, data, fn_cmp) \
llist_add_sorted ((llist_t *)l_ts, data, (llist_fn_cmp_t)fn_cmp)
#define LLIST_TS_REORDER(l_ts, data, fn_cmp) \
llist_reorder((llist_t *)l_ts, data, (llist_fn_cmp_t)fn_cmp)
|
ae3751fc46dd9aa79075fa528905b198849bbeac
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/drivers/wireless/ieee80211/bcm43xxx/cyw_reg_def.h
|
d309a1bf7a98108d0c04056287dec3f03aee9ff2
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 7,336
|
h
|
cyw_reg_def.h
|
/****************************************************************************
* drivers/wireless/ieee80211/bcm43xxx/cyw_reg_def.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_WIRELESS_CYW43439_CYW_REG_DEF_H
#define __DRIVERS_WIRELESS_CYW43439_CYW_REG_DEF_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spi/spi.h>
#include <nuttx/irq.h>
#include <stdint.h>
#include <stdbool.h>
#include "bcmf_sdio_regs.h"
/****************************************************************************
* Pre-Processor Declarations
****************************************************************************/
/* --- gSPI Registers --- */
#define CYW_REG_SETUP (0x0000) /* 32-bit register */
#define CYW_REG_INTERRUPT (0x0004) /* 16-bit register */
#define CYW_REG_INTR_ENA (0x0006) /* 16-bit register */
#define CYW_REG_STATUS (0x0008) /* 32-bit register */
#define CYW_REG_F1_INFO (0x000c) /* 16-bit register */
#define CYW_REG_F2_INFO (0x000e) /* 16-bit register */
#define CYW_REG_TEST_RO (0x0014) /* 32-bit register */
#define CYW_REG_TEST_RW (0x0018) /* 32-bit register */
#define CYW_REG_RESP_DELAY_F0 (0x001c) /* 8-bit register */
#define CYW_REG_RESP_DELAY_F1 (0x001d) /* 8-bit register */
#define CYW_REG_RESP_DELAY_F2 (0x001e) /* 8-bit register */
#define CYW_REG_RESP_DELAY_F3 (0x001f) /* 8-bit register */
/* --- Registers --- */
#define CYW_REG_SETUP_WORD_LEN_32 (1<<0)
#define CYW_REG_SETUP_BIG_ENDIAN (1<<1)
#define CYW_REG_SETUP_HIGH_SPEED (1<<4)
#define CYW_REG_SETUP_INT_POLARITY (1<<5)
#define CYW_REG_SETUP_WAKE_UP (1<<7)
#define CYW_REG_SETUP_RESP_DELAY_SHIFT (8)
#define CYW_REG_SETUP_RESP_DELAY_MASK (0x00FF << CYW_REG_SETUP_RESP_DELAY_SHIFT)
#define CYW_REG_STAT_ENA_STAT_ENA (1<<16)
#define CYW_REG_STAT_ENA_INTR_STAT (1<<17)
#define CYW_REG_INTERRUPT_DATA_NOT_AVAIL (1<<0)
#define CYW_REG_INTERRUPT_FIFO_UNDERFLOW (1<<1)
#define CYW_REG_INTERRUPT_FIFO_OVERFLOW (1<<2)
#define CYW_REG_INTERRUPT_COMMAND_ERROR (1<<3)
#define CYW_REG_INTERRUPT_DATA_ERROR (1<<4)
#define CYW_REG_INTERRUPT_F2_PKT_AVAIL (1<<5)
#define CYW_REG_INTERRUPT_F3_PKT_AVAIL (1<<6)
#define CYW_REG_INTERRUPT_F1_OVERFLOW (1<<7)
#define CYW_REG_INTERRUPT_F1_INTERRUPT (1<<13)
#define CYW_REG_INTERRUPT_F2_INTERRUPT (1<<14)
#define CYW_REG_INTERRUPT_F3_INTERRUPT (1<<15)
#define CYW_REG_INTR_ENA_DATA_NOT_AVAIL (1<<0)
#define CYW_REG_INTR_ENA_FIFO_UNDERFLOW (1<<1)
#define CYW_REG_INTR_ENA_FIFO_OVERFLOW (1<<2)
#define CYW_REG_INTR_ENA_COMMAND_ERROR (1<<3)
#define CYW_REG_INTR_ENA_DATA_ERROR (1<<4)
#define CYW_REG_INTR_ENA_F2_PKT_AVAIL (1<<5)
#define CYW_REG_INTR_ENA_F3_PKT_AVAIL (1<<6)
#define CYW_REG_INTR_ENA_F1_OVERFLOW (1<<7)
#define CYW_REG_INTR_ENA_F1_INTERRUPT (1<<13)
#define CYW_REG_INTR_ENA_F2_INTERRUPT (1<<14)
#define CYW_REG_INTR_ENA_F3_INTERRUPT (1<<15)
#define CYW_REG_STATUS_DATA_NOT_AVAIL (1<<0)
#define CYW_REG_STATUS_FIFO_UNDERFLOW (1<<1)
#define CYW_REG_STATUS_FIFO_OVERFLOW (1<<2)
#define CYW_REG_STATUS_F2_INTERRUPT (1<<3)
#define CYW_REG_STATUS_F3_INTERRUPT (1<<4)
#define CYW_REG_STATUS_F2_RECEIVE_RDY (1<<5)
#define CYW_REG_STATUS_F3_RECEIVE_RDY (1<<6)
#define CYW_REG_STATUS_CMD_DATA_ERROR (1<<7)
#define CYW_REG_STATUS_F2_PKT_AVAIL (1<<8)
#define CYW_REG_STATUS_F2_PKT_LEN_SHIFT (9)
#define CYW_REG_STATUS_F2_PKT_LEN_MASK (0x7FF << CYW_REG_STATUS_F2_PKT_LEN_SHIFT)
#define CYW_REG_STATUS_F3_PKT_AVAIL (1<<20)
#define CYW_REG_STATUS_F3_PKT_LEN_SHIFT (21)
#define CYW_REG_STATUS_F3_PKT_LEN_MASK (0x7FF << CYW_REG_STATUS_F3_PKT_LEN_SHIFT)
#define CYW_REG_F1_INFO_ENABLED (1<<0)
#define CYW_REG_F1_INFO_READY (1<<1)
#define CYW_REG_F1_INFO_MAX_SIZE_SHIFT (2)
#define CYW_REG_F1_INFO_MAX_SIZE_MASK (0x0FFF << CYW_REG_F1_INFO_MAX_SIZE_SHIFT)
#define CYW_REG_F2_INFO_ENABLED (1<<0)
#define CYW_REG_F2_INFO_READY (1<<1)
#define CYW_REG_F2_INFO_MAX_SIZE_SHIFT (2)
#define CYW_REG_F2_INFO_MAX_SIZE_MASK (0x0FFF << CYW_REG_F2_INFO_MAX_SIZE_SHIFT)
#define CYW_REG_RESP_DELAY_F0_SHIFT (0)
#define CYW_REG_RESP_DELAY_F0_MASK (0x00FF << CYW_REG_RESP_DELAY_F0_SHIFT)
#define CYW_REG_RESP_DELAY_F1_SHIFT (8)
#define CYW_REG_RESP_DELAY_F1_MASK (0x00FF << CYW_REG_RESP_DELAY_F1_SHIFT)
#define CYW_REG_RESP_DELAY_F2_SHIFT (16)
#define CYW_REG_RESP_DELAY_F2_MASK (0x00FF << CYW_REG_RESP_DELAY_F2_SHIFT)
#define CYW_REG_RESP_DELAY_F3_SHIFT (24)
#define CYW_REG_RESP_DELAY_F3_MASK (0x00FF << CYW_REG_RESP_DELAY_F3_SHIFT)
#define CYW_REG_TEST_RO_PATTERN (0xfeedbead)
#define CYW_STATUS_DATA_NOT_AVAIL (1<<0) /* data not avail on read */
#define CYW_STATUS_FIFO_UNDERFLOW (1<<1) /* read underflow (F2, F3) */
#define CYW_STATUS_FIFO_OVERFLOW (1<<2) /* write overflow (F1, F2, F3) */
#define CYW_STATUS_F2_INTERRUPT (1<<3) /* F2 channel interrupt */
#define CYW_STATUS_F3_INTERRUPT (1<<4)
#define CYW_STATUS_F2_RECEIVE_RDY (1<<5) /* F2 ready to receive data */
#define CYW_STATUS_F3_RECEIVE_RDY (1<<6)
#define CYW_STATUS_CMD_DATA_ERROR (1<<7)
#define CYW_STATUS_F2_PKT_AVAIL (1<<8) /* F2 has data to read */
#define CYW_STATUS_F2_PKT_LEN_SHIFT (9) /* Length of avail F2 data */
#define CYW_STATUS_F2_PKT_LEN_MASK (0x7FF << CYW_REG_STATUS_F2_PKT_LEN_SHIFT)
#define CYW_STATUS_F3_PKT_AVAIL (1<<20)
#define CYW_STATUS_F3_PKT_LEN_SHIFT (21)
#define CYW_STATUS_F3_PKT_LEN_MASK (0x7FF << CYW_REG_STATUS_F3_PKT_LEN_SHIFT)
/****************************************************************************
* Public Data Types
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
# define EXTERN extern "C"
extern "C"
{
#else
# define EXTERN extern
#endif
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __DRIVERS_WIRELESS_CYW43439_CYW_REG_DEF_H */
|
b528eaf8e768f6ae351c6597efdb36803e38cdf6
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/databases/VTK/avtVTKFileReader.C
|
d4b1653e028239e0b3aae79a57005f089878229d
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 69,843
|
c
|
avtVTKFileReader.C
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
// ************************************************************************* //
// avtVTKFileReader.C //
// ************************************************************************* //
#include <limits.h> // for INT_MAX
#include <float.h> // for DBL_MAX
#include <avtDatabaseMetaData.h>
#include <Expression.h>
#include <avtGhostData.h>
#include <avtMaterial.h>
#include <avtVTKFileReader.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkDataSetReader.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkRectilinearGrid.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkStringArray.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredPoints.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLImageDataReader.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLRectilinearGridReader.h>
#include <vtkXMLStructuredGridReader.h>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkVisItXMLPDataReader.h>
#include <PVTKParser.h>
#include <VTMParser.h>
#include <DebugStream.h>
#include <Expression.h>
#include <InvalidVariableException.h>
#include <InvalidFilesException.h>
#include <StringHelpers.h>
#include <vtkVisItUtility.h>
#include <map>
#include <string>
#include <vector>
#ifdef _WIN32
#define strcasecmp stricmp
#endif
using std::array;
using std::string;
using std::vector;
//
// Define the static const's
//
const char *avtVTKFileReader::MESHNAME="mesh";
const char *avtVTKFileReader::VARNAME="VTKVar";
static void GetListOfUniqueCellTypes(vtkUnstructuredGrid *ug,
vtkUnsignedCharArray *uca);
int avtVTKFileReader::INVALID_CYCLE = -INT_MAX;
double avtVTKFileReader::INVALID_TIME = -DBL_MAX;
// ****************************************************************************
// Method: avtVTKFileReader constructor
//
// Arguments:
// fname The file name.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Hank Childs, Tue May 24 12:05:52 PDT 2005
// Added arguments.
//
// Mark C. Miller, Thu Sep 15 19:45:51 PDT 2005
// Initialized matvarname
//
// Kathleen Bonnell, Thu Sep 22 15:37:13 PDT 2005
// Save the file extension.
//
// Kathleen Bonnell, Thu Jun 29 17:30:40 PDT 2006
// Add vtk_time, to store time from the VTK file if it is available.
//
// Hank Childs, Mon Jun 11 21:27:04 PDT 2007
// Do not assume there is an extension.
//
// Kathleen Bonnell, Wed Jul 9 17:48:21 PDT 2008
// Add vtk_cycle, to store cycle from the VTK file if it is available.
//
// Brad Whitlock, Tue May 11 11:13:29 PDT 2010
// Search for file extension from the back of the filename in case
// directories contain "." and terminate if we hit a path separator.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Eric Brugger, Tue Jul 9 09:36:44 PDT 2013
// I modified the reading of pvti, pvtr and pvts files to handle the case
// where the piece extent was a subset of the whole extent.
//
// Kathleen Biagas, Thu Aug 13 17:29:21 PDT 2015
// Add support for groups and block names.
//
// Kathleen Biagas, Fri Aug 13 2021
// pieceFileNames now a vector<string>.
// pieceExtents now vector<array<int,6>>.
//
// ****************************************************************************
avtVTKFileReader::avtVTKFileReader(const char *fname, const DBOptionsAttributes *) :
vtk_meshname()
{
filename = new char[strlen(fname)+1];
strcpy(filename, fname);
nblocks = 1;
pieceDatasets = NULL;
readInDataset = false;
matvarname = NULL;
// find the file extension
int i, start = -1;
int len = int(strlen(fname));
for(i = len-1; i >= 0; i--)
{
if(fname[i] == '.')
{
start = i;
break;
}
else if(fname[i] == '/' || fname[i] == '\\')
{
// We hit a path separator. There is no file extension.
start = -1;
break;
}
}
if (start != -1)
fileExtension = string(fname, start+1, len-1);
else
fileExtension = "none";
vtk_time = INVALID_TIME;
vtk_cycle = INVALID_CYCLE;
}
// ****************************************************************************
// Method: avtVTKFileReader::FreeUpResources
//
// Purpose:
// Frees up resources. Since this module does not keep an open file, that
// only means deleting the dataset. Since this is all reference counted,
// there is no worry that we will be deleting something that is being
// used.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Mark C. Miller, Thu Sep 15 19:45:51 PDT 2005
// Freed matvarname
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Mark C. Miller, Wed Jul 2 17:27:35 PDT 2014
// Delete everything even VTK datasets read.
//
// Kathleen Biagas, Fri Aug 13 2021
// pieceFileNames now a vector<string>.
// pieceExtents now vector<array<int,6>>.
//
// ****************************************************************************
void
avtVTKFileReader::FreeUpResources(void)
{
debug4 << "VTK file " << filename << " forced to free up resources." << endl;
if (matvarname != NULL)
{
free(matvarname);
matvarname = NULL;
}
pieceFileNames.clear();
if (pieceDatasets != NULL)
{
for (int i = 0; i < nblocks; i++)
{
if (pieceDatasets[i] != NULL)
pieceDatasets[i]->Delete();
}
delete [] pieceDatasets;
pieceDatasets = 0;
}
pieceExtents.clear();
for(std::map<string, vtkRectilinearGrid *>::iterator pos = vtkCurves.begin();
pos != vtkCurves.end(); ++pos)
{
pos->second->Delete();
}
vtkCurves.clear();
readInDataset = false;
}
// ****************************************************************************
// Method: avtVTKFileReader destructor
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Mark C. Miller, Thu Sep 15 19:45:51 PDT 2005
// Freed matvarname
//
// Brad Whitlock, Wed Oct 26 11:03:14 PDT 2011
// Delete curves in vtkCurves.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Eric Brugger, Tue Jul 9 09:36:44 PDT 2013
// I modified the reading of pvti, pvtr and pvts files to handle the case
// where the piece extent was a subset of the whole extent.
//
// Burlen Loring, Fri Jul 11 11:19:36 PDT 2014
// fix alloc-dealloc-mismatch (operator new [] vs free)
//
// ****************************************************************************
avtVTKFileReader::~avtVTKFileReader()
{
FreeUpResources();
delete [] filename;
}
// ****************************************************************************
// Method: avtVTKFileReader::GetNumberOfDomains
//
// Purpose:
// Return the number of domains, reading the data file to figure it out.
//
// Returns: The number of domains.
//
// Programmer: Brad Whitlock
// Creation: Mon Oct 22 17:08:06 PDT 2012
//
// Modifications:
//
// ****************************************************************************
int
avtVTKFileReader::GetNumberOfDomains()
{
if (!readInDataset)
{
ReadInFile();
}
return nblocks;
}
// ****************************************************************************
// Method: avtVTKFileReader::ReadInFile
//
// Purpose:
// Reads in the file.
//
// Programmer: Eric Brugger
// Creation: June 18, 2012
//
// Modifications:
// Eric Brugger, Tue Jul 9 09:36:44 PDT 2013
// I modified the reading of pvti, pvtr and pvts files to handle the case
// where the piece extent was a subset of the whole extent.
//
// Kathleen Biagas, Thu Aug 13 17:29:21 PDT 2015
// Add support for groups and block names, as read from 'vtm' file.
//
// Kathleen Biagas, Thu Sep 21 14:59:31 MST 2017
// Add support for pvtk files.
//
// Kathleen Biagas, Fri Aug 13 2021
// pieceFileNames now a vector<string>. Combine 2 for-blocks into 1.
// pieceExtents now vector<array<int,6>>.
//
// ****************************************************************************
void
avtVTKFileReader::ReadInFile(int _domain)
{
int domain = _domain == -1 ? 0 : _domain;
if (fileExtension == "pvtu" || fileExtension == "pvts" ||
fileExtension == "pvtr" || fileExtension == "pvti" ||
fileExtension == "pvtp")
{
vtkVisItXMLPDataReader *xmlpReader = vtkVisItXMLPDataReader::New();
xmlpReader->SetFileName(filename);
xmlpReader->ReadXMLInformation();
ngroups = 1;
nblocks = xmlpReader->GetNumberOfPieces();
pieceFileNames.resize(nblocks);
pieceExtents.resize(nblocks);
for (int i = 0; i < nblocks; i++)
{
pieceFileNames[i] = xmlpReader->GetPieceFileName(i);
int *ext = xmlpReader->GetExtent(i);
if (ext != NULL)
{
array<int, 6> pe = {ext[0], ext[1], ext[2], ext[3], ext[4], ext[5]};
pieceExtents[i] = pe;
}
}
xmlpReader->Delete();
pieceExtension = fileExtension.substr(1,3);
}
else if (fileExtension == "pvtk")
{
PVTKParser *parser = new PVTKParser();
parser->SetFileName(filename);
if (!parser->Parse())
{
string em = parser->GetErrorMessage();
delete parser;
EXCEPTION2(InvalidFilesException, filename, em);
}
ngroups = 1;
nblocks = int(parser->GetNumberOfPieces());
pieceFileNames.resize(nblocks);
for (int i = 0; i < nblocks; i++)
{
pieceFileNames[i] = parser->GetPieceFileName(i);
}
if (parser->HasExtents())
{
pieceExtents.resize(nblocks);
for (int i = 0; i < nblocks; i++)
{
vector< int > &readerExtent = parser->GetPieceExtent(i);
array<int,6> pe;
std::copy_n(readerExtent.begin(), 6, pe.begin());
pieceExtents[i] = pe;
}
}
delete parser;
pieceExtension = "vtk";
}
else if (fileExtension == "vtm")
{
VTMParser *parser = new VTMParser;
parser->SetFileName(filename);
if (!parser->Parse())
{
string em = parser->GetErrorMessage();
delete parser;
EXCEPTION2(InvalidFilesException, filename, em);
return;
}
nblocks = parser->GetNumberOfBlocks();
ngroups = parser->GetNumberOfGroups();
if (ngroups > 1)
{
groupNames = parser->GetGroupNames();
groupPieceName = parser->GetGroupPieceName();
groupIds = parser->GetGroupIds();
}
blockNames = parser->GetBlockNames();
blockPieceName = parser->GetBlockPieceName();
pieceFileNames.resize(nblocks);
for (int i = 0; i < nblocks; i++)
{
pieceFileNames[i] = parser->GetBlockFileName(i);
}
pieceExtension = parser->GetBlockExtension();
delete parser;
}
else
{
nblocks = 1;
ngroups = 1;
pieceFileNames.resize(1);
pieceFileNames[0] = filename;
pieceExtension = fileExtension;
}
pieceDatasets = new vtkDataSet*[nblocks];
for (int i = 0; i < nblocks; i++)
pieceDatasets[i] = NULL;
ReadInDataset(domain);
readInDataset = true;
}
// ****************************************************************************
// Method: avtVTKFileReader::ReadInDataset
//
// Purpose:
// Reads in the dataset.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Kathleen Bonnell, Thu Feb 12 15:52:01 PST 2004
// Use VisIt's version of the reader, so that all variables can be read
// into the dataset in one pass.
//
// Kathleen Bonnell, Thu Mar 11 12:53:12 PST 2004
// Convert StructuredPoints datasets into RectilinearGrids.
//
// Kathleen Bonnell, Thu Sep 22 15:37:13 PDT 2005
// Support vtk xml file formats.
//
// Kathleen Bonnell, Wed May 17 14:03:29 PDT 2006
// Remove call to SetSource(NULL), as it now removes information necessary
// to the dataset.
//
// Kathleen Bonnell, Thu Jun 29 17:30:40 PDT 2006
// Retrieve TIME from FieldData if available.
//
// Hank Childs, Mon Jun 11 21:27:04 PDT 2007
// Add support for files with no extensions.
//
// Kathleen Bonnell, Fri Feb 29 09:02:44 PST 2008
// Support VTK_IMAGE_DATA (returned from vtkXMLImageDataReader), convert it
// to rectilinear, as we do with StructuredPoints data.
//
// Sean Ahern, Mon Mar 24 17:19:56 EDT 2008
// Added better error checking to detect badly formatted VTK files.
//
// Kathleen Bonnell, Wed Jul 9 18:13:20 PDT 2008
// Retrieve CYCLE from FieldData if available.
//
// Brad Whitlock, Wed Oct 26 11:04:50 PDT 2011
// Create curves for 1D rectilinear grids.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Kathleen Biagas, Mon Jan 28 11:06:32 PST 2013
// Remove calls to ds->Update.
//
// Eric Brugger, Tue Jul 9 09:36:44 PDT 2013
// I modified the reading of pvti, pvtr and pvts files to handle the case
// where the piece extent was a subset of the whole extent.
//
// Mark C. Miller, Wed Jul 2 17:28:24 PDT 2014
// Add duplicate node removal (special case). Controlling logic should
// ensure it is rarely triggered.
//
// Kathleen Biagas, Mon Dec 22 09:49:22 PST 2014
// Moved logic for duplicate node removal into avtTransformManager, it
// is now controlled by setting a global preference.
//
// Kathleen Biagas, Fri Feb 6 06:00:16 PST 2015
// Added ability for parsing 'MeshName' field data from vtk file.
//
// Matt Larsen, Fri Mar 2 09:00:15 PST 2018
// Getting image data extents correctly from vti files
//
// Edward Rusu, Mon Oct 1 09:24:24 PST 2018
// Added support for vtkGhostType.
//
// Mark C. Miller, Mon Mar 9 19:53:06 PDT 2020
// Add logic to support VisIt expressions as vtkStringArrays
//
// Kathleen Biagas, Fri Aug 13 2021
// Change debug message to correctly identify actual file being read in.
// pieceFileNames now a vector<string>.
// pieceExtents now vector<array<int,6>>.
//
// ****************************************************************************
void
avtVTKFileReader::ReadInDataset(int domain)
{
debug4 << "Reading in dataset from VTK file ";
if (!pieceFileNames.empty())
debug4 << pieceFileNames[domain];
else
debug4 << filename;
debug4 << " (domain = " << domain << ") " << endl;
//
// This shouldn't ever happen (since we would already have the dataset
// we are trying to read from the file sitting in memory), but anything
// to prevent leaks.
//
if (pieceDatasets[domain] != NULL)
{
pieceDatasets[domain]->Delete();
pieceDatasets[domain] = NULL;
}
vtkDataSet *dataset = NULL;
if (pieceExtension == "vtk" || pieceExtension == "none")
{
if (pieceExtension == "none") {
debug1 << "No extension given ... assuming legacy VTK format."
<< endl;
}
//
// Create a file reader and set our dataset to be its output.
//
vtkDataSetReader *reader = vtkDataSetReader::New();
reader->ReadAllScalarsOn();
reader->ReadAllVectorsOn();
reader->ReadAllTensorsOn();
reader->SetFileName(pieceFileNames[domain].c_str());
reader->Update();
dataset = reader->GetOutput();
if (dataset == NULL)
{
EXCEPTION1(InvalidFilesException, pieceFileNames[domain]);
}
dataset->Register(NULL);
reader->Delete();
}
else if (pieceExtension == "vti")
{
vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
reader->SetFileName(pieceFileNames[domain].c_str());
reader->Update();
dataset = reader->GetOutput();
if (dataset == NULL)
{
EXCEPTION1(InvalidFilesException, pieceFileNames[domain]);
}
dataset->Register(NULL);
reader->Delete();
}
else if (pieceExtension == "vtr")
{
vtkXMLRectilinearGridReader *reader =
vtkXMLRectilinearGridReader::New();
reader->SetFileName(pieceFileNames[domain].c_str());
reader->Update();
dataset = reader->GetOutput();
if (dataset == NULL)
{
EXCEPTION1(InvalidFilesException, pieceFileNames[domain]);
}
dataset->Register(NULL);
reader->Delete();
}
else if (pieceExtension == "vts")
{
vtkXMLStructuredGridReader *reader =
vtkXMLStructuredGridReader::New();
reader->SetFileName(pieceFileNames[domain].c_str());
reader->Update();
dataset = reader->GetOutput();
if (dataset == NULL)
{
EXCEPTION1(InvalidFilesException, pieceFileNames[domain]);
}
dataset->Register(NULL);
reader->Delete();
}
else if (pieceExtension == "vtp")
{
vtkXMLPolyDataReader *reader = vtkXMLPolyDataReader::New();
reader->SetFileName(pieceFileNames[domain].c_str());
reader->Update();
dataset = reader->GetOutput();
if (dataset == NULL)
{
EXCEPTION1(InvalidFilesException, pieceFileNames[domain]);
}
dataset->Register(NULL);
reader->Delete();
}
else if (pieceExtension == "vtu")
{
vtkXMLUnstructuredGridReader *reader =
vtkXMLUnstructuredGridReader::New();
reader->SetFileName(pieceFileNames[domain].c_str());
reader->Update();
dataset = reader->GetOutput();
if (dataset == NULL)
{
EXCEPTION1(InvalidFilesException, pieceFileNames[domain]);
}
dataset->Register(NULL);
reader->Delete();
}
else
{
EXCEPTION2(InvalidFilesException, pieceFileNames[domain],
"could not match extension to a VTK file format type");
}
vtk_time = INVALID_TIME;
if (dataset->GetFieldData()->GetArray("TIME") != 0)
{
vtk_time = dataset->GetFieldData()->GetArray("TIME")->GetTuple1(0);
}
vtk_cycle = INVALID_CYCLE;
if (dataset->GetFieldData()->GetArray("CYCLE") != 0)
{
vtk_cycle = (int)dataset->GetFieldData()->GetArray("CYCLE")->GetTuple1(0);
}
vtk_meshname.clear();
if (dataset->GetFieldData()->GetAbstractArray("MeshName") != 0)
{
vtkStringArray *mn = vtkStringArray::SafeDownCast(
dataset->GetFieldData()->GetAbstractArray("MeshName"));
if (mn)
vtk_meshname = mn->GetValue(0);
}
vtk_exprs.ClearExpressions();
if (dataset->GetFieldData()->GetAbstractArray("VisItExpressions") != 0)
{
vtkStringArray *ve = vtkStringArray::SafeDownCast(
dataset->GetFieldData()->GetAbstractArray("VisItExpressions"));
for (int i = 0; i < ve->GetNumberOfTuples(); i++)
{
std::vector<std::string> expr_substrs = StringHelpers::split(ve->GetValue(i),';');
Expression::ExprType vtype = Expression::Unknown;
if (expr_substrs.size() != 3)
{
debug2 << "Ignoring invalid VisItExpression entry at index " << i << endl;
continue;
}
if (!strcasecmp(expr_substrs[1].c_str(),"curve"))
vtype = Expression::CurveMeshVar;
else if (!strcasecmp(expr_substrs[1].c_str(),"scalar"))
vtype = Expression::ScalarMeshVar;
else if (!strcasecmp(expr_substrs[1].c_str(),"vector"))
vtype = Expression::VectorMeshVar;
else if (!strcasecmp(expr_substrs[1].c_str(),"tensor"))
vtype = Expression::TensorMeshVar;
else if (!strcasecmp(expr_substrs[1].c_str(),"array"))
vtype = Expression::ArrayMeshVar;
else if (!strcasecmp(expr_substrs[1].c_str(),"material"))
vtype = Expression::Material;
else if (!strcasecmp(expr_substrs[1].c_str(),"species"))
vtype = Expression::Species;
Expression expr;
expr.SetName(expr_substrs[0]);
expr.SetType(vtype);
expr.SetDefinition(expr_substrs[2]);
vtk_exprs.AddExpressions(expr);
}
}
if (dataset->GetDataObjectType() == VTK_STRUCTURED_POINTS ||
dataset->GetDataObjectType() == VTK_IMAGE_DATA)
{
//
// The old dataset passed in will be deleted, a new one will be
// returned.
//
if((pieceExtents.empty() || pieceExtents[domain].empty()) &&
dataset->GetDataObjectType() == VTK_IMAGE_DATA)
{
vtkImageData *img = vtkImageData::SafeDownCast(dataset);
if(img)
{
int *ext = img->GetExtent();
dataset = ConvertStructuredPointsToRGrid((vtkStructuredPoints*)dataset,
ext);
}
}
else
{
dataset = ConvertStructuredPointsToRGrid((vtkStructuredPoints*)dataset,
pieceExtents[domain].data());
}
}
if(dataset->GetDataObjectType() == VTK_RECTILINEAR_GRID)
{
vtkRectilinearGrid *rgrid = vtkRectilinearGrid::SafeDownCast(dataset);
int dims[3];
rgrid->GetDimensions(dims);
if(dims[0] > 0 && dims[1] <= 1 && dims[2] <= 1)
{
// Make some curves from this dataset.
CreateCurves(rgrid);
}
}
// Convert vtkGhostType to avtGhostDataType
// Rename the arrays stored in dataset->GetCellData() and dataset->GetPointData()
vtkDataArray *zoneArray = dataset->GetCellData()->GetArray("vtkGhostType");
if (zoneArray)
{
zoneArray->SetName("avtGhostZones");
dataset->GetCellData()->AddArray(zoneArray);
}
vtkDataArray *nodeArray = dataset->GetPointData()->GetArray("vtkGhostType");
if (nodeArray)
{
nodeArray->SetName("avtGhostNodes");
dataset->GetPointData()->AddArray(nodeArray);
}
pieceDatasets[domain] = dataset;
}
// ****************************************************************************
// Method: avtVTKFileReader::CreateCurves
//
// Purpose:
// Create curve datasets based on the input rectilinear grid.
//
// Arguments:
// rgrid : The rectilinear grid from which to create curves.
//
// Returns:
//
// Note: vtkCurves gets the new datasets.
//
// Programmer: Brad Whitlock
// Creation: Wed Oct 26 11:01:44 PDT 2011
//
// Modifications:
//
// ****************************************************************************
void
avtVTKFileReader::CreateCurves(vtkRectilinearGrid *rgrid)
{
vtkDataArray *xc = rgrid->GetXCoordinates();
int nPts = xc->GetNumberOfTuples();
for(int i = 0; i < rgrid->GetPointData()->GetNumberOfArrays(); ++i)
{
vtkDataArray *arr = rgrid->GetPointData()->GetArray(i);
if(arr->GetNumberOfComponents() == 1)
{
vtkRectilinearGrid *curve = vtkVisItUtility::Create1DRGrid(nPts,VTK_FLOAT);
vtkDataArray *curve_xc = curve->GetXCoordinates();
vtkFloatArray *curve_yc = vtkFloatArray::New();
curve_yc->SetName(arr->GetName());
curve_yc->SetNumberOfTuples(nPts);
for(vtkIdType j = 0; j < nPts; ++j)
{
curve_xc->SetTuple1(j, xc->GetTuple1(j));
curve_yc->SetTuple1(j, arr->GetTuple1(j));
}
curve->GetPointData()->SetScalars(curve_yc);
curve_yc->Delete();
vtkCurves[string("curve_") + string(arr->GetName())] = curve;
}
}
for(int i = 0; i < rgrid->GetCellData()->GetNumberOfArrays(); ++i)
{
vtkDataArray *arr = rgrid->GetCellData()->GetArray(i);
if(arr->GetNumberOfComponents() == 1)
{
vtkRectilinearGrid *curve = vtkVisItUtility::Create1DRGrid(nPts,VTK_FLOAT);
vtkDataArray *curve_xc = curve->GetXCoordinates();
for(vtkIdType j = 0; j < nPts; ++j)
curve_xc->SetTuple1(j, xc->GetTuple1(j));
int nCells = nPts-1;
int idx = 0;
vtkFloatArray *curve_yc = vtkFloatArray::New();
curve_yc->SetName(arr->GetName());
curve_yc->SetNumberOfTuples(nPts);
curve_yc->SetTuple1(idx++, arr->GetTuple1(0));
for(vtkIdType j = 0; j < nCells-1; ++j)
curve_yc->SetTuple1(idx++, (arr->GetTuple1(j) + arr->GetTuple1(j+1)) / 2.);
curve_yc->SetTuple1(idx++, arr->GetTuple1(nCells-1));
curve->GetPointData()->SetScalars(curve_yc);
curve_yc->Delete();
vtkCurves[string("curve_") + string(arr->GetName())] = curve;
}
}
}
// ****************************************************************************
// Method: avtVTKFileReader::GetAuxiliaryData
//
// Programmer: Mark C. Miller
// Creation: September 15, 2005
//
// Modifications:
// Hank Childs, Fri Feb 15 11:25:32 PST 2008
// Fix memory leak.
//
// Cyrus Harrison, Fri Jan 7 10:17:19 PST 2011
// Determine the proper material variable name & material metadata
// if PopulateDatabaseMetaData has not been called. This supports materials
// in the case we multiple vtk files acting as separate timesteps.
//
// Cyrus Harrison, Wed Nov 16 13:35:54 PST 2011
// Use "MaterialIds" field data to help generate avtMaterials result object.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Kathleen Biagas, Mon Nov 20 13:04:51 PST 2017
// Pass domain to the GetVar call when retrieving materials.
//
// ****************************************************************************
void *
avtVTKFileReader::GetAuxiliaryData(const char *var, int domain,
const char *type, void *, DestructorFunction &df)
{
void *rv = NULL;
if (strcmp(type, AUXILIARY_DATA_MATERIAL) == 0)
{
vtkDataSet *dataset = NULL;
// matvarname is only inited if we call: PopulateDatabaseMetaData().
// If you have a series of vtk files using this variable will cause
// a crash any time the time slider is changed (and treat all dbs
// as time varying is off)
if(matvarname == NULL)
{
if (!readInDataset)
{
ReadInFile(domain);
}
if (pieceDatasets[domain] == NULL)
{
ReadInDataset(domain);
}
dataset = pieceDatasets[domain];
int ncellvars = dataset->GetCellData()->GetNumberOfArrays();
for(int i=0;( i < ncellvars) && (matvarname == NULL) ;i++)
{
// we are looking for either "avtSubsets" or "material"
if(strcmp(dataset->GetCellData()->GetArrayName(i), "avtSubsets") == 0)
matvarname = strdup("avtSubsets");
else if(strcmp(dataset->GetCellData()->GetArrayName(i), "material") == 0)
matvarname = strdup("material");
}
}
else
{
dataset = pieceDatasets[domain];
}
vtkIntArray *matarr = vtkIntArray::SafeDownCast(GetVar(domain, matvarname));
// again, if we haven't called PopulateDatabaseMetaData().
// this data will be bad ...
if(matnos.size() == 0)
{
vtkIntArray *iarr = NULL;
// check for field data "MaterialIds" that can directly provide us
// the proper set of material ids.
vtkDataArray *mids_arr = dataset->GetFieldData()->GetArray("MaterialIds");
if( mids_arr != NULL)
iarr = vtkIntArray::SafeDownCast(mids_arr);
else
iarr = vtkIntArray::SafeDownCast(matarr);
int *iptr = iarr->GetPointer(0);
std::map<int, bool> valMap;
int ntuples = iarr->GetNumberOfTuples();
for (int j = 0; j < ntuples; j++)
valMap[iptr[j]] = true;
std::map<int, bool>::const_iterator it;
for (it = valMap.begin(); it != valMap.end(); it++)
{
char tmpname[32];
snprintf(tmpname, sizeof(tmpname), "%d", it->first);
matnames.push_back(tmpname);
matnos.push_back(it->first);
}
}
int ntuples = matarr->GetNumberOfTuples();
int *matlist = matarr->GetPointer(0);
int *matnostmp = new int[matnos.size()];
char **matnamestmp = new char*[matnames.size()];
for (size_t i = 0; i < matnos.size(); i++)
{
matnostmp[i] = matnos[i];
matnamestmp[i] = (char*) matnames[i].c_str();
}
avtMaterial *mat = new avtMaterial((int)matnos.size(), //silomat->nmat,
matnostmp, //silomat->matnos,
matnamestmp, //silomat->matnames,
1, //silomat->ndims,
&ntuples, //silomat->dims,
0, //silomat->major_order,
matlist, //silomat->matlist,
0, //silomat->mixlen,
0, //silomat->mix_mat,
0, //silomat->mix_next,
0, //silomat->mix_zone,
0 //silomat->mix_vf
);
delete [] matnostmp;
delete [] matnamestmp;
matarr->Delete();
df = avtMaterial::Destruct;
rv = mat;
}
return rv;
}
// ****************************************************************************
// Method: avtVTKFileReader::GetMesh
//
// Purpose:
// Gets the mesh. The mesh is actually just the dataset, so return that.
//
// Arguments:
// mesh The desired meshname, this should be MESHNAME.
//
// Returns: The mesh as a VTK dataset.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Hank Childs, Tue Mar 26 13:33:43 PST 2002
// Add a reference so that reference counting tricks work.
//
// Brad Whitlock, Wed Oct 26 11:08:31 PDT 2011
// Return curves.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Kathleen Biagas, Fri Feb 6 06:06:24 PST 2015
// Use meshname from file (vtk_meshname), if available.
// Kathleen Biagas, Thu Apr 2 12:22:55 PDT 2015
// Return NULL a dataset with 0 points is read in.
//
// Kathleen Biagas, Fri Aug 13 2021
// Change debug message to correctly identify actual file being read in.
//
// ****************************************************************************
vtkDataSet *
avtVTKFileReader::GetMesh(int domain, const char *mesh)
{
debug5 << "Getting mesh from VTK file: " ;
if (!pieceFileNames.empty())
debug5 << pieceFileNames[domain];
else
debug5 << filename;
debug5 << " (domain = " << domain << ") " << endl;
if (!readInDataset)
{
ReadInFile(domain);
}
if (pieceDatasets[domain] == NULL)
{
ReadInDataset(domain);
}
vtkDataSet *dataset = pieceDatasets[domain];
if (dataset->GetNumberOfPoints() == 0)
{
return NULL;
}
// If the requested mesh is a curve, return it.
std::map<string, vtkRectilinearGrid *>::iterator pos = vtkCurves.find(mesh);
if(pos != vtkCurves.end())
{
pos->second->Register(NULL);
return pos->second;
}
if(vtk_meshname.empty())
{
if (strcmp(mesh, MESHNAME) != 0)
{
EXCEPTION1(InvalidVariableException, mesh);
}
}
else
{
if (strcmp(mesh, vtk_meshname.c_str()) != 0)
{
EXCEPTION1(InvalidVariableException, mesh);
}
}
//
// The routine that calls this method is going to assume that it can call
// Delete on what is returned. That means we better add an extra
// reference.
//
dataset->Register(NULL);
return dataset;
}
// ****************************************************************************
// Method: avtVTKFileReader::GetVar
//
// Purpose:
// Gets the variable.
//
// Arguments:
// var The desired varname, this should be VARNAME.
//
// Returns: The varialbe as VTK scalars.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Hank Childs, Tue Mar 20 09:23:26 PST 2001
// Account for vector variable in error checking.
//
// Hank Childs, Tue Mar 26 13:33:43 PST 2002
// Add a reference so that reference counting tricks work.
//
// Kathleen Bonnell, Wed Mar 27 15:47:14 PST 2002
// vtkScalars has been deprecated in VTK 4.0, use vtkDataArray instead.
//
// Hank Childs, Thu Aug 15 09:07:38 PDT 2002
// Add support for multiple variables.
//
// Hank Childs, Sat Mar 19 11:57:19 PST 2005
// Turn variables with name "internal_var_" back into "avt".
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Kathleen Biagas, Fri Aug 13 2021
// Change debug message to correctly identify actual file being read in.
//
// ****************************************************************************
vtkDataArray *
avtVTKFileReader::GetVar(int domain, const char *real_name)
{
debug5 << "Getting var from VTK file ";
if (!pieceFileNames.empty())
debug5 << pieceFileNames[domain];
else
debug5 << filename;
debug5 << " (domain = " << domain << ") " << endl;
if (!readInDataset)
{
ReadInFile(domain);
}
if (pieceDatasets[domain] == NULL)
{
ReadInDataset(domain);
}
vtkDataSet *dataset = pieceDatasets[domain];
const char *var = real_name;
char buffer[1024];
if (strncmp(var, "internal_var_", strlen("internal_var_")) == 0)
{
sprintf(buffer, "avt%s", var + strlen("internal_var_"));
var = buffer;
}
vtkDataArray *rv = NULL;
rv = dataset->GetPointData()->GetArray(var);
if (rv == NULL)
{
rv = dataset->GetCellData()->GetArray(var);
}
//
// See if we made up an artificial name for it.
//
if (strstr(var, VARNAME) != NULL)
{
const char *numstr = var + strlen(VARNAME);
int num = atoi(numstr);
int npointvars = dataset->GetPointData()->GetNumberOfArrays();
if (num < npointvars)
{
rv = dataset->GetPointData()->GetArray(num);
}
else
{
rv = dataset->GetCellData()->GetArray(num-npointvars);
}
}
if (rv == NULL)
{
EXCEPTION1(InvalidVariableException, var);
}
//
// The routine that calls this method is going to assume that it can call
// Delete on what is returned. That means we better add an extra
// reference.
//
rv->Register(NULL);
return rv;
}
// ****************************************************************************
// Method: avtVTKFileReader::GetVectorVar
//
// Purpose:
// Gets the vector variable.
//
// Arguments:
// var The desired varname, this should be VARNAME.
//
// Returns: The varialbe as VTK vectors.
//
// Programmer: Hank Childs
// Creation: March 20, 2001
//
// Modifications:
// Hank Childs, Tue Mar 26 13:33:43 PST 2002
// Add a reference so that reference counting tricks work.
//
// Kathleen Bonnell, Wed Mar 27 15:47:14 PST 2002
// vtkVectors has been deprecated in VTK 4.0, use vtkDataArray instead.
//
// Hank Childs, Thu Aug 15 09:17:14 PDT 2002
// Route the vector call through the scalar variable call, since there is
// now no effective difference between the two.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// ****************************************************************************
vtkDataArray *
avtVTKFileReader::GetVectorVar(int domain, const char *var)
{
//
// There is no difference between vectors and scalars for this class.
//
return GetVar(domain, var);
}
// ****************************************************************************
// Method: avtVTKFileReader::PopulateDatabaseMetaData
//
// Purpose:
// Sets the database meta data.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Hank Childs, Thu Mar 15 11:10:54 PST 2001
// Better determine if the dataset is 2D or 3D.
//
// Hank Childs, Tue Mar 20 09:13:30 PST 2001
// Allow for vector variables.
//
// Hank Childs, Mon Mar 11 08:52:59 PST 2002
// Renamed to PopulateDatabaseMetaData.
//
// Hank Childs, Sun Jun 23 20:50:17 PDT 2002
// Added support for point meshes.
//
// Hank Childs, Sat Jun 29 23:08:51 PDT 2002
// Add support for poly data meshes that are point meshes.
//
// Hank Childs, Thu Aug 15 09:07:38 PDT 2002
// Add support for multiple variables.
//
// Hank Childs, Thu Aug 21 23:28:44 PDT 2003
// Replace call to GetListOfUniqueCellTypes, which hangs in an infinite
// loop if there are multiple types of cells.
//
// Hank Childs, Wed Sep 24 08:02:08 PDT 2003
// Add support for tensors.
//
// Hank Childs, Thu Aug 26 08:32:09 PDT 2004
// Only declare the mesh as 2D if Z=0 for all points.
//
// Hank Childs, Sat Mar 19 11:57:19 PST 2005
// Do not return variables with name "avt", since we may want to look
// at these variables and the generic DB will throw them away.
//
// Kathleen Bonnell, Wed Jul 13 18:27:05 PDT 2005
// Specify whether or not scalar data should be treated as ascii.
//
// Mark C. Miller, Thu Sep 15 19:45:51 PDT 2005
// Added support for arrays representing materials
//
// Brad Whitlock, Wed Nov 9 10:59:35 PDT 2005
// Added support for color vectors (ncomps==4).
//
// Kathleen Bonnell, Fri Feb 3 11:20:02 PST 2006
// Added support for MeshCoordType (int in FieldData of dataset,
// 0 == XY, 1 == RZ, 2 == ZR).
//
// Jeremy Meredith, Mon Aug 28 17:40:47 EDT 2006
// Added support for unit cell vectors.
//
// Jeremy Meredith, Thu Apr 2 16:08:16 EDT 2009
// Added array variable support.
//
// Brad Whitlock, Fri May 15 16:05:22 PDT 2009
// I improved the array variable support, adding them for cell data and I
// added expressions to extract their components. I also added support
// label variables.
//
// Jeremy Meredith, Mon Nov 9 13:03:18 EST 2009
// Expand the test for lower topological dimensions to include
// structured grids.
//
// Hank Childs, Wed Sep 14 16:29:19 PDT 2011
// Improve handling of ghost data.
//
// Brad Whitlock, Wed Oct 26 11:12:17 PDT 2011
// Add metadata for curves.
//
// Cyrus Harrison, Wed Nov 16 13:35:54 PST 2011
// Use "MaterialIds" field data to help generate materials metadata.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// Mark C. Miller, Wed Jul 2 17:26:44 PDT 2014
// FreeUpResources before leaving. This is to ensure mdserver and non-zero
// mpi-ranks don't hang onto the VTK data read here solely for purposes
// of populating md.
//
// Kathleen Biagas, Fri Feb 6 06:00:16 PST 2015
// Use 'MeshName' from file if provided (stored in vtk_meshname).
//
// Kathleen Biagas, Thu Aug 13 17:29:21 PDT 2015
// Add support for groups and block names.
//
// Kathleen Biagas, Thu Nov 15 09:20:40 PST 2018
// If unstructured grid has declared no cells (valid in xml verisons),
// assume it is a point mesh and set topodim to 0.
//
// Kathleen Biagas, Tue Sep 10 12:11:23 PDT 2019
// Test UnstructedGrids and vtkPolyData for existence of Points before
// determining if the topological dimension should be lowered. Lack of
// points indicates an empty dataset.
//
// Kathleen Biagas, Thu Oct 31 12:26:22 PDT 2019
// Set mesh type to POINT_MESH when poly data contains only vertex cells.
//
// Mark C. Miller, Mon Mar 9 19:53:47 PDT 2020
// Add logic to define any expressions we found to metadata.
//
// Kathleen Biagas, Fri August 13, 2021
// Add call to ReadInDataset if pieceDataset[0] is NULL.
//
// ****************************************************************************
void
avtVTKFileReader::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
if (!readInDataset)
{
ReadInFile();
}
if (pieceDatasets[0] == NULL)
{
ReadInDataset(0);
}
vtkDataSet *dataset = pieceDatasets[0];
int spat = 3;
int topo = 3;
avtMeshType type;
int vtkType = dataset->GetDataObjectType();
switch (vtkType)
{
case VTK_RECTILINEAR_GRID:
type = AVT_RECTILINEAR_MESH;
break;
case VTK_STRUCTURED_GRID:
type = AVT_CURVILINEAR_MESH;
break;
case VTK_UNSTRUCTURED_GRID:
type = AVT_UNSTRUCTURED_MESH;
break;
case VTK_POLY_DATA:
topo = 2;
type = AVT_SURFACE_MESH;
break;
default:
debug1 << "Unable to identify mesh type " << vtkType << endl;
type = AVT_UNKNOWN_MESH;
break;
}
double bounds[6];
dataset->GetBounds(bounds);
if ((bounds[4] == bounds[5]) && (bounds[5] == 0.))
{
spat = 2;
topo = 2;
}
//
// Some mesh types can have a lower topological dimension
//
if (vtkType == VTK_UNSTRUCTURED_GRID)
{
vtkUnstructuredGrid *ugrid = (vtkUnstructuredGrid *) dataset;
if(ugrid->GetNumberOfPoints() > 0)
{
if (ugrid->GetNumberOfCells() == 0)
{
// no cells declared, assume point mesh.
debug5 << "The VTK file format contains all points -- "
<< "declaring this a point mesh." << endl;
type = AVT_POINT_MESH;
topo = 0;
}
else
{
vtkUnsignedCharArray *types = vtkUnsignedCharArray::New();
GetListOfUniqueCellTypes(ugrid, types);
if (types->GetNumberOfTuples() == 1)
{
int myType = (int) types->GetValue(0);
if (myType == VTK_VERTEX)
{
debug5 << "The VTK file format contains all points -- "
<< "declaring this a point mesh." << endl;
type = AVT_POINT_MESH;
topo = 0;
}
else if(myType == VTK_LINE)
{
debug5 << "The mesh contains all lines, set topo=1" << endl;
topo = 1;
}
}
types->Delete();
}
}
}
else if (vtkType == VTK_STRUCTURED_GRID)
{
vtkStructuredGrid *sgrid = (vtkStructuredGrid *) dataset;
int dims[3];
sgrid->GetDimensions(dims);
if ((dims[0] == 1 && dims[1] == 1) ||
(dims[0] == 1 && dims[2] == 1) ||
(dims[1] == 1 && dims[2] == 1))
{
topo = 1;
}
else if (dims[0] == 1 || dims[1] == 1 || dims[2] == 1)
{
topo = 2;
}
}
else if (vtkType == VTK_POLY_DATA)
{
vtkPolyData *pd = (vtkPolyData *) dataset;
if (pd->GetNumberOfPoints() > 0)
{
if (pd->GetNumberOfPolys() == 0 && pd->GetNumberOfStrips() == 0)
{
if (pd->GetNumberOfLines() > 0)
{
topo = 1;
}
else
{
debug3 << "The VTK file format contains all points -- "
<< "declaring this a point mesh." << endl;
type = AVT_POINT_MESH;
topo = 0;
}
}
}
}
avtMeshMetaData *mesh = new avtMeshMetaData;
if(vtk_meshname.empty())
{
mesh->name = MESHNAME;
}
else
{
mesh->name = vtk_meshname;
}
mesh->meshType = type;
mesh->spatialDimension = spat;
mesh->topologicalDimension = topo;
if (ngroups > 1)
{
mesh->numGroups = ngroups;
if (!groupNames.empty())
mesh->groupNames = groupNames;
if (!groupPieceName.empty())
{
mesh->groupPieceName = groupPieceName;
mesh->groupTitle = groupPieceName + string("s");
}
mesh->groupIds = groupIds;
}
mesh->numBlocks = nblocks;
mesh->blockOrigin = 0;
if (nblocks == 1)
mesh->SetExtents(bounds);
else
{
if (!blockPieceName.empty())
{
mesh->blockPieceName = blockPieceName;
mesh->blockTitle = blockPieceName + string("s");
}
if (!blockNames.empty() && (int)blockNames.size() == nblocks)
mesh->blockNames = blockNames;
}
if (dataset->GetFieldData()->GetArray("MeshCoordType") != NULL)
{
avtMeshCoordType mct = (avtMeshCoordType)
int(dataset->GetFieldData()->GetArray("MeshCoordType")->
GetComponent(0, 0));
mesh->meshCoordType = mct;
if (mct == AVT_RZ)
{
mesh->xLabel = "Z-Axis";
mesh->yLabel = "R-Axis";
}
else if (mct == AVT_ZR)
{
mesh->xLabel = "R-Axis";
mesh->yLabel = "Z-Axis";
}
}
if (dataset->GetFieldData()->GetArray("UnitCellVectors"))
{
vtkDataArray *ucv = dataset->GetFieldData()->
GetArray("UnitCellVectors");
for (int j=0; j<3; j++)
{
for (int k=0; k<3; k++)
{
mesh->unitCellVectors[j*3+k] = ucv->GetComponent(j*3+k,0);
}
}
}
if (dataset->GetCellData()->GetArray("avtGhostZones"))
{
mesh->containsGhostZones = AVT_HAS_GHOSTS;
int ncells = dataset->GetNumberOfCells();
vtkUnsignedCharArray *arr = (vtkUnsignedCharArray *) dataset->GetCellData()->GetArray("avtGhostZones");
unsigned char *ptr = arr->GetPointer(0);
unsigned char v = '\0';
avtGhostData::AddGhostZoneType(v, ZONE_EXTERIOR_TO_PROBLEM);
for (int i = 0 ; i < ncells ; i++)
if (ptr[i] & v)
{
mesh->containsExteriorBoundaryGhosts = true;
break;
}
}
else
mesh->containsGhostZones = AVT_NO_GHOSTS;
md->Add(mesh);
std::map<string, vtkRectilinearGrid *>::iterator pos;
for(pos = vtkCurves.begin(); pos != vtkCurves.end(); ++pos)
{
avtCurveMetaData *curve = new avtCurveMetaData;
curve->name = pos->first;
curve->hasSpatialExtents = false;
curve->hasDataExtents = false;
md->Add(curve);
}
int nvars = 0;
for (int i = 0 ; i < dataset->GetPointData()->GetNumberOfArrays() ; i++)
{
vtkDataArray *arr = dataset->GetPointData()->GetArray(i);
int ncomp = arr->GetNumberOfComponents();
const char *name = arr->GetName();
char buffer[1024];
char buffer2[1024];
if (name == NULL || strcmp(name, "") == 0)
{
sprintf(buffer, "%s%d", VARNAME, nvars);
name = buffer;
}
if (strncmp(name, "avt", strlen("avt")) == 0)
{
sprintf(buffer2, "internal_var_%s", name+strlen("avt"));
name = buffer2;
}
if (ncomp == 1)
{
bool ascii = arr->GetDataType() == VTK_CHAR;
AddScalarVarToMetaData(md, name, mesh->name, AVT_NODECENT, NULL, ascii);
}
else if (ncomp <= 4)
{
AddVectorVarToMetaData(md, name, mesh->name, AVT_NODECENT, ncomp);
}
else if (ncomp == 9)
{
AddTensorVarToMetaData(md, name, mesh->name, AVT_NODECENT);
}
else
{
if(arr->GetDataType() == VTK_UNSIGNED_CHAR ||
arr->GetDataType() == VTK_CHAR)
{
md->Add(new avtLabelMetaData(name, mesh->name, AVT_NODECENT));
}
else
{
AddArrayVarToMetaData(md, name, ncomp, mesh->name, AVT_NODECENT);
int compnamelen = int(strlen(name) + 40);
char *exp_name = new char[compnamelen];
char *exp_def = new char[compnamelen];
for(int c = 0; c < ncomp; ++c)
{
snprintf(exp_name, compnamelen, "%s/comp_%d", name, c);
snprintf(exp_def, compnamelen, "array_decompose(<%s>, %d)", name, c);
Expression e;
e.SetType(Expression::ScalarMeshVar);
e.SetName(exp_name);
e.SetDefinition(exp_def);
md->AddExpression(&e);
}
delete [] exp_name;
delete [] exp_def;
}
}
nvars++;
}
for (int i = 0 ; i < dataset->GetCellData()->GetNumberOfArrays() ; i++)
{
vtkDataArray *arr = dataset->GetCellData()->GetArray(i);
int ncomp = arr->GetNumberOfComponents();
const char *name = arr->GetName();
char buffer[1024];
char buffer2[1024];
if (name == NULL || strcmp(name, "") == 0)
{
sprintf(buffer, "%s%d", VARNAME, nvars);
name = buffer;
}
if (strncmp(name, "avt", strlen("avt")) == 0)
{
sprintf(buffer2, "internal_var_%s", name+strlen("avt"));
name = buffer2;
}
if ((arr->GetDataType() == VTK_INT) && (ncomp == 1) &&
((strncmp(name, "internal_var_Subsets", strlen("internal_var_Subsets")) == 0) ||
((strncmp(name, "material", strlen("material")) == 0))))
{
std::map<int, bool> valMap;
vtkIntArray *iarr = NULL;
// check for field data "MaterialIds" that can directly provide us
// the proper set of material ids.
vtkDataArray *mids_arr = dataset->GetFieldData()->GetArray("MaterialIds");
if( mids_arr != NULL)
iarr = vtkIntArray::SafeDownCast(mids_arr);
else
iarr = vtkIntArray::SafeDownCast(arr);
int *iptr = iarr->GetPointer(0);
int ntuples = iarr->GetNumberOfTuples();
for (int j = 0; j < ntuples; j++)
valMap[iptr[j]] = true;
std::map<int, bool>::const_iterator it;
for (it = valMap.begin(); it != valMap.end(); it++)
{
char tmpname[32];
snprintf(tmpname, sizeof(tmpname), "%d", it->first);
matnames.push_back(tmpname);
matnos.push_back(it->first);
}
avtMaterialMetaData *mmd =
new avtMaterialMetaData("materials", mesh->name,
(int)valMap.size(), matnames);
md->Add(mmd);
if (strncmp(name, "internal_var_Subsets", strlen("internal_var_Subsets")) == 0)
matvarname = strdup("internal_var_Subsets");
else
matvarname = strdup("material");
}
else if (ncomp == 1)
{
bool ascii = arr->GetDataType() == VTK_CHAR;
AddScalarVarToMetaData(md, name, mesh->name, AVT_ZONECENT, NULL, ascii);
}
else if (ncomp <= 4)
{
AddVectorVarToMetaData(md, name, mesh->name, AVT_ZONECENT, ncomp);
}
else if (ncomp == 9)
{
AddTensorVarToMetaData(md, name, mesh->name, AVT_ZONECENT);
}
else
{
if(arr->GetDataType() == VTK_UNSIGNED_CHAR ||
arr->GetDataType() == VTK_CHAR)
{
md->Add(new avtLabelMetaData(name, mesh->name, AVT_ZONECENT));
}
else
{
AddArrayVarToMetaData(md, name, ncomp, mesh->name, AVT_ZONECENT);
int compnamelen = int(strlen(name) + 40);
char *exp_name = new char[compnamelen];
char *exp_def = new char[compnamelen];
for(int c = 0; c < ncomp; ++c)
{
snprintf(exp_name, compnamelen, "%s/comp_%d", name, c);
snprintf(exp_def, compnamelen, "array_decompose(<%s>, %d)", name, c);
Expression e;
e.SetType(Expression::ScalarMeshVar);
e.SetName(exp_name);
e.SetDefinition(exp_def);
md->AddExpression(&e);
}
delete [] exp_name;
delete [] exp_def;
}
}
nvars++;
}
// Add expressions from the database
for (int i = 0; i < vtk_exprs.GetNumExpressions(); i++)
md->AddExpression(&vtk_exprs.GetExpressions(i));
// Don't hang on to all the data we've read. We might not even need it
// if we're in mdserver or of on non-zero mpi-rank.
FreeUpResources();
}
// ****************************************************************************
// Method: avtVTKFileReader::IsEmpty
//
// Purpose:
// Returns a flag indicating if the file contains an empty dataset.
//
// Programmer: Eric Brugger
// Creation: June 20, 2017
//
// Modifications:
// Kathleen Biagas, Fri August 13, 2021
// Add call to ReadInDataset if pieceDataset[0] is NULL.
//
// ****************************************************************************
bool
avtVTKFileReader::IsEmpty()
{
if (!readInDataset)
{
ReadInFile();
}
if (pieceDatasets[0] == NULL)
{
ReadInDataset(0);
}
vtkDataSet *dataset = pieceDatasets[0];
if (dataset->GetNumberOfCells() == 0 && dataset->GetNumberOfPoints() == 0)
{
FreeUpResources();
return true;
}
return false;
}
// ****************************************************************************
// Function: GetListOfUniqueCellTypes
//
// Purpose:
// Gets a list of the unique cell types.
//
// Notes: This is done externally to the similar method in
// vtkUnstructuredGrid, since that method is buggy and can get
// into an infinite loop.
//
// Programmer: Hank Childs
// Creation: August 21, 2003
//
// ****************************************************************************
static void
GetListOfUniqueCellTypes(vtkUnstructuredGrid *ug, vtkUnsignedCharArray *uca)
{
int i;
bool haveCellType[256];
for (i = 0 ; i < 256 ; i++)
haveCellType[i] = false;
int ncells = ug->GetNumberOfCells();
for (i = 0 ; i < ncells ; i++)
haveCellType[ug->GetCellType(i)] = true;
int ntypes = 0;
for (i = 0 ; i < 256 ; i++)
if (haveCellType[i])
ntypes++;
uca->SetNumberOfTuples(ntypes);
int idx = 0;
for (i = 0 ; i < 256 ; i++)
if (haveCellType[i])
{
uca->SetValue(idx++, i);
}
}
// ****************************************************************************
// Function: ConvertStructuredPointsToRGrid
//
// Purpose:
// Constructs a vtkRectilinearGrid from the passed vtkStructuredPoints.
//
// Notes: The passed in dataset will be deleted.
//
// Programmer: Kathleen Bonnell
// Creation: March 9, 2004
//
// Modifications:
// Eric Brugger, Tue Jul 9 09:36:44 PDT 2013
// I modified the reading of pvti, pvtr and pvts files to handle the case
// where the piece extent was a subset of the whole extent.
//
// Kathleen Biagas, Fri Nov 1 13:27:44 PDT 2013
// Changed pieceOrigin from int to double to prevent truncating.
//
// Kathleen Biagas, Thu Sep 14 13:45:00 PDT 2017
// Take the quick copy-array route when pieceDims == wholeDims.
//
// ****************************************************************************
vtkDataSet *
avtVTKFileReader::ConvertStructuredPointsToRGrid(vtkStructuredPoints *inSP,
int *extents)
{
int wholeDims[3];
double spacing[3];
double wholeOrigin[3];
inSP->GetDimensions(wholeDims);
inSP->GetSpacing(spacing);
inSP->GetOrigin(wholeOrigin);
int pieceDims[3];
double pieceOrigin[3];
bool pieceEqualWhole = false;
if (extents == NULL)
{
pieceDims[0] = wholeDims[0];
pieceDims[1] = wholeDims[1];
pieceDims[2] = wholeDims[2];
pieceOrigin[0] = wholeOrigin[0];
pieceOrigin[1] = wholeOrigin[1];
pieceOrigin[2] = wholeOrigin[2];
pieceEqualWhole = true;
}
else
{
pieceDims[0] = extents[1] - extents[0] + 1;
pieceDims[1] = extents[3] - extents[2] + 1;
pieceDims[2] = extents[5] - extents[4] + 1;
pieceOrigin[0] = wholeOrigin[0] + extents[0] * spacing[0];
pieceOrigin[1] = wholeOrigin[1] + extents[2] * spacing[1];
pieceOrigin[2] = wholeOrigin[2] + extents[4] * spacing[2];
pieceEqualWhole = (wholeDims[0] == pieceDims[0]) &&
(wholeDims[1] == pieceDims[1]) &&
(wholeDims[2] == pieceDims[2]);
}
vtkFloatArray *x = vtkFloatArray::New();
x->SetNumberOfComponents(1);
x->SetNumberOfTuples(pieceDims[0]);
vtkFloatArray *y = vtkFloatArray::New();
y->SetNumberOfComponents(1);
y->SetNumberOfTuples(pieceDims[1]);
vtkFloatArray *z = vtkFloatArray::New();
z->SetNumberOfComponents(1);
z->SetNumberOfTuples(pieceDims[2]);
vtkRectilinearGrid *outRG = vtkRectilinearGrid::New();
outRG->SetDimensions(pieceDims);
outRG->SetXCoordinates(x);
outRG->SetYCoordinates(y);
outRG->SetZCoordinates(z);
x->Delete();
y->Delete();
z->Delete();
int i;
float *ptr = x->GetPointer(0);
for (i = 0; i < pieceDims[0]; i++, ptr++)
*ptr = pieceOrigin[0] + i * spacing[0];
ptr = y->GetPointer(0);
for (i = 0; i < pieceDims[1]; i++, ptr++)
*ptr = pieceOrigin[1] + i * spacing[1];
ptr = z->GetPointer(0);
for (i = 0; i < pieceDims[2]; i++, ptr++)
*ptr = pieceOrigin[2] + i * spacing[2];
if (extents == NULL || pieceEqualWhole)
{
for (i = 0; i < inSP->GetPointData()->GetNumberOfArrays(); i++)
outRG->GetPointData()->AddArray(inSP->GetPointData()->GetArray(i));
for (i = 0; i < inSP->GetCellData()->GetNumberOfArrays(); i++)
outRG->GetCellData()->AddArray(inSP->GetCellData()->GetArray(i));
}
else
{
for (i = 0; i < inSP->GetPointData()->GetNumberOfArrays(); i++)
{
vtkDataArray *in = inSP->GetPointData()->GetArray(i);
vtkDataArray *out = vtkDataArray::CreateDataArray(in->GetDataType());
out->SetName(in->GetName());
out->SetNumberOfComponents(in->GetNumberOfComponents());
unsigned long ntuples = pieceDims[0] * pieceDims[1] * pieceDims[2];
out->SetNumberOfTuples(ntuples);
vtkIdType outIndex = 0;
vtkIdType nx = wholeDims[0];
vtkIdType nxy = wholeDims[0] * wholeDims[1];
for (unsigned int iZ = extents[4]; iZ < (unsigned int)extents[5]; iZ++)
{
for (unsigned int iY = extents[2]; iY < (unsigned int)extents[3]; iY++)
{
for (unsigned int iX = extents[0]; iX < (unsigned int)extents[1]; iX++)
{
vtkIdType inIndex = iZ * nxy + iY * nx + iX;
out->SetTuple(outIndex, inIndex, in);
outIndex++;
}
}
}
outRG->GetPointData()->AddArray(out);
}
for (i = 0; i < inSP->GetCellData()->GetNumberOfArrays(); i++)
{
vtkDataArray *in = inSP->GetCellData()->GetArray(i);
vtkDataArray *out = vtkDataArray::CreateDataArray(in->GetDataType());
out->SetName(in->GetName());
out->SetNumberOfComponents(in->GetNumberOfComponents());
int pieceZonalDims[3];
pieceZonalDims[0] = (pieceDims[0] <= 1) ? 1 : (pieceDims[0] - 1);
pieceZonalDims[1] = (pieceDims[1] <= 1) ? 1 : (pieceDims[1] - 1);
pieceZonalDims[2] = (pieceDims[2] <= 1) ? 1 : (pieceDims[2] - 1);
out->SetNumberOfTuples(pieceZonalDims[0] *
pieceZonalDims[1] *
pieceZonalDims[2]);
int wholeZonalDims[3];
wholeZonalDims[0] = (wholeDims[0] <= 1) ? 1 : (wholeDims[0] - 1);
wholeZonalDims[1] = (wholeDims[1] <= 1) ? 1 : (wholeDims[1] - 1);
wholeZonalDims[2] = (wholeDims[2] <= 1) ? 1 : (wholeDims[2] - 1);
vtkIdType outIndex = 0;
vtkIdType nX = wholeZonalDims[0];
vtkIdType nXY = wholeZonalDims[0] * wholeZonalDims[1];
int zoneExtents[6];
zoneExtents[0] = extents[0];
zoneExtents[1] = extents[0] + pieceZonalDims[0];
zoneExtents[2] = extents[2];
zoneExtents[3] = extents[2] + pieceZonalDims[1];
zoneExtents[4] = extents[4];
zoneExtents[5] = extents[4] + pieceZonalDims[2];
for (int iZ = zoneExtents[4]; iZ < zoneExtents[5]; iZ++)
{
for (int iY = zoneExtents[2]; iY < zoneExtents[3]; iY++)
{
for (int iX = zoneExtents[0]; iX < zoneExtents[1]; iX++)
{
vtkIdType inIndex = iZ * nXY + iY * nX + iX;
out->SetTuple(outIndex, inIndex, in);
outIndex++;
}
}
}
outRG->GetCellData()->AddArray(out);
}
}
inSP->Delete();
return outRG;
}
// ****************************************************************************
// Method: avtVTKFileReader::GetTime
//
// Purpose: Return the time associated with this file
//
// Programmer: Kathleen Bonnell
// Creation: Jun 29, 2006
//
// Modifications:
// Kathleen Bonnell, Wed Jul 9 18:14:24 PDT 2008
// Call ReadInDataset if not done already.
//
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// ****************************************************************************
double
avtVTKFileReader::GetTime()
{
if (INVALID_TIME == vtk_time && !readInDataset)
ReadInFile();
return vtk_time;
}
// ****************************************************************************
// Method: avtVTKFileReader::GetCycle
//
// Purpose: Return the cycle associated with this file
//
// Programmer: Kathleen Bonnell
// Creation: July 9, 2008
//
// Modifications:
// Eric Brugger, Mon Jun 18 12:28:25 PDT 2012
// I enhanced the reader so that it can read parallel VTK files.
//
// ****************************************************************************
int
avtVTKFileReader::GetCycle()
{
if (INVALID_CYCLE == vtk_cycle && !readInDataset)
ReadInFile();
return vtk_cycle;
}
// ****************************************************************************
// Method: avtFileFormat::AddScalarVarToMetaData
//
// Purpose:
// A convenience routine to add a scalar variable to the meta-data.
//
// Arguments:
// md The meta-data object to add the scalar var to.
// name The name of the scalar variable.
// mesh The mesh the scalar var is defined on.
// cent The centering type - node vs cell.
// extents The extents of the scalar var. (optional)
// treatAsASCII Whether the var is 'ascii' (optional)
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
// Kathleen Bonnell, Wed Jul 13 18:28:51 PDT 2005
// Add optional bool 'treatAsASCII' arg.
//
// ****************************************************************************
void
avtVTKFileReader::AddScalarVarToMetaData(avtDatabaseMetaData *md, string name,
string mesh, avtCentering cent,
const double *extents,
const bool treatAsASCII)
{
avtScalarMetaData *scalar = new avtScalarMetaData();
scalar->name = name;
scalar->meshName = mesh;
scalar->centering = cent;
if (extents != NULL)
{
scalar->hasDataExtents = true;
scalar->SetExtents(extents);
}
else
{
scalar->hasDataExtents = false;
}
scalar->treatAsASCII = treatAsASCII;
md->Add(scalar);
}
// ****************************************************************************
// Method: avtFileFormat::AddVectorVarToMetaData
//
// Purpose:
// A convenience routine to add a vector variable to the meta-data.
//
// Arguments:
// md The meta-data object to add the vector var to.
// name The name of the vector variable.
// mesh The mesh the vector var is defined on.
// cent The centering type - node vs cell.
// dim The dimension of the vector variable. (optional = 3)
// extents The extents of the vector var. (optional)
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// ****************************************************************************
void
avtVTKFileReader::AddVectorVarToMetaData(avtDatabaseMetaData *md, string name,
string mesh, avtCentering cent,
int dim, const double *extents)
{
avtVectorMetaData *vector = new avtVectorMetaData();
vector->name = name;
vector->meshName = mesh;
vector->centering = cent;
vector->varDim = dim;
if (extents != NULL)
{
vector->hasDataExtents = true;
vector->SetExtents(extents);
}
else
{
vector->hasDataExtents = false;
}
md->Add(vector);
}
// ****************************************************************************
// Method: avtFileFormat::AddTensorVarToMetaData
//
// Purpose:
// A convenience routine to add a tensor variable to the meta-data.
//
// Arguments:
// md The meta-data object to add the tensor var to.
// name The name of the tensor variable.
// mesh The mesh the tensor var is defined on.
// cent The centering type - node vs cell.
// dim The dimension of the tensor variable. (optional = 3)
//
// Programmer: Hank Childs
// Creation: September 20, 2003
//
// ****************************************************************************
void
avtVTKFileReader::AddTensorVarToMetaData(avtDatabaseMetaData *md, string name,
string mesh, avtCentering cent, int dim)
{
avtTensorMetaData *tensor = new avtTensorMetaData();
tensor->name = name;
tensor->meshName = mesh;
tensor->centering = cent;
tensor->dim = dim;
md->Add(tensor);
}
// ****************************************************************************
// Method: avtFileFormat::AddArrayVarToMetaData
//
// Purpose:
// A convenience routine to add a array variable to the meta-data.
//
// Arguments:
// md The meta-data object to add the tensor var to.
// name The name of the array variable.
// ncomps The number of components.
// mesh The mesh the array var is defined on.
// cent The centering type - node vs cell.
//
// Programmer: Hank Childs
// Creation: July 21, 2005
//
// ****************************************************************************
void
avtVTKFileReader::AddArrayVarToMetaData(avtDatabaseMetaData *md, string name,
int ncomps, string mesh,avtCentering cent)
{
avtArrayMetaData *st = new avtArrayMetaData();
st->name = name;
st->nVars = ncomps;
st->compNames.resize(ncomps);
for (int i = 0 ; i < ncomps ; i++)
{
char name[16];
snprintf(name, 16, "comp%02d", i);
st->compNames[i] = name;
}
st->meshName = mesh;
st->centering = cent;
md->Add(st);
}
|
5a46dc6fdec0a924c425422871e54de92b0445a0
|
dd6bdce2131e1f608ae711be1426765c9db44122
|
/src/utils/cutils/utils_array.h
|
64f414962fea66d2ffa9b6431ec21d264a079c87
|
[] |
no_license
|
openeuler-mirror/iSulad
|
df3b7bdd285e3ed0e2b572ec02c3cef8a80fa8a9
|
1faaae7ee243bc8b9484ede632302a3cd4bc8670
|
refs/heads/master
| 2023-09-01T04:07:42.243619
| 2023-08-26T01:28:08
| 2023-08-26T01:28:08
| 246,005,159
| 350
| 25
| null | null | null | null |
UTF-8
|
C
| false
| false
| 1,998
|
h
|
utils_array.h
|
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2018-11-1
* Description: provide container sha256 functions
********************************************************************************/
#ifndef UTILS_CUTILS_UTILS_ARRAY_H
#define UTILS_CUTILS_UTILS_ARRAY_H
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
size_t util_array_len(const char **array);
void util_free_array_by_len(char **array, size_t len);
void util_free_array(char **array);
int util_grow_array(char ***orig_array, size_t *orig_capacity, size_t size,
size_t increment);
int util_array_append(char ***array, const char *element);
bool util_array_contain(const char **array, const char *element);
// don't free element and set it null after call this function
int util_common_array_append_pointer(void ***array, void *element);
typedef struct string_array_t {
char **items;
size_t len;
size_t cap;
} string_array;
string_array *util_string_array_new(size_t len);
void util_free_string_array(string_array *ptr);
int util_append_string_array(string_array *sarr, const char *val);
bool util_string_array_contain(const string_array *sarr, const char *elem);
void util_free_sensitive_array(char **array);
void util_free_sensitive_array_by_len(char **array, size_t len);
#ifdef __cplusplus
}
#endif
#endif // UTILS_CUTILS_UTILS_ARRAY_H
|
46ad6913f51ccc0e2d0dd1c1d04067b6feea1a44
|
1231379e557a3094413045721b4c65ce9bae568b
|
/src/generated/linux/platform_posix.c.clog.h
|
c3eba82d731fcb7884580d73ce881fcf66a4314f
|
[
"MIT"
] |
permissive
|
microsoft/msquic
|
a63982f1b7d017fb0497e2dce56f1ef527bd6eaa
|
f91ccc2f975225a278bc68238555ed0923e676ba
|
refs/heads/main
| 2023-09-04T01:25:39.133074
| 2023-08-28T18:04:51
| 2023-08-28T18:04:51
| 217,654,199
| 3,641
| 521
|
MIT
| 2023-09-14T14:36:09
| 2019-10-26T04:10:24
|
C
|
UTF-8
|
C
| false
| false
| 6,321
|
h
|
platform_posix.c.clog.h
|
#ifndef CLOG_DO_NOT_INCLUDE_HEADER
#include <clog.h>
#endif
#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER CLOG_PLATFORM_POSIX_C
#undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "platform_posix.c.clog.h.lttng.h"
#if !defined(DEF_CLOG_PLATFORM_POSIX_C) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define DEF_CLOG_PLATFORM_POSIX_C
#include <lttng/tracepoint.h>
#define __int64 __int64_t
#include "platform_posix.c.clog.h.lttng.h"
#endif
#include <lttng/tracepoint-event.h>
#ifndef _clog_MACRO_QuicTraceLogWarning
#define _clog_MACRO_QuicTraceLogWarning 1
#define QuicTraceLogWarning(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifndef _clog_MACRO_QuicTraceLogInfo
#define _clog_MACRO_QuicTraceLogInfo 1
#define QuicTraceLogInfo(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifndef _clog_MACRO_QuicTraceEvent
#define _clog_MACRO_QuicTraceEvent 1
#define QuicTraceEvent(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------
// Decoder Ring for PlatformThreadCreateFailed
// [ lib] pthread_create failed, retrying without affinitization
// QuicTraceLogWarning(
PlatformThreadCreateFailed,
"[ lib] pthread_create failed, retrying without affinitization");
----------------------------------------------------------*/
#ifndef _clog_2_ARGS_TRACE_PlatformThreadCreateFailed
#define _clog_2_ARGS_TRACE_PlatformThreadCreateFailed(uniqueId, encoded_arg_string)\
tracepoint(CLOG_PLATFORM_POSIX_C, PlatformThreadCreateFailed );\
#endif
/*----------------------------------------------------------
// Decoder Ring for PosixLoaded
// [ dso] Loaded
// QuicTraceLogInfo(
PosixLoaded,
"[ dso] Loaded");
----------------------------------------------------------*/
#ifndef _clog_2_ARGS_TRACE_PosixLoaded
#define _clog_2_ARGS_TRACE_PosixLoaded(uniqueId, encoded_arg_string)\
tracepoint(CLOG_PLATFORM_POSIX_C, PosixLoaded );\
#endif
/*----------------------------------------------------------
// Decoder Ring for PosixUnloaded
// [ dso] Unloaded
// QuicTraceLogInfo(
PosixUnloaded,
"[ dso] Unloaded");
----------------------------------------------------------*/
#ifndef _clog_2_ARGS_TRACE_PosixUnloaded
#define _clog_2_ARGS_TRACE_PosixUnloaded(uniqueId, encoded_arg_string)\
tracepoint(CLOG_PLATFORM_POSIX_C, PosixUnloaded );\
#endif
/*----------------------------------------------------------
// Decoder Ring for PosixInitialized
// [ dso] Initialized (AvailMem = %llu bytes)
// QuicTraceLogInfo(
PosixInitialized,
"[ dso] Initialized (AvailMem = %llu bytes)",
CxPlatTotalMemory);
// arg2 = arg2 = CxPlatTotalMemory = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_PosixInitialized
#define _clog_3_ARGS_TRACE_PosixInitialized(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_PLATFORM_POSIX_C, PosixInitialized , arg2);\
#endif
/*----------------------------------------------------------
// Decoder Ring for PosixUninitialized
// [ dso] Uninitialized
// QuicTraceLogInfo(
PosixUninitialized,
"[ dso] Uninitialized");
----------------------------------------------------------*/
#ifndef _clog_2_ARGS_TRACE_PosixUninitialized
#define _clog_2_ARGS_TRACE_PosixUninitialized(uniqueId, encoded_arg_string)\
tracepoint(CLOG_PLATFORM_POSIX_C, PosixUninitialized );\
#endif
/*----------------------------------------------------------
// Decoder Ring for LibraryErrorStatus
// [ lib] ERROR, %u, %s.
// QuicTraceEvent(
LibraryErrorStatus,
"[ lib] ERROR, %u, %s.",
errno,
"open(/dev/urandom, O_RDONLY|O_CLOEXEC) failed");
// arg2 = arg2 = errno = arg2
// arg3 = arg3 = "open(/dev/urandom, O_RDONLY|O_CLOEXEC) failed" = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_LibraryErrorStatus
#define _clog_4_ARGS_TRACE_LibraryErrorStatus(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_PLATFORM_POSIX_C, LibraryErrorStatus , arg2, arg3);\
#endif
/*----------------------------------------------------------
// Decoder Ring for LibraryError
// [ lib] ERROR, %s.
// QuicTraceEvent(
LibraryError,
"[ lib] ERROR, %s.",
"pthread_attr_setaffinity_np failed");
// arg2 = arg2 = "pthread_attr_setaffinity_np failed" = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_LibraryError
#define _clog_3_ARGS_TRACE_LibraryError(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_PLATFORM_POSIX_C, LibraryError , arg2);\
#endif
/*----------------------------------------------------------
// Decoder Ring for AllocFailure
// Allocation of '%s' failed. (%llu bytes)
// QuicTraceEvent(
AllocFailure,
"Allocation of '%s' failed. (%llu bytes)",
"Custom thread context",
sizeof(CXPLAT_THREAD_CUSTOM_CONTEXT));
// arg2 = arg2 = "Custom thread context" = arg2
// arg3 = arg3 = sizeof(CXPLAT_THREAD_CUSTOM_CONTEXT) = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_AllocFailure
#define _clog_4_ARGS_TRACE_AllocFailure(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_PLATFORM_POSIX_C, AllocFailure , arg2, arg3);\
#endif
/*----------------------------------------------------------
// Decoder Ring for LibraryAssert
// [ lib] ASSERT, %u:%s - %s.
// QuicTraceEvent(
LibraryAssert,
"[ lib] ASSERT, %u:%s - %s.",
(uint32_t)Line,
File,
Expr);
// arg2 = arg2 = (uint32_t)Line = arg2
// arg3 = arg3 = File = arg3
// arg4 = arg4 = Expr = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_LibraryAssert
#define _clog_5_ARGS_TRACE_LibraryAssert(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_PLATFORM_POSIX_C, LibraryAssert , arg2, arg3, arg4);\
#endif
#ifdef __cplusplus
}
#endif
#ifdef CLOG_INLINE_IMPLEMENTATION
#include "quic.clog_platform_posix.c.clog.h.c"
#endif
|
3a6ce92b30b32f58ebf45bb006260859b4849e85
|
250b2c446f85e7cc6db4d1c5ee78856b8441a210
|
/lua/wincent/commandt/lib/scanner.h
|
42d608df8820922c04fdfe7c807f31e1692bd5e7
|
[
"BSD-2-Clause"
] |
permissive
|
wincent/command-t
|
ea122d74ab2a622652c05b0dc8e9e2cf508b900b
|
459e9c6e7d5bd8f559bbf8101869d0c9e800b154
|
refs/heads/main
| 2023-08-23T19:21:52.745438
| 2023-08-07T20:44:58
| 2023-08-07T20:47:57
| 553,200
| 1,921
| 325
|
BSD-2-Clause
| 2022-12-01T21:26:57
| 2010-03-08T22:11:39
|
Lua
|
UTF-8
|
C
| false
| false
| 2,263
|
h
|
scanner.h
|
/**
* SPDX-FileCopyrightText: Copyright 2021-present Greg Hurrell and contributors.
* SPDX-License-Identifier: BSD-2-Clause
*/
#ifndef SCANNER_H
#define SCANNER_H
#include "commandt.h" /* for scanner_t */
#include "str.h"
// Define short names for convenience, but all external symbols need prefixes.
#define scanner_new_copy commandt_scanner_new_copy
#define scanner_new_command commandt_scanner_new_command
#define scanner_new_str commandt_scanner_new_str
#define scanner_new commandt_scanner_new
#define scanner_dump commandt_scanner_dump
#define scanner_free commandt_scanner_free
/**
* Create a new `scanner_t` struct initialized with `candidates`.
*
* Copies are made of `candidates`. The caller should call `scanner_free()` when
* done.
*/
scanner_t *scanner_new_copy(const char **candidates, unsigned count);
/**
* Create a new `scanner_t` struct that will be populated by executing the
* NUL-terminated `command` string.
*
* The `drop` parameter indicates how many characters of prefix, if any, should
* be omitted from the strings returned by the scanner; commonly, this will be
* 0, but for commands such as `find .` which prefix all paths with "./", `drop`
* would be 2.
*/
scanner_t *scanner_new_command(const char *command, unsigned drop);
/**
* Create a new `scanner_t` struct initialized with `candidates`.
*
* Copies of the candidates are _not_ made, as they are assumed to belong to an
* `mmap()`-ed slab allocation and initialized with `str_init()`.
*/
scanner_t *scanner_new_str(str_t *candidates, unsigned count);
/**
* Create a `scanner_t` struct initialized with the provide values.
*
* This is a low-level sibling of `scanner_new_str`; just like that function,
* this one does not make copies of the provided values but does take
* "ownership" of them.
*/
scanner_t *scanner_new(
unsigned count,
str_t *candidates,
size_t candidates_size,
char *buffer,
size_t buffer_size
);
/**
* For debugging, a human-readable string representation of the scanner.
*
* Caller should call `str_free()` on the returned string.
*
* @internal
*/
str_t *scanner_dump(scanner_t *scanner);
/**
* Frees a previously created `scanner_t` structure.
*/
void scanner_free(scanner_t *scanner);
#endif
|
97aa7a834ee1a24d8c2a3b0a33b1f397b6e438b6
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/databases/Tecplot/avtTecplotFileFormat.C
|
02a816b0c2d1e630a371cfd716b4703db38121b3
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 79,412
|
c
|
avtTecplotFileFormat.C
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
// ************************************************************************* //
// avtTecplotFileFormat.C //
// ************************************************************************* //
#include <avtTecplotFileFormat.h>
#include <stdlib.h>
#include <string>
#include <vtkPointData.h>
#include <vtkFloatArray.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
#include <vtkCellTypes.h>
#include <vtkIdTypeArray.h>
#include <vtkCellArray.h>
#include <avtDatabaseMetaData.h>
#include <vtkPolyData.h>
#include <vtkVisItUtility.h>
#include <InvalidVariableException.h>
#include <InvalidFilesException.h>
#include <Expression.h>
#include <DebugStream.h>
#ifdef _MSC_VER
#include<shlwapi.h>
#endif
using std::string;
using std::vector;
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
#if defined(_MSC_VER) || !defined(HAVE_STRTOF) || !defined(HAVE_STRTOF_PROTOTYPE)
#ifndef strtof
#define strtof(f1,f2) ((float)strtod(f1,f2))
#endif
#endif
// ****************************************************************************
// Method: GetCoord/GuessCoord
//
// Purpose:
// Turns a variable name into an axis number (x=0,y=1,z=2, none=-1).
// GetCoord only returns exact matches.
// GuessCoord will also try non-exact maches (e.g. "X [m]" includes units).
//
// Arguments:
// tok the token to convert into an axis number
//
// Programmer: Jeremy Meredith
// Creation: July 7, 2008
//
// ****************************************************************************
static int GetCoord(const string &tok)
{
if (tok=="X" || tok=="x" || tok=="I")
return 0;
if (tok=="Y" || tok=="y" || tok=="J")
return 1;
if (tok=="Z" || tok=="z" || tok=="K")
return 2;
return -1;
}
static int GuessCoord(const string &tok)
{
int guessed = GetCoord(tok);
if (tok.length() >= 3)
{
// do match: "x[m]" or "x (m)", etc.
// don't match: "x velocity"
if ((!isspace(tok[1]) && !isalnum(tok[1])) ||
(isspace(tok[1] && !isalnum(tok[2]))))
{
guessed = GetCoord(tok.substr(0,1));
}
}
return guessed;
}
// ****************************************************************************
// Method: SimplifyWhitespace
//
// Purpose:
// Remove leading and trailing tabs and spaces from a string.
//
// Programmer: Jeremy Meredith
// Creation: June 18, 2007
//
// ****************************************************************************
static string SimplifyWhitespace(const std::string &s)
{
int first = 0;
int last = s.length()-1;
while (first < last && (s[first] == ' ' || s[first] == '\t'))
++first;
while (last > first && (s[last] == ' ' || s[last] == '\t'))
--last;
return s.substr(first, last-first+1);
}
// ****************************************************************************
// Method: avtTecplotFileFormat::PushBackToken
//
// Purpose:
// Needed for faking one-token lookahead.
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// ****************************************************************************
void
avtTecplotFileFormat::PushBackToken(const string &tok)
{
saved_token = tok;
}
// ****************************************************************************
// Method: avtTecplotFileFormat::GetNextToken
//
// Purpose:
// The scanner. It probably makes some serious assumptions about tecplot.
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
// Jeremy Meredith, Thu May 22 10:25:12 EDT 2008
// Support DOS format text files.
//
// Jeremy Meredith, Tue Oct 26 17:23:53 EDT 2010
// Change the scanner to allow any of []()= as single-character
// tokens. This allows us to parse some of the more complex patterns
// such as FOO=([4-6,8]=A,[5,12]=B).
//
// ****************************************************************************
string
avtTecplotFileFormat::GetNextToken()
{
// this is where we fake a one-token lookahead
if (!saved_token.empty())
{
string retval = saved_token;
saved_token = "";
return retval;
}
// oops! we hit EOF and someone still wanted more.
if (next_char_eof)
return "";
next_char_eol = false;
token_was_string = false;
string retval = "";
if (!next_char_valid)
{
next_char = file.get();
next_char_valid = true;
if (!file)
{
next_char_eof = true;
}
}
// skip inter-token whitespace
while (!next_char_eof &&
(next_char == ' ' ||
next_char == '\n' ||
next_char == '\r' ||
next_char == '\t' ||
next_char == ','))
{
if (next_char == '\n' || next_char == '\r')
{
next_char_eol = true;
}
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
// Ignore blank lines since they don't return a token
if (next_char_eol)
return GetNextToken();
}
if (next_char == '\"')
{
token_was_string = true;
// do strings
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
while (!next_char_eof && next_char != '\"')
{
retval += next_char;
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
}
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
}
else if (next_char == '=' ||
next_char == '(' ||
next_char == ')' ||
next_char == '[' ||
next_char == ']')
{
// simple one-character tokens
retval += next_char;
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
}
else
{
// do a normal token
while (!next_char_eof &&
(next_char != ' ' &&
next_char != '\n' &&
next_char != '\r' &&
next_char != '\t' &&
next_char != '=' &&
next_char != '(' &&
next_char != ')' &&
next_char != '[' &&
next_char != ']' &&
next_char != ','))
{
if (next_char >= 'a' && next_char <= 'z')
next_char += (int('A')-int('a'));
retval += next_char;
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
}
}
// skip whitespace to EOL
while (!next_char_eof &&
(next_char == ' ' ||
next_char == '\n' ||
next_char == '\r' ||
next_char == '\t' ||
next_char == ','))
{
if (next_char == '\n' || next_char == '\r')
{
next_char_eol = true;
}
next_char = file.get();
if (!file)
{
next_char_eof = true;
}
if (next_char_eol)
break;
}
return retval;
}
// ****************************************************************************
// Method: ParseArraysPoint
//
// Purpose:
// Reads the coordinates and/or nodal data for POINT and FEPOINT formats.
//
// Arguments:
// numNodes the number of nodes
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
// Jeremy Meredith, Mon Jul 7 14:09:28 EDT 2008
// Allow X/Y/Z coordinate arrays to show up as normal variables. This is
// because we now have improved axis-variable guessing, and so if we guess
// wrong we want to avoid hiding what might be a normal scalar variable.
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
// Renamed ParseNodes* to ParseArrays* to reflect this capability.
//
// Jeremy Meredith, Tue Oct 26 17:13:39 EDT 2010
// Added support for comments.
//
// Jeremy Meredith, Wed May 18 13:23:11 EDT 2011
// Removed distinction between allVariableNames and variableNames, since
// we treat even X/Y/Z coordinate arrays as normal variables, still.
//
// Jeremy Meredith, Wed Jul 27 13:55:55 EDT 2011
// Add support for 'nvals*value' repetition format for values.
//
// Jeremy Meredith, Thu Oct 20 13:23:42 EDT 2011
// Removed unused allScalars.
// Support VARSHARELIST.
// Minor performance improvements: it turns out the majority of the
// time in this routine appears to be down in GetNextToken, not
// any inefficiencies here, or even in the strtof call.
//
// Jeremy Meredith, Mon Oct 24 12:06:45 EDT 2011
// Add check for valid coord fields before assigned vals to them.
//
// ****************************************************************************
vtkPoints*
avtTecplotFileFormat::ParseArraysPoint(int numNodes, int numElements)
{
vtkPoints *points = vtkPoints::New();
points->SetNumberOfPoints(numNodes);
float *pts = (float *)points->GetVoidPointer(0);
int i;
for (i=0; i<numNodes*3; i++)
{
pts[i] = 0;
}
vector<float*> allptr;
for (int v=0; v<numTotalVars; v++)
{
if (variableShareMap[v] >= 0)
{
// just copy and add a reference to the array
int dest = variableShareMap[v];
vtkFloatArray *scalars = vars[variableNames[v]][dest];
scalars->Register(NULL);
vars[variableNames[v]].push_back(scalars);
// still need the raw pointer so our indexing below is valid
float *ptr = (float *) scalars->GetVoidPointer(0);
allptr.push_back(ptr);
}
else
{
int numVals = (variableCellCentered[v] ? numElements : numNodes);
vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfTuples(numVals);
float *ptr = (float *) scalars->GetVoidPointer(0);
vars[variableNames[v]].push_back(scalars);
allptr.push_back(ptr);
}
}
int repeatCounter = 0;
float currentValue = 0;
for (i=0; i<numNodes; i++)
{
bool doneWithCellCentered = (i>=numElements);
for (int v = 0; v < numTotalVars; v++)
{
if (variableCellCentered[v] && doneWithCellCentered)
continue;
if (variableShareMap[v] >= 0)
{
// note: we assume repeat counter doesn't affect shared vars
continue;
}
else
{
if (repeatCounter == 0)
{
string tok = GetNextToken();
int toklen = tok.length();
if (toklen>0 && tok[0]=='#')
{
while (!next_char_eol)
tok = GetNextToken();
tok = GetNextToken();
}
char *endptr;
const char *cptr;
repeatCounter = 1;
currentValue = strtof((cptr=tok.c_str()), &endptr);
int numparsed = endptr-cptr;
if (numparsed < toklen && tok[numparsed] == '*')
{
currentValue = atof(tok.substr(numparsed+1).c_str());
repeatCounter = atoi(tok.substr(0,numparsed).c_str());
}
}
allptr[v][i] = currentValue;
--repeatCounter;
}
}
}
for (i=0; i<numNodes; i++)
{
if (Xindex>=0)
pts[3*i + 0] = allptr[Xindex][i];
if (Yindex>=0)
pts[3*i + 1] = allptr[Yindex][i];
if (Zindex>=0)
pts[3*i + 2] = allptr[Zindex][i];
}
return points;
}
// ****************************************************************************
// Method: ParseArraysBlock
//
// Purpose:
// Reads the coordinates and/or nodal data for BLOCK and FEBLOCK formats.
//
// Arguments:
// numNodes the number of nodes
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
// Jeremy Meredith, Mon Jul 7 14:09:28 EDT 2008
// Allow X/Y/Z coordinate arrays to show up as normal variables. This is
// because we now have improved axis-variable guessing, and so if we guess
// wrong we want to avoid hiding what might be a normal scalar variable.
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
// Renamed ParseNodes* to ParseArrays* to reflect this capability.
//
// Jeremy Meredith, Tue Oct 26 17:13:39 EDT 2010
// Added support for comments.
//
// Jeremy Meredith, Wed May 18 13:23:11 EDT 2011
// Removed distinction between allVariableNames and variableNames, since
// we treat even X/Y/Z coordinate arrays as normal variables, still.
//
// Jeremy Meredith, Wed Jul 27 13:55:55 EDT 2011
// Add support for 'nvals*value' repetition format for values.
//
// Jeremy Meredith, Fri Oct 21 10:16:33 EDT 2011
// Support VARSHARELIST.
//
// ****************************************************************************
vtkPoints*
avtTecplotFileFormat::ParseArraysBlock(int numNodes, int numElements)
{
vtkPoints *points = vtkPoints::New();
points->SetNumberOfPoints(numNodes);
float *pts = (float *)points->GetVoidPointer(0);
for (int i=0; i<numNodes*3; i++)
{
pts[i] = 0;
}
int repeatCounter = 0;
float currentValue = 0;
for (int v = 0; v < numTotalVars; v++)
{
int numVals = (variableCellCentered[v] ? numElements : numNodes);
float *ptr = NULL;
// check if we're sharing with other variables first
if (variableShareMap[v] >= 0)
{
int dest = variableShareMap[v];
vtkFloatArray *scalars = vars[variableNames[v]][dest];
scalars->Register(NULL);
ptr = (float *) scalars->GetVoidPointer(0);
vars[variableNames[v]].push_back(scalars);
}
else
{
// nope, okay; read it
vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfTuples(numVals);
ptr = (float *) scalars->GetVoidPointer(0);
for (int i=0; i<numVals; i++)
{
if (repeatCounter == 0)
{
string tok = GetNextToken();
int toklen = tok.length();
if (toklen>0 && tok[0]=='#')
{
while (!next_char_eol)
tok = GetNextToken();
tok = GetNextToken();
}
char *endptr;
const char *cptr;
repeatCounter = 1;
currentValue = strtof((cptr=tok.c_str()), &endptr);
int numparsed = endptr-cptr;
if (numparsed < toklen && tok[numparsed] == '*')
{
currentValue = atof(tok.substr(numparsed+1).c_str());
repeatCounter = atoi(tok.substr(0,numparsed).c_str());
}
}
ptr[i] = currentValue;
--repeatCounter;
}
vars[variableNames[v]].push_back(scalars);
}
if (v==Xindex)
{
for (int i=0; i<numVals; i++)
pts[3*i + 0] = ptr[i];
}
else if (v==Yindex)
{
for (int i=0; i<numVals; i++)
pts[3*i + 1] = ptr[i];
}
else if (v==Zindex)
{
for (int i=0; i<numVals; i++)
pts[3*i + 2] = ptr[i];
}
}
return points;
}
// ****************************************************************************
// Method: avtTecplotFileFormat::ParseElements
//
// Purpose:
// Parses the element connectivity arrays.
//
// Arguments:
// numElements the number of elements
// elemType the element type
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for 'POINT' element. This is not a keyword tecplot
// understands but was necessary to enable support for point meshes.
//
// Jeremy Meredith, Tue Jun 19 15:11:50 EDT 2007
// Allowed an FE mesh with no ET (element type) field in the zone record
// header to default to a point mesh.
//
// Jeremy Meredith, Fri Oct 9 16:22:40 EDT 2009
// Added new names for element types.
//
// Jeremy Meredith, Tue Oct 26 11:03:35 EDT 2010
// Added a couple "FE" variants that were missing.
// Added support for comments.
//
// Mark C. Miller, Thu Jun 4 11:47:02 PDT 2015
// Added support for FELINESEG elem type
// ****************************************************************************
vtkUnstructuredGrid *
avtTecplotFileFormat::ParseElements(int numElements, const string &elemType)
{
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
// construct the cell arrays
int nelempts = -1;
int idtype = -1;
if (elemType == "BRICK" || elemType == "FEBRICK")
{
nelempts = 8;
idtype = VTK_HEXAHEDRON;
topologicalDimension = MAX(topologicalDimension, 3);
}
else if (elemType == "TRIANGLE" || elemType == "FETRIANGLE")
{
nelempts = 3;
idtype = VTK_TRIANGLE;
topologicalDimension = MAX(topologicalDimension, 2);
}
else if (elemType == "QUADRILATERAL" || elemType == "FEQUADRILATERAL")
{
nelempts = 4;
idtype = VTK_QUAD;
topologicalDimension = MAX(topologicalDimension, 2);
}
else if (elemType == "TETRAHEDRON" || elemType == "FETETRAHEDRON")
{
nelempts = 4;
idtype = VTK_TETRA;
topologicalDimension = MAX(topologicalDimension, 3);
}
else if (elemType == "LINESEG" || elemType == "FELINESEG")
{
nelempts = 2;
idtype = VTK_LINE;
topologicalDimension = MAX(topologicalDimension, 1);
}
else if (elemType == "POINT" || elemType == "FEPOINT" || elemType == "")
{
nelempts = 1;
idtype = VTK_VERTEX;
topologicalDimension = MAX(topologicalDimension, 0);
}
else
{
EXCEPTION2(InvalidFilesException, filename,
"Unknown element type for zone");
}
vtkIdTypeArray *nlist = vtkIdTypeArray::New();
nlist->SetNumberOfValues((nelempts+1) * numElements);
vtkIdType *nl = nlist->GetPointer(0);
vtkUnsignedCharArray *cellTypes = vtkUnsignedCharArray::New();
cellTypes->SetNumberOfValues(numElements);
unsigned char *ct = cellTypes->GetPointer(0);
vtkIdTypeArray *cellLocations = vtkIdTypeArray::New();
cellLocations->SetNumberOfValues(numElements);
vtkIdType *cl = cellLocations->GetPointer(0);
int offset = 0;
for (int c=0; c<numElements; c++)
{
*ct++ = idtype;
*nl++ = nelempts;
// 1-origin connectivity array
for (int j=0; j<nelempts; j++)
{
if (idtype == VTK_VERTEX)
*nl++ = c;
else
{
string tok = GetNextToken();
if (tok.length()>0 && tok[0]=='#')
{
while (!next_char_eol)
tok = GetNextToken();
tok = GetNextToken();
}
int val = atoi(tok.c_str());
*nl++ = val - 1;
}
}
*cl++ = offset;
offset += nelempts+1;
}
vtkCellArray *cells = vtkCellArray::New();
cells->SetCells(numElements, nlist);
nlist->Delete();
ugrid->SetCells(cellTypes, cellLocations, cells);
cellTypes->Delete();
cellLocations->Delete();
cells->Delete();
return ugrid;
}
// ****************************************************************************
// Method: avtTecplotFileFormat::ParseFEBLOCK
//
// Purpose:
// Parses an FEBLOCK zone
//
// Arguments:
// numNodes the number of nodes
// numElements the number of elements
// elemType the element type
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
//
// Mark C. Miller, Thu Apr 21 09:37:41 PDT 2005
// Fixed leak for 1D case
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for point meshes where topo dim is zero but spatial dim>1
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
// Renamed ParseNodes* to ParseArrays* to reflect this capability.
//
// Jeremy Meredith, Mon Apr 28 17:06:07 EDT 2014
// Added support for copying connectivity from earlier ZONE instead
// of having explicit arrays on disk.
//
// Mark C. Miller, Thu Jun 4 11:47:43 PDT 2015
// Adjusted logic for detecting curves defined on FELINESEG elem types
// ****************************************************************************
void
avtTecplotFileFormat::ParseFEBLOCK(int numNodes, int numElements,
const string &elemType, int connectivitycopy)
{
vtkPoints *points = ParseArraysBlock(numNodes,numElements);
vtkUnstructuredGrid *ugrid = NULL;
if (connectivitycopy >= 0)
{
vtkDataSet *from = meshes[connectivitycopy];
vtkUnstructuredGrid *fromug = dynamic_cast<vtkUnstructuredGrid*>(from);
if (from->GetDataObjectType() != VTK_UNSTRUCTURED_GRID ||
fromug == NULL)
EXCEPTION1(InvalidFilesException, "CONNECTIVITYCOPY refered to non-FE ZONE");
ugrid = vtkUnstructuredGrid::New();
ugrid->ShallowCopy(fromug);
}
else
{
ugrid = ParseElements(numElements, elemType);
}
ugrid->SetPoints(points);
points->Delete();
if ((topologicalDimension == 2 || topologicalDimension == 3) ||
(topologicalDimension <= 1 && spatialDimension > 1))
{
meshes.push_back(ugrid);
}
else
{
ugrid->Delete();
}
}
// ****************************************************************************
// Method: avtTecplotFileFormat::ParseFEPOINT
//
// Purpose:
// Parses an FEPOINT zone
//
// Arguments:
// numNodes the number of nodes
// numElements the number of elements
// elemType the element type
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
//
// Mark C. Miller, Thu Apr 21 09:37:41 PDT 2005
// Fixed leak for 1D case
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for point meshes where topo dim is zero but spatial dim>1
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
// Renamed ParseNodes* to ParseArrays* to reflect this capability.
//
// Jeremy Meredith, Mon Apr 28 17:06:07 EDT 2014
// Added support for copying connectivity from earlier ZONE instead
// of having explicit arrays on disk.
//
// Mark C. Miller, Thu Jun 4 11:47:43 PDT 2015
// Adjusted logic for detecting curves defined on FELINESEG elem types
// ****************************************************************************
void
avtTecplotFileFormat::ParseFEPOINT(int numNodes, int numElements,
const string &elemType, int connectivitycopy)
{
vtkPoints *points = ParseArraysPoint(numNodes,numElements);
vtkUnstructuredGrid *ugrid = NULL;
if (connectivitycopy >= 0)
{
vtkDataSet *from = meshes[connectivitycopy];
vtkUnstructuredGrid *fromug = dynamic_cast<vtkUnstructuredGrid*>(from);
if (from->GetDataObjectType() != VTK_UNSTRUCTURED_GRID ||
fromug == NULL)
EXCEPTION1(InvalidFilesException, "CONNECTIVITYCOPY refered to non-FE ZONE");
ugrid = vtkUnstructuredGrid::New();
ugrid->ShallowCopy(fromug);
}
else
{
ugrid = ParseElements(numElements, elemType);
}
ugrid->SetPoints(points);
points->Delete();
if ((topologicalDimension == 2 || topologicalDimension == 3) ||
(topologicalDimension <= 1 && spatialDimension > 1))
{
meshes.push_back(ugrid);
}
else
{
ugrid->Delete();
}
}
// ****************************************************************************
// Method: avtTecplotFileFormat::ParseBLOCK
//
// Purpose:
// Parses a structured BLOCK zone
//
// Arguments:
// numI/J/K the number of nodes in each dimension
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
//
// Mark C. Miller, Thu Apr 21 09:37:41 PDT 2005
// Fixed leak for 1D case
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for point meshes where topo dim is zero but spatial dim>1
//
// Jeremy Meredith, Thu Jun 26 17:28:16 EDT 2008
// Only assume it's a 1D mesh if *both* J and K dims are 1.
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
// Renamed ParseNodes* to ParseArrays* to reflect this capability.
//
// Mark C. Miller, Thu Jun 4 11:47:43 PDT 2015
// Adjusted logic for detecting curves defined on FELINESEG elem types
// ****************************************************************************
void
avtTecplotFileFormat::ParseBLOCK(int numI, int numJ, int numK)
{
int numNodes = numI * numJ * numK;
if (numJ==1 && numK==1)
topologicalDimension = MAX(topologicalDimension, 1);
else if (numK==1)
topologicalDimension = MAX(topologicalDimension, 2);
else
topologicalDimension = MAX(topologicalDimension, 3);
int numElementsI = (numI <= 1) ? 1 : numI-1;
int numElementsJ = (numJ <= 1) ? 1 : numJ-1;
int numElementsK = (numK <= 1) ? 1 : numK-1;
int numElements = numElementsI * numElementsJ * numElementsK;
vtkPoints *points = ParseArraysBlock(numNodes, numElements);
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
sgrid->SetPoints(points);
points->Delete();
int dims[3] = {numI, numJ, numK};
sgrid->SetDimensions(dims);
if ((topologicalDimension == 2 || topologicalDimension == 3) ||
(topologicalDimension <= 1 && spatialDimension > 1))
{
meshes.push_back(sgrid);
}
else
{
sgrid->Delete();
}
}
// ****************************************************************************
// Method: avtTecplotFileFormat::ParsePOINT
//
// Purpose:
// Parses a structured POINT zone
//
// Arguments:
// numI/J/K the number of nodes in each dimension
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
//
// Mark C. Miller, Thu Apr 21 09:37:41 PDT 2005
// Fixed leak for 1D case
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for point meshes where topo dim is zero but spatial dim>1
//
// Jeremy Meredith, Thu Jun 26 17:28:16 EDT 2008
// Only assume it's a 1D mesh if *both* J and K dims are 1.
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
// Renamed ParseNodes* to ParseArrays* to reflect this capability.
//
// Mark C. Miller, Tue Sep 1 10:52:13 PDT 2009
// Made it deal with POINT zones that contain more spatial dimensions
// than topological ones.
//
// Jeremy Meredith, Mon Nov 9 13:04:25 EST 2009
// Don't force an M-topo-dimension zone in a N-spatial-dimension block
// (where M<N) to become a point mesh. These types of blocks are
// perfectly valid, but extra support may need to be added to VisIt
// proper to handle them correctly.
//
// Mark C. Miller, Thu Jun 4 11:47:43 PDT 2015
// Adjusted logic for detecting curves defined on FELINESEG elem types
// ****************************************************************************
void
avtTecplotFileFormat::ParsePOINT(int numI, int numJ, int numK)
{
int numNodes = numI * numJ * numK;
int topologicalDimensionOfZone;
if (numJ==1 && numK==1)
topologicalDimensionOfZone = 1;
else if (numK==1)
topologicalDimensionOfZone = 2;
else
topologicalDimensionOfZone = 3;
topologicalDimension = MAX(topologicalDimension, topologicalDimensionOfZone);
int numElementsI = (numI <= 1) ? 1 : numI-1;
int numElementsJ = (numJ <= 1) ? 1 : numJ-1;
int numElementsK = (numK <= 1) ? 1 : numK-1;
int numElements = numElementsI * numElementsJ * numElementsK;
vtkPoints *points = ParseArraysPoint(numNodes, numElements);
if (topologicalDimensionOfZone == 0)
{
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
ugrid->SetPoints(points);
points->Delete();
meshes.push_back(ugrid);
}
else
{
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
sgrid->SetPoints(points);
points->Delete();
int dims[3] = {numI, numJ, numK};
sgrid->SetDimensions(dims);
if ((topologicalDimension == 2 || topologicalDimension == 3) ||
(topologicalDimension <= 1 && spatialDimension > 1))
{
meshes.push_back(sgrid);
}
else
{
sgrid->Delete();
}
}
}
// ****************************************************************************
// Method: avtTecplotFileFormat::ReadFile
//
// Purpose:
// Top-level method to re-read the whole file.
//
// Arguments:
// none (filename is stored as a class member already)
//
// Programmer: Jeremy Meredith
// Creation: December 10, 2004
//
// Modifications:
// Hank Childs, Sat Mar 5 14:28:52 PST 2005
// Add call to 'clear' so that the file can be re-used on subsequent calls.
//
// Brad Whitlock, Tue Jul 26 14:09:45 PST 2005
// I made it understand DATASETAUXDATA.
//
// Jeremy Meredith, Mon Jun 18 15:17:45 EDT 2007
// If no format is given, assume POINT. Also, allow for whitespace in
// the given names of the X/Y/Z variables; apparently this occurs in real
// life due to having to play nice with FORTRAN.
//
// Jeremy Meredith, Thu Jun 26 17:22:18 EDT 2008
// Allow "DATAPACKING" as an alias for "F" in zone record header.
// Add smarter X/Y/Z coordinate guessing.
//
// Jeremy Meredith, Mon Jul 7 14:09:28 EDT 2008
// Add two-stage guessing for axis variables, and make the guessing smarter.
// Also, allow X/Y/Z coordinate arrays to show up as normal variables just
// in case we still guessed wrong.
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
//
// Jeremy Meredith, Fri Oct 9 16:21:53 EDT 2009
// Add some support for new ways you can specify zone headers in
// recent tecplot flavors, including new keywords.
//
// Mark C. Miller, Tue Jan 12 17:36:23 PST 2010
// Added logic to parse SOLUTIONTIME and set solTime.
//
// Jeremy Meredith, Tue Jul 13 15:51:24 EDT 2010
// Allow the "$" which seems to appear alone on the last line of some
// ASCII tecplot files.
//
// Jeremy Meredith, Mon Sep 27 16:03:56 EDT 2010
// Accept "NODES" and "ELEMENTS" as aliases for "N" and "E" in ZONE records.
//
// Jeremy Meredith, Tue Oct 26 17:13:39 EDT 2010
// Don't be quite to restrictive about what constitutes an FE-style ZONE.
//
// Jeremy Meredith, Tue Oct 26 17:26:00 EDT 2010
// The parser now returns parens, brackets, and equals as tokens.
// Added code to skip over these when needed. Also added parsing
// support for complex version of VARLOCATION parameter.
//
// Jeremy Meredith, Wed May 18 13:24:06 EDT 2011
// Removed unused numVars and eliminated distinction between variableNames
// and allVariablesNames, since we now exposed even X/Y/Z coordinate
// arrays as normal variables.
// Allow multiple passes through VARIABLES records, as long as the number
// of variables (and we assume their names, too, though don't yet check)
// doesn't vary between passes.
//
// Jeremy Meredith, Fri Oct 21 10:17:30 EDT 2011
// Add support for VARSHARELIST.
// Skip STRANDID for now -- read it, but continue treating each zone
// as its own domain.
//
// Jeremy Meredith, Tue Oct 25 12:37:42 EDT 2011
// Allow user manual override of coordinate axis variables (via options).
//
// Jeremy Meredith, Mon Apr 28 17:06:07 EDT 2014
// Added support for CONNECTIVITYSHAREZONE. Also ignore "C" zone token.
//
// Eric Brugger, Mon Jul 13 11:14:15 PDT 2020
// Added support for FILETYPE. We only support FULL, so throw an
// exception if not.
//
// ****************************************************************************
void
avtTecplotFileFormat::ReadFile()
{
file.open(filename.c_str());
string tok = GetNextToken();
int currentZoneIndex = 0;
bool got_next_token_already = false;
bool first_token = true;
#define READING_UNTIL_END_OF_LINE !next_char_eof &&\
tok != "TITLE" &&\
tok != "VARIABLES" &&\
tok != "ZONE" &&\
tok != "GEOMETRY" &&\
tok != "TEXT" &&\
tok != "DATASETAUXDATA"
while (!next_char_eof)
{
got_next_token_already = false;
if (tok == "")
{
// whitespace! do nothing
}
else if (tok == "TITLE")
{
// it's a title
GetNextToken(); // skip the equals sign
title = GetNextToken();
debug5 << "Tecplot: parsed title as: '"<<title<<"'\n";
}
else if (tok == "FILETYPE")
{
// it's the file type. We only support FULL.
// Issue an error if it's not.
GetNextToken(); // skip the equals sign
tok = GetNextToken();
debug5 << "Tecplot: parsed FILETYPE token\n";
if (tok != "FULL")
{
char msg[200];
sprintf(msg, "FILETYPE=%s not supported.", tok.c_str());
EXCEPTION2(InvalidFilesException, filename, msg);
}
}
else if (tok == "GEOMETRY")
{
// unsupported
tok = GetNextToken();
while (READING_UNTIL_END_OF_LINE)
{
// Skipping token
tok = GetNextToken();
}
got_next_token_already = true;
debug5 << "Tecplot: Skipped unsupported GEOMETRY token\n";
}
else if (tok == "TEXT")
{
// unsupported
tok = GetNextToken();
while (READING_UNTIL_END_OF_LINE)
{
// Skipping token
tok = GetNextToken();
}
got_next_token_already = true;
debug5 << "Tecplot: Skipped unsupported TEXT token\n";
}
else if (tok == "$")
{
// this seems to have appeared at the end
// of some files; may simply be an eof
// pre-indicator, but it seems to be safe
// to skip it.....
tok = GetNextToken();
while (READING_UNTIL_END_OF_LINE)
{
// Skipping token
tok = GetNextToken();
}
got_next_token_already = true;
}
else if (tok == "VARIABLES")
{
debug5 << "Tecplot: Parsing VARIABLES token\n";
// keep track of values from previous pass through VARIABLES
int old_numTotalVars = numTotalVars;
numTotalVars = 0;
variableNames.clear();
int guessedXindex = -1;
int guessedYindex = -1;
int guessedZindex = -1;
// variable lists
GetNextToken(); // skip the equals sign
tok = GetNextToken();
while (token_was_string)
{
int l = tok.length();
for (int i=0;i<l;i++)
{
if (tok[i]=='(')
tok[i] = '[';
else if (tok[i]==')')
tok[i] = ']';
else if (tok[i]=='/')
tok[i] = '_';
}
string tok_nw = SimplifyWhitespace(tok);
switch (GetCoord(tok_nw))
{
case 0: Xindex = numTotalVars; break;
case 1: Yindex = numTotalVars; break;
case 2: Zindex = numTotalVars; break;
default: break;
}
switch (GuessCoord(tok_nw))
{
case 0: guessedXindex = numTotalVars; break;
case 1: guessedYindex = numTotalVars; break;
case 2: guessedZindex = numTotalVars; break;
default: break;
}
variableNames.push_back(tok);
debug5 << "Tecplot: got quoted variable name " << tok << "\n";
numTotalVars++;
tok = GetNextToken();
}
if (numTotalVars==0)
{
debug5 << "Tecplot: found no quoted variable names, assuming unquoted\n";
// If we didn't get any quoted variables, then
// it's probably just because they forgot to quote
// them. Assume all we get are variables till EOL.
// FIND A WAY TO DISPLAY THIS TO THE USER AS A WARNING!
//cerr << "Didn't get any quoted variables. Assuming"
// << " they weren't quoted and continuing until "
// << "the end-of-line.\n";
while (true)
{
string tok_nw = SimplifyWhitespace(tok);
switch (GetCoord(tok_nw))
{
case 0: Xindex = numTotalVars; break;
case 1: Yindex = numTotalVars; break;
case 2: Zindex = numTotalVars; break;
default: break;
}
switch (GuessCoord(tok_nw))
{
case 0: guessedXindex = numTotalVars; break;
case 1: guessedYindex = numTotalVars; break;
case 2: guessedZindex = numTotalVars; break;
default: break;
}
variableNames.push_back(tok);
debug5 << "Tecplot: got unquoted variable name " << tok << "\n";
numTotalVars++;
if (next_char_eol)
{
tok = GetNextToken();
break;
}
else
tok = GetNextToken();
}
}
// Make sure if we've encountered a VARAIBLES record before, the
// number of variables hasn't changed. (We assume they are
// consistent across all zones.)
if (old_numTotalVars > 0 &&
old_numTotalVars != numTotalVars)
{
EXCEPTION2(InvalidFilesException, filename,
"VARIABLES record differed among zones.");
}
// Default the centering to nodal
variableCellCentered.clear();
variableCellCentered.resize(numTotalVars, 0);
// Default to no shared vars
variableShareMap.clear();
variableShareMap.resize(numTotalVars, -1);
// If we didn't find an exact match for coordinate axis vars, guess
if (Xindex < 0) Xindex = guessedXindex;
if (Yindex < 0) Yindex = guessedYindex;
if (Zindex < 0) Zindex = guessedZindex;
// If the user specified, override any coordinate axis guessing
if (userSpecifiedAxisVars)
{
if (userSpecifiedX >= numTotalVars)
Xindex = -1;
else
Xindex = userSpecifiedX;
if (userSpecifiedY >= numTotalVars)
Yindex = -1;
else
Yindex = userSpecifiedY;
if (userSpecifiedZ >= numTotalVars)
Zindex = -1;
else
Zindex = userSpecifiedZ;
}
// Based on how many spatial coords we got, guess the spatial dim
if (Xindex >= 0)
{
spatialDimension = 1;
if (Yindex >= 0)
{
spatialDimension = 2;
if (Zindex >= 0)
{
spatialDimension = 3;
}
}
}
debug5 << "Tecplot: based on axis variables, spatial dim is " << spatialDimension << "\n";
got_next_token_already = true;
}
else if (tok == "ZONE")
{
debug5 << "Tecplot: starting ZONE\n";
// Parse a zone!
char untitledZoneTitle[40];
sprintf(untitledZoneTitle, "zone%05d", currentZoneIndex);
currentZoneIndex++;
string zoneTitle = untitledZoneTitle;
string elemType = "";
string format = "";
int numNodes = 0;
int numElements = 0;
int numI = 1, numJ = 1, numK = 1;
int connectivitycopy = -1;
tok = GetNextToken();
while (!(tok != "T" &&
tok != "I" &&
tok != "J" &&
tok != "K" &&
tok != "N" &&
tok != "NODES" &&
tok != "E" &&
tok != "ELEMENTS" &&
tok != "ET" &&
tok != "F" &&
tok != "ZONETYPE" &&
tok != "DATAPACKING" &&
tok != "SOLUTIONTIME" &&
tok != "VARLOCATION" &&
tok != "DT" &&
tok != "D" &&
tok != "C" &&
tok != "STRANDID" &&
tok != "VARSHARELIST" &&
tok != "CONNECTIVITYSHAREZONE"))
{
debug5 << "Tecplot: got zone token " << tok << "\n";
if (tok == "T")
{
GetNextToken(); // skip the equals sign
zoneTitle = GetNextToken();
if (!token_was_string)
{
EXCEPTION2(InvalidFilesException, filename,
"Zone titles MUST be quoted.");
}
}
else if (tok == "I")
{
GetNextToken(); // skip the equals sign
numI = atoi(GetNextToken().c_str());
}
else if (tok == "J")
{
GetNextToken(); // skip the equals sign
numJ = atoi(GetNextToken().c_str());
}
else if (tok == "K")
{
GetNextToken(); // skip the equals sign
numK = atoi(GetNextToken().c_str());
}
else if (tok == "N" || tok == "NODES")
{
GetNextToken(); // skip the equals sign
numNodes = atoi(GetNextToken().c_str());
}
else if (tok == "E" || tok == "ELEMENTS")
{
GetNextToken(); // skip the equals sign
numElements = atoi(GetNextToken().c_str());
}
else if (tok == "ET" || tok == "ZONETYPE")
{
GetNextToken(); // skip the equals sign
elemType = GetNextToken();
}
else if (tok == "F" || tok == "DATAPACKING")
{
GetNextToken(); // skip the equals sign
format = GetNextToken();
}
else if (tok == "C")
{
GetNextToken(); // skip the equals sign
GetNextToken(); // skip the color
}
else if (tok == "SOLUTIONTIME")
{
GetNextToken(); // skip the equals sign
solTime = strtod(GetNextToken().c_str(),0);
}
else if (tok == "VARLOCATION")
{
variableCellCentered.clear();
variableCellCentered.resize(numTotalVars, 0);
GetNextToken(); // skip the equals sign
GetNextToken(); // skip the open paren
string c;
c = GetNextToken();
if (c == "[")
{
// complex version
// e.g. VARLOCATION=([2-3,5]=CELLCENTERED,[4]=NODAL)
while (c != ")")
{
// c == "["
vector<int> varindices;
c = GetNextToken();
while (c != "]")
{
string::size_type pos = c.find("-");
if (pos != string::npos)
{
// Okay, we got something like "4-6".
// Note, this scans as a single token
// because we haven't gone all-out on
// a scanner rewrite. So just separate
// it into a "4 through 6" here.
// ALSO NOTE: THIS WILL NOT WORK
// WITH ANY WHITESPACE IN HERE.
// The examples don't have any, but
// the tecplot manual doesn't actually
// specify what's really allowed, so
// given past history, someone may
// eventually do something like that....
string first = c.substr(0,pos);
string last = c.substr(pos+1);
int beg = atoi(first.c_str());
int end = atoi(last.c_str());
for (int ind=beg; ind<=end; ind++)
varindices.push_back(ind);
}
else
{
varindices.push_back(atoi(c.c_str()));
}
c = GetNextToken();
}
GetNextToken(); // skip the equals sign
c = GetNextToken(); // that's the centering keyword
if (c == "CELLCENTERED")
{
// remember given indices are 1-origin
for (size_t i=0; i<varindices.size(); i++)
variableCellCentered[varindices[i]-1] = 1;
}
// next....
c = GetNextToken();
}
}
else
{
// simple version
// e.g. VARLOCATION=(NODAL,CELLCENTERED,CELLCENTERED)
for (int i=0; i<numTotalVars; i++)
{
if (c == "CELLCENTERED")
variableCellCentered[i] = 1;
c = GetNextToken();
// after the last var this picks up the close paren
}
}
}
else if (tok == "DT")
{
GetNextToken(); // skip the equals sign
GetNextToken(); // skip the open paren
for (int i=0; i<numTotalVars; i++)
GetNextToken();
GetNextToken(); // skip the close paren
}
else if (tok == "D")
{
EXCEPTION2(InvalidFilesException, filename,
"Tecplot Zone record parameter 'D' is "
"currently unsupported. Please contact a "
"VisIt developer if you need support for this "
"parameter.");
}
else if (tok == "STRANDID")
{
// not supporting STRANDID for now; assume domains
GetNextToken(); // skip the equals sign
GetNextToken(); // skip the value
}
else if (tok == "VARSHARELIST")
{
variableShareMap.clear();
variableShareMap.resize(numTotalVars, -1);
GetNextToken(); // skip the equals sign
GetNextToken(); // skip the open paren
string c;
c = GetNextToken();
// if (c == "[")
{
// Unlike VARLOCATION, this only has a complex version.
// Note that no "=" means implicitly use previous-zone.
// e.g. VARSHARELIST=([2-3,5]=1,[4])
while (c != ")")
{
// c == "["
vector<int> varindices;
c = GetNextToken();
while (c != "]")
{
string::size_type pos = c.find("-");
if (pos != string::npos)
{
// Okay, we got something like "4-6".
// Note, this scans as a single token
// because we haven't gone all-out on
// a scanner rewrite. So just separate
// it into a "4 through 6" here.
// ALSO NOTE: THIS WILL NOT WORK
// WITH ANY WHITESPACE IN HERE.
// The examples don't have any, but
// the tecplot manual doesn't actually
// specify what's really allowed, so
// given past history, someone may
// eventually do something like that....
string first = c.substr(0,pos);
string last = c.substr(pos+1);
int beg = atoi(first.c_str());
int end = atoi(last.c_str());
for (int ind=beg; ind<=end; ind++)
varindices.push_back(ind);
}
else
{
varindices.push_back(atoi(c.c_str()));
}
c = GetNextToken();
}
c = GetNextToken();
int dest = currentZoneIndex-1;
if (c == "=")
{
c = GetNextToken();
dest = atoi(c.c_str());
// next....
c = GetNextToken();
}
for (size_t vi=0; vi<varindices.size(); vi++)
{
// remember given indices are 1-origin
variableShareMap[varindices[vi]-1] = dest-1;
}
}
}
//else
//{
// unlike VARLOCATION, there is no simple version
//}
debug5 << "Tecplot: varshare: ";
for (int i=0; i<numTotalVars; ++i)
debug5 << variableShareMap[i] << " ";
debug5 << endl;
}
else if (tok == "CONNECTIVITYSHAREZONE")
{
GetNextToken(); // skip the equals sign
string fromzone = GetNextToken();
connectivitycopy = atoi(fromzone.c_str()) - 1; // change 1-origin to 0-origin
}
tok = GetNextToken();
debug5 << "Tecplot: NEXT TOKEN: " << tok << "\n";
}
PushBackToken(tok);
// New flavors of the tecplot format let you specify
// simply "point" or "block" for the format, and by
// adding a zonetype which starts with FE
// (e.g. "FETETRAHEDRON"), switch to an FE
// parsing mode. Ugh.
// Let's make this simple. Any element type which
// is specified and is not "ORDERED" will be assumed
// to make this a finite-element style zone.
if (elemType.length() > 0 && elemType != "ORDERED")
{
// Below we use the format type keyword to determine
// which style to use, so fix it up to conform to what
// we were originally expecting.
if (format == "POINT")
format = "FEPOINT";
if (format == "BLOCK")
format = "FEBLOCK";
}
zoneTitles.push_back(zoneTitle);
if (format=="FEBLOCK")
{
ParseFEBLOCK(numNodes, numElements, elemType, connectivitycopy);
}
else if (format=="FEPOINT")
{
ParseFEPOINT(numNodes, numElements, elemType, connectivitycopy);
}
else if (format=="BLOCK")
{
ParseBLOCK(numI,numJ,numK);
}
else if (format=="POINT")
{
ParsePOINT(numI,numJ,numK);
}
else if (format=="")
{
// No format given; we will assume we got a POINT format
ParsePOINT(numI,numJ,numK);
}
else
{
// UNKNOWN FORMAT
char msg[200];
sprintf(msg, "The format '%s' found in the file was unknown.",
format.c_str());
EXCEPTION2(InvalidFilesException, filename, msg);
}
}
else if(tok == "DATASETAUXDATA")
{
int tokIndex = 0;
bool haveVectorExpr = false;
tok = GetNextToken();
while (READING_UNTIL_END_OF_LINE)
{
if(tokIndex == 0)
{
haveVectorExpr = (tok == "VECTOR");
}
else if(tokIndex == 1)
{
// skip the equals sign
}
else if(tokIndex == 2)
{
if(haveVectorExpr)
{
// Remove spaces
std::string::size_type pos = tok.find(" ");
while(pos != std::string::npos)
{
tok.replace(pos, 1, "");
pos = tok.find(" ");
}
// Look for '('
pos = tok.find("(");
if(pos != std::string::npos)
{
std::string exprName(tok.substr(0, pos));
std::string exprDef(tok.substr(pos, tok.size()-pos));
exprDef.replace(0, 1, "{");
// Replace ')' with '}'
pos = exprDef.find(")");
if(pos != std::string::npos)
{
exprDef.replace(pos, 1, "}");
debug4 << "Expr name=" << exprName.c_str()
<< ", Expr def=" << exprDef.c_str()
<< endl;
Expression newE;
newE.SetName(exprName);
newE.SetDefinition(exprDef);
newE.SetType(Expression::VectorMeshVar);
expressions.AddExpressions(newE);
}
}
}
}
// Skipping token
tok = GetNextToken();
++tokIndex;
}
got_next_token_already = true;
}
else if (first_token && token_was_string)
{
// Robust: assume it's a title
title = tok;
}
else
{
debug5 << "Tecplot: unknown token " << tok << "\n";
// UNKNOWN RECORD TYPE
char msg[200];
sprintf(msg, "The record type '%s' found in the file was unknown.",
tok.c_str());
EXCEPTION2(InvalidFilesException, filename, msg);
}
first_token = false;
if (!got_next_token_already)
{
tok = GetNextToken();
}
}
file.close();
file.clear();
file_read = true;
//
// Fix up spatial and topological dimension.
// It may be that a file reported that it had 2-d data
// but we never found the "X" or "Y" variables, so we
// must treat it as a curve. See simpscat.tec as an example.
//
if (topologicalDimension > spatialDimension)
{
topologicalDimension = spatialDimension;
}
}
// ****************************************************************************
// Method: avtTecplot constructor
//
// Programmer: Jeremy Meredith
// Creation: November 7, 2004
//
// Modifications:
// Brad Whitlock, Tue Jul 26 14:59:48 PST 2005
// Initialized expressions.
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Initialized topo dim to zero to allow for point meshes
//
// Mark C. Miller, Tue Jan 12 17:36:41 PST 2010
// Initialize solTime.
//
// Jeremy Meredith, Tue Oct 25 12:37:42 EDT 2011
// Allow user manual override of coordinate axis variables (via options).
//
// ****************************************************************************
avtTecplotFileFormat::avtTecplotFileFormat(const char *fname,
const DBOptionsAttributes *readOpts)
: avtSTMDFileFormat(&fname, 1), expressions()
{
file_read = false;
filename = fname;
saved_token = "";
next_char_valid = false;
next_char_eof = false;
next_char_eol = false;
token_was_string = false;
Xindex = -1;
Yindex = -1;
Zindex = -1;
topologicalDimension = 0;
spatialDimension = 1;
numTotalVars = 0;
solTime = avtFileFormat::INVALID_TIME;
userSpecifiedAxisVars = false;
userSpecifiedX = -1;
userSpecifiedY = -1;
userSpecifiedZ = -1;
if (readOpts &&
readOpts->FindIndex("Method to determine coordinate axes")>=0)
{
int index = readOpts->GetEnum("Method to determine coordinate axes");
if (index==0) userSpecifiedAxisVars = false;
if (index==1) userSpecifiedAxisVars = true;
}
if (readOpts &&
readOpts->FindIndex("X axis variable index (or -1 for none)")>=0)
{
userSpecifiedX = readOpts->GetInt("X axis variable index (or -1 for none)");
}
if (readOpts &&
readOpts->FindIndex("Y axis variable index (or -1 for none)")>=0)
{
userSpecifiedY = readOpts->GetInt("Y axis variable index (or -1 for none)");
}
if (readOpts &&
readOpts->FindIndex("Z axis variable index (or -1 for none)")>=0)
{
userSpecifiedZ = readOpts->GetInt("Z axis variable index (or -1 for none)");
}
}
// ****************************************************************************
// Method: avtTecplot destructor
//
// Programmer: Jeremy Meredith
// Creation: March 17, 2005
//
// ****************************************************************************
avtTecplotFileFormat::~avtTecplotFileFormat()
{
FreeUpResources();
}
// ****************************************************************************
// Method: avtTecplotFileFormat::FreeUpResources
//
// Purpose:
// When VisIt is done focusing on a particular timestep, it asks that
// timestep to free up any resources (memory, file descriptors) that
// it has associated with it. This method is the mechanism for doing
// that.
//
// Programmer: meredith -- generated by xml2avt
// Creation: Fri Nov 5 15:44:16 PST 2004
//
// Modifications:
// Hank Childs, Sat Mar 5 10:03:47 PST 2005
// Do not blow away file name, because we will need that to re-read the file
// if asked.
//
// Brad Whitlock, Tue Jul 26 14:59:03 PST 2005
// Clear the expression list.
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
//
// Mark C. Miller, Mon Aug 31 19:51:39 PDT 2009
// Set topologicalDimension to 0 to make consistent with constructor.
// ****************************************************************************
void
avtTecplotFileFormat::FreeUpResources(void)
{
file_read = false;
saved_token = "";
next_char_valid = false;
next_char_eof = false;
next_char_eol = false;
token_was_string = false;
Xindex = -1;
Yindex = -1;
Zindex = -1;
topologicalDimension = 0;
spatialDimension = 1;
numTotalVars = 0;
unsigned int i,j;
for (i=0; i<meshes.size(); i++)
{
meshes[i]->Delete();
}
meshes.clear();
for (i=0; i<variableNames.size(); i++)
{
for (j=0; j<vars[variableNames[i]].size(); j++)
{
vars[variableNames[i]][j]->Delete();
}
vars[variableNames[i]].clear();
}
vars.clear();
variableNames.clear();
variableCellCentered.clear();
curveNames.clear();
curveFirstVar.clear();
curveSecondVar.clear();
zoneTitles.clear();
expressions.ClearExpressions();
}
// ****************************************************************************
// Method: avtTecplotFileFormat::DetermineAVTMeshType
//
// Purpose: Walk through the mesh(s) and decide what the overall mesh type
// should be.
//
// Programmer: Mark C. Miller
// Creation: Tue Sep 1 10:44:33 PDT 2009
//
// ****************************************************************************
avtMeshType avtTecplotFileFormat::DetermineAVTMeshType() const
{
if (topologicalDimension == 0)
return AVT_POINT_MESH;
bool allStructuredGrid = true;
for (size_t i = 0; i < meshes.size() && allStructuredGrid; i++)
if (meshes[i]->GetDataObjectType() != VTK_STRUCTURED_GRID)
allStructuredGrid = false;
if (allStructuredGrid)
return AVT_CURVILINEAR_MESH;
return AVT_UNSTRUCTURED_MESH;
}
// ****************************************************************************
// Method: avtTecplotFileFormat::PopulateDatabaseMetaData
//
// Purpose:
// This database meta-data object is like a table of contents for the
// file. By populating it, you are telling the rest of VisIt what
// information it can request from you.
//
// Programmer: meredith -- generated by xml2avt
// Creation: Fri Nov 5 15:44:16 PST 2004
//
// Modifications:
// Brad Whitlock, Tue Jul 26 15:00:41 PST 2005
// I made it add expressions if there are any.
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for point meshes where topo dim is zero but spatial dim>1
//
// Jeremy Meredith, Wed Oct 15 12:07:59 EDT 2008
// Added support for cell-centered vars (through VARLOCATION).
//
// Mark C. Miller, Tue Sep 1 10:53:21 PDT 2009
// Made it call DetermineAVTMeshType
//
// Brad Whitlock, Wed Sep 2 14:15:37 PDT 2009
// Set node origin to 1.
//
// Jeremy Meredith, Wed May 18 13:26:05 EDT 2011
// If we have at least two spatial dims, always expose a point
// mesh, even if we have curves or a spatial mesh. There are too
// many conventions for doing point meshes to deal with. It's
// simplest to just expose the darn point mesh, and any
// node-centered variables, and let the user choose it if that's
// what they wanted. Also, get rid of the "vs X" enforced
// convention for curves if the file has X coordinates; it never worked.
//
// Jeremy Meredith, Thu May 19 10:46:22 EDT 2011
// Make point mesh variables on a separate namespace from the normal mesh.
//
// Mark C. Miller, Thu Jun 4 11:47:43 PDT 2015
// Adjusted logic for detecting curves defined on FELINESEG elem types
//
// Mark C. Miller, Sat Jun 23 11:28:22 PDT 2018
// Adjust logic for curves such that defining every curve against every
// other curve only happens if the *first* variable listed does not
// appear to be a coordinate variable.
//
// Mark C. Miller, Sat Jun 30 09:03:43 PDT 2018
// Fix negated logic for strcasestr test for doAllVsAll
// ****************************************************************************
void
avtTecplotFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
if (!file_read)
ReadFile();
// we always want a point mesh, whether or not we think they have
// some sort of real grid or just curves
if (spatialDimension > 1)
{
avtMeshMetaData *mesh = new avtMeshMetaData;
mesh->name = "points/mesh";
mesh->topologicalDimension = 0;
mesh->spatialDimension = spatialDimension;
mesh->meshType = AVT_POINT_MESH;
mesh->numBlocks = (int)zoneTitles.size();
mesh->blockOrigin = 1;
mesh->cellOrigin = 1;
mesh->nodeOrigin = 1;
mesh->blockTitle = "Zones";
mesh->blockPieceName = "Zone";
mesh->hasSpatialExtents = false;
md->Add(mesh);
for (unsigned int i=0; i<variableNames.size(); i++)
{
if (variableCellCentered[i] == false)
{
string vn = string("points/")+variableNames[i];
AddScalarVarToMetaData(md, vn,
"points/mesh", AVT_NODECENT);
}
}
}
// and now do either curves or a real grid, depending....
if ((topologicalDimension==2 || topologicalDimension==3) ||
(topologicalDimension<=1 && spatialDimension > 1))
{
avtMeshMetaData *mesh = new avtMeshMetaData;
mesh->name = "mesh";
mesh->topologicalDimension = topologicalDimension;
mesh->spatialDimension = spatialDimension;
mesh->meshType = DetermineAVTMeshType();
mesh->numBlocks = (int)meshes.size();
mesh->blockOrigin = 1;
mesh->cellOrigin = 1;
mesh->nodeOrigin = 1;
mesh->blockTitle = "Zones";
mesh->blockPieceName = "Zone";
mesh->hasSpatialExtents = false;
md->Add(mesh);
for (unsigned int i=0; i<variableNames.size(); i++)
{
AddScalarVarToMetaData(md, variableNames[i],
"mesh", (variableCellCentered[i] ?
AVT_ZONECENT : AVT_NODECENT));
}
}
else
{
bool doAllVsAll = true;
if (variableNames[0] == "x" ||
variableNames[0] == "X" ||
variableNames[0] == "i" ||
variableNames[0] == "I" ||
#ifdef _MSC_VER
StrStrIA(variableNames[0].c_str(), "coord"))
#else
strcasestr(variableNames[0].c_str(), "coord"))
#endif
doAllVsAll = false;
//
// We're pretty sneaky about 1D plots -- we
// actual populate every pairing (n*(n-1)
// of 1D values in the metadata. But, DO NOT do
// this if the FIRST variable listed
// is "x","X","i","I" or contains "coord"
//
char s[200];
for (unsigned int z = 0 ; z < zoneTitles.size(); z++)
{
for (unsigned int i=0; i<variableNames.size(); i++)
{
for (unsigned int j=0; j<variableNames.size(); j++)
{
if (doAllVsAll)
{
if (i == j) continue;
}
else
{
if (i != j) continue;
}
if (zoneTitles.size() > 1)
{
if (doAllVsAll)
sprintf(s, "%s/%s vs/%s",
zoneTitles[z].c_str(),
variableNames[i].c_str(),
variableNames[j].c_str());
else
sprintf(s, "%s/%s",
zoneTitles[z].c_str(),
variableNames[i].c_str());
}
else
{
if (doAllVsAll)
sprintf(s, "%s vs/%s",
variableNames[i].c_str(),
variableNames[j].c_str());
else
sprintf(s, "%s",
variableNames[i].c_str());
}
curveIndices[s] = (int)curveNames.size();
curveNames.push_back(s);
curveDomains.push_back(z);
curveFirstVar.push_back(i);
curveSecondVar.push_back(doAllVsAll?j:0);
avtCurveMetaData *curve = new avtCurveMetaData;
curve->name = s;
md->Add(curve);
}
}
}
}
// Add expressions to the metadata.
for(int i = 0; i < expressions.GetNumExpressions(); ++i)
md->AddExpression(new Expression(expressions[i]));
}
// ****************************************************************************
// Method: avtTecplotFileFormat::GetMesh
//
// Purpose:
// Gets the mesh associated with this file. The mesh is returned as a
// derived type of vtkDataSet (ie vtkRectilinearGrid, vtkStructuredGrid,
// vtkUnstructuredGrid, etc).
//
// Arguments:
// domain The index of the domain. If there are NDomains, this
// value is guaranteed to be between 0 and NDomains-1,
// regardless of block origin.
// meshname The name of the mesh of interest. This can be ignored if
// there is only one mesh.
//
// Programmer: Jeremy Meredith
// Creation: November 16, 2004
//
// Modifications:
//
// Hank Childs, Sat Mar 5 10:03:47 PST 2005
// With dynamic load balancing, we may get here after calling FreeResources.
// Make sure we read the file again if necessary.
//
// Mark C. Miller, Thu Mar 29 11:28:34 PDT 2007
// Added support for point meshes where topo dim is zero but spatial dim>1
//
// Jeremy Meredith, Thu Jun 26 17:26:22 EDT 2008
// Changed curves to be created as rectilinear grids instead of polydata
// (so that they work with expressions).
//
// Jeremy Meredith, Wed May 18 13:31:03 EDT 2011
// We always expose a point mesh if they have 2 or more spatial dims.
//
// Jeremy Meredith, Thu May 19 10:46:22 EDT 2011
// Make point mesh variables on a separate namespace from the normal mesh.
// Also, fixed a bug with point mesh Z coordinates.
//
// Mark C. Miller, Thu Jun 4 11:47:43 PDT 2015
// Adjusted logic for detecting curves defined on FELINESEG elem types
// ****************************************************************************
vtkDataSet *
avtTecplotFileFormat::GetMesh(int domain, const char *meshname)
{
if (!file_read)
ReadFile();
// they might ask for points, no matter what was in the file
if (string(meshname) == "points/mesh")
{
vtkPolyData *pd = vtkPolyData::New();
vtkPoints *pts = vtkPoints::New();
vtkFloatArray *x = vars[variableNames[Xindex]][domain];
vtkFloatArray *y = vars[variableNames[Yindex]][domain];
vtkFloatArray *z = (Zindex >= 0) ? vars[variableNames[Zindex]][domain] : NULL;
int npts = x->GetNumberOfTuples();
pts->SetNumberOfPoints(npts);
pd->SetPoints(pts);
pts->Delete();
for (int j = 0 ; j < npts ; j++)
{
pts->SetPoint(j,
x->GetComponent(j,0),
y->GetComponent(j,0),
z ? z->GetComponent(j,0) : 0);
}
vtkCellArray *verts = vtkCellArray::New();
pd->SetVerts(verts);
verts->Delete();
for (int k = 0 ; k < npts ; k++)
{
verts->InsertNextCell(1);
verts->InsertCellPoint(k);
}
return pd;
}
// otherwise, what they get depends on the file contents
if ((topologicalDimension == 2 || topologicalDimension == 3) ||
(topologicalDimension <= 1 && spatialDimension > 1))
{
meshes[domain]->Register(NULL);
return meshes[domain];
}
else
{
//
// We're pretty sneaky about 1D plots -- we
// actual populated every n^2 (roughly) pairing
// of 1D values in the metadata but only
// construct the meshes here upon request.
//
if (curveIndices.count(meshname) <= 0)
EXCEPTION1(InvalidVariableException, meshname);
int curve = curveIndices[meshname];
int index1 = curveFirstVar[curve];
int index2 = curveSecondVar[curve];
// override domain
int curveDomain = curveDomains[curve];
if (index2 < 0)
EXCEPTION1(InvalidVariableException, meshname);
vtkFloatArray *var1 = vars[variableNames[index1]][curveDomain];
vtkFloatArray *var2 = vars[variableNames[index2]][curveDomain];
int nPts = var1->GetNumberOfTuples();
vtkFloatArray *vals = vtkFloatArray::New();
vals->SetNumberOfComponents(1);
vals->SetNumberOfTuples(nPts);
vals->SetName(meshname);
vtkRectilinearGrid *rg =
vtkVisItUtility::Create1DRGrid(nPts,VTK_FLOAT);
rg->GetPointData()->SetScalars(vals);
vtkDataArray *xc = rg->GetXCoordinates();
for (int j = 0 ; j < nPts ; j++)
{
xc->SetComponent(j, 0, var2->GetValue(j));
vals->SetValue(j, var1->GetValue(j));
}
vals->Delete();
return rg;
}
}
// ****************************************************************************
// Method: avtTecplotFileFormat::GetVar
//
// Purpose:
// Gets a scalar variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// domain The index of the domain. If there are NDomains, this
// value is guaranteed to be between 0 and NDomains-1,
// regardless of block origin.
// varname The name of the variable requested.
//
// Programmer: Jeremy Meredith
// Creation: November 16, 2004
//
// Modifications:
//
// Hank Childs, Sat Mar 5 10:03:47 PST 2005
// With dynamic load balancing, we may get here after calling FreeResources.
// Make sure we read the file again if necessary.
//
// Jeremy Meredith, Thu May 19 10:46:22 EDT 2011
// Make point mesh variables on a separate namespace from the normal mesh.
//
// ****************************************************************************
vtkDataArray *
avtTecplotFileFormat::GetVar(int domain, const char *vn)
{
if (!file_read)
ReadFile();
string varname(vn);
if (varname.length() > 7 && varname.substr(0,7) == "points/")
{
varname = varname.substr(7);
}
vars[varname][domain]->Register(NULL);
return vars[varname][domain];
}
// ****************************************************************************
// Method: avtTecplotFileFormat::GetVectorVar
//
// Purpose:
// Gets a vector variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// domain The index of the domain. If there are NDomains, this
// value is guaranteed to be between 0 and NDomains-1,
// regardless of block origin.
// varname The name of the variable requested.
//
// Programmer: Jeremy Meredith
// Creation: November 16, 2004
//
// ****************************************************************************
vtkDataArray *
avtTecplotFileFormat::GetVectorVar(int domain, const char *varname)
{
return NULL;
}
|
b7fb2224efc8fd3abee2e66ea5dce73e4e922c94
|
9823f12bbe144dae3c9decaba2bc38d3a2e94e90
|
/ebox/hardware/cortex-m4/rcc.h
|
6c0490ad15b1871e63e753dd2b1b6119d6720885
|
[
"MIT"
] |
permissive
|
eboxmaker/eBox_Framework
|
e8512fe26ecd729df97fdf38c875567677954858
|
b6c19c526568ac68df3032295c46cbd26212e111
|
refs/heads/master
| 2023-08-15T10:41:53.584433
| 2023-07-23T04:10:52
| 2023-07-23T04:10:52
| 95,169,842
| 133
| 68
|
MIT
| 2020-10-31T01:02:41
| 2017-06-23T01:07:19
|
C
|
UTF-8
|
C
| false
| false
| 191
|
h
|
rcc.h
|
#ifndef __RCC_H
#define __RCC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx.h"
void rcc_clock_cmd(uint32_t dev, FunctionalState state);
#ifdef __cplusplus
}
#endif
#endif
|
84d213c8d8e97d3671637dcfa44c3354b512a7ec
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/distrib/utils/sparkcrc/sparkcrc.c
|
f18d8356b55ce62174575747ed97f55008c1ee66
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 4,093
|
c
|
sparkcrc.c
|
/* $NetBSD: sparkcrc.c,v 1.3 2008/04/28 20:22:53 martin Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by David Brownlee
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
/*
* Trivial progarm to generate a crc suitable for use in a sparkive file
* Based on an algorithm by David Schwaderer
*/
uint16_t crclookup[256] = {
0, 49345, 49537, 320, 49921, 960, 640, 49729, 50689, 1728,
1920, 51009, 1280, 50625, 50305, 1088, 52225, 3264, 3456,
52545, 3840, 53185, 52865, 3648, 2560, 51905, 52097, 2880,
51457, 2496, 2176, 51265, 55297, 6336, 6528, 55617, 6912,
56257, 55937, 6720, 7680, 57025, 57217, 8000, 56577, 7616,
7296, 56385, 5120, 54465, 54657, 5440, 55041, 6080, 5760,
54849, 53761, 4800, 4992, 54081, 4352, 53697, 53377, 4160,
61441, 12480, 12672, 61761, 13056, 62401, 62081, 12864,
13824, 63169, 63361, 14144, 62721, 13760, 13440, 62529,
15360, 64705, 64897, 15680, 65281, 16320, 16000, 65089,
64001, 15040, 15232, 64321, 14592, 63937, 63617, 14400,
10240, 59585, 59777, 10560, 60161, 11200, 10880, 59969,
60929, 11968, 12160, 61249, 11520, 60865, 60545, 11328,
58369, 9408, 9600, 58689, 9984, 59329, 59009, 9792, 8704,
58049, 58241, 9024, 57601, 8640, 8320, 57409, 40961, 24768,
24960, 41281, 25344, 41921, 41601, 25152, 26112, 42689,
42881, 26432, 42241, 26048, 25728, 42049, 27648, 44225,
44417, 27968, 44801, 28608, 28288, 44609, 43521, 27328,
27520, 43841, 26880, 43457, 43137, 26688, 30720, 47297,
47489, 31040, 47873, 31680, 31360, 47681, 48641, 32448,
32640, 48961, 32000, 48577, 48257, 31808, 46081, 29888,
30080, 46401, 30464, 47041, 46721, 30272, 29184, 45761,
45953, 29504, 45313, 29120, 28800, 45121, 20480, 37057,
37249, 20800, 37633, 21440, 21120, 37441, 38401, 22208,
22400, 38721, 21760, 38337, 38017, 21568, 39937, 23744,
23936, 40257, 24320, 40897, 40577, 24128, 23040, 39617,
39809, 23360, 39169, 22976, 22656, 38977, 34817, 18624,
18816, 35137, 19200, 35777, 35457, 19008, 19968, 36545,
36737, 20288, 36097, 19904, 19584, 35905, 17408, 33985,
34177, 17728, 34561, 18368, 18048, 34369, 33281, 17088,
17280, 33601, 16640, 33217, 32897, 16448
};
int
main(int argc, char **argv)
{
unsigned char buf[1024];
FILE *fds;
int len;
int i;
int crc = 0;
if (argc != 2) {
fprintf(stderr, "Usage: sparkcrc filename\n");
exit(0);
}
if (!(fds = fopen(argv[1], "r")))
err(1, "Unable to open file '%s'", argv[1]);
while ((len = fread(buf, 1, sizeof(buf), fds)))
for (i = 0; i < len; ++i) {
crc = (crc >> 8) ^ crclookup[(crc & 0xff) ^ buf[i]];
}
fclose(fds);
printf("%d\n", (int)crc);
return (0);
}
|
794c2704c638ff46838fc4542cfdf34fc82279fb
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/PWGDQ/dielectron/macrosLMEE/Config_hmurakam_ElectronEfficiencyV2.C
|
a9f4e225bebdfcce843364cab5a1d02462260c43
|
[] |
permissive
|
alisw/AliPhysics
|
91bf1bd01ab2af656a25ff10b25e618a63667d3e
|
5df28b2b415e78e81273b0d9bf5c1b99feda3348
|
refs/heads/master
| 2023-08-31T20:41:44.927176
| 2023-08-31T14:51:12
| 2023-08-31T14:51:12
| 61,661,378
| 129
| 1,150
|
BSD-3-Clause
| 2023-09-14T18:48:45
| 2016-06-21T19:31:29
|
C++
|
UTF-8
|
C
| false
| false
| 28,740
|
c
|
Config_hmurakam_ElectronEfficiencyV2.C
|
void DoAdditionalWork(AliAnalysisTaskElectronEfficiencyV2* task);
void DoAdditionalWork2(AliAnalysisTaskElectronEfficiencyV2* task);
AliAnalysisFilter* SetupCuts(Int_t cutDefinition);
AliAnalysisCuts *SetupPIDcuts(Int_t cutDefinition);
AliDielectronVarCuts *SetupTrackCuts(Int_t cutDefinition);
AliDielectronEventCuts *GetEventCuts();
std::vector<bool> AddSingleLegMCSignal(AliAnalysisTaskElectronEfficiencyV2* task);
void AddPairMCSignal(AliAnalysisTaskElectronEfficiencyV2* task);
AliAnalysisTaskElectronEfficiencyV2* Config_Devel (TString name, int wagonnr);
TString names("cut0;cut1");
TString year = "16";
Int_t isAOD = 1;
Bool_t DoCentralityCorrection = kFALSE;
Bool_t cutlibPreloaded = kFALSE;
Int_t centrality = -1; // -1 for else, so min bias
TString generatorNameForMCSignal = "";//GP
TString generatorNameForULSSignal = "";//GP
//TString generatorNameForMCSignal = "Pythia CC_1;Pythia BB_1;Pythia B_1";//2016 HF MC
//TString generatorNameForULSSignal = "Pythia CC_1;Pythia BB_1;Pythia B_1";//2016 HF MC
//TString generatorNameForMCSignal = "Pythia CC_0;Pythia BB_0;Pythia B_0";//201[7,8] HF MC
//TString generatorNameForULSSignal = "Pythia CC_0;Pythia BB_0;Pythia B_0";//201[7,8] HF MC
//TString generatorNameForMCSignal = "Jpsi2ee_1;B2Jpsi2ee_1";//Jpsi MC
//TString generatorNameForULSSignal = "Jpsi2ee_1;B2Jpsi2ee_1";//Jpsi MC
Bool_t SetTOFCorrection = kTRUE;
bool SetGeneratedSmearingHistos = true;
bool DoPairing = true;
bool DoULSLS = true;
bool DeactivateLS = true;
//const Int_t triggerNames = AliVEvent::kMB;
const Int_t triggerNames = AliVEvent::kINT7;
Bool_t usePhiV = kFALSE;
Double_t maxMee = 0.04;
Double_t minphiv = 2.0;
const int nMCSignal = 0;
const int nCutsetting = 0;
const double minGenPt = 0.05;
const double maxGenPt = 100;
const double minGenEta = -1.5;
const double maxGenEta = 1.5;
// const double minPtCut = 0.2;
// const double minPtCut = 0.;
// const double maxPtCut = 100.0;
// const double minEtaCut = -100;
// const double maxEtaCut = 100;
const double minPtCut = 0.2;
// const double minPtCut = 0.2;
const double maxPtCut = 10.0;
const double minEtaCut = -0.8;
const double maxEtaCut = 0.8;
// binning of single leg histograms
bool usePtVector = true;
double ptBins[] = {0.000,0.050,0.100,0.150,0.200,0.250,0.300,0.350,0.400,0.450,0.500,0.550,0.600,0.650,0.700,0.750,0.800,0.850,0.900,0.950,
1.000,1.10,1.20,1.30,1.40,1.50,1.60,1.70,1.80,1.90,2.00,2.10,2.30,2.50,3.00,3.50,4.00,5.0,6.0,7.0,8.0, 9.0,10.};
const Int_t nBinsPt = ( sizeof(ptBins) / sizeof(ptBins[0]) )-1;
const double minPtBin = 0;
const double maxPtBin = 8;
const int stepsPtBin = 320;
const double minEtaBin = -1.0;
const double maxEtaBin = 1.0;
const int stepsEtaBin = 20;
const double minPhiBin = 0;
const double maxPhiBin = 6.3;
const int stepsPhiBin = 20;
const double minThetaBin = 0;
const double maxThetaBin = TMath::TwoPi();
const int stepsThetaBin = 60;
const double minMassBin = 0;
const double maxMassBin = 5;
const int stepsMassBin = 250;
const double minPairPtBin = 0;
const double maxPairPtBin = 8;
const int stepsPairPtBin = 160;
// Binning of resolution histograms
const int NbinsDeltaMom = 1000;
const double DeltaMomMin =-10.0;
const double DeltaMomMax = 10.0;
const int NbinsRelMom = 200;
const double RelMomMin = 0.0;
const double RelMomMax = 2.0;
const int NbinsDeltaEta = 100;
const double DeltaEtaMin = -0.4;
const double DeltaEtaMax = 0.4;
const int NbinsDeltaTheta = 100;
const double DeltaThetaMin = -0.4;
const double DeltaThetaMax = 0.4;
const int NbinsDeltaPhi = 100;
const double DeltaPhiMin = -0.4;
const double DeltaPhiMax = 0.4;
//Wrapper to return task with right name (same as config file)
//forward declarations
//get rif of cutlib
AliAnalysisTaskElectronEfficiencyV2* Config_Devel(TString name, int wagonnr)
{
AliAnalysisTaskElectronEfficiencyV2* task = new AliAnalysisTaskElectronEfficiencyV2(Form("%s%d",name.Data(), wagonnr));
// #########################################################
// #########################################################
// Possibility to set generator. If nothing set all generators are taken into account
// task->SetGeneratorName(generatorName);
task->SetGeneratorMCSignalName(generatorNameForMCSignal);
task->SetGeneratorULSSignalName(generatorNameForULSSignal);
// #########################################################
// #########################################################
// Event selection. Is the same for all the different cutsettings
task->SetEnablePhysicsSelection(kTRUE);
task->SetTriggerMask(triggerNames);
task->SetEventFilter(GetEventCuts()); //returns eventCuts from Config.
double centMin = 0.;
double centMax = 100.;
std::cout << "CentMin = " << centMin << " CentMax = " << centMax << std::endl;
task->SetCentrality(centMin, centMax);
// #########################################################
// #########################################################
// Set minimum and maximum values of generated tracks. Only used to save computing power.
// Do not set here your analysis pt-cuts
task->SetMinPtGen(minGenPt);
task->SetMaxPtGen(maxGenPt);
task->SetMinEtaGen(minGenEta);
task->SetMaxEtaGen(maxGenEta);
// #########################################################
// #########################################################
// Set minimum and maximum values of generated tracks. Only used to save computing power.
task->SetKinematicCuts(minPtCut, maxPtCut, minEtaCut, maxEtaCut);
// #########################################################
// #########################################################
// Set Binning
if (usePtVector == true) {
std::vector<double> ptBinsVec;
for (unsigned int i = 0; i < nBinsPt+1; ++i){
ptBinsVec.push_back(ptBins[i]);
}
task->SetPtBins(ptBinsVec);
}
else task->SetPtBinsLinear (minPtBin, maxPtBin, stepsPtBin);
task->SetEtaBinsLinear (minEtaBin, maxEtaBin, stepsEtaBin);
task->SetPhiBinsLinear (minPhiBin, maxPhiBin, stepsPhiBin);
task->SetThetaBinsLinear(minThetaBin, maxThetaBin, stepsThetaBin);
// Make arbitrary bins matching data!
std::vector<double> massBins = {0.00,0.02,0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26,0.28,0.30,0.32,0.34,0.36,0.38,0.40,0.42,0.44,0.46,0.48,0.50,0.52,0.54,0.56,0.58,0.60,0.62,0.64,0.66,0.68,0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.92,0.94,0.96,0.98,1.00,1.02,1.04,1.06,1.08,1.10,1.20,1.30,1.40,1.50,1.60,1.70,1.80,1.90,2.00,2.10,2.20,2.30,2.40,2.50,2.60,2.70,2.80,2.90,3.00,3.02,3.04,3.06,3.08,3.10,3.12,3.30,3.50,4.00,5.00};
task->SetMassBins (massBins);
// task->SetMassBinsLinear (minMassBin, maxMassBin, stepsMassBin);
std::vector<double> pteeBins= {0.000,0.050,0.100,0.150,0.200,0.250,0.300,0.350,0.400,0.450,0.500,0.550,0.600,0.650,0.700,0.750,0.800,0.850,0.900,0.950,1.000,1.100,1.200,1.300,1.400,1.500,1.600,1.700,1.800,1.900,2.000,2.100,2.200,2.300,2.400,2.500,2.600,2.700,2.800,2.900,3.000,3.100,3.200,3.300,3.400,3.500,3.600,3.700,3.800,3.900,4.000,4.100,4.200,4.300,4.400,4.500,5.000,5.500,6.000,6.500,7.000,8.000};
task->SetPairPtBins(pteeBins);
// task->SetPairPtBinsLinear(minPairPtBin, maxPairPtBin, stepsPairPtBin);
// #########################################################
// #########################################################
task->SetSmearGenerated (SetGeneratedSmearingHistos);
task->SetResolutionDeltaPtBinsLinear (DeltaMomMin, DeltaMomMax, NbinsDeltaMom);
task->SetResolutionRelPtBinsLinear (RelMomMin, RelMomMax, NbinsRelMom);
task->SetResolutionEtaBinsLinear (DeltaEtaMin, DeltaEtaMax, NbinsDeltaEta);
task->SetResolutionPhiBinsLinear (DeltaPhiMin, DeltaPhiMax, NbinsDeltaPhi);
task->SetResolutionThetaBinsLinear (DeltaThetaMin, DeltaThetaMax, NbinsDeltaTheta);
// #########################################################
// #########################################################
// Set centrality correction. If resoFilename = "" no correction is applied
// #########################################################
// #########################################################
// Set MCSignal and Cutsetting to fill the support histograms
task->SetSupportHistoMCSignalAndCutsetting(nMCSignal, nCutsetting);
// #########################################################
// #########################################################
// Pairing related config
task->SetDoPairing(DoPairing);
task->SetULSandLS(DoULSLS);
task->SetDeactivateLS(DeactivateLS);
task->SetPhiVBinsLinear(0, TMath::Pi(), 180);
task->SetFillPhiV(kFALSE);
//Set Phiv Cut
task->SetPhiVCut(usePhiV,maxMee,minphiv);
// #########################################################
// #########################################################
// Add MCSignals. Can be set to see differences of:
// e.g. secondaries and primaries. or primaries from charm and resonances
AddSingleLegMCSignal(task);
AddPairMCSignal(task);
std::vector<bool> DielectronsPairNotFromSameMother = AddSingleLegMCSignal(task);
task->AddMCSignalsWhereDielectronPairNotFromSameMother(DielectronsPairNotFromSameMother);
// #########################################################
// #########################################################
// Adding cutsettings
TObjArray* arrNames=names.Tokenize(";");
const Int_t nDie=arrNames->GetEntriesFast();
for (int iCut = 0; iCut < nDie; ++iCut){
TString cutDefinition(arrNames->At(iCut)->GetName());
AliAnalysisFilter* filter = SetupCuts(iCut);
filter->SetName(cutDefinition);
task->AddTrackCuts(filter);
DoAdditionalWork(task);
}
return task;
}
// #########################################################
// #########################################################
// Set mean and width correction for ITS, TPC and TOF
void DoAdditionalWork(AliAnalysisTaskElectronEfficiencyV2* task){
//Load PID post calibration
std::cout << task << std::endl;
std::cout << "starting DoAdditionalWork()\n";
if (SetTOFCorrection == true){
std::cout << "Loading TOF correction" << std::endl;
std::string file_name = "calMaps_TOF_mc.root";
TFile* _file = TFile::Open(file_name.c_str());
if (!_file){
gSystem->Exec(("alien_cp alien:///alice/cern.ch/user/h/hmurakam/PWGDQ/dielectron/calibLMEE/" + file_name + " file:.").c_str());
std::cout << "Copy TOF correction from Alien" << std::endl;
_file = TFile::Open(file_name.c_str());
}
else {
std::cout << "Correction loaded" << std::endl;
}
TH2F* histMean2DTOF = dynamic_cast<TH2F*>(_file->Get(Form("m%s",year.Data())));
TH2F* histWidth2DTOF = dynamic_cast<TH2F*>(_file->Get(Form("w%s",year.Data())));
printf("%s and %s\n",Form("m%s",year.Data()),Form("w%s",year.Data()));
for (Int_t i = 0; i <= histMean2DTOF->GetNbinsX()+1; i++){
for (Int_t k = 0; k <= histMean2DTOF->GetNbinsY()+1; k++){
if ( (i == 0) || (k == 0) || (i > histMean2DTOF->GetNbinsX()) || (k > histMean2DTOF->GetNbinsY())) { // under/overflows
histMean2DTOF->SetBinContent(i, k, 0.0 );
histWidth2DTOF->SetBinContent(i, k, 1.0 );
}
}
}
cout<<"Adding mean & width TOF PID correction" <<endl;
task->SetWidthCorrFunction(AliAnalysisTaskElectronEfficiencyV2::kTOF, histWidth2DTOF, AliDielectronVarManager::kPIn, AliDielectronVarManager::kEta, AliDielectronVarManager::kRefMultTPConly);
task->SetCentroidCorrFunction(AliAnalysisTaskElectronEfficiencyV2::kTOF, histMean2DTOF, AliDielectronVarManager::kPIn, AliDielectronVarManager::kEta, AliDielectronVarManager::kRefMultTPConly);
}
}
void DoAdditionalWork2(AliAnalysisTaskElectronEfficiencyV2* task){
//Load PID post calibration
std::cout << task << std::endl;
std::cout << "starting DoAdditionalWork()\n";
if (SetTOFCorrection == true){
std::cout << "Loading TOF correction" << std::endl;
std::string file_name = "outputTOF_MC.root";
TFile* _file = TFile::Open(file_name.c_str());
if (!_file){
gSystem->Exec(("alien_cp alien:///alice/cern.ch/user/h/hscheid/supportFiles/PIDrecalibration/TOF_MC/" + file_name + " file:.").c_str());
std::cout << "Copy TOF correction from Alien" << std::endl;
_file = TFile::Open(file_name.c_str());
}
else {
std::cout << "Correction loaded" << std::endl;
}
TH3D* mean = dynamic_cast<TH3D*>(_file->Get("sum_mean_correction"));
TH3D* width= dynamic_cast<TH3D*>(_file->Get("sum_width_correction"));
task->SetCentroidCorrFunction(AliAnalysisTaskElectronEfficiencyV2::kTOF, mean, AliDielectronVarManager::kP, AliDielectronVarManager::kEta, AliDielectronVarManager::kRefMultTPConly);
task->SetWidthCorrFunction (AliAnalysisTaskElectronEfficiencyV2::kTOF, width, AliDielectronVarManager::kP, AliDielectronVarManager::kEta, AliDielectronVarManager::kRefMultTPConly);
}
}
//______________________________________________________________________________________
AliAnalysisFilter* SetupCuts(Int_t cutDefinition)
{
AliAnalysisFilter *die = new AliAnalysisFilter("cuts","cuts");
// Setup specified cuts
// AOD track filter (needs to be first cut to speed up)
AliDielectronTrackCuts *trkFilter = new AliDielectronTrackCuts("TrkFilter","TrkFilter");
trkFilter->SetAODFilterBit(AliDielectronTrackCuts::kTPCqual);
trkFilter->SetRequireITSRefit(kTRUE);
trkFilter->SetRequireTPCRefit(kTRUE);
// trkFilter->SetClusterRequirementITS(AliDielectronTrackCuts::kSPD,AliDielectronTrackCuts::kFirst); // removed for track study
//Add track cuts to dielectron object
die->AddCuts(trkFilter);
// shared cluster cut -> maybe add to track cuts later, for variation
AliDielectronVarCuts *nSharedClsITS = new AliDielectronVarCuts("nSharedClsITS","nSharedClsITS");
nSharedClsITS->AddCut(AliDielectronVarManager::kNclsSITS, 1.0, 6.0, kTRUE);
if (cutDefinition != 0){ //for resolution maps: dont use any analysis (Track/PID) cuts
die->AddCuts(SetupPIDcuts(cutDefinition));
die->AddCuts(SetupPIDcuts(cutDefinition)); // removed for track study
die->AddCuts(SetupTrackCuts(cutDefinition)); // removed for track study
die->AddCuts(nSharedClsITS);
}
return die;
}
//______________________________________________________________________________________
//-----------------------------------pid------------------------------------------------
AliAnalysisCuts *SetupPIDcuts(Int_t cutDefinition){
std::cout << ">>>>>>>>>>>> Setup PID cuts! <<<<<<<<<<<<" << '\n';
//New PID standard cut: full PID setting with recovery of ITS and TOF tracks
//accepts an electron if it's identified in one of the 3 detector samples
AliDielectronPID *recover_TPC = new AliDielectronPID("recover_TPC","recover_TPC");
AliDielectronPID *recover_TOF = new AliDielectronPID("recover_TOF","recover_TOF");
//TPC electrons: includes electrons and exclude all possible other contributions using the TPC
//possible elemination of contamination using ITS and TOF
recover_TPC->AddCut(AliDielectronPID::kTPC,AliPID::kElectron, -3., 3. , 0. ,100., kFALSE);
recover_TPC->AddCut(AliDielectronPID::kTPC,AliPID::kPion, -100, 3.5 , 0.00 ,100., kTRUE);
recover_TPC->AddCut(AliDielectronPID::kTPC,AliPID::kKaon, -3, 3. , 0.200 ,100., kTRUE);
recover_TPC->AddCut(AliDielectronPID::kTPC,AliPID::kProton, -3, 3. , 0.200 ,100., kTRUE);
//TOF electrons: includes all electrons, exlcludes Pions using the TPC
//possible elemination of contamination using ITS
recover_TOF->AddCut(AliDielectronPID::kTPC,AliPID::kElectron, -3., 3. , 0.0 ,100., kFALSE);
recover_TOF->AddCut(AliDielectronPID::kTPC,AliPID::kPion, -100, 4. , 0.0 ,100., kTRUE);
recover_TOF->AddCut(AliDielectronPID::kTOF,AliPID::kElectron, -3. , 3. , 0.0 ,100., kFALSE, AliDielectronPID::kRequire);
// if the ITS identify a track as an electron include it back in
// AliDielectronCutGroup* recover_cg = new AliDielectronCutGroup("recover_cg","recover_cg",AliDielectronCutGroup::kCompAND);
AliDielectronCutGroup* recover_cg = new AliDielectronCutGroup("recover_cg","recover_cg",AliDielectronCutGroup::kCompOR);
recover_cg->AddCut(recover_TPC);
recover_cg->AddCut(recover_TOF);
AliAnalysisCuts* returnCut = NULL;
returnCut = reinterpret_cast<AliAnalysisCuts*> (recover_cg);
return returnCut;
}
//______________________________________________________________________________________
//-----------------------------------track cuts-----------------------------------------
//Reimplementation of SetupESDtrackCuts. Uses AliDielectronVarCuts to also be used in AOD analysis
AliDielectronVarCuts *SetupTrackCuts(Int_t cutDefinition){
AliDielectronVarCuts *fTrackCuts = new AliDielectronVarCuts("fTrackCuts","fTrackCuts");
//global
fTrackCuts->AddCut(AliDielectronVarManager::kPt, 0.2, 100.); //SetPtRange( 0.2 , 100. );
fTrackCuts->AddCut(AliDielectronVarManager::kEta,-0.8, 0.8); //SetEtaRange( -0.8 , 0.8 );
fTrackCuts->AddCut(AliDielectronVarManager::kImpactParXY, -1., 1.); //SetMaxDCAToVertexZ(3.);
fTrackCuts->AddCut(AliDielectronVarManager::kImpactParZ, -3., 3.); //SetMaxDCAToVertexXY(1.);
fTrackCuts->AddCut(AliDielectronVarManager::kNclsTPC, 100., 160.); //SetMinNClustersTPC(100);
fTrackCuts->AddCut(AliDielectronVarManager::kNFclsTPCr, 100., 160.); //SetMinNClustersTPC(100);
fTrackCuts->AddCut(AliDielectronVarManager::kNFclsTPCfCross, 0.5, 1.1); //SetMinRatioCrossedRowsOverFindableClustersTPC(0.5);
fTrackCuts->AddCut(AliDielectronVarManager::kTPCchi2Cl, 0.0, 4.); //SetMaxChi2PerClusterTPC(4);
fTrackCuts->AddCut(AliDielectronVarManager::kNclsITS, 3. , 10.); //SetMinNClustersITS(3);
fTrackCuts->AddCut(AliDielectronVarManager::kITSchi2Cl, 0.0, 5.5); //SetMaxChi2PerClusterITS(5.5);
AliDielectronVarCuts *returnCut = NULL;
returnCut = fTrackCuts;
return returnCut;
}
AliDielectronEventCuts *GetEventCuts(){
AliDielectronEventCuts *eventCuts=new AliDielectronEventCuts("eventCuts","Vertex Track && |vtxZ|<10 && ncontrib>0");
eventCuts->SetVertexType(AliDielectronEventCuts::kVtxSPD); // AOD
eventCuts->SetRequireVertex();
eventCuts->SetVertexZ(-10.,10.);
eventCuts->SetMinVtxContributors(1);
return eventCuts;
}
// #########################################################
// #########################################################
std::vector<bool> AddSingleLegMCSignal(AliAnalysisTaskElectronEfficiencyV2* task){
AliDielectronSignalMC partFinalState("partFinalState","partFinalState");
partFinalState.SetLegPDGs(0,1);//dummy second leg (never MCtrue)\n"
// partFinalState.SetCheckBothChargesLegs(kTRUE,kTRUE);
partFinalState.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
AliDielectronSignalMC eleFinalState("eleFinalState","eleFinalState");
eleFinalState.SetLegPDGs(11,1);//dummy second leg (never MCtrue)\n"
eleFinalState.SetCheckBothChargesLegs(kTRUE,kTRUE);
eleFinalState.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
AliDielectronSignalMC eleFinalStateFromSameMotherMeson("eleFinalStateFromSameMotherMeson","eleFinalStateFromSameMotherMeson");
eleFinalStateFromSameMotherMeson.SetLegPDGs(11,1);//dummy second leg (never MCtrue)\n"
eleFinalStateFromSameMotherMeson.SetCheckBothChargesLegs(kTRUE,kTRUE);
eleFinalStateFromSameMotherMeson.SetMotherPDGs(600, 600); // open charm mesons and baryons together
eleFinalStateFromSameMotherMeson.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//
AliDielectronSignalMC eleFinalStateFromD("eleFinalStateFromD","eleFinalStateFromD");
eleFinalStateFromD.SetLegPDGs(11,1);//dummy second leg (never MCtrue)\n"
eleFinalStateFromD.SetCheckBothChargesLegs(kTRUE,kTRUE);
eleFinalStateFromD.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
eleFinalStateFromD.SetMotherPDGs(402, 402); // open charm mesons and baryons together
eleFinalStateFromD.SetCheckBothChargesMothers(kTRUE,kTRUE);
//
AliDielectronSignalMC eleFinalStateFromB("eleFinalStateFromB","eleFinalStateFromB");
eleFinalStateFromB.SetLegPDGs(11,1);//dummy second leg (never MCtrue)\n"
eleFinalStateFromB.SetCheckBothChargesLegs(kTRUE,kTRUE);
eleFinalStateFromB.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
eleFinalStateFromB.SetMotherPDGs(502, 502); // open charm mesons and baryons together
eleFinalStateFromB.SetCheckBothChargesMothers(kTRUE,kTRUE);
// AliDielectronSignalMC eleSecondary("eleSecondary","eleSecondary");
// eleSecondary.SetLegPDGs(11,1);//dummy second leg (never MCtrue)\n"
// eleSecondary.SetCheckBothChargesLegs(kTRUE,kTRUE);
// eleSecondary.SetLegSources(AliDielectronSignalMC::kSecondary, AliDielectronSignalMC::kSecondary);
// task->AddSingleLegMCSignal(eleSecondary);
//
// AliDielectronSignalMC eleDontCare("eleDontCare","eleDontCare");
// eleDontCare.SetLegPDGs(11,1);//dummy second leg (never MCtrue)\n"
// eleDontCare.SetCheckBothChargesLegs(kTRUE,kTRUE);
// eleDontCare.SetLegSources(AliDielectronSignalMC::kDontCare, AliDielectronSignalMC::kDontCare);
// task->AddSingleLegMCSignal(eleDontCare);
// task->AddSingleLegMCSignal(partFinalState);
task->AddSingleLegMCSignal(eleFinalState);
// task->AddSingleLegMCSignal(eleFinalStateFromPion);
task->AddSingleLegMCSignal(eleFinalStateFromD);
task->AddSingleLegMCSignal(eleFinalStateFromB);
// task->AddSingleLegMCSignal(eleFinalStateFromSameMotherMeson);
// this is used to get electrons from charmed mesons in a environment where GEANT is doing the decay of D mesons, like in LHC18b5a
// ordering is according to MCSignals of single legs
std::vector<bool> DielectronsPairNotFromSameMother;
DielectronsPairNotFromSameMother.push_back(false);
DielectronsPairNotFromSameMother.push_back(false);//true
DielectronsPairNotFromSameMother.push_back(false);//true
// DielectronsPairNotFromSameMother.push_back(false);
return DielectronsPairNotFromSameMother;
}
// #########################################################
// #########################################################
void AddPairMCSignal(AliAnalysisTaskElectronEfficiencyV2* task){
AliDielectronSignalMC pair_sameMother("sameMother","sameMother");
pair_sameMother.SetLegPDGs(11,-11);
pair_sameMother.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother.SetMotherPDGs(22,22,kTRUE,kTRUE); // exclude conversion electrons. should have no effect on final state ele.
AliDielectronSignalMC pair_sameMother_pion("sameMother_pion","sameMother_pion");
pair_sameMother_pion.SetLegPDGs(11,-11);
pair_sameMother_pion.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_pion.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_pion.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_pion.SetMotherPDGs(111,111); //
AliDielectronSignalMC pair_sameMother_pion_anySource("sameMother_pion_anySource","sameMother_pion_anySource");
pair_sameMother_pion_anySource.SetLegPDGs(11,-11);
pair_sameMother_pion_anySource.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_pion_anySource.SetLegSources(AliDielectronSignalMC::kDontCare, AliDielectronSignalMC::kDontCare);
//mother
pair_sameMother_pion_anySource.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_pion_anySource.SetMotherPDGs(111,111); //
AliDielectronSignalMC pair_sameMother_pion_fromK("sameMother_pion_fromK0","sameMother_pion_fromK0");
pair_sameMother_pion_fromK.SetLegPDGs(11,-11);
pair_sameMother_pion_fromK.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_pion_fromK.SetLegSources(AliDielectronSignalMC::kDontCare, AliDielectronSignalMC::kDontCare);
//mother
pair_sameMother_pion_fromK.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_pion_fromK.SetMotherPDGs(111,111); //
// grand mother
pair_sameMother_pion_fromK.SetGrandMotherPDGs(310,310);
AliDielectronSignalMC pair_sameMother_eta("sameMother_eta","sameMother_eta");
pair_sameMother_eta.SetLegPDGs(11,-11);
pair_sameMother_eta.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_eta.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_eta.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_eta.SetMotherPDGs(221,221); //
AliDielectronSignalMC pair_sameMother_etaP("sameMother_etaP","sameMother_etaP");
pair_sameMother_etaP.SetLegPDGs(11,-11);
pair_sameMother_etaP.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_etaP.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_etaP.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_etaP.SetMotherPDGs(331,331); //
AliDielectronSignalMC pair_sameMother_rho("sameMother_rho","sameMother_rho");
pair_sameMother_rho.SetLegPDGs(11,-11);
pair_sameMother_rho.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_rho.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_rho.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_rho.SetMotherPDGs(113, 113); //
AliDielectronSignalMC pair_sameMother_omega("sameMother_omega","sameMother_omega");
pair_sameMother_omega.SetLegPDGs(11,-11);
pair_sameMother_omega.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_omega.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_omega.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_omega.SetMotherPDGs(223, 223); //
AliDielectronSignalMC pair_sameMother_phi("sameMother_phi","sameMother_phi");
pair_sameMother_phi.SetLegPDGs(11,-11);
pair_sameMother_phi.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_phi.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_phi.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_phi.SetMotherPDGs(333, 333); //
AliDielectronSignalMC pair_sameMother_jpsi("sameMother_jpsi","sameMother_jpsi");
pair_sameMother_jpsi.SetLegPDGs(11,-11);
pair_sameMother_jpsi.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_jpsi.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_jpsi.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_jpsi.SetMotherPDGs(443, 443); //
AliDielectronSignalMC pair_sameMother_CharmedMesonsWithSameMother("CharmedMesonsWithSameMother","CharmedMesonsWithSameMother");
pair_sameMother_CharmedMesonsWithSameMother.SetLegPDGs(11,-11);
pair_sameMother_CharmedMesonsWithSameMother.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_sameMother_CharmedMesonsWithSameMother.SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
//mother
pair_sameMother_CharmedMesonsWithSameMother.SetMothersRelation(AliDielectronSignalMC::kSame);
pair_sameMother_CharmedMesonsWithSameMother.SetMotherPDGs(402, 402); //
AliDielectronSignalMC pair_conversion("pair_conversion","pair_conversion");
pair_conversion.SetLegPDGs(11,-11);
pair_conversion.SetCheckBothChargesLegs(kTRUE,kTRUE);
pair_conversion.SetLegSources(AliDielectronSignalMC::kSecondary, AliDielectronSignalMC::kSecondary);
//mother
pair_conversion.SetMothersRelation(AliDielectronSignalMC::kSame);
task->AddPairMCSignal(pair_sameMother);
// task->AddPairMCSignal(pair_sameMother_pion);
// task->AddPairMCSignal(pair_sameMother_pion_anySource);
// task->AddPairMCSignal(pair_sameMother_pion_fromK);
// task->AddPairMCSignal(pair_sameMother_eta);
// task->AddPairMCSignal(pair_sameMother_etaP);
// task->AddPairMCSignal(pair_sameMother_rho);
// task->AddPairMCSignal(pair_sameMother_omega);
// task->AddPairMCSignal(pair_sameMother_phi);
// task->AddPairMCSignal(pair_sameMother_jpsi);
// task->AddPairMCSignal(pair_sameMother_CharmedMesonsWithSameMother);
// task->AddPairMCSignal(pair_conversion);
}
|
c225dae8a64314e4b234b7aed473f0356d475d24
|
b5e9996707d879b3b01dbb45e6478b667b22fac7
|
/ids.c
|
79c213774c25cb4906191360c1f251042a0c122e
|
[
"ISC",
"GPL-1.0-or-later"
] |
permissive
|
kristapsdz/openrsync
|
6cafc395f68389ac92e9f3786790124013299b10
|
f50d0f8204ea18306a0c29c6ae850292ea826995
|
refs/heads/master
| 2023-08-23T10:30:31.062794
| 2022-05-08T21:47:56
| 2022-05-08T21:47:56
| 166,116,085
| 401
| 30
|
ISC
| 2023-04-12T05:24:54
| 2019-01-16T21:38:50
|
C
|
UTF-8
|
C
| false
| false
| 7,155
|
c
|
ids.c
|
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#include <assert.h>
#include <grp.h>
#include <inttypes.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
/*
* Free a list of struct ident previously allocated with idents_add().
* Does nothing if the pointer is NULL.
*/
void
idents_free(struct ident *p, size_t sz)
{
size_t i;
if (p == NULL)
return;
for (i = 0; i < sz; i++)
free(p[i].name);
free(p);
}
/*
* Given a list of files with the identifiers as set by the sender,
* re-assign the identifiers from the list of remapped ones.
* Don't ever remap wheel/root.
* If we can't find the gid in the list (when, e.g., being sent by the
* daemon), don't try to map it.
*/
void
idents_assign_gid(struct sess *sess, struct flist *fl, size_t flsz,
const struct ident *ids, size_t idsz)
{
size_t i, j;
assert(!sess->opts->numeric_ids);
for (i = 0; i < flsz; i++) {
if (fl[i].st.gid == 0)
continue;
for (j = 0; j < idsz; j++)
if ((int32_t)fl[i].st.gid == ids[j].id)
break;
if (j < idsz)
fl[i].st.gid = ids[j].mapped;
}
}
/*
* Like idents_assign_gid().
*/
void
idents_assign_uid(struct sess *sess, struct flist *fl, size_t flsz,
const struct ident *ids, size_t idsz)
{
size_t i, j;
assert(!sess->opts->numeric_ids);
for (i = 0; i < flsz; i++) {
if (fl[i].st.uid == 0)
continue;
for (j = 0; j < idsz; j++)
if ((int32_t)fl[i].st.uid == ids[j].id)
break;
if (j < idsz)
fl[i].st.uid = ids[j].mapped;
}
}
/*
* Given a list of identifiers from the remote host, fill in our local
* identifiers of the same names.
* Use the remote numeric identifier if we can't find the identifier OR the
* identifier is zero (wheel/root).
* FIXME: we should at least warn when we can't find an identifier, use
* the numeric id, and that numeric id is assigned to a different user.
*/
void
idents_remap(struct sess *sess, int isgid, struct ident *ids, size_t idsz)
{
size_t i;
struct group *grp;
struct passwd *usr;
uint32_t id;
int valid;
assert(!sess->opts->numeric_ids);
for (i = 0; i < idsz; i++) {
assert(ids[i].id != 0);
/* Start by getting our local representation. */
valid = id = 0;
if (isgid) {
grp = getgrnam(ids[i].name);
if (grp) {
id = grp->gr_gid;
valid = 1;
}
} else {
usr = getpwnam(ids[i].name);
if (usr) {
id = usr->pw_uid;
valid = 1;
}
}
/*
* (1) Empty names inherit.
* (2) Unknown identifier names inherit.
* (3) Wheel/root inherits.
* (4) Otherwise, use the local identifier.
*/
if (ids[i].name[0] == '\0')
ids[i].mapped = ids[i].id;
else if (!valid)
ids[i].mapped = ids[i].id;
else
ids[i].mapped = id;
LOG4("remapped identifier %s: %" PRId32 " -> %" PRId32,
ids[i].name, ids[i].id, ids[i].mapped);
}
}
/*
* If "id" is not part of the list of known users or groups (depending
* upon "isgid", add it.
* This also verifies that the name isn't too long.
* Does nothing with user/group zero.
* Return zero on failure, non-zero on success.
*/
int
idents_add(int isgid, struct ident **ids, size_t *idsz, int32_t id)
{
struct group *grp;
struct passwd *usr;
size_t i, sz;
void *pp;
const char *name;
if (id == 0)
return 1;
for (i = 0; i < *idsz; i++)
if ((*ids)[i].id == id)
return 1;
/*
* Look up the reference in a type-specific way.
* Make sure that the name length is sane: we transmit it using
* a single byte.
*/
assert(i == *idsz);
if (isgid) {
if ((grp = getgrgid((gid_t)id)) == NULL) {
ERR("%" PRIu32 ": unknown gid", id);
return 0;
}
name = grp->gr_name;
} else {
if ((usr = getpwuid((uid_t)id)) == NULL) {
ERR("%" PRIu32 ": unknown uid", id);
return 0;
}
name = usr->pw_name;
}
if ((sz = strlen(name)) > UINT8_MAX) {
ERRX("%" PRIu32 ": name too long: %s", id, name);
return 0;
} else if (sz == 0) {
ERRX("%" PRIu32 ": zero-length name", id);
return 0;
}
/* Add the identifier to the array. */
pp = reallocarray(*ids, *idsz + 1, sizeof(struct ident));
if (pp == NULL) {
ERR("reallocarray");
return 0;
}
*ids = pp;
(*ids)[*idsz].id = id;
(*ids)[*idsz].name = strdup(name);
if ((*ids)[*idsz].name == NULL) {
ERR("strdup");
return 0;
}
LOG4("adding identifier to list: %s (%u)",
(*ids)[*idsz].name, (*ids)[*idsz].id);
(*idsz)++;
return 1;
}
/*
* Send a list of struct ident.
* See idents_recv().
* We should only do this if we're preserving gids/uids.
* Return zero on failure, non-zero on success.
*/
int
idents_send(struct sess *sess,
int fd, const struct ident *ids, size_t idsz)
{
size_t i, sz;
for (i = 0; i < idsz; i++) {
assert(ids[i].name != NULL);
assert(ids[i].id != 0);
sz = strlen(ids[i].name);
assert(sz > 0 && sz <= UINT8_MAX);
if (!io_write_uint(sess, fd, ids[i].id)) {
ERRX1("io_write_uint");
return 0;
} else if (!io_write_byte(sess, fd, sz)) {
ERRX1("io_write_byte");
return 0;
} else if (!io_write_buf(sess, fd, ids[i].name, sz)) {
ERRX1("io_write_buf");
return 0;
}
}
if (!io_write_int(sess, fd, 0)) {
ERRX1("io_write_int");
return 0;
}
return 1;
}
/*
* Receive a list of struct ident.
* See idents_send().
* We should only do this if we're preserving gids/uids.
* Return zero on failure, non-zero on success.
*/
int
idents_recv(struct sess *sess,
int fd, struct ident **ids, size_t *idsz)
{
uint32_t id;
uint8_t sz;
void *pp;
for (;;) {
if (!io_read_uint(sess, fd, &id)) {
ERRX1("io_read_uint");
return 0;
} else if (id == 0)
break;
pp = reallocarray(*ids,
*idsz + 1, sizeof(struct ident));
if (pp == NULL) {
ERR("reallocarray");
return 0;
}
*ids = pp;
memset(&(*ids)[*idsz], 0, sizeof(struct ident));
/*
* When reading the size, warn if we get a size of zero.
* The spec doesn't allow this, but we might have a
* noncomformant or adversarial sender.
*/
if (!io_read_byte(sess, fd, &sz)) {
ERRX1("io_read_byte");
return 0;
} else if (sz == 0)
WARNX("zero-length name in identifier list");
assert(id < INT32_MAX);
(*ids)[*idsz].id = id;
(*ids)[*idsz].name = calloc(sz + 1, 1);
if ((*ids)[*idsz].name == NULL) {
ERR("calloc");
return 0;
}
if (!io_read_buf(sess, fd, (*ids)[*idsz].name, sz)) {
ERRX1("io_read_buf");
return 0;
}
(*idsz)++;
}
return 1;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.