:: commit f8c0b317aa734d57d1e0ffff594124a0b59b93ab

mintsuki <mintsuki@protonmail.com> — 2020-04-29 14:53

parents: 45bae8018d

Resolve most GCC warnings

diff --git a/qloader2.bin b/qloader2.bin
index 3e2128ab..28b58c07 100644
Binary files a/qloader2.bin and b/qloader2.bin differ
diff --git a/src/Makefile b/src/Makefile
index b80522d0..ed29b8e5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,7 +12,8 @@ INTERNAL_CFLAGS = \
 	-mno-80387 \
 	-ffreestanding \
 	-fno-stack-protector \
-	-I.
+	-I. \
+	-Wno-address-of-packed-member
 
 LDFLAGS = -O2
 
diff --git a/src/fs/echfs.c b/src/fs/echfs.c
index 6f0654d9..ceddfe13 100644
--- a/src/fs/echfs.c
+++ b/src/fs/echfs.c
@@ -6,8 +6,8 @@
 #include <stdbool.h>
 
 struct echfs_identity_table {
-    uint8_t jmp[4];
-    uint8_t signature[8];
+    uint8_t  jmp[4];
+    char     signature[8];
     uint64_t block_count;
     uint64_t dir_length;
     uint64_t block_size;
diff --git a/src/lib/blib.c b/src/lib/blib.c
index 90b381e5..0e25df2a 100644
--- a/src/lib/blib.c
+++ b/src/lib/blib.c
@@ -8,7 +8,7 @@
 #include <lib/real.h>
 #include <lib/cio.h>
 
-void panic(const char *str) {
+__attribute__((noreturn)) void panic(const char *str) {
     print("PANIC: %s", str);
     for (;;) {
         asm volatile ("cli; hlt");
@@ -153,6 +153,7 @@ __attribute__((naked)) int _pit_sleep_and_quit_on_keypress(uint32_t ticks) {
         // Exit
         "ret\n\t"
     );
+    (void)ticks;
 }
 
 static bool int_08_hooked = false;
diff --git a/src/lib/blib.h b/src/lib/blib.h
index 2c1b9e2e..9cc1a4de 100644
--- a/src/lib/blib.h
+++ b/src/lib/blib.h
@@ -4,7 +4,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
-void panic(const char *str);
+__attribute__((noreturn)) void panic(const char *str);
 
 void pit_sleep(uint64_t pit_ticks);
 int pit_sleep_and_quit_on_keypress(uint32_t pit_ticks);
diff --git a/src/lib/part.c b/src/lib/part.c
index 799dbfcf..f9952712 100644
--- a/src/lib/part.c
+++ b/src/lib/part.c
@@ -66,7 +66,8 @@ static int gpt_get_part(struct part *ret, int drive, int partition) {
     if (header.revision != 0x00010000) return NO_PARTITION;
 
     // parse the entries if reached here
-    if (partition >= header.number_of_partition_entries) return NO_PARTITION;
+    if ((uint32_t)partition >= header.number_of_partition_entries)
+        return NO_PARTITION;
 
     struct gpt_entry entry = {0};
     read(drive, &entry,
diff --git a/src/lib/real.c b/src/lib/real.c
index 71c243f5..8bfeb5f7 100644
--- a/src/lib/real.c
+++ b/src/lib/real.c
@@ -2,10 +2,7 @@
 #include <lib/real.h>
 
 __attribute__((naked))
-void rm_int(
-  uint8_t int_no,
-  struct rm_regs *out_regs,
-  struct rm_regs *in_regs) {
+void rm_int(uint8_t int_no, struct rm_regs *out_regs, struct rm_regs *in_regs) {
     asm (
         // Self-modifying code: int $int_no
         "mov al, byte ptr ss:[esp+4]\n\t"
@@ -110,4 +107,5 @@ void rm_int(
         // in_regs
         "7: .long 0\n\t"
     );
+    (void)int_no; (void)out_regs; (void)in_regs;
 }
diff --git a/src/lib/real.h b/src/lib/real.h
index dfdd6b76..545cbded 100644
--- a/src/lib/real.h
+++ b/src/lib/real.h
@@ -22,6 +22,6 @@ struct rm_regs {
     uint32_t eax;
 };
 
-void rm_int(uint8_t, struct rm_regs *, struct rm_regs *);
+void rm_int(uint8_t int_no, struct rm_regs *out_regs, struct rm_regs *in_regs);
 
 #endif
diff --git a/src/main.c b/src/main.c
index 373cc3c2..8f44f728 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,6 +2,15 @@ asm (
     ".section .entry\n\t"
     "xor dh, dh\n\t"
     "push edx\n\t"
+
+    // Zero out .bss
+    "xor al, al\n\t"
+    "lea edi, bss_begin\n\t"
+    "lea ecx, bss_end\n\t"
+    "lea edx, bss_begin\n\t"
+    "sub ecx, edx\n\t"
+    "rep stosb\n\t"
+
     "call main\n\t"
 );
 
@@ -31,7 +40,7 @@ refresh:
 
     print("Select an entry:\n\n");
 
-    size_t max_entries;
+    int max_entries;
     for (max_entries = 0; ; max_entries++) {
         if (config_get_entry_name(config_entry_name, max_entries, 1024) == -1)
             break;
@@ -79,16 +88,9 @@ refresh:
     }
 }
 
-extern symbol bss_begin;
-extern symbol bss_end;
-
 void main(int boot_drive) {
     struct file_handle f;
 
-    // Zero out .bss section
-    for (uint8_t *p = bss_begin; p < bss_end; p++)
-        *p = 0;
-
     // Initial prompt.
     init_vga_textmode();
 
diff --git a/src/protos/stivale.c b/src/protos/stivale.c
index 0c5ea3ef..13a6800d 100644
--- a/src/protos/stivale.c
+++ b/src/protos/stivale.c
@@ -50,8 +50,6 @@ void stivale_load(struct file_handle *fd, char *cmdline) {
 
     int ret;
 
-    print("stivale: %u-bit ELF file detected\n", bits);
-
     switch (bits) {
         case 64:
             ret = elf64_load_section(fd, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header));
@@ -59,8 +57,12 @@ void stivale_load(struct file_handle *fd, char *cmdline) {
         case 32:
             ret = elf32_load_section(fd, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header));
             break;
+        default:
+            panic("Not 32 nor 64 bit x86 ELF file.");
     }
 
+    print("stivale: %u-bit ELF file detected\n", bits);
+
     switch (ret) {
         case 1:
             panic("stivale: File is not a valid ELF.\n");
tab: 248 wrap: offon