Skip to content

Commit 2b04380

Browse files
committed
added diagnostic markers
1 parent 2a8c9e9 commit 2b04380

10 files changed

Lines changed: 243 additions & 71 deletions

File tree

src/ai/ai_model.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,18 @@ int ai_matmul_q16_16(const q16_16_t* a, const q16_16_t* b, q16_16_t* c, uint32_t
785785
}
786786

787787
void ai_model_init(void) {
788+
serial_write_string("DEBUG: ai_model_init starting...\n");
788789
uint32_t phys_start = (uint32_t)&_ai_model_start;
789790
uint32_t phys_end = (uint32_t)&_ai_model_end;
791+
792+
serial_write_string("DEBUG: AI Model range: ");
793+
serial_write_hex32(phys_start);
794+
serial_write_string(" - ");
795+
serial_write_hex32(phys_end);
796+
serial_write_string("\n");
797+
790798
if (phys_end <= phys_start) {
799+
serial_write_string("DEBUG: AI Model not found (size 0)\n");
791800
ai_mapped_base = 0;
792801
ai_mapped_size = 0;
793802
return;
@@ -797,20 +806,30 @@ void ai_model_init(void) {
797806
uint32_t offset = phys_start - aligned_phys;
798807
uint32_t total = offset + size;
799808
uint32_t page_count = (total + 0x3FFFFF) >> 22;
809+
810+
serial_write_string("DEBUG: Mapping AI Model pages: ");
811+
serial_write_hex32(page_count);
812+
serial_write_string("\n");
813+
800814
for (uint32_t i = 0; i < page_count; ++i) {
815+
if ((i % 10) == 0) serial_write_string(".");
801816
map_page_4mb(AI_MODEL_VIRT_BASE + (i << 22), aligned_phys + (i << 22), 0x3);
802817
}
818+
serial_write_string("\nDEBUG: AI Model pages mapped\n");
819+
803820
ai_mapped_base = (uint8_t*)(AI_MODEL_VIRT_BASE + offset);
804821
ai_mapped_size = size;
805822

823+
serial_write_string("DEBUG: Reading GGUF header...\n");
806824
gguf_header_t header;
807825
if (gguf_read_header(ai_mapped_base, &header)) {
808-
serial_write("GGUF OK\n");
826+
serial_write_string("DEBUG: GGUF OK\n");
809827
diag_log(DIAG_INFO, "gguf header ok");
810828
} else {
811-
serial_write("GGUF BAD\n");
829+
serial_write_string("DEBUG: GGUF BAD\n");
812830
diag_log(DIAG_ERROR, "gguf header invalid");
813831
}
832+
serial_write_string("DEBUG: ai_model_init finished\n");
814833
}
815834

816835
static int contains_word(const char* text, const char* word) {

src/arch/gdt.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ gdt_flush:
1313
jmp 0x08:flush_cs
1414
flush_cs:
1515
ret
16+
17+
; Simple macro for serial debug in assembly if needed,
18+
; but let's just use the segment load as proof of success.
19+

src/arch/pit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include "ports.h"
33

44
void pit_init(uint32_t frequency) {
5+
if (frequency == 0) frequency = 1;
56
uint32_t divisor = 1193180 / frequency;
7+
if (divisor == 0) divisor = 1;
68
outb(0x43, 0x36);
79
outb(0x40, (uint8_t)(divisor & 0xFF));
810
outb(0x40, (uint8_t)((divisor >> 8) & 0xFF));

src/boot.asm

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,32 @@ global _start
1111
extern kernel_main
1212

1313
_start:
14-
; Setup stack and call kernel_main
15-
mov esp, stack_top
14+
; Setup stack
15+
mov esp, stack_top
16+
17+
; Direct VGA test: '@' at top-left
18+
mov word [0xB8000], 0x0E40 ; '@' yellow on black
19+
20+
; Serial debug '!' to show we started
21+
mov dx, 0x3F8 + 5 ; LSR
22+
.wait_serial:
23+
in al, dx
24+
test al, 0x20
25+
jz .wait_serial
26+
mov dx, 0x3F8
27+
mov al, '!'
28+
out dx, al
29+
30+
; Serial debug 'A' to show we are about to call kernel_main
31+
mov dx, 0x3F8 + 5 ; LSR
32+
.wait_serial_A:
33+
in al, dx
34+
test al, 0x20
35+
jz .wait_serial_A
36+
mov dx, 0x3F8
37+
mov al, 'A'
38+
out dx, al
39+
1640
push ebx ; Pointer to Multiboot info
1741
push eax ; Multiboot magic number
1842
call kernel_main

src/cpu/isr.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ static registers_t* exception_handler(registers_t* regs) {
186186
}
187187

188188
static registers_t* irq0_handler(registers_t* regs) {
189+
static uint32_t ticks = 0;
190+
ticks++;
191+
if (ticks % 100 == 0) {
192+
serial_write_string("T"); // T for Tick
193+
}
189194
timer_handler();
190195
kswapd_tick();
191196
process_t* previous = 0;
@@ -220,6 +225,9 @@ void isr_init(void) {
220225
}
221226

222227
registers_t* isr_handler(registers_t* regs) {
228+
serial_write_string("DEBUG: ISR ");
229+
serial_write_hex32(regs->int_no);
230+
serial_write_string("\n");
223231
if (interrupt_handlers[regs->int_no]) {
224232
return interrupt_handlers[regs->int_no](regs);
225233
}
@@ -228,6 +236,7 @@ registers_t* isr_handler(registers_t* regs) {
228236

229237
registers_t* irq_handler(registers_t* regs) {
230238
uint32_t int_no = regs->int_no;
239+
// serial_write_string("I"); // Too noisy? Let's use it for now
231240
if (interrupt_handlers[int_no]) {
232241
regs = interrupt_handlers[int_no](regs);
233242
}

src/drivers/vga.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,26 @@ static void vga_write_at(const char* text, uint8_t color, uint8_t x, uint8_t y)
109109
}
110110

111111
static void wait_ticks(uint64_t ticks) {
112+
if (ticks == 0) return;
112113
uint32_t eflags;
113114
asm volatile("pushf; pop %0" : "=r"(eflags));
114115
if (!(eflags & 0x200)) {
115116
// Interrupts are disabled, use a smaller busy loop to avoid hangs
116-
for (uint64_t i = 0; i < ticks * 100000; ++i) {
117-
asm volatile("nop");
117+
// 1 tick @ 100Hz is 10ms. 1000000 NOPs is roughly a few ms on modern CPUs.
118+
for (uint64_t i = 0; i < ticks * 1000000; ++i) {
119+
asm volatile("pause"); // Use pause for better power/sync
118120
}
119121
return;
120122
}
121123
uint64_t start = timer_get_ticks();
122-
while ((timer_get_ticks() - start) < ticks) { }
124+
uint64_t timeout = 0;
125+
while ((timer_get_ticks() - start) < ticks) {
126+
asm volatile("pause");
127+
if (++timeout > 10000000) { // Safety break if timer never increments
128+
serial_write_string("WARNING: wait_ticks safety break triggered!\n");
129+
break;
130+
}
131+
}
123132
}
124133

125134
static void typewriter_vga(const char* text, uint8_t color, uint8_t x, uint8_t y) {

0 commit comments

Comments
 (0)