User:Alexander/Combining Bran's Kernel Development and the Barebones Tutorials
This page or section is a work in progress and may thus be incomplete. Its content may be changed in the near future. |
This guide is aimed to help you combine the Bran's Kernel Development and the Barebones tutorials. This way you get the more modern gcc arguments, etc. and the clear explanation of interupts and nasm syntax assembly. This guide will also implement the fixes found in Bran's Known Bugs. It is recommended that you read both tutorials fully first as this guide will only tell you what to change some of the instructions in Bran's into. The sections of this guide are the same as the pages of Bran's tutorial
Getting Started
Make sure you are using a GCC Cross Compiler. Using DJGPP is not officially supported on newer systems than Windows XP. So sticking with the GCC Cross Compiler(i686) used in the Barebones tutorial is advised.
The Basic Kernel
In your buildscript change:
nasm -f aout -o start.o start.asm
into:
nasm -f elf -o start.o start.asm
Creating Main and Linking C Sources
The tutorial wants you to add:
extern _main
call _main
into the correct place in your start.asm file. Use this instead:
extern main
call main
Compiling the C sources in this tutorial should be done with:
gcc -I./include -c -o main.o main.c -std=gnu99 -ffreestanding -O2 -Wall -Wextra
of course replacing main.o and main.c.
Printing to the screen
I recommend you use the terminal/vga functions from the Barebones tutorial. You can use Bran's cls()
, move_csr()
and scroll()
functions as long as you replace csr_x
and csr_y
to terminal_column
and terminal_row
. You also want to make sure you have a global unsigned short *textmemptr
and you set it's adress in your terminal_initialize
by adding this line:
textmemptr = (unsigned short *)0xB8000;
The GDT
In the assembly snippet that you are adding to start.asm replace all identifiers starting with an underscore(_gp
, _gdt_flush
) to their equivalents without a prefixed underscore.(gp
, gdt_flush
)
The IDT
In the assembly snippet that you are adding to start.asm replace all identifiers starting with an underscore(_idtp
, _idt_load
) to their equivalents without a prefixed underscore.(idtp
, idt_load
)
Interrupt Service Routines
In the assembly snippet that you are adding to start.asm replace all identifiers starting with an underscore(_isr0
, _isr1
, etc., _fault_handler
) to their equivalents without a prefixed underscore.(isr0
, isr1
, etc., fault_handler
)
IRQs and PICs
In the assembly snippet that you are adding to start.asm replace all identifiers starting with an underscore(_irq0
, _irq1
, etc., _irq_handler
) to their equivalents without a prefixed underscore.(irq0
, irq1
, etc., irq_handler
)
The PIT: A System Clock
Make sure you replace:
int timer_ticks = 0;
with:
volatile int timer_ticks = 0;
And that you also replace:
irq_install_handler(0, timer_handler);
with:
irq_install_handler(0, (unsigned) timer_handler);
To preserve power when waiting with the timer_wait()
function you can replace:
while(timer_ticks < eticks);
with:
while(timer_ticks < eticks) {
__asm__ __volatile__("hlt");
}