Protected mode

Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
10x

Comments

  • : Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
    : 10x
    :

    Do a Google search for "Assembly Language FAQ" and read it. It will have some info and good links to websites that talk about protected mode.

    Nathan.
  • : Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
    : 10x
    :
    [green]
    Find IA32 Intels Software Developers Manual Vol. 3 at Intels site.
    [/green]

  • : : Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
    : : 10x

    It depend what environment, you start from, if you start in window or linux you are in pmode.
    If your in real dos (not a dos box under win) or want to make a OS, them you need to setup some stuff in real mode before going to pmode.
    Example:
    This code will put you in pmode , if your making a os.
    [code]
    ;************************************
    ; \|//
    ; (@ @)
    ; ASHLEY4.
    ; Put test.bin on boot sector
    ; with rawrite.
    ; Assemble with fasm
    ; c:fasm test.asm test.bin
    ;************************************
    org 0x7C00

    use16
    ;****************************
    ; Realmode startup code.
    ;****************************

    start:
    xor ax,ax
    mov ds,ax
    mov es,ax
    mov ss,ax
    mov sp,0x7C00

    ;*****************************
    ; Setting up, to enter pmode.
    ;*****************************
    cli
    lgdt [gdtr]

    mov eax, cr0
    or al,0x1
    mov cr0,eax

    jmp 0x10: protected

    ;*****************************
    ; Pmode. ;-)
    ;*****************************

    use32
    protected:
    mov ax,0x8
    mov ds,ax
    mov es,ax
    mov ss,ax
    mov esp,0x7C00
    ;*****************************
    ; Turn floppy off (if space).
    ;*****************************

    mov dx,3F2h
    mov al,0
    out dx,al

    lea esi,[msg0]
    mov edi,0xB8000 + (80 * 3 + 4) * 2
    mov ecx,28
    cld
    rep movsb

    jmp $
    ;*************************************
    ; GDT.
    ;*************************************

    gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    sys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CF
    gdt_end:

    gdtr: dw gdt_end - gdt - 1
    dd gdt

    ;*************************************
    ; Data.
    ;*************************************

    msg0 db " H E L L O W O R L D ! "

    ;*************************************
    ; Make program 510 byte's + 0xaa55
    ;*************************************

    times 510- ($-start) db 0
    dw 0xaa55 [/code]
    If this is not what you want let us know.

    ps: you must have the same spacers in the string, for the code to print the string.

    \\||////
    @)
    ASHLEY4.

    Batteries not included, Some assembly required.
  • : : : Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
    : : : 10x
    :
    : It depend what environment, you start from, if you start in window or linux you are in pmode.
    : If your in real dos (not a dos box under win) or want to make a OS, them you need to setup some stuff in real mode before going to pmode.
    : Example:
    : This code will put you in pmode , if your making a os.
    : [code]
    : ;************************************
    : ; \|//
    : ; (@ @)
    : ; ASHLEY4.
    : ; Put test.bin on boot sector
    : ; with rawrite.
    : ; Assemble with fasm
    : ; c:fasm test.asm test.bin
    : ;************************************
    : org 0x7C00
    :
    : use16
    : ;****************************
    : ; Realmode startup code.
    : ;****************************
    :
    : start:
    : xor ax,ax
    : mov ds,ax
    : mov es,ax
    : mov ss,ax
    : mov sp,0x7C00
    :
    : ;*****************************
    : ; Setting up, to enter pmode.
    : ;*****************************
    : cli
    : lgdt [gdtr]
    :
    : mov eax, cr0
    : or al,0x1
    : mov cr0,eax
    :
    : jmp 0x10: protected
    :
    : ;*****************************
    : ; Pmode. ;-)
    : ;*****************************
    :
    : use32
    : protected:
    : mov ax,0x8
    : mov ds,ax
    : mov es,ax
    : mov ss,ax
    : mov esp,0x7C00
    : ;*****************************
    : ; Turn floppy off (if space).
    : ;*****************************
    :
    : mov dx,3F2h
    : mov al,0
    : out dx,al
    :
    : lea esi,[msg0]
    : mov edi,0xB8000 + (80 * 3 + 4) * 2
    : mov ecx,28
    : cld
    : rep movsb
    :
    : jmp $
    : ;*************************************
    : ; GDT.
    : ;*************************************
    :
    : gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    : sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    : sys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CF
    : gdt_end:
    :
    : gdtr: dw gdt_end - gdt - 1
    : dd gdt
    :
    : ;*************************************
    : ; Data.
    : ;*************************************
    :
    : msg0 db " H E L L O W O R L D ! "
    :
    : ;*************************************
    : ; Make program 510 byte's + 0xaa55
    : ;*************************************
    :
    : times 510- ($-start) db 0
    : dw 0xaa55 [/code]
    : If this is not what you want let us know.
    :
    : ps: you must have the same spacers in the string, for the code to print the string.
    :
    : \\||////
    @)
    : ASHLEY4.
    :
    : Batteries not included, Some assembly required.
    :

    Yeah this is what i want but i would like to know what is lgdt [gdtr] ...
    10x

  • First you would be better asking ? like this here:
    http://www.osdever.net/forums/index.php?sid=bf5d2e11721d5df3cbc8a5490e9c64d7
    Also on that site is tut, that you can study.

    \\||////
    @)
    ASHLEY4.

    Batteries not included, Some assembly required.
  • First of all i have to say that i don't know absolutly nothing about the protected mode except the fact that is made to help multitasking and is used by many OS .Until now,programming in asm i worked only under real mode doing something like MS-DOS(it read's and writes files to a floppy disk FAT12 it loads com files exe files,it shows date and time it has chdir,cd and dir commands that works on FAT12, a keyboard bloker and some other stuff).So for the beginning i would like some simple documentation that presents the difrences between pmode and rmode and stuff like that

    10x
  • : First of all i have to say that i don't know absolutly nothing about the protected mode except the fact that is made to help multitasking and is used by many OS .Until now,programming in asm i worked only under real mode doing something like MS-DOS(it read's and writes files to a floppy disk FAT12 it loads com files exe files,it shows date and time it has chdir,cd and dir commands that works on FAT12, a keyboard bloker and some other stuff).So for the beginning i would like some simple documentation that presents the difrences between pmode and rmode and stuff like that
    :
    : 10x
    :

    Try this: http://my.execpc.com/~geezer/johnfine/segments.htm

    \\||////
    @)
    ASHLEY4.

    Batteries not included, Some assembly required.
  • : : Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
    : : 10x
    : :
    :
    : Do a Google search for "Assembly Language FAQ" and read it. It will have some info and good links to websites that talk about protected mode.
    :
    : Nathan.
    :
    I just published my assembler OS , where all Your questions are answered.
    Look at my homepage and downlod the sourcecode
    www.rcfriz.de
  • : : First of all i have to say that i don't know absolutly nothing about the protected mode except the fact that is made to help multitasking and is used by many OS .Until now,programming in asm i worked only under real mode doing something like MS-DOS(it read's and writes files to a floppy disk FAT12 it loads com files exe files,it shows date and time it has chdir,cd and dir commands that works on FAT12, a keyboard bloker and some other stuff).So for the beginning i would like some simple documentation that presents the difrences between pmode and rmode and stuff like that
    : :
    : : 10x
    : :
    :
    : Try this: http://my.execpc.com/~geezer/johnfine/segments.htm
    :
    : \\||////
    @)
    : ASHLEY4.
    :
    : Batteries not included, Some assembly required.
    :
    Here's the short form:
    In real mode, You can adress only the lowest 1M adresses and every program can adress in every other program - to redefine values or to jump to.
    Every adress is combined out of a segment-adress and an offset-adress. They are added as offset+segment*4 to form the one adress, which is needed.
    In protected mode the segment adresses are NOT stored in a segmentregister, but in a table called GDT. The first absolute adress in this table has to be stored in a special register ( new in protected mode). You store this adress using the mnemonic lgdt.
    The adresses, stored in the GDT are absolute, but have to be combined with some other bitsettings to form the 64-bit descriptors.
    The segmentregisters store in protected mode the inexadress of the descriptor in the GDT - and some bits in the lowest 3 bits of the value.
    What I called "bitsettings" is special information, which gave the protected mode its name. These settings are computed, to hide the segments to each other (if You want priviledged segments). Thus in protected mode a program could be prevented to adress in every other program as in real mode.
    In fact, this is a very complicated way to reach the benefits of something, You will never need, When You are the only user at Your machine and if You do only one thing at a time.
    But in stone-age there shared a lot of users one mainframe and needed therefore "multiusing". In stone-age too, there was the memory so little
    (I started once with 16K !), and you needed "multitasking" to put only that piece into the memory, which you needed at a time.
    This limititations are gone in the private sphere!
    Every bureaucracy for this purpose costs memoryspace and wastes time.
    Forget multitasking!
  • [b][red]This message was edited by bogdanul2003 at 2005-8-20 9:21:44[/red][/b][hr]
    [b][red]This message was edited by bogdanul2003 at 2005-8-20 9:7:58[/red][/b][hr]
    : : : Where can i find some good documentantion about protected mode,how do i initialize it how I use it etc ...
    : : : 10x
    :
    : It depend what environment, you start from, if you start in window or linux you are in pmode.
    : If your in real dos (not a dos box under win) or want to make a OS, them you need to setup some stuff in real mode before going to pmode.
    : Example:
    : This code will put you in pmode , if your making a os.
    : [code]
    : ;************************************
    : ; \|//
    : ; (@ @)
    : ; ASHLEY4.
    : ; Put test.bin on boot sector
    : ; with rawrite.
    : ; Assemble with fasm
    : ; c:fasm test.asm test.bin
    : ;************************************
    : org 0x7C00
    :
    : use16
    : ;****************************
    : ; Realmode startup code.
    : ;****************************
    :
    : start:
    : xor ax,ax
    : mov ds,ax
    : mov es,ax
    : mov ss,ax
    : mov sp,0x7C00
    :
    : ;*****************************
    : ; Setting up, to enter pmode.
    : ;*****************************
    : cli
    : lgdt [gdtr]
    :
    : mov eax, cr0
    : or al,0x1
    : mov cr0,eax
    :
    : jmp 0x10: protected
    :
    : ;*****************************
    : ; Pmode. ;-)
    : ;*****************************
    :
    : use32
    : protected:
    : mov ax,0x8
    : mov ds,ax
    : mov es,ax
    : mov ss,ax
    : mov esp,0x7C00
    : ;*****************************
    : ; Turn floppy off (if space).
    : ;*****************************
    :
    : mov dx,3F2h
    : mov al,0
    : out dx,al
    :
    : lea esi,[msg0]
    : mov edi,0xB8000 + (80 * 3 + 4) * 2
    : mov ecx,28
    : cld
    : rep movsb
    :
    : jmp $
    : ;*************************************
    : ; GDT.
    : ;*************************************
    :
    : gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    : sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    : sys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CF
    : gdt_end:
    :
    : gdtr: dw gdt_end - gdt - 1
    : dd gdt
    :
    : ;*************************************
    : ; Data.
    : ;*************************************
    :
    : msg0 db " H E L L O W O R L D ! "
    :
    : ;*************************************
    : ; Make program 510 byte's + 0xaa55
    : ;*************************************
    :
    : times 510- ($-start) db 0
    : dw 0xaa55 [/code]
    : If this is not what you want let us know.
    :
    : ps: you must have the same spacers in the string, for the code to print the string.
    :
    : \\||////
    @)
    : ASHLEY4.
    :
    : Batteries not included, Some assembly required.
    :


    ASHLEY4 can you explain me a littlebit why you put that values in sys_data and sys_code?
    And why do you use this far jump jmp 0x10: protected insted of jmp protected?to refer to the second entry in a GDT the value in a segment register must be 2 or 0x10 ???
    10x




  • If You want to program in assembler using protected mode, You need to think of the OS You are using. Normally there are special limitations caused by the manner to organize the use of memory. This depends not only on the stack-segment, but
    the bitsetting in the descriptors too. I.e. You can define a certain length of a segment - or You define maximum length in every case and ignore the use of the
    CPU-int, which is triggered, when a limit is riched....
    (But if You use maximum length and granularity, every program-segment MUST begin with a base-adress, which is a multiple of 1000h !)
    But You can find a short way to first experiments, when You look at my homepage
    www.rcfriz.de
    ...and download my FDOS. This is an OS, which is bootable from FD, written only in assembler (NASM-dialect) and contains besides the switch to protected mode a lot of needed things, which are spread over a lot of utilities, if You program under M$DOS. Simple filesystems for the use on FD and HD are added - and of course the drivers for FD and IDE. My FDOS is well commented for beginners and You can see, what things You need to do, when You switch to pmode.
    (The FAR jump after switching the p-bit is needed to change the meaning of the value in cs - in real mode its a part of the adress in memory, in pmode, its an offset in the GDT!)

    In the very next future ( maybe next month) i will publish a mature assembler kernel, which I derive from my FDOS.
  • 10x frizz
    I have startes reading intel manual vol 3 and some tutorials on the net but I can't make pmode to start... here is my code in NASM :

    CPU 386
    [BITS 16]
    [ORG 0]
    jmp start

    gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    sys_code: dw 0xFFFF, 0x0000, 0x9A00, 0x00CF
    gdt_end:

    gdtr: dw gdt_end - gdt - 1
    dd gdt


    start: xor ax,ax
    mov ds,ax
    mov ss,ax
    mov es,ax
    cli
    lgdt [gdtr]
    mov eax,cr0
    or al,0x1
    mov cr0,eax
    jmp 10h:pmode ;at this jump CPU resets

    [BITS 32]
    pmode:mov ax,08h
    jmp $
    mov ds,ax
    mov ss,ax
    mov es,ax
    mov esp,0x7C00
    mov word [0xB8000],844Dh

    Why is CPU reseting when executing that far jump ?... i made the corect GDT but the cpu still resets.Is it because NASM makes that far jump a 16 bit instruction and the segment is declared as 32 bit? or what is wrong?
    10x

  • [b][red]This message was edited by ASHLEY4 at 2005-8-24 11:20:54[/red][/b][hr]
    [b][red]This message was edited by ASHLEY4 at 2005-8-24 7:25:37[/red][/b][hr]
    : 10x frizz
    : I have startes reading intel manual vol 3 and some tutorials on the net but I can't make pmode to start... here is my code in NASM :
    :
    : CPU 386
    : [BITS 16]
    : [ORG 0]
    : jmp start
    :
    : gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    : sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    : sys_code: dw 0xFFFF, 0x0000, 0x9A00, 0x00CF
    : gdt_end:
    :
    : gdtr: dw gdt_end - gdt - 1
    : dd gdt
    :
    :
    : start: xor ax,ax
    : mov ds,ax
    : mov ss,ax
    : mov es,ax
    : cli
    : lgdt [gdtr]
    : mov eax,cr0
    : or al,0x1
    : mov cr0,eax
    : jmp 10h:pmode ;at this jump CPU resets
    :
    : [BITS 32]
    : pmode:mov ax,08h
    : jmp $
    : mov ds,ax
    : mov ss,ax
    : mov es,ax
    : mov esp,0x7C00
    : mov word [0xB8000],844Dh
    :
    : Why is CPU reseting when executing that far jump ?... i made the corect GDT but the cpu still resets.Is it because NASM makes that far jump a 16 bit instruction and the segment is declared as 32 bit? or what is wrong?
    : 10x
    :
    Try changing your ORG to 0x7C00, and i also do not like puting the gdt at the start .
    Here is why, your lables are just numbers to the computor, so if one of the lables is 20 it jump to 20, but you have bean loaded to 0x7C00 by the bios, your code will jump to 20, but becasue you have bean loaded to 0x7C00 this need to be added to the address to jmp to the right place. so 0x7C00 + 20 would get you to the right lable (20 is just a example ),.

    Hope this helps.


  • [b][red]This message was edited by frizzz at 2005-8-28 19:3:20[/red][/b][hr]
    [b][red]This message was edited by frizzz at 2005-8-25 19:35:4[/red][/b][hr]
    [b][red]This message was edited by frizzz at 2005-8-25 19:22:18[/red][/b][hr]
    You should not OR the contents of cr0, if You want a really clean switch.
    Do this:
    mov ax,1
    lmsw ax
    You should reset every flag too doing:
    push WORD 0
    popf
    And You forgot to define the base-adress of the IDT doing:
    lidt [adress of pointer] ; quite similar to lgdt...
    ...and I wonder why You jump with "jmp $" BEFORE You re-define the segment registers? You will get to nirwana, if ds=0 ! The CPU halts if the null-selector is in a segment-register!
    ....and are You shure, that Your code will be loaded to absolute adress =0 ?
    Else its true, that You need an other "org"! (Your bootsector (or DOS?) should transfer Your code to base-adress =0 - then the org 0 ist OK)
    :


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories