32-bit kernel that runs 64-bit apps

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: 32-bit kernel that runs 64-bit apps

Post by Combuster »

The 32-bit kernel (...) doesn't pick the 32-bit version from the universal binary but uses the 64-bit version
Citation needed. Your previous link demonstrated nothing.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 32-bit kernel that runs 64-bit apps

Post by iansjack »

Citation needed.
Mac OS X Internals - A systems approach, 1st Edition, Section 8.18.2.2.

Now, can you return the courtesy and give a citation as to why it is impossible to run 64-bit applications on a 32-bit kernel?

"Impossible is a word to be found only in the dictionary of fools."
Napoleon Bonaparte
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 32-bit kernel that runs 64-bit apps

Post by Brendan »

Hi,
Combuster wrote:
The 32-bit kernel (...) doesn't pick the 32-bit version from the universal binary but uses the 64-bit version
Citation needed. Your previous link demonstrated nothing.
As far as I can tell; it's all smoke, mirrors and lies.

For a lot of micro-kernels; the idea is to have an "OS personality" running on top of it. For example, you might have an L4 kernel with a POSIX style personality running on top. Part of this idea is to allow several different "OS personalities" on the same machine at the same time. The Mach micro-kernel is like this too.

So, what Apple do is they take the micro-kernel, and add an "OS X personality" layer on top (mostly by taking code from FreeBSD). Then they bastardise it to run the "OS X personality" at CPL=0 so they can ram device drivers into it like a monolithic system. After that they try to pretend that the real kernel doesn't exist and that the "OS X personality" (which runs in its own address space like a normal task) is the "kernel".

Of course for a system like this, if the real kernel (the Mach micro-kernel) is 64-bit and is capable of running 32-bit tasks (including 32-bit "OS personalities"); then you get a situation were stupid people believe a whole pile of crap (e.g. that an over-privileged 32-bit task is a "32-bit kernel" and it "runs 64-bit processes", when it only actually tells the real kernel to run those 64-bit processes).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 32-bit kernel that runs 64-bit apps

Post by iansjack »

I take it you haven't read the requested citation? ;)

What seems to bother no-one is that the 32-bit OS X kernel would run on a 32-bit processor. Not bad for a 64-bit kernel. :)

"Why, sometimes I've believed as many as six impossible things before breakfast."
Lewis Carroll
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: 32-bit kernel that runs 64-bit apps

Post by Combuster »

Mac OS X Internals - A systems approach, 1st Edition, Section 8.18.2.2
(...) two architectures: ppc and ppc64
That's not x86.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: 32-bit kernel that runs 64-bit apps

Post by mallard »

iansjack wrote:What seems to bother no-one is that the 32-bit OS X kernel would run on a 32-bit processor. Not bad for a 64-bit kernel. :)
Pseudocode:

if detected processor is 64-bit capable:
initialize 64-bit parts of kernel
else:
initialize 32-bit parts only

And if we look at the actual source code to Apple's Mac OS X kernel (XNU), we find a block of code that appears to do exactly that in i386_init.c and more code that appears to selectively enable 64-bit features in pmap.c... I think it's pretty safe to say that the osfmk (Mach) layer is capable of running in either 32 or 64-bit mode, while the BSD layer seems to be either word-length independent or 32-bit only, it's hard to tell from the code. (__darwin_ptrdiff_t seems to be 32-bit if there is no compiler provided __PTRDIFF_TYPE__, but most other pointer-related types are based on "long" which switches, assuming an LP64 compiler).
Image
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 32-bit kernel that runs 64-bit apps

Post by iansjack »

That's not x86.
The question was "can a 32-bit kernel run 64-bit apps". Don't limit your thinking to just one processor. There's a whole wide world out there.

But the same process applied to Intel versions of the kernel too.

Whether you think a 64-bit aware kernel cannot be a 32-bit kernel just because it runs 32-bit code is another matter. If not then, by definition, such a kernel is not 32-bit (but it's not 64-bit either, so perhaps we'll have to call it 48-bit ;)).

I'm a little surprised by some of the narrow thought processes in this thread. I've seen assertions that, for example, a 32-bit kernel couldn't understand 64-bit page tables. Goodness only knows how any 64-bit kernel ever gets itself started since it needs such a page table in the first place. I'm glad to say that I can handle 64-bit page tables with 32-bit code. It's not rocket science.

Now, I think this subject has been done to death.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: 32-bit kernel that runs 64-bit apps

Post by Combuster »

iansjack wrote:
That's not x86.
The question was "can a 32-bit kernel run 64-bit apps". Don't limit your thinking to just one processor.
iansjack wrote:The 32-bit Intel kernel could run 64-bit Intel userspace applications
Just accepting the fact that you were wrong is also an option. A healthy one even.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: 32-bit kernel that runs 64-bit apps

Post by Bender »

I'm not sure if this is sane but would it be possible to use Intel-VT or AMD-V virtualisation technologies to run 64 bit applications under a 32 bit environment?
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 32-bit kernel that runs 64-bit apps

Post by iansjack »

Good point. You can indeed run a 64-bit guest on VirtualBox running on a 32-bit host. So, another example of a 32-bit kernel running 64-bit programs.

Of course, everyone knows that that is not possible. ;)
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: 32-bit kernel that runs 64-bit apps

Post by Gigasoft »

This thread is silly. It is a matter of fact that the 32-bit version of the OSX kernel consists mainly of 32-bit code, which anyone can easily confirm by looking at the code instead of trying to reason away facts. There is only a tiny amount of 64-bit code having to do with 64-bit exception vectors, 64-bit syscalls, etc. If the CPU doesn't support long mode, it's simply not used. My OS does the same thing, and it's not particularly hard. There are about 20 places in the OSX kernel where it explicitly cares about whether the CPU is 64 bit.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 32-bit kernel that runs 64-bit apps

Post by Brendan »

Hi,
iansjack wrote:I take it you haven't read the requested citation? ;)
I take it the citation was written by a stupid Apple fanboy that can't see past their lies.
iansjack wrote:What seems to bother no-one is that the 32-bit OS X kernel would run on a 32-bit processor. Not bad for a 64-bit kernel. :)
What you're saying is that the "32-bit OS X personality" can run on top of a 32-bit Mach kernel or a 64-bit Mach kernel. So what? Most 64-bit kernels can run 32-bit tasks.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 32-bit kernel that runs 64-bit apps

Post by iansjack »

So what? Most 64-bit kernels can run 32-bit tasks.
On a 32-bit processor? Those Apple guys are cleverer than I thought. ;)

Gigasoft is right - this discussion is very silly. I suspect that half the contributors have never used OS X.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 32-bit kernel that runs 64-bit apps

Post by Brendan »

Hi,
iansjack wrote:
So what? Most 64-bit kernels can run 32-bit tasks.
On a 32-bit processor? Those Apple guys are cleverer than I thought. ;)
Nobody said that the 64-bit Mach kernel runs on a 32-bit CPU (you'd use the 32-bit Mach kernel for that). This is what's called a "red herring" - it indicates that you know your argument is false but aren't willing to admit it, so you pretend I said something I didn't in an attempt to hide your shame.
iansjack wrote:Gigasoft is right - this discussion is very silly. I suspect that half the contributors have never used OS X.
There's no logical connection between using something and knowing how it works.

There's probably billions of people that drive cars that don't know how combustion engines or transmissions work, and probably billions of people that use all sorts of OSs (including OS X) that don't know how they work. In the same way it's possible for someone to know how combustion engines and transmissions work without driving a car; and possible for someone that doesn't use OS X to know you're "misguided".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 32-bit kernel that runs 64-bit apps

Post by iansjack »

milouz wrote:Hi,

I thought that it was impossible to have a 32-bit kernel running 64-bit apps... until I read that some versions of Mac OS X kernel, despite being 32-bit, can effectively run 64-bit apps :shock:

Does anyone knows a little bit more about this ? I really can't figure out how it can be possible :?:
Let's try and make this my last word on what has turned into a very silly discussion (but very thought provoking OP).

Can 64-bit programs run on a 32-bit processor? Yes, but it would take a deal of emulation and would be pretty slow.

Can 64-bit programs run on a 32-bit OS? As Apple demonstrates, yes they can.

Is 32-bit OS X truly a 32-bit program? It will run on a 32-bit processor so, by any reasonable definition, yes it is.

On a 32-bit processor can OS X run 64-bit programs? No.

Does the 32-bit OS X kernel contain any 64-bit instructions? By definition, to be able to run 64-bit programs an OS must be 64-bit aware. This will involve some 64-bit instructions that will be called when a 64-bit user program is run.

Does that make the kernel 64-bit? No. Those instructions are just the glue that allows interaction between the 64-bit programs and the 32-bit kernel. They are, if you like, the 64-bit personality. This no more makes the kernel 64-bit than the 32-bit personality of a 64-bit kernel makes it 32-bit. The kernel functions perfectly without them but, in that case, it wouldn't be able to run 64-bit programs.

Was the mythical 32-bit OS X kernel just a marketing ploy by Apple to downplay their OS? Let's not get too silly!
Locked