Skip to content

Commit 42fc524

Browse files
author
Ian Seyler
committed
Remove PS/2 mouse driver
- Saves about 600 bytes in the kernel
1 parent 750bf87 commit 42fc524

File tree

8 files changed

+4
-324
lines changed

8 files changed

+4
-324
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ BareMetal provides basic support for symmetric multiprocessing, network, and sto
6060
* HID (Human Interface Devices)
6161
* Input
6262
* PS/2 Keyboard
63-
* PS/2 Mouse
6463
* USB Keyboard
6564
* Serial
6665
* Output

api/libBareMetal.asm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ b_system equ 0x0000000000100040 ; Configure system. IN: RCX = Function, RAX = V
2121
; Index for b_system calls
2222
TIMECOUNTER equ 0x00
2323
FREE_MEMORY equ 0x01
24-
GET_MOUSE equ 0x02
2524
SMP_ID equ 0x10
2625
SMP_NUMCORES equ 0x11
2726
SMP_SET equ 0x12
@@ -44,7 +43,6 @@ STDOUT_GET equ 0x53
4443
CALLBACK_TIMER equ 0x60
4544
CALLBACK_NETWORK equ 0x61
4645
CALLBACK_KEYBOARD equ 0x62
47-
CALLBACK_MOUSE equ 0x63
4846
DUMP_MEM equ 0x70
4947
DUMP_RAX equ 0x71
5048
DELAY equ 0x72

api/libBareMetal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ u64 b_system(u64 function, u64 var1, u64 var2);
3434
// Index for b_config calls
3535
#define TIMECOUNTER 0x00
3636
#define FREE_MEMORY 0x01
37-
#define GET_MOUSE 0x02
3837
#define SMP_ID 0x10
3938
#define SMP_NUMCORES 0x11
4039
#define SMP_SET 0x12
@@ -57,7 +56,6 @@ u64 b_system(u64 function, u64 var1, u64 var2);
5756
#define CALLBACK_TIMER 0x60
5857
#define CALLBACK_NETWORK 0x61
5958
#define CALLBACK_KEYBOARD 0x62
60-
#define CALLBACK_MOUSE 0x63
6159
#define DUMP_MEM 0x70
6260
#define DUMP_RAX 0x71
6361
#define DELAY 0x72

doc/Kernel API.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,6 @@ Return the amount of free memory.
209209
OUT: RAX = Free memory in Mebibytes (MiB)
210210
All other registers preserved
211211

212-
#### MOUSE
213-
214-
Return details of the mouse
215-
216-
IN: Nothing
217-
OUT: RAX = Mouse details
218-
All other registers preserved
219-
Bits 63:48 - Padding
220-
Bits 47:32 - Y position
221-
Bits 31:16 - X position
222-
Bits 15:0 - Buttons pressed
223-
224212
#### SMP_ID
225213

226214
Returns the APIC ID of the CPU that ran this function.
@@ -347,16 +335,6 @@ Configure an interface
347335

348336
#### CALLBACK_KEYBOARD
349337

350-
#### CALLBACK_MOUSE
351-
352-
Set a callback for execution on mouse activity.
353-
354-
IN: Nothing
355-
OUT: RAX = Address of callback
356-
All other registers preserved
357-
358-
Set a callback of 0x0 to disable it.
359-
360338
#### DUMP_MEM
361339

362340
Dump contents of memory

src/drivers/ps2.asm

Lines changed: 2 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,9 @@ ps2_init:
5656
mov al, PS2_KBD_EN
5757
call ps2_send_cmd
5858

59-
; Enable mouse
60-
; mov al, PS2_COMMAND_AUX_EN
61-
; call ps2_send_cmd
62-
6359
; Init keyboard
6460
; TODO - set rate
6561

66-
; Init mouse
67-
call ps2_mouse_init
68-
6962
; Set flag that the PS/2 keyboard was enabled
7063
; TODO - Move to a ps2_keyboard_init function
7164
or qword [os_SysConfEn], 1 << 0
@@ -77,21 +70,11 @@ ps2_init:
7770
mov edi, 0x21
7871
mov rax, int_keyboard
7972
call create_gate
80-
init_64_no_ps2keyboard:
81-
bt ebx, 0
82-
jnc init_64_no_ps2mouse
83-
mov edi, 0x2C
84-
mov rax, int_mouse
85-
call create_gate
86-
init_64_no_ps2mouse:
87-
88-
; Enable specific interrupts
73+
; Enable specific interrupt
8974
mov ecx, 1 ; Keyboard IRQ
9075
mov eax, 0x21 ; Keyboard Interrupt Vector
9176
call os_ioapic_mask_clear
92-
mov ecx, 12 ; Mouse IRQ
93-
mov eax, 0x2C ; Mouse Interrupt Vector
94-
call os_ioapic_mask_clear
77+
init_64_no_ps2keyboard:
9578

9679
ps2_init_error:
9780
ret
@@ -195,107 +178,6 @@ keyboard_done:
195178
; -----------------------------------------------------------------------------
196179

197180

198-
;-----------------------------------------------------------------------------
199-
ps2_mouse_interrupt:
200-
push rcx
201-
push rbx
202-
push rax
203-
204-
mov ecx, 1000
205-
xor eax, eax
206-
mouse_wait:
207-
in al, PS2_STATUS
208-
dec cl
209-
jnz mouse_getbyte
210-
pop rax
211-
pop rbx
212-
pop rcx
213-
iretq
214-
215-
mouse_getbyte:
216-
and al, 0x20 ; Check bit 5 (set if data is from mouse)
217-
jz mouse_wait ; If not, wait for more data
218-
in al, PS2_DATA ; Get a byte of data from the mouse
219-
mov cl, al ; Save the byte to CL
220-
; in al, 0x61 ; Read byte from keyboard controller unused port
221-
; out 0x61, al ; Write same byte back to keyboard controller unused port
222-
xor ebx, ebx
223-
mov bl, [os_ps2_mouse_count] ; Get the byte counter
224-
add ebx, os_ps2_mouse_packet ; Add the address of the mouse packet
225-
mov [ebx], cl ; Store the byte in CL to the correct index into the mouse packet
226-
inc byte [os_ps2_mouse_count] ; Increment the byte counter
227-
mov bl, [os_ps2_mouse_count] ; Copy the byte counter value to BL
228-
cmp bl, [packetsize] ; Compare byte counter to excepted packet size
229-
jb mouse_end ; If below then bail out, wait for rest of packet
230-
mov word [os_ps2_mouse_count], 0 ; At this point we have a full packet. Clear the byte counter
231-
232-
; Process the mouse packet
233-
234-
; Get state of buttons as well as X/Y sign
235-
xor eax, eax
236-
mov al, [os_ps2_mouse_packet] ; State of the buttons
237-
; TODO - Check X/Y overflow. If either are set then no movement, bail out
238-
and al, 7 ; Keep the low 3 bits for the buttons
239-
mov [os_ps2_mouse_buttons], ax
240-
241-
; Process byte for Delta X - Left is negative (128-255), Right is positive (1-127)
242-
mov bl, [os_ps2_mouse_packet+1] ; Load Delta X from mouse packet
243-
cmp bl, 0 ; Check if it was 0
244-
je mouse_skip_x_movement
245-
movsx eax, bl ; Sign extend the Delta for X movement
246-
add [os_ps2_mouse_x], ax
247-
mouse_skip_x_movement:
248-
249-
; Process byte for Delta Y - Up is positive (1-127), Down is negative (128-255)
250-
mov bl, [os_ps2_mouse_packet+2] ; Load Delta Y from mouse packet
251-
cmp bl, 0 ; Check if it was 0
252-
je mouse_skip_y_movement ; If so, jump past setting cursor Y location
253-
not bl ; Flip value since Y direction is, in my opinion, backwards - 0xFF becomes 0x00
254-
inc bl ; Add 1
255-
movsx eax, bl ; Sign extend the Delta for Y movement
256-
add [os_ps2_mouse_y], ax
257-
mouse_skip_y_movement:
258-
259-
; Keep cursor on the screen
260-
; X
261-
mov bx, [os_screen_x] ; Screen X dimension in number of pixels
262-
dec bx ; Decrement by one since valid pixels are 0 thru X-1
263-
mov ax, [os_ps2_mouse_x] ; Get the current X value for the mouse location
264-
cmp ax, 0xF000 ; Check if it wrapped around below 0
265-
ja checkx_min ; If so jump to min
266-
cmp ax, bx ; Check X value against valid max pixel location
267-
jbe checkx_end ; If less or equal then mouse cursor is on screen
268-
checkx_max: ; If greater then mouse cursor has moved off the right edge
269-
mov [os_ps2_mouse_x], bx ; Set the mouse X location to Screen X-1
270-
jmp checkx_end
271-
checkx_min:
272-
xor ax, ax ; Clear AX
273-
mov [os_ps2_mouse_x], ax ; Set the mouse X location to 0
274-
checkx_end:
275-
; Y
276-
mov bx, [os_screen_y] ; Screen Y dimension in number of pixels
277-
dec bx ; Decrement by one since valid pixels are 0 thru Y-1
278-
mov ax, [os_ps2_mouse_y] ; Get the current Y value for the mouse location
279-
cmp ax, 0xF000 ; Check if it wrapped around below 0
280-
ja checky_min ; If so jump to min
281-
cmp ax, bx ; Check Y value against valid max pixel location
282-
jbe checky_end ; If less or equal then mouse cursor is on screen
283-
checky_max: ; If greater then mouse cursor has moved off the bottom edge
284-
mov [os_ps2_mouse_y], bx ; Set the mouse Y location to Screen Y-1
285-
jmp checky_end
286-
checky_min:
287-
xor ax, ax ; Clear AX
288-
mov [os_ps2_mouse_y], ax ; Set the mouse Y location to 0
289-
checky_end:
290-
291-
mouse_end:
292-
pop rax
293-
pop rbx
294-
pop rcx
295-
ret
296-
; -----------------------------------------------------------------------------
297-
298-
299181
; -----------------------------------------------------------------------------
300182
; ps2_read_data - Read data from PS/2 port when it is ready
301183
ps2_read_data:
@@ -362,95 +244,6 @@ ps2wait_done:
362244
; -----------------------------------------------------------------------------
363245

364246

365-
; -----------------------------------------------------------------------------
366-
; ps2_mouse_write/ps2_mouse_read
367-
; IN: AL = byte to send (ps2_mouse_write only)
368-
; OUT: AL = byte received
369-
ps2_mouse_write:
370-
mov dh, al
371-
mov dl, 2
372-
call ps2wait
373-
mov al, PS2_AUX_WRITE
374-
out PS2_CMD, al
375-
call ps2wait
376-
mov al, dh
377-
out PS2_DATA, al
378-
; no ret, fall into read code to read acknowledgement
379-
ps2_mouse_read:
380-
mov dl, 1
381-
call ps2wait
382-
in al, PS2_DATA
383-
ret
384-
; -----------------------------------------------------------------------------
385-
386-
; Variables
387-
packetsize: db 0
388-
resolution: db 3 ; 8 count/mm
389-
samplerate: db 200 ; Decimal value - Samples/second
390-
391-
ps2_mouse_init:
392-
xor eax, eax
393-
mov dl, 2 ; Wait for write to be empty
394-
call ps2wait
395-
mov al, PS2_AUX_EN ; Enable mouse. Bit 5 of CCB should be clear
396-
out PS2_CMD, al ; Send command to PS2 controller
397-
call ps2_mouse_read ; Read acknowledgement
398-
mov dl, 2 ; Wait for write to be empty
399-
call ps2wait
400-
401-
mov al, PS2_RD_CCB ; Command to Read "byte 0" from internal RAM
402-
out PS2_CMD, al ; Send command to PS2 controller
403-
mov dl, 1 ; Wait for read to be empty
404-
call ps2wait
405-
in al, PS2_DATA ; Read data byte from PS2 controller
406-
bt ax, 5 ; Check if bit 5 is clear
407-
jc ps2_mouse_init_fail ; If not, jump to end - no AUX
408-
409-
bts ax, 1 ; Set bit 1 to enable second PS/2 port interrupts
410-
btr ax, 5 ; Clear bit 5 to enable second PS/2 port clock
411-
mov bl, al ; Save new CCB value to BL
412-
mov dl, 2
413-
414-
call ps2wait
415-
mov al, PS2_WR_CCB ; Write next byte to "byte 0" of internal RAM
416-
out PS2_CMD, al
417-
call ps2wait
418-
mov al, bl ; Restore new CCB value from BL
419-
out PS2_DATA, al
420-
mov dl, 1
421-
call ps2wait ; Get optional acknowledgement
422-
423-
; Set mouse parameters
424-
mov byte [packetsize], 3
425-
mov al, PS2_SETDEFAULTS
426-
call ps2_mouse_write
427-
mov al, PS2_SETSAMPLERATE
428-
call ps2_mouse_write
429-
mov al, byte [samplerate]
430-
call ps2_mouse_write
431-
mov al, PS2_SETRESOLUTION
432-
call ps2_mouse_write
433-
mov al, byte [resolution]
434-
call ps2_mouse_write
435-
mov al, PS2_SETSCALING1TO1
436-
call ps2_mouse_write
437-
mov al, PS2_ENABLEPACKETSTREAM
438-
call ps2_mouse_write
439-
440-
; Reset mouse variables
441-
xor eax, eax
442-
mov [os_ps2_mouse_count], ax
443-
mov [os_ps2_mouse_buttons], ax
444-
mov [os_ps2_mouse_x], ax
445-
mov [os_ps2_mouse_y], ax
446-
447-
; Set flag that the PS/2 mouse was enabled
448-
or qword [os_SysConfEn], 1 << 1
449-
450-
ps2_mouse_init_fail:
451-
ret
452-
; -----------------------------------------------------------------------------
453-
454247
; PS/2 Keyboard tables
455248
keylayoutlower:
456249
db 0x00, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x0e, 0, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0x1c, 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 0x27, '`', 0, '\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, 0, 0, ' ', 0
@@ -507,15 +300,6 @@ PS2_KBD_SCANSET equ 0xF0
507300
PS2_KBD_RATE equ 0xF3
508301
PS2_KBD_ENABLE equ 0xF4
509302

510-
; PS/2 Mouse Commands
511-
PS2_SETSCALING1TO1 equ 0xE6
512-
PS2_SETSCALING2TO1 equ 0xE7
513-
PS2_SETRESOLUTION equ 0xE8
514-
PS2_SETSAMPLERATE equ 0xF3
515-
PS2_ENABLEPACKETSTREAM equ 0xF4
516-
PS2_DISABLEPACKETSTREAM equ 0xF5
517-
PS2_SETDEFAULTS equ 0xF6 ; Disables streaming, sets the packet rate to 100 per second, and resolution to 4 pixels per mm.
518-
519303

520304
; =============================================================================
521305
; EOF

0 commit comments

Comments
 (0)