aboutsummaryrefslogtreecommitdiff
path: root/libc/inc/cpu.h
blob: c25dc60ba46ecef9ad0a4145145a8c22661c013c (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
// MIT License, Copyright (c) 2020 Marvin Borner

#ifndef CPU_H
#define CPU_H

#include <def.h>

u8 inb(u16 port);
u16 inw(u16 port);
u32 inl(u16 port);
void insl(u16 port, void *addr, int n);

void outb(u16 port, u8 data);
void outw(u16 port, u16 data);
void outl(u16 port, u32 data);

#ifdef kernel
void cli();
void sti();
void hlt();
void idle();
void loop();
#endif

static inline void spinlock(int *ptr)
{
	int prev;
	do
		__asm__ volatile("lock xchgl %0,%1" : "=a"(prev) : "m"(*ptr), "a"(1));
	while (prev);
}

#endif