Skip to content

[NECV25] New IBRK exception handler, inclusion of DIVZERO and NMI interrupt handler, current NEC V25 config#2582

Merged
ghaerr merged 3 commits intoghaerr:masterfrom
swausd:master
Jan 17, 2026
Merged

[NECV25] New IBRK exception handler, inclusion of DIVZERO and NMI interrupt handler, current NEC V25 config#2582
ghaerr merged 3 commits intoghaerr:masterfrom
swausd:master

Conversation

@swausd
Copy link
Copy Markdown
Contributor

@swausd swausd commented Jan 17, 2026

This PR adds a NEC V25 specific exception handler discussed here #2575. If the exception occurres, it is caught by the handler and the triggering IO instruction is re-executed. There is also a new config option in config.h to enable/disable the output of an associated message.

Also some configuration changes for integrating XT-IDE and NE2000 cards in the same NEC V25 system and some cleanups are included..

swausd added 2 commits January 17, 2026 18:27
…d to 0x200

This is my current config for the NEC V25 ELKS system. The hardware now supports a simplified 8 bit ISA bus, so a XT-IDE card was added and the ATA driver integrated. The NE2000 NIC address had to be moved to 0x200 for not conflicting wiht the default XT-IDE setup. And some additional cleanup.
…ero and nmi interrupt handler

The NEC V25 microcontrollers integrated peripherals are memory mapped. To support mapping of IO from the also supported IO-address space to memory mapped address space the V25 has a special IO emulation mode using the NEC specific IBRK flag in the processors PSW (see the processors user guide). This emulation is not useful in an ISA bus environment. To prevent IBRK exceptions, the USER_FLAGS in process.c have to have bit 1 set to 1. A new exception handler was added with ibrk-necv25.c to catch situations where the emulation mode is activated unwanted. In this situatio the IO instruction is restarted.
The divzero and nmi interrupt handlers are now also integrated in the NEC V25 port.
@ghaerr
Copy link
Copy Markdown
Owner

ghaerr commented Jan 17, 2026

Nicely done, especially the IBRK handler setting IBRK to restart the instruction! Were you able to actually test that?

It seems the NECV25 doesn't increment IP and requires the IBRK handler to skip over the offending instruction, if IBRK not set in the handler? I suppose that'd be even harder, since it would require special decoding instructions to determine exactly what instruction was used for intended I/O...

Comment thread elks/include/arch/irq.h Outdated
void nmi_handler(int irq, struct pt_regs *regs);
#ifdef CONFIG_ARCH_NECV25
void ibrk_handler(int irq, struct pt_regs *regs);
#endif
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may remove this ifdef and just add a comment that ibrk_handler is NECV25 specific, to reduce ifdef overload. Same with lines 9,12,14 - even though N_IRQS would waste two bytes on non-V25 systems, it's cleaner to not have configuration-specific ifdefs in the header files unless really necessary.

Comment thread elks/arch/i86/kernel/ibrk-necv25.c Outdated
if (intr_count > 1 /*|| current->t_regs.ss == kernel_ds*/) {
struct uregs __far *sys_stack;
sys_stack = _MK_FP(regs->ss, regs->sp);
#if IBRK_VERBOSE_MODE == 1
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool handler showing exactly where the problem is, then restarting the instruction!

I would suggest a simpler ifdef here too, just #if IBRK_VERBOSE_MODE which will work when == 1 and not when == 0, since multiple modes won't be used. This method of using #if is used in lots of other ELKS kernel code also.

@swausd
Copy link
Copy Markdown
Contributor Author

swausd commented Jan 17, 2026

Nicely done,

With your support and the already prepared divzero handler, this was easy. So thank you very much for that!

especially the IBRK handler setting IBRK to restart the instruction! Were you able to actually test that?

Yes, I have tested it and it did work.

It seems the NECV25 doesn't increment IP and requires the IBRK handler to skip over the offending instruction, if IBRK not set in the handler?

Yes that's the special handling of the emulation mode. Otherwise I probably would have skipped the restart.

I prepare the changes you mentioned above and submit in just a minute...

@ghaerr
Copy link
Copy Markdown
Owner

ghaerr commented Jan 17, 2026

Looks fantastic! Thank you for this nice update, it's a pleasure working with you. I especially like the instruction restart on V25 I/O, very cool. I only wish the 8086 didn't increment IP before a DIV 0 fault (and then that decision reversed in later processors!).

@ghaerr ghaerr merged commit 50584b5 into ghaerr:master Jan 17, 2026
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