summaryrefslogtreecommitdiff
path: root/src/kernel.c
blob: 2a4005a773e0a0a1a8010da72cc39298b06554b9 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <framebuffer.h>
#include <mailbox.h>
#include <mmio.h>
#include <raspi.h>
#include <string.h>
#include <uart.h>

#include <stdint.h>

static void halt() {
  while (1) {
    asm volatile("wfi"); // Wait for interrupt. Core enters low-power state.
  }
}

void main() {
  bool     success = true;
  uint32_t error   = -1;
  char buf[32];
  
  const int raspi = raspi_init();
  mmio_init(raspi); // Must be initialized before other peripherals.
  
  mbox_init();
  uart_init(raspi);
  uart_print("Initializing framebuffer\n");
  success = framebuffer_init(&error);
  if (!success) {
    uart_print("Failed to initialize framebuffer:\n");
    if (error == MAILBOX_DELIVERY_ERROR) {
      uart_print("MAILBOX_DELIVERY_ERROR\n");
    } else if (error == MAILBOX_ERROR) {
      uart_print("MAILBOX_ERROR\n");
    }
    goto end;
  }
  
  const Framebuffer* fb = framebuffer_get();
  uart_print("Framebuffer:");
  uart_print("\n  width:  ");
  uart_print(utoa(fb->width,  buf, sizeof(buf)));
  uart_print("\n  height: ");
  uart_print(utoa(fb->height, buf, sizeof(buf)));
  uart_print("\n  depth:   ");
  uart_print(utoa(fb->depth,  buf, sizeof(buf)));
  uart_print("\n  addr:    ");
  uart_print(ptoa(fb->pixels, buf, sizeof(buf)));
  uart_print("\n  size:    ");
  uart_print(utoa(fb->size,   buf, sizeof(buf)));
  uart_print("\n");
  
  uart_print("Clearing framebuffer\n");
  framebuffer_clear((Pixel){255, 0, 255});
  
  uart_print("All done\n");
  
end:
  halt();
}