[SeaBIOS] [PATCH 2/2] Jump into extra stack for all regular real-mode software irq entry points.

Kevin O'Connor kevin at koconnor.net
Thu Jun 14 04:55:24 CEST 2012


Use the extra stack for all entry points.  This significantly reduces
the stack overhead of SeaBIOS on the caller's stack.

However, this patch will likely break any code that attempts to call a
regular real-mode software handler while in 16bit protected mode.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/romlayout.S |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/romlayout.S b/src/romlayout.S
index 3ef69bf..036fd31 100644
--- a/src/romlayout.S
+++ b/src/romlayout.S
@@ -435,9 +435,57 @@ irqentry_extrastack:
         iretw
 
         // Main entry point for interrupts with args
-        DECLFUNC irqentryarg
-irqentryarg:
-        ENTRY_ARG_ST
+        DECLFUNC irqentry_arg_extrastack
+irqentry_arg_extrastack:
+        cli
+        cld
+        pushw %ds               // Set %ds:%eax to space on ExtraStack
+        pushl %eax
+        movl $_datalow_seg, %eax
+        movl %eax, %ds
+        movl StackPos, %eax
+        subl $BREGS_size+8, %eax
+        popl BREGS_eax(%eax)    // Backup registers
+        popw BREGS_ds(%eax)
+        movl %edi, BREGS_edi(%eax)
+        movl %esi, BREGS_esi(%eax)
+        movl %ebp, BREGS_ebp(%eax)
+        movl %ebx, BREGS_ebx(%eax)
+        movl %edx, BREGS_edx(%eax)
+        movl %ecx, BREGS_ecx(%eax)
+        popl %ecx
+        movw %es, BREGS_es(%eax)
+        movl %esp, BREGS_size+0(%eax)
+        movzwl %sp, %esp
+        movw %ss, BREGS_size+4(%eax)
+        movl (%esp), %edx
+        movl %edx, BREGS_code(%eax)
+        movw 4(%esp), %dx
+        movw %dx, BREGS_flags(%eax)
+
+        movw %ds, %dx           // Setup %ss/%esp and call function
+        movw %dx, %ss
+        movl %eax, %esp
+        calll *%ecx
+
+        movl %esp, %eax         // Restore registers and return
+        movw BREGS_size+4(%eax), %ss
+        movl BREGS_size+0(%eax), %esp
+        popl %edx
+        popw %dx
+        pushw BREGS_flags(%eax)
+        pushl BREGS_code(%eax)
+        movl BREGS_edi(%eax), %edi
+        movl BREGS_esi(%eax), %esi
+        movl BREGS_ebp(%eax), %ebp
+        movl BREGS_ebx(%eax), %ebx
+        movl BREGS_edx(%eax), %edx
+        movl BREGS_ecx(%eax), %ecx
+        movw BREGS_es(%eax), %es
+        pushw BREGS_ds(%eax)
+        pushl BREGS_eax(%eax)
+        popl %eax
+        popw %ds
         iretw
 
         // Define an entry point for hardware interrupts.
@@ -458,7 +506,7 @@ irqentryarg:
         .global entry_\num
         entry_\num :
         pushl $ handle_\num
-        jmp irqentryarg
+        jmp irqentry_arg_extrastack
         .endm
 
         .macro DECL_IRQ_ENTRY_ARG num
-- 
1.7.10.2




More information about the SeaBIOS mailing list