Elan SC520

Hello,

We are developing BSP for Elan SC520 board.
We could successfuly initialize LED Ports, SDRAM and Integrated UART Serial
Ports.

After this is done, the code is jumping to protected mode, before that, GDT
and LDT tables are initalised and the CR0 bit is set accordingly.
Well, everything goes correct till here. the problem is once the control
comes back from the protected mode successfully,
we switch the programming mode to 32 bit mode. The system is restarting.

Below is our protected mode code and the instructions for jumping into 32
bit mode.

Protected.S


#if defined(GAS_MINOR) && GAS_MINOR <= 9

…code16

#else

…code16gcc

#endif

…text

…align 2

…globl protected_mode

…macro CALLN, target

…byte 0xe8

…short &target -(. + 2)

…endm

protected_mode:

/*#--------------------------------------------------------------

Switch processor into protected mode. Upon return

the DS and ES will be set to selectors that can

access the entire 4G address space. This code is

designed to be completely position independent.

This routine must be called with a pointer to a 16-byte

area of memory that is used to store the GDT. The pointer

is in ds:ax.

The following selectors are defined:

8 - data selector for 0-4G

16 - code selector for 0-4G

#--------------------------------------------------------------*/

andw $0xfffc, %ax

movzwl %ax, %ebx

Calculate the linear address of the GDT area.

xor %eax, %eax

movw %ds, %ax

shl $4, %eax

addl %ebx, %eax

subl $8, %eax # -8 for null selector

\

Setup the GDT descriptor.

movw $24, (%ebx) # limit

movl %eax, 2(%ebx) # base

lgdt (%ebx)

\

The two GDT entries (code and data). In order to make the

code position independent we calculate the address of the

static GDT by putting a call just before the table.

CALLN pm1

data_entry:

…short 0xffff # limit

…short 0 # base_low

…byte 0 # base_high_low

…byte 0x93 # access rights

…byte 0xcf # flags + limit

…byte 0 # base_high_high

code_entry:

…short 0xffff # limit

…short 0 # base_low

…byte 0 # base_high_low

…byte 0x9b # access rights

…byte 0xcf # flags + limit

…byte 0 # base_high_high

\

Copy the 2 entry GDT into the passed GDT area.

pm1:

xor %esi, %esi

popw %si

movl $8, %ecx

pm2:

movw %cs:(%esi), %dx

movw %dx, (%ebx)

addw $2, %si

addw $2, %bx

loop pm2

\

Now switch the machine into protected mode by setting

bit 0 of CR0. Enable the cache for write-back mode.

movl %cr0, %eax

orw $1, %ax

movl %eax, %cr0

jmp flush

flush:

\

Now our two GDT entries are initialized we can load

the segment registers.

movw $0x08, %ax

movw %ax, %ds

movw %ax, %es

movw %ax, %ss

ret





_start.S

Start up file, from which we are calling protected.S


Initialize GP bus Timings

Initialize Par registers for led ports

Initialize SDRRAM Controller

Setup STACK

Enable RTC

INitialize Interrupt Controller

Initialize Serial UART



####################################

Switch the processor into protected mode

#################################

prot:

subw $16, %sp # save room for the GDT

movw %sp, %ax

call protected_mode



ljmpl $16, $x32

x32:

…code32

…align 4

call main

hlt


\

But after coming back from protected mode, the system is continuosly
resetting. Could anybody tell me whats wrong in my code and help me
in successfully switching into protected mode.

Thanks

Susan