Page 1 of 1

Selector base and stuff

Posted: Tue Jul 01, 2008 1:05 pm
by inflater
Hi,
I have loaded a 512 byte buffer for the floppy disk operations with data, but when I want to transfer them to another buffer using MOVSB and MOV ESI/MOV EDI, I must before the process, set DS and ES to linear base (selector 8 ), do the transfer and then set them to nonlinear base (selector 0x18, sys data). That same applies if I want to LODSB something from that buffer - or else it wouldn't fill up anything except zeros - a MOVSB operation without all that will leave EDI zero'ed and LODSB will leave AL=0. (But the location, without the selector setting, seems to be filled properly when I have it disassembled using Bochs). But when I want to print a string, I do normally mov esi,string call WriteS etc, and I don't have to switch the selectors.

If I would leave DS and ES in linear base, everything works very bad, for example the screen printing routine doesn't work etc.

Is this behavior normal?

//EDIT: Well, in the text i/o functions there IS a setting ES to 8, so I think it's normal..

Thanks in advance.
Regards
inflater

Re: Selector base and stuff

Posted: Tue Jul 01, 2008 1:33 pm
by Combuster
you'll have to be aware of the fact that writing to memory when ES.base = 0 results in something different than when ES.base != zero.

in pseudocode:
1) get the effective address (for MOVSx, that's ESI for reads and EDI for writes)
2) add the selector's base address (DS.base in most cases, ES.base for parts of string instructions)
3) apply paging
4) access the memory location computed

so if you want to access video memory at 0xA0000 when the segment's base is not zrero, you'll have to acces (0xA0000-base) instead