I tried to do that tutorial and the code failed too. Finally I did this.
Up vote 2 down vote favorite share g+ share fb share tw.
I am writing a simple kernel in C and ASM(to call assembly instructions generated by C compile). I am following this exelents articles from osdev.org. After read an kernel written in assembly and compiled and executed, it was worked fine, I see the kernel.
Bin running on qemu, fantastic. But I want really write it in C language, found an example in same web page an example in C I compiled it and tried run the kernel. Bin on qemu but I get "boot failed" from all devices: hard disk, floopd and CD-rom.
Then I disassembled the kernel. Bin generated by ks. O (kernel.
Asm assembled using nasm) and kernel. O(kernel. C assembled using gcc) assembled to bin file using the ld.
The kernel. Bin: pastebin.com/Y0pLFvij I can't see my string or any instruction to assembly write ny string on video. The c code that generate it: #define WHITE_TXT 0x07 // white on black text unsigned int k_printf(char *message, unsigned int line); void k_clear_screen(); k_main() { k_clear_screen(); k_printf("Hi!
\nHow's this for a starter OS? ", 0); }; unsigned int k_printf(char *message, unsigned int line) // the message and then the line # { char *vidmem = (char *) 0xb8000; unsigned int i=0; i=(line*80*2); while(*message! =0) { if(*message=='\n') // check for a new line { line++; i=(line*80*2); *message++; } else { vidmemi=*message; *message++; i++; vidmemi=WHITE_TXT; i++; }; }; return(1); }; void k_clear_screen() // clear the entire text screen { char *vidmem = (char *) 0xb8000; unsigned int i=0; while(i Ld `OUTPUT_FORMAT("binary") ENTRY(start) SECTIONS { .
Text 0x100000 : { code = . ; _code = . ; __code = .
; *(.text) . = ALIGN(4096); } . Data : { data = .
; _data = . ; __data = . ; *(.data) .
= ALIGN(4096); } . Bss : { bss = . ; _bss = .
; __bss = . ; *(.bss) . = ALIGN(4096); } end = .
; _end = . ; __end = . ; } and the makefile: ` bin: nasm -f aout -o ks.
O kernelbase. Asm gcc -Wall -c -o kernel. O kernel.
C ld -T link. Ld -o kernel. Bin ks.
O kernel. O run1: qemu kernel. Bin clear: rm -f *.
O cbin: rm -f *. Bin ` and the kernel in pure assembly, disassembled: http://pastebin.com/Bkvkq3YQ that worked fine for me. And I can see the instrutions to write on video.
My OS: Ubuntu 10.4 Compiler: gcc Assembler : NASM Where am I wrong? Any help is very appreciated. Thanks in advance.
C assembly kernel link|improve this question edited Mar 4 at 15:51 asked Mar 4 at 15:39Jack696110 74% accept rate.
There is code missing. The C code cannot possibly compile in that form. – Niklas B.
Mar 4 at 15:48 No, the C code is does not compile too well. Also, there are warnings. – Niklas B.
Mar 4 at 15:52 What do you think the difference is between C converted to asm then assembled and "really write it in C". Certainly gcc does this, you compile a c program it compiles to asm, then calls the assembler and linker for you. No difference (so long as you use the same compiler/assembler/linker, compile options, and linker script.
– dwelch Mar 4 at 16:09 @NiklasB. : how to remove this warnings? – Jack Mar 4 at 16:31 @dwelch:I know that there no difference, all is assembly.
When I say "Written in C" is uses C syntax and C compiler to make assembly. – Jack Mar 4 at 16:34.
I tried to do that tutorial and the code failed too. Finally I did this: Compile both files for 32 bit: nasm -f elf32 ks. Asm -o kernelbase.
O gcc -m32 -c kernel. C -o kernel. O And link: gcc -m32 kernelbase.
O kernel. O -o Kernel. Bin After a while I found out that I don't get any errors by using gcc for linking.
Hope I helped :-).
I removed it and was compiled successfully and I can see valid assembly output. Another question: have you tried run kernel. Bin?
I tried run it with qemu kernel. Bin but I get something like "boot failed" cannot found any device, then I liked it using ld: ld -T link. Ld -o kernel.
Bin kernelbase. O kernel. O , looks like a progress, it know the and show "Booting from hard disk" but never start the kernel.
Thanks very much, @XCoder. – Jack Mar 9 at 15:41 Sorry "-c" was my mistake I compiled it without the "-c". So far I haven't test it.
(no time) ;) – Xcoder Mar 9 at 16:01 I will to accept your answer. Thanks you, again! – Jack Mar 9 at 16:20.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.