1.1 --- a/config.c Sun Jan 14 23:22:03 2024 +0100
1.2 +++ b/config.c Sun Jan 14 23:54:40 2024 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Configuration settings.
1.6 *
1.7 - * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2019, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -33,4 +33,5 @@
1.13 .routines = 0,
1.14 .language = C_LANGUAGE,
1.15 .verbose = 0,
1.16 + .alignment = 0,
1.17 };
2.1 --- a/config.h Sun Jan 14 23:22:03 2024 +0100
2.2 +++ b/config.h Sun Jan 14 23:54:40 2024 +0100
2.3 @@ -1,7 +1,7 @@
2.4 /*
2.5 * Configuration settings.
2.6 *
2.7 - * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
2.8 + * Copyright (C) 2019, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
2.9 *
2.10 * This program is free software; you can redistribute it and/or
2.11 * modify it under the terms of the GNU General Public License as
2.12 @@ -49,6 +49,10 @@
2.13 /* Feedback to the user. */
2.14
2.15 int verbose;
2.16 +
2.17 + /* Optional structure alignment in bytes (0 meaning no explicit alignment). */
2.18 +
2.19 + int alignment;
2.20 };
2.21
2.22 extern struct config conf;
3.1 --- a/docs/idl.1 Sun Jan 14 23:22:03 2024 +0100
3.2 +++ b/docs/idl.1 Sun Jan 14 23:54:40 2024 +0100
3.3 @@ -105,6 +105,10 @@
3.4 of the option and an equals sign (\fB=\fR) or in the argument that follows them:
3.5 .PP
3.6 .TP
3.7 +\fB\-A\fR, \fB\-\-alignment\fR=\fIALIGNMENT\fR
3.8 +Specify a minimum alignment in bytes for operation parameters, determining how
3.9 +they are encoded in messages exchanged between components.
3.10 +.TP
3.11 \fB\-d\fR, \fB\-\-dir\fR=\fIDIRECTORY\fR
3.12 Indicate the output directory for generated files.
3.13 .TP
4.1 --- a/main.c Sun Jan 14 23:22:03 2024 +0100
4.2 +++ b/main.c Sun Jan 14 23:54:40 2024 +0100
4.3 @@ -1,7 +1,7 @@
4.4 /*
4.5 * Main program.
4.6 *
4.7 - * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
4.8 + * Copyright (C) 2019, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
4.9 *
4.10 * This program is free software; you can redistribute it and/or
4.11 * modify it under the terms of the GNU General Public License as
4.12 @@ -37,6 +37,7 @@
4.13
4.14 static struct option long_options[] = {
4.15 /* long opt following var pointer short opt */
4.16 + {"alignment", required_argument, NULL, 'A' },
4.17 {"all", no_argument, NULL, 'a' },
4.18 {"client", no_argument, NULL, 'c' },
4.19 {"dir", required_argument, NULL, 'd' },
4.20 @@ -72,12 +73,17 @@
4.21
4.22 while (1)
4.23 {
4.24 - option = getopt_long(argc, argv, "acd:fhil:rRsvV?", long_options, NULL);
4.25 + option = getopt_long(argc, argv, "A:acd:fhil:rRsvV?", long_options, NULL);
4.26 if (option == -1)
4.27 break;
4.28
4.29 switch (option)
4.30 {
4.31 + /* Set alignment. */
4.32 + case 'A':
4.33 + conf.alignment = atoi(optarg);
4.34 + break;
4.35 +
4.36 /* Generate everything. */
4.37 case 'a':
4.38 conf.client = 1; conf.server = 1;
5.1 --- a/mk/client_interface_c.mk Sun Jan 14 23:22:03 2024 +0100
5.2 +++ b/mk/client_interface_c.mk Sun Jan 14 23:54:40 2024 +0100
5.3 @@ -1,6 +1,6 @@
5.4 # C client interface generation rules.
5.5 #
5.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
5.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
5.8 #
5.9 # This program is free software; you can redistribute it and/or
5.10 # modify it under the terms of the GNU General Public License as
5.11 @@ -38,6 +38,6 @@
5.12 @touch $$@
5.13
5.14 $$($(1)_CLIENT_C_): $$($(1)_CLIENT_IDL) $$($(1)_CLIENT_INC) $(IDL_PROG)
5.15 - $(IDL_PROG) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c $$($(1)_CLIENT_IDL)
5.16 + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c $$($(1)_CLIENT_IDL)
5.17 @touch $$@
5.18 endef
6.1 --- a/mk/client_interface_cc.mk Sun Jan 14 23:22:03 2024 +0100
6.2 +++ b/mk/client_interface_cc.mk Sun Jan 14 23:54:40 2024 +0100
6.3 @@ -1,6 +1,6 @@
6.4 # C++ client interface generation rules.
6.5 #
6.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
6.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
6.8 #
6.9 # This program is free software; you can redistribute it and/or
6.10 # modify it under the terms of the GNU General Public License as
6.11 @@ -38,6 +38,6 @@
6.12 @touch $$@
6.13
6.14 $$($(1)_CLIENT_CC_): $$($(1)_CLIENT_IDL) $$($(1)_CLIENT_INC) $(IDL_PROG)
6.15 - $(IDL_PROG) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c++ $$($(1)_CLIENT_IDL)
6.16 + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --client --headers --routines --language=c++ $$($(1)_CLIENT_IDL)
6.17 @touch $$@
6.18 endef
7.1 --- a/mk/export_interface_c.mk Sun Jan 14 23:22:03 2024 +0100
7.2 +++ b/mk/export_interface_c.mk Sun Jan 14 23:54:40 2024 +0100
7.3 @@ -1,6 +1,6 @@
7.4 # C interface exporting rules.
7.5 #
7.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
7.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
7.8 #
7.9 # This program is free software; you can redistribute it and/or
7.10 # modify it under the terms of the GNU General Public License as
7.11 @@ -24,6 +24,6 @@
7.12
7.13 $$($(1)_INT_INC): $$($(1)_INT_IDL) $(IDL_PROG)
7.14 -mkdir -p $(IDL_EXPORT_DIR)
7.15 - $(IDL_PROG) -d $(IDL_EXPORT_DIR) --interfaces --language=c $$($(1)_INT_IDL)
7.16 + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_EXPORT_DIR) --interfaces --language=c $$($(1)_INT_IDL)
7.17 endif
7.18 endef
8.1 --- a/mk/export_interface_cc.mk Sun Jan 14 23:22:03 2024 +0100
8.2 +++ b/mk/export_interface_cc.mk Sun Jan 14 23:54:40 2024 +0100
8.3 @@ -1,6 +1,6 @@
8.4 # C++ interface exporting rules.
8.5 #
8.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
8.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
8.8 #
8.9 # This program is free software; you can redistribute it and/or
8.10 # modify it under the terms of the GNU General Public License as
8.11 @@ -24,6 +24,6 @@
8.12
8.13 $$($(1)_INT_INC): $$($(1)_INT_IDL) $(IDL_PROG)
8.14 -mkdir -p $(IDL_EXPORT_DIR)
8.15 - $(IDL_PROG) -d $(IDL_EXPORT_DIR) --interfaces --language=c++ $$($(1)_INT_IDL)
8.16 + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_EXPORT_DIR) --interfaces --language=c++ $$($(1)_INT_IDL)
8.17 endif
8.18 endef
9.1 --- a/mk/idl.mk Sun Jan 14 23:22:03 2024 +0100
9.2 +++ b/mk/idl.mk Sun Jan 14 23:54:40 2024 +0100
9.3 @@ -1,6 +1,6 @@
9.4 # Common definitions and functions.
9.5 #
9.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
9.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
9.8 #
9.9 # This program is free software; you can redistribute it and/or
9.10 # modify it under the terms of the GNU General Public License as
9.11 @@ -19,6 +19,17 @@
9.12
9.13 IDL_PROG = $(L4DIR)/idl4re/idl
9.14
9.15 +# Alignment could be overridden by testing for a particular architecture.
9.16 +# For example:
9.17 +#
9.18 +# ifeq ($(ARCH),x86)
9.19 +# IDL_ARGS = -A 8
9.20 +# else
9.21 +# ...
9.22 +# endif
9.23 +
9.24 +IDL_ARGS =
9.25 +
9.26 # Functions to generate filenames for individual interfaces.
9.27
9.28 export_includes = $(patsubst %,$(IDL_EXPORT_DIR)/%,$(1))
10.1 --- a/mk/server_interface_c.mk Sun Jan 14 23:22:03 2024 +0100
10.2 +++ b/mk/server_interface_c.mk Sun Jan 14 23:54:40 2024 +0100
10.3 @@ -1,6 +1,6 @@
10.4 # C server interface generation rules.
10.5 #
10.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
10.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
10.8 #
10.9 # This program is free software; you can redistribute it and/or
10.10 # modify it under the terms of the GNU General Public License as
10.11 @@ -38,6 +38,6 @@
10.12 @touch $$@
10.13
10.14 $$($(1)_SERVER_C_): $$($(1)_SERVER_IDL) $$($(1)_SERVER_INC) $(IDL_PROG)
10.15 - $(IDL_PROG) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c $$($(1)_SERVER_IDL)
10.16 + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c $$($(1)_SERVER_IDL)
10.17 @touch $$@
10.18 endef
11.1 --- a/mk/server_interface_cc.mk Sun Jan 14 23:22:03 2024 +0100
11.2 +++ b/mk/server_interface_cc.mk Sun Jan 14 23:54:40 2024 +0100
11.3 @@ -1,6 +1,6 @@
11.4 # C++ server interface generation rules.
11.5 #
11.6 -# Copyright (C) 2020, 2022 Paul Boddie <paul@boddie.org.uk>
11.7 +# Copyright (C) 2020, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
11.8 #
11.9 # This program is free software; you can redistribute it and/or
11.10 # modify it under the terms of the GNU General Public License as
11.11 @@ -38,6 +38,6 @@
11.12 @touch $$@
11.13
11.14 $$($(1)_SERVER_CC_): $$($(1)_SERVER_IDL) $$($(1)_SERVER_INC) $(IDL_PROG)
11.15 - $(IDL_PROG) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c++ $$($(1)_SERVER_IDL)
11.16 + $(IDL_PROG) $(IDL_ARGS) -d $(IDL_BUILD_DIR) --server --headers --routines --language=c++ $$($(1)_SERVER_IDL)
11.17 @touch $$@
11.18 endef
12.1 --- a/structure.c Sun Jan 14 23:22:03 2024 +0100
12.2 +++ b/structure.c Sun Jan 14 23:54:40 2024 +0100
12.3 @@ -1,7 +1,7 @@
12.4 /*
12.5 * Structure definition.
12.6 *
12.7 - * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
12.8 + * Copyright (C) 2019, 2023 Paul Boddie <paul@boddie.org.uk>
12.9 *
12.10 * This program is free software; you can redistribute it and/or
12.11 * modify it under the terms of the GNU General Public License as
12.12 @@ -20,7 +20,9 @@
12.13 */
12.14
12.15 #include <stdlib.h>
12.16 +#include <string.h>
12.17 #include "common.h"
12.18 +#include "config.h"
12.19 #include "declaration.h"
12.20 #include "structure.h"
12.21 #include "templates.h"
12.22 @@ -67,6 +69,21 @@
12.23 write_structures(sig->tail, fp, iface);
12.24 }
12.25
12.26 +/* Terminate a structure definition, setting any explicit structure
12.27 + alignment. */
12.28 +
12.29 +static void write_structure_alignment(FILE *fp)
12.30 +{
12.31 + char alignment[32];
12.32 +
12.33 + if (conf.alignment)
12.34 + sprintf(alignment, structure_epilogue_alignment, conf.alignment);
12.35 + else
12.36 + strcpy(alignment, "");
12.37 +
12.38 + fprintf(fp, structure_epilogue, alignment);
12.39 +}
12.40 +
12.41 /* Generate message structures for a signature. */
12.42
12.43 void write_structure(struct signature *sig, FILE *fp, struct interface *iface)
12.44 @@ -99,14 +116,14 @@
12.45 fprintf(fp, structure_opcode_member, L4_OPCODE_TYPE);
12.46 }
12.47 write_declarations(param, IN_PARAMETER, WORD_CLASS, fp);
12.48 - fputs(structure_epilogue, fp);
12.49 + write_structure_alignment(fp);
12.50 }
12.51
12.52 if (output_words)
12.53 {
12.54 fprintf(fp, structure_prologue, "out", opname);
12.55 write_declarations(param, OUT_PARAMETER, WORD_CLASS, fp);
12.56 - fputs(structure_epilogue, fp);
12.57 + write_structure_alignment(fp);
12.58 }
12.59
12.60 /* Free allocated strings. */
13.1 --- a/templates.h Sun Jan 14 23:22:03 2024 +0100
13.2 +++ b/templates.h Sun Jan 14 23:54:40 2024 +0100
13.3 @@ -349,7 +349,10 @@
13.4 " %s _op;\n"
13.5
13.6 #define structure_epilogue \
13.7 -"};\n"
13.8 +"}%s;\n"
13.9 +
13.10 +#define structure_epilogue_alignment \
13.11 +" __attribute__ ((aligned (%d)))"
13.12
13.13 /* Message access templates. */
13.14
13.15 @@ -386,6 +389,7 @@
13.16 "Usage: %s [ <options> ] <filename> ...\n\n" \
13.17 "Generate source code for the interfaces in the supplied files.\n\n" \
13.18 "The following options are supported:\n\n" \
13.19 +"--alignment or -A Align operation parameters to the given number of bytes.\n\n" \
13.20 "--all or -a Produce all kinds of output for a given language.\n\n" \
13.21 "--client or -c Generate client code.\n\n" \
13.22 "--dir or -d Create output in the indicated directory.\n\n" \