i have found this code but djgpp spits errors at me these are the compile commands i was given:
nasm -f aout -o load.o load.asm
gcc -c -O2 -Wall -g -o hello.o hello.c
ld -o pm.com -oformat binary -Ttext=0x100 load.o hello.o /djgpp/lib/libc.a
this is the code:
;/****************************************************************************
; file load.asm
;****************************************************************************/
[SECTION .text]
[BITS 16]
[GLOBAL start]
start: xor ebx,ebx ; now in real mode (16-bit)
mov bx,cs
shl ebx,4
mov eax,ebx ; EAX=EBX=CS<<4
lea eax,[ebx]
mov [gdt2 + 2],ax ; set descriptor base address=EAX
mov [gdt3 + 2],ax
shr eax,16
mov [gdt2 + 4],al
mov [gdt3 + 4],al
mov [gdt2 + 7],ah
mov [gdt3 + 7],ah
lea eax,[ebx + gdt] ; point gdt_ptr to the gdt
mov [gdt_ptr + 2],eax ; EAX=linear address of gdt
push dword 0 ; zero EFLAGS (interrupts off,
popfd ; IOPL=0, NT bit=0)
lgdt [gdt_ptr]
mov eax,cr0
or al,1
mov cr0,eax
jmp SYS_CODE_SEL:do_pm
[BITS 32]
do_pm: mov ax,SYS_DATA_SEL ; now in 32-bit pmode
mov ds,eax ; EAX works, one byte smaller
mov ss,eax
nop
mov es,eax
mov fs,eax
mov gs,eax
xor eax,eax ; zero top 16 bits of ESP
mov ax,sp
mov esp,eax
[EXTERN _main]
call _main ; call C code
jmp $ ; freeze
[SECTION .data]
; null descriptor
gdt: dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; linear data segment descriptor
LINEAR_SEL equ $-gdt
dw 0xFFFF ; limit 0xFFFFF (1 meg? 4 gig?)
dw 0 ; base for this one is always 0
db 0
db 0x92 ; present,ring 0,data,expand-up,writable
db 0xCF ; page-granular (4 gig limit), 32-bit
db 0
; code segment descriptor
SYS_CODE_SEL equ $-gdt
gdt2: dw 0xFFFF
dw 0 ; (base gets set above)
db 0
db 0x9A ; present,ring 0,code,non-conforming,readable
db 0xCF
db 0
; data segment descriptor
SYS_DATA_SEL equ $-gdt
gdt3: dw 0xFFFF
dw 0 ; (base gets set above)
db 0
db 0x92 ; present,ring 0,data,expand-up,writable
db 0xCF
db 0
gdt_end:
gdt_ptr:
dw gdt_end - gdt - 1 ; GDT limit
dd gdt ; linear, physical address of GDT
;/****************************************************************************
; file hello.c
;****************************************************************************/
#include /* movedata() */
#define LINEAR_SEL 0x08
#define SYS_DATA_SEL 0x18
int main(void)
{
const char Msg[] = "h e l l o ";
movedata(SYS_DATA_SEL, (unsigned)Msg,
LINEAR_SEL, 0xB8000,
sizeof(Msg));
return 0;
}
compiling problem
RE:compiling problem
It would help a lot, if you paste what the compiler spits out.
Anton.
Anton.
RE:compiling problem
i have it compiling now but it dose not seem to boot.
is there any nasm djgpp pmode demo and bootloader i could look at
to see the best way for it to be done.
regrads leon pegg
is there any nasm djgpp pmode demo and bootloader i could look at
to see the best way for it to be done.
regrads leon pegg