summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/drive.c6
-rw-r--r--src/kernel/drive.h6
-rw-r--r--src/kernel/fat.c67
-rw-r--r--src/kernel/idt.c11
-rw-r--r--src/kernel/isrs.asm2
-rw-r--r--src/kernel/kbd.c38
-rw-r--r--src/kernel/main.c21
-rw-r--r--src/kernel/main2.c69
-rw-r--r--src/kernel/vga.c11
-rw-r--r--src/kernel/vga.h1
10 files changed, 131 insertions, 101 deletions
diff --git a/src/kernel/drive.c b/src/kernel/drive.c
index 731088c..2ae050f 100644
--- a/src/kernel/drive.c
+++ b/src/kernel/drive.c
@@ -36,6 +36,11 @@ static uint32_t unknown_enumerate_dir(const struct drive *d, const char *path, s
return 0;
}
+__attribute__ ((const))
+static uint32_t unknown_n_dir_entries(const struct drive *d, const char *path) {
+ return 0;
+}
+
static inline void determine_fs(struct drive *d) {
if (try_fat_init_drive(d))
return;
@@ -46,6 +51,7 @@ static inline void determine_fs(struct drive *d) {
d->load_sector = &unknown_load_sector;
d->get_file_length = &unknown_get_file_length;
d->enumerate_dir = &unknown_enumerate_dir;
+ d->n_dir_entries = &unknown_n_dir_entries;
d->get_free_sectors = &unknown_get_free_sectors;
}
diff --git a/src/kernel/drive.h b/src/kernel/drive.h
index b02b4ad..03fe4b6 100644
--- a/src/kernel/drive.h
+++ b/src/kernel/drive.h
@@ -13,10 +13,11 @@ typedef uint8_t drive_id_t;
#define DCI_NAME_LEN 100
struct directory_content_info {
- bool is_dir;
char name[DCI_NAME_LEN];
uint32_t size;
-};
+ bool is_dir;
+ uint8_t pad[23];
+} __attribute__ ((packed));
struct drive {
char *drive_type;
@@ -34,6 +35,7 @@ struct drive {
void (*load_sector) (const struct drive *d, file_id_t fid, uint32_t sector, void *at);
uint32_t (*get_file_length) (const struct drive *d, file_id_t fid);
uint32_t (*enumerate_dir) (const struct drive *d, const char *path, struct directory_content_info *info, uint32_t max);
+ uint32_t (*n_dir_entries) (const struct drive *d, const char *path);
uint32_t (*get_free_sectors)(const struct drive *d);
fs_id_t fs_id;
};
diff --git a/src/kernel/fat.c b/src/kernel/fat.c
index c4461de..362539c 100644
--- a/src/kernel/fat.c
+++ b/src/kernel/fat.c
@@ -365,6 +365,72 @@ static uint32_t fat_enumerate_dir(const struct drive *d, const char *path, struc
}
}
+static uint32_t n_root_entries(const struct drive *d) {
+ uint32_t sect = infos[d->drive_id].root_start - 1;
+ struct directory_entry *entry = (struct directory_entry *)(fat_driver_buffer + 512);
+
+ uint32_t count = 0;
+
+ while (true) {
+ if (entry == (struct directory_entry *)(fat_driver_buffer + 512)) {
+ entry = (struct directory_entry *)fat_driver_buffer;
+ ++sect;
+ d->read_sectors(d, sect, 1, entry);
+ }
+
+ if (!*(uint8_t *)entry) {
+ d->done(d);
+ return count;
+ }
+
+ if (entry-> attrib & FA_LABEL) {
+ ++entry;
+ continue;
+ }
+
+ ++entry;
+ ++count;
+ }
+}
+
+static uint32_t fat_n_dir_entries(const struct drive *d, const char *path) {
+ d->ready(d);
+
+ if (!*path)
+ return n_root_entries(d);
+
+ if (!try_load_from_path(d, path)) {
+ d->done(d);
+ return 0;
+ }
+
+ uint16_t cluster = cur_dir->first_cluster;
+ load_cluster(cluster, fat_driver_buffer);
+ struct directory_entry *entry = (struct directory_entry *)fat_driver_buffer;
+
+ uint32_t count = 0;
+
+ while (true) {
+ if (entry == (struct directory_entry *)(fat_driver_buffer + 512)) {
+ entry = (struct directory_entry *)fat_driver_buffer;
+ load_cluster(cluster = next_cluster(cluster), fat_driver_buffer);
+ }
+
+ if (!*(uint8_t *)entry) {
+ d->done(d);
+ return count;
+ }
+
+ if (check_fat_names(entry->name, this_dir) || check_fat_names(entry->name, parent_dir)) {
+ ++entry;
+ continue;
+ }
+
+ ++entry;
+ ++count;
+ }
+}
+
void init_fat() {
next_fi = allocate_kernel_pages(1);
next_id = 0;
@@ -388,6 +454,7 @@ bool try_fat_init_drive(struct drive *d) {
d->load_sector = &fat_load_sector;
d->get_file_length = &fat_get_file_length;
d->enumerate_dir = &fat_enumerate_dir;
+ d->n_dir_entries = &fat_n_dir_entries;
d->get_free_sectors = &fat_get_free_sectors;
d->fs_id = next_id;
diff --git a/src/kernel/idt.c b/src/kernel/idt.c
index 90d8dc3..1b8e548 100644
--- a/src/kernel/idt.c
+++ b/src/kernel/idt.c
@@ -8,6 +8,7 @@
#include "paging.h"
#include "pmap.h"
#include "kbd.h"
+#include "vga.h"
enum {
IDT_PRESENT = 0x80,
@@ -100,6 +101,10 @@ static uint32_t sc_enumerate_dir(uint32_t drive_number, const char *path, struct
return drives[drive_number].enumerate_dir(drives + drive_number, path, buffer, max_entries);
}
+static uint32_t sc_count_of_dir(uint32_t drive_number, const char *path) {
+ return drives[drive_number].n_dir_entries(drives + drive_number, path);
+}
+
void const *syscall_table[] = {
&sc_open_file,
&sc_close_file,
@@ -111,7 +116,11 @@ void const *syscall_table[] = {
&sc_allocate_ram,
&sc_memory_info,
&sc_wait_for_task,
- &sc_enumerate_dir
+ &sc_enumerate_dir,
+ &vga_print_at,
+ &sc_count_of_dir,
+ &vga_blank,
+ &vga_set_color
};
//these aren't really void ()'s, but gcc complains if we take an address of a void, so we give it a type
diff --git a/src/kernel/isrs.asm b/src/kernel/isrs.asm
index 6ad469d..e7573ae 100644
--- a/src/kernel/isrs.asm
+++ b/src/kernel/isrs.asm
@@ -23,7 +23,7 @@ extern on_kbd_isr
extern make_sure_tasks
extern exception_halt
-n_syscalls equ 0xb
+n_syscalls equ 0xf
;section .bss
;_debug_is_start_task resb 1
diff --git a/src/kernel/kbd.c b/src/kernel/kbd.c
index f3eb323..c251db7 100644
--- a/src/kernel/kbd.c
+++ b/src/kernel/kbd.c
@@ -226,19 +226,34 @@ static const uint8_t codes_e0[] = {
0, 0, 0, 0, 0, 0, 0, 0
};
+#include "log.h"
+
+uint8_t get_code_byte() {
+ for (uint32_t spin = 0; spin < 10000000; ++spin)
+ ;
+ return inb(PS2_DATA);
+}
+
void on_kbd_isr() {
while (inb(PS2_CMD) & PS2S_CODE_READY) {
- uint8_t code = inb(PS2_DATA);
+ //char nbuf[11];
+ uint8_t code = get_code_byte();
+ //logsz("code: 0x");
+ //u8_hex(code, nbuf);
+ //logsz(nbuf);
if (code == 0xe1) {
- code = inb(PS2_DATA);
+ code = get_code_byte();
+ //logsz(" 0x");
+ //u8_hex(code, nbuf);
+ //logsz(nbuf);
if (code == 0x1d) {
- if (inb(PS2_DATA) != 0x45)
+ if (get_code_byte() != 0x45)
code = 0;
else
code = CODE_PAUSE;
}
else if (code == 0x9d) {
- if (inb(PS2_DATA) != 0xc5)
+ if (get_code_byte() != 0xc5)
code = 0;
else
code = 0xff;
@@ -247,17 +262,20 @@ void on_kbd_isr() {
code = 0;
}
else if (code == 0xe0) {
- code = inb(PS2_DATA);
+ code = get_code_byte();
+ //logsz(" 0x");
+ //u8_hex(code, nbuf);
+ //logsz(nbuf);
if (code == 0x2a) {
- if ((inb(PS2_DATA) != 0xe0) ||
- (inb(PS2_DATA) != 0x37))
+ if ((get_code_byte() != 0xe0) ||
+ (get_code_byte() != 0x37))
code = 0;
else
code = CODE_PRSCR;
}
else if (code == 0xb7) {
- if ((inb(PS2_DATA) != 0xe0) ||
- (inb(PS2_DATA) != 0xaa))
+ if ((get_code_byte() != 0xe0) ||
+ (get_code_byte() != 0xaa))
code = 0;
else
code = 0xff;
@@ -268,6 +286,8 @@ void on_kbd_isr() {
else
code = codes[code];
+ //logch('\n');
+
if (!code)
PANIC("Unknown scancode.");
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 06b83d1..b34f816 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -15,9 +15,6 @@
#include "vga.h"
#include "kbd.h"
-void reset_tree();
-void tree(struct drive *d);
-
void _start_user_mode() __attribute__ ((noreturn));
__attribute__ ((noreturn))
@@ -35,6 +32,7 @@ void main() {
pci_init();
+/*
u16_dec(n_pci_devices, nbuf);
logsz(nbuf);
logsz(" PCI device(s) found:\n");
@@ -63,6 +61,7 @@ void main() {
}
logch('\n');
+*/
init_fat();
//other fs drivers
@@ -72,6 +71,7 @@ void main() {
init_ide();
//other drive drivers
+/*
u8_dec(n_drives, nbuf);
logsz(nbuf);
logsz(" drive(s) found:\n");
@@ -108,20 +108,7 @@ void main() {
}
logch('\n');
-
- for (uint8_t n = 0; n < n_drives; ++n) {
- if (drives[n].get_free_sectors(drives + n) == -1)
- continue;
-
- u32_dec(n, nbuf);
- logsz("sd");
- logsz(nbuf);
- logsz(" tree:\n");
-
- reset_tree();
- tree(drives + n);
- logch('\n');
- }
+*/
if (BOOT_INFO->support_flags & BIS_PAE)
logsz("Processor supports PAE (but Portland OS does not yet).\n");
diff --git a/src/kernel/main2.c b/src/kernel/main2.c
deleted file mode 100644
index 27ef8de..0000000
--- a/src/kernel/main2.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include <stdint.h>
-#include "drive.h"
-#include "util.h"
-#include "log.h"
-
-static char nbuf2[11];
-
-static char path_builder[200];
-static uint8_t path_builder_len;
-
-static char indent_builder[20];
-static uint8_t indent_builder_len;
-
-void reset_tree() {
- path_builder[0] = '\0';
- path_builder_len = 0;
-
- indent_builder[0] = ' ';
- indent_builder[1] = ' ';
- indent_builder[2] = '\0';
- indent_builder_len = 2;
-}
-
-void tree(struct drive *d) {
- struct directory_content_info infos[100];
- uint8_t n_infos = d->enumerate_dir(d, path_builder, infos, 100);
-
- if (!n_infos) {
- logsz(indent_builder);
- logsz("(empty)\n");
- return;
- }
-
- for (uint8_t i = 0; i < n_infos; ++i) {
- logsz(indent_builder);
- logsz(infos[i].name);
-
- if (infos[i].is_dir) {
- logsz(":\n");
-
- indent_builder[indent_builder_len] = ' ';
- indent_builder[indent_builder_len + 1] = ' ';
- indent_builder[indent_builder_len + 2] = '\0';
- indent_builder_len += 2;
-
- uint8_t name_length = 0;
- while (infos[i].name[name_length])
- ++name_length;
-
- memcpy(path_builder + path_builder_len, infos[i].name, name_length + 1);
- path_builder_len += name_length;
-
- tree(d);
-
- path_builder_len -= name_length;
- path_builder[path_builder_len] = '\0';
-
- indent_builder_len -= 2;
- indent_builder[indent_builder_len] = '\0';
- }
-
- else {
- u32_dec(infos[i].size, nbuf2);
- logsz(" (");
- logsz(nbuf2);
- logsz(" bytes)\n");
- }
- }
-} \ No newline at end of file
diff --git a/src/kernel/vga.c b/src/kernel/vga.c
index daa92fe..42da312 100644
--- a/src/kernel/vga.c
+++ b/src/kernel/vga.c
@@ -2,8 +2,9 @@
#include <stdint.h>
#define VGA_COLUMNS 80
+#define VGA_ROWS 25
#define VGA_START (uint16_t *)0x000b8000
-#define VGA_END (VGA_START + VGA_COLUMNS * 25)
+#define VGA_END (VGA_START + VGA_COLUMNS * VGA_ROWS)
static uint16_t *cursor = VGA_START;
static uint16_t mask;
@@ -25,7 +26,7 @@ void vga_blank() {
uint32_t *p = (uint32_t *)VGA_START;
while (p < (uint32_t *)VGA_END)
*p++ = f;
- cursor = VGA_START;
+ cursor = VGA_END - VGA_COLUMNS;
}
void vga_printch(char ch) {
@@ -37,4 +38,10 @@ void vga_printch(char ch) {
*cursor++ = mask | (uint8_t)ch;
if (cursor == VGA_END)
vga_scroll();
+}
+
+void vga_print_at(uint16_t pos, const char *sz) {
+ cursor = VGA_START + (pos >> 8) * VGA_COLUMNS + (pos & 0xff);
+ while (*sz)
+ vga_printch(*sz++);
} \ No newline at end of file
diff --git a/src/kernel/vga.h b/src/kernel/vga.h
index bfc9fe6..fa97e11 100644
--- a/src/kernel/vga.h
+++ b/src/kernel/vga.h
@@ -3,6 +3,7 @@
#include <stdint.h>
+void vga_print_at(uint16_t pos, const char *sz);
void vga_set_color(uint8_t color);
void vga_blank();
void vga_printch(char ch);