-
Notifications
You must be signed in to change notification settings - Fork 1
Development #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "Panic.h" | ||
#include "Kernel.h" | ||
#include "Io.h" | ||
|
||
void __attribute__((noreturn)) Panic(const char* message) { | ||
|
||
asm volatile("cli"); | ||
|
||
ClearScreen(); | ||
CurrentLine = 0; | ||
CurrentColumn = 0; | ||
|
||
PrintKernel("[----KERNEL PANIC----]\n"); | ||
PrintKernel(message); | ||
PrintKernel("\n\nSystem halted.\n"); | ||
|
||
while(1) { | ||
asm volatile("hlt"); | ||
} | ||
} | ||
|
||
void __attribute__((noreturn)) PanicWithCode(const char* message, uint64_t error_code) { | ||
asm volatile("cli"); | ||
|
||
ClearScreen(); | ||
CurrentLine = 0; | ||
CurrentColumn = 0; | ||
|
||
PrintKernel("[----KERNEL PANIC----]\n"); | ||
PrintKernel(message); | ||
PrintKernel("\nError Code: "); | ||
PrintKernelHex(error_code); | ||
PrintKernel(" -- Not handled"); | ||
PrintKernel("\n\nSystem halted.\n"); | ||
|
||
while(1) { | ||
asm volatile("hlt"); | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||||||
#ifndef PANIC_H | ||||||||||||||||||||||||||||||||
#define PANIC_H | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
#include "stdint.h" | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
// Panic function - never returns | ||||||||||||||||||||||||||||||||
void __attribute__((noreturn)) Panic(const char* message); | ||||||||||||||||||||||||||||||||
void __attribute__((noreturn)) PanicWithCode(const char* message, uint64_t error_code); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
// Assert macro | ||||||||||||||||||||||||||||||||
#define ASSERT(condition) \ | ||||||||||||||||||||||||||||||||
do { \ | ||||||||||||||||||||||||||||||||
if (!(condition)) { \ | ||||||||||||||||||||||||||||||||
Panic("Assertion failed: " #condition " at " __FILE__ ":" __LINE__); \ | ||||||||||||||||||||||||||||||||
} \ | ||||||||||||||||||||||||||||||||
} while(0) | ||||||||||||||||||||||||||||||||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix ASSERT macro stringification of LINE. The Apply this fix to properly stringify the line number: -#define ASSERT(condition) \
- do { \
- if (!(condition)) { \
- Panic("Assertion failed: " #condition " at " __FILE__ ":" __LINE__); \
- } \
- } while(0)
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+#define ASSERT(condition) \
+ do { \
+ if (!(condition)) { \
+ Panic("Assertion failed: " #condition " at " __FILE__ ":" TOSTRING(__LINE__)); \
+ } \
+ } while(0) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential truncation of error code in PrintKernelHex call.
The function passes a
uint64_t error_code
toPrintKernelHex
which accepts anint
parameter. This will truncate high 32 bits of the error code on 64-bit systems.Consider either:
PrintKernelHex
to acceptuint64_t
PrintKernelHex64
function🤖 Prompt for AI Agents