flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help with setting up jmp to pmode GDT

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 09 Jan 2010, 05:29
I've read http://www.osdever.net/bkerndev/Docs/gdt.htm and all that OSDev.org has to offer on GDTs, and I still have no idea what I'm doing. Can someone give me an example of what "GDTR" would be in
Code:
CLI
LGDT [GDTR]
MOV EAX, CR0
OR AL, 1
MOV CR0, EAX
    

, an example I found at http://wiki.osdev.org/Protected_mode?

I'm not necessarily even asking for an example with actual values(would be easier to understand though) just something with a description of what needs to go where.
Post 09 Jan 2010, 05:29
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 09 Jan 2010, 06:36
Tyler wrote:
I've read http://www.osdever.net/bkerndev/Docs/gdt.htm and all that OSDev.org has to offer on GDTs, and I still have no idea what I'm doing.


Sad

Code:
CLI
LGDT [GDTR]  ; 6 Byte's 
MOV EAX, CR0
OR AL, 1     ; INC EAX Wink
MOV CR0, EAX
JMP FAR SEL:OFF
;-------------- 
    


Quote:
Can someone give me an example of what "GDTR" would be in


* 2 Byte's limit (at least 24)
* 4 Byte's base linear address (=physical if paging is off) where the GDT sits
Post 09 Jan 2010, 06:36
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 09 Jan 2010, 07:11
Sorry, I meant the GDT itself.(I know, the code example is misleading)

What needs to be at the location pointed to in GDTR?

[edit]It's 2am, I originally added some stupid questions with the ones I actually need to know, so I deleted them.[/edit]
Post 09 Jan 2010, 07:11
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 09 Jan 2010, 08:42
Tyler wrote:
Sorry, I meant the GDT itself.


0. Invalid selector (8 ZERO's)
1. Code selector (base=0 limit=4GiB Ring=0 type=code 32bit=YES DOWN=NO ...)
2. Data selector (base=0 limit=4GiB Ring=0 type=data 32bit=YES DOWN=NO ...)
Post 09 Jan 2010, 08:42
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Jan 2010, 09:55
Quote:
* 2 Byte's limit (at least 24)
23 Wink
Quote:
1. Code selector (base=0 limit=4GiB Ring=0 type=code 32bit=YES DOWN=NO ...)
Down expanded code segment... Smile This is not selector. This is descriptor. I have general TSS desc in this position.
Post 09 Jan 2010, 09:55
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4352
Location: Now
edfed 09 Jan 2010, 13:51
Code:
align 4
align 2                                    ; for GDTR alignment
gdtr   df @f-gdt-1:gdt                     ; GDTR in memory
gdt:                                       ; GDT entry
       dq 0                                ; (0) NULL selector
linear_sel_1:                              ; (8h) linear Data segment, read/write, expand down
       dw 0FFFFh,0
       db 0,10010010b,11001111b,0
sys_code_1:                                ; (10h) Code segment, read/execute, nonconforming
       dw 0FFFFh,0
       db 0,10011010b,11001111b,0
sys_data_1:                                ; (18h) Data segment, read/write, expand down
       dw 0FFFFh,0
       db 0,10010010b,11001111b,0
Real_code_1:                               ; (20h) Real mode code segment
       dw 0FFFFh,0
       db 0,10011010b,0,0
Real_data_1:                               ; (28h) Real mode data segment
       dw 0FFFFh,0
       db 0,10010010b,0,0
sys_vesa_1:                                ; (30h) vesa segment, read/write, expand down
       dw 0FFFFh,0
       db 0,10010010b,11001111b,0
@@:                                        ; Used to calculate the size of the GDT
sys_vbuff_1:                                ; (30h) vesa segment, read/write, expand down
       dw 0FFFFh,0
       db 0,10010010b,11001111b,0
@@:                                        ; Used to calculate the size of the GDT
    
Post 09 Jan 2010, 13:51
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Jan 2010, 15:55
Code:
align 4align 2    
What does it mean? Maybe you meant something like this.
Code:
align 4rb 2    
Or this.
Code:
rb 3 - ($+1) mod 4    

Code:
gdtr   df @f-gdt-1:gdt    
Does this work? Pointer form is dd,dw, but GDTR one is dw,dd.


Last edited by egos on 09 Jan 2010, 16:13; edited 2 times in total
Post 09 Jan 2010, 15:55
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 09 Jan 2010, 15:55
This is a post for someone new to pm - it has a sample in it and
link to websites... also he had some questions answered that may help..
The example is min to get into pm..

http://dex.7.forumer.com/viewtopic.php?t=533
Post 09 Jan 2010, 15:55
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4352
Location: Now
edfed 09 Jan 2010, 16:03
sorry, align 4 is enough.

i wrote this last year. itr is an error.

i made this because iwas thinking that df is like dw segment, dd offset.
in fact, align 4 is enough because offset is aligned on dword boundary.

df =
dd offset
dw segment

new
Code:
align 4
gdtr   df @f-gdt-1:gdt
    
Post 09 Jan 2010, 16:03
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Jan 2010, 16:38
Code:
rb 3 - ($+1) mod 4gdtr:dw @f-gdt-1dd gdt    
Post 09 Jan 2010, 16:38
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 09 Jan 2010, 19:20
Code:
gdt:
dq 0 ; Null
;                                (Access) (Limit 16-19)
; (Limit 0-15) (Base 0-23     )  ( Byte ) (  &  Flags )(Base 24-31)
db 0xFF, 0xFF, 0x00, 0x00, 0x00, 1001010b, 01001111b,   0x00  ;Code
db 0xFF, 0xFF, 0x00, 0x00, 0x00, 1000010b, 01001111b,   0x00  ;Data    

Is it in the right order or do I need to change something? And gdtr would be
Code:
db 23
dw gdt
    

right?


Last edited by Tyler on 09 Jan 2010, 21:02; edited 1 time in total
Post 09 Jan 2010, 19:20
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Jan 2010, 20:18
No! Open your eyes and try again Evil or Very Mad
Post 09 Jan 2010, 20:18
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Jan 2010, 21:55
No again Smile

Tyler wrote:
Is it in the right order or do I need to change something?
What are you want? What kind of segment? What size and position? Here are the standard FLAT descriptors for kernel mode.

Code:
gdt:
  ...

  dw 0FFFFh ; Limit 15-0
  dw 0 ; Base 15-0
  db 0 ; Base 23-16
  db 10011010b ; P=1, DPL=00b, 11b - code seg, C=0, R=1, A=0
  db 11001111b ; 1 - paged gran, 1 - 32-bit code, 00b - rsv and avl, 1111b - limit 19-16
  db 0 ; Base 31-24

  dw 0FFFFh ; Limit 15-0
  dw 0 ; Base 15-0
  db 0 ; Base 23-16
  db 10010010b ; P=1, DPL=00b, 10b - data seg, E=0, W=1, A=0
  db 11001111b ; 1 - paged gran, 1 - 32-bit data, 00b - rsv and avl, 1111b - limit 19-16
  db 0 ; Base 31-24

  ...
  gdt_size=$-gdt    


Tyler wrote:
And gdtr would be

Code:
gdtr:
  dw gdt_size-1
  dd gdt    
Post 09 Jan 2010, 21:55
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 09 Jan 2010, 23:11
Quote:

What [do] you want?

Your last post, thanks.
Post 09 Jan 2010, 23:11
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 10 Jan 2010, 01:54
With limit = 0xffffff do programs that use segmentation(".com"s) still work? For example, with limit = ffffff how would I load a .com at (any segment):0100h
Post 10 Jan 2010, 01:54
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4352
Location: Now
edfed 10 Jan 2010, 02:09
set base to anywhere you want.
set granularity to 4kB
set limit to 1MB.
and then, .com will be located at 100h in the segment, but will access all the 1mega memory.
IVT will not exist, because it is .com for Pmode.
all memory between 0and 100h inside the code segment can be used a a system code that will handle the program.
you will need 3 segments for graphics, 0a000h, 0B800h,
and vesalinear, returned by vesainfo ( int 10 ax=4f00h).
Post 10 Jan 2010, 02:09
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 10 Jan 2010, 07:36
Quote:

What [do] you want?
Oh, my english is not good, sorry Embarassed
Post 10 Jan 2010, 07:36
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 10 Jan 2010, 09:02
Tyler wrote:
With limit = 0xffffff do programs that use segmentation(".com"s) still work?
Yes, but it will be better if you enclose the "address space" for your program by the size 100h + file size + heap (bss and stack) size.
Post 10 Jan 2010, 09:02
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 12 Jan 2010, 08:55
Tyler wrote:
With limit = 0xffffff do programs that use segmentation(".com"s) still work?


NO.

High limit is irrelevant. DOS COM's won't work because:

1. Protected mode (writing values into seg registers in the "real mode style" will securely GPF Laughing
2. DOS services (INT $21) and other real mode INT's not available (you "could" fix this problem)
Post 12 Jan 2010, 08:55
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 12 Jan 2010, 11:18
Who did say about DOS?
Post 12 Jan 2010, 11:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

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