Skip to content

Commit

Permalink
添加panic_text和多任务管理的准备工作
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcao3 committed Sep 6, 2016
1 parent 8323976 commit 0063530
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions kernel/arch/i686/Basic/safe.c
Expand Up @@ -58,6 +58,21 @@ void panic(pt_regs* regs) {
__asm__ volatile ("jmp fatal_halt");
}

void panic_text(char* str) {
kputs("============= KERNEL PANIC =============");
#ifdef DEBUG
kprintf("[ Kernel debug enabled\r\n");
#endif
kprintf("[ Boot Ticks: %d\r\n[ Mills From boot: %d\r\n", tick, millis_from_boot);
kputs(str);
kputs("=============== INFO END ===============");
kputs("System Halted due to fatal error");

// 在遇到这种问题的时候我们需要使用jmp
// 这个情况下栈可能是乱的,调用可能不工作
__asm__ volatile ("jmp fatal_halt");
}

static void cs_assert(pt_regs* regs) {
if (regs->cs == 0x08) { // This is the kernel CS
// TODO: 理论上这里要设定一个应急栈
Expand Down
1 change: 1 addition & 0 deletions kernel/arch/i686/Basic/safe.h
Expand Up @@ -30,6 +30,7 @@

extern void fatal_halt();
extern void panic(pt_regs* regs);
extern void panic_text(char* str);

void Init_Safe();

Expand Down
20 changes: 20 additions & 0 deletions kernel/arch/i686/Basic/task.c
Expand Up @@ -35,6 +35,26 @@ void taska() {
volatile char sta[4096];
volatile void* sta_st;

task_node* current;
task_node tska, tskb;

void create_process() {
// Allocation is kind of crappy now..
uint32_t phy_p = Memory_SearchFree();
if (!Memory_AllocPhy(phy_p)) panic_text("Can not assign memory to create process!");



}

void insert_node(void* stack_top, task_node* dst) {
dst->next = current->next;
dst->prev = current;
current->next = dst;

dst->meta = false;
dst->ptr = (task_t*)stack_top;
}

void create_task(task_t* model, void* stack_top, void* eip) {
kprintf("New task, esp=0x%x\r\n", stack_top);
Expand Down
10 changes: 10 additions & 0 deletions kernel/arch/i686/Basic/task.h
Expand Up @@ -22,6 +22,7 @@

#include "config.h"
#include "Basic/types.h"
#include "Basic/memory.h"
#include "debug.h"

typedef volatile struct _task_t {
Expand All @@ -41,6 +42,15 @@ typedef volatile struct _task_t {
uint32_t ss;
} task_t;

typedef volatile struct _task_node {
struct _task_node* prev;
task_t* ptr;
bool meta; // meta = true表示当前node是一个空进程(标志用进程)
struct _task_node* next;
} task_node;

extern task_node* current;

extern void taskb();
extern volatile char stb[4096];
extern volatile void* stb_st;
Expand Down

0 comments on commit 0063530

Please sign in to comment.