flat assembler
Message board for the users of flat assembler.

Index > OS Construction > 16 bit real org 10000h lgdt

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 16 Feb 2006, 15:01
I want to switch to protected mode from 16 bit real code,
my 16 bit real code is in the second segment of memory
starting at 10000h, Cool

in this region of memory if you have say:

Code:
xyz      dw     3
    


then I think the CPU will fail if you do

Code:
            mov [xyz],cx           ; FAIL because xyz is > 0ffffh,
            mov [ds:xyz],cx       ; FAIL because xyz is > 0ffffh
    

Sad

(no problem if you are in the first 64K of memory,
it took at least a day to locate this bug!)

instead you have to do:

Code:
           mov ebx,xyz
           mov [ds:bx],cx  ; correct because offset is 16 bit,
   
           and ebx,0ffffh
           mov [ds:ebx],cx  ; also correct because ebx <= 0ffffh

    

Surprised
I dont know if there is a better way around the problem,

so for lgdt I dont think I can do
Code:
            lgdt [some_label]
    

except if some_label is in the first 64K of memory,

anyway an attempt at lgdt is as follows:

Code:
        org 10000h

                ....
        mov ebx,gdt_pointer
        and ebx,0ffffh
        lgdt    [ds:ebx]
                ....

struc xdtr size,linear 
        {
        .size   dw  size + 0 ; no. bytes in table,
        .linear dd  linear + 0 ; linear address of byte 0 of DT,
        }

gdt_pointer  xdtr some_size,mytable

               ....
mytable:   .....
    


I dont know if this is correct, here is the question:

the docs seem to be saying that there are 3 versions of lgdt,
one with a 32 bit base (.linear above), 1 with a 24 bit base
and 1 with a 64 bit base,

the version I want is the 32 bit base, with the base actually
being in the first 1MB of memory, is the above fragment
correct?

Intel's docs (vol 3, ch 9, example code) use:
Code:
 
db 66h
lgdt  ....
    


they use "lgdt some_label" which on FASM would be
equivalent to "lgdt [some_label]", I cannot use that
because [some_label] is actually [ds:some_label]
and as its not a 16 bit offset (because of org 10000h)
the CPU will probably freeze up,

later I may need this from say protected mode,
with the GDT anywhere in the 4G space,

the docs say you need a 32 bit opsize, how do I
force that?
Rolling Eyes
Post 16 Feb 2006, 15:01
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 17 Feb 2006, 09:37
Code:
push ds
push 1000h  ;10000h=1000:0000h
pop ds
lgdt pword [0]                ;pword for 32bits table at 1000:0000h
pop ds                           ;restore ds

    


Last edited by Octavio on 18 Feb 2006, 15:15; edited 1 time in total
Post 17 Feb 2006, 09:37
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 17 Feb 2006, 10:17
With fasm LGDT needs PWORD operand.
But I actually forgot that in 16-bit variant it used the 5-byte memory location, not 6-byte. Perhaps I should add another size prefix? FBYTE?
Post 17 Feb 2006, 10:17
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Feb 2006, 12:52
altough i don't like, it seems to be unavoidable. But maybe you should mention it in documentation only in part with "lgdt", not in general operators to prevent confusing reader... most people have probably never heard of instructions taking five-byte arguments.
Post 17 Feb 2006, 12:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 17 Feb 2006, 13:32
Well, there is other solution. I could make LGDT in 16-bit mode to make the 5-byte variant when no operand size is specified (just like it works now), and 6-byte variant with PWORD size defined. In 32-bit mode it would always be the 6-byte variant. This solution is not as versatile, but still is much better than the current one and it avoids introducing another strange operator.
Post 17 Feb 2006, 13:32
View user's profile Send private message Visit poster's website Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 17 Feb 2006, 22:34
Tomasz Grysztar wrote:
With fasm LGDT needs PWORD operand.
But I actually forgot that in 16-bit variant it used the 5-byte memory location, not 6-byte. Perhaps I should add another size prefix? FBYTE?


for my example problem are you saying the following?

Code:
      org 10000h 

                .... 
        mov ebx,gdt_pointer 
        lgdt  pword   [ds:bx] 
    


Shocked
Post 17 Feb 2006, 22:34
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 19 Feb 2006, 11:41
Rather something like:
Code:
mov bx,gdt_pointer and 0FFFh
mov ax,(gdt_pointer and 0FFFFF000h) shr 4
mov ds,ax
lgdt pword [ds:bx]    
Post 19 Feb 2006, 11:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.