Subject: Re: tf_pc value
To: Chris Gilbert <chris@paradox.demon.co.uk>
From: Ben Harris <bjh21@netbsd.org>
List: port-arm26
Date: 03/11/2001 11:38:18
On Sun, 11 Mar 2001, Chris Gilbert wrote:

> Eeks, when did port-arm mailing list appear?  Checks archive, odd the mail 
> from ben to arm26 and arm32 never made it...

I think it took a while to get through.

> > My reason for not having the assembler stubs for the SWI and undef handler
> > wind back tf_pc is that in order to do so, they need to know whether the
> > processor was in Thumb state (since the PC is advanced by one instruction,
> > rather than by a fixed number of bytes).  At the obvious point to do the
> > winding back, there are no spare registers to MRS into, so since the C
> > handlers will need to know what state the CPU was in anyway, they may as
> > well wind back tf_pc at the same time.
> 
> the swi they could be done in asm see page A9-12 of the ARM ARM, it's shows 
> how to get the right number out for either thumb or arm, so with the same 
> text you can move the tf_pc appropriatly.

It's possible, but since it does all the magic after (effectively) saving
the trapframe, it's not much of an improvement on my plan (though it does
have the virtue of keeping the entry to C clean).  I suspect my enthusiasm
for writing things in C rather than assembler may be influencing me here.

> Something of note is that it shows that thumb only allows for 256 swi codes, 
> I believe that netbsd has 512 syscalls at the mo, looks like some kind of 
> magic might be needed to make thumb cope with that....

Well, that could be claimed to be what syscall 0 (syscall()) is for.  It'd
require a bit of magic in the syscall stubs, but it wouldn't be too
painful.  You'd need to have each stub (for syscalls > 255) look something
like this:

LSYS_foo:
	.word	SYS_foo
foo:
	push	{r0-r3}
	pop	{r1-r3}
	ldr	r0, LSYS_foo
	swi	SYS_syscall
	add	sp, #4
	bcs	cerror
	bx	r14

-- 
Ben Harris                                                   <bjh21@netbsd.org>
Portmaster, NetBSD/arm26               <URL:http://www.netbsd.org/Ports/arm26/>