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 | d98781b | 2021-07-25 21:04:17 -0700 | [diff] [blame] | 76 | uint strnlen(char *s, size_t len); |
| 77 | int strncmp(char *a, char *b, size_t len); |
swissChili | 9b3584b | 2021-02-18 13:57:27 -0800 | [diff] [blame] | 78 | |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 79 | bool isdigit(char c); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Ignores trailing non-digit characters. |
| 82 | * @returns 0 if string is not a valid decimal integer |
| 83 | */ |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 84 | uint parse_int(char *string); |
| 85 | |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Read a scan code from the keyboard |
| 88 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 89 | uchar kbd_scan_code(); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Keyboard IRQ handler |
| 93 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 94 | void kbd_handle_input(struct registers *registers); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Set up keyboard driver. |
| 98 | */ |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 99 | void init_kbd(); |