Page 4 of 4
Re: problem with using printk in tftpbootable code
Posted: Fri Apr 30, 2010 8:53 pm
by aloktiagi
Yes it became correct after linking without -i option
Code: Select all
00001000 <main>:
1000: 55 push %ebp
1001: 89 e5 mov %esp,%ebp
1003: 83 ec 08 sub $0x8,%esp
1006: 83 e4 f0 and $0xfffffff0,%esp
1009: b8 00 00 00 00 mov $0x0,%eax
100e: 83 c0 0f add $0xf,%eax
1011: 83 c0 0f add $0xf,%eax
1014: c1 e8 04 shr $0x4,%eax
1017: c1 e0 04 shl $0x4,%eax
101a: 29 c4 sub %eax,%esp
101c: e8 14 00 00 00 call 1035 <k_clear_screen> (now proper)
1021: 83 ec 08 sub $0x8,%esp
1024: 6a 00 push $0x0
1026: 68 bc 10 00 00 push $0x10bc
102b: e8 0d 00 00 00 call 103d <k_printf>
1030: 83 c4 10 add $0x10,%esp
1033: eb fe jmp 1033 <main+0x33>
00001035 <k_clear_screen>:
1035: 55 push %ebp
1036: 89 e5 mov %esp,%ebp
1038: 83 ec 08 sub $0x8,%esp
103b: eb fe jmp 103b <k_clear_screen+0x6>
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 5:45 am
by aloktiagi
Hi
The following 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
What do the following three lines mean?
Code: Select all
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
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 6:15 am
by Selenic
aloktiagi wrote:Code: Select all
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
Note that I've re-added that last line to your snippet. rep movsb means 'copy cx bytes from [ds:si] to [es:di]'
In this case, cx is the size of a sector (so it's assuming you've got a one-sector kernel), si is where you've told the BIOS to load the kernel to and di is where you're moving it. Why it's not just read to that location anyway (as it's under 1MB) I don't know.
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 6:38 am
by aloktiagi
Hi
Ok the problem is as the kernel size is growing if i make a jump to a code location, where the amount of code between the caller and called location is large i.i a long jump the computer reboots.
Do i have to change something in these lines
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 6:49 am
by Selenic
aloktiagi wrote:Hi
Ok the problem is as the kernel size is growing if i make a jump to a code location, where the amount of code between the caller and called location is large i.i a long jump the computer reboots.
Do i have to change something in these lines
Yeah - it's only loading 512 bytes of the kernel. You need to modify it to load an arbitrary (but configurable) size.
A structure like GRUB's works well for this - have a second stage, the size of which is compiled into the first stage. The first stage simply loads and sets up the second stage, which then does whatever complicated stuff you want (mostly in 32-bit C code, with a few drops to real mode to make BIOS calls).
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 6:50 am
by aloktiagi
I increased it 1024 and it worked!!
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 8:32 am
by Selenic
aloktiagi wrote:I increased it 1024 and it worked!!
Then you'll just have the same problem when it grows further. Better to define (via a '-D KSECT=n' option to the assembler) a name which contains the size of your kernel in sectors (rounded up) - then you can pass this value to the function which reads in your kernel, and you can set the copy length to (512*KSECT).
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 8:57 am
by aloktiagi
Ok Thanks!!!
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 4:57 pm
by Gigasoft
No, this is a PXE boot image, so there are no sectors. The entire image is loaded at 0x7c00 by the BIOS.
It's probably better to include the kernel image using incbin:
Code: Select all
bits 16
org 7c00h
cli
xor ax,ax
mov ds,ax
mov es,ax
lgdt [gdt_desc]
mov si,LoadStart
mov di,1000h
mov cx,LoadEnd-LoadStart
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
LoadStart incbin kernel.bin
LoadEnd:
Then build it using this:
gcc -ffreestanding -c main.c -o main.o
ld -i -e _main -Ttext 0x1000 -o kernel.o main.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
nasm -f bin bootloader.asm -o os1.img
It should be noted that when the kernel's size exceeds 6c00h bytes, there will be a problem. In this case, you must copy the loading code to a location which won't overlap with the new kernel location before running it.
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 9:55 pm
by aloktiagi
Hi
i tried your suggestion, but i get an error!!
nasm -f bin bootsect.asm -o bootsect.bin
bootsect.asm:35: error: symbol `kernel.bin' not defined before use
Re: problem with using printk in tftpbootable code
Posted: Mon May 03, 2010 10:17 pm
by aloktiagi
Hi
Solved it by putting double qoutes
But the machine is still rebooting but works fine when i hardcode it like this
mov cx,1024 ; whatever the size of the kernel is