summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
blob: e5c001350f4aca06075374f52a09128dd90a8f94 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdint.h>
#include "vga.h"
#include "fat.h"
#include "ide.h"
#include "panic.h"
#include "serial.h"
#include "util.h"
#include "mem.h"
#include "pci.h"
#include "boot.h"
#include "vesa.h"

char nbuf[11];

#define SOTL(field) field = (void *)((*((uint16_t *)(&field) + 1) << 16) + *(uint16_t *)(&field));

__attribute__ ((noreturn)) void main() {
  SOTL(VESA_INFO->oem)
  SOTL(VESA_INFO->modes)
  SOTL(VESA_INFO->vendor)
  SOTL(VESA_INFO->pname)
  SOTL(VESA_INFO->prev)

  init_mmap();

  init_vesa();

  init_serial();

  vga_blank();
  vga_printsz("Portland v0.0.11\n\n");

  //list vesa modes?

  pci_init();

  u16_dec(n_pci_devices, nbuf);
  vga_printsz(nbuf);
  vga_printsz(" PCI device(s) found:\n");

  for (uint16_t n = 0; n < n_pci_devices; ++n) {
    struct pci_device *pd = nth_pci_device(n);

    u16_hex(pd->number, nbuf);
    vga_printsz("  ");
    vga_printsz(nbuf);
    vga_printsz(": ");

    u16_hex(pd->id_vendor, nbuf);
    nbuf[4] = '.';
    u16_hex(pd->id_device, nbuf + 5);
    vga_printsz(nbuf);

    u8_hex(pd->class, nbuf);
    nbuf[2] = '.';
    u8_hex(pd->subclass, nbuf + 3);
    nbuf[5] = '.';
    u8_hex(pd->iface, nbuf + 6);
    vga_printsz(" (");
    vga_printsz(nbuf);
    vga_printsz(")\n");
  }

  vga_printch('\n');

  init_fat();

  init_ide();

  u8_dec(n_drives, nbuf);
  vga_printsz(nbuf);
  vga_printsz(" drive(s) found:\n");

  for (uint8_t n = 0; n < n_drives; ++n) {
    struct drive *d = drives + n;

    u8_dec(n, nbuf);
    vga_printsz("  sd");
    vga_printsz(nbuf);
    vga_printsz(" (");
    vga_printsz(d->drive_type);
    vga_printsz("): ");

    vga_printsz(d->fs_type);
    vga_printsz(", ");

    u32_dec(d->n_sectors / 2, nbuf);
    vga_printsz(nbuf);
    if (d->n_sectors % 2)
      vga_printsz(".5");
    vga_printsz("k, ");

    uint32_t free_sectors = d->get_free_sectors(d);

    u32_dec(free_sectors / 2, nbuf);
    vga_printsz(nbuf);
    if (d->n_sectors % 2)
      vga_printsz(".5");
    vga_printsz("k free.\n");
  }

  vga_printch('\n');

  u32_dec(pages_left * 4, nbuf);
  vga_printsz(nbuf);
  vga_printsz("k dynamic memory free.\n\n");

  vga_printsz("Loading init process.");

  vga_printsz("\n\nTODO: load and switch to init process");
  while (1)
    asm ("hlt");
}