Fasm-TCC BareBones
来源:互联网 发布:js中怎么定义二维数组 编辑:程序博客网 时间:2024/06/05 01:22
转自: http://wiki.osdev.org/Fasm-TCC_BareBones
The purpose of this article is to explain how to make a sample ELF kernel withFASM and Tiny C Compiler (aka TCC). TCC is a small and fast C compiler, which produces x86, x86_64 or ARM code, and generates PE or ELF executables. TCC is heading toward full ISOC99 compliance, and can compile itself, like FASM. Here are all features of TCC:
- TCC compiles C code about 9 times faster than GCC.
- TCC generates averagely optimized x86 code.
- TCC supports the ISO C99 standard (even if this support is not as complete as PCC).
- Under Linux, TCC can be used as a C interpreter (just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line).
- TCC has few dependencies. Only libc is required for its compilation.
- TCC includes a linker and an assembler (for x86 only).
Contents
- 1A small kernel example
- 1.1 start32.asm
- 1.2 kernel.c
- 2Compiling and linking
A small kernel example
This little example builds a small kernel in ELF format, which can be booted by Grub.
Note: The Windows version of TCC doesn't produces ELF executables, but only object files. You need to recompile TCC without PE support, if you want to use this tutorial on Windows.
start32.asm
; Tutorial: A small kernel with Fasm & TCC; By Tommy. format elf use32 ;; Equates;MULTIBOOT_PAGE_ALIGN equ (1 shl 0)MULTIBOOT_MEMORY_INFO equ (1 shl 1)MULTIBOOT_AOUT_KLUDGE equ (1 shl 16)MULTIBOOT_HEADER_MAGIC equ 0x1BADB002MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFOMULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) section '.text' executable;; Multiboot header;dd MULTIBOOT_HEADER_MAGICdd MULTIBOOT_HEADER_FLAGSdd MULTIBOOT_CHECKSUM ;; Kernel entry point.; public _start extrn kmain_start: ; Call the main kernel function. call kmain @@: jmp @b
kernel.c
/* Tutorial: A small kernel with Fasm & TCC * By Tommy. */ /* * Main kernel function. */voidkmain (void){ *((unsigned char *) 0xB8000) = 'H'; *((unsigned char *) 0xB8001) = 0x1F; *((unsigned char *) 0xB8002) = 'E'; *((unsigned char *) 0xB8003) = 0x1F; *((unsigned char *) 0xB8004) = 'L'; *((unsigned char *) 0xB8005) = 0x1F; *((unsigned char *) 0xB8006) = 'L'; *((unsigned char *) 0xB8007) = 0x1F; *((unsigned char *) 0xB8008) = 'O'; *((unsigned char *) 0xB8009) = 0x1F;}
Compiling and linking
Assemble start32.asm with:
fasm start32.asm
Compile kernel.c with:
tcc -c kernel.c
Then link the whole thing with:
tcc -nostdlib -Wl,-Ttext,0x100000 start32.o kernel.o -o kernel-i386.elf
That's all!
- Fasm-TCC BareBones
- FASM
- TCC
- Mel Barebones L-System
- fasm giveio
- fasm Ke386SetIoAccessMap
- TCC事务
- FASM v 1.67.25
- FASM练习代码
- Fasm Native for Examples
- seh to fasm 研究
- fasm 控制台多线程示例
- 汇编开发工具 fasm
- FASM汇编编译器
- Fasm操作数据库sqlite
- fasm DirectDraw test
- fasm driver 驱动编程
- FASM源代码分析01
- vi常用操作
- MySQL的information_schema数据库是什么,有什么作用
- typedef用法总结!很棒!!!
- sql知识
- win7管理方便
- Fasm-TCC BareBones
- IE6与其它浏览器的区别 .
- 成型的网络重复数据删除技术
- godaddy的TurboPanel (simple control panel)手动开启的位置
- 对“关于boost::condition的用法”文章的个人的分析
- Android中的单位
- SQL字符串操作函数小结
- RadGrid for ASP.NET AJAX
- MySQL性能优化的最佳21条经验