From 8ad193623749855af4e59896d8461e64e9e251fa Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 23 Mar 2015 16:08:34 +0100 Subject: [PATCH] Fixed warnings --- 20-interrupts-timer/Makefile | 2 +- 21-shell/Makefile | 48 +++++++++++++++++++++++++++++++++++- 21-shell/README.md | 6 +++++ 21-shell/cpu/isr.c | 2 ++ 21-shell/cpu/isr.h | 1 + 21-shell/cpu/timer.c | 3 ++- 21-shell/drivers/keyboard.c | 4 ++- 21-shell/drivers/keyboard.h | 2 -- 21-shell/drivers/screen.c | 15 +++++------ 21-shell/drivers/screen.h | 2 ++ 21-shell/libc/mem.c | 2 +- 21-shell/libc/mem.h | 2 +- 21-shell/libc/string.h | 1 + 13 files changed, 75 insertions(+), 15 deletions(-) mode change 120000 => 100644 21-shell/Makefile diff --git a/20-interrupts-timer/Makefile b/20-interrupts-timer/Makefile index 2474d55..4d6da94 100644 --- a/20-interrupts-timer/Makefile +++ b/20-interrupts-timer/Makefile @@ -7,7 +7,7 @@ OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o} CC = /usr/local/i386elfgcc/bin/i386-elf-gcc GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb # -g: Use debugging symbols in gcc -CFLAGS = -g +CFLAGS = -g # First rule is run by default os-image.bin: boot/bootsect.bin kernel.bin diff --git a/21-shell/Makefile b/21-shell/Makefile deleted file mode 120000 index 0d639f8..0000000 --- a/21-shell/Makefile +++ /dev/null @@ -1 +0,0 @@ -../20-interrupts-timer/Makefile \ No newline at end of file diff --git a/21-shell/Makefile b/21-shell/Makefile new file mode 100644 index 0000000..f0e3700 --- /dev/null +++ b/21-shell/Makefile @@ -0,0 +1,47 @@ +C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c libc/*.c) +HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h libc/*.h) +# Nice syntax for file extension replacement +OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o} + +# Change this if your cross-compiler is somewhere else +CC = /usr/local/i386elfgcc/bin/i386-elf-gcc +GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb +# -g: Use debugging symbols in gcc +CFLAGS = -g -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs \ + -Wall -Wextra -Werror + +# First rule is run by default +os-image.bin: boot/bootsect.bin kernel.bin + cat $^ > os-image.bin + +# '--oformat binary' deletes all symbols as a collateral, so we don't need +# to 'strip' them manually on this case +kernel.bin: boot/kernel_entry.o ${OBJ} + i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary + +# Used for debugging purposes +kernel.elf: boot/kernel_entry.o ${OBJ} + i386-elf-ld -o $@ -Ttext 0x1000 $^ + +run: os-image.bin + qemu-system-i386 -fda os-image.bin + +# Open the connection to qemu and load our kernel-object file with symbols +debug: os-image.bin kernel.elf + qemu-system-i386 -s -fda os-image.bin -d guest_errors,int & + ${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf" + +# Generic rules for wildcards +# To make an object, always compile from its .c +%.o: %.c ${HEADERS} + ${CC} ${CFLAGS} -ffreestanding -c $< -o $@ + +%.o: %.asm + nasm $< -f elf -o $@ + +%.bin: %.asm + nasm $< -f bin -o $@ + +clean: + rm -rf *.bin *.dis *.o os-image.bin *.elf + rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o diff --git a/21-shell/README.md b/21-shell/README.md index 9b71df3..987c88e 100644 --- a/21-shell/README.md +++ b/21-shell/README.md @@ -31,6 +31,12 @@ move `drivers/ports.*` into `cpu/` since it is clearly cpu-dependent code. `boot/` is also CPU-dependent code, but we will not mess with it until we implement the boot sequence for a different machine. +There are more switches for the `CFLAGS` on the `Makefile`, since we will now +start creating higher-level functions for our C library and we don't want +the compiler to include any external code if we make a mistake with a declaration. +We also added some flags to turn warnings into errors, since an apparantly minor mistake +converting pointers can blow up later on. This also forced us to modify some misc pointer +declarations in our code. Keyboard characters ------------------- diff --git a/21-shell/cpu/isr.c b/21-shell/cpu/isr.c index 0f5d1fc..c46a1d8 100644 --- a/21-shell/cpu/isr.c +++ b/21-shell/cpu/isr.c @@ -1,7 +1,9 @@ #include "isr.h" #include "idt.h" #include "../drivers/screen.h" +#include "../drivers/keyboard.h" #include "../libc/string.h" +#include "timer.h" #include "ports.h" isr_t interrupt_handlers[256]; diff --git a/21-shell/cpu/isr.h b/21-shell/cpu/isr.h index 6673ca7..337fbf3 100644 --- a/21-shell/cpu/isr.h +++ b/21-shell/cpu/isr.h @@ -81,6 +81,7 @@ typedef struct { void isr_install(); void isr_handler(registers_t r); +void irq_install(); typedef void (*isr_t)(registers_t); void register_interrupt_handler(u8 n, isr_t handler); diff --git a/21-shell/cpu/timer.c b/21-shell/cpu/timer.c index 00a29be..82ce105 100644 --- a/21-shell/cpu/timer.c +++ b/21-shell/cpu/timer.c @@ -1,9 +1,10 @@ #include "timer.h" #include "isr.h" +#include "ports.h" u32 tick = 0; -static void timer_callback(registers_t regs) { +static void timer_callback() { tick++; } diff --git a/21-shell/drivers/keyboard.c b/21-shell/drivers/keyboard.c index 416243f..b61e5a8 100644 --- a/21-shell/drivers/keyboard.c +++ b/21-shell/drivers/keyboard.c @@ -8,6 +8,8 @@ #define BACKSPACE 0x0E #define ENTER 0x1C +static char key_buffer[256]; + #define SC_MAX 57 const char *sc_name[] = { "ERROR", "Esc", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "Backspace", "Tab", "Q", "W", "E", @@ -21,7 +23,7 @@ const char sc_ascii[] = { '?', '?', '1', '2', '3', '4', '5', '6', 'H', 'J', 'K', 'L', ';', '\'', '`', '?', '\\', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', '?', '?', '?', ' '}; -static void keyboard_callback(registers_t regs) { +static void keyboard_callback() { /* The PIC leaves us the scancode in port 0x60 */ u8 scancode = port_byte_in(0x60); diff --git a/21-shell/drivers/keyboard.h b/21-shell/drivers/keyboard.h index 2b5a199..ad4fc66 100644 --- a/21-shell/drivers/keyboard.h +++ b/21-shell/drivers/keyboard.h @@ -1,5 +1,3 @@ #include "../cpu/types.h" -static char key_buffer[256]; - void init_keyboard(); diff --git a/21-shell/drivers/screen.c b/21-shell/drivers/screen.c index 11c1b6e..e955688 100644 --- a/21-shell/drivers/screen.c +++ b/21-shell/drivers/screen.c @@ -1,5 +1,6 @@ #include "screen.h" #include "../cpu/ports.h" +#include "../libc/mem.h" /* Declaration of private functions */ int get_cursor_offset(); @@ -64,7 +65,7 @@ void kprint_backspace() { * Sets the video cursor to the returned offset */ int print_char(char c, int col, int row, char attr) { - unsigned char *vidmem = (unsigned char*) VIDEO_ADDRESS; + u8 *vidmem = (u8*) VIDEO_ADDRESS; if (!attr) attr = WHITE_ON_BLACK; /* Error control: print a red 'E' if the coords aren't right */ @@ -94,12 +95,12 @@ int print_char(char c, int col, int row, char attr) { if (offset >= MAX_ROWS * MAX_COLS * 2) { int i; for (i = 1; i < MAX_ROWS; i++) - memory_copy(get_offset(0, i) + VIDEO_ADDRESS, - get_offset(0, i-1) + VIDEO_ADDRESS, + memory_copy((u8*)(get_offset(0, i) + VIDEO_ADDRESS), + (u8*)(get_offset(0, i-1) + VIDEO_ADDRESS), MAX_COLS * 2); /* Blank last line */ - char *last_line = get_offset(0, MAX_ROWS-1) + VIDEO_ADDRESS; + char *last_line = (char*) (get_offset(0, MAX_ROWS-1) + (u8*) VIDEO_ADDRESS); for (i = 0; i < MAX_COLS * 2; i++) last_line[i] = 0; offset -= 2 * MAX_COLS; @@ -125,15 +126,15 @@ void set_cursor_offset(int offset) { /* Similar to get_cursor_offset, but instead of reading we write data */ offset /= 2; port_byte_out(REG_SCREEN_CTRL, 14); - port_byte_out(REG_SCREEN_DATA, (unsigned char)(offset >> 8)); + port_byte_out(REG_SCREEN_DATA, (u8)(offset >> 8)); port_byte_out(REG_SCREEN_CTRL, 15); - port_byte_out(REG_SCREEN_DATA, (unsigned char)(offset & 0xff)); + port_byte_out(REG_SCREEN_DATA, (u8)(offset & 0xff)); } void clear_screen() { int screen_size = MAX_COLS * MAX_ROWS; int i; - char *screen = VIDEO_ADDRESS; + u8 *screen = (u8*) VIDEO_ADDRESS; for (i = 0; i < screen_size; i++) { screen[i*2] = ' '; diff --git a/21-shell/drivers/screen.h b/21-shell/drivers/screen.h index 17313c6..24ec3e4 100644 --- a/21-shell/drivers/screen.h +++ b/21-shell/drivers/screen.h @@ -1,6 +1,8 @@ #ifndef SCREEN_H #define SCREEN_H +#include "../cpu/types.h" + #define VIDEO_ADDRESS 0xb8000 #define MAX_ROWS 25 #define MAX_COLS 80 diff --git a/21-shell/libc/mem.c b/21-shell/libc/mem.c index 63aff15..87f9ee1 100644 --- a/21-shell/libc/mem.c +++ b/21-shell/libc/mem.c @@ -1,6 +1,6 @@ #include "mem.h" -void memory_copy(char *source, char *dest, int nbytes) { +void memory_copy(u8 *source, u8 *dest, int nbytes) { int i; for (i = 0; i < nbytes; i++) { *(dest + i) = *(source + i); diff --git a/21-shell/libc/mem.h b/21-shell/libc/mem.h index 91e3cfd..ceab9da 100644 --- a/21-shell/libc/mem.h +++ b/21-shell/libc/mem.h @@ -3,7 +3,7 @@ #include "../cpu/types.h" -void memory_copy(char *source, char *dest, int nbytes); +void memory_copy(u8 *source, u8 *dest, int nbytes); void memory_set(u8 *dest, u8 val, u32 len); #endif diff --git a/21-shell/libc/string.h b/21-shell/libc/string.h index 85f99b9..75f2d1b 100644 --- a/21-shell/libc/string.h +++ b/21-shell/libc/string.h @@ -4,6 +4,7 @@ void int_to_ascii(int n, char str[]); void reverse(char s[]); int strlen(char s[]); +void backspace(char s[]); void append(char s[], char n); int strcmp(char s1[], char s2[]);