mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Peter Mamonov <pmamonov@gmail.com>
To: o.rempel@pengutronix.de
Cc: barebox@lists.infradead.org, Peter Mamonov <pmamonov@gmail.com>
Subject: RE: MIPS: relocation issue
Date: Tue, 28 Jan 2020 13:49:55 +0300	[thread overview]
Message-ID: <20200128104955.10994-1-pmamonov@gmail.com> (raw)
In-Reply-To: <49d641a2-d827-885f-64a1-aac54877cfb5@pengutronix.de>

Hi Oleksij,

Below you will find the patch, which adds the `whereami` command. The command
prints several addresses belonging to code, data, bss, heap and stack areas.
I've run it on qemu/malta with relocations enabled and disabled as per Antony's
mail. Output comparison shows that only the stack is relocated. Looks like 
relocation doesn't work as expected. Also note that the stack was relocated 
from the uncached KSEG1 to the cached KSEG0 segment, which is inconsistent at 
least.

Relocation enabled:

	barebox@qemu malta:/ whereami
	code   @ a0829bcc (a0829bc0)
	data   @ a085f3c0
	bss    @ a0861ae0
	heap   @ a0428c38
	stack  @ 8fb8fd50
	barebox@qemu malta:/ version

	barebox 2020.01.0-00104-gfe12ba2776 #3 Tue Jan 28 13:34:06 MSK 2020


Relocation disabled:

	barebox@qemu malta:/ whereami
	code   @ a0829bcc (a0829bc0)
	data   @ a085f1e0
	bss    @ a0861900
	heap   @ a0428c38
	stack  @ a03ffd50

Regards,
Peter
---
 commands/Kconfig    |  5 +++++
 commands/Makefile   |  1 +
 commands/whereami.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 commands/whereami.c

diff --git a/commands/Kconfig b/commands/Kconfig
index add0d26ee9..a660e09db4 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2217,6 +2217,11 @@ config CMD_UBSAN
 	  This is a test command for the undefined behavior sanitizer.
 	  It triggers various undefined behavior, and detect it.
 
+config CMD_WHEREAMI
+	tristate "whereami"
+	depends on MIPS
+	default y
+
 # end Miscellaneous commands
 endmenu
 
diff --git a/commands/Makefile b/commands/Makefile
index 8e8c449bc1..dfa3d6e447 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -128,6 +128,7 @@ obj-$(CONFIG_CMD_NAND_BITFLIP)	+= nand-bitflip.o
 obj-$(CONFIG_CMD_SEED)		+= seed.o
 obj-$(CONFIG_CMD_IP_ROUTE_GET)  += ip-route-get.o
 obj-$(CONFIG_CMD_UBSAN)		+= ubsan.o
+obj-$(CONFIG_CMD_WHEREAMI)	+= whereami.o
 
 UBSAN_SANITIZE_ubsan.o := y
 
diff --git a/commands/whereami.c b/commands/whereami.c
new file mode 100644
index 0000000000..3edb070fe8
--- /dev/null
+++ b/commands/whereami.c
@@ -0,0 +1,45 @@
+#include <common.h>
+#include <command.h>
+#include <complete.h>
+
+static volatile int data = 1;
+static volatile int bss;
+
+static void* code();
+static noinline void* code()
+{
+	void *ret;
+	__asm__ __volatile__(
+		".set	push\n"
+		".set	noreorder\n"
+		".set	noat\n"
+		"	move	$1, $31\n"
+		"	bal	255f\n"
+		"	nop\n"
+		"255:	move	%0, $31\n"
+		"	move	$31, $1\n"
+		".set	pop\n"
+		:"=r" (ret)
+	);
+	return ret;
+}
+
+static int do_whereami(int argc, char *argv[])
+{
+	volatile int stack;
+	int *heapp = malloc(sizeof(int));
+
+	printf("code   @ %p (%p)\n", code(), &code);
+	printf("data   @ %p\n", &data);
+	printf("bss    @ %p\n", &bss);
+	printf("heap   @ %p\n", heapp);
+	printf("stack  @ %p\n", &stack);
+	return 0;
+}
+
+BAREBOX_CMD_START(whereami)
+	.cmd		= do_whereami,
+	BAREBOX_CMD_DESC("print addresses from code, stack, heap and data sections")
+	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+	BAREBOX_CMD_COMPLETE(empty_complete)
+BAREBOX_CMD_END
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-01-28 10:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28  6:46 Antony Pavlov
2020-01-28  9:34 ` Oleksij Rempel
2020-01-28 10:49   ` Peter Mamonov [this message]
2020-01-28 11:03     ` Oleksij Rempel
2020-01-28 11:10       ` Peter Mamonov
2020-01-30  8:26 ` maeling list issue Oleksij Rempel
2020-01-30 11:14   ` Sascha Hauer

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=20200128104955.10994-1-pmamonov@gmail.com \
    --to=pmamonov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=o.rempel@pengutronix.de \
    /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