OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:16 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Babystep5 doesn't explain how keyboard interrupts work
PostPosted: Sat Oct 14, 2017 9:14 am 
Offline

Joined: Thu Oct 12, 2017 6:21 am
Posts: 5
Hello,

I want to learn low-level programming, to program bootloaders and OS'es. I go through the wiki's tutorials and I'm now at Babystep 5
The problem is that it wasn't completely explained how that works. I don't want to copy I want to understand. Could anyone please explain that to me?

The following is the code snippet from Babysteb 5

Code:
;==========================================
; nasmw boot.asm -f bin -o boot.bin
; partcopy boot.bin 0 200 -f0

[ORG 0x7c00]      ; add to offsets
   jmp start

   %include "print.inc"

start:   xor ax, ax   ; make it zero
   mov ds, ax   ; DS=0
   mov ss, ax   ; stack starts at 0
   mov sp, 0x9c00   ; 200h past code start

   mov ax, 0xb800   ; text video memory
   mov es, ax

   cli      ;no interruptions
   mov bx, 0x09   ;hardware interrupt #
   shl bx, 2   ;multiply by 4
   xor ax, ax
   mov gs, ax   ;start of memory
   mov [gs:bx], word keyhandler
   mov [gs:bx+2], ds ; segment
   sti

   jmp $      ; loop forever

keyhandler:
   in al, 0x60   ; get key data
   mov bl, al   ; save it
   mov byte [port60], al

   in al, 0x61   ; keybrd control
   mov ah, al
   or al, 0x80   ; disable bit 7
   out 0x61, al   ; send it back
   xchg ah, al   ; get original
   out 0x61, al   ; send that back

   mov al, 0x20   ; End of Interrupt
   out 0x20, al   ;

   and bl, 0x80   ; key released
   jnz done   ; don't repeat

   mov ax, [port60]
   mov  word [reg16], ax
   call printreg16

done:
   iret

port60   dw 0

   times 510-($-$$) db 0  ; fill sector w/ 0's
   dw 0xAA55        ; req'd by some BIOSes
;==========================================


Thanks for any help


Top
 Profile  
 
 Post subject: Re: Babystep5 doesn't explain how keyboard interrupts work
PostPosted: Sun Oct 15, 2017 9:29 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Wow, I didn't realize we had such a bad tutorial on the wiki. Port 0x61 doesn't have anything to do with the keyboard in any PC less than 30 years old. You should delete the six lines that involve reading and writing port 0x61 from the code before running it.

If you want to learn more, I'd suggest starting with the wiki article for the keyboard controller. From that, you should be able to figure out what the tutorial code is doing.


Top
 Profile  
 
 Post subject: Re: Babystep5 doesn't explain how keyboard interrupts work
PostPosted: Sun Oct 15, 2017 1:19 pm 
Offline

Joined: Thu Oct 12, 2017 6:21 am
Posts: 5
Thank you for notifying me about the mistakes in this tutorial. I was wondering about these 6 lines of code


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], Sa41848 and 65 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group