I sadly lost the credentials to my old account but recently planned to do a small upgrade to my build environment for my OS.
The idea was to use clang so I dont need any crosscompilers which worked very nicely on windows.
Now I wanted to compile the exact same code on WSL/Linux and the compilation worked, sadly the OS didnt boot.
It took me a while to figure out whats wrong (especially because the code is pretty small), anyways it seems like there is a problem with the stack.
Code: Select all
.code32
.section .text, "ax"
.extern init
.global _start
_start:
cli
mov esp, tmp_stack+0x2000
push 0x2f4b2f4f
pop eax
mov dword ptr [0xb8000], eax
_stop:
cli
hlt
jmp _stop
.section .bss, "aw"
.comm tmp_stack, 0x2000, 0x1000
Code: Select all
ENTRY(_start)
SECTIONS
{
. = 0x400000;
.text :
{
*(multiboot)
*(.text)
}
.data ALIGN(4096) :
{
*(.data)
}
.rodata ALIGN(4096) :
{
*(.rodata)
}
.bss ALIGN(4096) :
{
*(.bss)
}
/DISCARD/ :
{
*(.comment)
*(.eh_frame)
*(.note.gnu.build-id)
}
}
Code: Select all
SET(COMMON_FLAGS "-Wall -Wextra -pedantic -Werror ${COMMON_FLAGS}" CACHE STRING "" FORCE)
SET(COMMON_FLAGS "-target i386-none-elf -mno-mmx -mno-sse -mno-sse2 ${COMMON_FLAGS}" CACHE STRING "" FORCE)
SET(CMAKE_ASM_FLAGS "${COMMON_FLAGS} -masm=intel ${CMAKE_ASM_FLAGS}" CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -ffreestanding ${CMAKE_C_FLAGS}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -ffreestanding -fno-exceptions -fno-rtti ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
SET(CMAKE_EXE_LINKER_FLAGS_INIT "-target i386-linux-elf -nostdlib")
IF(WIN32)
SET(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} -fuse-ld=lld.exe")
ELSEIF(APPLE)
SET(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} -fuse-ld=lld")
ENDIF()
A normal mov without using the stack works fine.
Im really not sure why this happens
Thanks in advance!