iret: return CS selector null

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Realtime
Posts: 13
Joined: Mon Sep 22, 2014 10:38 am

iret: return CS selector null

Post by Realtime »

It wasn't much time from my last time posting my problem on this forum .. OS developing is hard (at least for me) .. Well whatever ...

My Error:

Code: Select all

Booting from 0000:7c00
00015731229e[CPU0  ] iret: return CS selector null
00104740000p[WINGUI] >>PANIC<< POWER button turned off.
00104740000i[CPU0  ] CPU is in protected mode (active)
00104740000i[CPU0  ] CS.mode = 32 bit
00104740000i[CPU0  ] SS.mode = 32 bit
00104740000i[CPU0  ] EFER   = 0x00000000
00104740000i[CPU0  ] | EAX=00008a4a  EBX=00007f44  ECX=00090000  EDX=00000000
00104740000i[CPU0  ] | ESP=000006f8  EBP=00000000  ESI=000e055d  EDI=00007f44
00104740000i[CPU0  ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf ZF af PF cf
00104740000i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00104740000i[CPU0  ] |  CS:0008( 0001| 0|  0) 00000000 ffffffff 1 1
00104740000i[CPU0  ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00104740000i[CPU0  ] |  SS:0018( 0003| 0|  0) 00000700 00000500 0 1
00104740000i[CPU0  ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00104740000i[CPU0  ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00104740000i[CPU0  ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00104740000i[CPU0  ] | EIP=00008713 (00008713)
00104740000i[CPU0  ] | CR0=0x60000011 CR2=0x00000000
00104740000i[CPU0  ] | CR3=0x00000000 CR4=0x00000000
00104740000i[CPU0  ] 0x0000000000008713>> jmp .-2 (0x00008713) : EBFE
00104740000i[CMOS  ] Last time is 1421172153 (Tue Jan 13 20:02:33 2015)
00104740000i[      ] restoring default signal behavior
00104740000i[SIM   ] quit_sim called with exit code 1
My interrupt handlers catch a GPF at 0x8:0x8A4A which is (i checked it with a dissassembler)

Code: Select all

iretd
in the function

Code: Select all

PIT_IRQ:
	inc dword[ticks]
	call PIC_EOI1
	iretd
as for PIC_EOI1:

Code: Select all

%define PIC1_CMD 0x20
%define PIC1_DATA 0x21
%define PIC2_CMD 0xa0
%define PIC2_DATA 0xa1

%define PIC_EOIV 0x20

PIC_EOI1:
	outb PIC1_CMD,PIC_EOIV
	ret
and outb is:

Code: Select all

%macro outb 2
	push edx
	push eax
	mov dx,%1
	mov al,%2
	out dx,al
	pop eax
	pop edx
%endmacro
I gave all the details i could .. Well , thanks in advance ...
Realtime
Posts: 13
Joined: Mon Sep 22, 2014 10:38 am

Re: iret: return CS selector null

Post by Realtime »

I just thought that the problem might be in the way how i initialize the PIT as i just copy pasted that part XD .. so yeah :

Code: Select all

PIT_Init:
	pushad
 
	mov ebx,PIT_IRQ
	mov ecx,0x20
	call IDT_SetInt
 
    ; Do some checking
 
    mov eax,0x10000                   ;eax = reload value for slowest possible frequency (65536)
    cmp ebx,18                        ;Is the requested frequency too low?
    jbe .gotReloadValue               ; yes, use slowest possible frequency
 
    mov eax,1                         ;ax = reload value for fastest possible frequency (1)
    cmp ebx,1193181                   ;Is the requested frequency too high?
    jae .gotReloadValue               ; yes, use fastest possible frequency
 
    ; Calculate the reload value
 
    mov eax,3579545
    mov edx,0                         ;edx:eax = 3579545
    div ebx                           ;eax = 3579545 / frequency, edx = remainder
    cmp edx,3579545 / 2               ;Is the remainder more than half?
    jb .l1                            ; no, round down
    inc eax                           ; yes, round up
 .l1:
    mov ebx,3
    mov edx,0                         ;edx:eax = 3579545 * 256 / frequency
    div ebx                           ;eax = (3579545 * 256 / 3 * 256) / frequency
    cmp edx,3 / 2                     ;Is the remainder more than half?
    jb .l2                            ; no, round down
    inc eax                           ; yes, round up
 .l2:
 
 
 ; Store the reload value and calculate the actual frequency
 
 .gotReloadValue:
    push eax                          ;Store reload_value for later
    mov [PIT_reload_value],ax         ;Store the reload value for later
    mov ebx,eax                       ;ebx = reload value
 
    mov eax,3579545
    mov edx,0                         ;edx:eax = 3579545
    div ebx                           ;eax = 3579545 / reload_value, edx = remainder
    cmp edx,3579545 / 2               ;Is the remainder more than half?
    jb .l3                            ; no, round down
    inc eax                           ; yes, round up
 .l3:
    mov ebx,3
    mov edx,0                         ;edx:eax = 3579545 / reload_value
    div ebx                           ;eax = (3579545 / 3) / frequency
    cmp edx,3 / 2                     ;Is the remainder more than half?
    jb .l4                            ; no, round down
    inc eax                           ; yes, round up
 .l4:
    mov [IRQ0_frequency],eax          ;Store the actual frequency for displaying later
 
 
 ; Calculate the amount of time between IRQs in 32.32 fixed point
 ;
 ; Note: The basic formula is:
 ;           time in ms = reload_value / (3579545 / 3) * 1000
 ;       This can be rearranged in the follow way:
 ;           time in ms = reload_value * 3000 / 3579545
 ;           time in ms = reload_value * 3000 / 3579545 * (2^42)/(2^42)
 ;           time in ms = reload_value * 3000 * (2^42) / 3579545 / (2^42)
 ;           time in ms * 2^32 = reload_value * 3000 * (2^42) / 3579545 / (2^42) * (2^32)
 ;           time in ms * 2^32 = reload_value * 3000 * (2^42) / 3579545 / (2^10)
 
    pop ebx                           ;ebx = reload_value
    mov eax,0xDBB3A062                ;eax = 3000 * (2^42) / 3579545
    mul ebx                           ;edx:eax = reload_value * 3000 * (2^42) / 3579545
    shrd eax,edx,10
    shr edx,10                        ;edx:eax = reload_value * 3000 * (2^42) / 3579545 / (2^10)
 
    mov [IRQ0_mS],edx                 ;Set whole mS between IRQs
    mov [IRQ0_fractions],eax          ;Set fractions of 1 mS between IRQs
 
 
 ; Program the PIT channel
 
    pushfd
    cli                               ;Disabled interrupts (just in case)
 
    mov al,00110100b                  ;channel 0, lobyte/hibyte, rate generator
    out 0x43, al
 
    mov ax,[PIT_reload_value]         ;ax = 16 bit reload value
    out 0x40,al                       ;Set low byte of PIT reload value
    mov al,ah                         ;ax = high 8 bits of reload value
    out 0x40,al                       ;Set high byte of PIT reload value
 
    popfd
	
    popad
    ret
Realtime
Posts: 13
Joined: Mon Sep 22, 2014 10:38 am

Re: iret: return CS selector null

Post by Realtime »

I found the problem , it was totally me being an idiot .. i forgot a ret instruction thus causing my kernel to enter PIT_IRQ without PIT actually sending an int .. I feel like a total idiot :/
Post Reply