Page 1 of 2
loading user programs
Posted: Sun Jul 29, 2007 5:33 pm
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
Posted: Sun Jul 29, 2007 5:41 pm
by gmoney
the rar file can be downloaded at
www.lpsoft.us
Posted: Mon Jul 30, 2007 3:00 am
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!)
Posted: Mon Jul 30, 2007 3:42 am
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
Posted: Mon Jul 30, 2007 3:44 am
by AJ
Oh - and your forums are completely trashed with spam...
Posted: Mon Jul 30, 2007 11:00 am
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
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Posted: Mon Jul 30, 2007 11:15 am
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.
Posted: Mon Jul 30, 2007 3:10 pm
by pcmattman
I'd bet that your loaded program isn't relocated yet and so you're loading rubbish to print.
Posted: Mon Jul 30, 2007 3:24 pm
by gmoney
how do you relocate it
Posted: Mon Jul 30, 2007 3:45 pm
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.
Posted: Mon Jul 30, 2007 10:58 pm
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
Posted: Mon Jul 30, 2007 11:12 pm
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).
Posted: Mon Jul 30, 2007 11:56 pm
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.
Posted: Tue Jul 31, 2007 12:00 am
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).
Posted: Tue Jul 31, 2007 12:24 am
by gmoney
i have paging working i just dont use it cause im not getting how virtural mem works