loading user programs

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

loading user programs

Post by gmoney »

Ive recently added system calls to my os and tried to load a program i compiled but it doesn't work. it shows that the program is loaded but the program is supose to print out "ok lol" but all i get is something that looks like a smiley face. im leaving my kernel src and 2 pictures. take a look and tell me what u think
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

the rar file can be downloaded at www.lpsoft.us
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

no. (edit: the reason I said this was because you're not even giving us any clues as to the location of the problem. You haven't posted any code snippets, or anything. AJ below obviously has more time on his hands than I have!)
Last edited by JamesM on Mon Jul 30, 2007 4:03 am, edited 1 time in total.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

I have had a bit of a look at the source and unfortunately do not have the time to wade through it all at the moment (some of it looks interesting - I'd like to read it eventually).

I assume that syscall_write is responsible for actually writing to the video device (or have I got this completely wrong?). If you are passing the string to this call in a particular register, I wonder if the wrong register is getting passed to your print function?

Could you summarise what happens on the system call (from the userland and kernel perspectives) and give any relevant code snippets. That way, you are likely to get more of a response from people with less time on their hands!

Cheers,
Adam
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Oh - and your forums are completely trashed with spam...
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

yea i know ppl can be idoits. when i use the system call printf in the kernel it prints normaly, but when i load init.bin and it call the printf function some symbols show up. i dont know if im compiling the user app wrong or if something else is wrong. and im sorry for not adding code snippets its just too much code to put in the forums, thats why i gave my website :D
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

the function printf uses the system call write, which writes to con0 under the vfs. the write function can also write to fd0 and other **** to.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I'd bet that your loaded program isn't relocated yet and so you're loading rubbish to print.
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

how do you relocate it
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

What format are you using?

You can't just load the binary and hope it works - it'll be referencing the wrong memory for such things as strings.
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

how do i get a binary to print a string then. because i seen other hobby oses load binarys and there programs print strings
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

What binary file format are you using (ELF, flat)?

Edit: I'm asking because relocation is different across different file formats. A flat binary is next to impossible to relocate (you'd need opcode tables). ELF is designed to be relocated, but you need paging to properly locate it.

Edit 2: I know, because at the moment the programs I'm writing in my OS are the user software for my OS (loaded from the disk).
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

im using flat binary, i haven't did anything with elf, i was thinkin about coff but i need to add a virtural memey handler and change my memery management which is going to suck. right now im having a problem with v memory cause the docs i have are confusing to me.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Try loading the flat binary to a specific location (such as 0x40000) and put an 'org' keyword at the start of it. For the time being it'll suffice.

If it's C make sure that it's linked to run at whatever location you choose.

The reason why you do this is to tell it the offset where memory accesses go to (for instance, in the file a string may be at offset 0x30, but if loaded to 0x40000 it'll still try to access 0x30, so it must be relocated to 0x40030).

I'd get virtual memory and paging working and then work with either COFF or ELF. They're designed to work in a virtual memory space, and the effort required to get paging working is worth the time you save in loading the programs (With paging enabled, loading an ELF executable takes about 20 lines of code).
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Post by gmoney »

i have paging working i just dont use it cause im not getting how virtural mem works
Post Reply