Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // XMega65 Kernal Development Template// Each function of the kernal is a no-args function
- // The functions are placed in the SYSCALLS table surrounded by JMP and NOP
- // Use a linker definition file (put the previous listing into that file)
- import "string"
- #pragma link("mega65hyper.ld")
- // Some definitions of addresses and special values that this program uses
- const char* RASTER = 0xd012;
- const char* VIC_MEMORY = 0xd018;
- const char* SCREEN = 0x0400;
- const char* BGCOL = 0xd021;
- const char* COLS = 0xd800;
- const char BLACK = 0;
- const char WHITE = 1;
- unsigned char *current_screen_line = $0400;
- unsigned char current_screen_x = 0;
- // Some text to display
- //char[] MESSAGE = "Checkpoint 2.3 by eich0017";
- void PRINT_TO_SCREEN(char *message){
- while (*message){
- current_screen_line[current_screen_x++] = *message;
- *message++;
- }
- }
- void print_hex(unsigned short value){
- char[5] hex;
- unsigned char i;
- for (i=0; i<4; i++){
- if(value<0xa000) hex[i] ='0'+(char)(value>>12);
- else hex[i] = (char)(value>>12)-9;
- value<<=4;
- }
- hex[4]=0;
- PRINT_TO_SCREEN(hex);
- }
- void detect_vicii(unsigned short address){
- volatile unsigned char *p = address;
- unsigned char v1, v2;
- unsigned short i;
- v1 = p[$12];
- for(i=1;i<1000;i++;){
- continue;
- }
- v2=p[$12];
- if(v2>v1){
- PRINT_NEWLINE();
- PRINT_TO_SCREEN("detected vic ii");
- }
- if(v2<v1){
- PRINT_NEWLINE();
- PRINT_TO_SCREEN("detected vic i");
- }
- }
- void detect_devices(){
- unsigned short device_start = $d000;
- unsigned short device_end = $dff0;
- for(unsigned short i = device_start; i<=device_end; i+=$10;){
- detect_vicii(i);
- }
- PRINT_NEWLINE();
- PRINT_TO_SCREEN("finish probing for devices")
- }
- void PRINT_NEWLINE(){
- current_screen_line += 40;
- current_screen_x = 0;
- }
- void test_memory(){
- unsigned short mem_start = $0800;
- unsigned short mem_end = $0800;
- volatile unsigned char *p = (unsigned char)&mem_end;
- while(mem_end <= $7fff){
- for(unsigned char i=0; i<255; i++){
- (unsigned char)p = i;
- if(p!=i){
- PRINT_NEWLINE();
- PRINT_TO_SCREEN("Memory initilize failed at: ");
- print_hex(mem_end);
- mem_end = --p;
- break;
- }
- p= (unsigned char)&mem_end;
- }
- mem_end++;
- }
- PRINT_NEWLINE();
- PRINT_TO_SCREEN("memory range: ");
- print_hex(mem_start);
- PRINT_TO_SCREEN(" - ");
- print_hex(mem_end);
- }
- void RESET() {
- // Initialize screen memory, and select correct font
- *VIC_MEMORY = 0x14;
- // Fill the screen with spaces
- memset(SCREEN, ' ', 40*25);
- // Set the colour of every character on the screen to white
- memset(COLS, WHITE, 40*25);
- // Print the "hello world!" message
- //char* sc = SCREEN+40;
- // Display it one line down on the screen
- //char* msg = MESSAGE;
- // The messag to display
- // A simple copy routine to copy the string
- PRINT_TO_SCREEN("eich0017 operating system starting...");
- PRINT_NEWLINE();
- PRINT_TO_SCREEN("testing hardware");
- //while(*msg) {*sc++ = *msg++;}
- test_memory();
- PRINT_NEWLINE();
- while(true) continue;
- }
- void main(){
- }
- void exit_hypervisor(){// Trigger exit from Hypervisor mode
- *(unsigned char *)$D67F = $01;
- }
- // Here are a couple sample SYSCALL handlers that just display a character on the screen
- void syscall1() {
- *(SCREEN+79) = '>';
- }
- void syscall2() {
- *(SCREEN+78) = '<';
- }
- void syscall3(){
- exit_hypervisor();
- }
- void syscall4(){
- exit_hypervisor();
- }
- void syscall5(){
- exit_hypervisor();
- }
- void syscall6(){
- exit_hypervisor();
- }
- void syscall7(){
- exit_hypervisor();
- }
- void syscall8(){
- exit_hypervisor();
- }
- void syscall9(){
- exit_hypervisor();
- }
- void syscallA(){
- exit_hypervisor();
- }
- void syscallB(){
- exit_hypervisor();
- }
- void syscallC(){
- exit_hypervisor();
- }
- void syscallD(){
- exit_hypervisor();
- }
- void syscallE(){
- exit_hypervisor();
- }
- void syscallF(){
- exit_hypervisor();
- }
- void syscall10(){
- exit_hypervisor();
- }
- void syscall11(){
- exit_hypervisor();
- }
- void SECURENTR(){
- exit_hypervisor();
- }
- void SECUREXIT(){
- exit_hypervisor();
- }
- void syscall12(){
- exit_hypervisor();
- }
- void syscall13(){
- exit_hypervisor();
- }
- void syscall14(){
- exit_hypervisor();
- }
- void syscall15(){
- exit_hypervisor();
- }
- void syscall16(){
- exit_hypervisor();
- }
- void syscall17(){
- exit_hypervisor();
- }
- void syscall18(){
- exit_hypervisor();
- }
- void syscall19(){
- exit_hypervisor();
- }
- void syscall1A(){
- exit_hypervisor();
- }
- void syscall1B(){
- exit_hypervisor();
- }
- void syscall1C(){
- exit_hypervisor();
- }
- void syscall1D(){
- exit_hypervisor();
- }
- void syscall1E(){
- exit_hypervisor();
- }
- void syscall1F(){
- exit_hypervisor();
- }
- void syscall20(){
- exit_hypervisor();
- }
- void syscall21(){
- exit_hypervisor();
- }
- void syscall22(){
- exit_hypervisor();
- }
- void syscall23(){
- exit_hypervisor();
- }
- void syscall24(){
- exit_hypervisor();
- }
- void syscall25(){
- exit_hypervisor();
- }
- void syscall26(){
- exit_hypervisor();
- }
- void syscall27(){
- exit_hypervisor();
- }
- void syscall28(){
- exit_hypervisor();
- }
- void syscall29(){
- exit_hypervisor();
- }
- void syscall2A(){
- exit_hypervisor();
- }
- void syscall2B(){
- exit_hypervisor();
- }
- void syscall2C(){
- exit_hypervisor();
- }
- void syscall2D(){
- exit_hypervisor();
- }
- void syscall2E(){
- exit_hypervisor();
- }
- void syscall2F(){
- exit_hypervisor();
- }
- void syscall30(){
- exit_hypervisor();
- }
- void syscall31(){
- exit_hypervisor();
- }
- void syscall32(){
- exit_hypervisor();
- }
- void syscall33(){
- exit_hypervisor();
- }
- void syscall34(){
- exit_hypervisor();
- }
- void syscall35(){
- exit_hypervisor();
- }
- void syscall36(){
- exit_hypervisor();
- }
- void syscall37(){
- exit_hypervisor();
- }
- void syscall38(){
- exit_hypervisor();
- }
- void syscall39(){
- exit_hypervisor();
- }
- void syscall3A(){
- exit_hypervisor();
- }
- void syscall3B(){
- exit_hypervisor();
- }
- void syscall3C(){
- exit_hypervisor();
- }
- void syscall3D(){
- exit_hypervisor();
- }
- void syscall3E(){
- exit_hypervisor();
- }
- void syscall3F(){
- exit_hypervisor();
- }
- void PAGFAULT(){
- exit_hypervisor();
- }
- void RESTORKEY(){
- exit_hypervisor();
- }
- void ALTTABKEY(){
- exit_hypervisor();
- }
- void VF011RD(){
- exit_hypervisor();
- }
- void VF011WR(){
- exit_hypervisor();
- }
- void undefined_trap(){
- exit_hypervisor();
- }
- void CPUKIL(){
- exit_hypervisor();
- }
- // Now we select the SYSCALL segment to hold the SYSCALL/trap entry point table.
- #pragma data_seg(Syscall)
- // The structure of each entry point is JMP <handler address> + NOP.
- // We have a char (xjmp) to hold the opcode for the JMP instruction,
- // and then put the address of the SYSCALL/trap handler in the next
- // two points as a pointer, and end with the NOP instruction opcode.
- struct SysCall {
- char xjmp;// Holds $4C, the JMP $nnnn opcode
- void()* syscall; // Holds handler address, will be the target of the JMP
- char xnop; // Holds $EA, the NOP opcode
- };
- // To save writing 0x4C and 0xEA all the time, we define them as constants
- const char JMP = 0x4c;
- const char NOP = 0xea;
- // Now we can have a nice table of up to 64 SYSCALL handlers expressed
- // in a fairly readable and easy format.
- // Each line is an instance of the struct SysCall from above, with the JMP
- // opcode value, the address of the handler routine and the NOP opcode value.
- export struct SysCall[] SYSCALLS = {
- { JMP, &syscall1, NOP },
- { JMP, &syscall2, NOP },
- { JMP, &syscall3, NOP },
- { JMP, &syscall4, NOP },
- { JMP, &syscall5, NOP },
- { JMP, &syscall6, NOP },
- { JMP, &syscall7, NOP },
- { JMP, &syscall8, NOP },
- { JMP, &syscall9, NOP },
- { JMP, &syscallA, NOP },
- { JMP, &syscallB, NOP },
- { JMP, &syscallC, NOP },
- { JMP, &syscallD, NOP },
- { JMP, &syscallE, NOP },
- { JMP, &syscallF, NOP },
- { JMP, &syscall10, NOP },
- { JMP, &SECURENTR, NOP },
- { JMP, &SECUREXIT, NOP },
- { JMP, &syscall13, NOP },
- { JMP, &syscall14, NOP },
- { JMP, &syscall15, NOP },
- { JMP, &syscall16, NOP },
- { JMP, &syscall17, NOP },
- { JMP, &syscall18, NOP },
- { JMP, &syscall19, NOP },
- { JMP, &syscall1A, NOP },
- { JMP, &syscall1B, NOP },
- { JMP, &syscall1C, NOP },
- { JMP, &syscall1D, NOP },
- { JMP, &syscall1E, NOP },
- { JMP, &syscall1F, NOP },
- { JMP, &syscall20, NOP },
- { JMP, &syscall21, NOP },
- { JMP, &syscall22, NOP },
- { JMP, &syscall23, NOP },
- { JMP, &syscall24, NOP },
- { JMP, &syscall25, NOP },
- { JMP, &syscall26, NOP },
- { JMP, &syscall27, NOP },
- { JMP, &syscall28, NOP },
- { JMP, &syscall29, NOP },
- { JMP, &syscall2A, NOP },
- { JMP, &syscall2B, NOP },
- { JMP, &syscall2C, NOP },
- { JMP, &syscall2D, NOP },
- { JMP, &syscall2E, NOP },
- { JMP, &syscall2F, NOP },
- { JMP, &syscall30, NOP },
- { JMP, &syscall31, NOP },
- { JMP, &syscall32, NOP },
- { JMP, &syscall33, NOP },
- { JMP, &syscall34, NOP },
- { JMP, &syscall35, NOP },
- { JMP, &syscall36, NOP },
- { JMP, &syscall37, NOP },
- { JMP, &syscall38, NOP },
- { JMP, &syscall39, NOP },
- { JMP, &syscall3A, NOP },
- { JMP, &syscall3B, NOP },
- { JMP, &syscall3C, NOP },
- { JMP, &syscall3D, NOP },
- { JMP, &syscall3E, NOP },
- { JMP, &syscall3F, NOP }
- };
- // In this example we had only two SYSCALLs defined, so rather than having
- // another 62 lines, we can just ask KickC to make the TRAP table begin
- // at the next multiple of $100, i.e., at $8100.
- export align(0x100) struct SysCall[] TRAPS = {
- { JMP, &RESET, NOP },
- { JMP, &PAGFAULT, NOP },
- { JMP, &RESTORKEY, NOP },
- { JMP, &ALTTABKEY, NOP },
- { JMP, &VF011RD, NOP },
- { JMP, &VF011WR, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &undefined_trap, NOP },
- { JMP, &CPUKIL, NOP }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement