TCC: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
No edit summary |
m Bot: Replace deprecated source tag with syntaxhighlight |
||
Line 111: | Line 111: | ||
===start32.asm=== |
===start32.asm=== |
||
< |
<syntaxhighlight lang="asm"> |
||
; Tutorial: A small kernel with Fasm & TCC |
; Tutorial: A small kernel with Fasm & TCC |
||
; By Tommy. |
; By Tommy. |
||
Line 149: | Line 149: | ||
jmp @b |
jmp @b |
||
</syntaxhighlight> |
|||
</source> |
|||
===kernel.c=== |
===kernel.c=== |
||
< |
<syntaxhighlight lang="c"> |
||
/* Tutorial: A small kernel with Fasm & TCC |
/* Tutorial: A small kernel with Fasm & TCC |
||
* By Tommy. |
* By Tommy. |
||
Line 175: | Line 175: | ||
} |
} |
||
</syntaxhighlight> |
|||
</source> |
|||
==Compiling and linking== |
==Compiling and linking== |
||
Assemble start32.asm with: |
Assemble start32.asm with: |
||
< |
<syntaxhighlight lang="bash"> |
||
fasm start32.asm |
fasm start32.asm |
||
</syntaxhighlight> |
|||
</source> |
|||
Compile kernel.c with: |
Compile kernel.c with: |
||
< |
<syntaxhighlight lang="bash"> |
||
tcc -c kernel.c |
tcc -c kernel.c |
||
</syntaxhighlight> |
|||
</source> |
|||
Then link the whole thing with: |
Then link the whole thing with: |
||
< |
<syntaxhighlight lang="bash"> |
||
tcc -nostdlib -Wl,-Ttext,0x100000 start32.o kernel.o -o kernel-i386.elf |
tcc -nostdlib -Wl,-Ttext,0x100000 start32.o kernel.o -o kernel-i386.elf |
||
</syntaxhighlight> |
|||
</source> |
|||
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: |
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: |
||
< |
<syntaxhighlight lang="bash"> |
||
tcc -nostdlib -Wl,-Ttext,0x100000 -Wl,--oformat,binary -static start32.o kernel.o -o kernel-i386.bin |
tcc -nostdlib -Wl,-Ttext,0x100000 -Wl,--oformat,binary -static start32.o kernel.o -o kernel-i386.bin |
||
</syntaxhighlight> |
|||
</source> |
|||
That's all! |
That's all! |
||
Line 202: | Line 202: | ||
==Inline Assembly== |
==Inline Assembly== |
||
TCC supports inline GAS syntax assembly like GCC: |
TCC supports inline GAS syntax assembly like GCC: |
||
< |
<syntaxhighlight lang="c"> |
||
__asm__ __volatile__("hlt"); |
__asm__ __volatile__("hlt"); |
||
</syntaxhighlight> |
|||
</source> |
|||
You can use this to your benefit for many things, such as debugging in Bochs: |
You can use this to your benefit for many things, such as debugging in Bochs: |
||
< |
<syntaxhighlight lang="c"> |
||
#define breakpoint() __asm__ __volatile__("xchg %bx, %bx"); |
#define breakpoint() __asm__ __volatile__("xchg %bx, %bx"); |
||
Line 216: | Line 216: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</source> |
|||
Then adding this to your bochsrc.bxrc file in a text editor: |
Then adding this to your bochsrc.bxrc file in a text editor: |
||
< |
<syntaxhighlight lang="text"> |
||
port_e9_hack: enabled=1 |
port_e9_hack: enabled=1 |
||
magic_break: enabled=1 |
magic_break: enabled=1 |
||
</syntaxhighlight> |
|||
</source> |
|||
And from boch's install location, executing bochsdbg.exe instead of bochs.exe. |
And from boch's install location, executing bochsdbg.exe instead of bochs.exe. |
||
Line 228: | 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. |
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: |
When creating structures, use something like this: |
||
< |
<syntaxhighlight lang="c"> |
||
// We use the attribute 'packed' to tell TCC not to change any of the alignment in the structure. |
// We use the attribute 'packed' to tell TCC not to change any of the alignment in the structure. |
||
struct some_struct { |
struct some_struct { |
||
Line 236: | Line 236: | ||
// This last attribute can be kept, it won't interfere with the compilation or output, so it may be |
// 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. |
// useful to retain compatilbity with GCC, as long as the above attributes don't interfere with GCC. |
||
</syntaxhighlight> |
|||
</source> |
|||
Instead of this: |
Instead of this: |
||
< |
<syntaxhighlight lang="c"> |
||
// We use the attribute 'packed' to tell GCC not to change any of the alignment in the structure. |
// We use the attribute 'packed' to tell GCC not to change any of the alignment in the structure. |
||
struct some_struct { |
struct some_struct { |
||
Line 244: | Line 244: | ||
unsigned char b; |
unsigned char b; |
||
} __attribute__((packed)); |
} __attribute__((packed)); |
||
</syntaxhighlight> |
|||
</source> |
|||