aboutsummaryrefslogtreecommitdiffstats
path: root/memdump/crt0.S
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-09-21 16:52:35 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-09-21 16:52:35 -0700
commit5a16eeb519c87fa4c437e838af81731b8d355052 (patch)
treef59258a720429d5ad8beaf2070f73cab6a187077 /memdump/crt0.S
parent31daeb2ddb972dc70b929da1c93288e821c87ed7 (diff)
downloadsyslinux-elf-5a16eeb519c87fa4c437e838af81731b8d355052.tar.gz
syslinux-elf-5a16eeb519c87fa4c437e838af81731b8d355052.tar.xz
syslinux-elf-5a16eeb519c87fa4c437e838af81731b8d355052.zip
memdump: a debugging utility to dump memory over a serial port
A memory-dumping utility which runs in real mode. Thus, it can be used to get memory dumps from a relatively pristine system.
Diffstat (limited to 'memdump/crt0.S')
-rw-r--r--memdump/crt0.S53
1 files changed, 53 insertions, 0 deletions
diff --git a/memdump/crt0.S b/memdump/crt0.S
new file mode 100644
index 00000000..92297ecf
--- /dev/null
+++ b/memdump/crt0.S
@@ -0,0 +1,53 @@
+ .code16
+
+#ifndef REGPARM
+# error "This file assumes -mregparm=3 -DREGPARM=3"
+#endif
+
+ .section ".init","ax"
+ .globl _start
+ .type _start,@function
+_start:
+ # Align the stack and make sure the high half is zero
+ andl $0xfff8,%esp
+
+ # Clear the .bss
+ cld
+ xorl %eax,%eax
+ movw $__bss_start,%di
+ movw $_end+3,%cx
+ subw %di,%cx
+ shrw $2,%cx
+ rep ; stosl
+
+ # Compute argc and argv (assumes REGPARM)
+ xorl %edx,%edx
+ movzbw 0x80,%bx
+ movb %dl,0x81(%bx) # Zero-terminate string
+ movb $0x81,%dl
+ pushl %eax # Make space for argv
+ movl %esp,%eax
+ calll __parse_argv
+ pushl %eax # argc
+
+ # Initialize malloc
+ # calll __init_memory_arena
+
+ # Now call main... (NOTE: gcc forces main to be regparm 0)
+ popl %eax # argc
+ popl %edx # argv
+ calll main
+
+ # Here %eax is the exit code, fall through into exit
+
+ .size _start,.-_start
+
+ .globl exit
+ .type exit,@function
+exit:
+ # Exit code already in %eax
+ movb $0x4c,%ah # Terminate program
+ int $0x21
+1: hlt
+ jmp 1b
+ .size exit,.-exit