From c4bcf3f92ca59adc7414cf7ae548b900d008297f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 15 Jan 2008 15:02:26 +0000 Subject: [PATCH] * Fixes * More test code * it actually runs now, till _start. However, calling TOS from C is broken: we use 32 bit param alignment on funcs, but TOS expects 16 bit... need to use asm macros instead of funcs. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23531 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../platform/atari_m68k/atari_memory_map.h | 4 +- .../atari_m68k/fixup_tos_floppy_chksum.c | 2 +- src/system/boot/platform/atari_m68k/mmu.h | 2 +- src/system/boot/platform/atari_m68k/shell.S | 140 +++++++++++++++--- src/system/boot/platform/atari_m68k/start.c | 6 + .../boot/platform/atari_m68k/toscalls.h | 33 +++-- 6 files changed, 148 insertions(+), 39 deletions(-) diff --git a/src/system/boot/platform/atari_m68k/atari_memory_map.h b/src/system/boot/platform/atari_m68k/atari_memory_map.h index e8d83319b3..f9c4260e3f 100644 --- a/src/system/boot/platform/atari_m68k/atari_memory_map.h +++ b/src/system/boot/platform/atari_m68k/atari_memory_map.h @@ -21,7 +21,7 @@ #define ATARI_SHADOW_BASE 0xff000000 /* how we will use it */ -#define ATARI_ZBEOS_STACK_BASE 0x00008000 -#define ATARI_ZBEOS_BASE 0x00010000 /* from .prg shell.S will copy itself there */ +#define ATARI_ZBEOS_STACK_BASE 0x00040000 +#define ATARI_ZBEOS_BASE 0x00080000 /* from .prg shell.S will copy itself there */ #endif /* ATARI_MEMORY_MAP_H */ diff --git a/src/system/boot/platform/atari_m68k/fixup_tos_floppy_chksum.c b/src/system/boot/platform/atari_m68k/fixup_tos_floppy_chksum.c index 2114f1043c..87fe8c9932 100644 --- a/src/system/boot/platform/atari_m68k/fixup_tos_floppy_chksum.c +++ b/src/system/boot/platform/atari_m68k/fixup_tos_floppy_chksum.c @@ -23,7 +23,7 @@ int main(int argc, char **argv) v += *p++; sum += v; } - sum = 0x1234 - sum + 1; + sum = 0x1234 - sum /*+ 1*/; //sum = 0xaa55; // big endian *p++ = (uint8_t)(sum >> 8); diff --git a/src/system/boot/platform/atari_m68k/mmu.h b/src/system/boot/platform/atari_m68k/mmu.h index 261288fdd1..80e1412632 100644 --- a/src/system/boot/platform/atari_m68k/mmu.h +++ b/src/system/boot/platform/atari_m68k/mmu.h @@ -26,7 +26,7 @@ struct boot_mmu_ops { /* len=0 to disable */ status_t (*set_tt)(int which, addr_t pa, size_t len, uint32 perms); /* load root pointers */ - status_t (*load_rp)(XXX); + status_t (*load_rp)(void/*XXX*/); status_t (*enable_paging)(void); }; diff --git a/src/system/boot/platform/atari_m68k/shell.S b/src/system/boot/platform/atari_m68k/shell.S index a4613723a8..e76df424bd 100644 --- a/src/system/boot/platform/atari_m68k/shell.S +++ b/src/system/boot/platform/atari_m68k/shell.S @@ -81,30 +81,57 @@ sNumSectors: .word 0x0180 real_entry: + lea h1,%a0 + bsr puts + move.l #0x1234aa55,%d0 + bsr putx + + + //_membot + move.l #0x432,%a0 + move.l (%a0),%d0 + bsr putx + + //_memtop + move.l #0x436,%a0 + move.l (%a0),%d0 + bsr putx + + //_v_bas_ad + move.l #0x44e,%a0 + move.l (%a0),%d0 + bsr putx + //Pterm0 - //move.w #1,%d0 + //move.w #0,-(%sp) //trap #1 // first, determine if .prg (user) or bootsect (super) // Super() move.l #SUP_INQUIRE,-(%sp) - move.w #0x20,%d0 + move.w #0x20,-(%sp) trap #1 addq.l #6,%sp - cmp.w #SUP_SUPER,%d0 - beq floppy_start + + bsr putx + + cmp.l #SUP_USER,%d0 + bne floppy_start + lea h2,%a0 + bsr puts + bra prg_start //bra bootsect_start rts floppy_start: + lea h3,%a0 + bsr puts lea str,%a0 bsr puts - bra floppy_start + //bra floppy_start // no interrupt - and.w #0x0700,%sr - // setup stack - move.l #ATARI_ZBEOS_STACK_BASE,%sp + or.w #0x0700,%sr //XXX: check for enough RAM // load the rest move.w sNumSectors,%d2 @@ -117,7 +144,14 @@ floppy_start: bsr puts bra spin floppy_done: - jmp ATARI_ZBEOS_BASE+512 + lea h4,%a0 + bsr puts + // setup stack + move.l #ATARI_ZBEOS_STACK_BASE,%sp + lea h5,%a0 + bsr puts + //jmp ATARI_ZBEOS_BASE+512 + jmp _start //rts @@ -136,12 +170,13 @@ load_sectors: move.w #4,-(%sp) trap #13 add.l #14,%sp + bsr putx rts floppy_end: // .org FAILURE_STRING failure_string: - .string " Loading failed! Press key to reboot.\r\n" +// .string " Loading failed! Press key to reboot.\r\n" // .org DOT_STRING .string "." @@ -155,22 +190,49 @@ failure_string: // this block as valid boot block for the BIOS prg_start: + lea h4,%a0 + bsr puts +#if 0 // .prg: // we need to switch to supervisor mode anyway move.l #SUP_SET,-(%sp) - move.w #0x20,%d0 + move.w #0x20,-(%sp) trap #1 addq.l #6,%sp move.l %d0,saved_super_stack + + lea h5,%a0 + bsr puts + //Pterm0 + move.w #0,-(%sp) + trap #1 + + // copy the rest of the prg + move.l sNumSectors,%d0 + sub.l #1,%d0 + lea _bs_entry,%a0 + move.l #ATARI_ZBEOS_BASE,%a1 + +nextsect: + move.l #512/4-1,%d1 +copysect_loop: + move.l (%a0)+,(%a1)+ + dbf %d1,copysect_loop + dbf %d0,nextsect +#endif + + lea str,%a0 + bsr puts // all done +spin: lea unimpl,%a0 bsr puts -spin: bra spin super_done: // XXX: copy the rest ! - jmp ATARI_ZBEOS_BASE+512 + //jmp ATARI_ZBEOS_BASE+512 + jmp _start saved_super_stack: .long 0 @@ -186,6 +248,33 @@ GLOBAL(gBootPartitionOffset): +putx: + movem.l %d0-%d2/%a0-%a2,-(%sp) + move.l #8-1,%d2 + move.l %d0,%d1 +putxloop: + move.l %d1,%d0 + lsl.l #4,%d1 + //swap %d0 + //lsr.l #8,%d0 + //lsr.l #4,%d0 + rol.l #4,%d0 + and.l #0x0f,%d0 + cmp.b #9,%d0 + ble putx0 + add.b #'a'-'0'-10,%d0 + //bra putxdisp +putx0: + add.b #'0',%d0 +putxdisp: + bsr putc + dbf %d2,putxloop + move.b #'\r',%d0 + bsr putc + move.b #'\n',%d0 + bsr putc + movem.l (%sp)+,%d0-%d2/%a0-%a2 + rts lea.l str,%a0 puts: @@ -195,10 +284,10 @@ puts: bsr putc bra .loopt .strout: - //Pterm0 - move.w #1,%d0 - trap #1 - + move.b #'\r',%d0 + bsr putc + move.b #'\n',%d0 + bsr putc rts .loop: @@ -207,21 +296,34 @@ puts: bra .loop rts + /* prints the char in d0.b to the console */ putc: - movem.l %a0,-(%sp) + movem.l %d0-%d2/%a0-%a2,-(%sp) move.w %d0,-(%sp) move.w #DEV_CON,-(%sp) // DEV_CON move.w #3,-(%sp) // Bconout trap #13 add.l #6,%sp - movem.l (%sp)+,%a0 + movem.l (%sp)+,%d0-%d2/%a0-%a2 rts + str: .string "Haiku!" +h1: + .string "H1" +h2: + .string "H2" +h3: + .string "H3" +h4: + .string "H4" +h5: + .string "H5" unimpl: .string "Unimplemented." + shell_end: //.fill (0x01fe - shell_end), 1, 0x55 .org 0x01fe diff --git a/src/system/boot/platform/atari_m68k/start.c b/src/system/boot/platform/atari_m68k/start.c index 52db87fccb..03eda8a2b3 100644 --- a/src/system/boot/platform/atari_m68k/start.c +++ b/src/system/boot/platform/atari_m68k/start.c @@ -108,6 +108,12 @@ void _start(void) { stage2_args args; + Bconout(DEV_CON, 'h'); + Bconout(DEV_CON, 'A'); + Bconout(DEV_CON, 'I'); + Bconout(DEV_CON, 'K'); + Bconout(DEV_CON, 'U'); + //asm("cld"); // Ain't nothing but a GCC thang. //asm("fninit"); // initialize floating point unit diff --git a/src/system/boot/platform/atari_m68k/toscalls.h b/src/system/boot/platform/atari_m68k/toscalls.h index 23f6086182..3aea90d489 100644 --- a/src/system/boot/platform/atari_m68k/toscalls.h +++ b/src/system/boot/platform/atari_m68k/toscalls.h @@ -15,7 +15,8 @@ extern "C" { #ifndef __ASSEMBLER__ #include -#endif +#endif /* __ASSEMBLER__ */ + /* * Atari BIOS calls @@ -169,7 +170,7 @@ extern int32 gemdos(uint16 nr, ...); #endif /* __ASSEMBLER__ */ -#ifdef __ASSEMBLER__ +#ifndef __ASSEMBLER__ /* * error mapping @@ -243,6 +244,8 @@ static inline const struct tos_osheader *tos_get_osheader() #define NF_COOKIE 0x5f5f4e46L //'__NF' #define NF_MAGIC 0x20021021L +#ifndef __ASSEMBLER__ + typedef struct { long magic; long (*nfGetID) (const char *); @@ -253,14 +256,18 @@ extern NatFeatCookie *gNatFeatCookie; static inline NatFeatCookie *nat_features(void) { + const struct tos_cookie *c; if (gNatFeatCookie == (void *)-1 || !gNatFeatCookie) return NULL; - gNatFeatCookie = tos_find_cookie(NF_COOKIE); - if (!gNatFeatCookie || gNatFeatCookie->magic != NF_MAGIC) { - gNatFeatCookie = (void *)-1; - return NULL; + c = tos_find_cookie(NF_COOKIE); + if (c) { + gNatFeatCookie = (NatFeatCookie *)c->pvalue; + if (gNatFeatCookie && gNatFeatCookie->magic == NF_MAGIC) { + return gNatFeatCookie; + } } - return c; + gNatFeatCookie = (NatFeatCookie *)-1; + return NULL; } @@ -269,21 +276,15 @@ static inline NatFeatCookie *nat_features(void) #define NF_XHDI "XHDI" #define nfxhdi(code, a...) \ -{ \ - gNatFeatCookie->nfCall((uint32) - if (gNatFeatCookie == NULL) { - c = tos_find_cookie(NF_COOKIE); - if (!c || c->magic != NF_MAGIC) - return NULL; - return c; -} +({ \ + gNatFeatCookie->nfCall((uint32)code, a##...); \ +}) #define NFXHversion() nfxhdi(0) #endif /* __ASSEMBLER__ */ - #ifdef __cplusplus } #endif