boot code needs fix [FIXED]

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.
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

whats kernelSize in? bytes? why add 3 then divide by 4?

thx!

p.s. how do you set the a20 in asm?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Post by bubach »

Here's one of my old bootsector that loads to 1mb, sets a20 + pmode and I think it checks memory too. It's not FAT12, and max kernel size is like 64 (becasue 1mb + 64kb is what you can access in rm), it only loads like 50kb right now though.

HTH
Attachments
NOFSboot.asm
(7.87 KiB) Downloaded 111 times
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

move_kernel:
mov esi, 0x00008000
mov edi, 0x00100000
mov ecx,( 0C800h + 3) / 4
rep movsd
breaks things and resets bochs?

@bubach: i dont see how you kernel gets to 0x00100000?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Post by bubach »

it starts loading at the beginning of realmode segment 0xffff which is at 1mb, so you can load 64kb after 1mb without going into unreal mode.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

GLNeo wrote:[ code ] breaks things and resets bochs?
you should be aware of the position-dependent forms: A normal jump is relative: if you do that here you end up executing in the wrong kernel image.
From my kernel:

Code: Select all

kernelimagestart:       
                        MOV ESI, 0x80000
                        MOV EDI, 0x100000
                        MOV ECX, kernelimagesize
                        CLD
                        REP MOVSB
                        MOV EAX, kernelentry
                        JMP EAX
then load your kernel at 0x8000:0000 (like my bootloader) and link your kernel at 1MB, and call the entry point at flat:0x80000 (if you load your kernel at 0x0000:8000, change the ESI value and entry point address accordingly)
bubach wrote:it starts loading at the beginning of realmode segment 0xffff which is at 1mb, so you can load 64kb after 1mb without going into unreal mode
Beware that a20 must be enabled at this point - theres some material on this in the wiki you should probably read.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

what would happen if i did this:

Code: Select all

jmp kernel_load:

LoadSectors:
            push ax
            push bx
            push cx
            mov dl, 12h
            div dl
            inc ah
            mov cl, ah
            mov dh, al
            and dh, 01h
            shr al, 1
            mov ch, al
            mov dl, 00h
            Read:
                mov ah, 02h
                mov al, 01h
                int 13h
                jc Read
            pop cx
            pop bx
            pop ax
            add bx, 0200h
            inc ax
            loop LoadSectors
            ret

kernel_load:
            mov ax, 0xffff
            mov es, ax
            mov bx, 0x0000
            mov ax, 1
            mov cx, 60
            call LoadSectors

[When in PMODE]

kernel:
            jmp 08h:100000h

bochs gives me:

Code: Select all

00005852715p[CPU  ] >>PANIC<< prefetch: running in bogus memory
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

bubach wrote:it starts loading at the beginning of realmode segment 0xffff which is at 1mb, so you can load 64kb after 1mb without going into unreal mode.
well actually 0xFFFF segment is short 16 bytes of 1 MiB so i hope that you take this into account and indeed the A20 line should be on. This is not a problem in bochs as it has the a20 by default(submitted a bug report for this). If the a20 line is not on the address wrap to 0 and that means you will overwrite the interruptvector table and the bios area.
GLneo wrote:bochs gives me: Code:
00005852715p[CPU ] >>PANIC<< prefetch: running in bogus memory
this means that the protected mode problably didn't take well. try copying the byte 0xC3 to the location where your kernel starts and instead of jumping to it make a call. if this works then it is related to your kernel.

Code: Select all

ljmp $8:label
label:
mov $10000h, %eax
call  *%eax
Author of COBOS
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

os64dev wrote: well actually 0xFFFF segment is short 16 bytes of 1 MiB so i hope that you take this into account
so i should do this:

Code: Select all

kernel_load:
            mov ax, 0xFFFF
            mov es, ax
            mov bx, 0x0010
            mov ax, 1
            mov cx, 60
            call LoadSectors
this allso doesn't work

p.s. my kernel started before the move from 0x1000 to 1MB point so it enters PMODE just fine( i think )
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

the following may sound lame but i have a vague memory about the same error:
- did you turn off interrupts before switching to pmode or did you setup an idt.
- is you kernel compiled with origin at 1Mib.

i just looked at you code and you seem to be missing the gdt entry for a code segement. you are jumping to a data segment which would explain the error.
Author of COBOS
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

my boot sector works,

i just want to know how to put my kernel at 0x100000 and jmp to it.

my boot sector works for 0x8000, but not for 0x100000

how (mabey some code) do i get this: http://lemonos.cvs.sourceforge.net/lemo ... iew=markup
to load my kernel to 0x100000?

thx
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

well you can copy the stuff you loaded at 0x8000 to 1 Mib after jumping to protected mode, that should do the trick. sorry i only know at&t syntax.
problably the rep stosl is faster but you'll get the idea.

Code: Select all

movl    $0x080000, %esi;
movl    $0x100000, %edi;
movl    $0x007800, %ecx; //- 60 sectors at 512 bytes.
copy_loop:
movl    (%esi), %edx;
movl    %edx, (%edi);
addl    $4, %esi;
addl    $4, %edi;
subl    $4, %ecx;
cmpl    $0, %ecx;
jne     copy_loop;
and remember to compile the kernel at $100000 and enable the address line a20, if you wish to do the a20 later maybe use $200000 but i think pmode requires a20.
Author of COBOS
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

this code works only when the A20 is NOT enabled!?!?!? on bochs it fails, then on qemu it works, then i enable the A20 and i doesnt, bochs the A20 is always on, so it only works when the A20 is off? mabey it rolls over to a working spot in memory? help!

thx
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

i think i fixed it, at the end of my a20 sector i jumped past my loader code :oops: , know it works on qemu (not on bochs)
Post Reply