Rewrite poweroff

This commit is contained in:
Alex Kotov 2022-11-28 18:27:25 +04:00
parent 5b72e959c5
commit 65a1acb58d
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 37 additions and 9 deletions

View File

@ -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

View File

@ -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.");
}

View File

@ -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)
{

14
src/poweroff.c Normal file
View File

@ -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);
}

13
src/poweroff.h Normal file
View File

@ -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