this a part of code, is an example for user application.
[sup]
40000000 <__code>:
40000000: e9 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ............
....
40000010 <main>:
40000010: 55 push %ebp
40000011: 89 e5 mov %esp,%ebp
40000013: 83 ec 14 sub $0x14,%esp
40000016: 53 push %ebx
void writetest(const char *str, unsigned len);
int main()
{
char *msg = "Please Enter your Name : ";
40000017: bb ec 01 00 00 mov $0x1ec,%ebx
4000001c: 8d 74 26 00 lea 0x0(%esi,1),%esi
while(1)
{
writetest(msg, 5);
40000020: 83 c4 f8 add $0xfffffff8,%esp
40000023: 6a 05 push $0x5
40000025: 53 push %ebx
40000026: e8 05 00 00 00 call 40000030 <writetest>
}
[/sup]
but it generate #PF because at 0x40000017: it move this address $0x1ec to %ebx, which will point to msg string and these address is not in the user address space. what I can imagine, that the linker should add this msg to the elf data segment! the user address space begint at 0x40000000
User applications - Question - ?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:User applications - Question - ?
it looks like your code needs relocation.
Re:User applications - Question - ?
but relocation is a job of linker, hi should relocate them.
here is my linker script:
ENTRY(entry)
SECTIONS
{
.text 0x40000000 : /* 1 gig */
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
end = .; _end = .;
}
here is my linker script:
ENTRY(entry)
SECTIONS
{
.text 0x40000000 : /* 1 gig */
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
end = .; _end = .;
}
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:User applications - Question - ?
hmm ... indeed. maybe you did not include the section where the strings lies (.rodata if you use ELF.)
Re:User applications - Question - ?
hi, that right, how have you found that? I have search the internet and have readed most of LD Manual, but there is no info about strings.
now it work.
now it work.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:User applications - Question - ?
i had the bug myself and tried "objdump -x" on the kernel file ... so i discovered a lot of sections that weren't in the COFF file format ... like ".rodata" that occured to hold my strings (previously in .text with COFF format).
You can move strings to the .data sction using "-fwritable-strings" (to be checked) or include it with text by specifying .rodata(*.o) in your linker script (or something alike)...
You can move strings to the .data sction using "-fwritable-strings" (to be checked) or include it with text by specifying .rodata(*.o) in your linker script (or something alike)...