3 ms·
Why not 64 bits?
by jesuslop 10y ago
Why not 64 bits?
- DSMan195276 10y agoI donno if this is a serious question or not, but x86-64 is very much an extension of regular 32-bit x86, just more complicated. For something like this there's little reason to attempt 64-bit when 32-bit is much easier and will essentially result in learning the same concepts.
- johncolanduoni 10y agoI messed around with writing OSes when I was around the same age, and I found x86-64 to not have much of an overhead relative to plain x86. Getting into long mode itself is just a tiny bit of boilerplate at the very beginning. If you didn't plan on using paging then you need to do a bit more work to identity map everything, but if you already did the extra virtual address space means you can just map all physical addresses (that are hooked up to anything) linearly somewhere and not have to play games with mapping/unmapping things just so the kernel can access them briefly. You lose the ability to have the processor save state on context switch for you via the TSS, but that's not very hard to do yourself either. The ins and outs of running something in compatibility mode are quite complicated, but there's no reason to involve yourself in that if you're writing your own toy OS. Overall I'd say 32-bit dodges a few things, but I wouldn't call it much easier.
- DSMan195276 10y agoA few things: x86-64 uses a 4-level page-table, which is much more annoying to get right then a 2-level page-table if you're not familiar with paging or haven't dealt with it before. I agree about TSS - nobody really bothers using it anyway. That said, x86-64 has a bit more state to handle when doing a context-switch (Though nothing very extreme) x86-64's calling convention is more complex then x86's calling convention. For this project it doesn't really apply because it isn't followed anyway, but for a C project it would come into play. IMO, another big issue with doing x86-64 is documentation - x86 has tons, x86-64 has comparatively little. I would definitely agree that if you know what you're doing the differences aren't huge, but if you don't know what you're doing I think you'll definitely have an easier time getting stuff working with x86.
- riscy 10y agoThere are real benefits to using x86-64 over x86, namely, x86 is starved of general purpose registers. There are many more registers available on x86-64.
- DSMan195276 10y agoTrue - that obviously applies more to writing assembly then C, but of course this is an assembly project. Depending on your coding style though I'm not sure how much it would really come into play - x86 is registered starved, but it also allowed memory addresses in lots of instructions, allowing you to avoid putting things into registers in the first place. You get twice the number of registers with x86-64, but his code doesn't really appear to be suffering for not having enough registers to begin with.
- jesuslop 10y agoI was about to respond (and from rusty personal memory, correct me if wrong) that having larger than 4Gb segments seems fit for todays ram dotations but this answer is even better.
- eximius 10y agoIIRC, turning on 64bit mode brings more complexity? I only briefly looked at this stuff last year. Someone can correct me if I'm wrong. But for someone learning this stuff, limiting the complexity you have to deal with is a good idea.
- Someone 10y agoI would guess for the same reason "PS/2 keyboard and mouse" have been implemented, but USB hasn't. If you want to write an OS with a GUI on modern x86 hardware from scratch, there is an insane amount of stuff you have to do to support a generic keyboard, mouse, and display before you can do any work on your OS proper. He's not alone in this, but the way; another OS author wrote "it probably never will support anything other than AT-harddisks, as that’s all I have :-(."