summaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-13 16:18:24 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-13 16:18:24 +0200
commit9a60edf72a3112adae4a914134da1adaf472ad5d (patch)
tree64fe18ef416160244ad7dc80875e9f5a47390971 /asm
parent39d0c5ad74f69ef368d6f83e4eac575e76060eb4 (diff)
fixing gdt and interrupts
Diffstat (limited to 'asm')
-rw-r--r--asm/GDT.asm78
-rw-r--r--asm/int_irq.asm36
-rw-r--r--asm/kernel_entry.asm27
-rw-r--r--asm/multiboot.s18
4 files changed, 114 insertions, 45 deletions
diff --git a/asm/GDT.asm b/asm/GDT.asm
new file mode 100644
index 0000000..f271377
--- /dev/null
+++ b/asm/GDT.asm
@@ -0,0 +1,78 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; Global Descriptor Table
+; we have the null descriptor and a code and data block for a start
+;
+; 0x08 code segment
+; 0x10 data segment
+;
+; this file contains pure data
+;
+;
+;
+;
+
+global gdt_descriptor
+
+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
+
+gdt16_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 10001111b ;flags & seg.limit
+ db 0x0 ;base
+
+gdt16_data:
+ ; flags:
+ ; code: 0 / expand down: 0 / writable: 1 / accessed: 0
+ dw 0xffff
+ dw 0x0
+ db 0x0
+ db 10010010b
+ db 10001111b
+ 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
+CODE16_SEG equ gdt16_code - gdt_start
+DATA16_SEG equ gdt16_data - gdt_start
diff --git a/asm/int_irq.asm b/asm/int_irq.asm
index fd57a50..e9864f0 100644
--- a/asm/int_irq.asm
+++ b/asm/int_irq.asm
@@ -43,85 +43,85 @@ global int_irq18
int_irq0:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_0 ;this will never return due to panic!
jmp $
int_irq1:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_1 ;this will never return due to panic!
jmp $
int_irq2:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_2 ;this will never return due to panic!
jmp $
int_irq3:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_3 ;this will never return due to panic!
jmp $
int_irq4:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_4 ;this will never return due to panic!
jmp $
int_irq5:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_5 ;this will never return due to panic!
jmp $
int_irq6:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_6 ;this will never return due to panic!
jmp $
int_irq7:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_7 ;this will never return due to panic!
jmp $
int_irq8:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_8 ;this will never return due to panic!
jmp $
int_irq9:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_9;this will never return due to panic!
jmp $
int_irq10:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_10;this will never return due to panic!
jmp $
int_irq11:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_11;this will never return due to panic!
jmp $
int_irq12:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_12 ;this will never return due to panic!
jmp $
int_irq13:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_13;this will never return due to panic!
jmp $
int_irq14:
@@ -134,23 +134,23 @@ int_irq14:
int_irq15:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_15 ;this will never return due to panic!
jmp $
int_irq16:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_16 ;this will never return due to panic!
jmp $
int_irq17:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_17 ;this will never return due to panic!
jmp $
int_irq18:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_18;this will never return due to panic!
jmp $
diff --git a/asm/kernel_entry.asm b/asm/kernel_entry.asm
deleted file mode 100644
index 71bedd1..0000000
--- a/asm/kernel_entry.asm
+++ /dev/null
@@ -1,27 +0,0 @@
-; DEPRECATED . use multiboot.s instead!
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;
-; this will be compiled to an object file and linked with the kernel
-; to simplify the entrance!
-;
-;
-global kernel_start
-
-[bits 32]
-[extern kernel_main]
-
-kernel_start:
-
-push 0x1
-
-cmp eax,1
-je multiproc
-push 0x0
-multiproc:
-
-push esp
-call kernel_main ; jumps in the world of C
diff --git a/asm/multiboot.s b/asm/multiboot.s
index a497e18..21df7bb 100644
--- a/asm/multiboot.s
+++ b/asm/multiboot.s
@@ -45,6 +45,8 @@ stack_top:
# doesn't make sense to return from this function as the bootloader is gone.
.section .text
.global _start
+.global stack_top
+.global stack_bottom
.type _start, @function
_start:
# Welcome to kernel mode! We now have sufficient code for the bootloader to
@@ -67,6 +69,8 @@ _start:
# a stack. Note that the processor is not fully initialized yet and stuff
# such as floating point instructions are not available yet.
+ lgdt gdt_descriptor #load descriptor table!
+
# To set up a stack, we simply set the esp register to point to the top of
# our stack (as it grows downwards).
movl $stack_top, %esp
@@ -77,6 +81,20 @@ _start:
push %ebx #pass address of the multiboot information data structure
push %eax #pass eax, so kernel can check for magic number
+
+
+ reloadSegments:
+ #Reload CS register containing code selector:
+ jmp $0x08,$reload_CS # 0x08 points at the new code selector
+
+ reload_CS:
+ mov $0x10, %ax
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %fs
+ mov %ax, %gs
+ mov %ax, %ss
+
call kernel_main
# In case the function returns, we'll want to put the computer into an