OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 11:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Accessing Hiword/Loword of an extern reference
PostPosted: Sun Nov 17, 2002 11:33 am 
Hi,
I want to set up a IDT in assembler, but the
handlers are programmed in C. So i need to put the
address of the C functions into the IDT. But since the address of the handler is splitted into the Loword and the Highword in an IDTE, i have to access the Loword and Highword of the address seperately. I already tried this:

dw (int0_handler & FFFF0000)

and this
dw (int0_handler >> 16)
and this
dw word int0_handler

to access just the Highword of the 32-bit address int0_handler, which is an extern reference to the C-function.

but it gives me a compiler error by nasm. I already searched the NASM Documentation and google for a solution, but couldn?t find anything about that.
Do you know of any NASM - Instruction to access the Hiword/Loword of an external 32-bit reference?
Thanks in advance,
Elfredo


Top
  
 
 Post subject: Re:Accessing Hiword/Loword of an extern reference
PostPosted: Sun Nov 17, 2002 12:22 pm 
That's because your using C code in NASM.

You can't use the "&", "(", ")", ">>", or "<<" operators in NASM like that.

You must use that code for the C kernel.

Sorry...

or you could just use the shift assembly lanugage code.

Best Idea: Just program it in C.


Top
  
 
 Post subject: Re:Accessing Hiword/Loword of an extern reference
PostPosted: Tue Nov 19, 2002 2:30 am 
Code:
mov eax,[reference]
mov ebx,eax
and eax,0xFFFF0000
and ebx,0x0000FFFF
shr eax,16
mov [hiword],ax
mov [loword],bx


Top
  
 
 Post subject: Re:Accessing Hiword/Loword of an extern reference
PostPosted: Mon Dec 02, 2002 6:35 am 
The problem here is that you're trying to do arithmetic on a value that is only known at link time.

"int0_handler" is the address of the int0_handler function, right? And that should be constant at run-time, right? Sure; code like this:
Code:
lea eax, [int0_handler]

will assemble to:
Code:
lea eax, [0x12345678]

But it's up to the linker to do the patching.

Ordinarily you can do arithmetic on constant expressions in NASM, and that's quite useful. You can also do some arithmetic on addresses like these, but it's restricted to adding and subtracting constant offsets. Why? Because NASM can't handle the arithmetic itself -- remember, this value will be patched by the linker. And the linker can't handle arithmetic like >> and <<: it can only add and subtract.

Basically, you can't do this. :)


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 60 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