diff --git a/Tests/elf_to_hex/Makefile b/Tests/elf_to_hex/Makefile index 9375211..7405cde 100644 --- a/Tests/elf_to_hex/Makefile +++ b/Tests/elf_to_hex/Makefile @@ -3,8 +3,20 @@ CC = gcc +# the LIBERARY path needs to be set for Apple devices, e.g., +# LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib" + +uname_S := $(shell uname -s) + +CFLAGS = -g -o elf_to_hex elf_to_hex.c -lelf + +ifeq ($(uname_S), Darwin) + CC = clang++ + APPLE_FLAGS = -I /opt/homebrew/lib -I /opt/homebrew/Cellar/libelf/0.8.13_1/include/ +endif + elf_to_hex: elf_to_hex.c - gcc -g -o elf_to_hex elf_to_hex.c -lelf + $(CC) $(CFLAGS) $(APPLE_FLAGS) # ================================================================ @@ -14,4 +26,4 @@ clean: .PHONY: full_clean full_clean: - rm -f *~ elf_to_hex + rm -f *~ elf_to_hex \ No newline at end of file diff --git a/Tests/elf_to_hex/elf_to_hex.c b/Tests/elf_to_hex/elf_to_hex.c index c691f25..7bf710a 100644 --- a/Tests/elf_to_hex/elf_to_hex.c +++ b/Tests/elf_to_hex/elf_to_hex.c @@ -3,6 +3,37 @@ // This program reads an ELF file and outputs a Verilog hex memory // image file (suitable for reading using $readmemh). +// Modifications for CHERI as well as compiling on APPLE devices: + + /*- + * Copyright (c) 2022 Jonathan Woodruff + * Copyright (c) 2022 Franz Fuchs + * All rights reserved. + * + * This software was developed by the University of Cambridge + * Department of Computer Science and Technology under the + * SIPP (Secure IoT Processor Platform with Remote Attestation) + * project funded by EPSRC: EP/S030868/1 + * + * @BERI_LICENSE_HEADER_START@ + * + * Licensed to BERI Open Systems C.I.C. (BERI) under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. BERI licenses this + * file to you under the BERI Hardware-Software License, Version 1.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.beri-open-systems.org/legal/license-1-0.txt + * + * Unless required by applicable law or agreed to in writing, Work 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. + * + * @BERI_LICENSE_HEADER_END@ + */ + // ================================================================ // Standard C includes @@ -12,7 +43,14 @@ #include #include #include + +#ifdef __APPLE__ +#include +#include +#else #include +#endif + // ================================================================ // Memory buffer into which we load the ELF file before @@ -35,7 +73,12 @@ #define MIN_MEM_ADDR_1GB BASE_ADDR_B #define MAX_MEM_ADDR_1GB (BASE_ADDR_B + 0x40000000lu) +#ifdef __APPLE__ +std::vector mem_buf(MAX_MEM_ADDR_1GB-MIN_MEM_ADDR_1GB,0); +#else uint8_t mem_buf [MAX_MEM_ADDR_1GB-MIN_MEM_ADDR_1GB]; +#endif + // Features of the ELF binary int bitwidth;