--- linux/kernel/chr_drv/mem.c 2018/04/24 18:08:20 1.1.1.1 +++ linux/kernel/chr_drv/mem.c 2018/04/24 18:15:45 1.1.1.5 @@ -1,15 +1,15 @@ /* * linux/kernel/chr_drv/mem.c * - * (C) 1991 Linus Torvalds + * Copyright (C) 1991, 1992 Linus Torvalds */ -#include -#include - +#include +#include #include #include #include +#include #include #include @@ -26,101 +26,29 @@ static int write_ram(struct inode * inod static int read_mem(struct inode * inode, struct file * file,char * buf, int count) { - unsigned long addr; - char *tmp; - unsigned long pde, pte, page; - int i; - - if (count < 0) - return -EINVAL; - addr = file->f_pos; - tmp = buf; - while (count > 0) { - pde = (unsigned long) pg_dir + (addr >> 20 & 0xffc); - if (!((pte = *((unsigned long *) pde)) & 1)) - break; - pte &= 0xfffff000; - pte += (addr >> 10) & 0xffc; - if (((page = *((unsigned long *) pte)) & 1) == 0) - break; -/* - if ((page & 2) == 0) - un_wp_page((unsigned long *) pte); -*/ - page &= 0xfffff000; - page += addr & 0xfff; - i = 4096-(addr & 0xfff); - if (i > count) - i = count; - memcpy_tofs(tmp,(void *) page,i); - addr += i; - tmp += i; - count -= i; - } - file->f_pos = addr; - return tmp-buf; -} - -static int write_mem(struct inode * inode, struct file * file,char * buf, int count) -{ - unsigned long addr; - char *tmp; - unsigned long pde, pte, page; - int i; - - if (count < 0) - return -EINVAL; - addr = file->f_pos; - tmp = buf; - while (count > 0) { - pde = (unsigned long) pg_dir + (addr >> 20 & 0xffc); - if (!((pte = *((unsigned long *) pde)) & 1)) - break; - pte &= 0xfffff000; - pte += (addr >> 10) & 0xffc; - if (((page = *((unsigned long *) pte)) & 1) == 0) - break; - if ((page & 2) == 0) - un_wp_page((unsigned long *) pte); - page &= 0xfffff000; - page += addr & 0xfff; - i = 4096-(addr & 0xfff); - if (i > count) - i = count; - memcpy_fromfs((void *) page,tmp,i); - addr += i; - tmp += i; - count -= i; - } - file->f_pos = addr; - return tmp-buf; -} - -static int read_kmem(struct inode * inode, struct file * file,char * buf, int count) -{ unsigned long p = file->f_pos; if (count < 0) return -EINVAL; - if (p >= HIGH_MEMORY) + if (p >= high_memory) return 0; - if (count > HIGH_MEMORY - p) - count = HIGH_MEMORY - p; + if (count > high_memory - p) + count = high_memory - p; memcpy_tofs(buf,(void *) p,count); file->f_pos += count; return count; } -static int write_kmem(struct inode * inode, struct file * file,char * buf, int count) +static int write_mem(struct inode * inode, struct file * file,char * buf, int count) { unsigned long p = file->f_pos; if (count < 0) return -EINVAL; - if (p >= HIGH_MEMORY) + if (p >= high_memory) return 0; - if (count > HIGH_MEMORY - p) - count = HIGH_MEMORY - p; + if (count > high_memory - p) + count = high_memory - p; memcpy_fromfs((void *) p,buf,count); file->f_pos += count; return count; @@ -154,6 +82,17 @@ static int write_port(struct inode * ino return tmp-buf; } +static int read_zero(struct inode *node,struct file *file,char *buf,int count) +{ + int left; + + for (left = count; left > 0; left--) { + put_fs_byte(0,buf); + buf++; + } + return count; +} + /* * The memory devices use the full 32 bits of the offset, and so we cannot * check against negative addresses: they are ok. The return value is weird, @@ -179,6 +118,9 @@ static int mem_lseek(struct inode * inod return file->f_pos; } +#define read_kmem read_mem +#define write_kmem write_mem + static int mem_read(struct inode * inode, struct file * file, char * buf, int count) { switch (MINOR(inode->i_rdev)) { @@ -192,6 +134,8 @@ static int mem_read(struct inode * inode return 0; /* /dev/null */ case 4: return read_port(inode,file,buf,count); + case 5: + return read_zero(inode,file,buf,count); default: return -ENODEV; } @@ -210,6 +154,8 @@ static int mem_write(struct inode * inod return count; /* /dev/null */ case 4: return write_port(inode,file,buf,count); + case 5: + return count; /* /dev/zero */ default: return -ENODEV; } @@ -226,9 +172,11 @@ static struct file_operations mem_fops = NULL /* no special release code */ }; -void chr_dev_init(void) +long chr_dev_init(long mem_start, long mem_end) { chrdev_fops[1] = &mem_fops; - tty_init(); - lp_init(); + mem_start = tty_init(mem_start); + mem_start = lp_init(mem_start); + mem_start = mouse_init(mem_start); + return mem_start; }