[PATCH 4 of 5] General improvements to arch dependent code

Juan Perez-Sanchez <[email protected]>
Newsgroups org.kernel.vger.linux-8086
Message-ID <CAD6VGuY5ppAxi=Lu9wb6ijvuRTjHrXN4NOhV6vRpdCES7UV1wQ@mail.gmail.com>
Hi,

 This patch corrects the following problems.

1. Fixed race condition where static variables "stashed_si" and
"sc_tmp" were used after reenabling interrupts.

2. Made the assembly function "syscall_int" faster, use less code size
and without the need to use the static variables "stashed_si" and
"sc_tmp".

3. Removed unused functions "save_regs" and "load_regs", and the now
unused variables "stashed_si" and "sc_tmp".

There is a reduction of 16 bytes in code size.

The kernel was built and the Image tested in qemu and dioscuri
emulators. Also tested in a ppro pc booting from floppy.

Greetings,

Juan
elksE.patch (application/octet-stream, 4.3 KB)
diff -Nurb elks.orig/arch/i86/kernel/irqtab.c elks/arch/i86/kernel/irqtab.c
--- elks.orig/arch/i86/kernel/irqtab.c	2012-05-24 16:58:24.000000000 -0500
+++ elks/arch/i86/kernel/irqtab.c	2012-05-24 17:41:07.000000000 -0500
@@ -39,23 +39,12 @@
 
 #ifndef CONFIG_ROMCODE
 	.globl cseg_stashed_ds
-	.globl cseg_stashed_si
-	.globl cseg_sc_tmp
 
         .even
 
 cseg_stashed_ds:
 	.word	0
 
-
-;from process.c
-
-cseg_stashed_si:
-	.word 	0
-cseg_sc_tmp:
-	.word	0
-
-
 #endif	
 	
 
diff -Nurb elks.orig/arch/i86/kernel/process.c elks/arch/i86/kernel/process.c
--- elks.orig/arch/i86/kernel/process.c	2012-05-11 13:26:27.000000000 -0500
+++ elks/arch/i86/kernel/process.c	2012-05-24 17:37:13.000000000 -0500
@@ -46,14 +46,10 @@
 #ifdef CONFIG_ROMCODE 
 
 #define stashed_ds	[0]
-#define stashed_si	[14]
-#define sc_tmp		[16]
 
 #else
 
 #define stashed_ds	cseg_stashed_ds
-#define stashed_si	cseg_stashed_si
-#define sc_tmp		cseg_sc_tmp
 
 #ifndef S_SPLINT_S
 #asm
@@ -67,8 +63,6 @@
  */
 
 	.extern	cseg_stashed_ds
-	.extern	cseg_stashed_si 	; Now in irqtab.c
-	.extern	cseg_sc_tmp
 
 /* and now code */
 
@@ -95,8 +89,6 @@
 #asm
 	.text
 
-#if 1	
-
 	.globl _tswitch
 
 _tswitch:
@@ -117,64 +109,9 @@
 	pop di
 	popf
 	pop bp		! BP of schedule()
-	xor ax,ax
-	ret
-
-#else
-
-	.globl _save_regs
-
-_save_regs:
-!
-!	Save the CPU registers (note: only need those which bcc would
-!	expect to be preserved through a function call)
-!	
-	pop ax		! Return address save
-	push bp		! /* schedule()'s bp */
-	pushf
-	push di
-	push si
-	push bx
-	push dx
-!
-!	Store KSP
-!
-	mov  bx,_current
-	mov  [bx],sp
-	push ax		! Return with the stack altered.
-	ret
-/*
- *	Unlike save_regs this does not return to the caller
- *	but to the caller's caller.
- */
-	.globl _load_regs
-
-_load_regs:
-!
-!	Recover KSP
-!	
-	mov bx,_current
-	mov ax,[bx]
-	mov sp,ax
-!
-!	Pull CPU state off the stack
-!
-	pop dx
-	pop bx
-	pop si
-	pop di
-	popf
-!
-!	Now we basically spoof the return code of schedule()
-!
-	pop bp		! BP of schedule()
-	mov sp,bp	! As schedule() would do on its return to get SP
-	pop bp		! Recover caller BP
 	xor ax,ax	! Set ax=0, as this may be fork() return from child
 	ret		! thus to caller of schedule()
 
-#endif
-	
 !
 !	System Call Vector
 !
@@ -193,67 +130,50 @@
 !
 !	We know the process DS, we can discard it (indeed may change it)
 !
-	cli
-
-        push ax
-
+!	Save si and free an index register
+!
+        push si
+!
+!	Load kernel data segment
+!
 #ifdef CONFIG_ROMCODE
-        mov ax,#CONFIG_ROM_IRQ_DATA
+        mov si,#CONFIG_ROM_IRQ_DATA
+        mov ds,si
 #else
-        mov ax,cs
+        seg cs
 #endif        
-
-        mov ds,ax
-        pop ax
-
-	mov sc_tmp,ax
-!
-!	Save si and free an index register
-!
-	mov stashed_si, si
-	mov si,bx
-
-	mov ax,stashed_ds
-	mov ds,ax            ;the org DS of kernel
-
+	mov ds,stashed_ds	! the org DS of kernel
 !
 !	Find our TCB
 !
-	mov bx,_current
+	mov si,_current
+	mov si,[si]		! pops si and
+        pop -2[si]		! save si in kernel stack
 !
 !	Stash user mode stack - needed for stack checking!
 !
-	mov ax,sp
-	mov 2[bx],ax
+	mov si,_current
+	mov 2[si],sp
+!
+!	load kernel stack pointer
+!
+	mov sp,[si]
+	sub sp,#2
 !
 !	Finish switching to the right things
 !
-	mov ax,[bx]	! kernel stack pointer
-	mov sp,ax
-	mov ax,ds	! ds=es=ss
-	mov es,ax
-	mov ss,ax
+	mov si,ds	! ds=es=ss
+	mov es,si
+	mov ss,si
 	cld
 !
 !	Stack is now right, we can take interrupts OK
 !
-	sti
-#ifdef CONFIG_ROMCODE
-        mov ax,#CONFIG_ROM_IRQ_DATA
-#else
-        mov ax,cs
-#endif        
-        mov ds,ax
-        
-	mov     ax, stashed_si
-	push    ax              ! push si
+	sti             ! SI already on top of stack
         push    di
 	push	dx
 	push	cx
-	push	si		! saved bx
-	mov	ax,sc_tmp	! restore ax
-        push es
-        pop  ds            ;orig kernel ds
+	push	bx
 
 #ifdef CONFIG_STRACE
 !
diff -Nurb elks.orig/arch/i86/sibo/irqtab.c elks/arch/i86/sibo/irqtab.c
--- elks.orig/arch/i86/sibo/irqtab.c	2012-05-24 16:58:24.000000000 -0500
+++ elks/arch/i86/sibo/irqtab.c	2012-05-24 17:41:57.000000000 -0500
@@ -36,21 +36,12 @@
 
 #ifndef CONFIG_ROMCODE
 	.globl	cseg_stashed_ds
-	.globl	cseg_stashed_si
-	.globl	cseg_sc_tmp
 
         .even
 
 cseg_stashed_ds:
 	.word	0
 
-;from process.c
-
-cseg_stashed_si:
-	.word 	0
-cseg_sc_tmp:
-	.word	0
-
 #endif
 
 #endasm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.