summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
blob: 194ce93c43bcdc50794a16cc2068caa361da34a5 (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
#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);
  }
  halt();
}