Re: Darwin
Re: Darwin
- Subject: Re: Darwin
- From: Michael Crawford <email@hidden>
- Date: Mon, 20 May 2013 13:25:07 -0700
Very few Macs were manufactured that used the 32-bit i386 Core Duo. Since late 2006 or early 2007 they have used the 64-bit Core 2 Duo (desktops and notebooks) or the Xeon (Mac Pro workstation). The edition of Understanding the Linux Kernel that I've got only covers 32-bit hardware memory management, but Intel's website should have a good explanation of 64-bit. Let's see if I can find it... no, it's not showing up when I search.
There is a wealth of information at
http://software.intel.com/ What you need to know is how the 64-bit segment registers are programmed. In the 32-bit protected mode at least, there is a flat address space that has hardware enforcement, as opposed to the old 16-bit segmented address space, in which user code could overwrite any of the memory addresses,.
You should be able to download a PDF of Intel's reference manual for the Core 2 Duo. That will have an explanation of all the registers. There are a lot of them, many of which are accessible only from supervisor mode - kernel mode, or x86 Ring 0.
The 64-bit x86 architecture was originally developed by AMD as AMD64. Intel at the time was focussing its 64-bit on the Itanium, which in no way resembles i386. AMD64 is a straightforward extension of i386, and was so successful that - without really openly admitting it - Intel adopted, but with some changes, called EM64T.
I'm pretty sure the userspace architecture (Ring 3 or user mode) is the same between AMD64 and EM64T, but there are lots of differences in the supervisor mode or Ring 0 architectures. Apple doesn't use AMD CPUs, but you'll see the differences mostly if you work on virtualization, such as the open source Xen and VirtualBox VMs.
The AMD64 architecture used to be documented at
http://www.amd64.org/ but that site doesn't seem to be there anymore. A cybersquatter has
amd64.com ;-)
The modern Intel assembly code is very complex and very hard to learn, with lots of cryptic mnemonics. If you want to learn Intel assembly, the best place to start IMHO is Pentium Processor Optimization Tools by Michael L. Schmit. It's long out of print, but can be had used. It comes with a floppy containing an assembly code "optimizer" that would produce a commented code listing pointing out such things as pipeline stalls.
32-bit Pentium assembly will run on a 64-bit Mac. Don't use gas (the GNU Assembler), use nasm. gas isn't really meant for programmers to use directly, but as a back-end for GCC. nasm has friendly features like better diagnostic messages, macros and so on.
There is very little reason to actually write assembly anymore, however there _is_ lots of assembly in the kernel, used to execute CPU instructions that are not accessible from C or C++, such as programming the MMU. However I have long found that it is very helpful to know how to _read_ assembly, and mentally translate it into the corresponding C source, so that I know how to debug a crash in someone else's code.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Darwin (From: Christ Levesque <email@hidden>) |
| >Re: Darwin (From: Alexander von Below <email@hidden>) |
| >Re: Darwin (From: Michael Crawford <email@hidden>) |
| >Re: Darwin (From: Alexander von Below <email@hidden>) |