summaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-08 17:08:55 +0200
committerMiguel <m.i@gmx.at>2018-09-08 17:08:55 +0200
commit9fde748acea83d775e367a64858414b674f05b13 (patch)
tree0927b570c07c9ee469817a560b965c094c5d8145 /asm
parentaa4b4c6c1918a51318709761873d1c5e248a831d (diff)
struggling with pic and lapic and smp...
Diffstat (limited to 'asm')
-rw-r--r--asm/asm_int.h1
-rw-r--r--asm/asm_int.s2
-rw-r--r--asm/asm_mp.asm16
-rw-r--r--asm/asm_pic.asm1
-rw-r--r--asm/asm_pit.h3
-rw-r--r--asm/asm_pit.s66
-rw-r--r--asm/asm_start.s2
7 files changed, 74 insertions, 17 deletions
diff --git a/asm/asm_int.h b/asm/asm_int.h
index 25ab885..465b08b 100644
--- a/asm/asm_int.h
+++ b/asm/asm_int.h
@@ -18,6 +18,7 @@ void int15();
void int128(); // syscalls
void int129(); // scheduler
void int200(); // apic timer
+void int170(); // smp scheduler
void int255(); // unhandled
void exc0();
diff --git a/asm/asm_int.s b/asm/asm_int.s
index f7107de..70993b4 100644
--- a/asm/asm_int.s
+++ b/asm/asm_int.s
@@ -19,6 +19,7 @@
.global int128
.global int129
.global int200
+.global int170
.global int255
.global exc0
@@ -159,6 +160,7 @@ int129: intx ack0 $129 interrupt_handler
int255: intx ack0 $255 interrupt_handler
int200: intx ack0 $200 interrupt_handler
+int170: intx ack0 $170 interrupt_handler
exc0: excx $0 exception_handle
exc1: excx $1 exception_handle
diff --git a/asm/asm_mp.asm b/asm/asm_mp.asm
index 5e5259e..165dc97 100644
--- a/asm/asm_mp.asm
+++ b/asm/asm_mp.asm
@@ -1,7 +1,8 @@
global smp_start
-global LLOCK
extern smp_main
global gdt_descriptor
+global asm_smp_unlock
+
; master boot record for application processors
smp_start:
@@ -20,7 +21,12 @@ smp_start:
[bits 32]
-LLOCK: dd 0
+LLOCK: dd 1
+
+asm_smp_unlock:
+ mov eax, 0x0
+ mov [LLOCK], eax
+ ret
init_pm:
@@ -31,7 +37,7 @@ init_pm:
mov fs, ax
mov gs, ax
- mov ebp, 0x7000
+ mov ebp, 0x7000 ;temporary stack
mov esp, ebp
call boot_32_pm ;continue booting in 32-bit protected mode
@@ -46,11 +52,11 @@ boot_32_pm:
mov ebp, 0x7000
mov esp, ebp
- call smp_main
+ and esp,-16 ; padding to align stack on 16byte boundary before CALL
+ call smp_main
jmp $ ; should never be reached
-
gdt_start:
gdt_null: ;null descriptor (2 x 4 bytes)
diff --git a/asm/asm_pic.asm b/asm/asm_pic.asm
index 901f854..2514be7 100644
--- a/asm/asm_pic.asm
+++ b/asm/asm_pic.asm
@@ -74,7 +74,6 @@ in al, 0x21 ; read in the primary PIC Interrupt Mask Register (IMR)
and al, 0x00 ; 0xEF => 11101111b. This sets the IRQ4 bit (Bit 5) in AL
out 0x21, al ; write the value back into IMR
-
in al, 0xA1 ; read in the primary PIC Interrupt Mask Register (IMR)
and al, 0x00 ; 0xEF => 11101111b. This sets the IRQ4 bit (Bit 5) in AL
out 0xA1, al ; write the value back into IMR
diff --git a/asm/asm_pit.h b/asm/asm_pit.h
index d020de1..58067bf 100644
--- a/asm/asm_pit.h
+++ b/asm/asm_pit.h
@@ -15,9 +15,6 @@
#include <stdint.h>
-/** Init PIT - 25 times a second*/
-void asm_pit_init();
-
/** install this interrupt handler to your Interrupt Vector Table */
void asm_pit_tick();
diff --git a/asm/asm_pit.s b/asm/asm_pit.s
index 8e16d0b..8be29cb 100644
--- a/asm/asm_pit.s
+++ b/asm/asm_pit.s
@@ -1,7 +1,16 @@
-.global asm_pit_init
.global asm_pit_tick
.global asm_pit_get_ticks
+.global asm_pit_sleep_50ms
+.global asm_pit_sleep_40ms
+.global asm_pit_sleep_10ms
+.global asm_pit_sleep_1ms
+
+.global asm_pit_rate_50ms
+.global asm_pit_rate_40ms
+.global asm_pit_rate_10ms
+.global asm_pit_rate_1ms
+
ticks:
.int 0
@@ -22,19 +31,62 @@ asm_pit_tick:
ret
-asm_pit_init:
+.macro asm_pit_rate val
- // configure ticking 25 times a second
- // 1193180 / 25 = 47727.2
- mov $47727, %dx
- mov $0b00110100, %al
+ mov $0b00110100, %al // chan 0 / mode 2
outb %al,$0x43
- mov %dx,%ax
+ // LSB first
+ mov \val, %dx
+ out %al, $0x40
+ xchg %ah,%al
+ out %al, $0x40
+
+ ret
+
+.endm
+
+.macro asm_pit_sleep val
+ mov $0x00110000, %al // chan 0 / mode 0
+ outb %al,$0x43
+
+ // LSB first
+ mov \val, %ax
out %al, $0x40
xchg %ah,%al
out %al, $0x40
+
+ // check if finished
+ mov $0xE2, %al
+ outb %al,$0x43
+
+ //sleep until finished
+ //7th bit determines if finished
+ sleep\val:
+ inb $0x40, %al
+ or $0b1000000, %al
+ cmp $0b1000000, %al
+ jne sleep\val
ret
+
+.endm
+
+/* decrements at 1.193182Mhz
+0xE90B // 50ms - 20 Hz
+0xBA6F // 40ms - 25 Hz
+0x2E9C // 10ms - 100 Hz
+0x04A9 // 1ms - 1000 Hz
+*/
+
+asm_pit_sleep_50ms: asm_pit_sleep $0xE90B
+asm_pit_sleep_40ms: asm_pit_sleep $0xBA6F
+asm_pit_sleep_10ms: asm_pit_sleep $0x2E9C
+asm_pit_sleep_1ms: asm_pit_sleep $0x04A9
+
+asm_pit_rate_50ms: asm_pit_rate $0xE90B
+asm_pit_rate_40ms: asm_pit_rate $0xBA6F
+asm_pit_rate_10ms: asm_pit_rate $0x2E9C
+asm_pit_rate_1ms: asm_pit_rate $0x04A9
diff --git a/asm/asm_start.s b/asm/asm_start.s
index e961ef6..8f0cf1e 100644
--- a/asm/asm_start.s
+++ b/asm/asm_start.s
@@ -20,7 +20,7 @@
.section .smp
.code16
_start_smp:
-call smp_start # TODO: align later before going C
+call smp_start
# 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.