Setting up  LDT question

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
Eric

Setting up  LDT question

Post by Eric »

lemme write out a few lines of code

mov ax,0x0400
mov ds,ax

(er..I hope this is how u write ur assembly code ..atleast w.r.t segment registers irrespective of whether it's 32 or 16 bit code..Excuse me if i am ignorant..i am a total newbie.Well..doesnt make too much sense to me..32  bit offsets but value moved into Segment register is only 16 bits?)

Now i have to set up my LDT.Say i've got my object file..
Now when the program executes this thing is gonna be moved into the DS
which wud yield erroneus results
So i am supposed to change this move in the object file with that of the selector or rather set up the DS reg beforehand and nop these instructions(which i suppose wud be bad coz for instance there cud be another move into
a ds register)...
If it's the first case...i wud need to find the value bein moved on to DS reg i suppose create a selector for the value moved into the register..
Any provisions to do that with an object file?

Thanks in advance
Gandalf

RE:Setting up  LDT question

Post by Gandalf »

Dear friend,

From your question it is quite clear that you are new to osdev. So start off read the os-faq @ www.mega-tokyo.com and read as much as you can about osdev from sites like this one(osdev.org) and osdever.net(they have a lot of useful tutorials). And if you are developing an os for x86 then download the Intel Architecture Manuals 1,2 and 3 (developer.intel.com) and read them (it gives a lot of insight into the architecture).

And also decide about the development tools you will be using. Folks generally prefer gcc and nasm(if you write ur own bootloader - reinventing the wheel in essence).

Or u could use GRUB and then gcc would be enough and for any assembly you can rely on inline assembly(Again you have to learn AT&T syntax for that but it pays in the long run). That doesn't mean that's all - you can develop in Turbo C/C++ Borland C/C++ and I have a friend who says he wants to develop in eiffel.

Anyway that is just the starting ....


Gandalf

PS: Honestly I couldn't understand the last few lines of your query. So please when you intend to ask a question make it clear.
Eric

RE:Setting up  LDT question

Post by Eric »

I'll try my best to make this clear :)

i've my assembly code like this

dseg segment
wrd1 dw 0000h
.......
dseg ends

cseg segment
mov ax,dseg
mov ds,ax
......
cseg ends

Now say i create my object file
The address of dseg in mov ax,dseg has to be filled in by the linker
How's it indicated in the object file that this has to be filled by my linker?
How is dseg indicated as a separate segment in my object file?
The purpose of segments is to fill the memory non-contiguously..So how are the various segments indicated in my object file?
If i know this i can set up my LDT(after loading the segment of course)
and make my linker move the selector for the descriptor of my data segment into my ds register like

mov ax,dseg(the selector)
mov ds,ax

Another issue is

what if the program rather does not think abt moving its data segment's address(relocatable) into the ds register...but rather does a

mov ax,0000h
mov ds,ax

This cud be quite disastrous?I have no idea what wud happen tho...What do i do in such situations?

Thanks in advance..Please help me out coz wud like to write my own linker
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

RE:Setting up  LDT question

Post by df »

i dont speak eric, but i will try;

eye wud suggestion you rud the spucifkation of the object file format that u hud choosed to like output.

in english, which we try and use on this board, object file formats are well documented around the internet. I suggest you somehow (magically?) work out what format you are using, and try and use your brain, to read the specification on how that particular format is implemented.
-- Stu --
Post Reply