Compare commits
	
		
			No commits in common. "96a3f236709b4ebe3c153cf7d98adcf1e77c9f3c" and "691785693642b576e6fdf7ba5cfe74ac8f725da2" have entirely different histories.
		
	
	
		
			96a3f23670
			...
			6917856936
		
	
		
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@ -12,6 +12,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    "C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"],
 | 
					    "C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"],
 | 
				
			||||||
    "C_Cpp.default.cStandard": "c17",
 | 
					    "C_Cpp.default.cStandard": "c17",
 | 
				
			||||||
 | 
					    "files.associations": {
 | 
				
			||||||
 | 
					        "cpu.h": "c"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "[c]": {
 | 
					    "[c]": {
 | 
				
			||||||
        "editor.tabSize": 2,
 | 
					        "editor.tabSize": 2,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
								
							@ -27,7 +27,7 @@ endif
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
musllib: $(SYSROOT)/usr/lib/libc.a
 | 
					musllib: $(SYSROOT)/usr/lib/libc.a
 | 
				
			||||||
$(SYSROOT)/usr/lib/libc.a:
 | 
					$(SYSROOT)/usr/lib/libc.a:
 | 
				
			||||||
	$(BUILDROOT)/toolchain/ports/musl/build.sh
 | 
						${BUILDROOT}/toolchain/build-musl.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
libmittos: $(SYSROOT)/usr/lib/libmittos.a
 | 
					libmittos: $(SYSROOT)/usr/lib/libmittos.a
 | 
				
			||||||
$(SYSROOT)/usr/lib/libmittos.a: FORCE
 | 
					$(SYSROOT)/usr/lib/libmittos.a: FORCE
 | 
				
			||||||
@ -46,7 +46,4 @@ distclean:
 | 
				
			|||||||
	$(MAKE) clean
 | 
						$(MAKE) clean
 | 
				
			||||||
	rm -rf $(SYSROOT)
 | 
						rm -rf $(SYSROOT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
love: FORCE
 | 
					 | 
				
			||||||
	@echo Not war?
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.PHONY: all dist sysroot FORCE
 | 
					.PHONY: all dist sysroot FORCE
 | 
				
			||||||
@ -2,7 +2,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
> - [PIC data sheet](http://pdos.csail.mit.edu/6.828/2005/readings/hardware/8259A.pdf)
 | 
					> - [PIC data sheet](http://pdos.csail.mit.edu/6.828/2005/readings/hardware/8259A.pdf)
 | 
				
			||||||
> - [IOAPIC data sheet](http://web.archive.org/web/20161130153145/http://download.intel.com/design/chipsets/datashts/29056601.pdf)
 | 
					> - [IOAPIC data sheet](http://web.archive.org/web/20161130153145/http://download.intel.com/design/chipsets/datashts/29056601.pdf)
 | 
				
			||||||
 | 
					 | 
				
			||||||
The Advanced Programmable Interrupt Controller (APIC) is not to be confused with (ACPI).
 | 
					The Advanced Programmable Interrupt Controller (APIC) is not to be confused with (ACPI).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
It's quite literally an upgrade to the legacy PIC and handles hardware interrupts and IRQs.
 | 
					It's quite literally an upgrade to the legacy PIC and handles hardware interrupts and IRQs.
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
ENTRY(_start)
 | 
					ENTRY(_start)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
KERNEL_OFFSET = 0xFFFFFF8000000000;
 | 
					KERNEL_OFFSET = 0xFFFFFF8000000000;
 | 
				
			||||||
KERNEL_START = 0x100000;
 | 
					KERNEL_START = 0x10000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SECTIONS
 | 
					SECTIONS
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -10,20 +10,20 @@ SECTIONS
 | 
				
			|||||||
    .text : AT(ADDR(.text) - KERNEL_OFFSET)
 | 
					    .text : AT(ADDR(.text) - KERNEL_OFFSET)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        *(.multiboot)
 | 
					        *(.multiboot)
 | 
				
			||||||
        *(.text*)
 | 
					        *(.text)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .rodata : AT(ADDR(.rodata) - KERNEL_OFFSET)
 | 
					    .rodata : AT(ADDR(.rodata) - KERNEL_OFFSET)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        *(.rodata*)
 | 
					        *(.rodata*)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .data ALIGN(0x1000) : AT(ADDR(.data) - KERNEL_OFFSET)
 | 
					    .data : AT(ADDR(.data) - KERNEL_OFFSET)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        *(.data*)
 | 
					        *(.data)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .bss : AT(ADDR(.bss) - KERNEL_OFFSET)
 | 
					    .bss : AT(ADDR(.bss) - KERNEL_OFFSET)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        *(.COMMON)
 | 
					        *(.COMMON)
 | 
				
			||||||
        *(.bss*)
 | 
					        *(.bss)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    kernel_end = .;
 | 
					    kernel_end = .;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -3,7 +3,6 @@
 | 
				
			|||||||
#include <mittos/graphics.h>
 | 
					#include <mittos/graphics.h>
 | 
				
			||||||
#include <memory.h>
 | 
					#include <memory.h>
 | 
				
			||||||
#include <cpu.h>
 | 
					#include <cpu.h>
 | 
				
			||||||
#include <math.h>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern gfx_context *term_fb;
 | 
					extern gfx_context *term_fb;
 | 
				
			||||||
extern gfx_context kernel_fb;
 | 
					extern gfx_context kernel_fb;
 | 
				
			||||||
@ -12,10 +11,8 @@ int *position = (void *)0x20000;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void thread1() {
 | 
					void thread1() {
 | 
				
			||||||
  int a = 1;
 | 
					  int a = 1;
 | 
				
			||||||
  double prev = 0;
 | 
					 | 
				
			||||||
  gfx_context *ctx =
 | 
					  gfx_context *ctx =
 | 
				
			||||||
      framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100);
 | 
					      framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100);
 | 
				
			||||||
  __asm__("sti");
 | 
					 | 
				
			||||||
  while(1) {
 | 
					  while(1) {
 | 
				
			||||||
    putCharacter(term_fb,
 | 
					    putCharacter(term_fb,
 | 
				
			||||||
        *position, *position,
 | 
					        *position, *position,
 | 
				
			||||||
@ -23,19 +20,14 @@ void thread1() {
 | 
				
			|||||||
        '0'+(a++%10)
 | 
					        '0'+(a++%10)
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    int s = (current_cpu->timer_ticks/1000)%10;
 | 
					    int s = (current_cpu->timer_ticks/1000)%10;
 | 
				
			||||||
    double cur = (double)(current_cpu->timer_ticks/100);
 | 
					 | 
				
			||||||
    putCharacter(term_fb,
 | 
					    putCharacter(term_fb,
 | 
				
			||||||
        0, 0,
 | 
					        0, 0,
 | 
				
			||||||
        RGB(255,255,0), RGB(0,0,0),
 | 
					        RGB(255,255,0), RGB(0,0,0),
 | 
				
			||||||
        '0'+(s%10)
 | 
					        '0'+(s%10)
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    flip(term_fb);
 | 
					    flip(term_fb);
 | 
				
			||||||
 | 
					    draw_line(ctx, 0, 100, 50, ((a-1)%100), RGB(0,0,0));
 | 
				
			||||||
    double angle = cur/3.14*2;
 | 
					    draw_line(ctx, 0, 100, 50, (a%100), RGB(255,0,0));
 | 
				
			||||||
 | 
					 | 
				
			||||||
    draw_line(ctx, 50, 50 + (int)(50*cos(prev)), 50, 50 + (int)(50*sin(prev)), RGB(0,0,0));
 | 
					 | 
				
			||||||
    draw_line(ctx, 50, 50 + (int)(50*cos(angle)), 50, 50 + (int)(50*sin(angle)), RGB(255,0,0));
 | 
					 | 
				
			||||||
    prev = angle;
 | 
					 | 
				
			||||||
    flip(ctx);
 | 
					    flip(ctx);
 | 
				
			||||||
    sched_yield();
 | 
					    sched_yield();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -43,17 +35,7 @@ void thread1() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void thread2() {
 | 
					void thread2() {
 | 
				
			||||||
  int a = 0;
 | 
					  int a = 0;
 | 
				
			||||||
  gfx_context *ctx =
 | 
					 | 
				
			||||||
      framebuffer_make_subcontext(&kernel_fb, 800, 400, 100, 100);
 | 
					 | 
				
			||||||
  __asm__("sti");
 | 
					 | 
				
			||||||
  while(1) {
 | 
					  while(1) {
 | 
				
			||||||
    double pos = (double)(current_cpu->timer_ticks/100);
 | 
					 | 
				
			||||||
    fill_rect(ctx, 0, 0, 100, 100, 0);
 | 
					 | 
				
			||||||
    for(int i = 0; i < 10000; i++) {
 | 
					 | 
				
			||||||
      putpixel(ctx, i/100, 50 + (int)(50.0*sin(pos + ((double)i)/1000.0)), RGB(0,0,255));
 | 
					 | 
				
			||||||
      putpixel(ctx, i/100, 50 + (int)(50.0*cos(pos + ((double)i)/1000.0)), RGB(255,0,0));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    flip(ctx);
 | 
					 | 
				
			||||||
    putCharacter(term_fb,
 | 
					    putCharacter(term_fb,
 | 
				
			||||||
        *position, *position,
 | 
					        *position, *position,
 | 
				
			||||||
        RGB(0,255,255), RGB(0,0,0),
 | 
					        RGB(0,255,255), RGB(0,0,0),
 | 
				
			||||||
 | 
				
			|||||||
@ -41,6 +41,8 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  cpu_init();
 | 
					  cpu_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  __asm__("sti");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  debug_info("Boot complete\n");
 | 
					  debug_info("Boot complete\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,7 +50,6 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) {
 | 
				
			|||||||
  irq_unmask(IRQ_PS2_KBD);
 | 
					  irq_unmask(IRQ_PS2_KBD);
 | 
				
			||||||
  TEMP_test_scheduler();
 | 
					  TEMP_test_scheduler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  __asm__("sti");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  start_scheduler();
 | 
					  start_scheduler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -27,5 +27,4 @@ void cpu_init() {
 | 
				
			|||||||
  apic_init();
 | 
					  apic_init();
 | 
				
			||||||
  ioapic_init();
 | 
					  ioapic_init();
 | 
				
			||||||
  timer_init();
 | 
					  timer_init();
 | 
				
			||||||
  sse_init();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,30 +0,0 @@
 | 
				
			|||||||
.intel_syntax noprefix
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.global sse_init
 | 
					 | 
				
			||||||
sse_init:
 | 
					 | 
				
			||||||
  //; Enable bits 9 and 10 in cr4
 | 
					 | 
				
			||||||
  //; 9: Enable SSE instructions
 | 
					 | 
				
			||||||
  //; 10: Enable SSE exceptions
 | 
					 | 
				
			||||||
  mov rax, cr4
 | 
					 | 
				
			||||||
  or rax, 1<<9 | 1<<10
 | 
					 | 
				
			||||||
  mov cr4, rax
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //; Set bit 1 and unset bit 2 in cr0
 | 
					 | 
				
			||||||
  //; 1: Coprocessor monitoring
 | 
					 | 
				
			||||||
  //; 2: Coprocessor emulation
 | 
					 | 
				
			||||||
  mov rax, cr0
 | 
					 | 
				
			||||||
  or rax, 1<<1
 | 
					 | 
				
			||||||
  and rax, ~(1<<2)
 | 
					 | 
				
			||||||
  mov cr0, rax
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ret
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.global sse_save
 | 
					 | 
				
			||||||
sse_save:
 | 
					 | 
				
			||||||
  fxsave [rdi]
 | 
					 | 
				
			||||||
  ret
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.global sse_restore
 | 
					 | 
				
			||||||
sse_restore:
 | 
					 | 
				
			||||||
  fxrstor [rdi]
 | 
					 | 
				
			||||||
  ret
 | 
					 | 
				
			||||||
@ -69,7 +69,6 @@ volatile int ctr = 0;
 | 
				
			|||||||
registers *apic_timer_handler(registers *r) {
 | 
					registers *apic_timer_handler(registers *r) {
 | 
				
			||||||
  current_cpu->timer_ticks++;
 | 
					  current_cpu->timer_ticks++;
 | 
				
			||||||
  irq_ack();
 | 
					  irq_ack();
 | 
				
			||||||
  // k_sched_yield();
 | 
					 | 
				
			||||||
  return r;
 | 
					  return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -99,8 +99,3 @@ void ioapic_init();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// cpu/timer.c
 | 
					// cpu/timer.c
 | 
				
			||||||
void timer_init();
 | 
					void timer_init();
 | 
				
			||||||
 | 
					 | 
				
			||||||
// cpu/sse.S
 | 
					 | 
				
			||||||
void sse_init();
 | 
					 | 
				
			||||||
void sse_save(void *addr);
 | 
					 | 
				
			||||||
void sse_restore(void *addr);
 | 
					 | 
				
			||||||
@ -7,7 +7,6 @@ struct process {
 | 
				
			|||||||
  uint64_t state;
 | 
					  uint64_t state;
 | 
				
			||||||
  uint64_t P4;
 | 
					  uint64_t P4;
 | 
				
			||||||
  struct process *q_next;
 | 
					  struct process *q_next;
 | 
				
			||||||
  void *sse;
 | 
					 | 
				
			||||||
  uint8_t stack[];
 | 
					  uint8_t stack[];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,5 @@
 | 
				
			|||||||
#include <memory.h>
 | 
					#include <memory.h>
 | 
				
			||||||
#include <debug.h>
 | 
					#include <debug.h>
 | 
				
			||||||
#include <sys/mman.h>
 | 
					 | 
				
			||||||
#include <string.h>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static long _brk = KERNEL_BRK0;
 | 
					static long _brk = KERNEL_BRK0;
 | 
				
			||||||
static long _mmap = KERNEL_MMAP;
 | 
					static long _mmap = KERNEL_MMAP;
 | 
				
			||||||
@ -35,22 +33,14 @@ long k_mmap(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  if(fd != -1)
 | 
					  if(fd != -1)
 | 
				
			||||||
    PANIC("Unknown mmap request\n");
 | 
					    PANIC("Unknown mmap request\n");
 | 
				
			||||||
  long pos = (flags & MAP_FIXED) ? addr : _mmap;
 | 
					  long retval = _mmap;
 | 
				
			||||||
  long retval = pos;
 | 
					  while(length > 0) {
 | 
				
			||||||
  uint64_t p;
 | 
					 | 
				
			||||||
  while(length >= 0) {
 | 
					 | 
				
			||||||
    p = pmm_alloc();
 | 
					 | 
				
			||||||
    vmm_set_page(kernel_P4,
 | 
					    vmm_set_page(kernel_P4,
 | 
				
			||||||
        pos, p,
 | 
					        _mmap, pmm_alloc(),
 | 
				
			||||||
        PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT
 | 
					        PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    if(flags & MAP_ANONYMOUS) {
 | 
					    _mmap += PAGE_SIZE;
 | 
				
			||||||
      memset((void *)pos, 0, PAGE_SIZE);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    pos += PAGE_SIZE;
 | 
					 | 
				
			||||||
    length -= PAGE_SIZE;
 | 
					    length -= PAGE_SIZE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if(!(flags & MAP_FIXED))
 | 
					 | 
				
			||||||
    _mmap = pos;
 | 
					 | 
				
			||||||
  return retval;
 | 
					  return retval;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,7 +1,6 @@
 | 
				
			|||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <proc.h>
 | 
					#include <proc.h>
 | 
				
			||||||
#include <memory.h>
 | 
					#include <memory.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct swtch_stack {
 | 
					struct swtch_stack {
 | 
				
			||||||
  uint64_t RBP;
 | 
					  uint64_t RBP;
 | 
				
			||||||
@ -25,10 +24,6 @@ struct process *new_process(void (*function)(void)) {
 | 
				
			|||||||
  p->q_next = 0;
 | 
					  p->q_next = 0;
 | 
				
			||||||
  p->P4 = new_P4();
 | 
					  p->P4 = new_P4();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Storage for SSE registers must be 16 byte aligned
 | 
					 | 
				
			||||||
  void *sse = malloc(512+15);
 | 
					 | 
				
			||||||
  p->sse = (void *) (((uintptr_t)sse + 15) & ~0xF);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  struct swtch_stack *stck = p->stack_ptr;
 | 
					  struct swtch_stack *stck = p->stack_ptr;
 | 
				
			||||||
  stck->RBP = (uint64_t)&stck->RBP2;
 | 
					  stck->RBP = (uint64_t)&stck->RBP2;
 | 
				
			||||||
  stck->ret = (uint64_t)function;
 | 
					  stck->ret = (uint64_t)function;
 | 
				
			||||||
 | 
				
			|||||||
@ -32,11 +32,8 @@ void scheduler() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    current_proc = new;
 | 
					    current_proc = new;
 | 
				
			||||||
    write_cr3(new->P4);
 | 
					    write_cr3(new->P4);
 | 
				
			||||||
    sse_restore(current_proc->sse);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    switch_stack(&scheduler_proc->stack_ptr, &new->stack_ptr);
 | 
					    switch_stack(&scheduler_proc->stack_ptr, &new->stack_ptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sse_save(current_proc->sse);
 | 
					 | 
				
			||||||
    scheduler_insert(current_proc);
 | 
					    scheduler_insert(current_proc);
 | 
				
			||||||
    current_proc = 0;
 | 
					    current_proc = 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ libmittos.a: $(OBJ)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
graphics/graphics.o: graphics/u_vga16.termfont.inc
 | 
					graphics/graphics.o: graphics/u_vga16.termfont.inc
 | 
				
			||||||
graphics/u_vga16.termfont.inc:
 | 
					graphics/u_vga16.termfont.inc:
 | 
				
			||||||
	${BUILDROOT}/toolchain/ports/uni_vga/build.sh
 | 
						${BUILDROOT}/toolchain/build-uni_vga.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Automatic dependency tracking
 | 
					# Automatic dependency tracking
 | 
				
			||||||
DEP := $(OBJ:.o=.d)
 | 
					DEP := $(OBJ:.o=.d)
 | 
				
			||||||
@ -31,7 +31,7 @@ $(OBJ): CPPFLAGS += $(DEPFLAGS)
 | 
				
			|||||||
# Installation
 | 
					# Installation
 | 
				
			||||||
DESTDIR ?= $(BUILDROOT)/sysroot
 | 
					DESTDIR ?= $(BUILDROOT)/sysroot
 | 
				
			||||||
LIBDIR := $(DESTDIR)/usr/lib
 | 
					LIBDIR := $(DESTDIR)/usr/lib
 | 
				
			||||||
INCDIR := $(DESTDIR)/usr/include
 | 
					INCDIR := $(DESTDIR)/usr/include/mittos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(LIBDIR)/libmittos.a: libmittos.a
 | 
					$(LIBDIR)/libmittos.a: libmittos.a
 | 
				
			||||||
	install -D $<  $@
 | 
						install -D $<  $@
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <mittos/graphics.h>
 | 
					#include <graphics.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define incptr(p, n) ((void *)(((uintptr_t)(p)) + (n)))
 | 
					#define incptr(p, n) ((void *)(((uintptr_t)(p)) + (n)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -27,32 +27,23 @@ void draw_line(
 | 
				
			|||||||
    uint64_t y0, uint64_t y1,
 | 
					    uint64_t y0, uint64_t y1,
 | 
				
			||||||
    uint32_t clr
 | 
					    uint32_t clr
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1;
 | 
					  int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1;
 | 
				
			||||||
  int sx = x0 < x1 ? 1 : -1;
 | 
					 | 
				
			||||||
  int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1;
 | 
					  int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1;
 | 
				
			||||||
  dy = -dy;
 | 
					  int sx = x1 > x0 ? 1 : -1;
 | 
				
			||||||
  int sy = y0 < y1 ? 1 : -1;
 | 
					  int sy = y1 > y0 ? 1 : -1;
 | 
				
			||||||
  int64_t err = dx + dy;
 | 
					  uint64_t x = x0, y = y0;
 | 
				
			||||||
 | 
					  int64_t diff = dx - dy;
 | 
				
			||||||
  uint32_t *fb = (uint32_t *)ctx->buffer;
 | 
					  uint32_t *fb = (uint32_t *)ctx->buffer;
 | 
				
			||||||
  while(1) {
 | 
					  while(1) {
 | 
				
			||||||
    if(0 < x0 && x0 < ctx->width &&
 | 
					    fb[PXL(ctx, x, y)] = clr;
 | 
				
			||||||
        0 < y0 && y0 < ctx->height)
 | 
					    if(x == x1 && y == y1) break;
 | 
				
			||||||
      fb[PXL(ctx, x0, y0)] = clr;
 | 
					 | 
				
			||||||
    if(x0 == x1 && y0 == y1) break;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int64_t e2 = 2*err;
 | 
					    if((2*diff) > -dy) {
 | 
				
			||||||
    if(e2 >= dy) {
 | 
					      diff -= dy;
 | 
				
			||||||
      if(x0 == x1) break;
 | 
					      x += sx;
 | 
				
			||||||
      err += dy;
 | 
					    } else {
 | 
				
			||||||
      x0 += sx;
 | 
					      diff += dx;
 | 
				
			||||||
    }
 | 
					      y += sy;
 | 
				
			||||||
    if(e2 <= dx) {
 | 
					 | 
				
			||||||
      if(y0 == y1) break;
 | 
					 | 
				
			||||||
      err += dx;
 | 
					 | 
				
			||||||
      y0 += sy;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,5 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  uint32_t width;
 | 
					  uint32_t width;
 | 
				
			||||||
@ -58,5 +58,7 @@ mkdir gcc-build && cd gcc-build
 | 
				
			|||||||
make all-gcc all-target-libgcc -j 4
 | 
					make all-gcc all-target-libgcc -j 4
 | 
				
			||||||
make install-gcc install-target-libgcc
 | 
					make install-gcc install-target-libgcc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					apk del build-base
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cd /
 | 
					cd /
 | 
				
			||||||
rm -rf /opt
 | 
					rm -rf /opt
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user