www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2008/01/19/22:30:33

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: YinMinHong AT gmail DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Enable Protect Mode & Run C Programs?
Date: Sat, 19 Jan 2008 19:24:49 -0800 (PST)
Organization: http://groups.google.com
Lines: 68
Message-ID: <c7638072-c4b7-4703-a31b-4fe4eae4b6bb@v17g2000hsa.googlegroups.com>
NNTP-Posting-Host: 123.165.34.164
Mime-Version: 1.0
X-Trace: posting.google.com 1200799489 15527 127.0.0.1 (20 Jan 2008 03:24:49 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: Sun, 20 Jan 2008 03:24:49 +0000 (UTC)
Complaints-To: groups-abuse AT google DOT com
Injection-Info: v17g2000hsa.googlegroups.com; posting-host=123.165.34.164;
posting-account=KuGQCQoAAAA0uzk636an2UcfiyRRtg0H
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1),gzip(gfe),gzip(gfe)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 $
------------------------------------------------------------------------------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019