AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
reboot.c
Go to the documentation of this file.
1
8
9#include <core/system.h>
10#include <core/arch.h>
11#include <sys/proc.h>
12#include <sys/signal.h>
13#include <sys/reboot.h>
14#include <dev/dev.h>
15
16#include <aquila/errno.h>
17
18static int cad_restarts = 1;
19
29int kernel_reboot(unsigned cmd)
30{
31 /* nothing may be left in the disks' write caches */
32 if (cmd == RB_AUTOBOOT || cmd == RB_HALT_SYSTEM || cmd == RB_POWER_OFF)
33 kdev_sync();
34
35 switch (cmd) {
36 case RB_AUTOBOOT:
37 printk("kernel: restarting system\n");
39 printk("kernel: restart failed, halting\n");
40 arch_halt();
41 case RB_HALT_SYSTEM:
42 printk("kernel: system halted\n");
43 arch_halt();
44 case RB_POWER_OFF:
45 printk("kernel: power down\n");
47 case RB_ENABLE_CAD:
48 cad_restarts = 1;
49 return 0;
50 case RB_DISABLE_CAD:
51 cad_restarts = 0;
52 return 0;
53 }
54
55 return -EINVAL;
56}
57
63{
64 /* restart right away, as a reset would: writing out the caches would
65 * wait for the disk, which an interrupt can't do */
66 if (cad_restarts) {
67 printk("kernel: restarting system\n");
69 return;
70 }
71
72 struct proc *init = proc_pid_find(1);
73
74 if (init)
75 signal_proc_send(init, SIGINT);
76}
int kdev_sync(void)
Writes what the block cache holds that was written, and what the block devices hold in their write ca...
Definition kdev.c:587
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
struct proc * proc_pid_find(pid_t pid)
Finds a process by its ID.
Definition proc.c:179
void arch_reboot(void)
Restarts the machine.
Definition psci.c:25
void arch_halt(void)
Stops the CPU for good, with interrupts off.
Definition psci.c:38
void arch_poweroff(void)
Powers the machine off, or halts it if it can't be powered off.
Definition psci.c:31
void kernel_ctrlaltdel(void)
Handles Ctrl+Alt+Del from the keyboard, possibly in an interrupt: it restarts the machine,...
Definition reboot.c:62
int kernel_reboot(unsigned cmd)
Carries out a reboot() command.
Definition reboot.c:29
int signal_proc_send(struct proc *proc, int signal)
Sends a signal to a process.
Definition signal.c:310
A process.
Definition proc.h:75
static int cad_restarts
Definition reboot.c:18