aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--devices/i8042.c4
-rw-r--r--devices/pic_8259.c18
-rw-r--r--devices/uart.h2
-rw-r--r--devices/uart/uart_16550.c14
-rw-r--r--devices/uart/uart_16550.h6
-rw-r--r--devices/vga.c12
-rw-r--r--devices/vga.h2
-rw-r--r--i686/lgdt.c2
-rw-r--r--i686/lidt.c6
-rw-r--r--i686/sys/io.h2
-rw-r--r--lib/libk/stdio/vfprintf.c2
-rw-r--r--lib/libk/stdlib/linked_list_allocator.c4
-rw-r--r--lib/libk/string.h5
-rw-r--r--lib/libk/string/itoa.c6
-rw-r--r--rules.mk7
-rw-r--r--src/kernel.c9
-rw-r--r--src/mem/vmm.c14
-rw-r--r--src/mmap.c10
-rw-r--r--src/sched/test_roundrobin.cc2
-rwxr-xr-xtools/kconfig/build.mk4
20 files changed, 74 insertions, 57 deletions
diff --git a/devices/i8042.c b/devices/i8042.c
index 4805529..cfd96a8 100644
--- a/devices/i8042.c
+++ b/devices/i8042.c
@@ -26,11 +26,11 @@ void
ps2_ctrl_init()
{
int i;
+ uint8_t test, conf;
/* eat all previous keystrikes */
while (inb(comm_port) & 0x1) inb(data_port);
- uint8_t test;
outb(0xaa, comm_port);
test = inb(data_port);
printf("i8042: self test 0xaa:%x %s\n", test, test == 0x55 ? "ok" : "failed");
@@ -63,7 +63,7 @@ ps2_ctrl_init()
printf("\n");
outb(comm_read_ctrl_config, comm_port);
- uint8_t conf = (inb(data_port) | 1) & ~0x10;
+ conf = (uint8_t)((inb(data_port) | 1) & ~0x10);
conf |= 0x22; /* mouse */
outb(comm_write_ctrl_config, comm_port);
diff --git a/devices/pic_8259.c b/devices/pic_8259.c
index 7b4807c..75aaf6d 100644
--- a/devices/pic_8259.c
+++ b/devices/pic_8259.c
@@ -33,17 +33,25 @@ pic_init()
outb(0xff, PIC2 + DATA);
}
+static unsigned char
+irq_mask(unsigned char irq)
+{
+ unsigned char mask = (unsigned char)~(1u << irq);
+ return 0xff & mask;
+}
+
void
pic_enable()
{
unsigned char mask1 = 0xff;
- mask1 &= ~(1 << 0); /* irq0 timer */
- mask1 &= ~(1 << 1); /* irq1 keyboard */
- mask1 &= ~(1 << 2); /* irq1 cascade */
+ unsigned char mask2 = 0xff;
+
+ mask1 &= irq_mask(0); /* irq0 timer */
+ mask1 &= irq_mask(1); /* irq1 keyboard */
+ mask1 &= irq_mask(2); /* irq2 cascade */
outb(mask1, PIC1 + DATA);
- unsigned char mask2 = 0xff;
- mask2 &= ~(1 << 4); /* irq12 mouse */
+ mask2 &= irq_mask(12 - 8); /* irq12 mouse */
outb(mask2, PIC2 + DATA);
enable_interrupts();
diff --git a/devices/uart.h b/devices/uart.h
index 3349042..53a4f41 100644
--- a/devices/uart.h
+++ b/devices/uart.h
@@ -29,4 +29,4 @@ enum UART {
};
#endif
-FILE *uart_init(enum UART port);
+FILE *uart_init(unsigned short port);
diff --git a/devices/uart/uart_16550.c b/devices/uart/uart_16550.c
index 0e19842..4697cf3 100644
--- a/devices/uart/uart_16550.c
+++ b/devices/uart/uart_16550.c
@@ -2,7 +2,7 @@
#include <stddef.h>
int
-uart_thre(enum UART port)
+uart_thre(unsigned short port)
{
return inb(port + LineStatus) & THRE;
}
@@ -10,12 +10,14 @@ uart_thre(enum UART port)
void
uart_putc(const FILE *self, char a)
{
- while (uart_thre((enum UART)self->id) == 0) {}
- outb(a, self->id);
+ const unsigned short port = (unsigned short)self->id;
+
+ while (uart_thre(port) == 0) {}
+ outb((unsigned char)a, port);
if (a == '\n') {
- while (uart_thre((enum UART)self->id) == 0) {}
- outb('\r', self->id);
+ while (uart_thre(port) == 0) {}
+ outb('\r', port);
}
}
@@ -49,7 +51,7 @@ uart_flush(__attribute__((unused)) const FILE *self)
FILE uart_stream;
FILE *
-uart_init(enum UART port)
+uart_init(unsigned short port)
{
outb(0x00, port + 1); /* Disable all interrupts */
outb(0x80, port + 3); /* Enable DLAB (set baud rate divisor) */
diff --git a/devices/uart/uart_16550.h b/devices/uart/uart_16550.h
index 176dea2..d4f470e 100644
--- a/devices/uart/uart_16550.h
+++ b/devices/uart/uart_16550.h
@@ -2,7 +2,7 @@
#include "../uart.h"
-int uart_thre(enum UART port);
+int uart_thre(unsigned short port);
void uart_putc(const FILE *self, char a);
int uart_puts(const FILE *self, const char *string, int length);
void uart_flush(__attribute__((unused)) const FILE *self);
@@ -15,7 +15,7 @@ enum uart_16550_offset {
ModemControl = 4,
LineStatus = 5,
ModemStatus = 6,
- Scratch = 7,
+ Scratch = 7
};
/* Line Control
@@ -45,5 +45,5 @@ enum LineStatus {
BI = (1 << 4), /* break indicator: see if there is a break in data input */
THRE = (1 << 5), /* transmitter holding register empty: see if transmission buffer is empty */
TEMT = (1 << 6), /* transmitter empty: see if transmitter is not doing anything */
- ERRO = (1 << 7), /* impending error: see if there is an error with a word in the input buffer */
+ ERRO = (1 << 7) /* impending error: see if there is an error with a word in the input buffer */
};
diff --git a/devices/vga.c b/devices/vga.c
index b2a6da4..51f860f 100644
--- a/devices/vga.c
+++ b/devices/vga.c
@@ -12,9 +12,9 @@
#define cursor_hide 0x20
struct __attribute__((packed)) VGAEntry {
- unsigned char text;
- uint8_t foreground : 4;
- uint8_t background : 4;
+ char text;
+ unsigned foreground : 4;
+ unsigned background : 4;
};
/* TODO _Static_assert(sizeof(struct VGAEntry) == 2, "sizeof VGAEntry"); */
@@ -46,13 +46,13 @@ vga_disable_cursor()
void
vga_update_cursor(void)
{
- const uint16_t pos = row * width + col;
+ const uint16_t pos = (uint16_t)(row * width + col);
outb(cursor_addr_l, cga_idx_port);
- outb(pos & 0xff, cga_dat_port);
+ outb((unsigned char)pos & 0xff, cga_dat_port);
outb(cursor_addr_h, cga_idx_port);
- outb((pos >> 8) & 0xff, cga_dat_port);
+ outb((unsigned char)(pos >> 8) & 0xff, cga_dat_port);
}
/* *** Text Mode Output *** */
diff --git a/devices/vga.h b/devices/vga.h
index cd3a272..df0d921 100644
--- a/devices/vga.h
+++ b/devices/vga.h
@@ -19,7 +19,7 @@ enum vga_color {
VGA_COLOR_LIGHT_RED = 12,
VGA_COLOR_LIGHT_MAGENTA = 13,
VGA_COLOR_LIGHT_BROWN = 14,
- VGA_COLOR_WHITE = 15,
+ VGA_COLOR_WHITE = 15
};
FILE *vga_init(void *addr);
diff --git a/i686/lgdt.c b/i686/lgdt.c
index d1b24c3..473a91d 100644
--- a/i686/lgdt.c
+++ b/i686/lgdt.c
@@ -10,11 +10,11 @@ static struct SegmentDescriptor_t segments[8] __attribute__((aligned(32)));
void
gdt_install()
{
+ const struct Pointer ptr = {sizeof(segments) - 1, (unsigned)&segments};
SegmentDescriptor(&segments[0], 0, 0, 0); /* null segment */
SegmentDescriptor(&segments[2], 0, 0xffffffff, 0x9a); /* ktext segment */
SegmentDescriptor(&segments[3], 0, 0xffffffff, 0x92); /* kdata segment */
- const struct Pointer ptr = {.limit = sizeof(segments) - 1, .base = (unsigned)&segments};
__asm__("lgdt (%0)" : : "a"(&ptr));
/* load the kernel data segment */
diff --git a/i686/lidt.c b/i686/lidt.c
index 3260eb9..86567f8 100644
--- a/i686/lidt.c
+++ b/i686/lidt.c
@@ -8,7 +8,7 @@ struct __attribute__((packed)) Pointer {
enum Type {
Null = 0,
- Intr = 0x8e, /* 1000 1110 32-bit interrupt */
+ Intr = 0x8e /* 1000 1110 32-bit interrupt */
};
struct __attribute__((packed)) Gate_t {
@@ -25,7 +25,7 @@ Gate(struct Gate_t *entry, void (*f)(struct interrupt_frame *), uint16_t selecto
{
uint32_t f_addr = (uint32_t)f;
entry->offset_15_0 = f_addr & 0xffff;
- entry->offset_31_16 = (f_addr >> 16) & 0xffff;
+ entry->offset_31_16 = (uint16_t)(f_addr >> 16) & 0xffff;
entry->selector = selector;
entry->__unused = 0;
entry->type = Intr;
@@ -37,6 +37,7 @@ void
idt_install()
{
int i;
+ const struct Pointer ptr = {sizeof(interrupt_table) - 1, (unsigned)&interrupt_table};
/* exceptions 0x00~0x13 */
for (i = 0; i <= 0x13; ++i) Gate(&interrupt_table[i], &abort_handler, 0x10);
@@ -50,6 +51,5 @@ idt_install()
/* syscall 0x80 */
Gate(&interrupt_table[0x80], &syscall_handler, 0x10);
- const struct Pointer ptr = {.limit = sizeof(interrupt_table) - 1, .base = (unsigned)&interrupt_table};
__asm__("lidt (%0)" : : "a"(&ptr));
}
diff --git a/i686/sys/io.h b/i686/sys/io.h
index 403dc54..4ff5d85 100644
--- a/i686/sys/io.h
+++ b/i686/sys/io.h
@@ -9,7 +9,7 @@ enum UART {
COM5 = 0x5f8,
COM6 = 0x4f8,
COM7 = 0x5e8,
- COM8 = 0x4e8,
+ COM8 = 0x4e8
};
static __inline__ void
diff --git a/lib/libk/stdio/vfprintf.c b/lib/libk/stdio/vfprintf.c
index a48600b..807c26a 100644
--- a/lib/libk/stdio/vfprintf.c
+++ b/lib/libk/stdio/vfprintf.c
@@ -23,7 +23,7 @@ vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list par
written += stream->puts(stream, arg, -1);
} break;
case 'c': {
- const int arg = va_arg(params, int);
+ const char arg = (char)va_arg(params, int);
stream->putc(stream, arg);
++written;
} break;
diff --git a/lib/libk/stdlib/linked_list_allocator.c b/lib/libk/stdlib/linked_list_allocator.c
index 898fd89..bcec580 100644
--- a/lib/libk/stdlib/linked_list_allocator.c
+++ b/lib/libk/stdlib/linked_list_allocator.c
@@ -58,8 +58,10 @@ malloc(size_t size)
void
free(void *ptr)
{
+ struct Chunk *chunk;
if (ptr == NULL) return;
- struct Chunk *chunk = (struct Chunk *)((uintptr_t)ptr - sizeof(struct Chunk));
+
+ chunk = (struct Chunk *)((uintptr_t)ptr - sizeof(struct Chunk));
chunk->used = 0;
/* merge next chunk */
diff --git a/lib/libk/string.h b/lib/libk/string.h
index 46d8636..45b05a5 100644
--- a/lib/libk/string.h
+++ b/lib/libk/string.h
@@ -7,9 +7,8 @@
/**
* Convert int into a string
*/
-char *itoa(char *p, int x, int base);
+char *itoa(char *p, int x, unsigned base);
/**
* Convert unsigned int into a string
*/
-char *utoa(char *p, unsigned x, int base);
-
+char *utoa(char *p, unsigned x, unsigned base);
diff --git a/lib/libk/string/itoa.c b/lib/libk/string/itoa.c
index 2db9768..0997345 100644
--- a/lib/libk/string/itoa.c
+++ b/lib/libk/string/itoa.c
@@ -4,7 +4,7 @@
static const char *numbers = "0123456789abcdef";
char *
-utoa(char *p, unsigned x, int base)
+utoa(char *p, unsigned x, unsigned base)
{
p += 3 * sizeof(unsigned);
*--p = '\0';
@@ -18,12 +18,12 @@ utoa(char *p, unsigned x, int base)
}
char *
-itoa(char *p, int x, int base)
+itoa(char *p, int x, unsigned base)
{
const bool is_negative = (x < 0);
if (is_negative) x = -x;
- p = utoa(p, x, base);
+ p = utoa(p, (unsigned)x, base);
if (is_negative) *--p = '-';
return p;
diff --git a/rules.mk b/rules.mk
index f8ad6d9..3f750f8 100644
--- a/rules.mk
+++ b/rules.mk
@@ -65,6 +65,7 @@ list-targets:
@echo " SRCS: ${$(basename $@).SRCS}"
@echo " OBJS: ${$(basename $@).OBJS}"
@echo " DEPS: ${$(basename $@).DEPS}"
+ @echo " LD ${${ARCH}_LDFLAGS}"
all: ${DEFAULT_TARGETS}
@echo " -> Built all in ${COMPONENT}"
@@ -131,13 +132,11 @@ valgrind.quiet: ${TESTS}
@echo " -> Running valgrind on tests in $(shell pwd | xargs basename)"
@../scripts/test_runner.py --valgrind ${TESTS}
-clean.base: FORCE
+clean: FORCE
@echo " -> Cleaning $(shell pwd | xargs basename)"
@$(foreach V,$(filter %.OBJS, ${.VARIABLES}), rm -rf $($(V)))
@$(foreach V,$(filter %.DEPS, ${.VARIABLES}), rm -rf $($(V)))
- @rm -rf *.a
+ @rm -rf *.a ${CLEAN_FILES}
@rm -rf ${TESTS}
-%: %.base ;
-
FORCE: ;
diff --git a/src/kernel.c b/src/kernel.c
index 8d7560b..98269c1 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -19,7 +19,7 @@ FILE *stdout;
FILE *stderr;
void
-kmain()
+kmain(void)
{
stderr = uart_init(COM1);
vmm_map(0xb8000, 0xc03ff000);
@@ -28,13 +28,14 @@ kmain()
printf("glitch [version " VERSION "] [" CC "]\n");
fprintf(stderr, "glitch [version " VERSION "] [" CC "]\n");
{
+ struct CPUVersion v;
+
char vendor[13] = {'\0'};
unsigned int eax;
__get_cpuid(0, &eax, (unsigned int *)vendor, (unsigned int *)(vendor + 8), (unsigned int *)(vendor + 4));
- struct CPUVersion v;
__get_cpuid(1, (unsigned int *)&v, &eax, &eax, &eax);
- printf("CPU: %s family %u model %u stepping %u\n", vendor, family(v), model(v), v.stepping);
- fprintf(stderr, "CPU: %s family %u model %u stepping %u\n", vendor, family(v), model(v), v.stepping);
+ printf("cpuid: %s family %u model %u stepping %u\n", vendor, family(v), model(v), v.stepping);
+ fprintf(stderr, "cpuid: %s family %u model %u stepping %u\n", vendor, family(v), model(v), v.stepping);
}
pic_init();
diff --git a/src/mem/vmm.c b/src/mem/vmm.c
index f62eadf..a07dd72 100644
--- a/src/mem/vmm.c
+++ b/src/mem/vmm.c
@@ -16,15 +16,15 @@ to_vaddr(unsigned paddr)
unsigned int
vmm_map(unsigned int paddr, unsigned int vaddr)
{
- if (paddr & 0xfff || vaddr & 0xfff) return 0;
-
+ struct TableEntry *table;
const unsigned table_idx = vaddr >> 22; /* high 10 bits */
const unsigned entry_idx = (vaddr >> 12) & 0x3ff; /* low 10 bits */
- if (k_pagedir[table_idx].present == 0) return 0;
- struct TableEntry *table = (struct TableEntry *)to_vaddr(k_pagedir[table_idx].address << 12);
+ if (paddr & 0xfff || vaddr & 0xfff) return 0;
- table[entry_idx].address = paddr >> 12;
+ if (k_pagedir[table_idx].present == 0) return 0;
+ table = (struct TableEntry *)to_vaddr(k_pagedir[table_idx].address << 12);
+ table[entry_idx].address = (paddr >> 12) & 0xfffff;
table[entry_idx].present = 1;
table[entry_idx].writeable = 1;
@@ -34,10 +34,12 @@ vmm_map(unsigned int paddr, unsigned int vaddr)
void
alloc4M()
{
+ struct DirectoryEntry4MB *directory;
+
/* enable pse in cr4 */
__asm__("movl %cr4, %eax; orl $0x10, %eax; movl %eax, %cr4");
- struct DirectoryEntry4MB *directory = (struct DirectoryEntry4MB *)&k_pagedir[0x301];
+ directory = (struct DirectoryEntry4MB *)&k_pagedir[0x301];
directory->address_low = 0x1;
directory->present = 1;
directory->writeable = 1;
diff --git a/src/mmap.c b/src/mmap.c
index c28ce79..e5d4be6 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -1,4 +1,6 @@
#include "mmap.h"
+#include <multiboot2.h>
+
#ifdef DEBUG
#include <stdio.h>
#endif
@@ -7,17 +9,19 @@ __attribute__((section(".multiboot.text"))) unsigned
multiboot2_mmap(const struct multiboot_mmap_entry entries[], unsigned entry_count, unsigned bitmap[1024 * 32])
{
unsigned i, l;
+ multiboot_uint64_t avail_frames = 0;
+ multiboot_uint64_t n_frames;
+ multiboot_uint64_t table_idx;
/* clear out the bitmap */
for (i = 0; i < 1024 * 32; ++i) bitmap[i] = 0;
- unsigned avail_frames = 0;
/* loop through all the mmap_entry structures where type is MULTIBOOT_MEMORY_AVAILABLE */
for (i = 0; i < entry_count; ++i) {
if (entries[i].type != MULTIBOOT_MEMORY_AVAILABLE) continue;
/* number of frames in this entry */
- unsigned n_frames = entries[i].len / 4096;
+ n_frames = entries[i].len / 4096;
avail_frames += n_frames;
#ifdef DEBUG
@@ -26,7 +30,7 @@ multiboot2_mmap(const struct multiboot_mmap_entry entries[], unsigned entry_coun
#endif
/* the bitmap is an array of blocks, each holding 32 (2^5) values */
- unsigned table_idx = (entries[i].addr >> 17); /* get the upper 15 bits */
+ table_idx = (entries[i].addr >> 17); /* get the upper 15 bits */
while (n_frames != 0) {
if (n_frames >= 32) {
diff --git a/src/sched/test_roundrobin.cc b/src/sched/test_roundrobin.cc
index 1431788..89f60bf 100644
--- a/src/sched/test_roundrobin.cc
+++ b/src/sched/test_roundrobin.cc
@@ -43,7 +43,7 @@ TEST(roundrobin, RoundRobinQueue)
std::cout << "Completed in (us): " << duration << std::endl;
// test should complete in 250us unless running on valgrind
- if (!RUNNING_ON_VALGRIND) EXPECT_LE(duration, 250);
+ if (!RUNNING_ON_VALGRIND) { EXPECT_LE(duration, 250); }
EXPECT_EQ(queue.head, nullptr);
EXPECT_EQ(queue.tail, nullptr);
diff --git a/tools/kconfig/build.mk b/tools/kconfig/build.mk
index 060dd99..a11a6d4 100755
--- a/tools/kconfig/build.mk
+++ b/tools/kconfig/build.mk
@@ -22,5 +22,5 @@ HOST_LDFLAGS := $(shell pkg-config --libs ncursesw)
lex.yy.c: lexer.l parser.tab.c
flex $<
-clean: clean.base
- @rm -f parser.tab.h parser.tab.c lex.yy.c
+CLEAN_FILES += parser.tab.h parser.tab.c lex.yy.c
+