[4f508e6] | 1 | | ------------------------------------------------------------------------------
|
---|
| 2 | | fsmain.s -- startup code for the Buchla 700 standalone C runtime library
|
---|
| 3 | | Version 3 -- 1987-06-29 -- D.N. Lynx Crowe
|
---|
| 4 |
|
---|
| 5 | | This code clears 'bss' space, sets up some global variables,
|
---|
| 6 | | and calls Croot(), which sets up the file system and calls main().
|
---|
| 7 |
|
---|
| 8 | | This routine should be entered with the address of the basepage
|
---|
| 9 | | as its parameter.
|
---|
| 10 | | ------------------------------------------------------------------------------
|
---|
[f40a309] | 11 | .text
|
---|
[4f508e6] | 12 |
|
---|
[f40a309] | 13 | .xdef start_
|
---|
[4f508e6] | 14 |
|
---|
[8325447] | 15 | .xref Croot
|
---|
[4f508e6] | 16 |
|
---|
[8325447] | 17 | .xdef panic
|
---|
| 18 | .xdef brk
|
---|
[4f508e6] | 19 |
|
---|
[8325447] | 20 | .xdef _heap
|
---|
| 21 | .xdef _break
|
---|
| 22 | .xdef _pmesg
|
---|
[4f508e6] | 23 |
|
---|
[8325447] | 24 | .xdef errno
|
---|
[4f508e6] | 25 |
|
---|
| 26 | p_bbase = 0x18 | bss base
|
---|
| 27 | p_blen = 0x1C | bss length
|
---|
| 28 |
|
---|
[f40a309] | 29 | .page
|
---|
[4f508e6] | 30 |
|
---|
| 31 | | start_ -- Initial entry point -- Must be first object file in link statement
|
---|
| 32 | | ------ ------------------------------------------------------------------
|
---|
| 33 |
|
---|
| 34 | | WARNING: Hazardous assumptions
|
---|
| 35 |
|
---|
| 36 | | We assume that:
|
---|
| 37 |
|
---|
| 38 | | the system has set the stack pointer for us.
|
---|
| 39 | | the system passed us a pointer to a valid basepage.
|
---|
| 40 | | the stack is above the heap.
|
---|
| 41 | | BSS is located in RAM.
|
---|
| 42 |
|
---|
| 43 | | If any of these assumptions is in error, we're in for serious trouble.
|
---|
| 44 |
|
---|
| 45 | start_: movea.l #0,a6 | Clear frame pointer
|
---|
| 46 | movea.l 4(a7),a1 | Set pointer to base page
|
---|
| 47 | movea.l p_bbase(a1),a0 | Setup to clear bss space
|
---|
| 48 |
|
---|
| 49 | start1: clr.w (a0)+ | Clear a word
|
---|
| 50 | cmpa.l a0,a7 | See if we're done
|
---|
| 51 | bne start1 | Loop if not done yet
|
---|
| 52 |
|
---|
| 53 | move.l p_bbase(a1),d0 | Calculate break address
|
---|
| 54 | add.l p_blen(a1),d0 | ...
|
---|
[8325447] | 55 | move.l d0,_break | Set initial break
|
---|
| 56 | move.l d0,_heap | Set heap start
|
---|
[4f508e6] | 57 |
|
---|
| 58 | move.l #0,-(a7) | Pass NULL to Croot (no command line)
|
---|
[8325447] | 59 | jsr Croot | call Croot() routine
|
---|
[4f508e6] | 60 | addq.l #4,a7 | ...
|
---|
| 61 |
|
---|
| 62 | move.l #pmsg1,-(a7) | panic(pmsg1);
|
---|
[8325447] | 63 | jsr panic | ...
|
---|
[4f508e6] | 64 | addq.l #4,a7 | ...
|
---|
| 65 |
|
---|
| 66 | hstop: stop #0x2000 | "Die, sucker!"
|
---|
[f40a309] | 67 | bra hstop
|
---|
[4f508e6] | 68 |
|
---|
[f40a309] | 69 | .page
|
---|
[4f508e6] | 70 |
|
---|
[8325447] | 71 | | panic -- hard halt for fatal errors
|
---|
| 72 | | ----- --------------------------
|
---|
| 73 | panic: movea.l 4(a7),a0 | Save panic message address
|
---|
| 74 | move.l a0,_pmesg | ...
|
---|
[4f508e6] | 75 |
|
---|
| 76 | trap #15 | Invoke ROMP (we hope ...)
|
---|
| 77 |
|
---|
| 78 | pstop: stop #0x2700 | HARD HALT
|
---|
[f40a309] | 79 | bra pstop
|
---|
[4f508e6] | 80 |
|
---|
[f40a309] | 81 | .page
|
---|
[4f508e6] | 82 |
|
---|
[8325447] | 83 | | brk -- set break value
|
---|
| 84 | | --- ---------------
|
---|
[4f508e6] | 85 | | WARNING: This only works if the stack is above the heap.
|
---|
| 86 |
|
---|
[8325447] | 87 | brk: cmpa.l _break,a7 | compare current break with stack
|
---|
[4f508e6] | 88 | bcs pstop | actual stack overflow!
|
---|
| 89 |
|
---|
| 90 | movea.l 4(sp),a0 | get new break
|
---|
| 91 | move.l a0,d0 | compare with current stack,
|
---|
| 92 | adda.l #0x100,a0 | ... including 256-byte slop factor
|
---|
| 93 | cmpa.l a0,a7 | if (sp < a0+256)
|
---|
| 94 | bcs badbrk | bad break;
|
---|
| 95 |
|
---|
[8325447] | 96 | move.l d0,_break | OK break: save the break
|
---|
[4f508e6] | 97 | clr.l d0 | Set OK return
|
---|
| 98 | rts | return
|
---|
| 99 |
|
---|
| 100 | badbrk: moveq.l #-1,d0 | Load return reg
|
---|
| 101 | rts | Return
|
---|
| 102 |
|
---|
[f40a309] | 103 | .page
|
---|
[4f508e6] | 104 |
|
---|
[84c0125] | 105 | |************************************************************************
|
---|
[4f508e6] | 106 | | Data Area |
|
---|
[84c0125] | 107 | |************************************************************************
|
---|
[4f508e6] | 108 |
|
---|
[f40a309] | 109 | .data
|
---|
[4f508e6] | 110 |
|
---|
[6dc5ea7] | 111 | pmsg1: .asciz " returned from Croot() "
|
---|
[4f508e6] | 112 |
|
---|
[84c0125] | 113 | |************************************************************************
|
---|
[4f508e6] | 114 | | BSS Area |
|
---|
[84c0125] | 115 | |************************************************************************
|
---|
[4f508e6] | 116 |
|
---|
[f40a309] | 117 | .bss
|
---|
| 118 | .even
|
---|
[4f508e6] | 119 |
|
---|
[8325447] | 120 | _pmesg: .ds.l 1 | panic() message string address
|
---|
| 121 | _heap: .ds.l 1 | Heap start (initial break)
|
---|
| 122 | _break: .ds.l 1 | Current break location
|
---|
| 123 | errno: .ds.w 1 | System error number
|
---|
[4f508e6] | 124 |
|
---|
[f40a309] | 125 | .end
|
---|