mirror of
https://github.com/tailix/libkernaux.git
synced 2025-03-17 17:14:00 -04:00
Shutdown driver (#119)
This commit is contained in:
parent
b8991a2d3d
commit
0df3f9cbba
4 changed files with 63 additions and 0 deletions
|
@ -120,6 +120,7 @@ if WITH_DRIVERS
|
|||
libkernaux_la_SOURCES += \
|
||||
src/drivers/console.c \
|
||||
src/drivers/framebuffer.c \
|
||||
src/drivers/shutdown.c \
|
||||
src/drivers/qemu.c
|
||||
|
||||
# Intel 8253-compatible programmable interval timer
|
||||
|
|
|
@ -96,6 +96,7 @@ if WITH_DRIVERS
|
|||
nobase_include_HEADERS += \
|
||||
kernaux/drivers/console.h \
|
||||
kernaux/drivers/framebuffer.h \
|
||||
kernaux/drivers/shutdown.h \
|
||||
kernaux/drivers/qemu.h
|
||||
|
||||
# Intel 8253-compatible programmable interval timer
|
||||
|
|
24
include/kernaux/drivers/shutdown.h
Normal file
24
include/kernaux/drivers/shutdown.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef KERNAUX_INCLUDED_DRIVERS_SHUTDOWN
|
||||
#define KERNAUX_INCLUDED_DRIVERS_SHUTDOWN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// TODO: make this cross-platform
|
||||
#define KERNAUX_DRIVERS_SHUTDOWN_INT 3
|
||||
#define KERNAUX_DRIVERS_SHUTDOWN_ASM "int $3"
|
||||
|
||||
bool kernaux_drivers_shutdown_is_doing();
|
||||
|
||||
__attribute__((noreturn))
|
||||
void kernaux_drivers_shutdown_halt();
|
||||
void kernaux_drivers_shutdown_poweroff();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
37
src/drivers/shutdown.c
Normal file
37
src/drivers/shutdown.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/drivers/shutdown.h>
|
||||
#include <kernaux/drivers/qemu.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
static bool is_doing = false;
|
||||
|
||||
bool kernaux_drivers_shutdown_is_doing()
|
||||
{
|
||||
return is_doing;
|
||||
}
|
||||
|
||||
void kernaux_drivers_shutdown_halt()
|
||||
{
|
||||
is_doing = true;
|
||||
|
||||
#ifdef ASM_X86
|
||||
for (;;) __asm__ __volatile__(KERNAUX_DRIVERS_SHUTDOWN_ASM);
|
||||
#endif
|
||||
|
||||
volatile int x = 0;
|
||||
for (;;) ++x;
|
||||
}
|
||||
|
||||
void kernaux_drivers_shutdown_poweroff()
|
||||
{
|
||||
is_doing = true;
|
||||
|
||||
kernaux_drivers_qemu_poweroff();
|
||||
|
||||
// If we can't poweroff then we halt
|
||||
kernaux_drivers_shutdown_halt();
|
||||
}
|
Loading…
Add table
Reference in a new issue