Using assembly with C and stack
Posted: Tue Aug 17, 2021 4:23 pm
Hi,
I have the following c code (run in protected mode, all segments well defined):
The second assembly code defines both functions:
I build them using :
nasm -f elf asmfile -o asmfile.o
gcc -ffreestanding -m32 -fno-pic -fno-pie -c kernel.c -o kernel.o
ld --oformat binary -Ttext 0x1000 -melf_i386 asmfile.o kernel.o -o kernel.bin
Then I run my bootloader with this kernel, like before, but it triple fault every time.
The ret is responsible of the triple fault, but I don't understand what should I do, I think the problem comes from the stack, I dont know how to clean it before using ret instruction.
Thank you !
I have the following c code (run in protected mode, all segments well defined):
Code: Select all
extern void _printcool();
extern void _wait();
int kmain()
{
_printcool();
while(1==1){}
return 0;
}
Code: Select all
[bits 32]
global _printcool
global _wait
_printcool:
mov byte [0xB8000], 'R'
mov byte [0xB8001], 0x52
ret
_wait:
jmp _wait
nasm -f elf asmfile -o asmfile.o
gcc -ffreestanding -m32 -fno-pic -fno-pie -c kernel.c -o kernel.o
ld --oformat binary -Ttext 0x1000 -melf_i386 asmfile.o kernel.o -o kernel.bin
Then I run my bootloader with this kernel, like before, but it triple fault every time.
The ret is responsible of the triple fault, but I don't understand what should I do, I think the problem comes from the stack, I dont know how to clean it before using ret instruction.
Thank you !