how run c program in protect mode with out OS

Y

YinMinHong

Now, the situation is I have two program, one is bootloader, it run
in
a floppy disk at 0x7c00, it works greak, it function is load the fd's
second and third sector into memory(2nd sector at 0x8000, 3rd sector
at 0x9000), the code at 0x8000 is used for enable the protect mode,
after that, GD-CODE segment in GDT is from 0 to 4GB, GD-DATA is same,
too. Then jump to 0x9000 and execute my program was loaded from fd's
3rd sector. I want to run a C-compiled program, is it's format must
be
'32bit plain binary file', and I'm using gcc, ld, objcopy to make it.

gcc -c test.c
ld test -o test.o -e my -Ttext 0x9000 -i
objcopy test.o test.bin -R .note -R .comment -S -O binary


the complete C code is here:
---------------------------------------------------------------------------­-------------------------------------------
void my()
{
unsigned char *vm=(unsigned char *)0xb8000;
*(vm++)='a';
*(vm++)=0xc;
*(vm++)=0xc;
*(vm++)='d';
while(1);


}


---------------------------------------------------------------------------­--------------------------------------------
it doesn't work~~!
and my assemble file works fine.

code is here:


(nasm)
---------------------------------------------------------------------------­----------------------------------------------
bits 32
org 09000h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;­;;;;;;;;
mov edi, (80 * 0 + 0) * 2 + 0b8000h
mov ah, 0Ch
mov al, 'a'
mov [ds:edi], ax


mov edi, (80 * 0 + 1) * 2 + 0b8000h
mov ah, 0Ch
mov al, 'b'
mov [ds:edi], ax


mov edi, (80 * 0 + 2) * 2 + 0b8000h
mov ah, 0Ch
mov al, 'c'
mov [ds:edi], ax


mov edi, (80 * 0 + 3) * 2 + 0b8000h
mov ah, 0Ch
mov al, 'd'
mov [ds:edi], ax


mov edi, (80 * 0 + 4) * 2 + 0b8000h
mov ah, 0Ch
mov al, 'e'
mov [ds:edi], ax


mov edi, (80 * 0 + 5) * 2 + 0b8000h
mov ah, 0Ch
mov al, 'f'
mov [ds:edi], ax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;­;;;;;;;;;;;


jmp $
---------------------------------------------------------------------------­---------------------------------------------------------------
 
S

santosh

sorry to everyone, it works well.
i made some serious mistakes.

Free standing, platform specific code is perhaps more topical for
alt.os.development or comp.arch and perhaps alt.lang.asm. This group is
primarily for Standard C which is usually inadequate for such purposes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top