From 9075401502fa18101b00727006defda0c1a64b18 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Wed, 12 Mar 2008 21:59:15 +0000 Subject: [PATCH] * doc/sdccman.lyx: added paragraph about bankswitching for mcs51 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5092 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 +- doc/sdccman.lyx | 228 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c31e1355..67690a55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,11 @@ +2008-03-12 Maarten Brock + + * doc/sdccman.lyx: added paragraph about bankswitching for mcs51 + 2008-03-12 Borut Razem * as/doc/asmlnk.doc, as/doc/asxhtm.html: updated command line options, - fixed documentation request ##1718191 + fixed documentation request #1718191 * as/hc80/asmain.c, as/mcs51/asmain.c: added option -c to usage * doc/sdccman.lyx: added description of --no-std-crt0 gbz80 command line option diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index ad51a397..86f2464a 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -23435,6 +23435,234 @@ Some MCS51 variants offer features like Double DPTR These are currently not used for the MCS51 port. If you absolutely need them you can fall back to inline assembly or submit a patch to SDCC. +\end_layout + +\begin_layout Subsection +Bankswitching +\end_layout + +\begin_layout Standard +Bankswitching +\begin_inset LatexCommand \index{Bankswitching} + +\end_inset + + (a.k.a. + code banking +\begin_inset LatexCommand \index{code banking} + +\end_inset + +) is a technique to increase the code space above the 64k limit of the 8051. +\end_layout + +\begin_layout Subsubsection +Hardware +\end_layout + +\begin_layout Standard +\begin_inset Tabular + + + + + + + + +\begin_inset Text + +\begin_layout Standard +\paragraph_spacing other 0.5 +8000-FFFF +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard +bank 1 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard +bank 2 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard +bank 3 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Standard +0000-7FFF +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard +common +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard + +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard + +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Standard +SiLabs C8051F120 example +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard + +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard + +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Standard + +\end_layout + +\end_inset + + + + +\end_inset + + +\newline + +\newline +Usually the hardware uses some sfr (an output port or an internal sfr) to + select a bank and put it in the banked area of the memory map. + Because the selected bank usually becomes active immediately you cannot + jump call directly from one bank to another and need to use a so-called + trampoline in the common area. + For SDCC an example trampoline is in crtbank.asm and you may need to change + it to your 8051 derivative or schematic. + The presented code is written for the C8051F120. +\newline + +\newline +When calling a banked function + SDCC will put the LSB of the functions address in register R0, the MSB + in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call. + The current selected bank is saved on the stack, the new bank is selected + and an indirect jump is made. + When the banked function returns it jumps to __sdcc_banked_ret which restores + the previous bank and returns to the caller. +\end_layout + +\begin_layout Subsubsection +Software +\end_layout + +\begin_layout Standard +When writing banked software using SDCC you need to use some special keywords + and options. + You also need to take over a bit of work from the linker. +\newline + +\newline +To create a function + that can be called from another bank it requires the keyword banked. + The caller must see this in the prototype of the callee and the callee + needs it for a proper return. + Called functions within the same bank as the caller do not need the banked + keyword nor do functions in the common area. + Beware: SDCC does not know or check if functions are in the same bank. + This is your responsibility! +\newline + +\newline +Normally all functions you write end up in + the segment CSEG. + If you want a function explicitly to reside in the common area put it in + segment HOME. + This applies for instance to interrupt service routines as they should + not be banked. +\end_layout + +\begin_layout Standard +Functions that need to be in a switched bank must be put in a named segment. + The name can be mostly anything upto eight characters (e.g. + BANK1). + To do this you either use --codeseg BANK1 on the command line when compiling + or #pragma codeseg BANK1 at the top of the C source file. + The segment name always applies to the whole source file and generated + object so functions for different banks need to be defined in different + source files. +\newline + +\newline +When linking your objects you need to tell the linker where + to put your segments. + To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180 +00. + This sets the virtual start address of this segment. + It sets the banknumber to 0x01 and maps the bank to 0x8000 and up. + The linker will not check for overflows, again this is your responsibility. +\end_layout + +\begin_layout Standard \begin_inset VSpace bigskip \end_inset -- 2.39.5