Добавлены блокировки в отладчик

This commit is contained in:
Aren Elchinyan 2024-01-21 22:00:56 +03:00
parent a7703f54ab
commit 50ad112d7f
7 changed files with 31 additions and 13 deletions

View File

@ -10,6 +10,7 @@
#ifndef ARCH_H
#define ARCH_H
#include <lock.h>
#include <stdint.h>
#define STACK_SIZE 8192 // 8 килобайт на стек
@ -53,6 +54,8 @@ struct frame {
typedef void (*int_entry_t)(struct frame *state);
extern lock_t task_lock;
void arch_init( );
void task_init( );
void task_switch(struct frame *state);

View File

@ -14,16 +14,21 @@
typedef struct {
int lock;
const char* file;
const char *func;
int line;
} lock_t;
#define LOCK(lock) \
lock.line = __LINE__; \
lock_acquire(lock);
#define LOCK_INIT \
(lock_t) { \
0, __FILE__ \
0, __FILE__, __LINE__ \
}
int lock_swap(lock_t* lock);
void lock_acquire(lock_t* lock);
void lock_release(lock_t* lock);
int lock_swap(lock_t lock);
void lock_acquire(lock_t lock);
void lock_release(lock_t lock);
#endif // lock.h

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 970
#define VERSION_BUILD 979

View File

@ -17,6 +17,7 @@ static task_t *kernel_task = NULL;
task_t *current_task = NULL;
uint32_t *test_buf = NULL;
extern uint64_t full_init;
lock_t task_lock;
void task_switch_asm(task_t *, task_t *);

View File

@ -13,19 +13,21 @@
#include <tool.h>
// Если не заблокировано - блокируем
int lock_swap(lock_t *lock) {
return __sync_bool_compare_and_swap(&lock->lock, 0, 1);
int lock_swap(lock_t lock) {
if (lock.lock) { return 0; }
lock.lock = 1;
return 1;
}
// Запрос блокировки ресурса
void lock_acquire(lock_t *lock) {
void lock_acquire(lock_t lock) {
uint64_t count = 0;
for (;;) {
if (lock_swap(lock)) { break; }
count++;
if (count > 1000000) {
LOG("%s блокировка зависла", lock->file);
LOG("%s:%u блокировка зависла", lock.func, lock.line);
assert(0);
}
@ -34,6 +36,6 @@ void lock_acquire(lock_t *lock) {
}
// Запрос разблокировки ресурса
void lock_release(lock_t *lock) {
__sync_bool_compare_and_swap(&lock->lock, 1, 0);
void lock_release(lock_t lock) {
lock.lock = 0;
}

View File

@ -20,6 +20,7 @@ static uint64_t fb_pos_x = 4;
static uint64_t fb_pos_y = 0;
static uint64_t buf_pos = 0;
static uint64_t buf_max = 1024;
static lock_t log_lock = LOCK_INIT;
#define FONT_WIDTH 6 + 1
#define FONT_HEIGHT 8 + 1
@ -104,13 +105,16 @@ void log_putchar(char c) {
// Вывод текстового сообщения
void log_printf(char *str, ...) {
LOCK(log_lock);
va_list args;
va_start(args, str);
tool_format(&log_putchar, str, args);
lock_release(log_lock);
va_end(args);
}
void log_init_mem( ) {
LOCK(log_lock);
if (fb_init_status < 1) {
LOG("Нет доступных фреймбуфферов для вывода\n");
return;
@ -124,6 +128,7 @@ void log_init_mem( ) {
buf_max = ((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT);
LOG("Размер буффера: %u символов\n", buf_max);
redraw_screen( );
lock_release(log_lock);
}
void log_init( ) {

View File

@ -80,7 +80,8 @@ static int is_ctrl(uint8_t scancode) {
}
}
static void handler( ) {
static void handler(struct frame *state) {
(void)state;
while (!(inb(0x64) & 1)) { asm volatile("pause"); }
uint8_t scancode = inb(0x60);
@ -143,6 +144,7 @@ static void handler( ) {
switch (scancode) {
case 0x01: virt_exit( ); break; // Клавиша "ESCAPE"
case 0x4F: // Клавиша "END"
fb_printf("END?\n");
break;
default: break;
}