what could be changing variables? [fixed]

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
earlz

what could be changing variables? [fixed]

Post by earlz »

hi I have recently tried to put some multitasking in my OS but to do that I had to have control over which stack is too be used for restoring all the registers and such and I do it by an interrupt

well I store where the stack is in a variable(in memory) and then I call the C interrupt handler then when it returns it puts whats in that stack variable into ESP so that the interrupt handler can change the stack quickly and easily and should be safely

this is my code:

Code: Select all

_irqm_template: ;compiled once but edited and used as a template
     push byte 0 ;error code
     push byte 0 ;interrupt number
    pusha
    push ds
    push es
    push fs
    push gs
    mov ax, 0x0   ; Load the Kernel Data Segment descriptor! -this is changed at template time
    cli
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
   mov ss,ax
    mov eax, esp   ; Push us the stack
    mov [_int_stack],esp
    push eax ;for whatever reason
    mov eax, _int_catcher ;this stays constant
    call eax   ; A special call, preserves the 'eip' register
   pop eax
   mov esp,[_int_stack] ;if I comment this out theirs no problems
    pop gs
    pop fs
    pop es
    pop ds
    mov al,0x20 ;for master irq
     out 0x20, al
    popa
    add esp, 8     ; Cleans up the pushed error code and pushed ISR number
    iret           ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
if I comment out "mov esp,[_int_stack]" then it works but if I don't then periodically in interrupts It will be changed to somethjig invalid, not by the interrupt

what could possibly cause the variable toi be changed!
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:what could be changing variables?

Post by ces_mohab »

I won't answer you yet as I am in hurry but I have some comments
you use cli which is not goot but any way you can use it early;
call eax a special call do you know what a special call is it?
mov ax, 0x0 0x0 is null descriptor or what?

Code: Select all

mov al,0x20 ;for master irq
out 0x20, al
what about slave irq??
Oh!! I remember do you tss task state segment and set esp0 or not?
To write an OS you need 2 minds one for coding and other for debugging.
earlz

Re:what could be changing variables?

Post by earlz »

I'm currently not switching to ring3(just trying to do 2 kernel tasks for a start)
what about slave irq??
this is the stub for the master irq interrupts(0-7) .. theres no slave involved
yea I just use cli right now... I'm afraid that it'd try putting 2 stacks in that 1 var. messing it up
I'm not sure about the call eax, I don't get how you "preserve" the ip register, it was just in the tutorial I read when I started the idt so I did it(it is the call to my interrupt catcher that calls the set interrupt hooks)
mov ax, 0x0 0x0 is null descriptor or what?
you have to understand my way of some stuff... these are "templates" and what I do with them is copy them into some malloc'd place and change some things of them for the proper task, including the that 0x0.. it gets changed to 0x08 I AM SURE!

also I'm not using any kind of paging and this variable is only used in 1 interrupt(which is not an irq) .. also I've tried moving it around so that the variables memory location(&int_stack) is at other places but it don't help... some how this is getting corrupted.
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:what could be changing variables?

Post by ces_mohab »

You can try these :
1-verify your initializing function.
2-try printing data in _int_stack and verify them.
3-use a static member data int_stack.
there have been much threads here taking about multitasking you can search.
To write an OS you need 2 minds one for coding and other for debugging.
earlz

Re:what could be changing variables?

Post by earlz »

1. I'm sure it works right!
2. tried it...
3. what?

I think I found the problem.. my console switching code was enabling interrupts inside interrupts(which I don't support yet)
gonna try to fix it now

edit:
w00t fixed it... I just made an alternate version of my console switcher that was for ints and didn't sti
Post Reply