Clean up the passing of the boot command line to the kernel.

kern/linux/linux_system.cc:
    Don't hard code the address of the command line in the kernel,
    instead, deduce it from the location of known symbols.
    don't use strcpy, it's dangerous.
kern/linux/linux_system.hh:
    Don't hard code the address of the command line in the kernel,
    instead, deduce it from the location of known symbols.

--HG--
extra : convert_revision : 128b1d5dbd00b0b8571707da99f86f76e29abfd1
This commit is contained in:
Nathan Binkert 2005-08-23 11:47:12 -04:00
parent c761aaae65
commit c0de2e7f12
2 changed files with 40 additions and 20 deletions

View file

@ -52,6 +52,24 @@ LinuxSystem::LinuxSystem(Params *p)
: System(p) : System(p)
{ {
Addr addr = 0; Addr addr = 0;
Addr paddr = 0;
/**
* The symbol swapper_pg_dir marks the beginning of the kernel and
* the location of bootloader passed arguments
*/
if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) {
panic("Could not determine start location of kernel");
}
/**
* Since we aren't using a bootloader, we have to copy the
* kernel arguments directly into the kernel's memory.
*/
paddr = vtophys(physmem, CommandLine());
char *commandline = (char *)physmem->dma_addr(paddr, sizeof(uint64_t));
if (commandline)
strncpy(commandline, params->boot_osflags.c_str(), CommandLineSize);
/** /**
* find the address of the est_cycle_freq variable and insert it * find the address of the est_cycle_freq variable and insert it
@ -59,7 +77,7 @@ LinuxSystem::LinuxSystem(Params *p)
* calculated it by using the PIT, RTC, etc. * calculated it by using the PIT, RTC, etc.
*/ */
if (kernelSymtab->findAddress("est_cycle_freq", addr)) { if (kernelSymtab->findAddress("est_cycle_freq", addr)) {
Addr paddr = vtophys(physmem, addr); paddr = vtophys(physmem, addr);
uint8_t *est_cycle_frequency = uint8_t *est_cycle_frequency =
physmem->dma_addr(paddr, sizeof(uint64_t)); physmem->dma_addr(paddr, sizeof(uint64_t));
@ -69,18 +87,6 @@ LinuxSystem::LinuxSystem(Params *p)
} }
/**
* Since we aren't using a bootloader, we have to copy the kernel arguments
* directly into the kernels memory.
*/
{
Addr paddr = vtophys(physmem, PARAM_ADDR);
char *commandline = (char*)physmem->dma_addr(paddr, sizeof(uint64_t));
if (commandline)
strcpy(commandline, params->boot_osflags.c_str());
}
/** /**
* EV5 only supports 127 ASNs so we are going to tell the kernel that the * EV5 only supports 127 ASNs so we are going to tell the kernel that the
* paritiuclar EV6 we have only supports 127 asns. * paritiuclar EV6 we have only supports 127 asns.
@ -88,7 +94,7 @@ LinuxSystem::LinuxSystem(Params *p)
* 255 ASNs. * 255 ASNs.
*/ */
if (kernelSymtab->findAddress("dp264_mv", addr)) { if (kernelSymtab->findAddress("dp264_mv", addr)) {
Addr paddr = vtophys(physmem, addr); paddr = vtophys(physmem, addr);
char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t));
if (dp264_mv) { if (dp264_mv) {

View file

@ -29,12 +29,6 @@
#ifndef __KERN_LINUX_LINUX_SYSTEM_HH__ #ifndef __KERN_LINUX_LINUX_SYSTEM_HH__
#define __KERN_LINUX_LINUX_SYSTEM_HH__ #define __KERN_LINUX_LINUX_SYSTEM_HH__
/**
* MAGIC address where the kernel arguments should go. Defined as
* PARAM in linux kernel alpha-asm.
*/
const Addr PARAM_ADDR = ULL(0xfffffc000030a000);
class ExecContext; class ExecContext;
class BreakPCEvent; class BreakPCEvent;
@ -52,6 +46,26 @@ class PrintThreadInfo;
*/ */
class LinuxSystem : public System class LinuxSystem : public System
{ {
private:
/**
* Addresses defining where the kernel bootloader places various
* elements. Details found in include/asm-alpha/system.h
*/
Addr KernelStart; // Lookup the symbol swapper_pg_dir
public:
Addr InitStack() const { return KernelStart + 0x02000; }
Addr EmptyPGT() const { return KernelStart + 0x04000; }
Addr EmptyPGE() const { return KernelStart + 0x08000; }
Addr ZeroPGE() const { return KernelStart + 0x0A000; }
Addr StartAddr() const { return KernelStart + 0x10000; }
Addr Param() const { return ZeroPGE() + 0x0; }
Addr CommandLine() const { return Param() + 0x0; }
Addr InitrdStart() const { return Param() + 0x100; }
Addr InitrdSize() const { return Param() + 0x108; }
static const int CommandLineSize = 256;
private: private:
#ifndef NDEBUG #ifndef NDEBUG
/** Event to halt the simulator if the kernel calls panic() */ /** Event to halt the simulator if the kernel calls panic() */