SHARE
TWEET

Untitled

a guest Sep 16th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // XMega65 Kernal Development Template// Each function of the kernal is a no-args function
  2. // The functions are placed in the SYSCALLS table surrounded by JMP and NOP
  3. // Use a linker definition file (put the previous listing into that file)
  4. import "string"
  5.  
  6. #pragma link("mega65hyper.ld")
  7. // Some definitions of addresses and special values that this program uses
  8. const char* RASTER = 0xd012;
  9. const char* VIC_MEMORY = 0xd018;
  10. const char* SCREEN = 0x0400;
  11. const char* BGCOL = 0xd021;
  12. const char* COLS = 0xd800;
  13. const char BLACK = 0;
  14. const char WHITE = 1;
  15. unsigned char *current_screen_line = $0400;
  16. unsigned char current_screen_x = 0;
  17.  
  18. // Some text to display
  19. //char[] MESSAGE = "Checkpoint 2.3 by eich0017";
  20.  
  21. void PRINT_TO_SCREEN(char *message){
  22.   while (*message){
  23.     current_screen_line[current_screen_x++] = *message;
  24.     *message++;
  25.   }
  26. }
  27. void print_hex(unsigned short value){
  28.     char[5] hex;
  29.     unsigned char i;
  30.     for (i=0; i<4; i++){
  31.         if(value<0xa000) hex[i] ='0'+(char)(value>>12);
  32.         else hex[i] = (char)(value>>12)-9;
  33.         value<<=4;
  34.     }
  35.     hex[4]=0;
  36.     PRINT_TO_SCREEN(hex);
  37. }
  38. void detect_vicii(unsigned short address){
  39. volatile unsigned char *p = address;
  40. unsigned char v1, v2;
  41. unsigned short i;
  42.  
  43. v1 = p[$12];
  44. for(i=1;i<1000;i++;){
  45.   continue;
  46. }
  47. v2=p[$12];
  48. if(v2>v1){
  49.   PRINT_NEWLINE();
  50.   PRINT_TO_SCREEN("detected vic ii");
  51. }
  52. if(v2<v1){
  53.   PRINT_NEWLINE();
  54.   PRINT_TO_SCREEN("detected vic i");
  55. }
  56. }
  57. void detect_devices(){
  58.   unsigned short device_start = $d000;
  59.   unsigned short device_end = $dff0;
  60.   for(unsigned short i = device_start; i<=device_end; i+=$10;){
  61.     detect_vicii(i);
  62.   }
  63.   PRINT_NEWLINE();
  64.   PRINT_TO_SCREEN("finish probing for devices")
  65. }
  66.  
  67. void PRINT_NEWLINE(){
  68.   current_screen_line += 40;
  69.   current_screen_x = 0;
  70. }
  71. void test_memory(){
  72.   unsigned short mem_start = $0800;
  73.   unsigned short mem_end = $0800;
  74.   volatile unsigned char *p = (unsigned char)&mem_end;
  75.   while(mem_end <= $7fff){
  76.       for(unsigned char i=0; i<255; i++){
  77.           (unsigned char)p = i;
  78.           if(p!=i){
  79.               PRINT_NEWLINE();
  80.               PRINT_TO_SCREEN("Memory initilize failed at: ");
  81.               print_hex(mem_end);
  82.               mem_end = --p;
  83.               break;
  84.           }
  85.           p= (unsigned char)&mem_end;
  86.       }
  87.       mem_end++;
  88.   }
  89.    PRINT_NEWLINE();
  90.    PRINT_TO_SCREEN("memory range: ");
  91.     print_hex(mem_start);
  92.     PRINT_TO_SCREEN(" - ");
  93.     print_hex(mem_end);
  94. }
  95.  
  96. void RESET() {
  97.     // Initialize screen memory, and select correct font
  98.     *VIC_MEMORY = 0x14;
  99.     // Fill the screen with spaces
  100.     memset(SCREEN, ' ', 40*25);
  101.     // Set the colour of every character on the screen to white
  102.     memset(COLS, WHITE, 40*25);
  103.     // Print the "hello world!" message
  104.     //char* sc = SCREEN+40;
  105.     // Display it one line down on the screen
  106.     //char* msg = MESSAGE;
  107.     // The messag to display
  108.     // A simple copy routine to copy the string
  109.     PRINT_TO_SCREEN("eich0017 operating system starting...");
  110.     PRINT_NEWLINE();
  111.     PRINT_TO_SCREEN("testing hardware");
  112.     //while(*msg) {*sc++ = *msg++;}
  113.    
  114.     test_memory();
  115.     PRINT_NEWLINE();
  116.     while(true) continue;
  117. }
  118.  
  119. void main(){
  120. }
  121.  
  122. void exit_hypervisor(){// Trigger exit from Hypervisor mode
  123.     *(unsigned char *)$D67F = $01;
  124. }
  125.  
  126.     // Here are a couple sample SYSCALL handlers that just display a character on the screen
  127.     void syscall1() {
  128.         *(SCREEN+79) = '>';
  129.     }
  130.     void syscall2() {
  131.     *(SCREEN+78) = '<';
  132.     }
  133.     void syscall3(){
  134.         exit_hypervisor();
  135.     }
  136.     void syscall4(){
  137.         exit_hypervisor();
  138.     }
  139.     void syscall5(){
  140.         exit_hypervisor();
  141.     }
  142.     void syscall6(){
  143.         exit_hypervisor();
  144.     }
  145.     void syscall7(){
  146.         exit_hypervisor();
  147.     }
  148.     void syscall8(){
  149.         exit_hypervisor();
  150.     }
  151.     void syscall9(){
  152.         exit_hypervisor();
  153.     }
  154.     void syscallA(){
  155.         exit_hypervisor();
  156.     }
  157.     void syscallB(){
  158.         exit_hypervisor();
  159.     }
  160.     void syscallC(){
  161.         exit_hypervisor();
  162.     }
  163.     void syscallD(){
  164.         exit_hypervisor();
  165.     }
  166.     void syscallE(){
  167.         exit_hypervisor();
  168.     }
  169.     void syscallF(){
  170.         exit_hypervisor();
  171.     }
  172.     void syscall10(){
  173.         exit_hypervisor();
  174.     }
  175.     void syscall11(){
  176.         exit_hypervisor();
  177.     }
  178.     void SECURENTR(){
  179.         exit_hypervisor();
  180.     }
  181.     void SECUREXIT(){
  182.         exit_hypervisor();
  183.     }
  184.     void syscall12(){
  185.         exit_hypervisor();
  186.     }
  187.     void syscall13(){
  188.         exit_hypervisor();
  189.     }
  190.     void syscall14(){
  191.         exit_hypervisor();
  192.     }
  193.     void syscall15(){
  194.         exit_hypervisor();
  195.     }
  196.     void syscall16(){
  197.         exit_hypervisor();
  198.     }
  199.     void syscall17(){
  200.         exit_hypervisor();
  201.     }
  202.     void syscall18(){
  203.         exit_hypervisor();
  204.     }
  205.     void syscall19(){
  206.         exit_hypervisor();
  207.     }
  208.     void syscall1A(){
  209.         exit_hypervisor();
  210.     }
  211.     void syscall1B(){
  212.         exit_hypervisor();
  213.     }
  214.     void syscall1C(){
  215.         exit_hypervisor();
  216.     }
  217.     void syscall1D(){
  218.         exit_hypervisor();
  219.     }
  220.     void syscall1E(){
  221.         exit_hypervisor();
  222.     }
  223.     void syscall1F(){
  224.         exit_hypervisor();
  225.     }
  226.     void syscall20(){
  227.         exit_hypervisor();
  228.     }
  229.     void syscall21(){
  230.         exit_hypervisor();
  231.     }
  232.     void syscall22(){
  233.         exit_hypervisor();
  234.     }
  235.     void syscall23(){
  236.         exit_hypervisor();
  237.     }
  238.     void syscall24(){
  239.         exit_hypervisor();
  240.     }
  241.     void syscall25(){
  242.         exit_hypervisor();
  243.     }
  244.     void syscall26(){
  245.         exit_hypervisor();
  246.     }
  247.     void syscall27(){
  248.         exit_hypervisor();
  249.     }
  250.     void syscall28(){
  251.         exit_hypervisor();
  252.     }
  253.     void syscall29(){
  254.         exit_hypervisor();
  255.     }
  256.     void syscall2A(){
  257.         exit_hypervisor();
  258.     }
  259.     void syscall2B(){
  260.         exit_hypervisor();
  261.     }
  262.     void syscall2C(){
  263.         exit_hypervisor();
  264.     }
  265.     void syscall2D(){
  266.         exit_hypervisor();
  267.     }
  268.     void syscall2E(){
  269.         exit_hypervisor();
  270.     }
  271.     void syscall2F(){
  272.         exit_hypervisor();
  273.     }
  274.     void syscall30(){
  275.         exit_hypervisor();
  276.     }
  277.     void syscall31(){
  278.         exit_hypervisor();
  279.     }
  280.     void syscall32(){
  281.         exit_hypervisor();
  282.     }
  283.     void syscall33(){
  284.         exit_hypervisor();
  285.     }
  286.     void syscall34(){
  287.         exit_hypervisor();
  288.     }
  289.     void syscall35(){
  290.         exit_hypervisor();
  291.     }
  292.     void syscall36(){
  293.         exit_hypervisor();
  294.     }
  295.     void syscall37(){
  296.         exit_hypervisor();
  297.     }
  298.     void syscall38(){
  299.         exit_hypervisor();
  300.     }
  301.     void syscall39(){
  302.         exit_hypervisor();
  303.     }
  304.     void syscall3A(){
  305.         exit_hypervisor();
  306.     }
  307.     void syscall3B(){
  308.         exit_hypervisor();
  309.     }
  310.     void syscall3C(){
  311.         exit_hypervisor();
  312.     }
  313.     void syscall3D(){
  314.         exit_hypervisor();
  315.     }
  316.     void syscall3E(){
  317.         exit_hypervisor();
  318.     }
  319.     void syscall3F(){
  320.         exit_hypervisor();
  321.     }
  322.     void PAGFAULT(){
  323.         exit_hypervisor();
  324.     }
  325.     void RESTORKEY(){
  326.         exit_hypervisor();
  327.     }
  328.     void ALTTABKEY(){
  329.         exit_hypervisor();
  330.     }
  331.     void VF011RD(){
  332.         exit_hypervisor();
  333.     }
  334.     void VF011WR(){
  335.         exit_hypervisor();
  336.     }
  337.     void undefined_trap(){
  338.         exit_hypervisor();
  339.     }
  340.     void CPUKIL(){
  341.         exit_hypervisor();
  342.     }
  343.  
  344.     // Now we select the SYSCALL segment to hold the SYSCALL/trap entry point table.
  345. #pragma data_seg(Syscall)
  346.     // The structure of each entry point is JMP <handler address> + NOP.
  347.     // We have a char (xjmp) to hold the opcode for the JMP instruction,
  348.     // and then put the address of the SYSCALL/trap handler in the next
  349.     // two points as a pointer, and end with the NOP instruction opcode.
  350.     struct SysCall {
  351.         char xjmp;// Holds $4C, the JMP $nnnn opcode
  352.         void()* syscall;   // Holds handler address, will be the target of the JMP
  353.         char xnop;  // Holds $EA, the NOP opcode
  354.         };
  355.     // To save writing 0x4C and 0xEA all the time, we define them as constants
  356.     const char JMP = 0x4c;
  357.     const char NOP = 0xea;
  358.     // Now we can have a nice table of up to 64 SYSCALL handlers expressed
  359.     // in a fairly readable and easy format.
  360.     // Each line is an instance of the struct SysCall from above, with the JMP
  361.     // opcode value, the address of the handler routine and the NOP opcode value.
  362.     export struct SysCall[] SYSCALLS = {
  363.         { JMP, &syscall1, NOP },
  364.         { JMP, &syscall2, NOP },
  365.         { JMP, &syscall3, NOP },
  366.         { JMP, &syscall4, NOP },
  367.         { JMP, &syscall5, NOP },
  368.         { JMP, &syscall6, NOP },
  369.         { JMP, &syscall7, NOP },
  370.         { JMP, &syscall8, NOP },
  371.         { JMP, &syscall9, NOP },
  372.         { JMP, &syscallA, NOP },
  373.         { JMP, &syscallB, NOP },
  374.         { JMP, &syscallC, NOP },
  375.         { JMP, &syscallD, NOP },
  376.         { JMP, &syscallE, NOP },
  377.         { JMP, &syscallF, NOP },
  378.         { JMP, &syscall10, NOP },
  379.         { JMP, &SECURENTR, NOP },
  380.         { JMP, &SECUREXIT, NOP },
  381.         { JMP, &syscall13, NOP },
  382.         { JMP, &syscall14, NOP },
  383.         { JMP, &syscall15, NOP },
  384.         { JMP, &syscall16, NOP },
  385.         { JMP, &syscall17, NOP },
  386.         { JMP, &syscall18, NOP },
  387.         { JMP, &syscall19, NOP },      
  388.     { JMP, &syscall1A, NOP },
  389.         { JMP, &syscall1B, NOP },
  390.         { JMP, &syscall1C, NOP },
  391.         { JMP, &syscall1D, NOP },
  392.         { JMP, &syscall1E, NOP },
  393.         { JMP, &syscall1F, NOP },
  394.         { JMP, &syscall20, NOP },
  395.         { JMP, &syscall21, NOP },
  396.         { JMP, &syscall22, NOP },
  397.         { JMP, &syscall23, NOP },
  398.         { JMP, &syscall24, NOP },
  399.         { JMP, &syscall25, NOP },
  400.         { JMP, &syscall26, NOP },
  401.         { JMP, &syscall27, NOP },
  402.         { JMP, &syscall28, NOP },
  403.         { JMP, &syscall29, NOP },
  404.         { JMP, &syscall2A, NOP },
  405.         { JMP, &syscall2B, NOP },
  406.         { JMP, &syscall2C, NOP },
  407.         { JMP, &syscall2D, NOP },
  408.         { JMP, &syscall2E, NOP },
  409.         { JMP, &syscall2F, NOP },
  410.         { JMP, &syscall30, NOP },
  411.         { JMP, &syscall31, NOP },
  412.         { JMP, &syscall32, NOP },
  413.         { JMP, &syscall33, NOP },
  414.         { JMP, &syscall34, NOP },
  415.         { JMP, &syscall35, NOP },
  416.     { JMP, &syscall36, NOP },
  417.         { JMP, &syscall37, NOP },
  418.         { JMP, &syscall38, NOP },
  419.         { JMP, &syscall39, NOP },
  420.         { JMP, &syscall3A, NOP },
  421.         { JMP, &syscall3B, NOP },
  422.         { JMP, &syscall3C, NOP },
  423.         { JMP, &syscall3D, NOP },
  424.         { JMP, &syscall3E, NOP },
  425.         { JMP, &syscall3F, NOP }
  426.        
  427.     };
  428.  
  429.     // In this example we had only two SYSCALLs defined, so rather than having
  430.     // another 62 lines, we can just ask KickC to make the TRAP table begin
  431.     // at the next multiple of $100, i.e., at $8100.
  432.     export align(0x100) struct SysCall[] TRAPS = {
  433.         { JMP, &RESET, NOP },
  434.         { JMP, &PAGFAULT, NOP },
  435.         { JMP, &RESTORKEY, NOP },
  436.         { JMP, &ALTTABKEY, NOP },
  437.         { JMP, &VF011RD, NOP },
  438.         { JMP, &VF011WR, NOP },
  439.     { JMP, &undefined_trap, NOP },
  440.     { JMP, &undefined_trap, NOP },
  441.     { JMP, &undefined_trap, NOP },
  442.     { JMP, &undefined_trap, NOP },
  443.     { JMP, &undefined_trap, NOP },
  444.     { JMP, &undefined_trap, NOP },
  445.     { JMP, &undefined_trap, NOP },
  446.     { JMP, &undefined_trap, NOP },
  447.     { JMP, &undefined_trap, NOP },
  448.     { JMP, &undefined_trap, NOP },
  449.     { JMP, &undefined_trap, NOP },
  450.     { JMP, &undefined_trap, NOP },
  451.     { JMP, &undefined_trap, NOP },
  452.     { JMP, &undefined_trap, NOP },
  453.     { JMP, &undefined_trap, NOP },
  454.     { JMP, &undefined_trap, NOP },
  455.     { JMP, &undefined_trap, NOP },
  456.     { JMP, &undefined_trap, NOP },
  457.     { JMP, &undefined_trap, NOP },
  458.     { JMP, &undefined_trap, NOP },
  459.     { JMP, &undefined_trap, NOP },
  460.     { JMP, &undefined_trap, NOP },
  461.     { JMP, &undefined_trap, NOP },
  462.     { JMP, &undefined_trap, NOP },
  463.     { JMP, &undefined_trap, NOP },
  464.     { JMP, &undefined_trap, NOP },
  465.     { JMP, &undefined_trap, NOP },
  466.     { JMP, &undefined_trap, NOP },
  467.     { JMP, &undefined_trap, NOP },
  468.     { JMP, &undefined_trap, NOP },
  469.     { JMP, &undefined_trap, NOP },
  470.     { JMP, &undefined_trap, NOP },
  471.     { JMP, &undefined_trap, NOP },
  472.     { JMP, &undefined_trap, NOP },
  473.     { JMP, &undefined_trap, NOP },
  474.     { JMP, &undefined_trap, NOP },
  475.     { JMP, &undefined_trap, NOP },
  476.     { JMP, &undefined_trap, NOP },
  477.     { JMP, &undefined_trap, NOP },
  478.     { JMP, &undefined_trap, NOP },
  479.     { JMP, &CPUKIL, NOP }  
  480.     };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top