blob: be82998dbd512bee1913281b934269f86e0a0a1b [file] [log] [blame]
swissChilid8137922021-02-17 15:34:07 -08001#pragma once
2
3#include "kint.h"
swissChili19ef4182021-02-21 17:45:51 -08004#include "registers.h"
5
swissChilie5adca52021-06-16 21:00:31 -07006/**
7 * IO port for keyboard commands.
8 */
swissChili19ef4182021-02-21 17:45:51 -08009#define KBD_CMD_PORT 0x64
swissChilie5adca52021-06-16 21:00:31 -070010
11/**
12 * IO port for keyboard data
13 */
swissChili19ef4182021-02-21 17:45:51 -080014#define KBD_DATA_PORT 0x60
15
swissChilie5adca52021-06-16 21:00:31 -070016/**
17 * Write a byte to a port
18 */
swissChilid8137922021-02-17 15:34:07 -080019void outb(ushort port, uchar val);
swissChilie5adca52021-06-16 21:00:31 -070020
21/**
22 * Write a double word to a port.
23 */
swissChili0d248832021-04-08 18:16:02 -070024void outl(ushort port, uint val);
swissChilie5adca52021-06-16 21:00:31 -070025
26/**
27 * Read a byte from a port.
28 */
swissChilid8137922021-02-17 15:34:07 -080029uchar inb(ushort port);
swissChilie5adca52021-06-16 21:00:31 -070030
31/**
32 * Read a word from a port.
33 */
swissChilid8137922021-02-17 15:34:07 -080034ushort inw(ushort port);
swissChilie5adca52021-06-16 21:00:31 -070035
36/**
37 * Write a word to a port.
38 */
39void outw(ushort port, ushort val);
40
41/**
42 * Just waste some time.
43 */
44void nop();
45
46/**
47 * Read a double word from a port
48 */
swissChili0d248832021-04-08 18:16:02 -070049uint inl(ushort port);
swissChilid8137922021-02-17 15:34:07 -080050
swissChilie5adca52021-06-16 21:00:31 -070051/**
52 * Set n bytes of s to c.
53 */
swissChilid8137922021-02-17 15:34:07 -080054void *memset(void *s, int c, size_t n);
swissChilie5adca52021-06-16 21:00:31 -070055
56/**
57 * Copy n bytes from src to dest.
58 */
swissChilid8137922021-02-17 15:34:07 -080059void *memcpy(void *dest, const void *src, size_t n);
swissChilie5adca52021-06-16 21:00:31 -070060
61/**
62 * Copy null terminated string src to dest.
63 */
swissChilie9289ee2021-03-20 21:54:28 -070064void strcpy(char *dest, char *src);
swissChilie5adca52021-06-16 21:00:31 -070065
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 */
swissChilif5448622021-03-08 20:17:36 -080071int strcmp(char *a, char *b);
swissChilie5adca52021-06-16 21:00:31 -070072/**
73 * @returns the length of null-terminated string a.
74 */
swissChilif5448622021-03-08 20:17:36 -080075uint strlen(char *a);
swissChili9b3584b2021-02-18 13:57:27 -080076
swissChili9bd74de2021-06-15 20:30:48 -070077bool isdigit(char c);
swissChilie5adca52021-06-16 21:00:31 -070078/**
79 * Ignores trailing non-digit characters.
80 * @returns 0 if string is not a valid decimal integer
81 */
swissChili9bd74de2021-06-15 20:30:48 -070082uint parse_int(char *string);
83
swissChilie5adca52021-06-16 21:00:31 -070084/**
85 * Read a scan code from the keyboard
86 */
swissChili19ef4182021-02-21 17:45:51 -080087uchar kbd_scan_code();
swissChilie5adca52021-06-16 21:00:31 -070088
89/**
90 * Keyboard IRQ handler
91 */
swissChili19ef4182021-02-21 17:45:51 -080092void kbd_handle_input(struct registers *registers);
swissChilie5adca52021-06-16 21:00:31 -070093
94/**
95 * Set up keyboard driver.
96 */
swissChili19ef4182021-02-21 17:45:51 -080097void init_kbd();