OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: ISR handler not being called
PostPosted: Thu Sep 29, 2022 6:47 pm 
Offline
User avatar

Joined: Thu Sep 29, 2022 6:12 pm
Posts: 3
Hi, I'm getting started in OS Dev and I just got to implementing ISR's. My problem is that the code in my ISR handler function seemingly isn't called. Here is my assembly file (boot header omitted):

Code:
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .text
.global _start
.type _start, @function
_start:
   mov $stack_top, %esp
   call kernel_main

.global _gdt_flush
.extern _gp
.type _gdt_flush, @function
_gdt_flush:
   lgdt  (_gp)
   mov %ax, 0x10     
    mov %ds, %ax
    mov %es, %ax
    mov %fs, %ax
    mov %gs, %ax
    mov %ss, %ax
    jmp $0x08, $flush2
flush2:
    ret

.global _idt_load
.extern _idtp
.type _idt_load, @function
_idt_load:
   lidt (_idtp)
   ret               

.global _isr0
/* _isr1, isr2 etc... */

.type _isr0, @function
_isr0:
   cli
   push 0
   push 0
   jmp isr_common_stub

.type _isr1, @function
_isr1:
    cli
    push 0
    push 1
    jmp isr_common_stub

/* _isr2, isr3 etc... */

.global isr_common_stub
.extern _fault_handler
.type isr_common_stub, @function
isr_common_stub:
   pusha
   push %ds
   push %es
   push %fs
   push %gs

   mov %ax, 0x10
   mov %ds, %ax
   mov %es, %ax   
   mov %fs, %ax
    mov %gs, %ax
    mov %eax, %esp 
    push %eax
    mov %eax, _fault_handler
    call *%eax     
    pop %eax
    pop %gs
    pop %fs
    pop %es
    pop %ds
    popa
    add %esp, 8     
    iret         

.size _start, . - _start


And here is my ISR code

Code:
struct regs{
    unsigned int gs, fs, es, ds;     
    unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; 
    unsigned int int_no, err_code;   
    unsigned int eip, cs, eflags, useresp, ss; 
};

extern void _isr0();
/* _isr1, isr2 etc... */

void isrs_install(){
    idt_set_gate(0, (unsigned)_isr0, 0x08, 0x8E);
    /* _isr1, isr2 etc... */
}

void _fault_handler(struct regs *r){
   printf("Exception!\n");   
}



I assume that the ISR handling works to some capacity because if I omit the isrs_install function then the kernel crashes if it encounters an interrupt like this

Code:
asm("int $0x10");


or when I divide an int by zero.

I have read the wiki page on this issue but I'm not sure if any of the listed potential problems apply to me. Can anyone point me in the right direction? Thanks.


Top
 Profile  
 
 Post subject: Re: ISR handler not being called
PostPosted: Thu Sep 29, 2022 10:59 pm 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Your code was originally written in Intel or NASM syntax and it wasn't correctly translated to AT&T syntax.


Top
 Profile  
 
 Post subject: Re: ISR handler not being called
PostPosted: Fri Sep 30, 2022 6:36 am 
Offline
User avatar

Joined: Thu Sep 29, 2022 6:12 pm
Posts: 3
Yes the ISR tutorial I followed had a different asm syntax but I tried my best to convert it. Since it compiled without errors I assumed it was correct. Do you mind pointing out with parts specifically should be different? Thanks.


Top
 Profile  
 
 Post subject: Re: ISR handler not being called
PostPosted: Fri Sep 30, 2022 12:38 pm 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
0xY wrote:
Do you mind pointing out with parts specifically should be different?

Almost all of it, since most instructions have the operands backwards. In Intel/NASM syntax, the first operand is the destination. In AT&T syntax, the first operand is the source.

Code:
   lgdt  (_gp)

The parentheses are unnecessary. A symbol without a prefix is an offset. In AT&T syntax, memory operands are typically written in the form "offset(base,index,scale)".

Code:
   mov %ax, 0x10

You need a $ prefix for immediate values. (You also have the operands backwards, as I mentioned above.)

Code:
    mov %eax, _fault_handler
    call *%eax

You can just call the function. Why are you trying to use an indirect call?


Top
 Profile  
 
 Post subject: Re: ISR handler not being called
PostPosted: Fri Sep 30, 2022 2:38 pm 
Offline
User avatar

Joined: Thu Sep 29, 2022 6:12 pm
Posts: 3
Got it working thanks to your help :D . I wasn't aware of those differences in the syntax.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 76 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