mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-09 04:22:04 -04:00
Implement the reboot command
This commit is contained in:
parent
a198047bef
commit
4a57f67583
1
Makefile
1
Makefile
@ -9,6 +9,7 @@ MICRO_KERNEL_UTILS_SRC=$(wildcard micro_kernel/utils/*.asm)
|
||||
micro_kernel.bin: $(MICRO_KERNEL_SRC) $(MICRO_KERNEL_UTILS_SRC)
|
||||
nasm -w+all -f bin -o micro_kernel.bin micro_kernel/micro_kernel.asm
|
||||
nasm -D DEBUG -g -w+all -f elf64 -o micro_kernel.g micro_kernel/micro_kernel.asm
|
||||
bash addresses.bash
|
||||
|
||||
KERNEL_FLAGS=-masm=intel -Ikernel/include/ -O1 -std=c++11 -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding
|
||||
KERNEL_LINK_FLAGS=-std=c++11 -T linker.ld -ffreestanding -O1 -nostdlib
|
||||
|
@ -5,12 +5,12 @@ function generate_address {
|
||||
hex_address="0x$address"
|
||||
hex_offset=`echo "obase=16; $(($hex_address+0x1000))" | bc`
|
||||
|
||||
echo "#define asm_$1 0x$hex_offset" >> src/addresses.hpp
|
||||
echo "#define asm_$1 0x$hex_offset" >> kernel/include/addresses.hpp
|
||||
}
|
||||
|
||||
echo "#ifndef ADDRESSES_H" > src/addresses.hpp
|
||||
echo "#define ADDRESSES_H" >> src/addresses.hpp
|
||||
echo "#ifndef ADDRESSES_H" > kernel/include/addresses.hpp
|
||||
echo "#define ADDRESSES_H" >> kernel/include/addresses.hpp
|
||||
|
||||
generate_address "register_irq_handler"
|
||||
|
||||
echo "#endif" >> src/addresses.hpp
|
||||
echo "#endif" >> kernel/include/addresses.hpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef ADDRESSES_H
|
||||
#define ADDRESSES_H
|
||||
#define asm_register_irq_handler 0x272E
|
||||
#define asm_register_irq_handler 0x276D
|
||||
#endif
|
||||
|
@ -13,6 +13,14 @@ void register_irq_handler(void (*handler)()){
|
||||
);
|
||||
}
|
||||
|
||||
template<uint8_t INT>
|
||||
void interrupt(){
|
||||
asm ("int %0"
|
||||
:
|
||||
: "i" (INT)
|
||||
);
|
||||
}
|
||||
|
||||
uint8_t in_byte(uint16_t _port);
|
||||
void out_byte (uint16_t _port, uint8_t _data);
|
||||
|
||||
|
@ -57,8 +57,21 @@ void keyboard_handler(){
|
||||
}
|
||||
}
|
||||
|
||||
void exec_command(){
|
||||
k_print("The command \"");
|
||||
k_print(current_input);
|
||||
k_print_line("\" does not exist");
|
||||
bool str_equals(const char* a, const char* b){
|
||||
while(*a && *a == *b){
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
void exec_command(){
|
||||
if(str_equals("reboot", current_input)){
|
||||
interrupt<60>();
|
||||
} else {
|
||||
k_print("The command \"");
|
||||
k_print(current_input);
|
||||
k_print_line("\" does not exist");
|
||||
}
|
||||
}
|
||||
|
@ -208,6 +208,11 @@ install_irqs:
|
||||
|
||||
ret
|
||||
|
||||
install_syscalls:
|
||||
IDT_SET_GATE 60, syscall_reboot, LONG_SELECTOR-GDT64, 0x8E
|
||||
|
||||
ret
|
||||
|
||||
; r8 = irq
|
||||
; r9 = handler address
|
||||
register_irq_handler:
|
||||
@ -215,6 +220,25 @@ register_irq_handler:
|
||||
|
||||
ret
|
||||
|
||||
; Syscalls
|
||||
|
||||
; Reboot the computer
|
||||
; No parameters
|
||||
syscall_reboot:
|
||||
cli
|
||||
|
||||
push rax
|
||||
|
||||
mov al, 0x64
|
||||
or al, 0xFE
|
||||
out 0x64, al
|
||||
mov al, 0xFE
|
||||
out 0x64, al
|
||||
|
||||
pop rax
|
||||
|
||||
iretq
|
||||
|
||||
; Data structures
|
||||
|
||||
; each idt entry is form like that:
|
||||
|
@ -99,6 +99,9 @@ lm_start:
|
||||
; Install all IRQs
|
||||
call install_irqs
|
||||
|
||||
; Install custom syscalls
|
||||
call install_syscalls
|
||||
|
||||
sti
|
||||
|
||||
call install_timer
|
||||
|
Loading…
x
Reference in New Issue
Block a user