From bd527d35727e2effb7580e24cfaa28a2c8090475 Mon Sep 17 00:00:00 2001 From: garenchan <1412950785@qq.com> Date: Tue, 27 Nov 2018 19:43:04 +0800 Subject: [PATCH 1/4] Use an array instead of an uninitialized wild pointer. Using wild pointers is a dangerous practice, although you may not encounter errors now. --- 20-interrupts-timer/drivers/keyboard.c | 74 +++++++++++++------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/20-interrupts-timer/drivers/keyboard.c b/20-interrupts-timer/drivers/keyboard.c index 8d1dec8..c47fd2b 100644 --- a/20-interrupts-timer/drivers/keyboard.c +++ b/20-interrupts-timer/drivers/keyboard.c @@ -6,7 +6,7 @@ static void keyboard_callback(registers_t regs) { /* The PIC leaves us the scancode in port 0x60 */ u8 scancode = port_byte_in(0x60); - char *sc_ascii; + char sc_ascii[4]; int_to_ascii(scancode, sc_ascii); kprint("Keyboard scancode: "); kprint(sc_ascii); @@ -99,24 +99,24 @@ void print_letter(u8 scancode) { case 0x19: kprint("P"); break; - case 0x1A: - kprint("["); - break; - case 0x1B: - kprint("]"); - break; - case 0x1C: - kprint("ENTER"); - break; - case 0x1D: - kprint("LCtrl"); - break; - case 0x1E: - kprint("A"); - break; - case 0x1F: - kprint("S"); - break; + case 0x1A: + kprint("["); + break; + case 0x1B: + kprint("]"); + break; + case 0x1C: + kprint("ENTER"); + break; + case 0x1D: + kprint("LCtrl"); + break; + case 0x1E: + kprint("A"); + break; + case 0x1F: + kprint("S"); + break; case 0x20: kprint("D"); break; @@ -147,24 +147,24 @@ void print_letter(u8 scancode) { case 0x29: kprint("`"); break; - case 0x2A: - kprint("LShift"); - break; - case 0x2B: - kprint("\\"); - break; - case 0x2C: - kprint("Z"); - break; - case 0x2D: - kprint("X"); - break; - case 0x2E: - kprint("C"); - break; - case 0x2F: - kprint("V"); - break; + case 0x2A: + kprint("LShift"); + break; + case 0x2B: + kprint("\\"); + break; + case 0x2C: + kprint("Z"); + break; + case 0x2D: + kprint("X"); + break; + case 0x2E: + kprint("C"); + break; + case 0x2F: + kprint("V"); + break; case 0x30: kprint("B"); break; From a95836d67d75e9d64b0b5cbf353d010dad501e63 Mon Sep 17 00:00:00 2001 From: garenchan <1412950785@qq.com> Date: Tue, 27 Nov 2018 20:25:57 +0800 Subject: [PATCH 2/4] irq_install() is placed on isr.c --- 21-shell/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/21-shell/README.md b/21-shell/README.md index e1a0611..d4dc91a 100644 --- a/21-shell/README.md +++ b/21-shell/README.md @@ -18,7 +18,7 @@ Right now we have a `utils.c` which we will split into `mem.c` and `string.c`, w Second, we will create a new function `irq_install()` so that the kernel only needs to perform one call to initialize all the IRQs. That function -is akin to `isr_install()` and placed on the same `irq.c`. +is akin to `isr_install()` and placed on the same `isr.c`. While we're here, we will disable the `kprint()` on `timer_callback()` to avoid filling the screen with junk, now that we know that it works properly. From 5c610205419add4422f9d4a97097248a42a4c51d Mon Sep 17 00:00:00 2001 From: garenchan <1412950785@qq.com> Date: Wed, 28 Nov 2018 18:33:13 +0800 Subject: [PATCH 3/4] 'strings' should be 'string'. --- 21-shell/libc/string.h | 4 ++-- 22-malloc/README.md | 2 +- 22-malloc/libc/string.h | 4 ++-- 23-fixes/libc/string.h | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/21-shell/libc/string.h b/21-shell/libc/string.h index 75f2d1b..0e7942d 100644 --- a/21-shell/libc/string.h +++ b/21-shell/libc/string.h @@ -1,5 +1,5 @@ -#ifndef STRINGS_H -#define STRINGS_H +#ifndef STRING_H +#define STRING_H void int_to_ascii(int n, char str[]); void reverse(char s[]); diff --git a/22-malloc/README.md b/22-malloc/README.md index da2ed0f..99dc482 100644 --- a/22-malloc/README.md +++ b/22-malloc/README.md @@ -15,7 +15,7 @@ our first page starts at 0x10000 (as hardcoded on `mem.c`) and subsequent `kmalloc()`'s produce a new address which is aligned 4096 bytes or 0x1000 from the previous one. -Note that we added a new `strings.c:hex_to_ascii()` for +Note that we added a new `string.c:hex_to_ascii()` for nicer printing of hex numbers. Another cosmetic modification is to rename `types.c` to diff --git a/22-malloc/libc/string.h b/22-malloc/libc/string.h index 39f3969..b958faa 100644 --- a/22-malloc/libc/string.h +++ b/22-malloc/libc/string.h @@ -1,5 +1,5 @@ -#ifndef STRINGS_H -#define STRINGS_H +#ifndef STRING_H +#define STRING_H void int_to_ascii(int n, char str[]); void hex_to_ascii(int n, char str[]); diff --git a/23-fixes/libc/string.h b/23-fixes/libc/string.h index 39f3969..b958faa 100644 --- a/23-fixes/libc/string.h +++ b/23-fixes/libc/string.h @@ -1,5 +1,5 @@ -#ifndef STRINGS_H -#define STRINGS_H +#ifndef STRING_H +#define STRING_H void int_to_ascii(int n, char str[]); void hex_to_ascii(int n, char str[]); From 0bbbdf7cf87e791eae6600990838072edbc45205 Mon Sep 17 00:00:00 2001 From: garenchan <1412950785@qq.com> Date: Wed, 28 Nov 2018 20:34:54 +0800 Subject: [PATCH 4/4] registers -> registers_t --- 23-fixes/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/23-fixes/README.md b/23-fixes/README.md index 4289413..7f9f735 100644 --- a/23-fixes/README.md +++ b/23-fixes/README.md @@ -79,7 +79,7 @@ We add `cld` just before `call isr_handler` on `cpu/interrupt.asm` as suggested by the osdev wiki. There is a final, important issue with `cpu/interrupt.asm`. The common stubs create an instance -of `struct registers` on the stack and then call the C handler. But that breaks the ABI, since +of `struct registers_t` on the stack and then call the C handler. But that breaks the ABI, since the stack belongs to the called function and they may change them as they please. It is needed to pass the struct as a pointer.