Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Enable cpu support for sse in bootstrap (#17)
Browse files Browse the repository at this point in the history
* sse xorps instruction is emitted
* Fixes the triple exception boot error when a sse instruction is encountered
  • Loading branch information
FrankRay78 authored Apr 10, 2024
1 parent 806e20f commit 96ea751
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mkdir ..\bin
cd ..\bin

csc /debug:embedded /noconfig /nostdlib /runtimemetadataversion:v4.0.30319 ../src/PatienceOS.Kernel/kernel.cs ../src/PatienceOS.Kernel/Console.cs ../src/PatienceOS.Kernel/FrameBuffer.cs ../src/PatienceOS.Kernel/zerosharp.cs /out:kernel.ilexe /langversion:latest /unsafe || goto Error
ilc --targetos windows --targetarch x86 kernel.ilexe -g -o kernel.obj --systemmodule kernel --map kernel.map -O || goto Error
ilc --targetos windows --targetarch x86 --instruction-set base --verbose kernel.ilexe -g -o kernel.obj --systemmodule kernel --map kernel.map -O || goto Error
nasm -f win32 -o loader.obj ../src/loader.asm || goto Error

:: QEMU doesn't boot properly when I use the Microsoft linker, continually stuck in a BIOS loop looking for something to boot.
Expand All @@ -23,7 +23,7 @@ nasm -f win32 -o loader.obj ../src/loader.asm || goto Error

ld -m i386pe -T ../src/linker.ld -o kernel.bin loader.obj kernel.obj || goto Error
objcopy -O elf32-i386 kernel.bin kernel.elf || goto Error
qemu-system-i386 -kernel kernel.elf || goto Error
qemu-system-i386 -cpu pentium3 -kernel kernel.elf -d int -no-reboot -no-shutdown || goto Error

cd ..\build
exit /B
Expand Down
3 changes: 2 additions & 1 deletion src/PatienceOS.Kernel/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ unsafe public struct Console
private FrameBuffer frameBuffer;

private int pos = 0;
private byte foregroundColor = 0x0F; // White

public Console(int width, int height, FrameBuffer frameBuffer)
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public void Print(string s)
for (int i = 0; i < s.Length; i++)
{
frameBuffer.Write(pos, (byte)ps[i]);
frameBuffer.Write(pos + 1, 0x0F);
frameBuffer.Write(pos + 1, foregroundColor);

pos += 2;
}
Expand Down
24 changes: 23 additions & 1 deletion src/loader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,31 @@ section .text
dd CHECKSUM

_start:
cli ; block interrupts
cli ; block interrupts (nb. not necessary, as QEMU boots into 32-bit protected mode with interrupts disabled)
mov esp, stack_space ; set stack pointer


enablesse:
; Is SSE supported on this CPU?
mov eax, 0x1
cpuid
test edx, 1<<25
jnz .sse ; If SSE supported enable it.
.nosse:
; SSE not supported - do something like print an error and stop
jmp $

.sse:
;now enable SSE and the like
mov eax, cr0
and ax, 0xFFFB ; clear coprocessor emulation CR0.EM
or ax, 0x2 ; set coprocessor monitoring CR0.MP
mov cr0, eax
mov eax, cr4
or ax, 3 << 9 ; set CR4.OSFXSR and CR4.OSXMMEXCPT at the same time
mov cr4, eax


; Call Main
call __managed__Main

Expand Down

0 comments on commit 96ea751

Please sign in to comment.