OSDev.org https://forum.osdev.org/ |
|
stack segment descriptor https://forum.osdev.org/viewtopic.php?f=1&t=16060 |
Page 1 of 1 |
Author: | sancho1980 [ Thu Jan 31, 2008 3:50 pm ] |
Post subject: | stack segment descriptor |
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 ? |
Author: | bewing [ Thu Jan 31, 2008 9:27 pm ] |
Post subject: | |
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? |
Author: | sancho1980 [ Fri Feb 01, 2008 4:46 am ] |
Post subject: | |
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 |
Author: | sancho1980 [ Fri Feb 01, 2008 12:59 pm ] |
Post subject: | |
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??? |
Author: | alkot [ Fri Feb 01, 2008 2:18 pm ] |
Post subject: | |
But bochs error log shows that you are trying to select invalid segment from GDT. How this things are connected? |
Author: | sancho1980 [ Sat Feb 02, 2008 4:47 am ] |
Post subject: | |
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 |
Author: | pcmattman [ Sat Feb 02, 2008 5:01 am ] |
Post subject: | |
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 . |
Author: | bluecode [ Sat Feb 02, 2008 6:57 am ] |
Post subject: | |
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... |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |