view src/impl/kernel_error.cbc @ 313:561eedeb9a99

ommit static variable at console
author anatofuz
date Thu, 06 Feb 2020 16:56:50 +0900
parents cd9092628a63
children
line wrap: on
line source

#include "param.h"
#include "proc.h"
#interface "ErrorGear.h"

// ----
// typedef struct KernelError <Type, Isa> impl ErrorGear {
//   __code infinity_loop(Type* error_gear,__code next(...));
// } KernelError;
// ----

ErrorGear* createKernelError(struct Context* cbc_context) {
    struct ErrorGear* error_gear  = new ErrorGear();
    struct KernelError* kernel_error = new KernelError();
    error_gear->error_gear = (union Data*)kernel_error;
    kernel_error->error_gear = NULL;
    kernel_error->infinity_loop = C_infinity_loopKernelError;
    error_gear->error = C_errorKernelError;
    error_gear->panic = C_panicKernelError;
    return error_gear;
}

__code infinity_loopKernelError(struct KernelError* error_gear,__code next(...)) {
    goto next(...);
}

__code errorKernelError(struct KernelError* error_gear, int err_code, __code next(...)) {

    goto next(...);
}

__code panicKernelError(struct KernelError* error_gear, char* msg) {
    extern struct cpu* cpu;
    extern struct { struct spinlock lock; int locking; } cons;
    extern int panicked;

    cli();
    cons.locking = 0;

    cprintf("cpu%d: panic: ", cpu->id);

    show_callstk(msg);
    panicked = 1; // freeze other CPU

    goto infinity_loopKernelError(error_gear, error_gear->inifinity_loop);
}