summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
blob: b34f8168ed26b15e9d32ba74ecafed83a1759be5 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdint.h>
#include "serial.h"
#include "panic.h"
#include "paging.h"
#include "boot.h"
#include "util.h"
#include "fat.h"
#include "ide.h"
#include "idt.h"
#include "pmap.h"
#include "task.h"
#include "pci.h"
#include "elf.h"
#include "log.h"
#include "vga.h"
#include "kbd.h"

void _start_user_mode() __attribute__ ((noreturn));

__attribute__ ((noreturn))
void main() {
  char nbuf[11];

  init_pagemap();
  init_paging();
  init_tasks();
  init_serial();
  set_log_mode(LOG_SYSTEM);
  vga_blank();

  logsz("Portland v0.0.11\n\n");

  pci_init();

/*
  u16_dec(n_pci_devices, nbuf);
  logsz(nbuf);
  logsz(" 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);
    logsz("  ");
    logsz(nbuf);
    logsz(": ");

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

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

  logch('\n');
*/

  init_fat();
  //other fs drivers

  init_drives();

  init_ide();
  //other drive drivers

/*
  u8_dec(n_drives, nbuf);
  logsz(nbuf);
  logsz(" drive(s) found:\n");

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

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

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

    logsz(d->fs_type);

    uint32_t free_sectors = d->get_free_sectors(d);
    if (free_sectors != -1) {
      u32_dec(free_sectors / 2, nbuf);
      logsz(", ");
      logsz(nbuf);
      if (free_sectors % 2)
        logsz(".5");
      logsz("k free");
    }

    logsz(".\n");
  }

  logch('\n');
*/

  if (BOOT_INFO->support_flags & BIS_PAE)
    logsz("Processor supports PAE (but Portland OS does not yet).\n");
  else
    logsz("Processor does not support PAE.\n");

  logsz("Kernel dynamic area size: ");
  u32_dec(max_kernel_pages * 4, nbuf);
  logsz(nbuf);
  logsz("k\nUserspace area size: ");
  u32_dec(max_user_pages * 4, nbuf);
  logsz(nbuf);
  logsz("k\n\n");

  if (!try_elf_run(drives, "bin/init", ""))
    PANIC("Failed to load init program.");

  init_kbd();
  init_idt();

  logsz("Switching to init task.\n");
  set_log_mode(LOG_USER);
  _start_user_mode();
}