Page 1 of 1

How to make a C pointer refers to an offset in SS?

Posted: Sun Mar 07, 2010 1:30 am
by iocoder
Hello everyone,
I have been trying to make a C (or C++) pointer that refers to an offset in SS and not DS.
Can anyone help me plz?
Regards,
Mostafa.

Re: How to make a C pointer refers to an offset in SS?

Posted: Sun Mar 07, 2010 2:41 am
by xenos
GCC (and many other C / C++ compilers) don't support segmentation at all. They simply assume that DS = SS, so it doesn't matter whether the offset belongs to DS or SS

If you really want a segmented memory model with DS != SS, I think you can use the Watcom compiler - but I am not absolutely sure. I remember that I once used it with a segmented memory, but that was a few years ago and I probably had DS = SS.

Re: How to make a C pointer refers to an offset in SS?

Posted: Sun Mar 07, 2010 2:57 am
by iocoder
Thanks XenOS for your reply,
I think i will have to write a little bit of assembly codes to make pointers read and write to SS offsets. The cause for what i do is that when a program calls System Call INT, System Call changes DS and ES to 0x10 (Kernel's Data Segment) and it keeps SS (in order to allow running tasks to call system call in the same time, so no violation will happen).
If System call wants to call a function in kernel, it makes vriables (which are made into SS) and calls the function, something like this function:

Code: Select all

void devman_getinfo(unsigned char id, unsigned short *irqs, unsigned short *cs, unsigned short *ds,
		    unsigned int *off, unsigned int *cls) {
This one needs to return irqs, cs, ds, off, and cls. so it does this:

Code: Select all

	irqs[0] = devman_devices[id].irq[0] + (devman_devices[id].irq[1]<<8);
	cs  [0] = devman_devices[id].cs;
	ds  [0] = devman_devices[id].ds;
	off [0] = devman_devices[id].entry;
	cls [0] = devman_devices[id].cls;
all these data are written to DS, so System Call will not recieve anything! I think i shall make a function like 'stack_read' and 'stack_write', and 'devman_getinfo' will be like this:

Code: Select all

void devman_getinfo(unsigned char id, unsigned short *irqs, unsigned short *cs, unsigned short *ds,
		    unsigned int *off, unsigned int *cls) {
	stack_write(devman_devices[id].irq[0] + (devman_devices[id].irq[1]<<8), irqs);
	stack_write(devman_devices[id].cs, cs);
	stack_write(devman_devices[id].ds, ds);
	stack_write(devman_devices[id].entry, off);
	stack_write(devman_devices[id].cls, cls);
}
Regards,
Mostafa