Explorar o código

Add reboot command

Johannes Zellner hai 8 meses
pai
achega
dd7877d66d
Modificáronse 2 ficheiros con 23 adicións e 2 borrados
  1. 5 2
      Makefile
  2. 18 0
      terminal.c

+ 5 - 2
Makefile

@@ -32,6 +32,9 @@ terminal.o: terminal.c terminal.h io.h rtc.h timer.h disk.h
 hello.o: hello.c io.h
 	$(CC) $(CFLAGS) -o $@ $<
 
+reboot.o: reboot.c
+	$(CC) $(CFLAGS) -o $@ $<
+
 disk.o: disk.c disk.h timer.h
 	$(CC) $(CFLAGS) -o $@ $<
 
@@ -53,7 +56,7 @@ boot.elf: boot.o
 timer.o: timer.S
 	$(AS) $(ASFLAGS) -o $@ $<
 
-kernel.elf: kernel.o timer.o io.o rtc.o terminal.o hello.o disk.o fat.o ls.o cat.o
+kernel.elf: kernel.o timer.o io.o rtc.o terminal.o hello.o reboot.o disk.o fat.o ls.o cat.o
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $^
 
 boot.bin: boot.elf
@@ -92,4 +95,4 @@ run: image.bin root.img
 	qemu-system-x86_64 -M pc -drive file=image.bin,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
 
 clean:
-	rm -f boot.o kernel.o timer.o io.o rtc.o terminal.o hello.o fat.o ls.o cat.o disk.o boot.elf kernel.elf boot.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin final.bin root.img
+	rm -f boot.o kernel.o timer.o io.o rtc.o terminal.o hello.o reboot.o fat.o ls.o cat.o disk.o boot.elf kernel.elf boot.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin final.bin root.img

+ 18 - 0
terminal.c

@@ -6,6 +6,7 @@
 #include "timer.h"
 
 extern void program_hello_main(void);
+extern void program_reboot_main(void);
 extern void program_ls_main(void);
 extern void program_cat_main(const char *filename);
 extern void disk_set_drive(unsigned int drive);
@@ -83,6 +84,21 @@ static int is_cmd_hello(const char *line, unsigned int line_len)
 	return (i == line_len);
 }
 
+static int is_cmd_reboot(const char *line, unsigned int line_len)
+{
+	unsigned int i = 0;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	if (i + 6 > line_len)
+		return 0;
+	if (line[i] != 'r' || line[i+1] != 'e' || line[i+2] != 'b' || line[i+3] != 'o' || line[i+4] != 'o' || line[i+5] != 't')
+		return 0;
+	i += 6;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	return (i == line_len);
+}
+
 static int is_cmd_ls(const char *line, unsigned int line_len)
 {
 	unsigned int i = 0;
@@ -176,6 +192,8 @@ void terminal_run(void)
 						program_hello_main();
 						io_drain_keyboard();
 						draw_header_row();
+					} else if (is_cmd_reboot(line, line_len)) {
+						program_reboot_main();
 					} else if (is_cmd_ls(line, line_len)) {
 						program_ls_main();
 						io_drain_keyboard();