Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:21

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <rtems/record.h>
0033 #include <rtems/version.h>
0034 #include <rtems.h>
0035 
0036 #include <sys/endian.h>
0037 #include <string.h>
0038 
0039 size_t _Record_Stream_header_initialize( Record_Stream_header *header )
0040 {
0041   rtems_record_item *items;
0042   size_t             available;
0043   size_t             used;
0044   const char        *str;
0045 
0046 #if BYTE_ORDER == LITTLE_ENDIAN
0047 #if __INTPTR_WIDTH__ == 32
0048   header->format = RTEMS_RECORD_FORMAT_LE_32,
0049 #elif __INTPTR_WIDTH__ == 64
0050   header->format = RTEMS_RECORD_FORMAT_LE_64,
0051 #else
0052 #error "unexpected __INTPTR_WIDTH__"
0053 #endif
0054 #elif BYTE_ORDER == BIG_ENDIAN
0055 #if __INTPTR_WIDTH__ == 32
0056   header->format = RTEMS_RECORD_FORMAT_BE_32,
0057 #elif __INTPTR_WIDTH__ == 64
0058   header->format = RTEMS_RECORD_FORMAT_BE_64,
0059 #else
0060 #error "unexpected __INTPTR_WIDTH__"
0061 #endif
0062 #else
0063 #error "unexpected BYTE_ORDER"
0064 #endif
0065 
0066   header->magic = RTEMS_RECORD_MAGIC;
0067 
0068   header->Version.event = RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_VERSION );
0069   header->Version.data = RTEMS_RECORD_THE_VERSION;
0070 
0071   header->Processor_maximum.event =
0072     RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_PROCESSOR_MAXIMUM );
0073   header->Processor_maximum.data = rtems_scheduler_get_processor_maximum() - 1;
0074 
0075   header->Count.event = RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_PER_CPU_COUNT );
0076   header->Count.data = _Record_Configuration.item_count;
0077 
0078   header->Frequency.event =
0079     RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_FREQUENCY );
0080   header->Frequency.data = rtems_counter_frequency();
0081 
0082   items = header->Info;
0083   available = RTEMS_ARRAY_SIZE( header->Info );
0084 
0085   str = CPU_NAME;
0086   used = _Record_String_to_items(
0087     RTEMS_RECORD_ARCH,
0088     str,
0089     strlen( str ),
0090     items,
0091     available
0092   );
0093   items += used;
0094   available -= used;
0095 
0096   str = CPU_MODEL_NAME;
0097   used = _Record_String_to_items(
0098     RTEMS_RECORD_MULTILIB,
0099     str,
0100     strlen( str ),
0101     items,
0102     available
0103   );
0104   items += used;
0105   available -= used;
0106 
0107   str = rtems_board_support_package();
0108   used = _Record_String_to_items(
0109     RTEMS_RECORD_BSP,
0110     str,
0111     strlen( str ),
0112     items,
0113     available
0114   );
0115   items += used;
0116   available -= used;
0117 
0118   str = rtems_version_control_key();
0119   used = _Record_String_to_items(
0120     RTEMS_RECORD_VERSION_CONTROL_KEY,
0121     str,
0122     strlen( str ),
0123     items,
0124     available
0125   );
0126   items += used;
0127   available -= used;
0128 
0129   str = __VERSION__;
0130   used = _Record_String_to_items(
0131     RTEMS_RECORD_TOOLS,
0132     str,
0133     strlen( str ),
0134     items,
0135     available
0136   );
0137   items += used;
0138 
0139   return (size_t) ( (char *) items - (char *) header );
0140 }