From: Jon Feldman Date: Tue, 21 Feb 2017 03:33:14 +0000 (-0500) Subject: Enable paranoia errors X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=4487c0417a795f172d7d22d98f2800e97d19f33a;p=misc%2Feidos.git Enable paranoia errors --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ce38083 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +--- +Language: Cpp +# BasedOnStyle: Mozilla +AccessModifierOffset: -2 +AlignAfterOpenBracket: true +AlignConsecutiveAssignments: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: TopLevel +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Mozilla +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +ColumnLimit: 160 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... + diff --git a/Makefile b/Makefile index f02c60e..62007cb 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,7 @@ TGT=i686 SOURCES= \ $(TGT)/entry.o $(TGT)/utils.o $(TGT)/gdt.o $(TGT)/idt.o $(TGT)/timer.o \ - module/biosvga/module.o \ - module/ps2input/module.o \ - module/console.o \ + module/biosvga/module.o module/ps2input/module.o module/console.o \ common/stdc/putc.o common/stdc/puts.o common/stdc/vsprintf.o common/stdc/printf.o common/stdc/strcatlen.o common/stdc/dumphex.o \ common/stdc/memmove.o common/stdc/strlen.o common/stdc/memcmp.o common/stdc/memset.o common/stdc/memcpy.o \ common/kernel_main.o @@ -27,7 +25,7 @@ OC=$(TGTNAM)-objcopy NM=$(TGTNAM)-nm RL=$(TGTNAM)-ranlib -CFLAGS=-ffreestanding -std=gnu11 +CFLAGS=-ffreestanding -std=gnu11 -Werror -Wall -Wextra CPPFLAGS=-Iinclude -Iinclude/stdc -I$(TGT)/include LDFLAGS=-T$(LDSC) ASFLAGS= @@ -36,7 +34,7 @@ LIBS= all: link qemu: all - qemu-system-i386 --kernel kernel + qemu-system-x86_64 --kernel kernel clean: rm -f $(SOURCES) kernel diff --git a/common/kernel_main.c b/common/kernel_main.c index 98fa21d..d2b8938 100644 --- a/common/kernel_main.c +++ b/common/kernel_main.c @@ -2,9 +2,11 @@ #include #include +#include + #include -int kernel_main(struct multiboot *mboot_ptr) +int kernel_main(void) { console_init(); diff --git a/common/stdc/putc.c b/common/stdc/putc.c index c38db8d..06fdcc3 100644 --- a/common/stdc/putc.c +++ b/common/stdc/putc.c @@ -1,5 +1,7 @@ #include +void put_handler(char); + void putc(char c) { - put_handler(c); + put_handler(c); } diff --git a/common/stdc/vsprintf.c b/common/stdc/vsprintf.c index 64cf60a..f4718ef 100644 --- a/common/stdc/vsprintf.c +++ b/common/stdc/vsprintf.c @@ -1,4 +1,5 @@ #include +#include void vsprintf(char *buffer, const char* fmt_con, va_list ap) { char* fmt = (char*)fmt_con; diff --git a/i686/entry.S b/i686/entry.S index dd0ff0b..e3096f4 100644 --- a/i686/entry.S +++ b/i686/entry.S @@ -56,8 +56,6 @@ _start: mov $stack_top, %esp - push %ebx - call i686_init call kernel_main diff --git a/i686/idt.c b/i686/idt.c index 0ab044b..524bf9a 100644 --- a/i686/idt.c +++ b/i686/idt.c @@ -2,6 +2,7 @@ #include #include +#include #include @@ -87,8 +88,6 @@ void isr_handler(struct interrupt_frame* esp) { } void irq_handler(struct interrupt_frame* esp) { - char c_kb = 0; - if (esp->int_no >= 7) { outb(0xA0, 0x20); } @@ -169,6 +168,8 @@ void init_irq() IRQ_CALL(15); } +extern void idt_flush(uint32_t); + void init_idt() { idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1; diff --git a/i686/timer.c b/i686/timer.c index 2755c04..a2bb732 100644 --- a/i686/timer.c +++ b/i686/timer.c @@ -2,10 +2,11 @@ #include #include +#include #include -int set_pitdiv(int freq) { +void set_pitdiv(int freq) { uint32_t div = 1193180 / freq; outb(0x43, 0x36); @@ -24,11 +25,11 @@ uint64_t clock() { return ticks; } -void clock_inc(struct interrupt_frame* frame) { +void clock_inc(__attribute__((unused)) struct interrupt_frame* frame) { ++ticks; } -void i686_pic_init() { +void i686_pit_init() { register_int_handler(32, clock_inc); set_pitdiv(CONF_TIMER_FREQ); } diff --git a/i686/utils.c b/i686/utils.c index 38ce5c3..7593ce7 100644 --- a/i686/utils.c +++ b/i686/utils.c @@ -47,11 +47,11 @@ uint32_t inl(uint16_t port) void init_gdt(); void init_idt(); -int set_pitdiv(int freq); +void i686_pit_init(); void i686_init() { init_gdt(); init_idt(); - i686_pic_init(); + i686_pit_init(); } diff --git a/include/module_console.h b/include/module_console.h index c274c8e..a57c872 100644 --- a/include/module_console.h +++ b/include/module_console.h @@ -21,3 +21,4 @@ void console_unreg_read(struct input*); void console_init(); void console_deinit(); +void console_refresh(); diff --git a/include/multiboot.h b/include/multiboot.h new file mode 100644 index 0000000..040e5f4 --- /dev/null +++ b/include/multiboot.h @@ -0,0 +1,223 @@ +/* multiboot.h - Multiboot header file. */ +/* Copyright (C) 1999,2003,2007,2008,2009 Free Software Foundation, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY + * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MULTIBOOT_HEADER +#define MULTIBOOT_HEADER 1 + +/* How many bytes from the start of the file we search for the header. */ +#define MULTIBOOT_SEARCH 8192 + +/* The magic field should contain this. */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* This should be in %eax. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The bits in the required part of flags field we don't support. */ +#define MULTIBOOT_UNSUPPORTED 0x0000fffc + +/* Alignment of multiboot modules. */ +#define MULTIBOOT_MOD_ALIGN 0x00001000 + +/* Alignment of the multiboot info structure. */ +#define MULTIBOOT_INFO_ALIGN 0x00000004 + +/* Flags set in the 'flags' member of the multiboot header. */ + +/* Align all boot modules on i386 page (4KB) boundaries. */ +#define MULTIBOOT_PAGE_ALIGN 0x00000001 + +/* Must pass memory information to OS. */ +#define MULTIBOOT_MEMORY_INFO 0x00000002 + +/* Must pass video information to OS. */ +#define MULTIBOOT_VIDEO_MODE 0x00000004 + +/* This flag indicates the use of the address fields in the header. */ +#define MULTIBOOT_AOUT_KLUDGE 0x00010000 + +/* Flags to be set in the 'flags' member of the multiboot info structure. */ + +/* is there basic lower/upper memory information? */ +#define MULTIBOOT_INFO_MEMORY 0x00000001 +/* is there a boot device set? */ +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +/* is the command-line defined? */ +#define MULTIBOOT_INFO_CMDLINE 0x00000004 +/* are there modules to do something with? */ +#define MULTIBOOT_INFO_MODS 0x00000008 + +/* These next two are mutually exclusive */ + +/* is there a symbol table loaded? */ +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +/* is there an ELF section header table? */ +#define MULTIBOOT_INFO_ELF_SHDR 0X00000020 + +/* is there a full memory map? */ +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 + +/* Is there drive info? */ +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 + +/* Is there a config table? */ +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 + +/* Is there a boot loader name? */ +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 + +/* Is there a APM table? */ +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 + +/* Is there video information? */ +#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 + +#ifndef ASM_FILE + +typedef unsigned short multiboot_uint16_t; +typedef unsigned int multiboot_uint32_t; +typedef unsigned long long multiboot_uint64_t; + +struct multiboot_header +{ + /* Must be MULTIBOOT_MAGIC - see above. */ + multiboot_uint32_t magic; + + /* Feature flags. */ + multiboot_uint32_t flags; + + /* The above fields plus this one must equal 0 mod 2^32. */ + multiboot_uint32_t checksum; + + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ + multiboot_uint32_t header_addr; + multiboot_uint32_t load_addr; + multiboot_uint32_t load_end_addr; + multiboot_uint32_t bss_end_addr; + multiboot_uint32_t entry_addr; + + /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ + multiboot_uint32_t mode_type; + multiboot_uint32_t width; + multiboot_uint32_t height; + multiboot_uint32_t depth; +}; + +/* The symbol table for a.out. */ +struct multiboot_aout_symbol_table +{ + multiboot_uint32_t tabsize; + multiboot_uint32_t strsize; + multiboot_uint32_t addr; + multiboot_uint32_t reserved; +}; +typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; + +/* The section header table for ELF. */ +struct multiboot_elf_section_header_table +{ + multiboot_uint32_t num; + multiboot_uint32_t size; + multiboot_uint32_t addr; + multiboot_uint32_t shndx; +}; +typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; + +struct multiboot_info +{ + /* Multiboot info version number */ + multiboot_uint32_t flags; + + /* Available memory from BIOS */ + multiboot_uint32_t mem_lower; + multiboot_uint32_t mem_upper; + + /* "root" partition */ + multiboot_uint32_t boot_device; + + /* Kernel command line */ + multiboot_uint32_t cmdline; + + /* Boot-Module list */ + multiboot_uint32_t mods_count; + multiboot_uint32_t mods_addr; + + union + { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; + + /* Memory Mapping buffer */ + multiboot_uint32_t mmap_length; + multiboot_uint32_t mmap_addr; + + /* Drive Info buffer */ + multiboot_uint32_t drives_length; + multiboot_uint32_t drives_addr; + + /* ROM configuration table */ + multiboot_uint32_t config_table; + + /* Boot Loader Name */ + multiboot_uint32_t boot_loader_name; + + /* APM table */ + multiboot_uint32_t apm_table; + + /* Video */ + multiboot_uint32_t vbe_control_info; + multiboot_uint32_t vbe_mode_info; + multiboot_uint16_t vbe_mode; + multiboot_uint16_t vbe_interface_seg; + multiboot_uint16_t vbe_interface_off; + multiboot_uint16_t vbe_interface_len; +}; +typedef struct multiboot_info multiboot_info_t; + +struct multiboot_mmap_entry +{ + multiboot_uint32_t size; + multiboot_uint64_t addr; + multiboot_uint64_t len; +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 + multiboot_uint32_t type; +} __attribute__((packed)); +typedef struct multiboot_mmap_entry multiboot_memory_map_t; + +struct multiboot_mod_list +{ + /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ + multiboot_uint32_t mod_start; + multiboot_uint32_t mod_end; + + /* Module command line */ + multiboot_uint32_t cmdline; + + /* padding to take it to 16 bytes (must be zero) */ + multiboot_uint32_t pad; +}; +typedef struct multiboot_mod_list multiboot_module_t; + +#endif /* ! ASM_FILE */ + +#endif /* ! MULTIBOOT_HEADER */ diff --git a/include/stdc/stdio.h b/include/stdc/stdio.h index 2b5c7d3..e2cca0d 100644 --- a/include/stdc/stdio.h +++ b/include/stdc/stdio.h @@ -1,5 +1,5 @@ -#ifndef _STRING_H -#define _STRING_H 1 +#ifndef _STDIO_H +#define _STDIO_H 1 #include #include diff --git a/module/biosvga/module.c b/module/biosvga/module.c index 04f1fca..283ca42 100644 --- a/module/biosvga/module.c +++ b/module/biosvga/module.c @@ -3,6 +3,8 @@ #include #include +#include + #define WIDTH 80 #define HEIGHT 25 diff --git a/module/console.c b/module/console.c index e836b88..2eee6d3 100644 --- a/module/console.c +++ b/module/console.c @@ -38,12 +38,18 @@ void console_refresh() { } } +void biosvga_init(); +void ps2input_init(); + void console_init() { // Temporary biosvga_init(); ps2input_init(); } +void biosvga_deinit(); +void ps2input_deinit(); + void console_deinit() { // Temporary biosvga_deinit(); diff --git a/module/ps2input/module.c b/module/ps2input/module.c index 27a1e6d..fedc674 100644 --- a/module/ps2input/module.c +++ b/module/ps2input/module.c @@ -4,11 +4,12 @@ #include #include +#include char avail_buf[256]; int avail_cnt = 0; -void ps2input_int(struct interrupt_frame* esp) { +void ps2input_int(__attribute__((unused)) struct interrupt_frame* esp) { do { if (inb(0x60) != 0) { avail_buf[avail_cnt] = inb(0x60); @@ -35,7 +36,8 @@ char ps2input_rb() { --avail_cnt; - char r = charmap[avail_buf[0]]; + int c = avail_buf[0]; + char r = charmap[c]; memcpy(&avail_buf[0], &avail_buf[1], 255);