1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SGSRTCID_H 27 #define _SGSRTCID_H 28 29 #include <sys/debug.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 36 /* 37 * This file defines the Rtc_id structure that is found at the beginning 38 * of linker configuration files. It resides at this level so that 39 * it can be accessed by file(1) as well as by crle(1) and the 40 * runtime linker (ld.so.1). The rest of the data structures for 41 * config files are found in usr/src/cmd/sgs/include/rtc.h 42 * 43 * The use of sizeof(char) data (no byte order issue) and explicit 44 * padding in the definition of Rtc_id ensures that it will have 45 * exactly the same layout on all systems, and will have a 46 * size of 16 bytes. The same layout means all systems can read it. 47 * the same size means that any data can be safely placed immediately 48 * following it, without the need for alignment. 49 */ 50 51 /* 52 * Identification header. 53 */ 54 typedef struct { 55 uchar_t id_magic0; /* RTC_ID_MAG0 */ 56 uchar_t id_magic1; /* RTC_ID_MAG1 */ 57 uchar_t id_magic2; /* RTC_ID_MAG2 */ 58 uchar_t id_magic3; /* RTC_ID_MAG3 */ 59 uchar_t id_class; /* File class/capacity (ELFCLASS constant) */ 60 uchar_t id_data; /* Data encoding (ELFDATA constant) */ 61 uchar_t id_machine; /* Architecture (ELF EM_ constant) */ 62 uchar_t id_pad[9]; /* Ensure size is 16 bytes */ 63 } Rtc_id; 64 65 /* 66 * This structure is a raw file header structured to be platform agnostic, it 67 * must always be precisely 16 bytes 68 */ 69 CTASSERT(sizeof (Rtc_id) == 16); 70 71 #define RTC_ID_MAG0 '\077' /* ? */ 72 #define RTC_ID_MAG1 'R' /* Runtime */ 73 #define RTC_ID_MAG2 'L' /* Linker */ 74 #define RTC_ID_MAG3 'C' /* Configuration */ 75 76 /* 77 * Ensure that the largest relevant machine constant will not grow beyond 78 * maximum value representable by an unsigned byte without our 79 * being alerted to it. 80 * 81 * This is a cop out because while e_machine has grown beyond this limit, the 82 * machines illumos needs to describe have not and are unlikely to. 83 * 84 * A more complete implementation would introduce an id_machinehi into the 85 * padding, to hold the high byte. 86 */ 87 #if !defined(__x86) && !defined(__sparc__) 88 #error "Ensure machine constant fits in a byte. Format may require revision." 89 #endif 90 91 /* 92 * Check the 4 bytes starting at the given address to see if 93 * they contain the Rtc_id magic number. The type of the address 94 * is unimportant as long as it is valid, because RTC_ID_TEST() 95 * will cast it to (uchar_t *). 96 */ 97 #define RTC_ID_TEST(addr) \ 98 ((RTC_ID_MAG0 == *((uchar_t *)addr)) && \ 99 (RTC_ID_MAG1 == *(((uchar_t *)addr) + 1)) && \ 100 (RTC_ID_MAG2 == *(((uchar_t *)addr) + 2)) && \ 101 (RTC_ID_MAG3 == *(((uchar_t *)addr) + 3))) 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif /* _SGSRTCID_H */ 108