GDTR and Segmentation in x86_64 - x86-64

As per the Intel® 64 and IA-32 Architectures
Software Developer’s Manual In 64-bit mode, segmentation is generally (but not completely) disabled, creating a flat 64-bit linear-address space. Does that mean GDTR is not needed/present in a x86_64 CPU?

Related

Operating system's performance

Will there be a difference in the performance of a 32 bit operating system running on 64 bit processor and a 32 bit operating system running on 32 bit processor?
Just realized this didn't specify x86. I don't know if any ARMv8 CPUs are slower in ARMv7 mode than a similar-cost ARMv7 CPU.
You can't really compare apples-to-apples, because there's no such thing as a 64-bit CPU that's exactly the same as a 32-bit CPU except for supporting 64-bit mode. There are always other microarchitectural changes, too. (Like from Pentium M to Core2 on Intel.)
If we're talking about x86, then no. A 64-bit capable x86 CPU is no worse at running 32-bit code. This is called "legacy mode", as opposed to "compat mode" (32-bit user-space under 64-bit OS), but they perform the same.
In fact, the only CPUs that can't run in x86-64 mode these days are old, slow, or both. e.g. using a 32-bit-only CPU means you're running on Pentium4, Pentium-M, or an old Atom! Or Athlon-XP. Or an embedded x86 like Geode.
This is the same reason that 32-bit software is still widely used under Windows (although usually under a 64-bit OS).
The option you didn't mention is the high-performance one: 64-bit OS on a 64-bit CPU, even if you want to run 32-bit user-space code.
Especially if you have more than 1 or 2GB of RAM, it's likely that your system will run faster with a 64-bit kernel. 32-bit kernels can use more RAM, but it's ugly and not as fast as if the kernel can have all physical memory mapped into kernel-space virtual memory. See Linus Torvald's comments on PAE (Physical-Address Extensions)
See the x86 tag wiki for more about how x86 CPUs perform, and how to optimize for them.
Yes because you wouldn't make full use of all those 64bits. If you have a 32bits OS than you will only use that and not 64. However, if you were to have 64bits OS than it will make full use of those bits.
Also, please have a look at:
https://www.howtogeek.com/194119/why-are-most-programs-still-32-bit-on-a-64-bit-version-of-windows/
and
http://www.osnews.com/story/5768

Why is "amd" written in many installers?

I have seen many installers like that of Python and Ubuntu which has "amd" on them. Why is that so? Can I run those programs on my laptop having intel cpu? Please explain to me in detail. Thanks :)
It's not just AMD, it's AMD64.
Linux/gcc's names for x86 architectures are: i386 for 32bit, and amd64 for 64bit.
AMD designed x86-64, and amd64 existed as a name for it before Intel's first ia-32e CPUs were released. (Yes, Intel made up their own name for it. Also note that ia-64 is Itanium, not x86-64.)
(See the x86 tag wiki for vendor manuals and assembly-language info).
You get your answer from the following excerpt from wikipedia.
x86-64 (also known as x64, x86_64 and AMD64) is the 64-bit version of
the x86 instruction set. It supports vastly larger amounts
(theoretically, 264 bytes or 16 exbibytes) of virtual memory and
physical memory than is possible on its 32-bit predecessors, allowing
programs to store larger amounts of data in memory.

What do x86_64, i386, ia64 and other such jargons stand for?

I frequently encounter these terms and am confused about them. Are they specific to the Processor, or the Operating System, or both?
I have Ubuntu 12.04 running on Intel i7 machine. So which one of them would apply for my case?
They are processor instruction set names:
i386 is the name of the 32-bit instruction set first implemented by Intel in the 386 processor. It became dominant thanks to dirt-cheap PC hardware.
x86-64 is the name of the AMD extension added to i386 to make it capable of executing 64-bit code. This is the one you have. It is highly compatible with i386 and will execute a 32-bit program as fast as an i386 processor.
ia64 is the name of the instruction set used in Itanium processors. The other 64-bit architecture that nobody uses anymore.
Those are cpu instruction sets. Apps installers are compiled to some subset of them. Here most difference is between 32bit(i386) and 64bits(x86_64 and ia64). You can not run app for 64bit on 32bit cpu but in reverse usually yes.
x86_64 (AMD64) cpu is most common instruction set as comes to 64bit cpu on desktop computer. It is from AMD which was few years earlier with their cpu which worked fine with x86(32-bits) instructions also.
ia64 (itanium) is from intel. Itanium works fast only with 64bits and is still used in industry.
Intel now uses x86_64 instructions from AMD due to its popularity in industry.
Sometimes key "amd" at installer package name is present and it is what you need for 64bit intel cpu.
i386 is quite old (Pentium times, pentium III has i686). To determine 32bits architecture(on desktop computers) also is used term x86 (aliases: IA-32, x86-32). There are also other architectures 32/64bit like ARM from smartphones.
Other cpu instruction sets can make compression, video coding/decoding, virtualization, random generators, security etc. to be faster and better. Windows 8 require PAE, NX, SSE2 (some of those are not present in ARM cpus so you have other version of Windows 8RT for them).
In hardware, x86_64 is a type of processor that can run both 32bit and 64bit applications just fine where ia64 runs 32bit applications SLOWER than any other CPU, as it is meant for 64bit only applications.
Moving on to the software side. I'm not sure about Ubuntu, but generally a 64bit Windows OS will allow you to use more than 3.3GBs of memory as well as the advantage of using your 64bit hardware to address memory better and have bigger than 2GB processes running. Usually on a 32bit, once an application reaches the 2GB limit, you'll get a OutOfMemory error from your application.
For a full article, refer to: http://en.wikipedia.org/wiki/64-bit_computing

Are "ia64" and "amd64" interchangeable in clickonce manifests?

I'm working on a tool which modifies clickonce manifests. I found an ambiguity in the MSDN documents around the clickonce application manifest. It says:
Specifies the processor. The valid values are msil for all processors,
x86 for 32-bit Windows, IA64 for 64-bit Windows, and Itanium for Intel
64-bit Itanium processors.
But yet, this doesn't cover all values. If I compile a clickonce application for a 64-bit only executable, I'll get a manifest with the value amd64. Is this interchangeable with ia64?
amd64 and ia64 are completely different plaforms. They are not interchangeable. The comment from microsoft is indeed misleading.
IA64 refers to Intel's Itanium CPU (developed in partnership with HP) which is 64-bit but which is NOT compatible with the widely used Intel x86 architecture (386,486,Pentium,CORE i3/i5/i7,various AMD,etc). The IA64 CPU uses a completely different instruction set than x86, and the IA64 instruction set implements a design known as VLIW (Very Long Instruction Word).
HP was apparently the main vendor of IA64 systems and they had developed the CPU (with Intel) as a replacement for their own RISC CPU, the HP PA-RISC. HP used Itanium 2 CPUs in their Integrity line of servers, with the high-end model of that line featuring up to 64 Itanium 2 CPUs. HP offered their Unix variant HP-UX as the OS for these IA64 systems, but there was also the option of running a version of Linux for IA64.
Although there were Windows XP and Windows Server releases for Itanium-based systems, I'm not aware of any Windows desktop PC model having much sales success with IA64 CPUs. There were also Linux releases for IA64 including Red Hat.

Lightweight method to use Amd64 instructions under 32-bit Windows?

For some CPU-bound code using 64-bit variables, it is beneficial to use the Amd64 instruction set rather than x86. How can it be done under 32-bit Windows (e.g. Windows XP SP3)? Of course I assume a modern, Amd64-enabled CPU. I'm excluding the working but heavyweight method: running a full-blown 64-bit OS as a virtual machine, e.g. Ubuntu for Amd64 under Virtualbox.
I understand some assembly is needed, and there will restrictions, in particular addressing more memory than 32-bit Windows manages. But I'm thinking of purely computational tasks needing only a moderate amount of memory and no call to external functions.
There is no way to use Amd64 instructions (Long mode) in 32-bit general-purpose OS (without kernel modification/special drivers/hypervisor).
This is because:
1) to use native 64-bit instructions you need to switch into long mode. This is privileged action. 32-bit OS kernel can't continue to work if the CPU is switched into 64-bit mode, so you should switch back before entering a kernel
2) But kernel are often called asynchronously, for timer (scheduler) and other hardware interrupts (drivers). It will not save 64-bit registers nor change mode from long into protected.
May be it is possible to write special driver, which will do the 64-bit tasks on 32-bit OS, but such driver is more like 64-bit kernel and dynamic patcher of kernel. I know no one such solution.
You can only use MMX, SSE, SSE2, SSE3, AVX for accessing 64-bit ALU and registers of your CPU when running in 32-bit OS.
I can say, that Linux, some BSD, Mac OS X have a mode, when 64-bit kernel is used, but user-space software is 32-bit. In such case it will be possible to run both 32-bit and 64-bit applications, because kernel knows about 64-bit mode and can access 64-bit registers to do a task switch. As far as I know, MS Windows have not such mode itself (the W7 emulates 32bit mode, but this is called my MS as simulator so I assume it is not an in-kernel feature).
Other possibility (this is better, is your CPU has support of hardware virtualization), is to use 64-bit hypervisor (VMware/Xen, other overpriced solutions) with 32-bit and 64-bit guest OSes. VirtualBox is other option of using hypervisor, and it is free to use.
In general, running 64-bit code in a 32-bit OS kernel is going to be next to impossible, for the following reasons:
The 32-bit OS is unaware of the additional 64-bit registers (and upper 32-bits of the existing registers) and will not save them across task switches
The 32-bit OS is not prepared to enable 64-bit code execution. Enabling 64-bit code execution means switching to IA-32e paging (which requires an entirely different page table format) and setting CS.L = 1 and CS.D = 0 in the code segment descriptor in the GDT (or LDT). (See the IA-32 manuals, vol 3a/3b 5.2.1)
In principle, you may be able to workaround both problems by writing a new HAL for Windows, which operates in IA-32e mode, and switches to a 64-bit trampoline code segment to save and restore 64-bit registers. This is a rather complex task; take a look at the Windows DDK for details. You could also use an emulation approach, as VirtualBox and friends do, if your CPU supports VMX. But it would be much simpler to simply use a 64-bit OS from the start.