I believe it’s better to implement the Forth stack by hand and separate from
the machine stack. The best machine to do that was the Motorola 6809,
because it had separate machine and user stacks: once in my remote past I
implemented a “Tiny Forth” for the 6809 that ran inside a 2K Eprom and had a
fair amount of functionality, and it had pretty close to the whole of the
Forth 79 standard inside a 4K Eprom. The Motorola 68K was good too, because
of its post-increment and pre-decrement addressing modes. So, the Forth
Stack becomes just a nonpaged memory buffer, and it operates separate from
the system stack which runs on the machine stack. The problem of
intertwining the Forth user stack with the machine stack is, you never know
who’s going to have pushed stuff onto it at what time ! You think you have
your operands on the stack when you do a ROT, and you’re instead messing up
somebody else’s interrupt stack…
Alberto.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Thursday, June 10, 2004 10:48 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Want to create a segment selector I can use
Well, this is quite interesting :).
For the OP, and I could be (at present ) really off of the mark, but LDT is
per process IIRC, so if you have the right process context, and if you
create a seg sel. into an unused slot, then the there is more, it has to be
mapped properly. But if all are done properly, when a context switch
happens, the new map should not affect !!! For that, the only requirement is
that the space you are after is pageable per process area !!! Adress space
mapping is per process, so we dont need to worry about any collision there
due to thread switching within a process, I suppose.
I dont know of anyway to execute an user stack at ring 0 ( specially of
NT+ ), but if you catch it under kernel, so that you gurantee that it is
your process, you capture the VM of the process, but you are in kernel stack
execution.
-pro
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Moreira, Alberto
Sent: Thursday, June 10, 2004 6:56 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Want to create a segment selector I can use
One relatively easy way to implement Forth threads is to do it inside your
Forth system itself. The context switching is easy, all you have to do is to
switch the Forth Stack, although it may help to split your dictionary into
two, a global and a local one, so that each FThread has its own local dict
that links upwards to the global dict. The task switcher is peanuts to
implement if you do it within your Forth system: a thread is just another
Forth stack and possibly another local dictionary. I find this approach a
lot cheaper than to try to mess with OS-level structures.
We did this way back in 1981, on Sperry DCPs running Telcon and on Sperry
1100s running Exec 8, and it worked wonders. No need to fiddle with the
hardware, it’s all within the VM.
The problem of writing to the LDT and such like things is that it works fine
provided you have full control of the system. However, if you’re running
within Windows, you don’t know when the OS is going to take over your
hardware and mess with it, or worse, assume something that you forgot to do
or that you just couldn’t do: you will manage to seize full control from
Windows (well, we do that here at Numega, hence it’s possible) but it’s a
big and complex job. So, I find it best to implement threading inside your
Forth VM, and plug it onto Windows somehow, without bothering their
mechanisms. Once you do that, the Forth environment itself will allow you to
take things over seamlessly, for as long as you want, specially if your
Forth has a decent compiling facility.
Hope this helps !
Alberto.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Michael Clagett
Sent: Thursday, June 10, 2004 2:05 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Want to create a segment selector I can use
Hi –
I am developing a Forth-based virtual machine that is able to bootstrap
itself into existence from within some host program. It relies on the host
to allocate for it a 1 MB piece of memory and then proceeds to write intel
opcodes to that memory for a basic 32-instruction machine and a rudimentary
parser, after which it parses and executes an increasingly powerful set of
Forth language instructions to build a more capable processing environment.
For the basic machine I take over the eax, ebx, ecx, edx, esi, edi and ebp
registers.
This has been entirely adequate up to now, but now that I am implementing
threads, I find that I need another register to give me access to per-thread
data structures. I can’t use the stack, code or data segment registers, but
I do notice that the es segment is sitting there unused. And what I would
like to do is be able to load a sgement selector index into it that will
ultimately point me back to a piece of memory that is part of my original 1
MB. So I would like to create a Local Descriptor Table entry for each
thread whose base address points to a data structure allocated by the forth
code already running. I figure that if I can get that to work, then I can
just use a segment override together with the other registers I already use
to read from and write to my thread-owned data and let the OS worry about
switching my tasks.
I can’t really use the stack for this purpose, since I’ve taken over ebp and
thus don’t really have a stack frame per se to work with. Bit I think this
approach I’ve outlined above should work pretty well, if my reading of the
Intel docs is correct. It may also give me the benefit of being able to
install one of my machines (the basic execution engine is really pretty
small) into code running at the kernel level and do driver work with it –
providing I don’t discover some show-stopper along the way that nixes the
idea.
After searching for the better part of a day, I can’t find sample code
anywhere that will show me how to allocate new segment selectors and install
them in the LDT. It looks like it should be as simple as getting the LDT
pointer form the Local Descriptor Table Register, creating a new selector
structure (there’s enough code out there that shows how to do that) and then
finding an available slot to stuff it into. It’s this last step that leaves
me a little perplexed. I can’t find anywhere any sort of protocol for doing
this in a safe and well-behaved way. I suppose I could just find the first
entry whose contents are still uninitialized and put my selector there. But
how do I know that some other process won’t come and trash it out from under
me? And how would that other process know that my selector slot is already
being used – especially if it does something icky like loading its own
selectors into a statically determined slot?
So my questions are two: First, am I totally out to lunch here or should I
in theory (or even better, in practice) be able to do what I am suggesting?
And second, how do I do this in a safe way. I guess a third question would
be, do I have to be at privilege level 0 to write to the LDT and if so, is
there any way I can put myself there from a user-mode program?
I would greatly appreciate some guidance from those more knowlegeable and
mighty than myself.
Thanks much,
Mike
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@garlic.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.