Garbage inserted before a function?
Posted: Sat Jul 16, 2022 2:27 pm
I'm trying to have a function that initializes all of the stuff in my kernel (framebuffer TTY, keyboard LEDS, serial port). But for some reason, when GCC compiles it, it inserts a bunch of junk before the actual function code starts. This junk code then gets executed, and proceeds to triple fault. I verified this by putting `__asm__ ("cli\n" "hlt")` before anything else in the function. And sure enough, there's like 20 garbage bytes in front of the `cli hlt` in the disassembly. I have the x86_64-elf cross compiler, with red zone disabled, and `-mcmodel=kernel` for both libgcc and for my kernel. You can find the source code to the problematic file here: https://github.com/techflashYT/Techflas ... initions.c. And the hex bytes & disassembly of the junk below.
Code: Select all
55 48 89 E5 48 83 EC 20 F3 0F 7E 05 50 0F 00 00 F3 0F 7E 0D 40 0F 00 00 0F 16 05 31 0F 00 00 0F 16 0D 42 0F 00 00 0F 29 45 E0 0F 29 4D F0
Code: Select all
ffffffffffe02040 <__init>:
ffffffffffe02040: 55 push %rbp
ffffffffffe02041: 48 89 e5 mov %rsp,%rbp
ffffffffffe02044: 48 83 ec 20 sub $0x20,%rsp
ffffffffffe02048: f3 0f 7e 05 50 0f 00 movq 0xf50(%rip),%xmm0 # ffffffffffe02fa0 <_binary_font_psf_end+0x10>
ffffffffffe0204f: 00
ffffffffffe02050: f3 0f 7e 0d 40 0f 00 movq 0xf40(%rip),%xmm1 # ffffffffffe02f98 <_binary_font_psf_end+0x8>
ffffffffffe02057: 00
ffffffffffe02058: 0f 16 05 31 0f 00 00 movhps 0xf31(%rip),%xmm0 # ffffffffffe02f90 <_binary_font_psf_end>
ffffffffffe0205f: 0f 16 0d 42 0f 00 00 movhps 0xf42(%rip),%xmm1 # ffffffffffe02fa8 <_binary_font_psf_end+0x18>
ffffffffffe02066: 0f 29 45 e0 movaps %xmm0,-0x20(%rbp)
ffffffffffe0206a: 0f 29 4d f0 movaps %xmm1,-0x10(%rbp)
ffffffffffe0206e: fa cli
ffffffffffe0206f: f4 hlt