Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Calm down, it's *____only* ones and zeroes.


computers / alt.sys.pdp11 / BSD2.9, sbrk() and signal()

SubjectAuthor
* BSD2.9, sbrk() and signal()Jonathan Harston
+- BSD2.9, sbrk() and signal()Bob Eager
`* BSD2.9, sbrk() and signal()Johnny Billquist
 `* BSD2.9, sbrk() and signal()Johnny Billquist
  `* BSD2.9, sbrk() and signal()Jonathan Harston
   `* BSD2.9, sbrk() and signal()Johnny Billquist
    +* BSD2.9, sbrk() and signal()Jonathan Harston
    |`* BSD2.9, sbrk() and signal()Johnny Billquist
    | `* BSD2.9, sbrk() and signal()Jonathan Harston
    |  `* BSD2.9, sbrk() and signal()Jonathan Harston
    |   `* BSD2.9, sbrk() and signal()Johnny Billquist
    |    `* BSD2.9, sbrk() and signal()Walter_F.J._Müller
    |     `* BSD2.9, sbrk() and signal()Walter_F.J._Müller
    |      `- BSD2.9, sbrk() and signal()Johnny Billquist
    `- BSD2.9, sbrk() and signal()Jonathan Harston

1
BSD2.9, sbrk() and signal()

<ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=832&group=alt.sys.pdp11#832

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:ac8:5cd3:0:b0:31d:3adc:bd00 with SMTP id s19-20020ac85cd3000000b0031d3adcbd00mr23080035qta.594.1658177173175; Mon, 18 Jul 2022 13:46:13 -0700 (PDT)
X-Received: by 2002:a05:6808:14d0:b0:33a:27c1:7c6b with SMTP id f16-20020a05680814d000b0033a27c17c6bmr15256502oiw.249.1658177172932; Mon, 18 Jul 2022 13:46:12 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Mon, 18 Jul 2022 13:46:12 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=77.96.251.164; posting-account=jgPW4gkAAACE_VxPxIZ8VykZc96-9sT_
NNTP-Posting-Host: 77.96.251.164
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
Subject: BSD2.9, sbrk() and signal()
From: jgh@mdfs.net (Jonathan Harston)
Injection-Date: Mon, 18 Jul 2022 20:46:13 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 124
X-Received-Bytes: 3828
 by: Jonathan Harston - Mon, 18 Jul 2022 20:46 UTC

Is there something special on BSD2.9 with sbrk() or signal()?
If I claim memory and stick the stack there, and set a signal,
when the signal is triggered everything blows up with the
signal dispatcher in the kernel unable to access memory to
stack to call the signal handler.

This doesn't happen if I leave the stack at the value on
entry at &FF00+xxx, and doesn't happen with Bell Unix v5/6/7.
I can't just leave the stack at &FFxx as it will descend
across I/O memory at &E000 upwards.

I've stripped my test code down to this:

ORG 0
EQUW &0107 ; magic number, also branch to code
EQUW _DATA%-_TEXT% ; size of text
EQUW _BSS%-_DATA% ; size of initialised data
EQUW _END%-_BSS% ; size of uninitialised data
EQUW &0000 ; size of symbol data
EQUW _ENTRY%-_TEXT% ; entry point
EQUW &0000 ; not used
EQUW &0001 ; no relocation info
; ORG 0
_TEXT%:
_ENTRY%:
mov #1,r0
trap 4 ; write(stdout, "RUN"..)
equw msg1
equw msg2-msg1
; trap 17 ; sbrk(&E000)
equw &E000
bcs quit ; failed
mov #1,r0
trap 4 ; write(stdout, "SBRK"..)
equw msg2
equw msg3-msg2
; trap 48 ; signal(SIGQUIT, quit)
equw 3
equw quit
mov #1,r0
trap 4 ; write(stdout, "SET"..)
equw msg3
equw msg4-msg3
; mov #&E000,sp ; put stack at top of memory
mov #1,r0
trap 4 ; write(stdout, "STOP"..)
equw msg4
equw msg5-msg4
stop:
jmp stop
quit:
mov #1,r0
trap 4 ; write(stdout, "QUIT"..)
equw msg5
equw msg6-msg5
clr r0
trap 1 ; exit

_DATA%:
msg1: equb "RUN",13,10
msg2: equb "SBRK",13,10
msg3: equb "SET",13,10
msg4: equb "STOP",13,10
msg5: equb "QUIT",13,10
msg6:
align
_BSS%:
_END%:

When run, this should display:
RUN
SBRK
SET
STOP
then when I press Ctrl-\ should display
QUIT
and cleanly exit.

Instead it does this:

Berkeley Unix 2.9BSD
:login: root
Welcome to the 2.9BSD (Berkeley) UNIX system.
# cd usr/jgh
# infile
RUN
SBRK
SET
STOP
^\Segmentation fault (core dumped)
#

It does this for any signal I try, and any value of SP I set up.
The memory claimed up to &E000 is actually there, if I put in a
little loop to dump memory from 0000 to DFFF is happily dumps
it all out
0000 blah blah blah blah
etc.
DFF0 blah blah blah blah
E000 Segmentation fault (core dumped) (as expected, it's gone
past the end of memory)

Compiling a short bit of C does as expected:

#include <signal.h>
int null()
{ exit(); }

int main()
{ signal(3,null); while(1) ; }

And examining the generated source is essentially identical to
the above handmade PDP11 code.... *other* than setting the
sbrk() and stack.

So. What is BSD2.9 sbrk() or signal() doing or not doing such
that the signal dispatcher in the kernal explodes trying to
JSR PC,signalhandler

jgh

Re: BSD2.9, sbrk() and signal()

<jjm1j2F4dsnU4@mid.individual.net>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=833&group=alt.sys.pdp11#833

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: news0009@eager.cx (Bob Eager)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: 18 Jul 2022 21:28:02 GMT
Lines: 15
Message-ID: <jjm1j2F4dsnU4@mid.individual.net>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net PoS8KRG3IWPciFSZiQ+QrwV4K+o0ARCLetc2q9cgQ2PqetL4vv
Cancel-Lock: sha1:N7tqCegoaIb3PN46wksrzIin8VU=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Bob Eager - Mon, 18 Jul 2022 21:28 UTC

On Mon, 18 Jul 2022 13:46:12 -0700, Jonathan Harston wrote:

> So. What is BSD2.9 sbrk() or signal() doing or not doing such that the
> signal dispatcher in the kernal explodes trying to JSR PC,signalhandler

Is there any signal trampoline code at the base of the stack? Or is that
only on the VAX?

--
Using UNIX since v6 (1975)...

Use the BIG mirror service in the UK:
http://www.mirrorservice.org

Re: BSD2.9, sbrk() and signal()

<tb5ssk$e76$1@news.misty.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=835&group=alt.sys.pdp11#835

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!.POSTED.185.159.157.200!not-for-mail
From: bqt@softjar.se (Johnny Billquist)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: Tue, 19 Jul 2022 11:18:11 +0200
Organization: MGT Consulting
Message-ID: <tb5ssk$e76$1@news.misty.com>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Jul 2022 09:18:12 -0000 (UTC)
Injection-Info: news.misty.com; posting-host="185.159.157.200";
logging-data="14566"; mail-complaints-to="abuse@misty.com"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Content-Language: en-US
In-Reply-To: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
 by: Johnny Billquist - Tue, 19 Jul 2022 09:18 UTC

On 2022-07-18 22:46, Jonathan Harston wrote:
> Is there something special on BSD2.9 with sbrk() or signal()?
> If I claim memory and stick the stack there, and set a signal,
> when the signal is triggered everything blows up with the
> signal dispatcher in the kernel unable to access memory to
> stack to call the signal handler.

Nothing I'm aware of.

> This doesn't happen if I leave the stack at the value on
> entry at &FF00+xxx, and doesn't happen with Bell Unix v5/6/7.
> I can't just leave the stack at &FFxx as it will descend
> across I/O memory at &E000 upwards.

What are you talking about? User programs don't have I/O memory in the
top page.

> I've stripped my test code down to this:
>
> ORG 0
> EQUW &0107 ; magic number, also branch to code
> EQUW _DATA%-_TEXT% ; size of text
> EQUW _BSS%-_DATA% ; size of initialised data
> EQUW _END%-_BSS% ; size of uninitialised data
> EQUW &0000 ; size of symbol data
> EQUW _ENTRY%-_TEXT% ; entry point
> EQUW &0000 ; not used
> EQUW &0001 ; no relocation info
> ;
> ORG 0
> _TEXT%:
> _ENTRY%:
> mov #1,r0
> trap 4 ; write(stdout, "RUN"..)
> equw msg1
> equw msg2-msg1
> ;
> trap 17 ; sbrk(&E000)
> equw &E000
> bcs quit ; failed
> mov #1,r0
> trap 4 ; write(stdout, "SBRK"..)
> equw msg2
> equw msg3-msg2
> ;
> trap 48 ; signal(SIGQUIT, quit)
> equw 3
> equw quit
> mov #1,r0
> trap 4 ; write(stdout, "SET"..)
> equw msg3
> equw msg4-msg3
> ;
> mov #&E000,sp ; put stack at top of memory

What assembler is this? I find the notation a bit weird. Is #&E000
really the constant E000? Or is it whatever value is located at E000?

With DEC assemblers, I guess it would be
MOV #160000,SP

and with the normal Unix assembler, it would be
MOV $160000,SP

Looking a few lines higher up, it certainly looked like you used just #n
for a literal constant, and not #&, so this all looks very fishy to me.

Can you run the code with a debugger and verify that you are getting a
good value? Also, what kind of CPU are you running on? I'm sortof
wondering, in case this is something like an 11/70, if the stack limit
register is used by the OS (I haven't checked). That could play tricks
with you if so. But I wouldn't think the system plays with the stack
limit register. My primary suspect is that you are not actually setting
the SP to what you think you are.

Johnny

Re: BSD2.9, sbrk() and signal()

<tb6djt$2gf$1@news.misty.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=836&group=alt.sys.pdp11#836

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!.POSTED.185.159.157.200!not-for-mail
From: bqt@softjar.se (Johnny Billquist)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: Tue, 19 Jul 2022 16:03:40 +0200
Organization: MGT Consulting
Message-ID: <tb6djt$2gf$1@news.misty.com>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Jul 2022 14:03:41 -0000 (UTC)
Injection-Info: news.misty.com; posting-host="185.159.157.200";
logging-data="2575"; mail-complaints-to="abuse@misty.com"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Content-Language: en-US
In-Reply-To: <tb5ssk$e76$1@news.misty.com>
 by: Johnny Billquist - Tue, 19 Jul 2022 14:03 UTC

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.

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.

So, something like this:

mov $4,-(sp)
mov $L4,-(sp)
mov $1,-(sp)
clr -(sp)
sys 4
clr (sp)
sys 1

..globl
..data
L4:.byte 146,157,157,12,0

Would print out a small 4 byte text and exit.

I have little clue what you are actually doing, but your code looks very
weird, basically.

Johnny

On 2022-07-19 11:18, Johnny Billquist wrote:
> On 2022-07-18 22:46, Jonathan Harston wrote:
>> Is there something special on BSD2.9 with sbrk() or signal()?
>> If I claim memory and stick the stack there, and set a signal,
>> when the signal is triggered everything blows up with the
>> signal dispatcher in the kernel unable to access memory to
>> stack to call the signal handler.
>
> Nothing I'm aware of.
>
>> This doesn't happen if I leave the stack at the value on
>> entry at &FF00+xxx, and doesn't happen with Bell Unix v5/6/7.
>> I can't just leave the stack at &FFxx as it will descend
>> across I/O memory at &E000 upwards.
>
> What are you talking about? User programs don't have I/O memory in the
> top page.
>
>> I've stripped my test code down to this:
>>
>> ORG  0
>> EQUW &0107        ; magic number, also branch to code
>> EQUW _DATA%-_TEXT%    ; size of text
>> EQUW _BSS%-_DATA%    ; size of initialised data
>> EQUW _END%-_BSS%    ; size of uninitialised data
>> EQUW &0000        ; size of symbol data
>> EQUW _ENTRY%-_TEXT%    ; entry point
>> EQUW &0000        ; not used
>> EQUW &0001        ; no relocation info
>> ;
>> ORG  0
>> _TEXT%:
>> _ENTRY%:
>> mov #1,r0
>> trap 4        ; write(stdout, "RUN"..)
>> equw msg1
>> equw msg2-msg1
>> ;
>> trap 17        ; sbrk(&E000)
>> equw &E000
>> bcs quit    ; failed
>> mov #1,r0
>> trap 4        ; write(stdout, "SBRK"..)
>> equw msg2
>> equw msg3-msg2
>> ;
>> trap 48        ; signal(SIGQUIT, quit)
>> equw 3
>> equw quit
>> mov #1,r0
>> trap 4        ; write(stdout, "SET"..)
>> equw msg3
>> equw msg4-msg3
>> ;
>> mov #&E000,sp    ; put stack at top of memory
>
> What assembler is this? I find the notation a bit weird. Is #&E000
> really the constant E000? Or is it whatever value is located at E000?
>
> With DEC assemblers, I guess it would be
>   MOV #160000,SP
>
> and with the normal Unix assembler, it would be
>   MOV $160000,SP
>
> Looking a few lines higher up, it certainly looked like you used just #n
> for a literal constant, and not #&, so this all looks very fishy to me.
>
> Can you run the code with a debugger and verify that you are getting a
> good value? Also, what kind of CPU are you running on? I'm sortof
> wondering, in case this is something like an 11/70, if the stack limit
> register is used by the OS (I haven't checked). That could play tricks
> with you if so. But I wouldn't think the system plays with the stack
> limit register. My primary suspect is that you are not actually setting
> the SP to what you think you are.
>
>   Johnny

Re: BSD2.9, sbrk() and signal()

<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=837&group=alt.sys.pdp11#837

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:a05:6214:23cb:b0:472:f1a5:5cea with SMTP id hr11-20020a05621423cb00b00472f1a55ceamr24846261qvb.13.1658244086555;
Tue, 19 Jul 2022 08:21:26 -0700 (PDT)
X-Received: by 2002:a05:6808:1204:b0:325:7ce2:77f6 with SMTP id
a4-20020a056808120400b003257ce277f6mr19751742oil.165.1658244086330; Tue, 19
Jul 2022 08:21:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Tue, 19 Jul 2022 08:21:26 -0700 (PDT)
In-Reply-To: <tb6djt$2gf$1@news.misty.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.96.251.164; posting-account=jgPW4gkAAACE_VxPxIZ8VykZc96-9sT_
NNTP-Posting-Host: 77.96.251.164
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: jgh@mdfs.net (Jonathan Harston)
Injection-Date: Tue, 19 Jul 2022 15:21:26 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3687
 by: Jonathan Harston - Tue, 19 Jul 2022 15:21 UTC

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?

https://www.tuhs.org/cgi-bin/utree.pl?file=2.9BSD/usr/src/sys/sys/sysent.c
and elsewhere.

> 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
_signal:
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
L00A4:
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
L00B2:
MOV (SP)+,R0 :\ R0=old func from table
MOV (SP)+,R5 :\ Restore R5
RTS PC :\ Return

(snip)

sigtrap:
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
parameters.

jgh

Re: BSD2.9, sbrk() and signal()

<tb6ket$asv$1@news.misty.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=838&group=alt.sys.pdp11#838

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!.POSTED.185.159.157.200!not-for-mail
From: bqt@softjar.se (Johnny Billquist)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: Tue, 19 Jul 2022 18:00:29 +0200
Organization: MGT Consulting
Message-ID: <tb6ket$asv$1@news.misty.com>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Jul 2022 16:00:30 -0000 (UTC)
Injection-Info: news.misty.com; posting-host="185.159.157.200";
logging-data="11167"; mail-complaints-to="abuse@misty.com"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Content-Language: en-US
In-Reply-To: <3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>
 by: Johnny Billquist - Tue, 19 Jul 2022 16:00 UTC

Very unexpected, and surprising that the numbers for the syscalls would
have changed between 2.9BSD and 2.11BSD.
Especially since seems to be some kind of 2.9 compatibility in 2.11.

But anyway. Let's assume that is correct then. What about the argument
to sbrk that I pointed at? It certainly looks broken to me. (And I'm
still confused by what assembler you are using.)

Johnny

On 2022-07-19 17:21, Jonathan Harston wrote:
> 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?
>
> https://www.tuhs.org/cgi-bin/utree.pl?file=2.9BSD/usr/src/sys/sys/sysent.c
> and elsewhere.
>
>> 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
> _signal:
> 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
> L00A4:
> 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
> L00B2:
> MOV (SP)+,R0 :\ R0=old func from table
> MOV (SP)+,R5 :\ Restore R5
> RTS PC :\ Return
>
> (snip)
>
> sigtrap:
> 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
> parameters.
>
> jgh

Re: BSD2.9, sbrk() and signal()

<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=839&group=alt.sys.pdp11#839

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:ac8:5f07:0:b0:31e:a164:6a89 with SMTP id x7-20020ac85f07000000b0031ea1646a89mr25594964qta.578.1658247729358;
Tue, 19 Jul 2022 09:22:09 -0700 (PDT)
X-Received: by 2002:a05:6830:129a:b0:61c:80f9:eefc with SMTP id
z26-20020a056830129a00b0061c80f9eefcmr10098347otp.72.1658247729132; Tue, 19
Jul 2022 09:22:09 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Tue, 19 Jul 2022 09:22:08 -0700 (PDT)
In-Reply-To: <tb6ket$asv$1@news.misty.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.96.251.164; posting-account=jgPW4gkAAACE_VxPxIZ8VykZc96-9sT_
NNTP-Posting-Host: 77.96.251.164
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com> <tb6ket$asv$1@news.misty.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: jgh@mdfs.net (Jonathan Harston)
Injection-Date: Tue, 19 Jul 2022 16:22:09 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1905
 by: Jonathan Harston - Tue, 19 Jul 2022 16:22 UTC

When I do:

clr r1 ; r1=top of memory, start at &10000
mov #&8911,TRAP_BUF ; SYS sbrk
InitMemLp:
sub #256,r1 ; Step down 256 bytes
mov r1,TRAP_BUF+2 ; Store as TRAP argument
TRAP 0 ; SYS sbrk,addr
EQUW TRAP_BUF
bcs InitMemLp ; Memory not claimable, try a bit less
rts pc

TRAP_BUF:
EQUW 0
EQUW 0
EQUW 0
EQUW 0

I end up with E000 has the highest top of memory I can claim.
The addresses at E000 upwards are inaccessible as they are
"elsewhere". My documentation tells me that Exxx is used
for paged memory access, and Fxxx is I/O access, "E000+ is
I/O" is just lazy shorthand for "not addresses I (ie the
code) can access".

Re: BSD2.9, sbrk() and signal()

<8d319dd9-0b77-45a9-8229-c9043751747cn@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=840&group=alt.sys.pdp11#840

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:a37:af04:0:b0:6b5:e908:b2c7 with SMTP id y4-20020a37af04000000b006b5e908b2c7mr6871624qke.214.1658248476176;
Tue, 19 Jul 2022 09:34:36 -0700 (PDT)
X-Received: by 2002:a05:6870:4603:b0:101:72f6:ba77 with SMTP id
z3-20020a056870460300b0010172f6ba77mr135604oao.38.1658248475950; Tue, 19 Jul
2022 09:34:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Tue, 19 Jul 2022 09:34:35 -0700 (PDT)
In-Reply-To: <tb6ket$asv$1@news.misty.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.96.251.164; posting-account=jgPW4gkAAACE_VxPxIZ8VykZc96-9sT_
NNTP-Posting-Host: 77.96.251.164
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com> <tb6ket$asv$1@news.misty.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8d319dd9-0b77-45a9-8229-c9043751747cn@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: jgh@mdfs.net (Jonathan Harston)
Injection-Date: Tue, 19 Jul 2022 16:34:36 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2067
 by: Jonathan Harston - Tue, 19 Jul 2022 16:34 UTC

On Tuesday, 19 July 2022 at 17:00:31 UTC+1, Johnny Billquist wrote:
> But anyway. Let's assume that is correct then. What about the argument
> to sbrk that I pointed at? It certainly looks broken to me. (And I'm
> still confused by what assembler you are using.)

It's definely E000, and on Bell V5/V6/V7 I end up with memory all the way
up to DFFF that I can use, and set the stack to E000 and fully descend
all the way to the bottom of memory. This is code that has been working
for almost 20 years on V5/V6/V7. Adding a debug display confirms it's E000:

0001 4E48 0000 0000 0000 0000 FF9A (at ENTRY)
RUN
0001 4E48 0000 0000 0000 0000 FF9A (after sbrk)
SBRK
SET
0005 4E48 0000 0000 0000 0000 E000 (after mov #&E000,sp)
STOP
^\Segmentation fault (core dumped)

The debug display is r0 r1 r2 r3 r4 r5 r6

Re: BSD2.9, sbrk() and signal()

<tb6qn4$idf$1@news.misty.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=841&group=alt.sys.pdp11#841

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!.POSTED.185.159.157.200!not-for-mail
From: bqt@softjar.se (Johnny Billquist)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: Tue, 19 Jul 2022 19:47:15 +0200
Organization: MGT Consulting
Message-ID: <tb6qn4$idf$1@news.misty.com>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>
<tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Jul 2022 17:47:16 -0000 (UTC)
Injection-Info: news.misty.com; posting-host="185.159.157.200";
logging-data="18863"; mail-complaints-to="abuse@misty.com"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Content-Language: en-US
In-Reply-To: <90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com>
 by: Johnny Billquist - Tue, 19 Jul 2022 17:47 UTC

On 2022-07-19 18:22, Jonathan Harston wrote:
>
> When I do:
>
> clr r1 ; r1=top of memory, start at &10000
> mov #&8911,TRAP_BUF ; SYS sbrk
> InitMemLp:
> sub #256,r1 ; Step down 256 bytes
> mov r1,TRAP_BUF+2 ; Store as TRAP argument
> TRAP 0 ; SYS sbrk,addr
> EQUW TRAP_BUF
> bcs InitMemLp ; Memory not claimable, try a bit less
> rts pc
>
> TRAP_BUF:
> EQUW 0
> EQUW 0
> EQUW 0
> EQUW 0
>
> I end up with E000 has the highest top of memory I can claim.
> The addresses at E000 upwards are inaccessible as they are
> "elsewhere". My documentation tells me that Exxx is used
> for paged memory access, and Fxxx is I/O access, "E000+ is
> I/O" is just lazy shorthand for "not addresses I (ie the
> code) can access".

Things sounds rather crazy, but I suspect I should really look at 2.9
before I say too much.

But hardware wise, the PDP-11 usually have the I/O page at E000 in
kernel space. Physically it's at the top 8K, but with the MMU you could
in theory map things around as much as you'd like. And any sane OS do
not have the I/O page mapped for user space programs. E000 and F000 is
on the same page, and cannot be mapped separately from each other, so
your notes about paged memory and I/O access cannot be correct
literally. But I have no idea what your notes actually are about in the
end, so it's hard to say that much.

But hardware wise, there are only 8 pages on the PDP-11, and they start
at 0, 2000, 4000, 6000, 8000, A000, C000 and E000, if we talk hex.

And the notation where you seem to sometimes use #& for literals and
sometimes just # is still unclear to me. What does the '&' signify?

Is this really assembled on 2.9BSD? If so, it must be using a completely
different assembler than 2.11BSD, which I find very surprising.

Also, sbrk is about the *increment* to the dataspace you request. It's
not an absolute number. So if sbrk(E000) works, that means you probably
have all the memory, because when your program starts you already have
at least one page of memory for the code and initial data. So growing by
more than 7 pages are unlikely to ever succeed. But that do not mean the
top of the memory you have is at E000. It means you managed to *add*
E000 bytes of data to your space.

Johnny

Re: BSD2.9, sbrk() and signal()

<d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=852&group=alt.sys.pdp11#852

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:a05:622a:110d:b0:31f:1c18:eb1a with SMTP id e13-20020a05622a110d00b0031f1c18eb1amr20464264qty.292.1658959918105;
Wed, 27 Jul 2022 15:11:58 -0700 (PDT)
X-Received: by 2002:a05:6808:1a26:b0:33a:76f6:fc19 with SMTP id
bk38-20020a0568081a2600b0033a76f6fc19mr2777073oib.19.1658959917815; Wed, 27
Jul 2022 15:11:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Wed, 27 Jul 2022 15:11:57 -0700 (PDT)
In-Reply-To: <tb6qn4$idf$1@news.misty.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.96.251.164; posting-account=jgPW4gkAAACE_VxPxIZ8VykZc96-9sT_
NNTP-Posting-Host: 77.96.251.164
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com> <tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com> <tb6qn4$idf$1@news.misty.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: jgh@mdfs.net (Jonathan Harston)
Injection-Date: Wed, 27 Jul 2022 22:11:58 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1703
 by: Jonathan Harston - Wed, 27 Jul 2022 22:11 UTC

As a temporary work-around, this "works":

mov sp,r1
loop:
tst -(sp)
cmp sp,#END+64 ; push stack all the way down to just above data section
bhi loop
mov sp,r0 ; r0=bottom of memory area
mov r1,sp ; r1=top of memory area

....but it leaves an inaccessible "gap" between the end of the uninitialised
data section and the memory forced into the memory map.

Re: BSD2.9, sbrk() and signal()

<7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=855&group=alt.sys.pdp11#855

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:a37:68c5:0:b0:6b5:e9ce:183c with SMTP id d188-20020a3768c5000000b006b5e9ce183cmr3087886qkc.651.1659107446699;
Fri, 29 Jul 2022 08:10:46 -0700 (PDT)
X-Received: by 2002:a05:6870:8a13:b0:10e:7c08:36ba with SMTP id
p19-20020a0568708a1300b0010e7c0836bamr2326764oaq.19.1659107446436; Fri, 29
Jul 2022 08:10:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Fri, 29 Jul 2022 08:10:46 -0700 (PDT)
In-Reply-To: <d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=194.72.137.133; posting-account=jgPW4gkAAACE_VxPxIZ8VykZc96-9sT_
NNTP-Posting-Host: 194.72.137.133
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com> <tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com> <tb6qn4$idf$1@news.misty.com>
<d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: jgh@mdfs.net (Jonathan Harston)
Injection-Date: Fri, 29 Jul 2022 15:10:46 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3376
 by: Jonathan Harston - Fri, 29 Jul 2022 15:10 UTC

I did a load of digging and single-stepping through the BSD2.9 code
and think I've worked out what's going on - or at least enough to
get a solution that's workable enough for me.

In Bell PDP11 Unix, the signal dispatcher pages in the entire
process before calling its signal handler. BSD 2.9 appears to
do a form of lazy task switching in that it pages in the text
and stack segments and waits for actual memory access to
trigger any of the data to be paged in.

This works fine if the stack is in the stack segment, but if
the stack is in the data segment, it falls over because pushing
to the stack doesn't trigger the paging in.

This may not be completely accurate, but close enough to
work out what's happening.

Further digging finds there's a 'nostk' function call that
disconnects the SP register from the stack segment and allows
you to put it anywhere. See:
https://minnie.tuhs.org/cgi-bin/utree.pl?file=2.9BSD/usr/man/cat2/nostk.2

So, I add a call to nostk to my code, with careful shuffling
around to avoid the stack disappearing under my feet:

; Assume the only thing on the stack is a return address
; Any stack frame above SP has already been processed
; clr r1 ; r1=top of memory, start at &0000-256=&FF00
mov #&8911,TRAP_BUF ; SYS brk
.IO_InitMemLp
sub #256,r1 ; Step down 256 bytes
mov r1,TRAP_BUF+2
trap 0 ; SYS brk,addr
equw TRAP_BUF
bcs IO_InitMemLp ; Memory not claimable, try a bit less
; ; r1=top of claimed memory
; ; and Carry is clear
mov (sp),r0 ; Get return address
mov r1,sp ; Put stack at top of claimed memory
mov r0,-(sp) ; and push the return address on it
trap 58 ; sys local,nostk
equw TRAP_NOSTK
bcs nostk_not_needed ; nostk doesn't exist, don't need it anyway
; ; nb: SIGSYS caught to set Cy and return
....
rts pc
....

TRAP_NOSTK:
trap 4 ; local nostk

TRAP_BUF:
trap 0
equw 0
equw 0
equw 0

Re: BSD2.9, sbrk() and signal()

<tc0vdd$dfl$1@news.misty.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=856&group=alt.sys.pdp11#856

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!.POSTED.h77-53-236-14.cust.a3fiber.se!not-for-mail
From: bqt@softjar.se (Johnny Billquist)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: Fri, 29 Jul 2022 17:46:52 +0200
Organization: MGT Consulting
Message-ID: <tc0vdd$dfl$1@news.misty.com>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>
<tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com>
<tb6qn4$idf$1@news.misty.com>
<d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com>
<7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Jul 2022 15:46:53 -0000 (UTC)
Injection-Info: news.misty.com; posting-host="h77-53-236-14.cust.a3fiber.se:77.53.236.14";
logging-data="13813"; mail-complaints-to="abuse@misty.com"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Content-Language: en-US
In-Reply-To: <7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>
 by: Johnny Billquist - Fri, 29 Jul 2022 15:46 UTC

I just want to make a quick comment on parts of this.
I doubt 2.11BSD is much different from 2.9BSD. With regards to pages,
there is no demand paging in general. All pages are loaded and mapped
before the process can run. However, the stack page can grow dynamically.
And that is where nostk() comes in. Because by default, page 7 is
reserved for the stack, and it grows downward, and can continue into
page 6 and so on. Which means any memory allocation with brk() or sbrk()
cannot grow any further than up to the lowest stack page.

Now, if you don't actually want to use the default stack behavior in
your process, you can call nostk(), and that frees page 7, so that brk()
and sbrk() can actually get memory all the way to the top.

This also should clearly tell you that the I/O page is not in the memory
map of user processes, since that also would normally be sitting at page
7, where you have your stack.

But nostk() don't actually have any impact on your actual stack as such.
It frees memory that would otherwise be reserved for the stack normally.
Not calling nostk() don't prevent you from setting your stack to
somewhere else. It just reduces the amount of memory you have left to
play with.

Johnny

On 2022-07-29 17:10, Jonathan Harston wrote:
> I did a load of digging and single-stepping through the BSD2.9 code
> and think I've worked out what's going on - or at least enough to
> get a solution that's workable enough for me.
>
> In Bell PDP11 Unix, the signal dispatcher pages in the entire
> process before calling its signal handler. BSD 2.9 appears to
> do a form of lazy task switching in that it pages in the text
> and stack segments and waits for actual memory access to
> trigger any of the data to be paged in.
>
> This works fine if the stack is in the stack segment, but if
> the stack is in the data segment, it falls over because pushing
> to the stack doesn't trigger the paging in.
>
> This may not be completely accurate, but close enough to
> work out what's happening.
>
> Further digging finds there's a 'nostk' function call that
> disconnects the SP register from the stack segment and allows
> you to put it anywhere. See:
> https://minnie.tuhs.org/cgi-bin/utree.pl?file=2.9BSD/usr/man/cat2/nostk.2
>
> So, I add a call to nostk to my code, with careful shuffling
> around to avoid the stack disappearing under my feet:
>
> ; Assume the only thing on the stack is a return address
> ; Any stack frame above SP has already been processed
> ;
> clr r1 ; r1=top of memory, start at &0000-256=&FF00
> mov #&8911,TRAP_BUF ; SYS brk
> .IO_InitMemLp
> sub #256,r1 ; Step down 256 bytes
> mov r1,TRAP_BUF+2
> trap 0 ; SYS brk,addr
> equw TRAP_BUF
> bcs IO_InitMemLp ; Memory not claimable, try a bit less
> ; ; r1=top of claimed memory
> ; ; and Carry is clear
> mov (sp),r0 ; Get return address
> mov r1,sp ; Put stack at top of claimed memory
> mov r0,-(sp) ; and push the return address on it
> trap 58 ; sys local,nostk
> equw TRAP_NOSTK
> bcs nostk_not_needed ; nostk doesn't exist, don't need it anyway
> ; ; nb: SIGSYS caught to set Cy and return
> ...
> rts pc
> ...
>
> TRAP_NOSTK:
> trap 4 ; local nostk
>
> TRAP_BUF:
> trap 0
> equw 0
> equw 0
> equw 0

Re: BSD2.9, sbrk() and signal()

<85699c0a-4518-420e-9b27-a7a72c0a5968n@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=857&group=alt.sys.pdp11#857

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:a05:6214:e6c:b0:476:a4bd:2b95 with SMTP id jz12-20020a0562140e6c00b00476a4bd2b95mr2166337qvb.25.1659343391789;
Mon, 01 Aug 2022 01:43:11 -0700 (PDT)
X-Received: by 2002:a05:6808:b02:b0:33b:d59:8442 with SMTP id
s2-20020a0568080b0200b0033b0d598442mr6411282oij.240.1659343391468; Mon, 01
Aug 2022 01:43:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Mon, 1 Aug 2022 01:43:11 -0700 (PDT)
In-Reply-To: <tc0vdd$dfl$1@news.misty.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:e6:f0a:4700:231e:555f:6b09:7714;
posting-account=bxzfyQoAAABDBdOPzrZfAXRIKSRXmQdP
NNTP-Posting-Host: 2003:e6:f0a:4700:231e:555f:6b09:7714
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com> <tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com> <tb6qn4$idf$1@news.misty.com>
<d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com> <7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>
<tc0vdd$dfl$1@news.misty.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <85699c0a-4518-420e-9b27-a7a72c0a5968n@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: wfjm.andro@gmail.com (Walter F.J. Müller)
Injection-Date: Mon, 01 Aug 2022 08:43:11 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2122
 by: Walter F.J. Müller - Mon, 1 Aug 2022 08:43 UTC

For 2.11BSD, which most likely is similar to 2.9BSD in this respect, the situation is clear.
The [nostk man page](https://www.retro11.de/ouxr/211bsd/usr/man/cat2/nostk.0.html) makes a simple statement: _"its use is discouraged"_ .
The implementation is simple, see
https://www.retro11.de/ouxr/211bsd/usr/src/sys/pdp/kern_pdp.c.html#s:_nostk
https://www.retro11.de/ouxr/211bsd/usr/src/sys/sys/vm_proc.c.html#s:_expand
The call `expand(0,S_STACK)` releases the stack segment(s).
Keep in mind, that this also includes the environment context.

Re: BSD2.9, sbrk() and signal()

<fb8b44e8-b82a-4e39-9f7a-605172f03dfbn@googlegroups.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=858&group=alt.sys.pdp11#858

  copy link   Newsgroups: alt.sys.pdp11
X-Received: by 2002:ac8:5fc1:0:b0:31e:f847:6c6f with SMTP id k1-20020ac85fc1000000b0031ef8476c6fmr17761131qta.616.1659430975953;
Tue, 02 Aug 2022 02:02:55 -0700 (PDT)
X-Received: by 2002:a05:6808:169e:b0:331:522a:4521 with SMTP id
bb30-20020a056808169e00b00331522a4521mr8057484oib.293.1659430975679; Tue, 02
Aug 2022 02:02:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.sys.pdp11
Date: Tue, 2 Aug 2022 02:02:55 -0700 (PDT)
In-Reply-To: <85699c0a-4518-420e-9b27-a7a72c0a5968n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:e6:f12:fd00:93f8:ed8a:5ac2:4be9;
posting-account=bxzfyQoAAABDBdOPzrZfAXRIKSRXmQdP
NNTP-Posting-Host: 2003:e6:f12:fd00:93f8:ed8a:5ac2:4be9
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com> <tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com> <tb6qn4$idf$1@news.misty.com>
<d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com> <7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>
<tc0vdd$dfl$1@news.misty.com> <85699c0a-4518-420e-9b27-a7a72c0a5968n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fb8b44e8-b82a-4e39-9f7a-605172f03dfbn@googlegroups.com>
Subject: Re: BSD2.9, sbrk() and signal()
From: wfjm.andro@gmail.com (Walter F.J. Müller)
Injection-Date: Tue, 02 Aug 2022 09:02:55 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 10
 by: Walter F.J. Müller - Tue, 2 Aug 2022 09:02 UTC

2.11BSD has more syscalls than 2.9BSD. For the common ones, the syscall numbers are similar, but not always identical.
See the sysent tables
https://www.retro11.de/ouxr/29bsd/usr/src/sys/sys/sysent.c.html#s:_sysent
https://www.retro11.de/ouxr/211bsd/usr/src/sys/sys/init_sysent.c.html#s:_sysent

'setuid' is 23 in 2.9BSD and 45 in 2.11BSD.

Beyond that a remark on octal and hex. Earlier on in this thread I saw a lot of HEX numbers.
All PDP-11 hardware documentation uses octal.
The MACRO-11 assembler has binary, octal and decimal radix, but no hex.
HEX is an alien in the PDP-11 hardware world, and shouldn't be used.

Re: BSD2.9, sbrk() and signal()

<tcc56j$tq3$1@news.misty.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=859&group=alt.sys.pdp11#859

  copy link   Newsgroups: alt.sys.pdp11
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!.POSTED.m83-185-45-236.cust.tele2.se!not-for-mail
From: bqt@softjar.se (Johnny Billquist)
Newsgroups: alt.sys.pdp11
Subject: Re: BSD2.9, sbrk() and signal()
Date: Tue, 2 Aug 2022 23:33:07 +0200
Organization: MGT Consulting
Message-ID: <tcc56j$tq3$1@news.misty.com>
References: <ec26c4e4-df2f-48ca-baf8-7a30e76ca249n@googlegroups.com>
<tb5ssk$e76$1@news.misty.com> <tb6djt$2gf$1@news.misty.com>
<3dfe2046-0b4f-4fac-a85a-2e3ca7303981n@googlegroups.com>
<tb6ket$asv$1@news.misty.com>
<90f2b1a8-7387-4314-8dcd-4caa89093ed6n@googlegroups.com>
<tb6qn4$idf$1@news.misty.com>
<d296c707-d39a-4e29-a888-220bf0e6f9bcn@googlegroups.com>
<7e19d1c6-cf5a-40c6-9486-f4f25916db0dn@googlegroups.com>
<tc0vdd$dfl$1@news.misty.com>
<85699c0a-4518-420e-9b27-a7a72c0a5968n@googlegroups.com>
<fb8b44e8-b82a-4e39-9f7a-605172f03dfbn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 2 Aug 2022 21:33:07 -0000 (UTC)
Injection-Info: news.misty.com; posting-host="m83-185-45-236.cust.tele2.se:83.185.45.236";
logging-data="30531"; mail-complaints-to="abuse@misty.com"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Content-Language: en-US
In-Reply-To: <fb8b44e8-b82a-4e39-9f7a-605172f03dfbn@googlegroups.com>
 by: Johnny Billquist - Tue, 2 Aug 2022 21:33 UTC

On 2022-08-02 11:02, Walter F.J. Müller wrote:
> 2.11BSD has more syscalls than 2.9BSD. For the common ones, the syscall numbers are similar, but not always identical.
> See the sysent tables
> https://www.retro11.de/ouxr/29bsd/usr/src/sys/sys/sysent.c.html#s:_sysent
> https://www.retro11.de/ouxr/211bsd/usr/src/sys/sys/init_sysent.c.html#s:_sysent
>
> 'setuid' is 23 in 2.9BSD and 45 in 2.11BSD.

There are also differences on how parameters are passed. With 2.11 it's
always on the stack. With 2.9 it's some stack, some register content.

> Beyond that a remark on octal and hex. Earlier on in this thread I saw a lot of HEX numbers.
> All PDP-11 hardware documentation uses octal.
> The MACRO-11 assembler has binary, octal and decimal radix, but no hex.
> HEX is an alien in the PDP-11 hardware world, and shouldn't be used.

I would agree that it feels more "normal" to use octal. But it's
incorrect that MACRO-11 don't have hex. It do. You just need a new
enough version; ^X is in there.

Johnny

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor