File arch/i86/mm/segment.c contained assembly functions _get_cs and _get_ds, and the unused functions _get_es and _get_ss. The functions returned the kernel code segment, kernel data segment etc. These were simply replaced with global variables kernel_cs and kernel_ds and initialized at boot time. This required changes in many files. File arch/i86/mm/segment.c was left blank and reference to it in the Makefile removed. Files arch/i86/kernel/irqtab.c and arch/i86/sibo/irqtab.c were modified to become all assembly files. Remove warnings in file net/ipv4/af_inet.c. Code size was reduced by 48 bytes and bss size increased by 8 bytes. Juan
diff -Nur elks.orig/arch/i86/boot/crt0.S elks/arch/i86/boot/crt0.S --- elks.orig/arch/i86/boot/crt0.S 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/boot/crt0.S 2015-04-30 17:01:30.000000000 -0500 @@ -54,6 +54,9 @@ ! End cleaning BSS + mov _kernel_cs, cs + mov _kernel_ds, ds + #ifndef CONFIG_ROMCODE mov ss,dx ! in ROMCODE stack is ready placed mov sp,#(_task + TASK_KSTKTOP - 10) @@ -81,6 +84,8 @@ .globl __endtext .globl __enddata .globl __endbss + .extern _kernel_cs + .extern _kernel_ds .extern _task __endtext: diff -Nur elks.orig/arch/i86/drivers/char/mem.c elks/arch/i86/drivers/char/mem.c --- elks.orig/arch/i86/drivers/char/mem.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/drivers/char/mem.c 2015-04-30 17:03:53.000000000 -0500 @@ -196,11 +196,11 @@ return 0; case MEM_GETCS: - i = (char *) get_cs(); + i = (char *) kernel_cs; put_user((unsigned short int)i, (void *)arg); return 0; case MEM_GETDS: - i = (char *) get_ds(); + i = (char *) kernel_ds; put_user((unsigned short int)i, (void *)arg); return 0; case MEM_GETUSAGE: diff -Nur elks.orig/arch/i86/drivers/char/meta.c elks/arch/i86/drivers/char/meta.c --- elks.orig/arch/i86/drivers/char/meta.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/drivers/char/meta.c 2015-04-30 17:05:34.000000000 -0500 @@ -102,7 +102,7 @@ #if 0 verified_memcpy_tofs(driver->udd_data, buff, BLOCK_SIZE); /* FIXME FIXME */ - fmemcpy(driver->udd_task->mm.dseg, driver->udd_data, get_ds(), + fmemcpy(driver->udd_task->mm.dseg, driver->udd_data, kernel_ds, buff, 1024); #endif } @@ -128,7 +128,7 @@ #if 0 verified_memcpy_fromfs(buff, driver->udd_data, BLOCK_SIZE); /* FIXME FIXME */ - fmemcpy(get_ds(), buff, driver->udd_task->mm.dseg, + fmemcpy(kernel_ds, buff, driver->udd_task->mm.dseg, driver->udd_data, 1024); #endif } diff -Nur elks.orig/arch/i86/drivers/char/tcpdev.c elks/arch/i86/drivers/char/tcpdev.c --- elks.orig/arch/i86/drivers/char/tcpdev.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/drivers/char/tcpdev.c 2015-04-30 17:06:51.000000000 -0500 @@ -64,8 +64,6 @@ int tcpdev_inetwrite(char *data, unsigned int len) { - __u16 ds; - debug2("TCPDEV: inetwrite( %p, %u )\n",data,len); if (len > TCPDEV_OUTBUFFERSIZE) return -EINVAL; /* FIXME: make sure this never happens */ @@ -73,8 +71,7 @@ down(&bufout_sem); /* Copy the data to the buffer */ - ds = get_ds(); - fmemcpy(ds, (__u16) tdout_buf, ds, (__u16) data, (__u16) len); + fmemcpy(kernel_ds, (__u16) tdout_buf, kernel_ds, (__u16) data, (__u16) len); tdout_tail = len; wake_up(&tcpdevq); debug("TCPDEV: inetwrite() returning\n"); diff -Nur elks.orig/arch/i86/kernel/irqtab.c elks/arch/i86/kernel/irqtab.c --- elks.orig/arch/i86/kernel/irqtab.c 2015-05-05 00:32:03.000000000 -0500 +++ elks/arch/i86/kernel/irqtab.c 2015-05-04 13:21:51.000000000 -0500 @@ -66,27 +66,22 @@ popf pushf jmp ax -#endasm -#endif - -void irqtab_init(void) -{ -#ifndef S_SPLINT_S -#asm ; CS points to this kernel code segment ; DS points to page 0 (interrupt table) ; ES points to the kernel data segment - cli - + .globl _irqtab_init +_irqtab_init: + cli + mov bx,ds #ifdef CONFIG_ROMCODE mov ax,#CONFIG_ROM_IRQ_DATA mov ds,ax #else seg cs -#endif +#endif mov stashed_ds,bx mov es,bx @@ -127,17 +122,11 @@ mov ds,bx ;the original value just here sti - -#endasm -#endif -} - + ret + /* * IRQ and IRQ return paths for Linux 8086 */ - -#ifndef S_SPLINT_S -#asm ! ! Other IRQs (see IRQ 0 at the bottom for the ! main code). @@ -471,7 +460,7 @@ a5: jmp a6 a6: outb 0x20,al ! Ack on primary controller ! -! And a trap does no hardware work +! And a trap does no hardware work ! was_trap: ! diff -Nur elks.orig/arch/i86/kernel/process.c elks/arch/i86/kernel/process.c --- elks.orig/arch/i86/kernel/process.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/kernel/process.c 2015-04-30 17:26:25.000000000 -0500 @@ -121,7 +121,7 @@ mov ds,si #else seg cs -#endif +#endif mov ds,stashed_ds ! the org DS of kernel ! ! At this point, the kernel stack is empty. Thus, we can push @@ -276,8 +276,8 @@ t = find_empty_process(); - t->t_regs.cs = get_cs(); - t->t_regs.ds = t->t_regs.ss = get_ds(); /* Run in kernel space */ + t->t_regs.cs = kernel_cs; + t->t_regs.ds = t->t_regs.ss = kernel_ds; /* Run in kernel space */ arch_build_stack(t, addr); } diff -Nur elks.orig/arch/i86/kernel/system.c elks/arch/i86/kernel/system.c --- elks.orig/arch/i86/kernel/system.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/kernel/system.c 2015-04-30 17:31:07.000000000 -0500 @@ -41,19 +41,19 @@ * Fill in the MM numbers - really ought to be in mm not kernel ? */ -#ifndef CONFIG_ARCH_SIBO +#ifndef CONFIG_ARCH_SIBO *end = (seg_t)(setupw(0x2a) << 6 - RAM_REDUCE); /* XXX plac: free root ram disk */ - *start = get_ds(); + *start = kernel_ds; *start += ((unsigned int) (_endbss+15)) >> 4; #else *end = (basmem)<<6; - *start = get_ds(); + *start = kernel_ds; *start += (unsigned int) 0x1000; #endif diff -Nur elks.orig/arch/i86/mm/init.c elks/arch/i86/mm/init.c --- elks.orig/arch/i86/mm/init.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/mm/init.c 2015-04-30 17:34:03.000000000 -0500 @@ -26,6 +26,7 @@ */ char cpuid[17], proc_name[17]; +__u16 kernel_cs, kernel_ds; void setup_mm(void) { @@ -67,10 +68,10 @@ "Kernel text at %x:0000, data at %x:0000 \n", (unsigned)_endtext, (unsigned)_enddata, (unsigned)_endbss - (unsigned)_enddata, - get_cs(), get_ds()); + kernel_cs, kernel_ds); /* - * This computes the 640K - _endbss + * This computes the 640K - _endbss */ #ifdef CONFIG_ARCH_SIBO @@ -83,7 +84,7 @@ #endif - memstart = ((long) get_ds()) << 4; + memstart = ((long) kernel_ds) << 4; memstart += (unsigned int) _endbss + 15; printk("%d K of memory for user processes.\n", diff -Nur elks.orig/arch/i86/mm/segment.c elks/arch/i86/mm/segment.c --- elks.orig/arch/i86/mm/segment.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/mm/segment.c 2015-04-30 18:23:52.000000000 -0500 @@ -1,32 +0,0 @@ -/* - * Fetch segment registers - */ - -#include <arch/segment.h> - -#ifndef S_SPLINT_S -#asm - - .globl _get_cs - .globl _get_ds - .globl _get_es - .globl _get_ss - -_get_cs: - mov ax, cs - ret - -_get_ds: - mov ax, ds - ret - -_get_es: - mov ax, es - ret - -_get_ss: - mov ax, ss - ret - -#endasm -#endif diff -Nur elks.orig/arch/i86/mm/user.c elks/arch/i86/mm/user.c --- elks.orig/arch/i86/mm/user.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/arch/i86/mm/user.c 2015-04-30 17:37:14.000000000 -0500 @@ -15,7 +15,7 @@ /* * Kernel tasks can always access */ - if (get_ds() == currentp->t_regs.ds) + if (kernel_ds == currentp->t_regs.ds) return 0; /* @@ -143,7 +143,7 @@ i++; return i; -} +} #endif diff -Nur elks.orig/arch/i86/sibo/irqtab.c elks/arch/i86/sibo/irqtab.c --- elks.orig/arch/i86/sibo/irqtab.c 2015-05-05 00:32:03.422279118 -0500 +++ elks/arch/i86/sibo/irqtab.c 2015-05-04 13:23:57.000000000 -0500 @@ -65,18 +65,14 @@ popf pushf jmp ax -#endasm -#endif - -void irqtab_init(void) -{ -#ifndef S_SPLINT_S -#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) + .globl _irqtab_init +_irqtab_init: + mov al, #0x00 ! disable psion hardware interrupt sources out 0x15, al mov al, #0x00 @@ -156,17 +152,11 @@ mov dx,ds ;the original value mov es,dx ;just here sti + ret -#endasm -#endif -} - /* * IRQ and IRQ return paths for Linux 8086 */ - -#ifndef S_SPLINT_S -#asm ! ! Other IRQs (see IRQ 0 at the bottom for the ! main code). @@ -423,7 +413,7 @@ btask: mov sp,#_intstack ! -! In ktask state we have a suitable stack. It might be +! In ktask state we have a suitable stack. It might be ! better to use the intstack.. ! ktask: diff -Nur elks.orig/fs/buffer.c elks/fs/buffer.c --- elks.orig/fs/buffer.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/fs/buffer.c 2015-04-30 17:43:18.000000000 -0500 @@ -264,7 +264,7 @@ bh->b_uptodate = 0; bh->b_dev = dev; bh->b_blocknr = block; - bh->b_seg = get_ds(); + bh->b_seg = kernel_ds; return bh; } @@ -287,7 +287,7 @@ } /* - * bforget() is like brelse(), except it removes the buffer + * bforget() is like brelse(), except it removes the buffer * data validity. */ #if 0 @@ -398,7 +398,7 @@ */ debug2("mapping buffer %d (%d)\n", bh->b_num, bh->b_mapcount); - if (bh->b_data || bh->b_seg != get_ds()) { + if (bh->b_data || bh->b_seg != kernel_ds) { #ifdef DEBUG if (!bh->b_mapcount) { @@ -423,7 +423,7 @@ bh->b_data = bufmem[i]; bh->b_mapcount++; if(bh->b_uptodate) - fmemcpy(get_ds(), (__u16) bh->b_data, _buf_ds, + fmemcpy(kernel_ds, (__u16) bh->b_data, _buf_ds, (__u16) (bh->b_num * BLOCK_SIZE), BLOCK_SIZE); debug3("BUFMAP: Buffer %d (block %d) mapped into L1 slot %d.\n", bh->b_num, bh->b_blocknr, i); @@ -443,7 +443,7 @@ bufmem_map[i]->b_num); /* Now unmap it */ fmemcpy(_buf_ds, (__u16) (bufmem_map[i]->b_num * BLOCK_SIZE), - get_ds(), (__u16) bufmem_map[i]->b_data, BLOCK_SIZE); + kernel_ds, (__u16) bufmem_map[i]->b_data, BLOCK_SIZE); bufmem_map[i]->b_data = 0; bufmem_map[i] = 0; break; diff -Nur elks.orig/fs/exec.c elks/fs/exec.c --- elks.orig/fs/exec.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/fs/exec.c 2015-04-30 17:45:07.000000000 -0500 @@ -109,7 +109,7 @@ effuid = pinode->i_uid; effgid = pinode->i_gid; - tregs->ds = get_ds(); + tregs->ds = kernel_ds; result = filp->f_op->read(pinode, filp, &mh, sizeof(mh)); /*tregs->ds = ds;*/ } @@ -127,7 +127,7 @@ #ifdef CONFIG_EXEC_ELKS if ((unsigned int) mh.hlen == 0x30) { /* BIG HEADER */ - /*tregs->ds = get_ds();*/ + /*tregs->ds = kernel_ds;*/ result = filp->f_op->read(inode, filp, &msuph, sizeof(msuph)); /*tregs->ds = ds;*/ if (result != sizeof(msuph)) { diff -Nur elks.orig/fs/minix/symlink.c elks/fs/minix/symlink.c --- elks.orig/fs/minix/symlink.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/fs/minix/symlink.c 2015-04-30 17:49:33.000000000 -0500 @@ -60,7 +60,7 @@ map_buffer(bh); pds = ¤t->t_regs.ds; ds = *pds; - *pds = get_ds(); + *pds = kernel_ds; error = open_namei(bh->b_data, flag, mode, res_inode, dir); *pds = ds; /* current-> */ link_count--; diff -Nur elks.orig/include/arch/segment.h elks/include/arch/segment.h --- elks.orig/include/arch/segment.h 2015-04-26 11:39:15.000000000 -0500 +++ elks/include/arch/segment.h 2015-04-30 17:54:14.000000000 -0500 @@ -3,20 +3,7 @@ #include <linuxmt/types.h> -#if 1 - -extern __u16 get_cs(void), get_ds(void), get_es(void), get_ss(void); - -#else - -#include <arch/asm.h> - -#define get_cs() asm("mov ax,cs") -#define get_ds() asm("mov ax,ds") -#define get_es() asm("mov ax,es") -#define get_ss() asm("mov ax,ss") - -#endif +extern __u16 kernel_cs, kernel_ds; extern __u16 setupw(unsigned short int); diff -Nur elks.orig/net/ipv4/af_inet.c elks/net/ipv4/af_inet.c --- elks.orig/net/ipv4/af_inet.c 2015-05-05 00:32:03.430279119 -0500 +++ elks/net/ipv4/af_inet.c 2015-05-04 13:47:28.000000000 -0500 @@ -164,11 +164,6 @@ return 0; } -void inet_socketpair(void) -{ - debug("inet_sockpair\n"); -} - #ifndef CONFIG_SOCK_CLIENTONLY static int inet_listen(register struct socket *sock, int backlog) @@ -237,11 +232,6 @@ #endif -void inet_getname(void) -{ - debug("inet_getname\n"); -} - static int inet_read(register struct socket *sock, char *ubuf, int size, int nonblock) { @@ -349,41 +339,6 @@ return 0; } -void inet_ioctl(void) -{ - debug("inet_ioctl\n"); -} - -void inet_shutdown(void) -{ - debug("inet_shutdown\n"); -} - -void inet_setsockopt(void) -{ - debug("setsockopt\n"); -} - -void inet_getsockopt(void) -{ - debug("inet_getsockopt\n"); -} - -void inet_fcntl(void) -{ - debug("inet_fcntl\n"); -} - -void inet_sendto(void) -{ - debug("inet_sendto\n"); -} - -void inet_recvfrom(void) -{ - debug("inet_recvfrom\n"); -} - static int inet_send(struct socket *sock, void *buff, int len, int nonblock, unsigned int flags) { @@ -402,6 +357,12 @@ return inet_read(sock, (char *) buff, len, nonblock); } +int not_implemented(void) /* Originally returned void */ +{ + debug("not_implemented\n"); + return 0; +} + /*@-type@*/ static struct proto_ops inet_proto_ops = { @@ -411,7 +372,7 @@ inet_release, inet_bind, inet_connect, - inet_socketpair, + not_implemented, /* inet_socketpair */ #ifdef CONFIG_SOCK_CLIENTONLY NULL, @@ -419,11 +380,11 @@ inet_accept, #endif - inet_getname, + not_implemented, /* inet_getname */ inet_read, inet_write, inet_select, - inet_ioctl, + not_implemented, /* inet_ioctl */ #ifdef CONFIG_SOCK_CLIENTONLY NULL, @@ -433,12 +394,12 @@ inet_send, inet_recv, - inet_sendto, - inet_recvfrom, - inet_shutdown, - inet_setsockopt, - inet_getsockopt, - inet_fcntl, + not_implemented, /* inet_sendto */ + not_implemented, /* inet_recvfrom */ + not_implemented, /* inet_shutdown */ + not_implemented, /* inet_setsockopt */ + not_implemented, /* inet_getsockopt */ + not_implemented, /* inet_fcntl */ }; /*@+type@*/ diff -Nur elks.orig/net/unix/af_unix.c elks/net/unix/af_unix.c --- elks.orig/net/unix/af_unix.c 2015-04-26 11:39:15.000000000 -0500 +++ elks/net/unix/af_unix.c 2015-04-30 18:15:31.000000000 -0500 @@ -162,7 +162,7 @@ fname[sockaddr_len] = '\0'; old_ds = current->t_regs.ds; - current->t_regs.ds = get_ds(); + current->t_regs.ds = kernel_ds; i = do_mknod(fname, S_IFSOCK | S_IRWXUGO, 0); @@ -218,7 +218,7 @@ fname[sockaddr_len] = '\0'; old_ds = current->t_regs.ds; - current->t_regs.ds = get_ds(); + current->t_regs.ds = kernel_ds; i = open_namei(fname, 2, S_IFSOCK, &inode, NULL); current->t_regs.ds = old_ds; @@ -548,7 +548,7 @@ return unix_write(sock, (char *) buff, len, nonblock); } -/* +/* * Receive data. This version of AF_UNIX also lacks MSG_PEEK 8( */