swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "kint.h" |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 4 | #include "registers.h" |
| 5 | |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 6 | /** |
| 7 | * IO port for keyboard commands. |
| 8 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 9 | #define KBD_CMD_PORT 0x64 |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 10 | |
| 11 | /** |
| 12 | * IO port for keyboard data |
| 13 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 14 | #define KBD_DATA_PORT 0x60 |
| 15 | |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 16 | /** |
| 17 | * Write a byte to a port |
| 18 | */ |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 19 | void outb(ushort port, uchar val); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Write a double word to a port. |
| 23 | */ |
swissChili | 0d24883 | 2021-04-08 18:16:02 -0700 | [diff] [blame] | 24 | void outl(ushort port, uint val); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Read a byte from a port. |
| 28 | */ |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 29 | uchar inb(ushort port); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Read a word from a port. |
| 33 | */ |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 34 | ushort inw(ushort port); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Write a word to a port. |
| 38 | */ |
| 39 | void outw(ushort port, ushort val); |
| 40 | |
| 41 | /** |
| 42 | * Just waste some time. |
| 43 | */ |
| 44 | void nop(); |
| 45 | |
| 46 | /** |
| 47 | * Read a double word from a port |
| 48 | */ |
swissChili | 0d24883 | 2021-04-08 18:16:02 -0700 | [diff] [blame] | 49 | uint inl(ushort port); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 50 | |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Set n bytes of s to c. |
| 53 | */ |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 54 | void *memset(void *s, int c, size_t n); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Copy n bytes from src to dest. |
| 58 | */ |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 59 | void *memcpy(void *dest, const void *src, size_t n); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Copy null terminated string src to dest. |
| 63 | */ |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 64 | void strcpy(char *dest, char *src); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Compare two strings. This might not work like the libc function, so be |
| 68 | * careful. |
| 69 | * @returns 0 if equal, non-0 otherwise. |
| 70 | */ |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 71 | int strcmp(char *a, char *b); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 72 | /** |
| 73 | * @returns the length of null-terminated string a. |
| 74 | */ |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 75 | uint strlen(char *a); |
swissChili | 9b3584b | 2021-02-18 13:57:27 -0800 | [diff] [blame] | 76 | |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 77 | bool isdigit(char c); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 78 | /** |
| 79 | * Ignores trailing non-digit characters. |
| 80 | * @returns 0 if string is not a valid decimal integer |
| 81 | */ |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 82 | uint parse_int(char *string); |
| 83 | |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Read a scan code from the keyboard |
| 86 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 87 | uchar kbd_scan_code(); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Keyboard IRQ handler |
| 91 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 92 | void kbd_handle_input(struct registers *registers); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Set up keyboard driver. |
| 96 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 97 | void init_kbd(); |