home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Other Stuff / Other Stuff ’97 / PowerOS Development / basic kernel source / kernel_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-24  |  3.6 KB  |  139 lines  |  [TEXT/R*ch]

  1. #define BAT_DEBUG
  2.  
  3. /*
  4.         kernel_main.c
  5.     the main C-based entry point for PowerOS
  6.         copyright 1996-1997 by Ben Martz
  7.         all rights reserved world wide
  8.  
  9.         ANY AND ALL MODIFICATIONS TO THIS SOURCE MUST CREDIT THE ORIGINAL
  10.         AUTHOR, BEN MARTZ (benmartz@ic.net), AND MUST BE GIVEN TO THE AUTHOR
  11.         FOR INTEGRATION INTO THE MAIN PowerOS SOURCE TREE. THANK YOU FOR YOUR
  12.         COOPERATION!
  13. */
  14.  
  15. #include "poweros_types.h"
  16. #include "boot.h"
  17. #include "debug_video.h"
  18. #include "debug_console.h"
  19. #include "dprintf.h"
  20. #include "misc.h"
  21. #include "bat.h"
  22. #include "memory.h"
  23. #include "stdhdr.s"
  24.  
  25. void kernel_main(KernelBootData *boot, int chip) {
  26.     unsigned long    i = 0;
  27.     char        *testptr;
  28.     long        *x;
  29.  
  30. #ifndef BAT_DEBUG
  31.     /* map the first 1MB 1:1 */
  32.     switch(chip) {
  33.     case k601: {
  34.         BATU_601    batu;
  35.         BATL_601    batl;
  36.         
  37.         batu.blpi = 0;    /* virtual address 0 */
  38.         batu.rsvd1 = 0;    /* zero */
  39.         batu.wim = 0;    /* nothing special */
  40.         batu.ks = 1;    /* supervisor enabled */
  41.         batu.ku = 0;    /* no user */
  42.         batu.pp = 2;    /* read and write */
  43.         
  44.         batl.pbn = 0;    /* physical address 0 */
  45.         batl.rsvd1 = 0;    /* zero */
  46.         batl.v = 1;    /* valid */
  47.         batl.bsm = BAT_BL_8M;    /* eight megabytes */
  48.     
  49.         __asm__ volatile("sync");
  50.         __asm__ volatile("mtdbatu 0, 0");
  51.         __asm__ volatile("mtdbatl 0, %0" : : "r" (batl));
  52.         __asm__ volatile("mtdbatu 0, %0" : : "r" (batu));
  53.         __asm__ volatile("sync");
  54.         
  55.         break; }
  56.     case k603:
  57.     case k604: {
  58.         BATU_60x    batu;
  59.         BATL_60x    batl;
  60.         
  61.         batu.bepi = 0;    /* virtual address 0 */
  62.         batu.rsvd1 = 0;    /* zero */
  63.         batu.bl = BAT_BL_256M;    /* 256 megabytes */
  64.         batu.vs = 1;    /* supervisor access enabled */
  65.         batu.vp = 0;    /* no user access */
  66.         
  67.         batl.brpn = 0;    /* physical address 0 */
  68.         batl.rsvd1 = 0;    /* zero */
  69.         batl.wimg = 0;    /* nothing special */
  70.         batl.rsvd2 = 0;    /* zero */
  71.         batl.pp = 2;    /* read/write */
  72.  
  73.         __asm__ volatile("sync");
  74.         __asm__ volatile("mtdbatu 0, 0");
  75.         __asm__ volatile("mtdbatl 0, %0" : : "r" (batl));
  76.         __asm__ volatile("mtdbatu 0, %0" : : "r" (batu));
  77.         __asm__ volatile("mtibatu 0, 0");
  78.         __asm__ volatile("mtibatl 0, %0" : : "r" (batl));
  79.         __asm__ volatile("mtibatu 0, %0" : : "r" (batu));
  80.         __asm__ volatile("sync");
  81.         
  82.         break; }
  83.     }
  84.  
  85.     /* disable the other 3 BATs */
  86.     __asm__ volatile("sync");
  87.     __asm__ volatile("mtdbatu 1, 0");
  88.     __asm__ volatile("mtdbatu 2, 0");
  89.     __asm__ volatile("mtdbatu 3, 0");
  90.     __asm__ volatile("sync");
  91.             
  92.     if((chip == k603) || (chip == k603)) {
  93.         __asm__ volatile("sync");
  94.         __asm__ volatile("mtibatu 1, 0");
  95.         __asm__ volatile("mtibatu 2, 0");
  96.         __asm__ volatile("mtibatu 3, 0");
  97.         __asm__ volatile("sync");
  98.     }
  99. #endif /* BAT_DEBUG */
  100.  
  101.     /* just a place where we could handle different booter versions later */
  102.     if(boot->version != BOOTVERSION);
  103.  
  104.     /* initialize the video and console functions */
  105.     vinit(boot->v_baseaddr,boot->v_rowbytes,boot->v_depth,
  106.         boot->v_width,boot->v_height);
  107.     cinit();
  108.     
  109.     /* say hi! */
  110.     dprintf("PowerOS Kernel - compiled %s %s with gcc %d.%d\n",__DATE__,__TIME__,__GNUC__,__GNUC_MINOR__);
  111.     dprintf("copyright (C)1996-1997 Ben Martz\n");
  112.     dprintf("all rights reserved world wide\n\n");
  113.  
  114.     dprintf("ppc chip    = 60%d\n",chip);
  115.     dprintf("kernel size = %ld bytes\n",_kernel_size());
  116.     dprintf("memory size = %d MB\n",boot->m_bytes/1024/1024);
  117.  
  118.     /* never let go! */
  119.     while(1)  {
  120.         i++;
  121.         cgotoxy(1,25);
  122.         dprintf("%d",i);
  123.         if(i == 10000) {
  124.             _sc(0x1234);
  125.         }
  126.         if(i == 20000) {
  127.             /* heh...this won't work until the mmu is set up properly! */
  128.             /*mem_init(_kernel_size(),boot->m_bytes - _kernel_size()); */
  129.             dprintf("\nlet's try something now...\n");
  130.             for(x = (long *) _kernel_size()+1024; x < (long *) 0xffffffff; x++) {
  131.                 *x = 0xdeadbeef;
  132.             }
  133.         }
  134.     }
  135.     
  136.     /* ouch */
  137.     dprintf("Umm...ouch?");
  138. }
  139.