9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Anant Narayanan <anant@kix.in>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] _tos puzzle
Date: Fri,  9 May 2008 11:00:24 +0530	[thread overview]
Message-ID: <7A069CFA-C55D-4B5F-99B3-B1E82EC0D4BF@kix.in> (raw)
In-Reply-To: <20080508203726.3AD111E8C5C@holo.morphisms.net>

Hi Russ,

> You should print AX after every instruction too, to see if
> you've actually set it up the way you think you did.

I did, and to my surprise, AX is 0, even though I set it properly in
the loader. It appears as if Linux is setting AX to 0 sometime after
the loader finishes, but before the executable begins. All other
registers, however, are preserved (eip being the most important).

>> That brings me to the question
>> of how 8a decides what address to put values like that in? Is the
>> address the same everytime, i.e. hardcoded into the binary?
>> (certainly
>> seems to be)
>
> _tos is no different than any other global variable.
> 8a doesn't use any address at all - it leaves a slot for 8l to fill
> in.
> The eventual address of _tos depends on what other data
> is in the binary.  I don't know why you say the address is
> the same every time:

I meant the address being fixed for a particular binary.

> No, the symbol table is only for debuggers and the like.
> Plan 9 doesn't load it into memory either.
>
> The good news is that you've identified the program
> behaving incorrectly after executing only *two* instructions.
> That should narrow things down considerably.

Every program linked with libc starts with:

83 ec 48: SUBL 0x48, SP

And the following opcode is:

89 05 xx xx xx xx: MOVL AX, _tos(SB).

As a hack, as I'm padding the executables anyway, I check for those
bytes and change 89 05 to 89 1D during the padding - which makes the
instruction MOVL BX, _tos(SB). I set BX to the proper value in the
loader (which is preserved by linux), and voila!

A lot of executables are working now, with the exception of awk (which
tries to open #e, which isn't there) - Thanks!

--
Anant




  reply	other threads:[~2008-05-09  5:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08 16:18 Anant Narayanan
2008-05-08 16:41 ` Russ Cox
2008-05-08 17:13   ` Anant Narayanan
2008-05-08 17:24     ` Russ Cox
2008-05-08 17:40       ` Steven Vormwald
2008-05-08 19:19       ` Anant Narayanan
2008-05-08 20:33         ` Russ Cox
2008-05-09  5:30           ` Anant Narayanan [this message]
2008-05-09 13:08             ` Russ Cox
2008-05-08 17:50     ` Charles Forsyth

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=7A069CFA-C55D-4B5F-99B3-B1E82EC0D4BF@kix.in \
    --to=anant@kix.in \
    --cc=9fans@9fans.net \
    /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 NNTP newsgroup(s).