Selector base and stuff

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Selector base and stuff

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Selector base and stuff

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply