summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
blob: 92e778cd3168b838d0c0331131b334776477c398 (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
#include <stdint.h>
#include "vga.h"
#include "fat.h"
#include "fs.h"
#include "ata.h"
#include "panic.h"
#include "serial.h"
#include "util.h"

uint8_t nbuf[11];

void main() {
  vga_blank();
  vga_printsz("Initializing drivers...");
  sinit();
  vga_printsz("\n  Serial ready.");
  load_fat();
  clear_fs_handles();
  vga_printsz("\n  File system ready.\n\nDisk info:\n  Disk label: ");
  vga_printsn(FAT_INFO->label, 11);
  vga_printsz("\n  Disk size:  ");
  u16_dec(FAT_INFO->sectors >> 1, nbuf);
  vga_printsz(nbuf);
  vga_printsz("k\n  FAT size:   ");
  u16_dec(FAT_INFO->sectors_per_fat >> 1, nbuf);
  vga_printsz(nbuf);
  vga_printsz("k\n  Root size:  ");
  u16_dec(FAT_INFO->root_entries >> 5, nbuf);
  vga_printsz(nbuf);
  vga_printsz("k\n\nRoot directory:");
  fs_handle root = fs_open_root();
  struct directory_entry e;
  while(1) {
    fs_read(root, 32, &e);
    if (!e.name[0])
      break;
    if (e.attrib == FA_LFN)
      continue;
    uint8_t *p = (uint8_t *)&e;
    nbuf[3] = 0;
    vga_printsz("\n  ");
    vga_printsn((uint8_t *)&e.name, 11);
    vga_printsz("  |  0x");
    u8_hex(e.attrib, nbuf);
    vga_printsz(nbuf);
    vga_printch(' ');
    vga_printch(e.attrib & FA_READ_ONLY ? 'R' : '_');
    vga_printch(e.attrib & FA_HIDDEN    ? 'H' : '_');
    vga_printch(e.attrib & FA_SYSTEM    ? 'S' : '_');
    vga_printch(e.attrib & FA_LABEL     ? 'L' : '_');
    vga_printch(e.attrib & FA_DIRECTORY ? 'D' : '_');
    vga_printch(e.attrib & FA_ARCHIVE   ? 'A' : '_');
    vga_printsz("  |  ");
    u32_dec(e.length, nbuf);
    vga_printsz(nbuf);
  }
  fs_close(root);
  if (root = fs_open("BLEH.TXT")) {
    vga_printsz("\n\nContents of BLEH.TXT:");
    uint8_t l;
    uint8_t line[82];
    line[0] = '\n';
    line[1] = ' ';
    line[2] = ' ';
    while (l = fs_read(root, 78, line + 3)) {
      line[l + 3] = 0;
      vga_printsz(line);
    }
    fs_close(root);
  }
  halt();
}