Alright, so, my 2nd Stage Boot Loader is up. The A20 and Protected Mode are enabled. Lets consider the following snippet from it (we are in PMode already):
Code: Select all
BITS 32
Code32:
MOV AX,16
MOV DS,AX
MOV ES,AX
MOV FS,AX
MOV GS,AX
MOV SS,AX
MOV ESP,0x9FFFF
;Load Kernel binary file from HD to "X" (X is some physical address in RAM)
;JMP 8:X
The kernel:
Code: Select all
void kmain()
{
unsigned char *videoram = (unsigned char *) 0xb8000;
videoram[0] = 65;
videoram[1] = 0x07;
}
1. If I CAN'T rely on it, then as far as I understand here comes "loader.s" in Bare Bones tutorial to solve this problem, because assembly's binary output is much more tunable, right? Therefore, by linking assembly "loader.o" and "kernel.o" I will get Kernel binary file with the first instruction on label "loader:" so jumping to 8:X will 100% execute it?
2. If I CAN rely on it, then it is probably linker, who can put "kmain" at the beginning of Kernel binary file. Since linker script contains "ENTRY(...)" directive. What if I just put "kmain" there? Then after jumping to 8:X will I 100% execute "kmain"?
Now I have several questions about linker. Consider the following linker script:
Code: Select all
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
Code: Select all
. = 0x00100000;
Code: Select all
ALIGN (0x1000)
1 KB of text
3 KB of some garbage (maybe zeroes)
1 KB of rodata
3 KB of some garbage (maybe zeroes)
1 KB of data
3 KB of some garbage (maybe zeroes)
1 KB of bss
3 KB of some garbage (maybe zeroes)
I believe, this is the only way to align. Am I right?
Here goes one more similar question about the .bss section in general. Look:
Code: Select all
section .bss
resb STACKSIZE
I think that's all for now. Thanks in advance guys and sorry for long post again.