summaryrefslogtreecommitdiff
path: root/src/kernel/util.h
blob: 243541ccdb6a04cc2e38a2d9af4c5661dc532122 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef UTIL_H
#define UTIL_H

#include <stdint.h>
#include "drive.h"

static inline void outb(uint16_t port, uint8_t value) {
  asm (
    "outb %0, %1"
  : : "a"(value), "Nd"(port));
}
static inline uint8_t inb(uint16_t port) {
  uint8_t value;
  asm volatile (
    "inb %1, %0"
  : "=a"(value) : "Nd"(port));
  return value;
}
static inline void outw(uint16_t port, uint16_t value) {
  asm (
    "outw %0, %1"
  : : "a"(value), "Nd"(port));
}
static inline uint16_t inw(uint16_t port) {
  uint16_t value;
  asm volatile (
    "inw %1, %0"
  : "=a"(value) : "Nd"(port));
  return value;
}
static inline void outd(uint16_t port, uint32_t value) {
  asm (
    "outl %0, %1"
  : : "a"(value), "Nd"(port));
}
static inline uint32_t ind(uint16_t port) {
  uint32_t value;
  asm volatile (
    "inl %1, %0"
  : "=a"(value) : "Nd"(port));
  return value;
}

void memcpy(void *to, void *from, uint32_t n);
void fmcpy(void *to, struct drive *d, drive_file_id_t f, uint32_t from, uint32_t n);

void u32_dec(uint32_t n, char *b);
void u16_dec(uint16_t n, char *b);
void u8_dec(uint8_t n, char *b);
void u32_hex(uint32_t n, char *b);
void u16_hex(uint16_t n, char *b);
void u8_hex(uint8_t n, char *b);

#endif