problem with using printk in tftpbootable code

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.
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: problem with using printk in tftpbootable code

Post by Hangin10 »

Your GDT is wrong. Look at what the far jump is trying to use as its descriptor.
The first GDT entry is unused; fill that with zeros, moving everything down one entry.

Don't be surprised when none of this works. The print_assembly file will be useless because you can't use BIOS interrupts in protected mode, and you haven't shown us where printk is defined, but since it looks like yoou did not write, you're doing it wrong. If you're trying to use something from Linux I'll have to assume (like everyone else who has tried to point it out), that's not going to work either.

Have you read Beginner Mistakes? And then after that, Bare bones ?
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: problem with using printk in tftpbootable code

Post by aloktiagi »

hi,

What the problem in this, can't figure it out (bootloader was provided by Gigasoft).

Code: Select all

bits 16
org 7c00h

cli
xor ax,ax
mov ds,ax
mov es,ax
lgdt [gdt_desc]
mov si,7e00h ; if your kernel has been placed at offset 200h, like you did
mov di,1000h ; the address where the kernel should be
mov cx,512 ; whatever the size of the kernel is
rep movsb
mov eax,cr0
or al,1
mov cr0,eax
jmp 8:clear_pipe
bits 32
clear_pipe:
mov ax,10h
mov ds,eax
mov es,eax
mov ss,eax
mov esp,90000h
jmp 1000h
gdt dd 0ffffh,0cf9a00h,0ffffh,0cf9200h
gdt_desc dw 23
dd gdt-8
The part about bare bones i've seen it but i need a bootloader first that sets up gdt and PM. Also i'm not using bochs. Testing it with a tftpboot.

Thanks
Alok
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: problem with using printk in tftpbootable code

Post by Gigasoft »

@Hangin10: Actually, that version of the GDT was mine, and it's fine. If you look at gdt_desc, you'll see why there is no zero-filled entry at the label "gdt".

@aloktiagi: Trust me, it's much easier to find out what's wrong by using Bochs. With testing on a real machine, at this stage you'll have a lot of trial and error and there will be almost no hope of making it work, especially when you don't have a firm grasp of the PC architecture to begin with. If you can't get TFTP booting to work in Bochs, you can always make a boot sector that relocates itself to another location, and then loads the entire Network Boot Program image from the virtual floppy, which is guarranteed to always work in Bochs. Use the debugging version of Bochs, and step through each instruction (stepping over BIOS services) to make sure the program works exactly how you expect it to.
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: problem with using printk in tftpbootable code

Post by aloktiagi »

Hi,

Found the problem!!! Just put the infinite loop instead of a jump to 1000h in the bootloader

Code: Select all

bits 16
org 7c00h

cli
xor ax,ax
mov ds,ax
mov es,ax
lgdt [gdt_desc]
mov si,7e00h ; if your kernel has been placed at offset 200h, like you did
mov di,1000h ; the address where the kernel should be
mov cx,512 ; whatever the size of the kernel is
rep movsb
mov eax,cr0
or al,1
mov cr0,eax
jmp 8:clear_pipe
bits 32
clear_pipe:
mov ax,10h
mov ds,eax
mov es,eax
mov ss,eax
mov esp,90000h
[b];jmp 1000h[/b]
[b]jmp $[/b]
gdt dd 0ffffh,0cf9a00h,0ffffh,0cf9200h
gdt_desc dw 23
dd gdt-8
times 510-($-$$) db 0           ; Fill up the file with zeros

        dw 0AA55h                ; Boot sector identifyer

Didn't reboot now, so am i jumping to the wrong place now?

Alok
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: problem with using printk in tftpbootable code

Post by gerryg400 »

Aloktiagi,

Congratulations. So glad you found the problem!

- gerryg400
If a trainstation is where trains stop, what is a workstation ?
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: problem with using printk in tftpbootable code

Post by aloktiagi »

Hi,

Thanks gerryg400!!

Now my bootloader code looks like this

Code: Select all

bits 16
org 7c00h

cli
xor ax,ax
mov ds,ax
mov es,ax
lgdt [gdt_desc]
mov si,7e00h ; if your kernel has been placed at offset 200h, like you did
mov di,1000h ; the address where the kernel should be
mov cx,512 ; whatever the size of the kernel is
rep movsb
mov eax,cr0
or al,1
mov cr0,eax
jmp 08h:clear_pipe
bits 32
clear_pipe:
mov ax,10h
mov ds,eax
mov es,eax
mov ss,eax
mov esp,90000h
jmp 08h:01000h
mov byte [ds:0B8000h], 'P'      ; Move the ASCII-code of 'P' into first video memory
mov byte [ds:0B8001h], 1Bh      ; Assign a color code

jmp $
gdt dd 0ffffh,0cf9a00h,0ffffh,0cf9200h
gdt_desc dw 23
dd gdt-8
times 510-($-$$) db 0           ; Fill up the file with zeros

        dw 0AA55h                ; Boot sector identifyer


My C code sits at 0x1000( linked it there). How do i find out that the jump from the bootloader is reaching the c code?

Thanks
Alok
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: problem with using printk in tftpbootable code

Post by Solar »

*sigh*

Is that so difficult to think up?

Make the C code print another character would be a good start.
Every good solution is obvious once you've found it.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: problem with using printk in tftpbootable code

Post by Gigasoft »

No, you didn't "find the problem". You just verified that the problem is in your C program, which was already known. What does your C program look like now?

By the way, it doesn't matter if you have jmp 1000h or jmp 8:1000h, since it's already running in segment 8.
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: problem with using printk in tftpbootable code

Post by aloktiagi »

Since GDT is configured now and i'm in protected mode (hopefully), what all can be done in the C code. Is anything else to be done?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: problem with using printk in tftpbootable code

Post by Solar »

Like, making it work?

"Hopefully" is a very poor status for a piece of code...

/me is looking for the candid camera...
Every good solution is obvious once you've found it.
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: problem with using printk in tftpbootable code

Post by aloktiagi »

Hi,

To make it work i put something like

Code: Select all

unsigned char *videoram = (unsigned char *) 0xb8000;
videoram[0] = 65; /* character 'A' */
videoram[1] = 0x07; /* forground, background color. */
(from http://wiki.osdev.org/Bare_bones)

And the computer reboots. If i only put a infinte loop in c code the computer hangs and doesn't reboot.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: problem with using printk in tftpbootable code

Post by Gigasoft »

What happens if you have the above followed by an infinite loop?
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: problem with using printk in tftpbootable code

Post by aloktiagi »

Hi,

It worked :) Thanks. Now after this what shud be the next step. My first main requirement is initializing the ethernet card. Can that be done now or i need to enable things like ISR, IDT etc...

Thanks
Alok
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: problem with using printk in tftpbootable code

Post by neon »

Hello,

Do you know exactly why your software was crashing? We do not know your design goals so we are limited in helping you plan your system.

I personally would work on the basic system components before anything else. Before that though you should decide on the basic structure of your system - microkernel? monolithic kernel? What do you want to support? If you are unsure, go with monolithic for now and focus on the IDT and adding hardware interrupt support (PIC or APIC).
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Lithorien
Member
Member
Posts: 59
Joined: Tue Oct 27, 2009 1:40 pm
Location: Hanover, PA

Re: problem with using printk in tftpbootable code

Post by Lithorien »

aloktiagi wrote:Hi,

It worked :) Thanks. Now after this what shud be the next step. My first main requirement is initializing the ethernet card. Can that be done now or i need to enable things like ISR, IDT etc...

Thanks
Alok
What you need to do next, honestly, is to take a look at these two Wiki pages:

http://wiki.osdev.org/What_order_should ... ings_in%3F
http://wiki.osdev.org/Nick_Stacky

Come up with a design plan - design documents aren't just for corporate environments. They're a good idea for anyone who is setting out on a large project (like an OS). Once you've figured out where you need (and want) to go, split it up into the things that must happen, the things that should happen, and then the things you would like to have happen. Write out a roadmap of features that you will code (including dependancies). Get your head on straight about what you're doing.

Then, and only then, should you start actually coding.
Post Reply