Page 1 of 2
Problem with code running in Bochs
Posted: Sun Jan 19, 2003 11:47 am
by beyondsociety
I am having some trouble with getting my code to work and when I ran it in Bochs, I got a weird error. Does anybody know what this error means and how I would go about solving it.
Code: Select all
00000542541p[CPU ] >>PANIC<< can_pop(): found SP=ffff
00000542541i[SYS ] Last time is 1042997919
00000542541i[CPU ] protected mode
00000542541i[CPU ] CS.d_b = 32 bit
00000542541i[CPU ] SS.d_b = 32 bit
00000542541i[CPU ] | EAX=60000010 EBX=00001000 ECX=000a0002 EDX=00000000
00000542541i[CPU ] | ESP=ffffffff EBP=ffffffff ESI=00000000 EDI=0000ffe4
00000542541i[CPU ] | IOPL=0 NV UP DI NG NZ AC PE NC
00000542541i[CPU ] | SEG selector base limit G D
00000542541i[CPU ] | SEG sltr(index|ti|rpl) base limit G D
00000542541i[CPU ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000542541i[CPU ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000542541i[CPU ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000542541i[CPU ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000542541i[CPU ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000542541i[CPU ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00000542541i[CPU ] | EIP=00001002 (00001001)
00000542541i[CPU ] | CR0=0x60000011 CR1=0x00000000 CR2=0x00000000
00000542541i[CPU ] | CR3=0x00000000 CR4=0x00000000
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 11:54 am
by Slasher
Your Os is trying to return from an interrupt with IRET but the values on the stack are not accurate or appropriate. Its a problem with the interrupt and stack working together. If you are trying tp set up a stack frame for stack based task switching then you frame setup code is not working properly!
if you paste code, it will be easier to know exactly what is the problem.
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 11:59 am
by beyondsociety
[attachment deleted by admin]
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 12:12 pm
by Slasher
HI,
you are setting ESP to 4GB without paging on in your boot code!!! You should put it an adress that EXISTS such as 1mb,2mb or 4mb!
Try that and see.
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 12:17 pm
by beyondsociety
When I do that, I get:
Code: Select all
>>PANIC<< exception(): 3rd (13) exception with no resolution
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 12:20 pm
by Slasher
Disable interrupts cause you do not have an IDT in place!
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 12:23 pm
by beyondsociety
I never enabled interrupts in my pmode bootsector.
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 12:30 pm
by Slasher
then the problem occurs when it wants to execute the c kernel try this, put
hlt
before
jmp LINEAR_CODE_SEL:0x1000
this will halt the cpu, if there isn't any problem then the boot code is fine and the problem is with the kernel part.
how did you write the kernel binary file to the disk?
all so add
-fwritable-string --nostdlib --freestanding (check the syntac in gcc info files) when you are compiling the kernel and remove the del *.bin and *.o commands from you compile.bat, you might be deleting the kernel before you even write it to disk!
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 12:57 pm
by beyondsociety
I changed a few things and I now I get a: running in bogus memory.
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 1:01 pm
by Slasher
did you first try halting the cpu as i suggested above?
what happened when you did?(if everything is fine, you should not get any messages from BOCHS, it will just stop)
Then tell me how you compiled the kernel(you can paste the lines in you next post)
ans how you wrote it to the disk?
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 1:08 pm
by beyondsociety
Code: Select all
Did you first try halting the cpu as i suggested above?
YES
Code: Select all
what happened when you did?(if everything is fine, you should not get any messages from BOCHS, it will just stop)
It stopped.
This is how I compiled it
Code: Select all
nasm -f bin bootpm.asm -o bootpm.bin
nasm -f aout km.asm -o km.o
gcc -c kernel.c -o kernel.o
ld -T link.ld -o kernel.bin km.o kernel.o
bootcopy bootpm.bin 0
bootcopy kernel.bin 1
makeboot test.img bootpm.bin kernel.bin
km.asm
Code: Select all
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file
start:
call _k_main
cli ; stop interrupts
hlt ; halt the CPU
link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x1000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
I just took out the stub function of my kernel.
I set my pmode stack to 0x100000.
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 1:14 pm
by Slasher
hi,
i once had a problem when i started my kernel and the only way i was able to solve it was by writing out my adresses in full in the linker script! so try
0x00001000 instead of 0x1000!
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 1:24 pm
by beyondsociety
I changed it.
I noticed something. When I set my pmode stack which is esp = 0xffff, it says running in bogus memory and when I look at the bochs dump, it says 00000fff.
If I set esp = 0x100000 (1 MB) it loads, displays a whole screen of blue symbols and then halts = running in bogus memory.
If I set esp = 0xFFFFFFFF it loads and halts like a: hlt.
What could be the problem?
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 1:42 pm
by Slasher
its the kernel code!
what is makeboot?
I think you should use a program like partcopy to copy the bootcode to the first sector and then the kernel to the 2nd sector of a real disk and then use partcopy to make an image of the disk
eg
partcopy -f0 0 1680000 test.img will create an image of the entire floppy called test.img
partcopy kernel.bin 200 <size of the kernel> -f0 will copy the kernel.bin file to sector 2 of the floppy(sectors numbers start from 1 not 0)
Re:Problem with code running in Bochs
Posted: Sun Jan 19, 2003 1:56 pm
by beyondsociety
I tried what you suggested and I get the same results. Look at the bochs memory dump and see if you see anything weird. In my pmode bootsector, ESP = 0x100000.
Code: Select all
>>PANIC<< prefetch: running in bogus memory
00000803660i[SYS ] Last time is 1043006043
00000803660i[CPU ] protected mode
00000803660i[CPU ] CS.d_b = 32 bit
00000803660i[CPU ] SS.d_b = 32 bit
00000803660i[CPU ] | EAX=60000010 EBX=00001000 ECX=000c0002 EDX=00000000
00000803660i[CPU ] | ESP=00001000 EBP=00000000 ESI=00000000 EDI=0000ffe4
00000803660i[CPU ] | IOPL=0 NV UP DI PL NZ NA PE NC
00000803660i[CPU ] | SEG selector base limit G D
00000803660i[CPU ] | SEG sltr(index|ti|rpl) base limit G D
00000803660i[CPU ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000803660i[CPU ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000803660i[CPU ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000803660i[CPU ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000803660i[CPU ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00000803660i[CPU ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00000803660i[CPU ] | EIP=06001000 (06001000)
00000803660i[CPU ] | CR0=0x60000011 CR1=0x00000000 CR2=0x00000000
00000803660i[CPU ] | CR3=0x00000000 CR4=0x00000000