From: Alan Cox Date: Thu, 16 Nov 2017 17:14:49 +0000 (+0000) Subject: cc: add initial runtime pieces X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=4af1151d567af901ff622e10a7bf3b77733ee557;p=FUZIX.git cc: add initial runtime pieces Need a decent signed divide implementation adding to crun --- diff --git a/Applications/SmallC/Z80/crt0.s b/Applications/SmallC/Z80/crt0.s new file mode 100644 index 00000000..74152586 --- /dev/null +++ b/Applications/SmallC/Z80/crt0.s @@ -0,0 +1,43 @@ + .code + +; start at 0x100 +start: jp start2 + .byte 'F' + .byte 'Z' + .byte 'X' + .byte '1' + +; +; Borrowed idea from UMZIX - put the info in known places then +; we can write "size" tools +; +; This is confusing. SDCC doesn't produce a BSS, instead it +; produces an INITIALIZED (which everyone else calls DATA) and a +; DATA which everyone else would think of as BSS. +; +; FIXME: we need to automate the load page setting +; + .byte 0x01 ; page to load at + .word 0 ; chmem ("0 - 'all'") + .word __code_size ; gives us code size info + .word __data_size ; gives us data size info + .word __bss_size ; bss size info + .word 0 ; spare + +start2: + ld hl, 4 + add hl, sp + ld (_environ), hl + pop de ; argc + pop hl ; argv + push hl + ld (___argv), hl ; needed for stuff like err() + push de + ld hl, _exit ; return vector + push hl + jp _main ; go + + .data + +_environ: .word 0 +___argv: .word 0 diff --git a/Applications/SmallC/Z80/runtime/crun.s b/Applications/SmallC/Z80/runtime/crun.s new file mode 100644 index 00000000..ed258a0e --- /dev/null +++ b/Applications/SmallC/Z80/runtime/crun.s @@ -0,0 +1,298 @@ +; +; Runtime support routines for the compiler itself. These are +; generated by the compiler in the compiled code +; +; Converted from 8080 to Z80 and tidied up a bit. Some optimized +; Z80 routines used. +; +; +; + .code + + .export ccgchar + .export ccgint + .export ccpchar + .export ccpint + .export ccsxt + .export ccor + .export ccand + .export ccxor + .export cceq + .export ccne + .export ccgt + .export ccle + .export ccge + .export cclt + .export ccuge + .export ccult + .export ccugt + .export ccule + .export ccasr + .export ccasl + .export ccsub + .export ccneg + .export cccom + .export cclneg + .export ccboot + .export ccmul + .export ccumul + .export ccdiv +; .export ccudiv + .export cccase + .export cccallhl + +ccgchar: + ld a,(hl) +ccsxt: + ld l,a + rlca + sbc a,a + ld h,a + ret +ccgint: + ld a,(hl) + inc hl + ld h,(hl) + ld l,a + ret +ccpchar: + ld a,l + ld (de),a + ret +ccpint: + ld a,l + ld (de),a + inc de + ld a,h + ld (de),a + ret +ccor: ld a,h + or d + ld h,a + ld a,l + or e + ld l,a + ret +ccxor: ld a,h + xor d + ld h,a + ld a,l + xor e + ld e,a + ret +ccand: ld a,h + and d + ld h,a + ld a,l + and e + ld e,a + ret +cceq: call cccmp + ret z + dec hl + ret +ccne: call cccmp + ret nz + dec hl + ret +ccgt: ex de,hl + call cccmp + ret c + dec hl + ret +ccle: call cccmp + ret c + ret z + dec hl + ret +ccge: call cccmp + ret nc + dec hl + ret +cclt: call cccmp + ret c + dec hl + ret +ccuge: call ccucmp + ret nc + dec hl + ret +ccult: call ccucmp + ret c + dec hl + ret +ccule: call ccucmp + ret z + ret c + dec hl + ret +cccmp: + ld a,e + sub l + ld e,a + ld a,d + sub h + ld hl,1 + jp m,cccmp1 + or e + ret +cccmp1: or e + scf + ret + +ccucmp: + ld a,d + cp h + jr nz,ccret1 + ld a,e + cp l +ccret1: + ld hl,1 + ret + +ccasr: ld a,l + or a + ret z +ccasrl: + sra d + rr e + dec a + jr nz,ccasrl + ret +ccasl: ld a,l + or a + ret z +ccasll: sla e + rl d + dec a + jr nz,ccasll + ret +ccsub: ex de,hl + or a + sbc hl,de + ret +ccneg: call cccomm + inc hl + ret +cccom: ld a,h + cpl + ld h,a + ld a,l + cpl + ld l,a + ret +cclneg: ld a,h + or l + jr nz,ret0 + inc hl + ret +ret0: ld hl,0 + ret +ccbool: ld a,h + or l + ret z + ld hl,#1 + ret + +; +; These might want to live somewhere else as they are bigger +; +; HL = DE * HL (signed) +; +ccumul: +ccmul: push bc + ld a,h + ld c,l + ld b,16 +ccmul_1: + add hl,hl + sla c + rla + jr nc, ccmul_2 + add hl,de +ccmul_2: + djnz ccmul_1 + pop bc + ret + +; +; Outputs HL = DE/HL and DE = DE % HL +; +ccudiv: + push bc + ex de,hl + ld a,h + ld b,8 + ld c,l + ld hl,0 +ccdiv_1: + rla + adc hl,hl + sbc hl,de + jr nc, ccdiv_2 + add hl,de +ccdiv_2: + djnz ccdiv_1 + rla + cpl + ld b,a + ld a,c + ld c,b + ld b,8 +ccdiv_3: + rla + adc hl,hl + sbc hl,de + jr nc, ccdiv_4 + add hl,de +ccdiv_4: + djnz ccdiv_3 + rla + cpl + ex de,hl + ld h,c + ld l,a + pop bc + ret + +; +; As above but signed +; +;ccdiv: TODO + +cccase: + ex de,hl + pop hl +cccase1: + call cccase4 + ld a,e + cp c + jr nz,cccase2 + ld a,d + cp b + jr nz,cccase2 + call cccase4 + jr z,cccase3 + push bc + ret +cccase2: + call cccase4 + jr nz,cccase1 +cccase3: + dec hl + dec hl + dec hl + ld d,(hl) + dec hl + ld e,(hl) + ex de,hl +cccallhl: + jp (hl) +cccase4: + ld c,(hl) + inc hl + ld b,(hl) + inc hl + ld a,c + or b + ret diff --git a/Applications/SmallC/Z80/syscall/__accept.s b/Applications/SmallC/Z80/syscall/__accept.s new file mode 100644 index 00000000..44f40a43 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__accept.s @@ -0,0 +1,7 @@ + .code + + .export __accept + +__accept: + ld hl, 94 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__exit.s b/Applications/SmallC/Z80/syscall/__exit.s new file mode 100644 index 00000000..4602ba09 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__exit.s @@ -0,0 +1,7 @@ + .code + + .export __exit + +__exit: + ld hl, 0 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__fork.s b/Applications/SmallC/Z80/syscall/__fork.s new file mode 100644 index 00000000..9b46cacc --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__fork.s @@ -0,0 +1,7 @@ + .code + + .export __fork + +__fork: + ld hl, 32 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__fstat.s b/Applications/SmallC/Z80/syscall/__fstat.s new file mode 100644 index 00000000..8e9abca0 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__fstat.s @@ -0,0 +1,7 @@ + .code + + .export __fstat + +__fstat: + ld hl, 16 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__getdirent.s b/Applications/SmallC/Z80/syscall/__getdirent.s new file mode 100644 index 00000000..98477258 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__getdirent.s @@ -0,0 +1,7 @@ + .code + + .export __getdirent + +__getdirent: + ld hl, 24 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__getfsys.s b/Applications/SmallC/Z80/syscall/__getfsys.s new file mode 100644 index 00000000..541598fc --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__getfsys.s @@ -0,0 +1,7 @@ + .code + + .export __getfsys + +__getfsys: + ld hl, 22 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__getsockaddrs.s b/Applications/SmallC/Z80/syscall/__getsockaddrs.s new file mode 100644 index 00000000..9dba91a3 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__getsockaddrs.s @@ -0,0 +1,7 @@ + .code + + .export __getsockaddrs + +__getsockaddrs: + ld hl, 95 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__lseek.s b/Applications/SmallC/Z80/syscall/__lseek.s new file mode 100644 index 00000000..f6590287 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__lseek.s @@ -0,0 +1,7 @@ + .code + + .export __lseek + +__lseek: + ld hl, 9 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys66.s b/Applications/SmallC/Z80/syscall/__nosys66.s new file mode 100644 index 00000000..7f5eebcf --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys66.s @@ -0,0 +1,7 @@ + .code + + .export __nosys66 + +__nosys66: + ld hl, 66 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys67.s b/Applications/SmallC/Z80/syscall/__nosys67.s new file mode 100644 index 00000000..8fd9f80f --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys67.s @@ -0,0 +1,7 @@ + .code + + .export __nosys67 + +__nosys67: + ld hl, 67 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys68.s b/Applications/SmallC/Z80/syscall/__nosys68.s new file mode 100644 index 00000000..e5df38c7 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys68.s @@ -0,0 +1,7 @@ + .code + + .export __nosys68 + +__nosys68: + ld hl, 68 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys69.s b/Applications/SmallC/Z80/syscall/__nosys69.s new file mode 100644 index 00000000..9658cb4e --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys69.s @@ -0,0 +1,7 @@ + .code + + .export __nosys69 + +__nosys69: + ld hl, 69 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys70.s b/Applications/SmallC/Z80/syscall/__nosys70.s new file mode 100644 index 00000000..70deb0fb --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys70.s @@ -0,0 +1,7 @@ + .code + + .export __nosys70 + +__nosys70: + ld hl, 70 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys71.s b/Applications/SmallC/Z80/syscall/__nosys71.s new file mode 100644 index 00000000..cdf557ae --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys71.s @@ -0,0 +1,7 @@ + .code + + .export __nosys71 + +__nosys71: + ld hl, 71 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys80.s b/Applications/SmallC/Z80/syscall/__nosys80.s new file mode 100644 index 00000000..fcf2ad46 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys80.s @@ -0,0 +1,7 @@ + .code + + .export __nosys80 + +__nosys80: + ld hl, 80 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys81.s b/Applications/SmallC/Z80/syscall/__nosys81.s new file mode 100644 index 00000000..b768c029 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys81.s @@ -0,0 +1,7 @@ + .code + + .export __nosys81 + +__nosys81: + ld hl, 81 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys82.s b/Applications/SmallC/Z80/syscall/__nosys82.s new file mode 100644 index 00000000..1e11f307 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys82.s @@ -0,0 +1,7 @@ + .code + + .export __nosys82 + +__nosys82: + ld hl, 82 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys83.s b/Applications/SmallC/Z80/syscall/__nosys83.s new file mode 100644 index 00000000..a6e468b1 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys83.s @@ -0,0 +1,7 @@ + .code + + .export __nosys83 + +__nosys83: + ld hl, 83 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys84.s b/Applications/SmallC/Z80/syscall/__nosys84.s new file mode 100644 index 00000000..33df767e --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys84.s @@ -0,0 +1,7 @@ + .code + + .export __nosys84 + +__nosys84: + ld hl, 84 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys85.s b/Applications/SmallC/Z80/syscall/__nosys85.s new file mode 100644 index 00000000..a78b7901 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys85.s @@ -0,0 +1,7 @@ + .code + + .export __nosys85 + +__nosys85: + ld hl, 85 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys86.s b/Applications/SmallC/Z80/syscall/__nosys86.s new file mode 100644 index 00000000..3383d307 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys86.s @@ -0,0 +1,7 @@ + .code + + .export __nosys86 + +__nosys86: + ld hl, 86 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys87.s b/Applications/SmallC/Z80/syscall/__nosys87.s new file mode 100644 index 00000000..54a9ce7b --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys87.s @@ -0,0 +1,7 @@ + .code + + .export __nosys87 + +__nosys87: + ld hl, 87 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys88.s b/Applications/SmallC/Z80/syscall/__nosys88.s new file mode 100644 index 00000000..21c899e9 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys88.s @@ -0,0 +1,7 @@ + .code + + .export __nosys88 + +__nosys88: + ld hl, 88 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__nosys89.s b/Applications/SmallC/Z80/syscall/__nosys89.s new file mode 100644 index 00000000..a1227d2d --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__nosys89.s @@ -0,0 +1,7 @@ + .code + + .export __nosys89 + +__nosys89: + ld hl, 89 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__pause.s b/Applications/SmallC/Z80/syscall/__pause.s new file mode 100644 index 00000000..14f6ebeb --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__pause.s @@ -0,0 +1,7 @@ + .code + + .export __pause + +__pause: + ld hl, 37 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__profil.s b/Applications/SmallC/Z80/syscall/__profil.s new file mode 100644 index 00000000..887acdd1 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__profil.s @@ -0,0 +1,7 @@ + .code + + .export __profil + +__profil: + ld hl, 56 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__recvfrom.s b/Applications/SmallC/Z80/syscall/__recvfrom.s new file mode 100644 index 00000000..1ed6a465 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__recvfrom.s @@ -0,0 +1,7 @@ + .code + + .export __recvfrom + +__recvfrom: + ld hl, 97 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__select.s b/Applications/SmallC/Z80/syscall/__select.s new file mode 100644 index 00000000..30aabdf8 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__select.s @@ -0,0 +1,7 @@ + .code + + .export __select + +__select: + ld hl, 72 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__sendto.s b/Applications/SmallC/Z80/syscall/__sendto.s new file mode 100644 index 00000000..58ed1e88 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__sendto.s @@ -0,0 +1,7 @@ + .code + + .export __sendto + +__sendto: + ld hl, 96 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__shutdown.s b/Applications/SmallC/Z80/syscall/__shutdown.s new file mode 100644 index 00000000..12a6a085 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__shutdown.s @@ -0,0 +1,7 @@ + .code + + .export __shutdown + +__shutdown: + ld hl, 98 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__sigdisp.s b/Applications/SmallC/Z80/syscall/__sigdisp.s new file mode 100644 index 00000000..25ac7354 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__sigdisp.s @@ -0,0 +1,7 @@ + .code + + .export __sigdisp + +__sigdisp: + ld hl, 59 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__stat.s b/Applications/SmallC/Z80/syscall/__stat.s new file mode 100644 index 00000000..c93a17b0 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__stat.s @@ -0,0 +1,7 @@ + .code + + .export __stat + +__stat: + ld hl, 15 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__stime.s b/Applications/SmallC/Z80/syscall/__stime.s new file mode 100644 index 00000000..ac0371d3 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__stime.s @@ -0,0 +1,7 @@ + .code + + .export __stime + +__stime: + ld hl, 28 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__time.s b/Applications/SmallC/Z80/syscall/__time.s new file mode 100644 index 00000000..57bc840b --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__time.s @@ -0,0 +1,7 @@ + .code + + .export __time + +__time: + ld hl, 27 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__umount.s b/Applications/SmallC/Z80/syscall/__umount.s new file mode 100644 index 00000000..72a6695e --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__umount.s @@ -0,0 +1,7 @@ + .code + + .export __umount + +__umount: + ld hl, 34 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/__uname.s b/Applications/SmallC/Z80/syscall/__uname.s new file mode 100644 index 00000000..8e886cfc --- /dev/null +++ b/Applications/SmallC/Z80/syscall/__uname.s @@ -0,0 +1,7 @@ + .code + + .export __uname + +__uname: + ld hl, 54 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_access.s b/Applications/SmallC/Z80/syscall/_access.s new file mode 100644 index 00000000..83b4b174 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_access.s @@ -0,0 +1,7 @@ + .code + + .export _access + +_access: + ld hl, 12 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_acct.s b/Applications/SmallC/Z80/syscall/_acct.s new file mode 100644 index 00000000..f189fa05 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_acct.s @@ -0,0 +1,7 @@ + .code + + .export _acct + +_acct: + ld hl, 63 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_alarm.s b/Applications/SmallC/Z80/syscall/_alarm.s new file mode 100644 index 00000000..9ad407cf --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_alarm.s @@ -0,0 +1,7 @@ + .code + + .export _alarm + +_alarm: + ld hl, 38 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_bind.s b/Applications/SmallC/Z80/syscall/_bind.s new file mode 100644 index 00000000..9adecd92 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_bind.s @@ -0,0 +1,7 @@ + .code + + .export _bind + +_bind: + ld hl, 92 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_brk.s b/Applications/SmallC/Z80/syscall/_brk.s new file mode 100644 index 00000000..86233ae1 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_brk.s @@ -0,0 +1,7 @@ + .code + + .export _brk + +_brk: + ld hl, 30 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_chdir.s b/Applications/SmallC/Z80/syscall/_chdir.s new file mode 100644 index 00000000..0706e645 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_chdir.s @@ -0,0 +1,7 @@ + .code + + .export _chdir + +_chdir: + ld hl, 10 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_chmod.s b/Applications/SmallC/Z80/syscall/_chmod.s new file mode 100644 index 00000000..c1de97d8 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_chmod.s @@ -0,0 +1,7 @@ + .code + + .export _chmod + +_chmod: + ld hl, 13 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_chown.s b/Applications/SmallC/Z80/syscall/_chown.s new file mode 100644 index 00000000..67a094a7 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_chown.s @@ -0,0 +1,7 @@ + .code + + .export _chown + +_chown: + ld hl, 14 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_chroot.s b/Applications/SmallC/Z80/syscall/_chroot.s new file mode 100644 index 00000000..f637eb21 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_chroot.s @@ -0,0 +1,7 @@ + .code + + .export _chroot + +_chroot: + ld hl, 46 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_close.s b/Applications/SmallC/Z80/syscall/_close.s new file mode 100644 index 00000000..d36f3bdf --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_close.s @@ -0,0 +1,7 @@ + .code + + .export _close + +_close: + ld hl, 2 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_connect.s b/Applications/SmallC/Z80/syscall/_connect.s new file mode 100644 index 00000000..56fac39f --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_connect.s @@ -0,0 +1,7 @@ + .code + + .export _connect + +_connect: + ld hl, 93 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_dup.s b/Applications/SmallC/Z80/syscall/_dup.s new file mode 100644 index 00000000..77987cb7 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_dup.s @@ -0,0 +1,7 @@ + .code + + .export _dup + +_dup: + ld hl, 17 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_dup2.s b/Applications/SmallC/Z80/syscall/_dup2.s new file mode 100644 index 00000000..180c230b --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_dup2.s @@ -0,0 +1,7 @@ + .code + + .export _dup2 + +_dup2: + ld hl, 36 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_execve.s b/Applications/SmallC/Z80/syscall/_execve.s new file mode 100644 index 00000000..9751d553 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_execve.s @@ -0,0 +1,7 @@ + .code + + .export _execve + +_execve: + ld hl, 23 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_fchdir.s b/Applications/SmallC/Z80/syscall/_fchdir.s new file mode 100644 index 00000000..866e9b37 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_fchdir.s @@ -0,0 +1,7 @@ + .code + + .export _fchdir + +_fchdir: + ld hl, 48 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_fchmod.s b/Applications/SmallC/Z80/syscall/_fchmod.s new file mode 100644 index 00000000..79d2888a --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_fchmod.s @@ -0,0 +1,7 @@ + .code + + .export _fchmod + +_fchmod: + ld hl, 49 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_fchown.s b/Applications/SmallC/Z80/syscall/_fchown.s new file mode 100644 index 00000000..6ad60d92 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_fchown.s @@ -0,0 +1,7 @@ + .code + + .export _fchown + +_fchown: + ld hl, 50 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_fcntl.s b/Applications/SmallC/Z80/syscall/_fcntl.s new file mode 100644 index 00000000..4097e02a --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_fcntl.s @@ -0,0 +1,7 @@ + .code + + .export _fcntl + +_fcntl: + ld hl, 47 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_flock.s b/Applications/SmallC/Z80/syscall/_flock.s new file mode 100644 index 00000000..ec12c712 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_flock.s @@ -0,0 +1,7 @@ + .code + + .export _flock + +_flock: + ld hl, 60 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getegid.s b/Applications/SmallC/Z80/syscall/_getegid.s new file mode 100644 index 00000000..8849be51 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getegid.s @@ -0,0 +1,7 @@ + .code + + .export _getegid + +_getegid: + ld hl, 45 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_geteuid.s b/Applications/SmallC/Z80/syscall/_geteuid.s new file mode 100644 index 00000000..191fda6f --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_geteuid.s @@ -0,0 +1,7 @@ + .code + + .export _geteuid + +_geteuid: + ld hl, 44 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getgid.s b/Applications/SmallC/Z80/syscall/_getgid.s new file mode 100644 index 00000000..45c1a4f3 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getgid.s @@ -0,0 +1,7 @@ + .code + + .export _getgid + +_getgid: + ld hl, 41 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getgroups.s b/Applications/SmallC/Z80/syscall/_getgroups.s new file mode 100644 index 00000000..498c9e07 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getgroups.s @@ -0,0 +1,7 @@ + .code + + .export _getgroups + +_getgroups: + ld hl, 74 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getpgrp.s b/Applications/SmallC/Z80/syscall/_getpgrp.s new file mode 100644 index 00000000..f8ad3131 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getpgrp.s @@ -0,0 +1,7 @@ + .code + + .export _getpgrp + +_getpgrp: + ld hl, 61 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getpid.s b/Applications/SmallC/Z80/syscall/_getpid.s new file mode 100644 index 00000000..8eec6c25 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getpid.s @@ -0,0 +1,7 @@ + .code + + .export _getpid + +_getpid: + ld hl, 18 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getppid.s b/Applications/SmallC/Z80/syscall/_getppid.s new file mode 100644 index 00000000..a2069295 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getppid.s @@ -0,0 +1,7 @@ + .code + + .export _getppid + +_getppid: + ld hl, 19 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getrlimit.s b/Applications/SmallC/Z80/syscall/_getrlimit.s new file mode 100644 index 00000000..b266ee62 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getrlimit.s @@ -0,0 +1,7 @@ + .code + + .export _getrlimit + +_getrlimit: + ld hl, 75 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getsid.s b/Applications/SmallC/Z80/syscall/_getsid.s new file mode 100644 index 00000000..ee02cc48 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getsid.s @@ -0,0 +1,7 @@ + .code + + .export _getsid + +_getsid: + ld hl, 79 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_getuid.s b/Applications/SmallC/Z80/syscall/_getuid.s new file mode 100644 index 00000000..617ef1e7 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_getuid.s @@ -0,0 +1,7 @@ + .code + + .export _getuid + +_getuid: + ld hl, 20 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_ioctl.s b/Applications/SmallC/Z80/syscall/_ioctl.s new file mode 100644 index 00000000..3cfcaee5 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_ioctl.s @@ -0,0 +1,7 @@ + .code + + .export _ioctl + +_ioctl: + ld hl, 29 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_kill.s b/Applications/SmallC/Z80/syscall/_kill.s new file mode 100644 index 00000000..13b813bb --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_kill.s @@ -0,0 +1,7 @@ + .code + + .export _kill + +_kill: + ld hl, 39 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_link.s b/Applications/SmallC/Z80/syscall/_link.s new file mode 100644 index 00000000..bc1535c0 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_link.s @@ -0,0 +1,7 @@ + .code + + .export _link + +_link: + ld hl, 5 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_listen.s b/Applications/SmallC/Z80/syscall/_listen.s new file mode 100644 index 00000000..d89b5960 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_listen.s @@ -0,0 +1,7 @@ + .code + + .export _listen + +_listen: + ld hl, 91 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_memalloc.s b/Applications/SmallC/Z80/syscall/_memalloc.s new file mode 100644 index 00000000..6e798289 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_memalloc.s @@ -0,0 +1,7 @@ + .code + + .export _memalloc + +_memalloc: + ld hl, 64 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_memfree.s b/Applications/SmallC/Z80/syscall/_memfree.s new file mode 100644 index 00000000..3f977183 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_memfree.s @@ -0,0 +1,7 @@ + .code + + .export _memfree + +_memfree: + ld hl, 65 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_mkdir.s b/Applications/SmallC/Z80/syscall/_mkdir.s new file mode 100644 index 00000000..bf5ba461 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_mkdir.s @@ -0,0 +1,7 @@ + .code + + .export _mkdir + +_mkdir: + ld hl, 51 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_mknod.s b/Applications/SmallC/Z80/syscall/_mknod.s new file mode 100644 index 00000000..3463376c --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_mknod.s @@ -0,0 +1,7 @@ + .code + + .export _mknod + +_mknod: + ld hl, 4 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_mount.s b/Applications/SmallC/Z80/syscall/_mount.s new file mode 100644 index 00000000..9b92aca7 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_mount.s @@ -0,0 +1,7 @@ + .code + + .export _mount + +_mount: + ld hl, 33 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_nice.s b/Applications/SmallC/Z80/syscall/_nice.s new file mode 100644 index 00000000..c0956458 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_nice.s @@ -0,0 +1,7 @@ + .code + + .export _nice + +_nice: + ld hl, 58 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_open.s b/Applications/SmallC/Z80/syscall/_open.s new file mode 100644 index 00000000..1f17317d --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_open.s @@ -0,0 +1,7 @@ + .code + + .export _open + +_open: + ld hl, 1 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_pipe.s b/Applications/SmallC/Z80/syscall/_pipe.s new file mode 100644 index 00000000..3689f3b2 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_pipe.s @@ -0,0 +1,7 @@ + .code + + .export _pipe + +_pipe: + ld hl, 40 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_read.s b/Applications/SmallC/Z80/syscall/_read.s new file mode 100644 index 00000000..0d504a5e --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_read.s @@ -0,0 +1,7 @@ + .code + + .export _read + +_read: + ld hl, 7 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_rename.s b/Applications/SmallC/Z80/syscall/_rename.s new file mode 100644 index 00000000..eba2ece6 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_rename.s @@ -0,0 +1,7 @@ + .code + + .export _rename + +_rename: + ld hl, 3 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_rmdir.s b/Applications/SmallC/Z80/syscall/_rmdir.s new file mode 100644 index 00000000..8bab7327 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_rmdir.s @@ -0,0 +1,7 @@ + .code + + .export _rmdir + +_rmdir: + ld hl, 52 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_sbrk.s b/Applications/SmallC/Z80/syscall/_sbrk.s new file mode 100644 index 00000000..e0be95b6 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_sbrk.s @@ -0,0 +1,7 @@ + .code + + .export _sbrk + +_sbrk: + ld hl, 31 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setgid.s b/Applications/SmallC/Z80/syscall/_setgid.s new file mode 100644 index 00000000..c7180497 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setgid.s @@ -0,0 +1,7 @@ + .code + + .export _setgid + +_setgid: + ld hl, 26 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setgroups.s b/Applications/SmallC/Z80/syscall/_setgroups.s new file mode 100644 index 00000000..5556edb6 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setgroups.s @@ -0,0 +1,7 @@ + .code + + .export _setgroups + +_setgroups: + ld hl, 73 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setpgid.s b/Applications/SmallC/Z80/syscall/_setpgid.s new file mode 100644 index 00000000..d8fdc442 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setpgid.s @@ -0,0 +1,7 @@ + .code + + .export _setpgid + +_setpgid: + ld hl, 77 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setpgrp.s b/Applications/SmallC/Z80/syscall/_setpgrp.s new file mode 100644 index 00000000..95e3f92b --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setpgrp.s @@ -0,0 +1,7 @@ + .code + + .export _setpgrp + +_setpgrp: + ld hl, 53 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setrlimit.s b/Applications/SmallC/Z80/syscall/_setrlimit.s new file mode 100644 index 00000000..ef82605c --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setrlimit.s @@ -0,0 +1,7 @@ + .code + + .export _setrlimit + +_setrlimit: + ld hl, 76 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setsid.s b/Applications/SmallC/Z80/syscall/_setsid.s new file mode 100644 index 00000000..cb93e123 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setsid.s @@ -0,0 +1,7 @@ + .code + + .export _setsid + +_setsid: + ld hl, 78 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_setuid.s b/Applications/SmallC/Z80/syscall/_setuid.s new file mode 100644 index 00000000..bc30e8b8 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_setuid.s @@ -0,0 +1,7 @@ + .code + + .export _setuid + +_setuid: + ld hl, 25 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_signal.s b/Applications/SmallC/Z80/syscall/_signal.s new file mode 100644 index 00000000..e10cda2d --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_signal.s @@ -0,0 +1,7 @@ + .code + + .export _signal + +_signal: + ld hl, 35 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_socket.s b/Applications/SmallC/Z80/syscall/_socket.s new file mode 100644 index 00000000..5b7afe3a --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_socket.s @@ -0,0 +1,7 @@ + .code + + .export _socket + +_socket: + ld hl, 90 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_sync.s b/Applications/SmallC/Z80/syscall/_sync.s new file mode 100644 index 00000000..8dde179c --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_sync.s @@ -0,0 +1,7 @@ + .code + + .export _sync + +_sync: + ld hl, 11 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_times.s b/Applications/SmallC/Z80/syscall/_times.s new file mode 100644 index 00000000..7664d682 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_times.s @@ -0,0 +1,7 @@ + .code + + .export _times + +_times: + ld hl, 42 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_uadmin.s b/Applications/SmallC/Z80/syscall/_uadmin.s new file mode 100644 index 00000000..f0decdb2 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_uadmin.s @@ -0,0 +1,7 @@ + .code + + .export _uadmin + +_uadmin: + ld hl, 57 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_umask.s b/Applications/SmallC/Z80/syscall/_umask.s new file mode 100644 index 00000000..db1ebe79 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_umask.s @@ -0,0 +1,7 @@ + .code + + .export _umask + +_umask: + ld hl, 21 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_unlink.s b/Applications/SmallC/Z80/syscall/_unlink.s new file mode 100644 index 00000000..cd8b5565 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_unlink.s @@ -0,0 +1,7 @@ + .code + + .export _unlink + +_unlink: + ld hl, 6 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_utime.s b/Applications/SmallC/Z80/syscall/_utime.s new file mode 100644 index 00000000..906b0833 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_utime.s @@ -0,0 +1,7 @@ + .code + + .export _utime + +_utime: + ld hl, 43 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_waitpid.s b/Applications/SmallC/Z80/syscall/_waitpid.s new file mode 100644 index 00000000..6de2d73c --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_waitpid.s @@ -0,0 +1,7 @@ + .code + + .export _waitpid + +_waitpid: + ld hl, 55 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_write.s b/Applications/SmallC/Z80/syscall/_write.s new file mode 100644 index 00000000..2f868add --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_write.s @@ -0,0 +1,7 @@ + .code + + .export _write + +_write: + ld hl, 8 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/_yield.s b/Applications/SmallC/Z80/syscall/_yield.s new file mode 100644 index 00000000..94d73ccb --- /dev/null +++ b/Applications/SmallC/Z80/syscall/_yield.s @@ -0,0 +1,7 @@ + .code + + .export _yield + +_yield: + ld hl, 62 + jp __syscall diff --git a/Applications/SmallC/Z80/syscall/syscall.s b/Applications/SmallC/Z80/syscall/syscall.s new file mode 100644 index 00000000..5bebfe61 --- /dev/null +++ b/Applications/SmallC/Z80/syscall/syscall.s @@ -0,0 +1,19 @@ + .export __syscall + + .code +__syscall: + ex (sp), hl ; hl is now return addr + ; stack is syscall + ex de, hl ; save return addr in de + rst 0x30 + ex de, hl ; undo the magic + ex (sp), hl + ex de, hl ; return with HL + ret nc ; ok + ld (_errno), hl ; error path + ld hl, 0xffff + ret + + .data + +_errno: .word 0 diff --git a/Applications/SmallC/tools/gen-syscall.c b/Applications/SmallC/tools/gen-syscall.c new file mode 100644 index 00000000..8f0fe7ff --- /dev/null +++ b/Applications/SmallC/tools/gen-syscall.c @@ -0,0 +1,65 @@ +/* + * Generate the syscall functions. For Z80 at the moment. Extend to + * do the others as well + */ + +#include +#include +#include +#include "syscall_name.h" + +static char namebuf[128]; + +/* + * For Z80 it's kind of simple - load the call number and jump + * to the common helper. + */ +static void write_Z80_call(int n) +{ + FILE *fp; + snprintf(namebuf, 128, "Z80/syscall/_%s.s", syscall_name[n]); + fp = fopen(namebuf, "w"); + if (fp == NULL) { + perror(namebuf); + exit(1); + } + fprintf(fp, "\t.code\n\n"); + fprintf(fp, "\t.export _%s\n\n", syscall_name[n]); + fprintf(fp, "_%s:\n\tld hl, %d\n", syscall_name[n], n); + fprintf(fp, "\tjp __syscall\n"); + fclose(fp); +} + +static void write_Z80_call_table(void) +{ + int i; + for (i = 0; i < NR_SYSCALL; i++) + write_Z80_call(i); +} + +static void write_Z80_makefile(void) +{ + int i; + FILE *fp = fopen("Z80/syscall/Makefile", "w"); + if (fp == NULL) { + perror("Makefile"); + exit(1); + } + fprintf(fp, "SRCS = syscall.s\n", syscall_name[0]); + for (i = 0; i < NR_SYSCALL; i++) + fprintf(fp, "SRCS += _%s.s\n", syscall_name[i]); + fprintf(fp, "\nsyscall.a: $(SRCS)\n"); + fprintf(fp, "\t$(CROSS_AR) rc syslib.lib $(OBJS)\n\n"); + fprintf(fp, "$(OBJS): %%.o: %%.s\n"); + fprintf(fp, "\t$(CROSS_AS) $<\n\n"); + fprintf(fp, "clean:\n"); + fprintf(fp, "\trm -f $(OBJS) $(SRCS) syscall.a *~\n\n"); + fclose(fp); +} + +int main(int argc, char *argv[]) +{ + write_Z80_makefile(); + write_Z80_call_table(); + exit(0); +}