Last change
on this file was
e16e8f2,
checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago
|
bootstuff
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[e16e8f2] | 1 | .code16 |
---|
| 2 | |
---|
| 3 | #ifndef REGPARM |
---|
| 4 | # error "This file assumes -mregparm=3 -DREGPARM=3" |
---|
| 5 | #endif |
---|
| 6 | |
---|
| 7 | .section ".text","ax" |
---|
| 8 | .globl _start |
---|
| 9 | .type _start,@function |
---|
| 10 | _start: |
---|
| 11 | # Align the stack and make sure the high half is zero |
---|
| 12 | andl $0xfffc,%esp |
---|
| 13 | |
---|
| 14 | # DS, ES points to the PSP at this point |
---|
| 15 | pushw %es # Save PSP pointer |
---|
| 16 | movw %cs,%ax |
---|
| 17 | movw %ax,%ds |
---|
| 18 | movw %ax,%es |
---|
| 19 | |
---|
| 20 | # Clear the .bss |
---|
| 21 | cld |
---|
| 22 | xorl %eax,%eax |
---|
| 23 | movw $__bss_start,%di |
---|
| 24 | movw $__bss_end+3,%cx |
---|
| 25 | subw %di,%cx |
---|
| 26 | shrw $2,%cx |
---|
| 27 | rep ; stosl |
---|
| 28 | |
---|
| 29 | # Copy the PSP into our own segment |
---|
| 30 | popw %fs # FS -> PSP |
---|
| 31 | movw $_PSP,%di |
---|
| 32 | xorw %si,%si |
---|
| 33 | movw $0x40,%cx |
---|
| 34 | fs ; rep ; movsl |
---|
| 35 | |
---|
| 36 | # Verify that this is a supportable DOS version |
---|
| 37 | movw $0x3001,%ax |
---|
| 38 | int $0x21 |
---|
| 39 | xchgb %ah,%al |
---|
| 40 | movw %ax,dos_version |
---|
| 41 | cmpw $0x0314,%ax # DOS >= 3.20? |
---|
| 42 | jae 1f # If so, okay |
---|
| 43 | movw $bad_dos,%dx # Print error message |
---|
| 44 | movb $0x09,%ah |
---|
| 45 | int $0x21 |
---|
| 46 | int $0x20 # Die |
---|
| 47 | |
---|
| 48 | 1: |
---|
| 49 | # Compute argc and argv (assumes REGPARM) |
---|
| 50 | pushl %eax # Make space for argv |
---|
| 51 | movl %esp,%eax |
---|
| 52 | calll __parse_argv |
---|
| 53 | pushl %eax # argc |
---|
| 54 | |
---|
| 55 | # Initialize malloc |
---|
| 56 | calll __init_memory_arena |
---|
| 57 | |
---|
| 58 | # Now call main |
---|
| 59 | popl %eax # argc |
---|
| 60 | popl %edx # argv |
---|
| 61 | calll main |
---|
| 62 | |
---|
| 63 | # Here %eax is the exit code, fall through into exit |
---|
| 64 | |
---|
| 65 | .size _start,.-_start |
---|
| 66 | |
---|
| 67 | .globl exit |
---|
| 68 | .type exit,@function |
---|
| 69 | exit: |
---|
| 70 | # Exit code already in %eax |
---|
| 71 | movb $0x4c,%ah # Terminate program |
---|
| 72 | int $0x21 |
---|
| 73 | 1: hlt |
---|
| 74 | jmp 1b |
---|
| 75 | .size exit,.-exit |
---|
| 76 | |
---|
| 77 | .section ".rodata","a" |
---|
| 78 | bad_dos: |
---|
| 79 | .ascii "Unsupported DOS version\r\n$" |
---|
| 80 | .size bad_dos,.-bad_dos |
---|
| 81 | |
---|
| 82 | .section ".bss","aw" |
---|
| 83 | .balign 16 |
---|
| 84 | .globl _PSP |
---|
| 85 | _PSP: |
---|
| 86 | .space 256 |
---|
| 87 | .size _PSP, .-_PSP |
---|
| 88 | |
---|
| 89 | /* Purely for sanity */ |
---|
| 90 | .section ".null","a" |
---|
| 91 | .long 0,0,0,0 |
---|
Note: See
TracBrowser
for help on using the repository browser.