]> Chaos Git - misc/eidos.git/commitdiff
Enable paranoia errors
authorJon Feldman <chaos.kagami@gmail.com>
Tue, 21 Feb 2017 03:33:14 +0000 (22:33 -0500)
committerJon Feldman <chaos.kagami@gmail.com>
Tue, 21 Feb 2017 03:33:14 +0000 (22:33 -0500)
15 files changed:
.clang-format [new file with mode: 0644]
Makefile
common/kernel_main.c
common/stdc/putc.c
common/stdc/vsprintf.c
i686/entry.S
i686/idt.c
i686/timer.c
i686/utils.c
include/module_console.h
include/multiboot.h [new file with mode: 0644]
include/stdc/stdio.h
module/biosvga/module.c
module/console.c
module/ps2input/module.c

diff --git a/.clang-format b/.clang-format
new file mode 100644 (file)
index 0000000..ce38083
--- /dev/null
@@ -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
+...
+
index f02c60e8ae2a3c808dfd5425ab104c20b2cae192..62007cb5b15698dcfa4940323150bf65613cf46c 100644 (file)
--- 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
index 98fa21d23a0e0bc51c7d8f3970d520bd853e8e43..d2b8938ebf1e6b497b19039dbbb8d6345ffaf8ae 100644 (file)
@@ -2,9 +2,11 @@
 #include <module.h>
 #include <module_console.h>
 
+#include <multiboot.h>
+
 #include <stdio.h>
 
-int kernel_main(struct multiboot *mboot_ptr)
+int kernel_main(void)
 {
     console_init();
 
index c38db8dea9e9a55df63beaacc8b9f3427ad5c0a3..06fdcc3b6704c7e03aaf671664be23159abb9ef3 100644 (file)
@@ -1,5 +1,7 @@
 #include <stdio.h>
 
+void put_handler(char);
+
 void putc(char c) {
-     put_handler(c);
+    put_handler(c);
 }
index 64cf60a03b22a8751ca816bfd278eba5da4d329d..f4718efc826100b4463aa9c9eeeaafc4d9592bfc 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 
 void vsprintf(char *buffer, const char* fmt_con, va_list ap) {
     char* fmt = (char*)fmt_con;
index dd0ff0bc727b6e9c53688de640b1dc1c1455671d..e3096f414028fc3f951bd96278ffcc15c9f5e29a 100644 (file)
@@ -56,8 +56,6 @@ _start:
 
     mov $stack_top, %esp
 
-    push %ebx
-
     call i686_init
 
     call kernel_main
index 0ab044b0c7706e9a17fe9ce406532299974c1e43..524bf9a7a00f246baf00ae9b4fccd535c35f3297 100644 (file)
@@ -2,6 +2,7 @@
 #include <stddef.h>
 
 #include <idt.h>
+#include <utils.h>
 
 #include <stdc/string.h>
 
@@ -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;
index 2755c0481db993fa941494f71f6ea325b021d804..a2bb732533f8723dbc5e834eda14bf6d1b48a906 100644 (file)
@@ -2,10 +2,11 @@
 #include <stddef.h>
 
 #include <idt.h>
+#include <utils.h>
 
 #include <stdc/string.h>
 
-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);
 }
index 38ce5c36de16034ac9d46fcd346fb8d825871995..7593ce71d36c6906d895b81805961965de035bf1 100644 (file)
@@ -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();
 }
index c274c8e7610640004ee5477eab734cd6f418fbba..a57c872d3f950f5d77ed8b33a9b99409cf965217 100644 (file)
@@ -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 (file)
index 0000000..040e5f4
--- /dev/null
@@ -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 */
index 2b5c7d305c17c4eadd37eae425ad5f1e0be7979a..e2cca0dcf40ce5542d9178f90eafa4b7f6bb7e2a 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _STRING_H
-#define _STRING_H 1
+#ifndef _STDIO_H
+#define _STDIO_H 1
 
 #include <sys/cdefs.h>
 #include <stddef.h>
index 04f1fcac5b1ee5999e101643257a9e10abb2e816..283ca422fe80c188d0f0cb8d188a3a130fd431dc 100644 (file)
@@ -3,6 +3,8 @@
 #include <module.h>
 #include <module_console.h>
 
+#include <utils.h>
+
 #define WIDTH  80
 #define HEIGHT 25
 
index e836b88f479e2a85f921e80ee5289bfba9e117b1..2eee6d388fa14ba2bc54d1974497665d08909eff 100644 (file)
@@ -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();
index 27a1e6d7bb58c592a6a40c7213662f41dd5f5e62..fedc6742d9ebe8f23dc7e275c1551ee9fc414f58 100644 (file)
@@ -4,11 +4,12 @@
 #include <module_console.h>
 
 #include <idt.h>
+#include <utils.h>
 
 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);