summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--asm/copy_page_physical.asm33
-rw-r--r--asm/read_eip.asm6
-rw-r--r--boot/kernel_entry.asm2
-rw-r--r--kernel/kernel.c17
5 files changed, 59 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 653b9e9..b633722 100644
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,11 @@ mbr.bin: boot/mbr.asm
kernel_entry.o: boot/kernel_entry.asm
nasm -f elf $^ -o $@
+read_eip.o: asm/read_eip.asm
+ nasm -f elf $^ -o $@
+
+copy_page_physical.o: asm/copy_page_physical.asm
+ nasm -f elf $^ -o $@
kernel.o: kernel/kernel.c kernel/console.h
gcc -ffreestanding -std=gnu99 -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
@@ -89,7 +94,7 @@ log.o: lib/logger/log.c
printf.o: lib/printf/printf.c
gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o floppy.o x86.o shell.o mem.o vmem.o pci.o e1000.o vesa.o log.o printf.o
+kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o floppy.o x86.o shell.o mem.o vmem.o pci.o e1000.o vesa.o log.o printf.o read_eip.o copy_page_physical.o
ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0
# dump from vbox
diff --git a/asm/copy_page_physical.asm b/asm/copy_page_physical.asm
new file mode 100644
index 0000000..f8d3af1
--- /dev/null
+++ b/asm/copy_page_physical.asm
@@ -0,0 +1,33 @@
+[bits 32]
+
+global copy_page_physical
+copy_page_physical:
+ push ebx ; According to __cdecl, we must preserve the contents of EBX.
+ pushf ; push EFLAGS, so we can pop it and reenable interrupts
+ ; later, if they were enabled anyway.
+ cli ; Disable interrupts, so we aren't interrupted.
+ ; Load these in BEFORE we disable paging!
+ mov ebx, [esp+12] ; Source address
+ mov ecx, [esp+16] ; Destination address
+
+ mov edx, cr0 ; Get the control register...
+ and edx, 0x7fffffff ; and...
+ mov cr0, edx ; Disable paging.
+
+ mov edx, 1024 ; 1024*4bytes = 4096 bytes to copy
+
+.loop:
+ mov eax, [ebx] ; Get the word at the source address
+ mov [ecx], eax ; Store it at the dest address
+ add ebx, 4 ; Source address += sizeof(word)
+ add ecx, 4 ; Dest address += sizeof(word)
+ dec edx ; One less word to do
+ jnz .loop
+
+ mov edx, cr0 ; Get the control register again
+ or edx, 0x80000000 ; and...
+ mov cr0, edx ; Enable paging.
+
+ popf ; Pop EFLAGS back.
+ pop ebx ; Get the original value of EBX back.
+ ret
diff --git a/asm/read_eip.asm b/asm/read_eip.asm
new file mode 100644
index 0000000..3341943
--- /dev/null
+++ b/asm/read_eip.asm
@@ -0,0 +1,6 @@
+; http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html
+[bits 32]
+global read_eip
+read_eip:
+ pop eax
+ jmp eax
diff --git a/boot/kernel_entry.asm b/boot/kernel_entry.asm
index f1e3b6b..6667fe0 100644
--- a/boot/kernel_entry.asm
+++ b/boot/kernel_entry.asm
@@ -8,4 +8,6 @@
;
[bits 32]
[extern kernel_main]
+
+push esp
call kernel_main ; jumps in the world of C
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 2dd57fd..517c9d5 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,3 +1,7 @@
+//
+// http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html
+//
+
#include "kernel.h" // general kernel config & includes
#include "console.h" // this will allow us to write to screen
#include "x86.h"
@@ -18,6 +22,8 @@ void int_floppy_handler();
////////// KERNEL MAIN///// /////
//
+uint32_t read_eip();
+
// just a test handler for software interrupt 88, todo: remove and
// implement some syscalls!
//
@@ -37,7 +43,7 @@ void int_test_handler()
}
// heart of our operating system.
-void kernel_main()
+void kernel_main(uint32_t initial_stack)
{
//
@@ -61,6 +67,7 @@ void kernel_main()
//
uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x7200);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack);
//
// PIT config (timer)
timer_init();
@@ -136,10 +143,10 @@ void kernel_main()
esp--;
}
*/
-
-
-
- while(1); // never ending loop
+ while(1)
+ {
+
+ }
}