Skip to content

Conversation

@ghaerr
Copy link
Owner

@ghaerr ghaerr commented Dec 29, 2025

During testing of the CONFIG_TIMER_INT1C in #2553 using emu86, a number of problematic situations were found that caused kernel startup to fail and noted. The reasons for these issues were finally found, and are fixed in this PR.

The following enhancements and fixes are included:

  • The previous setsp function call was problematic since it changes SP, but the compiler was emitting ADD $2,SP instructions after the function call to clean up the stack, causing endless hard-to-find problems. An ASM macro is now used.
  • int3 is now also a macro, useful for tracing in emu86.
  • The majority of the kernel startup in kernel_start was moved to far_kernel_start which is now released as available free memory after kernel startup.
  • Chlynging the stack pointer midway through kernel initialization proved problematic, since there's no way to inform the compiler of such nefarious activities. Now, the startup interrupt stack is switched to an unused task stack just after the task arrays are allocated, and then only switched to the idle stack immediately before the idle task runs, in another function. This gets around ongoing issues compiler-generated optimized code doing something one wouldn't think of.
  • At startup, the cpu FLAGS register is displayed, showing potential propblems with setup.S code inadvertantly enabling interrupts. It seems interrupts may still be inadvertently enabled during certain CPU processer identification code execution. Interrupts are now explicitly disabled immediately after the FLAG word display since startup is using the kernel interrupt stack.
  • It was found that printk is using a large amount of stack, which could (and sometimes did) cause stack overflow on the 160-byte idle task or (larger) 512-byte interrupt stack. This is now fixed through the use of static variables in printk routines, making its use much cleaner for debugging issues that might have involved the stack without knowing it.
  • The funny business of having to have irq.c compiled using -fno-defer-pop is now removed, since the ultimate issue was related to kernel stack startup issues discussed above.
  • The IRQ 0 timer interrupt bottom half routine timer_bh is now only enabled late in kernel initialization, since the timer bottom half could otherwise interfere with kernel startup by assuming the system is fully operational when run. It is now enabled immediately before the idle task main loop.
  • ps is added as a valid login, for quick system testing and observation without logging in.

Tested on QEMU and EMU86 under normal and INT 1C configurations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants