From e7648669694806b366824c0dc0c8b80c8d167d35 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 3 Sep 2014 23:21:33 +0200 Subject: debugging floppy driver :( --- Makefile | 12 ++++++++---- asm/int_floppy_handler.asm | 16 ++++++++++++++++ bochsrc | 2 +- data/testdata | 3 +++ kernel/config.h | 2 ++ kernel/floppy.c | 6 +----- kernel/interrupts.c | 46 ++++++++++------------------------------------ kernel/kernel.c | 13 +++++++------ kernel/shell.c | 4 ---- 9 files changed, 48 insertions(+), 56 deletions(-) create mode 100644 asm/int_floppy_handler.asm create mode 100644 data/testdata diff --git a/Makefile b/Makefile index 3fdad89..9afd77a 100644 --- a/Makefile +++ b/Makefile @@ -13,14 +13,14 @@ ############ some constants ############ -USB_STICK=/dev/sdf +USB_STICK=/dev/sdf #take care! -#ap bin : MP_IMG_START=26112 #code for the other processors intialllly at 0x6600 -#font data starts here: FONT_DATA_START=26624 #fool font initially at 0x6800 +DATA_START=32768 #0x8000 here we put some "files" later a fs. + #here our kernel will be loaded by the bootloader. KERNEL_START=0x10000 @@ -93,12 +93,16 @@ binfont.bin: data/binfont.src # master boot record, kernel binary and fool-font -FoolOS.img: $(MBR) kernel.bin $(MP_BIN) binfont.img $(FILLUP) +FoolOS.img: $(MBR) kernel.bin $(MP_BIN) binfont.img $(FILLUP) data.img cp $(FILLUP) $@ dd if=$(MBR) of=$@ bs=1 seek=0 conv=notrunc dd if=kernel.bin of=$@ bs=1 seek=512 conv=notrunc dd if=$(MP_BIN) of=$@ bs=1 seek=$(MP_IMG_START) conv=notrunc dd if=binfont.img of=$@ bs=1 seek=$(FONT_DATA_START) conv=notrunc + dd if=data.img of=$@ bs=1 seek=$(DATA_START) conv=notrunc + +data.img: data/testdata + cp $^ $@ binfont.img: binfont.bin diff --git a/asm/int_floppy_handler.asm b/asm/int_floppy_handler.asm new file mode 100644 index 0000000..53fb9e7 --- /dev/null +++ b/asm/int_floppy_handler.asm @@ -0,0 +1,16 @@ +global int_floppy_handler +[extern int_floppy] + + +[bits 32] +int_floppy_handler: + + cli + + call int_floppy + + mov al, 0x20 ;Port number AND command number to Acknowledge IRQ + out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts + + sti + iret ;Interrupt-Return diff --git a/bochsrc b/bochsrc index f6072ce..697ea55 100644 --- a/bochsrc +++ b/bochsrc @@ -131,7 +131,7 @@ romimage: file=/home/miguel/opt/bochs-2.6.6/bios/BIOS-bochs-latest # 2.2.6 2.1Ghz Athlon XP with Linux 2.6/g++ 3.4 12 to 15 Mips # 2.0.1 1.6Ghz Intel P4 with Win2000/g++ 3.3 5 to 7 Mips #======================================================================= -cpu: count=3, ips=10000000 #, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def" +cpu: count=1, ips=10000000 #, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def" #======================================================================= # CPUID: diff --git a/data/testdata b/data/testdata new file mode 100644 index 0000000..ffe498e --- /dev/null +++ b/data/testdata @@ -0,0 +1,3 @@ +This is just some test text +to try loading data from the place where we place it. +Hooray it works! diff --git a/kernel/config.h b/kernel/config.h index 15d2121..7af5c03 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -1,2 +1,4 @@ #define FOOLOS_COMPILE_FLOPPY +#define FOOLOS_TEST_FLOPPY_READ +//#define FOOLOS_TEST_FLOPPY_WRITE diff --git a/kernel/floppy.c b/kernel/floppy.c index 355801c..50bd8d0 100644 --- a/kernel/floppy.c +++ b/kernel/floppy.c @@ -303,12 +303,10 @@ void flpydsk_reset() flpydsk_calibrate ( _CurrentDrive ); } -void int_floppy_handler() +void int_floppy() { - X86_IRQ_BEGIN _FloppyDiskIRQ=1; - X86_IRQ_END } @@ -536,7 +534,6 @@ void floppy_init() flpydsk_reset (); -#ifdef FOOLOS_TEST_FLOPPY log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test read (sector: 0)"); flpydsk_read_sector(0); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"finished reading"); @@ -552,7 +549,6 @@ void floppy_init() log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test write (sector: 100)"); flpydsk_write_sector(100); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"finished writing"); -#endif } diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 599221c..81ad1c9 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -32,9 +32,19 @@ void int_def_handler() { X86_IRQ_BEGIN + panic(FOOLOS_MODULE_NAME,"Unexpected Interrupt occured"); + X86_IRQ_END } +void show_error(uint32_t err) +{ + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"interrupt error code: 0x%08x",err); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"External Event: %x",err&0b001); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Location: %x",err&0b110); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Selector: %x",err&0b1111111111111000); +} + void int_irq0(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Divide by 0"); X86_IRQ_END } void int_irq1(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Single step (debugger)"); X86_IRQ_END } void int_irq2(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Non Maskable Interrupt"); X86_IRQ_END } @@ -49,14 +59,6 @@ void int_irq10(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Invalid TSS"); X86_ void int_irq11(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Segment Not Present"); X86_IRQ_END } void int_irq12(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Stack Segment Overrun"); X86_IRQ_END } -void show_error(uint32_t err) -{ - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"interrupt error code: 0x%08x",err); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"External Event: %x",err&0b001); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Location: %x",err&0b110); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Selector: %x",err&0b1111111111111000); -} - void int_irq13() { X86_IRQ_BEGIN @@ -136,31 +138,3 @@ void int_install() __asm__("lidt %0"::"m" (idtd)); } -/* -//print interrupt table; //TODO! -void int_show() -{ - uint16_t *ptr3=&idt[0]; // TODO! - - scr_put_string("idt located: "); - scr_put_hex(ptr3); - scr_nextline(); - - - // first two bytes as chars - int offset; - for(offset=32;offset<40;offset++) - { - print_hex(offset-32); //ir // install keyboard handler - int_install_ir(33, 0b10001110, 0x08,&int_kb_handler); -q - print_string(" -> "); - print_hex(*(ptr3+offset*4)); //addrLo - print_hex(*(ptr3+1+offset*4)); //sel - print_hex(*(ptr3+2+offset*4)); //zeros & flags - print_hex(*(ptr3+3+offset*4)); //addrHi - print_nextline(); - } -} -*/ - diff --git a/kernel/kernel.c b/kernel/kernel.c index a582563..85c3da1 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -11,7 +11,7 @@ // todo: move somewhere else!? void int_clock_handler(); void int_kb_handler(); -//void int_floppy_handler(); +void int_floppy_handler(); uint32_t read_eip(); uint32_t c1,c2,c3; @@ -53,6 +53,7 @@ void kernel_main(uint32_t initial_stack, int mp) // move the foolfont and aps code before it gets overwritten! uint8_t *source=0x16600; uint8_t *dest=0x80000; + for(int i=0;i<2*512;i++) { dest[i]=source[i]; @@ -133,7 +134,7 @@ void kernel_main(uint32_t initial_stack, int mp) int_install_ir(33, 0b10001110, 0x08,&int_kb_handler); // install floppy interrupt handler (irq 6 => 38) - //int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler); + int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler); // now we can enable interrupts back again x86_int_enable(); @@ -159,13 +160,13 @@ void kernel_main(uint32_t initial_stack, int mp) panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!"); // Start the other Processors (also before paging !) - smp_start_aps(&procdata); + // smp_start_aps(&procdata); ///////////////////// // paging (pass the vesa physbase address for identity mapping) - vmem_init(vesa_physbase); + //vmem_init(vesa_physbase); ////////////////////// @@ -176,13 +177,13 @@ void kernel_main(uint32_t initial_stack, int mp) // Its driver will be hopefully implemented one day ;) // - pci_init(); + //pci_init(); // // Initialize Floppy Disk // - //floppy_init(); + floppy_init(); // diff --git a/kernel/shell.c b/kernel/shell.c index cc529da..b377ce0 100644 --- a/kernel/shell.c +++ b/kernel/shell.c @@ -21,7 +21,6 @@ void shell_init() { pos=0; command[0]=0; - scr_put_string("Command> "); } void shell_put(char x) @@ -89,9 +88,6 @@ void shell_execute() } pos=0; - scr_nextline(); - scr_put_string("Command> "); - } -- cgit v1.2.3