arch/sparc/boot/piggyback.c
Source file repositories/reference/linux-study-clean/arch/sparc/boot/piggyback.c
File Facts
- System
- Linux kernel
- Corpus path
arch/sparc/boot/piggyback.c- Extension
.c- Size
- 6268 bytes
- Lines
- 266
- Domain
- Architecture Layer
- Bucket
- arch/sparc
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dirent.hstdlib.hstring.hunistd.hctype.herrno.hfcntl.hstdio.hsys/types.hsys/stat.h
Detected Declarations
function alignfunction ld2function st4function diefunction usagefunction start_linefunction end_linefunction get_start_endfunction filefunction main
Annotated Snippet
if (offset < 0) {
errno = -EINVAL;
die("Calculated a negative offset, probably elftoaout generated an invalid image. Did you use a recent elftoaout ?");
}
if (lseek(kernelfd, offset, SEEK_SET) < 0)
die("lseek");
if (read(kernelfd, buffer, BUFSIZE) != BUFSIZE)
die(filename);
for (i = 0; i < LOOKBACK; i += 4) {
if (buffer[i + 0] == 'H' && buffer[i + 1] == 'd' &&
buffer[i + 2] == 'r' && buffer[i + 3] == 'S') {
return offset + i;
}
}
}
fprintf (stderr, "Couldn't find headers signature in %s\n", filename);
exit(1);
}
int main(int argc,char **argv)
{
static char aout_magic[] = { 0x01, 0x03, 0x01, 0x07 };
char buffer[1024];
unsigned int i, start, end;
off_t offset;
struct stat s;
int image, tail;
if (argc != 5)
usage();
if (strcmp(argv[1], "64") == 0)
is64bit = 1;
if (stat (argv[4], &s) < 0)
die(argv[4]);
if (!get_start_end(argv[3], &start, &end)) {
fprintf(stderr, "Could not determine start and end from %s\n",
argv[3]);
exit(1);
}
if ((image = open(argv[2], O_RDWR)) < 0)
die(argv[2]);
if (read(image, buffer, 512) != 512)
die(argv[2]);
if (memcmp(buffer, aout_magic, 4) != 0) {
fprintf (stderr, "Not a.out. Don't blame me.\n");
exit(1);
}
/*
* We need to fill in values for
* sparc_ramdisk_image + sparc_ramdisk_size
* To locate these symbols search for the "HdrS" text which appear
* in the image a little before the gokernel symbol.
* See definition of these in init_32.S
*/
offset = get_hdrs_offset(image, argv[2]);
/* skip HdrS + LINUX_VERSION_CODE + HdrS version */
offset += 10;
if (lseek(image, offset, 0) < 0)
die("lseek");
/*
* root_flags = 0
* root_dev = 1 (RAMDISK_MAJOR)
* ram_flags = 0
* sparc_ramdisk_image = "PAGE aligned address after _end")
* sparc_ramdisk_size = size of image
*/
st4(buffer, 0);
st4(buffer + 4, 0x01000000);
st4(buffer + 8, align(end + 32));
st4(buffer + 12, s.st_size);
if (write(image, buffer + 2, 14) != 14)
die(argv[2]);
/* For sparc64 update a_text and clear a_data + a_bss */
if (is64bit)
{
if (lseek(image, 4, 0) < 0)
die("lseek");
/* a_text */
st4(buffer, align(end + 32 + 8191) - (start & ~0x3fffffUL) +
s.st_size);
/* a_data */
st4(buffer + 4, 0);
/* a_bss */
Annotation
- Immediate include surface: `dirent.h`, `stdlib.h`, `string.h`, `unistd.h`, `ctype.h`, `errno.h`, `fcntl.h`, `stdio.h`.
- Detected declarations: `function align`, `function ld2`, `function st4`, `function die`, `function usage`, `function start_line`, `function end_line`, `function get_start_end`, `function file`, `function main`.
- Atlas domain: Architecture Layer / arch/sparc.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.