src/utils.h

Mon, 14 Jan 2013 09:22:12 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 14 Jan 2013 09:22:12 +0000
changeset 118
feee84e0b3bf
parent 98
d1af20db5f02
child 143
0fa6f5a480a6
permissions
-rw-r--r--

More bus error fixes for FreeBee

I have fixed two more bus error handling bugs in FreeBee. First, the CPU core was executing the instruction regardless of whether a bus error occurs when fetching the opcode (which caused it to execute a bogus instruction in such cases). The other one was related to one of my previous fixes - the jump to the bus error vector was at the beginning of the main loop, so it wouldn't be called immediately after the bus error occurred if the timeslot expired, causing the return address to be off.

With these fixes, Unix now runs enough to get into userspace and run the install script (it is also possible to break out and get a shell prompt). However, many commands segfault semi-randomly (or more specifically, it seems that some child processes forked by the shell might be segfaulting before they can exec the command program), so installing the system isn't possible yet. I am not sure exactly what the bug is, but it seems to be related to some function in the shell returning null when the code calling it is assuming that it won't. What the function is, or why it is returning null, I'm not sure (the shell is built without the shared libc and is stripped, making identifying the function harder). I suspect that the function might be in libc, but that is hard to tell.

Author: Andrew Warkentin <andreww591 gmail com>

philpem@88 1 #ifndef _UTILS_H
philpem@88 2 #define _UTILS_H
philpem@71 3
philpem@89 4 #include <stdio.h>
philpem@89 5
philpem@71 6 #ifndef NDEBUG
philpem@71 7 /// Log a message to stderr
philpem@71 8 # define LOG(x, ...) do { fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0)
philpem@98 9 # define LOGS(x) do { fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); } while (0)
philpem@71 10 /// Log a message to stderr if 'cond' is true
philpem@71 11 # define LOG_IF(cond, x, ...) do { if (cond) fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0)
philpem@98 12 # define LOG_IFS(cond, x) do { if (cond) fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); } while (0)
philpem@71 13 #else
philpem@71 14 #define LOG(x, ...)
philpem@98 15 #define LOGS(x)
philpem@71 16 #define LOG_IF(cond, x, ...)
philpem@98 17 #define LOG_IFS(cond, x)
philpem@71 18 #endif
philpem@71 19
philpem@88 20 /// Get the number of elements in an array
philpem@88 21 #define NELEMS(x) (sizeof(x)/sizeof(x[0]))
philpem@88 22
philpem@71 23 #endif // _H_UTILS