OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:12 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 67 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject:
PostPosted: Thu Jun 07, 2007 7:25 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Combuster wrote:
After an exception control is transferred to the kernel which DOES live above the 1MB mark. You are looking at the EIP of a JMP $ instruction inside the kernel. :shock:


:oops: Oops - missed that in my reply!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 10:47 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
Hi...

Now things are making more and more sense to me.
but I have another question:
I made a simple normal task not virtual and it was at 4KB (0x1000).
Inside this normal task I printed a char using direct access to
video memory 0xB8000 and every thing worked fine without any exceptions.
but when I tried to use my normal functions such as printf I got gpf.
what does this mean? why I couldn't use my functions there at 0x1000?

Just to be sure:
I used the same task but this time I enabled VM bit in EFLAGS so this task
became a virtual task I tried to print a char using direct access to 0xB8000
but I got gpf this sould be fine as long as I don't have a gpf handluer,
Am I right?
Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 12:33 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Everything I am going to say now has been said before in this thread one way or the other. I doubt that is a good sign :roll:

Quote:
I made a simple normal task not virtual and it was at 4KB (0x1000).
Inside this normal task I printed a char using direct access to
video memory 0xB8000 and every thing worked fine without any exceptions.
but when I tried to use my normal functions such as printf I got gpf.
what does this mean? why I couldn't use my functions there at 0x1000?

Quote:
Have you actually organised your code with an entry point of 0x1000 [ORG 0x1000]? If you are using C, you will need to link to entry point 0x1000.

The logic behind that: an function thinks relative to itself. When you move a single function, all the functions related to it are somewhere completely different (they are now 1MB rather than a few bytes):

Quote:
I used the same task but this time I enabled VM bit in EFLAGS so this task
became a virtual task I tried to print a char using direct access to 0xB8000
but I got gpf this sould be fine as long as I don't have a gpf handluer,
Am I right?
Thanx.

Quote:
* You can not normally use GCC to generate code for virtual 8086 tasks. This is because GCC generates 32-bit code while in virtual mode code is executed as 16 bits. The easiest way is to write 16-bit assembly with nasm/yasm and use that.

_________________
"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 ]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 1:51 pm 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
Hi...

Quote:
The logic behind that: an function thinks relative to itself. When you move a single function, all the functions related to it are somewhere completely different (they are now 1MB rather than a few bytes):


I think I didn't get this point quite right,would you please give me more
explain about that

Quote:
Have you actually organised your code with an entry point of 0x1000 [ORG 0x1000]? If you are using C, you will need to link to entry point 0x1000.


I'm using C ,so how can I link to an entry point 0x1000?

Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 1:47 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
OK - you are using C, so firstly, make sure you are using a C compiler *which supports 16 bit code* (not GCC). You will either need to specify a command-line option or use a linker (like LD), to link at 0x1000. A linker script may have code like:

Code:
ENTRY(__main);

phys = 0x1000;

SECTIONS
{
  .text phys : AT(phys) {
...
...
}


or something similar. You will have to know the specific command line option / script command for the 16 bit toolchain you are using.

The code output by your compiler is not position-independant. This means that the binary has to know where it is expecting to be loaded in memory. That's why you need to specify this value. Your exe loader needs to honour the expected entry point in order for the code to work.

I know this is probably extremely hypocritical of me :twisted: , but I think you really need to know more about your chosen toolchain before attempting to develop an OS in it. There is normally a manual (online or otherwise) for the compiler which will explain what command switches do.

Granted - these online references can be a bit cryptic at times!

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 1:57 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
FYI:
http://en.wikipedia.org/wiki/Position_independent_code
http://www.delorie.com/gnu/docs/binutils/ld_6.html

Next time, google before asking :roll:

_________________
"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 ]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 5:09 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
I'm okay now. :)

Thank you guys for your help.

I'm so grateful.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 67 posts ]  Go to page Previous  1, 2, 3, 4, 5

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group