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