Skip to content

Commit

Permalink
6800: various fixes to things to line up with the compiler
Browse files Browse the repository at this point in the history
This gets us into init but things then go wrong somewhere
  • Loading branch information
EtchedPixels committed Dec 10, 2024
1 parent 41f99af commit 6c2600e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 75 deletions.
60 changes: 24 additions & 36 deletions Kernel/cpu-6800/lowlevel-6800.S
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,11 @@ outd:



;
; We are called from SWI. The stack holds 7 bytes of return
; information, A holds the syscall number on entry, B the arg count
; Arguments are left to right ordered.
;
; On enry our frame looks like this
;
; 12-> more arguments
; 11-10 last arg
; 11-10 first argument
; 9-8 return PC for caller to syscall
; 7-6 UserPC
; 5-4 X
Expand All @@ -129,30 +125,23 @@ outd:
;
;
unix_syscall_entry:
sts @tmp ; No ABX so we have to do a bit of work
addb @tmp+1
stab @tmp+1
bcc noinc
inc @tmp
noinc:
ldx @tmp
inx ; Because we are not using TSX
tsx
sts _udata+U_DATA__U_SYSCALL_SP
staa _udata+U_DATA__U_CALLNO
ldaa 7,x
ldab 8,x
ldaa 9,x
ldab 10,x
staa _udata+U_DATA__U_ARGN
stab _udata+U_DATA__U_ARGN+1
ldaa 5,x
ldab 6,x
ldaa 11,x
ldab 12,x
staa _udata+U_DATA__U_ARGN+2
stab _udata+U_DATA__U_ARGN+3
ldaa 3,x
ldab 4,x
ldaa 13,x
ldab 14,x
staa _udata+U_DATA__U_ARGN+4
stab _udata+U_DATA__U_ARGN+5
ldaa ,x
ldab 1,x
ldaa 15,x
ldab 16,x
staa _udata+U_DATA__U_ARGN+6
stab _udata+U_DATA__U_ARGN+7
ldaa #1
Expand Down Expand Up @@ -514,16 +503,15 @@ to_rts:

_memset:
tsx
ldaa 4,x
ldab 5,x
stab @tmp ; destination
ldaa 2,x ; length
ldab 3,x
ldx 6,x ; destination
stab @tmp ; pattern
ldaa 6,x ; length
ldab 7,x
ldx 2,x ; destination
bsr snextblock
tsx
ldaa 7,x
ldab 8,x
ldaa 2,x
ldab 3,x
jmp __cleanup6

snextblock:
Expand Down Expand Up @@ -559,21 +547,21 @@ clearloop:

_memcpy:
tsx
ldaa 6,x
ldab 7,x
ldaa 2,x
ldab 3,x
staa @tmp ; destination
stab @tmp+1
ldaa 2,x ; length
oraa 3,x
ldaa 6,x ; length
oraa 7,x
beq nocopy
ldaa 2,x
ldab 3,x
ldaa 6,x
ldab 7,x
ldx 4,x ; src
bsr nextblock
tsx
nocopy:
ldaa 6,x
ldab 7,x
ldaa 2,x
ldab 3,x
jmp __cleanup6

nextblock:
Expand Down
21 changes: 13 additions & 8 deletions Kernel/cpu-6800/stdarg.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/*
* This is a bit strange because our argments are left to right on
* the stack.
* stdarg.h - variable arguments
*
* From the ack cc
*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */

#ifndef _STDARG_H
#define _STDARG_H

typedef unsigned char *va_list;

#define __typesize(__type) (sizeof(__type) == 1 ? sizeof(int) : sizeof(__type))
typedef char* va_list;

#define va_start(__ap, __last) ((__ap) = (va_list)(&(__last)))
#define va_end(__ap)
#define __vasz(x) ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int) -1))

#define va_arg(__ap, __type) (*((__type *)(void *)(__ap -= __typesize(__type))))
#define va_start(ap, parmN) (ap = (va_list)&parmN + __vasz(parmN))
#define va_arg(ap, type) (*((type *)(void *)((ap += __vasz(type)) - __vasz(type))))
#define va_end(ap)

#endif
26 changes: 13 additions & 13 deletions Kernel/cpu-6800/usermem_std-6800.S
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

__uputc:
tsx
ldab 5,x
ldx 2,x
ldab 3,x
ldx 4,x
jsr map_proc_always
stab 0,x
jsr map_kernel
jmp __cleanup4

__uputw:
ldaa 4,x
tsx
ldab 5,x
ldx 2,x
ldaa 2,x
ldab 3,x
ldx 4,x
jsr map_proc_always
staa 0,x
stab 1,x
Expand All @@ -49,9 +49,9 @@ __ugetw:

__uzero:
tsx
ldaa 2,x
ldab 3,x
ldx 4,x
ldaa 4,x
ldab 5,x
ldx 2,x
jsr map_proc_always
; Optimize, unroll etc ?
pshb
Expand Down Expand Up @@ -84,13 +84,13 @@ __uget:
; We can optimize this a lot by abusing the stack etc but
; start simple. Take care as tmp/to/from are kernel mapped
tsx
ldx 2,x
ldx 6,x
stx @tmp
tsx
ldx 4,x ; to
stx @to
tsx
ldx 6,x ; from
ldx 2,x ; from
stx @from
ugetl:
ldx @from
Expand All @@ -117,13 +117,13 @@ __uput:
; We can optimize this a lot by abusing the stack etc but
; start simple. Take care as tmp/to/from are kernel mapped
tsx
ldx 2,x
stx @tmp
ldx 6,x
stx @tmp
tsx
ldx 4,x
stx @to
tsx
ldx 6,x ; from
ldx 2,x ; from
stx @from
uputl:
ldx @from
Expand Down
21 changes: 13 additions & 8 deletions Library/include/6800/stdarg.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/*
* This is a bit strange because our argments are left to right on
* the stack.
* stdarg.h - variable arguments
*
* From the ack cc
*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */

#ifndef _STDARG_H
#define _STDARG_H

typedef unsigned char *va_list;

#define __typesize(__type) (sizeof(__type) == 1 ? sizeof(int) : sizeof(__type))
typedef char* va_list;

#define va_start(__ap, __last) ((__ap) = (va_list)(&(__last)))
#define va_end(__ap)
#define __vasz(x) ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int) -1))

#define va_arg(__ap, __type) (*((__type *)(void *)(__ap -= __typesize(__type))))
#define va_start(ap, parmN) (ap = (va_list)&parmN + __vasz(parmN))
#define va_arg(ap, type) (*((type *)(void *)((ap += __vasz(type)) - __vasz(type))))
#define va_end(ap)

#endif
6 changes: 3 additions & 3 deletions Library/libs/crt0_6800.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ head:
.word $80A8
.byte 2 ; 6800 series
.byte 0 ; Needs only 6800 features
.byte >head ; Load page
.byte 1 ; Load at 0x100
.byte 0 ; No hints
.word __code_size
.word __data_size
.word __data-0x0100 ; Code
.word __data_size ; Data
.word __bss_size
.byte <start ; Offset to execute from
.byte 0 ; No size hint
Expand Down
8 changes: 4 additions & 4 deletions Library/libs/crt0nostdio_6800.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ head:
.word $80A8
.byte 2 ; 6800 series
.byte 0 ; Need no extra features
.byte >head ; Load page
.byte 1 ; Load at 0x0100
.byte 0 ; No hints
.word __code_size
.word __data_size
.word __bss_size
.word __data - 0x0100 ; Code size
.word __data_size ; Data size
.word __bss_size ; And BSS
.byte <start ; Offset to execute from
.byte 0 ; No size hint
.byte 0 ; No stack hint
Expand Down
6 changes: 3 additions & 3 deletions Library/tools/syscall_6800.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void write_call(int n)
fprintf(fp, "noerror:\n");
/* Non varargs functions do their own tail clean up */
if (syscall_args[n])
fprintf(fp, "\tjmp __popret%d\n", syscall_args[n] * 2);
fprintf(fp, "\tjmp __cleanup%d\n", syscall_args[n] * 2);
else
fprintf(fp, "\trts\n");
fclose(fp);
Expand All @@ -55,8 +55,8 @@ static void write_vacall(int n)
fprintf(fp, "\t.code\n\n");
fprintf(fp, "\t.export _%s\n\n", syscall_name[n]);
fprintf(fp, "_%s:\n\tldaa #%d\n", syscall_name[n], n);
/* This works because all varargs syscalls have 2 fixed arguments */
fprintf(fp, "\taddb #4\n");
/* We don't really use this for the fcc ABI but pass it for now */
fprintf(fp, "\tldab #4\n");
fprintf(fp, "\tswi\n");
fprintf(fp, "\tcpx @zero\n");
fprintf(fp, "\tbeq noerror\n");
Expand Down

0 comments on commit 6c2600e

Please sign in to comment.