mikaku / Fiwix

A UNIX-like kernel for the i386 architecture
https://www.fiwix.org
Other
401 stars 32 forks source link

Recent floating point math not compiling with tcc #73

Closed rick-masters closed 6 months ago

rick-masters commented 6 months ago

Fiwix doesn't compile with tcc now, ending with this error message:

tcc: error: undefined symbol '__fixdfdi'
make: *** [Makefile:70: all] Error 1

This is a result of adding floating point math recently using PAGE_HASH_PERCENTAGE. The floating point math can be avoided with a simple change like I've pasted below. It's not the greatest patch so if you have any suggestions let me know. This could also be changed with #ifdef __TINYC__. If you have a preference and/or would like me to submit a PR please let me know.

diff --git a/include/fiwix/config.h b/include/fiwix/config.h
index 9c55834..ff87afb 100644
--- a/include/fiwix/config.h
+++ b/include/fiwix/config.h
@@ -16,7 +16,7 @@
 #define NR_FLOCKS              (NR_PROCS * 5)  /* max. number of flocks */

 #define FREE_PAGES_RATIO       5       /* % minimum of free memory pages */
-#define PAGE_HASH_PERCENTAGE   0.1     /* % of hash buckets relative to the
+#define PAGE_HASH_PER_10K       10     /* % of % of hash buckets relative to the
                                           number of physical pages */
 #define BUFFER_PERCENTAGE      100     /* % of memory for buffer cache */
 #define BUFFER_HASH_PERCENTAGE 10      /* % of hash buckets relative to the
diff --git a/mm/memory.c b/mm/memory.c
index 2addf61..56a3a00 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -450,7 +450,7 @@ void mem_init(void)
 #endif /* CONFIG_KEXEC */

        /* the last one must be the page_table structure */
-       n = (kstat.physical_pages * PAGE_HASH_PERCENTAGE) / 100;
+       n = (kstat.physical_pages * PAGE_HASH_PER_10K) / 10000;
        n = MAX(n, 1);  /* 1 page for the hash table as minimum */
        n = MIN(n, 16); /* 16 pages for the hash table as maximum */
        page_hash_table_size = n * PAGE_SIZE;
mikaku commented 6 months ago

Oh, I'm sorry. I'm afraid I didn't take tcc into account when making this change. Your patch is fine, please submit your PR.

Just curious, why 10000 and not 1000?.

Thank you.

rick-masters commented 6 months ago

Just curious, why 10000 and not 1000?.

It is just arbitrary, but 10000 converts the current 0.1 to 10 which allows you to lower if necessary in the future.

mikaku commented 6 months ago

It is just arbitrary, but 10000 converts the current 0.1 to 10 which allows you to lower if necessary in the future.

Good point. Thank you.