📄 slocs.h
字号:
//++
//slocs.h
//
// Copyright (C) 2005 by Spare Time Gizmos. All rights reserved.
//
// This file is part of the Spare Time Gizmos' MP3 PLayer firmware.
//
// This firmware is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place, Suite 330, Boston, MA 02111-1307 USA.
//
// DESCRIPTION:
//
// The sloc problem - sit for a while and let's talk...
//
// SDCC is fairly inefficient about utilizing the 8051's registers and internal
// memory, and it has a nasty habit of generating teporary locations in DATA to
// hold intermediate results. The SDCC designers call these temporary locations
// "Spill Locations" or "slocs" for short. The biggest problem with slocs is that
// the compiler isn't smart enough to overlay them, so any slocs allocated to a
// routine are permanently and forever used up.
//
// This problem is especially a killer for some of the code in fat.c, because
// there are some routines that do a fair amount of 32 bit data mamipulations
// (they have to in order to handle LBAs) and 32 bit temporaries generate four
// byte slocs. There are a few routines, e.g. ReadMBR() or ReadVBS(), that
// can generate 20 bytes of slocs! This memory is permanently allocated and
// can never be touched by anything else - all for a routine that's called only
// once! All together, the ReadMBR(), ReadVBS() and GetLFN() routines alone were
// permanently sucking up about 40 bytes of DATA space.
//
// Argghhh!! Where's my ice pick???
//
// Fortunately, however, there is a way out. The solution is to declare the
// offending routines as reentrant. Huh? It may not be immediately obvious how
// this fixes the problem, but think about it. Reentrant effectively tells the
// compiler to allocate all locals and parameters - i.e. all automatic data -
// on the stack, INCLUDING slocs. With the slocs moved to the stack we can free
// up the DATA space allocated to them and, better yet, the space allocated to
// the stack can be reused for other purposes!
//
// The drawback, of course, is that the 8051 has no stack based addressing modes
// and the code generated for some of these reentrant functions is truly painful
// to see. It's kind of like a software Medusa - you'll turn to stone if you look
// at it, so don't look... It's enough that it works and, fortunately, routines
// like ReadMBR() and ReadVBS() are only called once.
//
// Keil C51 has none of these problems. It's a) much more efficient about
// using the 8051 registers and doesn't need nearly as many temporaries as SDCC,
// and b) C51 is smart enough to overlay the temporaries that it does create, so
// the space allocated to them isn't lost forever.
//
// REVISION HISTORY:
// dd-mmm-yy who description
// 19-Oct-05 RLA New file.
//--
#ifndef _slocs_h_
#define _slocs_h_
// For SDCC STACKSLOCS is defined as reentrant but for everything else it
// is nothing...
#define STACKSLOCS reentrant
#endif // ifdef _slocs_h_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -