├── 000-环境搭建.md ├── 001-Linux-0.00的编译和运行.md ├── README.md ├── bochs ├── README.md └── bochsrc-0.00.bxrc ├── image ├── 1528507608975.png ├── 1528517709173.png ├── 1530928925710.png ├── 1530928941007.png ├── 1530928957834.png ├── 1530936626048.png ├── 1530960311089.png ├── 1531454085477.png └── 1531473293936.png ├── linux-0.00-ok ├── Makefile ├── README.md ├── bochsrc-0.00.bxrc ├── boot.s ├── head.s └── result.png ├── linux-0.00-rh9 ├── Makefile ├── boot.s └── head.s └── linux-0.11-060618-gcc4 ├── Makefile ├── boot ├── bootsect.s ├── head.s └── setup.s ├── fs ├── Makefile ├── bitmap.c ├── block_dev.c ├── buffer.c ├── char_dev.c ├── exec.c ├── fcntl.c ├── file_dev.c ├── file_table.c ├── inode.c ├── ioctl.c ├── namei.c ├── open.c ├── pipe.c ├── read_write.c ├── stat.c ├── super.c └── truncate.c ├── include ├── a.out.h ├── asm │ ├── io.h │ ├── memory.h │ ├── segment.h │ └── system.h ├── const.h ├── ctype.h ├── errno.h ├── fcntl.h ├── linux │ ├── config.h │ ├── fdreg.h │ ├── fs.h │ ├── hdreg.h │ ├── head.h │ ├── kernel.h │ ├── mm.h │ ├── sched.h │ ├── sched.h.cur1 │ ├── sched.h.old │ ├── sys.h │ └── tty.h ├── signal.h ├── stdarg.h ├── stddef.h ├── string.h ├── sys │ ├── stat.h │ ├── times.h │ ├── types.h │ ├── utsname.h │ └── wait.h ├── termios.h ├── time.h ├── unistd.h └── utime.h ├── init └── main.c ├── kernel ├── Makefile ├── asm.s ├── blk_drv │ ├── Makefile │ ├── blk.h │ ├── floppy.c │ ├── hd.c │ ├── ll_rw_blk.c │ └── ramdisk.c ├── chr_drv │ ├── Makefile │ ├── console.c │ ├── keyboard.S │ ├── rs_io.s │ ├── serial.c │ ├── tty_io.c │ └── tty_ioctl.c ├── exit.c ├── fork.c ├── math │ ├── Makefile │ └── math_emulate.c ├── mktime.c ├── panic.c ├── printk.c ├── sched.c ├── signal.c ├── sys.c ├── system_call.s ├── traps.c └── vsprintf.c ├── lib ├── Makefile ├── _exit.c ├── close.c ├── ctype.c ├── dup.c ├── errno.c ├── execve.c ├── malloc.c ├── open.c ├── setsid.c ├── string.c ├── wait.c └── write.c ├── mm ├── Makefile ├── Makefile-gcc3.x ├── Makefile-gcc4.1 ├── memory.c └── page.s └── tools └── build.c /000-环境搭建.md: -------------------------------------------------------------------------------- 1 | 2 | 使用 3 | ubuntu-16.04.5-desktop-i386.iso 4 | 5 | 6 | 7 | ubuntu16.04上安装bochs 8 | https://blog.csdn.net/shujuliu818/article/details/61417423 9 | 10 | Linux 0.00 的编译和运行 11 | https://blog.csdn.net/longintchar/article/details/78757065 12 | 13 | https://blog.csdn.net/longintchar/article/details/79252928?utm_source=blogxgwz1 14 | 15 | ubuntu-18.04.1-desktop-amd64.iso 16 | 17 | sudo apt-get install bochs 18 | sudo apt-get install vgabios 19 | sudo apt-get install bochs-x 20 | sudo apt-get install bochsbios 21 | sudo apt-get install bochs-doc 22 | sudo apt-get install xorg-dev 23 | sudo apt-get install bochs-sdl 24 | 25 | 安装as86 26 | sudo apt-get install bin86 27 | 28 | ##### linux-0.11 was compiled successfully on the platform ubuntu-16.04.5-desktop-i386 29 | 30 | ``` 31 | Source from: 32 | http://www.oldlinux.org/Linux.old/kernel/0.1x/linux-0.11-060618-gcc4.tar.gz 33 | 34 | Compile platform: 35 | ubuntu-16.04.5-desktop-i386.iso 36 | ``` 37 | -------------------------------------------------------------------------------- /001-Linux-0.00的编译和运行.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://blog.csdn.net/longintchar/article/details/78757065 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 《linux-0.12 内核完全剖析》 2 | 3 | ![1528507608975.png](image/1528507608975.png) 4 | 5 | 赵炯,上海同济大学计算机通信专业毕业,多年从事操作系统,计算机网络和系统软件的研究工作,具有很高的学术水平。2004年编写的《Linux内核完全注释 -基于0.12内核》(**Linux 0.12版本发布于1992年1月15日**)一书,一年内印刷4次,在各大计算机排行榜始终名列前茅,并被《中华读书报》评为“2004年度十大电脑图书”之一。 6 | 7 | ![1528517709173.png](image/1528517709173.png) 8 | 9 | ## 本仓库内容 10 | 11 | 1. linux 0.12 源码 12 | 2. linux 0.12 各个章节笔记 13 | 3. 源码编译脚本及bochs启动运行脚本 14 | 15 | 16 | 《操作系统概念》(第七版),Silberschatz、Galvin和Gagne编著,高等教育出版社 17 | 《Linux内核剖析》,赵炯编著,电子工业出版社 18 | -------------------------------------------------------------------------------- /bochs/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | bochsrc-0.00.bxrc --- 放于目录linux-0.00-rh9,用户实验 4 | -------------------------------------------------------------------------------- /bochs/bochsrc-0.00.bxrc: -------------------------------------------------------------------------------- 1 | romimage: file=$BXSHARE/BIOS-bochs-latest 2 | vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest 3 | megs: 16 4 | floppya: 1_44="Image", status=inserted 5 | boot: a 6 | log: bochsout.txt -------------------------------------------------------------------------------- /image/1528507608975.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1528507608975.png -------------------------------------------------------------------------------- /image/1528517709173.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1528517709173.png -------------------------------------------------------------------------------- /image/1530928925710.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1530928925710.png -------------------------------------------------------------------------------- /image/1530928941007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1530928941007.png -------------------------------------------------------------------------------- /image/1530928957834.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1530928957834.png -------------------------------------------------------------------------------- /image/1530936626048.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1530936626048.png -------------------------------------------------------------------------------- /image/1530960311089.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1530960311089.png -------------------------------------------------------------------------------- /image/1531454085477.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1531454085477.png -------------------------------------------------------------------------------- /image/1531473293936.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/image/1531473293936.png -------------------------------------------------------------------------------- /linux-0.00-ok/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for the simple example kernel. 2 | AS86 =as86 -0 -a 3 | LD86 =ld86 -0 4 | AS =as --32 5 | LD =ld 6 | LDFLAGS =-m elf_i386 -Ttext 0 -e startup_32 -s -x -M 7 | 8 | all: Image 9 | 10 | Image: boot system 11 | dd bs=32 if=boot of=Image skip=1 12 | objcopy -O binary system head 13 | cat head >> Image 14 | 15 | disk: Image 16 | dd bs=8192 if=Image of=/dev/fd0 17 | sync;sync;sync 18 | 19 | head.o: head.s 20 | 21 | system: head.o 22 | $(LD) $(LDFLAGS) head.o -o system > System.map 23 | 24 | boot: boot.s 25 | $(AS86) -o boot.o boot.s 26 | $(LD86) -s -o boot boot.o 27 | 28 | clean: 29 | rm -f Image System.map core boot head *.o system 30 | -------------------------------------------------------------------------------- /linux-0.00-ok/README.md: -------------------------------------------------------------------------------- 1 | 《Linux内核完全剖析》这本书在第4章给出了一个简单多任务内核示例程序,我们称之为Linux 0.00系统。本文介绍了一种把它跑起来的方法。 2 | 3 | # 一、实验环境 4 | * compile system 5 | ubuntu-16.04.5-desktop-i386.iso 6 | * bochs 7 | Bochs x86 Emulator 2.6 8 | 9 | # 二、源码下载 10 | 11 | 下载地址是 12 | http://oldlinux.org/Linux.old/bochs/ 13 | 要下载的文件是linux-0.00-050613.zip 14 | 15 | # 三、编译 16 | 17 | ``` 18 | nick@nick-VirtualBox:~/oldlinux/linux-0.00-ok$ make 19 | as86 -0 -a -o boot.o boot.s 20 | ld86 -0 -s -o boot boot.o 21 | as --32 -o head.o head.s 22 | ld -m elf_i386 -Ttext 0 -e startup_32 -s -x -M head.o -o system > System.map 23 | dd bs=32 if=boot of=Image skip=1 24 | 16+0 records in 25 | 16+0 records out 26 | 512 bytes copied, 0.00150062 s, 341 kB/s 27 | objcopy -O binary system head 28 | cat head >> Image 29 | ``` 30 | 31 | # 四、运行 32 | 33 | 进入虚拟机(需要有界面显示)执行 34 | 35 | ``` 36 | bochs -f bochsrc-0.00.bxrc 37 | ``` 38 | 39 | ![linux-0.00运行结果](https://github.com/nicklgw/oldlinux/blob/master/linux-0.00-ok/result.png?raw=true) 40 | 41 | # 五、参考 42 | 43 | Linux 0.00 的编译和运行 44 | https://blog.csdn.net/longintchar/article/details/78757065 45 | -------------------------------------------------------------------------------- /linux-0.00-ok/bochsrc-0.00.bxrc: -------------------------------------------------------------------------------- 1 | romimage: file=$BXSHARE/BIOS-bochs-latest 2 | vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest 3 | megs: 16 4 | floppya: 1_44="Image", status=inserted 5 | boot: a 6 | log: bochsout.txt 7 | -------------------------------------------------------------------------------- /linux-0.00-ok/boot.s: -------------------------------------------------------------------------------- 1 | ! boot.s 2 | ! 3 | ! It then loads the system at 0x10000, using BIOS interrupts. Thereafter 4 | ! it disables all interrupts, changes to protected mode, and calls the 5 | 6 | BOOTSEG = 0x07c0 7 | SYSSEG = 0x1000 ! system loaded at 0x10000 (65536). 8 | SYSLEN = 17 ! sectors occupied. 9 | 10 | entry start 11 | start: 12 | jmpi go,#BOOTSEG 13 | go: mov ax,cs 14 | mov ds,ax 15 | mov ss,ax 16 | mov sp,#0x400 ! arbitrary value >>512 17 | 18 | ! ok, we've written the message, now 19 | load_system: 20 | mov dx,#0x0000 21 | mov cx,#0x0002 22 | mov ax,#SYSSEG 23 | mov es,ax 24 | xor bx,bx 25 | mov ax,#0x200+SYSLEN 26 | int 0x13 27 | jnc ok_load 28 | die: jmp die 29 | 30 | ! now we want to move to protected mode ... 31 | ok_load: 32 | cli ! no interrupts allowed ! 33 | mov ax, #SYSSEG 34 | mov ds, ax 35 | xor ax, ax 36 | mov es, ax 37 | mov cx, #0x2000 38 | sub si,si 39 | sub di,di 40 | rep 41 | movw 42 | mov ax, #BOOTSEG 43 | mov ds, ax 44 | lidt idt_48 ! load idt with 0,0 45 | lgdt gdt_48 ! load gdt with whatever appropriate 46 | 47 | ! absolute address 0x00000, in 32-bit protected mode. 48 | mov ax,#0x0001 ! protected mode (PE) bit 49 | lmsw ax ! This is it! 50 | jmpi 0,8 ! jmp offset 0 of segment 8 (cs) 51 | 52 | gdt: .word 0,0,0,0 ! dummy 53 | 54 | .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 55 | .word 0x0000 ! base address=0x00000 56 | .word 0x9A00 ! code read/exec 57 | .word 0x00C0 ! granularity=4096, 386 58 | 59 | .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 60 | .word 0x0000 ! base address=0x00000 61 | .word 0x9200 ! data read/write 62 | .word 0x00C0 ! granularity=4096, 386 63 | 64 | idt_48: .word 0 ! idt limit=0 65 | .word 0,0 ! idt base=0L 66 | gdt_48: .word 0x7ff ! gdt limit=2048, 256 GDT entries 67 | .word 0x7c00+gdt,0 ! gdt base = 07xxx 68 | .org 510 69 | .word 0xAA55 70 | 71 | -------------------------------------------------------------------------------- /linux-0.00-ok/head.s: -------------------------------------------------------------------------------- 1 | # head.s contains the 32-bit startup code. 2 | # Two L3 task multitasking. The code of tasks are in kernel area, 3 | # just like the Linux. The kernel code is located at 0x10000. 4 | SCRN_SEL = 0x18 5 | TSS0_SEL = 0x20 6 | LDT0_SEL = 0x28 7 | TSS1_SEL = 0X30 8 | LDT1_SEL = 0x38 9 | .global startup_32 10 | .code32 # 加上这句话 11 | .text 12 | startup_32: 13 | movl $0x10,%eax 14 | mov %ax,%ds 15 | # mov %ax,%es 16 | lss init_stack,%esp 17 | 18 | # setup base fields of descriptors. 19 | call setup_idt 20 | call setup_gdt 21 | movl $0x10,%eax # reload all the segment registers 22 | mov %ax,%ds # after changing gdt. 23 | mov %ax,%es 24 | mov %ax,%fs 25 | mov %ax,%gs 26 | lss init_stack,%esp 27 | 28 | # setup up timer 8253 chip. 29 | movb $0x36, %al 30 | movl $0x43, %edx 31 | outb %al, %dx 32 | movl $11930, %eax # timer frequency 100 HZ 33 | movl $0x40, %edx 34 | outb %al, %dx 35 | movb %ah, %al 36 | outb %al, %dx 37 | 38 | # setup timer & system call interrupt descriptors. 39 | movl $0x00080000, %eax 40 | movw $timer_interrupt, %ax 41 | movw $0x8E00, %dx 42 | movl $0x08, %ecx # The PC default timer int. 43 | lea idt(,%ecx,8), %esi 44 | movl %eax,(%esi) 45 | movl %edx,4(%esi) 46 | movw $system_interrupt, %ax 47 | movw $0xef00, %dx 48 | movl $0x80, %ecx 49 | lea idt(,%ecx,8), %esi 50 | movl %eax,(%esi) 51 | movl %edx,4(%esi) 52 | 53 | # unmask the timer interrupt. 54 | # movl $0x21, %edx 55 | # inb %dx, %al 56 | # andb $0xfe, %al 57 | # outb %al, %dx 58 | 59 | # Move to user mode (task 0) 60 | pushfl 61 | andl $0xffffbfff, (%esp) 62 | popfl 63 | movl $TSS0_SEL, %eax 64 | ltr %ax 65 | movl $LDT0_SEL, %eax 66 | lldt %ax 67 | movl $0, current 68 | sti 69 | pushl $0x17 70 | pushl $init_stack 71 | pushfl 72 | pushl $0x0f 73 | pushl $task0 74 | iret 75 | 76 | /****************************************/ 77 | setup_gdt: 78 | lgdt lgdt_opcode 79 | ret 80 | 81 | setup_idt: 82 | lea ignore_int,%edx 83 | movl $0x00080000,%eax 84 | movw %dx,%ax /* selector = 0x0008 = cs */ 85 | movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ 86 | lea idt,%edi 87 | mov $256,%ecx 88 | rp_sidt: 89 | movl %eax,(%edi) 90 | movl %edx,4(%edi) 91 | addl $8,%edi 92 | dec %ecx 93 | jne rp_sidt 94 | lidt lidt_opcode 95 | ret 96 | 97 | # ----------------------------------- 98 | write_char: 99 | push %gs 100 | pushl %ebx 101 | # pushl %eax 102 | mov $SCRN_SEL, %ebx 103 | mov %bx, %gs 104 | movl scr_loc, %ebx 105 | shl $1, %ebx 106 | movb %al, %gs:(%ebx) 107 | shr $1, %ebx 108 | incl %ebx 109 | cmpl $2000, %ebx 110 | jb 1f 111 | movl $0, %ebx 112 | 1: movl %ebx, scr_loc 113 | # popl %eax 114 | popl %ebx 115 | pop %gs 116 | ret 117 | 118 | /***********************************************/ 119 | /* This is the default interrupt "handler" :-) */ 120 | .align 2 121 | ignore_int: 122 | push %ds 123 | pushl %eax 124 | movl $0x10, %eax 125 | mov %ax, %ds 126 | movl $67, %eax /* print 'C' */ 127 | call write_char 128 | popl %eax 129 | pop %ds 130 | iret 131 | 132 | /* Timer interrupt handler */ 133 | .align 2 134 | timer_interrupt: 135 | push %ds 136 | pushl %eax 137 | movl $0x10, %eax 138 | mov %ax, %ds 139 | movb $0x20, %al 140 | outb %al, $0x20 141 | movl $1, %eax 142 | cmpl %eax, current 143 | je 1f 144 | movl %eax, current 145 | ljmp $TSS1_SEL, $0 146 | jmp 2f 147 | 1: movl $0, current 148 | ljmp $TSS0_SEL, $0 149 | 2: popl %eax 150 | pop %ds 151 | iret 152 | 153 | /* system call handler */ 154 | .align 2 155 | system_interrupt: 156 | push %ds 157 | pushl %edx 158 | pushl %ecx 159 | pushl %ebx 160 | pushl %eax 161 | movl $0x10, %edx 162 | mov %dx, %ds 163 | call write_char 164 | popl %eax 165 | popl %ebx 166 | popl %ecx 167 | popl %edx 168 | pop %ds 169 | iret 170 | 171 | /*********************************************/ 172 | current:.long 0 173 | scr_loc:.long 0 174 | 175 | .align 2 176 | lidt_opcode: 177 | .word 256*8-1 # idt contains 256 entries 178 | .long idt # This will be rewrite by code. 179 | lgdt_opcode: 180 | .word (end_gdt-gdt)-1 # so does gdt 181 | .long gdt # This will be rewrite by code. 182 | 183 | .align 8 184 | idt: .fill 256,8,0 # idt is uninitialized 185 | 186 | gdt: .quad 0x0000000000000000 /* NULL descriptor */ 187 | .quad 0x00c09a00000007ff /* 8Mb 0x08, base = 0x00000 */ 188 | .quad 0x00c09200000007ff /* 8Mb 0x10 */ 189 | .quad 0x00c0920b80000002 /* screen 0x18 - for display */ 190 | 191 | .word 0x0068, tss0, 0xe900, 0x0 # TSS0 descr 0x20 192 | .word 0x0040, ldt0, 0xe200, 0x0 # LDT0 descr 0x28 193 | .word 0x0068, tss1, 0xe900, 0x0 # TSS1 descr 0x30 194 | .word 0x0040, ldt1, 0xe200, 0x0 # LDT1 descr 0x38 195 | end_gdt: 196 | .fill 128,4,0 197 | init_stack: # Will be used as user stack for task0. 198 | .long init_stack 199 | .word 0x10 200 | 201 | /*************************************/ 202 | .align 8 203 | ldt0: .quad 0x0000000000000000 204 | .quad 0x00c0fa00000003ff # 0x0f, base = 0x00000 205 | .quad 0x00c0f200000003ff # 0x17 206 | 207 | tss0: .long 0 /* back link */ 208 | .long krn_stk0, 0x10 /* esp0, ss0 */ 209 | .long 0, 0, 0, 0, 0 /* esp1, ss1, esp2, ss2, cr3 */ 210 | .long 0, 0, 0, 0, 0 /* eip, eflags, eax, ecx, edx */ 211 | .long 0, 0, 0, 0, 0 /* ebx esp, ebp, esi, edi */ 212 | .long 0, 0, 0, 0, 0, 0 /* es, cs, ss, ds, fs, gs */ 213 | .long LDT0_SEL, 0x8000000 /* ldt, trace bitmap */ 214 | 215 | .fill 128,4,0 216 | krn_stk0: 217 | # .long 0 218 | 219 | /************************************/ 220 | .align 8 221 | ldt1: .quad 0x0000000000000000 222 | .quad 0x00c0fa00000003ff # 0x0f, base = 0x00000 223 | .quad 0x00c0f200000003ff # 0x17 224 | 225 | tss1: .long 0 /* back link */ 226 | .long krn_stk1, 0x10 /* esp0, ss0 */ 227 | .long 0, 0, 0, 0, 0 /* esp1, ss1, esp2, ss2, cr3 */ 228 | .long task1, 0x200 /* eip, eflags */ 229 | .long 0, 0, 0, 0 /* eax, ecx, edx, ebx */ 230 | .long usr_stk1, 0, 0, 0 /* esp, ebp, esi, edi */ 231 | .long 0x17,0x0f,0x17,0x17,0x17,0x17 /* es, cs, ss, ds, fs, gs */ 232 | .long LDT1_SEL, 0x8000000 /* ldt, trace bitmap */ 233 | 234 | .fill 128,4,0 235 | krn_stk1: 236 | 237 | /************************************/ 238 | task0: 239 | movl $0x17, %eax 240 | movw %ax, %ds 241 | movb $65, %al /* print 'A' */ 242 | int $0x80 243 | movl $0xfff, %ecx 244 | 1: loop 1b 245 | jmp task0 246 | 247 | task1: 248 | movl $0x17, %eax 249 | movw %ax, %ds 250 | movb $66, %al /* print 'B' */ 251 | int $0x80 252 | movl $0xfff, %ecx 253 | 1: loop 1b 254 | jmp task1 255 | 256 | .fill 128,4,0 257 | usr_stk1: 258 | -------------------------------------------------------------------------------- /linux-0.00-ok/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklgw/oldlinux/76b0f1b28ad5851fe18720a37f4ba9d43b36d025/linux-0.00-ok/result.png -------------------------------------------------------------------------------- /linux-0.00-rh9/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for the simple example kernel. 2 | AS86 =as86 -0 -a 3 | LD86 =ld86 -0 4 | AS =as --32 5 | LD =ld 6 | LDFLAGS =-m elf_i386 -Ttext 0 -e startup_32 -s -x -M 7 | 8 | all: Image 9 | 10 | Image: boot system 11 | dd bs=32 if=boot of=Image skip=1 12 | objcopy -O binary system head 13 | cat head >> Image 14 | 15 | disk: Image 16 | dd bs=8192 if=Image of=/dev/fd0 17 | sync;sync;sync 18 | 19 | head.o: head.s 20 | 21 | system: head.o 22 | $(LD) $(LDFLAGS) head.o -o system > System.map 23 | 24 | boot: boot.s 25 | $(AS86) -o boot.o boot.s 26 | $(LD86) -s -o boot boot.o 27 | 28 | clean: 29 | rm -f Image System.map core boot head *.o system 30 | -------------------------------------------------------------------------------- /linux-0.00-rh9/boot.s: -------------------------------------------------------------------------------- 1 | ! boot.s 2 | ! 3 | ! It then loads the system at 0x10000, using BIOS interrupts. Thereafter 4 | ! it disables all interrupts, changes to protected mode, and calls the 5 | 6 | BOOTSEG = 0x07c0 7 | SYSSEG = 0x1000 ! system loaded at 0x10000 (65536). 8 | SYSLEN = 17 ! sectors occupied. 9 | 10 | entry start 11 | start: 12 | jmpi go,#BOOTSEG 13 | go: mov ax,cs 14 | mov ds,ax 15 | mov ss,ax 16 | mov sp,#0x400 ! arbitrary value >>512 17 | 18 | ! ok, we've written the message, now 19 | load_system: 20 | mov dx,#0x0000 21 | mov cx,#0x0002 22 | mov ax,#SYSSEG 23 | mov es,ax 24 | xor bx,bx 25 | mov ax,#0x200+SYSLEN 26 | int 0x13 27 | jnc ok_load 28 | die: jmp die 29 | 30 | ! now we want to move to protected mode ... 31 | ok_load: 32 | cli ! no interrupts allowed ! 33 | mov ax, #SYSSEG 34 | mov ds, ax 35 | xor ax, ax 36 | mov es, ax 37 | mov cx, #0x2000 38 | sub si,si 39 | sub di,di 40 | rep 41 | movw 42 | mov ax, #BOOTSEG 43 | mov ds, ax 44 | lidt idt_48 ! load idt with 0,0 45 | lgdt gdt_48 ! load gdt with whatever appropriate 46 | 47 | ! absolute address 0x00000, in 32-bit protected mode. 48 | mov ax,#0x0001 ! protected mode (PE) bit 49 | lmsw ax ! This is it! 50 | jmpi 0,8 ! jmp offset 0 of segment 8 (cs) 51 | 52 | gdt: .word 0,0,0,0 ! dummy 53 | 54 | .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 55 | .word 0x0000 ! base address=0x00000 56 | .word 0x9A00 ! code read/exec 57 | .word 0x00C0 ! granularity=4096, 386 58 | 59 | .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 60 | .word 0x0000 ! base address=0x00000 61 | .word 0x9200 ! data read/write 62 | .word 0x00C0 ! granularity=4096, 386 63 | 64 | idt_48: .word 0 ! idt limit=0 65 | .word 0,0 ! idt base=0L 66 | gdt_48: .word 0x7ff ! gdt limit=2048, 256 GDT entries 67 | .word 0x7c00+gdt,0 ! gdt base = 07xxx 68 | .org 510 69 | .word 0xAA55 70 | 71 | -------------------------------------------------------------------------------- /linux-0.00-rh9/head.s: -------------------------------------------------------------------------------- 1 | # head.s contains the 32-bit startup code. 2 | # Two L3 task multitasking. The code of tasks are in kernel area, 3 | # just like the Linux. The kernel code is located at 0x10000. 4 | SCRN_SEL = 0x18 5 | TSS0_SEL = 0x20 6 | LDT0_SEL = 0x28 7 | TSS1_SEL = 0X30 8 | LDT1_SEL = 0x38 9 | .global startup_32 10 | .code32 # 加上这句话 11 | .text 12 | startup_32: 13 | movl $0x10,%eax 14 | mov %ax,%ds 15 | # mov %ax,%es 16 | lss init_stack,%esp 17 | 18 | # setup base fields of descriptors. 19 | call setup_idt 20 | call setup_gdt 21 | movl $0x10,%eax # reload all the segment registers 22 | mov %ax,%ds # after changing gdt. 23 | mov %ax,%es 24 | mov %ax,%fs 25 | mov %ax,%gs 26 | lss init_stack,%esp 27 | 28 | # setup up timer 8253 chip. 29 | movb $0x36, %al 30 | movl $0x43, %edx 31 | outb %al, %dx 32 | movl $11930, %eax # timer frequency 100 HZ 33 | movl $0x40, %edx 34 | outb %al, %dx 35 | movb %ah, %al 36 | outb %al, %dx 37 | 38 | # setup timer & system call interrupt descriptors. 39 | movl $0x00080000, %eax 40 | movw $timer_interrupt, %ax 41 | movw $0x8E00, %dx 42 | movl $0x08, %ecx # The PC default timer int. 43 | lea idt(,%ecx,8), %esi 44 | movl %eax,(%esi) 45 | movl %edx,4(%esi) 46 | movw $system_interrupt, %ax 47 | movw $0xef00, %dx 48 | movl $0x80, %ecx 49 | lea idt(,%ecx,8), %esi 50 | movl %eax,(%esi) 51 | movl %edx,4(%esi) 52 | 53 | # unmask the timer interrupt. 54 | # movl $0x21, %edx 55 | # inb %dx, %al 56 | # andb $0xfe, %al 57 | # outb %al, %dx 58 | 59 | # Move to user mode (task 0) 60 | pushfl 61 | andl $0xffffbfff, (%esp) 62 | popfl 63 | movl $TSS0_SEL, %eax 64 | ltr %ax 65 | movl $LDT0_SEL, %eax 66 | lldt %ax 67 | movl $0, current 68 | sti 69 | pushl $0x17 70 | pushl $init_stack 71 | pushfl 72 | pushl $0x0f 73 | pushl $task0 74 | iret 75 | 76 | /****************************************/ 77 | setup_gdt: 78 | lgdt lgdt_opcode 79 | ret 80 | 81 | setup_idt: 82 | lea ignore_int,%edx 83 | movl $0x00080000,%eax 84 | movw %dx,%ax /* selector = 0x0008 = cs */ 85 | movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ 86 | lea idt,%edi 87 | mov $256,%ecx 88 | rp_sidt: 89 | movl %eax,(%edi) 90 | movl %edx,4(%edi) 91 | addl $8,%edi 92 | dec %ecx 93 | jne rp_sidt 94 | lidt lidt_opcode 95 | ret 96 | 97 | # ----------------------------------- 98 | write_char: 99 | push %gs 100 | pushl %ebx 101 | # pushl %eax 102 | mov $SCRN_SEL, %ebx 103 | mov %bx, %gs 104 | movl scr_loc, %ebx 105 | shl $1, %ebx 106 | movb %al, %gs:(%ebx) 107 | shr $1, %ebx 108 | incl %ebx 109 | cmpl $2000, %ebx 110 | jb 1f 111 | movl $0, %ebx 112 | 1: movl %ebx, scr_loc 113 | # popl %eax 114 | popl %ebx 115 | pop %gs 116 | ret 117 | 118 | /***********************************************/ 119 | /* This is the default interrupt "handler" :-) */ 120 | .align 2 121 | ignore_int: 122 | push %ds 123 | pushl %eax 124 | movl $0x10, %eax 125 | mov %ax, %ds 126 | movl $67, %eax /* print 'C' */ 127 | call write_char 128 | popl %eax 129 | pop %ds 130 | iret 131 | 132 | /* Timer interrupt handler */ 133 | .align 2 134 | timer_interrupt: 135 | push %ds 136 | pushl %eax 137 | movl $0x10, %eax 138 | mov %ax, %ds 139 | movb $0x20, %al 140 | outb %al, $0x20 141 | movl $1, %eax 142 | cmpl %eax, current 143 | je 1f 144 | movl %eax, current 145 | ljmp $TSS1_SEL, $0 146 | jmp 2f 147 | 1: movl $0, current 148 | ljmp $TSS0_SEL, $0 149 | 2: popl %eax 150 | pop %ds 151 | iret 152 | 153 | /* system call handler */ 154 | .align 2 155 | system_interrupt: 156 | push %ds 157 | pushl %edx 158 | pushl %ecx 159 | pushl %ebx 160 | pushl %eax 161 | movl $0x10, %edx 162 | mov %dx, %ds 163 | call write_char 164 | popl %eax 165 | popl %ebx 166 | popl %ecx 167 | popl %edx 168 | pop %ds 169 | iret 170 | 171 | /*********************************************/ 172 | current:.long 0 173 | scr_loc:.long 0 174 | 175 | .align 2 176 | lidt_opcode: 177 | .word 256*8-1 # idt contains 256 entries 178 | .long idt # This will be rewrite by code. 179 | lgdt_opcode: 180 | .word (end_gdt-gdt)-1 # so does gdt 181 | .long gdt # This will be rewrite by code. 182 | 183 | .align 8 184 | idt: .fill 256,8,0 # idt is uninitialized 185 | 186 | gdt: .quad 0x0000000000000000 /* NULL descriptor */ 187 | .quad 0x00c09a00000007ff /* 8Mb 0x08, base = 0x00000 */ 188 | .quad 0x00c09200000007ff /* 8Mb 0x10 */ 189 | .quad 0x00c0920b80000002 /* screen 0x18 - for display */ 190 | 191 | .word 0x0068, tss0, 0xe900, 0x0 # TSS0 descr 0x20 192 | .word 0x0040, ldt0, 0xe200, 0x0 # LDT0 descr 0x28 193 | .word 0x0068, tss1, 0xe900, 0x0 # TSS1 descr 0x30 194 | .word 0x0040, ldt1, 0xe200, 0x0 # LDT1 descr 0x38 195 | end_gdt: 196 | .fill 128,4,0 197 | init_stack: # Will be used as user stack for task0. 198 | .long init_stack 199 | .word 0x10 200 | 201 | /*************************************/ 202 | .align 8 203 | ldt0: .quad 0x0000000000000000 204 | .quad 0x00c0fa00000003ff # 0x0f, base = 0x00000 205 | .quad 0x00c0f200000003ff # 0x17 206 | 207 | tss0: .long 0 /* back link */ 208 | .long krn_stk0, 0x10 /* esp0, ss0 */ 209 | .long 0, 0, 0, 0, 0 /* esp1, ss1, esp2, ss2, cr3 */ 210 | .long 0, 0, 0, 0, 0 /* eip, eflags, eax, ecx, edx */ 211 | .long 0, 0, 0, 0, 0 /* ebx esp, ebp, esi, edi */ 212 | .long 0, 0, 0, 0, 0, 0 /* es, cs, ss, ds, fs, gs */ 213 | .long LDT0_SEL, 0x8000000 /* ldt, trace bitmap */ 214 | 215 | .fill 128,4,0 216 | krn_stk0: 217 | # .long 0 218 | 219 | /************************************/ 220 | .align 8 221 | ldt1: .quad 0x0000000000000000 222 | .quad 0x00c0fa00000003ff # 0x0f, base = 0x00000 223 | .quad 0x00c0f200000003ff # 0x17 224 | 225 | tss1: .long 0 /* back link */ 226 | .long krn_stk1, 0x10 /* esp0, ss0 */ 227 | .long 0, 0, 0, 0, 0 /* esp1, ss1, esp2, ss2, cr3 */ 228 | .long task1, 0x200 /* eip, eflags */ 229 | .long 0, 0, 0, 0 /* eax, ecx, edx, ebx */ 230 | .long usr_stk1, 0, 0, 0 /* esp, ebp, esi, edi */ 231 | .long 0x17,0x0f,0x17,0x17,0x17,0x17 /* es, cs, ss, ds, fs, gs */ 232 | .long LDT1_SEL, 0x8000000 /* ldt, trace bitmap */ 233 | 234 | .fill 128,4,0 235 | krn_stk1: 236 | 237 | /************************************/ 238 | task0: 239 | movl $0x17, %eax 240 | movw %ax, %ds 241 | movb $65, %al /* print 'A' */ 242 | int $0x80 243 | movl $0xfff, %ecx 244 | 1: loop 1b 245 | jmp task0 246 | 247 | task1: 248 | movl $0x17, %eax 249 | movw %ax, %ds 250 | movb $66, %al /* print 'B' */ 251 | int $0x80 252 | movl $0xfff, %ecx 253 | 1: loop 1b 254 | jmp task1 255 | 256 | .fill 128,4,0 257 | usr_stk1: 258 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # if you want the ram-disk device, define this to be the 3 | # size in blocks. 4 | # 5 | RAMDISK = #-DRAMDISK=512 6 | 7 | AS86 =as86 -0 -a 8 | LD86 =ld86 -0 9 | 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-m elf_i386 -Ttext 0 -e startup_32 13 | CC =gcc -mcpu=i386 $(RAMDISK) 14 | CFLAGS =-Wall -O2 -fomit-frame-pointer 15 | 16 | CPP =cpp -nostdinc -Iinclude 17 | 18 | # 19 | # ROOT_DEV specifies the default root-device when making the image. 20 | # This can be either FLOPPY, /dev/xxxx or empty, in which case the 21 | # default of /dev/hd6 is used by 'build'. 22 | # 23 | ROOT_DEV= #FLOPPY 24 | 25 | ARCHIVES=kernel/kernel.o mm/mm.o fs/fs.o 26 | DRIVERS =kernel/blk_drv/blk_drv.a kernel/chr_drv/chr_drv.a 27 | MATH =kernel/math/math.a 28 | LIBS =lib/lib.a 29 | 30 | .c.s: 31 | $(CC) $(CFLAGS) \ 32 | -nostdinc -Iinclude -S -o $*.s $< 33 | .s.o: 34 | $(AS) -o $*.o $< 35 | .c.o: 36 | $(CC) $(CFLAGS) \ 37 | -nostdinc -Iinclude -c -o $*.o $< 38 | 39 | all: Image 40 | 41 | Image: boot/bootsect boot/setup tools/system tools/build 42 | objcopy -O binary -R .note -R .comment tools/system tools/kernel 43 | tools/build boot/bootsect boot/setup tools/kernel $(ROOT_DEV) > Image 44 | rm tools/kernel -f 45 | sync 46 | 47 | disk: Image 48 | dd bs=8192 if=Image of=/dev/fd0 49 | 50 | tools/build: tools/build.c 51 | $(CC) $(CFLAGS) \ 52 | -o tools/build tools/build.c 53 | 54 | boot/head.o: boot/head.s 55 | gcc -I./include -traditional -c boot/head.s 56 | mv head.o boot/ 57 | 58 | tools/system: boot/head.o init/main.o \ 59 | $(ARCHIVES) $(DRIVERS) $(MATH) $(LIBS) 60 | $(LD) $(LDFLAGS) boot/head.o init/main.o \ 61 | $(ARCHIVES) \ 62 | $(DRIVERS) \ 63 | $(MATH) \ 64 | $(LIBS) \ 65 | -o tools/system 66 | nm tools/system | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aU] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)'| sort > System.map 67 | 68 | kernel/math/math.a: 69 | (cd kernel/math; make) 70 | 71 | kernel/blk_drv/blk_drv.a: 72 | (cd kernel/blk_drv; make) 73 | 74 | kernel/chr_drv/chr_drv.a: 75 | (cd kernel/chr_drv; make) 76 | 77 | kernel/kernel.o: 78 | (cd kernel; make) 79 | 80 | mm/mm.o: 81 | (cd mm; make) 82 | 83 | fs/fs.o: 84 | (cd fs; make) 85 | 86 | lib/lib.a: 87 | (cd lib; make) 88 | 89 | boot/setup: boot/setup.s 90 | $(AS86) -o boot/setup.o boot/setup.s 91 | $(LD86) -s -o boot/setup boot/setup.o 92 | 93 | boot/bootsect: boot/bootsect.s 94 | $(AS86) -o boot/bootsect.o boot/bootsect.s 95 | $(LD86) -s -o boot/bootsect boot/bootsect.o 96 | 97 | tmp.s: boot/bootsect.s tools/system 98 | (echo -n "SYSSIZE = (";ls -l tools/system | grep system \ 99 | | cut -c25-31 | tr '\012' ' '; echo "+ 15 ) / 16") > tmp.s 100 | cat boot/bootsect.s >> tmp.s 101 | 102 | clean: 103 | rm -f Image System.map tmp_make core boot/bootsect boot/setup 104 | rm -f init/*.o tools/system tools/build boot/*.o 105 | (cd mm;make clean) 106 | (cd fs;make clean) 107 | (cd kernel;make clean) 108 | (cd lib;make clean) 109 | 110 | backup: clean 111 | (cd .. ; tar cf - linux | compress16 - > backup.Z) 112 | sync 113 | 114 | dep: 115 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 116 | (for i in init/*.c;do echo -n "init/";$(CPP) -M $$i;done) >> tmp_make 117 | cp tmp_make Makefile 118 | (cd fs; make dep) 119 | (cd kernel; make dep) 120 | (cd mm; make dep) 121 | 122 | ### Dependencies: 123 | init/main.o: init/main.c include/unistd.h include/sys/stat.h \ 124 | include/sys/types.h include/sys/times.h include/sys/utsname.h \ 125 | include/utime.h include/time.h include/linux/tty.h include/termios.h \ 126 | include/linux/sched.h include/linux/head.h include/linux/fs.h \ 127 | include/linux/mm.h include/signal.h include/asm/system.h \ 128 | include/asm/io.h include/stddef.h include/stdarg.h include/fcntl.h 129 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/boot/bootsect.s: -------------------------------------------------------------------------------- 1 | ! 2 | ! SYS_SIZE is the number of clicks (16 bytes) to be loaded. 3 | ! 0x3000 is 0x30000 bytes = 196kB, more than enough for current 4 | ! versions of linux 5 | ! 6 | SYSSIZE = 0x3000 7 | ! 8 | ! bootsect.s (C) 1991 Linus Torvalds 9 | ! 10 | ! bootsect.s is loaded at 0x7c00 by the bios-startup routines, and moves 11 | ! iself out of the way to address 0x90000, and jumps there. 12 | ! 13 | ! It then loads 'setup' directly after itself (0x90200), and the system 14 | ! at 0x10000, using BIOS interrupts. 15 | ! 16 | ! NOTE! currently system is at most 8*65536 bytes long. This should be no 17 | ! problem, even in the future. I want to keep it simple. This 512 kB 18 | ! kernel size should be enough, especially as this doesn't contain the 19 | ! buffer cache as in minix 20 | ! 21 | ! The loader has been made as simple as possible, and continuos 22 | ! read errors will result in a unbreakable loop. Reboot by hand. It 23 | ! loads pretty fast by getting whole sectors at a time whenever possible. 24 | 25 | .globl begtext, begdata, begbss, endtext, enddata, endbss 26 | .text 27 | begtext: 28 | .data 29 | begdata: 30 | .bss 31 | begbss: 32 | .text 33 | 34 | SETUPLEN = 4 ! nr of setup-sectors 35 | BOOTSEG = 0x07c0 ! original address of boot-sector 36 | INITSEG = 0x9000 ! we move boot here - out of the way 37 | SETUPSEG = 0x9020 ! setup starts here 38 | SYSSEG = 0x1000 ! system loaded at 0x10000 (65536). 39 | ENDSEG = SYSSEG + SYSSIZE ! where to stop loading 40 | 41 | ! ROOT_DEV: 0x000 - same type of floppy as boot. 42 | ! 0x301 - first partition on first drive etc 43 | ROOT_DEV = 0x306 44 | 45 | entry _start 46 | _start: 47 | mov ax,#BOOTSEG 48 | mov ds,ax 49 | mov ax,#INITSEG 50 | mov es,ax 51 | mov cx,#256 52 | sub si,si 53 | sub di,di 54 | rep 55 | movw 56 | jmpi go,INITSEG 57 | go: mov ax,cs 58 | mov ds,ax 59 | mov es,ax 60 | ! put stack at 0x9ff00. 61 | mov ss,ax 62 | mov sp,#0xFF00 ! arbitrary value >>512 63 | 64 | ! load the setup-sectors directly after the bootblock. 65 | ! Note that 'es' is already set up. 66 | 67 | load_setup: 68 | mov dx,#0x0000 ! drive 0, head 0 69 | mov cx,#0x0002 ! sector 2, track 0 70 | mov bx,#0x0200 ! address = 512, in INITSEG 71 | mov ax,#0x0200+SETUPLEN ! service 2, nr of sectors 72 | int 0x13 ! read it 73 | jnc ok_load_setup ! ok - continue 74 | mov dx,#0x0000 75 | mov ax,#0x0000 ! reset the diskette 76 | int 0x13 77 | j load_setup 78 | 79 | ok_load_setup: 80 | 81 | ! Get disk drive parameters, specifically nr of sectors/track 82 | 83 | mov dl,#0x00 84 | mov ax,#0x0800 ! AH=8 is get drive parameters 85 | int 0x13 86 | mov ch,#0x00 87 | seg cs 88 | mov sectors,cx 89 | mov ax,#INITSEG 90 | mov es,ax 91 | 92 | ! Print some inane message 93 | 94 | mov ah,#0x03 ! read cursor pos 95 | xor bh,bh 96 | int 0x10 97 | 98 | mov cx,#24 99 | mov bx,#0x0007 ! page 0, attribute 7 (normal) 100 | mov bp,#msg1 101 | mov ax,#0x1301 ! write string, move cursor 102 | int 0x10 103 | 104 | ! ok, we've written the message, now 105 | ! we want to load the system (at 0x10000) 106 | 107 | mov ax,#SYSSEG 108 | mov es,ax ! segment of 0x010000 109 | call read_it 110 | call kill_motor 111 | 112 | ! After that we check which root-device to use. If the device is 113 | ! defined (!= 0), nothing is done and the given device is used. 114 | ! Otherwise, either /dev/PS0 (2,28) or /dev/at0 (2,8), depending 115 | ! on the number of sectors that the BIOS reports currently. 116 | 117 | seg cs 118 | mov ax,root_dev 119 | cmp ax,#0 120 | jne root_defined 121 | seg cs 122 | mov bx,sectors 123 | mov ax,#0x0208 ! /dev/ps0 - 1.2Mb 124 | cmp bx,#15 125 | je root_defined 126 | mov ax,#0x021c ! /dev/PS0 - 1.44Mb 127 | cmp bx,#18 128 | je root_defined 129 | undef_root: 130 | jmp undef_root 131 | root_defined: 132 | seg cs 133 | mov root_dev,ax 134 | 135 | ! after that (everyting loaded), we jump to 136 | ! the setup-routine loaded directly after 137 | ! the bootblock: 138 | 139 | jmpi 0,SETUPSEG 140 | 141 | ! This routine loads the system at address 0x10000, making sure 142 | ! no 64kB boundaries are crossed. We try to load it as fast as 143 | ! possible, loading whole tracks whenever we can. 144 | ! 145 | ! in: es - starting address segment (normally 0x1000) 146 | ! 147 | sread: .word 1+SETUPLEN ! sectors read of current track 148 | head: .word 0 ! current head 149 | track: .word 0 ! current track 150 | 151 | read_it: 152 | mov ax,es 153 | test ax,#0x0fff 154 | die: jne die ! es must be at 64kB boundary 155 | xor bx,bx ! bx is starting address within segment 156 | rp_read: 157 | mov ax,es 158 | cmp ax,#ENDSEG ! have we loaded all yet? 159 | jb ok1_read 160 | ret 161 | ok1_read: 162 | seg cs 163 | mov ax,sectors 164 | sub ax,sread 165 | mov cx,ax 166 | shl cx,#9 167 | add cx,bx 168 | jnc ok2_read 169 | je ok2_read 170 | xor ax,ax 171 | sub ax,bx 172 | shr ax,#9 173 | ok2_read: 174 | call read_track 175 | mov cx,ax 176 | add ax,sread 177 | seg cs 178 | cmp ax,sectors 179 | jne ok3_read 180 | mov ax,#1 181 | sub ax,head 182 | jne ok4_read 183 | inc track 184 | ok4_read: 185 | mov head,ax 186 | xor ax,ax 187 | ok3_read: 188 | mov sread,ax 189 | shl cx,#9 190 | add bx,cx 191 | jnc rp_read 192 | mov ax,es 193 | add ax,#0x1000 194 | mov es,ax 195 | xor bx,bx 196 | jmp rp_read 197 | 198 | read_track: 199 | push ax 200 | push bx 201 | push cx 202 | push dx 203 | mov dx,track 204 | mov cx,sread 205 | inc cx 206 | mov ch,dl 207 | mov dx,head 208 | mov dh,dl 209 | mov dl,#0 210 | and dx,#0x0100 211 | mov ah,#2 212 | int 0x13 213 | jc bad_rt 214 | pop dx 215 | pop cx 216 | pop bx 217 | pop ax 218 | ret 219 | bad_rt: mov ax,#0 220 | mov dx,#0 221 | int 0x13 222 | pop dx 223 | pop cx 224 | pop bx 225 | pop ax 226 | jmp read_track 227 | 228 | !/* 229 | ! * This procedure turns off the floppy drive motor, so 230 | ! * that we enter the kernel in a known state, and 231 | ! * don't have to worry about it later. 232 | ! */ 233 | kill_motor: 234 | push dx 235 | mov dx,#0x3f2 236 | mov al,#0 237 | outb 238 | pop dx 239 | ret 240 | 241 | sectors: 242 | .word 0 243 | 244 | msg1: 245 | .byte 13,10 246 | .ascii "Loading system ..." 247 | .byte 13,10,13,10 248 | 249 | .org 508 250 | root_dev: 251 | .word ROOT_DEV 252 | boot_flag: 253 | .word 0xAA55 254 | 255 | .text 256 | endtext: 257 | .data 258 | enddata: 259 | .bss 260 | endbss: 261 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/boot/setup.s: -------------------------------------------------------------------------------- 1 | ! 2 | ! setup.s (C) 1991 Linus Torvalds 3 | ! 4 | ! setup.s is responsible for getting the system data from the BIOS, 5 | ! and putting them into the appropriate places in system memory. 6 | ! both setup.s and system has been loaded by the bootblock. 7 | ! 8 | ! This code asks the bios for memory/disk/other parameters, and 9 | ! puts them in a "safe" place: 0x90000-0x901FF, ie where the 10 | ! boot-block used to be. It is then up to the protected mode 11 | ! system to read them from there before the area is overwritten 12 | ! for buffer-blocks. 13 | ! 14 | 15 | ! NOTE! These had better be the same as in bootsect.s! 16 | 17 | INITSEG = 0x9000 ! we move boot here - out of the way 18 | SYSSEG = 0x1000 ! system loaded at 0x10000 (65536). 19 | SETUPSEG = 0x9020 ! this is the current segment 20 | 21 | .globl begtext, begdata, begbss, endtext, enddata, endbss 22 | .text 23 | begtext: 24 | .data 25 | begdata: 26 | .bss 27 | begbss: 28 | .text 29 | 30 | entry start 31 | start: 32 | 33 | ! ok, the read went well so we get current cursor position and save it for 34 | ! posterity. 35 | 36 | mov ax,#INITSEG ! this is done in bootsect already, but... 37 | mov ds,ax 38 | mov ah,#0x03 ! read cursor pos 39 | xor bh,bh 40 | int 0x10 ! save it in known place, con_init fetches 41 | mov [0],dx ! it from 0x90000. 42 | ! Get memory size (extended mem, kB) 43 | 44 | mov ah,#0x88 45 | int 0x15 46 | mov [2],ax 47 | 48 | ! Get video-card data: 49 | 50 | mov ah,#0x0f 51 | int 0x10 52 | mov [4],bx ! bh = display page 53 | mov [6],ax ! al = video mode, ah = window width 54 | 55 | ! check for EGA/VGA and some config parameters 56 | 57 | mov ah,#0x12 58 | mov bl,#0x10 59 | int 0x10 60 | mov [8],ax 61 | mov [10],bx 62 | mov [12],cx 63 | 64 | ! Get hd0 data 65 | 66 | mov ax,#0x0000 67 | mov ds,ax 68 | lds si,[4*0x41] 69 | mov ax,#INITSEG 70 | mov es,ax 71 | mov di,#0x0080 72 | mov cx,#0x10 73 | rep 74 | movsb 75 | 76 | ! Get hd1 data 77 | 78 | mov ax,#0x0000 79 | mov ds,ax 80 | lds si,[4*0x46] 81 | mov ax,#INITSEG 82 | mov es,ax 83 | mov di,#0x0090 84 | mov cx,#0x10 85 | rep 86 | movsb 87 | 88 | ! Check that there IS a hd1 :-) 89 | 90 | mov ax,#0x01500 91 | mov dl,#0x81 92 | int 0x13 93 | jc no_disk1 94 | cmp ah,#3 95 | je is_disk1 96 | no_disk1: 97 | mov ax,#INITSEG 98 | mov es,ax 99 | mov di,#0x0090 100 | mov cx,#0x10 101 | mov ax,#0x00 102 | rep 103 | stosb 104 | is_disk1: 105 | 106 | ! now we want to move to protected mode ... 107 | 108 | cli ! no interrupts allowed ! 109 | 110 | ! first we move the system to it's rightful place 111 | 112 | mov ax,#0x0000 113 | cld ! 'direction'=0, movs moves forward 114 | do_move: 115 | mov es,ax ! destination segment 116 | add ax,#0x1000 117 | cmp ax,#0x9000 118 | jz end_move 119 | mov ds,ax ! source segment 120 | sub di,di 121 | sub si,si 122 | mov cx,#0x8000 123 | rep 124 | movsw 125 | jmp do_move 126 | 127 | ! then we load the segment descriptors 128 | 129 | end_move: 130 | mov ax,#SETUPSEG ! right, forgot this at first. didn't work :-) 131 | mov ds,ax 132 | lidt idt_48 ! load idt with 0,0 133 | lgdt gdt_48 ! load gdt with whatever appropriate 134 | 135 | ! that was painless, now we enable A20 136 | 137 | call empty_8042 138 | mov al,#0xD1 ! command write 139 | out #0x64,al 140 | call empty_8042 141 | mov al,#0xDF ! A20 on 142 | out #0x60,al 143 | call empty_8042 144 | 145 | ! well, that went ok, I hope. Now we have to reprogram the interrupts :-( 146 | ! we put them right after the intel-reserved hardware interrupts, at 147 | ! int 0x20-0x2F. There they won't mess up anything. Sadly IBM really 148 | ! messed this up with the original PC, and they haven't been able to 149 | ! rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f, 150 | ! which is used for the internal hardware interrupts as well. We just 151 | ! have to reprogram the 8259's, and it isn't fun. 152 | 153 | mov al,#0x11 ! initialization sequence 154 | out #0x20,al ! send it to 8259A-1 155 | .word 0x00eb,0x00eb ! jmp $+2, jmp $+2 156 | out #0xA0,al ! and to 8259A-2 157 | .word 0x00eb,0x00eb 158 | mov al,#0x20 ! start of hardware int's (0x20) 159 | out #0x21,al 160 | .word 0x00eb,0x00eb 161 | mov al,#0x28 ! start of hardware int's 2 (0x28) 162 | out #0xA1,al 163 | .word 0x00eb,0x00eb 164 | mov al,#0x04 ! 8259-1 is master 165 | out #0x21,al 166 | .word 0x00eb,0x00eb 167 | mov al,#0x02 ! 8259-2 is slave 168 | out #0xA1,al 169 | .word 0x00eb,0x00eb 170 | mov al,#0x01 ! 8086 mode for both 171 | out #0x21,al 172 | .word 0x00eb,0x00eb 173 | out #0xA1,al 174 | .word 0x00eb,0x00eb 175 | mov al,#0xFF ! mask off all interrupts for now 176 | out #0x21,al 177 | .word 0x00eb,0x00eb 178 | out #0xA1,al 179 | 180 | ! well, that certainly wasn't fun :-(. Hopefully it works, and we don't 181 | ! need no steenking BIOS anyway (except for the initial loading :-). 182 | ! The BIOS-routine wants lots of unnecessary data, and it's less 183 | ! "interesting" anyway. This is how REAL programmers do it. 184 | ! 185 | ! Well, now's the time to actually move into protected mode. To make 186 | ! things as simple as possible, we do no register set-up or anything, 187 | ! we let the gnu-compiled 32-bit programs do that. We just jump to 188 | ! absolute address 0x00000, in 32-bit protected mode. 189 | mov ax,#0x0001 ! protected mode (PE) bit 190 | lmsw ax ! This is it! 191 | jmpi 0,8 ! jmp offset 0 of segment 8 (cs) 192 | 193 | ! This routine checks that the keyboard command queue is empty 194 | ! No timeout is used - if this hangs there is something wrong with 195 | ! the machine, and we probably couldn't proceed anyway. 196 | empty_8042: 197 | .word 0x00eb,0x00eb 198 | in al,#0x64 ! 8042 status port 199 | test al,#2 ! is input buffer full? 200 | jnz empty_8042 ! yes - loop 201 | ret 202 | 203 | gdt: 204 | .word 0,0,0,0 ! dummy 205 | 206 | .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 207 | .word 0x0000 ! base address=0 208 | .word 0x9A00 ! code read/exec 209 | .word 0x00C0 ! granularity=4096, 386 210 | 211 | .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 212 | .word 0x0000 ! base address=0 213 | .word 0x9200 ! data read/write 214 | .word 0x00C0 ! granularity=4096, 386 215 | 216 | idt_48: 217 | .word 0 ! idt limit=0 218 | .word 0,0 ! idt base=0L 219 | 220 | gdt_48: 221 | .word 0x800 ! gdt limit=2048, 256 GDT entries 222 | .word 512+gdt,0x9 ! gdt base = 0X9xxxx 223 | 224 | .text 225 | endtext: 226 | .data 227 | enddata: 228 | .bss 229 | endbss: 230 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/Makefile: -------------------------------------------------------------------------------- 1 | AR =ar 2 | AS =as 3 | CC =gcc -mcpu=i386 -fno-stack-protector 4 | LD =ld 5 | CFLAGS =-Wall -fstrength-reduce -fomit-frame-pointer \ 6 | -nostdinc -I../include 7 | CPP =gcc -fno-stack-protector -E -nostdinc -I../include 8 | 9 | .c.s: 10 | $(CC) $(CFLAGS) \ 11 | -S -o $*.s $< 12 | .c.o: 13 | $(CC) $(CFLAGS) \ 14 | -c -o $*.o $< 15 | .s.o: 16 | $(AS) -o $*.o $< 17 | 18 | OBJS= open.o read_write.o inode.o file_table.o buffer.o super.o \ 19 | block_dev.o char_dev.o file_dev.o stat.o exec.o pipe.o namei.o \ 20 | bitmap.o fcntl.o ioctl.o truncate.o 21 | 22 | fs.o: $(OBJS) 23 | $(LD) -r -o fs.o $(OBJS) 24 | 25 | clean: 26 | rm -f core *.o *.a tmp_make 27 | for i in *.c;do rm -f `basename $$i .c`.s;done 28 | 29 | dep: 30 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 31 | (for i in *.c;do $(CPP) -M $$i;done) >> tmp_make 32 | cp tmp_make Makefile 33 | 34 | ### Dependencies: 35 | bitmap.o: bitmap.c ../include/string.h ../include/linux/sched.h \ 36 | ../include/linux/head.h ../include/linux/fs.h ../include/sys/types.h \ 37 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h 38 | block_dev.o: block_dev.c ../include/errno.h ../include/linux/sched.h \ 39 | ../include/linux/head.h ../include/linux/fs.h ../include/sys/types.h \ 40 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h \ 41 | ../include/asm/segment.h ../include/asm/system.h 42 | buffer.o: buffer.c ../include/stdarg.h ../include/linux/config.h \ 43 | ../include/linux/sched.h ../include/linux/head.h ../include/linux/fs.h \ 44 | ../include/sys/types.h ../include/linux/mm.h ../include/signal.h \ 45 | ../include/linux/kernel.h ../include/asm/system.h ../include/asm/io.h 46 | char_dev.o: char_dev.c ../include/errno.h ../include/sys/types.h \ 47 | ../include/linux/sched.h ../include/linux/head.h ../include/linux/fs.h \ 48 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h \ 49 | ../include/asm/segment.h ../include/asm/io.h 50 | exec.o: exec.c ../include/errno.h ../include/string.h \ 51 | ../include/sys/stat.h ../include/sys/types.h ../include/a.out.h \ 52 | ../include/linux/fs.h ../include/linux/sched.h ../include/linux/head.h \ 53 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h \ 54 | ../include/asm/segment.h 55 | fcntl.o: fcntl.c ../include/string.h ../include/errno.h \ 56 | ../include/linux/sched.h ../include/linux/head.h ../include/linux/fs.h \ 57 | ../include/sys/types.h ../include/linux/mm.h ../include/signal.h \ 58 | ../include/linux/kernel.h ../include/asm/segment.h ../include/fcntl.h \ 59 | ../include/sys/stat.h 60 | file_dev.o: file_dev.c ../include/errno.h ../include/fcntl.h \ 61 | ../include/sys/types.h ../include/linux/sched.h ../include/linux/head.h \ 62 | ../include/linux/fs.h ../include/linux/mm.h ../include/signal.h \ 63 | ../include/linux/kernel.h ../include/asm/segment.h 64 | file_table.o: file_table.c ../include/linux/fs.h ../include/sys/types.h 65 | inode.o: inode.c ../include/string.h ../include/sys/stat.h \ 66 | ../include/sys/types.h ../include/linux/sched.h ../include/linux/head.h \ 67 | ../include/linux/fs.h ../include/linux/mm.h ../include/signal.h \ 68 | ../include/linux/kernel.h ../include/asm/system.h 69 | ioctl.o: ioctl.c ../include/string.h ../include/errno.h \ 70 | ../include/sys/stat.h ../include/sys/types.h ../include/linux/sched.h \ 71 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 72 | ../include/signal.h 73 | namei.o: namei.c ../include/linux/sched.h ../include/linux/head.h \ 74 | ../include/linux/fs.h ../include/sys/types.h ../include/linux/mm.h \ 75 | ../include/signal.h ../include/linux/kernel.h ../include/asm/segment.h \ 76 | ../include/string.h ../include/fcntl.h ../include/errno.h \ 77 | ../include/const.h ../include/sys/stat.h 78 | open.o: open.c ../include/string.h ../include/errno.h ../include/fcntl.h \ 79 | ../include/sys/types.h ../include/utime.h ../include/sys/stat.h \ 80 | ../include/linux/sched.h ../include/linux/head.h ../include/linux/fs.h \ 81 | ../include/linux/mm.h ../include/signal.h ../include/linux/tty.h \ 82 | ../include/termios.h ../include/linux/kernel.h ../include/asm/segment.h 83 | pipe.o: pipe.c ../include/signal.h ../include/sys/types.h \ 84 | ../include/linux/sched.h ../include/linux/head.h ../include/linux/fs.h \ 85 | ../include/linux/mm.h ../include/asm/segment.h 86 | read_write.o: read_write.c ../include/sys/stat.h ../include/sys/types.h \ 87 | ../include/errno.h ../include/linux/kernel.h ../include/linux/sched.h \ 88 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 89 | ../include/signal.h ../include/asm/segment.h 90 | stat.o: stat.c ../include/errno.h ../include/sys/stat.h \ 91 | ../include/sys/types.h ../include/linux/fs.h ../include/linux/sched.h \ 92 | ../include/linux/head.h ../include/linux/mm.h ../include/signal.h \ 93 | ../include/linux/kernel.h ../include/asm/segment.h 94 | super.o: super.c ../include/linux/config.h ../include/linux/sched.h \ 95 | ../include/linux/head.h ../include/linux/fs.h ../include/sys/types.h \ 96 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h \ 97 | ../include/asm/system.h ../include/errno.h ../include/sys/stat.h 98 | truncate.o: truncate.c ../include/linux/sched.h ../include/linux/head.h \ 99 | ../include/linux/fs.h ../include/sys/types.h ../include/linux/mm.h \ 100 | ../include/signal.h ../include/sys/stat.h 101 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/bitmap.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* bitmap.c contains the code that handles the inode and block bitmaps */ 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #define clear_block(addr) \ 14 | __asm__ __volatile__ ("cld\n\t" \ 15 | "rep\n\t" \ 16 | "stosl" \ 17 | ::"a" (0),"c" (BLOCK_SIZE/4),"D" ((long) (addr))) 18 | 19 | #define set_bit(nr,addr) ({\ 20 | register int res ; \ 21 | __asm__ __volatile__("btsl %2,%3\n\tsetb %%al": \ 22 | "=a" (res):"0" (0),"r" (nr),"m" (*(addr))); \ 23 | res;}) 24 | 25 | #define clear_bit(nr,addr) ({\ 26 | register int res ; \ 27 | __asm__ __volatile__("btrl %2,%3\n\tsetnb %%al": \ 28 | "=a" (res):"0" (0),"r" (nr),"m" (*(addr))); \ 29 | res;}) 30 | 31 | #define find_first_zero(addr) ({ \ 32 | int __res; \ 33 | __asm__ __volatile__ ("cld\n" \ 34 | "1:\tlodsl\n\t" \ 35 | "notl %%eax\n\t" \ 36 | "bsfl %%eax,%%edx\n\t" \ 37 | "je 2f\n\t" \ 38 | "addl %%edx,%%ecx\n\t" \ 39 | "jmp 3f\n" \ 40 | "2:\taddl $32,%%ecx\n\t" \ 41 | "cmpl $8192,%%ecx\n\t" \ 42 | "jl 1b\n" \ 43 | "3:" \ 44 | :"=c" (__res):"c" (0),"S" (addr)); \ 45 | __res;}) 46 | 47 | void free_block(int dev, int block) 48 | { 49 | struct super_block * sb; 50 | struct buffer_head * bh; 51 | 52 | if (!(sb = get_super(dev))) 53 | panic("trying to free block on nonexistent device"); 54 | if (block < sb->s_firstdatazone || block >= sb->s_nzones) 55 | panic("trying to free block not in datazone"); 56 | bh = get_hash_table(dev,block); 57 | if (bh) { 58 | if (bh->b_count != 1) { 59 | printk("trying to free block (%04x:%d), count=%d\n", 60 | dev,block,bh->b_count); 61 | return; 62 | } 63 | bh->b_dirt=0; 64 | bh->b_uptodate=0; 65 | brelse(bh); 66 | } 67 | block -= sb->s_firstdatazone - 1 ; 68 | if (clear_bit(block&8191,sb->s_zmap[block/8192]->b_data)) { 69 | printk("block (%04x:%d) ",dev,block+sb->s_firstdatazone-1); 70 | panic("free_block: bit already cleared"); 71 | } 72 | sb->s_zmap[block/8192]->b_dirt = 1; 73 | } 74 | 75 | int new_block(int dev) 76 | { 77 | struct buffer_head * bh; 78 | struct super_block * sb; 79 | int i,j; 80 | 81 | if (!(sb = get_super(dev))) 82 | panic("trying to get new block from nonexistant device"); 83 | j = 8192; 84 | for (i=0 ; i<8 ; i++) 85 | if ((bh=sb->s_zmap[i])) 86 | if ((j=find_first_zero(bh->b_data))<8192) 87 | break; 88 | if (i>=8 || !bh || j>=8192) 89 | return 0; 90 | if (set_bit(j,bh->b_data)) 91 | panic("new_block: bit already set"); 92 | bh->b_dirt = 1; 93 | j += i*8192 + sb->s_firstdatazone-1; 94 | if (j >= sb->s_nzones) 95 | return 0; 96 | if (!(bh=getblk(dev,j))) 97 | panic("new_block: cannot get block"); 98 | if (bh->b_count != 1) 99 | panic("new block: count is != 1"); 100 | clear_block(bh->b_data); 101 | bh->b_uptodate = 1; 102 | bh->b_dirt = 1; 103 | brelse(bh); 104 | return j; 105 | } 106 | 107 | void free_inode(struct m_inode * inode) 108 | { 109 | struct super_block * sb; 110 | struct buffer_head * bh; 111 | 112 | if (!inode) 113 | return; 114 | if (!inode->i_dev) { 115 | memset(inode,0,sizeof(*inode)); 116 | return; 117 | } 118 | if (inode->i_count>1) { 119 | printk("trying to free inode with count=%d\n",inode->i_count); 120 | panic("free_inode"); 121 | } 122 | if (inode->i_nlinks) 123 | panic("trying to free inode with links"); 124 | if (!(sb = get_super(inode->i_dev))) 125 | panic("trying to free inode on nonexistent device"); 126 | if (inode->i_num < 1 || inode->i_num > sb->s_ninodes) 127 | panic("trying to free inode 0 or nonexistant inode"); 128 | if (!(bh=sb->s_imap[inode->i_num>>13])) 129 | panic("nonexistent imap in superblock"); 130 | if (clear_bit(inode->i_num&8191,bh->b_data)) 131 | printk("free_inode: bit already cleared.\n\r"); 132 | bh->b_dirt = 1; 133 | memset(inode,0,sizeof(*inode)); 134 | } 135 | 136 | struct m_inode * new_inode(int dev) 137 | { 138 | struct m_inode * inode; 139 | struct super_block * sb; 140 | struct buffer_head * bh; 141 | int i,j; 142 | 143 | if (!(inode=get_empty_inode())) 144 | return NULL; 145 | if (!(sb = get_super(dev))) 146 | panic("new_inode with unknown device"); 147 | j = 8192; 148 | for (i=0 ; i<8 ; i++) 149 | if ((bh=sb->s_imap[i])) 150 | if ((j=find_first_zero(bh->b_data))<8192) 151 | break; 152 | if (!bh || j >= 8192 || j+i*8192 > sb->s_ninodes) { 153 | iput(inode); 154 | return NULL; 155 | } 156 | if (set_bit(j,bh->b_data)) 157 | panic("new_inode: bit already set"); 158 | bh->b_dirt = 1; 159 | inode->i_count=1; 160 | inode->i_nlinks=1; 161 | inode->i_dev=dev; 162 | inode->i_uid=current->euid; 163 | inode->i_gid=current->egid; 164 | inode->i_dirt=1; 165 | inode->i_num = j + i*8192; 166 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 167 | return inode; 168 | } 169 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/block_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/block_dev.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int block_write(int dev, long * pos, char * buf, int count) 15 | { 16 | int block = *pos >> BLOCK_SIZE_BITS; 17 | int offset = *pos & (BLOCK_SIZE-1); 18 | int chars; 19 | int written = 0; 20 | struct buffer_head * bh; 21 | register char * p; 22 | 23 | while (count>0) { 24 | chars = BLOCK_SIZE - offset; 25 | if (chars > count) 26 | chars=count; 27 | if (chars == BLOCK_SIZE) 28 | bh = getblk(dev,block); 29 | else 30 | bh = breada(dev,block,block+1,block+2,-1); 31 | block++; 32 | if (!bh) 33 | return written?written:-EIO; 34 | p = offset + bh->b_data; 35 | offset = 0; 36 | *pos += chars; 37 | written += chars; 38 | count -= chars; 39 | while (chars-->0) 40 | *(p++) = get_fs_byte(buf++); 41 | bh->b_dirt = 1; 42 | brelse(bh); 43 | } 44 | return written; 45 | } 46 | 47 | int block_read(int dev, unsigned long * pos, char * buf, int count) 48 | { 49 | int block = *pos >> BLOCK_SIZE_BITS; 50 | int offset = *pos & (BLOCK_SIZE-1); 51 | int chars; 52 | int read = 0; 53 | struct buffer_head * bh; 54 | register char * p; 55 | 56 | while (count>0) { 57 | chars = BLOCK_SIZE-offset; 58 | if (chars > count) 59 | chars = count; 60 | if (!(bh = breada(dev,block,block+1,block+2,-1))) 61 | return read?read:-EIO; 62 | block++; 63 | p = offset + bh->b_data; 64 | offset = 0; 65 | *pos += chars; 66 | read += chars; 67 | count -= chars; 68 | while (chars-->0) 69 | put_fs_byte(*(p++),buf++); 70 | brelse(bh); 71 | } 72 | return read; 73 | } 74 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/char_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/char_dev.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | extern int tty_read(unsigned minor,char * buf,int count); 17 | extern int tty_write(unsigned minor,char * buf,int count); 18 | 19 | typedef int (*crw_ptr)(int rw,unsigned minor,char * buf,int count,off_t * pos); 20 | 21 | static int rw_ttyx(int rw,unsigned minor,char * buf,int count,off_t * pos) 22 | { 23 | return ((rw==READ)?tty_read(minor,buf,count): 24 | tty_write(minor,buf,count)); 25 | } 26 | 27 | static int rw_tty(int rw,unsigned minor,char * buf,int count, off_t * pos) 28 | { 29 | if (current->tty<0) 30 | return -EPERM; 31 | return rw_ttyx(rw,current->tty,buf,count,pos); 32 | } 33 | 34 | static int rw_ram(int rw,char * buf, int count, off_t *pos) 35 | { 36 | return -EIO; 37 | } 38 | 39 | static int rw_mem(int rw,char * buf, int count, off_t * pos) 40 | { 41 | return -EIO; 42 | } 43 | 44 | static int rw_kmem(int rw,char * buf, int count, off_t * pos) 45 | { 46 | return -EIO; 47 | } 48 | 49 | static int rw_port(int rw,char * buf, int count, off_t * pos) 50 | { 51 | int i=*pos; 52 | 53 | while (count-->0 && i<65536) { 54 | if (rw==READ) 55 | put_fs_byte(inb(i),buf++); 56 | else 57 | outb(get_fs_byte(buf++),i); 58 | i++; 59 | } 60 | i -= *pos; 61 | *pos += i; 62 | return i; 63 | } 64 | 65 | static int rw_memory(int rw, unsigned minor, char * buf, int count, off_t * pos) 66 | { 67 | switch(minor) { 68 | case 0: 69 | return rw_ram(rw,buf,count,pos); 70 | case 1: 71 | return rw_mem(rw,buf,count,pos); 72 | case 2: 73 | return rw_kmem(rw,buf,count,pos); 74 | case 3: 75 | return (rw==READ)?0:count; /* rw_null */ 76 | case 4: 77 | return rw_port(rw,buf,count,pos); 78 | default: 79 | return -EIO; 80 | } 81 | } 82 | 83 | #define NRDEVS ((sizeof (crw_table))/(sizeof (crw_ptr))) 84 | 85 | static crw_ptr crw_table[]={ 86 | NULL, /* nodev */ 87 | rw_memory, /* /dev/mem etc */ 88 | NULL, /* /dev/fd */ 89 | NULL, /* /dev/hd */ 90 | rw_ttyx, /* /dev/ttyx */ 91 | rw_tty, /* /dev/tty */ 92 | NULL, /* /dev/lp */ 93 | NULL}; /* unnamed pipes */ 94 | 95 | int rw_char(int rw,int dev, char * buf, int count, off_t * pos) 96 | { 97 | crw_ptr call_addr; 98 | 99 | if (MAJOR(dev)>=NRDEVS) 100 | return -ENODEV; 101 | if (!(call_addr=crw_table[MAJOR(dev)])) 102 | return -ENODEV; 103 | return call_addr(rw,MINOR(dev),buf,count,pos); 104 | } 105 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/fcntl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/fcntl.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* #include */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | extern int sys_close(int fd); 17 | 18 | static int dupfd(unsigned int fd, unsigned int arg) 19 | { 20 | if (fd >= NR_OPEN || !current->filp[fd]) 21 | return -EBADF; 22 | if (arg >= NR_OPEN) 23 | return -EINVAL; 24 | while (arg < NR_OPEN) 25 | if (current->filp[arg]) 26 | arg++; 27 | else 28 | break; 29 | if (arg >= NR_OPEN) 30 | return -EMFILE; 31 | current->close_on_exec &= ~(1<filp[arg] = current->filp[fd])->f_count++; 33 | return arg; 34 | } 35 | 36 | int sys_dup2(unsigned int oldfd, unsigned int newfd) 37 | { 38 | sys_close(newfd); 39 | return dupfd(oldfd,newfd); 40 | } 41 | 42 | int sys_dup(unsigned int fildes) 43 | { 44 | return dupfd(fildes,0); 45 | } 46 | 47 | int sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) 48 | { 49 | struct file * filp; 50 | 51 | if (fd >= NR_OPEN || !(filp = current->filp[fd])) 52 | return -EBADF; 53 | switch (cmd) { 54 | case F_DUPFD: 55 | return dupfd(fd,arg); 56 | case F_GETFD: 57 | return (current->close_on_exec>>fd)&1; 58 | case F_SETFD: 59 | if (arg&1) 60 | current->close_on_exec |= (1<close_on_exec &= ~(1<f_flags; 66 | case F_SETFL: 67 | filp->f_flags &= ~(O_APPEND | O_NONBLOCK); 68 | filp->f_flags |= arg & (O_APPEND | O_NONBLOCK); 69 | return 0; 70 | case F_GETLK: case F_SETLK: case F_SETLKW: 71 | return -1; 72 | default: 73 | return -1; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/file_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/file_dev.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define MIN(a,b) (((a)<(b))?(a):(b)) 15 | #define MAX(a,b) (((a)>(b))?(a):(b)) 16 | 17 | int file_read(struct m_inode * inode, struct file * filp, char * buf, int count) 18 | { 19 | int left,chars,nr; 20 | struct buffer_head * bh; 21 | 22 | if ((left=count)<=0) 23 | return 0; 24 | while (left) { 25 | if ((nr = bmap(inode,(filp->f_pos)/BLOCK_SIZE))) { 26 | if (!(bh=bread(inode->i_dev,nr))) 27 | break; 28 | } else 29 | bh = NULL; 30 | nr = filp->f_pos % BLOCK_SIZE; 31 | chars = MIN( BLOCK_SIZE-nr , left ); 32 | filp->f_pos += chars; 33 | left -= chars; 34 | if (bh) { 35 | char * p = nr + bh->b_data; 36 | while (chars-->0) 37 | put_fs_byte(*(p++),buf++); 38 | brelse(bh); 39 | } else { 40 | while (chars-->0) 41 | put_fs_byte(0,buf++); 42 | } 43 | } 44 | inode->i_atime = CURRENT_TIME; 45 | return (count-left)?(count-left):-ERROR; 46 | } 47 | 48 | int file_write(struct m_inode * inode, struct file * filp, char * buf, int count) 49 | { 50 | off_t pos; 51 | int block,c; 52 | struct buffer_head * bh; 53 | char * p; 54 | int i=0; 55 | 56 | /* 57 | * ok, append may not work when many processes are writing at the same time 58 | * but so what. That way leads to madness anyway. 59 | */ 60 | if (filp->f_flags & O_APPEND) 61 | pos = inode->i_size; 62 | else 63 | pos = filp->f_pos; 64 | while (ii_dev,block))) 68 | break; 69 | c = pos % BLOCK_SIZE; 70 | p = c + bh->b_data; 71 | bh->b_dirt = 1; 72 | c = BLOCK_SIZE-c; 73 | if (c > count-i) c = count-i; 74 | pos += c; 75 | if (pos > inode->i_size) { 76 | inode->i_size = pos; 77 | inode->i_dirt = 1; 78 | } 79 | i += c; 80 | while (c-->0) 81 | *(p++) = get_fs_byte(buf++); 82 | brelse(bh); 83 | } 84 | inode->i_mtime = CURRENT_TIME; 85 | if (!(filp->f_flags & O_APPEND)) { 86 | filp->f_pos = pos; 87 | inode->i_ctime = CURRENT_TIME; 88 | } 89 | return (i?i:-1); 90 | } 91 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/file_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/file_table.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | struct file file_table[NR_FILE]; 10 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/ioctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/ioctl.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* #include */ 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | extern int tty_ioctl(int dev, int cmd, int arg); 14 | 15 | typedef int (*ioctl_ptr)(int dev,int cmd,int arg); 16 | 17 | #define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr))) 18 | 19 | static ioctl_ptr ioctl_table[]={ 20 | NULL, /* nodev */ 21 | NULL, /* /dev/mem */ 22 | NULL, /* /dev/fd */ 23 | NULL, /* /dev/hd */ 24 | tty_ioctl, /* /dev/ttyx */ 25 | tty_ioctl, /* /dev/tty */ 26 | NULL, /* /dev/lp */ 27 | NULL}; /* named pipes */ 28 | 29 | 30 | int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) 31 | { 32 | struct file * filp; 33 | int dev,mode; 34 | 35 | if (fd >= NR_OPEN || !(filp = current->filp[fd])) 36 | return -EBADF; 37 | mode=filp->f_inode->i_mode; 38 | if (!S_ISCHR(mode) && !S_ISBLK(mode)) 39 | return -EINVAL; 40 | dev = filp->f_inode->i_zone[0]; 41 | if (MAJOR(dev) >= NRDEVS) 42 | return -ENODEV; 43 | if (!ioctl_table[MAJOR(dev)]) 44 | return -ENOTTY; 45 | return ioctl_table[MAJOR(dev)](dev,cmd,arg); 46 | } 47 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/open.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/open.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* #include */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int sys_ustat(int dev, struct ustat * ubuf) 20 | { 21 | return -ENOSYS; 22 | } 23 | 24 | int sys_utime(char * filename, struct utimbuf * times) 25 | { 26 | struct m_inode * inode; 27 | long actime,modtime; 28 | 29 | if (!(inode=namei(filename))) 30 | return -ENOENT; 31 | if (times) { 32 | actime = get_fs_long((unsigned long *) ×->actime); 33 | modtime = get_fs_long((unsigned long *) ×->modtime); 34 | } else 35 | actime = modtime = CURRENT_TIME; 36 | inode->i_atime = actime; 37 | inode->i_mtime = modtime; 38 | inode->i_dirt = 1; 39 | iput(inode); 40 | return 0; 41 | } 42 | 43 | /* 44 | * XXX should we use the real or effective uid? BSD uses the real uid, 45 | * so as to make this call useful to setuid programs. 46 | */ 47 | int sys_access(const char * filename,int mode) 48 | { 49 | struct m_inode * inode; 50 | int res, i_mode; 51 | 52 | mode &= 0007; 53 | if (!(inode=namei(filename))) 54 | return -EACCES; 55 | i_mode = res = inode->i_mode & 0777; 56 | iput(inode); 57 | if (current->uid == inode->i_uid) 58 | res >>= 6; 59 | else if (current->gid == inode->i_gid) 60 | res >>= 6; 61 | if ((res & 0007 & mode) == mode) 62 | return 0; 63 | /* 64 | * XXX we are doing this test last because we really should be 65 | * swapping the effective with the real user id (temporarily), 66 | * and then calling suser() routine. If we do call the 67 | * suser() routine, it needs to be called last. 68 | */ 69 | if ((!current->uid) && 70 | (!(mode & 1) || (i_mode & 0111))) 71 | return 0; 72 | return -EACCES; 73 | } 74 | 75 | int sys_chdir(const char * filename) 76 | { 77 | struct m_inode * inode; 78 | 79 | if (!(inode = namei(filename))) 80 | return -ENOENT; 81 | if (!S_ISDIR(inode->i_mode)) { 82 | iput(inode); 83 | return -ENOTDIR; 84 | } 85 | iput(current->pwd); 86 | current->pwd = inode; 87 | return (0); 88 | } 89 | 90 | int sys_chroot(const char * filename) 91 | { 92 | struct m_inode * inode; 93 | 94 | if (!(inode=namei(filename))) 95 | return -ENOENT; 96 | if (!S_ISDIR(inode->i_mode)) { 97 | iput(inode); 98 | return -ENOTDIR; 99 | } 100 | iput(current->root); 101 | current->root = inode; 102 | return (0); 103 | } 104 | 105 | int sys_chmod(const char * filename,int mode) 106 | { 107 | struct m_inode * inode; 108 | 109 | if (!(inode=namei(filename))) 110 | return -ENOENT; 111 | if ((current->euid != inode->i_uid) && !suser()) { 112 | iput(inode); 113 | return -EACCES; 114 | } 115 | inode->i_mode = (mode & 07777) | (inode->i_mode & ~07777); 116 | inode->i_dirt = 1; 117 | iput(inode); 118 | return 0; 119 | } 120 | 121 | int sys_chown(const char * filename,int uid,int gid) 122 | { 123 | struct m_inode * inode; 124 | 125 | if (!(inode=namei(filename))) 126 | return -ENOENT; 127 | if (!suser()) { 128 | iput(inode); 129 | return -EACCES; 130 | } 131 | inode->i_uid=uid; 132 | inode->i_gid=gid; 133 | inode->i_dirt=1; 134 | iput(inode); 135 | return 0; 136 | } 137 | 138 | int sys_open(const char * filename,int flag,int mode) 139 | { 140 | struct m_inode * inode; 141 | struct file * f; 142 | int i,fd; 143 | 144 | mode &= 0777 & ~current->umask; 145 | for(fd=0 ; fdfilp[fd]) 147 | break; 148 | if (fd>=NR_OPEN) 149 | return -EINVAL; 150 | current->close_on_exec &= ~(1<f_count) break; 154 | if (i>=NR_FILE) 155 | return -EINVAL; 156 | (current->filp[fd]=f)->f_count++; 157 | if ((i=open_namei(filename,flag,mode,&inode))<0) { 158 | current->filp[fd]=NULL; 159 | f->f_count=0; 160 | return i; 161 | } 162 | /* ttys are somewhat special (ttyxx major==4, tty major==5) */ 163 | if (S_ISCHR(inode->i_mode)) { 164 | if (MAJOR(inode->i_zone[0])==4) { 165 | if (current->leader && current->tty<0) { 166 | current->tty = MINOR(inode->i_zone[0]); 167 | tty_table[current->tty].pgrp = current->pgrp; 168 | } 169 | } else if (MAJOR(inode->i_zone[0])==5) 170 | if (current->tty<0) { 171 | iput(inode); 172 | current->filp[fd]=NULL; 173 | f->f_count=0; 174 | return -EPERM; 175 | } 176 | } 177 | /* Likewise with block-devices: check for floppy_change */ 178 | if (S_ISBLK(inode->i_mode)) 179 | check_disk_change(inode->i_zone[0]); 180 | f->f_mode = inode->i_mode; 181 | f->f_flags = flag; 182 | f->f_count = 1; 183 | f->f_inode = inode; 184 | f->f_pos = 0; 185 | return (fd); 186 | } 187 | 188 | int sys_creat(const char * pathname, int mode) 189 | { 190 | return sys_open(pathname, O_CREAT | O_TRUNC, mode); 191 | } 192 | 193 | int sys_close(unsigned int fd) 194 | { 195 | struct file * filp; 196 | 197 | if (fd >= NR_OPEN) 198 | return -EINVAL; 199 | current->close_on_exec &= ~(1<filp[fd])) 201 | return -EINVAL; 202 | current->filp[fd] = NULL; 203 | if (filp->f_count == 0) 204 | panic("Close: file count is 0"); 205 | if (--filp->f_count) 206 | return (0); 207 | iput(filp->f_inode); 208 | return (0); 209 | } 210 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/pipe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/pipe.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include /* for get_free_page */ 11 | #include 12 | 13 | int read_pipe(struct m_inode * inode, char * buf, int count) 14 | { 15 | int chars, size, read = 0; 16 | 17 | while (count>0) { 18 | while (!(size=PIPE_SIZE(*inode))) { 19 | wake_up(&inode->i_wait); 20 | if (inode->i_count != 2) /* are there any writers? */ 21 | return read; 22 | sleep_on(&inode->i_wait); 23 | } 24 | chars = PAGE_SIZE-PIPE_TAIL(*inode); 25 | if (chars > count) 26 | chars = count; 27 | if (chars > size) 28 | chars = size; 29 | count -= chars; 30 | read += chars; 31 | size = PIPE_TAIL(*inode); 32 | PIPE_TAIL(*inode) += chars; 33 | PIPE_TAIL(*inode) &= (PAGE_SIZE-1); 34 | while (chars-->0) 35 | put_fs_byte(((char *)inode->i_size)[size++],buf++); 36 | } 37 | wake_up(&inode->i_wait); 38 | return read; 39 | } 40 | 41 | int write_pipe(struct m_inode * inode, char * buf, int count) 42 | { 43 | int chars, size, written = 0; 44 | 45 | while (count>0) { 46 | while (!(size=(PAGE_SIZE-1)-PIPE_SIZE(*inode))) { 47 | wake_up(&inode->i_wait); 48 | if (inode->i_count != 2) { /* no readers */ 49 | current->signal |= (1<<(SIGPIPE-1)); 50 | return written?written:-1; 51 | } 52 | sleep_on(&inode->i_wait); 53 | } 54 | chars = PAGE_SIZE-PIPE_HEAD(*inode); 55 | if (chars > count) 56 | chars = count; 57 | if (chars > size) 58 | chars = size; 59 | count -= chars; 60 | written += chars; 61 | size = PIPE_HEAD(*inode); 62 | PIPE_HEAD(*inode) += chars; 63 | PIPE_HEAD(*inode) &= (PAGE_SIZE-1); 64 | while (chars-->0) 65 | ((char *)inode->i_size)[size++]=get_fs_byte(buf++); 66 | } 67 | wake_up(&inode->i_wait); 68 | return written; 69 | } 70 | 71 | int sys_pipe(unsigned long * fildes) 72 | { 73 | struct m_inode * inode; 74 | struct file * f[2]; 75 | int fd[2]; 76 | int i,j; 77 | 78 | j=0; 79 | for(i=0;j<2 && if_count++; 82 | if (j==1) 83 | f[0]->f_count=0; 84 | if (j<2) 85 | return -1; 86 | j=0; 87 | for(i=0;j<2 && ifilp[i]) { 89 | current->filp[ fd[j]=i ] = f[j]; 90 | j++; 91 | } 92 | if (j==1) 93 | current->filp[fd[0]]=NULL; 94 | if (j<2) { 95 | f[0]->f_count=f[1]->f_count=0; 96 | return -1; 97 | } 98 | if (!(inode=get_pipe_inode())) { 99 | current->filp[fd[0]] = 100 | current->filp[fd[1]] = NULL; 101 | f[0]->f_count = f[1]->f_count = 0; 102 | return -1; 103 | } 104 | f[0]->f_inode = f[1]->f_inode = inode; 105 | f[0]->f_pos = f[1]->f_pos = 0; 106 | f[0]->f_mode = 1; /* read */ 107 | f[1]->f_mode = 2; /* write */ 108 | put_fs_long(fd[0],0+fildes); 109 | put_fs_long(fd[1],1+fildes); 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/read_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/read_write.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | extern int rw_char(int rw,int dev, char * buf, int count, off_t * pos); 16 | extern int read_pipe(struct m_inode * inode, char * buf, int count); 17 | extern int write_pipe(struct m_inode * inode, char * buf, int count); 18 | extern int block_read(int dev, off_t * pos, char * buf, int count); 19 | extern int block_write(int dev, off_t * pos, char * buf, int count); 20 | extern int file_read(struct m_inode * inode, struct file * filp, 21 | char * buf, int count); 22 | extern int file_write(struct m_inode * inode, struct file * filp, 23 | char * buf, int count); 24 | 25 | int sys_lseek(unsigned int fd,off_t offset, int origin) 26 | { 27 | struct file * file; 28 | int tmp; 29 | 30 | if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode) 31 | || !IS_SEEKABLE(MAJOR(file->f_inode->i_dev))) 32 | return -EBADF; 33 | if (file->f_inode->i_pipe) 34 | return -ESPIPE; 35 | switch (origin) { 36 | case 0: 37 | if (offset<0) return -EINVAL; 38 | file->f_pos=offset; 39 | break; 40 | case 1: 41 | if (file->f_pos+offset<0) return -EINVAL; 42 | file->f_pos += offset; 43 | break; 44 | case 2: 45 | if ((tmp=file->f_inode->i_size+offset) < 0) 46 | return -EINVAL; 47 | file->f_pos = tmp; 48 | break; 49 | default: 50 | return -EINVAL; 51 | } 52 | return file->f_pos; 53 | } 54 | 55 | int sys_read(unsigned int fd,char * buf,int count) 56 | { 57 | struct file * file; 58 | struct m_inode * inode; 59 | 60 | if (fd>=NR_OPEN || count<0 || !(file=current->filp[fd])) 61 | return -EINVAL; 62 | if (!count) 63 | return 0; 64 | verify_area(buf,count); 65 | inode = file->f_inode; 66 | if (inode->i_pipe) 67 | return (file->f_mode&1)?read_pipe(inode,buf,count):-EIO; 68 | if (S_ISCHR(inode->i_mode)) 69 | return rw_char(READ,inode->i_zone[0],buf,count,&file->f_pos); 70 | if (S_ISBLK(inode->i_mode)) 71 | return block_read(inode->i_zone[0],&file->f_pos,buf,count); 72 | if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode)) { 73 | if (count+file->f_pos > inode->i_size) 74 | count = inode->i_size - file->f_pos; 75 | if (count<=0) 76 | return 0; 77 | return file_read(inode,file,buf,count); 78 | } 79 | printk("(Read)inode->i_mode=%06o\n\r",inode->i_mode); 80 | return -EINVAL; 81 | } 82 | 83 | int sys_write(unsigned int fd,char * buf,int count) 84 | { 85 | struct file * file; 86 | struct m_inode * inode; 87 | 88 | if (fd>=NR_OPEN || count <0 || !(file=current->filp[fd])) 89 | return -EINVAL; 90 | if (!count) 91 | return 0; 92 | inode=file->f_inode; 93 | if (inode->i_pipe) 94 | return (file->f_mode&2)?write_pipe(inode,buf,count):-EIO; 95 | if (S_ISCHR(inode->i_mode)) 96 | return rw_char(WRITE,inode->i_zone[0],buf,count,&file->f_pos); 97 | if (S_ISBLK(inode->i_mode)) 98 | return block_write(inode->i_zone[0],&file->f_pos,buf,count); 99 | if (S_ISREG(inode->i_mode)) 100 | return file_write(inode,file,buf,count); 101 | printk("(Write)inode->i_mode=%06o\n\r",inode->i_mode); 102 | return -EINVAL; 103 | } 104 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/stat.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | static void cp_stat(struct m_inode * inode, struct stat * statbuf) 16 | { 17 | struct stat tmp; 18 | int i; 19 | 20 | verify_area(statbuf,sizeof (* statbuf)); 21 | tmp.st_dev = inode->i_dev; 22 | tmp.st_ino = inode->i_num; 23 | tmp.st_mode = inode->i_mode; 24 | tmp.st_nlink = inode->i_nlinks; 25 | tmp.st_uid = inode->i_uid; 26 | tmp.st_gid = inode->i_gid; 27 | tmp.st_rdev = inode->i_zone[0]; 28 | tmp.st_size = inode->i_size; 29 | tmp.st_atime = inode->i_atime; 30 | tmp.st_mtime = inode->i_mtime; 31 | tmp.st_ctime = inode->i_ctime; 32 | for (i=0 ; i= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode)) 53 | return -EBADF; 54 | cp_stat(inode,statbuf); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/fs/truncate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/truncate.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | static void free_ind(int dev,int block) 12 | { 13 | struct buffer_head * bh; 14 | unsigned short * p; 15 | int i; 16 | 17 | if (!block) 18 | return; 19 | if ((bh=bread(dev,block))) { 20 | p = (unsigned short *) bh->b_data; 21 | for (i=0;i<512;i++,p++) 22 | if (*p) 23 | free_block(dev,*p); 24 | brelse(bh); 25 | } 26 | free_block(dev,block); 27 | } 28 | 29 | static void free_dind(int dev,int block) 30 | { 31 | struct buffer_head * bh; 32 | unsigned short * p; 33 | int i; 34 | 35 | if (!block) 36 | return; 37 | if ((bh=bread(dev,block))) { 38 | p = (unsigned short *) bh->b_data; 39 | for (i=0;i<512;i++,p++) 40 | if (*p) 41 | free_ind(dev,*p); 42 | brelse(bh); 43 | } 44 | free_block(dev,block); 45 | } 46 | 47 | void truncate(struct m_inode * inode) 48 | { 49 | int i; 50 | 51 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) 52 | return; 53 | for (i=0;i<7;i++) 54 | if (inode->i_zone[i]) { 55 | free_block(inode->i_dev,inode->i_zone[i]); 56 | inode->i_zone[i]=0; 57 | } 58 | free_ind(inode->i_dev,inode->i_zone[7]); 59 | free_dind(inode->i_dev,inode->i_zone[8]); 60 | inode->i_zone[7] = inode->i_zone[8] = 0; 61 | inode->i_size = 0; 62 | inode->i_dirt = 1; 63 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/asm/io.h: -------------------------------------------------------------------------------- 1 | #define outb(value,port) \ 2 | __asm__ ("outb %%al,%%dx"::"a" (value),"d" (port)) 3 | 4 | 5 | #define inb(port) ({ \ 6 | unsigned char _v; \ 7 | __asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \ 8 | _v; \ 9 | }) 10 | 11 | #define outb_p(value,port) \ 12 | __asm__ ("outb %%al,%%dx\n" \ 13 | "\tjmp 1f\n" \ 14 | "1:\tjmp 1f\n" \ 15 | "1:"::"a" (value),"d" (port)) 16 | 17 | #define inb_p(port) ({ \ 18 | unsigned char _v; \ 19 | __asm__ volatile ("inb %%dx,%%al\n" \ 20 | "\tjmp 1f\n" \ 21 | "1:\tjmp 1f\n" \ 22 | "1:":"=a" (_v):"d" (port)); \ 23 | _v; \ 24 | }) 25 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/asm/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NOTE!!! memcpy(dest,src,n) assumes ds=es=normal data segment. This 3 | * goes for all kernel functions (ds=es=kernel space, fs=local data, 4 | * gs=null), as well as for all well-behaving user programs (ds=es= 5 | * user data space). This is NOT a bug, as any user program that changes 6 | * es deserves to die if it isn't careful. 7 | */ 8 | #define memcpy(dest,src,n) ({ \ 9 | void * _res = dest; \ 10 | __asm__ ("cld;rep;movsb" \ 11 | ::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \ 12 | ); \ 13 | _res; \ 14 | }) 15 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/asm/segment.h: -------------------------------------------------------------------------------- 1 | static inline unsigned char get_fs_byte(const char * addr) 2 | { 3 | unsigned register char _v; 4 | 5 | __asm__ ("movb %%fs:%1,%0":"=r" (_v):"m" (*addr)); 6 | return _v; 7 | } 8 | 9 | static inline unsigned short get_fs_word(const unsigned short *addr) 10 | { 11 | unsigned short _v; 12 | 13 | __asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr)); 14 | return _v; 15 | } 16 | 17 | static inline unsigned long get_fs_long(const unsigned long *addr) 18 | { 19 | unsigned long _v; 20 | 21 | __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \ 22 | return _v; 23 | } 24 | 25 | static inline void put_fs_byte(char val,char *addr) 26 | { 27 | __asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr)); 28 | } 29 | 30 | static inline void put_fs_word(short val,short * addr) 31 | { 32 | __asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr)); 33 | } 34 | 35 | static inline void put_fs_long(unsigned long val,unsigned long * addr) 36 | { 37 | __asm__ ("movl %0,%%fs:%1"::"r" (val),"m" (*addr)); 38 | } 39 | 40 | /* 41 | * Someone who knows GNU asm better than I should double check the followig. 42 | * It seems to work, but I don't know if I'm doing something subtly wrong. 43 | * --- TYT, 11/24/91 44 | * [ nothing wrong here, Linus ] 45 | */ 46 | 47 | static inline unsigned long get_fs() 48 | { 49 | unsigned short _v; 50 | __asm__("mov %%fs,%%ax":"=a" (_v):); 51 | return _v; 52 | } 53 | 54 | static inline unsigned long get_ds() 55 | { 56 | unsigned short _v; 57 | __asm__("mov %%ds,%%ax":"=a" (_v):); 58 | return _v; 59 | } 60 | 61 | static inline void set_fs(unsigned long val) 62 | { 63 | __asm__("mov %0,%%fs"::"a" ((unsigned short) val)); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/asm/system.h: -------------------------------------------------------------------------------- 1 | #define move_to_user_mode() \ 2 | __asm__ ("movl %%esp,%%eax\n\t" \ 3 | "pushl $0x17\n\t" \ 4 | "pushl %%eax\n\t" \ 5 | "pushfl\n\t" \ 6 | "pushl $0x0f\n\t" \ 7 | "pushl $1f\n\t" \ 8 | "iret\n" \ 9 | "1:\tmovl $0x17,%%eax\n\t" \ 10 | "movw %%ax,%%ds\n\t" \ 11 | "movw %%ax,%%es\n\t" \ 12 | "movw %%ax,%%fs\n\t" \ 13 | "movw %%ax,%%gs" \ 14 | :::"ax") 15 | 16 | #define sti() __asm__ ("sti"::) 17 | #define cli() __asm__ ("cli"::) 18 | #define nop() __asm__ ("nop"::) 19 | 20 | #define iret() __asm__ ("iret"::) 21 | 22 | #define _set_gate(gate_addr,type,dpl,addr) \ 23 | __asm__ ("movw %%dx,%%ax\n\t" \ 24 | "movw %0,%%dx\n\t" \ 25 | "movl %%eax,%1\n\t" \ 26 | "movl %%edx,%2" \ 27 | : \ 28 | : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \ 29 | "o" (*((char *) (gate_addr))), \ 30 | "o" (*(4+(char *) (gate_addr))), \ 31 | "d" ((char *) (addr)),"a" (0x00080000)) 32 | 33 | #define set_intr_gate(n,addr) \ 34 | _set_gate(&idt[n],14,0,addr) 35 | 36 | #define set_trap_gate(n,addr) \ 37 | _set_gate(&idt[n],15,0,addr) 38 | 39 | #define set_system_gate(n,addr) \ 40 | _set_gate(&idt[n],15,3,addr) 41 | 42 | #define _set_seg_desc(gate_addr,type,dpl,base,limit) {\ 43 | *(gate_addr) = ((base) & 0xff000000) | \ 44 | (((base) & 0x00ff0000)>>16) | \ 45 | ((limit) & 0xf0000) | \ 46 | ((dpl)<<13) | \ 47 | (0x00408000) | \ 48 | ((type)<<8); \ 49 | *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \ 50 | ((limit) & 0x0ffff); } 51 | 52 | #define _set_tssldt_desc(n,addr,type) \ 53 | __asm__ ("movw $104,%1\n\t" \ 54 | "movw %%ax,%2\n\t" \ 55 | "rorl $16,%%eax\n\t" \ 56 | "movb %%al,%3\n\t" \ 57 | "movb $" type ",%4\n\t" \ 58 | "movb $0x00,%5\n\t" \ 59 | "movb %%ah,%6\n\t" \ 60 | "rorl $16,%%eax" \ 61 | ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \ 62 | "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \ 63 | ) 64 | 65 | #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x89") 66 | #define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x82") 67 | 68 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/const.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONST_H 2 | #define _CONST_H 3 | 4 | #define BUFFER_END 0x200000 5 | 6 | #define I_TYPE 0170000 7 | #define I_DIRECTORY 0040000 8 | #define I_REGULAR 0100000 9 | #define I_BLOCK_SPECIAL 0060000 10 | #define I_CHAR_SPECIAL 0020000 11 | #define I_NAMED_PIPE 0010000 12 | #define I_SET_UID_BIT 0004000 13 | #define I_SET_GID_BIT 0002000 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _CTYPE_H 2 | #define _CTYPE_H 3 | 4 | #define _U 0x01 /* upper */ 5 | #define _L 0x02 /* lower */ 6 | #define _D 0x04 /* digit */ 7 | #define _C 0x08 /* cntrl */ 8 | #define _P 0x10 /* punct */ 9 | #define _S 0x20 /* white space (space/lf/tab) */ 10 | #define _X 0x40 /* hex digit */ 11 | #define _SP 0x80 /* hard space (0x20) */ 12 | 13 | extern unsigned char _ctype[]; 14 | extern char _ctmp; 15 | 16 | #define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D)) 17 | #define isalpha(c) ((_ctype+1)[c]&(_U|_L)) 18 | #define iscntrl(c) ((_ctype+1)[c]&(_C)) 19 | #define isdigit(c) ((_ctype+1)[c]&(_D)) 20 | #define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D)) 21 | #define islower(c) ((_ctype+1)[c]&(_L)) 22 | #define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP)) 23 | #define ispunct(c) ((_ctype+1)[c]&(_P)) 24 | #define isspace(c) ((_ctype+1)[c]&(_S)) 25 | #define isupper(c) ((_ctype+1)[c]&(_U)) 26 | #define isxdigit(c) ((_ctype+1)[c]&(_D|_X)) 27 | 28 | #define isascii(c) (((unsigned) c)<=0x7f) 29 | #define toascii(c) (((unsigned) c)&0x7f) 30 | 31 | #define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp) 32 | #define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_H 2 | #define _ERRNO_H 3 | 4 | /* 5 | * ok, as I hadn't got any other source of information about 6 | * possible error numbers, I was forced to use the same numbers 7 | * as minix. 8 | * Hopefully these are posix or something. I wouldn't know (and posix 9 | * isn't telling me - they want $$$ for their f***ing standard). 10 | * 11 | * We don't use the _SIGN cludge of minix, so kernel returns must 12 | * see to the sign by themselves. 13 | * 14 | * NOTE! Remember to change strerror() if you change this file! 15 | */ 16 | 17 | extern int errno; 18 | 19 | #define ERROR 99 20 | #define EPERM 1 21 | #define ENOENT 2 22 | #define ESRCH 3 23 | #define EINTR 4 24 | #define EIO 5 25 | #define ENXIO 6 26 | #define E2BIG 7 27 | #define ENOEXEC 8 28 | #define EBADF 9 29 | #define ECHILD 10 30 | #define EAGAIN 11 31 | #define ENOMEM 12 32 | #define EACCES 13 33 | #define EFAULT 14 34 | #define ENOTBLK 15 35 | #define EBUSY 16 36 | #define EEXIST 17 37 | #define EXDEV 18 38 | #define ENODEV 19 39 | #define ENOTDIR 20 40 | #define EISDIR 21 41 | #define EINVAL 22 42 | #define ENFILE 23 43 | #define EMFILE 24 44 | #define ENOTTY 25 45 | #define ETXTBSY 26 46 | #define EFBIG 27 47 | #define ENOSPC 28 48 | #define ESPIPE 29 49 | #define EROFS 30 50 | #define EMLINK 31 51 | #define EPIPE 32 52 | #define EDOM 33 53 | #define ERANGE 34 54 | #define EDEADLK 35 55 | #define ENAMETOOLONG 36 56 | #define ENOLCK 37 57 | #define ENOSYS 38 58 | #define ENOTEMPTY 39 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _FCNTL_H 2 | #define _FCNTL_H 3 | 4 | #include 5 | 6 | /* open/fcntl - NOCTTY, NDELAY isn't implemented yet */ 7 | #define O_ACCMODE 00003 8 | #define O_RDONLY 00 9 | #define O_WRONLY 01 10 | #define O_RDWR 02 11 | #define O_CREAT 00100 /* not fcntl */ 12 | #define O_EXCL 00200 /* not fcntl */ 13 | #define O_NOCTTY 00400 /* not fcntl */ 14 | #define O_TRUNC 01000 /* not fcntl */ 15 | #define O_APPEND 02000 16 | #define O_NONBLOCK 04000 /* not fcntl */ 17 | #define O_NDELAY O_NONBLOCK 18 | 19 | /* Defines for fcntl-commands. Note that currently 20 | * locking isn't supported, and other things aren't really 21 | * tested. 22 | */ 23 | #define F_DUPFD 0 /* dup */ 24 | #define F_GETFD 1 /* get f_flags */ 25 | #define F_SETFD 2 /* set f_flags */ 26 | #define F_GETFL 3 /* more flags (cloexec) */ 27 | #define F_SETFL 4 28 | #define F_GETLK 5 /* not implemented */ 29 | #define F_SETLK 6 30 | #define F_SETLKW 7 31 | 32 | /* for F_[GET|SET]FL */ 33 | #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ 34 | 35 | /* Ok, these are locking features, and aren't implemented at any 36 | * level. POSIX wants them. 37 | */ 38 | #define F_RDLCK 0 39 | #define F_WRLCK 1 40 | #define F_UNLCK 2 41 | 42 | /* Once again - not implemented, but ... */ 43 | struct flock { 44 | short l_type; 45 | short l_whence; 46 | off_t l_start; 47 | off_t l_len; 48 | pid_t l_pid; 49 | }; 50 | 51 | extern int creat(const char * filename,mode_t mode); 52 | extern int fcntl(int fildes,int cmd, ...); 53 | extern int open(const char * filename, int flags, ...); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H 2 | #define _CONFIG_H 3 | 4 | /* 5 | * The root-device is no longer hard-coded. You can change the default 6 | * root-device by changing the line ROOT_DEV = XXX in boot/bootsect.s 7 | */ 8 | 9 | /* 10 | * define your keyboard here - 11 | * KBD_FINNISH for Finnish keyboards 12 | * KBD_US for US-type 13 | * KBD_GR for German keyboards 14 | * KBD_FR for Frech keyboard 15 | */ 16 | #define KBD_US 17 | /*#define KBD_GR */ 18 | /*#define KBD_FR */ 19 | /*#define KBD_FINNISH */ 20 | 21 | /* 22 | * Normally, Linux can get the drive parameters from the BIOS at 23 | * startup, but if this for some unfathomable reason fails, you'd 24 | * be left stranded. For this case, you can define HD_TYPE, which 25 | * contains all necessary info on your harddisk. 26 | * 27 | * The HD_TYPE macro should look like this: 28 | * 29 | * #define HD_TYPE { head, sect, cyl, wpcom, lzone, ctl} 30 | * 31 | * In case of two harddisks, the info should be sepatated by 32 | * commas: 33 | * 34 | * #define HD_TYPE { h,s,c,wpcom,lz,ctl },{ h,s,c,wpcom,lz,ctl } 35 | */ 36 | /* 37 | This is an example, two drives, first is type 2, second is type 3: 38 | 39 | #define HD_TYPE { 4,17,615,300,615,8 }, { 6,17,615,300,615,0 } 40 | 41 | NOTE: ctl is 0 for all drives with heads<=8, and ctl=8 for drives 42 | with more than 8 heads. 43 | 44 | If you want the BIOS to tell what kind of drive you have, just 45 | leave HD_TYPE undefined. This is the normal thing to do. 46 | */ 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/fdreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains some defines for the floppy disk controller. 3 | * Various sources. Mostly "IBM Microcomputers: A Programmers 4 | * Handbook", Sanches and Canton. 5 | */ 6 | #ifndef _FDREG_H 7 | #define _FDREG_H 8 | 9 | extern int ticks_to_floppy_on(unsigned int nr); 10 | extern void floppy_on(unsigned int nr); 11 | extern void floppy_off(unsigned int nr); 12 | extern void floppy_select(unsigned int nr); 13 | extern void floppy_deselect(unsigned int nr); 14 | 15 | /* Fd controller regs. S&C, about page 340 */ 16 | #define FD_STATUS 0x3f4 17 | #define FD_DATA 0x3f5 18 | #define FD_DOR 0x3f2 /* Digital Output Register */ 19 | #define FD_DIR 0x3f7 /* Digital Input Register (read) */ 20 | #define FD_DCR 0x3f7 /* Diskette Control Register (write)*/ 21 | 22 | /* Bits of main status register */ 23 | #define STATUS_BUSYMASK 0x0F /* drive busy mask */ 24 | #define STATUS_BUSY 0x10 /* FDC busy */ 25 | #define STATUS_DMA 0x20 /* 0- DMA mode */ 26 | #define STATUS_DIR 0x40 /* 0- cpu->fdc */ 27 | #define STATUS_READY 0x80 /* Data reg ready */ 28 | 29 | /* Bits of FD_ST0 */ 30 | #define ST0_DS 0x03 /* drive select mask */ 31 | #define ST0_HA 0x04 /* Head (Address) */ 32 | #define ST0_NR 0x08 /* Not Ready */ 33 | #define ST0_ECE 0x10 /* Equipment chech error */ 34 | #define ST0_SE 0x20 /* Seek end */ 35 | #define ST0_INTR 0xC0 /* Interrupt code mask */ 36 | 37 | /* Bits of FD_ST1 */ 38 | #define ST1_MAM 0x01 /* Missing Address Mark */ 39 | #define ST1_WP 0x02 /* Write Protect */ 40 | #define ST1_ND 0x04 /* No Data - unreadable */ 41 | #define ST1_OR 0x10 /* OverRun */ 42 | #define ST1_CRC 0x20 /* CRC error in data or addr */ 43 | #define ST1_EOC 0x80 /* End Of Cylinder */ 44 | 45 | /* Bits of FD_ST2 */ 46 | #define ST2_MAM 0x01 /* Missing Addess Mark (again) */ 47 | #define ST2_BC 0x02 /* Bad Cylinder */ 48 | #define ST2_SNS 0x04 /* Scan Not Satisfied */ 49 | #define ST2_SEH 0x08 /* Scan Equal Hit */ 50 | #define ST2_WC 0x10 /* Wrong Cylinder */ 51 | #define ST2_CRC 0x20 /* CRC error in data field */ 52 | #define ST2_CM 0x40 /* Control Mark = deleted */ 53 | 54 | /* Bits of FD_ST3 */ 55 | #define ST3_HA 0x04 /* Head (Address) */ 56 | #define ST3_TZ 0x10 /* Track Zero signal (1=track 0) */ 57 | #define ST3_WP 0x40 /* Write Protect */ 58 | 59 | /* Values for FD_COMMAND */ 60 | #define FD_RECALIBRATE 0x07 /* move to track 0 */ 61 | #define FD_SEEK 0x0F /* seek track */ 62 | #define FD_READ 0xE6 /* read with MT, MFM, SKip deleted */ 63 | #define FD_WRITE 0xC5 /* write with MT, MFM */ 64 | #define FD_SENSEI 0x08 /* Sense Interrupt Status */ 65 | #define FD_SPECIFY 0x03 /* specify HUT etc */ 66 | 67 | /* DMA commands */ 68 | #define DMA_READ 0x46 69 | #define DMA_WRITE 0x4A 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/fs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file has definitions for some important file table 3 | * structures etc. 4 | */ 5 | 6 | #ifndef _FS_H 7 | #define _FS_H 8 | 9 | #include 10 | 11 | /* devices are as follows: (same as minix, so we can use the minix 12 | * file system. These are major numbers.) 13 | * 14 | * 0 - unused (nodev) 15 | * 1 - /dev/mem 16 | * 2 - /dev/fd 17 | * 3 - /dev/hd 18 | * 4 - /dev/ttyx 19 | * 5 - /dev/tty 20 | * 6 - /dev/lp 21 | * 7 - unnamed pipes 22 | */ 23 | 24 | #define IS_SEEKABLE(x) ((x)>=1 && (x)<=3) 25 | 26 | #define READ 0 27 | #define WRITE 1 28 | #define READA 2 /* read-ahead - don't pause */ 29 | #define WRITEA 3 /* "write-ahead" - silly, but somewhat useful */ 30 | 31 | void buffer_init(long buffer_end); 32 | 33 | #define MAJOR(a) (((unsigned)(a))>>8) 34 | #define MINOR(a) ((a)&0xff) 35 | 36 | #define NAME_LEN 14 37 | #define ROOT_INO 1 38 | 39 | #define I_MAP_SLOTS 8 40 | #define Z_MAP_SLOTS 8 41 | #define SUPER_MAGIC 0x137F 42 | 43 | #define NR_OPEN 20 44 | #define NR_INODE 32 45 | #define NR_FILE 64 46 | #define NR_SUPER 8 47 | #define NR_HASH 307 48 | #define NR_BUFFERS nr_buffers 49 | #define BLOCK_SIZE 1024 50 | #define BLOCK_SIZE_BITS 10 51 | #ifndef NULL 52 | #define NULL ((void *) 0) 53 | #endif 54 | 55 | #define INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct d_inode))) 56 | #define DIR_ENTRIES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct dir_entry))) 57 | 58 | #define PIPE_HEAD(inode) ((inode).i_zone[0]) 59 | #define PIPE_TAIL(inode) ((inode).i_zone[1]) 60 | #define PIPE_SIZE(inode) ((PIPE_HEAD(inode)-PIPE_TAIL(inode))&(PAGE_SIZE-1)) 61 | #define PIPE_EMPTY(inode) (PIPE_HEAD(inode)==PIPE_TAIL(inode)) 62 | #define PIPE_FULL(inode) (PIPE_SIZE(inode)==(PAGE_SIZE-1)) 63 | #define INC_PIPE(head) \ 64 | __asm__("incl %0\n\tandl $4095,%0"::"m" (head)) 65 | 66 | typedef char buffer_block[BLOCK_SIZE]; 67 | 68 | struct buffer_head { 69 | char * b_data; /* pointer to data block (1024 bytes) */ 70 | unsigned long b_blocknr; /* block number */ 71 | unsigned short b_dev; /* device (0 = free) */ 72 | unsigned char b_uptodate; 73 | unsigned char b_dirt; /* 0-clean,1-dirty */ 74 | unsigned char b_count; /* users using this block */ 75 | unsigned char b_lock; /* 0 - ok, 1 -locked */ 76 | struct task_struct * b_wait; 77 | struct buffer_head * b_prev; 78 | struct buffer_head * b_next; 79 | struct buffer_head * b_prev_free; 80 | struct buffer_head * b_next_free; 81 | }; 82 | 83 | struct d_inode { 84 | unsigned short i_mode; 85 | unsigned short i_uid; 86 | unsigned long i_size; 87 | unsigned long i_time; 88 | unsigned char i_gid; 89 | unsigned char i_nlinks; 90 | unsigned short i_zone[9]; 91 | }; 92 | 93 | struct m_inode { 94 | unsigned short i_mode; 95 | unsigned short i_uid; 96 | unsigned long i_size; 97 | unsigned long i_mtime; 98 | unsigned char i_gid; 99 | unsigned char i_nlinks; 100 | unsigned short i_zone[9]; 101 | /* these are in memory also */ 102 | struct task_struct * i_wait; 103 | unsigned long i_atime; 104 | unsigned long i_ctime; 105 | unsigned short i_dev; 106 | unsigned short i_num; 107 | unsigned short i_count; 108 | unsigned char i_lock; 109 | unsigned char i_dirt; 110 | unsigned char i_pipe; 111 | unsigned char i_mount; 112 | unsigned char i_seek; 113 | unsigned char i_update; 114 | }; 115 | 116 | struct file { 117 | unsigned short f_mode; 118 | unsigned short f_flags; 119 | unsigned short f_count; 120 | struct m_inode * f_inode; 121 | off_t f_pos; 122 | }; 123 | 124 | struct super_block { 125 | unsigned short s_ninodes; 126 | unsigned short s_nzones; 127 | unsigned short s_imap_blocks; 128 | unsigned short s_zmap_blocks; 129 | unsigned short s_firstdatazone; 130 | unsigned short s_log_zone_size; 131 | unsigned long s_max_size; 132 | unsigned short s_magic; 133 | /* These are only in memory */ 134 | struct buffer_head * s_imap[8]; 135 | struct buffer_head * s_zmap[8]; 136 | unsigned short s_dev; 137 | struct m_inode * s_isup; 138 | struct m_inode * s_imount; 139 | unsigned long s_time; 140 | struct task_struct * s_wait; 141 | unsigned char s_lock; 142 | unsigned char s_rd_only; 143 | unsigned char s_dirt; 144 | }; 145 | 146 | struct d_super_block { 147 | unsigned short s_ninodes; 148 | unsigned short s_nzones; 149 | unsigned short s_imap_blocks; 150 | unsigned short s_zmap_blocks; 151 | unsigned short s_firstdatazone; 152 | unsigned short s_log_zone_size; 153 | unsigned long s_max_size; 154 | unsigned short s_magic; 155 | }; 156 | 157 | struct dir_entry { 158 | unsigned short inode; 159 | char name[NAME_LEN]; 160 | }; 161 | 162 | extern struct m_inode inode_table[NR_INODE]; 163 | extern struct file file_table[NR_FILE]; 164 | extern struct super_block super_block[NR_SUPER]; 165 | extern struct buffer_head * start_buffer; 166 | extern int nr_buffers; 167 | 168 | extern void check_disk_change(int dev); 169 | extern int floppy_change(unsigned int nr); 170 | extern int ticks_to_floppy_on(unsigned int dev); 171 | extern void floppy_on(unsigned int dev); 172 | extern void floppy_off(unsigned int dev); 173 | extern void truncate(struct m_inode * inode); 174 | extern void sync_inodes(void); 175 | extern void wait_on(struct m_inode * inode); 176 | extern int bmap(struct m_inode * inode,int block); 177 | extern int create_block(struct m_inode * inode,int block); 178 | extern struct m_inode * namei(const char * pathname); 179 | extern int open_namei(const char * pathname, int flag, int mode, 180 | struct m_inode ** res_inode); 181 | extern void iput(struct m_inode * inode); 182 | extern struct m_inode * iget(int dev,int nr); 183 | extern struct m_inode * get_empty_inode(void); 184 | extern struct m_inode * get_pipe_inode(void); 185 | extern struct buffer_head * get_hash_table(int dev, int block); 186 | extern struct buffer_head * getblk(int dev, int block); 187 | extern void ll_rw_block(int rw, struct buffer_head * bh); 188 | extern void brelse(struct buffer_head * buf); 189 | extern struct buffer_head * bread(int dev,int block); 190 | extern void bread_page(unsigned long addr,int dev,int b[4]); 191 | extern struct buffer_head * breada(int dev,int block,...); 192 | extern int new_block(int dev); 193 | extern void free_block(int dev, int block); 194 | extern struct m_inode * new_inode(int dev); 195 | extern void free_inode(struct m_inode * inode); 196 | extern int sync_dev(int dev); 197 | extern struct super_block * get_super(int dev); 198 | extern int ROOT_DEV; 199 | 200 | extern void mount_root(void); 201 | 202 | #endif 203 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/hdreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains some defines for the AT-hd-controller. 3 | * Various sources. Check out some definitions (see comments with 4 | * a ques). 5 | */ 6 | #ifndef _HDREG_H 7 | #define _HDREG_H 8 | 9 | /* Hd controller regs. Ref: IBM AT Bios-listing */ 10 | #define HD_DATA 0x1f0 /* _CTL when writing */ 11 | #define HD_ERROR 0x1f1 /* see err-bits */ 12 | #define HD_NSECTOR 0x1f2 /* nr of sectors to read/write */ 13 | #define HD_SECTOR 0x1f3 /* starting sector */ 14 | #define HD_LCYL 0x1f4 /* starting cylinder */ 15 | #define HD_HCYL 0x1f5 /* high byte of starting cyl */ 16 | #define HD_CURRENT 0x1f6 /* 101dhhhh , d=drive, hhhh=head */ 17 | #define HD_STATUS 0x1f7 /* see status-bits */ 18 | #define HD_PRECOMP HD_ERROR /* same io address, read=error, write=precomp */ 19 | #define HD_COMMAND HD_STATUS /* same io address, read=status, write=cmd */ 20 | 21 | #define HD_CMD 0x3f6 22 | 23 | /* Bits of HD_STATUS */ 24 | #define ERR_STAT 0x01 25 | #define INDEX_STAT 0x02 26 | #define ECC_STAT 0x04 /* Corrected error */ 27 | #define DRQ_STAT 0x08 28 | #define SEEK_STAT 0x10 29 | #define WRERR_STAT 0x20 30 | #define READY_STAT 0x40 31 | #define BUSY_STAT 0x80 32 | 33 | /* Values for HD_COMMAND */ 34 | #define WIN_RESTORE 0x10 35 | #define WIN_READ 0x20 36 | #define WIN_WRITE 0x30 37 | #define WIN_VERIFY 0x40 38 | #define WIN_FORMAT 0x50 39 | #define WIN_INIT 0x60 40 | #define WIN_SEEK 0x70 41 | #define WIN_DIAGNOSE 0x90 42 | #define WIN_SPECIFY 0x91 43 | 44 | /* Bits for HD_ERROR */ 45 | #define MARK_ERR 0x01 /* Bad address mark ? */ 46 | #define TRK0_ERR 0x02 /* couldn't find track 0 */ 47 | #define ABRT_ERR 0x04 /* ? */ 48 | #define ID_ERR 0x10 /* ? */ 49 | #define ECC_ERR 0x40 /* ? */ 50 | #define BBD_ERR 0x80 /* ? */ 51 | 52 | struct partition { 53 | unsigned char boot_ind; /* 0x80 - active (unused) */ 54 | unsigned char head; /* ? */ 55 | unsigned char sector; /* ? */ 56 | unsigned char cyl; /* ? */ 57 | unsigned char sys_ind; /* ? */ 58 | unsigned char end_head; /* ? */ 59 | unsigned char end_sector; /* ? */ 60 | unsigned char end_cyl; /* ? */ 61 | unsigned int start_sect; /* starting sector counting from 0 */ 62 | unsigned int nr_sects; /* nr of sectors in partition */ 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/head.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEAD_H 2 | #define _HEAD_H 3 | 4 | typedef struct desc_struct { 5 | unsigned long a,b; 6 | } desc_table[256]; 7 | 8 | extern unsigned long pg_dir[1024]; 9 | extern desc_table idt,gdt; 10 | 11 | #define GDT_NUL 0 12 | #define GDT_CODE 1 13 | #define GDT_DATA 2 14 | #define GDT_TMP 3 15 | 16 | #define LDT_NUL 0 17 | #define LDT_CODE 1 18 | #define LDT_DATA 2 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/kernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 'kernel.h' contains some often-used function prototypes etc 3 | */ 4 | void verify_area(void * addr,int count); 5 | volatile void panic(const char * str); 6 | int printf(const char * fmt, ...); 7 | int printk(const char * fmt, ...); 8 | int tty_write(unsigned ch,char * buf,int count); 9 | void * malloc(unsigned int size); 10 | void free_s(void * obj, int size); 11 | 12 | #define free(x) free_s((x), 0) 13 | 14 | /* 15 | * This is defined as a macro, but at some point this might become a 16 | * real subroutine that sets a flag if it returns true (to do 17 | * BSD-style accounting where the process is flagged if it uses root 18 | * privs). The implication of this is that you should do normal 19 | * permissions checks first, and check suser() last. 20 | */ 21 | #define suser() (current->euid == 0) 22 | 23 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/mm.h: -------------------------------------------------------------------------------- 1 | #ifndef _MM_H 2 | #define _MM_H 3 | 4 | #define PAGE_SIZE 4096 5 | 6 | extern unsigned long get_free_page(void); 7 | extern unsigned long put_page(unsigned long page,unsigned long address); 8 | extern void free_page(unsigned long addr); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/sys.h: -------------------------------------------------------------------------------- 1 | extern int sys_setup(); 2 | extern int sys_exit(); 3 | extern int sys_fork(); 4 | extern int sys_read(); 5 | extern int sys_write(); 6 | extern int sys_open(); 7 | extern int sys_close(); 8 | extern int sys_waitpid(); 9 | extern int sys_creat(); 10 | extern int sys_link(); 11 | extern int sys_unlink(); 12 | extern int sys_execve(); 13 | extern int sys_chdir(); 14 | extern int sys_time(); 15 | extern int sys_mknod(); 16 | extern int sys_chmod(); 17 | extern int sys_chown(); 18 | extern int sys_break(); 19 | extern int sys_stat(); 20 | extern int sys_lseek(); 21 | extern int sys_getpid(); 22 | extern int sys_mount(); 23 | extern int sys_umount(); 24 | extern int sys_setuid(); 25 | extern int sys_getuid(); 26 | extern int sys_stime(); 27 | extern int sys_ptrace(); 28 | extern int sys_alarm(); 29 | extern int sys_fstat(); 30 | extern int sys_pause(); 31 | extern int sys_utime(); 32 | extern int sys_stty(); 33 | extern int sys_gtty(); 34 | extern int sys_access(); 35 | extern int sys_nice(); 36 | extern int sys_ftime(); 37 | extern int sys_sync(); 38 | extern int sys_kill(); 39 | extern int sys_rename(); 40 | extern int sys_mkdir(); 41 | extern int sys_rmdir(); 42 | extern int sys_dup(); 43 | extern int sys_pipe(); 44 | extern int sys_times(); 45 | extern int sys_prof(); 46 | extern int sys_brk(); 47 | extern int sys_setgid(); 48 | extern int sys_getgid(); 49 | extern int sys_signal(); 50 | extern int sys_geteuid(); 51 | extern int sys_getegid(); 52 | extern int sys_acct(); 53 | extern int sys_phys(); 54 | extern int sys_lock(); 55 | extern int sys_ioctl(); 56 | extern int sys_fcntl(); 57 | extern int sys_mpx(); 58 | extern int sys_setpgid(); 59 | extern int sys_ulimit(); 60 | extern int sys_uname(); 61 | extern int sys_umask(); 62 | extern int sys_chroot(); 63 | extern int sys_ustat(); 64 | extern int sys_dup2(); 65 | extern int sys_getppid(); 66 | extern int sys_getpgrp(); 67 | extern int sys_setsid(); 68 | extern int sys_sigaction(); 69 | extern int sys_sgetmask(); 70 | extern int sys_ssetmask(); 71 | extern int sys_setreuid(); 72 | extern int sys_setregid(); 73 | 74 | fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read, 75 | sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link, 76 | sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod, 77 | sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount, 78 | sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm, 79 | sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access, 80 | sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir, 81 | sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid, 82 | sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys, 83 | sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit, 84 | sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid, 85 | sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask, 86 | sys_setreuid,sys_setregid }; 87 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/linux/tty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 'tty.h' defines some structures used by tty_io.c and some defines. 3 | * 4 | * NOTE! Don't touch this without checking that nothing in rs_io.s or 5 | * con_io.s breaks. Some constants are hardwired into the system (mainly 6 | * offsets into 'tty_queue' 7 | */ 8 | 9 | #ifndef _TTY_H 10 | #define _TTY_H 11 | 12 | #include 13 | 14 | #define TTY_BUF_SIZE 1024 15 | 16 | struct tty_queue { 17 | unsigned long data; 18 | unsigned long head; 19 | unsigned long tail; 20 | struct task_struct * proc_list; 21 | char buf[TTY_BUF_SIZE]; 22 | }; 23 | 24 | #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1)) 25 | #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1)) 26 | #define EMPTY(a) ((a).head == (a).tail) 27 | #define LEFT(a) (((a).tail-(a).head-1)&(TTY_BUF_SIZE-1)) 28 | #define LAST(a) ((a).buf[(TTY_BUF_SIZE-1)&((a).head-1)]) 29 | #define FULL(a) (!LEFT(a)) 30 | #define CHARS(a) (((a).head-(a).tail)&(TTY_BUF_SIZE-1)) 31 | #define GETCH(queue,c) \ 32 | (void)({c=(queue).buf[(queue).tail];INC((queue).tail);}) 33 | #define PUTCH(c,queue) \ 34 | (void)({(queue).buf[(queue).head]=(c);INC((queue).head);}) 35 | 36 | #define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR]) 37 | #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT]) 38 | #define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE]) 39 | #define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL]) 40 | #define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF]) 41 | #define START_CHAR(tty) ((tty)->termios.c_cc[VSTART]) 42 | #define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP]) 43 | #define SUSPEND_CHAR(tty) ((tty)->termios.c_cc[VSUSP]) 44 | 45 | struct tty_struct { 46 | struct termios termios; 47 | int pgrp; 48 | int stopped; 49 | void (*write)(struct tty_struct * tty); 50 | struct tty_queue read_q; 51 | struct tty_queue write_q; 52 | struct tty_queue secondary; 53 | }; 54 | 55 | extern struct tty_struct tty_table[]; 56 | 57 | /* intr=^C quit=^| erase=del kill=^U 58 | eof=^D vtime=\0 vmin=\1 sxtc=\0 59 | start=^Q stop=^S susp=^Z eol=\0 60 | reprint=^R discard=^U werase=^W lnext=^V 61 | eol2=\0 62 | */ 63 | #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" 64 | 65 | void rs_init(void); 66 | void con_init(void); 67 | void tty_init(void); 68 | 69 | int tty_read(unsigned c, char * buf, int n); 70 | int tty_write(unsigned c, char * buf, int n); 71 | 72 | void rs_write(struct tty_struct * tty); 73 | void con_write(struct tty_struct * tty); 74 | 75 | void copy_to_cooked(struct tty_struct * tty); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIGNAL_H 2 | #define _SIGNAL_H 3 | 4 | #include 5 | 6 | typedef int sig_atomic_t; 7 | typedef unsigned int sigset_t; /* 32 bits */ 8 | 9 | #define _NSIG 32 10 | #define NSIG _NSIG 11 | 12 | #define SIGHUP 1 13 | #define SIGINT 2 14 | #define SIGQUIT 3 15 | #define SIGILL 4 16 | #define SIGTRAP 5 17 | #define SIGABRT 6 18 | #define SIGIOT 6 19 | #define SIGUNUSED 7 20 | #define SIGFPE 8 21 | #define SIGKILL 9 22 | #define SIGUSR1 10 23 | #define SIGSEGV 11 24 | #define SIGUSR2 12 25 | #define SIGPIPE 13 26 | #define SIGALRM 14 27 | #define SIGTERM 15 28 | #define SIGSTKFLT 16 29 | #define SIGCHLD 17 30 | #define SIGCONT 18 31 | #define SIGSTOP 19 32 | #define SIGTSTP 20 33 | #define SIGTTIN 21 34 | #define SIGTTOU 22 35 | 36 | /* Ok, I haven't implemented sigactions, but trying to keep headers POSIX */ 37 | #define SA_NOCLDSTOP 1 38 | #define SA_NOMASK 0x40000000 39 | #define SA_ONESHOT 0x80000000 40 | 41 | #define SIG_BLOCK 0 /* for blocking signals */ 42 | #define SIG_UNBLOCK 1 /* for unblocking signals */ 43 | #define SIG_SETMASK 2 /* for setting the signal mask */ 44 | 45 | #define SIG_DFL ((void (*)(int))0) /* default signal handling */ 46 | #define SIG_IGN ((void (*)(int))1) /* ignore signal */ 47 | 48 | struct sigaction { 49 | void (*sa_handler)(int); 50 | sigset_t sa_mask; 51 | int sa_flags; 52 | void (*sa_restorer)(void); 53 | }; 54 | 55 | void (*signal(int _sig, void (*_func)(int)))(int); 56 | int raise(int sig); 57 | int kill(pid_t pid, int sig); 58 | int sigaddset(sigset_t *mask, int signo); 59 | int sigdelset(sigset_t *mask, int signo); 60 | int sigemptyset(sigset_t *mask); 61 | int sigfillset(sigset_t *mask); 62 | int sigismember(sigset_t *mask, int signo); /* 1 - is, 0 - not, -1 error */ 63 | int sigpending(sigset_t *set); 64 | int sigprocmask(int how, sigset_t *set, sigset_t *oldset); 65 | int sigsuspend(sigset_t *sigmask); 66 | int sigaction(int sig, struct sigaction *act, struct sigaction *oldact); 67 | 68 | #endif /* _SIGNAL_H */ 69 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | typedef char *va_list; 5 | 6 | /* Amount of space required in an argument list for an arg of type TYPE. 7 | TYPE may alternatively be an expression whose type is used. */ 8 | 9 | #define __va_rounded_size(TYPE) \ 10 | (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) 11 | 12 | #ifndef __sparc__ 13 | #define va_start(AP, LASTARG) \ 14 | (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG))) 15 | #else 16 | #define va_start(AP, LASTARG) \ 17 | (__builtin_saveregs (), \ 18 | AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG))) 19 | #endif 20 | 21 | void va_end (va_list); /* Defined in gnulib */ 22 | #define va_end(AP) 23 | 24 | #define va_arg(AP, TYPE) \ 25 | (AP += __va_rounded_size (TYPE), \ 26 | *((TYPE *) (AP - __va_rounded_size (TYPE)))) 27 | 28 | #endif /* _STDARG_H */ 29 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | #ifndef _PTRDIFF_T 5 | #define _PTRDIFF_T 6 | typedef long ptrdiff_t; 7 | #endif 8 | 9 | #ifndef _SIZE_T 10 | #define _SIZE_T 11 | typedef unsigned long size_t; 12 | #endif 13 | 14 | #undef NULL 15 | #define NULL ((void *)0) 16 | 17 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_STAT_H 2 | #define _SYS_STAT_H 3 | 4 | #include 5 | 6 | struct stat { 7 | dev_t st_dev; 8 | ino_t st_ino; 9 | umode_t st_mode; 10 | nlink_t st_nlink; 11 | uid_t st_uid; 12 | gid_t st_gid; 13 | dev_t st_rdev; 14 | off_t st_size; 15 | time_t st_atime; 16 | time_t st_mtime; 17 | time_t st_ctime; 18 | }; 19 | 20 | #define S_IFMT 00170000 21 | #define S_IFREG 0100000 22 | #define S_IFBLK 0060000 23 | #define S_IFDIR 0040000 24 | #define S_IFCHR 0020000 25 | #define S_IFIFO 0010000 26 | #define S_ISUID 0004000 27 | #define S_ISGID 0002000 28 | #define S_ISVTX 0001000 29 | 30 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 31 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 32 | #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 33 | #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 34 | #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 35 | 36 | #define S_IRWXU 00700 37 | #define S_IRUSR 00400 38 | #define S_IWUSR 00200 39 | #define S_IXUSR 00100 40 | 41 | #define S_IRWXG 00070 42 | #define S_IRGRP 00040 43 | #define S_IWGRP 00020 44 | #define S_IXGRP 00010 45 | 46 | #define S_IRWXO 00007 47 | #define S_IROTH 00004 48 | #define S_IWOTH 00002 49 | #define S_IXOTH 00001 50 | 51 | extern int chmod(const char *_path, mode_t mode); 52 | extern int fstat(int fildes, struct stat *stat_buf); 53 | extern int mkdir(const char *_path, mode_t mode); 54 | extern int mkfifo(const char *_path, mode_t mode); 55 | extern int stat(const char *filename, struct stat *stat_buf); 56 | extern mode_t umask(mode_t mask); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/sys/times.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMES_H 2 | #define _TIMES_H 3 | 4 | #include 5 | 6 | struct tms { 7 | time_t tms_utime; 8 | time_t tms_stime; 9 | time_t tms_cutime; 10 | time_t tms_cstime; 11 | }; 12 | 13 | extern time_t times(struct tms * tp); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/sys/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TYPES_H 2 | #define _SYS_TYPES_H 3 | 4 | #ifndef _SIZE_T 5 | #define _SIZE_T 6 | typedef unsigned int size_t; 7 | #endif 8 | 9 | #ifndef _TIME_T 10 | #define _TIME_T 11 | typedef long time_t; 12 | #endif 13 | 14 | #ifndef _PTRDIFF_T 15 | #define _PTRDIFF_T 16 | typedef long ptrdiff_t; 17 | #endif 18 | 19 | #ifndef NULL 20 | #define NULL ((void *) 0) 21 | #endif 22 | 23 | typedef int pid_t; 24 | typedef unsigned short uid_t; 25 | typedef unsigned char gid_t; 26 | typedef unsigned short dev_t; 27 | typedef unsigned short ino_t; 28 | typedef unsigned short mode_t; 29 | typedef unsigned short umode_t; 30 | typedef unsigned char nlink_t; 31 | typedef int daddr_t; 32 | typedef long off_t; 33 | typedef unsigned char u_char; 34 | typedef unsigned short ushort; 35 | 36 | typedef struct { int quot,rem; } div_t; 37 | typedef struct { long quot,rem; } ldiv_t; 38 | 39 | struct ustat { 40 | daddr_t f_tfree; 41 | ino_t f_tinode; 42 | char f_fname[6]; 43 | char f_fpack[6]; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_UTSNAME_H 2 | #define _SYS_UTSNAME_H 3 | 4 | #include 5 | 6 | struct utsname { 7 | char sysname[9]; 8 | char nodename[9]; 9 | char release[9]; 10 | char version[9]; 11 | char machine[9]; 12 | }; 13 | 14 | extern int uname(struct utsname * utsbuf); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_WAIT_H 2 | #define _SYS_WAIT_H 3 | 4 | #include 5 | 6 | #define _LOW(v) ( (v) & 0377) 7 | #define _HIGH(v) ( ((v) >> 8) & 0377) 8 | 9 | /* options for waitpid, WUNTRACED not supported */ 10 | #define WNOHANG 1 11 | #define WUNTRACED 2 12 | 13 | #define WIFEXITED(s) (!((s)&0xFF) 14 | #define WIFSTOPPED(s) (((s)&0xFF)==0x7F) 15 | #define WEXITSTATUS(s) (((s)>>8)&0xFF) 16 | #define WTERMSIG(s) ((s)&0x7F) 17 | #define WSTOPSIG(s) (((s)>>8)&0xFF) 18 | #define WIFSIGNALED(s) (((unsigned int)(s)-1 & 0xFFFF) < 0xFF) 19 | 20 | pid_t wait(int *stat_loc); 21 | pid_t waitpid(pid_t pid, int *stat_loc, int options); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/termios.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMIOS_H 2 | #define _TERMIOS_H 3 | 4 | #define TTY_BUF_SIZE 1024 5 | 6 | /* 0x54 is just a magic number to make these relatively uniqe ('T') */ 7 | 8 | #define TCGETS 0x5401 9 | #define TCSETS 0x5402 10 | #define TCSETSW 0x5403 11 | #define TCSETSF 0x5404 12 | #define TCGETA 0x5405 13 | #define TCSETA 0x5406 14 | #define TCSETAW 0x5407 15 | #define TCSETAF 0x5408 16 | #define TCSBRK 0x5409 17 | #define TCXONC 0x540A 18 | #define TCFLSH 0x540B 19 | #define TIOCEXCL 0x540C 20 | #define TIOCNXCL 0x540D 21 | #define TIOCSCTTY 0x540E 22 | #define TIOCGPGRP 0x540F 23 | #define TIOCSPGRP 0x5410 24 | #define TIOCOUTQ 0x5411 25 | #define TIOCSTI 0x5412 26 | #define TIOCGWINSZ 0x5413 27 | #define TIOCSWINSZ 0x5414 28 | #define TIOCMGET 0x5415 29 | #define TIOCMBIS 0x5416 30 | #define TIOCMBIC 0x5417 31 | #define TIOCMSET 0x5418 32 | #define TIOCGSOFTCAR 0x5419 33 | #define TIOCSSOFTCAR 0x541A 34 | #define TIOCINQ 0x541B 35 | 36 | struct winsize { 37 | unsigned short ws_row; 38 | unsigned short ws_col; 39 | unsigned short ws_xpixel; 40 | unsigned short ws_ypixel; 41 | }; 42 | 43 | #define NCC 8 44 | struct termio { 45 | unsigned short c_iflag; /* input mode flags */ 46 | unsigned short c_oflag; /* output mode flags */ 47 | unsigned short c_cflag; /* control mode flags */ 48 | unsigned short c_lflag; /* local mode flags */ 49 | unsigned char c_line; /* line discipline */ 50 | unsigned char c_cc[NCC]; /* control characters */ 51 | }; 52 | 53 | #define NCCS 17 54 | struct termios { 55 | unsigned long c_iflag; /* input mode flags */ 56 | unsigned long c_oflag; /* output mode flags */ 57 | unsigned long c_cflag; /* control mode flags */ 58 | unsigned long c_lflag; /* local mode flags */ 59 | unsigned char c_line; /* line discipline */ 60 | unsigned char c_cc[NCCS]; /* control characters */ 61 | }; 62 | 63 | /* c_cc characters */ 64 | #define VINTR 0 65 | #define VQUIT 1 66 | #define VERASE 2 67 | #define VKILL 3 68 | #define VEOF 4 69 | #define VTIME 5 70 | #define VMIN 6 71 | #define VSWTC 7 72 | #define VSTART 8 73 | #define VSTOP 9 74 | #define VSUSP 10 75 | #define VEOL 11 76 | #define VREPRINT 12 77 | #define VDISCARD 13 78 | #define VWERASE 14 79 | #define VLNEXT 15 80 | #define VEOL2 16 81 | 82 | /* c_iflag bits */ 83 | #define IGNBRK 0000001 84 | #define BRKINT 0000002 85 | #define IGNPAR 0000004 86 | #define PARMRK 0000010 87 | #define INPCK 0000020 88 | #define ISTRIP 0000040 89 | #define INLCR 0000100 90 | #define IGNCR 0000200 91 | #define ICRNL 0000400 92 | #define IUCLC 0001000 93 | #define IXON 0002000 94 | #define IXANY 0004000 95 | #define IXOFF 0010000 96 | #define IMAXBEL 0020000 97 | 98 | /* c_oflag bits */ 99 | #define OPOST 0000001 100 | #define OLCUC 0000002 101 | #define ONLCR 0000004 102 | #define OCRNL 0000010 103 | #define ONOCR 0000020 104 | #define ONLRET 0000040 105 | #define OFILL 0000100 106 | #define OFDEL 0000200 107 | #define NLDLY 0000400 108 | #define NL0 0000000 109 | #define NL1 0000400 110 | #define CRDLY 0003000 111 | #define CR0 0000000 112 | #define CR1 0001000 113 | #define CR2 0002000 114 | #define CR3 0003000 115 | #define TABDLY 0014000 116 | #define TAB0 0000000 117 | #define TAB1 0004000 118 | #define TAB2 0010000 119 | #define TAB3 0014000 120 | #define XTABS 0014000 121 | #define BSDLY 0020000 122 | #define BS0 0000000 123 | #define BS1 0020000 124 | #define VTDLY 0040000 125 | #define VT0 0000000 126 | #define VT1 0040000 127 | #define FFDLY 0040000 128 | #define FF0 0000000 129 | #define FF1 0040000 130 | 131 | /* c_cflag bit meaning */ 132 | #define CBAUD 0000017 133 | #define B0 0000000 /* hang up */ 134 | #define B50 0000001 135 | #define B75 0000002 136 | #define B110 0000003 137 | #define B134 0000004 138 | #define B150 0000005 139 | #define B200 0000006 140 | #define B300 0000007 141 | #define B600 0000010 142 | #define B1200 0000011 143 | #define B1800 0000012 144 | #define B2400 0000013 145 | #define B4800 0000014 146 | #define B9600 0000015 147 | #define B19200 0000016 148 | #define B38400 0000017 149 | #define EXTA B19200 150 | #define EXTB B38400 151 | #define CSIZE 0000060 152 | #define CS5 0000000 153 | #define CS6 0000020 154 | #define CS7 0000040 155 | #define CS8 0000060 156 | #define CSTOPB 0000100 157 | #define CREAD 0000200 158 | #define CPARENB 0000400 159 | #define CPARODD 0001000 160 | #define HUPCL 0002000 161 | #define CLOCAL 0004000 162 | #define CIBAUD 03600000 /* input baud rate (not used) */ 163 | #define CRTSCTS 020000000000 /* flow control */ 164 | 165 | #define PARENB CPARENB 166 | #define PARODD CPARODD 167 | 168 | /* c_lflag bits */ 169 | #define ISIG 0000001 170 | #define ICANON 0000002 171 | #define XCASE 0000004 172 | #define ECHO 0000010 173 | #define ECHOE 0000020 174 | #define ECHOK 0000040 175 | #define ECHONL 0000100 176 | #define NOFLSH 0000200 177 | #define TOSTOP 0000400 178 | #define ECHOCTL 0001000 179 | #define ECHOPRT 0002000 180 | #define ECHOKE 0004000 181 | #define FLUSHO 0010000 182 | #define PENDIN 0040000 183 | #define IEXTEN 0100000 184 | 185 | /* modem lines */ 186 | #define TIOCM_LE 0x001 187 | #define TIOCM_DTR 0x002 188 | #define TIOCM_RTS 0x004 189 | #define TIOCM_ST 0x008 190 | #define TIOCM_SR 0x010 191 | #define TIOCM_CTS 0x020 192 | #define TIOCM_CAR 0x040 193 | #define TIOCM_RNG 0x080 194 | #define TIOCM_DSR 0x100 195 | #define TIOCM_CD TIOCM_CAR 196 | #define TIOCM_RI TIOCM_RNG 197 | 198 | /* tcflow() and TCXONC use these */ 199 | #define TCOOFF 0 200 | #define TCOON 1 201 | #define TCIOFF 2 202 | #define TCION 3 203 | 204 | /* tcflush() and TCFLSH use these */ 205 | #define TCIFLUSH 0 206 | #define TCOFLUSH 1 207 | #define TCIOFLUSH 2 208 | 209 | /* tcsetattr uses these */ 210 | #define TCSANOW 0 211 | #define TCSADRAIN 1 212 | #define TCSAFLUSH 2 213 | 214 | typedef int speed_t; 215 | 216 | extern speed_t cfgetispeed(struct termios *termios_p); 217 | extern speed_t cfgetospeed(struct termios *termios_p); 218 | extern int cfsetispeed(struct termios *termios_p, speed_t speed); 219 | extern int cfsetospeed(struct termios *termios_p, speed_t speed); 220 | extern int tcdrain(int fildes); 221 | extern int tcflow(int fildes, int action); 222 | extern int tcflush(int fildes, int queue_selector); 223 | extern int tcgetattr(int fildes, struct termios *termios_p); 224 | extern int tcsendbreak(int fildes, int duration); 225 | extern int tcsetattr(int fildes, int optional_actions, 226 | struct termios *termios_p); 227 | 228 | #endif 229 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIME_H 2 | #define _TIME_H 3 | 4 | #ifndef _TIME_T 5 | #define _TIME_T 6 | typedef long time_t; 7 | #endif 8 | 9 | #ifndef _SIZE_T 10 | #define _SIZE_T 11 | typedef unsigned int size_t; 12 | #endif 13 | 14 | #define CLOCKS_PER_SEC 100 15 | 16 | typedef long clock_t; 17 | 18 | struct tm { 19 | int tm_sec; 20 | int tm_min; 21 | int tm_hour; 22 | int tm_mday; 23 | int tm_mon; 24 | int tm_year; 25 | int tm_wday; 26 | int tm_yday; 27 | int tm_isdst; 28 | }; 29 | 30 | clock_t clock(void); 31 | time_t time(time_t * tp); 32 | double difftime(time_t time2, time_t time1); 33 | time_t mktime(struct tm * tp); 34 | 35 | char * asctime(const struct tm * tp); 36 | char * ctime(const time_t * tp); 37 | struct tm * gmtime(const time_t *tp); 38 | struct tm *localtime(const time_t * tp); 39 | size_t strftime(char * s, size_t smax, const char * fmt, const struct tm * tp); 40 | void tzset(void); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/include/utime.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIME_H 2 | #define _UTIME_H 3 | 4 | #include /* I know - shouldn't do this, but .. */ 5 | 6 | struct utimbuf { 7 | time_t actime; 8 | time_t modtime; 9 | }; 10 | 11 | extern int utime(const char *filename, struct utimbuf *times); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/init/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/init/main.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | #include 10 | 11 | /* 12 | * we need this inline - forking from kernel space will result 13 | * in NO COPY ON WRITE (!!!), until an execve is executed. This 14 | * is no problem, but for the stack. This is handled by not letting 15 | * main() use the stack at all after fork(). Thus, no function 16 | * calls - which means inline code for fork too, as otherwise we 17 | * would use the stack upon exit from 'fork()'. 18 | * 19 | * Actually only pause and fork are needed inline, so that there 20 | * won't be any messing with the stack from main(), but we define 21 | * some others too. 22 | */ 23 | static inline _syscall0(int,fork) 24 | static inline _syscall0(int,pause) 25 | static inline _syscall1(int,setup,void *,BIOS) 26 | static inline _syscall0(int,sync) 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | static char printbuf[1024]; 43 | 44 | extern int vsprintf(); 45 | extern void init(void); 46 | extern void blk_dev_init(void); 47 | extern void chr_dev_init(void); 48 | extern void hd_init(void); 49 | extern void floppy_init(void); 50 | extern void mem_init(long start, long end); 51 | extern long rd_init(long mem_start, int length); 52 | extern long kernel_mktime(struct tm * tm); 53 | extern long startup_time; 54 | 55 | /* 56 | * This is set up by the setup-routine at boot-time 57 | */ 58 | #define EXT_MEM_K (*(unsigned short *)0x90002) 59 | #define DRIVE_INFO (*(struct drive_info *)0x90080) 60 | #define ORIG_ROOT_DEV (*(unsigned short *)0x901FC) 61 | 62 | /* 63 | * Yeah, yeah, it's ugly, but I cannot find how to do this correctly 64 | * and this seems to work. I anybody has more info on the real-time 65 | * clock I'd be interested. Most of this was trial and error, and some 66 | * bios-listing reading. Urghh. 67 | */ 68 | 69 | #define CMOS_READ(addr) ({ \ 70 | outb_p(0x80|addr,0x70); \ 71 | inb_p(0x71); \ 72 | }) 73 | 74 | #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) 75 | 76 | static void time_init(void) 77 | { 78 | struct tm time; 79 | 80 | do { 81 | time.tm_sec = CMOS_READ(0); 82 | time.tm_min = CMOS_READ(2); 83 | time.tm_hour = CMOS_READ(4); 84 | time.tm_mday = CMOS_READ(7); 85 | time.tm_mon = CMOS_READ(8); 86 | time.tm_year = CMOS_READ(9); 87 | } while (time.tm_sec != CMOS_READ(0)); 88 | BCD_TO_BIN(time.tm_sec); 89 | BCD_TO_BIN(time.tm_min); 90 | BCD_TO_BIN(time.tm_hour); 91 | BCD_TO_BIN(time.tm_mday); 92 | BCD_TO_BIN(time.tm_mon); 93 | BCD_TO_BIN(time.tm_year); 94 | time.tm_mon--; 95 | startup_time = kernel_mktime(&time); 96 | } 97 | 98 | static long memory_end = 0; 99 | static long buffer_memory_end = 0; 100 | static long main_memory_start = 0; 101 | 102 | struct drive_info { char dummy[32]; } drive_info; 103 | 104 | void main(void) /* This really IS void, no error here. */ 105 | { /* The startup routine assumes (well, ...) this */ 106 | /* 107 | * Interrupts are still disabled. Do necessary setups, then 108 | * enable them 109 | */ 110 | ROOT_DEV = ORIG_ROOT_DEV; 111 | drive_info = DRIVE_INFO; 112 | memory_end = (1<<20) + (EXT_MEM_K<<10); 113 | memory_end &= 0xfffff000; 114 | if (memory_end > 16*1024*1024) 115 | memory_end = 16*1024*1024; 116 | if (memory_end > 12*1024*1024) 117 | buffer_memory_end = 4*1024*1024; 118 | else if (memory_end > 6*1024*1024) 119 | buffer_memory_end = 2*1024*1024; 120 | else 121 | buffer_memory_end = 1*1024*1024; 122 | main_memory_start = buffer_memory_end; 123 | #ifdef RAMDISK 124 | main_memory_start += rd_init(main_memory_start, RAMDISK*1024); 125 | #endif 126 | mem_init(main_memory_start,memory_end); 127 | trap_init(); 128 | blk_dev_init(); 129 | chr_dev_init(); 130 | tty_init(); 131 | time_init(); 132 | sched_init(); 133 | buffer_init(buffer_memory_end); 134 | hd_init(); 135 | floppy_init(); 136 | sti(); 137 | move_to_user_mode(); 138 | if (!fork()) { /* we count on this going ok */ 139 | init(); 140 | } 141 | /* 142 | * NOTE!! For any other task 'pause()' would mean we have to get a 143 | * signal to awaken, but task0 is the sole exception (see 'schedule()') 144 | * as task 0 gets activated at every idle moment (when no other tasks 145 | * can run). For task0 'pause()' just means we go check if some other 146 | * task can run, and if not we return here. 147 | */ 148 | for(;;) pause(); 149 | } 150 | 151 | static int printf(const char *fmt, ...) 152 | { 153 | va_list args; 154 | int i; 155 | 156 | va_start(args, fmt); 157 | write(1,printbuf,i=vsprintf(printbuf, fmt, args)); 158 | va_end(args); 159 | return i; 160 | } 161 | 162 | static char * argv_rc[] = { "/bin/sh", NULL }; 163 | static char * envp_rc[] = { "HOME=/", NULL }; 164 | 165 | static char * argv[] = { "-/bin/sh",NULL }; 166 | static char * envp[] = { "HOME=/usr/root", NULL }; 167 | 168 | void init(void) 169 | { 170 | int pid,i; 171 | 172 | setup((void *) &drive_info); 173 | (void) open("/dev/tty0",O_RDWR,0); 174 | (void) dup(0); 175 | (void) dup(0); 176 | printf("%d buffers = %d bytes buffer space\n\r",NR_BUFFERS, 177 | NR_BUFFERS*BLOCK_SIZE); 178 | printf("Free mem: %d bytes\n\r",memory_end-main_memory_start); 179 | if (!(pid=fork())) { 180 | close(0); 181 | if (open("/etc/rc",O_RDONLY,0)) 182 | _exit(1); 183 | execve("/bin/sh",argv_rc,envp_rc); 184 | _exit(2); 185 | } 186 | if (pid>0) 187 | while (pid != wait(&i)) 188 | /* nothing */; 189 | while (1) { 190 | if ((pid=fork())<0) { 191 | printf("Fork failed in init\r\n"); 192 | continue; 193 | } 194 | if (!pid) { 195 | close(0);close(1);close(2); 196 | setsid(); 197 | (void) open("/dev/tty0",O_RDWR,0); 198 | (void) dup(0); 199 | (void) dup(0); 200 | _exit(execve("/bin/sh",argv,envp)); 201 | } 202 | while (1) 203 | if (pid == wait(&i)) 204 | break; 205 | printf("\n\rchild %d died with code %04x\n\r",pid,i); 206 | sync(); 207 | } 208 | _exit(0); /* NOTE! _exit, not exit() */ 209 | } 210 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the FREAX-kernel. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-s -x 13 | CC =gcc -fno-stack-protector -mcpu=i386 14 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../include 16 | CPP =gcc -fno-stack-protector -E -nostdinc -I../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = sched.o system_call.o traps.o asm.o fork.o \ 28 | panic.o printk.o vsprintf.o sys.o exit.o \ 29 | signal.o mktime.o 30 | 31 | kernel.o: $(OBJS) 32 | $(LD) -r -o kernel.o $(OBJS) 33 | sync 34 | 35 | clean: 36 | rm -f core *.o *.a tmp_make keyboard.s 37 | for i in *.c;do rm -f `basename $$i .c`.s;done 38 | (cd chr_drv; make clean) 39 | (cd blk_drv; make clean) 40 | (cd math; make clean) 41 | 42 | dep: 43 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 44 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 45 | $(CPP) -M $$i;done) >> tmp_make 46 | cp tmp_make Makefile 47 | (cd chr_drv; make dep) 48 | (cd blk_drv; make dep) 49 | 50 | ### Dependencies: 51 | exit.s exit.o: exit.c ../include/errno.h ../include/signal.h \ 52 | ../include/sys/types.h ../include/sys/wait.h ../include/linux/sched.h \ 53 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 54 | ../include/linux/kernel.h ../include/linux/tty.h ../include/termios.h \ 55 | ../include/asm/segment.h 56 | fork.s fork.o: fork.c ../include/errno.h ../include/linux/sched.h \ 57 | ../include/linux/head.h ../include/linux/fs.h ../include/sys/types.h \ 58 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h \ 59 | ../include/asm/segment.h ../include/asm/system.h 60 | mktime.s mktime.o: mktime.c ../include/time.h 61 | panic.s panic.o: panic.c ../include/linux/kernel.h ../include/linux/sched.h \ 62 | ../include/linux/head.h ../include/linux/fs.h ../include/sys/types.h \ 63 | ../include/linux/mm.h ../include/signal.h 64 | printk.s printk.o: printk.c ../include/stdarg.h ../include/stddef.h \ 65 | ../include/linux/kernel.h 66 | sched.s sched.o: sched.c ../include/linux/sched.h ../include/linux/head.h \ 67 | ../include/linux/fs.h ../include/sys/types.h ../include/linux/mm.h \ 68 | ../include/signal.h ../include/linux/kernel.h ../include/linux/sys.h \ 69 | ../include/linux/fdreg.h ../include/asm/system.h ../include/asm/io.h \ 70 | ../include/asm/segment.h 71 | signal.s signal.o: signal.c ../include/linux/sched.h ../include/linux/head.h \ 72 | ../include/linux/fs.h ../include/sys/types.h ../include/linux/mm.h \ 73 | ../include/signal.h ../include/linux/kernel.h ../include/asm/segment.h 74 | sys.s sys.o: sys.c ../include/errno.h ../include/linux/sched.h \ 75 | ../include/linux/head.h ../include/linux/fs.h ../include/sys/types.h \ 76 | ../include/linux/mm.h ../include/signal.h ../include/linux/tty.h \ 77 | ../include/termios.h ../include/linux/kernel.h ../include/asm/segment.h \ 78 | ../include/sys/times.h ../include/sys/utsname.h 79 | traps.s traps.o: traps.c ../include/string.h ../include/linux/head.h \ 80 | ../include/linux/sched.h ../include/linux/fs.h ../include/sys/types.h \ 81 | ../include/linux/mm.h ../include/signal.h ../include/linux/kernel.h \ 82 | ../include/asm/system.h ../include/asm/segment.h ../include/asm/io.h 83 | vsprintf.s vsprintf.o: vsprintf.c ../include/stdarg.h ../include/string.h 84 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/asm.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/asm.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * asm.s contains the low-level code for most hardware faults. 9 | * page_exception is handled by the mm, so that isn't here. This 10 | * file also handles (hopefully) fpu-exceptions due to TS-bit, as 11 | * the fpu must be properly saved/resored. This hasn't been tested. 12 | */ 13 | 14 | .globl divide_error,debug,nmi,int3,overflow,bounds,invalid_op 15 | .globl double_fault,coprocessor_segment_overrun 16 | .globl invalid_TSS,segment_not_present,stack_segment 17 | .globl general_protection,coprocessor_error,irq13,reserved 18 | 19 | divide_error: 20 | pushl $do_divide_error 21 | no_error_code: 22 | xchgl %eax,(%esp) 23 | pushl %ebx 24 | pushl %ecx 25 | pushl %edx 26 | pushl %edi 27 | pushl %esi 28 | pushl %ebp 29 | push %ds 30 | push %es 31 | push %fs 32 | pushl $0 # "error code" 33 | lea 44(%esp),%edx 34 | pushl %edx 35 | movl $0x10,%edx 36 | mov %dx,%ds 37 | mov %dx,%es 38 | mov %dx,%fs 39 | call *%eax 40 | addl $8,%esp 41 | pop %fs 42 | pop %es 43 | pop %ds 44 | popl %ebp 45 | popl %esi 46 | popl %edi 47 | popl %edx 48 | popl %ecx 49 | popl %ebx 50 | popl %eax 51 | iret 52 | 53 | debug: 54 | pushl $do_int3 # _do_debug 55 | jmp no_error_code 56 | 57 | nmi: 58 | pushl $do_nmi 59 | jmp no_error_code 60 | 61 | int3: 62 | pushl $do_int3 63 | jmp no_error_code 64 | 65 | overflow: 66 | pushl $do_overflow 67 | jmp no_error_code 68 | 69 | bounds: 70 | pushl $do_bounds 71 | jmp no_error_code 72 | 73 | invalid_op: 74 | pushl $do_invalid_op 75 | jmp no_error_code 76 | 77 | coprocessor_segment_overrun: 78 | pushl $do_coprocessor_segment_overrun 79 | jmp no_error_code 80 | 81 | reserved: 82 | pushl $do_reserved 83 | jmp no_error_code 84 | 85 | irq13: 86 | pushl %eax 87 | xorb %al,%al 88 | outb %al,$0xF0 89 | movb $0x20,%al 90 | outb %al,$0x20 91 | jmp 1f 92 | 1: jmp 1f 93 | 1: outb %al,$0xA0 94 | popl %eax 95 | jmp coprocessor_error 96 | 97 | double_fault: 98 | pushl $do_double_fault 99 | error_code: 100 | xchgl %eax,4(%esp) # error code <-> %eax 101 | xchgl %ebx,(%esp) # &function <-> %ebx 102 | pushl %ecx 103 | pushl %edx 104 | pushl %edi 105 | pushl %esi 106 | pushl %ebp 107 | push %ds 108 | push %es 109 | push %fs 110 | pushl %eax # error code 111 | lea 44(%esp),%eax # offset 112 | pushl %eax 113 | movl $0x10,%eax 114 | mov %ax,%ds 115 | mov %ax,%es 116 | mov %ax,%fs 117 | call *%ebx 118 | addl $8,%esp 119 | pop %fs 120 | pop %es 121 | pop %ds 122 | popl %ebp 123 | popl %esi 124 | popl %edi 125 | popl %edx 126 | popl %ecx 127 | popl %ebx 128 | popl %eax 129 | iret 130 | 131 | invalid_TSS: 132 | pushl $do_invalid_TSS 133 | jmp error_code 134 | 135 | segment_not_present: 136 | pushl $do_segment_not_present 137 | jmp error_code 138 | 139 | stack_segment: 140 | pushl $do_stack_segment 141 | jmp error_code 142 | 143 | general_protection: 144 | pushl $do_general_protection 145 | jmp error_code 146 | 147 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/blk_drv/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the FREAX-kernel block device drivers. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-s -x 13 | CC =gcc -fno-stack-protector -mcpu=i386 14 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../../include 16 | CPP =gcc -fno-stack-protector -E -nostdinc -I../../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = ll_rw_blk.o floppy.o hd.o ramdisk.o 28 | 29 | blk_drv.a: $(OBJS) 30 | $(AR) rcs blk_drv.a $(OBJS) 31 | sync 32 | 33 | clean: 34 | rm -f core *.o *.a tmp_make 35 | for i in *.c;do rm -f `basename $$i .c`.s;done 36 | 37 | dep: 38 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 39 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 40 | $(CPP) -M $$i;done) >> tmp_make 41 | cp tmp_make Makefile 42 | 43 | ### Dependencies: 44 | floppy.s floppy.o: floppy.c ../../include/linux/sched.h ../../include/linux/head.h \ 45 | ../../include/linux/fs.h ../../include/sys/types.h \ 46 | ../../include/linux/mm.h ../../include/signal.h \ 47 | ../../include/linux/kernel.h ../../include/linux/fdreg.h \ 48 | ../../include/asm/system.h ../../include/asm/io.h \ 49 | ../../include/asm/segment.h blk.h 50 | hd.s hd.o: hd.c ../../include/linux/config.h ../../include/linux/sched.h \ 51 | ../../include/linux/head.h ../../include/linux/fs.h \ 52 | ../../include/sys/types.h ../../include/linux/mm.h \ 53 | ../../include/signal.h ../../include/linux/kernel.h \ 54 | ../../include/linux/hdreg.h ../../include/asm/system.h \ 55 | ../../include/asm/io.h ../../include/asm/segment.h blk.h 56 | ll_rw_blk.s ll_rw_blk.o: ll_rw_blk.c ../../include/errno.h \ 57 | ../../include/linux/sched.h ../../include/linux/head.h \ 58 | ../../include/linux/fs.h ../../include/sys/types.h \ 59 | ../../include/linux/mm.h ../../include/signal.h \ 60 | ../../include/linux/kernel.h ../../include/asm/system.h blk.h 61 | ramdisk.s ramdisk.o: ramdisk.c ../../include/string.h ../../include/linux/config.h \ 62 | ../../include/linux/sched.h ../../include/linux/head.h \ 63 | ../../include/linux/fs.h ../../include/sys/types.h \ 64 | ../../include/linux/mm.h ../../include/signal.h \ 65 | ../../include/linux/kernel.h ../../include/asm/system.h \ 66 | ../../include/asm/segment.h ../../include/asm/memory.h blk.h 67 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/blk_drv/blk.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLK_H 2 | #define _BLK_H 3 | 4 | #define NR_BLK_DEV 7 5 | /* 6 | * NR_REQUEST is the number of entries in the request-queue. 7 | * NOTE that writes may use only the low 2/3 of these: reads 8 | * take precedence. 9 | * 10 | * 32 seems to be a reasonable number: enough to get some benefit 11 | * from the elevator-mechanism, but not so much as to lock a lot of 12 | * buffers when they are in the queue. 64 seems to be too many (easily 13 | * long pauses in reading when heavy writing/syncing is going on) 14 | */ 15 | #define NR_REQUEST 32 16 | 17 | /* 18 | * Ok, this is an expanded form so that we can use the same 19 | * request for paging requests when that is implemented. In 20 | * paging, 'bh' is NULL, and 'waiting' is used to wait for 21 | * read/write completion. 22 | */ 23 | struct request { 24 | int dev; /* -1 if no request */ 25 | int cmd; /* READ or WRITE */ 26 | int errors; 27 | unsigned long sector; 28 | unsigned long nr_sectors; 29 | char * buffer; 30 | struct task_struct * waiting; 31 | struct buffer_head * bh; 32 | struct request * next; 33 | }; 34 | 35 | /* 36 | * This is used in the elevator algorithm: Note that 37 | * reads always go before writes. This is natural: reads 38 | * are much more time-critical than writes. 39 | */ 40 | #define IN_ORDER(s1,s2) \ 41 | ((s1)->cmd<(s2)->cmd || ((s1)->cmd==(s2)->cmd && \ 42 | ((s1)->dev < (s2)->dev || ((s1)->dev == (s2)->dev && \ 43 | (s1)->sector < (s2)->sector)))) 44 | 45 | struct blk_dev_struct { 46 | void (*request_fn)(void); 47 | struct request * current_request; 48 | }; 49 | 50 | extern struct blk_dev_struct blk_dev[NR_BLK_DEV]; 51 | extern struct request request[NR_REQUEST]; 52 | extern struct task_struct * wait_for_request; 53 | 54 | #ifdef MAJOR_NR 55 | 56 | /* 57 | * Add entries as needed. Currently the only block devices 58 | * supported are hard-disks and floppies. 59 | */ 60 | 61 | #if (MAJOR_NR == 1) 62 | /* ram disk */ 63 | #define DEVICE_NAME "ramdisk" 64 | #define DEVICE_REQUEST do_rd_request 65 | #define DEVICE_NR(device) ((device) & 7) 66 | #define DEVICE_ON(device) 67 | #define DEVICE_OFF(device) 68 | 69 | #elif (MAJOR_NR == 2) 70 | /* floppy */ 71 | #define DEVICE_NAME "floppy" 72 | #define DEVICE_INTR do_floppy 73 | #define DEVICE_REQUEST do_fd_request 74 | #define DEVICE_NR(device) ((device) & 3) 75 | #define DEVICE_ON(device) floppy_on(DEVICE_NR(device)) 76 | #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device)) 77 | 78 | #elif (MAJOR_NR == 3) 79 | /* harddisk */ 80 | #define DEVICE_NAME "harddisk" 81 | #define DEVICE_INTR do_hd 82 | #define DEVICE_REQUEST do_hd_request 83 | #define DEVICE_NR(device) (MINOR(device)/5) 84 | #define DEVICE_ON(device) 85 | #define DEVICE_OFF(device) 86 | 87 | #elif 88 | /* unknown blk device */ 89 | #error "unknown blk device" 90 | 91 | #endif 92 | 93 | #define CURRENT (blk_dev[MAJOR_NR].current_request) 94 | #define CURRENT_DEV DEVICE_NR(CURRENT->dev) 95 | 96 | #ifdef DEVICE_INTR 97 | void (*DEVICE_INTR)(void) = NULL; 98 | #endif 99 | static void (DEVICE_REQUEST)(void); 100 | 101 | static inline void unlock_buffer(struct buffer_head * bh) 102 | { 103 | if (!bh->b_lock) 104 | printk(DEVICE_NAME ": free buffer being unlocked\n"); 105 | bh->b_lock=0; 106 | wake_up(&bh->b_wait); 107 | } 108 | 109 | static inline void end_request(int uptodate) 110 | { 111 | DEVICE_OFF(CURRENT->dev); 112 | if (CURRENT->bh) { 113 | CURRENT->bh->b_uptodate = uptodate; 114 | unlock_buffer(CURRENT->bh); 115 | } 116 | if (!uptodate) { 117 | printk(DEVICE_NAME " I/O error\n\r"); 118 | printk("dev %04x, block %d\n\r",CURRENT->dev, 119 | CURRENT->bh->b_blocknr); 120 | } 121 | wake_up(&CURRENT->waiting); 122 | wake_up(&wait_for_request); 123 | CURRENT->dev = -1; 124 | CURRENT = CURRENT->next; 125 | } 126 | 127 | #define INIT_REQUEST \ 128 | repeat: \ 129 | if (!CURRENT) \ 130 | return; \ 131 | if (MAJOR(CURRENT->dev) != MAJOR_NR) \ 132 | panic(DEVICE_NAME ": request list destroyed"); \ 133 | if (CURRENT->bh) { \ 134 | if (!CURRENT->bh->b_lock) \ 135 | panic(DEVICE_NAME ": block not locked"); \ 136 | } 137 | 138 | #endif 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/blk_drv/ll_rw_blk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/blk_dev/ll_rw.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * This handles all read/write requests to block devices 9 | */ 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "blk.h" 16 | 17 | /* 18 | * The request-struct contains all necessary data 19 | * to load a nr of sectors into memory 20 | */ 21 | struct request request[NR_REQUEST]; 22 | 23 | /* 24 | * used to wait on when there are no free requests 25 | */ 26 | struct task_struct * wait_for_request = NULL; 27 | 28 | /* blk_dev_struct is: 29 | * do_request-address 30 | * next-request 31 | */ 32 | struct blk_dev_struct blk_dev[NR_BLK_DEV] = { 33 | { NULL, NULL }, /* no_dev */ 34 | { NULL, NULL }, /* dev mem */ 35 | { NULL, NULL }, /* dev fd */ 36 | { NULL, NULL }, /* dev hd */ 37 | { NULL, NULL }, /* dev ttyx */ 38 | { NULL, NULL }, /* dev tty */ 39 | { NULL, NULL } /* dev lp */ 40 | }; 41 | 42 | static inline void lock_buffer(struct buffer_head * bh) 43 | { 44 | cli(); 45 | while (bh->b_lock) 46 | sleep_on(&bh->b_wait); 47 | bh->b_lock=1; 48 | sti(); 49 | } 50 | 51 | static inline void unlock_buffer(struct buffer_head * bh) 52 | { 53 | if (!bh->b_lock) 54 | printk("ll_rw_block.c: buffer not locked\n\r"); 55 | bh->b_lock = 0; 56 | wake_up(&bh->b_wait); 57 | } 58 | 59 | /* 60 | * add-request adds a request to the linked list. 61 | * It disables interrupts so that it can muck with the 62 | * request-lists in peace. 63 | */ 64 | static void add_request(struct blk_dev_struct * dev, struct request * req) 65 | { 66 | struct request * tmp; 67 | 68 | req->next = NULL; 69 | cli(); 70 | if (req->bh) 71 | req->bh->b_dirt = 0; 72 | if (!(tmp = dev->current_request)) { 73 | dev->current_request = req; 74 | sti(); 75 | (dev->request_fn)(); 76 | return; 77 | } 78 | for ( ; tmp->next ; tmp=tmp->next) 79 | if ((IN_ORDER(tmp,req) || 80 | !IN_ORDER(tmp,tmp->next)) && 81 | IN_ORDER(req,tmp->next)) 82 | break; 83 | req->next=tmp->next; 84 | tmp->next=req; 85 | sti(); 86 | } 87 | 88 | static void make_request(int major,int rw, struct buffer_head * bh) 89 | { 90 | struct request * req; 91 | int rw_ahead; 92 | 93 | /* WRITEA/READA is special case - it is not really needed, so if the */ 94 | /* buffer is locked, we just forget about it, else it's a normal read */ 95 | if ((rw_ahead = (rw == READA || rw == WRITEA))) { 96 | if (bh->b_lock) 97 | return; 98 | if (rw == READA) 99 | rw = READ; 100 | else 101 | rw = WRITE; 102 | } 103 | if (rw!=READ && rw!=WRITE) 104 | panic("Bad block dev command, must be R/W/RA/WA"); 105 | lock_buffer(bh); 106 | if ((rw == WRITE && !bh->b_dirt) || (rw == READ && bh->b_uptodate)) { 107 | unlock_buffer(bh); 108 | return; 109 | } 110 | repeat: 111 | /* we don't allow the write-requests to fill up the queue completely: 112 | * we want some room for reads: they take precedence. The last third 113 | * of the requests are only for reads. 114 | */ 115 | if (rw == READ) 116 | req = request+NR_REQUEST; 117 | else 118 | req = request+((NR_REQUEST*2)/3); 119 | /* find an empty request */ 120 | while (--req >= request) 121 | if (req->dev<0) 122 | break; 123 | /* if none found, sleep on new requests: check for rw_ahead */ 124 | if (req < request) { 125 | if (rw_ahead) { 126 | unlock_buffer(bh); 127 | return; 128 | } 129 | sleep_on(&wait_for_request); 130 | goto repeat; 131 | } 132 | /* fill up the request-info, and add it to the queue */ 133 | req->dev = bh->b_dev; 134 | req->cmd = rw; 135 | req->errors=0; 136 | req->sector = bh->b_blocknr<<1; 137 | req->nr_sectors = 2; 138 | req->buffer = bh->b_data; 139 | req->waiting = NULL; 140 | req->bh = bh; 141 | req->next = NULL; 142 | add_request(major+blk_dev,req); 143 | } 144 | 145 | void ll_rw_block(int rw, struct buffer_head * bh) 146 | { 147 | unsigned int major; 148 | 149 | if ((major=MAJOR(bh->b_dev)) >= NR_BLK_DEV || 150 | !(blk_dev[major].request_fn)) { 151 | printk("Trying to read nonexistent block-device\n\r"); 152 | return; 153 | } 154 | make_request(major,rw,bh); 155 | } 156 | 157 | void blk_dev_init(void) 158 | { 159 | int i; 160 | 161 | for (i=0 ; i 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define MAJOR_NR 1 18 | #include "blk.h" 19 | 20 | char *rd_start; 21 | int rd_length = 0; 22 | 23 | void do_rd_request(void) 24 | { 25 | int len; 26 | char *addr; 27 | 28 | INIT_REQUEST; 29 | addr = rd_start + (CURRENT->sector << 9); 30 | len = CURRENT->nr_sectors << 9; 31 | if ((MINOR(CURRENT->dev) != 1) || (addr+len > rd_start+rd_length)) { 32 | end_request(0); 33 | goto repeat; 34 | } 35 | if (CURRENT-> cmd == WRITE) { 36 | (void ) memcpy(addr, 37 | CURRENT->buffer, 38 | len); 39 | } else if (CURRENT->cmd == READ) { 40 | (void) memcpy(CURRENT->buffer, 41 | addr, 42 | len); 43 | } else 44 | panic("unknown ramdisk-command"); 45 | end_request(1); 46 | goto repeat; 47 | } 48 | 49 | /* 50 | * Returns amount of memory which needs to be reserved. 51 | */ 52 | long rd_init(long mem_start, int length) 53 | { 54 | int i; 55 | char *cp; 56 | 57 | blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST; 58 | rd_start = (char *) mem_start; 59 | rd_length = length; 60 | cp = rd_start; 61 | for (i=0; i < length; i++) 62 | *cp++ = '\0'; 63 | return(length); 64 | } 65 | 66 | /* 67 | * If the root device is the ram disk, try to load it. 68 | * In order to do this, the root device is originally set to the 69 | * floppy, and we later change it to be ram disk. 70 | */ 71 | void rd_load(void) 72 | { 73 | struct buffer_head *bh; 74 | struct super_block s; 75 | int block = 256; /* Start at block 256 */ 76 | int i = 1; 77 | int nblocks; 78 | char *cp; /* Move pointer */ 79 | 80 | if (!rd_length) 81 | return; 82 | printk("Ram disk: %d bytes, starting at 0x%x\n", rd_length, 83 | (int) rd_start); 84 | if (MAJOR(ROOT_DEV) != 2) 85 | return; 86 | bh = breada(ROOT_DEV,block+1,block,block+2,-1); 87 | if (!bh) { 88 | printk("Disk error while looking for ramdisk!\n"); 89 | return; 90 | } 91 | *((struct d_super_block *) &s) = *((struct d_super_block *) bh->b_data); 92 | brelse(bh); 93 | if (s.s_magic != SUPER_MAGIC) 94 | /* No ram disk image present, assume normal floppy boot */ 95 | return; 96 | nblocks = s.s_nzones << s.s_log_zone_size; 97 | if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) { 98 | printk("Ram disk image too big! (%d blocks, %d avail)\n", 99 | nblocks, rd_length >> BLOCK_SIZE_BITS); 100 | return; 101 | } 102 | printk("Loading %d bytes into ram disk... 0000k", 103 | nblocks << BLOCK_SIZE_BITS); 104 | cp = rd_start; 105 | while (nblocks) { 106 | if (nblocks > 2) 107 | bh = breada(ROOT_DEV, block, block+1, block+2, -1); 108 | else 109 | bh = bread(ROOT_DEV, block); 110 | if (!bh) { 111 | printk("I/O error on block %d, aborting load\n", 112 | block); 113 | return; 114 | } 115 | (void) memcpy(cp, bh->b_data, BLOCK_SIZE); 116 | brelse(bh); 117 | printk("\010\010\010\010\010%4dk",i); 118 | cp += BLOCK_SIZE; 119 | block++; 120 | nblocks--; 121 | i++; 122 | } 123 | printk("\010\010\010\010\010done \n"); 124 | ROOT_DEV=0x0101; 125 | } 126 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/chr_drv/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the FREAX-kernel character device drivers. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-s -x 13 | CC =gcc -fno-stack-protector -mcpu=i386 14 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../../include 16 | CPP =gcc -fno-stack-protector -E -nostdinc -I../../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = tty_io.o console.o keyboard.o serial.o rs_io.o \ 28 | tty_ioctl.o 29 | 30 | chr_drv.a: $(OBJS) 31 | $(AR) rcs chr_drv.a $(OBJS) 32 | sync 33 | 34 | keyboard.s: keyboard.S ../../include/linux/config.h 35 | $(CPP) -traditional keyboard.S -o keyboard.s 36 | 37 | clean: 38 | rm -f core *.o *.a tmp_make keyboard.s 39 | for i in *.c;do rm -f `basename $$i .c`.s;done 40 | 41 | dep: 42 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 43 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 44 | $(CPP) -M $$i;done) >> tmp_make 45 | cp tmp_make Makefile 46 | 47 | ### Dependencies: 48 | console.s console.o: console.c ../../include/linux/sched.h \ 49 | ../../include/linux/head.h ../../include/linux/fs.h \ 50 | ../../include/sys/types.h ../../include/linux/mm.h \ 51 | ../../include/signal.h ../../include/linux/tty.h \ 52 | ../../include/termios.h ../../include/asm/io.h \ 53 | ../../include/asm/system.h 54 | serial.s serial.o: serial.c ../../include/linux/tty.h ../../include/termios.h \ 55 | ../../include/linux/sched.h ../../include/linux/head.h \ 56 | ../../include/linux/fs.h ../../include/sys/types.h \ 57 | ../../include/linux/mm.h ../../include/signal.h \ 58 | ../../include/asm/system.h ../../include/asm/io.h 59 | tty_io.s tty_io.o: tty_io.c ../../include/ctype.h ../../include/errno.h \ 60 | ../../include/signal.h ../../include/sys/types.h \ 61 | ../../include/linux/sched.h ../../include/linux/head.h \ 62 | ../../include/linux/fs.h ../../include/linux/mm.h \ 63 | ../../include/linux/tty.h ../../include/termios.h \ 64 | ../../include/asm/segment.h ../../include/asm/system.h 65 | tty_ioctl.s tty_ioctl.o: tty_ioctl.c ../../include/errno.h ../../include/termios.h \ 66 | ../../include/linux/sched.h ../../include/linux/head.h \ 67 | ../../include/linux/fs.h ../../include/sys/types.h \ 68 | ../../include/linux/mm.h ../../include/signal.h \ 69 | ../../include/linux/kernel.h ../../include/linux/tty.h \ 70 | ../../include/asm/io.h ../../include/asm/segment.h \ 71 | ../../include/asm/system.h 72 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/chr_drv/rs_io.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/rs_io.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * rs_io.s 9 | * 10 | * This module implements the rs232 io interrupts. 11 | */ 12 | 13 | .text 14 | .globl rs1_interrupt,rs2_interrupt 15 | 16 | size = 1024 /* must be power of two ! 17 | and must match the value 18 | in tty_io.c!!! */ 19 | 20 | /* these are the offsets into the read/write buffer structures */ 21 | rs_addr = 0 22 | head = 4 23 | tail = 8 24 | proc_list = 12 25 | buf = 16 26 | 27 | startup = 256 /* chars left in write queue when we restart it */ 28 | 29 | /* 30 | * These are the actual interrupt routines. They look where 31 | * the interrupt is coming from, and take appropriate action. 32 | */ 33 | .align 2 34 | rs1_interrupt: 35 | pushl $table_list+8 36 | jmp rs_int 37 | .align 2 38 | rs2_interrupt: 39 | pushl $table_list+16 40 | rs_int: 41 | pushl %edx 42 | pushl %ecx 43 | pushl %ebx 44 | pushl %eax 45 | push %es 46 | push %ds /* as this is an interrupt, we cannot */ 47 | pushl $0x10 /* know that bs is ok. Load it */ 48 | pop %ds 49 | pushl $0x10 50 | pop %es 51 | movl 24(%esp),%edx 52 | movl (%edx),%edx 53 | movl rs_addr(%edx),%edx 54 | addl $2,%edx /* interrupt ident. reg */ 55 | rep_int: 56 | xorl %eax,%eax 57 | inb %dx,%al 58 | testb $1,%al 59 | jne end 60 | cmpb $6,%al /* this shouldn't happen, but ... */ 61 | ja end 62 | movl 24(%esp),%ecx 63 | pushl %edx 64 | subl $2,%edx 65 | call jmp_table(,%eax,2) /* NOTE! not *4, bit0 is 0 already */ 66 | popl %edx 67 | jmp rep_int 68 | end: movb $0x20,%al 69 | outb %al,$0x20 /* EOI */ 70 | pop %ds 71 | pop %es 72 | popl %eax 73 | popl %ebx 74 | popl %ecx 75 | popl %edx 76 | addl $4,%esp # jump over _table_list entry 77 | iret 78 | 79 | jmp_table: 80 | .long modem_status,write_char,read_char,line_status 81 | 82 | .align 2 83 | modem_status: 84 | addl $6,%edx /* clear intr by reading modem status reg */ 85 | inb %dx,%al 86 | ret 87 | 88 | .align 2 89 | line_status: 90 | addl $5,%edx /* clear intr by reading line status reg. */ 91 | inb %dx,%al 92 | ret 93 | 94 | .align 2 95 | read_char: 96 | inb %dx,%al 97 | movl %ecx,%edx 98 | subl $table_list,%edx 99 | shrl $3,%edx 100 | movl (%ecx),%ecx # read-queue 101 | movl head(%ecx),%ebx 102 | movb %al,buf(%ecx,%ebx) 103 | incl %ebx 104 | andl $size-1,%ebx 105 | cmpl tail(%ecx),%ebx 106 | je 1f 107 | movl %ebx,head(%ecx) 108 | 1: pushl %edx 109 | call do_tty_interrupt 110 | addl $4,%esp 111 | ret 112 | 113 | .align 2 114 | write_char: 115 | movl 4(%ecx),%ecx # write-queue 116 | movl head(%ecx),%ebx 117 | subl tail(%ecx),%ebx 118 | andl $size-1,%ebx # nr chars in queue 119 | je write_buffer_empty 120 | cmpl $startup,%ebx 121 | ja 1f 122 | movl proc_list(%ecx),%ebx # wake up sleeping process 123 | testl %ebx,%ebx # is there any? 124 | je 1f 125 | movl $0,(%ebx) 126 | 1: movl tail(%ecx),%ebx 127 | movb buf(%ecx,%ebx),%al 128 | outb %al,%dx 129 | incl %ebx 130 | andl $size-1,%ebx 131 | movl %ebx,tail(%ecx) 132 | cmpl head(%ecx),%ebx 133 | je write_buffer_empty 134 | ret 135 | .align 2 136 | write_buffer_empty: 137 | movl proc_list(%ecx),%ebx # wake up sleeping process 138 | testl %ebx,%ebx # is there any? 139 | je 1f 140 | movl $0,(%ebx) 141 | 1: incl %edx 142 | inb %dx,%al 143 | jmp 1f 144 | 1: jmp 1f 145 | 1: andb $0xd,%al /* disable transmit interrupt */ 146 | outb %al,%dx 147 | ret 148 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/chr_drv/serial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/serial.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * serial.c 9 | * 10 | * This module implements the rs232 io functions 11 | * void rs_write(struct tty_struct * queue); 12 | * void rs_init(void); 13 | * and all interrupts pertaining to serial IO. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define WAKEUP_CHARS (TTY_BUF_SIZE/4) 22 | 23 | extern void rs1_interrupt(void); 24 | extern void rs2_interrupt(void); 25 | 26 | static void init(int port) 27 | { 28 | outb_p(0x80,port+3); /* set DLAB of line control reg */ 29 | outb_p(0x30,port); /* LS of divisor (48 -> 2400 bps */ 30 | outb_p(0x00,port+1); /* MS of divisor */ 31 | outb_p(0x03,port+3); /* reset DLAB */ 32 | outb_p(0x0b,port+4); /* set DTR,RTS, OUT_2 */ 33 | outb_p(0x0d,port+1); /* enable all intrs but writes */ 34 | (void)inb(port); /* read data port to reset things (?) */ 35 | } 36 | 37 | void rs_init(void) 38 | { 39 | set_intr_gate(0x24,rs1_interrupt); 40 | set_intr_gate(0x23,rs2_interrupt); 41 | init(tty_table[1].read_q.data); 42 | init(tty_table[2].read_q.data); 43 | outb(inb_p(0x21)&0xE7,0x21); 44 | } 45 | 46 | /* 47 | * This routine gets called when tty_write has put something into 48 | * the write_queue. It must check wheter the queue is empty, and 49 | * set the interrupt register accordingly 50 | * 51 | * void _rs_write(struct tty_struct * tty); 52 | */ 53 | void rs_write(struct tty_struct * tty) 54 | { 55 | cli(); 56 | if (!EMPTY(tty->write_q)) 57 | outb(inb_p(tty->write_q.data+1)|0x02,tty->write_q.data+1); 58 | sti(); 59 | } 60 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/chr_drv/tty_ioctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/chr_drv/tty_ioctl.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | static unsigned short quotient[] = { 19 | 0, 2304, 1536, 1047, 857, 20 | 768, 576, 384, 192, 96, 21 | 64, 48, 24, 12, 6, 3 22 | }; 23 | 24 | static void change_speed(struct tty_struct * tty) 25 | { 26 | unsigned short port,quot; 27 | 28 | if (!(port = tty->read_q.data)) 29 | return; 30 | quot = quotient[tty->termios.c_cflag & CBAUD]; 31 | cli(); 32 | outb_p(0x80,port+3); /* set DLAB */ 33 | outb_p(quot & 0xff,port); /* LS of divisor */ 34 | outb_p(quot >> 8,port+1); /* MS of divisor */ 35 | outb(0x03,port+3); /* reset DLAB */ 36 | sti(); 37 | } 38 | 39 | static void flush(struct tty_queue * queue) 40 | { 41 | cli(); 42 | queue->head = queue->tail; 43 | sti(); 44 | } 45 | 46 | static void wait_until_sent(struct tty_struct * tty) 47 | { 48 | /* do nothing - not implemented */ 49 | } 50 | 51 | static void send_break(struct tty_struct * tty) 52 | { 53 | /* do nothing - not implemented */ 54 | } 55 | 56 | static int get_termios(struct tty_struct * tty, struct termios * termios) 57 | { 58 | int i; 59 | 60 | verify_area(termios, sizeof (*termios)); 61 | for (i=0 ; i< (sizeof (*termios)) ; i++) 62 | put_fs_byte( ((char *)&tty->termios)[i] , i+(char *)termios ); 63 | return 0; 64 | } 65 | 66 | static int set_termios(struct tty_struct * tty, struct termios * termios) 67 | { 68 | int i; 69 | 70 | for (i=0 ; i< (sizeof (*termios)) ; i++) 71 | ((char *)&tty->termios)[i]=get_fs_byte(i+(char *)termios); 72 | change_speed(tty); 73 | return 0; 74 | } 75 | 76 | static int get_termio(struct tty_struct * tty, struct termio * termio) 77 | { 78 | int i; 79 | struct termio tmp_termio; 80 | 81 | verify_area(termio, sizeof (*termio)); 82 | tmp_termio.c_iflag = tty->termios.c_iflag; 83 | tmp_termio.c_oflag = tty->termios.c_oflag; 84 | tmp_termio.c_cflag = tty->termios.c_cflag; 85 | tmp_termio.c_lflag = tty->termios.c_lflag; 86 | tmp_termio.c_line = tty->termios.c_line; 87 | for(i=0 ; i < NCC ; i++) 88 | tmp_termio.c_cc[i] = tty->termios.c_cc[i]; 89 | for (i=0 ; i< (sizeof (*termio)) ; i++) 90 | put_fs_byte( ((char *)&tmp_termio)[i] , i+(char *)termio ); 91 | return 0; 92 | } 93 | 94 | /* 95 | * This only works as the 386 is low-byt-first 96 | */ 97 | static int set_termio(struct tty_struct * tty, struct termio * termio) 98 | { 99 | int i; 100 | struct termio tmp_termio; 101 | 102 | for (i=0 ; i< (sizeof (*termio)) ; i++) 103 | ((char *)&tmp_termio)[i]=get_fs_byte(i+(char *)termio); 104 | *(unsigned short *)&tty->termios.c_iflag = tmp_termio.c_iflag; 105 | *(unsigned short *)&tty->termios.c_oflag = tmp_termio.c_oflag; 106 | *(unsigned short *)&tty->termios.c_cflag = tmp_termio.c_cflag; 107 | *(unsigned short *)&tty->termios.c_lflag = tmp_termio.c_lflag; 108 | tty->termios.c_line = tmp_termio.c_line; 109 | for(i=0 ; i < NCC ; i++) 110 | tty->termios.c_cc[i] = tmp_termio.c_cc[i]; 111 | change_speed(tty); 112 | return 0; 113 | } 114 | 115 | int tty_ioctl(int dev, int cmd, int arg) 116 | { 117 | struct tty_struct * tty; 118 | if (MAJOR(dev) == 5) { 119 | dev=current->tty; 120 | if (dev<0) 121 | panic("tty_ioctl: dev<0"); 122 | } else 123 | dev=MINOR(dev); 124 | tty = dev + tty_table; 125 | switch (cmd) { 126 | case TCGETS: 127 | return get_termios(tty,(struct termios *) arg); 128 | case TCSETSF: 129 | flush(&tty->read_q); /* fallthrough */ 130 | case TCSETSW: 131 | wait_until_sent(tty); /* fallthrough */ 132 | case TCSETS: 133 | return set_termios(tty,(struct termios *) arg); 134 | case TCGETA: 135 | return get_termio(tty,(struct termio *) arg); 136 | case TCSETAF: 137 | flush(&tty->read_q); /* fallthrough */ 138 | case TCSETAW: 139 | wait_until_sent(tty); /* fallthrough */ 140 | case TCSETA: 141 | return set_termio(tty,(struct termio *) arg); 142 | case TCSBRK: 143 | if (!arg) { 144 | wait_until_sent(tty); 145 | send_break(tty); 146 | } 147 | return 0; 148 | case TCXONC: 149 | return -EINVAL; /* not implemented */ 150 | case TCFLSH: 151 | if (arg==0) 152 | flush(&tty->read_q); 153 | else if (arg==1) 154 | flush(&tty->write_q); 155 | else if (arg==2) { 156 | flush(&tty->read_q); 157 | flush(&tty->write_q); 158 | } else 159 | return -EINVAL; 160 | return 0; 161 | case TIOCEXCL: 162 | return -EINVAL; /* not implemented */ 163 | case TIOCNXCL: 164 | return -EINVAL; /* not implemented */ 165 | case TIOCSCTTY: 166 | return -EINVAL; /* set controlling term NI */ 167 | case TIOCGPGRP: 168 | verify_area((void *) arg,4); 169 | put_fs_long(tty->pgrp,(unsigned long *) arg); 170 | return 0; 171 | case TIOCSPGRP: 172 | tty->pgrp=get_fs_long((unsigned long *) arg); 173 | return 0; 174 | case TIOCOUTQ: 175 | verify_area((void *) arg,4); 176 | put_fs_long(CHARS(tty->write_q),(unsigned long *) arg); 177 | return 0; 178 | case TIOCINQ: 179 | verify_area((void *) arg,4); 180 | put_fs_long(CHARS(tty->secondary), 181 | (unsigned long *) arg); 182 | return 0; 183 | case TIOCSTI: 184 | return -EINVAL; /* not implemented */ 185 | case TIOCGWINSZ: 186 | return -EINVAL; /* not implemented */ 187 | case TIOCSWINSZ: 188 | return -EINVAL; /* not implemented */ 189 | case TIOCMGET: 190 | return -EINVAL; /* not implemented */ 191 | case TIOCMBIS: 192 | return -EINVAL; /* not implemented */ 193 | case TIOCMBIC: 194 | return -EINVAL; /* not implemented */ 195 | case TIOCMSET: 196 | return -EINVAL; /* not implemented */ 197 | case TIOCGSOFTCAR: 198 | return -EINVAL; /* not implemented */ 199 | case TIOCSSOFTCAR: 200 | return -EINVAL; /* not implemented */ 201 | default: 202 | return -EINVAL; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/exit.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int sys_pause(void); 17 | int sys_close(int fd); 18 | 19 | void release(struct task_struct * p) 20 | { 21 | int i; 22 | 23 | if (!p) 24 | return; 25 | for (i=1 ; i32) 38 | return -EINVAL; 39 | if (priv || (current->euid==p->euid) || suser()) 40 | p->signal |= (1<<(sig-1)); 41 | else 42 | return -EPERM; 43 | return 0; 44 | } 45 | 46 | static void kill_session(void) 47 | { 48 | struct task_struct **p = NR_TASKS + task; 49 | 50 | while (--p > &FIRST_TASK) { 51 | if (*p && (*p)->session == current->session) 52 | (*p)->signal |= 1<<(SIGHUP-1); 53 | } 54 | } 55 | 56 | /* 57 | * XXX need to check permissions needed to send signals to process 58 | * groups, etc. etc. kill() permissions semantics are tricky! 59 | */ 60 | int sys_kill(int pid,int sig) 61 | { 62 | struct task_struct **p = NR_TASKS + task; 63 | int err, retval = 0; 64 | 65 | if (!pid) while (--p > &FIRST_TASK) { 66 | if (*p && (*p)->pgrp == current->pid) 67 | if ((err=send_sig(sig,*p,1))) 68 | retval = err; 69 | } else if (pid>0) while (--p > &FIRST_TASK) { 70 | if (*p && (*p)->pid == pid) 71 | if ((err=send_sig(sig,*p,0))) 72 | retval = err; 73 | } else if (pid == -1) while (--p > &FIRST_TASK) { 74 | if ((err = send_sig(sig,*p,0))) 75 | retval = err; 76 | } else while (--p > &FIRST_TASK) 77 | if (*p && (*p)->pgrp == -pid) 78 | if ((err = send_sig(sig,*p,0))) 79 | retval = err; 80 | return retval; 81 | } 82 | 83 | static void tell_father(int pid) 84 | { 85 | int i; 86 | 87 | if (pid) 88 | for (i=0;ipid != pid) 92 | continue; 93 | task[i]->signal |= (1<<(SIGCHLD-1)); 94 | return; 95 | } 96 | /* if we don't find any fathers, we just release ourselves */ 97 | /* This is not really OK. Must change it to make father 1 */ 98 | printk("BAD BAD - no father found\n\r"); 99 | release(current); 100 | } 101 | 102 | int do_exit(long code) 103 | { 104 | int i; 105 | free_page_tables(get_base(current->ldt[1]),get_limit(0x0f)); 106 | free_page_tables(get_base(current->ldt[2]),get_limit(0x17)); 107 | for (i=0 ; ifather == current->pid) { 109 | task[i]->father = 1; 110 | if (task[i]->state == TASK_ZOMBIE) 111 | /* assumption task[1] is always init */ 112 | (void) send_sig(SIGCHLD, task[1], 1); 113 | } 114 | for (i=0 ; ifilp[i]) 116 | sys_close(i); 117 | iput(current->pwd); 118 | current->pwd=NULL; 119 | iput(current->root); 120 | current->root=NULL; 121 | iput(current->executable); 122 | current->executable=NULL; 123 | if (current->leader && current->tty >= 0) 124 | tty_table[current->tty].pgrp = 0; 125 | if (last_task_used_math == current) 126 | last_task_used_math = NULL; 127 | if (current->leader) 128 | kill_session(); 129 | current->state = TASK_ZOMBIE; 130 | current->exit_code = code; 131 | tell_father(current->father); 132 | schedule(); 133 | return (-1); /* just to suppress warnings */ 134 | } 135 | 136 | int sys_exit(int error_code) 137 | { 138 | return do_exit((error_code&0xff)<<8); 139 | } 140 | 141 | int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options) 142 | { 143 | int flag, code; 144 | struct task_struct ** p; 145 | 146 | verify_area(stat_addr,4); 147 | repeat: 148 | flag=0; 149 | for(p = &LAST_TASK ; p > &FIRST_TASK ; --p) { 150 | if (!*p || *p == current) 151 | continue; 152 | if ((*p)->father != current->pid) 153 | continue; 154 | if (pid>0) { 155 | if ((*p)->pid != pid) 156 | continue; 157 | } else if (!pid) { 158 | if ((*p)->pgrp != current->pgrp) 159 | continue; 160 | } else if (pid != -1) { 161 | if ((*p)->pgrp != -pid) 162 | continue; 163 | } 164 | switch ((*p)->state) { 165 | case TASK_STOPPED: 166 | if (!(options & WUNTRACED)) 167 | continue; 168 | put_fs_long(0x7f,stat_addr); 169 | return (*p)->pid; 170 | case TASK_ZOMBIE: 171 | current->cutime += (*p)->utime; 172 | current->cstime += (*p)->stime; 173 | flag = (*p)->pid; 174 | code = (*p)->exit_code; 175 | release(*p); 176 | put_fs_long(code,stat_addr); 177 | return flag; 178 | default: 179 | flag=1; 180 | continue; 181 | } 182 | } 183 | if (flag) { 184 | if (options & WNOHANG) 185 | return 0; 186 | current->state=TASK_INTERRUPTIBLE; 187 | schedule(); 188 | if (!(current->signal &= ~(1<<(SIGCHLD-1)))) 189 | goto repeat; 190 | else 191 | return -EINTR; 192 | } 193 | return -ECHILD; 194 | } 195 | 196 | 197 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/fork.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * 'fork.c' contains the help-routines for the 'fork' system call 9 | * (see also system_call.s), and some misc functions ('verify_area'). 10 | * Fork is rather simple, once you get the hang of it, but the memory 11 | * management can be a bitch. See 'mm/mm.c': 'copy_page_tables()' 12 | */ 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | extern void write_verify(unsigned long address); 21 | 22 | long last_pid=0; 23 | 24 | void verify_area(void * addr,int size) 25 | { 26 | unsigned long start; 27 | 28 | start = (unsigned long) addr; 29 | size += start & 0xfff; 30 | start &= 0xfffff000; 31 | start += get_base(current->ldt[2]); 32 | while (size>0) { 33 | size -= 4096; 34 | write_verify(start); 35 | start += 4096; 36 | } 37 | } 38 | 39 | int copy_mem(int nr,struct task_struct * p) 40 | { 41 | unsigned long old_data_base,new_data_base,data_limit; 42 | unsigned long old_code_base,new_code_base,code_limit; 43 | 44 | code_limit=get_limit(0x0f); 45 | data_limit=get_limit(0x17); 46 | old_code_base = get_base(current->ldt[1]); 47 | old_data_base = get_base(current->ldt[2]); 48 | if (old_data_base != old_code_base) 49 | panic("We don't support separate I&D"); 50 | if (data_limit < code_limit) 51 | panic("Bad data_limit"); 52 | new_data_base = new_code_base = nr * 0x4000000; 53 | p->start_code = new_code_base; 54 | set_base(p->ldt[1],new_code_base); 55 | set_base(p->ldt[2],new_data_base); 56 | if (copy_page_tables(old_data_base,new_data_base,data_limit)) { 57 | printk("free_page_tables: from copy_mem\n"); 58 | free_page_tables(new_data_base,data_limit); 59 | return -ENOMEM; 60 | } 61 | return 0; 62 | } 63 | 64 | /* 65 | * Ok, this is the main fork-routine. It copies the system process 66 | * information (task[nr]) and sets up the necessary registers. It 67 | * also copies the data segment in it's entirety. 68 | */ 69 | int copy_process(int nr,long ebp,long edi,long esi,long gs,long none, 70 | long ebx,long ecx,long edx, 71 | long fs,long es,long ds, 72 | long eip,long cs,long eflags,long esp,long ss) 73 | { 74 | struct task_struct *p; 75 | int i; 76 | struct file *f; 77 | 78 | p = (struct task_struct *) get_free_page(); 79 | if (!p) 80 | return -EAGAIN; 81 | task[nr] = p; 82 | *p = *current; /* NOTE! this doesn't copy the supervisor stack */ 83 | p->state = TASK_UNINTERRUPTIBLE; 84 | p->pid = last_pid; 85 | p->father = current->pid; 86 | p->counter = p->priority; 87 | p->signal = 0; 88 | p->alarm = 0; 89 | p->leader = 0; /* process leadership doesn't inherit */ 90 | p->utime = p->stime = 0; 91 | p->cutime = p->cstime = 0; 92 | p->start_time = jiffies; 93 | p->tss.back_link = 0; 94 | p->tss.esp0 = PAGE_SIZE + (long) p; 95 | p->tss.ss0 = 0x10; 96 | p->tss.eip = eip; 97 | p->tss.eflags = eflags; 98 | p->tss.eax = 0; 99 | p->tss.ecx = ecx; 100 | p->tss.edx = edx; 101 | p->tss.ebx = ebx; 102 | p->tss.esp = esp; 103 | p->tss.ebp = ebp; 104 | p->tss.esi = esi; 105 | p->tss.edi = edi; 106 | p->tss.es = es & 0xffff; 107 | p->tss.cs = cs & 0xffff; 108 | p->tss.ss = ss & 0xffff; 109 | p->tss.ds = ds & 0xffff; 110 | p->tss.fs = fs & 0xffff; 111 | p->tss.gs = gs & 0xffff; 112 | p->tss.ldt = _LDT(nr); 113 | p->tss.trace_bitmap = 0x80000000; 114 | if (last_task_used_math == current) 115 | __asm__("clts ; fnsave %0"::"m" (p->tss.i387)); 116 | if (copy_mem(nr,p)) { 117 | task[nr] = NULL; 118 | free_page((long) p); 119 | return -EAGAIN; 120 | } 121 | for (i=0; ifilp[i])) 123 | f->f_count++; 124 | if (current->pwd) 125 | current->pwd->i_count++; 126 | if (current->root) 127 | current->root->i_count++; 128 | if (current->executable) 129 | current->executable->i_count++; 130 | set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss)); 131 | set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&(p->ldt)); 132 | p->state = TASK_RUNNING; /* do this last, just in case */ 133 | return last_pid; 134 | } 135 | 136 | int find_empty_process(void) 137 | { 138 | int i; 139 | 140 | repeat: 141 | if ((++last_pid)<0) last_pid=1; 142 | for(i=0 ; ipid == last_pid) goto repeat; 144 | for(i=1 ; i tmp_make 39 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 40 | $(CPP) -M $$i;done) >> tmp_make 41 | cp tmp_make Makefile 42 | 43 | ### Dependencies: 44 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/math/math_emulate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/math/math_emulate.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * This directory should contain the math-emulation code. 9 | * Currently only results in a signal. 10 | */ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | void math_emulate(long edi, long esi, long ebp, long sys_call_ret, 19 | long eax,long ebx,long ecx,long edx, 20 | unsigned short fs,unsigned short es,unsigned short ds, 21 | unsigned long eip,unsigned short cs,unsigned long eflags, 22 | unsigned short ss, unsigned long esp) 23 | { 24 | unsigned char first, second; 25 | 26 | /* 0x0007 means user code space */ 27 | if (cs != 0x000F) { 28 | printk("math_emulate: %04x:%08x\n\r",cs,eip); 29 | panic("Math emulation needed in kernel"); 30 | } 31 | first = get_fs_byte((char *)((*&eip)++)); 32 | second = get_fs_byte((char *)((*&eip)++)); 33 | printk("%04x:%08x %02x %02x\n\r",cs,eip-2,first,second); 34 | current->signal |= 1<<(SIGFPE-1); 35 | } 36 | 37 | void math_error(void) 38 | { 39 | __asm__("fnclex"); 40 | if (last_task_used_math) 41 | last_task_used_math->signal |= 1<<(SIGFPE-1); 42 | } 43 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/mktime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/mktime.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | /* 10 | * This isn't the library routine, it is only used in the kernel. 11 | * as such, we don't care about years<1970 etc, but assume everything 12 | * is ok. Similarly, TZ etc is happily ignored. We just do everything 13 | * as easily as possible. Let's find something public for the library 14 | * routines (although I think minix times is public). 15 | */ 16 | /* 17 | * PS. I hate whoever though up the year 1970 - couldn't they have gotten 18 | * a leap-year instead? I also hate Gregorius, pope or no. I'm grumpy. 19 | */ 20 | #define MINUTE 60 21 | #define HOUR (60*MINUTE) 22 | #define DAY (24*HOUR) 23 | #define YEAR (365*DAY) 24 | 25 | /* interestingly, we assume leap-years */ 26 | static int month[12] = { 27 | 0, 28 | DAY*(31), 29 | DAY*(31+29), 30 | DAY*(31+29+31), 31 | DAY*(31+29+31+30), 32 | DAY*(31+29+31+30+31), 33 | DAY*(31+29+31+30+31+30), 34 | DAY*(31+29+31+30+31+30+31), 35 | DAY*(31+29+31+30+31+30+31+31), 36 | DAY*(31+29+31+30+31+30+31+31+30), 37 | DAY*(31+29+31+30+31+30+31+31+30+31), 38 | DAY*(31+29+31+30+31+30+31+31+30+31+30) 39 | }; 40 | 41 | long kernel_mktime(struct tm * tm) 42 | { 43 | long res; 44 | int year; 45 | 46 | year = tm->tm_year - 70; 47 | /* magic offsets (y+1) needed to get leapyears right.*/ 48 | res = YEAR*year + DAY*((year+1)/4); 49 | res += month[tm->tm_mon]; 50 | /* and (y+2) here. If it wasn't a leap-year, we have to adjust */ 51 | if (tm->tm_mon>1 && ((year+2)%4)) 52 | res -= DAY; 53 | res += DAY*(tm->tm_mday-1); 54 | res += HOUR*tm->tm_hour; 55 | res += MINUTE*tm->tm_min; 56 | res += tm->tm_sec; 57 | return res; 58 | } 59 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/panic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/panic.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * This function is used through-out the kernel (includeinh mm and fs) 9 | * to indicate a major problem. 10 | */ 11 | #define PANIC 12 | 13 | #include 14 | #include 15 | 16 | void sys_sync(void); /* it's really int */ 17 | 18 | volatile void panic(const char * s) 19 | { 20 | printk("Kernel panic: %s\n\r",s); 21 | if (current == task[0]) 22 | printk("In swapper task - not syncing\n\r"); 23 | else 24 | sys_sync(); 25 | for(;;); 26 | } 27 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/printk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/printk.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * When in kernel-mode, we cannot use printf, as fs is liable to 9 | * point to 'interesting' things. Make a printf with fs-saving, and 10 | * all is well. 11 | */ 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | static char buf[1024]; 18 | 19 | extern int vsprintf(char * buf, const char * fmt, va_list args); 20 | 21 | int printk(const char *fmt, ...) 22 | { 23 | va_list args; 24 | int i; 25 | 26 | va_start(args, fmt); 27 | i=vsprintf(buf,fmt,args); 28 | va_end(args); 29 | __asm__("push %%fs\n\t" 30 | "push %%ds\n\t" 31 | "pop %%fs\n\t" 32 | "pushl %0\n\t" 33 | "pushl $buf\n\t" 34 | "pushl $0\n\t" 35 | "call tty_write\n\t" 36 | "addl $8,%%esp\n\t" 37 | "popl %0\n\t" 38 | "pop %%fs" 39 | ::"r" (i):"ax","cx","dx"); 40 | return i; 41 | } 42 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/signal.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | volatile void do_exit(int error_code); 14 | 15 | int sys_sgetmask() 16 | { 17 | return current->blocked; 18 | } 19 | 20 | int sys_ssetmask(int newmask) 21 | { 22 | int old=current->blocked; 23 | 24 | current->blocked = newmask & ~(1<<(SIGKILL-1)); 25 | return old; 26 | } 27 | 28 | static inline void save_old(char * from,char * to) 29 | { 30 | int i; 31 | 32 | verify_area(to, sizeof(struct sigaction)); 33 | for (i=0 ; i< sizeof(struct sigaction) ; i++) { 34 | put_fs_byte(*from,to); 35 | from++; 36 | to++; 37 | } 38 | } 39 | 40 | static inline void get_new(char * from,char * to) 41 | { 42 | int i; 43 | 44 | for (i=0 ; i< sizeof(struct sigaction) ; i++) 45 | *(to++) = get_fs_byte(from++); 46 | } 47 | 48 | int sys_signal(int signum, long handler, long restorer) 49 | { 50 | struct sigaction tmp; 51 | 52 | if (signum<1 || signum>32 || signum==SIGKILL) 53 | return -1; 54 | tmp.sa_handler = (void (*)(int)) handler; 55 | tmp.sa_mask = 0; 56 | tmp.sa_flags = SA_ONESHOT | SA_NOMASK; 57 | tmp.sa_restorer = (void (*)(void)) restorer; 58 | handler = (long) current->sigaction[signum-1].sa_handler; 59 | current->sigaction[signum-1] = tmp; 60 | return handler; 61 | } 62 | 63 | int sys_sigaction(int signum, const struct sigaction * action, 64 | struct sigaction * oldaction) 65 | { 66 | struct sigaction tmp; 67 | 68 | if (signum<1 || signum>32 || signum==SIGKILL) 69 | return -1; 70 | tmp = current->sigaction[signum-1]; 71 | get_new((char *) action, 72 | (char *) (signum-1+current->sigaction)); 73 | if (oldaction) 74 | save_old((char *) &tmp,(char *) oldaction); 75 | if (current->sigaction[signum-1].sa_flags & SA_NOMASK) 76 | current->sigaction[signum-1].sa_mask = 0; 77 | else 78 | current->sigaction[signum-1].sa_mask |= (1<<(signum-1)); 79 | return 0; 80 | } 81 | 82 | void do_signal(long signr,long eax, long ebx, long ecx, long edx, 83 | long fs, long es, long ds, 84 | long eip, long cs, long eflags, 85 | unsigned long * esp, long ss) 86 | { 87 | unsigned long sa_handler; 88 | long old_eip=eip; 89 | struct sigaction * sa = current->sigaction + signr - 1; 90 | int longs; 91 | unsigned long * tmp_esp; 92 | 93 | sa_handler = (unsigned long) sa->sa_handler; 94 | if (sa_handler==1) 95 | return; 96 | if (!sa_handler) { 97 | if (signr==SIGCHLD) 98 | return; 99 | else 100 | do_exit(1<<(signr-1)); 101 | } 102 | if (sa->sa_flags & SA_ONESHOT) 103 | sa->sa_handler = NULL; 104 | *(&eip) = sa_handler; 105 | longs = (sa->sa_flags & SA_NOMASK)?7:8; 106 | *(&esp) -= longs; 107 | verify_area(esp,longs*4); 108 | tmp_esp=esp; 109 | put_fs_long((long) sa->sa_restorer,tmp_esp++); 110 | put_fs_long(signr,tmp_esp++); 111 | if (!(sa->sa_flags & SA_NOMASK)) 112 | put_fs_long(current->blocked,tmp_esp++); 113 | put_fs_long(eax,tmp_esp++); 114 | put_fs_long(ecx,tmp_esp++); 115 | put_fs_long(edx,tmp_esp++); 116 | put_fs_long(eflags,tmp_esp++); 117 | put_fs_long(old_eip,tmp_esp++); 118 | current->blocked |= sa->sa_mask; 119 | } 120 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/sys.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/sys.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int sys_ftime() 17 | { 18 | return -ENOSYS; 19 | } 20 | 21 | int sys_break() 22 | { 23 | return -ENOSYS; 24 | } 25 | 26 | int sys_ptrace() 27 | { 28 | return -ENOSYS; 29 | } 30 | 31 | int sys_stty() 32 | { 33 | return -ENOSYS; 34 | } 35 | 36 | int sys_gtty() 37 | { 38 | return -ENOSYS; 39 | } 40 | 41 | int sys_rename() 42 | { 43 | return -ENOSYS; 44 | } 45 | 46 | int sys_prof() 47 | { 48 | return -ENOSYS; 49 | } 50 | 51 | int sys_setregid(int rgid, int egid) 52 | { 53 | if (rgid>0) { 54 | if ((current->gid == rgid) || 55 | suser()) 56 | current->gid = rgid; 57 | else 58 | return(-EPERM); 59 | } 60 | if (egid>0) { 61 | if ((current->gid == egid) || 62 | (current->egid == egid) || 63 | (current->sgid == egid) || 64 | suser()) 65 | current->egid = egid; 66 | else 67 | return(-EPERM); 68 | } 69 | return 0; 70 | } 71 | 72 | int sys_setgid(int gid) 73 | { 74 | return(sys_setregid(gid, gid)); 75 | } 76 | 77 | int sys_acct() 78 | { 79 | return -ENOSYS; 80 | } 81 | 82 | int sys_phys() 83 | { 84 | return -ENOSYS; 85 | } 86 | 87 | int sys_lock() 88 | { 89 | return -ENOSYS; 90 | } 91 | 92 | int sys_mpx() 93 | { 94 | return -ENOSYS; 95 | } 96 | 97 | int sys_ulimit() 98 | { 99 | return -ENOSYS; 100 | } 101 | 102 | int sys_time(long * tloc) 103 | { 104 | int i; 105 | 106 | i = CURRENT_TIME; 107 | if (tloc) { 108 | verify_area(tloc,4); 109 | put_fs_long(i,(unsigned long *)tloc); 110 | } 111 | return i; 112 | } 113 | 114 | /* 115 | * Unprivileged users may change the real user id to the effective uid 116 | * or vice versa. 117 | */ 118 | int sys_setreuid(int ruid, int euid) 119 | { 120 | int old_ruid = current->uid; 121 | 122 | if (ruid>0) { 123 | if ((current->euid==ruid) || 124 | (old_ruid == ruid) || 125 | suser()) 126 | current->uid = ruid; 127 | else 128 | return(-EPERM); 129 | } 130 | if (euid>0) { 131 | if ((old_ruid == euid) || 132 | (current->euid == euid) || 133 | suser()) 134 | current->euid = euid; 135 | else { 136 | current->uid = old_ruid; 137 | return(-EPERM); 138 | } 139 | } 140 | return 0; 141 | } 142 | 143 | int sys_setuid(int uid) 144 | { 145 | return(sys_setreuid(uid, uid)); 146 | } 147 | 148 | int sys_stime(long * tptr) 149 | { 150 | if (!suser()) 151 | return -EPERM; 152 | startup_time = get_fs_long((unsigned long *)tptr) - jiffies/HZ; 153 | return 0; 154 | } 155 | 156 | int sys_times(struct tms * tbuf) 157 | { 158 | if (tbuf) { 159 | verify_area(tbuf,sizeof *tbuf); 160 | put_fs_long(current->utime,(unsigned long *)&tbuf->tms_utime); 161 | put_fs_long(current->stime,(unsigned long *)&tbuf->tms_stime); 162 | put_fs_long(current->cutime,(unsigned long *)&tbuf->tms_cutime); 163 | put_fs_long(current->cstime,(unsigned long *)&tbuf->tms_cstime); 164 | } 165 | return jiffies; 166 | } 167 | 168 | int sys_brk(unsigned long end_data_seg) 169 | { 170 | if (end_data_seg >= current->end_code && 171 | end_data_seg < current->start_stack - 16384) 172 | current->brk = end_data_seg; 173 | return current->brk; 174 | } 175 | 176 | /* 177 | * This needs some heave checking ... 178 | * I just haven't get the stomach for it. I also don't fully 179 | * understand sessions/pgrp etc. Let somebody who does explain it. 180 | */ 181 | int sys_setpgid(int pid, int pgid) 182 | { 183 | int i; 184 | 185 | if (!pid) 186 | pid = current->pid; 187 | if (!pgid) 188 | pgid = current->pid; 189 | for (i=0 ; ipid==pid) { 191 | if (task[i]->leader) 192 | return -EPERM; 193 | if (task[i]->session != current->session) 194 | return -EPERM; 195 | task[i]->pgrp = pgid; 196 | return 0; 197 | } 198 | return -ESRCH; 199 | } 200 | 201 | int sys_getpgrp(void) 202 | { 203 | return current->pgrp; 204 | } 205 | 206 | int sys_setsid(void) 207 | { 208 | if (current->leader && !suser()) 209 | return -EPERM; 210 | current->leader = 1; 211 | current->session = current->pgrp = current->pid; 212 | current->tty = -1; 213 | return current->pgrp; 214 | } 215 | 216 | int sys_uname(struct utsname * name) 217 | { 218 | static struct utsname thisname = { 219 | "linux .0","nodename","release ","version ","machine " 220 | }; 221 | int i; 222 | 223 | if (!name) return -ERROR; 224 | verify_area(name,sizeof *name); 225 | for(i=0;iumask; 233 | 234 | current->umask = mask & 0777; 235 | return (old); 236 | } 237 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/system_call.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/system_call.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * system_call.s contains the system-call low-level handling routines. 9 | * This also contains the timer-interrupt handler, as some of the code is 10 | * the same. The hd- and flopppy-interrupts are also here. 11 | * 12 | * NOTE: This code handles signal-recognition, which happens every time 13 | * after a timer-interrupt and after each system call. Ordinary interrupts 14 | * don't handle signal-recognition, as that would clutter them up totally 15 | * unnecessarily. 16 | * 17 | * Stack layout in 'ret_from_system_call': 18 | * 19 | * 0(%esp) - %eax 20 | * 4(%esp) - %ebx 21 | * 8(%esp) - %ecx 22 | * C(%esp) - %edx 23 | * 10(%esp) - %fs 24 | * 14(%esp) - %es 25 | * 18(%esp) - %ds 26 | * 1C(%esp) - %eip 27 | * 20(%esp) - %cs 28 | * 24(%esp) - %eflags 29 | * 28(%esp) - %oldesp 30 | * 2C(%esp) - %oldss 31 | */ 32 | 33 | SIG_CHLD = 17 34 | 35 | EAX = 0x00 36 | EBX = 0x04 37 | ECX = 0x08 38 | EDX = 0x0C 39 | FS = 0x10 40 | ES = 0x14 41 | DS = 0x18 42 | EIP = 0x1C 43 | CS = 0x20 44 | EFLAGS = 0x24 45 | OLDESP = 0x28 46 | OLDSS = 0x2C 47 | 48 | state = 0 # these are offsets into the task-struct. 49 | counter = 4 50 | priority = 8 51 | signal = 12 52 | sigaction = 16 # MUST be 16 (=len of sigaction) 53 | blocked = (33*16) 54 | 55 | # offsets within sigaction 56 | sa_handler = 0 57 | sa_mask = 4 58 | sa_flags = 8 59 | sa_restorer = 12 60 | 61 | nr_system_calls = 72 62 | 63 | /* 64 | * Ok, I get parallel printer interrupts while using the floppy for some 65 | * strange reason. Urgel. Now I just ignore them. 66 | */ 67 | .globl system_call,sys_fork,timer_interrupt,sys_execve 68 | .globl hd_interrupt,floppy_interrupt,parallel_interrupt 69 | .globl device_not_available, coprocessor_error 70 | 71 | .align 2 72 | bad_sys_call: 73 | movl $-1,%eax 74 | iret 75 | .align 2 76 | reschedule: 77 | pushl $ret_from_sys_call 78 | jmp schedule 79 | .align 2 80 | system_call: 81 | cmpl $nr_system_calls-1,%eax 82 | ja bad_sys_call 83 | push %ds 84 | push %es 85 | push %fs 86 | pushl %edx 87 | pushl %ecx # push %ebx,%ecx,%edx as parameters 88 | pushl %ebx # to the system call 89 | movl $0x10,%edx # set up ds,es to kernel space 90 | mov %dx,%ds 91 | mov %dx,%es 92 | movl $0x17,%edx # fs points to local data space 93 | mov %dx,%fs 94 | call sys_call_table(,%eax,4) 95 | pushl %eax 96 | movl current,%eax 97 | cmpl $0,state(%eax) # state 98 | jne reschedule 99 | cmpl $0,counter(%eax) # counter 100 | je reschedule 101 | ret_from_sys_call: 102 | movl current,%eax # task[0] cannot have signals 103 | cmpl task,%eax 104 | je 3f 105 | cmpw $0x0f,CS(%esp) # was old code segment supervisor ? 106 | jne 3f 107 | cmpw $0x17,OLDSS(%esp) # was stack segment = 0x17 ? 108 | jne 3f 109 | movl signal(%eax),%ebx 110 | movl blocked(%eax),%ecx 111 | notl %ecx 112 | andl %ebx,%ecx 113 | bsfl %ecx,%ecx 114 | je 3f 115 | btrl %ecx,%ebx 116 | movl %ebx,signal(%eax) 117 | incl %ecx 118 | pushl %ecx 119 | call do_signal 120 | popl %eax 121 | 3: popl %eax 122 | popl %ebx 123 | popl %ecx 124 | popl %edx 125 | pop %fs 126 | pop %es 127 | pop %ds 128 | iret 129 | 130 | .align 2 131 | coprocessor_error: 132 | push %ds 133 | push %es 134 | push %fs 135 | pushl %edx 136 | pushl %ecx 137 | pushl %ebx 138 | pushl %eax 139 | movl $0x10,%eax 140 | mov %ax,%ds 141 | mov %ax,%es 142 | movl $0x17,%eax 143 | mov %ax,%fs 144 | pushl $ret_from_sys_call 145 | jmp math_error 146 | 147 | .align 2 148 | device_not_available: 149 | push %ds 150 | push %es 151 | push %fs 152 | pushl %edx 153 | pushl %ecx 154 | pushl %ebx 155 | pushl %eax 156 | movl $0x10,%eax 157 | mov %ax,%ds 158 | mov %ax,%es 159 | movl $0x17,%eax 160 | mov %ax,%fs 161 | pushl $ret_from_sys_call 162 | clts # clear TS so that we can use math 163 | movl %cr0,%eax 164 | testl $0x4,%eax # EM (math emulation bit) 165 | je math_state_restore 166 | pushl %ebp 167 | pushl %esi 168 | pushl %edi 169 | call math_emulate 170 | popl %edi 171 | popl %esi 172 | popl %ebp 173 | ret 174 | 175 | .align 2 176 | timer_interrupt: 177 | push %ds # save ds,es and put kernel data space 178 | push %es # into them. %fs is used by _system_call 179 | push %fs 180 | pushl %edx # we save %eax,%ecx,%edx as gcc doesn't 181 | pushl %ecx # save those across function calls. %ebx 182 | pushl %ebx # is saved as we use that in ret_sys_call 183 | pushl %eax 184 | movl $0x10,%eax 185 | mov %ax,%ds 186 | mov %ax,%es 187 | movl $0x17,%eax 188 | mov %ax,%fs 189 | incl jiffies 190 | movb $0x20,%al # EOI to interrupt controller #1 191 | outb %al,$0x20 192 | movl CS(%esp),%eax 193 | andl $3,%eax # %eax is CPL (0 or 3, 0=supervisor) 194 | pushl %eax 195 | call do_timer # 'do_timer(long CPL)' does everything from 196 | addl $4,%esp # task switching to accounting ... 197 | jmp ret_from_sys_call 198 | 199 | .align 2 200 | sys_execve: 201 | lea EIP(%esp),%eax 202 | pushl %eax 203 | call do_execve 204 | addl $4,%esp 205 | ret 206 | 207 | .align 2 208 | sys_fork: 209 | call find_empty_process 210 | testl %eax,%eax 211 | js 1f 212 | push %gs 213 | pushl %esi 214 | pushl %edi 215 | pushl %ebp 216 | pushl %eax 217 | call copy_process 218 | addl $20,%esp 219 | 1: ret 220 | 221 | hd_interrupt: 222 | pushl %eax 223 | pushl %ecx 224 | pushl %edx 225 | push %ds 226 | push %es 227 | push %fs 228 | movl $0x10,%eax 229 | mov %ax,%ds 230 | mov %ax,%es 231 | movl $0x17,%eax 232 | mov %ax,%fs 233 | movb $0x20,%al 234 | outb %al,$0xA0 # EOI to interrupt controller #1 235 | jmp 1f # give port chance to breathe 236 | 1: jmp 1f 237 | 1: xorl %edx,%edx 238 | xchgl do_hd,%edx 239 | testl %edx,%edx 240 | jne 1f 241 | movl $unexpected_hd_interrupt,%edx 242 | 1: outb %al,$0x20 243 | call *%edx # "interesting" way of handling intr. 244 | pop %fs 245 | pop %es 246 | pop %ds 247 | popl %edx 248 | popl %ecx 249 | popl %eax 250 | iret 251 | 252 | floppy_interrupt: 253 | pushl %eax 254 | pushl %ecx 255 | pushl %edx 256 | push %ds 257 | push %es 258 | push %fs 259 | movl $0x10,%eax 260 | mov %ax,%ds 261 | mov %ax,%es 262 | movl $0x17,%eax 263 | mov %ax,%fs 264 | movb $0x20,%al 265 | outb %al,$0x20 # EOI to interrupt controller #1 266 | xorl %eax,%eax 267 | xchgl do_floppy,%eax 268 | testl %eax,%eax 269 | jne 1f 270 | movl $unexpected_floppy_interrupt,%eax 271 | 1: call *%eax # "interesting" way of handling intr. 272 | pop %fs 273 | pop %es 274 | pop %ds 275 | popl %edx 276 | popl %ecx 277 | popl %eax 278 | iret 279 | 280 | parallel_interrupt: 281 | pushl %eax 282 | movb $0x20,%al 283 | outb %al,$0x20 284 | popl %eax 285 | iret 286 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/traps.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/traps.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * 'Traps.c' handles hardware traps and faults after we have saved some 9 | * state in 'asm.s'. Currently mostly a debugging-aid, will be extended 10 | * to mainly kill the offending process (probably by giving it a signal, 11 | * but possibly by killing it outright if necessary). 12 | */ 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define get_seg_byte(seg,addr) ({ \ 23 | register char __res; \ 24 | __asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \ 25 | :"=a" (__res):"0" (seg),"m" (*(addr))); \ 26 | __res;}) 27 | 28 | #define get_seg_long(seg,addr) ({ \ 29 | register unsigned long __res; \ 30 | __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \ 31 | :"=a" (__res):"0" (seg),"m" (*(addr))); \ 32 | __res;}) 33 | 34 | #define _fs() ({ \ 35 | register unsigned short __res; \ 36 | __asm__("mov %%fs,%%ax":"=a" (__res):); \ 37 | __res;}) 38 | 39 | int do_exit(long code); 40 | 41 | void page_exception(void); 42 | 43 | void divide_error(void); 44 | void debug(void); 45 | void nmi(void); 46 | void int3(void); 47 | void overflow(void); 48 | void bounds(void); 49 | void invalid_op(void); 50 | void device_not_available(void); 51 | void double_fault(void); 52 | void coprocessor_segment_overrun(void); 53 | void invalid_TSS(void); 54 | void segment_not_present(void); 55 | void stack_segment(void); 56 | void general_protection(void); 57 | void page_fault(void); 58 | void coprocessor_error(void); 59 | void reserved(void); 60 | void parallel_interrupt(void); 61 | void irq13(void); 62 | 63 | static void die(char * str,long esp_ptr,long nr) 64 | { 65 | long * esp = (long *) esp_ptr; 66 | int i; 67 | 68 | printk("%s: %04x\n\r",str,nr&0xffff); 69 | printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n", 70 | esp[1],esp[0],esp[2],esp[4],esp[3]); 71 | printk("fs: %04x\n",_fs()); 72 | printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17)); 73 | if (esp[4] == 0x17) { 74 | printk("Stack: "); 75 | for (i=0;i<4;i++) 76 | printk("%p ",get_seg_long(0x17,i+(long *)esp[3])); 77 | printk("\n"); 78 | } 79 | str(i); 80 | printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i); 81 | for(i=0;i<10;i++) 82 | printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0]))); 83 | printk("\n\r"); 84 | do_exit(11); /* play segment exception */ 85 | } 86 | 87 | void do_double_fault(long esp, long error_code) 88 | { 89 | die("double fault",esp,error_code); 90 | } 91 | 92 | void do_general_protection(long esp, long error_code) 93 | { 94 | die("general protection",esp,error_code); 95 | } 96 | 97 | void do_divide_error(long esp, long error_code) 98 | { 99 | die("divide error",esp,error_code); 100 | } 101 | 102 | void do_int3(long * esp, long error_code, 103 | long fs,long es,long ds, 104 | long ebp,long esi,long edi, 105 | long edx,long ecx,long ebx,long eax) 106 | { 107 | int tr; 108 | 109 | __asm__("str %%ax":"=a" (tr):"0" (0)); 110 | printk("eax\t\tebx\t\tecx\t\tedx\n\r%8x\t%8x\t%8x\t%8x\n\r", 111 | eax,ebx,ecx,edx); 112 | printk("esi\t\tedi\t\tebp\t\tesp\n\r%8x\t%8x\t%8x\t%8x\n\r", 113 | esi,edi,ebp,(long) esp); 114 | printk("\n\rds\tes\tfs\ttr\n\r%4x\t%4x\t%4x\t%4x\n\r", 115 | ds,es,fs,tr); 116 | printk("EIP: %8x CS: %4x EFLAGS: %8x\n\r",esp[0],esp[1],esp[2]); 117 | } 118 | 119 | void do_nmi(long esp, long error_code) 120 | { 121 | die("nmi",esp,error_code); 122 | } 123 | 124 | void do_debug(long esp, long error_code) 125 | { 126 | die("debug",esp,error_code); 127 | } 128 | 129 | void do_overflow(long esp, long error_code) 130 | { 131 | die("overflow",esp,error_code); 132 | } 133 | 134 | void do_bounds(long esp, long error_code) 135 | { 136 | die("bounds",esp,error_code); 137 | } 138 | 139 | void do_invalid_op(long esp, long error_code) 140 | { 141 | die("invalid operand",esp,error_code); 142 | } 143 | 144 | void do_device_not_available(long esp, long error_code) 145 | { 146 | die("device not available",esp,error_code); 147 | } 148 | 149 | void do_coprocessor_segment_overrun(long esp, long error_code) 150 | { 151 | die("coprocessor segment overrun",esp,error_code); 152 | } 153 | 154 | void do_invalid_TSS(long esp,long error_code) 155 | { 156 | die("invalid TSS",esp,error_code); 157 | } 158 | 159 | void do_segment_not_present(long esp,long error_code) 160 | { 161 | die("segment not present",esp,error_code); 162 | } 163 | 164 | void do_stack_segment(long esp,long error_code) 165 | { 166 | die("stack segment",esp,error_code); 167 | } 168 | 169 | void do_coprocessor_error(long esp, long error_code) 170 | { 171 | if (last_task_used_math != current) 172 | return; 173 | die("coprocessor error",esp,error_code); 174 | } 175 | 176 | void do_reserved(long esp, long error_code) 177 | { 178 | die("reserved (15,17-47) error",esp,error_code); 179 | } 180 | 181 | void trap_init(void) 182 | { 183 | int i; 184 | 185 | set_trap_gate(0,÷_error); 186 | set_trap_gate(1,&debug); 187 | set_trap_gate(2,&nmi); 188 | set_system_gate(3,&int3); /* int3-5 can be called from all */ 189 | set_system_gate(4,&overflow); 190 | set_system_gate(5,&bounds); 191 | set_trap_gate(6,&invalid_op); 192 | set_trap_gate(7,&device_not_available); 193 | set_trap_gate(8,&double_fault); 194 | set_trap_gate(9,&coprocessor_segment_overrun); 195 | set_trap_gate(10,&invalid_TSS); 196 | set_trap_gate(11,&segment_not_present); 197 | set_trap_gate(12,&stack_segment); 198 | set_trap_gate(13,&general_protection); 199 | set_trap_gate(14,&page_fault); 200 | set_trap_gate(15,&reserved); 201 | set_trap_gate(16,&coprocessor_error); 202 | for (i=17;i<48;i++) 203 | set_trap_gate(i,&reserved); 204 | set_trap_gate(45,&irq13); 205 | outb_p(inb_p(0x21)&0xfb,0x21); 206 | outb(inb_p(0xA1)&0xdf,0xA1); 207 | set_trap_gate(39,¶llel_interrupt); 208 | } 209 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/kernel/vsprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/vsprintf.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ 8 | /* 9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | /* we use this so that we can do without the ctype library */ 16 | #define is_digit(c) ((c) >= '0' && (c) <= '9') 17 | 18 | static int skip_atoi(const char **s) 19 | { 20 | int i=0; 21 | 22 | while (is_digit(**s)) 23 | i = i*10 + *((*s)++) - '0'; 24 | return i; 25 | } 26 | 27 | #define ZEROPAD 1 /* pad with zero */ 28 | #define SIGN 2 /* unsigned/signed long */ 29 | #define PLUS 4 /* show plus */ 30 | #define SPACE 8 /* space if plus */ 31 | #define LEFT 16 /* left justified */ 32 | #define SPECIAL 32 /* 0x */ 33 | #define SMALL 64 /* use 'abcdef' instead of 'ABCDEF' */ 34 | 35 | #define do_div(n,base) ({ \ 36 | int __res; \ 37 | __asm__("divl %4":"=a" (n),"=d" (__res):"0" (n),"1" (0),"r" (base)); \ 38 | __res; }) 39 | 40 | static char * number(char * str, int num, int base, int size, int precision 41 | ,int type) 42 | { 43 | char c,sign,tmp[36]; 44 | const char *digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 45 | int i; 46 | 47 | if (type&SMALL) digits="0123456789abcdefghijklmnopqrstuvwxyz"; 48 | if (type&LEFT) type &= ~ZEROPAD; 49 | if (base<2 || base>36) 50 | return 0; 51 | c = (type & ZEROPAD) ? '0' : ' ' ; 52 | if (type&SIGN && num<0) { 53 | sign='-'; 54 | num = -num; 55 | } else 56 | sign=(type&PLUS) ? '+' : ((type&SPACE) ? ' ' : 0); 57 | if (sign) size--; 58 | if (type&SPECIAL) { 59 | if (base==16) size -= 2; 60 | else if (base==8) size--; 61 | } 62 | i=0; 63 | if (num==0) 64 | tmp[i++]='0'; 65 | else while (num!=0) 66 | tmp[i++]=digits[do_div(num,base)]; 67 | if (i>precision) precision=i; 68 | size -= precision; 69 | if (!(type&(ZEROPAD+LEFT))) 70 | while(size-->0) 71 | *str++ = ' '; 72 | if (sign) 73 | *str++ = sign; 74 | if (type&SPECIAL) { 75 | if (base==8) 76 | *str++ = '0'; 77 | else if (base==16) { 78 | *str++ = '0'; 79 | *str++ = digits[33]; 80 | } 81 | } 82 | if (!(type&LEFT)) 83 | while(size-->0) 84 | *str++ = c; 85 | while(i0) 88 | *str++ = tmp[i]; 89 | while(size-->0) 90 | *str++ = ' '; 91 | return str; 92 | } 93 | 94 | int vsprintf(char *buf, const char *fmt, va_list args) 95 | { 96 | int len; 97 | int i; 98 | char * str; 99 | char *s; 100 | int *ip; 101 | 102 | int flags; /* flags to number() */ 103 | 104 | int field_width; /* width of output field */ 105 | int precision; /* min. # of digits for integers; max 106 | number of chars for from string */ 107 | int qualifier; /* 'h', 'l', or 'L' for integer fields */ 108 | 109 | for (str=buf ; *fmt ; ++fmt) { 110 | if (*fmt != '%') { 111 | *str++ = *fmt; 112 | continue; 113 | } 114 | 115 | /* process flags */ 116 | flags = 0; 117 | repeat: 118 | ++fmt; /* this also skips first '%' */ 119 | switch (*fmt) { 120 | case '-': flags |= LEFT; goto repeat; 121 | case '+': flags |= PLUS; goto repeat; 122 | case ' ': flags |= SPACE; goto repeat; 123 | case '#': flags |= SPECIAL; goto repeat; 124 | case '0': flags |= ZEROPAD; goto repeat; 125 | } 126 | 127 | /* get field width */ 128 | field_width = -1; 129 | if (is_digit(*fmt)) 130 | field_width = skip_atoi(&fmt); 131 | else if (*fmt == '*') { 132 | /* it's the next argument */ 133 | field_width = va_arg(args, int); 134 | if (field_width < 0) { 135 | field_width = -field_width; 136 | flags |= LEFT; 137 | } 138 | } 139 | 140 | /* get the precision */ 141 | precision = -1; 142 | if (*fmt == '.') { 143 | ++fmt; 144 | if (is_digit(*fmt)) 145 | precision = skip_atoi(&fmt); 146 | else if (*fmt == '*') { 147 | /* it's the next argument */ 148 | precision = va_arg(args, int); 149 | } 150 | if (precision < 0) 151 | precision = 0; 152 | } 153 | 154 | /* get the conversion qualifier */ 155 | qualifier = -1; 156 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { 157 | qualifier = *fmt; 158 | ++fmt; 159 | } 160 | 161 | switch (*fmt) { 162 | case 'c': 163 | if (!(flags & LEFT)) 164 | while (--field_width > 0) 165 | *str++ = ' '; 166 | *str++ = (unsigned char) va_arg(args, int); 167 | while (--field_width > 0) 168 | *str++ = ' '; 169 | break; 170 | 171 | case 's': 172 | s = va_arg(args, char *); 173 | len = strlen(s); 174 | if (precision < 0) 175 | precision = len; 176 | else if (len > precision) 177 | len = precision; 178 | 179 | if (!(flags & LEFT)) 180 | while (len < field_width--) 181 | *str++ = ' '; 182 | for (i = 0; i < len; ++i) 183 | *str++ = *s++; 184 | while (len < field_width--) 185 | *str++ = ' '; 186 | break; 187 | 188 | case 'o': 189 | str = number(str, va_arg(args, unsigned long), 8, 190 | field_width, precision, flags); 191 | break; 192 | 193 | case 'p': 194 | if (field_width == -1) { 195 | field_width = 8; 196 | flags |= ZEROPAD; 197 | } 198 | str = number(str, 199 | (unsigned long) va_arg(args, void *), 16, 200 | field_width, precision, flags); 201 | break; 202 | 203 | case 'x': 204 | flags |= SMALL; 205 | case 'X': 206 | str = number(str, va_arg(args, unsigned long), 16, 207 | field_width, precision, flags); 208 | break; 209 | 210 | case 'd': 211 | case 'i': 212 | flags |= SIGN; 213 | case 'u': 214 | str = number(str, va_arg(args, unsigned long), 10, 215 | field_width, precision, flags); 216 | break; 217 | 218 | case 'n': 219 | ip = va_arg(args, int *); 220 | *ip = (str - buf); 221 | break; 222 | 223 | default: 224 | if (*fmt != '%') 225 | *str++ = '%'; 226 | if (*fmt) 227 | *str++ = *fmt; 228 | else 229 | --fmt; 230 | break; 231 | } 232 | } 233 | *str = '\0'; 234 | return str-buf; 235 | } 236 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for some libs needed in the kernel. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-s -x 13 | CC =gcc -mcpu=i386 14 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../include 16 | CPP =gcc -E -nostdinc -I../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = ctype.o _exit.o open.o close.o errno.o write.o dup.o setsid.o \ 28 | execve.o wait.o string.o malloc.o 29 | 30 | lib.a: $(OBJS) 31 | $(AR) rcs lib.a $(OBJS) 32 | sync 33 | 34 | clean: 35 | rm -f core *.o *.a tmp_make 36 | for i in *.c;do rm -f `basename $$i .c`.s;done 37 | 38 | dep: 39 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 40 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 41 | $(CPP) -M $$i;done) >> tmp_make 42 | cp tmp_make Makefile 43 | 44 | ### Dependencies: 45 | _exit.s _exit.o : _exit.c ../include/unistd.h ../include/sys/stat.h \ 46 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 47 | ../include/utime.h 48 | close.s close.o : close.c ../include/unistd.h ../include/sys/stat.h \ 49 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 50 | ../include/utime.h 51 | ctype.s ctype.o : ctype.c ../include/ctype.h 52 | dup.s dup.o : dup.c ../include/unistd.h ../include/sys/stat.h \ 53 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 54 | ../include/utime.h 55 | errno.s errno.o : errno.c 56 | execve.s execve.o : execve.c ../include/unistd.h ../include/sys/stat.h \ 57 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 58 | ../include/utime.h 59 | malloc.s malloc.o : malloc.c ../include/linux/kernel.h ../include/linux/mm.h \ 60 | ../include/asm/system.h 61 | open.s open.o : open.c ../include/unistd.h ../include/sys/stat.h \ 62 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 63 | ../include/utime.h ../include/stdarg.h 64 | setsid.s setsid.o : setsid.c ../include/unistd.h ../include/sys/stat.h \ 65 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 66 | ../include/utime.h 67 | string.s string.o : string.c ../include/string.h 68 | wait.s wait.o : wait.c ../include/unistd.h ../include/sys/stat.h \ 69 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 70 | ../include/utime.h ../include/sys/wait.h 71 | write.s write.o : write.c ../include/unistd.h ../include/sys/stat.h \ 72 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 73 | ../include/utime.h 74 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/_exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/_exit.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | volatile void _exit(int exit_code) 11 | { 12 | __asm__("int $0x80"::"a" (__NR_exit),"b" (exit_code)); 13 | } 14 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/close.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/close.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall1(int,close,int,fd) 11 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/ctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/ctype.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | char _ctmp; 10 | unsigned char _ctype[] = {0x00, /* EOF */ 11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 12 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 14 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 15 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 16 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 17 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 18 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 19 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 21 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 22 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 23 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 25 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 26 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ 28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ 29 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 160-175 */ 30 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 176-191 */ 31 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 192-207 */ 32 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 208-223 */ 33 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 224-239 */ 34 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* 240-255 */ 35 | 36 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/dup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/dup.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall1(int,dup,int,fd) 11 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/errno.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/errno.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | int errno; 8 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/execve.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/execve.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall3(int,execve,const char *,file,char **,argv,char **,envp) 11 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/open.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/open.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | #include 10 | 11 | int open(const char * filename, int flag, ...) 12 | { 13 | register int res; 14 | va_list arg; 15 | 16 | va_start(arg,flag); 17 | __asm__("int $0x80" 18 | :"=a" (res) 19 | :"0" (__NR_open),"b" (filename),"c" (flag), 20 | "d" (va_arg(arg,int))); 21 | if (res>=0) 22 | return res; 23 | errno = -res; 24 | return -1; 25 | } 26 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/setsid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/setsid.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall0(pid_t,setsid) 11 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/string.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #ifndef __GNUC__ 8 | #error I want gcc! 9 | #endif 10 | 11 | #define extern 12 | #define inline 13 | #define static 14 | #define __LIBRARY__ 15 | #include 16 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/wait.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/wait.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | #include 10 | 11 | _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options) 12 | 13 | pid_t wait(int * wait_stat) 14 | { 15 | return waitpid(-1,wait_stat,0); 16 | } 17 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/lib/write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/write.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall3(int,write,int,fd,const char *,buf,off_t,count) 11 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/mm/Makefile: -------------------------------------------------------------------------------- 1 | CC =gcc -mcpu=i386 -fno-stack-protector 2 | #CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 3 | -finline-functions -nostdinc -I../include 4 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -I../include 5 | AS =as 6 | AR =ar 7 | LD =ld 8 | CPP =gcc -fno-stack-protector -E -nostdinc -I../include 9 | 10 | .c.o: 11 | $(CC) $(CFLAGS) \ 12 | -c -o $*.o $< 13 | .s.o: 14 | $(AS) -o $*.o $< 15 | .c.s: 16 | $(CC) $(CFLAGS) \ 17 | -S -o $*.s $< 18 | 19 | OBJS = memory.o page.o 20 | 21 | all: mm.o 22 | 23 | mm.o: $(OBJS) 24 | $(LD) -r -o mm.o $(OBJS) 25 | 26 | clean: 27 | rm -f core *.o *.a tmp_make 28 | for i in *.c;do rm -f `basename $$i .c`.s;done 29 | 30 | dep: 31 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 32 | (for i in *.c;do $(CPP) -M $$i;done) >> tmp_make 33 | cp tmp_make Makefile 34 | 35 | ### Dependencies: 36 | memory.o: memory.c ../include/signal.h ../include/sys/types.h \ 37 | ../include/asm/system.h ../include/linux/sched.h \ 38 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 39 | ../include/linux/kernel.h 40 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/mm/Makefile-gcc3.x: -------------------------------------------------------------------------------- 1 | CC =gcc -mcpu=i386 2 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 3 | -finline-functions -nostdinc -I../include 4 | #CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -I../include 5 | AS =as 6 | AR =ar 7 | LD =ld 8 | CPP =gcc -E -nostdinc -I../include 9 | 10 | .c.o: 11 | $(CC) $(CFLAGS) \ 12 | -c -o $*.o $< 13 | .s.o: 14 | $(AS) -o $*.o $< 15 | .c.s: 16 | $(CC) $(CFLAGS) \ 17 | -S -o $*.s $< 18 | 19 | OBJS = memory.o page.o 20 | 21 | all: mm.o 22 | 23 | mm.o: $(OBJS) 24 | $(LD) -r -o mm.o $(OBJS) 25 | 26 | clean: 27 | rm -f core *.o *.a tmp_make 28 | for i in *.c;do rm -f `basename $$i .c`.s;done 29 | 30 | dep: 31 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 32 | (for i in *.c;do $(CPP) -M $$i;done) >> tmp_make 33 | cp tmp_make Makefile 34 | 35 | ### Dependencies: 36 | memory.o: memory.c ../include/signal.h ../include/sys/types.h \ 37 | ../include/asm/system.h ../include/linux/sched.h \ 38 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 39 | ../include/linux/kernel.h 40 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/mm/Makefile-gcc4.1: -------------------------------------------------------------------------------- 1 | CC =gcc -mcpu=i386 2 | #CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \ 3 | -finline-functions -nostdinc -I../include 4 | CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -I../include 5 | AS =as 6 | AR =ar 7 | LD =ld 8 | CPP =gcc -E -nostdinc -I../include 9 | 10 | .c.o: 11 | $(CC) $(CFLAGS) \ 12 | -c -o $*.o $< 13 | .s.o: 14 | $(AS) -o $*.o $< 15 | .c.s: 16 | $(CC) $(CFLAGS) \ 17 | -S -o $*.s $< 18 | 19 | OBJS = memory.o page.o 20 | 21 | all: mm.o 22 | 23 | mm.o: $(OBJS) 24 | $(LD) -r -o mm.o $(OBJS) 25 | 26 | clean: 27 | rm -f core *.o *.a tmp_make 28 | for i in *.c;do rm -f `basename $$i .c`.s;done 29 | 30 | dep: 31 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 32 | (for i in *.c;do $(CPP) -M $$i;done) >> tmp_make 33 | cp tmp_make Makefile 34 | 35 | ### Dependencies: 36 | memory.o: memory.c ../include/signal.h ../include/sys/types.h \ 37 | ../include/asm/system.h ../include/linux/sched.h \ 38 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 39 | ../include/linux/kernel.h 40 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/mm/page.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/mm/page.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * page.s contains the low-level page-exception code. 9 | * the real work is done in mm.c 10 | */ 11 | 12 | .globl page_fault 13 | 14 | page_fault: 15 | xchgl %eax,(%esp) 16 | pushl %ecx 17 | pushl %edx 18 | push %ds 19 | push %es 20 | push %fs 21 | movl $0x10,%edx 22 | mov %dx,%ds 23 | mov %dx,%es 24 | mov %dx,%fs 25 | movl %cr2,%edx 26 | pushl %edx 27 | pushl %eax 28 | testl $1,%eax 29 | jne 1f 30 | call do_no_page 31 | jmp 2f 32 | 1: call do_wp_page 33 | 2: addl $8,%esp 34 | pop %fs 35 | pop %es 36 | pop %ds 37 | popl %edx 38 | popl %ecx 39 | popl %eax 40 | iret 41 | -------------------------------------------------------------------------------- /linux-0.11-060618-gcc4/tools/build.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/tools/build.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * This file builds a disk-image from three different files: 9 | * 10 | * - bootsect: max 510 bytes of 8086 machine code, loads the rest 11 | * - setup: max 4 sectors of 8086 machine code, sets up system parm 12 | * - system: 80386 code for actual system 13 | * 14 | * It does some checking that all files are of the correct type, and 15 | * just writes the result to stdout, removing headers and padding to 16 | * the right amount. It also writes some system data to stderr. 17 | */ 18 | 19 | /* 20 | * Changes by tytso to allow root device specification 21 | */ 22 | 23 | #include /* fprintf */ 24 | #include 25 | #include /* contains exit */ 26 | #include /* unistd.h needs this */ 27 | #include 28 | #include /* contains read/write */ 29 | #include 30 | 31 | #define MAJOR(a) (((unsigned)(a))>>8) 32 | #define MINOR(a) ((a)&0xff) 33 | 34 | #define MINIX_HEADER 32 35 | #define GCC_HEADER 1024 36 | 37 | #define SYS_SIZE 0x3000 38 | 39 | #define DEFAULT_MAJOR_ROOT 2 40 | #define DEFAULT_MINOR_ROOT 0x1d 41 | 42 | /* max nr of sectors of setup: don't change unless you also change 43 | * bootsect etc */ 44 | #define SETUP_SECTS 4 45 | 46 | #define STRINGIFY(x) #x 47 | 48 | void die(char * str) 49 | { 50 | fprintf(stderr,"%s\n",str); 51 | exit(1); 52 | } 53 | 54 | void usage(void) 55 | { 56 | die("Usage: build bootsect setup system [rootdev] [> image]"); 57 | } 58 | 59 | int main(int argc, char ** argv) 60 | { 61 | int i,c,id; 62 | char buf[1024]; 63 | char major_root, minor_root; 64 | struct stat sb; 65 | 66 | if ((argc != 4) && (argc != 5)) 67 | usage(); 68 | if (argc == 5) { 69 | if (strcmp(argv[4], "FLOPPY")) { 70 | if (stat(argv[4], &sb)) { 71 | perror(argv[4]); 72 | die("Couldn't stat root device."); 73 | } 74 | major_root = MAJOR(sb.st_rdev); 75 | minor_root = MINOR(sb.st_rdev); 76 | } else { 77 | major_root = 0; 78 | minor_root = 0; 79 | } 80 | } else { 81 | major_root = DEFAULT_MAJOR_ROOT; 82 | minor_root = DEFAULT_MINOR_ROOT; 83 | } 84 | fprintf(stderr, "Root device is (%d, %d)\n", major_root, minor_root); 85 | if ((major_root != 2) && (major_root != 3) && 86 | (major_root != 0)) { 87 | fprintf(stderr, "Illegal root device (major = %d)\n", 88 | major_root); 89 | die("Bad root device --- major #"); 90 | } 91 | for (i=0;i0 ; i+=c ) 138 | if (write(1,buf,c)!=c) 139 | die("Write call failed"); 140 | close (id); 141 | if (i > SETUP_SECTS*512) 142 | die("Setup exceeds " STRINGIFY(SETUP_SECTS) 143 | " sectors - rewrite build/boot/setup"); 144 | fprintf(stderr,"Setup is %d bytes.\n",i); 145 | for (c=0 ; c sizeof(buf)) 150 | c = sizeof(buf); 151 | if (write(1,buf,c) != c) 152 | die("Write call failed"); 153 | i += c; 154 | } 155 | 156 | if ((id=open(argv[3],O_RDONLY,0))<0) 157 | die("Unable to open 'system'"); 158 | // if (read(id,buf,GCC_HEADER) != GCC_HEADER) 159 | // die("Unable to read header of 'system'"); 160 | // if (((long *) buf)[5] != 0) 161 | // die("Non-GCC header of 'system'"); 162 | for (i=0 ; (c=read(id,buf,sizeof buf))>0 ; i+=c ) 163 | if (write(1,buf,c)!=c) 164 | die("Write call failed"); 165 | close(id); 166 | fprintf(stderr,"System is %d bytes.\n",i); 167 | if (i > SYS_SIZE*16) 168 | die("System is too big"); 169 | return(0); 170 | } 171 | --------------------------------------------------------------------------------