Skip to content

Incorrect stack alignment #80

@GuillaumeDIDIER

Description

@GuillaumeDIDIER

The boot loader provides the kernel with a miss aligned stack.

This cause issues when SSE is enabled, as some of those instructions expect 16-aligned stacks and the alignment is off by eight.

Reproduction steps:

Take blog-os post-03, enable SSE in the boot loader and target, call panic! in main, if running under bochs you will get a fault.
(QEMU appears to ignore the issue)

The fault occurs on movaps instruction form xmm0 to the (mis-aligned stack).

The stack alignment is mess-ed up because when the _start function is called the compiler assumes a return address has been pushed on the stack, making it 16x +8 aligned, while it is apparently 16 aligned when called by the bootloader.

From reading OS dev wiki, the kernel entry point should be reached using a call instruction so that it matches the compiler assumptions, (Even in C) whereas the boot loader appears to use a jmp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions