# HG changeset patch # User Paul Boddie # Date 1680887458 -7200 # Node ID a60bfff28db32ee27f2e7cfb6cb4b3a7d09768ae # Parent 764d7c541daa496365c354997c431d0907e8289a Added support for indicating the structure member alignment employed when encoding messages. This is not actually helpful to resolve x86 ABI problems, however. Although a modified minimum alignment would permit interoperability with the problematic L4Re implementation of the dataspace protocol, it would affect interoperability with other components that encode their messages differently. diff -r 764d7c541daa -r a60bfff28db3 config.c --- a/config.c Thu Mar 23 00:32:22 2023 +0100 +++ b/config.c Fri Apr 07 19:10:58 2023 +0200 @@ -1,7 +1,7 @@ /* * Configuration settings. * - * Copyright (C) 2019, 2022 Paul Boddie + * Copyright (C) 2019, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -33,4 +33,5 @@ .routines = 0, .language = C_LANGUAGE, .verbose = 0, + .alignment = 0, }; diff -r 764d7c541daa -r a60bfff28db3 config.h --- a/config.h Thu Mar 23 00:32:22 2023 +0100 +++ b/config.h Fri Apr 07 19:10:58 2023 +0200 @@ -1,7 +1,7 @@ /* * Configuration settings. * - * Copyright (C) 2019, 2022 Paul Boddie + * Copyright (C) 2019, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -49,6 +49,10 @@ /* Feedback to the user. */ int verbose; + + /* Optional structure alignment in bytes (0 meaning no explicit alignment). */ + + int alignment; }; extern struct config conf; diff -r 764d7c541daa -r a60bfff28db3 docs/idl.1 --- a/docs/idl.1 Thu Mar 23 00:32:22 2023 +0100 +++ b/docs/idl.1 Fri Apr 07 19:10:58 2023 +0200 @@ -105,6 +105,10 @@ of the option and an equals sign (\fB=\fR) or in the argument that follows them: .PP .TP +\fB\-A\fR, \fB\-\-alignment\fR=\fIALIGNMENT\fR +Specify a minimum alignment in bytes for operation parameters, determining how +they are encoded in messages exchanged between components. +.TP \fB\-d\fR, \fB\-\-dir\fR=\fIDIRECTORY\fR Indicate the output directory for generated files. .TP diff -r 764d7c541daa -r a60bfff28db3 main.c --- a/main.c Thu Mar 23 00:32:22 2023 +0100 +++ b/main.c Fri Apr 07 19:10:58 2023 +0200 @@ -1,7 +1,7 @@ /* * Main program. * - * Copyright (C) 2019, 2022 Paul Boddie + * Copyright (C) 2019, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -37,6 +37,7 @@ static struct option long_options[] = { /* long opt following var pointer short opt */ + {"alignment", required_argument, NULL, 'A' }, {"all", no_argument, NULL, 'a' }, {"client", no_argument, NULL, 'c' }, {"dir", required_argument, NULL, 'd' }, @@ -72,12 +73,17 @@ while (1) { - option = getopt_long(argc, argv, "acd:fhil:rRsvV?", long_options, NULL); + option = getopt_long(argc, argv, "A:acd:fhil:rRsvV?", long_options, NULL); if (option == -1) break; switch (option) { + /* Set alignment. */ + case 'A': + conf.alignment = atoi(optarg); + break; + /* Generate everything. */ case 'a': conf.client = 1; conf.server = 1; diff -r 764d7c541daa -r a60bfff28db3 mk/client_interface_c.mk --- a/mk/client_interface_c.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/client_interface_c.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # C client interface generation rules. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -38,6 +38,6 @@ @touch $$@ $$($(1)_CLIENT_C_): $$($(1)_CLIENT_IDL) $$($(1)_CLIENT_INC) $(IDL_PROG) - $(IDL_PROG) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c $$($(1)_CLIENT_IDL) + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c $$($(1)_CLIENT_IDL) @touch $$@ endef diff -r 764d7c541daa -r a60bfff28db3 mk/client_interface_cc.mk --- a/mk/client_interface_cc.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/client_interface_cc.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # C++ client interface generation rules. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -38,6 +38,6 @@ @touch $$@ $$($(1)_CLIENT_CC_): $$($(1)_CLIENT_IDL) $$($(1)_CLIENT_INC) $(IDL_PROG) - $(IDL_PROG) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c++ $$($(1)_CLIENT_IDL) + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c++ $$($(1)_CLIENT_IDL) @touch $$@ endef diff -r 764d7c541daa -r a60bfff28db3 mk/export_interface_c.mk --- a/mk/export_interface_c.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/export_interface_c.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # C interface exporting rules. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -24,6 +24,6 @@ $$($(1)_INT_INC): $$($(1)_INT_IDL) $(IDL_PROG) -mkdir -p $(IDL_EXPORT_DIR) - $(IDL_PROG) -d $(IDL_EXPORT_DIR) --interfaces --language=c $$($(1)_INT_IDL) + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_EXPORT_DIR) --interfaces --language=c $$($(1)_INT_IDL) endif endef diff -r 764d7c541daa -r a60bfff28db3 mk/export_interface_cc.mk --- a/mk/export_interface_cc.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/export_interface_cc.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # C++ interface exporting rules. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -24,6 +24,6 @@ $$($(1)_INT_INC): $$($(1)_INT_IDL) $(IDL_PROG) -mkdir -p $(IDL_EXPORT_DIR) - $(IDL_PROG) -d $(IDL_EXPORT_DIR) --interfaces --language=c++ $$($(1)_INT_IDL) + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_EXPORT_DIR) --interfaces --language=c++ $$($(1)_INT_IDL) endif endef diff -r 764d7c541daa -r a60bfff28db3 mk/idl.mk --- a/mk/idl.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/idl.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # Common definitions and functions. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -19,6 +19,17 @@ IDL_PROG = $(L4DIR)/idl4re/idl +# Alignment could be overridden by testing for a particular architecture. +# For example: +# +# ifeq ($(ARCH),x86) +# IDL_ARGS = -A 8 +# else +# ... +# endif + +IDL_ARGS = + # Functions to generate filenames for individual interfaces. export_includes = $(patsubst %,$(IDL_EXPORT_DIR)/%,$(1)) diff -r 764d7c541daa -r a60bfff28db3 mk/server_interface_c.mk --- a/mk/server_interface_c.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/server_interface_c.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # C server interface generation rules. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -38,6 +38,6 @@ @touch $$@ $$($(1)_SERVER_C_): $$($(1)_SERVER_IDL) $$($(1)_SERVER_INC) $(IDL_PROG) - $(IDL_PROG) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c $$($(1)_SERVER_IDL) + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c $$($(1)_SERVER_IDL) @touch $$@ endef diff -r 764d7c541daa -r a60bfff28db3 mk/server_interface_cc.mk --- a/mk/server_interface_cc.mk Thu Mar 23 00:32:22 2023 +0100 +++ b/mk/server_interface_cc.mk Fri Apr 07 19:10:58 2023 +0200 @@ -1,6 +1,6 @@ # C++ server interface generation rules. # -# Copyright (C) 2020, 2022 Paul Boddie +# Copyright (C) 2020, 2022, 2023 Paul Boddie # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -38,6 +38,6 @@ @touch $$@ $$($(1)_SERVER_CC_): $$($(1)_SERVER_IDL) $$($(1)_SERVER_INC) $(IDL_PROG) - $(IDL_PROG) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c++ $$($(1)_SERVER_IDL) + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c++ $$($(1)_SERVER_IDL) @touch $$@ endef diff -r 764d7c541daa -r a60bfff28db3 structure.c --- a/structure.c Thu Mar 23 00:32:22 2023 +0100 +++ b/structure.c Fri Apr 07 19:10:58 2023 +0200 @@ -1,7 +1,7 @@ /* * Structure definition. * - * Copyright (C) 2019 Paul Boddie + * Copyright (C) 2019, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,7 +20,9 @@ */ #include +#include #include "common.h" +#include "config.h" #include "declaration.h" #include "structure.h" #include "templates.h" @@ -67,6 +69,21 @@ write_structures(sig->tail, fp, iface); } +/* Terminate a structure definition, setting any explicit structure + alignment. */ + +static void write_structure_alignment(FILE *fp) +{ + char alignment[32]; + + if (conf.alignment) + sprintf(alignment, structure_epilogue_alignment, conf.alignment); + else + strcpy(alignment, ""); + + fprintf(fp, structure_epilogue, alignment); +} + /* Generate message structures for a signature. */ void write_structure(struct signature *sig, FILE *fp, struct interface *iface) @@ -99,14 +116,14 @@ fprintf(fp, structure_opcode_member, L4_OPCODE_TYPE); } write_declarations(param, IN_PARAMETER, WORD_CLASS, fp); - fputs(structure_epilogue, fp); + write_structure_alignment(fp); } if (output_words) { fprintf(fp, structure_prologue, "out", opname); write_declarations(param, OUT_PARAMETER, WORD_CLASS, fp); - fputs(structure_epilogue, fp); + write_structure_alignment(fp); } /* Free allocated strings. */ diff -r 764d7c541daa -r a60bfff28db3 templates.h --- a/templates.h Thu Mar 23 00:32:22 2023 +0100 +++ b/templates.h Fri Apr 07 19:10:58 2023 +0200 @@ -349,7 +349,10 @@ " %s _op;\n" #define structure_epilogue \ -"};\n" +"}%s;\n" + +#define structure_epilogue_alignment \ +" __attribute__ ((aligned (%d)))" /* Message access templates. */ @@ -386,6 +389,7 @@ "Usage: %s [ ] ...\n\n" \ "Generate source code for the interfaces in the supplied files.\n\n" \ "The following options are supported:\n\n" \ +"--alignment or -A Align operation parameters to the given number of bytes.\n\n" \ "--all or -a Produce all kinds of output for a given language.\n\n" \ "--client or -c Generate client code.\n\n" \ "--dir or -d Create output in the indicated directory.\n\n" \