flat assembler
Message board for the users of flat assembler.

Index > OS Construction > IVT Setup/Layout

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Hey,

I was looking at the MiniDOS source code and I noticed that Dex put in his own interrupts.

How did you do it?

From the looks of things you were putting handlers in the IVT, but can you give more insight into what needs to be done when doing that?
Post 16 Nov 2007, 14:59
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
an interrupt is a routine thats ends with iret
an int vector is a 16 bit far pointer
so you just have to build the pointers for your routines
there is a DOS int to make this
but the best is to direct memory write

int vector for int 0 is located at linear 0
int vector for int 1 is located at linear 4
int vector for int 2 is located at linear 8
int vector for int 3 is located at linear 12

etc etc...
to change the int vector, you first must cli
then change the vectors ( farpointers )
and sti
Post 16 Nov 2007, 15:32
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Wow! It's that simple?

Thanks.
Post 16 Nov 2007, 16:04
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
In realmode it very simple eg:
Code:
Installints:push  ds                            ; Save DScli                                      ; Turn off int'sxor   ax,axmov   ds,ax                       ; 0 DSmov   word [ds:21h*4],int21         ; load int vecter with int21h addressmov   word [ds:21h*4+2],cs          ; + CSsti                                 ; Turn on int'spop   ds                            ; restore DSret                                 ; Returnint21:                            ;You would come here on int 21hiret                               ; Int return.    


You should also save the regs and you can cmp AH like this
Code:
cmp   ah,0                         ; Does AH = 0je    int21_00                      ; Terminate programcmp   ah,1                         ; Does AH = 1je    int21_01                           ; Read char with echocmp   ah,2                         ; Does AH = 2je    int21_02                         ; Write charcmp   ah,7                         ; Does AH = 7je    int21_07                          ; Read char without echocmp   ah,8                         ; Does AH = 8je    int21_07                      ; Read char;more code here    
Post 17 Nov 2007, 13:54
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
you can also save cpu time with a sub int vector table if you have a lot of sub function
instead of testing all possibles ah values, you direct call the good function after some fixed time computation
very important to be the more real time possible
but it consumme more memory and is harder to debug
not good for size optimisation but good for speed & system optimisation, you can easilly change the sub code offset!
note that all PC since 1998 have a lot of memory
>32 Mb ram, >2Gbytes Hd
so for modern Os, using all the first linear megabyte for basic kernel is not a problem
Code:
int_XX:
        push ds cs               ;saving ds
        pop ds                   ;asssume ds=cs
        push eax                 ;save eax
        and eax,0ffh             ;limit eax to 255
        cmp eax,[.svt]           ;is subfunction out of SubVector Table?
        jg .error
        mov eax,[eax*4+.svt+4]   ;look into the SVT
        cmp eax,0                ;is function supported?
        je .error
        call eax                 ;call, not jump, the sub function
        pop eax                  ;restore context
        pop ds
        or eax,10000000h         ;eax =/= 0 then OK
        iret                     ;and finally iret
.error: 
        pop eax
        pop ds
        mov eax,0                ;eax == 0 then error
        iret
.svt: 
dd @f-$-2                        ;size of subvetor table in bytes
dd .0 
dd .1 
dd .2 
dd 0 
dd .3 
dd 0                             ;int XX.4 doesn't exists
dd .5 
dd .6 
dd .na                           ;int XX.7 is unassigned
dd .na 
dd .0 
dd .a 
rd 4fh 
dd .5ah 
dd .5bh 
@@:                              ;end of subvector table
.0: 
;int XX.0 code 
        ret
.1: 
;int XX.1 code 
        ret
.2: 
;int XX.2 code 
        ret
.3: 
;int XX.3 code 
        ret
.4: 
;int XX.4 code 
        ret
.5: 
;int XX.5 code 
        ret
;not supported sub vectors 
.6: 
.7: 
.8: 
.9: 
.a: 
.b: 
.c: 
.d: 
.e: 
.f: 
.10: 
.11: 
.12: 
.na: ;not assigned 
.5ah: 
.5bh: 
        ret
                        


this is not tested because i don't use int until december! Wink

could that kind of code have a chance to be adopted? Sad
Post 17 Nov 2007, 14:42
View user's profile Send private message Visit poster's website 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.