Creating services.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Igor1024
Member
Member
Posts: 32
Joined: Mon Apr 11, 2011 12:19 am

Creating services.

Post 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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Creating services.

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Igor1024
Member
Member
Posts: 32
Joined: Mon Apr 11, 2011 12:19 am

Re: Creating services.

Post 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.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Creating services.

Post 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.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Igor1024
Member
Member
Posts: 32
Joined: Mon Apr 11, 2011 12:19 am

Re: Creating services.

Post 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
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Creating services.

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
Igor1024
Member
Member
Posts: 32
Joined: Mon Apr 11, 2011 12:19 am

Re: Creating services.

Post by Igor1024 »

So, I've solved my problem: I organised work with stack by wrong way, so that's why I got #GP.
Post Reply