flat assembler
Message board for the users of flat assembler.

Index > OS Construction > ISR hook

Author
Thread Post new topic Reply to topic
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 25 Sep 2007, 18:11
Hello,

I'm making my first kernel and sortof at the phase of laying the foundation for my CPU scheduler. I need a Timer ISR hook. I was translating this from some other dialect and the far pointers translation to FASM wasn't exactly obvious... So I'm wondering if I got it about right:

ISR Hook:
Code:
ISRnewTimerInstall:
        cli
        mov     ax,cs       ;data is where the code is
        mov     ds,ax
        mov     ax, 0       ;ISR routing table is in sector 0
        mov     es,ax
        mov     ax,[es:32]  ;8 (as int Cool * 4
        mov     bx,[es:34]  ;8 (as int Cool * 4 + 2
        mov     [ISRoldTimerOffset],ax
        mov     [ISRoldTimerSegment],bx
        mov     [es:32],word ISRnewTimerOffset
        mov     [es:34],word cs
        sti            
    


ISR Routine:
Code:
ISRnewTimerOffset:
        cli
        sti
        jmp far dword [ISRoldTimerOffset]
ISRoldTimerOffset       dw      ?
ISRoldTimerSegment      dw      ?  
    


Does it appear right?

Thanks for any help. Smile
Post 25 Sep 2007, 18:11
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta 25 Sep 2007, 21:31
[ Post removed by author. ]


Last edited by mikegonta on 27 Jan 2009, 22:00; edited 2 times in total
Post 25 Sep 2007, 21:31
View user's profile Send private message Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 26 Sep 2007, 18:06
mikegonta wrote:

Assemble your 32 bit protected mode program with ORG 100000h (1 meg), rename it "start" and copy it to the FAT12 disk.


While I do appreciate the program you have created and am aware that it would help to simplify quite a lot in various cases a lot like mine.... my Kernel does not use file systems, much less FAT12, nor would I like to rely on any other software while testing my basic concepts for implementability.
Post 26 Sep 2007, 18:06
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta 27 Sep 2007, 00:39
[ Post removed by author. ]


Last edited by mikegonta on 27 Jan 2009, 22:01; edited 2 times in total
Post 27 Sep 2007, 00:39
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 27 Sep 2007, 03:33
@DustWolf, here are two fasm examples:
16bit real mode example, from MiniDos
Code:
;====================================================;;  set interrupt vector                              ;;====================================================;int21_25:  cmp   al,19h                       ; No change int 19h (for rebooting)        je    int21_error                  ; Jump to int21_error label        cli                                ; Turn off int's        xor   ah,ah                        ; 0 AH        shl   ax,2                         ; Mul whats in AX by 4        push  si                           ; Save SI        push  bx                           ; Save BX        push  es                           ; Save ES        mov   si,ax                        ; Move AX into SI        xor   bx,bx                        ; 0 BX        mov   es,bx                        ; Move BX into ES        mov   word[es:si],dx              ; Move offset address to ES:SI points to.        mov   bx, ds                       ; Move DS into BX        mov   word[es:si+2],bx                 ; Move segment of address to ES:SI+2 points too.        pop   es                           ; Restore ES        pop   bx                           ; Restore BX        pop   si                           ; Restore SI        sti                                ; Turn int's on       jmp int21_exit                     ; Jump to int21_exit label;====================================================;;  Get interrupt vector                              ;;====================================================;int21_35:        push  ds                           ; Save DS        push  si                           ; Save SI    xor   ah,ah                        ; 0 AH        shl   ax,2                         ; Mul whats in AX by 4        mov   si,ax                        ; Move AX into SI        xor   bx,bx                        ; 0 BX        mov   ds,bx                         ; DS = 0        mov   bx,word[ds:si+2]            ; Move the word that DS:SI+2 points to, into BX        push bx                            ; Save BX        mov   bx,word [ds:si]            ; Move the word that DS:SI points to, into BX        pop es                               ; Move what was in the pushed BX into ES        pop si                             ; Restore SI        pop ds                             ; Restore DS jmp   int21_exit                   ; Jump to int21_exit label    

pmode 32bit example from "TITANSRC"
Code:
  get_int_vector:                  ; AL = interrupt number       movzx   eax,al        shl     eax,3 add     eax,10800h              ; add address of IDT  cli   mov     cx,word [ds:eax+2]  ; get selector        mov     [esp+18h],cx            ; return selector in CX       mov     dx,word [ds:eax+6]        shl     edx,16        mov     dx,word [ds:eax]  mov     [esp+14h],edx           ; return offset in EDX        sti   jmp     int_ok  set_int_vector:                   ; CX:EDX - interrupt handler      movzx   eax,al                  ; AL = interrupt number       shl     eax,3 add     eax,10800h              ; add address of IDT  cli   mov     word [ds:eax+2],cx  ; store selector      mov     word [ds:eax],dx    ; store offset        shr     edx,16        mov     word [ds:eax+6],dx        sti   jmp     int_ok    
Post 27 Sep 2007, 03:33
View user's profile Send private message Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 27 Sep 2007, 22:24
Dex4u: Thanks! Could you just also add the code of the 16 bit version where the dx value is derived for the interrupt set? Also I could use some code on how to do an interrupt routine (only basic structure relevant) and continue into another.

mikegonta: I'm not coding in 16 bit mode, my loader is in 16 bit mode. As such it is not relying on anything in it's runtime, only at load-time which can be dismissed. The BIOS extender you are offering, regardless of how valuable it is in most cases, is a hack and thus an undefined variable which will make the results of my idea-exploring harder to interpet.
Post 27 Sep 2007, 22:24
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 28 Sep 2007, 02:36
DustWolf wrote:
Dex4u: Thanks! Could you just also add the code of the 16 bit version where the dx value is derived for the interrupt set? Also I could use some code on how to do an interrupt routine (only basic structure relevant) and continue into another.

Sure, as MiniDos is a Dos clone, its the same as calling int 21h, function 25h from dos
example:
Code:
xor ax,axmov ds,ax                        mov ah,25hmov al,9hmov dx,int9hhandlerint 21h;some stuff hereint9hhandler:;some stuff hereiret    

Note: the above code would be called from a user program.

Also the full code to MiniDos is here: http://board.flatassembler.net/topic.php?t=5275
Post 28 Sep 2007, 02:36
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.