#ifndef __KERNEL_PRINTK_INCLUDED__
#define __KERNEL_PRINTK_INCLUDED__
#include
int __printk(const char *file, int line, const char *fmt, ...);
#define printk(fmt, ...) __printk(__FUNCTION__, __LINE__, fmt, ## __VA_ARGS__)
#ifdef JOHNYIN_DBG
#define KPRINTF(fmt, ...) __printk(__FUNCTION__, __LINE__, fmt, ## __VA_ARGS__)
#else
#define KPRINTF(...)
#endif
void* kmalloc(uint32_t nbytes);
void kfree(void *pointer);
void kmemdump();
typedef enum states
{
INVALID=0,
CREATED,
READY,
RUNNING,
WAITING,
BLOCKED,
ZOMBIE,
FINISHED,
} states_t;
typedef enum priority
{
HIGH_PRIO=0,
NORM_PRIO,
LOW_PRIO,
IDLE_PRIO,
} priority_t;
#include
typedef struct thread_t
{
union
{
struct
{
struct list_t link;
uint8_t *stack_top; // top of the stack goes to esp
states_t state;
priority_t prio; /*priority*/
uint32_t id; // threads id
uint32_t pid; // parent id if it has one
int num_child; // number of child threads of this thread
};
uint8_t stack[STACK_SIZE];// a static stack for the thread
};
} thread_t;
thread_t *create_thread(void (* entry)(uint32_t), uint32_t args, priority_t p, int detached);
static inline void dump_regs(struct pt_regs *r)
{
printk("=================CPU State==================\n");
printk("EAX= %x EBX= %x\n", r->eax, r->ebx);
printk("ECX= %x EDX= %x\n", r->ecx, r->edx);
printk("ESP= %x EBP= %x\n", r->esp, r->ebp);
printk("ESI= %x EDI= %x\n", r->esi, r->edi);
printk("EIP= %x CS = %x\n", r->eip, r->cs);
printk("DS = %x ES = %x\n", r->ds, r->es);
printk("FS = %x GS = %x\n", r->fs, r->gs);
printk("Interrupt# = %x\n", r->int_no);
printk("Err.Code = %x\n", r->err_code);
printk("e-Flags = %x\n", r->eflags);
printk("============================================\n");
}
static inline void dump_thread(struct thread_t *t)
{
char *msg[] = { "INVALID", "CREATED", "READY", "RUNNING", "WAITING", "BLOCKED", "ZOMBIE", "FINISHED", };
char *msg1[] = { "HIGH", "NORM", "LOW", "IDLE", };
printk("Thread ID = %d(%s:[%s])\n", t->id, msg[t->state], msg1[t->prio]);
printk("Thread PID = %d\n", t->pid);
dump_regs((struct pt_regs *)t->stack_top);
printk("\n");
}
#endif
阅读(1270) | 评论(0) | 转发(0) |