blob: edfe2c71cb80cedd48067192bbfcb9de4998c8ac [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);
swissChilid98781b2021-07-25 21:04:17 -070076uint strnlen(char *s, size_t len);
77int strncmp(char *a, char *b, size_t len);
swissChili9b3584b2021-02-18 13:57:27 -080078
swissChili9bd74de2021-06-15 20:30:48 -070079bool isdigit(char c);
swissChilie5adca52021-06-16 21:00:31 -070080/**
81 * Ignores trailing non-digit characters.
82 * @returns 0 if string is not a valid decimal integer
83 */
swissChili9bd74de2021-06-15 20:30:48 -070084uint parse_int(char *string);
85
swissChilie5adca52021-06-16 21:00:31 -070086/**
87 * Read a scan code from the keyboard
88 */
swissChili19ef4182021-02-21 17:45:51 -080089uchar kbd_scan_code();
swissChilie5adca52021-06-16 21:00:31 -070090
91/**
92 * Keyboard IRQ handler
93 */
swissChili19ef4182021-02-21 17:45:51 -080094void kbd_handle_input(struct registers *registers);
swissChilie5adca52021-06-16 21:00:31 -070095
96/**
97 * Set up keyboard driver.
98 */
swissChili19ef4182021-02-21 17:45:51 -080099void init_kbd();