Skip to content

Commit 4e4be65

Browse files
authored
Merge pull request #129 from assembler-0/Development
Development
2 parents 5f48598 + 584fb45 commit 4e4be65

File tree

12 files changed

+538
-430
lines changed

12 files changed

+538
-430
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ CMakeLists.txt
88
*build*
99
target
1010
.venv
11-
*cache*
11+
*cache*
12+
.amazonq

arch/x86_64/interrupts/Interrupts.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ asmlinkage void InterruptHandler(Registers* regs) {
9595
// If we get here, it's a serious kernel fault
9696
FaultContext ctx = {0};
9797
AnalyzeFault(regs, &ctx);
98-
PrintDetailedFaultInfo(&ctx, regs);RegistersDumpT dump = {0};
98+
PrintDetailedFaultInfo(&ctx, regs);
99+
RegistersDumpT dump = {0};
99100
DumpRegisters(&dump);
100101
// Override with fault context where applicable
101102
dump.rip = regs->rip;
@@ -116,6 +117,15 @@ asmlinkage void InterruptHandler(Registers* regs) {
116117
FaultContext ctx = {0};
117118
AnalyzeFault(regs, &ctx);
118119
PrintDetailedFaultInfo(&ctx, regs);
120+
RegistersDumpT dump = {0};
121+
DumpRegisters(&dump);
122+
// Override with fault context where applicable
123+
dump.rip = regs->rip;
124+
dump.cs = regs->cs;
125+
dump.rflags = regs->rflags;
126+
dump.rsp = regs->rsp;
127+
dump.ss = regs->ss;
128+
PrintRegisters(&dump);
119129
PanicFromInterrupt(ctx.fault_reason, regs);
120130
break;
121131
}
@@ -125,7 +135,15 @@ asmlinkage void InterruptHandler(Registers* regs) {
125135
char int_str[20], rip_str[20];
126136
itoa(regs->interrupt_number, int_str);
127137
htoa(regs->rip, rip_str);
128-
138+
RegistersDumpT dump = {0};
139+
DumpRegisters(&dump);
140+
// Override with fault context where applicable
141+
dump.rip = regs->rip;
142+
dump.cs = regs->cs;
143+
dump.rflags = regs->rflags;
144+
dump.rsp = regs->rsp;
145+
dump.ss = regs->ss;
146+
PrintRegisters(&dump);
129147
strcpy(panic_message, "Unhandled Exception #");
130148
strcat(panic_message, int_str);
131149
strcat(panic_message, " at ");

drivers/Vesa.c

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,34 @@ void VBEFillScreen(uint32_t color) {
147147
void VBEDrawRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t color) {
148148
if (!vbe_initialized) return;
149149

150-
for (uint32_t row = y; row < y + height && row < vbe_info.height; row++) {
151-
for (uint32_t col = x; col < x + width && col < vbe_info.width; col++) {
152-
VBEPutPixel(col, row, color);
150+
if (x >= vbe_info.width || y >= vbe_info.height) return;
151+
152+
// Clip
153+
if (width > vbe_info.width - x) width = vbe_info.width - x;
154+
if (height > vbe_info.height - y) height = vbe_info.height - y;
155+
if (width == 0 || height == 0) return;
156+
157+
uint32_t mapped = VBEMapColor(color);
158+
159+
uint8_t* fb = (uint8_t*)vbe_info.framebuffer;
160+
uint32_t pitch = vbe_info.pitch;
161+
162+
// Pattern buffer: 1 KiB = 256 pixels
163+
uint32_t pattern[256];
164+
for (uint32_t i = 0; i < 256; i++) pattern[i] = mapped;
165+
166+
uint64_t row_bytes = (uint64_t)width * 4u;
167+
168+
for (uint32_t r = 0; r < height; r++) {
169+
uint8_t* dst = fb + (uint64_t)(y + r) * pitch + (uint64_t)x * 4u;
170+
uint64_t remaining = row_bytes;
171+
while (remaining >= sizeof(pattern)) {
172+
FastMemcpy(dst, pattern, sizeof(pattern));
173+
dst += sizeof(pattern);
174+
remaining -= sizeof(pattern);
175+
}
176+
if (remaining) {
177+
FastMemcpy(dst, pattern, remaining);
153178
}
154179
}
155180
}
@@ -187,21 +212,40 @@ void VBEDrawChar(uint32_t x, uint32_t y, char c, uint32_t fg_color, uint32_t bg_
187212
return; // Character out of bounds
188213
}
189214

215+
// Clip early if entirely outside
216+
if (x >= vbe_info.width || y >= vbe_info.height) return;
217+
190218
const unsigned char* glyph = console_font[(unsigned char)c];
191219

220+
// Pre-map colors
221+
uint32_t fg = VBEMapColor(fg_color);
222+
uint32_t bg = VBEMapColor(bg_color);
223+
224+
uint32_t max_w = vbe_info.width;
225+
uint32_t max_h = vbe_info.height;
226+
192227
// Use the font dimensions from font.h
193228
for (int row = 0; row < FONT_HEIGHT; row++) {
229+
uint32_t py = y + (uint32_t)row;
230+
if (py >= max_h) break; // Outside vertical bounds
231+
194232
// Calculate which byte contains this row's data
195233
int byte_index = row * ((FONT_WIDTH + 7) / 8); // Number of bytes per row
196234

235+
// Start of the destination row in framebuffer
236+
uint32_t* dst_row = (uint32_t*)((uint8_t*)vbe_info.framebuffer + (uint64_t)py * vbe_info.pitch) + x;
237+
197238
for (int col = 0; col < FONT_WIDTH; col++) {
198-
int bit_position = 7 - (col % 8); // MSB first
239+
uint32_t px = x + (uint32_t)col;
240+
if (px >= max_w) break; // Outside horizontal bounds
199241

200-
if ((glyph[byte_index + (col / 8)] >> bit_position) & 1) {
201-
VBEPutPixel(x + col, y + row, fg_color);
242+
int bit_position = 7 - (col % 8); // MSB first
243+
uint8_t glyph_byte = glyph[byte_index + (col / 8)];
244+
if ((glyph_byte >> bit_position) & 1) {
245+
dst_row[col] = fg;
202246
} else {
203247
// Always draw background to ensure proper clearing
204-
VBEPutPixel(x + col, y + row, bg_color);
248+
dst_row[col] = bg;
205249
}
206250
}
207251
}
@@ -288,32 +332,62 @@ void VBEShowSplash(void) {
288332
if (!vbe_initialized) return;
289333

290334
for (unsigned int i = 0; i < num_splash_images; i++) { // Loop
291-
const uint32_t* image_data = (const uint32_t*)splash_images[i % num_splash_images];
292-
335+
const uint32_t* image_data = (const uint32_t*)splash_images[i];
336+
uint8_t* fb = (uint8_t*)vbe_info.framebuffer;
337+
// Copy entire scanlines at once instead of pixel-by-pixel
293338
for (uint32_t y = 0; y < vbe_info.height; y++) {
294-
for (uint32_t x = 0; x < vbe_info.width; x++) {
295-
VBEPutPixel(x, y, image_data[y * vbe_info.width + x]);
339+
// Calculate source and destination for this scanline
340+
const uint32_t* src = &image_data[y * vbe_info.width];
341+
uint8_t* dst = fb + (y * vbe_info.pitch);
342+
// Fast path: only when framebuffer uses 8:8:8 at 16/8/0 (0x00RRGGBB)
343+
int direct_compatible =
344+
(vbe_info.red_mask_size == 8 && vbe_info.red_field_position == 16) &&
345+
(vbe_info.green_mask_size == 8 && vbe_info.green_field_position == 8) &&
346+
(vbe_info.blue_mask_size == 8 && vbe_info.blue_field_position == 0);
347+
if (direct_compatible) {
348+
FastMemcpy(dst, src, vbe_info.width * 4);
349+
} else {
350+
// Fallback: map each pixel
351+
uint32_t* d32 = (uint32_t*)dst;
352+
const uint32_t* s32 = src;
353+
for (uint32_t x = 0; x < vbe_info.width; x++) {
354+
// Assume source is 0x00RRGGBB
355+
d32[x] = VBEMapColor(s32[x]);
356+
}
296357
}
297358
}
298359
}
299-
delay(700000000);
300360
}
301361
#endif
302362

303363
#ifndef VF_CONFIG_EXCLUDE_EXTRA_OBJECTS
304364
void VBEShowPanic(void) {
305365
if (!vbe_initialized) return;
306-
const uint32_t* image_data = (const uint32_t*)panic_images[0];
307-
uint8_t* fb = (uint8_t*)vbe_info.framebuffer;
308-
309-
// Copy entire scanlines at once instead of pixel-by-pixel
310-
for (uint32_t y = 0; y < vbe_info.height; y++) {
311-
// Calculate source and destination for this scanline
312-
const uint32_t* src = &image_data[y * vbe_info.width];
313-
uint8_t* dst = fb + (y * vbe_info.pitch);
314-
315-
// Copy entire scanline (width * 4 bytes) using optimized memcpy
316-
FastMemcpy(dst, src, vbe_info.width * 4);
366+
for (unsigned int i = 0; i < num_panic_images; i++) { // Loop
367+
const uint32_t* image_data = (const uint32_t*)panic_images[i];
368+
uint8_t* fb = (uint8_t*)vbe_info.framebuffer;
369+
// Copy entire scanlines at once instead of pixel-by-pixel
370+
for (uint32_t y = 0; y < vbe_info.height; y++) {
371+
// Calculate source and destination for this scanline
372+
const uint32_t* src = &image_data[y * vbe_info.width];
373+
uint8_t* dst = fb + (y * vbe_info.pitch);
374+
// Fast path: only when framebuffer uses 8:8:8 at 16/8/0 (0x00RRGGBB)
375+
int direct_compatible =
376+
(vbe_info.red_mask_size == 8 && vbe_info.red_field_position == 16) &&
377+
(vbe_info.green_mask_size == 8 && vbe_info.green_field_position == 8) &&
378+
(vbe_info.blue_mask_size == 8 && vbe_info.blue_field_position == 0);
379+
if (direct_compatible) {
380+
FastMemcpy(dst, src, vbe_info.width * 4);
381+
} else {
382+
// Fallback: map each pixel
383+
uint32_t* d32 = (uint32_t*)dst;
384+
const uint32_t* s32 = src;
385+
for (uint32_t x = 0; x < vbe_info.width; x++) {
386+
// Assume source is 0x00RRGGBB
387+
d32[x] = VBEMapColor(s32[x]);
388+
}
389+
}
390+
}
317391
}
318392
}
319393
#endif

kernel/core/Kernel.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ asmlinkage void KernelMain(const uint32_t magic, const uint32_t info) {
783783

784784
console.buffer = (volatile uint16_t*)VGA_BUFFER_ADDR;
785785

786-
ClearScreen();
787786
PrintKernelSuccess("System: VoidFrame Kernel - Version 0.0.2-development2 loaded\n");
788787
PrintKernel("Magic: ");
789788
PrintKernelHex(magic);
@@ -799,11 +798,9 @@ void KernelMainHigherHalf(void) {
799798

800799
// Initialize core systems
801800
PXS2();
802-
PrintKernelSuccess("System: Kernel initialization complete\n");
803-
PrintKernelSuccess("System: Initializing interrupts...\n");
804801

805802
#ifdef VF_CONFIG_SNOOZE_ON_BOOT
806-
ClearScreen();
803+
ClearScreen();
807804
Unsnooze();
808805
#endif
809806

@@ -813,6 +810,9 @@ void KernelMainHigherHalf(void) {
813810
ExecuteCommand("post");
814811
#endif
815812

813+
PrintKernelSuccess("System: Kernel initialization complete\n");
814+
PrintKernelSuccess("System: Initializing interrupts...\n");
815+
816816
sti();
817817

818818
while (1) {

kernel/core/Panic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ void __attribute__((noreturn)) KernelPanicHandler(const char* message, uint64_t
7474
int use_vbe_graphics = VBEIsInitialized();
7575

7676
if (use_vbe_graphics) {
77-
// Pure VBE graphics path - show panic image ONLY
7877
#ifndef VF_CONFIG_EXCLUDE_EXTRA_OBJECTS
7978
VBEShowPanic();
8079
#endif

kernel/etc/Console.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ static void ConsolePutcharAt(char c, uint32_t x, uint32_t y, uint8_t color) {
8686

8787
void ClearScreen(void) {
8888
SpinLock(&lock);
89-
9089
if (use_vbe) {
9190
VBEConsoleClear();
9291
} else {
@@ -172,17 +171,13 @@ void ConsoleSetColor(uint8_t color) {
172171
}
173172
}
174173

175-
void SystemLog(const char * str) {
176-
extern int IsVFSInitialized;
177-
if (!IsVFSInitialized) return;
178-
VfsWriteFile(SystemKernelLog, str, StringLength(str));
179-
}
180-
181174
void PrintKernel(const char* str) {
182175
if (!str) return;
183-
if (snooze) goto serial;
176+
if (snooze) {
177+
SerialWrite(str);
178+
return;
179+
}
184180
SpinLock(&lock);
185-
186181
if (use_vbe) {
187182
VBEConsolePrint(str);
188183
} else {
@@ -192,10 +187,8 @@ void PrintKernel(const char* str) {
192187
}
193188
console.color = original_color;
194189
}
195-
serial:
196190
SpinUnlock(&lock);
197191
SerialWrite(str);
198-
SystemLog(str);
199192
}
200193

201194
void PrintKernelChar(const char c) {
@@ -293,15 +286,6 @@ void PrintKernelSuccessF(const char* format, ...) {
293286
PrintKernelSuccess(buffer);
294287
}
295288

296-
void SystemLogF(const char * format, ... ) {
297-
char buffer[1024];
298-
va_list args;
299-
va_start(args, format);
300-
Format(buffer, sizeof(buffer), format, args);
301-
va_end(args);
302-
SystemLog(buffer);
303-
}
304-
305289
void SerialWriteF(const char* format, ...) {
306290
char buffer[1024];
307291
va_list args;

kernel/etc/Shell.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ static const HelpEntry system_cmds[] = {
177177
{"perf", "Show performance stats"},
178178
{"kill <pid>", "Terminate process"},
179179
{"memstat", "Show memory statistics"},
180-
{"lscpu", "List CPU features"}
180+
{"lscpu", "List CPU features"},
181+
{"snoozer <on/off>", "Snooze messages from PrintKernel"},
181182
};
182183

183184
static const HelpEntry file_cmds[] = {
@@ -330,6 +331,8 @@ static void MemstatHandler(const char * args) {
330331
PrintKernel("% fragmented, Used: ");
331332
PrintKernelInt(stats.used_physical_bytes / (1024*1024));
332333
PrintKernel("MB\n");
334+
PrintVMemStats();
335+
PrintHeapStats();
333336
}
334337

335338
static void LsPCIHandler(const char * args) {
@@ -1181,8 +1184,25 @@ static void PingHandler(const char* args) {
11811184
KernelFree(ip_str);
11821185
}
11831186

1184-
static const ShellCommand commands[] = {
1187+
static void SnoozeHandler(const char* args) {
1188+
char* status = GetArg(args, 1);
1189+
if (!status) {
1190+
PrintKernel("Usage: snooze <on/off>\n");
1191+
return;
1192+
}
1193+
if (FastStrCmp(status, "on") == 0) {
1194+
Snooze();
1195+
} else if (FastStrCmp(status, "off") == 0) {
1196+
Unsnooze();
1197+
} else {
1198+
PrintKernel("Usage: snooze <on/off>\n");
1199+
KernelFree(status);
1200+
return;
1201+
}
1202+
KernelFree(status);
1203+
}
11851204

1205+
static const ShellCommand commands[] = {\
11861206
{"help", HelpHandler},
11871207
{"ps", PSHandler},
11881208
{"sched", SchedHandler},
@@ -1232,6 +1252,7 @@ static const ShellCommand commands[] = {
12321252
{"regdump", RegDumpHandler},
12331253
{"post", POSTHandler},
12341254
{"ping", PingHandler},
1255+
{"snooze", SnoozeHandler},
12351256
};
12361257

12371258
void ExecuteCommand(const char* cmd) {

kernel/sched/MLFQ.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,7 @@ void VFCompositorRequestInit(const char * str) {
18001800
PrintKernelError("System: VFCompositor disabled in this build\n");
18011801
return;
18021802
#endif
1803+
Snooze();
18031804
static uint32_t cached_vfc_pid = 0;
18041805
if (cached_vfc_pid) {
18051806
MLFQProcessControlBlock* p = MLFQGetCurrentProcessByPID(cached_vfc_pid);

meson.build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ c_flags = [
4444
'-fstack-protector-strong',
4545
'-D_FORTIFY_SOURCE=2',
4646
'-fvisibility=hidden',
47-
'-Wall',
48-
'-Wpedantic',
49-
'-Wextra',
5047
]
5148

5249
cpp_flags = c_flags + [
@@ -203,7 +200,7 @@ vf_config_flags = [
203200
'-DVF_CONFIG_USE_ASTRA',
204201
'-DVF_CONFIG_USE_CERBERUS',
205202
# '-DVF_CONFIG_CERBERUS_VFS_LOGGING',
206-
'-DVF_CONFIG_CERBERUS_THREAT_REPORTING',
203+
# '-DVF_CONFIG_CERBERUS_THREAT_REPORTING',
207204
'-DVF_CONFIG_CERBERUS_STACK_PROTECTION',
208205
'-DVF_CONFIG_SCHED_MLFQ',
209206
# '-DVF_CONFIG_PROCINFO_AUTO_CLEANUP',

0 commit comments

Comments
 (0)