OK, now we start with 8086, as I know fuck-all about the ones before that, as there is fuck-all information about them, and I can't read the circuit diagram for the 4004. Here we have something from IRC:
<@Spaz> GreaseMonkey, you know why IBM adopted x86 right?
<@GreaseMonkey> Spaz: nope
<@GreaseMonkey> was it the only thing around?
<@Spaz> GreaseMonkey, two things, (1. it was cheap, (2. it wouldn't compete with their servers
<@Spaz> since they knew it was such shit
(x86 is what they call the whole architecture nowadays.)
Oh yeah, just before I continue, some legalese:
<@Spaz> GreaseMonkey, all my quotations are 2-clause BSD licenced
So, this is where I think, "I love open source", and print the whole fucking license:
Copyright (c) 2008, Spaz
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS QUOTE IS PROVIDED BY SPAZ ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SPAZ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS QUOTE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
At least it's a lot smaller than the EULA or the GPL. Anyway, moving on...
So, the 8086 was a cheap piece of shit which would be suitable for people who couldn't afford a blazing rocket of a machine. Unfortunately, there was no memory protection, and also you could only access 1MB of memory, AND due to architecture limitations that was shrunk down to 640KB (which, of course, is enough for anybody), so then we progress towards...
... the 80286. It could access a whole 16MB! Wow! On top of that, you had up to 4 levels of security! However, there were several catches with this:
- It still followed the segmented memory model. Under this, you could still only access 64KB in a segment. The same limit was imposed on the 80286.
- Instead of having 65536 unique segments, that was dropped down to 8192 in the Global Descriptor Table (GDT), not including TSS entries, LDT pointers, or call/task gates. The Local Descriptor Table (LDT) would allow another 8192 segments, also not including TSS entries or call/task gates. Why? Because part of the code segment is used for determining the privilege level of your code.
- There were "code segments" and "data segments". You could only run code in a code segment, and optionally read it. As for a data segment, you could not. You could read it, and optionally write to it. While this did offer another form of memory protection, I have yet to see anyone actually take advantage of this, instead of making identically sized and located pairs of code and data segments.
- To use the memory protection, you would have to put stuff into a Task State Segment (TSS), even if you do not want to use hardware task switching. Which is what the TSS was for. There were a few necessary fields you would have to fill in so, in case of any interruption (which actually happened many times in a second), it could enter a higher privilege level.
- Most people would only use 2 levels of security: kernel mode and user mode. For example, Microsoft. In fact, they still do this, even with Vi$ta. Not only that, but the 80286 came out when DOS was still king, and people who code for DOS generally don't use memory protection. So, the security levels weren't really used a lot.
- To enter protected mode, you had to set up a GDT, enable a flag, set all your segments to appropriate settings, then do a jump to another segment.
- To exit protected mode, you had to reset the CPU.
Then came the 80386. They managed to fix a few things. Firstly, you could access up to 4GB of memory. Secondly, you could actually exit protected mode without resetting your CPU. Thirdly, you could access all 4GB of memory without having to make a buttload of segments.
And they did a few other things, too. Firstly, everything was 32-bit, instead of 16-bit like the last two processors. (The 8080, if I'm correct, is 8-bit.) This meant that you could work with bigger numbers, read and write memory faster, and pretend you're awesome. Secondly, they introduced paging (better known as virtual memory), which allowed you to relocate memory, and get an extra method of protection. Thirdly, it supported hardware debugging, allowing you to "trap" something when it reads, writes, or executes a part of memory, and makes it an absolute joy for hacking games and making cheats for them.
When paging first came out, you had two levels of tables. You had the first level, which was 4KB in size. This pointed to 1024 second level tables, which were also 4KB in size. Each of the 1024 told the CPU where to actually look when something wanted to access a part of memory. Each page was 4KB in size, just in case you were wondering.
Sounds too good to be true? Well, it's not as good as it sounds.
- If you wanted to page every single piece of memory, you'd use up 4100KB, which is just over 4MB, just for the page tables. While you don't have to complete the whole thing, it's easier if you do, but most computers back in that day could do a heck of a lot more with an extra 4MB. Although overlap hackery could work. But still...
- If you decided not to page a secondary table, you could save 4KB, but then you'd lose a whole 4MB of virtual memory space.
- You can mark pages as either User or Supervisor. Unfortunately, the way that this was designed was that only the lowest security level would be affected, hence rendering two of the security levels rather pointless.
- The architecture was still quite dependent on the BIOS for several services. Now, the floppy disk controller is a fucking nightmare to code for if you're doing it without using the BIOS services, so generally it's easier to just use the BIOS services. Most video cards have VESA support, but until VESA 3.0 came out, you still had to use the BIOS services. Problem? The BIOS was 16-bit. You had to use a new mode, called Virtual-8086 mode, to do this.
- Virtual-8086 mode relied on the TSS. Dammit.
- Virtual-8086 mode relied heavily on catching a whole bunch of instructions that it wasn't supposed to run, which you would then have to emulate. Unfortunately, there are several pre-flags you have to catch, and there are about 6 opcodes on their own related to IN and OUT, never mind the pre-flags.
- Thanks to the extensions of the architecture, it is now a complete fucking mess when it comes to 16-bit code and 32-bit code. It reuses 16-bit opcodes and makes 32-bit versions out of them, unless you put a pre-flag in.
- One of the registers, CR1, was marked as reserved. It has never, ever, ever been touched.
- Page Address Extension (PAE): This allowed you to access up to 64GB. Four problems: it's buggy, it uses 3 levels of paging (taking up even more memory), no-one implements it without any compatibility issues, and you need paging enabled to access it.
- Page Size Extension (PSE): This allowed you to use 4MB pages, and save an extra 4KB on making another table. This also relies on paging.
- PSE-36: Like above, but allowed you to access up to 64GB without using PAE.
- System Management Mode (SMM): A complete fucking nightmare. Only the hacker underground uses it to its full potential, and that's to install rootkits. Introduced with the 386SL. Fuck the 386SL.
- MMX, SSE and the like: I've never used them. Apparently they're used to allow you to calculate lots of things at once. Apparently they work well.
- No eXecute bit (NX): Yay. You can finally stop people from executing certain pages.
After a while, it gets fairly clear: the x86 architecture is a little too clunky, yet a little too restricted. So, what do we do?
Intel had an idea: IA-64. Pretty much an entirely different architecture, starting as an x86 core, but can be transferred to IA-64. Unfortunately, it's not x86, so it hasn't been successful.
So, they decide to go with AMD's slightly older idea: x86-64 (originally AMD64 if I recall correctly). What do they do?
- They remove the need for the GDT, instead relying on paging (we're up to 4 levels of paging now). There's no segmentation, either. I'm not sure how they handle privilege levels.
- They allow you to access up to 256TB (262144GB) of memory. What? Shouldn't that be higher? Well, yes, they've got plans for allowing 64PB (65536TB), but if you had a 64-bit address space, you'd probably want to support 16EB (16386PB).
- They add yet another fucking instruction set to the x86 architecture.
Not only that, but x86-64 is suffering badly from compatibility, having to support 8086, 80286, and 80386 apps!
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!
What. A. Nightmare.
Fortunately, there are other processors out there. There's the ARM processor, for one. And then there's my personal favourite, the MIPS, which has gone through at least 4 backwards compatible versions, was the fastest damn thing you could get, is nice and simple, and has a few really really nifty features to it. This just makes me want a computer with a MIPS in it.
It's such a pity that the most common desktop processor is a flaming pile of dogshit. We need something better. In fact, the whole bloody architecture is a mess.
5 comments:
You hit the nail on the head with this one GreaseMonkey :). I wish though you would have touted the advantages of the MIPS :(.
1) The new x86-64 instruction set reads more like an Intel-dialect version of PowerPC, which is a vast improvement.
2) x86-64 provides more general registers (which takes away another stupid, artificial limit from x86: four general registers).
3) I've been extremely successful on running 32-bit applications on Linux x64, FreeBSD x64, and Windows x64.
While I don't disagree that x86-64 isn't the best, it isn't exactly the worst, either; and they have definitely made improvements.
Yes but the CPU still boots into 8-bit mode by default (as in, when power is applied to the CPU, it is a fancy 8088). IIRC you have to go through 16 bit then 32 bit modes to get to 64 bit mode. Plus paging is still a damn mess.
It doesn't boot into 8-bit mode, as that does not exist on the 8086/8088. It boots into 16-bit mode. Then, yes, you have to progress up the ladder.
Post a Comment