On Tuesday, 19 July 2022 at 15:03:42 UTC+1, Johnny Billquist wrote:
> By the way - another thing. This can't have been compiled and run on a
> 2.9BSD system. Where did you get those syscall numbers from?
> I am quite certain the numbers have not changed between 2.9BSD and
> 2.11BSD, and I can tell:
> 4 is write
> 17 is *not* sbrk, but chflags. sbrk is 69.
> 48 is *not* signal, but getegid. signal is just a wrapper around sigvec,
> which is 108.
My BSD2.11 agrees with you, my BSD2.9 does not.
> However, even the call to write is wrong. In 2.11BSD (and I believe
> 2.9BSD), you basically should have all arguments on the stack.
That's what I thought, and I was initially pulling my hair out with
everything falling over with the parameters on the stack, but with
BSD2.9 they are definitely inline. Here is the assembler for signal()
from the above C snippet:
\ On entry: sp=>ret, signum, func
MOV R5,-(SP) :\ Save R5, sp=>R5, ret, signum, func
MOV SP,R5 :\ R5=>stack frame
MOV &0004(R5),R1 :\ R1=signum
CMP R1,#&0014 :\ CMP MAXSIG
BCC L00B8 :\ Too big, bad signum
MOV &0006(R5),R0 :\ R0=func
MOV R1,&0170 :\ Store signum in TRAP
ASL R1 :\ signum*2, index into dispatch table
MOV &0178(R1),-(SP) :\ Stack old entry (default=0)
MOV R0,&0178(R1) :\ Store func in table
MOV R0,&0172 :\ Also store func in TRAP in case not C function
BEQ L00A4 :\ If zero, jump to pass to TRAP to turn off
BIT #&0001,R0 :\ Is func.b0=1?
BNE L00A4 :\ Also jump to pass to TRAP to disable
ASL R1 :\ R1 is now signum*4
ADD #&00C0,R1 :\ Index into jump block
MOV R1,&0172 :\ Store this as func in TRAP
TRAP &00 :\ TRAP indir
EQUW &016E :\ signal, signum, func
BCS L00BC :\ Error, jump to return it
BIT #&0001,R0 :\ Was old func bit 0 set?
BEQ L00B2 :\ No, skip past to return it
MOV R0,(SP) :\ Yes, overwrite stacked old func
MOV (SP)+,R0 :\ R0=old func from table
MOV (SP)+,R5 :\ Restore R5
RTS PC :\ Return
TRAP &30 :\ 016E 30 89 0.
HALT :\ 0170 00 00 ..
HALT :\ 0172 00 00 ..
At L00A4 it's definitely doing a Bell-style indirect TRAP with inline