OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
hal.h
1#ifndef _HAL_H
2#define _HAL_H
3
4
5// HAL stands for Hardware Abstraction Layer.
6// This is a way for our OS to interact with hardware without having to know
7// any specific details of the hardware.
8
9#include <stdint.h>
10#include "limine.h"
11
12int hal_init(void);
13
14struct limine_framebuffer* hal_get_fb(void);
15
16
17static inline void hal_putpixel(struct limine_framebuffer *fb, uint32_t x, uint32_t y, uint32_t color) {
18 uint32_t *pixel = (uint32_t *)
19 ((uint8_t *)fb->address + y * fb->pitch + x * 4);
20
21 *pixel = color;
22}
23
24static inline void hal_fillrect(
25 struct limine_framebuffer *fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color) {
26
27 uint8_t* where = fb->address + (y * fb->pitch) + (x * 4);
28
29 for (uint32_t j = 0; j < h; j++) {
30 for (uint32_t i = 0; i < w; i++) {
31 *(uint32_t*)(where + i*4 + j*fb->pitch) = color;
32 }
33 }
34}
35
36static inline uint64_t hal_fb_width() {
37 return hal_get_fb()->width;
38}
39
40static inline uint64_t hal_fb_height() {
41 return hal_get_fb()->height;
42}
43
44#endif