source: soft/giet_vm/giet_kernel/giet.s @ 742

Last change on this file since 742 was 742, checked in by alain, 8 years ago

Remove the seg_kernel_init vseg: All the kernel code is now packed
in one single seg_kernel_code vseg. The entry point for the _kernel_init()
function (from the boot code is now at vaddr = 0x80000000.
The goal is to use only one BPP per cluster for the replicated kernel code.

  • Property svn:executable set to *
File size: 7.5 KB
Line 
1/************************************************************************************
2* This file contains the two entry points in the GIET_VM code:
3* - the _init entry point (from the boot code)      is 0x80000000 
4* - the _giet entry point (from user applications)  is 0x80000180 
5* => The base address of the segment containing this code MUST be 0x80000000.
6*
7* The _giet uses two arrays of functions:
8* - the _cause_vector[16] array defines the 16 causes to enter the GIET
9*   it is initialized in th exc_handler.c file
10* - the _syscall_vector[64] array defines the 64 system calls entry points
11*   it is initialised in the sys_handler.c file
12***********************************************************************************/
13
14    .section .giet, "ax", @progbits
15
16/*
17 * INIT entry point (at address 0x80000000)
18 */
19
20    .func   _init
21    .type   _init, %function
22
23_init:
24    la      $26,    _kernel_init
25    jr      $26                        /* jump to _kernel_init */
26
27    .endfunc
28    .size _init, .-_init
29
30    .space  0x170                      /* the _entry function occupies 16 bytes */
31
32/*
33 * GIET Entry point (at address 0x80000180)
34 */
35
36    .func   _giet
37    .type   _giet, %function
38
39_giet:
40    mfc0    $27,    $13                 /* $27 <= Cause register */
41    la      $26,    _cause_vector       /* $26 <= _cause_vector */
42    andi    $27,    $27,    0x3c            /* $27 <= XCODE*4 */
43    addu    $26,    $26,    $27             /* $26 <= &_cause_vector[XCODE] */
44    lw      $26,    ($26)               /* $26 <=  _cause_vector[XCODE] */
45    jr      $26                         /* Jump to handler indexed by XCODE */
46
47    .endfunc
48    .size _giet, .-_giet
49
50/*
51 * *** Syscall Handler ***
52 *
53 * A system call is handled as a special function call.
54 *  - $2 contains the system call index (< 64).
55 *  - $3 is used to store the syscall address
56 *  - $4, $5, $6, $7 contain the arguments values.
57 *  - The return address (EPC) and the (SR) are saved in the stack.
58 *  - Interrupts are enabled before branching to the syscall.
59 *  - All syscalls must return to the syscall handler.
60 *  - $2, $3, $4, $5, $6, $7 as well as $26 & $27 can be modified.
61 *
62 * In case of undefined system call, an error message displays
63 * the value of EPC on the kernel TTY, and the user program is killed.
64 */
65
66    .globl  _sys_handler
67    .func   _sys_handler
68    .type   _sys_handler, %function
69
70_sys_handler:
71    addiu   $29,    $29,    -24     /* 2 slots for SR & EPC, 4 slots for args */
72    mfc0    $27,    $14             /* $27 <= EPC                             */
73    addiu   $27,    $27,    4       /* increment EPC for return address       */
74    sw      $27,    20($29)         /* save EPC in the stack                  */
75    mfc0    $27,    $12             /* $27 <= SR                              */
76    sw      $27,    16($29)         /* save SR in the stack                   */
77
78    andi    $26,    $2,     0x3F    /* $26 <= syscall index (i < 64)          */
79    sll     $26,    $26,    2       /* $26 <= index * 4                       */
80    la      $27,    _syscall_vector /* $27 <= &_syscall_vector[0]             */
81    addu    $27,    $27,    $26     /* $27 <= &_syscall_vector[i]             */
82    lw      $3,     0($27)          /* $3  <= syscall address                 */
83    li      $27,    0xFFFFFFED      /* Mask for UM & EXL bits                 */
84    mfc0    $26,    $12             /* $26 <= SR                              */
85    and     $26,    $26,    $27     /* UM = 0 / EXL = 0                       */
86    mtc0    $26,    $12             /* interrupt enabled                      */
87    jalr    $3                      /* jump to the proper syscall             */
88
89    mtc0    $0,     $12             /* SR <= 0 : interrupt disabled           */
90    lw      $26,    16($29)         /* $26 <= SR from stack                   */
91    mtc0    $26,    $12             /* restore SR                             */
92    lw      $26,    20($29)         /* $26 <= EPC from stack                  */
93    mtc0    $26,    $14             /* restore EPC                            */
94    addiu   $29,    $29,    24      /* restore stack pointer                  */
95    eret                            /* exit GIET                              */
96
97    .endfunc
98    .size _sys_handler, .-_sys_handler
99
100/*
101 * *** Interrupt Handler ***
102 *
103 * This simple interrupt handler cannot be interrupted.
104 *
105 * All non persistant registers, such as $1 to $15, and $24 to $25, as well as
106 * register $31 and EPC, are saved in the interrupted program stack, before
107 * calling the Interrupt Service Routine. These registers can be used by the
108 * ISR code.
109 */
110
111    .globl  _int_handler
112    .func   _int_handler
113    .type   _int_handler, %function
114
115_int_handler:
116    addiu   $29,    $29,    -25*4   /* stack space reservation (21 registers to
117                                       save and 4 free words to call function) */
118    .set noat
119    sw      $1,     4*4($29)        /* save $1 */
120    .set at
121    sw      $2,     5*4($29)        /* save $2 */
122    sw      $3,     6*4($29)        /* save $3 */
123    sw      $4,     7*4($29)        /* save $4 */
124    sw      $5,     8*4($29)        /* save $5 */
125    sw      $6,     9*4($29)        /* save $6 */
126    sw      $7,     10*4($29)       /* save $7 */
127    sw      $8,     11*4($29)       /* save $8 */
128    sw      $9,     12*4($29)       /* save $9 */
129    sw      $10,    13*4($29)       /* save $10 */
130    sw      $11,    14*4($29)       /* save $11 */
131    sw      $12,    15*4($29)       /* save $12 */
132    sw      $13,    16*4($29)       /* save $13 */
133    sw      $14,    17*4($29)       /* save $14 */
134    sw      $15,    18*4($29)       /* save $15 */
135    sw      $24,    19*4($29)       /* save $24 */
136    sw      $25,    20*4($29)       /* save $25 */
137    sw      $31,    21*4($29)       /* save $31 */
138    mflo    $26
139    sw      $26,    22*4($29)       /* save LO */
140    mfhi    $26
141    sw      $26,    23*4($29)       /* save HI */
142    mfc0    $27,    $14
143    sw      $27,    24*4($29)       /* save EPC */
144
145    la      $26,    _irq_demux
146    jalr    $26                     /* jump to a C function to find the proper ISR */
147
148restore:
149    .set noat
150    lw      $1,     4*4($29)        /* restore $1 */
151    .set at
152    lw      $2,     4*5($29)        /* restore $2 */
153    lw      $3,     4*6($29)        /* restore $3 */
154    lw      $4,     4*7($29)        /* restore $4 */
155    lw      $5,     4*8($29)        /* restore $5 */
156    lw      $6,     4*9($29)        /* restore $6 */
157    lw      $7,     4*10($29)       /* restore $7 */
158    lw      $8,     4*11($29)       /* restore $8 */
159    lw      $9,     4*12($29)       /* restore $9 */
160    lw      $10,    4*13($29)       /* restore $10 */
161    lw      $11,    4*14($29)       /* restore $11 */
162    lw      $12,    4*15($29)       /* restore $12 */
163    lw      $13,    4*16($29)       /* restore $13 */
164    lw      $14,    4*17($29)       /* restore $14 */
165    lw      $15,    4*18($29)       /* restore $15 */
166    lw      $24,    4*19($29)       /* restore $24 */
167    lw      $25,    4*20($29)       /* restore $25 */
168    lw      $31,    4*21($29)       /* restore $31 */
169    lw      $26,    4*22($29)
170    mtlo    $26                     /* restore LO */
171    lw      $26,    4*23($29)
172    mthi    $26                     /* restore HI */
173    lw      $27,    4*24($29)       /* return address (EPC) */
174    addiu   $29,    $29,    25*4    /* restore stack pointer */
175    mtc0    $27,    $14             /* restore EPC */
176    eret                            /* exit GIET */
177
178    .endfunc
179    .size _int_handler, .-_int_handler
180
Note: See TracBrowser for help on using the repository browser.