From 28a5480ead2278bf677f245c8c2a9e11fcf513c7 Mon Sep 17 00:00:00 2001 From: AceVest Date: Fri, 27 Jun 2014 23:28:31 +0800 Subject: [PATCH] delete the pci and setup dir --- Makefile | 4 +- drivers/keyboard.c | 1 - include/system.h | 1 + {setup => kernel}/cpuid.c | 0 kernel/i8259.c | 2 - pci/setuppci.c => kernel/pci.c | 2 +- {setup => kernel}/setup.c | 0 kernel/system.c | 150 ++++++++++++++++++++++++++++++- scripts/grub.cfg | 2 +- setup/system.c | 155 --------------------------------- 10 files changed, 151 insertions(+), 166 deletions(-) rename {setup => kernel}/cpuid.c (100%) rename pci/setuppci.c => kernel/pci.c (99%) rename {setup => kernel}/setup.c (100%) delete mode 100644 setup/system.c diff --git a/Makefile b/Makefile index d660621..a698a4d 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ SYSTEMMAP = System.map KERNELBIN = KERNEL.BIN LINKSCRIPT = scripts/link.ld -SRC_DIRS = boot setup mm lib fs kernel drivers pci +SRC_DIRS = boot mm lib fs kernel drivers INC_DIRS = include drivers CFLAGS += ${INC_DIRS:%=-I%} @@ -16,7 +16,7 @@ OBJS := $(patsubst %,%.o,$(SOURCE_FILES)) ${KERNELBIN}: ${OBJS} ld -M -T$(LINKSCRIPT) $(OBJS) -o $@ > $(SYSTEMMAP) - rm setup/setup.c.o + rm kernel/setup.c.o %.S.o: %.S ${HEADER_FILES} ${CC} ${CFLAGS} $< -o $@ diff --git a/drivers/keyboard.c b/drivers/keyboard.c index 745e967..01d465a 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -85,6 +85,5 @@ int sysc_read_kbd() DECLARE_WAIT_QUEUE(wait, current); add_wait_queue(&cnsl_rd_q.wait, &wait); - return 0; } diff --git a/include/system.h b/include/system.h index aa90148..acd7834 100644 --- a/include/system.h +++ b/include/system.h @@ -256,6 +256,7 @@ extern System system; #define INT_VECT_PAGEFAULT 0xE #define INT_VECT_COPROCERR 0x10 #endif + #define INT_VECT_IRQ0 0x20 #define INT_VECT_IRQ8 0x28 diff --git a/setup/cpuid.c b/kernel/cpuid.c similarity index 100% rename from setup/cpuid.c rename to kernel/cpuid.c diff --git a/kernel/i8259.c b/kernel/i8259.c index 133c3a9..29a317f 100644 --- a/kernel/i8259.c +++ b/kernel/i8259.c @@ -24,8 +24,6 @@ void mask_i8259() //mask all of 8259 outb_p(0xFF, PIC_MASTER_IMR); outb_p(0xFF, PIC_SLAVE_IMR); - //outb_p(0x0, PIC_MASTER_IMR); - //outb_p(0x0, PIC_SLAVE_IMR); } void init_i8259() diff --git a/pci/setuppci.c b/kernel/pci.c similarity index 99% rename from pci/setuppci.c rename to kernel/pci.c index da35004..1af8866 100644 --- a/pci/setuppci.c +++ b/kernel/pci.c @@ -1,6 +1,6 @@ /* *-------------------------------------------------------------------------- - * File Name: setuppci.c + * File Name: pci.c * * Description: none * diff --git a/setup/setup.c b/kernel/setup.c similarity index 100% rename from setup/setup.c rename to kernel/setup.c diff --git a/kernel/system.c b/kernel/system.c index 21cf10f..94749a3 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -2,18 +2,160 @@ *-------------------------------------------------------------------------- * File Name: system.c * + * Description: none + * + * * Author: Zhao Yanbai [zhaoyanbai@126.com] - * Sun Jan 24 13:57:46 2010 * - * Description: none + * Version: 1.0 + * Create Date: Wed Mar 4 21:34:47 2009 + * Last Update: Wed Mar 4 21:34:47 2009 * *-------------------------------------------------------------------------- */ - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -int sysc_reboot(int mode) +void setup_gdt() +{ + pDesc pdesc; + //change to new gdt. + sgdt(); + memcpy(gdt, (void *)pa2va(*((unsigned long*)(gdtr+2))), + *((unsigned short *)gdtr)); + *((unsigned short *)gdtr) = NGDT*sizeof(Desc); + *((unsigned long *)(gdtr+2)) = (unsigned long)gdt; + lgdt(); + memcpy(gdt+INDEX_UCODE, gdt+INDEX_KCODE, sizeof(Desc)); + memcpy(gdt+INDEX_UDATA, gdt+INDEX_KDATA, sizeof(Desc)); + pdesc = gdt+INDEX_UCODE; + pdesc->seg.DPL = 3; + pdesc = gdt+INDEX_UDATA; + pdesc->seg.DPL = 3; +} + +void setup_idt() +{ + *((unsigned short *)idtr) = NIDT*sizeof(Gate); + *((unsigned long *)(idtr+2)) = (unsigned long)idt; + lidt(); +} + + + +void setup_gate() +{ int i; + set_sys_int(0x00, TRAP_GATE, PRIVILEGE_KRNL, DivideError); + set_sys_int(0x01, TRAP_GATE, PRIVILEGE_KRNL, Debug); + set_sys_int(0x02, INTR_GATE, PRIVILEGE_KRNL, NMI); + set_sys_int(0x03, TRAP_GATE, PRIVILEGE_USER, BreakPoint); + set_sys_int(0x04, TRAP_GATE, PRIVILEGE_USER, OverFlow); + set_sys_int(0x05, TRAP_GATE, PRIVILEGE_USER, BoundsCheck); + set_sys_int(0x06, TRAP_GATE, PRIVILEGE_KRNL, InvalidOpcode); + set_sys_int(0x07, TRAP_GATE, PRIVILEGE_KRNL, DeviceNotAvailable); + set_sys_int(0x08, TRAP_GATE, PRIVILEGE_KRNL, DoubleFault); + set_sys_int(0x09, TRAP_GATE, PRIVILEGE_KRNL, CoprocSegOverRun); + set_sys_int(0x0A, TRAP_GATE, PRIVILEGE_KRNL, InvalidTss); + set_sys_int(0x0B, TRAP_GATE, PRIVILEGE_KRNL, SegNotPresent); + set_sys_int(0x0C, TRAP_GATE, PRIVILEGE_KRNL, StackFault); + set_sys_int(0x0D, TRAP_GATE, PRIVILEGE_KRNL, GeneralProtection); + set_sys_int(0x0E, TRAP_GATE, PRIVILEGE_KRNL, PageFault); + set_sys_int(0x10, TRAP_GATE, PRIVILEGE_KRNL, CoprocError); + + for(i=0x20; i<256; i++) + set_sys_int(i, INTR_GATE, PRIVILEGE_KRNL, no_irq_handler); + + set_sys_int(0x20, INTR_GATE, PRIVILEGE_KRNL, irq_0x00_handler); + set_sys_int(0x21, INTR_GATE, PRIVILEGE_KRNL, irq_0x01_handler); + set_sys_int(0x22, INTR_GATE, PRIVILEGE_KRNL, irq_0x02_handler); + set_sys_int(0x23, INTR_GATE, PRIVILEGE_KRNL, irq_0x03_handler); + set_sys_int(0x24, INTR_GATE, PRIVILEGE_KRNL, irq_0x04_handler); + set_sys_int(0x25, INTR_GATE, PRIVILEGE_KRNL, irq_0x05_handler); + set_sys_int(0x26, INTR_GATE, PRIVILEGE_KRNL, irq_0x06_handler); + set_sys_int(0x27, INTR_GATE, PRIVILEGE_KRNL, irq_0x07_handler); + set_sys_int(0x28, INTR_GATE, PRIVILEGE_KRNL, irq_0x08_handler); + set_sys_int(0x29, INTR_GATE, PRIVILEGE_KRNL, irq_0x09_handler); + set_sys_int(0x2A, INTR_GATE, PRIVILEGE_KRNL, irq_0x0A_handler); + set_sys_int(0x2B, INTR_GATE, PRIVILEGE_KRNL, irq_0x0B_handler); + set_sys_int(0x2C, INTR_GATE, PRIVILEGE_KRNL, irq_0x0C_handler); + set_sys_int(0x2D, INTR_GATE, PRIVILEGE_KRNL, irq_0x0D_handler); + set_sys_int(0x2E, INTR_GATE, PRIVILEGE_KRNL, irq_0x0E_handler); + set_sys_int(0x2F, INTR_GATE, PRIVILEGE_KRNL, irq_0x0F_handler); +} + +void ide_irq(); +void default_irq_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) +{ + printk("default irq handler %d \n", irq); + ide_irq(); +} + +void setup_irqs() +{ + extern void init_i8259(); + init_i8259(); + + int i; + for(i=0; iesp0 = 0; // delay to init root_task + p->ss0 = SELECTOR_KRNL_DS; + p->ss = SELECTOR_KRNL_DS; + p->gs = SELECTOR_KRNL_DS; + p->fs = SELECTOR_KRNL_DS; + p->es = SELECTOR_KRNL_DS; + p->ds = SELECTOR_KRNL_DS; + p->cs = SELECTOR_KRNL_CS; + p->eflags = 0x1200; + p->iomap_base = sizeof(TSS); + set_tss_gate(INDEX_TSS, (u32)p); + asm("ltr %%ax"::"a"((INDEX_TSS<<3)+3)); +} + +void setup_root_dev() +{ + unsigned char dev; + dev = (unsigned char)(system.boot_device >> 24); + printk("root device: %08x\n", system.root_dev); +} + +int sysc_reboot(int mode) { void do_reboot(); diff --git a/scripts/grub.cfg b/scripts/grub.cfg index 6db5b49..b2e8467 100644 --- a/scripts/grub.cfg +++ b/scripts/grub.cfg @@ -7,6 +7,6 @@ insmod ext2 root=(hd0,msdos1) -menuentry 'Kernel' --class os { +menuentry 'Kernel' --class os { multiboot /boot/Kernel root=(hd0,0) debug=1 } diff --git a/setup/system.c b/setup/system.c deleted file mode 100644 index 6b27976..0000000 --- a/setup/system.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - *-------------------------------------------------------------------------- - * File Name: system.c - * - * Description: none - * - * - * Author: Zhao Yanbai [zhaoyanbai@126.com] - * - * Version: 1.0 - * Create Date: Wed Mar 4 21:34:47 2009 - * Last Update: Wed Mar 4 21:34:47 2009 - * - *-------------------------------------------------------------------------- - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void setup_gdt() -{ - pDesc pdesc; - //change to new gdt. - sgdt(); - memcpy(gdt, (void *)pa2va(*((unsigned long*)(gdtr+2))), - *((unsigned short *)gdtr)); - *((unsigned short *)gdtr) = NGDT*sizeof(Desc); - *((unsigned long *)(gdtr+2)) = (unsigned long)gdt; - lgdt(); - memcpy(gdt+INDEX_UCODE, gdt+INDEX_KCODE, sizeof(Desc)); - memcpy(gdt+INDEX_UDATA, gdt+INDEX_KDATA, sizeof(Desc)); - pdesc = gdt+INDEX_UCODE; - pdesc->seg.DPL = 3; - pdesc = gdt+INDEX_UDATA; - pdesc->seg.DPL = 3; -} - -void setup_idt() -{ - *((unsigned short *)idtr) = NIDT*sizeof(Gate); - *((unsigned long *)(idtr+2)) = (unsigned long)idt; - lidt(); -} - - - -void setup_gate() -{ int i; - set_sys_int(0x00, TRAP_GATE, PRIVILEGE_KRNL, DivideError); - set_sys_int(0x01, TRAP_GATE, PRIVILEGE_KRNL, Debug); - set_sys_int(0x02, INTR_GATE, PRIVILEGE_KRNL, NMI); - set_sys_int(0x03, TRAP_GATE, PRIVILEGE_USER, BreakPoint); - set_sys_int(0x04, TRAP_GATE, PRIVILEGE_USER, OverFlow); - set_sys_int(0x05, TRAP_GATE, PRIVILEGE_USER, BoundsCheck); - set_sys_int(0x06, TRAP_GATE, PRIVILEGE_KRNL, InvalidOpcode); - set_sys_int(0x07, TRAP_GATE, PRIVILEGE_KRNL, DeviceNotAvailable); - set_sys_int(0x08, TRAP_GATE, PRIVILEGE_KRNL, DoubleFault); - set_sys_int(0x09, TRAP_GATE, PRIVILEGE_KRNL, CoprocSegOverRun); - set_sys_int(0x0A, TRAP_GATE, PRIVILEGE_KRNL, InvalidTss); - set_sys_int(0x0B, TRAP_GATE, PRIVILEGE_KRNL, SegNotPresent); - set_sys_int(0x0C, TRAP_GATE, PRIVILEGE_KRNL, StackFault); - set_sys_int(0x0D, TRAP_GATE, PRIVILEGE_KRNL, GeneralProtection); - set_sys_int(0x0E, TRAP_GATE, PRIVILEGE_KRNL, PageFault); - set_sys_int(0x10, TRAP_GATE, PRIVILEGE_KRNL, CoprocError); - - for(i=0x20; i<256; i++) - set_sys_int(i, INTR_GATE, PRIVILEGE_KRNL, no_irq_handler); - - set_sys_int(0x20, INTR_GATE, PRIVILEGE_KRNL, irq_0x00_handler); - set_sys_int(0x21, INTR_GATE, PRIVILEGE_KRNL, irq_0x01_handler); - set_sys_int(0x22, INTR_GATE, PRIVILEGE_KRNL, irq_0x02_handler); - set_sys_int(0x23, INTR_GATE, PRIVILEGE_KRNL, irq_0x03_handler); - set_sys_int(0x24, INTR_GATE, PRIVILEGE_KRNL, irq_0x04_handler); - set_sys_int(0x25, INTR_GATE, PRIVILEGE_KRNL, irq_0x05_handler); - set_sys_int(0x26, INTR_GATE, PRIVILEGE_KRNL, irq_0x06_handler); - set_sys_int(0x27, INTR_GATE, PRIVILEGE_KRNL, irq_0x07_handler); - set_sys_int(0x28, INTR_GATE, PRIVILEGE_KRNL, irq_0x08_handler); - set_sys_int(0x29, INTR_GATE, PRIVILEGE_KRNL, irq_0x09_handler); - set_sys_int(0x2A, INTR_GATE, PRIVILEGE_KRNL, irq_0x0A_handler); - set_sys_int(0x2B, INTR_GATE, PRIVILEGE_KRNL, irq_0x0B_handler); - set_sys_int(0x2C, INTR_GATE, PRIVILEGE_KRNL, irq_0x0C_handler); - set_sys_int(0x2D, INTR_GATE, PRIVILEGE_KRNL, irq_0x0D_handler); - set_sys_int(0x2E, INTR_GATE, PRIVILEGE_KRNL, irq_0x0E_handler); - set_sys_int(0x2F, INTR_GATE, PRIVILEGE_KRNL, irq_0x0F_handler); -} - -void ide_irq(); -void default_irq_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) -{ - printk("default irq handler %d \n", irq); - ide_irq(); -} - -void setup_irqs() -{ - extern void init_i8259(); - init_i8259(); - - int i; - for(i=0; iesp0 = 0; // delay to init root_task - p->ss0 = SELECTOR_KRNL_DS; - p->ss = SELECTOR_KRNL_DS; - p->gs = SELECTOR_KRNL_DS; - p->fs = SELECTOR_KRNL_DS; - p->es = SELECTOR_KRNL_DS; - p->ds = SELECTOR_KRNL_DS; - p->cs = SELECTOR_KRNL_CS; - p->eflags = 0x1200; - p->iomap_base = sizeof(TSS); - set_tss_gate(INDEX_TSS, (u32)p); - asm("ltr %%ax"::"a"((INDEX_TSS<<3)+3)); -} - -void setup_root_dev() -{ - unsigned char dev; - dev = (unsigned char)(system.boot_device >> 24); - printk("root device: %08x\n", system.root_dev); -} -- 2.44.0