Browse Source

shutdown / reboot

master
Mathieu Serandour 1 year ago
parent
commit
3cd1d7e22c
  1. 34
      kernel/acpi/power.c
  2. 12
      kernel/acpi/power.h

34
kernel/acpi/power.c

@ -0,0 +1,34 @@
#include "power.h"
#include "../lib/assert.h"
#include "../drivers/ps2kb.h"
static void (*funcs[MAX_SHUTDOWN_FUNCS])(void);
static int n_funcs = 0;
// register function to execute
// right before the computer
// shuts down / reboots
void atshutdown(void (*fun)(void)) {
assert(n_funcs < MAX_SHUTDOWN_FUNCS);
funcs[n_funcs++] = fun;
}
void shutdown(void) {
// cannot shutdown anything yet.
// need an AML interpreter.
reboot();
}
// reboot the computer using the
// ps/2 controller
void reboot(void) {
for(int i = 0; i < n_funcs; i++)
funcs[i]();
_cli();
ps2_trigger_CPU_reset();
for(;;)
asm("hlt");
}

12
kernel/acpi/power.h

@ -0,0 +1,12 @@
#pragma once
// register function to execute
// right before the computer
// shuts down / reboots
void atshutdown(void (*)(void));
#define MAX_SHUTDOWN_FUNCS 128
void shutdown(void);
void reboot(void);
Loading…
Cancel
Save