Re: Silly new instructions



"Peter \"Firefly\" Lund" <firefly@xxxxxxx> writes:

> On Sat, 13 Aug 2005, Dan Koren wrote:
>
> > One could also argue the case that having the SP
> > and the PC (almost) invisible and inaccessible to
> > (user mode) software could bring very considerable
> > benefits.
>
> So you could load/store stuff relative to the SP (and possibly
> relative to a base pointer) but you couldn't get the effective address
> of that stuff?
>
> That wouldn't play well with automatic arrays in C, for example, as
> they are typically implemented.

And similarly for call-by-reference to stack-allocated objects an
Pascal-style non-local variables.

Moving the SP to an unnumbered register with limited access will
require a complete rethinking of the way addresses are handled. It
could work like this:

- Registers and memory add an extra tag bit that identify whether
what you have is a pointer or integer.

- Pointers are always intervals of memory addresses, so they take up
two words/registers (aligned). The tag bit in the second word
indicates whether the interval stores code or data. The PC is an
interval plus offset.

- No pointer arithmetic, only pointer+offset.

- Load/store instructions take a pointer and offset and trap if the
offset takes the address outside the interval. Store to code
addresses is not allowed in user mode.

- All jumps are relative to an address (i.e., interval) stored in a
register-pair or memory (or current PC). It is checked that the
offset is within bounds and that the address is to code (when in
user mode).

- Instructions exist for joining adjacent intervals or splitting an
interval in two. These can be used for managing stacks, heaps etc.
You can only join intervals of the same type (code or data), and
when you split an interval, the two new intervals will be of the
same type as the original.

- When overwriting a register or memory-word that is tagged as an
address interval, both words in the interval must be overwritten.
I.e., you need to check the tags for the full double-word.

- Superviser mode can set up intervals at "real" addresses and tag
them as desired.

Note that this doesn't give full protection, as it is possible to
split an interval and still load/store relative to the original. But
it means that you can give a user process access only to limited code
and data spaces.

Note that it is, AFAICS, possible to implement C with these
restrictions. Pointers just take up more space than usual (three
words: Two for an interval and one for an offset into this).

Torben

.



Relevant Pages

  • dynamic allocation file buffer
    ... between concurrently running programs (IPC / shared memory). ... and does not offer persistence, ... a program can acquire the offset of an unused block of a ... Node: tag: b ...
    (comp.lang.python)
  • Re: dynamic allocation file buffer
    ... between concurrently running programs (IPC / shared memory). ... and does not offer persistence, ... a program can acquire the offset of an unused block of a ... Node: tag: b ...
    (comp.lang.python)
  • Re: different way of finding out offsetof a member in structure
    ... of finding out the offset of a variable in structure. ... pointer creates a null pointer, which does not point to address 0, ... but in this case its a restricted memory architecture. ... this depends on the architecture. ...
    (comp.lang.c)
  • Re: Problem using With statement
    ... first thing in the block is a pointer to the Virtual Method Table. ... offset in their respective VMTs. ... When you instantiate a TA object, it will allocate memory for a VMT ...
    (comp.lang.pascal.delphi.misc)
  • Re: NULL with representation other then all bits 0
    ... >> Pointers have a range from 0 to the maximum allowed memory address. ... A pointer only has to point. ... > process id, segment id, page id, page offset, and bit or byte. ...
    (comp.lang.c)