Project

General

Profile

Revision 99

complete restructure

View differences:

lab5/graphics.c
7 7
#include <stdio.h>
8 8

  
9 9
static void *video_mem; /** @brief Frame-buffer VM address */
10
static vbe_mode_info_t vbe_mem_info;
11
//static mmap_t mem_map;
10
//static vbe_mode_info_t vbe_mem_info;
11
static mmap_t mem_map;
12 12

  
13
int (set_graphics_mode)(uint16_t mode) {
14
    int r;
13
int (get_permission)(unsigned int base_addr, unsigned int size) {
15 14
    struct minix_mem_range mmr;
16
    mmr.mr_base =  0x0;
17
    mmr.mr_limit = 0xFFFFF;
15
    mmr.mr_base = base_addr;
16
    mmr.mr_limit = base_addr + size;
17
    return sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr);
18
}
18 19

  
19
    struct reg86 reg_86;
20
int (get_permissions_first_mbyte)(void) {
21
    return get_permission(MBYTE_BASE, MBYTE_SIZE);
22
}
20 23

  
21
    if ((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr)))
22
        panic("sys_privctl (ADD MEM) failed: %d\n", r);
24
int (vbe_get_mode_information)(uint16_t mode, vbe_mode_info_t *vmi_p) {
25
    memset(vmi_p, 0, sizeof(vbe_mode_info_t)); // reset values
23 26

  
27
    struct reg86 reg_86;
28
    memset(&reg_86, 0, sizeof(reg_86)); // reset struct
24 29

  
25
    memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // clear mem_info to initialize it
30
    vbe_mode_info_t *virtual_addr = lm_alloc(sizeof(vbe_mode_info_t), &mem_map);
26 31

  
27
    if (vbe_get_mode_info(mode, &vbe_mem_info)) {
28
        printf("vbe_get_mode_info: Failed to get VBE Mode Info for mode %x\n", mode);
29
        return LCF_ERROR;
32
    reg_86.intno = VC_BIOS_SERV;
33
    reg_86.ah = VBE_CALL;
34
    reg_86.al = VBE_MD_INFO;
35
    reg_86.cx = mode;
36
    reg_86.es = PB2BASE(mem_map.phys);
37
    reg_86.di = PB2OFF(mem_map.phys);
38
    // BIOS CALL
39
    if (sys_int86(&reg_86)) {
40
        printf("%s: sys_int86 failed\n", __func__);
41
        if (free_memory()) {
42
            printf("%s: lm_free failed\n", __func__);
43
            return LCF_ERROR;
44
        }
45
        return BIOS_CALL_ERROR;
30 46
    }
31
    unsigned int vram_base = vbe_mem_info.PhysBasePtr;
32
    unsigned int vram_size = vbe_mem_info.XResolution * vbe_mem_info.YResolution * (vbe_mem_info.BitsPerPixel >> 3);
33 47

  
34
    // Allow memory mapping
35
    mmr.mr_base =  vram_base;
36
    mmr.mr_limit = vram_base + vram_size;
48
    vmi_p = memcpy((void*)vmi_p, (void*)virtual_addr, mem_map.size);
49
    return SUCCESS;
50
}
37 51

  
38
    if ((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr)))
39
        panic("sys_privctl (ADD MEM) failed: %d\n", r);
52
int (map_vram)(unsigned int vram_base, unsigned int vram_size) {
53
    int r;
54
    if ((r = get_permission(vram_base, vram_size)))
55
        panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
40 56

  
41
    // Map memory
57
    video_mem = vm_map_phys(SELF, (void *)vram_base, vram_size);
42 58

  
43
    video_mem = vm_map_phys(SELF, (void *)mmr.mr_base, vram_size);
44

  
45 59
    if (video_mem == MAP_FAILED)
46
        panic("Error: couldn't map video memory.");
60
        panic("%s: couldn't map video memory.", __func__);
47 61

  
62
    return SUCCESS;
63
}
64

  
65
int (free_memory)(void) {
66
    return lm_free(&mem_map);
67
}
68

  
69
int (set_graphics_mode)(uint16_t mode) {
70
    struct reg86 reg_86;
71

  
48 72
    memset(&reg_86, 0, sizeof(reg_86)); // reset struct
49 73

  
74
    // Set Reg86
50 75
    reg_86.intno = VC_BIOS_SERV;
51 76
    reg_86.ah = VBE_CALL;
52 77
    reg_86.al = SET_VBE_MD;
53 78
    reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD;
54 79

  
55 80
    // BIOS CALL
56

  
57 81
    if (sys_int86(&reg_86)) {
58 82
        printf("%s: sys_int86 failed\n", __func__);
59 83
        return BIOS_CALL_ERROR;
60 84
    }
85

  
61 86
    return SUCCESS;
62 87
}
lab5/graphics.h
1 1
#ifndef GRAPHICS_H_INCLUDED
2 2
#define GRAPHICS_H_INCLUDED
3 3

  
4
#include <lcom/lcf.h>
4 5
#include <stdint.h>
5 6

  
7
int (get_permission)(unsigned int base_addr, unsigned int size);
8

  
9
int (get_permissions_first_mbyte)(void);
10

  
11
int (vbe_get_mode_information)(uint16_t mode, vbe_mode_info_t *vmi_p);
12

  
13
int (map_vram)(unsigned int vram_base, unsigned int vram_size);
14

  
15
int (free_memory)(void);
16

  
6 17
/**
7 18
 * @brief
8 19
 * @param mode
lab5/graphics_macros.h
4 4
#define VC_BIOS_SERV  0x10 /** @brief TODO */
5 5
#define VBE_CALL      0x4F /** @brief TODO */
6 6

  
7
#define MBYTE_BASE  0x0
8
#define MBYTE_SIZE  0xFFFFF
9

  
7 10
// Graphics Functions
8 11
#define VBE_CTRL_INFO       0x00 /** @brief Get VBE Controller Information */
9 12
#define VBE_MD_INFO         0x01 /** @brief Get VBE Mode Information */
lab5/lab5.c
35 35
}
36 36

  
37 37
int(video_test_init)(uint16_t mode, uint8_t delay) {
38
    int r;
39
    if ((r = get_permissions_first_mbyte()))
40
        panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
38 41

  
39
    set_graphics_mode(mode);
42
    if (set_graphics_mode(mode)) {
43
        printf("%s: failed to set graphic mode %x.\n", __func__, mode);
44
        if (vg_exit())
45
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
46
        return 1;
47
    };
40 48

  
49
    vbe_mode_info_t vbe_mem_info;
50

  
51
    if (vbe_get_mode_information(mode, &vbe_mem_info)) {
52
        printf("%s: failed to get information for mode %x.\n", __func__, mode);
53
        if (vg_exit())
54
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
55
        return 1;
56
    }
57

  
58
    unsigned int vram_base = vbe_mem_info.PhysBasePtr;
59
    unsigned int vram_size = vbe_mem_info.XResolution * vbe_mem_info.YResolution * ((vbe_mem_info.BitsPerPixel + 7) >> 3);
60

  
61
    map_vram(vram_base, vram_size); // if function fails it aborts program
62

  
41 63
    tickdelay(micros_to_ticks(delay*1e6));
42 64

  
43
    vg_exit();
65
    if (vg_exit()) {
66
        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
67
        if (free_memory())
68
            printf("%s: lm_free failed\n", __func__);
69
        return 1;
70
    }
71

  
72
    if (free_memory()) {
73
        printf("%s: lm_free failed\n", __func__);
74
        return 1;
75
    }
76

  
44 77
    return 0;
45 78
}
46 79

  

Also available in: Unified diff