Skip to content

Commit 8ad1936

Browse files
committed
Fixed warnings
1 parent 8a5e637 commit 8ad1936

File tree

13 files changed

+75
-15
lines changed

13 files changed

+75
-15
lines changed

20-interrupts-timer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o}
77
CC = /usr/local/i386elfgcc/bin/i386-elf-gcc
88
GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
99
# -g: Use debugging symbols in gcc
10-
CFLAGS = -g
10+
CFLAGS = -g
1111

1212
# First rule is run by default
1313
os-image.bin: boot/bootsect.bin kernel.bin

21-shell/Makefile

Lines changed: 0 additions & 1 deletion
This file was deleted.

21-shell/Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c libc/*.c)
2+
HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h libc/*.h)
3+
# Nice syntax for file extension replacement
4+
OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o}
5+
6+
# Change this if your cross-compiler is somewhere else
7+
CC = /usr/local/i386elfgcc/bin/i386-elf-gcc
8+
GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
9+
# -g: Use debugging symbols in gcc
10+
CFLAGS = -g -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs \
11+
-Wall -Wextra -Werror
12+
13+
# First rule is run by default
14+
os-image.bin: boot/bootsect.bin kernel.bin
15+
cat $^ > os-image.bin
16+
17+
# '--oformat binary' deletes all symbols as a collateral, so we don't need
18+
# to 'strip' them manually on this case
19+
kernel.bin: boot/kernel_entry.o ${OBJ}
20+
i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
21+
22+
# Used for debugging purposes
23+
kernel.elf: boot/kernel_entry.o ${OBJ}
24+
i386-elf-ld -o $@ -Ttext 0x1000 $^
25+
26+
run: os-image.bin
27+
qemu-system-i386 -fda os-image.bin
28+
29+
# Open the connection to qemu and load our kernel-object file with symbols
30+
debug: os-image.bin kernel.elf
31+
qemu-system-i386 -s -fda os-image.bin -d guest_errors,int &
32+
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
33+
34+
# Generic rules for wildcards
35+
# To make an object, always compile from its .c
36+
%.o: %.c ${HEADERS}
37+
${CC} ${CFLAGS} -ffreestanding -c $< -o $@
38+
39+
%.o: %.asm
40+
nasm $< -f elf -o $@
41+
42+
%.bin: %.asm
43+
nasm $< -f bin -o $@
44+
45+
clean:
46+
rm -rf *.bin *.dis *.o os-image.bin *.elf
47+
rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o

21-shell/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ move `drivers/ports.*` into `cpu/` since it is clearly cpu-dependent code.
3131
`boot/` is also CPU-dependent code, but we will not mess with it until
3232
we implement the boot sequence for a different machine.
3333

34+
There are more switches for the `CFLAGS` on the `Makefile`, since we will now
35+
start creating higher-level functions for our C library and we don't want
36+
the compiler to include any external code if we make a mistake with a declaration.
37+
We also added some flags to turn warnings into errors, since an apparantly minor mistake
38+
converting pointers can blow up later on. This also forced us to modify some misc pointer
39+
declarations in our code.
3440

3541
Keyboard characters
3642
-------------------

21-shell/cpu/isr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "isr.h"
22
#include "idt.h"
33
#include "../drivers/screen.h"
4+
#include "../drivers/keyboard.h"
45
#include "../libc/string.h"
6+
#include "timer.h"
57
#include "ports.h"
68

79
isr_t interrupt_handlers[256];

21-shell/cpu/isr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef struct {
8181

8282
void isr_install();
8383
void isr_handler(registers_t r);
84+
void irq_install();
8485

8586
typedef void (*isr_t)(registers_t);
8687
void register_interrupt_handler(u8 n, isr_t handler);

21-shell/cpu/timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "timer.h"
22
#include "isr.h"
3+
#include "ports.h"
34

45
u32 tick = 0;
56

6-
static void timer_callback(registers_t regs) {
7+
static void timer_callback() {
78
tick++;
89
}
910

21-shell/drivers/keyboard.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define BACKSPACE 0x0E
99
#define ENTER 0x1C
1010

11+
static char key_buffer[256];
12+
1113
#define SC_MAX 57
1214
const char *sc_name[] = { "ERROR", "Esc", "1", "2", "3", "4", "5", "6",
1315
"7", "8", "9", "0", "-", "=", "Backspace", "Tab", "Q", "W", "E",
@@ -21,7 +23,7 @@ const char sc_ascii[] = { '?', '?', '1', '2', '3', '4', '5', '6',
2123
'H', 'J', 'K', 'L', ';', '\'', '`', '?', '\\', 'Z', 'X', 'C', 'V',
2224
'B', 'N', 'M', ',', '.', '/', '?', '?', '?', ' '};
2325

24-
static void keyboard_callback(registers_t regs) {
26+
static void keyboard_callback() {
2527
/* The PIC leaves us the scancode in port 0x60 */
2628
u8 scancode = port_byte_in(0x60);
2729

21-shell/drivers/keyboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#include "../cpu/types.h"
22

3-
static char key_buffer[256];
4-
53
void init_keyboard();

21-shell/drivers/screen.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "screen.h"
22
#include "../cpu/ports.h"
3+
#include "../libc/mem.h"
34

45
/* Declaration of private functions */
56
int get_cursor_offset();
@@ -64,7 +65,7 @@ void kprint_backspace() {
6465
* Sets the video cursor to the returned offset
6566
*/
6667
int print_char(char c, int col, int row, char attr) {
67-
unsigned char *vidmem = (unsigned char*) VIDEO_ADDRESS;
68+
u8 *vidmem = (u8*) VIDEO_ADDRESS;
6869
if (!attr) attr = WHITE_ON_BLACK;
6970

7071
/* 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) {
9495
if (offset >= MAX_ROWS * MAX_COLS * 2) {
9596
int i;
9697
for (i = 1; i < MAX_ROWS; i++)
97-
memory_copy(get_offset(0, i) + VIDEO_ADDRESS,
98-
get_offset(0, i-1) + VIDEO_ADDRESS,
98+
memory_copy((u8*)(get_offset(0, i) + VIDEO_ADDRESS),
99+
(u8*)(get_offset(0, i-1) + VIDEO_ADDRESS),
99100
MAX_COLS * 2);
100101

101102
/* Blank last line */
102-
char *last_line = get_offset(0, MAX_ROWS-1) + VIDEO_ADDRESS;
103+
char *last_line = (char*) (get_offset(0, MAX_ROWS-1) + (u8*) VIDEO_ADDRESS);
103104
for (i = 0; i < MAX_COLS * 2; i++) last_line[i] = 0;
104105

105106
offset -= 2 * MAX_COLS;
@@ -125,15 +126,15 @@ void set_cursor_offset(int offset) {
125126
/* Similar to get_cursor_offset, but instead of reading we write data */
126127
offset /= 2;
127128
port_byte_out(REG_SCREEN_CTRL, 14);
128-
port_byte_out(REG_SCREEN_DATA, (unsigned char)(offset >> 8));
129+
port_byte_out(REG_SCREEN_DATA, (u8)(offset >> 8));
129130
port_byte_out(REG_SCREEN_CTRL, 15);
130-
port_byte_out(REG_SCREEN_DATA, (unsigned char)(offset & 0xff));
131+
port_byte_out(REG_SCREEN_DATA, (u8)(offset & 0xff));
131132
}
132133

133134
void clear_screen() {
134135
int screen_size = MAX_COLS * MAX_ROWS;
135136
int i;
136-
char *screen = VIDEO_ADDRESS;
137+
u8 *screen = (u8*) VIDEO_ADDRESS;
137138

138139
for (i = 0; i < screen_size; i++) {
139140
screen[i*2] = ' ';

0 commit comments

Comments
 (0)