1 // 16bit code to handle mouse events.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU GPLv3 license.
8 #include "biosvar.h" // GET_EBDA
9 #include "util.h" // debug_isr
10 #include "pic.h" // unmask_pic2
11 #include "bregs.h" // struct bregs
12 #include "ps2port.h" // aux_command
17 if (! CONFIG_PS2_MOUSE)
19 dprintf(3, "init mouse\n");
20 // pointing device installed
21 SETBITS_BDA(equipment_list_flags, 0x04);
22 // Enable IRQ12 (handle_74)
23 unmask_pic2(PIC2_IRQ12);
26 #define RET_SUCCESS 0x00
27 #define RET_EINVFUNCTION 0x01
28 #define RET_EINVINPUT 0x02
29 #define RET_EINTERFACE 0x03
30 #define RET_ENEEDRESEND 0x04
31 #define RET_ENOHANDLER 0x05
36 u8 ps2ctr = GET_EBDA(ps2ctr);
37 ps2ctr |= I8042_CTR_AUXDIS;
38 ps2ctr &= ~I8042_CTR_AUXINT;
39 SET_EBDA(ps2ctr, ps2ctr);
41 return aux_command(PSMOUSE_CMD_DISABLE, NULL);
46 mouse_15c20000(struct bregs *regs)
48 int ret = disable_mouse();
50 set_code_fail(regs, RET_ENEEDRESEND);
52 set_code_success(regs);
57 mouse_15c20001(struct bregs *regs)
59 u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
60 if ((mouse_flags_2 & 0x80) == 0) {
61 set_code_fail(regs, RET_ENOHANDLER);
65 u8 ps2ctr = GET_EBDA(ps2ctr);
66 ps2ctr &= ~I8042_CTR_AUXDIS;
67 ps2ctr |= I8042_CTR_AUXINT;
68 SET_EBDA(ps2ctr, ps2ctr);
70 int ret = aux_command(PSMOUSE_CMD_ENABLE, NULL);
72 set_code_fail(regs, RET_ENEEDRESEND);
74 set_code_success(regs);
78 mouse_15c200XX(struct bregs *regs)
80 set_code_fail(regs, RET_EINVFUNCTION);
83 // Disable/Enable Mouse
85 mouse_15c200(struct bregs *regs)
88 case 0x00: mouse_15c20000(regs); break;
89 case 0x01: mouse_15c20001(regs); break;
90 default: mouse_15c200XX(regs); break;
96 mouse_15c201(struct bregs *regs)
99 int ret = aux_command(PSMOUSE_CMD_RESET_BAT, param);
101 set_code_fail(regs, RET_ENEEDRESEND);
106 set_code_success(regs);
111 mouse_15c202(struct bregs *regs)
113 static u8 sample_rates[7] = {10, 20, 40, 60, 80, 100, 200};
114 if (regs->bh >= ARRAY_SIZE(sample_rates)) {
115 set_code_fail(regs, RET_EINVINPUT);
118 u8 mouse_data1 = GET_VAR(CS, sample_rates[regs->bh]);
119 int ret = aux_command(PSMOUSE_CMD_SETRATE, &mouse_data1);
121 set_code_fail(regs, RET_ENEEDRESEND);
123 set_code_success(regs);
128 mouse_15c203(struct bregs *regs)
131 // 0 = 25 dpi, 1 count per millimeter
132 // 1 = 50 dpi, 2 counts per millimeter
133 // 2 = 100 dpi, 4 counts per millimeter
134 // 3 = 200 dpi, 8 counts per millimeter
136 set_code_fail(regs, RET_EINVINPUT);
140 int ret = aux_command(PSMOUSE_CMD_SETRES, ¶m);
142 set_code_fail(regs, RET_ENEEDRESEND);
144 set_code_success(regs);
149 mouse_15c204(struct bregs *regs)
152 int ret = aux_command(PSMOUSE_CMD_GETID, param);
154 set_code_fail(regs, RET_ENEEDRESEND);
158 set_code_success(regs);
163 mouse_15c205(struct bregs *regs)
166 set_code_fail(regs, RET_EINTERFACE);
169 SET_EBDA(mouse_flag1, 0x00);
170 SET_EBDA(mouse_flag2, regs->bh);
178 mouse_15c20600(struct bregs *regs)
181 int ret = aux_command(PSMOUSE_CMD_GETINFO, param);
183 set_code_fail(regs, RET_ENEEDRESEND);
189 set_code_success(regs);
192 // Set Scaling Factor to 1:1
194 mouse_15c20601(struct bregs *regs)
196 int ret = aux_command(PSMOUSE_CMD_SETSCALE11, NULL);
198 set_code_fail(regs, RET_ENEEDRESEND);
200 set_code_success(regs);
203 // Set Scaling Factor to 2:1
205 mouse_15c20602(struct bregs *regs)
207 int ret = aux_command(PSMOUSE_CMD_SETSCALE21, NULL);
209 set_code_fail(regs, RET_ENEEDRESEND);
211 set_code_success(regs);
215 mouse_15c206XX(struct bregs *regs)
217 set_code_fail(regs, RET_EINVFUNCTION);
220 // Return Status & Set Scaling Factor...
222 mouse_15c206(struct bregs *regs)
225 case 0x00: mouse_15c20600(regs); break;
226 case 0x01: mouse_15c20601(regs); break;
227 case 0x02: mouse_15c20602(regs); break;
228 default: mouse_15c206XX(regs); break;
232 // Set Mouse Handler Address
234 mouse_15c207(struct bregs *regs)
236 u32 farptr = (regs->es << 16) | regs->bx;
237 u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
240 if ((mouse_flags_2 & 0x80) != 0) {
241 mouse_flags_2 &= ~0x80;
245 /* install handler */
246 mouse_flags_2 |= 0x80;
248 SET_EBDA(mouse_flag2, mouse_flags_2);
249 SET_EBDA(far_call_pointer, farptr);
250 set_code_success(regs);
254 mouse_15c2XX(struct bregs *regs)
256 set_code_fail(regs, RET_EINVFUNCTION);
260 handle_15c2(struct bregs *regs)
264 if (! CONFIG_PS2_MOUSE) {
265 set_code_fail(regs, RET_EUNSUPPORTED);
272 case 0x00: mouse_15c200(regs); break;
273 case 0x01: mouse_15c201(regs); break;
274 case 0x02: mouse_15c202(regs); break;
275 case 0x03: mouse_15c203(regs); break;
276 case 0x04: mouse_15c204(regs); break;
277 case 0x05: mouse_15c205(regs); break;
278 case 0x06: mouse_15c206(regs); break;
279 case 0x07: mouse_15c207(regs); break;
280 default: mouse_15c2XX(regs); break;
287 u8 v = inb(PORT_PS2_STATUS);
288 if ((v & 0x21) != 0x21) {
289 dprintf(1, "int74 but no mouse data.\n");
292 v = inb(PORT_PS2_DATA);
294 u8 mouse_flags_1 = GET_EBDA(mouse_flag1);
295 u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
297 if (! (mouse_flags_2 & 0x80))
298 // far call handler not installed
301 u8 package_count = mouse_flags_2 & 0x07;
302 u8 index = mouse_flags_1 & 0x07;
303 SET_EBDA(mouse_data[index], v);
305 if ((index+1) < package_count) {
307 SET_EBDA(mouse_flag1, mouse_flags_1);
311 //BX_DEBUG_INT74("int74_function: make_farcall=1\n");
312 u16 status = GET_EBDA(mouse_data[0]);
313 u16 X = GET_EBDA(mouse_data[1]);
314 u16 Y = GET_EBDA(mouse_data[2]);
315 SET_EBDA(mouse_flag1, 0);
317 u32 func = GET_EBDA(far_call_pointer);
320 "pushw %w1\n" // status
327 : "+a" (func), "+b" (status), "+c" (X), "+d" (Y)
329 : "esi", "edi", "ebp", "cc"
333 // INT74h : PS/2 mouse hardware interrupt
337 debug_isr(DEBUG_ISR_74);
338 if (! CONFIG_PS2_MOUSE)