From 509bf85036b3c345f832558a299257effabba108 Mon Sep 17 00:00:00 2001 From: aqua Date: Wed, 2 Nov 2022 23:09:18 +0200 Subject: fix compiler warnings --- devices/pic_8259.c | 1 + devices/uart_16550.c | 41 +++++++++++++++++++++++++++++++++++++++++ devices/uart_16550.h | 41 ----------------------------------------- i686/gdt.h | 6 +++--- i686/isr.c | 12 +++++++----- i686/lidt.c | 6 +++--- i686/paging.h | 6 +++--- i686/sys/control.h | 6 +++--- i686/sys/cpuid.h | 2 +- src/boot.h | 2 +- 10 files changed, 63 insertions(+), 60 deletions(-) diff --git a/devices/pic_8259.c b/devices/pic_8259.c index d3a2f6a..d00f74a 100644 --- a/devices/pic_8259.c +++ b/devices/pic_8259.c @@ -53,4 +53,5 @@ void pic_clear(unsigned char irq) { outb(0x20, PIC1); + if (irq >= 8) outb(0x20, PIC2); } diff --git a/devices/uart_16550.c b/devices/uart_16550.c index 7cec968..22f33ad 100644 --- a/devices/uart_16550.c +++ b/devices/uart_16550.c @@ -1,6 +1,47 @@ #include "uart_16550.h" #include +enum uart_16550_offset { + Data = 0, // read from receive buffer / write to transmit buffer | BaudDiv_l + InterruptControl = 1, // interrupt enable | BaudDiv_h + FifoControl = 2, // interrupt ID and FIFO control + LineControl = 3, // most significant bit is the DLAB + ModemControl = 4, + LineStatus = 5, + ModemStatus = 6, + Scratch = 7, +}; +// Line Control +// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// |dla| | parity | s | data | + +enum LineControl { + d5bit = 0x00, // 0000 0000 data bits + d6bit = 0x01, // 0000 0001 + d7bit = 0x02, // 0000 0010 + d8bit = 0x03, // 0000 0011 + // none = 0b00000000, // parity bits + odd = 0x08, // 0000 1000 + even = 0x18, // 0001 1000 + mark = 0x28, // 0010 1000 + space = 0x38, // 0011 1000 + // s1bit = 0b00000000, // stop bits + s2bit = 0x04, // 0000 0100 1.5 for 5bit data; 2 otherwise + dlab = 0x80 // 1000 0000 divisor latch access bit +}; + +// Line Status Register +enum LineStatus { + DR = (1 << 0), // data ready: see if there is data to read + OE = (1 << 1), // overrun error: see if there has been data lost + PE = (1 << 2), // parity error: see if there was error in transmission + FE = (1 << 3), // framing error: see if a stop bit was missing + 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 +}; + int uart_init(enum UART port) { diff --git a/devices/uart_16550.h b/devices/uart_16550.h index 0e181b2..bb219cc 100644 --- a/devices/uart_16550.h +++ b/devices/uart_16550.h @@ -1,46 +1,5 @@ #pragma once -enum uart_16550_offset { - Data = 0, // read from receive buffer / write to transmit buffer | BaudDiv_l - InterruptControl = 1, // interrupt enable | BaudDiv_h - FifoControl = 2, // interrupt ID and FIFO control - LineControl = 3, // most significant bit is the DLAB - ModemControl = 4, - LineStatus = 5, - ModemStatus = 6, - Scratch = 7, -}; -// Line Control -// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// |dla| | parity | s | data | - -enum LineControl { - d5bit = 0b00000000, // data bits - d6bit = 0b00000001, - d7bit = 0b00000010, - d8bit = 0b00000011, - // none = 0b00000000, // parity bits - odd = 0b00001000, - even = 0b00011000, - mark = 0b00101000, - space = 0b00111000, - // s1bit = 0b00000000, // stop bits - s2bit = 0b00000100, // 1.5 for 5bit data; 2 otherwise - dlab = 0b10000000, // divisor latch access bit -}; - -// Line Status Register -enum LineStatus { - DR = 0b00000001, // data ready: see if there is data to read - OE = 0b00000010, // overrun error: see if there has been data lost - PE = 0b00000100, // parity error: see if there was error in transmission - FE = 0b00001000, // framing error: see if a stop bit was missing - BI = 0b00010000, // break indicator: see if there is a break in data input - THRE = 0b00100000, // transmitter holding register empty: see if transmission buffer is empty - TEMT = 0b01000000, // transmitter empty: see if transmitter is not doing anything - ERRO = 0b10000000, // impending error: see if there is an error with a word in the input buffer -}; - enum UART { COM1 = 0x3f8, COM2 = 0x2f8, diff --git a/i686/gdt.h b/i686/gdt.h index 9148c3d..f00ff7f 100644 --- a/i686/gdt.h +++ b/i686/gdt.h @@ -14,9 +14,9 @@ struct __attribute__((packed)) Access { enum Ring privilege : 2; // descriptor privilege level bool present : 1; // true for every active segment }; -_Static_assert(sizeof(struct Access) == 1); +_Static_assert(sizeof(struct Access) == 1, "access byte size"); -static const struct Access null_access = {}; +static const struct Access null_access = {false, false, false, false, false, false, false}; static const struct Access ktext_access = {.readwrite = true, .executable = true, .segment = true, .present = true}; static const struct Access kdata_access = {.readwrite = true, .segment = true, .present = true}; @@ -43,7 +43,7 @@ struct __attribute__((packed)) SegmentDescriptor_t { bool granularity : 1; // limit scaled by 4k when set uint8_t base_31_24; // high bits of segment address }; -_Static_assert(sizeof(struct SegmentDescriptor_t) == 8); +_Static_assert(sizeof(struct SegmentDescriptor_t) == 8, "segment descriptor size"); void SegmentDescriptor(struct SegmentDescriptor_t *self, unsigned base, unsigned limit, uint8_t access); diff --git a/i686/isr.c b/i686/isr.c index 6fbe200..862f74a 100644 --- a/i686/isr.c +++ b/i686/isr.c @@ -17,30 +17,32 @@ abort_handler(struct interrupt_frame *frame) } __attribute__((interrupt)) void -syscall_handler(struct interrupt_frame *) +syscall_handler(__attribute__((unused)) struct interrupt_frame *frame) { - printf("syscall\n"); + unsigned int n; + asm volatile("mov %%eax, %0" : "=r"(n)); + printf("syscall %x\n, n"); abort(); } void pic_clear(unsigned char irq); __attribute__((interrupt)) void -irq0x00(struct interrupt_frame *) +irq0x00(__attribute__((unused)) struct interrupt_frame *frame) { pic_clear(0x00); } extern void ps2_keyboard_irq_handler(); __attribute__((interrupt)) void -irq0x01(struct interrupt_frame *) +irq0x01(__attribute__((unused)) struct interrupt_frame *frame) { ps2_keyboard_irq_handler(); pic_clear(0x01); } __attribute__((interrupt)) void -irq0x0c(struct interrupt_frame *) +irq0x0c(__attribute__((unused)) struct interrupt_frame *frame) { printf("irq 0x0c\n"); pic_clear(0x0c); diff --git a/i686/lidt.c b/i686/lidt.c index 8a70bf3..59a2611 100644 --- a/i686/lidt.c +++ b/i686/lidt.c @@ -9,7 +9,7 @@ struct __attribute__((packed)) Pointer { enum Type { Null = 0, - Intr = 0b10001110, // 32-bit interrupt + Intr = 0x8e, // 1000 1110 32-bit interrupt }; struct __attribute__((packed)) Gate_t { @@ -19,7 +19,7 @@ struct __attribute__((packed)) Gate_t { uint8_t type; // interrupt type uint16_t offset_31_16; // segment offset high }; -_Static_assert(sizeof(struct Gate_t) == 8); +_Static_assert(sizeof(struct Gate_t) == 8, "interrupt gate size"); void Gate(struct Gate_t *entry, void (*f)(struct interrupt_frame *), uint16_t selector) @@ -47,7 +47,7 @@ idt_install() Gate(&interrupt_table[0x2c], &irq0x0c, 0x10); // syscall 0x80 - Gate(&interrupt_table[0x80], &abort_handler, 0x10); + Gate(&interrupt_table[0x80], &syscall_handler, 0x10); const struct Pointer ptr = {.limit = sizeof(interrupt_table) - 1, .base = (unsigned)&interrupt_table}; asm volatile("lidt (%0)" : : "a"(&ptr)); diff --git a/i686/paging.h b/i686/paging.h index cff0506..f9c04a8 100644 --- a/i686/paging.h +++ b/i686/paging.h @@ -16,7 +16,7 @@ struct __attribute__((packed)) DirectoryEntry { unsigned int __available__ : 3; // available to the OS unsigned int address : 20; }; -_Static_assert(sizeof(struct DirectoryEntry) == 4); +_Static_assert(sizeof(struct DirectoryEntry) == 4, "DirectoryEntry size"); // DirectoryEntry4MB // |31| | | | | | | | |22|21|20| | | | | | |13|12|11| | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| @@ -38,7 +38,7 @@ struct __attribute__((packed)) DirectoryEntry4MB { unsigned rsvd : 1; // 21 unsigned int address_low : 10; }; -_Static_assert(sizeof(struct DirectoryEntry4MB) == 4); +_Static_assert(sizeof(struct DirectoryEntry4MB) == 4, "DirectoryEntry4M size"); // TableEntry // |31| | | | | | | | | | | | | | | | | | | |11| | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| @@ -56,4 +56,4 @@ struct __attribute__((packed)) TableEntry { unsigned int __available__ : 3; // available to the OS unsigned int address : 20; }; -_Static_assert(sizeof(struct TableEntry) == 4); +_Static_assert(sizeof(struct TableEntry) == 4, "TableEntry size"); diff --git a/i686/sys/control.h b/i686/sys/control.h index 0231236..1b38472 100644 --- a/i686/sys/control.h +++ b/i686/sys/control.h @@ -1,6 +1,6 @@ #pragma once -static void +static inline void abort() { asm volatile(R"(cli @@ -8,13 +8,13 @@ h: hlt jmp h)"); } -static void +static inline void enable_interrupts() { asm volatile("sti"); } -static void +static inline void disable_interrupts() { asm volatile("cli"); diff --git a/i686/sys/cpuid.h b/i686/sys/cpuid.h index f2ffe37..862601f 100644 --- a/i686/sys/cpuid.h +++ b/i686/sys/cpuid.h @@ -12,7 +12,7 @@ struct CPUVersion { unsigned int family_ex : 8; unsigned int __unused_2 : 4; } __attribute__((packed, aligned(__alignof__(unsigned int)))); -_Static_assert(sizeof(struct CPUVersion) == sizeof(unsigned int)); +_Static_assert(sizeof(struct CPUVersion) == sizeof(unsigned int), "cpuid version struct size"); unsigned int family(const struct CPUVersion v) diff --git a/src/boot.h b/src/boot.h index 56ff219..8d62bdc 100644 --- a/src/boot.h +++ b/src/boot.h @@ -17,7 +17,7 @@ typedef struct { char module_cmdline[64]; } boot_info_t; -_Static_assert((1024 * 32 * sizeof(unsigned) * 8) == (1024 * 1024)); +_Static_assert((1024 * 32 * sizeof(unsigned) * 8) == (1024 * 1024), "bitmap size check"); #ifdef __cplusplus } -- cgit v1.2.1