diff --git a/include/linux/config.h b/include/linux/config.h new file mode 100644 index 0000000000000000000000000000000000000000..dae1a6754f0b73d8cfb9e52ef550bb0d058e5419 --- /dev/null +++ b/include/linux/config.h @@ -0,0 +1,17 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#define UTS_SYSNAME "Linux" +#define UTS_NODENAME "(none)" +#define UTS_RELEASE "" +#define UTS_VERSION "0.12" +#define UTS_MACHINE "i386" + +#define DEF_INITSEG 0x9000 +#define DEF_SYSSEG 0x1000 +#define DEF_SETUPSEG 0x9020 +#define DEF_SYSSIZE 0x3000 + +/* HD_TYPE, if you know what hard disk you have. */ + +#endif diff --git a/include/linux/hdreg.h b/include/linux/hdreg.h new file mode 100644 index 0000000000000000000000000000000000000000..213f054a0c22ab8fe44dc0821c03d6d81664da08 --- /dev/null +++ b/include/linux/hdreg.h @@ -0,0 +1,18 @@ +#ifndef _HDREG_H +#define _HDREG_H + +struct partition { + unsigned char boot_ind; + unsigned char head; + unsigned char sector; + unsigned char cyl; + unsigned char sys_ind; + unsigned char end_head; + unsigned char end_sector; + unsigned char end_cyl; + unsigned int start_sect; + unsigned int nr_sects; +}; + +#endif + diff --git a/include/linux/sys.h b/include/linux/sys.h index 69cd49b04b628f851d02e373231aa519124af5f3..111699df946615043257ece07ce9b54b9fba2e02 100644 --- a/include/linux/sys.h +++ b/include/linux/sys.h @@ -1,4 +1,4 @@ -//extern int sys_setup(); +extern int sys_setup(); //extern int sys_exit(); extern int sys_fork(); //extern int sys_read(); @@ -87,7 +87,7 @@ extern int sys_write(); //extern int sys_uselib(); fn_ptr sys_call_table[] = { - 0, /*sys_setup*/ + sys_setup, 0, /*sys_exit*/ sys_fork, 0, /*sys_read,*/ diff --git a/include/unistd.h b/include/unistd.h index 060344121161ff06ee8155e260783722f0c560c5..608c8e11b36d359affb32154386c97af55562b50 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -109,20 +109,30 @@ __asm__ volatile("int $0x80\n\r"\ return -1; \ } +#define _syscall1(type, name, atype, a) \ +type name(atype a) { \ + long __res; \ +__asm__ volatile("int $0x80\n\r"\ + : "=a"(__res) \ + : "a"(__NR_##name), "b"((long)(a))); \ + if (__res >= 0) \ + return (type)__res; \ + errno = -__res; \ + return -1; \ +} + #define _syscall3(type,name,atype,a,btype,b,ctype,c) \ type name(atype a, btype b, ctype c) { \ long __res; \ __asm__ volatile("int $0x80\n\r"\ : "=a"(__res) \ - : "a"(__NR_##name), "b"((long)a), "c"((long)b), "d"((long)c)); \ + : "a"(__NR_##name), "b"((long)(a)), "c"((long)(b)), "d"((long)(c))); \ if (__res >= 0) \ return (type)__res; \ errno = -__res; \ return -1; \ } - - #endif /* __LIBRARY__ */ extern int errno; diff --git a/kernel/Makefile b/kernel/Makefile index f33e5411dd4fafec24764070a77401b29f6c4b03..3e7bd23ed388c7ce0fd760eba0f9fe2a4e9a8c93 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,7 @@ GCC := gcc CCFLAG := -I../include -nostdinc -ffreestanding -Wall -fomit-frame-pointer -fno-pic -fno-stack-protector -c -m32 LDFLAG := -Ttext 0x0 -s --oformat binary -m elf_i386 INCDIR := ../include -OBJS := head.o main.o sys_call.o asm.o sched.o printk.o vsprintf.o traps.o fork.o chr_drv/chr_drv.a ../mm/mm.o ../lib/lib.a ../fs/fs.o +OBJS := head.o main.o sys_call.o asm.o sched.o printk.o vsprintf.o traps.o fork.o chr_drv/chr_drv.a blk_drv/blk_drv.a ../mm/mm.o ../lib/lib.a ../fs/fs.o system: $(OBJS) $(LD) $(LDFLAG) -M -e startup_32 -o $@ $^ > System.map @@ -37,6 +37,9 @@ fork.o : fork.c chr_drv/chr_drv.a: chr_drv/*.c cd chr_drv; make chr_drv.a; cd .. +blk_drv/blk_drv.a: blk_drv/*.c + cd blk_drv; make blk_drv.a; cd .. + ../mm/mm.o : ../mm/*.c cd ../mm; make mm.o; cd ../kernel @@ -51,6 +54,7 @@ clean : rm system rm System.map cd chr_drv; make clean; cd .. + cd blk_drv; make clean; cd .. cd ../mm; make clean; cd ../kernel cd ../lib; make clean; cd ../kernel cd ../fs; make clean; cd ../kernel diff --git a/kernel/blk_drv/Makefile b/kernel/blk_drv/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1d0e958d451bbbfb2becd30b68794b107f68a670 --- /dev/null +++ b/kernel/blk_drv/Makefile @@ -0,0 +1,17 @@ +AR := ar +LD := ld +GCC := gcc +CCFLAG := -m32 -I../../include -nostdinc -ffreestanding -fno-pic -Wall -fomit-frame-pointer -fno-stack-protector -c +OBJS := hd.o + +blk_drv.a : $(OBJS) + $(AR) rcs $@ $^ + sync + +hd.o : hd.c + $(GCC) $(CCFLAG) -o $@ $< + +clean : + rm *.o + rm blk_drv.a + diff --git a/kernel/blk_drv/blk.h b/kernel/blk_drv/blk.h new file mode 100644 index 0000000000000000000000000000000000000000..de09f835d46eb73482262fcac5fb4f5a845fe94a --- /dev/null +++ b/kernel/blk_drv/blk.h @@ -0,0 +1,6 @@ +#ifndef _BLK_H +#define _BLK_H + + + +#endif diff --git a/kernel/blk_drv/hd.c b/kernel/blk_drv/hd.c new file mode 100644 index 0000000000000000000000000000000000000000..c5c19dfb42f5e6160c5f7a3868456527c4ae75bc --- /dev/null +++ b/kernel/blk_drv/hd.c @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "blk.h" + +extern int printf(const char* fmt, ...); + +#define CMOS_READ(addr) ({ \ +outb_p(0x80|addr,0x70); \ +inb_p(0x71); \ +}) + +#define MAX_HD 2 + +struct hd_i_struct { + int head,sect,cyl,wpcom,lzone,ctl; +}; + +#ifdef HD_TYPE +struct hd_i_struct hd_info[] = { HD_TYPE }; +#define NR_HD ((sizeof (hd_info))/(sizeof (struct hd_i_struct))) +#else +struct hd_i_struct hd_info[] = { {0,0,0,0,0,0},{0,0,0,0,0,0} }; +static int NR_HD = 0; +#endif + +static struct hd_struct { + long start_sect; + long nr_sects; +} hd[5*MAX_HD]={{0,0},}; + + +int sys_setup(void * BIOS) { + static int callable = 1; + int i,drive; + unsigned char cmos_disks; + //struct partition *p; + //struct buffer_head * bh; + + if (!callable) + return -1; + + callable = 0; + +#ifndef HD_TYPE + for (drive=0 ; drive<2 ; drive++) { + hd_info[drive].cyl = *(unsigned short *) BIOS; + hd_info[drive].head = *(unsigned char *) (2+BIOS); + hd_info[drive].wpcom = *(unsigned short *) (5+BIOS); + hd_info[drive].ctl = *(unsigned char *) (8+BIOS); + hd_info[drive].lzone = *(unsigned short *) (12+BIOS); + hd_info[drive].sect = *(unsigned char *) (14+BIOS); + BIOS += 16; + } + + if (hd_info[1].cyl) + NR_HD = 2; + else + NR_HD = 1; +#endif + + for (i=0 ; i inline _syscall0(int, fork); +inline _syscall1(int,setup,void *,BIOS) int errno; @@ -19,14 +20,20 @@ static char printbuf[1024]; int printf(const char* fmt, ...); extern int vsprintf(char* buf, const char* fmt, va_list args); +void init(); extern void mem_init(long start, long end); #define EXT_MEM_K (*(unsigned short *)0x90002) +#define DRIVE_INFO (*(struct drive_info *)0x90080) +#define ORIG_ROOT_DEV (*(unsigned short *)0x901FC) +#define ORIG_SWAP_DEV (*(unsigned short *)0x901FA) static long memory_end = 0; static long buffer_memory_end = 0; static long main_memory_start = 0; +struct drive_info { char dummy[32]; } drive_info; + void main(void) { /* @@ -39,6 +46,8 @@ void main(void) //__asm__("int $0x80\n\r"::); + drive_info = DRIVE_INFO; + memory_end = (1<<20) + (EXT_MEM_K<<10); memory_end &= 0xfffff000; if (memory_end > 16*1024*1024) @@ -63,9 +72,8 @@ void main(void) move_to_user_mode(); if (!fork()) { - printf("In second process, user mode!\n"); test_b(); - while(1) {} + init(); } __asm__("movl $0x0, %edi\n\r" @@ -89,3 +97,7 @@ int printf(const char* fmt, ...) { return i; } +void init() { + setup((void *) &drive_info); +} + diff --git a/kernel/sched.c b/kernel/sched.c index e279768f2805ddebf4530c90e68ece225fffab52..9ad225a18d0d8cffb54f8c3b2ce1e5e55ec54cca 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -84,7 +84,8 @@ repeat: if (!*p) printk("Warning: *P = NULL\n\r"); - if (*p = tmp) + *p = tmp; + if (*p) tmp->state = 0; } diff --git a/kernel/sys_call.S b/kernel/sys_call.S index e7ef6ee566466c40228fd860fc8aa69b5160511c..06112db2b86d871ac1dbe70c257ba06e488c91ad 100644 --- a/kernel/sys_call.S +++ b/kernel/sys_call.S @@ -33,7 +33,7 @@ system_call: movl $0x17, %edx movw %dx, %fs - call sys_call_table(, %eax, 4) + call *sys_call_table(, %eax, 4) pushl %eax diff --git a/tools/build.c b/tools/build.c index e321f9f64b88a93c0e413c15d7b065cfb464fa5b..b48ffc2ad0f910f7e5cd8c9af226aa2138487714 100644 --- a/tools/build.c +++ b/tools/build.c @@ -13,7 +13,7 @@ #define SYS_SIZE 0x2000 #define DEFAULT_MAJOR_ROOT 3 -#define DEFAULT_MINOR_ROOT 6 +#define DEFAULT_MINOR_ROOT 2 #define SETUP_SECTS 4