summaryrefslogtreecommitdiff
path: root/src/include/smp.h
blob: e33103670dd34d5db641b58969ececd85eaa3483 (plain)
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
#ifndef SMP_INCLUDED
#define SMP_INCLUDED
#include <stdint.h>
#include <stdbool.h>
#include <cpuid.h>
#include <printf.h>
void smp_prepare();
extern uint8_t corecount;

static inline void lock(uint8_t *lock) {
  asm("mov al, 1\n"
      "spinlock:\n"
      "lock xchgb [%0], al\n"
      "test al, al\n"
      "pause\n"
      "jnz spinlock\n"
      ::"r"(lock):"al");
} 

static inline void unlock(uint8_t *lock) {
  asm("lock andb [%0], 0"::"r"(lock));
}

static inline bool get_set_mutex(uint16_t *mutex) {
  bool ret;
  asm("lock bts %1, 0\n"
      "jc .mutex_taken\n"
      "mov %0, 0\n"
      "jmp .done\n"
      ".mutex_taken:\n"
      "mov %0, 1\n"
      ".done:\n"
      :"=r"(ret)
      :"m"(*mutex));
  return ret;
}



//THIS IS ONLY UNTIL WE GET MULTITHREADING SET UP
uint8_t get_coreid();

#define CREATE_LOTO(name)

#endif