9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] _tos puzzle
@ 2008-05-08 16:18 Anant Narayanan
  2008-05-08 16:41 ` Russ Cox
  0 siblings, 1 reply; 10+ messages in thread
From: Anant Narayanan @ 2008-05-08 16:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Good day,

I got some plan9 binaries to work on Linux (8c, 8l, cat, sed, cal and
a few more were tested), but all others are failing at exactly the
same instruction:

plock+0x31 MOVL 0x30(CX), CX

(which is called whenever malloc is used). For some context:

acid: asm(plock+0x20)
plock+0x20	JEQ		plock+0x27(SB)
plock+0x22	CALL	abort(SB)
plock+0x27	MOVL	pv+0xc(SP), AX
plock+0x2b	MOVL	_tos(SB), CX
plock+0x31	MOVL	0x30(CX), CX
plock+0x32	DECL	CX
plock+0x33	XORB	CL, 0xc4830448(CX)
plock+0x39	ADCB	AL,BL

The line of interest is plock+0x2b: (_tos(SB), CX); which is supposed
to store a value at CX. However, when the binary is run in Linux, CX
becomes 0 after that instruction, so plock+0x31 becomes (MOVL 0x30,
CX) resulting in a segfault as 0x30 is an invalid address in the
process address space (it starts only at 0x1000).

acid: asm(_tos)
_tos		ADDB	AL, 0x0(AX)

I defined a TEXT section for _tos, in the 'Hello Assembly' program
discussed earlier, and used _tos after printing Hello on the screen.
acid tells me CX becomes 0 after that instruction, which is exactly
what happens on Linux too:

DATA 	string<>+0(SB)/8, $"Plan9\n\z\z"
GLOBL 	string<>+0(SB), $8

TEXT 	_main+0(SB), 1, $0
MOVL	$string<>+0(SB), 4(SP)
MOVL	$8, AX
MOVL	_tos(SB), CX
MOVL	0x30(CX), CX
INT		$64

TEXT	_tos+0(SB), 1, $0
ADDB	AL, 0x0(AX)

8.out: 1831: suicide: sys: trap: fault read addr=0x30 pc=0x00001033

What is _tos supposed to do, and why does it set CX to different
values for some plan9 binaries, but not in a standalone assembled
program and on linux (in both cases, CX is set to 0)?

Thanks in advance for your help!

Regards,
Anant




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-05-09 13:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-08 16:18 [9fans] _tos puzzle 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
2008-05-09 13:08             ` Russ Cox
2008-05-08 17:50     ` Charles Forsyth

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).