64-Bits?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Fear
Member
Member
Posts: 39
Joined: Wed May 24, 2006 11:00 pm

64-Bits?

Post by Fear »

I'm really interested in developing a 64-bit operating system. I have two questions:
1. Does a 64-bit operating system require a special computer, or could I run it from my current computer?
2. Where can I find information about setting up 64-bit mode (I think its called long mode)?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 64-Bits?

Post by Brendan »

Hi,
Fear wrote:1. Does a 64-bit operating system require a special computer, or could I run it from my current computer?
For 80x86, it requires a CPU that supports long mode (or an emulator that supports long mode, like Bochs or Qemu).
Fear wrote:2. Where can I find information about setting up 64-bit mode (I think its called long mode)?
From the current programmer's manuals from either Intel or AMD (they've both got example code for initialising long mode, to go with all the details).


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.
Fear
Member
Member
Posts: 39
Joined: Wed May 24, 2006 11:00 pm

Post by Fear »

How do I find out if my computer does support long mode? Is there some test to run?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
Fear wrote:How do I find out if my computer does support long mode? Is there some test to run?
If you're in real mode, it could go something like:

Code: Select all

    pushf
    pop ax                       ;ax = original flags
    test ah,0x80                 ;Is bit 15 set?
    jne .longModeNotSupported    ; yes, old 8086!

    xor ah,0x30                  ;ax = flags with modified IOPL bits
    push ax                      ;Save flags
    popf                         ;Load flags
    pushf                        ;Save modified flags
    pop bx                       ;bx = modified flags
    xor ax,bx                    ;ax = flags with changed bits set
    test ah,0x30                 ;Did IOPL bits change?
    jne .longModeNotSupported    ; no, not a 32 bit CPU

    pushfd
    mov eax,[esp]                ;eax = original eflags
    xor eax,0x00040000           ;Invert AC flag
    push eax                     ;Store new eflags on stack
    popfd                        ;Read new eflags
    pushfd                       ;Store modified eflags
    pop ebx                      ;ebx = flags after changing
    xor eax,ebx                  ;If bits changed set them, else clear them
    popfd                        ;Restore original eflags
    test eax,0x40000             ;Is alignment check supported?
    jne .longModeNotSupported    ; no, not a 486 or later CPU

    pushfd                       ;Save eflags
    cli                          ;Disable interrupts
    mov eax,[esp]                ;eax = original eflags
    mov ebx,eax                  ;ebx = original eflags
    xor eax,0x200000             ;Invert ID flag
    push eax                     ;Store new eflags on stack
    popfd                        ;Read new eflags
    pushfd                       ;Store modified eflags
    pop eax                      ;eax = flags after changing
    xor eax,ebx                  ;If bits changed set them, else clear them
    popfd                        ;Restore original eflags (and interrupts)
    test eax,0x200000            ;Is CPUID supported?
    je .longModeNotSupported     ; no

    mov eax,0x80000000           ;eax = extended CPUID functions
    cpuid                        ;Get maximum extended CPUID function
    cmp eax,0x80000001           ;Is the extended feature flags function supported?
    jb .longModeNotSupported     ; no

    mov eax,0x80000001           ;eax = extended feature flags function
    cpuid                        ;Get the extended feature flags
    test edx,0x20000000          ;Is long mode supported?
    je .longModeNotSupported     ; no
A faster way would be to setup an invalid opcode exception handler, and then try to execute the CPUID instruction (whether it's supported or not). In this case if you get an invalid opcode exception then you know there's no long mode, and if you don't you only need to do the last 2 tests.

If your OS is started in protected mode (e.g. by GRUB), then you can skip the first 2 tests because you know it's at least capable of 32-bit....


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.
Fear
Member
Member
Posts: 39
Joined: Wed May 24, 2006 11:00 pm

Post by Fear »

Are there any tutorials on the subject? Because I was reading about it, but I wasn't quite sure how to do it...
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

the best advice i can give is:

read the intel manuals (if you dont have them there is a link in my sig, and at the bottom of that page there is a link to ordering hard-copies -- definitely recommended)

make sure you thoroughly understand PMode first, as it is almost exactly like LMode (intel calls it IA-32e mode), dont be concerned if you dont understand right away, the general rule is read all of volume 3, then reread chapters 3,4, and 5


for information about initializing the CPU in LMode or PMode, chapter 9 particularly section 9.8 & 9.9 -- if you dont understand anything here, you should prob take a closer look at chapters 3 & 4
Fear
Member
Member
Posts: 39
Joined: Wed May 24, 2006 11:00 pm

Post by Fear »

After reading about it, I think I'm going to write my OS in P-Mode, and later (2-3 major revisions from now) upgrade it to L-Mode, and in the processing eliminating design flaws I noticed from the original versions.
Post Reply