Page 1 of 1

accessing segments

Posted: Sat Jul 28, 2007 4:02 pm
by sancho1980
hi

i have a simple question: ive now written some code that boots the pc, switches over to protected mode and then jumps to some other code writen in c...before jumping there i loaded the ds register with a segment descriptor pointing to b8000 so that when in my c code i do something like

Code: Select all

char *video=0;

*video='A'
the letter A is displayed in the upper left corner. but of course there are 3 more segment registers (es, fs, gs) that *could* be used for video memory instead of having main data register ds point to video memory...is there any way at all to specify in c that for this or that particular memory reference another data register be used, so i can make use of all the 4 data registers without having to refer to assembly???

thanks

martin

Posted: Sat Jul 28, 2007 6:28 pm
by frank
Well the simple answer is no. GCC assumes that all segment registers are the same and that they are all have a base of zero IIRC.

Re: accessing segments

Posted: Tue Jul 31, 2007 3:25 pm
by Candy
sancho1980 wrote:is there any way at all to specify in c that for this or that particular memory reference another data register be used, so i can make use of all the 4 data registers without having to refer to assembly???
C is a platform-independant language. It does not allow for paging nor for segmentation. Paging is wrt this transparent, but segmentation just isn't going to work. There is a part-hack called __thread that allows something like this but I haven't looked into what's generated and/or whether it even works. I think it's FS or GS based access to variables but I'm not quite sure how they're allocated.