aboutsummaryrefslogtreecommitdiff
path: root/libk/stdlib/console.cc
blob: dbc9b86ca462bdae05ae22bbfea349d7baaba940 (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
#include "stdlib.h"

static Console *global_console = nullptr;

void console_set(Console *ptr) {
  if (ptr != nullptr) {
    global_console = ptr;
  }
}

void printk(const String &msg) {
  if (global_console == nullptr)
    return;

  global_console->write(msg);
}

void abort() {
  /*
   * On gcc, a 'while(true) {}' will infinitely loop
   * but clang will optimize it away on -O2 if it's empty
   * therefore, add no-op
   */
  while (true) {
    asm volatile("nop");
  }
  __builtin_unreachable();
}