-5

To which memory location does the stack pointer point at the beginning of the program in PDP 11? And what can be the end address the SP can point to before overflow occurs?

  • 1
    SOme PDP-11s have more than one stack pointer. – tofro Jun 6 '17 at 20:42
  • 4
    We need more information to answer your question. At the beginning of the program -- do you mean after hardware reset? Or after the operating system has loaded your application? And then, which operating system? – Wilson Jun 6 '17 at 20:49
  • Methinks this is a homework question. – Alex Hajnal Jun 28 '18 at 12:38
  • @AlexHajnal For which class? Do they teach retrocomputing somewhere? – Leo B. Jun 30 '18 at 1:23
  • @LeoB. Yes, at the Technion. They use either the PDP-11 or VAX architecture (I forget which) for some of their undergrad computing classes. – Alex Hajnal Jun 30 '18 at 1:38
3

A "naked" PDP-11 (at least the ones I've seen, might also have been preconfigured) would start up with the system stack configured to &400 to &777 (& == octal notation, as common on the PDP-11) and execute code typically starting from &1000 (the next address beyond the stack top). As it's unclear what you mean with "program", I'd assume the initial startup after reset. The area below the stack (&000-&377) holds the interrupt and trap vectors.

What happens after that is entirely dependant on the operating system and machine configuration.

As you see from the above, the system stack cannot technically grow lower than &400 (it would overwrite the vector area) - Actually, the PDP-11 has a stack limit register that monitors stack usage and will execute a processor trap once the stack grows into a configurable "yellow zone", and a reset if the stack grows even lower into what DEC called the "red zone".

From the PDP-11/40 manual:

PROGRAMMABLE STACK LIMIT

The stack limit allows program control of the lower limit for permissible stack addresses. This limit may be varied in increments of &400 words, up to a maximum address of &177400, almost the top of a 32K word memory. The normal boundary for stack addresses is &400. The stack limit option allows this lower limit to be raised, providing more address space for interrupt vectors or other data that should not be destroyed by a program.

The contents of the stack limit register (SL) are compared to the stack address to determine if a violation has occurred (although memory references that do not alter memory are always allowed). The least significant bit of the register (bit 8) has a value of &400. The determination of the violation zones is as follows:

  • Yellow Zone = (SL) + (&340 through &377) execute, then trap.
  • Red Zone = (SL) +(&337) abort, then trap to location 4.

If the stack limit register contents were zero:

  • YellowZone = &340 through &377
  • RedZone = &000 through &337

The stack limit register is, to my knowledge, exclusively available in the PDP-11/40 and sits at location &177400. You could thus reserve a protected memory zone between the stack and the vector area.

Once the OS is loaded, the limits and locations can, depending on the operating system, be entirely different. Note the PDP-11 supports virtual memory and a larger system address space than addressable by a single process and can page in/out memory, the variance between OSs can be significant.

  • The stack limit register is completely new to me. I didn't think the PDP-11 had anything like that. Could you provide more information about how that worked? – Wilson Jun 6 '17 at 21:17
  • @Wilson See my edit, was too much for a comment. – tofro Jun 6 '17 at 21:28
3

In UNIX V6:

# STTY -LCASE
# chdir tmp
# echo 'main() { int x; printf("%o\n", &x); }' > stack.c
# cat stack.c
main() { int x; printf("%o\n", &x); }
# cc stack.c
# ./a.out
177744
# 

The stack starts at the very top of the virtual memory, then the kernel puts the command line plus the argv array there; plus the space for saved registers at the start of main; overall, there are 26 bytes used before the stack space for the local variables in main starts.

When main() is called recursively, the execution, after a considerable wait, ends with

22336
22320
22302
22264
22246
Memory fault -- Core dumped

whereas size a.out shows a mere 638+58+530=1226 (2312).

That looks like a swap space exhaustion rather than a limitation. Ostensibly, the stack can grow down to the page just above the highest page containing dynamically allocated memory.

2

If you are programming a 'bare metal' PDP-11 (no operating system or program loader) then you should not assume the stack pointer (R6) is initialized to any particular value (i.e. you need to initialize it yourself). If your PDP-11 has front-panel toggle switches you can set R6 by toggling a value into location 177706. Presumably this could also be done on later systems using Console ODT.

If you are running a program under an operating system or monitor, the initial value of the stack pointer will typically be set for you, but the exact value may vary. The documentation for the operating system or monitor you're running should tell you.

The lower bound of the stack pointer is 256 (400 octal). If a stack 'push' operation causes the stack pointer to fall below that limit (the stack grows downwards) it will trigger a Stack Overflow trap (via the trap vector at address 4). This is described in chapter 2, page 43 of the 1969 edition of the PDP-11 Processor Handbook (http://gordonbell.azurewebsites.net/digital/pdp%2011%20handbook%201969.pdf)

  • 1
    Note that different PDP-11 models behave slightly differently, and what a machine does when it is powered on depends on things like the processor model, settings of the front panel switches, whether you have core memory or not, and what kind of boot options you have installed. A PDP-11/20 for example might trap to location 24 on power up (the Power Fail trap) and what happens next will depend on what is stored in the words at that location. – Ken Gober Jun 6 '17 at 21:51
  • But OP does not say he's using R6 as the stack pointer. Any register will do, R6 is just a convention. – Wilson Jun 28 '18 at 18:32
1

I can answer for the Soviet computer BK-0010, which uses a clone processor of PDP-11. When a user's program would start, its atarting address would be &1000 and SP would be initialized to the same value as well (the stack would grow backwards while PC would grow forward).

  • 1
    Not a clone, rather a reimplementation. – Wilson Jul 4 '18 at 14:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.