feat: moved block dev loop to a daemon task. Fixed bug in string.c and

main loop
This commit is contained in:
2021-03-01 21:42:35 +01:00
parent 990b850c43
commit 76792dd6fd
7 changed files with 32 additions and 21 deletions

View File

@@ -42,10 +42,10 @@ void echo(const char *arg);
void help(const char *arg);
cmd_handler cmd_handlers[] = {
{"help", help},
{"echo", echo},
{"print", print},
{"ide", ide},
{"help\0", help},
{"echo\0", echo},
{"print\0", print},
{"ide\0", ide},
{NULL, NULL},
};
@@ -127,8 +127,9 @@ void store_bootloader_info(multiboot_info_t *multiboot_info) {
void noreturn main_loop(void* data) {
while (true) {
char *msg = readline(NULL);
char *args = strchr(msg, ' ') + 1;
args[-1] = 0;
char *args = strchr(msg, ' ');
args[0] = 0;
args = &args[1];
int test_index = 0;
while (true) {
if (cmd_handlers[test_index].cmd == 0) {

View File

@@ -6,6 +6,9 @@
#include <libk/libk.h>
#include <libc/kprintf.h>
#include <mem/malloc.h>
#include <tasks/task.h>
#include <tasks/locking.h>
#include <attributes.h>
#include "blockdev.h"
#define MAX_BLOCK_DEVS 64
@@ -15,6 +18,8 @@ int last_block_dev = 0;
block_device block_devices[MAX_BLOCK_DEVS];
int last_block_driver = 0;
block_dev_driver block_dev_drivers[MAX_BLOCK_DRIVERS];
semaphore_t *block_semaphore;
bool blockdev_task_running = false;
uint8_t block_dev_register_driver(block_dev_driver *driver) {
if (last_block_dev >= MAX_BLOCK_DEVS - 1) {
@@ -30,6 +35,10 @@ uint8_t block_dev_register(block_device *device) {
return BLOCK_DEV_REGISTER_FULL;
}
if (blockdev_task_running) {
semaphore_signal(block_semaphore);
}
memcpy((uint8_t *) &block_devices[last_block_dev++], (const uint8_t *) device, sizeof(block_device));
return BLOCK_DEV_REGISTER_OK;
}
@@ -76,12 +85,19 @@ void block_dev_scan() {
}
}
void block_dev_scan_repeat() {
while (block_dev_num_not_scanned() > 0) {
void noreturn block_dev_task(void *data) {
while (true) {
semaphore_wait(block_semaphore);
block_dev_scan();
}
}
void block_dev_start_task() {
block_semaphore = semaphore_create(1);
blockdev_task_running = true;
task_spawn(block_dev_task, NULL);
}
void block_dev_print_info() {
printf("Block devices:\n");
for (int i = 0; i < last_block_dev; ++i) {

View File

@@ -64,7 +64,7 @@ uint8_t block_dev_register(block_device *device);
void block_dev_free(block_device *device);
void block_dev_scan_repeat();
void block_dev_start_task();
void block_dev_print_info();

View File

@@ -13,9 +13,7 @@
#include <fs/mbr.h>
#include <fs/blockdev.h>
#include <fs/fat.h>
#include <stdbool.h>
#include <cpu/cpuidx.h>
#include <mem/malloc.h>
#include <tasks/task.h>
#include <libk/syscall.h>
#include <command.h>
@@ -29,8 +27,6 @@ void init_mmap(multiboot_info_t *multiboot_info) {
if (multiboot_info->flags & (1 << 6)) {
mmap_init_multiboot((struct multiboot_mmap_entry *) multiboot_info->mmap_addr,
multiboot_info->mmap_length / sizeof(struct multiboot_mmap_entry));
// malloc_init();
// todo fallback on other mechanisms?
} else {
k_panics("mmap invalid!\n");
}
@@ -51,9 +47,6 @@ void init_block_devices() {
// register drivers
mbr_register_block_driver();
fat_register_block_driver();
// scan
block_dev_scan_repeat();
}
void noreturn kmain(multiboot_info_t *multiboot_info) {
@@ -79,6 +72,7 @@ void noreturn kmain(multiboot_info_t *multiboot_info) {
printf("Booted successfully v%d.%d.%d\n", version_major, version_minor, version_patch);
task_init();
block_dev_start_task();
task_spawn(main_loop, NULL);
syscall_start_scheduler();
}

View File

@@ -21,7 +21,7 @@ int strlen(const char *str) {
int strcmp(const char *s1, const char *s2) {
int len1 = strlen(s1);
int len2 = strlen(s1);
int len2 = strlen(s2);
return strncmp(s1, s2, maxi(len1, len2));
}

View File

@@ -30,9 +30,9 @@ struct spinlock {
volatile uint32_t lock;
};
semaphore_t *semaphore_create() {
semaphore_t *semaphore_create(int32_t start) {
semaphore_t *semaphore = malloc(sizeof(semaphore_t));
semaphore->value = 1;
semaphore->value = start;
return semaphore;
}
@@ -54,7 +54,7 @@ void semaphore_wait(semaphore_t *semaphore) {
}
void semaphore_signal(semaphore_t *semaphore) {
if (__sync_add_and_fetch(&semaphore->value, 1) == 1) {
if (__sync_add_and_fetch(&semaphore->value, 1) >= 1) {
return; // last in queue
}
task_lock_acquire();

View File

@@ -13,7 +13,7 @@ typedef struct mutex mutex_t;
typedef struct spinlock spinlock_t;
semaphore_t *semaphore_create();
semaphore_t *semaphore_create(int32_t start);
void semaphore_wait(semaphore_t *semaphore);