Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Sauermann J.Realtime operating systems.Concepts and implementation of microkernels for embedded systems.1997.pdf
Скачиваний:
29
Добавлен:
23.08.2013
Размер:
1.32 Mб
Скачать

7. Miscellaneous

123

 

 

7 Miscellaneous

7.1General

This chapter covers topics that do not fit in the previous chapters in any natural way.

7.2Porting to different Processors

So far, a MC68020 has been assumed as target CPU. For using a different CPU, the assembler part of the kernel has to be rewritten. Since most of the code is specified in C++, the amount of code to be rewritten is fairly small. The files concerned are crt0.S and the files containing in-line assembler code, i.e. os.cc, os.hh, Task.hh, and Semaphore.hh.

7.2.1 Porting to MC68000 or MC68008 Processors

If the target CPU is a MC68000 or MC68008, then only one instruction in crt0.S needs to be removed. The start-up code crt0.S has been written so that it can be linked not only to base address 0 (i.e. assuming the code is executed directly after a processor RESET) but also to other addresses. In this case, a jump to the start of crt0.S is required:

1

| crt0.S

 

 

 

 

...

 

 

 

 

 

37

_null: BRA

_reset

|

0

initial SSP (end of RAM)

38

.LONG

_reset

|

1

initial PC

Normally, exception vector 0 contains the initial supervisor stack pointer, but since the supervisor stack pointer is not required from the outset, we have inserted a branch to label _reset instead. Thus a BRA _null has the same effect as a processor RESET. The CPU needs to know, however, where the vector table (starting at label _null) is located in the memory. For MC68010 CPUs and above, a special register, the vector base register VBR, has been implemented. After RESET, the VBR is set to 0. If crt0.S is linked to a different address, then the VBR has to be set accordingly. In crt0.S, the vector base address is computed automatically so that the user is not concerned with this matter:

1 | crt0.S

124

 

 

7.2 Porting to different Processors

 

 

 

 

...

 

 

 

81

_reset:

 

|

82

MOVE.L

#RAMend, SP

| since we abuse vector 0 for BRA.W

83

LEA

_null, A0

|

84

MOVEC

A0, VBR

| MC68010++ only

The first instruction after label _reset sets up the SSP, which fixes the abuse of vector 0. Then the VBR is set to point to the actual vector table. For a MC68000 or a MC68008, there is no VBR and the instruction would cause an illegal instruction trap at this point. For a MC68000 or MC68008 CPU, the move instruction to the VBR must be removed. Clearly, for such CPUs it is impossible to locate the vector table (i.e. crt0.S) to anywhere else than address 0.

7.2.2 Porting to Other Processor families

The only specific feature of the MC68000 family we used was the distinction between supervisor mode and user mode. At the end of an exception processing routine, it was checked whether a change back to user mode would happen. If so, a pending task switch was executed.

235

_return_from_exception:

| check for task switch

236

OR.W

#0x0700, SR

| disable interrupts

237

MOVE.W

(SP), -(SP)

| get status register before exception

238

AND.W

#0x2700, (SP)+

| supervisor mode or ints disabled ?

239

BNE

L_task_switch_done

| yes dont switch task

If a processor, e.g a Z80, does not provide different modes, then these modes can be emulated by a counter which is initialized to 0. For every exception, i.e. interrupts and also the function calls using the TRAP interface such as Semaphore::P(), this counter is incremented. At the end of every exception processing, the counter is decremented, and reaching 0 is equivalent to returning to user mode.