Guest User

kernel

a guest
Feb 8th, 2019
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     - returning from kernel_main causes a triple fault
  3. */
  4. #include "kernel.h"
  5. void kernel_main(void);
  6. void print(char*);
  7. void* memcpy(void*,void*,int);
  8.  
  9. static int x=0;
  10. static shortbuf term=vga_mem;
  11. static int ti=5,tx=5,ty=0;
  12. /* static data is collected in the .data section
  13.     -> this might be broken: references to x go to ds:0x40! (that is 0x0000000000000040!!)
  14. */
  15. void kernel_main(void) {
  16.     /* on entry: push ebp, mov esp to ebp, esp:=esp-(size of local vars) */
  17.     /* local variables are collected on the stack as follows:
  18.         mov REG,<value>         /   lea REG,[ebp-<i>]   (to store an address)
  19.         mov [ebp-<i>],REG           mov [ebp-<j>],REG
  20.     */
  21.     volatile char s[30]="volatile!";
  22.     print((void*)s);
  23.     /*for(x=10; x<20; x++) {
  24.         term[x]=vga_entry(str[x],vga_color(vga_red,vga_lightgrey));
  25.     }
  26.     for(x=20;x<500;x++){
  27.         term[x]=vga_entry('X',vga_color(vga_cyan,vga_black));
  28.     }
  29.     hang();
  30.     while(1);*/
  31.     return;
  32.     /* on exit: esp:=esp+(size of local vars), pop ebp */
  33. }
  34.  
  35. void print(char *p) {
  36.     int x=0;
  37.     for(x=0; p[x]; x++) {
  38.         /*if(++tx==vga_width) {
  39.             ty+=1;
  40.             tx=0;
  41.         }*/
  42.         term[ti++]=vga_entry(p[x],vga_color(vga_white,vga_black));
  43.         /*term[ti++]=p[x];*/
  44.     }
  45. }
  46.  
  47. /* required user-supplied functions */
  48. void* memcpy(void *dest,void *src,int count) {
  49.     if(count==0) return dest;
  50.     /*byte *dp=(byte*)dest;
  51.     byte *sp=(byte*)src;*/
  52.     ((byte*)dest)[count]=((byte*)src)[count];
  53.     return memcpy(((byte*)dest)+1,((byte*)src)+1,count-1);
  54. }
RAW Paste Data