Page 1 of 1

Creating services.

Posted: Sun Apr 24, 2011 12:24 am
by Igor1024
I'm trying to make up services... So, the first one is 'text service'; and I have a problem with it - text service doesn't work or crash the 'system'. When the same code was in keyboard handler it worked very well.
Keyboard handler saves in the first byte of 'keyb_state' scancode of the key, second byte is set to 0; Text service firstly checks whether was this scancode used (it's used when second byte in 'keyb_state' is set to 1),
The structure is like that

Code: Select all

PM_32_ENTRY:  
.............
call text_serv  
Function 'store_keyb_state' is used by keyboard handler:

Code: Select all

store_keyb_state:                      ;al - scancode
        mov byte [keyb_state],al
        mov byte [keyb_state+1],0
        ret
And the last one: text service

Code: Select all

text_serv:
        pusha
        xor ax,ax
        call .read_keyb_state
        cmp al,0Eh
        je .backsp
        cmp al,75
        je .cursor_left
        cmp al,77
        je .cursor_right
        cmp al,72
        je .cursor_up
        cmp al,80
        je .cursor_down
        jmp .just_key


.backsp:
........
        jmp .end

.just_key:
........
        jmp .end

.cursor_left:
........
        jmp .end

.cursor_right:
........
        jmp .end

.cursor_up:
........
        jmp .end

.cursor_down:
........
        jmp .end

.read_keyb_state:
       mov al,byte [keyb_state]
       mov ah,byte [keyb_state+1]
       cmp ah,1
       je .end
       mov byte [keyb_state+1],1
       ret

.end:   
        call replace_cursor
        push 18h       ;reinitialize segment registers
        pop es
        push ss
        pop ds
        popa
        jmp text_serv
All this crashes... perhaps I've just sealed up or haven't seen my stupid mistake.

Re: Creating services.

Posted: Sun Apr 24, 2011 1:44 am
by thepowersgang
Without knowing the intricacies of the system (from your description, it sounds like a microkernel of some form) it is impossible to solve your problem for you.

However, I suggest using a debugger of some form (even just catching the fault and displaying the location) to help trace down your bug.

Re: Creating services.

Posted: Sun Apr 24, 2011 5:23 am
by Igor1024
1)It's not a 'system' right now... It's useless right now and seems just like code running in PM... And it's simple.
2)It's rather hard to even 'catch' the place of error cause I have just stubs for exceptions handlers. I think that the problem is in segment selector...
If need, I can add the whole code.

Re: Creating services.

Posted: Sun Apr 24, 2011 2:32 pm
by DavidCooper

Code: Select all

       push 18h       ;reinitialize segment registers
        pop es
        push ss
        pop ds
It may be right, but I'd be interested to know what you're doing this bit for.

Re: Creating services.

Posted: Sun Apr 24, 2011 11:59 pm
by Igor1024
I'm trying to debug my code but I'm still not suceeded.
Perhaps the code will help.
That's the keyboard handler:

Code: Select all

keyboard:
        pushad
        push ds
        xor eax,eax
        xor edi,edi
        xor ebx,ebx
        in al,60h 
        mov ah,al
        and ah,80h
        jnz .end
        call store_keyb_state
        jmp .end

.end:
        pop ds
        push 18h
        pop es
        popad
        jmp int_EOI
And that's the 'service' (very simple).

Code: Select all

text_serv:
        xor ax,ax
        call .read_keyb_state
        cmp al,0Eh
        je .backsp
        cmp al,75
        je .cursor_left
        cmp al,77
        je .cursor_right
        cmp al,72
        je .cursor_up
        cmp al,80
        je .cursor_down
        jmp .just_key


.backsp:
        xor eax,eax
        xor edi,edi
        cmp [cursor],1
        je .end
        dec [cursor]
        movzx edi,[cursor]
        mov al,' '
        mov word [es:edi*2],ax
        jmp .end

.just_key:
        mov ebx,ascii
        add ebx,eax
        mov edi,ebx
        mov al,byte [edi]
        mov ah,07h
        movzx edi,[cursor]
        mov word [es:edi*2],ax
        inc [cursor]
        jmp .end

.cursor_left:
        cmp [cursor],0
        je .end
        dec [cursor]
        mov al,' '
        mov ah,07h
        jmp .end

.cursor_right:
        inc [cursor]
        mov al,' '
        mov ah,07h
        jmp .end

.cursor_up:
        cmp [cursor],80
        jl .end
        sub [cursor],80
        mov al,' '
        mov ah,07h
        jmp .end

.cursor_down:
        add [cursor],80
        mov al,' '
        mov ah,07h
        jmp .end

.read_keyb_state:
       mov al,byte [keyb_state]
       mov ah,byte [keyb_state+1]
       cmp ah,1
       je text_serv
       mov byte [keyb_state+1],1   ;mark as read
       jmp text_serv

.end:   call replace_cursor
          jmp text_serv

replace_cursor:
        push ax
        push dx

        mov dx,3D4h
        mov ax,14
        out dx,ax

        mov dx,3D5h
        mov ax,[cursor+1]
        out dx,ax

        mov dx,3D4h
        mov ax,15
        out dx,ax

        mov dx,3D5h
        mov ax,[cursor]
        dec ax
        out dx,ax

        pop dx
        pop ax
        ret

Re: Creating services.

Posted: Mon Apr 25, 2011 12:53 am
by egos

Code: Select all

.read_keyb_state:
       mov al,byte [keyb_state]
       mov ah,byte [keyb_state+1]
       cmp ah,1
       je text_serv
       mov byte [keyb_state+1],1   ;mark as read
       jmp text_serv
What about locking?

P.S. "wait_key" function could be useful too.

Re: Creating services.

Posted: Sat Apr 30, 2011 7:28 pm
by Igor1024
So, I've solved my problem: I organised work with stack by wrong way, so that's why I got #GP.