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
Accessing Hiword/Loword of an extern reference
Re:Accessing Hiword/Loword of an extern reference
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.
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.
Re:Accessing Hiword/Loword of an extern reference
Code: Select all
mov eax,[reference]
mov ebx,eax
and eax,0xFFFF0000
and ebx,0x0000FFFF
shr eax,16
mov [hiword],ax
mov [loword],bx
Re:Accessing Hiword/Loword of an extern reference
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:
will assemble to:
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.
"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: Select all
lea eax, [int0_handler]
Code: Select all
lea eax, [0x12345678]
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.