//---------------------------------------------------------------- // ledstate.s // // This program allows a user to control the PC keyboard's // three Light Emitting Diodes (LEDs) by entering an octal // digit (0..7) in response to a prompting message. Below // is shown the standard arrangement of these three LEDs: // // digit binary NumLock CapsLock ScrollLock // ---------------------------------------------- // 0 000 off off off // 1 001 off off on // 2 010 off on off // 3 011 off on on // 4 100 on off off // 5 101 on off on // 6 110 on on off // 7 111 on on on // ---------------------------------------------- // // To execute the privileged IN and OUT instructions (used // when transferring data between the CPU and any device), // it is necessary for this program to acquire an elevated // input/output privilege-level (IOPL), by first executing // a special program named 'iopl3' that was created by our // System Administrator Alex Fedosov: // // $ iopl3 // // But you only need to run 'iopl3' once after logging in. // // assemble using: $ as ledstate.s -o ledstate.o // and link ising: $ ld ledstate.o -o ledstate // // NOTE: The standard PC keyboard implements LED circuitry // using bits as follows (thus requiring bit-translation): // // bit #0: controls LED for ScrollLock // bit #1: controls LED for NumLock // bit #2: controls LED for CapsLock // // programmer: ALLAN CRUSE // written on: 08 MAR 2005 //---------------------------------------------------------------- .equ sys_exit, 1 .equ sys_read, 3 .equ sys_write, 4 .equ stdin_ID, 0 .equ stdout_ID, 1 .equ LED_CMD, 0xED .equ KB_STAT, 0x64 .equ KB_CNTRL, 0x64 .equ KB_DATA, 0x60 .data msg: .ascii "\nPlease type an octal numeral (0..7): " len: .int . - msg num: .int -1 table: .byte 0, 1, 4, 5, 2, 3, 6, 7 .text _start: # display the prompting message movl $sys_write, %eax movl $stdout_ID, %ebx leal msg, %ecx movl len, %edx int $0x80 # obtain the user's response movl $sys_read, %eax movl $stdin_ID, %ebx leal num, %ecx movl $4, %edx int $0x80 # rearrange bits to match LED hardware movl num, %eax andl $7, %eax leal table, %ebx xlat movl %eax, num # issue command to the keyboard controller call kb_ready jnz finis movb $LED_CMD, %al outb %al, $KB_DATA call kb_ready jnz finis movb num, %al outb %al, $KB_DATA call kb_ready finis: # return control to the shell movl $sys_exit, %eax xorl %ebx, %ebx int $0x80 kb_ready: # spins until keyboard controller is ready for data pushl %ecx xorl %ecx, %ecx again: inb $KB_STAT, %al test $0x02, %al loopnz again popl %ecx ret .global _start .end