summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--README.md15
-rw-r--r--bochs/bochsdebug (renamed from xxx/bochs/bochsdebug)0
-rw-r--r--bochs/bochsrc (renamed from xxx/bochs/bochsrc)36
-rw-r--r--fs/fs.c6
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/interrupts.c5
-rw-r--r--kernel/kernel.c49
-rw-r--r--kernel/smp.c51
-rw-r--r--kernel/syscalls.c2
-rw-r--r--kernel/task.c4
-rw-r--r--kernel/usermode.c14
-rw-r--r--mp/mp.asm84
-rw-r--r--userspace/Makefile7
-rw-r--r--xxx/boot2/mp.asm36
15 files changed, 194 insertions, 121 deletions
diff --git a/Makefile b/Makefile
index a45417a..2a8beb4 100644
--- a/Makefile
+++ b/Makefile
@@ -156,7 +156,7 @@ $(FOOLOS_VDI): disk.img
# run in our local bochs (we need cirrus support for our vesa mode)
run-bochs: all
- ~/opt/bochs-2.6.6/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug
+ ~/opt/bochs-2.6.8/bin/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug
# run in qemu
run-qemu:
@@ -165,7 +165,7 @@ run-qemu:
run-qemu-debug:
# qemu -enable-kvm -s -S ~/temp/FoolOs/disk.img
# qemu -enable-kvm -s -singlestep disk.img
- qemu -enable-kvm -s -S -kernel foolos.img -smp 4 # -initrd ext2.img
+ qemu -enable-kvm -s -S -kernel foolos.img -smp 4 # -initrd ext2.img
stop:
killall qemu
diff --git a/README.md b/README.md
index eb8cea2..8c77cc8 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
Welcome to FoolOS
=================
+
Disclaimer
----------
@@ -71,6 +72,7 @@ Supported Platforms
FoolOS is tested/developed on the following emulators/machines
* bochs 2.6.6 (compiled with: ./configure --enable-clgd54xx --enable-a20-pin --enable-debugger --enable-disasm --enable-e1000 --with-x --with-x11 --with-term --enable-smp) (add -lpthread to LIBS in the Makefile!)
+* bochs 2.6.8 (compiled with: ./configure --enable-clgd54xx --enable-a20-pin --enable-debugger --enable-disasm --enable-e1000 --with-x --with-x11 --with-term --enable-smp) (add -lpthread to LIBS in the Makefile!)
* qemu 1.1.2
* virtual box 4.1.18
* Acer Aspire 1810TZ (Notebook)
@@ -106,25 +108,28 @@ Fetures are under this line are currently disabled / not developed:
Todos
-----
-* Implement Multiboot Spec. User ELF for kernel itself
-* finish porting ncurses? (Does this require g++ toolchain?)
+* smp
+* porting ncurses? (Does this require g++ toolchain?)
+* Port more software (vim, coreutils, gcc, apache?)
* Support some TTY standard (xterm)
* implement read syscall!
* /dev/console
* /dev/kb
-* Real User space
* E1000 driver (or some other easy network card driver) maybe NS2000 better?
* Networking stack
-* Port more software (vim, coreutils, gcc, apache?)
* Port X? 2d drivers, 3d drivers? hw acceleration.
-* USB driver (for stroage at least)
+* FPU?
Issues
------
+* sbrk()
* ESP collisions!?
+* TSS-ESP0?
+* kbfree()
+* pg_directory alloc
* implement posix(?) getdents instead of our own readdir.
* Turning on some gcc optimizations breaks the kernel. (need debug so go for ELF!)
* Assumed support for VESA mode 0x114 with linear addressing. (let the user select)
diff --git a/xxx/bochs/bochsdebug b/bochs/bochsdebug
index fabafe9..fabafe9 100644
--- a/xxx/bochs/bochsdebug
+++ b/bochs/bochsdebug
diff --git a/xxx/bochs/bochsrc b/bochs/bochsrc
index fc56d19..47a7d3f 100644
--- a/xxx/bochs/bochsrc
+++ b/bochs/bochsrc
@@ -76,7 +76,7 @@ display_library: x, options="gui_debug" # use GTK debugger gui
#romimage: file=/usr/share/bochs/BIOS-bochs-latest
#romimage: file=bios/seabios-0.5.1.bin
#romimage: file=mybios.bin, address=0xfff80000 # 512k at memory top
-romimage: file=/home/miguel/opt/bochs-2.6.6/bios/BIOS-bochs-latest
+#romimage: file=/home/miguel/opt/bochs-2.6.6/bios/BIOS-bochs-latest
#=======================================================================
@@ -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=2, ips=10000000 #, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
+cpu: count=2 #, ips=1000000 #, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
#=======================================================================
# CPUID:
@@ -260,7 +260,7 @@ memory: guest=128, host=1024
#vgaromimage: file=/usr/share/vgabios/vgabios.debug.bin
#vgaromimage: file=/usr/share/vgabios/vgabios.cirrus.bin
#vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest
-vgaromimage: file=/home/miguel/opt/bochs-2.6.6/bios/VGABIOS-lgpl-latest-cirrus
+#vgaromimage: file=/home/miguel/opt/bochs-2.6.6/bios/VGABIOS-lgpl-latest-cirrus
#=======================================================================
# VGA:
@@ -269,7 +269,7 @@ vgaromimage: file=/home/miguel/opt/bochs-2.6.6/bios/VGABIOS-lgpl-latest-cirrus
# values are 'vbe' for Bochs VBE and 'cirrus' for Cirrus SVGA support.
#=======================================================================
#vga: extension=vbe
-vga: extension=cirrus
+#vga: extension=cirrus
#=======================================================================
# FLOPPYA:
@@ -377,7 +377,7 @@ vga: extension=cirrus
# The biosdetect option has currently no effect on the bios
#
# Examples:
- ata0-master: type=disk, mode=flat, path=FoolOS.img #, cylinders=10, heads=4, spt=18
+ ata0-master: type=disk, mode=flat, path=disk.img #, cylinders=10, heads=4, spt=18
# ata0-master: type=disk, mode=flat, path=disk.img
# ata0-slave: type=disk, mode=flat, path=20M.sample, cylinders=615, heads=4, spt=17
# ata1-master: type=disk, mode=flat, path=30M.sample, cylinders=615, heads=6, spt=17
@@ -443,7 +443,7 @@ boot: disk
#
# Default value are sync=none, time0=local
#=======================================================================
-clock: sync=realtime, time0=local
+#clock: sync=realtime, time0=local
#=======================================================================
@@ -468,7 +468,7 @@ clock: sync=realtime, time0=local
# log: /dev/tty
#=======================================================================
#log: /dev/stdout
-log: ./bochs.log
+#log: ./bochs.log
#=======================================================================
# LOGPREFIX:
@@ -508,10 +508,10 @@ log: ./bochs.log
# cause bochs to become unstable. The panic is a "graceful exit," so
# if you disable it you may get a spectacular disaster instead.
#=======================================================================
-panic: action=ask
-error: action=report
-info: action=report
-debug: action=report
+#panic: action=ask
+#error: action=report
+#info: action=report
+#debug: action=report
#debug: action=report
#pass: action=fatal
@@ -525,7 +525,7 @@ debug: action=report
#=======================================================================
#debugger_log: /dev/null
#debugger_log: debugger.out
-debugger_log: -
+#debugger_log: -
#=======================================================================
# COM1, COM2, COM3, COM4:
@@ -641,7 +641,7 @@ debugger_log: -
# Examples:
# keyboard_serial_delay: 200
#=======================================================================
-keyboard_serial_delay: 250
+#keyboard_serial_delay: 250
#=======================================================================
# KEYBOARD_PASTE_DELAY:
@@ -658,7 +658,7 @@ keyboard_serial_delay: 250
# Examples:
# keyboard_paste_delay: 100000
#=======================================================================
-keyboard_paste_delay: 100000
+#keyboard_paste_delay: 100000
#=======================================================================
# MOUSE:
@@ -691,7 +691,7 @@ keyboard_paste_delay: 100000
# mouse: type=serial, enabled=1
# mouse: enabled=0, toggle=ctrl+f10
#=======================================================================
-mouse: enabled=1
+#mouse: enabled=1
#=======================================================================
# private_colormap: Request that the GUI create and use it's own
@@ -704,7 +704,7 @@ mouse: enabled=1
# private_colormap: enabled=1
# private_colormap: enabled=0
#=======================================================================
-private_colormap: enabled=0
+#private_colormap: enabled=0
#=======================================================================
# ne2k: NE2000 compatible ethernet adapter
@@ -958,8 +958,8 @@ private_colormap: enabled=0
#
#
##
-pci: enabled=1, chipset=i440fx, slot1=cirrus
+#pci: enabled=1, chipset=i440fx, slot1=cirrus
#i440fxsupport: enabled=1, slot1=cirrus
-e1000: enabled=1, mac=52:54:00:12:34:56 #, ethmod=slirp, script=slirp.conf
+#e1000: enabled=1, mac=52:54:00:12:34:56 #, ethmod=slirp, script=slirp.conf
diff --git a/fs/fs.c b/fs/fs.c
index 19027d6..bc43e22 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -41,6 +41,12 @@ void fs_mount(multiboot_information *info)
}
}
+void fs_content(char *path, uint32_t dest, uint32_t max_bytes)
+{
+ int inode= ext2_filename_to_inode(root_ext2_ramimage, path);
+ ext2_inode_content(root_ext2_ramimage,inode,dest,max_bytes);
+}
+
uint32_t fs_get_root_ext2_ramimage()
{
return root_ext2_ramimage;
diff --git a/kernel/config.h b/kernel/config.h
index 8329457..74304d8 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -8,7 +8,7 @@
#define FOOLOS_CONFIG_H
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-//#define FOOLOS_LOG_OFF // do not log anything
+#define FOOLOS_LOG_OFF // do not log anything
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define FOOLSOS_SHOW_VESAMODES
#define MEM_PRINT_MEMORYMAP
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index a7e021c..088c94e 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -173,10 +173,10 @@ void int_init(uint16_t sel)
int_install_ir(0x80, 0b11101110, 0x08,&int_syscall_handler);
- int_install();
+ int_install();
// now we can enable interrupts back again
- x86_int_enable();
+ x86_int_enable();
}
@@ -191,3 +191,4 @@ void int_install()
__asm__("lidt %0"::"m" (idtd));
}
+
diff --git a/kernel/kernel.c b/kernel/kernel.c
index e5369f4..df3a573 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -37,7 +37,6 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
console_init();
-
//
// PR
//
@@ -55,6 +54,11 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
gdt_setup();
+ //
+ // Setup Interrupts (code segment: 0x08)
+ //
+ int_init(0x08);
+
//
// Process Multiboot Header
@@ -63,6 +67,16 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
+ // Gather Info about other processors. (APs = application processors)
+ // ACPI or MP
+ //
+ smp_processors procdata;
+
+ if(!acpi_find(&procdata))
+ if(!mp_find(&procdata))
+ panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
+
+ //
// Memory Init
//
// after this is set up we will be able to allocate and deallocate
@@ -71,35 +85,22 @@ void kernel_main(uint32_t eax,uint32_t ebx)
uint32_t kernel_blocks=mem_init(info);
//
- // Gather Info about other processors. (APs = application processors)
- // ACPI or MP
- //
- smp_processors procdata;
+ // Mount Root EXT2 ramimage (needs to be done before other processors started, because of /boot/mp.bin)
+ //
+ fs_mount(info);
- if(!acpi_find(&procdata))
- if(!mp_find(&procdata))
- panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
//
- // Start the other Processors (before paging)
+ // Start the other Processors (before paging because apic addr etc..?)
//
- smp_log_procdata(&procdata);
+ // smp_log_procdata(&procdata);
//TODO: !!! Check commented out sleep ()!!!
- //smp_start_aps(&procdata,0x80000); // starts at 0x80000
- // but it will be copied over mbr
- while(1);
+ smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr
//
// Activate Virtual Memory (paging)
//
pdirectory *dir=vmem_init(kernel_blocks);
-
- //
- // Setup Interrupts (code segment: 0x08)
- //
- int_init(0x08);
-
-
//
// Scan the PCI Bus
//
@@ -107,13 +108,6 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// Its driver will be hopefully implemented one day ;) TODO
//
//pci_init();
-
-
-
- //
- // Mount Root EXT2 ramimage
- //
- fs_mount(info);
//
@@ -122,6 +116,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
task_init(dir);
+
//
// Abvoe should never returon
//
diff --git a/kernel/smp.c b/kernel/smp.c
index 8d122ee..f776c72 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -16,19 +16,22 @@ uint32_t c1,c2,c3;
volatile uint8_t proc;
uint32_t cpu_counter[SMP_MAX_PROC];
+extern
+
void smp_main()
{
- /// TODO
- /////// SYMMETRIC MULTIPROCESSING, APS get caought here, move it away ///
- // catch the APs (Application Processors)
-// if(mp==1)
- {
- uint32_t ebp=pmmngr_alloc_block()+4095;
- asm volatile("mov %0, %%ebp"::"r"(ebp));
- asm volatile("mov %ebp, %esp");
- asm volatile("jmp kernel_ap");
- }
+ // int_install();
+ // x86_int_enable();
+ switch_to_user_mode();
+
+ while(1);
+
+ uint32_t ebp=pmmngr_alloc_block()+4095;
+
+ asm volatile("mov %0, %%ebp"::"r"(ebp));
+ asm volatile("mov %ebp, %esp");
+ asm volatile("jmp kernel_ap");
proc=c1=c2=c3=0;
for(int i=0;i<SMP_MAX_PROC;i++)cpu_counter[i]=0;
@@ -58,22 +61,20 @@ void smp_log_procdata(smp_processors *procdata)
}
+
// this will start all our application processors!
-void smp_start_aps(smp_processors *pros,uint8_t *start_sel)
-{
+void smp_start_aps(smp_processors *pros,char *path)
+{
+ //lets copy the binary into mbr
+ fs_content(path,0x7000,0x100); // copy 0x100 bytes to 0x7000
- //lets copy the code to the bootsector !
-
- uint8_t *dest=0x7000;
- for(int i=0;i<0x100;i++)
- {
- dest[i]=start_sel[i];
+ // tell them where to enter (agreed adress at 0x8010)
+ uint32_t *entry=0x8010;
+ *entry=smp_main;
- }
-
//bsp (boot processor) enables its local apic
uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
- *reg=0xffffffff; // all bits 1 and interrupt 255
+// *reg=0xffffffff; // all bits 1 and interrupt 255
for(int i=0;i<pros->processors;i++)
{
@@ -90,12 +91,20 @@ void smp_start_aps(smp_processors *pros,uint8_t *start_sel)
*reg=(5<<8)|(1<<14); // 101 INIT
// do we really neet this?
+ // TODO!!
// todo: use some real sleep (not implemented yet :( )
//sleep(30);
// start proc 0x7 = 0x7000; etc..
*reg=(6<<8)|(1<<14)|0x7; // 110 SIPI
+
+ //bsp (boot processor) enables its local apic
+ uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
+ // *reg=0xffffffff; // all bits 1 and interrupt 255
+
+
}
}
+
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 9671469..e9ef9d5 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -31,6 +31,7 @@ int syscall_lseek(int file,int ptr,int dir)
// TODO: /dev/console or /dev/tty1 - /dev/ttyN
int syscall_write(int file, char *buf, int len)
{
+ lock_spin(2);
//x86_int_disable();
#ifdef LOG_SYSCALLS
@@ -44,6 +45,7 @@ int syscall_write(int file, char *buf, int len)
{
console_put_char_green(buf[i]);
}
+ lock_release(2);
//x86_int_enable();
return len;
}
diff --git a/kernel/task.c b/kernel/task.c
index 000dc74..54381fa 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -82,8 +82,8 @@ volatile uint32_t my_scheduler(uint32_t oldesp)
// this gets called by our clock interrupt regularly!
volatile uint32_t task_switch_next(uint32_t oldesp)
{
- asm volatile("sti");
+ //syscall_write(1,"\n\n*tick*\n\n",10);
timer_tick();
@@ -161,7 +161,7 @@ volatile void task_init(pdirectory *dir)
task_list[0].esp = 0; // will be set by next task_switch_next() call.
current_task=0;
-
+ while(1);
switch_to_user_mode();
//syscall_execve("/bin/foolshell",argv_init,env_init);
diff --git a/kernel/usermode.c b/kernel/usermode.c
index 76128d1..ff16156 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -55,9 +55,11 @@ void install_tss(int cpu_no){
void switch_to_user_mode()
{
- char text[]="internal";
- write(1,text,10);
- asm_usermode();
+ char text[]="[internal] ";
+
+ //asm_usermode();
+ write(1,text,11);
+
while(1); // will not be reached?
}
@@ -75,11 +77,11 @@ void userfunc()
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"we are usermode!");
}
-
- while(1)
- {
char text[]="syscalling!";
write(1,text,10);
+
+ while(1)
+ {
}
}
diff --git a/mp/mp.asm b/mp/mp.asm
new file mode 100644
index 0000000..740a1a0
--- /dev/null
+++ b/mp/mp.asm
@@ -0,0 +1,84 @@
+; master boot record for application processors
+
+[org 0x7000]
+[bits 16]
+
+
+
+ cli ;switch off interrupts!
+ lgdt [gdt_descriptor] ;load descriptor table!
+
+ ;switch on 32-bit protected mode
+ mov eax, cr0
+ or eax,0x1
+ mov cr0, eax
+
+ jmp 0x8:init_pm
+
+[bits 32]
+
+
+LLOCK: dd 0
+
+init_pm:
+
+ mov ax, 0x10
+ mov ds, ax
+ mov ss, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+
+ mov ebp, 0x8000
+ mov esp, ebp
+
+ call boot_32_pm ;continue booting in 32-bit protected mode
+
+boot_32_pm:
+
+ mov eax, 1 ; semaphore
+ xchg eax, [LLOCK]
+ cmp eax,1
+ je $
+
+ call [0x8010] ;kernel_ap ;jump into our Kernel!
+ jmp $ ; should never be reached
+
+
+gdt_start:
+
+gdt_null: ;null descriptor (2 x 4 bytes)
+ dd 0x0
+ dd 0x0
+
+gdt_code:
+ ; flags:
+ ; present: 1 / privilege: 00 / type: 1
+ ; code: 1 / conforming: 0 / readable: 1 / accessed: 0
+ ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0
+ dw 0xffff ;limit
+ dw 0x0 ;base
+ db 0x0 ;base
+ db 10011010b ;flags
+ db 11001111b ;flags & seg.limit
+ db 0x0 ;base
+
+gdt_data:
+ ; flags:
+ ; code: 0 / expand down: 0 / writable: 1 / accessed: 0
+ dw 0xffff
+ dw 0x0
+ db 0x0
+ db 10010010b
+ db 11001111b
+ db 0x0
+
+gdt_end:
+
+gdt_descriptor:
+ dw gdt_end-gdt_start-1
+ dd gdt_start
+
+CODE_SEG equ gdt_code - gdt_start
+DATA_SEG equ gdt_data - gdt_start
+
diff --git a/userspace/Makefile b/userspace/Makefile
index 8e97ac8..666f210 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,3 +1,4 @@
+
CC=i686-foolos-gcc
CFLAGS=
@@ -14,13 +15,16 @@ LDFLAGS=-lfool
PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat
-ext2.img: $(PROGS)
+include ../Makefile.common
+
+ext2.img: $(PROGS) ../mp/mp.bin
dd if=/dev/zero of=ext2.img bs=512 count=10000
sudo mkfs.ext2 -O none ext2.img -F
mkdir mnt
sudo mount ext2.img mnt
sudo chown miguel mnt
mkdir -p mnt/home/miguel
+ mkdir -p mnt/boot
echo "hello one" > mnt/home/miguel/test1.txt
mkdir -p mnt/bin
cp $^ mnt/bin
@@ -28,6 +32,7 @@ ext2.img: $(PROGS)
# cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin
cp ../font/binfont.bin mnt/
cp ~/temp/fool-os-stuff/ncurses-5.9/progs/tput mnt/bin
+ cp ../mp/mp.bin mnt/boot/
mkdir -p mnt/etc
echo "127.0.0.1 localhost" > mnt/etc/hosts
sync
diff --git a/xxx/boot2/mp.asm b/xxx/boot2/mp.asm
deleted file mode 100644
index 6273226..0000000
--- a/xxx/boot2/mp.asm
+++ /dev/null
@@ -1,36 +0,0 @@
-; other processors will enter here!
-[org 0x7000] ; here the binary will be loaded
-
-[bits 16]
-
- cli ;switch off interrupts!
- lgdt [gdt_descriptor] ;load descriptor table!
-
- ;switch on 32-bit protected mode
- mov eax, cr0
- or eax,0x1
- mov cr0, eax
-
- jmp 0x8:init_pm
-
-[bits 32]
-init_pm:
-
- mov ax, 0x10
- mov ds, ax
- mov ss, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
-
- mov ebp, 0x95000
- mov esp, ebp
-
- call boot_32_pm ;continue booting in 32-bit protected mode
-
-boot_32_pm:
-
-;
- call 0x18000 ;jump into our Kernel!
-
-%include "GDT.asm"