OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:52 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: stack segment descriptor
PostPosted: Thu Jan 31, 2008 3:50 pm 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
hi

suppose i want to write a stack segment descriptor for a stack segment that stretches from 0100000h to 0110000h, would that be correct:
Code:
   dw 0ffff0000h   ;limit of the segment

   dw 0110000h   ;base address of segment

   db 0      ;still belonging to base address of segment

   db 10010010b   ;1 for "segment is present"

         ;00 for "privilege 0"

         ;1 for "data or code segment"

         ;0 for "data segment"

         ;0 for "expand downward"

         ;1 for writable

         ;0 (access flag set by cpu on 1st access)

   db 01000000b   ;0 for byte-granularity

         ;1 for 32-bit stack pointer

         ;0 (reserved bit)

         ;0 (available to system programmers)

         ;0000b for last bits of segment limit

   db 0      ;last byte of base address


it keeps giving me errors. what goes in the base address? the top or the bottom of the stack? i understand that in order to calculate the value that goes in the limit field, i subtract the size s of the segment from 0ffffffffh, is that right? i have tried all thinkable and unthinkable combinations but i keep getting read/write errors

ok, i tend to read DOUBLE WORD instead of DEFINE WORD whenever i see "dw", so i guess it really has to look like this:

Code:
   dw 0fff0h   ;limit of the segment

sbase1:   dw 0700h   ;base address of segment

sbase2:   db 010h      ;still belonging to base address of segment

   db 10010010b   ;1 for "segment is present"

         ;00 for "privilege 0"

         ;1 for "data or code segment"

         ;0 for "data segment"

         ;0 for "expand downward"

         ;1 for writable

         ;0 (access flag set by cpu on 1st access)

   db 11001111b   ;1 for page-granularity

         ;1 for 32-bit stack pointer

         ;0 (reserved bit)

         ;0 (available to system programmers)

         ;1111b for last bits of segment limit

   db 0      ;last byte of base address


but its not working out! i mean my question, as simple as that: what do i have to change about this descriptor to make it a stack segment from 0100000h - 0110000h ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 9:27 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
I think you're getting messed up by the low-endianness of the cpu.

It's been awile since I did a gdt entry by hand, but let's see:
I get:
dw 0xf
dw 0
dw 0x9310
dw 0x00cf

How do you end up with a 7 in your base address? And I'm not sure that I'm calculating my limit properly. Don't you drop the bottom 12 bits?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 4:46 am 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
Are you sure about this?

If you want to write a segment descriptor for a stack segment that ranges from 0x100000 to 0x110000, shouldn't the base address be

0x110000

??? (i.e. the upper end of the segment)

i.e. shouldnt it be something like this (correct me if im wrong pls):

Code:
   dw fff0h   ;limit of the segment
   dw 0      ;base address of segment
   db 11h      ;still belonging to base address of segment
   db 10010010b   ;1 for "segment is present"
         ;00 for "privilege 0"
         ;1 for "data or code segment"
         ;0 for "data segment"
         ;0 for "expand downward"
         ;1 for writable
         ;0 (access flag set by cpu on 1st access)
   db 11001111b   ;1 for page-granularity
         ;1 for 32-bit stack pointer
         ;0 (reserved bit)
         ;0 (available to system programmers)
         ;1111b for last bits of segment limit
   db 0      ;last byte of base address


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 12:59 pm 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
ok i really should have done this earlier, it seems that as it turns out, the problem lies not with my code but with a bug in bochs
the intel manual says pretty clear that with an expand down segment, the limit stipulates the LOWER bound of the segment
this is to make it possible to ioncrease the size of a stack segment downward
so if you want a stack segment from 0x100000 to 0x110000, your base address needs be 0x110000 and your limit 0xffff0 (page granularity)
a protection fault should really be raised whenever the offset into the segment is BELOW 0xffff0000 (not when its above)

with my stack segment, bochs keeps giving me an error along the lines of:

Code:
fetch_raw_descriptor: GDT: index (f007)1e00 > limit (6f)


in virtualbox it runs just fine

can anyone confirm this is a bug???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 2:18 pm 
Offline

Joined: Tue Nov 06, 2007 5:10 am
Posts: 13
But bochs error log shows that you are trying to select invalid segment from GDT. How this things are connected?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 4:47 am 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
i dont know what youre saying there
i think this error just tells me that my offset is bigger than my limit, which is intentional, because this is an expand-down segment and i believe the bochs developers seem to have forgotten to take that into account


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 5:01 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
Bochs is open source - if you think you've got a bug, tell them about it (submit into the bugs tracker) and then let them deal with it. Make Bochs better :D.

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 6:57 am 
Offline
Member
Member
User avatar

Joined: Wed Nov 17, 2004 12:00 am
Posts: 202
Location: Germany
alkot is right. You are trying to access a descriptor beyond the GDT limit, see in the bochs sourcecode for youself: here. You might want to debug your OS with the bochs debugger since something else is going wrong here...

_________________
lightOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], nullplan and 59 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group