mirror of https://github.com/tailix/kernel.git
Rewrite poweroff
This commit is contained in:
parent
5b72e959c5
commit
65a1acb58d
|
@ -25,6 +25,7 @@ CPPFLAGS = \
|
|||
# Architecture-dependent
|
||||
OBJS = start.s.o
|
||||
OBJS += main.c.o
|
||||
OBJS += poweroff.c.o
|
||||
OBJS += panic.c.o
|
||||
OBJS += paging.c.o
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "main.h"
|
||||
#include "../panic.h"
|
||||
#include "../poweroff.h"
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
|
||||
|
@ -40,11 +41,13 @@ static const char *const messages[] = {
|
|||
|
||||
void exception_handler(struct IsrRegisters regs)
|
||||
{
|
||||
if (regs.int_no > INT_EXCEPTION_LAST) {
|
||||
return;
|
||||
}
|
||||
if (regs.int_no > INT_EXCEPTION_LAST) return;
|
||||
if (regs.int_no == POWEROFF_INT && poweroff_doing) return;
|
||||
|
||||
kernaux_drivers_console_printf("[FAIL] exception: Unhandled protected-mode exception: %s\n", messages[regs.int_no]);
|
||||
kernaux_drivers_console_printf(
|
||||
"[FAIL] exception: Unhandled protected-mode exception: %s\n",
|
||||
messages[regs.int_no]
|
||||
);
|
||||
|
||||
panic("Can not continue.");
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
#include "panic.h"
|
||||
#include "poweroff.h"
|
||||
|
||||
#include <kernaux/asm/i386.h>
|
||||
#include <kernaux/drivers/console.h>
|
||||
|
||||
static void poweroff()
|
||||
{
|
||||
kernaux_asm_x86_outportw(0x604, 0x2000);
|
||||
}
|
||||
#include <kernaux/drivers/qemu.h>
|
||||
|
||||
void panic(const char *const s)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "poweroff.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <kernaux/drivers/qemu.h>
|
||||
|
||||
bool poweroff_doing = false;
|
||||
|
||||
void poweroff()
|
||||
{
|
||||
poweroff_doing = true;
|
||||
kernaux_drivers_qemu_poweroff();
|
||||
for (;;) asm volatile(POWEROFF_ASM);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef KERNEL_INCLUDED_POWEROFF
|
||||
#define KERNEL_INCLUDED_POWEROFF 1
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define POWEROFF_INT 3
|
||||
#define POWEROFF_ASM "int $3"
|
||||
|
||||
extern bool poweroff_doing;
|
||||
|
||||
void poweroff();
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue