// activate keyboard
// if keyboard input buffer is full after 0xFFFF counters or does not
// response with ACK code, activation fails
if (kActivateKeyboard()) {
kPrintString(45, 12, "Pass");
// set Num Lock, Caps Lock, Scroll Lock off
kChangeKeyboardLED(FALSE, FALSE, FALSE);
}
else {
kPrintString(45, 12, "Fail");
while (1);
}
// Simple shell section
char vcTemp[2] = {0, };
BYTE bFlags;
BYTE bTemp;
int i = 0;
while (TRUE) {
// if key is sent from keyboard
if (kIsOutputBufferFull()) {
bTemp = kGetKeyboardScanCode();
// convert scan code to ASCII code
if (kConvertScanCodeToASCIICode(bTemp, &(vcTemp[0]), &bFlags)) {
// print only when key is pressed. In other word,
// do not print when key is released
if (bFlags & KEY_FLAGS_DOWN) {
kPrintString(i++, 13, vcTemp);
}
}
}
}OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386:x86-64)
SECTIONS {
/* long mode code resides at 0x200000
* Instead of concatenating EntryPoint.bin with Kernel.bin, EntryPoint is
* also involved in the linking process
*/
.text 0x200000 : {
/* text section of Main file comes first in file*/
EntryPoint.o(.text)
Main.o(.text)
/* text section of other files comes after main in the order of input */
*(.text)
}
. = ALIGN(512);
/* as .rodata data comes here, operand of instruction that references to a
* data in .rodata is adjusted
*/
.rodata : {
*(.rodata)
}
. = ALIGN(512);
.data : {
*(.data)
}
. = ALIGN(512);
.bss : {
*(.bss)
}
/* discard all other sections in input files. If this is not specified,
* ld adds the sections somewhere in the program although instruction to
* add the sections is not in the script
*/
/DISCARD/ : {
*(*)
}
}
-
Because CPU keep checking PS/2 Controller by looping, it is waste of CPU time. From next chapter, the checking will be processed by
interrupt -
In the Keyboard.c, there are a lot of
duplicatecode. The code will be refactored later -
If you compile and run kernel without modifying linker script, kernel
rebootwhen you hit a key. This is because linker script discarded .bss and .data sections when linking. This means that some code references wrong address and some data is inserted into image file. To solve the problem, It is required to involve .bss and .data section into program.
-
Memory Layout up to CH11
- start(inclusive) ~ end(exclusive)
- 0x00000 ~ 0x00400 (Interrupt Vector Table)
- 0x07C00 ~ 0x07E00 (Bootloader)
- 0x07E00 ~ 0x10000 (Stack for real mode and protected mode)
- 0x10000 ~ 0x10400 (32 bit code of OS; EntryPoint.S + Main.c + ...)
- 0xA0000 ~ ... (video memory for graphic mode)
- 0xB8000 ~ ... (video memory for text mode)
- 0x100000(1MB) ~ 0x142000(1MB+264KB) (IA-32 mode page table tree structure)
- 0x200000(2MB) ~ ... (64 bit code of OS; EntryPoint.S + Main.c + ...)
- 0x600000(6MB) ~ 0x6FFFFF(7MB) (Stack for long mode)