summaryrefslogtreecommitdiff
path: root/asm
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 /asm
parent4404fa9b3d98646f942e32146722a9d0a68edc13 (diff)
various improvmenets
* added debugging symbols to nasm output * started implementing an unified interrupt interface * moved smp entry point to kernel image!
Diffstat (limited to 'asm')
-rw-r--r--asm/int.h17
-rw-r--r--asm/int.s126
-rw-r--r--asm/mp.asm83
-rw-r--r--asm/multiboot.s4
-rw-r--r--asm/pit.s10
5 files changed, 234 insertions, 6 deletions
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/asm/mp.asm b/asm/mp.asm
new file mode 100644
index 0000000..1c04f3f
--- /dev/null
+++ b/asm/mp.asm
@@ -0,0 +1,83 @@
+global smp_go
+; master boot record for application processors
+;[org 0x7000]
+smp_go:
+[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 $
+ jmp $ ; loop forever here
+
+ 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/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