OS works on one PC, on other not...?

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.
Post Reply
Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

OS works on one PC, on other not...?

Post by Juggl3r »

Hey guys,

for my university I have to expand an OS. We are using Potatoes: http://potatoes-project.tk/
Compiling is no problem, but when I try to run the .img files, there always comes "fs: FS loading failed" and then comes "fs: creating new FS" and then it hangs.
I'm using Qemu to emulat the OS.

This error also appears, when I try it with the downloaded .img files. I tryed to find the error and find this function calls:
create_fs() => init_bmap() => mark_block() => wrt_block() => hd_write_sector() => repoutsw()

So in the function "repoutsw" the program beginns to hang. This is a Assembler Function:

repoutsw:
cld
mov ecx, [esp+12] ;value
mov esi, [esp+8] ;source buffer
mov edx, [esp+4] ;dest address
rep outsw
ret

The Value in this function-call should be 256, so in ECX is 256.

Anybody know, why this piece of code will hang up my OS?

When I try the same things on another pc (my laptop), all works fine......
But I does the exactly same things. Downloaded Qemu and downloaded the .img files and started them with the same comments.
Somebody have an idea? Or does somebody knows what the "outsw" instruction is doing??

Thanks guys, really need your help.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: OS works on one PC, on other not...?

Post by gerryg400 »

I'm guessing that "rep outsw" is too fast for your hardware. It's recommended to use a loop with individual outsw opcodes.
If a trainstation is where trains stop, what is a workstation ?
Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

Re: OS works on one PC, on other not...?

Post by Juggl3r »

Oh thanks!

You can maybe show me a little piece of code, how I should modify it? I'm no Assembler programmer.... so that would be really, really great!
DLBuunk
Member
Member
Posts: 39
Joined: Sun May 18, 2008 9:36 am
Location: The Netherlands

Re: OS works on one PC, on other not...?

Post by DLBuunk »

Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

Re: OS works on one PC, on other not...?

Post by Juggl3r »

Hmm, I'm sorry, I don't understand how to change it with this wiki? Why there are jumps to "1f"? Isn't that a deadlock?

Here's my change:

Code: Select all

[GLOBAL repoutsw]

repoutsw:
        cld
        mov ecx, [esp+12] ;value
        mov esi, [esp+8] ;source buffer
        mov edx, [esp+4] ;dest address
	Loop1:
        outsw
			dec ecx
			nop; don t use loop instruction
			jecxz Loop1; because loop is too fast
        ret
This code is working. But my problem is, in the repinsw-function the same thing happens. Program hangs, when it comes to this function call. Here's the code:

Code: Select all

[GLOBAL repinsw]

repinsw:
        cld
        mov ecx, [esp+12] ;value
        mov edi, [esp+8] ;dest buffer
        mov edx, [esp+4] ;source address
        rep insw
        ret
When I make the same changes like above, the code looks like this:

Code: Select all

[GLOBAL repinsw]

repinsw:
        cld
        mov ecx, [esp+12] ;value
        mov edi, [esp+8] ;dest buffer
        mov edx, [esp+4] ;source address
	Loop3:
			nop
        insw
			dec ecx
			nop
			jecxz Loop3
        ret
And when I compile and run it, the OS don't starts. There comes the same error as when the img is damaged (had this error some time ago).
"<0x100000:0x110000:0x0>, <0x1111000:0xa000:0x54f0>, shtab=0x1212a8Starting up..."

So why the other code is working and this not? I have to fix this issue, so please give me a hint.
I'm no Assembler programmer, so I also don't know how to call a c-code function from a assembler source.... or how to put this assembler code the correct way into my assembler function....? The Assembler Code from the Wiki looks like a deadlook, why should this work? We Jump to Label1 and at Label1 we are jumping back to Label1 and so on...?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: OS works on one PC, on other not...?

Post by gerryg400 »

Code: Select all

jecxz Loop3
This jumps if ecx is zero. That's the opposite of what you need.
If a trainstation is where trains stop, what is a workstation ?
Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

Re: OS works on one PC, on other not...?

Post by Juggl3r »

Oh yeah, that's the point...

Another question: Why there is no function-präambel?
Should not be there "push ebp; movl ebp, esp" instructions ??
And is it possible that on some processors the arguments are pushed on the stack in different order?
For example:

repoutsw(1,2,3);
==>
mov ecx, [esp+12] ;==> 3
mov esi, [esp+8] ; ==> 2
mov edx, [esp+4] ; ==> 1

And that on other processors the same function call will become to this:
repoutsw(1,2,3);
==>
mov ecx, [esp+12] ;==> 1
mov esi, [esp+8] ; ==> 2
mov edx, [esp+4] ; ==> 3

??
Because then the ECX register will get the content of "destination address", and the REP Instruction will too often be executed?
DLBuunk
Member
Member
Posts: 39
Joined: Sun May 18, 2008 9:36 am
Location: The Netherlands

Re: OS works on one PC, on other not...?

Post by DLBuunk »

Juggl3r wrote:Another question: Why there is no function-präambel?
Should not be there "push ebp; movl ebp, esp" instructions ??
"pushl ebp; movl ebp,esp" is only needed if you use local variables on the stack, it is also needed in realmode as you cannot use sp as index register in realmode.
Juggl3r wrote:And is it possible that on some processors the arguments are pushed on the stack in different order?
That does not depend on the processor, but on the calling sequence, your code is using the 32-bit C calling sequence. If you use another language than C, or switch to 64-bit code, you'll have to rewrite it.

See here: http://wiki.osdev.org/Calling_Conventions
And also here: http://en.wikipedia.org/wiki/X86_calling_conventions
Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

Re: OS works on one PC, on other not...?

Post by Juggl3r »

Now if I change it, it don't works.... -.-

Code: Select all

[GLOBAL repoutsw]

repoutsw:
        cld
        mov ecx, [esp+12] ;value
        mov esi, [esp+8] ;source buffer
        mov edx, [esp+4] ;dest address
	Loop1:
        outsw
		dec ecx
		nop; don t use loop instruction
		test ecx, ecx
		jnz Loop1
        ret
It worked before, because it don't jumps.... but know it jumps and still don't work -.-
So whats the problem here? I really don't get it.


When I change the code, so that esp+4 is stored in ecx and esp+12 is stored in edx (so I change the order of arguments), the function is executed, but at the 4th function call, it also stops and hangs up.

Is there maybe an error, because my computer is dual-core? (on my Laptop it works and laptop has only one core).

Or does anybody else have an idea????


edit:
If I change the instruction mov ecx, [esp+12] ;value to mov ecx, $5
all works fine and program don't hang up.
If I change it to mov ecx, $256 the programm hangs up in the first function call of this function.
If I change it to mov ecx, $15 the programm hangs up at the 7 function call of this function......


So what is this and how can I fix this?
Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

Re: OS works on one PC, on other not...?

Post by Juggl3r »

Can really nobody help me?
I don't get it, how to implement this "waiting" in Assembler.... if I copy the code from the wiki, I get error's from the linker.
Can please somebody post the needed changes? That would be really, really great for me. I want to learn some new stuff in developing new stuff for this project, but don't want to search for 1 error for x weeks....
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: OS works on one PC, on other not...?

Post by Luns »

How do you call the function?

You shouldn't just change random things and hope they work, otherwise you'll never understand what you're doing. Try reading this, it might help you get the right parameters in the right registers - http://courses.engr.illinois.edu/ece390 ... ixing.html .

Also, if you're using Intel syntax for your assembly, you don't need the dollar sign in front of number constants.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: OS works on one PC, on other not...?

Post by Brendan »

Hi,
Juggl3r wrote:Can really nobody help me?
You can have a reliable OS (like Linux) and it'll be too complex for educational purposes, or you can have something simple (like POTATOES or etiOS) and it'll be an unreliable piece of crap. It's impossible to have something that is both reliable and simple (especially for 80x86), because the hardware is messy and there's lots variation and lots of corner cases to take care of.

The first thing I'd do is explain to your lecturer/uni that the unmodified POTATOES code fails (and therefore you can't begin extending it); and try to make them figure out how to work around the problem/s with their own subject materials. If that doesn't work, then...

The first step would be to go through the code and rewrite all of the error handling, so that you get useful/descriptive error messages from it (rather than locking up or saying "something failed" without any indication of why). To begin with I'd add a time-out to the "void wait_on_hd_interrupt(char* str)" function. Then I'd start messing with "void hd_init()" and make it determine which PIO modes the hardware supports from the IDENTIFY information and if the drive is using one of the LBA modes and not CHS (rather than using blind assumptions). Then I'd rip "io_main.c" to pieces and try to figure out why the morons are assuming an old "PATA" hard disk controller exists in the first place (and not something like SATA/AHCI, SCSI, USB) and probably replace the entire file with something that scans PCI buses.

After spending about 6 months doing a full rewrite of every single thing in POTATOES, you'll be able to start extending it. Of course after only 3 months of work you'd probably be more qualified to teach the uni's OS course than your current lecturer... ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Juggl3r
Posts: 8
Joined: Mon Aug 29, 2011 5:09 pm

Re: OS works on one PC, on other not...?

Post by Juggl3r »

Thank you both.

Bendan:

The problem is, for the next semester at university (begin about februar 2012) there is a new course at our university about "programming OS". My job is, to find out "how difficult" it is, to program some extensions in Potatoes. (for example adding /dev/random, /dev/crypt, adding a new scheduling algorithm, adding mm-protection, ....
The thing is now, I could do all the stuff on my laptop (where all is working fine), but when other students will visit this course and they will get the same error's like I, would that be not very good....

Hmmmm, why do you say, that I should rewrite all the error-handling? I think that would need very much time, because I would have to read very much stuff on this topics and I think, I don't have the time for that. Is the error handling really as bad, as you say here?

Can you tell me, from where in the code you know, that they are using an old "pata" controller (and no SATA, SCSI, USB, PCI)?
And can that be the reason, why my "rep outsw" instruction fails?

The thing is, that this instruction only fails, if I execute it more than ~5 times.....
Or could it be, that it is really too fast? If, how I can change this? I tried to put some "sleep"-code after it, but it still don't work (I changed the rep instruction to a jump-to-label instruction).

I don't need a "perfect" system, I really only have to become the system running, so that I can work on the other tasks with a clear conscience.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: OS works on one PC, on other not...?

Post by gerryg400 »

Code: Select all

[GLOBAL repoutsw]

repoutsw:
        cld
        mov ecx, [esp+12] ;value
        mov esi, [esp+8] ;source buffer
        mov edx, [esp+4] ;dest address
   Loop1:
        outsw
      dec ecx
      nop; don t use loop instruction
      test ecx, ecx
      jnz Loop1
        ret
Is a function called from C allowed to modify esi like that without restoring it ? I thought the called function had to preserve ebx, esi and edi. Also the rules about the direction flag have recently changed in gcc.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: OS works on one PC, on other not...?

Post by Brendan »

Hi,
Juggl3r wrote:The problem is, for the next semester at university (begin about februar 2012) there is a new course at our university about "programming OS". My job is, to find out "how difficult" it is, to program some extensions in Potatoes. (for example adding /dev/random, /dev/crypt, adding a new scheduling algorithm, adding mm-protection, ....
The thing is now, I could do all the stuff on my laptop (where all is working fine), but when other students will visit this course and they will get the same error's like I, would that be not very good....
Let's take a look at POTATOES...

The error handling throughout is crap and there's hundreds of stupid assumptions that will break as soon as the computer isn't "a desktop 80x86 from 1992" (and all those stupid assumptions are used instead of any form of device detection). I couldn't see where the physical memory manager ends and the virtual memory manager begins (inadequate separation between logically separate pieces). The "io" directory contains half of each device driver while the "pm" directory has the other half (e.g. "io/io_keyboard.c" and "pm/dev_keyboard.c"). There's some sort of virtual terminal thing somewhere, but I don't know where (probably scattered over 5 different files in a few different directories). The scheduler as hard to find as the virtual terminal thing - I found part of it in "pm/pm_main.c" but there's more somewhere ("sleep()" and "halt()" for example) that I haven't found yet. Parts of the code are commented out for no obvious reason (see if you can guess how "free_memory()" works and why). I couldn't find anything to handle disk partitions (does it even support partitions?), and there doesn't seem to be anything to mount and unmount file systems (do they just assume that the first hard disk is theirs?). I don't even know what the file system actually is (it's not FAT, NTFS, ISO9660 or HFS, and it can't be something they invented themselves as GRUB boots from it - maybe it's ext2; but they don't actually say what it might be anywhere). If you can find 10 lines of source code that don't contain "FIXME" or "TODO" or "hackhackhack" then you're lucky.

Ok, so that covers some of the bad things that I noticed in about 10 minutes of looking at it (and if I cared enough to really look through it I could probably create a list several pages long). What about all the good things? Well, there's some good ASCII art ("init/test.c"). The only other good thing is that if you're lucky it will probably crash or fail before it trashes your hard drive (but only if you're lucky).

Now let's take a look at all the comments from all the other universities that are using this OS as part of their courses. There's a forum for the project which must be full of lots of useful advice, comments, etc; so let's start there... Doh! [-o<

Drop POTATOES now. Drop it hard and fast. Drop it like it's a bag of dog poo that's on fire. Then run as far away from it as you can. Don't look back.

Now look at what other universities are using for their courses.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply