972
edits
[unchecked revision] | [unchecked revision] |
No edit summary |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
Line 111:
===start32.asm===
<
; Tutorial: A small kernel with Fasm & TCC
; By Tommy.
Line 149:
jmp @b
</syntaxhighlight>
===kernel.c===
<
/* Tutorial: A small kernel with Fasm & TCC
* By Tommy.
Line 175:
}
</syntaxhighlight>
==Compiling and linking==
Assemble start32.asm with:
<
fasm start32.asm
</syntaxhighlight>
Compile kernel.c with:
<
tcc -c kernel.c
</syntaxhighlight>
Then link the whole thing with:
<
tcc -nostdlib -Wl,-Ttext,0x100000 start32.o kernel.o -o kernel-i386.elf
</syntaxhighlight>
If you would prefer it in binary form, for example, if you're using your own bootloader that doesn't support ELF, link it with this:
<
tcc -nostdlib -Wl,-Ttext,0x100000 -Wl,--oformat,binary -static start32.o kernel.o -o kernel-i386.bin
</syntaxhighlight>
That's all!
Line 202:
==Inline Assembly==
TCC supports inline GAS syntax assembly like GCC:
<
__asm__ __volatile__("hlt");
</syntaxhighlight>
You can use this to your benefit for many things, such as debugging in Bochs:
<
#define breakpoint() __asm__ __volatile__("xchg %bx, %bx");
Line 216:
}
}
</syntaxhighlight>
Then adding this to your bochsrc.bxrc file in a text editor:
<
port_e9_hack: enabled=1
magic_break: enabled=1
</syntaxhighlight>
And from boch's install location, executing bochsdbg.exe instead of bochs.exe.
Line 228:
So if you use structs to store your GDT entries or GDTR, beware, you will encounter issues loading your GDT if you don't specify the packing of structures correctly.
When creating structures, use something like this:
<
// We use the attribute 'packed' to tell TCC not to change any of the alignment in the structure.
struct some_struct {
Line 236:
// This last attribute can be kept, it won't interfere with the compilation or output, so it may be
// useful to retain compatilbity with GCC, as long as the above attributes don't interfere with GCC.
</syntaxhighlight>
Instead of this:
<
// We use the attribute 'packed' to tell GCC not to change any of the alignment in the structure.
struct some_struct {
Line 244:
unsigned char b;
} __attribute__((packed));
</syntaxhighlight>
|