Enter and leaving protected mode

  • Nobody/Anonymous

    I have some code, but no one can be assemble in masm or nasm. Maybe there are in some syntax that is not recognized in nasm nor masm. i am working in window vista

    So, if someone can give codes that work fine in nasm or masm32 of protected mode, will be really appreciated. Also some links or tutorial will be of big help for me and others.

    The following code is an example of protected mode that I find but can’t be assemble. There are some lines and instructions that need to be converted in nasm or masm syntax but I don’t know how.

        stack segment stack use16
                        dd 100 dup(0)
        stack ends
        data segment use16
         gdt dd 0
            dd 0
         code_desc dd 0000ffffh
    dd 00cf9a00h
         data_desc dd 0000ffffh
    dd 00cf9200h
         ret_desc dd 0000ffffh
    dd 00cf9a00h
         gdt_label label fword
         gdt_limit dw 4*8-1
         gdt_base dd ?
         protected_code_address dd 0
                       dw  08h
        data ends

        code segment para public use16 'code'
        assume cs:code,ds:data,ss:stack

    mov ax, data
    mov ds,ax ; setup gdt
    mov eax,0
    mov ax, offset data
    shl eax,4
    add eax,offset gdt
    mov gdt_base,eax ; runtime fixup of far jump into pmode
    mov eax,0
    mov ax, offset code32
    shl eax,4
    add eax,offset protected_code
            mov protected_code_address,eax ; runtime fixup for far jump back to rmode

    mov eax,0
    mov ax, offset code32
    mov es,ax
    mov word ptr es:,18h

    db 66h
    lgdt gdt_label
    smsw ax
    or ax,1
    lmsw ax
    jmp next
    next: jmp fword ptr protected_code_address

            smsw ax
    and ax,0fffeh
    lmsw ax
    jmp cs:s16
    mov ax,4c00h
    int 21h
        code ends

        code32 segment use32
        assume cs:code32
    jmp cs:ret_real
    mov ax,10h
    mov ds,ax
    mov ebx,0b8000h
    mov ax,0741h
    mov ecx,80*25
    mov ,ax
    add ebx,2
    loop st1
    jmp sto

        code32 ends

  • Frank Kotler

    Frank Kotler - 2010-01-05

    What you've got there appears to be Masm code (possibly Tasm). Perhaps Jwasm would assemble it. Or, it wouldn't be hard to translate to something Nasm would assemble.

    But it won't run in Vista - this is for real mode dos! (that is, no "dosbox" or emm386.sys loaded - those are VM86 mode).

    If you can boot a system that will run it, I'll see if I can dig up some Nasm code that will do the same thing. Not really very useful unless you're writing your own OS.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks