summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-31 11:49:07 +0200
committerMiguel <m.i@gmx.at>2018-08-31 11:49:07 +0200
commit47d7e8e4527c663dd1a0c04a4ea5624589464895 (patch)
treed6d5ef82f1089a9ab058b27c427c1463db0fae60
parent4404fa9b3d98646f942e32146722a9d0a68edc13 (diff)
various improvmenets
* added debugging symbols to nasm output * started implementing an unified interrupt interface * moved smp entry point to kernel image!
-rw-r--r--Makefile3
-rw-r--r--Makefile.common6
-rw-r--r--README.md2
-rw-r--r--asm/int.h17
-rw-r--r--asm/int.s126
-rw-r--r--asm/mp.asm (renamed from mp/mp.asm)9
-rw-r--r--asm/multiboot.s4
-rw-r--r--asm/pit.s10
-rw-r--r--kernel/interrupts.c43
-rw-r--r--kernel/kernel.c4
-rw-r--r--kernel/smp.c7
-rw-r--r--linker.ld6
-rw-r--r--userspace/Makefile3
13 files changed, 191 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index 1e6f791..b718f91 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,6 @@ ASFLAGS+=-gstabs
########## verbosity ##################3
V = 0
CC = @echo "Compiling (i686-elf-gcc) $<..."; i686-elf-gcc
-CC = i686-elf-gcc
AS = @echo "Assembling (i686-elf-as) $<..."; i686-elf-as
#CC_1 = $(CCC)
#CC = $(CC_$(V))
@@ -173,7 +172,7 @@ stop-qemu:
############ cleanup ############
clean: $(CLEANDIRS)
- @echo "Cleaning..."; rm -f *.bin $(FOOLOS) $(FOOLOS_ISO) $(FOOLOS_VDI) $(KERNEL_ENTRY) $(ASM_MULTIBOOT_OBJ) $(KERNEL_IMG) $(ASM_OBJECTS) $(OBJECTS) $(IMG_FILLUP) $(BIN_MBR) $(BIN_MP) $(BIN_STAGE2) $(DEPS) bochs.out bochs.log ne2k-tx.log ne2k-txdump.txt tags mp/mp.bin grubiso/boot/foolos.bin grubiso/boot/ext2.img
+ @echo "Cleaning..."; rm -f *.bin $(FOOLOS) $(FOOLOS_ISO) $(FOOLOS_VDI) $(KERNEL_ENTRY) $(ASM_MULTIBOOT_OBJ) $(KERNEL_IMG) $(ASM_OBJECTS) $(OBJECTS) $(IMG_FILLUP) $(BIN_MBR) $(BIN_MP) $(BIN_STAGE2) $(DEPS) bochs.out bochs.log ne2k-tx.log ne2k-txdump.txt tags grubiso/boot/foolos.bin grubiso/boot/ext2.img
@echo "Cleaning Documentation..."; rm -f ./doc/ -r
tags:
diff --git a/Makefile.common b/Makefile.common
index 89b90e8..2dd538c 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -1,11 +1,7 @@
### explicit rules ###
%.o: %.asm
- @echo "Assembling (nasm) $@..."; nasm -f elf $*.asm -o $@
-
-%.bin: %.asm
- @echo "Assembling (nasm) $@..."; nasm -f bin $*.asm -o $@
-
+ @echo "Assembling (nasm) $@..."; nasm -f elf $*.asm -o $@ -f elf -F dwarf -g
#%.o: %.s
# i686-elf-as $*.s -o $@
diff --git a/README.md b/README.md
index fe383a0..44d1fc4 100644
--- a/README.md
+++ b/README.md
@@ -91,6 +91,8 @@ Fetures are under this line are currently disabled / not developed:
Todos
-----
+* check 16bit stack alignment before all calls from asm
+* put boot code for application processors in kernel image
* Porting (ncurses, gcc, binutils, vim, apache...)
* Support some TTY standard (xterm)
diff --git a/asm/int.h b/asm/int.h
new file mode 100644
index 0000000..4af9eac
--- /dev/null
+++ b/asm/int.h
@@ -0,0 +1,17 @@
+void int0();
+void int1();
+void int2();
+void int3();
+void int4();
+void int5();
+void int6();
+void int7();
+void int8();
+void int9();
+void int10();
+void int11();
+void int12();
+void int13();
+void int14();
+void int15();
+void int128();
diff --git a/asm/int.s b/asm/int.s
new file mode 100644
index 0000000..49efb35
--- /dev/null
+++ b/asm/int.s
@@ -0,0 +1,126 @@
+.global int0
+.global int1
+.global int2
+.global int3
+.global int4
+.global int5
+.global int6
+.global int7
+
+.global int8
+.global int9
+.global int10
+.global int11
+.global int12
+.global int13
+.global int14
+.global int15
+
+.global int128
+
+// nothing to ack
+.macro ack0
+.endm
+
+// ack master
+.macro ack1
+ push %eax // persist
+ mov $0x20,%al
+ out %al,$0x20
+ pop %eax // load original
+.endm
+
+// ack master and servant
+.macro ack2
+ push %eax // persist
+ mov $0x20,%al
+ out %al,$0xa0 // slave
+ out %al,$0x20 // master
+ pop %eax // load original
+.endm
+
+.macro intx ack num func
+
+ \ack
+
+ pusha //Push all standard registers 8 regs x 4bytes/32bit
+ push %ds //Push data segment
+ push %es //etc...
+ push %fs
+ push %gs
+
+ mov %esp,%eax
+
+ and $-16,%esp // padding to align stack on 16byte boundary before CALL
+ push \num
+ push \num
+
+ push \num
+ push %eax // pass in original %esp
+
+ call \func
+
+ mov %eax,%esp // use %esp we got
+
+ pop %gs
+ pop %fs
+ pop %es
+ pop %ds
+ popa
+
+ iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack
+
+.endm
+
+int0: intx ack1 $0 pit_handler
+int1: intx ack1 $1 kb_handler
+int2: intx ack1 $2 interrupt_handler
+int3: intx ack1 $3 interrupt_handler
+int4: intx ack1 $4 interrupt_handler
+int5: intx ack1 $5 interrupt_handler
+int6: intx ack1 $6 interrupt_handler
+int7: intx ack1 $7 interrupt_handler
+
+int8: intx ack2 $8 interrupt_handler
+int9: intx ack2 $9 interrupt_handler
+int10: intx ack2 $10 interrupt_handler
+int11: intx ack2 $11 interrupt_handler
+int12: intx ack2 $12 mouse_handler
+int13: intx ack2 $13 interrupt_handler
+int14: intx ack2 $14 interrupt_handler
+int15: intx ack2 $15 interrupt_handler
+
+int128: intx ack0 $128 interrupt_handler
+
+pit_handler:
+ call pit_interrupt_handler
+ push $0
+ push 8(%esp)
+ push 16(%esp)
+ call interrupt_handler
+ add $12,%esp
+ ret
+
+kb_handler:
+ push %eax
+ mov $0x0,%eax
+ in $0x60,%al
+ pop %eax
+ push $0
+ push 8(%esp)
+ push 16(%esp)
+ call interrupt_handler
+ add $12,%esp
+ ret
+
+mouse_handler:
+ push %eax
+ mov $0x0,%eax
+ in $0x60,%al
+ pop %eax
+ push $0
+ push 8(%esp)
+ push 16(%esp)
+ call interrupt_handler
+ add $12,%esp
+ ret
diff --git a/mp/mp.asm b/asm/mp.asm
index 740a1a0..1c04f3f 100644
--- a/mp/mp.asm
+++ b/asm/mp.asm
@@ -1,10 +1,9 @@
+global smp_go
; master boot record for application processors
-
-[org 0x7000]
+;[org 0x7000]
+smp_go:
[bits 16]
-
-
cli ;switch off interrupts!
lgdt [gdt_descriptor] ;load descriptor table!
@@ -40,6 +39,7 @@ boot_32_pm:
xchg eax, [LLOCK]
cmp eax,1
je $
+ jmp $ ; loop forever here
call [0x8010] ;kernel_ap ;jump into our Kernel!
jmp $ ; should never be reached
@@ -81,4 +81,3 @@ gdt_descriptor:
CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start
-
diff --git a/asm/multiboot.s b/asm/multiboot.s
index c26b647..837aa0b 100644
--- a/asm/multiboot.s
+++ b/asm/multiboot.s
@@ -13,10 +13,10 @@
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
-
+# entry point for application processors at 0x7000
.section .smp
.code16
-jmp .
+call smp_go
# Declare a header as in the Multiboot Standard. We put this into a special
# section so we can force the header to be in the start of the final program.
diff --git a/asm/pit.s b/asm/pit.s
index c25e9a1..34b69ec 100644
--- a/asm/pit.s
+++ b/asm/pit.s
@@ -19,13 +19,14 @@ pit_interrupt_handler:
incl (%eax)
// ACK IRQ
- mov $0x20,%al
- out %al,$0x20
+ //mov $0x20,%al
+ //out %al,$0x20
pop %eax // load original
///////
+ /*
pusha //Push all standard registers
push %ds //Push data segment
push %es //etc...
@@ -45,8 +46,9 @@ pit_interrupt_handler:
pop %ds
popa
- iret
-
+ iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack
+*/
+ ret
pit_init:
// configure ticking 25 times a second
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 51682b4..74377ad 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -1,4 +1,5 @@
#include "kernel/kernel.h"
+#include "asm/int.h"
#include "asm/asm.h"
#include "asm/pit.h"
#include "driver/mouse.h"
@@ -7,6 +8,13 @@
#define INT_MAX 255 // size of our interrupts table
+
+uint32_t interrupt_handler(uint32_t num, uint32_t esp)
+{
+ if(num!=990)klog("int: %d %d",num,esp);
+ return esp;
+}
+
void errlog(uint32_t error_code)
{
klog("error_code: 0x%08X",error_code);
@@ -129,16 +137,16 @@ void interrupts_init(uint16_t sel)
}
// exceptions
- int_install_ir(0, 0b10001110, 0x08,&int_irq0);
- int_install_ir(1, 0b10001110, 0x08,&int_irq1);
- int_install_ir(2, 0b10001110, 0x08,&int_irq2);
- int_install_ir(3, 0b10001110, 0x08,&int_irq3);
- int_install_ir(4, 0b10001110, 0x08,&int_irq4);
- int_install_ir(5, 0b10001110, 0x08,&int_irq5);
- int_install_ir(6, 0b10001110, 0x08,&int_irq6);
- int_install_ir(7, 0b10001110, 0x08,&int_irq7);
- int_install_ir(8, 0b10001110, 0x08,&int_irq8);
- int_install_ir(9, 0b10001110, 0x08,&int_irq9);
+ int_install_ir(0, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(1, 0b10001110, 0x08,&int_irq1);
+ int_install_ir(2, 0b10001110, 0x08,&int_irq2);
+ int_install_ir(3, 0b10001110, 0x08,&int_irq3);
+ int_install_ir(4, 0b10001110, 0x08,&int_irq4);
+ int_install_ir(5, 0b10001110, 0x08,&int_irq5);
+ int_install_ir(6, 0b10001110, 0x08,&int_irq6);
+ int_install_ir(7, 0b10001110, 0x08,&int_irq7);
+ int_install_ir(8, 0b10001110, 0x08,&int_irq8);
+ int_install_ir(9, 0b10001110, 0x08,&int_irq9);
int_install_ir(10, 0b10001110, 0x08,&int_irq10);
int_install_ir(11, 0b10001110, 0x08,&int_irq11);
int_install_ir(12, 0b10001110, 0x08,&int_irq12);
@@ -153,27 +161,22 @@ void interrupts_init(uint16_t sel)
// remember that we shifted all interrupts with the pic by 32
// install PIT interrupt handler (irq 0 => 32)
- int_install_ir(32, 0b10001110, 0x08,&pit_interrupt_handler);
+ int_install_ir(32, 0b10001110, 0x08,&int0);
// install keyboard interrupt handler (irq 1 => 33)
- int_install_ir(33, 0b10001110, 0x08,&int_kb_handler);
+ int_install_ir(33, 0b10001110, 0x08,&int1);
//mouse interrupt handler (irq 12 => 34)
- int_install_ir(44, 0b10001110, 0x08,&int_mouse_handler);
+ int_install_ir(44, 0b10001110, 0x08,&int12);
- //system calls
- int_install_ir(0x80, 0b11101110, 0x08,&int_syscall_handler);
+ //system calls (can be called from ring3 (0b11))
+ int_install_ir(0x80, 0b11101110, 0x08,&int128);
int_install();
-
- // now we can enable interrupts back again
- // x86_sti();
- //x86_cli();
}
void int_install()
{
-
idtd.size=sizeof(struct int_desc)*INT_MAX;
uint32_t addr=(uint32_t)&idt[0];
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 97aef77..9392a1e 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -56,11 +56,11 @@ void kernel_main(uint32_t eax,uint32_t ebx)
fs_mount(info);
// Start the other Processors (before paging because apic addr etc..?)
- //TODO: !!! Check commented out sleep ()!!!
+ //TODO: remap apic !!! Check commented out sleep ()!!!
// https://wiki.osdev.org/Symmetric_Multiprocessing
klog("Symmetric Multi Processing (SMP) start ... ");
smp_log_procdata(&procdata);
- //smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr
+ smp_start_aps(&procdata);
klog("Vritual Memory / Paging init ... ");
pdirectory *dir=vmem_init(kernel_blocks,(uint32_t)info->framebuffer_addr);
diff --git a/kernel/smp.c b/kernel/smp.c
index 4fe0705..e2de6fe 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -86,13 +86,6 @@ void smp_start_aps(smp_processors *pros,char *path)
{
local_apic_addr=pros->local_apic_address;
- //lets copy the binary into mbr
- fs_content(path,0x7000,0x100); // copy 0x100 bytes to 0x7000
-
- // 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=local_apic_addr+FOOLOS_APIC_SPUR_INT;
// *reg=0xffffffff; // all bits 1 and interrupt 255 (is this not set anyway?)
diff --git a/linker.ld b/linker.ld
index 869ae97..1352163 100644
--- a/linker.ld
+++ b/linker.ld
@@ -2,6 +2,12 @@ ENTRY(_start)
SECTIONS
{
+ . = 0x7000;
+ .text BLOCK(4K) : ALIGN(4K)
+ {
+ *(.smp)
+ }
+
. = 1M;
kernel_start = .;
diff --git a/userspace/Makefile b/userspace/Makefile
index a8aa418..74e0943 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -26,7 +26,7 @@ include ../Makefile.common
all: crt0.o ext2.img
-ext2.img: $(PROGS) ../mp/mp.bin
+ext2.img: $(PROGS)
make -C fonts
@echo "----------------------"
@echo "Creating ext2.img ...."
@@ -53,7 +53,6 @@ ext2.img: $(PROGS) ../mp/mp.bin
# cp ~/opt/foolos/usr/bin/ncurses mnt/bin/
# cp ~/opt/foolos/usr/bin/bs mnt/bin/
#
- @cp ../mp/mp.bin mnt/boot/
@mkdir -p mnt/etc
@echo "127.0.0.1 localhost" > mnt/etc/hosts
@sync