Author Topic: Enter and leaving protected mode  (Read 20497 times)

nobody

  • Guest
Enter and leaving protected mode
« on: January 05, 2010, 12:02:38 AM »
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.

.386p
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

start:
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:[4],18h

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

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

code      ends


code32      segment   use32
assume   cs:code32

sto:
jmp   cs:ret_real
protected_code:
mov   ax,10h
mov   ds,ax
mov   ebx,0b8000h
mov   ax,0741h
mov   ecx,80*25
st1:
mov   [ebx],ax
add   ebx,2
loop   st1
jmp   sto

code32      ends

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Enter and leaving protected mode
« Reply #1 on: January 05, 2010, 05:08:49 PM »
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.

Best,
Frank