[PATCH] More separation of C and assembly functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

-File arch/i86/kernel/process.c is now only C.
-Removed innecesary includes in several files.
-Fix arch/i86/kernel/Makefile to handle entry.c as
 an assembly file entry.S
-Small fixes in other files.

The kernel was compiled with BCC and tested with QEMU.
Code and data sizes were unchanged.

Juan
diff -Nur elks.orig/arch/i86/drivers/block/floppy.c elks/arch/i86/drivers/block/floppy.c
--- elks.orig/arch/i86/drivers/block/floppy.c	2015-04-26 11:39:15.000000000 -0500
+++ elks/arch/i86/drivers/block/floppy.c	2015-06-11 13:50:49.000000000 -0500
@@ -61,6 +61,7 @@
 #define FLOPPY_IRQ 6
 #define FLOPPY_DMA 2
 
+#include <linuxmt/config.h>
 #include <linuxmt/sched.h>
 #include <linuxmt/fs.h>
 #include <linuxmt/kernel.h>
@@ -70,7 +71,6 @@
 #include <linuxmt/fdreg.h>
 #include <linuxmt/fd.h>
 #include <linuxmt/errno.h>
-#include <linuxmt/config.h>
 
 #include <arch/dma.h>
 #include <arch/system.h>
diff -Nur elks.orig/arch/i86/drivers/block/Makefile elks/arch/i86/drivers/block/Makefile
--- elks.orig/arch/i86/drivers/block/Makefile	2015-04-26 11:39:15.000000000 -0500
+++ elks/arch/i86/drivers/block/Makefile	2015-06-11 14:41:33.000000000 -0500
@@ -33,8 +33,12 @@
 #########################################################################
 # Objects to be compiled.
 
-OBJS  = genhd.o doshd.o ll_rw_blk.o rd.o floppy.o directhd.o init.o \
-	sibo_ssd.o ssd_asm.o
+ifeq ($(CONFIG_ARCH_SIBO), y)
+OBJS  = init.o genhd.o ll_rw_blk.o rd.o sibo_ssd.o ssd_asm.o
+else
+OBJS  = init.o genhd.o ll_rw_blk.o rd.o doshd.o floppy.o directhd.o
+
+endif
 
 #########################################################################
 # Commands.
diff -Nur elks.orig/arch/i86/kernel/irqtab.c elks/arch/i86/kernel/irqtab.c
--- elks.orig/arch/i86/kernel/irqtab.c	2015-06-11 13:27:21.000000000 -0500
+++ elks/arch/i86/kernel/irqtab.c	2015-06-11 13:54:02.000000000 -0500
@@ -1,7 +1,11 @@
 #include <linuxmt/config.h>
-#include <arch/irq.h>
 #include <arch/asm-offsets.h>
 
+#ifndef S_SPLINT_S
+#asm
+
+	.text
+
 /*
  *	Easy way to store our kernel DS
  *
@@ -17,14 +21,8 @@
  *  the offset is constant per #define
  */
    #define stashed_ds       [0]
-#endif
 
-#ifndef S_SPLINT_S
-#asm
-
-	.text
-
-#ifndef CONFIG_ROMCODE
+#else
 /*
  Kernel is in RAM. Reserve space in the
  code segment to save the kernel DS
@@ -337,12 +335,12 @@
 #else
         seg     cs
 #endif        
-	mov	bx,stashed_ds		! Recover the data segment
+	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
+	mov	dx,ss		! Get current SS
+	mov	bp,sp		! Get current SP
 !
 !	Set up task switch controller
 !
@@ -450,13 +448,13 @@
 !
 was_trap:
 !
-!   Restore intr_count
+!	Restore intr_count
 !
-        dec     _intr_count
+	dec	_intr_count
 !
 !	Now look at rescheduling
 !
-        orb     ch,ch                   ! Schedule allowed ?
+	orb	ch,ch			! Schedule allowed ?
 	je	nosched			! No
 !	mov	bx,_need_resched	! Schedule needed
 !	cmp	bx,#0			!
@@ -506,8 +504,178 @@
 !
 	iret
 
+/*
+ *	tswitch();
+ *
+ *	This function can only be called with SS=DS=ES=kernel DS and
+ *	CS=kernel CS. SS:SP is the relevant kernel stack (IRQ's are
+ *	taken on 'current' kernel stack. Thus we don't need to arse about
+ *	with segment registers. The kernel isn't relocating.
+ *
+ *	To understand this you need to know how the compilers generate 8086
+ *	stack frames. Functions normally start
+ *
+ *	push bp		! Save callers BP
+ *	mov  bp,sp	! BP so we can use it to index registers
+ *
+ *	and end
+ *
+ *	mov sp,bp	! Fastest way to destroy local variables
+ *	pop bp		! Restore callers BP
+ *	ret		! Return address is top of stack now
+ *
+ *	tswitch() saves the "previous" task registers and state. It in effect
+ *	freezes a copy of the caller context. Then restores the "current"
+ *	context and returns running the current task.
+ *
+ * ELKS 0.76 7/1999  Fixed for ROMCODE-Version
+ * Christian Mardm?ller  (chm@xxxxxx)
+ */
+
+	.globl _tswitch
+
+_tswitch:
+	push	bp	! /* schedule()'s bp */
+	pushf
+	push	di
+	push	si
+	mov	bx,_previous
+	mov	TASK_KRNL_SP[bx],sp
+	mov	bx,_current
+	mov	sp,TASK_KRNL_SP[bx]
+	pop	si
+	pop	di
+	popf
+	pop	bp	! BP of schedule()
+	xor	ax,ax	! Set ax=0, as this may be fork() return from child
+	ret		! thus to caller of schedule()
+
+!
+!	System Call Vector
+!
+!	On entry we are on the wrong stack, DS, ES are wrong
+!
+	.globl	_syscall_int
+	.globl	_ret_from_syscall
+	.extern	_stack_check
+	.extern	_syscall
+
+!
+!	System calls enter here with ax as function and bx,cx,dx,di and si
+!	as parameters.
+!	syscall returns a value in ax
+!
+
+_syscall_int:
+!
+!	We know the process DS, we can discard it (indeed may change it)
+!
+!	Save si and free an index register
+!
+	push	si
+!
+!	Load kernel data segment
+!
+#ifdef CONFIG_ROMCODE
+	mov	si,#CONFIG_ROM_IRQ_DATA
+	mov	ds,si
+#else
+	seg	cs
+#endif
+	mov	ds,stashed_ds		! the org DS of kernel
+!
+!	At this point, the kernel stack is empty. Thus, we can push
+!       data into the kernel stack by writing directly to memory
+!
+	mov	si,_current		! pops SI from user stack and pushes
+	pop	TASK_KSTKT_SI[si]	! it directly into kernel stack
+!
+!	Stash user mode stack - needed for stack checking!
+!
+	mov	TASK_USER_SP[si],sp
+!
+!	load kernel stack pointer
+!
+	lea	sp,TASK_KSTKT_SI[si]
+!
+!	Finish switching to the right things
+!
+	mov	si,ds			! ds=es=ss
+	mov	es,si
+	mov	ss,si
+	cld
+!
+!	Stack is now right, we can take interrupts OK
+!
+	sti				! SI already on top of stack
+	push	di
+	push	dx
+	push	cx
+	push	bx
+
+#ifdef CONFIG_STRACE
+!
+!	strace(syscall#, params...)
+!
+	push	ax
+	call	_strace
+	pop	ax
+#endif
+!
+!	syscall(params...)
+!
+	push	ax
+	call	_stack_check
+	pop	ax
+	call	_syscall
+	push	ax
+	mov	bx,_current
+	mov	8[bx],#0
+	call	_sig_check
+	pop	ax
+	pop	bx
+	pop	cx
+	pop	dx
+	pop	di
+	pop	si
+#ifdef CONFIG_STRACE
+!
+!	ret_strace(retval)
+!
+	push	ax
+	call	_ret_strace
+	pop	ax
+#endif
+!
+!	Now mend everything
+!
+_ret_from_syscall:
+	cli
+	mov	bx,_current
+!
+!	At this point, the kernel stack is empty. Thus, there is no
+!       need to save the kernel stack pointer.
+!
+	mov	sp,TASK_USER_SP[bx]
+	mov	bx,TASK_USER_SS[bx]
+!
+!	User segment recovery
+!
+	mov	ds,bx
+	mov	es,bx
+	mov	ss,bx
+!
+!	return with error info.
+!
+	iret
+!
+!	Done.
+!
+
 	.data
 	.globl	_intr_count
+	.extern	_current
+	.extern	_previous
 
 	.even
 
diff -Nur elks.orig/arch/i86/kernel/Makefile elks/arch/i86/kernel/Makefile
--- elks.orig/arch/i86/kernel/Makefile	2015-04-26 11:39:15.000000000 -0500
+++ elks/arch/i86/kernel/Makefile	2015-06-11 14:45:25.000000000 -0500
@@ -19,7 +19,7 @@
 
 CLEANDEP	= 
 
-CLEANME 	= entry.c
+CLEANME 	= entry.S entry.s
 
 DEPEND  	= 
 
@@ -47,14 +47,17 @@
 #########################################################################
 # Commands.
 
+entry.o: entry.s
+	as86 -0 -u -o entry.o entry.s
+
 all:	akernel.a
 
 akernel.a: $(OBJS)
 	ar rcs akernel.a $(OBJS)
 
-entry.c: syscall.dat mkentry.sh
+entry.S: syscall.dat mkentry.sh
 	sh mkentry.sh > entry.tmp
-	mv entry.tmp entry.c
+	mv entry.tmp entry.S
 
 #########################################################################
 # Standard commands.
diff -Nur elks.orig/arch/i86/kernel/process.c elks/arch/i86/kernel/process.c
--- elks.orig/arch/i86/kernel/process.c	2015-06-11 13:27:31.000000000 -0500
+++ elks/arch/i86/kernel/process.c	2015-06-11 13:50:49.000000000 -0500
@@ -7,35 +7,9 @@
 #include <linuxmt/types.h>
 
 #include <arch/segment.h>
-#include <arch/asm-offsets.h>
-
-#ifdef CONFIG_ROMCODE
-
-#define stashed_ds	[0]
-
-#else
-
-#ifndef S_SPLINT_S
-#asm
-
-    .text
-
-/*
- *  This code is either in code segment or CONFIG_ROM_IRQ_DATA
- *  The CS-Code must always be placed in irqtab.c, because the
- *  linker doesnt store them in block.
- */
-
-    .extern stashed_ds
-
-/* and now code */
-
-#endasm
-#endif
-
-#endif
 
 extern int do_signal(void);
+extern void ret_from_syscall(void);
 
 void sig_check(void)
 {
@@ -43,177 +17,6 @@
         do_signal();
 }
 
-/*
- *	tswitch();
- *
- *	This function can only be called with SS=DS=ES=kernel DS and
- *	CS=kernel CS. SS:SP is the relevant kernel stack (IRQ's are
- *	taken on 'current' kernel stack. Thus we don't need to arse about
- *	with segment registers. The kernel isn't relocating.
- *
- *	To understand this you need to know how the compilers generate 8086
- *	stack frames. Functions normally start
- *
- *	push bp		! Save callers BP
- *	mov  bp,sp	! BP so we can use it to index registers
- *
- *	and end
- *
- *	mov sp,bp	! Fastest way to destroy local variables
- *	pop bp		! Restore callers BP
- *	ret		! Return address is top of stack now
- *
- *	tswitch() saves the "previous" task registers and state. It in effect
- *	freezes a copy of the caller context. Then restores the "current"
- *	context and returns running the current task.
- *
- * ELKS 0.76 7/1999  Fixed for ROMCODE-Version
- * Christian Mardm?ller  (chm@xxxxxx)
- */
-#ifndef S_SPLINT_S
-#asm
-	.text
-
-	.globl _tswitch
-
-_tswitch:
-	push bp		! /* schedule()'s bp */
-	pushf
-	push di
-	push si
-	mov bx,_previous
-	mov TASK_KRNL_SP[bx],sp
-	mov bx,_current
-	mov sp,TASK_KRNL_SP[bx]
-	pop si
-	pop di
-	popf
-	pop bp		! BP of schedule()
-	xor ax,ax	! Set ax=0, as this may be fork() return from child
-	ret		! thus to caller of schedule()
-
-!
-!	System Call Vector
-!
-!	On entry we are on the wrong stack, DS, ES are wrong
-!
-
-	.globl _syscall_int
-
-!
-!	System calls enter here with ax as function and bx,cx,dx,di and si
-!	as parameters.
-!	syscall returns a value in ax
-!
-
-_syscall_int:
-!
-!	We know the process DS, we can discard it (indeed may change it)
-!
-!	Save si and free an index register
-!
-        push si
-!
-!	Load kernel data segment
-!
-#ifdef CONFIG_ROMCODE
-        mov si,#CONFIG_ROM_IRQ_DATA
-        mov ds,si
-#else
-        seg cs
-#endif
-	mov ds,stashed_ds	! the org DS of kernel
-!
-!	At this point, the kernel stack is empty. Thus, we can push
-!       data into the kernel stack by writing directly to memory
-!
-	mov si,_current         ! pops SI from user stack and pushes
-	pop TASK_KSTKT_SI[si]   ! it directly into kernel stack
-!
-!	Stash user mode stack - needed for stack checking!
-!
-	mov TASK_USER_SP[si],sp
-!
-!	load kernel stack pointer
-!
-        lea sp,TASK_KSTKT_SI[si]
-!
-!	Finish switching to the right things
-!
-	mov si,ds	! ds=es=ss
-	mov es,si
-	mov ss,si
-	cld
-!
-!	Stack is now right, we can take interrupts OK
-!
-	sti             ! SI already on top of stack
-        push    di
-	push	dx
-	push	cx
-	push	bx
-
-#ifdef CONFIG_STRACE
-!
-!	strace(syscall#, params...)
-!
-	push ax
-	call _strace
-	pop ax
-#endif
-!
-!	syscall(params...)
-!
-	push	ax
-	call	_stack_check
-	pop	ax
-	call	_syscall
-	push	ax
-        mov     bx,_current
-        mov     8[bx],#0
-	call	_sig_check
-	pop	ax
-	pop	bx
-	pop	cx
-	pop	dx
-        pop     di
-	pop     si
-#ifdef CONFIG_STRACE
-!
-!	ret_strace(retval)
-!
-	push ax
-	call _ret_strace
-	pop ax
-#endif
-!
-!	Now mend everything
-!
-_ret_from_syscall:
-	cli
-	mov	bx,_current
-!
-!	At this point, the kernel stack is empty. Thus, there is no
-!       need to save the kernel stack pointer.
-!
-	mov 	sp,TASK_USER_SP[bx]
-	mov	bx,TASK_USER_SS[bx]
-!
-!	User segment recovery
-!
-	mov	ds,bx
-	mov	es,bx
-	mov	ss,bx
-!
-!	return with error info.
-!
-	iret
-!
-!	Done.
-!
-#endasm
-#endif
-
 int run_init_process(char *cmd, char *ar)
 {
     int num;
diff -Nur elks.orig/init/main.c elks/init/main.c
--- elks.orig/init/main.c	2015-06-11 13:27:31.000000000 -0500
+++ elks/init/main.c	2015-06-11 13:50:49.000000000 -0500
@@ -5,7 +5,6 @@
 #include <linuxmt/init.h>
 #include <linuxmt/mm.h>
 #include <linuxmt/sched.h>
-#include <linuxmt/timex.h>
 #include <linuxmt/types.h>
 #include <linuxmt/utsname.h>
 

[Index of Archives]     [Kernel]     [Linux ia64]     [DCCP]     [Linux for ARM]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux