Selaa lähdekoodia

2.164u-int: using print in interrupt handlers

rain 5 vuotta sitten
vanhempi
sitoutus
9e939a63ae
5 muutettua tiedostoa jossa 30 lisäystä ja 16 poistoa
  1. 1 0
      LINES
  2. 3 0
      README.md
  3. 20 8
      init/head.S
  4. 1 1
      init/main.c
  5. 5 7
      kernel/int.c

+ 1 - 0
LINES

@@ -12,4 +12,5 @@
 2021-6-20 2.040: 2040 lines, 25 files, rain
 2021-7-04 2.035: 2035 lines, 25 files, rain
 2021-7-04 2.154: 2154 lines, 25 files, rain
+2021-7-04 2.164: 2164 lines, 25 files, rain
 

+ 3 - 0
README.md

@@ -62,3 +62,6 @@ source software, you can get its source code from <https://gitee.com/pengruiyang
 2.154u-boot:  
 &nbsp;&nbsp;&nbsp;&nbsp;now this boot routine can run on my computer successfully (16GB u-disk). but it can't run on old-PCs which uses floppy. 
 
+2.164u-int:  
+&nbsp;&nbsp;&nbsp;&nbsp;now interrupt handlers and head.S can use print now. 
+

+ 20 - 8
init/head.S

@@ -23,8 +23,24 @@
 
 
 
-/* it is BRIGHT+RED (well...) */
-#define RED $0x0c
+/* #NO! it is BRIGHT+RED (well...) */
+/* we are in VGA mode now */
+
+#define RED $0x04
+
+/* 
+ * arguments in long-mode: 
+ * %rdi, %rsi, %rdx, %rcx, and...
+ * stack...
+ */
+
+#define WARNING(msg)	\
+	movq RED, %rdi;	\
+	xorq %rsi, %rsi;\
+	leaq msg, %rdx;	\
+	call print;
+			
+	
 
 .text
 
@@ -109,18 +125,14 @@ init_die:
 
 
 init_panic:
-	movq RED, %rdi
-	leaq panic_msg(%rip), %rsi
-//	callq printf
+	WARNING(panic_msg(%rip))
 
 	jmp init_die
 
 
 default_int_handler:
 	/* put a message on screen, and die */
-	movq RED, %rdi
-	leaq int_msg(%rip), %rsi
-//	call printf
+	WARNING(int_msg(%rip))
 
 dih_die:
 	hlt

+ 1 - 1
init/main.c

@@ -45,7 +45,7 @@
 int init(void) {
 	init_int();
 
-	print(0x0f, 0x00, "XNIX kernel is starting...\ninitial done. \n");
+	print(0x0f, 0x00, "XNIX kernel is starting...\n");
 
 	return 0;
 }

+ 5 - 7
kernel/int.c

@@ -28,9 +28,12 @@
 #include <kernel/errno.h>
 #include <kernel/types.h>
 
+#include <kernel/graphic.h>
+
 #include <arch/x86/int.h>
 #include <arch/io.h>
 #include <arch/sys.h>
+
 #include <modules/tty.h>
 
 
@@ -85,18 +88,13 @@ void set_gate(struct idt_entry *entry, char attr, char ist, void *addr) {
 
 
 void syscall(void) {
-//	printf(COLOR_BRIGHT + RED, "int #0x80: system call. \n");
+	print(0x04, 0x00, "int #0x80: system call. \n");
 	for (;;);
 }
 
 
 void die(char *s, __uint64_t *rsp, char nr) {
-//	printf(COLOR_BRIGHT + RED, "int #%b: %s. \n");
-
-	int i;
-
-	for (i = 0; i < 50; i++) 
-	//	printf(COLOR_BRIGHT + RED, "stack: %q\n", rsp[i]);
+	print(0x04, 0x00, "int #%b: %s. \n");
 
 	for (;;);
 }