+ Reply to Thread
Page 4 of 4 FirstFirst ... 234
Results 31 to 38 of 38
Like Tree1Likes

Thread: On The Theory of Interrupts

  1. #31
    Lifetime Supporter Nikita's Avatar
    Join Date
    May 2009
    Posts
    769

    Default Re: On The Theory of Interrupts

    Is it possible for an interrupt to change what address CPU returns to after the "nmiret"?

    I'm trying to figure out how to make a thread scheduler.

  2. #32
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default Re: On The Theory of Interrupts

    Quote Originally Posted by Nikita View Post
    Is it possible for an interrupt to change what address CPU returns to after the "nmiret"?

    I'm trying to figure out how to make a thread scheduler.
    The correct way to do thread switching is to simply switch stacks (returned address is stored on current threads stack - if you change stack to other threads stack, it will return there instead)
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  3. #33
    Wirererer CCFreak2K's Avatar
    Join Date
    Apr 2007
    Posts
    111

    Default Re: On The Theory of Interrupts

    Quote Originally Posted by Nikita View Post
    Is it possible for an interrupt to change what address CPU returns to after the "nmiret"?

    I'm trying to figure out how to make a thread scheduler.
    What you do is store ESP and SS separately, such as in an array in kernel-space. When the scheduler interrupt is called, you store ESP and SS, then restore ESP and SS for the thread that should run next and return from the interrupt.

  4. #34
    Lifetime Supporter Nikita's Avatar
    Join Date
    May 2009
    Posts
    769

    Default Re: On The Theory of Interrupts

    I'm trying to figure out how to get NMI working. So far I've done everything by the book:
    Code:
    stef
    jmp Init
    IntTable:
    alloc 1024
    Init:
    sti
    lidtr IntTable
    mov eax, IntTable
    add eax, 128
    mov #eax, Interrupt32
    add eax, 3
    mov #eax, 64
    jmp Main
    However, when I send it the value of 32, it gives me the error 32, while the main code keeps running fine. The interrupt function at Interrupt32 label was not executed. Could someone point out what could I possible have got wrong there?

  5. #35
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default Re: On The Theory of Interrupts

    Try 96 instead of 64
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  6. #36
    Lifetime Supporter Nikita's Avatar
    Join Date
    May 2009
    Posts
    769

    Default Re: On The Theory of Interrupts

    Thanks, that works.

    Hmm, maybe you could include binary notation to the next version of the assembly editor? 0b1100000 might be handier to write in cases like this one...

    An update to the documentation (and this thread's OP) would be nice too!

  7. #37
    Wire Noob aqez's Avatar
    Join Date
    Dec 2009
    Posts
    5

    Default Re: On The Theory of Interrupts

    So.. I've been messing with cpu for a little bit, and understand asm thoroughly, but I'm having trouble with nmi's. For my example, I've got a cpu wired to an address bus that has a keyboard and a console screen. I also have the NMI output from cpu going to keyboard, and when I press the 'a' key on the keyboard, it triggers interrupt 97. I've got code in place to handle the interrupt, interrupts are enabled, and the code returns with nmiret, but for some reason the code isn't being called, and the cpu is locking at the interrupt, with the nmi number as the error output(obviously). So, thought maybe you gurus could take a look at the pieces of code I'll post here, and see what I'm doing wrong.

    Near the top of my data section we have..
    Code:
    _interrupts:
        alloc 1024
    A little bit further down I have an example interrupt handler, for this example 'a' pressed on a wired keybooard:
    Code:
    _interrupt_a:
        push eax // I push the registers onto the stack before
        push esi // each call's main work, to preserve whatever
        //may have been in the registers
        cmp #ConsoleCurrentChar, #ConsoleLastChar
        cge _screenshiftup
        mov eax, #ConsoleCurrentChar //Current console character
        mov esi, _a // _a is a pointer to the character 'a' in memory
        mov #eax, esi
        inc eax
        mov #eax, #ConsoleParams // Obvious..
        inc eax
        mov #ConsoleCurrentChar, eax
        sub #ModChar, 2
        cmp #ModChar, 2
        cl _resetmod //Dont worry about this, my way of keeping track of line endings
        pop esi
        pop eax
    nmiret //Return from nmi
    And a bit further down in my interrupt table initialization function..:
    Code:
    //------------------------------
    // Function: Interrupt Setup
    // Purpose: Set up interrupts
    // Notes: 
    // Should be called very soon 
    // after boot.
    //------------------------------
    _interruptsetup:
        
        
        lidtr _interrupts //Tell cpu where interrupt table begins
        mov edi, _interrupts
        add edi, 388 //Move to interrupt address
        mov #edi, _interrupt_a //Move address of handler into the table
        add edi, 3
        mov #edi, 96
        
        inc edi
        mov #edi, _interrupt_b
        add edi, 3
        mov #edi, 96
        
        inc edi
        mov #edi, _interrupt_c
        add edi, 3
        mov #edi, 96
        
        ret

    So for the life of me I can't figure out why this isnt working. I'll say it again since I didn't include it in the code: protected mode and interrupts are turned on.


    Edit: So, I've figured out it IS calling the interrupt, its just taking forever to do so.. and once done with this, it quickly alternates between error 2 and 4.???. ??? being digits I can't identify because it swaps out so fast. So that brings about two more questions: Why does it take so long for the interrupt to be handled, and why does it alternate between errors once completed?
    Last edited by aqez; 05-16-2010 at 07:05 PM.

  8. #38
    Wirererer Xandaros's Avatar
    Join Date
    Apr 2007
    Location
    Bremerhaven, Germany
    Posts
    364

    Default Re: On The Theory of Interrupts

    The errors are 2 and 4. 2 means "End of Program execution" and 4 means "Unknown Opcode".

    Have you checked for compilation errors? (Console after uploading the code to the CPU)
    You probably mistyped somewhere in the code. (not necessarily in the part of the code you have posted, it could be anywhere)

    Fix Error 4 first, it might fix 2, too.
    I love very poor avatars

    Quote Originally Posted by Dav1d View Post
    It's too big to copy all in one.

+ Reply to Thread
Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. Interrupts (like unicorns)
    By InfectiousFight in forum Installation and Malfunctions Support
    Replies: 3
    Last Post: 12-03-2008, 09:47 AM
  2. All about Interrupts - because you wanted it...
    By dnifan in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 4
    Last Post: 10-06-2008, 12:36 PM
  3. Conspiracy Theory: OMG REAL GMAN!?!?!?
    By turck3 in forum Wiremod General Chat
    Replies: 7
    Last Post: 05-13-2008, 06:12 PM
  4. theory
    By Admung in forum Installation and Malfunctions Support
    Replies: 1
    Last Post: 02-19-2008, 08:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots