root/memdump/crt0.S

Revision 5a16eeb519c87fa4c437e838af81731b8d355052, 1.0 KB (checked in by H. Peter Anvin <hpa@…>, 5 years ago)

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.

  • Property mode set to 100644
Line 
1        .code16
2
3#ifndef REGPARM
4# error "This file assumes -mregparm=3 -DREGPARM=3"
5#endif
6
7        .section ".init","ax"
8        .globl _start
9        .type _start,@function
10_start:
11        # Align the stack and make sure the high half is zero
12        andl $0xfff8,%esp
13
14        # Clear the .bss
15        cld
16        xorl %eax,%eax
17        movw $__bss_start,%di
18        movw $_end+3,%cx
19        subw %di,%cx
20        shrw $2,%cx
21        rep ; stosl
22
23        # Compute argc and argv (assumes REGPARM)
24        xorl %edx,%edx
25        movzbw 0x80,%bx
26        movb %dl,0x81(%bx)      # Zero-terminate string
27        movb $0x81,%dl
28        pushl %eax              # Make space for argv
29        movl %esp,%eax
30        calll __parse_argv
31        pushl %eax              # argc
32
33        # Initialize malloc
34        # calll __init_memory_arena
35
36        # Now call main... (NOTE: gcc forces main to be regparm 0)
37        popl %eax               # argc
38        popl %edx               # argv
39        calll main
40
41        # Here %eax is the exit code, fall through into exit
42
43        .size _start,.-_start
44
45        .globl exit
46        .type exit,@function
47exit:
48        # Exit code already in %eax
49        movb $0x4c,%ah          # Terminate program
50        int $0x21
511:      hlt
52        jmp 1b
53        .size exit,.-exit
Note: See TracBrowser for help on using the browser.