diff options
| -rw-r--r-- | asm/asm.h | 1 | ||||
| -rw-r--r-- | fs/ext2.h | 4 | ||||
| -rw-r--r-- | fs/fs.c | 2 | ||||
| -rw-r--r-- | fs/fs.h | 1 | ||||
| -rw-r--r-- | kernel/acpi.h | 2 | ||||
| -rw-r--r-- | kernel/e1000.h | 1 | ||||
| -rw-r--r-- | kernel/interrupts.h | 1 | ||||
| -rw-r--r-- | kernel/kernel.c | 12 | ||||
| -rw-r--r-- | kernel/keyboard.c | 5 | ||||
| -rw-r--r-- | kernel/keyboard.h | 2 | ||||
| -rw-r--r-- | kernel/mem.h | 6 | ||||
| -rw-r--r-- | kernel/mouse.c | 79 | ||||
| -rw-r--r-- | kernel/mp.c | 1 | ||||
| -rw-r--r-- | kernel/mp.h | 2 | ||||
| -rw-r--r-- | kernel/pci.c | 2 | ||||
| -rw-r--r-- | kernel/smp.c | 1 | ||||
| -rw-r--r-- | kernel/smp.h | 5 | ||||
| -rw-r--r-- | kernel/spinlock.c | 1 | ||||
| -rw-r--r-- | kernel/spinlock.h | 3 | ||||
| -rw-r--r-- | kernel/syscalls.c | 2 | ||||
| -rw-r--r-- | kernel/syscalls.h | 6 | ||||
| -rw-r--r-- | kernel/task.c | 1 | ||||
| -rw-r--r-- | kernel/timer.h | 1 | ||||
| -rw-r--r-- | kernel/vesa.c | 84 | ||||
| -rw-r--r-- | kernel/vesa.h | 45 | ||||
| -rw-r--r-- | kernel/vmem.c | 5 | ||||
| -rw-r--r-- | kernel/x86.h | 9 | ||||
| -rw-r--r-- | lib/buffer/ringbuffer.c | 1 | ||||
| -rw-r--r-- | lib/buffer/ringbuffer.h | 5 | ||||
| -rw-r--r-- | lib/logger/log.c | 1 | ||||
| -rw-r--r-- | lib/logger/log.h | 2 | ||||
| -rw-r--r-- | userspace/Makefile | 2 |
32 files changed, 195 insertions, 100 deletions
diff --git a/asm/asm.h b/asm/asm.h new file mode 100644 index 0000000..6be89ca --- /dev/null +++ b/asm/asm.h @@ -0,0 +1 @@ +void pic_setup(); diff --git a/fs/ext2.h b/fs/ext2.h new file mode 100644 index 0000000..e74d55f --- /dev/null +++ b/fs/ext2.h @@ -0,0 +1,4 @@ +#include "lib/int/stdint.h" +int ext2_check(uint8_t *ram); +int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max); +int ext2_read_dir(uint8_t *ram, int inode_nr,fs_dirent *dirs,int max); @@ -1,6 +1,8 @@ // abstraction layer for filesystems #include <lib/int/stdint.h> #include "fs.h" +#include "ext2.h" + // // returns number of entries in the directory specified by name. // fills 0-max into *dirs @@ -15,5 +15,6 @@ typedef struct fs_dirent_struct uint8_t type; char name[256]; }fs_dirent; +int fs_readdir(const char *name,fs_dirent *dirs,int max); #endif diff --git a/kernel/acpi.h b/kernel/acpi.h new file mode 100644 index 0000000..b7c7342 --- /dev/null +++ b/kernel/acpi.h @@ -0,0 +1,2 @@ +#include "smp.h" +bool acpi_find(smp_processors *procdata); diff --git a/kernel/e1000.h b/kernel/e1000.h new file mode 100644 index 0000000..5413fe1 --- /dev/null +++ b/kernel/e1000.h @@ -0,0 +1 @@ +void init_e1000(); diff --git a/kernel/interrupts.h b/kernel/interrupts.h index ce70447..f708210 100644 --- a/kernel/interrupts.h +++ b/kernel/interrupts.h @@ -6,4 +6,5 @@ #define INT_MAX 255 // size of our interrupts table void int_install(); +void int_init(uint16_t sel); #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 7cafc49..45fc68c 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,14 +1,26 @@ #define FOOLOS_MODULE_NAME "kernel" #include "config.h" +#include "asm/asm.h" #include "lib/logger/log.h" #include "lib/int/stdint.h" #include "lib/bool/bool.h" +#include "lib/buffer/ringbuffer.h" #include "smp.h" #include "time.h" +#include "timer.h" +#include "spinlock.h" +#include "syscalls.h" +#include "mem.h" +#include "vesa.h" +#include "interrupts.h" +#include "acpi.h" +#include "mp.h" +#include "keyboard.h" #include "fs/fs.h" +#include "fs/ext2.h" #ifdef FOOLOS_COMPILE_FLOPPY #include "floppy.h" diff --git a/kernel/keyboard.c b/kernel/keyboard.c index 3b0bbb1..0e31e67 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -4,8 +4,9 @@ #include "x86.h" #include "console.h" -#include "../lib/logger/log.h" // logger facilities -#include "../lib/bool/bool.h" +#include "lib/buffer/ringbuffer.h" +#include "lib/logger/log.h" // logger facilities +#include "lib/bool/bool.h" /// keyboard driver //// // http://www.computer-engineering.org/ps2keyboard/scancodes1.html diff --git a/kernel/keyboard.h b/kernel/keyboard.h new file mode 100644 index 0000000..0b3bf28 --- /dev/null +++ b/kernel/keyboard.h @@ -0,0 +1,2 @@ +void keyboard_init(); + diff --git a/kernel/mem.h b/kernel/mem.h new file mode 100644 index 0000000..1624a06 --- /dev/null +++ b/kernel/mem.h @@ -0,0 +1,6 @@ + +#include "lib/int/stdint.h" +void* pmmngr_alloc_block (); +void* pmmngr_alloc_blocks (uint32_t size); +void pmmngr_free_block (void* p); +void mem_init(uint16_t *memmap,uint16_t entries); diff --git a/kernel/mouse.c b/kernel/mouse.c index 610baa8..910f0cf 100644 --- a/kernel/mouse.c +++ b/kernel/mouse.c @@ -19,6 +19,45 @@ static volatile uint8_t mouse_a; uint8_t mouse_read(); +void mouse_wait(uint8_t a_type) //unsigned char +{ + uint32_t _time_out=100000; //unsigned int + if(a_type==0) + { + while(_time_out--) //Data + { + if((x86_inb(0x64) & 1)==1) + { + return; + } + } + return; + } + else + { + while(_time_out--) //Signal + { + if((x86_inb(0x64) & 2)==0) + { + return; + } + } + return; + } +} + +void mouse_write(uint8_t a_write) +{ + //Wait to be able to send a command + mouse_wait(1); + //Tell the mouse we are sending a command + x86_outb(0x64, 0xD4); + //Wait for the final part + mouse_wait(1); + //Finally write + x86_outb(0x60, a_write); +} + int8_t mouse_get_x() { return mouse_x; @@ -97,7 +136,7 @@ void mouse_log() //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d / %d / %02x ",mouse_x, mouse_y,mouse_byte[2]); - PutFont('X', mouse_x,600-mouse_y, 0xffffff); + //PutFont('X', mouse_x,600-mouse_y, 0xffffff); } //Mouse functions @@ -134,41 +173,3 @@ uint8_t mouse_read() return x86_inb(0x60); } -inline void mouse_write(uint8_t a_write) -{ - //Wait to be able to send a command - mouse_wait(1); - //Tell the mouse we are sending a command - x86_outb(0x64, 0xD4); - //Wait for the final part - mouse_wait(1); - //Finally write - x86_outb(0x60, a_write); -} - -inline void mouse_wait(uint8_t a_type) //unsigned char -{ - uint32_t _time_out=100000; //unsigned int - if(a_type==0) - { - while(_time_out--) //Data - { - if((x86_inb(0x64) & 1)==1) - { - return; - } - } - return; - } - else - { - while(_time_out--) //Signal - { - if((x86_inb(0x64) & 2)==0) - { - return; - } - } - return; - } -} diff --git a/kernel/mp.c b/kernel/mp.c index f240597..1f6c2e6 100644 --- a/kernel/mp.c +++ b/kernel/mp.c @@ -3,6 +3,7 @@ #include "x86.h" #include "lib/logger/log.h" // logger facilities #include "lib/bool/bool.h" +#include "lib/string/string.h" #include "smp.h" diff --git a/kernel/mp.h b/kernel/mp.h new file mode 100644 index 0000000..fc7f036 --- /dev/null +++ b/kernel/mp.h @@ -0,0 +1,2 @@ +#include "smp.h" +bool mp_find(smp_processors *procdata); diff --git a/kernel/pci.c b/kernel/pci.c index c8bd95d..e5d9711 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -1,5 +1,6 @@ #include "kernel.h" #include "x86.h" +#include "e1000.h" #include "../lib/logger/log.h" // logger facilities #define FOOLOS_MODULE_NAME "pci" @@ -85,6 +86,7 @@ uint16_t pciCheck(uint8_t bus, uint8_t slot) { // uint16_t irq=pciConfigReadWord(bus,slot,0,0x3C); // uint16_t irq2=pciConfigReadWord(bus,slot,0,0x3E); + // init_e1000(); test_bar(bus,slot,0x10); diff --git a/kernel/smp.c b/kernel/smp.c index 1721382..46767ac 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -3,6 +3,7 @@ #include "lib/logger/log.h" #include "lib/int/stdint.h" #include "smp.h" +#include "x86.h" #define FOOLOS_APIC_SPUR_INT 0x00f0 #define FOOLOS_APIC_INT_COMMAND_LOW 0x0300 diff --git a/kernel/smp.h b/kernel/smp.h index ebf007d..8737ffc 100644 --- a/kernel/smp.h +++ b/kernel/smp.h @@ -1,3 +1,6 @@ +#ifndef SMP_H +#define SMP_H + #define SMP_MAX_PROC 32 typedef struct @@ -13,3 +16,5 @@ typedef struct uint32_t local_apic_id[SMP_MAX_PROC]; // unique for every processor }smp_processors; + +#endif diff --git a/kernel/spinlock.c b/kernel/spinlock.c index c6d0023..33ed178 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c @@ -2,6 +2,7 @@ #include "lib/logger/log.h" #include "lib/int/stdint.h" +#include "x86.h" // https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html diff --git a/kernel/spinlock.h b/kernel/spinlock.h new file mode 100644 index 0000000..4c39dfe --- /dev/null +++ b/kernel/spinlock.h @@ -0,0 +1,3 @@ +void init_spinlocks(); +volatile void lock_spin(int i); +void lock_release(int i); diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 031d419..267c96f 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -1,7 +1,9 @@ #define FOOLOS_MODULE_NAME "syscalls" +#include "lib/buffer/ringbuffer.h" #include "lib/logger/log.h" #include "lib/bool/bool.h" #include "fs/fs.h" +#include "fs/ext2.h" // int syscall_write(int file, char *buf, int len) diff --git a/kernel/syscalls.h b/kernel/syscalls.h new file mode 100644 index 0000000..6569aa6 --- /dev/null +++ b/kernel/syscalls.h @@ -0,0 +1,6 @@ +#include "fs/fs.h" + +int syscall_write(int file, char *buf, int len); +int syscall_read(int file, char *buf, int len); +int syscall_readdir(const char *name,fs_dirent *dirs,int max); +int syscall_execve(char *name, char **argv, char **env); diff --git a/kernel/task.c b/kernel/task.c index c2f3bd5..1e94b26 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -4,6 +4,7 @@ #include "kernel.h" #include "lib/logger/log.h" // logger facilities #include "lib/int/stdint.h" +#include "mem.h" #define FOOLOS_MODULE_NAME "task" int started; diff --git a/kernel/timer.h b/kernel/timer.h new file mode 100644 index 0000000..4859925 --- /dev/null +++ b/kernel/timer.h @@ -0,0 +1 @@ +void timer_init(); diff --git a/kernel/vesa.c b/kernel/vesa.c index 25c92a1..be17623 100644 --- a/kernel/vesa.c +++ b/kernel/vesa.c @@ -2,53 +2,16 @@ #include <stdarg.h> #include "kernel.h" #include "config.h" +#include "mem.h" +#include "vesa.h" #include "lib/logger/log.h" // logger facilities #include "lib/int/stdint.h" +#include "lib/printf/printf.h" #define FOOLOS_MODULE_NAME "vesa" #define FOOLSOS_SHOW_VESAMODES -typedef struct vbeinfo_struct{ - char VbeSignature[4]; // == "VESA" - uint16_t VbeVersion; // == 0x0300 for VBE 3.0 - uint16_t OemStringPtr[2]; // isa vbeFarPtr - uint8_t Capabilities[4]; - uint16_t VideoModePtr[2]; // isa vbeFarPtr - uint16_t TotalMemory; // as # of 64KB blocks -}vbeinfo; - -typedef struct ModeInfoBlock { - uint16_t attributes; - uint8_t winA,winB; - uint16_t granularity; - uint16_t winsize; - uint16_t segmentA, segmentB; - uint16_t realFctPtr[2]; -// VBE_FAR(realFctPtr); - uint16_t pitch; // bytes per scanline - - uint16_t Xres, Yres; - uint8_t Wchar, Ychar, planes, bpp, banks; - uint8_t memory_model, bank_size, image_pages; - uint8_t reserved0; - - uint8_t red_mask, red_position; - uint8_t green_mask, green_position; - uint8_t blue_mask, blue_position; - uint8_t rsv_mask, rsv_position; - uint8_t directcolor_attributes; - - volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;) - uint32_t reserved1; - uint16_t reserved2; -}vbemodeinfo; - -typedef struct foolfont_struct -{ - uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit - -}foolfont; static foolfont *deffont; static vbemodeinfo *VbeModeInfoBlock; @@ -62,6 +25,28 @@ static int console_cols; static uint8_t* buffer; static uint8_t* physbase; +void PutConsoleNL(); +void PutPixel(int x,int y, int color); + +void vesa_switch_buffers() +{ + for(int i=0;i<800*600*2;i++)physbase[i]=buffer[i]; + +} + +void vesa_put_rect(int x, int y, int w , int h, int color) +{ + for(int i=x;i<x+w;i++) + for(int j=y;j<y+h;j++) + PutPixel(i,j,color); +} + +void vesa_clear_screen() +{ + vesa_put_rect(0,0,VbeModeInfoBlock->Xres, VbeModeInfoBlock->Yres, 0xffffff); +} + + void vesa_set_physbase(uint32_t addr) { VbeModeInfoBlock->physbase=addr; @@ -94,6 +79,7 @@ uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) mode->Xres, mode->Yres, mode->banks, mode->attributes); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bpp: %d / physbase: 0x%x", mode->bpp,mode->physbase); +/* // vesa modes // todo: take segment from vbeinfo! #ifdef FOOLSOS_SHOW_VESAMODES @@ -106,6 +92,7 @@ uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) modeptr++; } #endif +*/ return VbeModeInfoBlock->physbase; @@ -239,22 +226,5 @@ void vesa_init_doublebuff() VbeModeInfoBlock->physbase=buffer; } -void vesa_switch_buffers() -{ - for(int i=0;i<800*600*2;i++)physbase[i]=buffer[i]; - -} - -void vesa_clear_screen() -{ - vesa_put_rect(0,0,VbeModeInfoBlock->Xres, VbeModeInfoBlock->Yres, 0xffffff); -} - -void vesa_put_rect(int x, int y, int w , int h, int color) -{ - for(int i=x;i<x+w;i++) - for(int j=y;j<y+h;j++) - PutPixel(i,j,color); -} diff --git a/kernel/vesa.h b/kernel/vesa.h new file mode 100644 index 0000000..89cb680 --- /dev/null +++ b/kernel/vesa.h @@ -0,0 +1,45 @@ +#include "lib/int/stdint.h" + +typedef struct foolfont_struct +{ + uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit + +}foolfont; + +typedef struct vbeinfo_struct{ + char VbeSignature[4]; // == "VESA" + uint16_t VbeVersion; // == 0x0300 for VBE 3.0 + uint16_t OemStringPtr[2]; // isa vbeFarPtr + uint8_t Capabilities[4]; + uint16_t VideoModePtr[2]; // isa vbeFarPtr + uint16_t TotalMemory; // as # of 64KB blocks +}vbeinfo; + + +typedef struct ModeInfoBlock { + uint16_t attributes; + uint8_t winA,winB; + uint16_t granularity; + uint16_t winsize; + uint16_t segmentA, segmentB; + uint16_t realFctPtr[2]; +// VBE_FAR(realFctPtr); + uint16_t pitch; // bytes per scanline + + uint16_t Xres, Yres; + uint8_t Wchar, Ychar, planes, bpp, banks; + uint8_t memory_model, bank_size, image_pages; + uint8_t reserved0; + + uint8_t red_mask, red_position; + uint8_t green_mask, green_position; + uint8_t blue_mask, blue_position; + uint8_t rsv_mask, rsv_position; + uint8_t directcolor_attributes; + + volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;) + uint32_t reserved1; + uint16_t reserved2; +}vbemodeinfo; + +uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont); diff --git a/kernel/vmem.c b/kernel/vmem.c index de96bb5..e700da3 100644 --- a/kernel/vmem.c +++ b/kernel/vmem.c @@ -2,7 +2,8 @@ #include "kernel.h" #include "x86.h" -#include "../lib/logger/log.h" // logger facilities +#include "mem.h" +#include "lib/logger/log.h" // logger facilities #define FOOLOS_MODULE_NAME "vmem" @@ -278,7 +279,7 @@ void vmem_init(uint32_t vesa_physbase) x86_paging_enable(); - vesa_set_physbase(vesa_mapped); + //vesa_set_physbase(vesa_mapped); show_cr(); diff --git a/kernel/x86.h b/kernel/x86.h index 6942816..9d1ba93 100644 --- a/kernel/x86.h +++ b/kernel/x86.h @@ -9,6 +9,8 @@ #define X86_IRQ_BEGIN asm("\ncli\npusha"); #define X86_IRQ_END asm("mov $0x20, %al\nout %al, $0x20\nmov $0x20, %al\noutb %al,$0xa0\npopa\nleave\nsti\niret"); +void sleep(int i); // TODO : Real sleep! + void x86_outb(int port, uint8_t data); uint8_t x86_inb(int port); void x86_outw(int port, uint16_t data); @@ -18,5 +20,12 @@ uint32_t x86_inl(int port); void x86_set_pdbr(uint32_t addr); void x86_paging_enable(); void x86_flush_tlb(uint32_t addr); +void x86_int_enable(); +uint32_t x86_get_cr0(); +uint32_t x86_get_cr1(); +uint32_t x86_get_cr2(); +uint32_t x86_get_cr3(); +uint32_t x86_get_cr4(); +uint8_t x86_xchg(uint8_t *addr, uint8_t val); #endif diff --git a/lib/buffer/ringbuffer.c b/lib/buffer/ringbuffer.c index cdb5fed..9e3adaf 100644 --- a/lib/buffer/ringbuffer.c +++ b/lib/buffer/ringbuffer.c @@ -5,6 +5,7 @@ #define FOOLOS_MODULE_NAME "ringbuffer" #include "lib/bool/bool.h" #include "lib/logger/log.h" +#include "kernel/spinlock.h" static volatile int front; static volatile int back; diff --git a/lib/buffer/ringbuffer.h b/lib/buffer/ringbuffer.h new file mode 100644 index 0000000..2bb6528 --- /dev/null +++ b/lib/buffer/ringbuffer.h @@ -0,0 +1,5 @@ +#include "lib/bool/bool.h" + +void ringbuffer_init(); +bool ringbuffer_put(char c); +bool ringbuffer_get(char *c); diff --git a/lib/logger/log.c b/lib/logger/log.c index 391fbcf..7bc1d82 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -4,6 +4,7 @@ #include <stdarg.h> #include "log.h" +#include "lib/printf/printf.h" #include "kernel/config.h" #include "lib/int/stdint.h" #include "kernel/time.h" diff --git a/lib/logger/log.h b/lib/logger/log.h index b00f462..1159d94 100644 --- a/lib/logger/log.h +++ b/lib/logger/log.h @@ -7,5 +7,7 @@ void log(char *module_name, int prio, char *format_string, ...); void panic(char *module_name, char *format_string); +void log_init(); +void log_log(); #endif diff --git a/userspace/Makefile b/userspace/Makefile index c6bfb3f..d54bfa8 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -4,6 +4,8 @@ CC=i686-elf-gcc LD=i686-elf-ld CFLAGS=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include +CFLAGS+=--no-builtin-malloc +CFLAGS+=--no-builtin-free LDFLAGS=-L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/newlib/ \ -L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/libgloss/libnosys/ \ -lnosys |
