mirror of
				https://github.com/cfenollosa/os-tutorial.git
				synced 2025-06-13 12:54:24 +00:00 
			
		
		
		
	Fixed warnings
This commit is contained in:
		
							parent
							
								
									8a5e637701
								
							
						
					
					
						commit
						8ad1936237
					
				| @ -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 | ||||
|  | ||||
| @ -1 +0,0 @@ | ||||
| ../20-interrupts-timer/Makefile | ||||
							
								
								
									
										47
									
								
								21-shell/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								21-shell/Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
| @ -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 | ||||
| ------------------- | ||||
|  | ||||
| @ -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]; | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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++; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -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); | ||||
|      | ||||
|  | ||||
| @ -1,5 +1,3 @@ | ||||
| #include "../cpu/types.h" | ||||
| 
 | ||||
| static char key_buffer[256]; | ||||
| 
 | ||||
| void init_keyboard(); | ||||
|  | ||||
| @ -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] = ' '; | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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[]); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user