Page 1 of 1

Zero length isr_wrapper

Posted: Wed Jan 21, 2015 3:48 pm
by jackman
I'm attempting to emulate this wiki page: http://wiki.osdev.org/Interrupt_Service_Routines.

I copy-pasted the isr_wrapper code and put it in its own file.
To make it visible to C, I put the function signature in the source file where I use it. I'm attempting to fill in the IVT with the relative address of the assembly function. This is what the code looks like:

Code: Select all

extern void isr_wrapper(void);                            

u32 *ivt;                                                 
                                                         
void ivt_init(){                                          
ivt = (u32*)IVT_BASE;                                     
                                                          
u32 ptr = &isr_wrapper;                                   
u32 segment = ptr/16;                                     
u32 offset = ptr - (segment*16);                          
u32 reladd = (segment << 16) | offset;                    
ivt[9] = reladd; // keyboard                              
ivt[74] = reladd; // mouse                                
                                                          
// Debugging output.
terminal_printf("Segment: %x\n", segment);                
terminal_printf("Offset: %x\n", offset);                  
terminal_printf("IVT Base: %x\n", &ivt[0]);               
terminal_printf("IVT Vector 9: %x\n", &ivt[9]);           
terminal_printf("ISR Linear Address: %x\n", &isr_wrapper);
terminal_printf("ISR Relative Address: %x\n", reladd);    
                                                          
}                                                         
All the numbers appear to be sane in the debugging output. What puzzles me is that, first, the wrapper/handler never appears to be called. Second, the size of isr_wrapper the readelf output is zero.

Code: Select all

Symbol table '.symtab' contains 79 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
...
    70: 00080310    19 FUNC    GLOBAL DEFAULT    1 msr_get
    71: 00080e58     0 NOTYPE  GLOBAL DEFAULT    1 isr_wrapper
    72: 00080760    45 FUNC    GLOBAL DEFAULT    1 cstr_hex_from_u32
...
What am I doing wrong? Why is the size zero? I've tried various things, including formatting the assembly code like what's in this page: https://banisterfiend.wordpress.com/200 ... on-from-c/. That only gets the type to register as 'FUNC'.

Thank you.

Re: zero length isr_wrapper

Posted: Wed Jan 21, 2015 4:03 pm
by iansjack
Probably a stupid question, but how are you assembling the wrapper function and linking it with the rest of your code? What size is the object file that you get from assembling the function. Are you declaring it as .global (or whatever your assembler requires)?

Re: zero length isr_wrapper

Posted: Wed Jan 21, 2015 4:42 pm
by jackman
Thank you for your response.

Feel free to look at my project makefile: https://github.com/jackmanlabs/barebone ... r/Makefile

That should answer your questions about how the code is assembled and linked. Likewise, you can look at the source at my last commit.

For your convenience, here is the contents of the assembly file:

Code: Select all

.globl  isr_wrapper
.type   isr_wrapper, @function
.align  4

isr_wrapper:
        pusha
        call isr_default
        popa
        iret
The resulting object of that code is 560 bytes. It is an ELF binary:

Code: Select all

Symbol table '.symtab' contains 6 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    1
     2: 00000000     0 SECTION LOCAL  DEFAULT    3
     3: 00000000     0 SECTION LOCAL  DEFAULT    4
     4: 00000000     0 FUNC    GLOBAL DEFAULT    1 isr_wrapper
     5: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND isr_default
I didn't think to look at the ELF data for just the object before. I see now that the isr_wrapper here has a zero size, too.

My build tools are built exactly how the process is described in the wiki: http://wiki.osdev.org/GCC_Cross-Compiler.

I just committed, BTW.

Re: Zero length isr_wrapper

Posted: Thu Jan 22, 2015 3:23 am
by iansjack
OK - the "size" problem is trivial. You need to specify the size of the function in your source file using the ".size" directive":

.size name , expression

So, in this case, you need to add the line:

.size isr_wrapper, .-isr_wrapper

after the "iret" instruction. It's often helpful with problems like this to study the assembler output of a simple C file; look at what assembler directives it uses and try to find out what each one is for.

This doesn't explain why the function isn't working in the way you want it to - I'd suggest that you run the code under a debugger to see what is happening.

Re: Zero length isr_wrapper

Posted: Thu Jan 22, 2015 10:25 am
by jackman
Thank you very much for the help. I owe you the drink of your choice. :)