|
|
|||
File indexing completed on 2026-04-09 07:49:15
0001 /* Copyright (C) Arm Limited, 2023 All rights reserved. 0002 0003 https://developer.arm.com/documentation/ka004805/latest/ 0004 0005 The example code is provided to you as an aid to learning when working 0006 with Arm-based technology, including but not limited to programming tutorials. 0007 Arm hereby grants to you, subject to the terms and conditions of this Licence, 0008 a non-exclusive, non-transferable, non-sub-licensable, free-of-charge licence, 0009 to use and copy the Software solely for the purpose of demonstration and 0010 evaluation. 0011 0012 You accept that the Software has not been tested by Arm therefore the Software 0013 is provided "as is", without warranty of any kind, express or implied. In no 0014 event shall the authors or copyright holders be liable for any claim, damages 0015 or other liability, whether in action or contract, tort or otherwise, arising 0016 from, out of or in connection with the Software or the use of Software. */ 0017 0018 #include <stdint.h> 0019 #include <stdlib.h> 0020 #include <stdio.h> 0021 0022 // Macro to help create 128-bit literals from two 64-bit literals 0023 #define MAKE128CONST(hi,lo) ((((__uint128_t)hi << 64) | lo)) 0024 0025 // Helper type to use to print 128-bit literals as hexadecimal values 0026 typedef union 0027 { 0028 __uint128_t as_128; 0029 struct 0030 { 0031 uint64_t lo; 0032 uint64_t hi; 0033 } as_2x64; 0034 } reinterpret128_t; 0035 0036 // Function to write a 128-bit value to memory 0037 __attribute__((always_inline)) static void reg128_write(uint64_t addr, __uint128_t data) 0038 { 0039 volatile __uint128_t *as_ptr = (volatile __uint128_t *)addr; 0040 *as_ptr = data; 0041 } 0042 0043 // Function to read a 128-bit value from memory 0044 __attribute((always_inline)) static __uint128_t reg128_read(uint64_t addr) 0045 { 0046 volatile __uint128_t *as_ptr = (volatile __uint128_t *)addr; 0047 return *as_ptr; 0048 } 0049 0050 // Function to convert a 128-bit value to a zero-padded hexadecimcal string 0051 __attribute__((always_inline)) static const char * reg128_as_hex(__uint128_t data) 0052 { 0053 reinterpret128_t temp = *((reinterpret128_t *)(&data)); 0054 char * buffer = (char*)malloc(33); 0055 sprintf(buffer, "%016llx%016llx", temp.as_2x64.hi, temp.as_2x64.lo); 0056 return buffer; 0057 } 0058 0059 int main(void) 0060 { 0061 // 128-bit literals are not supported. Instead, use the MAKE128CONST macro. 0062 // __uint128_t data = 0x44444444333333332222222211111111; 0063 0064 uint64_t buffer[2] ; 0065 uint64_t* ptr = &buffer[0] ; 0066 uint64_t iptr = (uint64_t)(ptr) ; 0067 0068 // Write 128-bit constant value to an address. 0069 reg128_write(iptr, MAKE128CONST(0x4444444433333333ULL, 0x2222222211111111ULL)); 0070 0071 // Print 128-bit value read from an address. 0072 // The helper function reg128_as_hex is used to convert a 128-bit value to a hex string without the '0x' suffix. 0073 printf("0x%s\n", reg128_as_hex(reg128_read(iptr))); 0074 0075 return 0; 0076 } 0077
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|