[haiku-commits] r37250 - haiku/trunk/src/system/boot/platform/atari_m68k

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 25 Jun 2010 10:30:17 +0200 (CEST)

Author: axeld
Date: 2010-06-25 10:30:17 +0200 (Fri, 25 Jun 2010)
New Revision: 37250
Changeset: http://dev.haiku-os.org/changeset/37250/haiku

Added:
   haiku/trunk/src/system/boot/platform/atari_m68k/debug.cpp
   haiku/trunk/src/system/boot/platform/atari_m68k/start.cpp
   haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.cpp
Removed:
   haiku/trunk/src/system/boot/platform/atari_m68k/debug.c
   haiku/trunk/src/system/boot/platform/atari_m68k/start.c
   haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.c
Modified:
   haiku/trunk/src/system/boot/platform/atari_m68k/Jamfile
   haiku/trunk/src/system/boot/platform/atari_m68k/atari_memory_map.h
   haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.h
Log:
* Renamed the remaining C files to C++ files.
* Fixed some copyrights.


Modified: haiku/trunk/src/system/boot/platform/atari_m68k/Jamfile
===================================================================
--- haiku/trunk/src/system/boot/platform/atari_m68k/Jamfile     2010-06-25 
08:03:58 UTC (rev 37249)
+++ haiku/trunk/src/system/boot/platform/atari_m68k/Jamfile     2010-06-25 
08:30:17 UTC (rev 37250)
@@ -26,7 +26,7 @@
 
 # cpu-specific stuff
 # should be moved to boot/arch/m68k/...
-# XXX: add 020+68851 support
+# TODO: add 020+68851 support
 KernelMergeObject boot_arch_m68k_030.o :
        mmu_030.cpp
        : -fno-pic -Wno-unused -m68030
@@ -45,9 +45,9 @@
 
 KernelMergeObject boot_platform_atari_m68k_other.o :
 #      shell.S
-       start.c
-       toscalls.c
-       debug.c
+       start.cpp
+       toscalls.cpp
+       debug.cpp
        #bios.S
        console.cpp
        #serial.cpp

Modified: haiku/trunk/src/system/boot/platform/atari_m68k/atari_memory_map.h
===================================================================
--- haiku/trunk/src/system/boot/platform/atari_m68k/atari_memory_map.h  
2010-06-25 08:03:58 UTC (rev 37249)
+++ haiku/trunk/src/system/boot/platform/atari_m68k/atari_memory_map.h  
2010-06-25 08:30:17 UTC (rev 37250)
@@ -5,6 +5,7 @@
 #ifndef ATARI_MEMORY_MAP_H
 #define ATARI_MEMORY_MAP_H
 
+
 /* the DMA-accessible RAM */
 /*#define ATARI_CHIPRAM_BASE                   0x00000000*/
 /* actually, the first 2kB aren't usable */

Copied: haiku/trunk/src/system/boot/platform/atari_m68k/debug.cpp (from rev 
37247, haiku/trunk/src/system/boot/platform/atari_m68k/debug.c)
===================================================================
--- haiku/trunk/src/system/boot/platform/atari_m68k/debug.cpp                   
        (rev 0)
+++ haiku/trunk/src/system/boot/platform/atari_m68k/debug.cpp   2010-06-25 
08:30:17 UTC (rev 37250)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004-2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include "keyboard.h"
+#include "toscalls.h"
+
+#include <boot/platform.h>
+#include <boot/stdio.h>
+#include <stdarg.h>
+
+#include <Errors.h>
+
+/*!    This works only after console_init() was called.
+*/
+void
+panic(const char *format, ...)
+{
+       const char greetings[] = "\n*** PANIC ***";
+       char buffer[512];
+       va_list list;
+
+       //platform_switch_to_text_mode();
+
+       Bconputs(DEV_CONSOLE, greetings);
+       // send to the emulator's stdout if available
+       nat_feat_debugprintf(greetings);
+       nat_feat_debugprintf("\n");
+
+       va_start(list, format);
+       vsnprintf(buffer, sizeof(buffer), format, list);
+       va_end(list);
+
+       Bconputs(DEV_CONSOLE, buffer);
+       // send to the emulator's stdout if available
+       nat_feat_debugprintf(buffer);
+       nat_feat_debugprintf("\n");
+
+       Bconputs(DEV_CONSOLE, "\nPress key to reboot.");
+
+       clear_key_buffer();
+       wait_for_key();
+       platform_exit();
+}
+
+
+void
+dprintf(const char *format, ...)
+{
+       char buffer[512];
+       va_list list;
+
+       va_start(list, format);
+       vsnprintf(buffer, sizeof(buffer), format, list);
+       va_end(list);
+
+       Bconput(DEV_AUX, buffer);
+
+       // send to the emulator's stdout if available
+       nat_feat_debugprintf(buffer);
+
+       //if (platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT)
+               Bconput(DEV_CONSOLE, buffer);
+}
+
+

Copied: haiku/trunk/src/system/boot/platform/atari_m68k/start.cpp (from rev 
37247, haiku/trunk/src/system/boot/platform/atari_m68k/start.c)
===================================================================
--- haiku/trunk/src/system/boot/platform/atari_m68k/start.cpp                   
        (rev 0)
+++ haiku/trunk/src/system/boot/platform/atari_m68k/start.cpp   2010-06-25 
08:30:17 UTC (rev 37250)
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2003-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Copyright 2008, François Revol, revol@xxxxxxxx All rights reserved.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <KernelExport.h>
+#include <boot/platform.h>
+#include <boot/heap.h>
+#include <boot/stage2.h>
+#include <arch/cpu.h>
+
+#include <string.h>
+
+#include "console.h"
+#include "cpu.h"
+#include "mmu.h"
+#include "keyboard.h"
+#include "toscalls.h"
+
+
+#define HEAP_SIZE 65536
+
+// GCC defined globals
+extern void (*__ctor_list)(void);
+extern void (*__ctor_end)(void);
+extern uint8 __bss_start;
+extern uint8 _end;
+
+extern "C" int main(stage2_args *args);
+extern "C" void _start(void);
+
+
+static uint32 sBootOptions;
+
+
+static void
+clear_bss(void)
+{
+       memset(&__bss_start, 0, &_end - &__bss_start);
+}
+
+
+static void
+call_ctors(void)
+{
+       void (**f)(void);
+
+       for (f = &__ctor_list; f < &__ctor_end; f++) {          
+               (**f)();
+       }
+}
+
+
+extern "C" uint32
+platform_boot_options(void)
+{
+#if 0
+       if (!gKernelArgs.fb.enabled)
+               sBootOptions |= check_for_boot_keys();
+#endif
+       return sBootOptions;
+}
+
+
+extern "C" void
+platform_start_kernel(void)
+{
+       static struct kernel_args *args = &gKernelArgs;
+               // something goes wrong when we pass &gKernelArgs directly
+               // to the assembler inline below - might be a bug in GCC
+               // or I don't see something important...
+       addr_t stackTop
+               = gKernelArgs.cpu_kstack[0].start + 
gKernelArgs.cpu_kstack[0].size;
+
+       //smp_init_other_cpus();
+       //serial_cleanup();
+       mmu_init_for_kernel();
+       //smp_boot_other_cpus();
+
+#warning M68K: stop ints
+       
+       dprintf("kernel entry at %lx\n",
+               gKernelArgs.kernel_image.elf_header.e_entry);
+
+       asm volatile (
+               "move.l %0,%%sp;        "                       // move stack 
out of way
+               : : "m" (stackTop));
+
+       asm volatile (
+               "or     #0x0700,%%sr; " : : );          // disable interrupts
+
+       asm volatile (
+               "move.l  #0x0,-(%%sp); "                // we're the BSP cpu (0)
+               "move.l         %0,-(%%sp);     "               // kernel args
+               "move.l         #0x0,-(%%sp);"          // dummy retval for 
call to main
+               "move.l         %1,-(%%sp);     "               // this is the 
start address
+               "rts;           "                                       // jump.
+               : : "g" (args), "g" 
(gKernelArgs.kernel_image.elf_header.e_entry));
+
+       // Huston, we have a problem!
+
+       asm volatile (
+               "and    #0xf8ff,%%sr; " : : );          // reenable interrupts
+
+       panic("kernel returned!\n");
+
+}
+
+
+extern "C" void
+platform_exit(void)
+{
+       // Terminate
+       // TODO: Puntaes() instead ?
+       Pterm0();
+}
+
+
+extern "C" void
+_start(void)
+{
+       stage2_args args;
+       Bconout(DEV_CON, 'H');
+
+       //asm("cld");                   // Ain't nothing but a GCC thang.
+       //asm("fninit");                // initialize floating point unit
+
+       clear_bss();
+       Bconout(DEV_CON, 'A');
+       call_ctors();
+               // call C++ constructors before doing anything else
+       Bconout(DEV_CON, 'I');
+
+       args.heap_size = HEAP_SIZE;
+       args.arguments = NULL;
+       
+       // so we can dprintf
+       init_nat_features();
+
+       //serial_init();
+       Bconout(DEV_CON, 'K');
+       console_init();
+       Bconout(DEV_CON, 'U');
+       dprintf("membot   = %p\n", (void*)*TOSVAR_membot);
+       dprintf("memtop   = %p\n", (void*)*TOSVAR_memtop);
+       dprintf("v_bas_ad = %p\n", *TOSVAR_v_bas_ad);
+       dprintf("phystop  = %p\n", (void*)*TOSVARphystop);
+       dprintf("ramtop   = %p\n", (void*)*TOSVARramtop);
+       cpu_init();
+       mmu_init();
+
+       // wait a bit to give the user the opportunity to press a key
+       spin(750000);
+
+       // reading the keyboard doesn't seem to work in graphics mode (maybe a 
bochs problem)
+       sBootOptions = check_for_boot_keys();
+       //if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT)
+               //serial_enable();
+
+       //apm_init();
+       //smp_init();
+       main(&args);
+}

Copied: haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.cpp (from rev 
37247, haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.c)
===================================================================
--- haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.cpp                
                (rev 0)
+++ haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.cpp        
2010-06-25 08:30:17 UTC (rev 37250)
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2008, François Revol, revol@xxxxxxxx All rights reserved.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <boot/platform.h>
+#include <boot/stage2.h>
+#include <boot/stdio.h>
+#include <stdarg.h>
+
+#include <Errors.h>
+
+#include "toscalls.h"
+
+
+void *gXHDIEntryPoint = NULL;
+uint32 gXHDIVersion = 0;
+
+NatFeatCookie *gNatFeatCookie = NULL;
+uint32 gDebugPrintfNatFeatID = 0;
+
+
+/*! Maps TOS error codes to native errors
+ */
+extern "C" status_t
+toserror(int32 err)
+{
+       // generated from:
+       // http://www.fortunecity.com/skyscraper/apple/308/html/appendd.htm
+       // with:
+       // while read N; do read V; read L; echo -e "\tcase $V: /* $N - $L 
*/\n\t\treturn EINVAL;"; done >> errs
+       switch (err) {
+       /* BIOS errors */
+       case 0: /* E_OK - No error */
+               return B_OK;
+       case -1: /* ERROR - Generic error */
+               return B_ERROR;
+       case -2: /* EDRVNR - Drive not ready */
+               return B_DEV_NOT_READY;
+       case -3: /* EUNCMD - Unknown command */
+               return EINVAL;  //XXX
+       case -4: /* E_CRC - CRC error */
+               return B_DEV_CRC_ERROR;
+       case -5: /* EBADRQ - Bad request */
+               return EINVAL;  //XXX
+       case -6: /* E_SEEK - Seek error */
+               return B_DEV_SEEK_ERROR;
+       case -7: /* EMEDIA - Unknown media */
+               return B_DEV_UNREADABLE;
+       case -8: /* ESECNF - Sector not found */
+               return B_DEV_FORMAT_ERROR;
+       case -9: /* EPAPER - Out of paper */
+               return ENODEV;
+       case -10: /* EWRITF - Write fault */
+               return B_DEV_WRITE_ERROR;
+       case -11: /* EREADF - Read fault */
+               return B_DEV_READ_ERROR;
+       case -12: /* EWRPRO - Device is write protected */
+               return B_READ_ONLY_DEVICE;
+       case -14: /* E_CHNG - Media change detected */
+               return B_DEV_MEDIA_CHANGED;
+       case -15: /* EUNDEV - Unknown device */
+               return B_DEV_BAD_DRIVE_NUM;
+       case -16: /* EBADSF - Bad sectors on format */
+               return B_DEV_UNREADABLE;
+       case -17: /* EOTHER - Insert other disk (request) */
+               return B_DEV_MEDIA_CHANGE_REQUESTED;
+       /* GEMDOS errors */
+       case -32: /* EINVFN - Invalid function */
+               return EINVAL;
+       case -33: /* EFILNF - File not found */
+               return B_FILE_NOT_FOUND;
+       case -34: /* EPTHNF - Path not found */
+               return B_ENTRY_NOT_FOUND;
+       case -35: /* ENHNDL - No more handles */
+               return B_NO_MORE_FDS;
+       case -36: /* EACCDN - Access denied */
+               return EACCES;
+       case -37: /* EIHNDL - Invalid handle */
+               return EBADF;
+       case -39: /* ENSMEM - Insufficient memory */
+               return ENOMEM;
+       case -40: /* EIMBA - Invalid memory block address */
+               return EFAULT;
+       case -46: /* EDRIVE - Invalid drive specification */
+               return B_DEV_BAD_DRIVE_NUM;
+       case -48: /* ENSAME - Cross device rename */
+               return EXDEV;
+       case -49: /* ENMFIL - No more files */
+               return EMFILE;
+       case -58: /* ELOCKED - Record is already locked */
+               return EINVAL;  //XXX
+       case -59: /* ENSLOCK - Invalid lock removal request */
+               return EINVAL;  //XXX
+       case -64: /* ERANGE or ENAMETOOLONG - Range error */
+               return ENAMETOOLONG;
+       case -65: /* EINTRN - Internal error */
+               return B_ERROR;
+       case -66: /* EPLFMT - Invalid program load format */
+               return ENOEXEC;
+       case -67: /* EGSBF - Memory block growth failure */
+               return EINVAL;
+       case -80: /* ELOOP - Too many symbolic links */
+               return ELOOP;
+       case -200: /* EMOUNT - Mount point crossed (indicator) */
+               return EINVAL;  
+       default:
+               return B_ERROR;
+       }
+}
+
+
+/*! Maps XHDI error codes to native errors
+ * cf. http://toshyp.atari.org/010008.htm#XHDI_20error_20codes
+ */
+extern "C" status_t
+xhdierror(int32 err)
+{
+       if (err <= -456) {
+               int ide = -(err + 456);
+               // ide status reg
+               // guessed mapping
+               if (ide & (1 << 1)) {   // track 0 not found
+                       return B_DEV_FORMAT_ERROR;
+               } else if (ide & (1 << 0)) {    // DAM not found
+                       return B_DEV_FORMAT_ERROR;
+               } else if (ide & (1 << 4)) {    // ID field not found
+                       return B_DEV_ID_ERROR;
+               } else if (ide & (1 << 7)) {    // bad block mark
+                       return B_DEV_FORMAT_ERROR;
+               } else if (ide & (1 << 6)) {    // uncorrectable error
+                       return B_DEV_UNREADABLE;
+               } else if (ide & (1 << 2)) {    // command aborted
+                       return EINTR;
+               } else if (ide & (1 << 5)) {    // media change
+                       return B_DEV_MEDIA_CHANGED;
+               } else if (ide & (1 << 3)) {    // media change requested
+                       return B_DEV_MEDIA_CHANGE_REQUESTED;
+               }
+               return B_ERROR;
+       } else if (err <= -200) {
+               /* SCSI errors */
+               int scsi = -(err + 200);
+               //XXX:
+               switch (scsi) {
+               case 0x06:
+                       return B_DEV_FORMAT_ERROR;
+               case 0x10:
+                       return B_DEV_FORMAT_ERROR;
+               case 0x11:
+                       return B_DEV_UNREADABLE;
+               case 0x12:
+                       return B_DEV_ID_ERROR;
+               case 0x13:
+                       return B_DEV_FORMAT_ERROR;
+               case 0x20:
+                       return EINTR;
+               case 0x28:
+                       return B_DEV_FORMAT_ERROR;
+               case 0x5a:
+                       return B_DEV_FORMAT_ERROR;
+               }
+       }
+       return toserror(err);
+}
+
+
+static void
+dump_tos_cookie(const struct tos_cookie *c)
+{
+       if (c != NULL) {
+               dprintf("%4.4s: 0x%08lx, %ld\n", (const char *)&c->cookie, 
c->ivalue,
+                       c->ivalue);
+       }
+}
+
+
+extern "C" void
+dump_tos_cookies(void)
+{
+       const tos_cookie *c = COOKIE_JAR;
+       dprintf("Cookies:\n");
+       while (c && (c->cookie)) {
+               dump_tos_cookie(c++);
+       }
+}
+
+
+extern "C" status_t
+init_xhdi(void)
+{
+       const struct tos_cookie *c;
+
+       if (gXHDIEntryPoint)
+               return B_OK;
+       
+       c = tos_find_cookie(XHDI_COOKIE);
+       if (!c)
+               return ENOENT;
+       if (((uint32 *)c->pvalue)[-1] != XHDI_MAGIC)
+               return EINVAL;
+       gXHDIEntryPoint = c->pvalue;
+       gXHDIVersion = XHGetVersion();
+       return B_OK;
+}
+
+
+extern "C" status_t
+init_nat_features(void)
+{
+       gKernelArgs.arch_args.plat_args.atari.nat_feat.nf_get_id = NULL;
+       gKernelArgs.arch_args.plat_args.atari.nat_feat.nf_call = NULL;
+       gKernelArgs.arch_args.plat_args.atari.nat_feat.nf_dprintf_id = 0;
+       if (nat_features()) {
+               // find debugprintf id
+               gDebugPrintfNatFeatID = nat_feat_getid("DEBUGPRINTF");
+               // pass native features infos to the kernel
+               gKernelArgs.arch_args.plat_args.atari.nat_feat.nf_get_id =
+                       nat_features()->nfGetID;
+               gKernelArgs.arch_args.plat_args.atari.nat_feat.nf_call = 
+                       nat_features()->nfCall;
+               gKernelArgs.arch_args.plat_args.atari.nat_feat.nf_dprintf_id =
+                       gDebugPrintfNatFeatID;
+       }
+       return nat_features() ? B_OK : ENOENT;
+}
+
+
+extern "C" void
+nat_feat_debugprintf(const char *str)
+{
+       if (gDebugPrintfNatFeatID)
+               nat_feat_call(gDebugPrintfNatFeatID, 0, str);
+}

Modified: haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.h
===================================================================
--- haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.h  2010-06-25 
08:03:58 UTC (rev 37249)
+++ haiku/trunk/src/system/boot/platform/atari_m68k/toscalls.h  2010-06-25 
08:30:17 UTC (rev 37250)
@@ -5,10 +5,10 @@
  * Author:
  *             François Revol, revol@xxxxxxxx
  */
-
 #ifndef _TOSCALLS_H
 #define _TOSCALLS_H
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif


Other related posts:

  • » [haiku-commits] r37250 - haiku/trunk/src/system/boot/platform/atari_m68k - axeld