Page 1 of 1

Please help me with these questions

Posted: Sat Jul 26, 2003 11:00 pm
by Neo
I've got a bunch of questions and would appreciate if any of you could
enlighten me on them.Here they go

1. Could anyone please tell me how i can debug with BOCHS in Windows98. I've got it working and can see my program but have no wayof stepping or tracing the execution.

2. I'm thinking of developing an OS and would like to know in what order the programming tasks should be dealt, like taskwise what can be done one by one . I've started with a FAT12 bootloader(but am stuck at the point of reading a file based on its FAT entries any help???). This should read in the secondary loader which I think must jump into protected mode and then load the kernel. Could anyone please give the specifics of implementing these, I mean you tell me what exactly each should do.

3. I've read somewhere that the BIOS reads the boot sector into memory at location 0000:7c00 or at 07c0:0000 well whats the difference?? how will it affect my code?? and what should I do to write a general boot loader?

4. I would also like to know how I can use GRUB to load my kernel file. I mean i've never used GRUB before. So please be detailed or just point me in the right direction.

Any help will be greatly appreciated

RE:Please help me with these questions

Posted: Sat Jul 26, 2003 11:00 pm
by Adek336
debugging in bochs - just insert a JMP $ or a CLI HLT anywhere you want to trace, press the gui POWER button. In file bochsout.txt there is a dump of registers, so you may use EAX EBX etc for debugging.

Hope this helps,
Adrian.

RE:Please help me with these questions

Posted: Sat Jul 26, 2003 11:00 pm
by DaveHK
1.Bochs has 2 versions, normal bochs (which is kind of a PC simulator and bochsdbg which is more usefor you at this stage, in the debug mode, the simulator will start up in command mode at which point you can check register values etc and set breakpoints before running the code, which will allow you to analyse program flow - very useful, especialy at the bootloader stage you are at now.

2. bootloaders are rarely involved in filesystems, it is common for the bootloader to just load in a number of condecutive sectors from the boot disk

3. basically there is little difference, they are exactly the same address in memory, the only difference is the setting of the code segment register (CS) which could affect how much code can be executed before you need to do a far jump. I honestly can't remember which setting is used and it may even differ between BIOS's, but as you are probably going to go straight into protected mode anyway (you are going into protected mode - right ?), then it is of little consequence

4. I've never used GRUB before either, so someone else take over here ?

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by Hefe
hi

1. like DaveHK said, you can use bochsbdg.exe for debugging your kernel.
the users manual for the debugger can be found here:
http://bochs.sourceforge.net/doc/docboo ... x2095.html
maybe its a good idea to read the bochs manual anyway.

2. there are alot of fat12 boot loader around. check out the "Development Links" ond this page or http://my.execpc.com/~geezer/osd/boot/index.htm

3. i also had problems with this. i solved it by just DON'T changing the value of cs. alot of people do something like
  mov ax, 0x7c0
  mov es, ax
-or-
  [ORG 0]
i only got it working on all machines by doing none of both.

4. never used grub, sorry

kind regards
hefe

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by Hefe
sorry my last post was wrong:

[ORG 0x7c00] <= wrong on some machines

[ORG 0] <= is the RIGHT way to do it

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by Jamethiel
Umm... No.

The right way to do it is to encode a far jump to fix the CS:IP to whatever you want.

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by Hefe
Umm... Yes! :)

You are right, this is a safer solution.
However, because I set ds right, and only use relative jumps, I dont have to care about CS:IP at all, so with relative jumps my solution should work.
Or am i wrong ?

But your solution is better, I would also recommend it now.

kind regards
hefe

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by Jamethiel
No, you're correct.

I was just looking at my own bootsector code, and it doesn't bother fixing CS:IP because it doesn't use any CS-relative data addressing. I too do everything through DS and ES (a 4-gig flat unreal ES, but ES nonetheless).

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by Robert Lee
The solution to set CS properly (Which is the method I use) is:

DB 0EAh
DW OFFSET L01, 7C0h
L01:

This makes 7C0h the segment and makes the boot sector segment-aligned. With the code segment-aligned the $ operator works as expected and static variables can be used.

-Robert

RE:Please help me with these questions

Posted: Sun Jul 27, 2003 11:00 pm
by rexlunae
'4. I would also like to know how I can use GRUB to load my kernel file. I mean i've never used GRUB before. So please be detailed or just point me in the right direction.'

Grub uses the Multiboot standard, so this link should tell you what you need to know:   http://www.mcc.ac.uk/grub/multiboot_toc.html.  This information is appropriate for making your kernel multiboot compliant.

The users manual is located here: http://www.mcc.ac.uk/grub/grub_toc.html.

Incidentally, I highly recommend grub.  It allows you to skip the nasty real-mode steps, and concentrate on the more interesting aspects of OS design.