Page 1 of 1
The best place for kernel and loader
Posted: Wed Aug 02, 2006 2:21 pm
by Lorax
As an ex-osdeveloper(near past - 2003), I decided to rewrite/revise my ex-code.
As I left, my os's bootsector loads all kernel to 9000h. Now, I change my mind
and want to seperate 32bit code and 16bit code. Ill use nasm for both 16-32 bit
asm parts, TCC for 16bit code, GCC for 32bit code. My boot sector will load 16bit
and 32bit binary files to their locations and jump 16bit part.This part will do
all the 16 bit stuff, like some hardware check, some initializations, some bios
issues, pci issues, fdc, hdd etc. Then jump to 32bit kernel and its job will over.
And now for the memory places for os. Those are all the reserved memory places as
I remember and find.
00000000 -> Int vec table (And Ill be glad if someone explain the place for these
interrupts.I mean this is a jump table and where is the jumped code resides?)
XXXX:0000 - a000:0000 -> Extended bios data area (I dont know where it starts)
A000:0h - FFFF:F Video Memory, External ROM code, rom related memory..
These are all I know (If another place exists, please warn).
I use fat12 as file system. So I need some place to load fat, directory table, my 16bit code
part and 32bit code part. I decided to place:
DirectoryTable ........................ 6000h - 7c00h ( 1c00h ) (224*32)
Boot sector ........................... 7C00h - 7E00h ( 200h )
FAT ................................... 7E00h - 8E00h ( 1200h ) (9 * 512)
But cant decide place for kernel parts. I think 10000h is a traditional place to load kernel.
Where do you - most people - load their kernels (and why - if there is a reason)? What
should be the factors when deciding the kernel place? Is there any other memory area under 1mb
should not be changed? Is my place for fat and directory table >good< or where is the
traditional place for them?
Any answer/comment appreciated. Thanks from now...
Re:The best place for kernel and loader
Posted: Wed Aug 02, 2006 3:38 pm
by bubach
I had this mem-map in my old bootsector:
[tt]; 16-bit mem map (seg:off)
; 0x0000:0x0000 -> 0x0000:0x0500 BIOS stuff
; 0x0000:0x0500 -> 0x0000:0x2100 FAT12 rootdir
; 0x0000:0x2100 -> 0x0000:0x3300 FAT for FAT12
; 0x0000:0x3300 -> 0x0000:0x6c00 14,25kb free space
; 0x0000:0x6c00 -> 0x0000:0x7400 IDT, 256 descriptors
; 0x0000:0x7400 -> 0x0000:0x7c00 GDT, 256 descriptors
; 0x0000:0x7c00 -> 0x0000:0x7e00 bootsector
; 0x0000:0x7e00 <- 0x0000:0xffff ~32,5kb stack for boot
; 0x1000:0x0000 -> 0x9000:0xffff 576kb kernel/free space
; 0xa000:0x0000 -> ............. VGA mem etc.[/tt]
But as you can see, it says that everything from 0x9000:0x0000->0x9000:0xFFFF is free.. So it might not be 100% true, but i posted it to show you where I used to load stuff.
This is from the OS-FAQ:
[tt] start end size region/exception description
Low Memory (the first MiB)
00000000 - 000003FF 400 RAM Real-Mode IVT (Interrupt Vector Table)
00000400 - 000004FF 100 RAM BDA (BIOS data area)
00000500 - 0009FBFF ? 9F700 RAM/free for use Conventional memory (<= 9F700 Byte)
00007C00 - 00007DFF 200 RAM Operating System BootSector
0009FC00 - 0009FFFF 400 RAM EBDA (Extended BIOS data area)
000A0000 - 000FFFFF 60000 various ROM Area (384 KiB)
Standard usage of the ROM Area:
000A0000 - 000BFFFF 20000 video RAM VGA Mem (128 KiB)
000A0000 - 000AFFFF 10000 video RAM VGA framebuffer (64 KiB)
000B0000 - 000B7FFF 8000 video RAM text monochrom (32 KiB)
000B8000 - 000BFFFF 8000 video RAM text color (32 KiB)
000C0000 - 000C7FFF 8000 ROM Video BIOS* (32 KiB is typical size)
000F0000 - 000FFFFF 10000 ROM Motherboard BIOS* (64 KiB is typical size)
High Memory (everything after the first MiB)
00100000 - FEBFFFFF FEB00000 RAM?/free for use? Extended memory
01000000 - 010FFFFF 100000 ? ISA 15-16MB (only with ISA bus?)
FEC00000 - FFFFFFFF 1400000 various PnP NVRAM?, LAPIC, ...[/tt]
Re:The best place for kernel and loader
Posted: Thu Aug 03, 2006 2:46 am
by Lorax
I tried to avoid using memory reagon near bios stuff (int.vect.table). Anyway, where is the jumped-codes of interrupts? And as for an another question, do you move idt and gdt later to upper memory place? If so why?
Re:The best place for kernel and loader
Posted: Fri Aug 04, 2006 9:06 am
by JAAman
Lorax wrote:
Anyway, where is the jumped-codes of interrupts?
as an OSdever, you can be reasonably certain that on boot, they all point somewhere in the ROM locations (some will point to BIOS code, and others to other ROM chips), but they can point to different addresses on different systems (depending on BIOS, video, and other devices)
Re:The best place for kernel and loader
Posted: Fri Aug 04, 2006 12:46 pm
by Lorax
Yeah, I can guess that they are some ROM code and mapped somewhere in memory. And I can guess somewhere after video memory and before POST bootcode. But there is a memory smaller than 100k to handle all 256 interrupts. So little area per interrupt (Nearly 400 byte). With technology the hardwares change, and so I guess also the interrupt codes for that hardwares change although the interfaces (vectors) stay same. So what am I asking is if some other memory also reserved for this?
Anyway thanks for your reply. And Ill be glad if you-and others- also mention a little with your memory maps.
Re:The best place for kernel and loader
Posted: Fri Aug 04, 2006 7:22 pm
by blip
By far, most interrupts are handled with a simple IRET or something a little longer, that or the vector points to 0:0. A lot of default hardware IRQ handlers simply acknowledge the IRQ at the PIC, with the exception of the PIT, keyboard, IDE, FDC, etc. CPU exceptions are usually handled in a legacy manner, like the invalid opcode handler emulating LOADALL286 and a few others, and if none of those then it acts like an 8088/6 and increments the IP of the faulting program by 1.
It is also possible that some interrupt code may not be in ROM. One possible scenario is a virus that infects the boot HD's MBR to cause it to load the portion of itself residing in the first cylinder before the first partition begins, to the top of conventional memory.
In the BDA at address 0:413h there is a word that specifies conventional memory size in kilobytes, and this is how it knows where to load itself and it would also decrement the value by its own size to prevent anything from attempting to use the area it is in. (I think the EBDA is accounted for in this.) It could then proceed to hook any interrupts it wishes, so this would be much like a DOS TSR.
I think something similar happens when you use drive overlay things, and one could for example create a boot floppy that hooks INT 13h to provide access past the ~8GB limit on older machines. I have also heard of some computers that have less than 640KB of conventional memory but have more past the 1MB mark.
Re:The best place for kernel and loader
Posted: Mon Aug 07, 2006 8:54 am
by Lorax
As for my first question, the kernel place.... I decided my memory map to be like this:
0x0000:0x0000 -> 0x0000:0x0500 BIOS stuff
0x0000:0x0500 -> 0x0000:0x2500 GDT (256*32)
0x0000:0x2500 -> 0x0000:0x4500 IDT (256*32)
0x0000:0x4500 -> 0x0000:0x7c00 RootDirectory (may reside up to 440 file)
0x0000:0x7c00 -> 0x0000:0x7e00 BootCode
0x0000:0x7e00 -> 0x0000:0x8000 Stack for BootCode
0x0000:0x8000 -> 0x0000:0x9000 OS Global Data
0x0000:0x9000 -> 0x1000:0x0000 FAT (Nearly 28k for fat)
0x1000:0x0000 -> 0xa000:0x0000 Place for kernel
...
I give place for fat and directory table bigger than need. I found max fat area is about 6kb but dont find what should be the rootdirectory memory area size. I think 512 byte is enough for boot code stack. May be idt and gdt may be smaller but no need extra space so I gave them full size memory area.
Stay safe...
Re:The best place for kernel and loader
Posted: Tue Aug 08, 2006 10:35 am
by Candy
Lorax wrote:
I give place for fat and directory table bigger than need. I found max fat area is about 6kb but dont find what should be the rootdirectory memory area size. I think 512 byte is enough for boot code stack. May be idt and gdt may be smaller but no need extra space so I gave them full size memory area.
For mathematical limits, use your calculator and your head, not a wet finger in the wind.
12 bit fat has at most 4085 entries. 4085 entries times 1.5 byte per entry equals 6127.5 bytes, which always is smaller than 6kb.
16 bit fat has at most 65525 entries, which are each 2 bytes. This makes a total of 131050 bytes, which is about 128kb.
28 bit fat (FAT32) has at most 2^28 - 11 entries, each 4 bytes in size. This gives a maximum size of 1GB.
Re:The best place for kernel and loader
Posted: Wed Aug 09, 2006 2:28 am
by Lorax
Candy wrote:
For mathematical limits, use your calculator and your head, not a wet finger in the wind.
12 bit fat has at most 4085 entries. 4085 entries times 1.5 byte per entry equals 6127.5 bytes, which always is smaller than 6kb.
Yeah as I said - but forgotten to emphesize type of fat - about max 6kb for fat (fat12).
BTW, is there any specification - or calculater & mind arithmetic - for max count of root directory entries?
Re:The best place for kernel and loader
Posted: Wed Aug 09, 2006 9:27 am
by Candy
well, empirically there can be a maximum of 65535 root entries (since you only have a 16-bit variable). That directly limits it to 65536 * 32 = 2^16 * 2^5 = 2^21 = 2097152 bytes. Not practical however, since that's more than your entire floppy disk.
I have seen somewhere (I recall) that Microsoft disrecommends using more than 512, so I guess 512 is a safe limit. That boils down to 16kb of space. You'd need to search for my reference though, I'm not certain.
Re:The best place for kernel and loader
Posted: Wed Aug 09, 2006 3:14 pm
by JAAman
the normal values for MAX_ENTRIES is:
HDD 512
1.44MB 224
2.88MB 448
Jaz/Zip 512
LS-120 512
Sparq 512
----reference: Scott Mueller's "Upgrading and Repairing PC's" -11th edition, pg 1389
this should be the same for both FAT12 and FAT16 (though FAT32 has a variable root directory), i believe you would be safe with assuming a MAX_ENTRIES of no more than 512
@candy: i also remember hearing something like that, though i dont know where... mabey the FAT docs? not sure, and i dont have them availible atm to check