public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: binutils@sourceware.org
Cc: Indu Bhagat <indu.bhagat@oracle.com>
Subject: [PATCH 04/12] libsframe: add new APIs to add and get SFrame FDE in SFrame version 2
Date: Tue, 27 Jun 2023 14:20:20 -0700	[thread overview]
Message-ID: <20230627212028.2138604-5-indu.bhagat@oracle.com> (raw)
In-Reply-To: <20230627212028.2138604-1-indu.bhagat@oracle.com>

These APIs are used to:
  - get an SFrame FDE data from the decoder context, and
  - add an SFrame FDE to the encoder context.

The additional argument is useful for SFrame FDEs where FDE type is
SFRAME_FDE_TYPE_PCMASK.

include/
	* sframe-api.h (sframe_decoder_get_funcdesc_v2): New
	declaration.
	(sframe_encoder_add_funcdesc_v2): Likewise.
libsframe/
	* libsframe.ver: Add the new APIs.
	* sframe.c (sframe_decoder_get_funcdesc_v2): New definition.
	(sframe_encoder_add_funcdesc_v2): Likewise.
---
 include/sframe-api.h    | 23 ++++++++++++++++
 libsframe/libsframe.ver |  2 ++
 libsframe/sframe.c      | 61 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)

diff --git a/include/sframe-api.h b/include/sframe-api.h
index 7883b668e31..961ff7eb05f 100644
--- a/include/sframe-api.h
+++ b/include/sframe-api.h
@@ -172,6 +172,19 @@ sframe_decoder_get_funcdesc (sframe_decoder_ctx *ctx,
 			     int32_t *func_start_address,
 			     unsigned char *func_info);
 
+/* Get the data (NUM_FRES, FUNC_SIZE, FUNC_START_ADDRESS, FUNC_INFO,
+   REP_BLOCK_SIZE) from the function descriptor entry at index I'th
+   in the decoder CTX.  If failed, return error code.
+   This API is only available from SFRAME_VERSION_2.  */
+extern int
+sframe_decoder_get_funcdesc_v2 (sframe_decoder_ctx *ctx,
+				unsigned int i,
+				uint32_t *num_fres,
+				uint32_t *func_size,
+				int32_t *func_start_address,
+				unsigned char *func_info,
+				uint8_t *rep_block_size);
+
 /* SFrame textual dump.  */
 extern void
 dump_sframe (sframe_decoder_ctx *decoder, uint64_t addr);
@@ -246,6 +259,16 @@ sframe_encoder_add_funcdesc (sframe_encoder_ctx *encoder,
 			     unsigned char func_info,
 			     uint32_t num_fres);
 
+/* Add a new function descriptor entry with START_ADDR, FUNC_SIZE, FUNC_INFO
+   and REP_BLOCK_SIZE to the encoder.  */
+extern int
+sframe_encoder_add_funcdesc_v2 (sframe_encoder_ctx *encoder,
+				int32_t start_addr,
+				uint32_t func_size,
+				unsigned char func_info,
+				uint8_t rep_block_size,
+				uint32_t num_fres);
+
 /* Serialize the contents of the encoder and return the buffer.  ENCODED_SIZE
    is updated to the size of the buffer.  Sets ERRP if failure.  */
 extern char  *
diff --git a/libsframe/libsframe.ver b/libsframe/libsframe.ver
index 3e2a5695e93..57f5fb6c378 100644
--- a/libsframe/libsframe.ver
+++ b/libsframe/libsframe.ver
@@ -20,6 +20,7 @@ LIBSFRAME_1.0 {
     sframe_find_fre;
     sframe_decoder_get_num_fidx;
     sframe_decoder_get_funcdesc;
+    sframe_decoder_get_funcdesc_v2;
     sframe_decoder_get_fre;
     sframe_encode;
     sframe_encoder_free;
@@ -29,6 +30,7 @@ LIBSFRAME_1.0 {
     sframe_encoder_get_num_fidx;
     sframe_encoder_add_fre;
     sframe_encoder_add_funcdesc;
+    sframe_encoder_add_funcdesc_v2;
     sframe_encoder_write;
     dump_sframe;
     sframe_errmsg;
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index cb73a0ca87f..7031cee50b8 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -1208,6 +1208,36 @@ sframe_decoder_get_funcdesc (sframe_decoder_ctx *ctx,
   return 0;
 }
 
+int
+sframe_decoder_get_funcdesc_v2 (sframe_decoder_ctx *dctx,
+				unsigned int i,
+				uint32_t *num_fres,
+				uint32_t *func_size,
+				int32_t *func_start_address,
+				unsigned char *func_info,
+				uint8_t *rep_block_size)
+{
+  sframe_func_desc_entry *fdp;
+  int err = 0;
+
+  if (dctx == NULL || func_start_address == NULL
+      || num_fres == NULL || func_size == NULL
+      || sframe_decoder_get_version (dctx) == SFRAME_VERSION_1)
+    return sframe_set_errno (&err, SFRAME_ERR_INVAL);
+
+  fdp = sframe_decoder_get_funcdesc_at_index (dctx, i);
+
+  if (fdp == NULL)
+    return sframe_set_errno (&err, SFRAME_ERR_FDE_NOTFOUND);
+
+  *num_fres = fdp->sfde_func_num_fres;
+  *func_start_address = fdp->sfde_func_start_address;
+  *func_size = fdp->sfde_func_size;
+  *func_info = fdp->sfde_func_info;
+  *rep_block_size = fdp->sfde_func_rep_size;
+
+  return 0;
+}
 /* Get the FRE_IDX'th FRE of the function at FUNC_IDX'th function
    descriptor entry in the SFrame decoder CTX.  Returns error code as
    applicable.  */
@@ -1579,6 +1609,37 @@ bad:
   return -1;
 }
 
+/* Add a new function descriptor entry with START_ADDR, FUNC_SIZE, FUNC_INFO
+   and REP_BLOCK_SIZE to the encoder.
+
+   This API is valid only for SFrame format version 2.  */
+
+int
+sframe_encoder_add_funcdesc_v2 (sframe_encoder_ctx *encoder,
+				int32_t start_addr,
+				uint32_t func_size,
+				unsigned char func_info,
+				uint8_t rep_block_size,
+				uint32_t num_fres __attribute__ ((unused)))
+{
+  sf_fde_tbl *fd_info;
+  int err;
+
+  if (encoder == NULL
+      || sframe_encoder_get_version (encoder) == SFRAME_VERSION_1)
+    return sframe_set_errno (&err, SFRAME_ERR_INVAL);
+
+  err = sframe_encoder_add_funcdesc (encoder, start_addr, func_size, func_info,
+				     num_fres);
+  if (err)
+    return SFRAME_ERR;
+
+  fd_info = encoder->sfe_funcdesc;
+  fd_info->entry[fd_info->count-1].sfde_func_rep_size = rep_block_size;
+
+  return 0;
+}
+
 static int
 sframe_sort_funcdesc (sframe_encoder_ctx *encoder)
 {
-- 
2.39.2


  parent reply	other threads:[~2023-06-27 21:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 21:20 [PATCH 00/12] SFrame Version 2 - definition and support Indu Bhagat
2023-06-27 21:20 ` [PATCH 01/12] sframe.h: format bump to SFrame version 2 Indu Bhagat
2023-06-27 21:20 ` [PATCH 02/12] gas: generate SFrame section with version SFRAME_VERSION_2 Indu Bhagat
2023-06-27 21:20 ` [PATCH 03/12] libsframe: add new APIs to get SFrame version Indu Bhagat
2023-06-27 21:20 ` Indu Bhagat [this message]
2023-06-27 21:20 ` [PATCH 05/12] libsframe: adjust version check in sframe_header_sanity_check_p Indu Bhagat
2023-06-27 21:20 ` [PATCH 06/12] libsframe: testsuite: fixes for SFRAME_VERSION_2 Indu Bhagat
2023-06-27 21:20 ` [PATCH 07/12] bfd: linker: add support for rep_block_size for pltN entries Indu Bhagat
2023-06-27 21:20 ` [PATCH 08/12] bfd: linker: generate SFrame sections with version SFRAME_VERSION_2 Indu Bhagat
2023-06-27 21:20 ` [PATCH 09/12] objdump/readelf: adjust for SFRAME_VERSION_2 Indu Bhagat
2023-06-28 23:04   ` Hans-Peter Nilsson
2023-06-29  6:41     ` Indu Bhagat
2023-06-27 21:20 ` [PATCH 10/12] doc: sframe: update specification " Indu Bhagat
2023-06-27 21:20 ` [PATCH 11/12] doc: sframe: add details about alignment in the SFrame format Indu Bhagat
2023-06-27 21:20 ` [PATCH 12/12] binutils/NEWS: announce SFrame version 2 as the new default Indu Bhagat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230627212028.2138604-5-indu.bhagat@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).