User:Alexander/Combining Bran's Kernel Development and the Barebones Tutorials: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
Content added Content deleted
(Create Page)
 
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:In Progress}}
{{Template:In Progress}}
<!--{{Rating|1}}-->
{{
{{Rating|1}}
This guide is aimed to help you combine the [http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial 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
This guide is aimed to help you combine the [http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial 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 ==
== 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.
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 ==
== The Basic Kernel ==
Line 21: Line 18:
== Creating Main and Linking C Sources ==
== Creating Main and Linking C Sources ==
The tutorial wants you to add:
The tutorial wants you to add:
<source lang="asm">
<syntaxhighlight lang="asm">
extern _main
extern _main
call _main
call _main
</syntaxhighlight>
</source>
into the correct place in your start.asm file. Use this instead:
into the correct place in your start.asm file. Use this instead:
<source lang="asm">
<syntaxhighlight lang="asm">
extern main
extern main
call main
call main
</syntaxhighlight>
</source>
Compiling the C sources in this tutorial should be done with:
Compiling the C sources in this tutorial should be done with:
<pre>
<pre>
Line 38: Line 35:
== Printing to the screen ==
== Printing to the screen ==
I recommend you use the terminal/vga functions from the [[Barebones]] tutorial. You can use Bran's <code>cls()</code>, <code>move_csr()</code> and <code>scroll()</code> functions as long as you replace <code>csr_x</code> and <code>csr_y</code> to <code>terminal_column</code> and <code>terminal_row</code>. You also want to make sure you have a global <code>unsigned short *textmemptr</code> and you set it's adress in your <code>terminal_initialize</code> by adding this line:
I recommend you use the terminal/vga functions from the [[Barebones]] tutorial. You can use Bran's <code>cls()</code>, <code>move_csr()</code> and <code>scroll()</code> functions as long as you replace <code>csr_x</code> and <code>csr_y</code> to <code>terminal_column</code> and <code>terminal_row</code>. You also want to make sure you have a global <code>unsigned short *textmemptr</code> and you set it's adress in your <code>terminal_initialize</code> by adding this line:
<source lang="c">textmemptr = (unsigned short *)0xB8000;</source>
<syntaxhighlight lang="c">textmemptr = (unsigned short *)0xB8000;</syntaxhighlight>


== The GDT ==
== The GDT ==
Line 54: Line 51:
== The PIT: A System Clock ==
== The PIT: A System Clock ==
Make sure you replace:
Make sure you replace:
<source lang="c">
<syntaxhighlight lang="c">
int timer_ticks = 0;
int timer_ticks = 0;
</syntaxhighlight>
</source>
with:
with:
<source lang="c">
<syntaxhighlight lang="c">
volatile in timer_ticks = 0;
volatile int timer_ticks = 0;
</syntaxhighlight>
</source>
And that you also replace:
And that you also replace:
<source lang="c">
<syntaxhighlight lang="c">
irq_install_handler(0, timer_handler);
irq_install_handler(0, timer_handler);
</syntaxhighlight>
</source>
with:
with:
<source lang="c">
<syntaxhighlight lang="c">
irq_install_handler(0, (unsigned) timer_handler);
irq_install_handler(0, (unsigned) timer_handler);
</syntaxhighlight>
</source>
To preserve power when waiting with the <code>timer_wait()</code> function you can replace:
To preserve power when waiting with the <code>timer_wait()</code> function you can replace:
<source lang="c">
<syntaxhighlight lang="c">
while(timer_ticks < eticks);
while(timer_ticks < eticks);
</syntaxhighlight>
</source>
with:
with:
<source lang="c">
<syntaxhighlight lang="c">
while(timer_ticks < eticks)__asm__ __volatile__("hlt");
while(timer_ticks < eticks) {
__asm__ __volatile__("hlt");
</source>
}
</syntaxhighlight>

Latest revision as of 07:08, 9 June 2024

This page is a work in progress.
This page 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");
}