From 93bb4f992bec7ca02cc088c80888c1d93eb5e3aa Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 27 May 2012 14:57:32 +0200 Subject: [PATCH] Added support for floating point numbers. Note that the scheduler does not load/restore floating point numbers yet upon task switching. This means only one task can use floating point numbers at the same time without the risk of race conditions. Note that this enables SSE in 32-bit x86 platforms - but not all models have such support, which limits which computers Sortix works on. Ideally, we should detect what features are available on the computer at runtime and enable/disable the proper kernel support. This is not a problem on x86_64. --- sortix/x64/boot.s | 21 ++++++++++++++++++--- sortix/x86/base.s | 3 +-- sortix/x86/boot.s | 22 +++++++++++++++++++++- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sortix/x64/boot.s b/sortix/x64/boot.s index 7ebb80f9..636a4b83 100644 --- a/sortix/x64/boot.s +++ b/sortix/x64/boot.s @@ -31,7 +31,7 @@ .code32 start: _start: - jmp multiboot_entry + jmp prepare_kernel_execution # Align 32 bits boundary. .align 4 @@ -45,8 +45,7 @@ multiboot_header: # Checksum. .long -(0x1BADB002 + 0x00000003) -multiboot_entry: - +prepare_kernel_execution: # We got our multiboot information in various registers. But we are going # to need these registers. But where can we store them then? Oh hey, let's # store then in the code already run! @@ -127,6 +126,22 @@ Realm64: mov %ax, %fs mov %ax, %gs + # Enable the floating point unit. + mov %cr0, %rax + and $0xFFFD, %ax + or $0x10, %ax + mov %rax, %cr0 + fninit + + # Enable Streaming SIMD Extensions. + mov %cr0, %rax + and $0xFFFB, %ax + or $0x2, %ax + mov %rax, %cr0 + mov %cr4, %rax + or $0x600, %rax + mov %rax, %cr4 + # Alright, that was the bootstrap code. Now begin preparing to run the # actual 64-bit kernel. jmp Main diff --git a/sortix/x86/base.s b/sortix/x86/base.s index c02c11b3..6c2a71ce 100644 --- a/sortix/x86/base.s +++ b/sortix/x86/base.s @@ -28,9 +28,8 @@ .section .text .text 0x100000 -.type _beginkernel, @function +.type beginkernel, @function beginkernel: -_beginkernel: # Initialize the stack pointer. The magic value is from kernel.cpp. movl $stack, %esp addl $65536, %esp # 64 KiB, see kernel.cpp diff --git a/sortix/x86/boot.s b/sortix/x86/boot.s index 07394c40..63a990ba 100644 --- a/sortix/x86/boot.s +++ b/sortix/x86/boot.s @@ -31,7 +31,7 @@ .type _start, @function start: _start: - jmp beginkernel + jmp prepare_kernel_execution # Align 32 bits boundary. .align 4 @@ -45,3 +45,23 @@ multiboot_header: # Checksum. .long -(0x1BADB002 + 0x00000003) +prepare_kernel_execution: + # Enable the floating point unit. + mov %eax, 0x100000 + mov %cr0, %eax + and $0xFFFD, %ax + or $0x10, %ax + mov %eax, %cr0 + fninit + + # Enable Streaming SIMD Extensions. + mov %cr0, %eax + and $0xFFFB, %ax + or $0x2, %ax + mov %eax, %cr0 + mov %cr4, %eax + or $0x600, %eax + mov %eax, %cr4 + mov 0x100000, %eax + + jmp beginkernel