Thank you for answer.
Code: Select all
// this function is in physical addr 0x0A00 ~ 0x1000.
// inline asm is turbo asm.
// C compiler is Borland C++ 3.1
// Real Mode Data Segment Value is 0x0000.
// Real Mode Code Segment Value is 0x0000.
// Real Mode Stack Segment Value is 0x0000.
// Stack is valid in this function.( SP is initialized 0xFFFF in other function.)
// this is linked with following.asm
//.model tiny
//.code
//org 0A00h
//end
#define jmpn(offset) db 0xEB , offset;
#define jmpf(segment,offset) db 0xEA; dw offset; dw segment;
#define HALT db 0xEB , 0xFE;
void protected_mode()
{
asm cli;
init_GDT(0x600);// initialize and load( asm lgdt ) GDT at physical addr 0x600
// index 0 : null descriptor
// index 1 : 16bit code descriptor , addr 0x00 ~ 0xFFFF, excute_read
// index 2 : 16bit data descriptor , addr 0x00 ~ 0xFFFF, read_write
asm {
first_real_16 label;
smsw ax;
or ax,0x0001;
lmsw ax;
jmpn (0x00);
jmpf (0x0008,protected_16); // use selector on segment arg
protected_16 label;
ready_real label;
mov ax, 0x0010; // selector index 2
mov ds, ax;
mov es, ax;
db 0x8E, 0xE0; // mov fs, ax;
db 0x8E, 0xE8; // mov gs, ax;
mov ss, ax;
lidt real_mode_IDTR; // size 1024(4*256), addr 0x00000000
smsw ax;
and ax, 0xFFFE;
lmsw ax;
jmpf (0x0000, second_real_16); /* system is rebooted this line */
HALT; // for debug , if problem is not , halt.
second_real_16 label;
mov ax, 0;
mov ds, ax;
mov es, ax;
db 0x8E, 0xE0; // mov fs, ax;
db 0x8E, 0xE8; // mov gs, ax;
mov ss, ax;
}
asm sti;
}