summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
blob: 9ad9d1c86d2a0323fda884a516b6d9fc3dd6b809 (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
/*
Copyright 2019 Benji Dial

Permission to use, copy, modify, and/or distribute this
software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this
permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
*/

#include "vga.h"
#include "files.h"
#include "mem.h"
#include "proc.h"
#include "misc.h"

void _start(void) {
  *(uint16_t *)0x0000200e = 0x0000;

  *(uint32_t *)0x0000050c = (uint32_t)allocate_pages(16 * sizeof(struct file_handle_info), 2);
  for (struct file_handle_info *i = FILE_HANDLES, *l = FILE_HANDLES + 65536; i < l; ++i)
    i->first_sector = 0;

  *(uint32_t *)0x00000510 = (uint32_t)allocate_pages(16 * sizeof(struct proc_info), 2);
  for (struct proc_info *i = PROCS, *l = PROCS + 65536; i < l; ++i)
    i->memory_start = 0;

  uint16_t pages_free = 0, pages_total = 0;
  for (uint16_t *i = MMAP; i < MMAP + 0x1000; ++i)
    switch (*i) {
    case 1:
      continue;
    case 0:
      ++pages_free;
    default:
      ++pages_total;
    }
  put_16(pages_free);
  put_sz(" of ");
  put_16(pages_total);
  put_sz(" pages free.\n");

  put_sz("Welcome to Portland version 0.0.8!\n");
  while (1)
    put_sz("|\b/\b-\b\\\b");
}