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

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

 This patch implements:

1. Updated file "arch/i86/sibo/irqtab.c" to work the same way as
"arch/i86/kernel/irqtab.c". That is, simpler, faster, smaller and
easier to understand code.

2. Removed the following unused variables from irqtab.c:

    off_stashed_irq0
    seg_stashed_irq0
    stashed_ss
    stashed_sp
    stashed_irq
    bios_call_cnt
    stashed_di
    cs_tmp
    IRQdata_offs

There is a reduction of 16 bytes in code size.

Kernel was built with options Architecture SIBO, SSD disk support
enabled and network support disabled. The kernel built without errors,
but I have no means to test this architecture.

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

Greetings,

Juan
elksD.patch (application/octet-stream, 9.9 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 14:05:05.000000000 -0500
+++ elks/arch/i86/kernel/irqtab.c	2012-05-24 14:56:01.000000000 -0500
@@ -15,25 +15,11 @@
 
 #ifdef CONFIG_ROMCODE 
    #define stashed_ds       [0]
-   #define off_stashed_irq0 [2]
-   #define seg_stashed_irq0 [4]
-   #define stashed_ss       [6]
-   #define stashed_sp       [8]
-   #define stashed_irq      [10]  
-   #define bios_call_cnt    [12] 
-   /*      stashed_di       [14]   process.c */
-   /*      cs_tmp           [16]   process.c */
    /*      _our_ds          [18]   bios16.c  */
 
 #else
    #define stashed_ds       cseg_stashed_ds
-   #define seg_stashed_irq0 cseg_seg_stashed_irq0
-   #define off_stashed_irq0 cseg_off_stashed_irq0
 
-   #define stashed_ss       cseg_stashed_ss
-   #define stashed_sp       cseg_stashed_sp
-   #define stashed_irq      cseg_stashed_irq
-   #define bios_call_cnt    cseg_bios_call_cnt
 #endif
 
 #ifdef CONFIG_ROMCODE
@@ -55,26 +41,11 @@
 	.globl cseg_stashed_ds
 	.globl cseg_stashed_si
 	.globl cseg_sc_tmp
-	.globl IRQdata_offs
 
         .even
 
 cseg_stashed_ds:
 	.word	0
-cseg_seg_stashed_irq0:
-	.word	0
-cseg_off_stashed_irq0:
-	.word	0
-
-
-cseg_stashed_ss:
-	.word 	0
-cseg_stashed_sp:
-	.word 	0
-cseg_stashed_irq:
-	.word	0
-cseg_bios_call_cnt:
-	.word	0
 
 
 ;from process.c
@@ -83,8 +54,6 @@
 	.word 	0
 cseg_sc_tmp:
 	.word	0
-IRQdata_offs:
-        .word   0
 
 
 #endif	
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 14:05:05.000000000 -0500
+++ elks/arch/i86/sibo/irqtab.c	2012-05-24 15:04:57.000000000 -0500
@@ -4,52 +4,54 @@
 /*
  *	Easy way to store our kernel DS
  */
-#define stashed_ds       cseg_stashed_ds
-#define seg_stashed_irq0 cseg_seg_stashed_irq0
-#define off_stashed_irq0 cseg_off_stashed_irq0
-
-#define stashed_ss       cseg_stashed_ss
-#define stashed_sp       cseg_stashed_sp
-#define stashed_irq      cseg_stashed_irq
+
+/* moving variables from code segment to an extra segment
+/  CONFIG_ROM_IRQ_DATA for the ROM_CODE-Version
+/  ELKS 0.76 7/1999 Christian Mard”ller  ([email protected])
+/  */
+
+#ifdef CONFIG_ROMCODE
+   #define stashed_ds       [0]
+   /*      _our_ds          [18]   bios16.c  */
+
+#else
+   #define stashed_ds       cseg_stashed_ds
+
+#endif
+
+#ifdef CONFIG_ROMCODE
+ #define SEG_IRQ_DATA es
+#else
+ #define SEG_IRQ_DATA cs
+#endif
 
 #ifndef S_SPLINT_S
 #asm
+/* In ROM-Mode we must generate a physical 3th segment :-)
+/  The segmentaddress is given by CONFIG_ROM_IRQ_DATA,
+/  the offset is constant per #define
+/-------------------------------------------------------*/
+
+
 
+#ifndef CONFIG_ROMCODE
 	.globl	cseg_stashed_ds
 	.globl	cseg_stashed_si
 	.globl	cseg_sc_tmp
-	.globl	IRQdata_offs
 
         .even
 
 cseg_stashed_ds:
 	.word	0
 
-cseg_seg_stashed_irq0:
-	.word	0
-
-cseg_off_stashed_irq0:
-	.word	0
-
-cseg_stashed_ss:
-	.word 	0
-
-cseg_stashed_sp:
-	.word 	0
-
-cseg_stashed_irq:
-	.word	0
-
-; from process.c
+;from process.c
 
 cseg_stashed_si:
 	.word 	0
-
 cseg_sc_tmp:
 	.word	0
 
-IRQdata_offs:
-        .word   0
+#endif
 
 #endasm
 #endif
@@ -57,35 +59,43 @@
 void irqtab_init(void)
 {
 #ifndef S_SPLINT_S
-#asm				! disable psion hardware interrupt sources
-	mov	al, #0x00
+#asm
+
+; CS points to this kernel code segment
+; ES points to page 0  (interrupt table)
+; DS points to the irqdataseg (cs or CONFIG_ROM_IRQ_DATA)
+
+	mov	al, #0x00	! disable psion hardware interrupt sources
 	out	0x15, al
 	mov	al, #0x00
 	out	0x08, al
+        push ds
+        mov dx,ds      ;the original value
+        cli            ;just here
 
-	cli
-	mov	ax,ds
-	seg	cs
-	mov	stashed_ds,ax	! FIXME: code is not ROM-able
-	xor	ax,ax
+#ifdef CONFIG_ROMCODE
+        mov ax,#CONFIG_ROM_IRQ_DATA
 	mov	es,ax
+#endif
 
-	cli
-	push	ds
-	mov	ax, #0x0000	! change data segment
-	mov	ds, ax
+        seg SEG_IRQ_DATA
+	mov stashed_ds,ds
 
-	out	0x15, al	! memory protection
+        xor ax,ax
+        mov es,ax      ;intr table
 
+	out	0x15, al	! memory protection
 	mov	ax, cs
+	seg	es
 	mov	0x01e6, ax
 	mov	ax, #_irq0
+	seg	es
 	mov	0x01e4, ax
-
-	pop	ds
 #if 0
 	mov	ax, cs
 	mov	0x01c2, ax
+#endif
+#if 0
 	lea	ax,_irq0
 	seg	es
 	mov	[0xe4],ax
@@ -121,21 +131,22 @@
 	seg	es
 	mov	[0x12],ax
 	
-				! etc for the rest
 #endif
 
-				! Setup INT 0x80 (for syscall)
+! Setup INT 0x80 (for syscall)
 	lea	ax,_syscall_int
 	seg	es
 	mov	[512],ax
 	mov	ax,cs
 	seg	es
 	mov	[514],ax
+! Tidy up
 
-				! Tidy up
+	pop ds           ;the org segments
 	mov	ax,ds
 	mov	es,ax
 	sti
+
 #endasm
 #endif
 }	
@@ -166,31 +177,22 @@
 !	.globl	_irq13
 !	.globl	_irq14
 !	.globl	_irq15
-
 	.extern	_do_IRQ
 
 	.data
-
 	.extern	_cache_A1
 	.extern	_cache_21
 
 	.text 
 			
-!_irq0:
-!	push	ax
-!	mov	ax,#0
-!	br	_irqit
-
 _irq1:
 	push	ax
 	mov	ax,#1
 	br	_irqit
-
 _irq2:
 	push	ax
 	mov	ax,#2
 	br	_irqit
-
 _irq3:
 	push	ax
 	mov	ax,#3
@@ -205,184 +207,153 @@
 	push	ax
 	mov	ax,#5
 	br	_irqit
-
 _irq6:
 	push	ax
 	mov	ax,#6
 	br	_irqit
-
 _irq7:
 	push	ax
 	mov	ax,#7
 	br	_irqit
-
 _irq8:
 	push	ax
 	mov	ax,#8
 	br	_irqit
-
 _irq9:
 	push	ax
 	mov	ax,#9
 	br	_irqit
-
 _irq10:
 	push	ax
 	mov	ax,#10
 	br	_irqit
-
 _irq11:
 	push	ax
 	mov	ax,#11
 	jmp	_irqit
-
 _irq12:
 	push	ax
 	mov	ax,#12
 	jmp	_irqit
-
 _irq13:
 	push	ax
 	mov	ax,#13
 	jmp	_irqit
-
 _irq14:
 	push	ax
 	mov	ax,#14
 	jmp	_irqit
-
 _irq15:
 	push	ax
 	mov	ax,#15
 	jmp	_irqit
-
+!
+!
 !	Traps (we use IRQ 16->31 for these)
 !
 !	Currently not used so removed for space.
-
 #if 0
-
 	.globl	_div0
-
 _div0:
 	push	ax
 	mov	ax,#16
 	jmp	_irqit
 
 	.globl _dbugtrap
-
 _dbugtrap:
 	push	ax
 	mov	ax,#17
 	jmp	_irqit
 
 	.globl _nmi
-
 _nmi:
 	push	ax
 	mov	ax,#18
 	jmp	_irqit
 
 	.globl	_brkpt
-
 _brkpt:
 	push 	ax
 	mov	ax,#19
 	jmp	_irqit
 
 	.globl	_oflow
-
 _oflow:
 	push	ax
 	mov	ax,#20
 	jmp	_irqit
 
 	.globl	_bounds
-
 _bounds:
 	push	ax
 	mov	ax,#21
 	jmp	_irqit
 	
 	.globl	_invop
-
 _invop:
 	push	ax
 	mov	ax,#22
 	jmp	_irqit
 	
 	.globl _devnp
-
 _devnp:
 	push	ax
 	mov	ax,#23
 	jmp	_irqit
 
 	.globl	_dfault
-
 _dfault:
 	push	ax
 	mov	ax,#24
 	jmp	_irqit
-
-!
-!	trap 9 is reserved
-!
+;
+;	trap 9 is reserved
+;
 	.globl _itss
 _itss:
-
 	push	ax
 	mov	ax,#26
 	jmp	_irqit
 
 	.globl _nseg
-
 _nseg:
 	push	ax
 	mov	ax,#27
 	jmp	_irqit
 	
 	.globl _stkfault
-
 _stkfault:
 	push 	ax
 	mov	ax,#28
 	jmp	_irqit
 
 	.globl	_segovr
-
 _segovr:
 	push	ax
 	mov	ax,#29
 	jmp	_irqit
 	
 	.globl _pfault
-
 _pfault:
 	push	ax
 	mov	ax,#30
 	jmp	_irqit
-
-!
-!	trap 15 is reserved
-!
+;
+;	trap 15 is reserved
+;
 	.globl	_fpetrap
-
 _fpetrap:
 	push	ax
 	mov	ax,#32
 	jmp	_irqit
 
 	.globl	_algn
-
 _algn:
 	push	ax
 	mov	ax,#33
 	jmp	_irqit
 
-
 #endif
-
 !
 !	On entry CS:IP is all we can trust
 !
@@ -409,19 +380,18 @@
 !
 !
 	.globl	_irq0
-
 _irq0:
 !
 !	Save AX and load it with the IRQ number
 !
 	push	ax
 	xor	ax,ax
-	
 _irqit:
 !
 !	Save all registers
 !
-	cli		! Might not be disabled on an exception
+
+!	cli		! Might not be disabled on an exception
 	push	ds
 	push	es
 	push	bx
@@ -430,25 +400,23 @@
 	push	si
 	push	di
 	push	bp
+
 !
 !	Recover segments
 !
+#ifdef CONFIG_ROMCODE
+        mov bx,#CONFIG_ROM_IRQ_DATA
+        mov ds,bx
+#else
 	seg	cs
-	mov	stashed_irq,ax	! Save IRQ number
-	mov	ax,ss		! Get current SS
-	mov	bx,ax		! Save for later
-	seg	cs
-	mov	stashed_ss, ax	! Save SS:SP
-	mov	ax,sp
-	seg	cs
-	mov	stashed_sp, ax
-	seg	cs		! Recover the data segment
-	mov	ax,stashed_ds
-!
-!	Switch segments
-!
-	mov	ds,ax
-	mov	es,ax
+#endif
+	mov	bx,stashed_ds		! Recover the data segment
+	mov	ds,bx
+	mov	es,bx
+
+	mov	dx,ss			! Get current SS
+	mov	bp,sp			! Get current SP
+	movb	cl,bios_call_cnt_l
 !
 !	Set up task switch controller
 !
@@ -456,14 +424,13 @@
 !
 !	See where we were (BX holds the SS on entry)
 !
-	cmp	ax,bx		! SS = kernel SS ?
+	cmp	dx,bx		! SS = kernel SS ?
 	je	ktask		! Kernel - no work
 !
 !	User or BIOS etc
 !
-	mov	ax,bx
 	mov	bx,_current
-	cmp	ax,4[bx]	! entry ss = current->t_regs.ss?
+	cmp	dx,4[bx]	! entry ss = current->t_regs.ss?
 	je	utask		! Switch to kernel
 !
 !	Bios etc - switch to interrupt stack
@@ -474,43 +441,35 @@
 !
 !	User task. Extract kernel SP. (BX already holds current)
 !
-
 utask:
-	mov	ax,[bx]		! kernel stack ptr
-	mov	sp,ax		! switch to kernel stack
+	mov	sp,[bx]		! switch to kernel stack ptr
 	inc	ch		! Switch allowable
-	j	switched
-
-ktask:
 !
 !	In ktask state we have a suitable stack. It might be 
 !	better to use the intstack..
 !
-
 switched:
-	mov	ax,ds
-	mov	ss,ax		! Set SS: right
-!
-!	Put the old SS;SP on the top of the stack. We can not
+	mov	bx,ds
+	mov	ss,bx		! /* Set SS: right */
+ktask:
+! /*
+!	Put the old SS;SP on the top of the stack. We can't
 !	leave them in stashed_ss/sp as we could re-enter the
 !	routine on a reschedule.
-!
-	seg 	cs
-	push	stashed_sp
-	seg	cs
-	push	stashed_ss
+! */
+	push	bp		! push entry SP
+	push	dx		! push entry SS
 !
 !	We are on a suitable stack and cx says whether we can	
 !	switch afterwards. The C code will want to eat CX so
 !	we have to hide it
 !
+!
 !	The registers are now stored. Remember where
 !
 	mov	bp,sp
 	mov	_can_tswitch, ch
 	push	cx		! Save ch
-	seg	cs		! Recover the IRQ we saved
-	mov	ax,stashed_irq
 	push	ax		! IRQ for later
 	push	bp		! Register base
 	push	ax		! IRQ number
@@ -544,6 +503,12 @@
 	pop	ax	! stacked SS
 	pop	cx	! stacked SP
 	mov	bx,_current
+#ifdef CONFIG_ADVANCED_MM
+	mov ax, 4[bx]	! user ds
+	mov bp, sp
+	mov 12[bp], ax	! change the es in the stack
+	mov 14[bp], ax	! change the ds in the stack
+#endif
 	mov	[bx],sp
 	j	noschedpop
 	
@@ -556,7 +521,6 @@
 !
 !	Switch stacks to the interrupting stack
 !
-
 noschedpop:
 	mov	ss,ax
 	mov	sp,cx
@@ -576,17 +540,20 @@
 !	Iret restores CS:IP and F (thus including the interrupt bit)
 !
 	iret
-!
-!	Data.
-!
-	.data
 
+	.data
 	.globl	_can_tswitch
-
 _can_tswitch:
 	.byte 0
-	.zerow	256		! (was) 128 byte interrupt stack
 
+off_stashed_irq0_l:
+	.word	0
+seg_stashed_irq0_l:
+	.word	0
+bios_call_cnt_l:
+	.word	0
+
+	.zerow	256		! (was) 128 byte interrupt stack
 _intstack:
 
 #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.