News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Global Descriptor Table

Started by MaxPayne, May 23, 2005, 11:13:23 PM

Previous topic - Next topic

MaxPayne

Hi !

I've got some problems with load Global Descriptor Table. When i try to use: lgdt gdt MASM (ver. 6.11) returns "immidiate operands not allowed". I tried to use registers but it doesn't help.

Greetings

MaxPayne


mnemonic

Hi MaxPayne,

welcome in here.

I think you do not use the instruction right.
OPCODES.HLP (\masm32\help\) says:
LGDT - Load Global Descriptor Table (286+ privileged)
        Usage:  LGDT    src
        Modifies flags: None
        Loads a value from an operand into the Global Descriptor Table
        (GDT) register.
                                 Clocks                 Size
        Operands         808x  286   386   486          Bytes
        mem64              -    11    11    11            5

        0F 01 /2 LGDT m16&32 Load m into GDTR

That means you must use a memory location as operand (maybe "gdt" is a reserved word).

Regards
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

MaxPayne

#2
Yes i know, it's not reserved and under gdt hiddes
gdt:
dw 5*8-1
dd gdt

_gdt:
dd 0,0 ; NULL Descriptor
dd 00000FFFFh,000CF9A00h
dd 00000FFFFh,000CF9200h
dd 00000FFFFh,000CFFA00h
dd 00000FFFFh,000CFF200h

Could You give me some working examples, i have no idea how to do that :(

mnemonic

Sorry, I never did something before with "lgdt". I only know its meaning from books.
So I don´t have any working code regarding this issue, sorry.

Quote from: MaxPayne on May 23, 2005, 11:38:55 PM
gdt:
dw 5*8-1
dd gdt

_gdt:
dd 0,0 ; NULL Descriptor
dd 00000FFFFh,000CF9A00h
dd 00000FFFFh,000CF9200h
dd 00000FFFFh,000CFFA00h
dd 00000FFFFh,000CFF200h
I don´t know what you´re really doing with that declaration but as long as MASM complains about "immidiate operands not allowed"...
Did you try to use
lgdt offset gdt
Maybe that helps.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

MichaelW

Hi MaxPayne,

Before I provide an answer, is this supposed to run under Windows? Why DPL=3?

eschew obfuscation

AeroASM

He is (you are) trying to make an OS with MASM, which I attempted a couple of months ago and gave up, because MASM physically will not let you use direct immediate operands. I switched to FASM, it is much easier.

MaxPayne

#6
Quote from: MichaelW on May 24, 2005, 12:22:43 AM
Hi MaxPayne,

Before I provide an answer, is this supposed to run under Windows? Why DPL=3?



hymm, i'm trying to write something like os and maybe it's true that there could be problems with dpl level, but if does - how could it change gdt ? I thought that assembler is assembler and it should complie... even under windows. Thank You for adsvices and sorry for my English

MaxPayne

AeroASM

MASM is a high-level kind of assembler [Aero shields himself from hutch--  :eek] and so not only provides many high level constructs it also tries to protect the coder. MASM was designed only for making programs under Windows and so you never need direct memory access, so they are protecting you from accessing memory directly. As I said, try using NASM or FASM to compile and you should be fine.

MaxPayne

Aero -> Thank You very much :).. if I don't ask about this i will be blind for a long time :D. I hadn't found any info saying that MASM is -somekind- high level asm. Once again thanks :)

MichaelW

Aero,

MASM was designed for making pretty much any kind of executable, and it can readily assemble things like this. In this case MASM is refusing to assemble an instruction with an operand of the wrong type.

Max,

LGDT and LIDT take a 6-byte data operand in memory, so unless the table descriptor is defined as an FWORD, you must precede the operand with FWORD PTR, as in:

lgdt fword ptr gdt

eschew obfuscation

MaxPayne

#10
It works :D Thank You.. I didn't know about this conversion.. maybe i'm using too old books :P.. anyway thank You :)

Greetings

Max

MaxPayne

#11
Hi !

I've got new problem :)... everything compile and code looks to be ok but when a EIP goes to lgdt fword ptr gdt_descr program ends and i don't know why ? There is my code:

.model small,stdcall
.386p
.stack 512
.data
   gdt_descr dw 3*8-1
                  dd  gdt
      gdt dd 0,0 ; NULL Descriptor
      dd 00000FFFFh,000CF9A00h ;
      dd 00000FFFFh,000CF9200h ;

.code
  start:
         mov ax,@data
         mov ds,ax 
     
         clli
         mov al,0D1h
         out 064h,al

         mov al,0DFh
         out 060h,al

       ;   xor ax,ax
       ;   mov ax,ds
       ;   shl ax,4
       ;   or eax,dword ptr gdt_descr
       ;        lgdt fword ptr ds:[eax]

        lgdt fword ptr ds:[gdt_descr]    <-------- Everything ends here


        mov eax,cr0
        or eax,01h
        mov cr0,eax

I tried this with other memory models (etc. tiny,small..) and the results were the same - program ends. Ii becomes before i set cr0 register.
Thank You for any help

Greetings

MaxPayne

   

AeroASM

Are you running this in real MS-DOS mode or from the Windows console?

The Windows console is just an emulator of DOS and so will not handle these things.

MaxPayne

#13
:) I run it on a windows console and under VMware machine. In VMware the program has stops and it doesn't do nothing -  i mean it doesn't execute code after lgdt instruction. Under windows i tried to debug it but when debugger comes to this line and it ends like before.

Greetings

MaxPayne

MichaelW

Max,

Windows is terminating your program when it detects the attempt to execute a privileged instruction. To do such things directly the processor must be in real mode. If you are running Windows 9x you can restart in MS-DOS mode. If not, possible choices are a Windows 9x boot diskette (that should be able to access a FAT32 file system) or a DOS boot diskette (that will normally be limited to accessing the diskette). Perhaps I should mention that 386 memory managers run the processor in protected mode, and at least most of them will intercept and block privileged instructions.
eschew obfuscation