minf...@arcor.de writes:
>I am no OS expert but I once read that for 32-bit applications the Win64
>system emulates a Win32 environment and provides a different set of runtime
>libraries with it.
Yes, something like this. On AMD64 32-bit has a different
architecture (the same instruction bits mean something different than
in the 64-bit architecture) than the 64-bit stuff. 32-bit code is
executed on a 64-bit OS in compatibility mode; when such a program
makes a system call, the CPU switches to 64-bit mode, but of course it
knows that the system call is coming from a program running in
compatibility mode and acts accordingly (essentially every system call
has a 32-bit variant and a 64-bit variant). I expect that it's the
same in ARMv8.
For architectures that run 32-bit and 64-bit code in the same mode,
the OS can use the same system call infrastructure, but has to ensure
that it never hands an address outside the 32-bit range to a 32-bit
application.
>So I fear that the address space >4 gigs is not emulated and CQ@ won't work.
>
>I don't know whether BSD/Linux/OSX behave similarly.
On AMD64 there is no other way to deal with legacy 32-bit code, so
yes, they all deal with it in this way.
There has been an effort to define a 32-bit ABI for AMD64 64-bit mode
(called x32) for Linux, similar in spirit to what the single-mode
architectures do for 32-bit code. That would be a platform for
implementing a 32-bit Forth that could have a CQ@. Of course, if you
use this mode as it is intended, there is no need for a CQ@, because
the OS will never make any address accessible that you cannot access
with C@.
x32 did not catch on; given that we have (32-bit) IA-32 and (64-bit)
AMD64, there is no need for x32; people argued for x32 with
performance advantages, but they were obviously not enough. Lesson
for Forth systems: Just go with 64 bit cells on 64-bit platforms.
The failure of x32 has not been enough of a lesson, so there are
people proposing the same thing for Aarch64 (Aarch64 ILP32); they have
a slightly better case, because there are CPUs in the pipeline that
understand Aarch64, but not 32-bit ARM, and there may still be some
(C/C++) code around that does not port to 64-bit platforms). Still,
even the page presenting this ABI
<
https://wiki.linaro.org/Platform/arm64-ilp32> it says:
| This is a very weak reason for a whole new ABI, but it is technically
| possible if people wish to do the work.
My guess is, that like for x32, there will be a lack of people who
wish to do the work.
However, for a Forth system like those of Albert van der Horst that
just deals with system calls and never calls a library function, the
Forth system implementor can do the work: Have 32-bit cells, ask the
OS for addresses in 32-bit space (e.g., with the MAP_32BIT flag of
mmap in Linux), and you have a 32-bit system. And when you then
allocate memory outside the 32-bit range (by not using MAP_32BIT), you
get addresses that need a CQ@ or somesuch. I would not recommend
using such a system, but who knows, maybe it's just what everybody
else in the the world has waited for.