🆕 具有中断管理功能的自旋锁

This commit is contained in:
fslongjin 2022-05-11 20:41:47 +08:00
parent c120a0e992
commit 77d4854db7
3 changed files with 70 additions and 21 deletions

View File

@ -635,9 +635,9 @@ static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, uns
* @param font bitmap
*/
//#if DEBUG
//#if DEBUG
uart_send(COM1, font);
//#endif
//#endif
unsigned char *font_ptr = font_ascii[font];
unsigned int *addr;
@ -664,24 +664,23 @@ static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, uns
}
}
/**
* @brief
*
* @param FRcolor
* @param BKcolor
* @param ...
*/
int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...)
{
/**
* @brief
*
* @param FRcolor
* @param BKcolor
* @param ...
*/
/*
if (get_rflags() & 0x200UL)
spin_lock(&printk_lock); // 不是中断处理程序调用printk加锁
*/
uint64_t rflags = 0; // 加锁后rflags存储到这里
spin_lock_irqsave(&printk_lock, rflags);
va_list args;
va_start(args, fmt);
char buf[4096]; // vsprintf()的缓冲区
int len = vsprintf(buf, fmt, args);
va_end(args);
@ -734,10 +733,7 @@ int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ..
}
}
/*
if (get_rflags() & 0x200UL)
spin_unlock(&printk_lock);
*/
spin_unlock_irqrestore(&printk_lock, rflags);
return i;
}
@ -838,7 +834,7 @@ int scroll(bool direction, int pixels, bool animation)
do_scroll(direction, delta_x);
}
}
return 0;
}

View File

@ -52,7 +52,7 @@ struct screen_info
extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap8*16大小 ps:位于font.h中
char buf[4096]; // vsprintf()的缓冲区
/**
* @brief printk的屏幕信息

View File

@ -76,4 +76,57 @@ long spin_trylock(spinlock_t *lock)
if (!tmp_val)
preempt_enable();
return tmp_val;
}
}
// 保存当前rflags的值到变量x内并关闭中断
#define local_irq_save(x) __asm__ __volatile__("pushfq ; popq %0 ; cli" \
: "=g"(x)::"memory")
// 恢复先前保存的rflags的值x
#define local_irq_restore(x) __asm__ __volatile__("pushq %0 ; popfq" ::"g"(x) \
: "memory")
#define local_irq_disable() cli();
#define local_irq_enable() sti();
/**
* @brief
*
*/
#define spin_lock_irqsave(lock, flags) \
do \
{ \
local_irq_save(flags); \
spin_lock(lock); \
} while (0)
/**
* @brief rflags以及中断状态并解锁自旋锁
*
*/
#define spin_unlock_irqrestore(lock, flags) \
do \
{ \
spin_unlock(lock); \
local_irq_restore(flags); \
} while (0)
/**
* @brief
*
*/
#define spin_lock_irq(lock) \
do \
{ \
local_irq_disable(); \
spin_lock(lock); \
} while (0)
/**
* @brief
*
*/
#define spin_unlock_irq(lock) \
do \
{ \
spin_unlock(lock); \
local_irq_enable(); \
} while (0)