Page 1 of 1

How to boot Kolibri in protected mode?

Posted: Mon Dec 11, 2023 3:38 am
by bzt
Hi,

I'm trying to write a boot loader for KolibriOS. It already works in real mode on BIOS, but I also want to support UEFI, so I'm trying to start the Kolibri kernel in protected mode (related topic).

The kernel boots fine, it can use the lfb, memory is detected correctly, everything seems to be working, but then it cannot start the launcher.
kolibriboot.png
kolibriboot.png (3 KiB)
Viewed 903 times
What I have:

GDT:

Code: Select all

gdt[0x0008]=Code segment, base=0x00000000, limit=0xffffffff, Execute/Read, Non-Conforming, Accessed, 32-bit
gdt[0x0010]=Data segment, base=0x00000000, limit=0xffffffff, Read/Write
gdt[0x0018]=Code segment, base=0x00000000, limit=0xffffffff, Execute/Read, Non-Conforming, 64-bit
KERNEL.MNT (loaded at 10000h), detected prot mode entry point:

Code: Select all

0008:0000000000011a78 (unk. ctxt): mov ax, 0x0010 
KOLIBRI.IMG loaded at 100000h:

Code: Select all

0x0000000000100000 <bogus+       0>: \xEB  <   \x90  K    O    L    I    B  
0x0000000000100008 <bogus+       8>:  R    I        \0   \2   \1   \1   \0  
0x0000000000100010 <bogus+      16>: \2   \xE0 \0    @   \x0B \xF0 \9   \0  
0x0000000000100018 <bogus+      24>: \x12 \0   \2   \0   \0   \0   \0   \0  
0x0000000000100020 <bogus+      32>: \0   \0   \0   \0   \0   \0    )   \0  
0x0000000000100028 <bogus+      40>: \0   \0   \0    K    O    L    I    B  
0x0000000000100030 <bogus+      48>:  R    I                        F    A  
0x0000000000100038 <bogus+      56>:  T    1    2                  \xFC  1  
BOOT_LO constructed at 9000h:

Code: Select all

0x0000000000009000 <bogus+       0>:	0x20	0x80	0x0c	0x00	0x00	0x00	0x00	0x00
0x0000000000009008 <bogus+       8>:	0x00	0x00	0x20	0x03	0x58	0x02	0x00	0x00
0x0000000000009010 <bogus+      16>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009018 <bogus+      24>:	0x00	0x00	0x00	0xe0	0x00	0x01	0x00	0x02
0x0000000000009020 <bogus+      32>:	0x01	0xfe	0x00	0x03	0x00	0x00	0x00	0x00
0x0000000000009028 <bogus+      40>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009030 <bogus+      48>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009038 <bogus+      56>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009040 <bogus+      64>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009048 <bogus+      72>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009050 <bogus+      80>:	0x00	0x00	0x00	0x00	0x00	0x00	0x03	0x00
0x0000000000009058 <bogus+      88>:	0x00	0x00	0x72	0x30	0xc8	0x06	0x02	0x00
0x0000000000009060 <bogus+      96>:	0x2f	0x72	0x64	0x2f	0x30	0x2f	0x00	0x00
0x0000000000009068 <bogus+     104>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009070 <bogus+     112>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009078 <bogus+     120>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009080 <bogus+     128>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009088 <bogus+     136>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009090 <bogus+     144>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009098 <bogus+     152>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090a0 <bogus+     160>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090a8 <bogus+     168>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090b0 <bogus+     176>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090b8 <bogus+     184>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090c0 <bogus+     192>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090c8 <bogus+     200>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090d0 <bogus+     208>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090d8 <bogus+     216>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090e0 <bogus+     224>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090e8 <bogus+     232>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090f0 <bogus+     240>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x00000000000090f8 <bogus+     248>:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009100 <bogus+     256>:	0x06	0x00	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009108 <bogus+     264>:	0x00	0x00	0x00	0x00	0x00	0xf0	0x09	0x00
0x0000000000009110 <bogus+     272>:	0x00	0x00	0x00	0x00	0x01	0x00	0x00	0x00
0x0000000000009118 <bogus+     280>:	0x00	0xf0	0x09	0x00	0x00	0x00	0x00	0x00
0x0000000000009120 <bogus+     288>:	0x00	0x10	0x00	0x00	0x00	0x00	0x00	0x00
0x0000000000009128 <bogus+     296>:	0x02	0x00	0x00	0x00	0x00	0x80	0x0e	0x00
0x0000000000009130 <bogus+     304>:	0x00	0x00	0x00	0x00	0x00	0x80	0x01	0x00
0x0000000000009138 <bogus+     312>:	0x00	0x00	0x00	0x00	0x02	0x00	0x00	0x00
0x0000000000009140 <bogus+     320>:	0x00	0x00	0x10	0x00	0x00	0x00	0x00	0x00
0x0000000000009148 <bogus+     328>:	0x00	0x00	0xef	0x07	0x00	0x00	0x00	0x00
0x0000000000009150 <bogus+     336>:	0x01	0x00	0x00	0x00	0x00	0x00	0xff	0x07
0x0000000000009158 <bogus+     344>:	0x00	0x00	0x00	0x00	0x00	0x00	0x01	0x00
0x0000000000009160 <bogus+     352>:	0x00	0x00	0x00	0x00	0x03	0x00	0x00	0x00
0x0000000000009168 <bogus+     360>:	0x00	0x00	0xfc	0xff	0x00	0x00	0x00	0x00
0x0000000000009170 <bogus+     368>:	0x00	0x00	0x04	0x00	0x00	0x00	0x00	0x00
0x0000000000009178 <bogus+     376>:	0x02	0x00	0x00	0x00	0x00	0x00	0x00	0x00
In this latter, I have launcher_start = 1, rd_read_from = 3, sys_disk = r0, syspath = "/rd/0/".

What am I missing? Probably I have missed to set some fields in BOOT_LO, but I can't see what. Any ideas how to further debug this? Or do I have some obviously bad values in BOOT_LO perhaps?

The source is here (in theory C, but in reality two Assembly blocks). The first block is the one that tries to start KolibriOS in protected mode (not working), the second block starts it in real mode (that one works). Sorry about the AT&T syntax! Anyway this seems to be okay, I think the issue is in BOOT_LO.

Thanks,
bzt

Re: How to boot Kolibri in protected mode?

Posted: Mon Dec 11, 2023 9:11 am
by dunkaist
Hi bzt,

Thank you for your interest in KolibriOS.
bzt wrote: Mon Dec 11, 2023 3:38 am In this latter, I have launcher_start = 1, rd_read_from = 3, sys_disk = r0, syspath = "/rd/0/".

What am I missing?
You missed that partition numbers start from 1, not from 0. Perhaps, you missed it because rd is just rd, not rd0 like hd0 and other disks in KolibriOS. Yes, the ramdisk name is special and doesn't have any number at the end.

I managed to boot KolibriOS successfully with the following menu.cfg:

Code: Select all

framebuffer 1024 768 32
menuentry kolibrios
kernel kernel.mnt sysdisk=r1
module kolibri.img

Re: How to boot Kolibri in protected mode?

Posted: Mon Dec 11, 2023 7:14 pm
by bzt
Ah, thank you so much, that was it!

Cheers,
bzt