Some cleanups based on patch by Nguyen Anh Quynh
authorKevin O'Connor <kevin@koconnor.net>
Wed, 27 Feb 2008 15:41:41 +0000 (10:41 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 27 Feb 2008 15:41:41 +0000 (10:41 -0500)
Add include guards to header files.
Disable stack protector on gcc versions with that option.
Fix lds bug in src/rombios32.lds.S
Don't forward declare "struct bregs;" - it may be confusing gcc on some versions.

Makefile
src/disk.h
src/farptr.h
src/rombios32.lds.S
src/util.h

index e747126b55b7b5f2b3671cee734f8c8edc3e355d..ad99d817a244bc08c92fd95dfe2a2825398cfd82 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,9 +11,17 @@ OUT=out/
 SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c boot.c
 SRC32=post.c output.c
 
+cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
+              /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
+
 # Default compiler flags
-CFLAGS = -Wall -g -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
-CFLAGS16 = -Wall -Os -MD -m32 -DMODE16 -march=i386 -mregparm=2 -ffreestanding -fno-jump-tables
+COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
+COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
+COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
+COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
+
+CFLAGS = $(COMMONCFLAGS) -g
+CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
 
 all: $(OUT) $(OUT)rom.bin
 
index 04600f57e000982c3abfc3dbe43971af6534f871..358347aff772121b84fdcd10e5e3f8cd15779a0c 100644 (file)
@@ -3,8 +3,11 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
+#ifndef __DISK_H
+#define __DISK_H
 
 #include "ioport.h" // outb
+#include "biosvar.h" // struct bregs
 
 #define DISK_RET_SUCCESS     0x00
 #define DISK_RET_EPARAM      0x01
@@ -15,6 +18,7 @@
 #define DISK_RET_EMEDIA      0xC0
 
 // floppy.c
-struct bregs;
 void floppy_13(struct bregs *regs, u8 drive);
 void floppy_tick();
+
+#endif // disk.h
index 86179cce38ecc58a5c2143b127d62c1a3e6d6d0a..7216f2377745419310b42082f9b2a7af1c84a743 100644 (file)
@@ -3,6 +3,8 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
+#ifndef __FARPTR_H
+#define __FARPTR_H
 
 #define READ8_SEG(SEG, var) ({                                          \
     u8 __value;                                                         \
@@ -97,3 +99,5 @@ extern void __force_link_error__unknown_type();
 #define GET_FARPTR(ptr) (ptr)
 #define SET_FARPTR(ptr, val) do { (var) = (val); } while (0)
 #endif
+
+#endif // farptr.h
index 18b8ab030fc52af5947b1f00299a935bf5f3af3c..5d7e77247eb17e34c5b46e189164c6f51c94b3cd 100644 (file)
@@ -9,7 +9,7 @@
 #include "../out/rom16.offset.auto.h"
 
 OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
-OUTPUT_ARCH(i386)
+OUTPUT_ARCH("i386")
 ENTRY(_start);
 SECTIONS
 {
index 916f672e86b7bf8a4b88d8ab3db4eb27eff2e24e..53281b5e92dac6e185e877feb05f15345cd79088 100644 (file)
@@ -3,16 +3,20 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
+#ifndef __UTIL_H
+#define __UTIL_H
 
 #include "ioport.h" // outb
 #include "biosvar.h" // struct bregs
 
-static inline void irq_disable(void) {
-        asm volatile("cli": : :"memory");
+static inline void irq_disable(void)
+{
+    asm volatile("cli": : :"memory");
 }
 
-static inline void irq_enable(void) {
-        asm volatile("sti": : :"memory");
+static inline void irq_enable(void)
+{
+    asm volatile("sti": : :"memory");
 }
 
 static inline unsigned long irq_save(void)
@@ -91,7 +95,6 @@ void call16(struct bregs *callregs)
 // output.c
 void bprintf(u16 action, const char *fmt, ...)
     __attribute__ ((format (printf, 2, 3)));
-struct bregs;
 void __debug_enter(const char *fname, struct bregs *regs);
 void __debug_exit(const char *fname, struct bregs *regs);
 #define debug_enter(regs) \
@@ -115,3 +118,5 @@ handle_ret(struct bregs *regs, u8 code)
     regs->ah = code;
     set_cf(regs, code);
 }
+
+#endif // util.h