summaryrefslogtreecommitdiff
path: root/test_general/ecos/src/exception.c
blob: 09f6dbd55f819a3947de4ae8991723ce7e57dc74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    exception.c
 * \brief   how to catch an exception
 * \ingroup 
 *
 * this is a test program to check eCos well work
 */

#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>
#include <cyg/hal/hal_intr.h>
#include "common/std.h"

void system_call_exception(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info)
{
    switch(number)
    {
    case CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION: 
        diag_printf("eCos: Exception Error (Illegal Instruction)!!!\n");
        break;

    case CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS: 
        diag_printf("eCos: Exception Error (Data Access Unaligned)!!!\n");
        break;
    default:
        diag_printf("eCos: Exception Error (Unknown)!!!\n");
    }
//    cyg_hal_sys_exit(1);
}

void cyg_user_start(void)
{
    unsigned int *ptr = (unsigned int*)0x00000001;
    cyg_exception_handler_t *oldHandler;
    cyg_addrword_t oldData;

    //config UART
    unsigned int *uart_scaler = (unsigned int*)0x8000007C;
    unsigned int *uart_ctrl = (unsigned int*)0x80000078;
    *uart_scaler = 0xF4;  //soit 75MHz / (8 * 38400)
    *uart_ctrl = 0x3;     //enable TX and RX

    diag_write_string("debut du main\n");

    cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION,
                              &system_call_exception,
                              0,
                              &oldHandler,
                              &oldData);
    cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, 
                              &system_call_exception,
                              0,
                              &oldHandler,
                              &oldData);

    diag_write_string("exception enregistrees\n");

    // 1st exception : undefined instruction
    asm volatile ("unimp        0\n\t");
    // 2nd exception : unaligned address
    *ptr = 12;

    diag_write_string("fin du main\n");
}