Hallo!
I need I little help. I think it's only a problem of relocation, but I need some advice
Ok, my boot loads some sectors in memori 0x1000:0 (0x00010000) then switches in pmode, then jumps to 0x00010000.
Ok, the 32-bit code is simple, write a letter directly in video-memory.
When I create this code in asm it's all ok, no craches.
When I create this code in c, I have some problems.
The c code is like
void _main()
{
*((int *)0xb8000)=0x07650765;
while(0)
{}
}
ok, If you eliminate the video statement no crashes happen.
I compiled this in all possible mode:
gcc -c kernel.c -o kernel.bin -nostdlib -nostartfiles ecc...
ld ... --Ttext 0x10000 --oformat binary
crash!
I recompiled gcc/as for using elf target and I used the ld script found in osdev, and the loader to make the jump to _main...
crash!
How can complie and link my kernel in C (remember now I also have a gcc/as for elf)
Where do you think the error is?
Can you show me how can complie and link my kernel in c?
Thanks...
Bye from Italy
KERNEL - LITTLE HELP
-
- Posts: 5
- Joined: Sun Nov 19, 2006 11:11 am
- Location: Italy
- Contact:
KERNEL - LITTLE HELP
CometKeeper... A Dream Guardian...
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
several notes:
1: where is your ss and esp pointing, - gcc will add pushes and pops to ebp to functions you write. SS should be properly loaded, and esp should be pointing at some sane address
2: while(0) should be while(1)?
3: Tried bochs' debugging features?
4: For next time, please post all relevant code, not just main()
1: where is your ss and esp pointing, - gcc will add pushes and pops to ebp to functions you write. SS should be properly loaded, and esp should be pointing at some sane address
2: while(0) should be while(1)?
3: Tried bochs' debugging features?
4: For next time, please post all relevant code, not just main()
Two things: One, try making Video Memory two characters, instead of an int. This probably won't help, but it'll make your code more readable. But, you should also try writing a null character to Video Memory with no color. If that works, than its something wrong with your text, char-color combination, not your code. If neither of those help, at least we'll no exactly what the problem isn't.
-
- Posts: 5
- Joined: Sun Nov 19, 2006 11:11 am
- Location: Italy
- Contact:
ALL CODE
Hallo, You were right, I wrote a short msg.
Here is all:
boot.asm
; load sectors
; feel 510 db 0
db 0x55,0xaa
; switch tO pmode
jmp dword 8:0x00010000 ; were sectors read are
loader.s
.global _loader
.set STACKSIZE, 0x4000 # that is, 16k.
.comm stack STACKSIZE,32
.code32
_loader: mov $(stack + STACKSIZE), %esp # set up the stack
call _main # call kernel proper
hlt
kernel.c
void _main()
{
*((char*)0xb8000)=0x07690749;
while(1)
{}
}
NOTE: if instead of kernel.c I use kernel.asm
kernel.asm
mov ax,0x10 ;selector
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x000a0000
mov ax,0xb8000
mov ds,ax
mov bx,0
mov word [ds:bx],0x1f65
jmp $
this work correctly!
linker.ld
ENTRY (_loader)
SECTIONS
{
. = 0x00100000;
.text :
{
*(.text)
}
.rodata ALIGN (0x1000) :
{
*(.rodata)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
copied from osdev.
I know something is surely wrong!
I'm not very expert in As e linker script
1.Somewhere to read out?
2.Some advices?
3.Where wrong?
smile - smile
Bye from Italy
Here is all:
boot.asm
; load sectors
; feel 510 db 0
db 0x55,0xaa
; switch tO pmode
jmp dword 8:0x00010000 ; were sectors read are
loader.s
.global _loader
.set STACKSIZE, 0x4000 # that is, 16k.
.comm stack STACKSIZE,32
.code32
_loader: mov $(stack + STACKSIZE), %esp # set up the stack
call _main # call kernel proper
hlt
kernel.c
void _main()
{
*((char*)0xb8000)=0x07690749;
while(1)
{}
}
NOTE: if instead of kernel.c I use kernel.asm
kernel.asm
mov ax,0x10 ;selector
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x000a0000
mov ax,0xb8000
mov ds,ax
mov bx,0
mov word [ds:bx],0x1f65
jmp $
this work correctly!
linker.ld
ENTRY (_loader)
SECTIONS
{
. = 0x00100000;
.text :
{
*(.text)
}
.rodata ALIGN (0x1000) :
{
*(.rodata)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
copied from osdev.
I know something is surely wrong!
I'm not very expert in As e linker script
1.Somewhere to read out?
2.Some advices?
3.Where wrong?
smile - smile
Bye from Italy
CometKeeper... A Dream Guardian...
Hi,
1. How about if you set up all the segments (as you have done in your working asm version) before calling main?
2. I know you have set the entry point in the linker script, but from the examples I have seen it strikes me as a little unusual to have the stack positioned at the start of the assembly file.
3. Are you certain you have loaded the entire binary file from disk? If you have set your stack up in that way (16k inside your program file), your program will take up several disk sectors - ensure they are all in RAM.
HTH
Adam
1. How about if you set up all the segments (as you have done in your working asm version) before calling main?
2. I know you have set the entry point in the linker script, but from the examples I have seen it strikes me as a little unusual to have the stack positioned at the start of the assembly file.
3. Are you certain you have loaded the entire binary file from disk? If you have set your stack up in that way (16k inside your program file), your program will take up several disk sectors - ensure they are all in RAM.
HTH
Adam
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Code: Select all
NOTE: if instead of kernel.c I use kernel.asm
kernel.asm
mov ax,0x10 ;selector
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x000a0000
mov ax,0xb8000
mov ds,ax
mov bx,0
mov word [ds:bx],0x1f65
jmp $
Code: Select all
d:\temp\dump.asm:5: warning: word value exceeds bounds
d:\temp\dump.asm:6: warning: word value exceeds bounds
also your bootloader suggests that you have parts beyond the 512 byte limit. If you have code here then it needs to be loaded from disk before you can use it.
I.e. you might be looking at the effects of some code other than your own...
Once again, you should get some debugging skills to find the issue yourself. Bochs is an excellent debugger - learn to use it
-
- Posts: 5
- Joined: Sun Nov 19, 2006 11:11 am
- Location: Italy
- Contact:
Thanks to all
I post very quickly because often I have not too much time, so I made many errors (english too ) and maybe I miss some info.
Ok. Let's reply!
I tried in loader.s to set the segment as done in kernel.asm. System crashes!
the kernel.asm uses 32-bit although I write a 16-bit code in the last post.
It's true that my experience in pmode is very poor, maybe I need to read carefully some pages: gdt, idt, selectors, descriptors etc.
Surely an OS cannot be done by pasting and modifying where you want to change something.
Osdev/faq is a very good resource, but it is also very dispersive!
Many of you have written quite good "demos", can you tell me a good "strategy" and how did you come to a "working" kernel/OS?
bye from Italy
I post very quickly because often I have not too much time, so I made many errors (english too ) and maybe I miss some info.
Ok. Let's reply!
I tried in loader.s to set the segment as done in kernel.asm. System crashes!
the kernel.asm uses 32-bit although I write a 16-bit code in the last post.
It's true that my experience in pmode is very poor, maybe I need to read carefully some pages: gdt, idt, selectors, descriptors etc.
Surely an OS cannot be done by pasting and modifying where you want to change something.
Osdev/faq is a very good resource, but it is also very dispersive!
Many of you have written quite good "demos", can you tell me a good "strategy" and how did you come to a "working" kernel/OS?
bye from Italy
CometKeeper... A Dream Guardian...
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Years of practice and experiencecometkeeper wrote:and how did you come to a "working" kernel/OS?
In essence:
1: learn a language, and MASTER it. (a lot of people miss this, unfortunately)
2: be able to build big complex things in that language.
3: find a platform independent compiler for your language.
4: learn 16-bit assembly, and write programs for DOS
5: learn how computer systems work and apply that knowledge using 4
6: learn also 32-bit and/or 64-bit assembly depending on wether you want a realmode/pmode/longmode.
7: learn to make designs
8: learn to read complex/poorly written documents
if you got the skills to get through this, writing an OS from scratch isnt a hard next step: you can write low level programs, you know the differences between 32-bit and 16 bit, (realmode and pmode/lmode), you have the programming and debugging skills to make things a success, you are able to read the necessary manuals needed for the task.
Myself, i had over 10 years of programming experience before i started on the task, and even so i had to restart from scratch 2 times before i got it to this stage.