Hi I am back....
I have a kernel (right now it does nothing though). All that it does is print a 'S' character and calls a C function. And this calling is within a while(1) loop(infinite). But bochs reports SP==1 error(stack pointer error) after a going thru the loop for some time. This is the code :
start.asm
---------
extern _Dmain
global _Start
[SEGMENT .text]
_Start:
mov ax, cs
mov ds, ax
mov ss, ax
mov es, ax
mov sp, 0xFFFF
call _Dmain
kernel.c
--------
void summa();
void Dmain()
{
int a = 20; //No use vars
char b = 'S'; //No use vars
while(1)
{
print();
summa();
}
}
void summa()
{
//Function does nothing
}
print.asm
----------global _print
[SEGMENT .text]
_print:
push ebp
mov ebp, esp
mov ah,0x0E
mov al,0x53
int 0x10
pop ebp
ret
link.ld - My linker script
---------------------------
OUTPUT_FORMAT("binary")
ENTRY(_Start)
SECTIONS
{
.text 0x00000000 :
{
*(.text)
}
}
PS: I am in real mode (obvious isn't it?)
Problem kernel code
-
knicos
RE:Problem kernel code
Is your code been compiled as 16bit or 32bit? Cant see any [BITS 16], and what compiler are you using.
-
mindvnas
RE:Problem kernel code
always align your (e)sp on 4 byte boundaries - see intel for explanation.
-
modshah
RE:Problem kernel code
I use gcc and nasm. As for the bits I believe gcc outputs only 32bit code. Correct me if I am wrong.
regards
modshah
regards
modshah
-
jcmatias
RE:Problem kernel code
1 - if u use gcc and ld , your kernel certaly is 32 bits .
2- U must prepare a 32 bits cpu mode creating and seting gdt, idt and loading
valid selectors in your segment registers etc..
3- There are a very particular thing about linking using this script:
declare a data section end bss, otherwise your vars may be in stack
2- U must prepare a 32 bits cpu mode creating and seting gdt, idt and loading
valid selectors in your segment registers etc..
3- There are a very particular thing about linking using this script:
declare a data section end bss, otherwise your vars may be in stack