Project

General

Profile

Revision 99

complete restructure

View differences:

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
}

Also available in: Unified diff