Page 1 of 1

Help with setting up IVT for Real Mode kernel

Posted: Sun Oct 12, 2014 9:42 am
by Hanz
I'm creating a little 16bit operating system (With CLI, of course). Now I'm starting to work with other programs that kernel can run. I think I must set up IVT before that, so I followed the tutorial here (http://wiki.osdev.org/Real_mode_assembly_IV), but I get stuck about instruction 6: "Move your handler's segment into [es:bx]". How do I do that?


Here is some code:

Code: Select all

EnableIntHandler:
    push es
    xor ax, ax  ; ax=0
    xor bx, bx  ; bx=0
    mov es, ax  ; es=0

    mov al, 70h ; al=112
    mov bl, 4h  ; bl=4
    mul bx      ; ax=448
    mov bx, ax  ; bx=448

    mov word [es:bx], inthandler    ; move pointer?
    add bx, 2   ; bx=450

    ; What do I do here?

    pop es
    ret
inthandler:
	cmp ah,0
	je .type0

    ; Error at interrupt
    call ErrorMsg
	cli
	hlt

.type0:
    call DumpRegisters
	iret

(Edits... lots of typos :/ )

Re: Help with setting up IVT for Real Mode kernel

Posted: Sun Oct 12, 2014 10:37 am
by Brendan
Hi,
Hanz wrote:I'm creating a little 16bit operating system (With CLI, of course). Now I'm starting to work with other programs that kernel can run. I think I must set up IVT before that, so I followed the tutorial here (http://wiki.osdev.org/Real_mode_assembly_IV), but I get stuck about instruction 6: "Move your handler's segment into [es:bx]". How do I do that?
Those instructions are bad anyway.

You want something more like:

Code: Select all

%define INT_NUMBER  0x70
%define CODE_SEG  0x1234      ;Change to whatever code segment your code uses

    push ax          ;(probably avoidable)
    push es          ;(probably avoidable)
    xor ax,ax        ;AX = 0 (probably avoidable)
    mov es,ax        ;ES = 0 (probably avoidable)

    mov word [es:INT_NUMBER*4], inthandler
    mov word [es:INT_NUMBER*4+4], CODE_SEG

    pop es           ;(probably avoidable)
    pop ax           ;(probably avoidable)
Note that it's likely you've got a segment register that is zero anyway (even if it's CS or SS - it doesn't matter); and if you do you can reduce the code above down to 2 instructions.


Cheers,

Brendan

Re: Help with setting up IVT for Real Mode kernel

Posted: Sun Oct 12, 2014 11:42 am
by Hanz
Thanks for answer. I can now understand much more, but there is still one thing... how do I know what is the right segment number?

My kernel is loaded at 0x1000. It begins with:

Code: Select all

[BITS 16]
[ORG 0x1000]
jmp main
%define INT_NUMBER  0x70
%define CODE_SEG  0x1000
inthandler:
	cmp ah,0
	je .type0

    ; Error with interrupt
    call Panic
	cli
	hlt

.type0:
    call DumpRegisters
	iret

main:
    cli
    push cs  ; set DS=CS
    pop ds
    sti
    ; set up inthandler
    push ax
    push es
    xor ax,ax
    mov es,ax
    mov word [es:INT_NUMBER*4], inthandler
    mov word [es:INT_NUMBER*4+4], CODE_SEG
    pop es
    pop ax

I still can't get what I'm doing wrong.
Thanks for help in advance.

Re: Help with setting up IVT for Real Mode kernel

Posted: Sun Oct 12, 2014 11:56 am
by Antti

Code: Select all

    mov word [es:INT_NUMBER*4+4], CODE_SEG
There is an error there. It should be "es:INT_NUMBER*4+2".

Re: Help with setting up IVT for Real Mode kernel

Posted: Sun Oct 12, 2014 12:22 pm
by Hanz
Thank you so much. It work now just like it have to be.

Re: Help with setting up IVT for Real Mode kernel

Posted: Sun Oct 12, 2014 12:37 pm
by Antti
I am not still very comfortable with this. Did you change your CODE_SEG? Otherwise your int handler is at 0x1000:0x1002 and that does not make sense if your kernel is at 0x00001000. Please make sure that you fully understand the difference.