feat: partial PCIe support (MCFG table parsing)
[lunaix-os.git] / lunaix-os / kernel / peripheral / ps2kbd.c
1 #include <hal/acpi/acpi.h>
2 #include <hal/ioapic.h>
3 #include <lunaix/clock.h>
4 #include <lunaix/common.h>
5 #include <lunaix/peripheral/ps2kbd.h>
6 #include <lunaix/syslog.h>
7 #include <lunaix/timer.h>
8
9 #include <arch/x86/interrupts.h>
10 #include <hal/cpu.h>
11 #include <klibc/string.h>
12
13 #include <stdint.h>
14
15 #define PS2_DEV_CMD_MAX_ATTEMPTS 5
16
17 LOG_MODULE("PS2KBD");
18
19 static struct ps2_cmd_queue cmd_q;
20 static struct ps2_key_buffer key_buf;
21 static struct ps2_kbd_state kbd_state;
22
23 #define KEY_NUM(x) (x + 0x30)
24 #define KEY_NPAD(x) ON_KEYPAD(KEY_NUM(x))
25
26 // 我们使用 Scancode Set 2
27
28 // clang-format off
29
30 // 大部分的扫描码(键码)
31 static kbd_keycode_t scancode_set2[] = {
32     0, KEY_F9, 0, KEY_F5, KEY_F3, KEY_F1, KEY_F2, KEY_F12, 0, KEY_F10, KEY_F8, KEY_F6,
33     KEY_F4, KEY_HTAB, '`', 0, 0, KEY_LALT, KEY_LSHIFT, 0, KEY_LCTRL, 'q', KEY_NUM(1), 
34     0, 0, 0, 'z', 's', 'a', 'w', KEY_NUM(2), 0, 0, 'c', 'x', 'd', 'e', KEY_NUM(4), KEY_NUM(3), 
35     0, 0, KEY_SPACE, 'v', 'f', 't', 'r', KEY_NUM(5),
36     0, 0, 'n', 'b', 'h', 'g', 'y', KEY_NUM(6), 0, 0, 0, 'm', 'j', 'u', KEY_NUM(7), KEY_NUM(8),
37     0, 0, ',', 'k', 'i', 'o', KEY_NUM(0), KEY_NUM(9), 0, 0, '.', '/', 'l', ';', 'p', '-', 0, 0,
38     0, '\'', 0, '[', '=', 0, 0, KEY_CAPSLK, KEY_RSHIFT, KEY_LF, ']', 0, '\\', 0, 0, 0, 0, 0, 0, 0,
39     0, KEY_BS, 0, 0, KEY_NPAD(1), 0, KEY_NPAD(4), KEY_NPAD(7), 0, 0, 0, KEY_NPAD(0), ON_KEYPAD('.'),
40     KEY_NPAD(2), KEY_NPAD(5), KEY_NPAD(6), KEY_NPAD(8), KEY_ESC, KEY_NUMSLK, KEY_F11, ON_KEYPAD('+'),
41     KEY_NPAD(3), ON_KEYPAD('-'), ON_KEYPAD('*'), KEY_NPAD(9), KEY_SCRLLK, 0, 0, 0, 0, KEY_F7
42 };
43
44 // 一些特殊的键码(以 0xe0 位前缀的)
45 static kbd_keycode_t scancode_set2_ex[] = {
46     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RALT, 0, 0,
47     KEY_RCTRL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
48     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
49     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ON_KEYPAD('/'), 0, 0, 0, 0, 0, 0, 0, 0, 
50     0, 0, 0, 0, 0, 0, 0, ON_KEYPAD(KEY_LF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51     KEY_END, 0, KEY_LEFT, KEY_HOME,
52     0, 0, 0, KEY_INSERT, KEY_DELETE, KEY_DOWN, 0, KEY_RIGHT, KEY_UP, 0, 0,
53     0, 0, KEY_PG_DOWN, 0, 0, KEY_PG_UP
54 };
55
56 // 用于处理 Shift+<key> 的情况
57 static kbd_keycode_t scancode_set2_shift[] = {
58     0, KEY_F9, 0, KEY_F5, KEY_F3, KEY_F1, KEY_F2, KEY_F12, 0, KEY_F10, KEY_F8, KEY_F6,
59     KEY_F4, KEY_HTAB, '~', 0, 0, KEY_LALT, KEY_LSHIFT, 0, KEY_LCTRL, 'Q', '!', 
60     0, 0, 0, 'Z', 'S', 'A', 'W', '@', 0, 0, 'C', 'X', 'D', 'E', '$', '#', 
61     0, 0, KEY_SPACE, 'V', 'F', 'T', 'R', '%',
62     0, 0, 'N', 'B', 'H', 'G', 'Y', '^', 0, 0, 0, 'M', 'J', 'U', '&', '*',
63     0, 0, '<', 'K', 'I', 'O', ')', '(', 0, 0, '>', '?', 'L', ':', 'P', '_', 0, 0,
64     0, '"', 0, '{', '+', 0, 0, KEY_CAPSLK, KEY_RSHIFT, KEY_LF, '}', 0, '|', 0, 0, 0, 0, 0, 0, 0,
65     0, KEY_BS, 0, 0, KEY_NPAD(1), 0, KEY_NPAD(4), KEY_NPAD(7), 0, 0, 0, KEY_NPAD(0), ON_KEYPAD('.'),
66     KEY_NPAD(2), KEY_NPAD(5), KEY_NPAD(6), KEY_NPAD(8), KEY_ESC, KEY_NUMSLK, KEY_F11, ON_KEYPAD('+'),
67     KEY_NPAD(3), ON_KEYPAD('-'), ON_KEYPAD('*'), KEY_SCRLLK, 0, 0, 0, 0, KEY_F7
68 };
69
70 // clang-format on
71
72 #define KBD_STATE_KWAIT 0x00
73 #define KBD_STATE_KSPECIAL 0x01
74 #define KBD_STATE_KRELEASED 0x02
75 #define KBD_STATE_CMDPROCS 0x40
76
77 #define KBD_ENABLE_SPIRQ_FIX
78 // #define KBD_DBGLOG
79
80 void
81 intr_ps2_kbd_handler(const isr_param* param);
82 static struct kdb_keyinfo_pkt*
83 ps2_keybuffer_next_write();
84
85 void
86 ps2_device_post_cmd(char cmd, char arg)
87 {
88     mutex_lock(&cmd_q.mutex);
89     int index = (cmd_q.queue_ptr + cmd_q.queue_len) % PS2_CMD_QUEUE_SIZE;
90     if (index == cmd_q.queue_ptr && cmd_q.queue_len) {
91         // 队列已满!
92         mutex_unlock(&cmd_q.mutex);
93         return;
94     }
95
96     struct ps2_cmd* container = &cmd_q.cmd_queue[index];
97     container->cmd = cmd;
98     container->arg = arg;
99     cmd_q.queue_len++;
100
101     // 释放锁,同理。
102     mutex_unlock(&cmd_q.mutex);
103 }
104
105 void
106 ps2_kbd_init()
107 {
108
109     memset(&cmd_q, 0, sizeof(cmd_q));
110     memset(&key_buf, 0, sizeof(key_buf));
111     memset(&kbd_state, 0, sizeof(kbd_state));
112
113     mutex_init(&cmd_q.mutex);
114     mutex_init(&key_buf.mutex);
115
116     kbd_state.translation_table = scancode_set2;
117     kbd_state.state = KBD_STATE_KWAIT;
118
119     acpi_context* acpi_ctx = acpi_get_context();
120     if (acpi_ctx->fadt.header.rev > 1) {
121         /*
122          *  只有当前ACPI版本大于1时,我们才使用FADT的IAPC_BOOT_ARCH去判断8042是否存在。
123          *  这是一个坑,在ACPI v1中,这个字段是reserved!而这及至ACPI v2才出现。
124          *  需要注意:Bochs 和 QEMU 使用的是ACPI v1,而非 v2
125          * (virtualbox好像是v4)
126          *
127          *  (2022/6/28)
128          *  QEMU似乎在 Q35 + ICH9 支持了 ACPI
129          * v2。但是对于IAPC_BOOT_ARCH的设置还是 停留在ACPI
130          * v1的时代。IAPC_ARCH_8042没有被正确的设置。这是一个今年的bug,好像还未修复
131          *  参考:https://lore.kernel.org/all/20220304115257.1816983-1-ani@anisinha.ca/T/
132          *
133          *  请看Bochs的bios源码(QEMU的BIOS其实是照抄bochs的,所以也是一个德行。。):
134          *      https://bochs.sourceforge.io/cgi-bin/lxr/source/bios/rombios32.c#L1314
135          */
136         if (!(acpi_ctx->fadt.boot_arch & IAPC_ARCH_8042)) {
137             kprintf(KERROR "No PS/2 controller detected.\n");
138             // FUTURE: Some alternative fallback on this? Check PCI bus for USB
139             // controller instead?
140             return;
141         }
142     } else {
143         kprintf(KWARN "Outdated FADT used, assuming 8042 always exist.\n");
144     }
145
146     char result;
147
148     cpu_disable_interrupt();
149
150     // 1、禁用任何的PS/2设备
151     ps2_post_cmd(PS2_PORT_CTRL_CMDREG, PS2_CMD_PORT1_DISABLE, PS2_NO_ARG);
152     ps2_post_cmd(PS2_PORT_CTRL_CMDREG, PS2_CMD_PORT2_DISABLE, PS2_NO_ARG);
153
154     // 2、清空控制器缓冲区
155     io_inb(PS2_PORT_ENC_DATA);
156
157     // 3、屏蔽所有PS/2设备(端口1&2)IRQ,并且禁用键盘键码转换功能
158     result = ps2_issue_cmd(PS2_CMD_READ_CFG, PS2_NO_ARG);
159     result = result & ~(PS2_CFG_P1INT | PS2_CFG_P2INT | PS2_CFG_TRANSLATION);
160     ps2_post_cmd(PS2_PORT_CTRL_CMDREG, PS2_CMD_WRITE_CFG, result);
161
162     // 4、控制器自检
163     result = ps2_issue_cmd(PS2_CMD_SELFTEST, PS2_NO_ARG);
164     if (result != PS2_RESULT_TEST_OK) {
165         kprintf(KERROR "Controller self-test failed.");
166         goto done;
167     }
168
169     // 5、设备自检(端口1自检,通常是我们的键盘)
170     result = ps2_issue_cmd(PS2_CMD_SELFTEST_PORT1, PS2_NO_ARG);
171     if (result != 0) {
172         kprintf(KERROR "Interface test on port 1 failed.");
173         goto done;
174     }
175
176     // 6、开启位于端口1的 IRQ,并启用端口1。不用理会端口2,那儿一般是鼠标。
177     ps2_post_cmd(PS2_PORT_CTRL_CMDREG, PS2_CMD_PORT1_ENABLE, PS2_NO_ARG);
178     result = ps2_issue_cmd(PS2_CMD_READ_CFG, PS2_NO_ARG);
179     result = result | PS2_CFG_P1INT;
180     ps2_post_cmd(PS2_PORT_CTRL_CMDREG, PS2_CMD_WRITE_CFG, result);
181
182     // 至此,PS/2控制器和设备已完成初始化,可以正常使用。
183
184     // 将我们的键盘驱动挂载到第204号中断上(已由IOAPIC映射至IRQ#1),
185     intr_subscribe(PC_KBD_IV, intr_ps2_kbd_handler);
186
187     // 搞一个计时器,将我们的 ps2_process_cmd
188     // 挂上去。每隔5毫秒执行排在队头的命令。
189     //  为什么只执行队头的命令,而不是全部的命令?
190     //      因为我们需要保证isr尽量的简短,运行起来快速。而发送这些命令非常的耗时。
191     timer_run_ms(5, ps2_process_cmd, NULL, TIMER_MODE_PERIODIC);
192
193     /*
194      *   一切准备就绪后,我们才教ioapic去启用IRQ#1。
195      *   至于为什么要在这里,原因是:初始化所使用的一些指令可能会导致IRQ#1的触发(因为返回码),或者是一些什么
196      *  情况导致IRQ#1的误触发(可能是未初始化导致IRQ#1线上不稳定)。于是这些IRQ#1会堆积在APIC的队列里(因为此时我们正在
197      *  初始化8042,屏蔽了所有中断,IF=0)。
198      *  当sti后,这些堆积的中断会紧跟着递送进CPU里,导致我们的键盘handler误认为由按键按下,从而将这个毫无意义的数值加入
199      *  我们的队列中,以供上层读取。
200      *
201      *  所以,保险的方法是:在初始化后才去设置ioapic,这样一来我们就能有一个稳定的IRQ#1以放心使用。
202      */
203     uint8_t irq_kbd = ioapic_get_irq(acpi_ctx, PC_AT_IRQ_KBD);
204     ioapic_redirect(irq_kbd, PC_KBD_IV, 0, IOAPIC_DELMOD_FIXED);
205
206 done:
207     cpu_enable_interrupt();
208 }
209
210 void
211 ps2_process_cmd(void* arg)
212 {
213     /*
214      * 检查锁是否已被启用,如果启用,则表明该timer中断发生时,某个指令正在入队。
215      * 如果是这种情况则跳过,留到下一轮再尝试处理。
216      * 注意,这里其实是ISR的一部分(timer中断),对于单核CPU来说,ISR等同于单个的原子操作。
217      * (因为EFLAGS.IF=0,所有可屏蔽中断被屏蔽。对于NMI的情况,那么就直接算是triple
218      * fault了,所以也没有讨论的意义)
219      * 所以,假若我们遵从互斥锁的严格定义(即这里需要阻塞),那么中断将会被阻塞,进而造成死锁。
220      * 因此,我们这里仅仅进行判断。
221      * 会不会产生指令堆积?不会,因为指令发送的频率远远低于指令队列清空的频率。在目前,我们发送的唯一指令
222      * 就只是用来开关键盘上的LED灯(如CAPSLOCK)。
223      */
224     if (mutex_on_hold(&cmd_q.mutex) || !cmd_q.queue_len) {
225         return;
226     }
227
228     // 处理队列排头的指令
229     struct ps2_cmd* pending_cmd = &cmd_q.cmd_queue[cmd_q.queue_ptr];
230     char result;
231     int attempts = 0;
232
233     // 尝试将命令发送至PS/2键盘(通过PS/2控制器)
234     // 如果不成功(0x60 IO口返回 0xfe,即 NAK i.e. Resend)
235     // 则尝试最多五次
236     do {
237         result = ps2_issue_dev_cmd(pending_cmd->cmd, pending_cmd->arg);
238 #ifdef KBD_ENABLE_SPIRQ_FIX
239         kbd_state.state += KBD_STATE_CMDPROCS;
240 #endif
241         attempts++;
242     } while (result == PS2_RESULT_NAK && attempts < PS2_DEV_CMD_MAX_ATTEMPTS);
243
244     // XXX: 是否需要处理不成功的指令?
245
246     cmd_q.queue_ptr = (cmd_q.queue_ptr + 1) % PS2_CMD_QUEUE_SIZE;
247     cmd_q.queue_len--;
248 }
249
250 void
251 kbd_buffer_key_event(kbd_keycode_t key, uint8_t scancode, kbd_kstate_t state)
252 {
253     /*
254         forgive me on these ugly bit-level tricks,
255         I really hate doing branching on these "fliping switch" things
256     */
257     if (key == KEY_CAPSLK) {
258         kbd_state.key_state ^= KBD_KEY_FCAPSLKED & -state;
259     } else if (key == KEY_NUMSLK) {
260         kbd_state.key_state ^= KBD_KEY_FNUMBLKED & -state;
261     } else if (key == KEY_SCRLLK) {
262         kbd_state.key_state ^= KBD_KEY_FSCRLLKED & -state;
263     } else {
264         if ((key & MODIFR)) {
265             kbd_kstate_t tmp = (KBD_KEY_FLSHIFT_HELD << (key & 0x00ff));
266             kbd_state.key_state = (kbd_state.key_state & ~tmp) | (tmp & -state);
267         } else if (!(key & 0xff00) &&
268                    (kbd_state.key_state &
269                     (KBD_KEY_FLSHIFT_HELD | KBD_KEY_FRSHIFT_HELD))) {
270             key = scancode_set2_shift[scancode];
271         }
272         state = state | kbd_state.key_state;
273         key = key & (0xffdf |
274                      -('a' > key || key > 'z' || !(state & KBD_KEY_FCAPSLKED)));
275
276         if (!mutex_on_hold(&key_buf.mutex)) {
277             struct kdb_keyinfo_pkt* keyevent_pkt = ps2_keybuffer_next_write();
278             *keyevent_pkt =
279               (struct kdb_keyinfo_pkt){ .keycode = key,
280                                         .scancode = scancode,
281                                         .state = state,
282                                         .timestamp = clock_systime() };
283         }
284
285         return;
286     }
287
288     if (state & KBD_KEY_FPRESSED) {
289         // Ooops, this guy generates irq!
290         ps2_device_post_cmd(PS2_KBD_CMD_SETLED,
291                             (kbd_state.key_state >> 1) & 0x00ff);
292     }
293 }
294
295 void
296 intr_ps2_kbd_handler(const isr_param* param)
297 {
298
299     // This is important! Don't believe me? try comment it out and run on Bochs!
300     while (!(io_inb(PS2_PORT_CTRL_STATUS) & PS2_STATUS_OFULL))
301         ;
302
303     // I know you are tempting to move this chunk after the keyboard state
304     // check. But DO NOT. This chunk is in right place and right order. Moving
305     // it at your own risk This is to ensure we've cleared the output buffer
306     // everytime, so it won't pile up across irqs.
307     uint8_t scancode = io_inb(PS2_PORT_ENC_DATA);
308     kbd_keycode_t key;
309
310     /*
311      *    判断键盘是否处在指令发送状态,防止误触发。(伪输入中断)
312      * 这是因为我们需要向ps/2设备发送指令(比如控制led灯),而指令会有返回码。
313      * 这就会有可能导致ps/2控制器在受到我们的命令后(在ps2_process_cmd中),
314      * 产生IRQ#1中断(虽然说这种情况取决于底层BIOS实现,但还是会发生,比如QEMU和bochs)。
315      * 所以这就是说,当IRQ#1中断产生时,我们的CPU正处在另一个ISR中。这样就会导致所有的外部中断被缓存在APIC内部的
316      * FIFO队列里,进行排队等待(APIC长度为二的队列 {IRR, TMR};参考 Intel
317      * Manual Vol.3A 10.8.4)
318      * 那么当ps2_process_cmd执行完后(内嵌在#APIC_TIMER_IV),CPU返回EOI给APIC,APIC紧接着将排在队里的IRQ#1发送给CPU
319      * 造成误触发。也就是说,我们此时读入的scancode实则上是上一个指令的返回代码。
320      *
321      * Problem 1 (Fixed):
322      *      但是这种方法有个问题,那就是,假若我们的某一个命令失败了一次,ps/2给出0xfe,我们重传,ps/2收到指令并给出0xfa。
323      *  那么这样一来,将会由两个连续的IRQ#1产生。而APIC是最多可以缓存两个IRQ,于是我们就会漏掉一个IRQ,依然会误触发。
324      * Solution:
325      *      累加掩码 ;)
326      *
327      * Problem 2:
328      *    +
329      * 这种累加掩码的操作是基于只有一号IRQ产生的中断的假设,万一中间夹杂了别的中断?Race
330      * Condition!
331      *    +
332      * 不很稳定x1,假如连续4次发送失败,那么就会导致累加的掩码上溢出,从而导致下述判断失败。
333      */
334 #ifdef KBD_ENABLE_SPIRQ_FIX
335     if ((kbd_state.state & 0xc0)) {
336         kbd_state.state -= KBD_STATE_CMDPROCS;
337
338         return;
339     }
340 #endif
341
342 #ifdef KBD_DBGLOG
343     kprintf(KDEBUG "%x\n", scancode & 0xff);
344 #endif
345
346     switch (kbd_state.state) {
347         case KBD_STATE_KWAIT:
348             if (scancode == 0xf0) { // release code
349                 kbd_state.state = KBD_STATE_KRELEASED;
350             } else if (scancode == 0xe0) {
351                 kbd_state.state = KBD_STATE_KSPECIAL;
352                 kbd_state.translation_table = scancode_set2_ex;
353             } else {
354                 key = kbd_state.translation_table[scancode];
355                 kbd_buffer_key_event(key, scancode, KBD_KEY_FPRESSED);
356             }
357             break;
358         case KBD_STATE_KSPECIAL:
359             if (scancode == 0xf0) { // release code
360                 kbd_state.state = KBD_STATE_KRELEASED;
361             } else {
362                 key = kbd_state.translation_table[scancode];
363                 kbd_buffer_key_event(key, scancode, KBD_KEY_FPRESSED);
364
365                 kbd_state.state = KBD_STATE_KWAIT;
366                 kbd_state.translation_table = scancode_set2;
367             }
368             break;
369         case KBD_STATE_KRELEASED:
370             key = kbd_state.translation_table[scancode];
371             kbd_buffer_key_event(key, scancode, KBD_KEY_FRELEASED);
372
373             // reset the translation table to scancode_set2
374             kbd_state.state = KBD_STATE_KWAIT;
375             kbd_state.translation_table = scancode_set2;
376             break;
377
378         default:
379             break;
380     }
381 }
382
383 static uint8_t
384 ps2_issue_cmd(char cmd, uint16_t arg)
385 {
386     ps2_post_cmd(PS2_PORT_CTRL_CMDREG, cmd, arg);
387
388     // 等待PS/2控制器返回。通过轮询(polling)状态寄存器的 bit 0
389     // 如置位,则表明返回代码此时就在 0x60 IO口上等待读取。
390     while (!(io_inb(PS2_PORT_CTRL_STATUS) & PS2_STATUS_OFULL))
391         ;
392
393     return io_inb(PS2_PORT_ENC_CMDREG);
394 }
395
396 static void
397 ps2_post_cmd(uint8_t port, char cmd, uint16_t arg)
398 {
399     // 等待PS/2输入缓冲区清空,这样我们才可以写入命令
400     while (io_inb(PS2_PORT_CTRL_STATUS) & PS2_STATUS_IFULL)
401         ;
402
403     io_outb(port, cmd);
404     io_delay(PS2_DELAY);
405
406     if (!(arg & PS2_NO_ARG)) {
407         // 所有参数一律通过0x60传入。
408         io_outb(PS2_PORT_ENC_CMDREG, (uint8_t)(arg & 0x00ff));
409         io_delay(PS2_DELAY);
410     }
411 }
412
413 static uint8_t
414 ps2_issue_dev_cmd(char cmd, uint16_t arg)
415 {
416     ps2_post_cmd(PS2_PORT_ENC_CMDREG, cmd, arg);
417
418     // 等待PS/2控制器返回。通过轮询(polling)状态寄存器的 bit 0
419     // 如置位,则表明返回代码此时就在 0x60 IO口上等待读取。
420     while (!(io_inb(PS2_PORT_CTRL_STATUS) & PS2_STATUS_OFULL))
421         ;
422
423     return io_inb(PS2_PORT_ENC_CMDREG);
424 }
425
426 int
427 kbd_recv_key(struct kdb_keyinfo_pkt* key_event)
428 {
429     if (!key_buf.buffered_len) {
430         return 0;
431     }
432     mutex_lock(&key_buf.mutex);
433
434     struct kdb_keyinfo_pkt* pkt_current = &key_buf.buffer[key_buf.read_ptr];
435
436     *key_event = *pkt_current;
437     key_buf.buffered_len--;
438     key_buf.read_ptr = (key_buf.read_ptr + 1) % PS2_KBD_RECV_BUFFER_SIZE;
439
440     mutex_unlock(&key_buf.mutex);
441     return 1;
442 }
443
444 static struct kdb_keyinfo_pkt*
445 ps2_keybuffer_next_write()
446 {
447     int index =
448       (key_buf.read_ptr + key_buf.buffered_len) % PS2_KBD_RECV_BUFFER_SIZE;
449     if (index == key_buf.read_ptr && key_buf.buffered_len) {
450         // the reader is lagged so much such that the buffer is full.
451         // It is suggested to read from beginning for nearly up-to-date
452         // readings.
453         key_buf.read_ptr = 0;
454         key_buf.buffered_len = index;
455     } else {
456         key_buf.buffered_len++;
457     }
458     return &key_buf.buffer[index];
459 }