From: Alan Cox Date: Mon, 1 Jan 2018 17:58:18 +0000 (+0000) Subject: v65c816-big: get to the point it starts up X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7176f706facea529bcab578ac62ff2b5e36d1f65;p=FUZIX.git v65c816-big: get to the point it starts up With these changes the image is loaded and appears to get put in the right places. We enter the discard code hit start, hit d_open and then the compiler generates self modifying code store to jmpvec+1/+2 jmp jmpvec So it looks like little bit of compiler hacking will be needed next, or possibly a dirty hack of putting jmpvec in stubs in bank 1 and bank 2 so that it writes the address into bank 2 and jumps to a bank 1 stub that can then fix up the mess. (Even better of course would be if someone was nuts enough to port the ANSI pcc compiler to 65C816) --- diff --git a/Kernel/platform-v65c816-big/Makefile b/Kernel/platform-v65c816-big/Makefile index 08bf4ec9..5a5c77c6 100644 --- a/Kernel/platform-v65c816-big/Makefile +++ b/Kernel/platform-v65c816-big/Makefile @@ -46,4 +46,6 @@ image: ../syscall_net.o net_native.o ../level2.o ../syscall_level2.o \ ../select.o dd if=../fuzix.bin of=fuzix.img bs=256 skip=255 count=1 - dd if=../fuzix.bin of=fuzix.img bs=256 seek=1 skip=1 conv=notrunc \ No newline at end of file + dd if=/dev/zero of=fuzix.img bs=256 seek=1 count=2 + dd if=fuzix.i of=fuzix.img bs=256 seek=3 count=239 + dd if=fuzix.d of=fuzix.img bs=256 seek=242 count=10 diff --git a/Kernel/platform-v65c816-big/crt0.s b/Kernel/platform-v65c816-big/crt0.s index 09d59d07..6abdbadb 100644 --- a/Kernel/platform-v65c816-big/crt0.s +++ b/Kernel/platform-v65c816-big/crt0.s @@ -35,25 +35,64 @@ entry: ; ; We are entered at $0102 just after the required magic number ; -; We get run from bank 0, our I/O writes would otherwise need to be -; 24bit +; The big image load is much more complicated as we need to shuffle +; chunks of it into banks, clear spaces and fire things up +; ; sep #$30 ; ensure we are in 8bit mode lda #'F' - sta $FE20 ; signal our arrival + sta f:$00FE20 ; signal our arrival sei ; interrupts off cld ; decimal off - - ; vectors is packed in DP, move it to FF00 rep #$30 .a16 .i16 - lda #255 - ldx #0 + +; +; Move the stubs into bank 1 +; + ldx #$0000 ldy #$FF00 - mvn KERNEL_BANK,KERNEL_BANK + lda #$00FF + mvn $1,$0 +; +; Move the code into bank 1 +; + ldx #$0300 + ldy #$0300 + lda #$EEFF + mvn $1,$0 +; +; Move the data into bank 2 +; + ldx #$F200 + ldy #$0200 + lda #$09FF + mvn $2,$0 +; +; Wipe the rest (bank was left as 2 here) +; + ldx #$0C00 + ldy #$0C01 + stz $0C00 + lda #$EFFE ; Wipe 0C00-FBFF + mvn $2,$2 + +; +; Wipe the low spaces +; + ldx #$0C00 + ldy #$0000 + lda #$1FF + mvn $2,$2 ; Wipe low memory using clear space in bank 2 + + ldx #$0C00 + ldy #$0000 + lda #$1FF + mvn $0,$2 ; Wipe low memory using clear space in bank 2 + sep #$30 .a8 @@ -61,8 +100,26 @@ entry: lda #'u' - sta $FE20 + sta f:$00FE20 + ; jml 1:switch (the assembler is too smart for its own good so + ; do it by hand) + .byte $5C + .word switch + .byte $01 + +; +; We are now running in the right bank of code +; + +switch: + lda #$02 + pha + plb + +; +; And the right bank of data +; rep #$10 .i16 @@ -70,7 +127,7 @@ entry: txs ; Stack (6502 not C) lda #'z' - sta $FE20 + sta f:$00FE20 ldx #kstackc_top-1 ; C stack stx sp @@ -78,31 +135,27 @@ entry: ldx #__BSS_RUN__ lda #'i' - sta $FE20 + sta f:$00FE20 txy iny - ; Wipe the BSS - - rep #$20 - .a16 - - lda #__BSS_SIZE__-2 ; must be >=2 bytes or else - stz a:0,x - mvn 0,0 - sep #$30 .a8 .i8 lda #'x' - sta $FE20 + sta f:$00FE20 jsr init_early lda #'.' - sta $FE20 + sta f:$00FE20 jsr init_hardware + lda #13 + sta f:$00FE20 + lda #10 + sta f:$00FE20 + jmp code .code @@ -110,17 +163,13 @@ entry: .a8 .i8 code: - lda #13 - sta $FE20 - lda #10 - sta $FE20 jsr _fuzix_main ; Should never return sei ; Spin stop: bra stop ; -; Processor vector table (0xFFE0) +; Processor vector table (0:0xFFE0) ; .segment "VECTORS" diff --git a/Kernel/platform-v65c816-big/devtty.c b/Kernel/platform-v65c816-big/devtty.c index abc9c33a..6dbbb005 100644 --- a/Kernel/platform-v65c816-big/devtty.c +++ b/Kernel/platform-v65c816-big/devtty.c @@ -6,9 +6,7 @@ #include #include #include - -static volatile uint8_t *uart = (volatile uint8_t *)0xFE20; -static volatile uint8_t *timer = (volatile uint8_t *)0xFE10; +#include static char tbuf1[TTYSIZ]; PTY_BUFFERS; @@ -35,7 +33,7 @@ ttyready_t tty_writeready(uint8_t minor) void tty_putc(uint8_t minor, unsigned char c) { minor; - uart[0] = c; + poke(0x2000|c); } void tty_setup(uint8_t minor) @@ -59,16 +57,16 @@ void tty_poll(void) { uint8_t x; - x = uart[1] & 1; + x = peek(0x21); if (x) { - x = uart[0]; + x = peek(0x20); tty_inproc(1, x); } } void platform_interrupt(void) { - uint8_t t = *timer; + uint8_t t = peek(0x10); tty_poll(); while(t--) { timer_interrupt(); diff --git a/Kernel/platform-v65c816-big/io.h b/Kernel/platform-v65c816-big/io.h new file mode 100644 index 00000000..caa0557d --- /dev/null +++ b/Kernel/platform-v65c816-big/io.h @@ -0,0 +1,2 @@ +extern uint8_t peek(uint8_t); +extern void poke(uint16_t); diff --git a/Kernel/platform-v65c816-big/ld65.cfg b/Kernel/platform-v65c816-big/ld65.cfg index d15411e0..4fbb56de 100644 --- a/Kernel/platform-v65c816-big/ld65.cfg +++ b/Kernel/platform-v65c816-big/ld65.cfg @@ -12,10 +12,10 @@ MEMORY { STUB: start = $FF00, size = $00E0, type = rw, fill = yes; VECTOR: start = $FFE0, size = $0020, type = rw, fill = yes; #Bank1 - MAIN: file = "fuzix.i", start = $0200, size = $10000, type = rw, fill = yes; + MAIN: file = "fuzix.i", start = $0300, size = $EF00, type = rw, fill = yes; #Bank2 UDATA: file = "fuzix.d", start = $0000, size = $0200, type = rw, fill = yes; - BSEG: file = "fuzix.d", start = $0200, size = $FE000, type = rw, fill = yes; + BSEG: file = "fuzix.d", start = $0200, size = $FE00, type = rw, fill = yes; } SEGMENTS { @@ -29,11 +29,12 @@ SEGMENTS { RODATA: load = BSEG, type = ro; DATA: load = BSEG, type = rw, define = yes; - BSS: load = BSEG, type = bss, define = yes; DISCARD: load = MAIN, type = ro; DISCARDDATA: load = BSEG, type = ro; + BSS: load = BSEG, type = bss, define = yes; + STUBS: load = STUB, type = ro; VECTORS: load = VECTOR, type = ro; } diff --git a/Kernel/platform-v65c816-big/v65.s b/Kernel/platform-v65c816-big/v65.s index 43ef72fa..a9eac6c8 100644 --- a/Kernel/platform-v65c816-big/v65.s +++ b/Kernel/platform-v65c816-big/v65.s @@ -145,6 +145,7 @@ outchar: .export _hd_kmap .export _hd_read_data .export _hd_write_data + .export _peek,_poke ; ; Disk copier @@ -205,3 +206,35 @@ hd_wpatch: _hd_kmap: .res 1 + +; +; For non bank 0 we can't just poke addresses from C but need helpers. +; We pass a single argument of dataoffset,data so we get a single +; value in XA for speed (X is offset A data) +; +_poke: + stx ptr1 + ldx #$FE + stx ptr1+1 + ldx #0 + phb + phx + plb + sta (ptr1) + plb + rts +_peek: + sta ptr1 + lda #$FE + sta ptr1+1 + phb + lda #0 + pha + plb + lda (ptr1) + plb + ldx #0 + rts + + + \ No newline at end of file